hframe.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef H_FRAME_H
  2. #define H_FRAME_H
  3. #include <deque>
  4. #include "hbuf.h"
  5. #include "hmutex.h"
  6. typedef struct hframe_s{
  7. hbuf_t buf;
  8. int w;
  9. int h;
  10. int type;
  11. int bpp;
  12. uint64 ts;
  13. void* userdata;
  14. hframe_s(){
  15. w = h = type = bpp = ts = 0;
  16. userdata = NULL;
  17. }
  18. bool isNull(){
  19. return w == 0 || h == 0 || buf.isNull();
  20. }
  21. // deep copy
  22. void copy(const hframe_s& rhs){
  23. this->w = rhs.w;
  24. this->h = rhs.h;
  25. this->type = rhs.type;
  26. this->bpp = rhs.bpp;
  27. this->ts = rhs.ts;
  28. this->userdata = rhs.userdata;
  29. if (this->buf.isNull() || this->buf.len != rhs.buf.len){
  30. this->buf.init(rhs.buf.len);
  31. }
  32. memcpy(this->buf.base, rhs.buf.base, rhs.buf.len);
  33. }
  34. }HFrame;
  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 // H_FRAME_H