123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #ifndef DECODEVEDIO_H
- #define DECODEVEDIO_H
- #include <QObject>
- #include <QQueue>
- #include <QTimer>
- #include <QMutex>
- #include <QWaitCondition>
- extern "C"
- {
- #include <libavformat/avformat.h>
- }
- class DecodeVedio : public QObject
- {
- Q_OBJECT
- public:
- explicit DecodeVedio(QThread* thread, QObject* parent = nullptr);
- ~DecodeVedio();
-
- void initFFmpeg(const QString& fileName);
- void unInitFFmpeg();
- bool isInitFFmpeg() { return m_initFFmpeg; }
-
- void startDecodeVedio();
- void stopDecodeVedio();
- void setCurrentPos(quint64 pos);
- qint64 getCurrentPos();
- qint64 getDuration();
- bool isRunning() { return m_isRunning; }
- void wakeUpCondQueueNoEmpty();
- QImage* getOneImage();
- QImage* getOneImageUntilHave();
-
- int getFrameCount();
-
- int getSrcVideoWidth() const {return m_srcWidth;}
-
- int getSrcVideoHeight() const {return m_srcHeight;}
-
- void setVideoSize(int width,int height);
- signals:
- void signal_oneImage();
- void signal_playCompleted();
- private:
- void freeFFmpeg();
- void decodeVedio();
- void exitThread();
- void pauseDecode();
- private slots:
- void do_startDecodeVedio();
- private:
- QThread* m_thread = nullptr;
- std::atomic_bool m_isRunning = false;
- QTimer m_startThread;
- std::atomic_bool m_initFFmpeg = false;
- std::atomic_bool m_threadStopped = false;
- std::atomic_bool m_pauseDecode = false;
- std::atomic_bool m_decodeStatus = false;
- std::atomic_bool m_isSeek = false;
- QString m_fileName;
- AVFormatContext *m_pFormatContext = nullptr;
- AVCodecContext *m_pCodecCtx = nullptr;
- AVPacket* m_packet = nullptr;
- AVFrame* m_pFrame = nullptr;
- AVFrame* m_pFrameRGB = nullptr;
- struct SwsContext *m_sws_ctx = nullptr;
- uint8_t *m_buffer = nullptr;
- int m_videoStream = -1;
- int m_srcWidth = 0;
- int m_srcHeight = 0;
- int m_width = 0;
- int m_height = 0;
- int m_frameCount = 0;
- int m_fps;
- qint64 m_duration = 0;
- qint64 m_currentPos = 0;
- qint64 m_startPos = 0;
-
- int m_queueMaxNum = 10;
- QQueue<QImage*> m_queueImage;
- QMutex m_mutexQueue;
- QWaitCondition m_condQueueNoFull;
- QWaitCondition m_condQueueNoEmpty;
- };
- #endif
|