hframe.h 1.9 KB

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