#ifndef __VIDEOPLAYER_H__
#define __VIDEOPLAYER_H__

#include <functional>
#include <string>
#include <thread>

class QImage;
struct AVFormatContext;

class VideoPlayer {
public:
    using FrameCallback = std::function<void(const QImage &image)>;
    using ErrorCallback = std::function<void(int error, const std::string &message)>;
    VideoPlayer();
    void setFrameCallback(FrameCallback &&callback);
    void setErrorCallback(ErrorCallback &&callback);
    ~VideoPlayer();
    bool open(const std::string &deviceName);
    void close();

protected:
    void run();

private:
    AVFormatContext *m_formatContext = nullptr;
    bool m_exit = true;
    std::thread m_thread;

    FrameCallback m_callback;
    ErrorCallback m_errorCallback;
};

#endif // __VIDEOPLAYER_H__
