123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #ifndef DECODEVEDIO_H
- #define DECODEVEDIO_H
- #include <QObject>
- #include <QQueue>
- #include <QTimer>
- #include <QMutex>
- #include <QWaitCondition>
- #include <QImage>
- #include "RingQueue/RingQueue.hpp"
- extern "C"
- {
- #include <libavformat/avformat.h>
- }
- class DecodeVedio : public QObject
- {
- Q_OBJECT
- enum class DecodeState
- {
- NONE = 0,
- DecodeRun,
- DecodePause,
- DecodeSeek,
- DecodeStop,
- DecodeExit
- };
- public:
- explicit DecodeVedio(QThread* thread, QObject* parent = nullptr);
- ~DecodeVedio();
-
- void openVedio(const QString& fileName);
-
-
- void startDecodeVedio();
-
- void stopDecodeVedio();
-
- bool isDecoding() { return m_threadRuning; }
-
- void setCurrentPos(qint64 pos);
-
- qint64 getCurrentPos();
-
- qint64 getDuration();
- qint64 getTotalFrame() { return m_totalFrame; }
-
-
- QImage* getOneImage();
-
- QImage* getOneImageUntilHave(int timeOut = -1);
-
- int getFPS() const { return m_fps; }
-
- void setFPS(int fps) { m_fps = fps; }
-
- QSize getSrcVideoSize() const {return m_srcSize; }
-
- QString getDecoderName() const { return m_decoderName; }
-
- QStringList getHWDecoderList() const { return m_listDecoderName; }
-
- static void findHWDecoder(QStringList& listDecoderName);
- signals:
- void signal_oneImage();
- void signal_playCompleted();
- void signal_startDecode();
- private:
-
- void findHWDecoder();
-
- void initHWDecoder(const AVCodec* codec);
-
- bool copyDataFromGPU(AVFrame* pFrameHW, AVFrame* pFrameSRC);
-
-
- void threadDecodeUsingCPU();
-
- void threadDecodeUsingGPU();
-
- void exitThread();
-
- void pauseDecode();
-
- void continueDecode();
-
- qreal rationalToDouble(AVRational* rational);
-
- void freeAll();
- private slots:
- void do_startDecodeVedio();
- private:
- QThread* m_thread = nullptr;
-
- std::atomic_bool m_threadRuning;
- std::atomic_bool m_initFFmpeg;
- std::atomic_bool m_pauseDecode;
- std::atomic_bool m_decodeStatus;
- std::atomic_bool m_isSeek;
- std::atomic_bool m_flushDecoder;
- std::atomic<DecodeState> m_decodeState;
-
- QString m_fileName;
- AVFormatContext *m_pFormatContext = nullptr;
- AVCodecContext *m_pCodecContext = nullptr;
- AVPacket* m_packet = nullptr;
- AVFrame* m_pFrameSRC = nullptr;
- AVFrame* m_pFrameHW = nullptr;
- struct SwsContext *m_sws_ctx = nullptr;
- uint8_t *m_buffer = nullptr;
- int m_videoStream = -1;
-
- bool m_supportHWDecoder = false;
- AVBufferRef* m_hw_device_ctx = nullptr;
- QList<int> m_listHWDeviceType;
- QStringList m_listDecoderName;
-
- QSize m_srcSize;
- qint64 m_totalFrame = 0;
- int m_fps = 0;
- qint64 m_duration = 0;
- qint64 m_startPos = 0;
- std::atomic<qint64> m_pts;
-
- qint64 m_targetPos = -1;
- qint64 m_currentFrame = 0;
- QString m_decoderName;
- RingQueue<QImage*> m_queueImage;
-
- };
- #endif
|