Commit c649aebc14 for ffmpeg
commit c649aebc14ec5265f13d53bd11b5fbbd6bd61b80
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Sun Nov 1 08:37:39 2026 -0600
avcodec/opus/dec: split setting up from a header out of init and close
Move setting the streams up from a header, and freeing them, out of
initialization and closing, so that they can run again for a header
arriving later.
diff --git a/libavcodec/opus/dec.c b/libavcodec/opus/dec.c
index bb38aec148..2cc677d667 100644
--- a/libavcodec/opus/dec.c
+++ b/libavcodec/opus/dec.c
@@ -474,10 +474,8 @@ finish:
return output_samples;
}
-static av_cold int opus_decode_close(AVCodecContext *avctx)
+static av_cold void opus_free_streams(OpusContext *c)
{
- OpusContext *c = avctx->priv_data;
-
for (int i = 0; i < c->p.nb_streams; i++) {
OpusStreamContext *s = &c->streams[i];
@@ -497,27 +495,26 @@ static av_cold int opus_decode_close(AVCodecContext *avctx)
c->p.nb_streams = 0;
av_freep(&c->p.channel_maps);
+}
+
+static av_cold int opus_decode_close(AVCodecContext *avctx)
+{
+ OpusContext *c = avctx->priv_data;
+
+ opus_free_streams(c);
av_freep(&c->fdsp);
return 0;
}
-static av_cold int opus_decode_init(AVCodecContext *avctx)
+static av_cold int opus_init_streams(AVCodecContext *avctx,
+ const uint8_t *header, int header_size)
{
OpusContext *c = avctx->priv_data;
int ret;
- avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
- if (!avctx->sample_rate)
- avctx->sample_rate = 48000;
-
- c->fdsp = avpriv_float_dsp_alloc(0);
- if (!c->fdsp)
- return AVERROR(ENOMEM);
-
/* find out the channel configuration */
- ret = ff_opus_parse_extradata(avctx, &c->p, avctx->extradata,
- avctx->extradata_size);
+ ret = ff_opus_parse_extradata(avctx, &c->p, header, header_size);
if (ret < 0)
return ret;
if (c->p.gain_i)
@@ -581,6 +578,21 @@ static av_cold int opus_decode_init(AVCodecContext *avctx)
return 0;
}
+static av_cold int opus_decode_init(AVCodecContext *avctx)
+{
+ OpusContext *c = avctx->priv_data;
+
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
+ if (!avctx->sample_rate)
+ avctx->sample_rate = 48000;
+
+ c->fdsp = avpriv_float_dsp_alloc(0);
+ if (!c->fdsp)
+ return AVERROR(ENOMEM);
+
+ return opus_init_streams(avctx, avctx->extradata, avctx->extradata_size);
+}
+
static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
int *got_frame_ptr, AVPacket *avpkt)
{