* [FFmpeg-devel] [PATCH] avcodec/mpegaudiodec_template: Don't modify AVCodecContext.priv_data (PR #20431)
@ 2025-09-04 11:17 mkver via ffmpeg-devel
0 siblings, 0 replies; only message in thread
From: mkver via ffmpeg-devel @ 2025-09-04 11:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: mkver
PR #20431 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20431
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20431.patch
>From fcfe42e86c7c3027b80f60dd0a43a99ebedbdccb Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Thu, 4 Sep 2025 12:00:24 +0200
Subject: [PATCH 1/4] avcodec/mpegaudiodec_template: Don't modify
AVCodecContext.priv_data
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegaudiodec_template.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index d7c5210eb8..5c38f4e9d7 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -280,10 +280,9 @@ static av_cold void decode_init_static(void)
ff_mpegaudiodec_common_init_static();
}
-static av_cold int decode_init(AVCodecContext * avctx)
+static av_cold int decode_ctx_init(AVCodecContext *avctx, MPADecodeContext *s)
{
static AVOnce init_static_once = AV_ONCE_INIT;
- MPADecodeContext *s = avctx->priv_data;
s->avctx = avctx;
@@ -315,6 +314,11 @@ static av_cold int decode_init(AVCodecContext * avctx)
return 0;
}
+static av_cold int decode_init(AVCodecContext *avctx)
+{
+ return decode_ctx_init(avctx, avctx->priv_data);
+}
+
#define C3 FIXHR(0.86602540378443864676/2)
#define C4 FIXHR(0.70710678118654752439/2) //0.5 / cos(pi*(9)/36)
#define C5 FIXHR(0.51763809020504152469/2) //0.5 / cos(pi*(5)/36)
@@ -1771,19 +1775,13 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
s->syncword = 0xfff00000;
/* Init the first mp3 decoder in standard way, so that all tables get built
- * We replace avctx->priv_data with the context of the first decoder so that
- * decode_init() does not have to be changed.
* Other decoders will be initialized here copying data from the first context
*/
// Allocate zeroed memory for the first decoder context
s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
if (!s->mp3decctx[0])
return AVERROR(ENOMEM);
- // Put decoder context in place to make init_decode() happy
- avctx->priv_data = s->mp3decctx[0];
- ret = decode_init(avctx);
- // Restore mp3on4 context pointer
- avctx->priv_data = s;
+ ret = decode_ctx_init(avctx, s->mp3decctx[0]);
if (ret < 0)
return ret;
s->mp3decctx[0]->adu_mode = 1; // Set adu mode
--
2.49.1
>From fb818736d4a9ef8eafd85c97c0f2ff2c31ff6703 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Thu, 4 Sep 2025 12:07:06 +0200
Subject: [PATCH 2/4] avcodec/mpegaudiodec_template: Allocate sub-contexts
jointly
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegaudiodec_template.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 5c38f4e9d7..42e995643b 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -1738,10 +1738,8 @@ static const int16_t chan_layout[8] = {
static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
{
MP3On4DecodeContext *s = avctx->priv_data;
- int i;
- for (i = 0; i < s->frames; i++)
- av_freep(&s->mp3decctx[i]);
+ av_freep(&s->mp3decctx[0]);
return 0;
}
@@ -1777,8 +1775,8 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
/* Init the first mp3 decoder in standard way, so that all tables get built
* Other decoders will be initialized here copying data from the first context
*/
- // Allocate zeroed memory for the first decoder context
- s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
+ // Allocate zeroed memory for the decoder contexts
+ s->mp3decctx[0] = av_calloc(s->frames, sizeof(*s->mp3decctx[0]));
if (!s->mp3decctx[0])
return AVERROR(ENOMEM);
ret = decode_ctx_init(avctx, s->mp3decctx[0]);
@@ -1790,9 +1788,7 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
* Each frame is 1 or 2 channels - up to 5 frames allowed
*/
for (i = 1; i < s->frames; i++) {
- s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext));
- if (!s->mp3decctx[i])
- return AVERROR(ENOMEM);
+ s->mp3decctx[i] = s->mp3decctx[0] + i;
s->mp3decctx[i]->adu_mode = 1;
s->mp3decctx[i]->avctx = avctx;
s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
--
2.49.1
>From 3e1a4eb308100f30b7b141ec5390f1ff7121ef77 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Thu, 4 Sep 2025 12:25:48 +0200
Subject: [PATCH 3/4] avcodec/mpegaudiodec_template: Mark flush functions as
av_cold
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegaudiodec_template.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 42e995643b..3ca9adb8ab 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -1625,7 +1625,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
return buf_size + skipped;
}
-static void mp_flush(MPADecodeContext *ctx)
+static av_cold void mp_flush(MPADecodeContext *ctx)
{
memset(ctx->synth_buf, 0, sizeof(ctx->synth_buf));
memset(ctx->mdct_buf, 0, sizeof(ctx->mdct_buf));
@@ -1633,7 +1633,7 @@ static void mp_flush(MPADecodeContext *ctx)
ctx->dither_state = 0;
}
-static void flush(AVCodecContext *avctx)
+static av_cold void flush(AVCodecContext *avctx)
{
mp_flush(avctx->priv_data);
}
@@ -1799,7 +1799,7 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
}
-static void flush_mp3on4(AVCodecContext *avctx)
+static av_cold void flush_mp3on4(AVCodecContext *avctx)
{
int i;
MP3On4DecodeContext *s = avctx->priv_data;
--
2.49.1
>From 407c8ae0e89573da2aad0845bb1f58ba760b2b3d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Thu, 4 Sep 2025 12:29:28 +0200
Subject: [PATCH 4/4] avcodec/mpegaudiodec_template: Avoid write-only stores
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegaudiodec_template.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 3ca9adb8ab..0efcf9853d 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -1792,7 +1792,9 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
s->mp3decctx[i]->adu_mode = 1;
s->mp3decctx[i]->avctx = avctx;
s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
+#if USE_FLOATS
s->mp3decctx[i]->butterflies_float = s->mp3decctx[0]->butterflies_float;
+#endif
}
return 0;
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-09-04 11:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-04 11:17 [FFmpeg-devel] [PATCH] avcodec/mpegaudiodec_template: Don't modify AVCodecContext.priv_data (PR #20431) mkver via ffmpeg-devel
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 https://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/ https://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