Utilise existing rate unset representation C.RATE_UNSET_INT

Use `C.RATE_UNSET_INT` instead of introducing `Long.MIN_VALUE` as the default value for rate parameters. Modifies default behaviour of the `TrackSelection.getLatestBitrateEstimate()` method and the `measuredThroughputInKbps` parameter in `CmcdHeadersFactory.CmcdRequest`.

PiperOrigin-RevId: 555939420
This commit is contained in:
rohks 2023-08-11 14:09:08 +00:00 committed by Tianyi Feng
parent 0466bd7957
commit 45348f1576
3 changed files with 11 additions and 10 deletions

View file

@ -411,7 +411,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
playbackSpeed = 1f; playbackSpeed = 1f;
reason = C.SELECTION_REASON_UNKNOWN; reason = C.SELECTION_REASON_UNKNOWN;
lastBufferEvaluationMs = C.TIME_UNSET; lastBufferEvaluationMs = C.TIME_UNSET;
latestBitrateEstimate = Long.MIN_VALUE; latestBitrateEstimate = C.RATE_UNSET_INT;
} }
@CallSuper @CallSuper

View file

@ -296,10 +296,10 @@ public interface ExoTrackSelection extends TrackSelection {
/** /**
* Returns the most recent bitrate estimate utilised for track selection. * Returns the most recent bitrate estimate utilised for track selection.
* *
* <p>The default behavior is to return {@link Long#MIN_VALUE}, indicating that the bitrate * <p>The default behavior is to return {@link C#RATE_UNSET_INT}, indicating that the bitrate
* estimate was not computed for the track selection decision. * estimate was not computed for the track selection decision.
*/ */
default long getLatestBitrateEstimate() { default long getLatestBitrateEstimate() {
return Long.MIN_VALUE; return C.RATE_UNSET_INT;
} }
} }

View file

@ -242,7 +242,7 @@ public final class CmcdHeadersFactory {
cmcdRequest.setBufferLengthMs(Util.usToMs(bufferedDurationUs)); cmcdRequest.setBufferLengthMs(Util.usToMs(bufferedDurationUs));
} }
if (cmcdConfiguration.isMeasuredThroughputLoggingAllowed() if (cmcdConfiguration.isMeasuredThroughputLoggingAllowed()
&& trackSelection.getLatestBitrateEstimate() != Long.MIN_VALUE) { && trackSelection.getLatestBitrateEstimate() != C.RATE_UNSET_INT) {
cmcdRequest.setMeasuredThroughputInKbps( cmcdRequest.setMeasuredThroughputInKbps(
Util.ceilDivide(trackSelection.getLatestBitrateEstimate(), 1000)); Util.ceilDivide(trackSelection.getLatestBitrateEstimate(), 1000));
} }
@ -471,7 +471,7 @@ public final class CmcdHeadersFactory {
/** Creates a new instance with default values. */ /** Creates a new instance with default values. */
public Builder() { public Builder() {
this.bufferLengthMs = C.TIME_UNSET; this.bufferLengthMs = C.TIME_UNSET;
this.measuredThroughputInKbps = Long.MIN_VALUE; this.measuredThroughputInKbps = C.RATE_UNSET_INT;
this.deadlineMs = C.TIME_UNSET; this.deadlineMs = C.TIME_UNSET;
} }
@ -491,14 +491,15 @@ public final class CmcdHeadersFactory {
/** /**
* Sets the {@link CmcdRequest#measuredThroughputInKbps}. Rounded to nearest 100 kbps. The * Sets the {@link CmcdRequest#measuredThroughputInKbps}. Rounded to nearest 100 kbps. The
* default value is {@link Long#MIN_VALUE}. * default value is {@link C#RATE_UNSET_INT}.
* *
* @throws IllegalArgumentException If {@code measuredThroughputInKbps} is not equal to {@link * @throws IllegalArgumentException If {@code measuredThroughputInKbps} is not equal to {@link
* Long#MIN_VALUE} and is negative. * C#RATE_UNSET_INT} and is negative.
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder setMeasuredThroughputInKbps(long measuredThroughputInKbps) { public Builder setMeasuredThroughputInKbps(long measuredThroughputInKbps) {
checkArgument(measuredThroughputInKbps >= 0 || measuredThroughputInKbps == Long.MIN_VALUE); checkArgument(
measuredThroughputInKbps >= 0 || measuredThroughputInKbps == C.RATE_UNSET_INT);
this.measuredThroughputInKbps = ((measuredThroughputInKbps + 50) / 100) * 100; this.measuredThroughputInKbps = ((measuredThroughputInKbps + 50) / 100) * 100;
return this; return this;
@ -551,7 +552,7 @@ public final class CmcdHeadersFactory {
/** /**
* The throughput between client and server, as measured by the client, or {@link * The throughput between client and server, as measured by the client, or {@link
* Long#MIN_VALUE} if unset. * C#RATE_UNSET_INT} if unset.
* *
* <p>This value MUST be rounded to the nearest 100 kbps. This value, however derived, SHOULD be * <p>This value MUST be rounded to the nearest 100 kbps. This value, however derived, SHOULD be
* the value that the client is using to make its next Adaptive Bitrate switching decision. If * the value that the client is using to make its next Adaptive Bitrate switching decision. If
@ -607,7 +608,7 @@ public final class CmcdHeadersFactory {
if (bufferLengthMs != C.TIME_UNSET) { if (bufferLengthMs != C.TIME_UNSET) {
headerValueList.add(CmcdConfiguration.KEY_BUFFER_LENGTH + "=" + bufferLengthMs); headerValueList.add(CmcdConfiguration.KEY_BUFFER_LENGTH + "=" + bufferLengthMs);
} }
if (measuredThroughputInKbps != Long.MIN_VALUE) { if (measuredThroughputInKbps != C.RATE_UNSET_INT) {
headerValueList.add( headerValueList.add(
CmcdConfiguration.KEY_MEASURED_THROUGHPUT + "=" + measuredThroughputInKbps); CmcdConfiguration.KEY_MEASURED_THROUGHPUT + "=" + measuredThroughputInKbps);
} }