From 13c2e6ac6c15edc19bd5f227a888331ac8e8cd5f Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Fri, 11 Apr 2025 11:37:38 +0200 Subject: [PATCH] vdec/lavc: accept corrupted to separate fn + print the value in VERBOSE (for all video decoders) --- src/rtp/video_decoders.cpp | 2 ++ src/video_decompress/libavcodec.c | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/rtp/video_decoders.cpp b/src/rtp/video_decoders.cpp index c897acf4c..aae2aa201 100644 --- a/src/rtp/video_decoders.cpp +++ b/src/rtp/video_decoders.cpp @@ -1384,6 +1384,8 @@ static bool reconfigure_decoder(struct state_video_decoder *decoder, DECOMPRESS_PROPERTY_ACCEPTS_CORRUPTED_FRAME, &res, &size); decoder->accepts_corrupted_frame = ret && res; + MSG(VERBOSE, "Decoder accepts corrupted frames: %d", + (int) decoder->accepts_corrupted_frame); } // Pass metadata to receiver thread (it can tweak parameters) diff --git a/src/video_decompress/libavcodec.c b/src/video_decompress/libavcodec.c index 7ffa2c576..da08b7568 100644 --- a/src/video_decompress/libavcodec.c +++ b/src/video_decompress/libavcodec.c @@ -1145,6 +1145,22 @@ ADD_TO_PARAM("lavd-accept-corrupted", "* lavd-accept-corrupted[=no]\n" " Pass corrupted frames to decoder. If decoder isn't error-resilient,\n" " may crash! Use \"no\" to disable even if enabled by default.\n"); +static bool +accept_corrupted(const AVCodecContext *ctx) +{ + const char *const val = get_commandline_param("lavd-accept-corrupted"); + if (val != NULL) { + return strcmp(val, "no") != 0; + } + if (ctx == NULL) { + return false; + } + if (ctx->codec->id == AV_CODEC_ID_H264) { + return true; + } + return false; +} + static int libavcodec_decompress_get_property(void *state, int property, void *val, size_t *len) { struct state_libavcodec_decompress *s = @@ -1156,15 +1172,7 @@ static int libavcodec_decompress_get_property(void *state, int property, void *v if (*len < sizeof(int)) { return false; } - *(int *) val = false; - if (s->codec_ctx && strcmp(s->codec_ctx->codec->name, "h264") == 0) { - *(int *) val = true; - } - if (get_commandline_param("lavd-accept-corrupted")) { - *(int *) val = - strcmp(get_commandline_param("lavd-accept-corrupted"), "no") != 0; - } - + *(int *) val = accept_corrupted(s->codec_ctx); *len = sizeof(int); ret = true; break;