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
This commit is contained in:
andrewlewis 2017-04-13 10:53:02 -07:00 committed by Oliver Woodman
parent 579d57b445
commit 835839456f
2 changed files with 11 additions and 4 deletions

View file

@ -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;
}

View file

@ -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;
}
}