Fix ope_encoder_drain() assertion failure

If the stream is drained without writing any audio and the frame size is
smaller than the encoder latency, the assertion (enc->streams == NULL)
would fail because pad_samples was computed using an incorrect value of
enc->global_granule_offset before it was set in init_stream(), causing
the padding to be insufficient to drain the stream.
parent feb233a8
......@@ -808,9 +808,9 @@ int ope_encoder_drain(OggOpusEnc *enc) {
if (enc->unrecoverable) return enc->unrecoverable;
/* Check if it's already been drained. */
if (enc->streams == NULL) return OPE_TOO_LATE;
if (!enc->streams->stream_is_init) init_stream(enc);
if (enc->re) resampler_drain = speex_resampler_get_output_latency(enc->re);
pad_samples = MAX(LPC_PADDING, enc->global_granule_offset + enc->frame_size + resampler_drain + 1);
if (!enc->streams->stream_is_init) init_stream(enc);
shift_buffer(enc);
assert(enc->buffer_end + pad_samples <= BUFFER_SAMPLES);
memset(&enc->buffer[enc->channels*enc->buffer_end], 0, pad_samples*enc->channels*sizeof(enc->buffer[0]));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment