From: mkver via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: mkver <code@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH] Various libmpeghdec patches (PR #20602) Date: Wed, 24 Sep 2025 15:26:57 -0000 Message-ID: <175872761781.25.4480376046819961295@bf249f23a2c8> (raw) PR #20602 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20602 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20602.patch There is another issue not fixed in this PR: The decoder treats avctx->sample_rate as time base of avpkt->pts, although it is AVCodecContext.pkt_timebase. That is probably the reason for the sample_rate check. >From a4b870ecb2c422faa8bb9fb5876b3a83f5ec4918 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Wed, 24 Sep 2025 12:07:28 +0200 Subject: [PATCH 1/8] avcodec/libmpeghdec: Remove redundant manual close calls This decoder has the INIT_CLEANUP flag set. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/libmpeghdec.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavcodec/libmpeghdec.c b/libavcodec/libmpeghdec.c index e293ec3396..ae85924625 100644 --- a/libavcodec/libmpeghdec.c +++ b/libavcodec/libmpeghdec.c @@ -171,16 +171,13 @@ static av_cold int mpegh3dadec_init(AVCodecContext *avctx) s->decoder_buffer_size = MAX_OUTBUF_SIZE; s->decoder_buffer = av_malloc(s->decoder_buffer_size); - if (!s->decoder_buffer) { - mpegh3dadec_close(avctx); + if (!s->decoder_buffer) return AVERROR(ENOMEM); - } // initialize the decoder s->decoder = mpeghdecoder_init(cicp); if (s->decoder == NULL) { av_log(avctx, AV_LOG_ERROR, "MPEG-H decoder library init failed.\n"); - mpegh3dadec_close(avctx); return AVERROR_EXTERNAL; } @@ -188,7 +185,6 @@ static av_cold int mpegh3dadec_init(AVCodecContext *avctx) if (mpeghdecoder_setMhaConfig(s->decoder, avctx->extradata, avctx->extradata_size)) { av_log(avctx, AV_LOG_ERROR, "Unable to set MHA configuration\n"); - mpegh3dadec_close(avctx); return AVERROR_INVALIDDATA; } } -- 2.49.1 >From b7ef96c52a8534cd2c00ab4d560cf0aca39bc1d7 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Wed, 24 Sep 2025 12:09:39 +0200 Subject: [PATCH 2/8] avcodec/libmpeghdec: Remove private class This decoder doesn't have any options. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/libmpeghdec.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/libavcodec/libmpeghdec.c b/libavcodec/libmpeghdec.c index ae85924625..2d6798e49e 100644 --- a/libavcodec/libmpeghdec.c +++ b/libavcodec/libmpeghdec.c @@ -35,7 +35,6 @@ #include "libavutil/channel_layout.h" #include "libavutil/frame.h" #include "libavutil/mem.h" -#include "libavutil/opt.h" #include "codec_internal.h" #include "decode.h" @@ -45,7 +44,6 @@ #define MAX_OUTBUF_SIZE (sizeof(int32_t) * 24 * 3072 * (MAX_LOST_FRAMES + 1)) typedef struct MPEGH3DADecContext { - AVClass *av_class; // pointer to the decoder HANDLE_MPEGH_DECODER_CONTEXT decoder; @@ -54,13 +52,6 @@ typedef struct MPEGH3DADecContext { int decoder_buffer_size; } MPEGH3DADecContext; -// private class definition for ffmpeg -static const AVClass mpegh3da_class = { - .class_name = "MPEG-H 3D Audio Decoder", - .item_name = av_default_item_name, - .version = LIBAVUTIL_VERSION_INT, -}; - static av_cold int mpegh3dadec_close(AVCodecContext *avctx) { MPEGH3DADecContext *s = avctx->priv_data; @@ -268,7 +259,6 @@ static av_cold void mpegh3dadec_flush(AVCodecContext *avctx) const FFCodec ff_libmpeghdec_decoder = { .p.name = "libmpeghdec", CODEC_LONG_NAME("libmpeghdec (MPEG-H 3D Audio)"), - .p.priv_class = &mpegh3da_class, .p.type = AVMEDIA_TYPE_AUDIO, .p.id = AV_CODEC_ID_MPEGH_3D_AUDIO, .p.capabilities = -- 2.49.1 >From 63a1d668db8922a12b8093115512348836e139d5 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Wed, 24 Sep 2025 12:10:32 +0200 Subject: [PATCH 3/8] avcodec/libmpeghdec: Don't set AVCodec.sample_fmts It is mostly pointless for decoders (only useful for those codecs for which a floating-point and a fixed-point decoder exists). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/libmpeghdec.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/libmpeghdec.c b/libavcodec/libmpeghdec.c index 2d6798e49e..e3cb219838 100644 --- a/libavcodec/libmpeghdec.c +++ b/libavcodec/libmpeghdec.c @@ -268,7 +268,6 @@ const FFCodec ff_libmpeghdec_decoder = { FF_CODEC_DECODE_CB(mpegh3dadec_decode_frame), .close = mpegh3dadec_close, .flush = mpegh3dadec_flush, - CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_S32), .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, .p.wrapper_name = "libmpeghdec", }; -- 2.49.1 >From 2a6618920c40420b0604fe41546ff88fab4e2473 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Wed, 24 Sep 2025 12:13:16 +0200 Subject: [PATCH 4/8] avcodec/libmpeghdec: Inline constant Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/libmpeghdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libmpeghdec.c b/libavcodec/libmpeghdec.c index e3cb219838..5233b36bc3 100644 --- a/libavcodec/libmpeghdec.c +++ b/libavcodec/libmpeghdec.c @@ -236,7 +236,7 @@ static int mpegh3dadec_decode_frame(AVCodecContext *avctx, AVFrame *frame, memcpy(frame->extended_data[0], s->decoder_buffer, avctx->ch_layout.nb_channels * avctx->frame_size * - av_get_bytes_per_sample(avctx->sample_fmt)); + sizeof(*s->decoder_buffer) /* only AV_SAMPLE_FMT_S32 is supported */); *got_frame_ptr = 1; return ret = avpkt->size; -- 2.49.1 >From 76892e05752acab6a9e769478cd07058dd6692c8 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Wed, 24 Sep 2025 12:18:57 +0200 Subject: [PATCH 5/8] avcodec/libmpeghdec: Don't use too big buffer The channel count is fixed, so we don't need to allocate space to hold samples for nonexisting channels. Also switch to decoder_buffer_size to be samples-based. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/libmpeghdec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/libmpeghdec.c b/libavcodec/libmpeghdec.c index 5233b36bc3..ebb5e54d7b 100644 --- a/libavcodec/libmpeghdec.c +++ b/libavcodec/libmpeghdec.c @@ -40,8 +40,8 @@ #include "decode.h" #define MAX_LOST_FRAMES 2 -// 32-bit int * 22.2 * max framesize * (max delay frames + 1) -#define MAX_OUTBUF_SIZE (sizeof(int32_t) * 24 * 3072 * (MAX_LOST_FRAMES + 1)) +// max framesize * (max delay frames + 1) +#define PER_CHANNEL_OUTBUF_SIZE (3072 * (MAX_LOST_FRAMES + 1)) typedef struct MPEGH3DADecContext { // pointer to the decoder @@ -49,7 +49,7 @@ typedef struct MPEGH3DADecContext { // Internal values int32_t *decoder_buffer; - int decoder_buffer_size; + int decoder_buffer_size; ///< in samples } MPEGH3DADecContext; static av_cold int mpegh3dadec_close(AVCodecContext *avctx) @@ -160,8 +160,8 @@ static av_cold int mpegh3dadec_init(AVCodecContext *avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S32; avctx->sample_rate = 48000; - s->decoder_buffer_size = MAX_OUTBUF_SIZE; - s->decoder_buffer = av_malloc(s->decoder_buffer_size); + s->decoder_buffer_size = PER_CHANNEL_OUTBUF_SIZE * avctx->ch_layout.nb_channels; + s->decoder_buffer = av_malloc_array(s->decoder_buffer_size, sizeof(*s->decoder_buffer)); if (!s->decoder_buffer) return AVERROR(ENOMEM); @@ -214,7 +214,7 @@ static int mpegh3dadec_decode_frame(AVCodecContext *avctx, AVFrame *frame, } err = mpeghdecoder_getSamples(s->decoder, s->decoder_buffer, - s->decoder_buffer_size / sizeof(int32_t), + s->decoder_buffer_size, &out_info); if (err == MPEGH_DEC_FEED_DATA) { // no frames to produce at the moment -- 2.49.1 >From cad21108aa91439c01bc85073808424fbea6e4dd Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Wed, 24 Sep 2025 12:22:33 +0200 Subject: [PATCH 6/8] avcodec/libmpeghdec: Remove always-false check The pointer to the decoder is always set after init has been called successfully. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/libmpeghdec.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavcodec/libmpeghdec.c b/libavcodec/libmpeghdec.c index ebb5e54d7b..174fd5da34 100644 --- a/libavcodec/libmpeghdec.c +++ b/libavcodec/libmpeghdec.c @@ -247,9 +247,6 @@ static av_cold void mpegh3dadec_flush(AVCodecContext *avctx) MPEGH_DECODER_ERROR err; MPEGH3DADecContext *s = avctx->priv_data; - if (!s->decoder) - return; - err = mpeghdecoder_flush(s->decoder); if (err != MPEGH_DEC_OK && err != MPEGH_DEC_FEED_DATA) -- 2.49.1 >From 523517c4426820164dfaf55ce6c2a57d65bc8915 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Wed, 24 Sep 2025 15:00:25 +0200 Subject: [PATCH 7/8] avcodec/libmpeghdec: Align FFCodec initializers Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/libmpeghdec.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavcodec/libmpeghdec.c b/libavcodec/libmpeghdec.c index 174fd5da34..bd63db8ed6 100644 --- a/libavcodec/libmpeghdec.c +++ b/libavcodec/libmpeghdec.c @@ -254,17 +254,17 @@ static av_cold void mpegh3dadec_flush(AVCodecContext *avctx) } const FFCodec ff_libmpeghdec_decoder = { - .p.name = "libmpeghdec", + .p.name = "libmpeghdec", CODEC_LONG_NAME("libmpeghdec (MPEG-H 3D Audio)"), - .p.type = AVMEDIA_TYPE_AUDIO, - .p.id = AV_CODEC_ID_MPEGH_3D_AUDIO, - .p.capabilities = - AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_CHANNEL_CONF, + .p.type = AVMEDIA_TYPE_AUDIO, + .p.id = AV_CODEC_ID_MPEGH_3D_AUDIO, + .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | + AV_CODEC_CAP_CHANNEL_CONF, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, .priv_data_size = sizeof(MPEGH3DADecContext), - .init = mpegh3dadec_init, + .init = mpegh3dadec_init, FF_CODEC_DECODE_CB(mpegh3dadec_decode_frame), - .close = mpegh3dadec_close, - .flush = mpegh3dadec_flush, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .flush = mpegh3dadec_flush, + .close = mpegh3dadec_close, .p.wrapper_name = "libmpeghdec", }; -- 2.49.1 >From c72e8408c26eda5dd8795d713d9850a1fdd2893b Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Wed, 24 Sep 2025 17:05:27 +0200 Subject: [PATCH 8/8] avcodec/libmpeghdec: Don't set AVCodecContext.frame_size It indicates a constant frame size (in samples); yet the documentation of the MPEGH_DECODER_OUTPUT_INFO structure says that it "gives information about the currently decoded audio data" and makes no guarantees about it being constant. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/libmpeghdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/libmpeghdec.c b/libavcodec/libmpeghdec.c index bd63db8ed6..527627ba16 100644 --- a/libavcodec/libmpeghdec.c +++ b/libavcodec/libmpeghdec.c @@ -225,7 +225,7 @@ static int mpegh3dadec_decode_frame(AVCodecContext *avctx, AVFrame *frame, return AVERROR_UNKNOWN; } - frame->nb_samples = avctx->frame_size = out_info.numSamplesPerChannel; + frame->nb_samples = out_info.numSamplesPerChannel; frame->sample_rate = avctx->sample_rate = out_info.sampleRate; frame->pts = out_info.ticks; frame->time_base.num = 1; @@ -235,7 +235,7 @@ static int mpegh3dadec_decode_frame(AVCodecContext *avctx, AVFrame *frame, return ret; memcpy(frame->extended_data[0], s->decoder_buffer, - avctx->ch_layout.nb_channels * avctx->frame_size * + avctx->ch_layout.nb_channels * frame->nb_samples * sizeof(*s->decoder_buffer) /* only AV_SAMPLE_FMT_S32 is supported */); *got_frame_ptr = 1; -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-09-24 15:27 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=175872761781.25.4480376046819961295@bf249f23a2c8 \ --to=ffmpeg-devel@ffmpeg.org \ --cc=code@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror http://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ http://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git