split and deprecate PlaybackParameters in AudioSink
This change deprecates PlaybackParameter in AudioSink and splits it into playbackSpeed and skipSilenceEnabled. These properties are set separately in a future CL. The playback speed will be set through the MediaClock, while skipSilenceEnabled will be set by sending a message to the audio renderer. PiperOrigin-RevId: 296457043
This commit is contained in:
parent
42d4afe7b6
commit
bc8fd2ca12
@ -263,18 +263,28 @@ public interface AudioSink {
|
|||||||
boolean hasPendingData();
|
boolean hasPendingData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to set the playback parameters. The audio sink may override these parameters if they
|
* @deprecated Use {@link #setPlaybackSpeed(float)} and {@link #setSkipSilenceEnabled(boolean)}
|
||||||
* are not supported.
|
* instead.
|
||||||
*
|
|
||||||
* @param playbackParameters The new playback parameters to attempt to set.
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void setPlaybackParameters(PlaybackParameters playbackParameters);
|
void setPlaybackParameters(PlaybackParameters playbackParameters);
|
||||||
|
|
||||||
/**
|
/** @deprecated Use {@link #getPlaybackSpeed()} and {@link #getSkipSilenceEnabled()} instead. */
|
||||||
* Gets the active {@link PlaybackParameters}.
|
@Deprecated
|
||||||
*/
|
|
||||||
PlaybackParameters getPlaybackParameters();
|
PlaybackParameters getPlaybackParameters();
|
||||||
|
|
||||||
|
/** Sets the playback speed. */
|
||||||
|
void setPlaybackSpeed(float playbackSpeed);
|
||||||
|
|
||||||
|
/** Gets the playback speed. */
|
||||||
|
float getPlaybackSpeed();
|
||||||
|
|
||||||
|
/** Sets whether silences should be skipped in the audio stream. */
|
||||||
|
void setSkipSilenceEnabled(boolean skipSilenceEnabled);
|
||||||
|
|
||||||
|
/** Gets whether silences are skipped in the audio stream. */
|
||||||
|
boolean getSkipSilenceEnabled();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets attributes for audio playback. If the attributes have changed and if the sink is not
|
* Sets attributes for audio playback. If the attributes have changed and if the sink is not
|
||||||
* configured for use with tunneling, then it is reset and the audio session id is cleared.
|
* configured for use with tunneling, then it is reset and the audio session id is cleared.
|
||||||
|
@ -81,15 +81,31 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
AudioProcessor[] getAudioProcessors();
|
AudioProcessor[] getAudioProcessors();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures audio processors to apply the specified playback parameters immediately, returning
|
* @deprecated Use {@link #applyPlaybackSpeed(float)} and {@link
|
||||||
* the new parameters, which may differ from those passed in. Only called when processors have
|
* #applySkipSilenceEnabled(boolean)} instead.
|
||||||
* no input pending.
|
|
||||||
*
|
|
||||||
* @param playbackParameters The playback parameters to try to apply.
|
|
||||||
* @return The playback parameters that were actually applied.
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
PlaybackParameters applyPlaybackParameters(PlaybackParameters playbackParameters);
|
PlaybackParameters applyPlaybackParameters(PlaybackParameters playbackParameters);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures audio processors to apply the specified playback speed immediately, returning the
|
||||||
|
* new playback speed, which may differ from the speed passed in. Only called when processors
|
||||||
|
* have no input pending.
|
||||||
|
*
|
||||||
|
* @param playbackSpeed The playback speed to try to apply.
|
||||||
|
* @return The playback speed that was actually applied.
|
||||||
|
*/
|
||||||
|
float applyPlaybackSpeed(float playbackSpeed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures audio processors to apply whether to skip silences immediately, returning the new
|
||||||
|
* value. Only called when processors have no input pending.
|
||||||
|
*
|
||||||
|
* @param skipSilenceEnabled Whether silences should be skipped in the audio stream.
|
||||||
|
* @return The new value.
|
||||||
|
*/
|
||||||
|
boolean applySkipSilenceEnabled(boolean skipSilenceEnabled);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scales the specified playout duration to take into account speedup due to audio processing,
|
* Scales the specified playout duration to take into account speedup due to audio processing,
|
||||||
* returning an input media duration, in arbitrary units.
|
* returning an input media duration, in arbitrary units.
|
||||||
@ -138,12 +154,27 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
return audioProcessors;
|
return audioProcessors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #applyPlaybackSpeed(float)} and {@link
|
||||||
|
* #applySkipSilenceEnabled(boolean)} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public PlaybackParameters applyPlaybackParameters(PlaybackParameters playbackParameters) {
|
public PlaybackParameters applyPlaybackParameters(PlaybackParameters playbackParameters) {
|
||||||
silenceSkippingAudioProcessor.setEnabled(playbackParameters.skipSilence);
|
|
||||||
return new PlaybackParameters(
|
return new PlaybackParameters(
|
||||||
sonicAudioProcessor.setSpeed(playbackParameters.speed),
|
applyPlaybackSpeed(playbackParameters.speed),
|
||||||
playbackParameters.skipSilence);
|
applySkipSilenceEnabled(playbackParameters.skipSilence));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float applyPlaybackSpeed(float playbackSpeed) {
|
||||||
|
return sonicAudioProcessor.setSpeed(playbackSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean applySkipSilenceEnabled(boolean skipSilenceEnabled) {
|
||||||
|
silenceSkippingAudioProcessor.setEnabled(skipSilenceEnabled);
|
||||||
|
return skipSilenceEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -199,6 +230,10 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
*/
|
*/
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
private static final int WRITE_NON_BLOCKING = AudioTrack.WRITE_NON_BLOCKING;
|
private static final int WRITE_NON_BLOCKING = AudioTrack.WRITE_NON_BLOCKING;
|
||||||
|
/** The default playback speed. */
|
||||||
|
private static final float DEFAULT_PLAYBACK_SPEED = 1.0f;
|
||||||
|
/** The default skip silence flag. */
|
||||||
|
private static final boolean DEFAULT_SKIP_SILENCE = false;
|
||||||
|
|
||||||
private static final String TAG = "AudioTrack";
|
private static final String TAG = "AudioTrack";
|
||||||
|
|
||||||
@ -240,7 +275,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
private AudioTrack audioTrack;
|
private AudioTrack audioTrack;
|
||||||
|
|
||||||
private AudioAttributes audioAttributes;
|
private AudioAttributes audioAttributes;
|
||||||
@Nullable private PlaybackParameters afterDrainPlaybackParameters;
|
@Nullable private MediaPositionParameters afterDrainParameters;
|
||||||
private MediaPositionParameters mediaPositionParameters;
|
private MediaPositionParameters mediaPositionParameters;
|
||||||
|
|
||||||
@Nullable private ByteBuffer avSyncHeader;
|
@Nullable private ByteBuffer avSyncHeader;
|
||||||
@ -346,7 +381,10 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
auxEffectInfo = new AuxEffectInfo(AuxEffectInfo.NO_AUX_EFFECT_ID, 0f);
|
auxEffectInfo = new AuxEffectInfo(AuxEffectInfo.NO_AUX_EFFECT_ID, 0f);
|
||||||
mediaPositionParameters =
|
mediaPositionParameters =
|
||||||
new MediaPositionParameters(
|
new MediaPositionParameters(
|
||||||
PlaybackParameters.DEFAULT, /* mediaTimeUs= */ 0, /* audioTrackPositionUs= */ 0);
|
DEFAULT_PLAYBACK_SPEED,
|
||||||
|
DEFAULT_SKIP_SILENCE,
|
||||||
|
/* mediaTimeUs= */ 0,
|
||||||
|
/* audioTrackPositionUs= */ 0);
|
||||||
drainingAudioProcessorIndex = C.INDEX_UNSET;
|
drainingAudioProcessorIndex = C.INDEX_UNSET;
|
||||||
activeAudioProcessors = new AudioProcessor[0];
|
activeAudioProcessors = new AudioProcessor[0];
|
||||||
outputBuffers = new ByteBuffer[0];
|
outputBuffers = new ByteBuffer[0];
|
||||||
@ -528,7 +566,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
startMediaTimeUs = Math.max(0, presentationTimeUs);
|
startMediaTimeUs = Math.max(0, presentationTimeUs);
|
||||||
startMediaTimeUsNeedsSync = false;
|
startMediaTimeUsNeedsSync = false;
|
||||||
|
|
||||||
applyPlaybackParameters(getPlaybackParameters(), presentationTimeUs);
|
applyPlaybackSpeedAndSkipSilence(presentationTimeUs);
|
||||||
|
|
||||||
audioTrackPositionTracker.setAudioTrack(
|
audioTrackPositionTracker.setAudioTrack(
|
||||||
audioTrack,
|
audioTrack,
|
||||||
@ -582,7 +620,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
pendingConfiguration = null;
|
pendingConfiguration = null;
|
||||||
}
|
}
|
||||||
// Re-apply playback parameters.
|
// Re-apply playback parameters.
|
||||||
applyPlaybackParameters(getPlaybackParameters(), presentationTimeUs);
|
applyPlaybackSpeedAndSkipSilence(presentationTimeUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
@ -615,14 +653,13 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (afterDrainPlaybackParameters != null) {
|
if (afterDrainParameters != null) {
|
||||||
if (!drainToEndOfStream()) {
|
if (!drainToEndOfStream()) {
|
||||||
// Don't process any more input until draining completes.
|
// Don't process any more input until draining completes.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlaybackParameters newPlaybackParameters = afterDrainPlaybackParameters;
|
applyPlaybackSpeedAndSkipSilence(presentationTimeUs);
|
||||||
afterDrainPlaybackParameters = null;
|
afterDrainParameters = null;
|
||||||
applyPlaybackParameters(newPlaybackParameters, presentationTimeUs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanity check that presentationTimeUs is consistent with the expected value.
|
// Sanity check that presentationTimeUs is consistent with the expected value.
|
||||||
@ -652,7 +689,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
startMediaTimeUs += adjustmentUs;
|
startMediaTimeUs += adjustmentUs;
|
||||||
startMediaTimeUsNeedsSync = false;
|
startMediaTimeUsNeedsSync = false;
|
||||||
// Re-apply playback parameters because the startMediaTimeUs changed.
|
// Re-apply playback parameters because the startMediaTimeUs changed.
|
||||||
applyPlaybackParameters(getPlaybackParameters(), presentationTimeUs);
|
applyPlaybackSpeedAndSkipSilence(presentationTimeUs);
|
||||||
if (listener != null && adjustmentUs != 0) {
|
if (listener != null && adjustmentUs != 0) {
|
||||||
listener.onPositionDiscontinuity();
|
listener.onPositionDiscontinuity();
|
||||||
}
|
}
|
||||||
@ -825,35 +862,49 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
return isInitialized() && audioTrackPositionTracker.hasPendingData(getWrittenFrames());
|
return isInitialized() && audioTrackPositionTracker.hasPendingData(getWrittenFrames());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #setPlaybackSpeed(float)} and {@link #setSkipSilenceEnabled(boolean)}
|
||||||
|
* instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public void setPlaybackParameters(PlaybackParameters playbackParameters) {
|
public void setPlaybackParameters(PlaybackParameters playbackParameters) {
|
||||||
if (configuration != null && !configuration.canApplyPlaybackParameters) {
|
setPlaybackSpeedAndSkipSilence(playbackParameters.speed, playbackParameters.skipSilence);
|
||||||
playbackParameters = PlaybackParameters.DEFAULT;
|
}
|
||||||
}
|
|
||||||
PlaybackParameters lastSetPlaybackParameters = getPlaybackParameters();
|
/** @deprecated Use {@link #getPlaybackSpeed()} and {@link #getSkipSilenceEnabled()} instead. */
|
||||||
if (!playbackParameters.equals(lastSetPlaybackParameters)) {
|
@Deprecated
|
||||||
if (isInitialized()) {
|
@Override
|
||||||
// Drain the audio processors so we can determine the frame position at which the new
|
public PlaybackParameters getPlaybackParameters() {
|
||||||
// parameters apply.
|
MediaPositionParameters mediaPositionParameters = getMediaPositionParameters();
|
||||||
afterDrainPlaybackParameters = playbackParameters;
|
return new PlaybackParameters(
|
||||||
} else {
|
mediaPositionParameters.playbackSpeed, mediaPositionParameters.skipSilence);
|
||||||
// Update the playback parameters now. They will be applied to the audio processors during
|
|
||||||
// initialization.
|
|
||||||
mediaPositionParameters =
|
|
||||||
new MediaPositionParameters(
|
|
||||||
playbackParameters, /* mediaTimeUs= */ 0, /* audioTrackPositionUs= */ 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlaybackParameters getPlaybackParameters() {
|
public void setPlaybackSpeed(float playbackSpeed) {
|
||||||
// Mask the already set parameters.
|
if (configuration != null && !configuration.canApplyPlaybackParameters) {
|
||||||
return afterDrainPlaybackParameters != null
|
playbackSpeed = DEFAULT_PLAYBACK_SPEED;
|
||||||
? afterDrainPlaybackParameters
|
}
|
||||||
: !mediaPositionParametersCheckpoints.isEmpty()
|
setPlaybackSpeedAndSkipSilence(playbackSpeed, getSkipSilenceEnabled());
|
||||||
? mediaPositionParametersCheckpoints.getLast().playbackParameters
|
}
|
||||||
: mediaPositionParameters.playbackParameters;
|
|
||||||
|
@Override
|
||||||
|
public float getPlaybackSpeed() {
|
||||||
|
return getMediaPositionParameters().playbackSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkipSilenceEnabled(boolean skipSilenceEnabled) {
|
||||||
|
if (configuration != null && !configuration.canApplyPlaybackParameters) {
|
||||||
|
skipSilenceEnabled = DEFAULT_SKIP_SILENCE;
|
||||||
|
}
|
||||||
|
setPlaybackSpeedAndSkipSilence(getPlaybackSpeed(), skipSilenceEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getSkipSilenceEnabled() {
|
||||||
|
return getMediaPositionParameters().skipSilence;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -951,9 +1002,12 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
framesPerEncodedSample = 0;
|
framesPerEncodedSample = 0;
|
||||||
mediaPositionParameters =
|
mediaPositionParameters =
|
||||||
new MediaPositionParameters(
|
new MediaPositionParameters(
|
||||||
getPlaybackParameters(), /* mediaTimeUs= */ 0, /* audioTrackPositionUs= */ 0);
|
getPlaybackSpeed(),
|
||||||
|
getSkipSilenceEnabled(),
|
||||||
|
/* mediaTimeUs= */ 0,
|
||||||
|
/* audioTrackPositionUs= */ 0);
|
||||||
startMediaTimeUs = 0;
|
startMediaTimeUs = 0;
|
||||||
afterDrainPlaybackParameters = null;
|
afterDrainParameters = null;
|
||||||
mediaPositionParametersCheckpoints.clear();
|
mediaPositionParametersCheckpoints.clear();
|
||||||
trimmingAudioProcessor.resetTrimmedFrameCount();
|
trimmingAudioProcessor.resetTrimmedFrameCount();
|
||||||
flushAudioProcessors();
|
flushAudioProcessors();
|
||||||
@ -1005,9 +1059,9 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
playing = false;
|
playing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Internal methods.
|
||||||
* Releases {@link #keepSessionIdAudioTrack} asynchronously, if it is non-{@code null}.
|
|
||||||
*/
|
/** Releases {@link #keepSessionIdAudioTrack} asynchronously, if it is non-{@code null}. */
|
||||||
private void releaseKeepSessionIdAudioTrack() {
|
private void releaseKeepSessionIdAudioTrack() {
|
||||||
if (keepSessionIdAudioTrack == null) {
|
if (keepSessionIdAudioTrack == null) {
|
||||||
return;
|
return;
|
||||||
@ -1024,15 +1078,54 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyPlaybackParameters(
|
private void setPlaybackSpeedAndSkipSilence(float playbackSpeed, boolean skipSilence) {
|
||||||
PlaybackParameters playbackParameters, long presentationTimeUs) {
|
if (configuration != null && !configuration.canApplyPlaybackParameters) {
|
||||||
PlaybackParameters newPlaybackParameters =
|
playbackSpeed = DEFAULT_PLAYBACK_SPEED;
|
||||||
|
skipSilence = DEFAULT_SKIP_SILENCE;
|
||||||
|
}
|
||||||
|
MediaPositionParameters currentMediaPositionParameters = getMediaPositionParameters();
|
||||||
|
if (playbackSpeed != currentMediaPositionParameters.playbackSpeed
|
||||||
|
|| skipSilence != currentMediaPositionParameters.skipSilence) {
|
||||||
|
MediaPositionParameters mediaPositionParameters =
|
||||||
|
new MediaPositionParameters(
|
||||||
|
playbackSpeed,
|
||||||
|
skipSilence,
|
||||||
|
/* mediaTimeUs= */ C.TIME_UNSET,
|
||||||
|
/* audioTrackPositionUs= */ C.TIME_UNSET);
|
||||||
|
if (isInitialized()) {
|
||||||
|
// Drain the audio processors so we can determine the frame position at which the new
|
||||||
|
// parameters apply.
|
||||||
|
this.afterDrainParameters = mediaPositionParameters;
|
||||||
|
} else {
|
||||||
|
// Update the audio processor chain parameters now. They will be applied to the audio
|
||||||
|
// processors during initialization.
|
||||||
|
this.mediaPositionParameters = mediaPositionParameters;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MediaPositionParameters getMediaPositionParameters() {
|
||||||
|
// Mask the already set parameters.
|
||||||
|
return afterDrainParameters != null
|
||||||
|
? afterDrainParameters
|
||||||
|
: !mediaPositionParametersCheckpoints.isEmpty()
|
||||||
|
? mediaPositionParametersCheckpoints.getLast()
|
||||||
|
: mediaPositionParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyPlaybackSpeedAndSkipSilence(long presentationTimeUs) {
|
||||||
|
float playbackSpeed =
|
||||||
configuration.canApplyPlaybackParameters
|
configuration.canApplyPlaybackParameters
|
||||||
? audioProcessorChain.applyPlaybackParameters(playbackParameters)
|
? audioProcessorChain.applyPlaybackSpeed(getPlaybackSpeed())
|
||||||
: PlaybackParameters.DEFAULT;
|
: DEFAULT_PLAYBACK_SPEED;
|
||||||
|
boolean skipSilence =
|
||||||
|
configuration.canApplyPlaybackParameters
|
||||||
|
? audioProcessorChain.applySkipSilenceEnabled(getSkipSilenceEnabled())
|
||||||
|
: DEFAULT_SKIP_SILENCE;
|
||||||
mediaPositionParametersCheckpoints.add(
|
mediaPositionParametersCheckpoints.add(
|
||||||
new MediaPositionParameters(
|
new MediaPositionParameters(
|
||||||
newPlaybackParameters,
|
playbackSpeed,
|
||||||
|
skipSilence,
|
||||||
/* mediaTimeUs= */ Math.max(0, presentationTimeUs),
|
/* mediaTimeUs= */ Math.max(0, presentationTimeUs),
|
||||||
/* audioTrackPositionUs= */ configuration.framesToDurationUs(getWrittenFrames())));
|
/* audioTrackPositionUs= */ configuration.framesToDurationUs(getWrittenFrames())));
|
||||||
setupAudioProcessors();
|
setupAudioProcessors();
|
||||||
@ -1053,7 +1146,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
|
|
||||||
long playoutDurationSinceLastCheckpoint =
|
long playoutDurationSinceLastCheckpoint =
|
||||||
positionUs - mediaPositionParameters.audioTrackPositionUs;
|
positionUs - mediaPositionParameters.audioTrackPositionUs;
|
||||||
if (mediaPositionParameters.playbackParameters.speed != 1f) {
|
if (mediaPositionParameters.playbackSpeed != 1f) {
|
||||||
if (mediaPositionParametersCheckpoints.isEmpty()) {
|
if (mediaPositionParametersCheckpoints.isEmpty()) {
|
||||||
playoutDurationSinceLastCheckpoint =
|
playoutDurationSinceLastCheckpoint =
|
||||||
audioProcessorChain.getMediaDuration(playoutDurationSinceLastCheckpoint);
|
audioProcessorChain.getMediaDuration(playoutDurationSinceLastCheckpoint);
|
||||||
@ -1061,8 +1154,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
// Playing data at a previous playback speed, so fall back to multiplying by the speed.
|
// Playing data at a previous playback speed, so fall back to multiplying by the speed.
|
||||||
playoutDurationSinceLastCheckpoint =
|
playoutDurationSinceLastCheckpoint =
|
||||||
Util.getMediaDurationForPlayoutDuration(
|
Util.getMediaDurationForPlayoutDuration(
|
||||||
playoutDurationSinceLastCheckpoint,
|
playoutDurationSinceLastCheckpoint, mediaPositionParameters.playbackSpeed);
|
||||||
mediaPositionParameters.playbackParameters.speed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mediaPositionParameters.mediaTimeUs + playoutDurationSinceLastCheckpoint;
|
return mediaPositionParameters.mediaTimeUs + playoutDurationSinceLastCheckpoint;
|
||||||
@ -1248,16 +1340,19 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
/** Stores parameters used to calculate the current media position. */
|
/** Stores parameters used to calculate the current media position. */
|
||||||
private static final class MediaPositionParameters {
|
private static final class MediaPositionParameters {
|
||||||
|
|
||||||
/** The playback parameters. */
|
/** The playback speed. */
|
||||||
public final PlaybackParameters playbackParameters;
|
public final float playbackSpeed;
|
||||||
|
/** Whether to skip silences. */
|
||||||
|
public final boolean skipSilence;
|
||||||
/** The media time from which the playback parameters apply, in microseconds. */
|
/** The media time from which the playback parameters apply, in microseconds. */
|
||||||
public final long mediaTimeUs;
|
public final long mediaTimeUs;
|
||||||
/** The audio track position from which the playback parameters apply, in microseconds. */
|
/** The audio track position from which the playback parameters apply, in microseconds. */
|
||||||
public final long audioTrackPositionUs;
|
public final long audioTrackPositionUs;
|
||||||
|
|
||||||
private MediaPositionParameters(
|
private MediaPositionParameters(
|
||||||
PlaybackParameters playbackParameters, long mediaTimeUs, long audioTrackPositionUs) {
|
float playbackSpeed, boolean skipSilence, long mediaTimeUs, long audioTrackPositionUs) {
|
||||||
this.playbackParameters = playbackParameters;
|
this.playbackSpeed = playbackSpeed;
|
||||||
|
this.skipSilence = skipSilence;
|
||||||
this.mediaTimeUs = mediaTimeUs;
|
this.mediaTimeUs = mediaTimeUs;
|
||||||
this.audioTrackPositionUs = audioTrackPositionUs;
|
this.audioTrackPositionUs = audioTrackPositionUs;
|
||||||
}
|
}
|
||||||
|
@ -95,14 +95,42 @@ public class ForwardingAudioSink implements AudioSink {
|
|||||||
return sink.hasPendingData();
|
return sink.hasPendingData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #setPlaybackSpeed(float)} and {@link #setSkipSilenceEnabled(boolean)}
|
||||||
|
* instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public void setPlaybackParameters(PlaybackParameters playbackParameters) {
|
public void setPlaybackParameters(PlaybackParameters playbackParameters) {
|
||||||
sink.setPlaybackParameters(playbackParameters);
|
sink.setPlaybackSpeed(playbackParameters.speed);
|
||||||
|
sink.setSkipSilenceEnabled(playbackParameters.skipSilence);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated Use {@link #getPlaybackSpeed()} and {@link #getSkipSilenceEnabled()} instead. */
|
||||||
|
@Deprecated
|
||||||
|
@Override
|
||||||
|
public PlaybackParameters getPlaybackParameters() {
|
||||||
|
return new PlaybackParameters(sink.getPlaybackSpeed(), sink.getSkipSilenceEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlaybackParameters getPlaybackParameters() {
|
public void setPlaybackSpeed(float playbackSpeed) {
|
||||||
return sink.getPlaybackParameters();
|
sink.setPlaybackSpeed(playbackSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getPlaybackSpeed() {
|
||||||
|
return sink.getPlaybackSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkipSilenceEnabled(boolean skipSilenceEnabled) {
|
||||||
|
sink.setSkipSilenceEnabled(skipSilenceEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getSkipSilenceEnabled() {
|
||||||
|
return sink.getSkipSilenceEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +21,6 @@ import static org.robolectric.annotation.Config.TARGET_SDK;
|
|||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -89,8 +88,7 @@ public final class DefaultAudioSinkTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlesBufferAfterReset_withPlaybackParameters() throws Exception {
|
public void handlesBufferAfterReset_withPlaybackParameters() throws Exception {
|
||||||
PlaybackParameters playbackParameters = new PlaybackParameters(1.5f);
|
defaultAudioSink.setPlaybackSpeed(/* playbackSpeed= */ 1.5f);
|
||||||
defaultAudioSink.setPlaybackParameters(playbackParameters);
|
|
||||||
configureDefaultAudioSink(CHANNEL_COUNT_STEREO);
|
configureDefaultAudioSink(CHANNEL_COUNT_STEREO);
|
||||||
defaultAudioSink.handleBuffer(
|
defaultAudioSink.handleBuffer(
|
||||||
createDefaultSilenceBuffer(), /* presentationTimeUs= */ 0, /* encodedAccessUnitCount= */ 1);
|
createDefaultSilenceBuffer(), /* presentationTimeUs= */ 0, /* encodedAccessUnitCount= */ 1);
|
||||||
@ -100,7 +98,7 @@ public final class DefaultAudioSinkTest {
|
|||||||
configureDefaultAudioSink(CHANNEL_COUNT_STEREO);
|
configureDefaultAudioSink(CHANNEL_COUNT_STEREO);
|
||||||
defaultAudioSink.handleBuffer(
|
defaultAudioSink.handleBuffer(
|
||||||
createDefaultSilenceBuffer(), /* presentationTimeUs= */ 0, /* encodedAccessUnitCount= */ 1);
|
createDefaultSilenceBuffer(), /* presentationTimeUs= */ 0, /* encodedAccessUnitCount= */ 1);
|
||||||
assertThat(defaultAudioSink.getPlaybackParameters()).isEqualTo(playbackParameters);
|
assertThat(defaultAudioSink.getPlaybackSpeed()).isEqualTo(1.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -118,8 +116,7 @@ public final class DefaultAudioSinkTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlesBufferAfterReset_withFormatChangeAndPlaybackParameters() throws Exception {
|
public void handlesBufferAfterReset_withFormatChangeAndPlaybackParameters() throws Exception {
|
||||||
PlaybackParameters playbackParameters = new PlaybackParameters(1.5f);
|
defaultAudioSink.setPlaybackSpeed(/* playbackSpeed= */ 1.5f);
|
||||||
defaultAudioSink.setPlaybackParameters(playbackParameters);
|
|
||||||
configureDefaultAudioSink(CHANNEL_COUNT_STEREO);
|
configureDefaultAudioSink(CHANNEL_COUNT_STEREO);
|
||||||
defaultAudioSink.handleBuffer(
|
defaultAudioSink.handleBuffer(
|
||||||
createDefaultSilenceBuffer(), /* presentationTimeUs= */ 0, /* encodedAccessUnitCount= */ 1);
|
createDefaultSilenceBuffer(), /* presentationTimeUs= */ 0, /* encodedAccessUnitCount= */ 1);
|
||||||
@ -129,7 +126,7 @@ public final class DefaultAudioSinkTest {
|
|||||||
configureDefaultAudioSink(CHANNEL_COUNT_MONO);
|
configureDefaultAudioSink(CHANNEL_COUNT_MONO);
|
||||||
defaultAudioSink.handleBuffer(
|
defaultAudioSink.handleBuffer(
|
||||||
createDefaultSilenceBuffer(), /* presentationTimeUs= */ 0, /* encodedAccessUnitCount= */ 1);
|
createDefaultSilenceBuffer(), /* presentationTimeUs= */ 0, /* encodedAccessUnitCount= */ 1);
|
||||||
assertThat(defaultAudioSink.getPlaybackParameters()).isEqualTo(playbackParameters);
|
assertThat(defaultAudioSink.getPlaybackSpeed()).isEqualTo(1.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user