1
0

hframe.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "hframe.h"
  2. int HFrameBuf::push(HFrame* pFrame){
  3. if (pFrame->isNull())
  4. return -10;
  5. frame_stats.push_cnt++;
  6. std::lock_guard<std::mutex> locker(mutex);
  7. if (frames.size() >= cache_num){
  8. if (policy == HFrameBuf::DISCARD){
  9. return -20; // note: cache full, discard frame
  10. }
  11. // note: cache full, remove front, push newer frame
  12. HFrame& frame = frames.front();
  13. frames.pop_front();
  14. free(frame.buf.len);
  15. }
  16. int ret = 0;
  17. if (isNull()){
  18. init(pFrame->buf.len * cache_num);
  19. ret = 1; // note: first push
  20. frame_info.w = pFrame->w;
  21. frame_info.h = pFrame->h;
  22. frame_info.type = pFrame->type;
  23. frame_info.bpp = pFrame->bpp;
  24. }
  25. HFrame frame;
  26. frame.buf.base = alloc(pFrame->buf.len);
  27. frame.buf.len = pFrame->buf.len;
  28. frame.copy(*pFrame);
  29. frames.push_back(frame);
  30. frame_stats.push_ok_cnt++;
  31. return ret;
  32. }
  33. int HFrameBuf::pop(HFrame* pFrame){
  34. frame_stats.pop_cnt++;
  35. std::lock_guard<std::mutex> locker(mutex);
  36. if (isNull())
  37. return -10;
  38. if (frames.size() == 0)
  39. return -20;
  40. HFrame& frame = frames.front();
  41. frames.pop_front();
  42. free(frame.buf.len);
  43. if (frame.isNull())
  44. return -30;
  45. pFrame->copy(frame);
  46. frame_stats.pop_ok_cnt++;
  47. return 0;
  48. }