From 835839456ff7792afb6d7a768914696993eecf80 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Thu, 13 Apr 2017 10:53:02 -0700 Subject: [PATCH] Apply playback parameters when uninitialized If AudioTrack.setPlaybackParameters was called before initialization (for example, when an audio renderer is enabled) the parameters would actually be dropped, because configure calls reset, which didn't apply draining playback parameters if the track was not initialized. It would then overwrite the draining parameters with the current parameters. Set the playback parameters directly (without draining) for uninitialized tracks so that the call to setPlaybackParameters in configure is a no-op. Also, reset the stored channel count and sample rate when the audio processor is released so that configure returns true when it is next used, which makes sure that it gets flushed. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=153078759 --- .../google/android/exoplayer2/audio/AudioTrack.java | 11 ++++++++--- .../android/exoplayer2/audio/SonicAudioProcessor.java | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTrack.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTrack.java index d376ffee14..b3700695e5 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTrack.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTrack.java @@ -1002,9 +1002,13 @@ public final class AudioTrack { ? playbackParametersCheckpoints.getLast().playbackParameters : this.playbackParameters; if (!playbackParameters.equals(lastSetPlaybackParameters)) { - // We need to change the playback parameters. Drain the audio processors so we can determine - // the frame position at which the new parameters apply. - drainingPlaybackParameters = playbackParameters; + if (isInitialized()) { + // Drain the audio processors so we can determine the frame position at which the new + // parameters apply. + drainingPlaybackParameters = playbackParameters; + } else { + this.playbackParameters = playbackParameters; + } } return this.playbackParameters; } @@ -1132,6 +1136,7 @@ public final class AudioTrack { framesPerEncodedSample = 0; if (drainingPlaybackParameters != null) { playbackParameters = drainingPlaybackParameters; + drainingPlaybackParameters = null; } else if (!playbackParametersCheckpoints.isEmpty()) { playbackParameters = playbackParametersCheckpoints.getLast().playbackParameters; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java index 2dc14a094d..ba18ebd65a 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java @@ -201,9 +201,11 @@ import java.nio.ShortBuffer; @Override public void release() { sonic = null; + channelCount = Format.NO_VALUE; + sampleRateHz = Format.NO_VALUE; buffer = EMPTY_BUFFER; + shortBuffer = buffer.asShortBuffer(); outputBuffer = EMPTY_BUFFER; - shortBuffer = null; } }