#ifndef RTSPPLAYER_H #define RTSPPLAYER_H #include #include #include #include class RtspPlayer : public QThread { Q_OBJECT public: explicit RtspPlayer(QObject *parent = nullptr); ~RtspPlayer() override; // 初始化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; // 重连标记 }; #endif // RTSPPLAYER_H