Revert "avcodec/opus/parse: export the packet and extradata parsing functions"

This reverts commit aa20d7b3e8.

Adding these avpriv functions is absolutely overblown: Muxers
can get the desired duration in a few lines themselves.
In particular, using the parse functions from this file
necessitated parsing the extradata (and entailed exporting
the parsing function), although it was only used to know
whether the frames are self-delimiting, but everything of
interest to a muxer does not depend on this at all.

The commit to be reverted also made several structures
part of the ABI, which should be avoided in general.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2026-02-06 13:52:59 +01:00
parent 12747e6296
commit 0fefecd53f
6 changed files with 40 additions and 141 deletions
Vendored
-3
View File
@@ -2724,7 +2724,6 @@ CONFIG_EXTRA="
msmpeg4dec
msmpeg4enc
mss34dsp
opusparse
pixblockdsp
qpeldsp
qsv
@@ -3184,7 +3183,6 @@ nellymoser_encoder_select="audio_frame_queue sinewin"
notchlc_decoder_select="lzf"
nuv_decoder_select="idctdsp"
opus_decoder_deps="swresample"
opus_decoder_select="opusparse"
opus_encoder_select="audio_frame_queue"
pdv_decoder_select="inflate_wrapper"
png_decoder_select="inflate_wrapper"
@@ -3639,7 +3637,6 @@ h264_parser_select="golomb h264dsp h264parse h264_sei"
hevc_parser_select="hevcparse hevc_sei"
mpegaudio_parser_select="mpegaudioheader"
mpeg4video_parser_select="mpegvideodec"
opus_parser_select="opusparse"
vc1_parser_select="vc1dsp"
vvc_parser_select="cbs_h266"
+2 -3
View File
@@ -1,9 +1,6 @@
clean::
$(RM) $(CLEANSUFFIXES:%=libavcodec/opus/%)
OBJS += \
opus/parse.o \
OBJS-$(CONFIG_OPUS_DECODER) += \
opus/dec.o \
opus/dec_celt.o \
@@ -13,12 +10,14 @@ OBJS-$(CONFIG_OPUS_DECODER) += \
opus/silk.o \
opus/tab.o \
opus/dsp.o \
opus/parse.o \
opus/rc.o \
OBJS-$(CONFIG_OPUS_PARSER) += \
opus/frame_duration_tab.o \
opus/parser.o \
opus/parse.o \
OBJS-$(CONFIG_OPUS_ENCODER) += \
+1 -1
View File
@@ -672,7 +672,7 @@ static av_cold int opus_decode_close(AVCodecContext *avctx)
c->p.nb_streams = 0;
avpriv_opus_parse_uninit_context(&c->p);
av_freep(&c->p.channel_maps);
av_freep(&c->fdsp);
return 0;
+36 -125
View File
@@ -39,7 +39,6 @@
#include "tab.h"
#include "vorbis_data.h"
#if CONFIG_OPUSPARSE
/**
* Read a 1- or 2-byte frame length
*/
@@ -283,47 +282,51 @@ static int channel_reorder_unknown(int nb_channels, int channel_idx)
return channel_idx;
}
static av_cold int opus_parse_extradata(OpusParseContext *s, const uint8_t *buf,
size_t size, int channels, void *logctx)
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
OpusParseContext *s)
{
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;
int version, map_type, streams, stereo_streams, i, j, ret;
AVChannelLayout layout = { 0 };
if (!buf) {
if (!avctx->extradata) {
if (channels > 2) {
av_log(logctx, AV_LOG_ERROR,
av_log(avctx, AV_LOG_ERROR,
"Multichannel configuration without extradata.\n");
return AVERROR(EINVAL);
}
extradata = opus_default_extradata;
extradata_size = sizeof(opus_default_extradata);
} else {
extradata = buf;
extradata_size = size;
extradata = avctx->extradata;
extradata_size = avctx->extradata_size;
}
if (extradata_size < 19) {
av_log(logctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
extradata_size);
return AVERROR_INVALIDDATA;
}
version = extradata[8];
if (version > 15) {
avpriv_request_sample(logctx, "Extradata version %d", version);
avpriv_request_sample(avctx, "Extradata version %d", version);
return AVERROR_PATCHWELCOME;
}
s->delay = AV_RL16(extradata + 10);
avctx->delay = AV_RL16(extradata + 10);
if (avctx->internal)
avctx->internal->skip_samples = avctx->delay;
channels = buf ? extradata[9] : (channels == 1) ? 1 : 2;
channels = avctx->extradata ? extradata[9] : (channels == 1) ? 1 : 2;
if (!channels) {
av_log(logctx, AV_LOG_ERROR, "Zero channel count specified in the extradata\n");
av_log(avctx, AV_LOG_ERROR, "Zero channel count specified in the extradata\n");
return AVERROR_INVALIDDATA;
}
@@ -332,19 +335,19 @@ static av_cold int opus_parse_extradata(OpusParseContext *s, const uint8_t *buf,
map_type = extradata[18];
if (!map_type) {
if (channels > 2) {
av_log(logctx, AV_LOG_ERROR,
av_log(avctx, AV_LOG_ERROR,
"Channel mapping 0 is only specified for up to 2 channels\n");
ret = AVERROR_INVALIDDATA;
goto fail;
}
s->layout = (channels == 1) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
layout = (channels == 1) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
streams = 1;
stereo_streams = channels - 1;
channel_map = default_channel_map;
} else if (map_type == 1 || map_type == 2 || map_type == 255) {
if (extradata_size < 21 + channels) {
av_log(logctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
extradata_size);
ret = AVERROR_INVALIDDATA;
goto fail;
@@ -354,7 +357,7 @@ static av_cold int opus_parse_extradata(OpusParseContext *s, const uint8_t *buf,
stereo_streams = extradata[20];
if (!streams || stereo_streams > streams ||
streams + stereo_streams > 255) {
av_log(logctx, AV_LOG_ERROR,
av_log(avctx, AV_LOG_ERROR,
"Invalid stream/stereo stream count: %d/%d\n", streams, stereo_streams);
ret = AVERROR_INVALIDDATA;
goto fail;
@@ -362,18 +365,18 @@ static av_cold int opus_parse_extradata(OpusParseContext *s, const uint8_t *buf,
if (map_type == 1) {
if (channels > 8) {
av_log(logctx, AV_LOG_ERROR,
av_log(avctx, AV_LOG_ERROR,
"Channel mapping 1 is only specified for up to 8 channels\n");
ret = AVERROR_INVALIDDATA;
goto fail;
}
av_channel_layout_copy(&s->layout, &ff_vorbis_ch_layouts[channels - 1]);
av_channel_layout_copy(&layout, &ff_vorbis_ch_layouts[channels - 1]);
channel_reorder = channel_reorder_vorbis;
} else if (map_type == 2) {
int ambisonic_order = ff_sqrt(channels) - 1;
if (channels != ((ambisonic_order + 1) * (ambisonic_order + 1)) &&
channels != ((ambisonic_order + 1) * (ambisonic_order + 1) + 2)) {
av_log(logctx, AV_LOG_ERROR,
av_log(avctx, AV_LOG_ERROR,
"Channel mapping 2 is only specified for channel counts"
" which can be written as (n + 1)^2 or (n + 1)^2 + 2"
" for nonnegative integer n\n");
@@ -381,23 +384,23 @@ static av_cold int opus_parse_extradata(OpusParseContext *s, const uint8_t *buf,
goto fail;
}
if (channels > 227) {
av_log(logctx, AV_LOG_ERROR, "Too many channels\n");
av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
ret = AVERROR_INVALIDDATA;
goto fail;
}
s->layout.order = AV_CHANNEL_ORDER_AMBISONIC;
s->layout.nb_channels = channels;
layout.order = AV_CHANNEL_ORDER_AMBISONIC;
layout.nb_channels = channels;
if (channels != ((ambisonic_order + 1) * (ambisonic_order + 1)))
s->layout.u.mask = AV_CH_LAYOUT_STEREO;
layout.u.mask = AV_CH_LAYOUT_STEREO;
} else {
s->layout.order = AV_CHANNEL_ORDER_UNSPEC;
s->layout.nb_channels = channels;
layout.order = AV_CHANNEL_ORDER_UNSPEC;
layout.nb_channels = channels;
}
channel_map = extradata + 21;
} else {
avpriv_request_sample(logctx, "Mapping type %d", map_type);
avpriv_request_sample(avctx, "Mapping type %d", map_type);
return AVERROR_PATCHWELCOME;
}
@@ -415,7 +418,7 @@ static av_cold int opus_parse_extradata(OpusParseContext *s, const uint8_t *buf,
map->silence = 1;
continue;
} else if (idx >= streams + stereo_streams) {
av_log(logctx, AV_LOG_ERROR,
av_log(avctx, AV_LOG_ERROR,
"Invalid channel map for output channel %d: %d\n", i, idx);
av_freep(&s->channel_maps);
ret = AVERROR_INVALIDDATA;
@@ -440,107 +443,15 @@ static av_cold int opus_parse_extradata(OpusParseContext *s, const uint8_t *buf,
}
}
ret = av_channel_layout_copy(&avctx->ch_layout, &layout);
if (ret < 0)
goto fail;
s->nb_streams = streams;
s->nb_stereo_streams = stereo_streams;
return 0;
fail:
av_channel_layout_uninit(&s->layout);
av_freep(&s->channel_maps);
av_channel_layout_uninit(&layout);
return ret;
}
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
OpusParseContext *s)
{
int ret = opus_parse_extradata(s, avctx->extradata, avctx->extradata_size,
avctx->ch_layout.nb_channels, avctx);
if (ret < 0)
return ret;
avctx->delay = s->delay;
if (avctx->internal)
avctx->internal->skip_samples = avctx->delay;
ret = av_channel_layout_copy(&avctx->ch_layout, &s->layout);
if (ret < 0)
goto fail;
return 0;
fail:
av_channel_layout_uninit(&s->layout);
av_freep(&s->channel_maps);
return ret;
}
#endif
int avpriv_opus_parse_packet(OpusPacket **ppkt, const uint8_t *buf, size_t size,
int self_delimiting, void *logctx)
{
#if CONFIG_OPUSPARSE
int ret = 0;
int allocated = 0;
if (!ppkt || !buf)
return AVERROR_INVALIDDATA;
if (!*ppkt) {
allocated = 1;
*ppkt = av_mallocz(sizeof(OpusPacket));
} else
memset(*ppkt, 0, sizeof(OpusPacket));
if (!*ppkt)
return AVERROR(ENOMEM);
ret = ff_opus_parse_packet(*ppkt, buf, size, self_delimiting);
if (ret < 0) {
if (allocated)
av_freep(ppkt);
return ret;
}
return 0;
#else
return AVERROR(ENOSYS);
#endif
}
av_cold int avpriv_opus_parse_extradata(OpusParseContext **ps, const uint8_t *buf,
size_t size, int channels, void *logctx)
{
#if CONFIG_OPUSPARSE
int ret = 0;
int allocated = 0;
if (!ps)
return AVERROR_INVALIDDATA;
if (!*ps) {
allocated = 1;
*ps = av_mallocz(sizeof(OpusParseContext));
} else {
avpriv_opus_parse_uninit_context(*ps);
memset(*ps, 0, sizeof(OpusParseContext));
}
if (!*ps)
return AVERROR(ENOMEM);
ret = opus_parse_extradata(*ps, buf, size, channels, logctx);
if (ret < 0) {
if (allocated)
av_freep(ps);
return ret;
}
return 0;
#else
return AVERROR(ENOSYS);
#endif
}
av_cold void avpriv_opus_parse_uninit_context(OpusParseContext *s)
{
av_channel_layout_uninit(&s->layout);
av_freep(&s->channel_maps);
}
-8
View File
@@ -64,8 +64,6 @@ typedef struct OpusParseContext {
int nb_streams;
int nb_stereo_streams;
AVChannelLayout layout;
int16_t delay;
int16_t gain_i;
ChannelMap *channel_maps;
@@ -73,13 +71,7 @@ typedef struct OpusParseContext {
int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size,
int self_delimited);
int avpriv_opus_parse_packet(OpusPacket **ppkt, const uint8_t *buf, size_t size,
int self_delimited, void *logctx);
int ff_opus_parse_extradata(AVCodecContext *avctx, OpusParseContext *s);
int avpriv_opus_parse_extradata(OpusParseContext **ps, const uint8_t *buf,
size_t size, int channels, void *logctx);
void avpriv_opus_parse_uninit_context(OpusParseContext *s);
#endif /* AVCODEC_OPUS_PARSE_H */
+1 -1
View File
@@ -182,7 +182,7 @@ static int opus_parse(AVCodecParserContext *ctx, AVCodecContext *avctx,
av_log(avctx, AV_LOG_ERROR, "Error parsing Ogg extradata.\n");
goto fail;
}
avpriv_opus_parse_uninit_context(&s->ctx);
av_freep(&s->ctx.channel_maps);
s->extradata_parsed = 1;
}