123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #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 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 getVideoWidth() const {return m_width;}
- int getVideoHeight() const {return m_height;}
- void setVideoSize(int width,int height);
- signals:
- void signal_oneImage();
- private:
- void freeFFmpeg();
- void decodeVedio();
- void exitThread();
- 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;
- 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_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 = 30;
- QQueue<QImage*> m_queueImage;
- QMutex m_mutexQueue;
- QWaitCondition m_condQueueNoFull;
- QWaitCondition m_condQueueNoEmpty;
- };
- #endif
|