SmartLockerTools/Analyser/VideoPlayer.h

35 lines
776 B
C
Raw Permalink Normal View History

2024-06-13 15:41:40 +08:00
#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__