blob: 7c0ba068a534abfc1f5170dc5c3999432c4480af [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 205552370e058d99452fd34983942e10f2db6dff Mon Sep 17 00:00:00 2001
2From: Mark Harris <mark.hsj@gmail.com>
3Date: Mon, 28 Dec 2020 12:58:17 -0800
4Subject: [PATCH] Fix ope_encoder_drain() assertion failure
5
6If the stream is drained without writing any audio and the frame size is
7smaller than the encoder latency, the assertion (enc->streams == NULL)
8would fail because pad_samples was computed using an incorrect value of
9enc->global_granule_offset before it was set in init_stream(), causing
10the padding to be insufficient to drain the stream.
11---
12 src/opusenc.c | 2 +-
13 1 file changed, 1 insertion(+), 1 deletion(-)
14
15--- a/src/opusenc.c
16+++ b/src/opusenc.c
17@@ -808,9 +808,9 @@ int ope_encoder_drain(OggOpusEnc *enc) {
18 if (enc->unrecoverable) return enc->unrecoverable;
19 /* Check if it's already been drained. */
20 if (enc->streams == NULL) return OPE_TOO_LATE;
21+ if (!enc->streams->stream_is_init) init_stream(enc);
22 if (enc->re) resampler_drain = speex_resampler_get_output_latency(enc->re);
23 pad_samples = MAX(LPC_PADDING, enc->global_granule_offset + enc->frame_size + resampler_drain + 1);
24- if (!enc->streams->stream_is_init) init_stream(enc);
25 shift_buffer(enc);
26 assert(enc->buffer_end + pad_samples <= BUFFER_SAMPLES);
27 memset(&enc->buffer[enc->channels*enc->buffer_end], 0, pad_samples*enc->channels*sizeof(enc->buffer[0]));