hframe.h 1.7 KB

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