From 91adee2f5b7cad68260fc9b73db0469fa176e8d7 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 21 Jul 2025 16:34:17 -0400 Subject: [PATCH] Fix GPU VP8 decoding without breaking unsupported devices --- src/video_core/host1x/ffmpeg/ffmpeg.cpp | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/video_core/host1x/ffmpeg/ffmpeg.cpp b/src/video_core/host1x/ffmpeg/ffmpeg.cpp index 31f2b361b0..c7ac360954 100644 --- a/src/video_core/host1x/ffmpeg/ffmpeg.cpp +++ b/src/video_core/host1x/ffmpeg/ffmpeg.cpp @@ -41,20 +41,30 @@ constexpr std::array PreferredGpuDecoders = { }; AVPixelFormat GetGpuFormat(AVCodecContext* codec_context, const AVPixelFormat* pix_fmts) { - // Check if there is a pixel format supported by the GPU decoder. const auto desc = av_pix_fmt_desc_get(codec_context->pix_fmt); - if (desc && desc->flags & AV_PIX_FMT_FLAG_HWACCEL) { - for (const AVPixelFormat* p = pix_fmts; *p != AV_PIX_FMT_NONE; ++p) { - if (*p == codec_context->pix_fmt) { - return codec_context->pix_fmt; + if (desc && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) { + for (int i = 0;; i++) { + const AVCodecHWConfig* config = avcodec_get_hw_config(codec_context->codec, i); + if (!config) { + break; + } + + for (const auto type : PreferredGpuDecoders) { + if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX && config->device_type == type) { + codec_context->pix_fmt = config->pix_fmt; + } } } } - // Fallback to CPU decoder. - LOG_INFO(HW_GPU, "Could not find supported GPU pixel format, falling back to CPU decoder"); - av_buffer_unref(&codec_context->hw_device_ctx); + for (const AVPixelFormat* p = pix_fmts; *p != AV_PIX_FMT_NONE; ++p) { + if (*p == codec_context->pix_fmt) { + return codec_context->pix_fmt; + } + } + LOG_INFO(HW_GPU, "Could not find supported GPU pixel format, falling back to CPU decoder"); + av_buffer_unref(&codec_context->hw_device_ctx); codec_context->pix_fmt = PreferredCpuFormat; return codec_context->pix_fmt; }