hframe.h 1.6 KB

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