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
78 return buf + bytestream2_tell(&gb);78 return buf + bytestream2_tell(&gb);
79}79}
80 80
81static 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
81/**96/**
82 * Find the end of the current frame in the bitstream.97 * Find the end of the current frame in the bitstream.
83 * @return the position of the first byte of the next frame, or -198 * @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
126 if (!s->ts_framing)141 if (!s->ts_framing)
127 payload_len = buf_size;142 payload_len = buf_size;
128 143
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
139 if (payload_len <= buf_size && (!s->ts_framing || start_found)) {144 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);
141 if (ret < 0) {146 if (ret < 0) {
142 av_log(avctx, AV_LOG_ERROR, "Error parsing Opus packet header.\n");
143 pc->frame_start_found = 0;147 pc->frame_start_found = 0;
144 return AVERROR_INVALIDDATA;148 return AVERROR_INVALIDDATA;
145 }149 }
146
147 ctx->duration = s->pkt.frame_count * s->pkt.frame_duration;
148 }150 }
149 151
150 if (s->ts_framing) {152 if (s->ts_framing) {
@@ -174,9 +176,26 @@ static int opus_parse(AVCodecParserContext *ctx, AVCodecContext *avctx, · 23 unmodified lines
174 176
175 avctx->sample_rate = 48000;177 avctx->sample_rate = 48000;
176 178
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) {
178 next = buf_size;191 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 {
180 next = opus_find_frame_end(ctx, avctx, buf, buf_size, &header_len);199 next = opus_find_frame_end(ctx, avctx, buf, buf_size, &header_len);
181 200
182 if (s->ts_framing && next != AVERROR_INVALIDDATA &&201 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