hframe.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef HW_FRAME_H_
  2. #define HW_FRAME_H_
  3. #include <deque>
  4. #include <mutex>
  5. #include "hbuf.h"
  6. class HFrame {
  7. public:
  8. HBuf buf;
  9. int w;
  10. int h;
  11. int bpp;
  12. int type;
  13. uint64_t ts;
  14. int64_t useridx;
  15. void* userdata;
  16. HFrame() {
  17. w = h = bpp = type = ts = 0;
  18. useridx = -1;
  19. userdata = NULL;
  20. }
  21. bool isNull() {
  22. return w == 0 || h == 0 || buf.isNull();
  23. }
  24. void copy(const HFrame& rhs) {
  25. w = rhs.w;
  26. h = rhs.h;
  27. bpp = rhs.bpp;
  28. type = rhs.type;
  29. ts = rhs.ts;
  30. useridx = rhs.useridx;
  31. userdata = rhs.userdata;
  32. buf.copy(rhs.buf.base, rhs.buf.len);
  33. }
  34. };
  35. typedef struct frame_info_s {
  36. int w;
  37. int h;
  38. int type;
  39. int bpp;
  40. } FrameInfo;
  41. typedef struct frame_stats_s {
  42. int push_cnt;
  43. int pop_cnt;
  44. int push_ok_cnt;
  45. int pop_ok_cnt;
  46. frame_stats_s() {
  47. push_cnt = pop_cnt = push_ok_cnt = pop_ok_cnt = 0;
  48. }
  49. } FrameStats;
  50. #define DEFAULT_FRAME_CACHENUM 10
  51. class HFrameBuf : public HRingBuf {
  52. public:
  53. enum CacheFullPolicy {
  54. SQUEEZE,
  55. DISCARD,
  56. } policy;
  57. HFrameBuf() : HRingBuf() {
  58. cache_num = DEFAULT_FRAME_CACHENUM;
  59. policy = SQUEEZE;
  60. }
  61. void setCache(int num) {cache_num = num;}
  62. void setPolicy(CacheFullPolicy policy) {this->policy = policy;}
  63. int push(HFrame* pFrame);
  64. int pop(HFrame* pFrame);
  65. int cache_num;
  66. FrameStats frame_stats;
  67. FrameInfo frame_info;
  68. std::deque<HFrame> frames;
  69. std::mutex mutex;
  70. };
  71. #endif // HW_FRAME_H_