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 <noreply@anthropic.com>
(cherry picked from commit 47cd1458a7)
(cherry picked from commit 1998833265)
mr26.2.1
Dragos Oancea 3 weeks ago committed by Richard Fuchs
parent 47aa1f571d
commit 018df102c7

@ -81,9 +81,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);

Loading…
Cancel
Save