Commit e359e23355 for ffmpeg
commit e359e233554a044ee441ee19ed95b66a06edd44c
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Sat Oct 31 09:44:35 2026 -0500
avcodec/opus/parse: take the header to parse as an argument
Pass the header to ff_opus_parse_extradata() rather than reading it
from the codec context, so that a header arriving later can be parsed
the same way.
diff --git a/libavcodec/opus/dec.c b/libavcodec/opus/dec.c
index c284f7a03b..0ca457d77d 100644
--- a/libavcodec/opus/dec.c
+++ b/libavcodec/opus/dec.c
@@ -694,7 +694,8 @@ static av_cold int opus_decode_init(AVCodecContext *avctx)
return AVERROR(ENOMEM);
/* find out the channel configuration */
- ret = ff_opus_parse_extradata(avctx, &c->p);
+ ret = ff_opus_parse_extradata(avctx, &c->p, avctx->extradata,
+ avctx->extradata_size);
if (ret < 0)
return ret;
if (c->p.gain_i)
diff --git a/libavcodec/opus/parse.c b/libavcodec/opus/parse.c
index 78442031ff..5910ddf9e2 100644
--- a/libavcodec/opus/parse.c
+++ b/libavcodec/opus/parse.c
@@ -284,19 +284,20 @@ static int channel_reorder_unknown(int nb_channels, int channel_idx)
}
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
- OpusParseContext *s)
+ OpusParseContext *s,
+ const uint8_t *header, int header_size)
{
static const uint8_t default_channel_map[2] = { 0, 1 };
int (*channel_reorder)(int, int) = channel_reorder_unknown;
int channels = avctx->ch_layout.nb_channels;
- const uint8_t *extradata, *channel_map;
- int extradata_size;
+ const uint8_t *extradata = header, *channel_map;
+ int extradata_size = header_size;
int version, map_type, streams, stereo_streams, i, j, ret;
AVChannelLayout layout = { 0 };
- if (!avctx->extradata) {
+ if (!header) {
if (channels > 2) {
av_log(avctx, AV_LOG_ERROR,
"Multichannel configuration without extradata.\n");
@@ -304,9 +305,6 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
}
extradata = opus_default_extradata;
extradata_size = sizeof(opus_default_extradata);
- } else {
- extradata = avctx->extradata;
- extradata_size = avctx->extradata_size;
}
if (extradata_size < 19) {
@@ -323,7 +321,7 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
avctx->delay = AV_RL16(extradata + 10);
- channels = avctx->extradata ? extradata[9] : (channels == 1) ? 1 : 2;
+ channels = header ? extradata[9] : (channels == 1) ? 1 : 2;
if (!channels) {
av_log(avctx, AV_LOG_ERROR, "Zero channel count specified in the extradata\n");
return AVERROR_INVALIDDATA;
diff --git a/libavcodec/opus/parse.h b/libavcodec/opus/parse.h
index 467957364f..85cb7a782b 100644
--- a/libavcodec/opus/parse.h
+++ b/libavcodec/opus/parse.h
@@ -72,6 +72,7 @@ typedef struct OpusParseContext {
int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size,
int self_delimited);
-int ff_opus_parse_extradata(AVCodecContext *avctx, OpusParseContext *s);
+int ff_opus_parse_extradata(AVCodecContext *avctx, OpusParseContext *s,
+ const uint8_t *header, int header_size);
#endif /* AVCODEC_OPUS_PARSE_H */
diff --git a/libavcodec/opus/parser.c b/libavcodec/opus/parser.c
index be04cf78bd..975acf2dfe 100644
--- a/libavcodec/opus/parser.c
+++ b/libavcodec/opus/parser.c
@@ -181,7 +181,8 @@ static int opus_parse(AVCodecParserContext *ctx, AVCodecContext *avctx,
avctx->sample_rate = 48000;
if (avctx->extradata && !s->extradata_parsed) {
- if (ff_opus_parse_extradata(avctx, &s->ctx) < 0) {
+ if (ff_opus_parse_extradata(avctx, &s->ctx, avctx->extradata,
+ avctx->extradata_size) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error parsing Ogg extradata.\n");
goto fail;
}