Commit 40870b87 by olly Committed by Toni

Prevent audio pops on audio format change. We'd like to switch opus audio…

Prevent audio pops on audio format change. We'd like to switch opus audio bitrates in the middle of playback based on network conditions.

Changing between different bitrates on the same codec should not require decoder initialization.

PiperOrigin-RevId: 267208043
parent 0e7740f5
...@@ -361,6 +361,17 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements ...@@ -361,6 +361,17 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements
null, null, 0, null); null, null, 0, null);
} }
/**
* Returns whether the existing decoder can be kept for a new format.
*
* @param oldFormat The previous format.
* @param newFormat The new format.
* @return True if the existing decoder can be kept.
*/
protected boolean canKeepCodec(Format oldFormat, Format newFormat) {
return false;
}
private boolean drainOutputBuffer() throws ExoPlaybackException, AudioDecoderException, private boolean drainOutputBuffer() throws ExoPlaybackException, AudioDecoderException,
AudioSink.ConfigurationException, AudioSink.InitializationException, AudioSink.ConfigurationException, AudioSink.InitializationException,
AudioSink.WriteException { AudioSink.WriteException {
...@@ -689,14 +700,16 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements ...@@ -689,14 +700,16 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements
} }
} }
if (decoderReceivedBuffers) { if (!canKeepCodec(oldFormat, inputFormat)) {
// Signal end of stream and wait for any final output buffers before re-initialization. if (decoderReceivedBuffers) {
decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM; // Signal end of stream and wait for any final output buffers before re-initialization.
} else { decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
// There aren't any final output buffers, so release the decoder immediately. } else {
releaseDecoder(); // There aren't any final output buffers, so release the decoder immediately.
maybeInitDecoder(); releaseDecoder();
audioTrackNeedsConfigure = true; maybeInitDecoder();
audioTrackNeedsConfigure = true;
}
} }
encoderDelay = inputFormat.encoderDelay; encoderDelay = inputFormat.encoderDelay;
......
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 sign in to comment