#ifndef DECODESTREAM_H #define DECODESTREAM_H #include #include #include #include #include #include #include "avpacketqueuemanager.h" #include "ffmpeginclude.h" class DecodeStream : public QObject { Q_OBJECT public: DecodeStream(QObject *parent = nullptr); bool init(AVPacketQueueManager *queueManager, AVFormatContext *formatContext, int videoIndex); void close(); public slots: void startDecode(); signals: void repaintSignal(AVFrame *frame); // 重绘 void startDecodeSignal(); void sendErrorMessageSignal(QString message, int type); private: bool initObject(); // 初始化对象 bool initDecoder(AVFormatContext *inputFormatContext, int videoIndex); // 初始化解码器 AVFrame *decodePacket(AVPacket *inputPacket); void free(); // 释放 bool isValidAVFrame(AVFrame *frame); bool isValidAVPacket(AVPacket *pkt); private: bool m_start = true; int m_videoIndex = 0; AVFormatContext *m_formatContext = nullptr; AVCodecContext *m_codecContext = nullptr; // 解码器上下文 QQueue *m_packetsQueue = nullptr; // 解码前的视频帧队列 AVFrame *m_frame = nullptr; // 解码后的视频帧 AVFrame *m_frameTemp = nullptr; AVPacketQueueManager *m_queueManager = nullptr; QMutex m_mutex; }; #endif // DECODESTREAM_H