History

avcodec/opus/parser: set duration when complete frames are fed

Fixes a regression since 873a34c129869e551cb7d3d2445e28c0ba079948.

James Almer committed 1 year ago

Commit 37155d61 parent 4bf784c1 file · +35 −16Browse files

Unified · Split

libavcodec/opus/parser.c+35−16
@@ -78,6 +78,21 @@ static const uint8_t *parse_opus_ts_header(const uint8_t *start, int *payload_le · 77 unmodified lines
7878 return buf + bytestream2_tell(&gb);
7979 }
8080
81+static int set_frame_duration(AVCodecParserContext *ctx, AVCodecContext *avctx,
82+ const uint8_t *buf, int buf_size)
83+{
84+ OpusParserContext *s = ctx->priv_data;
85+
86+ if (ff_opus_parse_packet(&s->pkt, buf, buf_size, s->ctx.nb_streams > 1) < 0) {
87+ av_log(avctx, AV_LOG_ERROR, "Error parsing Opus packet header.\n");
88+ return AVERROR_INVALIDDATA;
89+ }
90+
91+ ctx->duration = s->pkt.frame_count * s->pkt.frame_duration;
92+
93+ return 0;
94+}
95+
8196 /**
8297 * Find the end of the current frame in the bitstream.
8398 * @return the position of the first byte of the next frame, or -1
@@ -126,25 +141,12 @@ static int opus_find_frame_end(AVCodecParserContext *ctx, AVCodecContext *avctx, · 42 unmodified lines
126141 if (!s->ts_framing)
127142 payload_len = buf_size;
128143
129− if (avctx->extradata && !s->extradata_parsed) {
130− ret = ff_opus_parse_extradata(avctx, &s->ctx);
131− if (ret < 0) {
132− av_log(avctx, AV_LOG_ERROR, "Error parsing Ogg extradata.\n");
133− return AVERROR_INVALIDDATA;
134− }
135− av_freep(&s->ctx.channel_maps);
136− s->extradata_parsed = 1;
137− }
138−
139144 if (payload_len <= buf_size && (!s->ts_framing || start_found)) {
140− ret = ff_opus_parse_packet(&s->pkt, payload, payload_len, s->ctx.nb_streams > 1);
145+ ret = set_frame_duration(ctx, avctx, payload, payload_len);
141146 if (ret < 0) {
142− av_log(avctx, AV_LOG_ERROR, "Error parsing Opus packet header.\n");
143147 pc->frame_start_found = 0;
144148 return AVERROR_INVALIDDATA;
145149 }
146−
147− ctx->duration = s->pkt.frame_count * s->pkt.frame_duration;
148150 }
149151
150152 if (s->ts_framing) {
@@ -174,9 +176,26 @@ static int opus_parse(AVCodecParserContext *ctx, AVCodecContext *avctx, · 23 unmodified lines
174176
175177 avctx->sample_rate = 48000;
176178
177− if (ctx->flags & PARSER_FLAG_COMPLETE_FRAMES)
179+ if (avctx->extradata && !s->extradata_parsed) {
180+ if (ff_opus_parse_extradata(avctx, &s->ctx) < 0) {
181+ av_log(avctx, AV_LOG_ERROR, "Error parsing Ogg extradata.\n");
182+ *poutbuf = NULL;
183+ *poutbuf_size = 0;
184+ return buf_size;
185+ }
186+ av_freep(&s->ctx.channel_maps);
187+ s->extradata_parsed = 1;
188+ }
189+
190+ if (ctx->flags & PARSER_FLAG_COMPLETE_FRAMES) {
178191 next = buf_size;
179− else {
192+
193+ if (set_frame_duration(ctx, avctx, buf, buf_size) < 0) {
194+ *poutbuf = NULL;
195+ *poutbuf_size = 0;
196+ return buf_size;
197+ }
198+ } else {
180199 next = opus_find_frame_end(ctx, avctx, buf, buf_size, &header_len);
181200
182201 if (s->ts_framing && next != AVERROR_INVALIDDATA &&

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t