diff --git a/PayloadAPP.pro b/PayloadAPP.pro index b6f2486..fb5f483 100644 --- a/PayloadAPP.pro +++ b/PayloadAPP.pro @@ -14,7 +14,7 @@ QMAKE_PROJECT_DEPTH = 0 # QMAKE_LFLAGS += /MANIFESTUAC:\"level=\'requireAdministrator\' uiAccess=\'false\'\" #程序版本 -VERSION = 1.1.0.1 +VERSION = 1.1.0.2 #程序版本 QMAKE_TARGET_COMPANY = "HTSDFP" diff --git a/Src/VideoGL/decodestream.cpp b/Src/VideoGL/decodestream.cpp index 0267f2f..d1fa2d4 100644 --- a/Src/VideoGL/decodestream.cpp +++ b/Src/VideoGL/decodestream.cpp @@ -1,18 +1,6 @@ #include "decodestream.h" -DecodeStream::DecodeStream(QObject *parent) : QObject{parent} { - /************* 获取当前环境支持的硬件解码器 **************/ - AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE; - QStringList strTypes; - while ((type = av_hwdevice_iterate_types(type)) != AV_HWDEVICE_TYPE_NONE) { - m_HWDeviceTypes.append(type); - const char *ctype = av_hwdevice_get_type_name(type); - if (ctype) { - strTypes.append(QString(ctype)); - } - } - qDebug() << "支持的硬件解码器:" << strTypes; -} +DecodeStream::DecodeStream(QObject *parent) : QObject{parent} {} bool DecodeStream::init(AVPacketQueueManager *queueManager, AVFormatContext *formatContext, int videoIndex) { @@ -63,14 +51,6 @@ void DecodeStream::close() { qDebug() << "decode Stream close!" << m_start; } -/** - * @brief 设置是否使用硬件解码 - * @param flag true:使用 false:不使用 - */ -void DecodeStream::setHWDecoder(bool flag) { - m_HWDecoder = flag; -} - bool DecodeStream::initObject() { // 分配AVFrame并将其字段设置为默认值。 m_frame = av_frame_alloc(); @@ -79,16 +59,6 @@ bool DecodeStream::initObject() { free(); return false; } - - m_frameHW = av_frame_alloc(); - if (!m_frameHW) { -#if PRINT_LOG - qWarning() << "av_frame_alloc() Error!"; -#endif - free(); - return false; - } - return true; } @@ -137,11 +107,6 @@ bool DecodeStream::initDecoder(AVFormatContext *inputFormatContext, // m_codecContext->err_recognition = AV_EF_IGNORE_ERR; // m_codecContext->flags |= AV_CODEC_FLAG2_CHUNKS; - if (m_HWDecoder) { - // 初始化硬件解码器(在avcodec_open2前调用) - initHWDecoder(codec); - } - // 初始化解码器上下文,如果之前avcodec_alloc_context3传入了解码器,这里设置NULL就可以 ret = avcodec_open2(m_codecContext, codec, nullptr); if (ret < 0) { @@ -173,12 +138,6 @@ AVFrame *DecodeStream::decodePacket(AVPacket *inputPacket) { } m_frameTemp = m_frame; - if (!m_frame->data[0]) { - m_frameTemp = m_frameHW; - if (!dataCopy()) { - break; - } - } return m_frameTemp; // QThread::msleep(1); } @@ -203,101 +162,10 @@ void DecodeStream::free() { if (m_codecContext) { avcodec_free_context(&m_codecContext); } - if (hw_device_ctx) { - av_buffer_unref(&hw_device_ctx); - } + if (m_frame) { av_frame_free(&m_frame); } - if (m_frameHW) { - av_frame_free(&m_frameHW); - } -} - -/*********** FFmpeg获取GPU硬件解码帧格式的回调函数 ***************/ -static enum AVPixelFormat g_pixelFormat; -/** - * @brief 回调函数,获取GPU硬件解码帧的格式 - * @param s - * @param fmt - * @return - */ -AVPixelFormat get_hw_format(AVCodecContext *s, const enum AVPixelFormat *fmt) { - Q_UNUSED(s) - const enum AVPixelFormat *p; - - for (p = fmt; *p != -1; p++) { - if (*p == g_pixelFormat) { - return *p; - } - } - qDebug() << "无法获取硬件表面格式."; - return AV_PIX_FMT_NONE; -} - -/** - * @brief 初始化硬件解码器 - * @param codec - */ -bool DecodeStream::initHWDecoder(const AVCodec *codec) { - if (!codec) return false; - - for (int i = 0;; i++) { - const AVCodecHWConfig *config = avcodec_get_hw_config(codec, i); - if (!config) { - qDebug() << "打开硬件解码器失败!"; - return false; - } - - if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) { - for (auto i : m_HWDeviceTypes) { - if (config->device_type == AVHWDeviceType(i)) { - g_pixelFormat = config->pix_fmt; - - // 打开指定类型的设备,并为其创建AVHWDeviceContext。 - int ret = av_hwdevice_ctx_create(&hw_device_ctx, - config->device_type, - nullptr, nullptr, 0); - if (ret < 0) { - showError(ret); - free(); - return false; - } - qDebug() << "打开硬件解码器:" - << av_hwdevice_get_type_name(config->device_type); - m_codecContext->hw_device_ctx = - av_buffer_ref(hw_device_ctx); - m_codecContext->get_format = get_hw_format; - return true; - } - } - } - } - return false; -} - -/** - * @brief 硬件解码完成需要将数据从GPU复制到CPU - * @return - */ -bool DecodeStream::dataCopy() { - if (m_frame->format != g_pixelFormat) { - av_frame_unref(m_frame); - return false; - } -#if 1 - int ret = av_hwframe_map(m_frameHW, m_frame, 0); - if (ret < 0) { - showError(ret); - av_frame_unref(m_frame); - return false; - } - m_frameHW->width = m_frame->width; - m_frameHW->height = m_frame->height; -#else - -#endif - return true; } bool DecodeStream::isValidAVFrame(AVFrame *frame) { diff --git a/Src/VideoGL/decodestream.h b/Src/VideoGL/decodestream.h index ab19d65..3e9cb8f 100644 --- a/Src/VideoGL/decodestream.h +++ b/Src/VideoGL/decodestream.h @@ -18,7 +18,6 @@ public: bool init(AVPacketQueueManager *queueManager, AVFormatContext *formatContext, int videoIndex); void close(); - void setHWDecoder(bool flag); // 是否使用硬件解码器 public slots: void startDecode(); @@ -34,9 +33,6 @@ private: AVFrame *decodePacket(AVPacket *inputPacket); void free(); // 释放 - bool initHWDecoder(const AVCodec *codec); // 初始化硬件解码器 - bool dataCopy(); // 硬件解码完成需要将数据从GPU复制到CPU - bool isValidAVFrame(AVFrame *frame); bool isValidAVPacket(AVPacket *pkt); @@ -47,11 +43,7 @@ private: AVCodecContext *m_codecContext = nullptr; // 解码器上下文 QQueue *m_packetsQueue = nullptr; // 解码前的视频帧队列 AVFrame *m_frame = nullptr; // 解码后的视频帧 - AVFrame *m_frameHW = nullptr; // 硬件解码后的视频帧 AVFrame *m_frameTemp = nullptr; - QList m_HWDeviceTypes; // 保存当前环境支持的硬件解码器 - AVBufferRef *hw_device_ctx = nullptr; // 对数据缓冲区的引用 - bool m_HWDecoder = false; // 记录是否使用硬件解码 AVPacketQueueManager *m_queueManager = nullptr; QMutex m_mutex; }; diff --git a/Src/VideoGL/videowidget.cpp b/Src/VideoGL/videowidget.cpp index b9368a9..2de644d 100644 --- a/Src/VideoGL/videowidget.cpp +++ b/Src/VideoGL/videowidget.cpp @@ -70,7 +70,6 @@ bool VideoWidget::play(const QString &url) { &VideoWidget::repaint, Qt::QueuedConnection); // Qt::BlockingQueuedConnection - if (m_HWDecoder) decodeStreamer->setHWDecoder(m_HWDecoder); decodeStreamer->moveToThread(&decodeStreamThread); decodeStreamThread.start(); @@ -176,10 +175,6 @@ void VideoWidget::setPushURL(const QString &url) { m_pushURL = url; } -void VideoWidget::setHWDecoder(bool flag) { - m_HWDecoder = flag; -} - void VideoWidget::setVedioSaveFileDirPath(const QString &dirPath) { m_videoSaveDirPath = dirPath; } diff --git a/Src/VideoGL/videowidget.h b/Src/VideoGL/videowidget.h index 9638f56..235e89f 100644 --- a/Src/VideoGL/videowidget.h +++ b/Src/VideoGL/videowidget.h @@ -49,7 +49,6 @@ public: void stopPushStream(); void setPullURL(const QString &url); void setPushURL(const QString &url); - void setHWDecoder(bool flag); void setVedioSaveFileDirPath(const QString &dirPath); protected: @@ -95,7 +94,6 @@ private: bool m_playFlag = false; bool m_pullFlag = false; bool m_pushFlag = false; - bool m_HWDecoder = false; QString m_videoSaveDirPath; ReadStream *readStreamer = nullptr; diff --git a/global.cpp b/global.cpp index 367cd8e..9ba60df 100644 --- a/global.cpp +++ b/global.cpp @@ -2,7 +2,7 @@ global::global() {} -QString g_SoftwareVersion = "版本号:V1.1.0.1_20241128"; +QString g_SoftwareVersion = "版本号:V1.1.0.2_20241202"; NotifyManager *g_notifyManager = nullptr;