VideoCaptureManager.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef VIDEOCAPTUREMANAGER_H
  2. #define VIDEOCAPTUREMANAGER_H
  3. #include "IVideoCapturer.h"
  4. #include "VideoCapturerFactory.h"
  5. #include <memory>
  6. namespace avrecorder {
  7. namespace video {
  8. class VideoCaptureManager {
  9. public:
  10. bool open(const CaptureTarget& target, CaptureMethod method, int width, int height) {
  11. // 确保在创建新捕获器之前关闭旧的
  12. if (m_capturer) {
  13. m_capturer->close();
  14. m_capturer.reset();
  15. }
  16. m_capturer = VideoCapturerFactory::create(method);
  17. if (!m_capturer) return false;
  18. return m_capturer->open(target, width, height);
  19. }
  20. void close() {
  21. if (m_capturer) m_capturer->close();
  22. }
  23. AVFrame* getFrame() {
  24. return m_capturer ? m_capturer->getFrame() : nullptr;
  25. }
  26. void setDrawCursor(bool enable) {
  27. if (m_capturer) m_capturer->setDrawCursor(enable);
  28. }
  29. private:
  30. std::unique_ptr<IVideoCapturer> m_capturer;
  31. };
  32. } // namespace video
  33. } // namespace avrecorder
  34. #endif // VIDEOCAPTUREMANAGER_H