Files
EJM_Display/PublicFunctions/RtspPlayer.h

58 lines
1.5 KiB
C
Raw Normal View History

2025-09-15 22:28:43 +08:00
#ifndef RTSPPLAYER_H
#define RTSPPLAYER_H
#include <QThread>
2025-09-28 17:14:34 +08:00
#include <GlobalDefinitions/Variable.h>
#if CONFIG_EN_RTSP //开启 RTSP 读取
2025-09-15 22:28:43 +08:00
#include <QMutex>
#include <QImage>
#include <opencv2/opencv.hpp>
2025-09-28 17:14:34 +08:00
#endif
2025-09-15 22:28:43 +08:00
class RtspPlayer : public QThread
{
Q_OBJECT
public:
explicit RtspPlayer(QObject *parent = nullptr);
~RtspPlayer() override;
2025-09-28 17:14:34 +08:00
#if CONFIG_EN_RTSP //开启 RTSP 读取
2025-09-15 22:28:43 +08:00
// 初始化RTSP连接返回是否成功
bool init(const QString &rtspUrl);
// 开始播放
void startPlay();
// 暂停播放
void pausePlay();
// 停止播放(强制释放所有资源)
void stopPlay();
// 获取播放状态
bool isPlaying() const;
// 检查线程是否在运行
bool isRunning() const { return m_isRunning; }
signals:
// 新帧就绪信号
void frameReady(const QImage &frame);
// 错误信息信号
void errorOccurred(const QString &errorMsg);
protected:
// 线程主函数
void run() override;
private:
// OpenCV Mat转QImage内部使用确保线程安全
QImage cvMatToQImage(const cv::Mat &mat);
cv::VideoCapture m_cap; // 视频捕获对象
QString m_rtspUrl; // RTSP地址
mutable QMutex m_mutex; // 互斥锁mutable允许const函数使用
bool m_isPlaying = false; // 播放状态
bool m_isRunning = false; // 线程运行状态
bool m_isPaused = false; // 暂停状态
bool m_needReconnect = false; // 重连标记
2025-09-28 17:14:34 +08:00
#endif
2025-09-15 22:28:43 +08:00
};
#endif // RTSPPLAYER_H