From f7e23d3c5e47ec0c105bf506e58e23f635faa20e Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 30 Oct 2025 15:24:58 -0400 Subject: Wip sink changes around errored/ended buffers Signed-off-by: Andrew Opalach --- src/codec/ffmpeg/decoder.c | 26 ++++++++++++++++++-------- src/codec/ffmpeg/decoder.h | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/codec/ffmpeg') diff --git a/src/codec/ffmpeg/decoder.c b/src/codec/ffmpeg/decoder.c index 6eff28b..645a88a 100644 --- a/src/codec/ffmpeg/decoder.c +++ b/src/codec/ffmpeg/decoder.c @@ -7,7 +7,7 @@ #ifdef CAMU_FF_DECODER_HWACCEL #include "../../render/renderer.h" -static const char *hwdevces[] = { +static const char *hwdevices[] = { #ifdef CAMU_HAVE_VULKAN_DECODE "vulkan", #endif @@ -75,7 +75,7 @@ static s32 init_hwframe_context(struct camu_ff_decoder *av, AVCodecContext *cont frames_ctx->sw_format = av->codec_context->sw_pix_fmt; frames_ctx->width = av->codec_context->width; frames_ctx->height = av->codec_context->height; - frames_ctx->initial_pool_size = 20; + frames_ctx->initial_pool_size = 12; s32 ret = av_hwframe_ctx_init(hw_frames_ref); if (ret < 0) { @@ -114,8 +114,10 @@ static enum AVPixelFormat get_hw_format(AVCodecContext *context, const enum AVPi log_error("Failed to get %s HW surface format.", hwdevice_name); // Remake AVCodecContext as a software decoder. - AVCodecParameters *codecpar = avcodec_parameters_alloc(); - avcodec_parameters_from_context(codecpar, av->codec_context); + // This might log an error like "Your platform doesn't support hardware accelerated AV1 decoding.". + // Even though the problem is really a lack of any decoder hardware OR software. + // This happens with wine + d3d11va. Maybe a build configuration issue or FFmpeg bug? + AVCodecParameters *codecpar = av->codecpar; av->errored_hw_context = av->codec_context; alloc_codec_context_internal(av, codec, codecpar); // Note about thread_type choice in ff_decoder_init(). @@ -131,7 +133,13 @@ out: static s32 init_hwdevice_context(struct camu_ff_decoder *av, AVCodecContext *context) { + if (av->hw_device_type == AV_HWDEVICE_TYPE_D3D11VA) { + log_info("av_hwdevice_ctx_create()."); + } s32 ret = av_hwdevice_ctx_create(&av->hw_context, av->hw_device_type, NULL, NULL, 0); + if (av->hw_device_type == AV_HWDEVICE_TYPE_D3D11VA) { + log_info("av_hwdevice_ctx_create() returns."); + } if (ret < 0) { log_error("Failed to create specified HW device."); return ret; @@ -139,7 +147,7 @@ static s32 init_hwdevice_context(struct camu_ff_decoder *av, AVCodecContext *con context->hw_device_ctx = av_buffer_ref(av->hw_context); // Note that context->extra_hw_frames has the ability to cause corruption. - //context->extra_hw_frames = 18; + context->extra_hw_frames = 12; return ret; } @@ -231,6 +239,8 @@ static bool ff_decoder_init(struct camu_decoder *dec, struct camu_renderer *rend #endif AVCodecParameters *codecpar = stream->av.stream->codecpar; + av->codecpar = codecpar; + const AVCodec *codec = avcodec_find_decoder(codecpar->codec_id); if (!codec) { log_error("Failed to find decoder."); @@ -244,9 +254,9 @@ static bool ff_decoder_init(struct camu_decoder *dec, struct camu_renderer *rend collect_supported_hwaccels(av); av->hw_device_type = AV_HWDEVICE_TYPE_NONE; av->hw_pix_fmt = AV_PIX_FMT_NONE; - for (u32 i = 0; i < ARRAY_SIZE(hwdevces); i++) { - size_t length = sizeof(hwdevces[i]) - 1; - av->hw_device_type = hw_device_supported_by_name(av, hwdevces[i], length); + for (u32 i = 0; i < ARRAY_SIZE(hwdevices); i++) { + size_t length = sizeof(hwdevices[i]) - 1; + av->hw_device_type = hw_device_supported_by_name(av, hwdevices[i], length); if (!get_hwdevice_config(av, codec, av->hw_device_type)) { av->hw_device_type = AV_HWDEVICE_TYPE_NONE; } else { diff --git a/src/codec/ffmpeg/decoder.h b/src/codec/ffmpeg/decoder.h index ff513b9..0c3d4d7 100644 --- a/src/codec/ffmpeg/decoder.h +++ b/src/codec/ffmpeg/decoder.h @@ -10,6 +10,7 @@ struct camu_ff_decoder { struct camu_decoder dec; + AVCodecParameters *codecpar; AVCodecContext *codec_context; s32 thread_count; #ifdef CAMU_FF_DECODER_HWACCEL -- cgit v1.2.3-101-g0448