video_recorder.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 UnloadMuxer(AvMuxer& muxer);
  16. bool StartRecord();
  17. void StopRecord();
  18. AVFrame* GetRenderFrame();
  19. void Close();
  20. void SetIsDrawCursor(bool isDraw) { _capturer.setDrawCursor(isDraw); }
  21. bool IsCaptureOverload() const { return _captureTimer.IsOverload(); }
  22. double GetLossRate();
  23. void SetCaptureSource(HWND srcHwnd, CaptureMethod method);
  24. void SetCaptureSource(int monitorIdx, CaptureMethod method);
  25. private:
  26. struct MuxerInfo {
  27. AvMuxer* muxer;
  28. int streamIndex;
  29. MuxerInfo(AvMuxer* m, int idx) : muxer(m), streamIndex(idx) {}
  30. };
  31. static constexpr int kCanvasWidth = 1920;
  32. static constexpr int kCanvasHeight = 1080;
  33. bool _Open(Encoder<MediaType::VIDEO>::Param& param);
  34. VideoCaptureManager _capturer;
  35. std::vector<MuxerInfo> _muxers;
  36. std::mutex _muxersMtx;
  37. bool _isRecord = false;
  38. AVFrame* _encodeFrame = nullptr;
  39. AVFrame* _renderFrame = nullptr;
  40. Encoder<MediaType::VIDEO>::Param _param;
  41. Timer _captureTimer;
  42. Timer _muxTimer;
  43. std::mutex _renderMtx;
  44. std::mutex _lossMtx;
  45. uint64_t _totalPts = 0;
  46. uint64_t _lossPts = 0;
  47. // 滑动窗口丢帧统计
  48. static constexpr int LOSS_WINDOW = 100;
  49. std::deque<bool> _lossHistory;
  50. };
  51. #endif