ffmpeg | branch: master | James Almer <jamr...@gmail.com> | Fri Jan 3 11:58:44 2025 -0300| [37155d68ec6270eab37e1900f2a5ee3e113c4851] | committer: James Almer
avcodec/opus/parser: set duration when complete frames are fed Fixes a regression since 873a34c129869e551cb7d3d2445e28c0ba079948. Signed-off-by: James Almer <jamr...@gmail.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=37155d68ec6270eab37e1900f2a5ee3e113c4851 --- libavcodec/opus/parser.c | 51 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/libavcodec/opus/parser.c b/libavcodec/opus/parser.c index e16b0f72a2..3ebb65d266 100644 --- a/libavcodec/opus/parser.c +++ b/libavcodec/opus/parser.c @@ -78,6 +78,21 @@ static const uint8_t *parse_opus_ts_header(const uint8_t *start, int *payload_le return buf + bytestream2_tell(&gb); } +static int set_frame_duration(AVCodecParserContext *ctx, AVCodecContext *avctx, + const uint8_t *buf, int buf_size) +{ + OpusParserContext *s = ctx->priv_data; + + if (ff_opus_parse_packet(&s->pkt, buf, buf_size, s->ctx.nb_streams > 1) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error parsing Opus packet header.\n"); + return AVERROR_INVALIDDATA; + } + + ctx->duration = s->pkt.frame_count * s->pkt.frame_duration; + + return 0; +} + /** * Find the end of the current frame in the bitstream. * @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, if (!s->ts_framing) payload_len = buf_size; - if (avctx->extradata && !s->extradata_parsed) { - ret = ff_opus_parse_extradata(avctx, &s->ctx); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Error parsing Ogg extradata.\n"); - return AVERROR_INVALIDDATA; - } - av_freep(&s->ctx.channel_maps); - s->extradata_parsed = 1; - } - if (payload_len <= buf_size && (!s->ts_framing || start_found)) { - ret = ff_opus_parse_packet(&s->pkt, payload, payload_len, s->ctx.nb_streams > 1); + ret = set_frame_duration(ctx, avctx, payload, payload_len); if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Error parsing Opus packet header.\n"); pc->frame_start_found = 0; return AVERROR_INVALIDDATA; } - - ctx->duration = s->pkt.frame_count * s->pkt.frame_duration; } if (s->ts_framing) { @@ -174,9 +176,26 @@ static int opus_parse(AVCodecParserContext *ctx, AVCodecContext *avctx, avctx->sample_rate = 48000; - if (ctx->flags & PARSER_FLAG_COMPLETE_FRAMES) + if (avctx->extradata && !s->extradata_parsed) { + if (ff_opus_parse_extradata(avctx, &s->ctx) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error parsing Ogg extradata.\n"); + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + av_freep(&s->ctx.channel_maps); + s->extradata_parsed = 1; + } + + if (ctx->flags & PARSER_FLAG_COMPLETE_FRAMES) { next = buf_size; - else { + + if (set_frame_duration(ctx, avctx, buf, buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } else { next = opus_find_frame_end(ctx, avctx, buf, buf_size, &header_len); if (s->ts_framing && next != AVERROR_INVALIDDATA && _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".