[FFmpeg-devel] [PATCH] avcodec/opus/parser: set duration when complete frames are fed
Lynne
dev at lynne.ee
Tue Jan 7 01:45:59 EET 2025
On 04/01/2025 00:07, James Almer wrote:
> Fixes a regression since 873a34c129869e551cb7d3d2445e28c0ba079948.
>
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
> libavcodec/opus/parser.c | 38 +++++++++++++++++++++++++++++---------
> 1 file changed, 29 insertions(+), 9 deletions(-)
>
> diff --git a/libavcodec/opus/parser.c b/libavcodec/opus/parser.c
> index e16b0f72a2..be011485f6 100644
> --- a/libavcodec/opus/parser.c
> +++ b/libavcodec/opus/parser.c
> @@ -78,6 +78,25 @@ static const uint8_t *parse_opus_ts_header(const uint8_t *start, int *payload_le
> return buf + bytestream2_tell(&gb);
> }
>
> +static int set_duration(AVCodecParserContext *ctx, AVCodecContext *avctx,
> + const uint8_t *buf, int buf_size)
> +{
> + OpusParserContext *s = ctx->priv_data;
> + ParseContext *pc = &s->pc;
> + int ret;
> +
> + ret = ff_opus_parse_packet(&s->pkt, buf, buf_size, s->ctx.nb_streams > 1);
> + 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;
> +
> + 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
> @@ -137,14 +156,9 @@ static int opus_find_frame_end(AVCodecParserContext *ctx, AVCodecContext *avctx,
> }
>
> 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);
> - if (ret < 0) {
> - av_log(avctx, AV_LOG_ERROR, "Error parsing Opus packet header.\n");
> - pc->frame_start_found = 0;
> + ret = set_duration(ctx, avctx, payload, payload_len);
> + if (ret < 0)
> return AVERROR_INVALIDDATA;
> - }
> -
> - ctx->duration = s->pkt.frame_count * s->pkt.frame_duration;
> }
>
> if (s->ts_framing) {
> @@ -174,9 +188,15 @@ static int opus_parse(AVCodecParserContext *ctx, AVCodecContext *avctx,
>
> avctx->sample_rate = 48000;
>
> - if (ctx->flags & PARSER_FLAG_COMPLETE_FRAMES)
> + if (ctx->flags & PARSER_FLAG_COMPLETE_FRAMES) {
> next = buf_size;
> - else {
> +
> + if (set_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 &&
LGTM
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xA2FEA5F03F034464.asc
Type: application/pgp-keys
Size: 624 bytes
Desc: OpenPGP public key
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250107/05f2c3fa/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250107/05f2c3fa/attachment.sig>
More information about the ffmpeg-devel
mailing list