video_recorder.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef __VIDEO_RECORDER_H__
  2. #define __VIDEO_RECORDER_H__
  3. #include "basic/timer.h"
  4. #include "avrecorder/capturer/video/VideoCaptureManager.h"
  5. using namespace avrecorder::video;
  6. #include "muxer/av_muxer.h"
  7. #include <deque>
  8. // #include <condition_variable>
  9. // #include <queue>
  10. class VideoRecorder {
  11. public:
  12. bool Open(HWND srcHwnd, Encoder<MediaType::VIDEO>::Param& param, CaptureMethod method);
  13. bool Open(int monitorIdx, Encoder<MediaType::VIDEO>::Param& param, CaptureMethod method);
  14. bool LoadMuxer(AvMuxer& muxer);
  15. bool StartRecord();
  16. void StopRecord();
  17. AVFrame* GetRenderFrame();
  18. void Close();
  19. void SetIsDrawCursor(bool isDraw) { _capturer.setDrawCursor(isDraw); }
  20. bool IsCaptureOverload() const { return _captureTimer.IsOverload(); }
  21. double GetLossRate();
  22. private:
  23. bool _Open(Encoder<MediaType::VIDEO>::Param& param);
  24. VideoCaptureManager _capturer;
  25. AvMuxer* _muxer = nullptr;
  26. bool _isRecord = false;
  27. int _streamIndex = -1;
  28. AVFrame* _encodeFrame = nullptr;
  29. AVFrame* _renderFrame = nullptr;
  30. Encoder<MediaType::VIDEO>::Param _param;
  31. Timer _captureTimer;
  32. Timer _muxTimer;
  33. std::mutex _renderMtx;
  34. uint64_t _totalPts = 0;
  35. uint64_t _lossPts = 0;
  36. // 滑动窗口丢帧统计
  37. static constexpr int LOSS_WINDOW = 100;
  38. std::deque<bool> _lossHistory;
  39. };
  40. #endif