Commit 83583945 by andrewlewis Committed by Oliver Woodman

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
parent 579d57b4
...@@ -1002,9 +1002,13 @@ public final class AudioTrack { ...@@ -1002,9 +1002,13 @@ public final class AudioTrack {
? playbackParametersCheckpoints.getLast().playbackParameters ? playbackParametersCheckpoints.getLast().playbackParameters
: this.playbackParameters; : this.playbackParameters;
if (!playbackParameters.equals(lastSetPlaybackParameters)) { if (!playbackParameters.equals(lastSetPlaybackParameters)) {
// We need to change the playback parameters. Drain the audio processors so we can determine if (isInitialized()) {
// the frame position at which the new parameters apply. // Drain the audio processors so we can determine the frame position at which the new
drainingPlaybackParameters = playbackParameters; // parameters apply.
drainingPlaybackParameters = playbackParameters;
} else {
this.playbackParameters = playbackParameters;
}
} }
return this.playbackParameters; return this.playbackParameters;
} }
...@@ -1132,6 +1136,7 @@ public final class AudioTrack { ...@@ -1132,6 +1136,7 @@ public final class AudioTrack {
framesPerEncodedSample = 0; framesPerEncodedSample = 0;
if (drainingPlaybackParameters != null) { if (drainingPlaybackParameters != null) {
playbackParameters = drainingPlaybackParameters; playbackParameters = drainingPlaybackParameters;
drainingPlaybackParameters = null;
} else if (!playbackParametersCheckpoints.isEmpty()) { } else if (!playbackParametersCheckpoints.isEmpty()) {
playbackParameters = playbackParametersCheckpoints.getLast().playbackParameters; playbackParameters = playbackParametersCheckpoints.getLast().playbackParameters;
} }
......
...@@ -201,9 +201,11 @@ import java.nio.ShortBuffer; ...@@ -201,9 +201,11 @@ import java.nio.ShortBuffer;
@Override @Override
public void release() { public void release() {
sonic = null; sonic = null;
channelCount = Format.NO_VALUE;
sampleRateHz = Format.NO_VALUE;
buffer = EMPTY_BUFFER; buffer = EMPTY_BUFFER;
shortBuffer = buffer.asShortBuffer();
outputBuffer = EMPTY_BUFFER; outputBuffer = EMPTY_BUFFER;
shortBuffer = null;
} }
} }
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