#ifndef VIDEOCAPTUREMANAGER_H
#define VIDEOCAPTUREMANAGER_H

#include "IVideoCapturer.h"
#include "VideoCapturerFactory.h"
#include <memory>

namespace avrecorder {
namespace video {

class VideoCaptureManager {
public:
    bool open(const CaptureTarget& target, CaptureMethod method, int width, int height) {
        // 确保在创建新捕获器之前关闭旧的
        if (m_capturer) {
            m_capturer->close();
            m_capturer.reset();
        }
        
        m_capturer = VideoCapturerFactory::create(method);
        if (!m_capturer) return false;
        return m_capturer->open(target, width, height);
    }
    void close() {
        if (m_capturer) m_capturer->close();
    }
    AVFrame* getFrame() {
        return m_capturer ? m_capturer->getFrame() : nullptr;
    }
    void setDrawCursor(bool enable) {
        if (m_capturer) m_capturer->setDrawCursor(enable);
    }
private:
    std::unique_ptr<IVideoCapturer> m_capturer;
};

} // namespace video
} // namespace avrecorder

#endif // VIDEOCAPTUREMANAGER_H