Avoid draining audio processors while reset

If the DefaultAudioSink was reconfigured in a way that was compatible with the
previous configuration just after having been reset, we would try to drain audio
processors despite not having an AudioTrack. This could result in a
NullPointerException if speed adjustment was active.

Fix this behavior by only trying to drain audio processors if we actually have
an AudioTrack.

PiperOrigin-RevId: 235355466
This commit is contained in:
andrewlewis 2019-02-23 20:20:10 +00:00 committed by Oliver Woodman
parent e8077fb3f4
commit caeaa9574e

View File

@ -465,14 +465,17 @@ public final class DefaultAudioSink implements AudioSink {
processingEnabled, processingEnabled,
canApplyPlaybackParameters, canApplyPlaybackParameters,
availableAudioProcessors); availableAudioProcessors);
if (configuration == null || !pendingConfiguration.canReuseAudioTrack(configuration)) { if (isInitialized()) {
// We need a new AudioTrack before we can handle more input. We should first stop() the track if (!pendingConfiguration.canReuseAudioTrack(configuration)) {
// (if we have one) and wait for audio to play out. Tracked by [Internal: b/33161961]. // We need a new AudioTrack before we can handle more input. We should first stop() the
flush(); // track and wait for audio to play out (tracked by [Internal: b/33161961]), but for now we
} else if (flushAudioProcessors) { // discard the audio track immediately.
// We don't need a new AudioTrack but audio processors need to be flushed. flush();
this.pendingConfiguration = pendingConfiguration; } else if (flushAudioProcessors) {
return; // We don't need a new AudioTrack but audio processors need to be drained and flushed.
this.pendingConfiguration = pendingConfiguration;
return;
}
} }
configuration = pendingConfiguration; configuration = pendingConfiguration;
} }