video_recorder.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. void SetCaptureSource(HWND srcHwnd, CaptureMethod method);
  23. void SetCaptureSource(int monitorIdx, CaptureMethod method);
  24. private:
  25. static constexpr int kCanvasWidth = 1920;
  26. static constexpr int kCanvasHeight = 1080;
  27. bool _Open(Encoder<MediaType::VIDEO>::Param& param);
  28. VideoCaptureManager _capturer;
  29. AvMuxer* _muxer = nullptr;
  30. bool _isRecord = false;
  31. int _streamIndex = -1;
  32. AVFrame* _encodeFrame = nullptr;
  33. AVFrame* _renderFrame = nullptr;
  34. Encoder<MediaType::VIDEO>::Param _param;
  35. Timer _captureTimer;
  36. Timer _muxTimer;
  37. std::mutex _renderMtx;
  38. uint64_t _totalPts = 0;
  39. uint64_t _lossPts = 0;
  40. // 滑动窗口丢帧统计
  41. static constexpr int LOSS_WINDOW = 100;
  42. std::deque<bool> _lossHistory;
  43. };
  44. #endif