hframe.h 1.7 KB

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