video_recorder.h 1.4 KB

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