Commit be1fd236 by olly Committed by Oliver Woodman

Rename setOperatingRate to setPlaybackSpeed

This avoids confusion that currently exists between "operating rate"
and "codec operating rate", which are different. It also tightens the
requirement of the value being passed to be more than a "hint". It's
already being used as more than a hint for setting the Surface frame
rate.

PiperOrigin-RevId: 340201829
parent 42891129
......@@ -2116,7 +2116,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
updateTrackSelectionPlaybackSpeed(playbackParameters.speed);
for (Renderer renderer : renderers) {
if (renderer != null) {
renderer.setOperatingRate(playbackParameters.speed);
renderer.setPlaybackSpeed(playbackParameters.speed);
}
}
}
......
......@@ -403,16 +403,15 @@ public interface Renderer extends PlayerMessage.Target {
void resetPosition(long positionUs) throws ExoPlaybackException;
/**
* Sets the operating rate of this renderer, where 1 is the default rate, 2 is twice the default
* rate, 0.5 is half the default rate and so on. The operating rate is a hint to the renderer of
* the speed at which playback will proceed, and may be used for resource planning.
* Indicates the player's speed to this renderer, where 1 is the default rate, 2 is twice the
* default rate, 0.5 is half the default rate and so on.
*
* <p>The default implementation is a no-op.
*
* @param operatingRate The operating rate.
* @throws ExoPlaybackException If an error occurs handling the operating rate.
* @param playbackSpeed The playback speed.
* @throws ExoPlaybackException If an error occurs handling the playback speed.
*/
default void setOperatingRate(float operatingRate) throws ExoPlaybackException {}
default void setPlaybackSpeed(float playbackSpeed) throws ExoPlaybackException {}
/**
* Incrementally renders the {@link SampleStream}.
......
......@@ -347,7 +347,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Override
protected float getCodecOperatingRateV23(
float operatingRate, Format format, Format[] streamFormats) {
float playbackSpeed, Format format, Format[] streamFormats) {
// Use the highest known stream sample-rate up front, to avoid having to reconfigure the codec
// should an adaptive switch to that stream occur.
int maxSampleRate = -1;
......@@ -357,7 +357,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
maxSampleRate = max(maxSampleRate, streamSampleRate);
}
}
return maxSampleRate == -1 ? CODEC_OPERATING_RATE_UNSET : (maxSampleRate * operatingRate);
return maxSampleRate == -1 ? CODEC_OPERATING_RATE_UNSET : (maxSampleRate * playbackSpeed);
}
@Override
......
......@@ -304,7 +304,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
@Nullable private MediaCrypto mediaCrypto;
private boolean mediaCryptoRequiresSecureDecoder;
private long renderTimeLimitMs;
private float operatingRate;
private float playbackSpeed;
@Nullable private MediaCodec codec;
@Nullable private MediaCodecAdapter codecAdapter;
@Nullable private Format codecInputFormat;
......@@ -381,7 +381,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
formatQueue = new TimedValueQueue<>();
decodeOnlyPresentationTimestamps = new ArrayList<>();
outputBufferInfo = new MediaCodec.BufferInfo();
operatingRate = 1f;
playbackSpeed = 1f;
renderTimeLimitMs = C.TIME_UNSET;
pendingOutputStreamStartPositionsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
......@@ -678,8 +678,8 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
}
@Override
public void setOperatingRate(float operatingRate) throws ExoPlaybackException {
this.operatingRate = operatingRate;
public void setPlaybackSpeed(float playbackSpeed) throws ExoPlaybackException {
this.playbackSpeed = playbackSpeed;
if (codec != null
&& codecDrainAction != DRAIN_ACTION_REINITIALIZE
&& getState() != STATE_DISABLED) {
......@@ -1043,7 +1043,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
float codecOperatingRate =
Util.SDK_INT < 23
? CODEC_OPERATING_RATE_UNSET
: getCodecOperatingRateV23(operatingRate, inputFormat, getStreamFormats());
: getCodecOperatingRateV23(playbackSpeed, inputFormat, getStreamFormats());
if (codecOperatingRate <= assumedMinimumCodecOperatingRate) {
codecOperatingRate = CODEC_OPERATING_RATE_UNSET;
}
......@@ -1582,9 +1582,9 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
&& SystemClock.elapsedRealtime() < codecHotswapDeadlineMs));
}
/** Returns the renderer operating rate, as set by {@link #setOperatingRate}. */
protected float getOperatingRate() {
return operatingRate;
/** Returns the playback speed, as set by {@link #setPlaybackSpeed}. */
protected float getPlaybackSpeed() {
return playbackSpeed;
}
/** Returns the operating rate used by the current codec */
......@@ -1593,19 +1593,19 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
}
/**
* Returns the {@link MediaFormat#KEY_OPERATING_RATE} value for a given renderer operating rate,
* current {@link Format} and set of possible stream formats.
* Returns the {@link MediaFormat#KEY_OPERATING_RATE} value for a given playback speed, current
* {@link Format} and set of possible stream formats.
*
* <p>The default implementation returns {@link #CODEC_OPERATING_RATE_UNSET}.
*
* @param operatingRate The renderer operating rate.
* @param playbackSpeed The playback speed.
* @param format The {@link Format} for which the codec is being configured.
* @param streamFormats The possible stream formats.
* @return The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if no codec operating
* rate should be set.
*/
protected float getCodecOperatingRateV23(
float operatingRate, Format format, Format[] streamFormats) {
float playbackSpeed, Format format, Format[] streamFormats) {
return CODEC_OPERATING_RATE_UNSET;
}
......@@ -1620,7 +1620,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
}
float newCodecOperatingRate =
getCodecOperatingRateV23(operatingRate, codecInputFormat, getStreamFormats());
getCodecOperatingRateV23(playbackSpeed, codecInputFormat, getStreamFormats());
if (codecOperatingRate == newCodecOperatingRate) {
// No change.
} else if (newCodecOperatingRate == CODEC_OPERATING_RATE_UNSET) {
......
......@@ -586,14 +586,14 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
}
@Override
public void setOperatingRate(float operatingRate) throws ExoPlaybackException {
super.setOperatingRate(operatingRate);
public void setPlaybackSpeed(float playbackSpeed) throws ExoPlaybackException {
super.setPlaybackSpeed(playbackSpeed);
updateSurfaceFrameRate(/* isNewSurface= */ false);
}
@Override
protected float getCodecOperatingRateV23(
float operatingRate, Format format, Format[] streamFormats) {
float playbackSpeed, Format format, Format[] streamFormats) {
// Use the highest known stream frame-rate up front, to avoid having to reconfigure the codec
// should an adaptive switch to that stream occur.
float maxFrameRate = -1;
......@@ -603,7 +603,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
maxFrameRate = max(maxFrameRate, streamFrameRate);
}
}
return maxFrameRate == -1 ? CODEC_OPERATING_RATE_UNSET : (maxFrameRate * operatingRate);
return maxFrameRate == -1 ? CODEC_OPERATING_RATE_UNSET : (maxFrameRate * playbackSpeed);
}
@Override
......@@ -1081,7 +1081,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
return;
}
boolean shouldSetFrameRate = getState() == STATE_STARTED && currentFrameRate != Format.NO_VALUE;
float surfaceFrameRate = shouldSetFrameRate ? currentFrameRate * getOperatingRate() : 0;
float surfaceFrameRate = shouldSetFrameRate ? currentFrameRate * getPlaybackSpeed() : 0;
// We always set the frame-rate if we have a new surface, since we have no way of knowing what
// it might have been set to previously.
if (this.surfaceFrameRate == surfaceFrameRate && !isNewSurface) {
......
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