video_recorder.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 <condition_variable>
  7. // #include <queue>
  8. class VideoRecorder {
  9. public:
  10. bool Open(HWND srcHwnd, Encoder<MediaType::VIDEO>::Param& param, VideoCapturer::Method type);
  11. bool Open(int monitorIdx, Encoder<MediaType::VIDEO>::Param& param, VideoCapturer::Method type);
  12. bool LoadMuxer(AvMuxer& muxer);
  13. bool StartRecord();
  14. void StopRecord();
  15. auto GetCapturerType() { return _capturer.GetMethod(); }
  16. AVFrame* GetRenderFrame();
  17. // 停止录制
  18. void Close();
  19. void SetIsDrawCursor(bool isDraw)
  20. {
  21. _capturer.SetDrawCursor(isDraw);
  22. }
  23. bool IsCaptureOverload() const { return _captureTimer.IsOverload(); }
  24. double GetLossRate() { return _lossPts == 0 ? 0 : (double)_lossPts / _totalPts; }
  25. private:
  26. bool _Open(Encoder<MediaType::VIDEO>::Param& param);
  27. VideoCapturer _capturer;
  28. AvMuxer* _muxer = nullptr;
  29. bool _isRecord = false;
  30. int _streamIndex = -1;
  31. AVFrame* _encodeFrame = nullptr;
  32. AVFrame* _renderFrame = nullptr;
  33. Encoder<MediaType::VIDEO>::Param _param;
  34. Timer _captureTimer;
  35. Timer _muxTimer;
  36. std::mutex _renderMtx;
  37. uint64_t _totalPts = 0;
  38. uint64_t _lossPts = 0;
  39. };
  40. #endif