Fix FFmpeg GPU decoding (#242)
All checks were successful
eden-build / source (push) Successful in 3m31s
eden-build / linux (push) Successful in 21m7s
eden-build / android (push) Successful in 25m3s
eden-build / windows (msvc) (push) Successful in 26m43s

This fixes the FFmpeg GPU decoding on some platforms.

Co-authored-by: MaranBr <maranbr@outlook.com>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/242
This commit is contained in:
MaranBr 2025-06-30 14:37:00 +00:00
parent fa600b88b1
commit 2fe728766e
2 changed files with 13 additions and 6 deletions

View file

@ -237,16 +237,22 @@ std::shared_ptr<Frame> DecoderContext::ReceiveFrame() {
if (m_codec_context->hw_device_ctx) { if (m_codec_context->hw_device_ctx) {
// If we have a hardware context, make a separate frame here to receive the // If we have a hardware context, make a separate frame here to receive the
// hardware result before sending it to the output. // hardware result before sending it to the output.
Frame intermediate_frame; std::shared_ptr<Frame> intermediate_frame = std::make_shared<Frame>();
if (!receive(intermediate_frame.GetFrame())) { if (!receive(intermediate_frame->GetFrame())) {
return {}; return {};
} }
m_temp_frame->SetFormat(PreferredGpuFormat); const auto fmt = intermediate_frame->GetPixelFormat();
if (int ret = av_hwframe_transfer_data(m_temp_frame->GetFrame(), intermediate_frame.GetFrame(), 0); ret < 0) { const auto desc = av_pix_fmt_desc_get(fmt);
LOG_ERROR(HW_GPU, "av_hwframe_transfer_data error: {}", AVError(ret)); if (desc && (desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
return {}; m_temp_frame->SetFormat(PreferredGpuFormat);
if (int ret = av_hwframe_transfer_data(m_temp_frame->GetFrame(), intermediate_frame->GetFrame(), 0); ret < 0) {
LOG_ERROR(HW_GPU, "av_hwframe_transfer_data error: {}", AVError(ret));
return {};
}
} else {
m_temp_frame = std::move(intermediate_frame);
} }
} else { } else {
// Otherwise, decode the frame as normal. // Otherwise, decode the frame as normal.

View file

@ -21,6 +21,7 @@ extern "C" {
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavutil/opt.h> #include <libavutil/opt.h>
#include <libavutil/pixdesc.h>
#include <libavcodec/codec_internal.h> #include <libavcodec/codec_internal.h>
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)