From 274f54b290bd4dd03e4f09d0b049d02007ad96f3 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Tue, 27 Oct 2026 20:22:38 +0200 Subject: [PATCH] MT#55283 opus: size decoder output buffer for the longest Opus packet The decoder output frame was hard-coded to 960 samples, which is 20 ms at 48 kHz. libopus refuses to decode a packet that does not fit the given frame size, so every 40 ms and 60 ms packet (both ptimes accepted by opus_init) failed with "buffer too small" and was dropped. Size the buffer for 120 ms, the longest duration an Opus packet can carry, at the decoder's clock rate. Closes #2224 Change-Id: Ic2fcb32977ad0e262d42b74948103b0f68511d95 Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 47cd1458a7b8c05a3d798176a6cfe3fa8da91a35) (cherry picked from commit 8591ed023a6ccd97669b45570a8a23ec2fed1f08) --- lib/codeclib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/codeclib.c b/lib/codeclib.c index bbd7775db..a3a65cb6b 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -2322,9 +2322,10 @@ static void libopus_decoder_close(decoder_t *dec) { opus_decoder_destroy(dec->opus); } static int libopus_decoder_input(decoder_t *dec, const str *data, GQueue *out) { - // get frame with buffer large enough for the max + // get frame with buffer large enough for the max: an Opus packet can + // carry up to 120 ms of audio, at whatever rate the decoder runs at AVFrame *frame = av_frame_alloc(); - frame->nb_samples = 960; + frame->nb_samples = dec->in_format.clockrate * 120 / 1000; frame->format = AV_SAMPLE_FMT_S16; frame->sample_rate = dec->in_format.clockrate; DEF_CH_LAYOUT(&frame->CH_LAYOUT, dec->in_format.channels);