Rename some white/blacklist occurrences in core library
ISSUE: #7565 PiperOrigin-RevId: 319734842
This commit is contained in:
parent
6872910d5a
commit
b30e2b961f
@ -489,12 +489,12 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
|
||||
LoadErrorInfo loadErrorInfo =
|
||||
new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount);
|
||||
|
||||
long blacklistDurationMs =
|
||||
long exclusionDurationMs =
|
||||
cancelable
|
||||
? loadErrorHandlingPolicy.getBlacklistDurationMsFor(loadErrorInfo)
|
||||
: C.TIME_UNSET;
|
||||
@Nullable LoadErrorAction loadErrorAction = null;
|
||||
if (chunkSource.onChunkLoadError(loadable, cancelable, error, blacklistDurationMs)) {
|
||||
if (chunkSource.onChunkLoadError(loadable, cancelable, error, exclusionDurationMs)) {
|
||||
if (cancelable) {
|
||||
loadErrorAction = Loader.DONT_RETRY;
|
||||
if (isMediaChunk) {
|
||||
|
@ -96,12 +96,12 @@ public interface ChunkSource {
|
||||
* @param chunk The chunk whose load encountered the error.
|
||||
* @param cancelable Whether the load can be canceled.
|
||||
* @param e The error.
|
||||
* @param blacklistDurationMs The duration for which the associated track may be blacklisted, or
|
||||
* {@link C#TIME_UNSET} if the track may not be blacklisted.
|
||||
* @param exclusionDurationMs The duration for which the associated track may be excluded, or
|
||||
* {@link C#TIME_UNSET} if the track may not be excluded.
|
||||
* @return Whether the load should be canceled so that a replacement chunk can be loaded instead.
|
||||
* Must be {@code false} if {@code cancelable} is {@code false}. If {@code true}, {@link
|
||||
* #getNextChunk(long, long, List, ChunkHolder)} will be called to obtain the replacement
|
||||
* chunk.
|
||||
*/
|
||||
boolean onChunkLoadError(Chunk chunk, boolean cancelable, Exception e, long blacklistDurationMs);
|
||||
boolean onChunkLoadError(Chunk chunk, boolean cancelable, Exception e, long exclusionDurationMs);
|
||||
}
|
||||
|
@ -569,22 +569,22 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||
* Computes the ideal selected index ignoring buffer health.
|
||||
*
|
||||
* @param nowMs The current time in the timebase of {@link Clock#elapsedRealtime()}, or {@link
|
||||
* Long#MIN_VALUE} to ignore blacklisting.
|
||||
* Long#MIN_VALUE} to ignore track exclusion.
|
||||
*/
|
||||
private int determineIdealSelectedIndex(long nowMs) {
|
||||
long effectiveBitrate = bandwidthProvider.getAllocatedBandwidth();
|
||||
int lowestBitrateNonBlacklistedIndex = 0;
|
||||
int lowestBitrateAllowedIndex = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (nowMs == Long.MIN_VALUE || !isBlacklisted(i, nowMs)) {
|
||||
Format format = getFormat(i);
|
||||
if (canSelectFormat(format, format.bitrate, playbackSpeed, effectiveBitrate)) {
|
||||
return i;
|
||||
} else {
|
||||
lowestBitrateNonBlacklistedIndex = i;
|
||||
lowestBitrateAllowedIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lowestBitrateNonBlacklistedIndex;
|
||||
return lowestBitrateAllowedIndex;
|
||||
}
|
||||
|
||||
private long minDurationForQualityIncreaseUs(long availableDurationUs) {
|
||||
|
@ -49,10 +49,8 @@ public abstract class BaseTrackSelection implements TrackSelection {
|
||||
* The {@link Format}s of the selected tracks, in order of decreasing bandwidth.
|
||||
*/
|
||||
private final Format[] formats;
|
||||
/**
|
||||
* Selected track blacklist timestamps, in order of decreasing bandwidth.
|
||||
*/
|
||||
private final long[] blacklistUntilTimes;
|
||||
/** Selected track exclusion timestamps, in order of decreasing bandwidth. */
|
||||
private final long[] excludeUntilTimes;
|
||||
|
||||
// Lazily initialized hashcode.
|
||||
private int hashCode;
|
||||
@ -77,7 +75,7 @@ public abstract class BaseTrackSelection implements TrackSelection {
|
||||
for (int i = 0; i < length; i++) {
|
||||
this.tracks[i] = group.indexOf(formats[i]);
|
||||
}
|
||||
blacklistUntilTimes = new long[length];
|
||||
excludeUntilTimes = new long[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -152,30 +150,30 @@ public abstract class BaseTrackSelection implements TrackSelection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean blacklist(int index, long blacklistDurationMs) {
|
||||
public final boolean blacklist(int index, long exclusionDurationMs) {
|
||||
long nowMs = SystemClock.elapsedRealtime();
|
||||
boolean canBlacklist = isBlacklisted(index, nowMs);
|
||||
for (int i = 0; i < length && !canBlacklist; i++) {
|
||||
canBlacklist = i != index && !isBlacklisted(i, nowMs);
|
||||
boolean canExclude = isBlacklisted(index, nowMs);
|
||||
for (int i = 0; i < length && !canExclude; i++) {
|
||||
canExclude = i != index && !isBlacklisted(i, nowMs);
|
||||
}
|
||||
if (!canBlacklist) {
|
||||
if (!canExclude) {
|
||||
return false;
|
||||
}
|
||||
blacklistUntilTimes[index] =
|
||||
excludeUntilTimes[index] =
|
||||
Math.max(
|
||||
blacklistUntilTimes[index],
|
||||
Util.addWithOverflowDefault(nowMs, blacklistDurationMs, Long.MAX_VALUE));
|
||||
excludeUntilTimes[index],
|
||||
Util.addWithOverflowDefault(nowMs, exclusionDurationMs, Long.MAX_VALUE));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the track at the specified index in the selection is blacklisted.
|
||||
* Returns whether the track at the specified index in the selection is excluded.
|
||||
*
|
||||
* @param index The index of the track in the selection.
|
||||
* @param nowMs The current time in the timebase of {@link SystemClock#elapsedRealtime()}.
|
||||
*/
|
||||
protected final boolean isBlacklisted(int index, long nowMs) {
|
||||
return blacklistUntilTimes[index] > nowMs;
|
||||
return excludeUntilTimes[index] > nowMs;
|
||||
}
|
||||
|
||||
// Object overrides.
|
||||
|
@ -102,21 +102,21 @@ public final class RandomTrackSelection extends BaseTrackSelection {
|
||||
long availableDurationUs,
|
||||
List<? extends MediaChunk> queue,
|
||||
MediaChunkIterator[] mediaChunkIterators) {
|
||||
// Count the number of non-blacklisted formats.
|
||||
// Count the number of allowed formats.
|
||||
long nowMs = SystemClock.elapsedRealtime();
|
||||
int nonBlacklistedFormatCount = 0;
|
||||
int allowedFormatCount = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (!isBlacklisted(i, nowMs)) {
|
||||
nonBlacklistedFormatCount++;
|
||||
allowedFormatCount++;
|
||||
}
|
||||
}
|
||||
|
||||
selectedIndex = random.nextInt(nonBlacklistedFormatCount);
|
||||
if (nonBlacklistedFormatCount != length) {
|
||||
// Adjust the format index to account for blacklisted formats.
|
||||
nonBlacklistedFormatCount = 0;
|
||||
selectedIndex = random.nextInt(allowedFormatCount);
|
||||
if (allowedFormatCount != length) {
|
||||
// Adjust the format index to account for excluded formats.
|
||||
allowedFormatCount = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (!isBlacklisted(i, nowMs) && selectedIndex == nonBlacklistedFormatCount++) {
|
||||
if (!isBlacklisted(i, nowMs) && selectedIndex == allowedFormatCount++) {
|
||||
selectedIndex = i;
|
||||
return;
|
||||
}
|
||||
|
@ -294,20 +294,20 @@ public interface TrackSelection {
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to blacklist the track at the specified index in the selection, making it ineligible
|
||||
* for selection by calls to {@link #updateSelectedTrack(long, long, long, List,
|
||||
* Attempts to exclude the track at the specified index in the selection, making it ineligible for
|
||||
* selection by calls to {@link #updateSelectedTrack(long, long, long, List,
|
||||
* MediaChunkIterator[])} for the specified period of time.
|
||||
*
|
||||
* <p>Blacklisting will fail if all other tracks are currently blacklisted. If blacklisting the
|
||||
* currently selected track, note that it will remain selected until the next call to {@link
|
||||
* <p>Exclusion will fail if all other tracks are currently excluded. If excluding the currently
|
||||
* selected track, note that it will remain selected until the next call to {@link
|
||||
* #updateSelectedTrack(long, long, long, List, MediaChunkIterator[])}.
|
||||
*
|
||||
* <p>This method will only be called when the selection is enabled.
|
||||
*
|
||||
* @param index The index of the track in the selection.
|
||||
* @param blacklistDurationMs The duration of time for which the track should be blacklisted, in
|
||||
* @param exclusionDurationMs The duration of time for which the track should be excluded, in
|
||||
* milliseconds.
|
||||
* @return Whether blacklisting was successful.
|
||||
* @return Whether exclusion was successful.
|
||||
*/
|
||||
boolean blacklist(int index, long blacklistDurationMs);
|
||||
boolean blacklist(int index, long exclusionDurationMs);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class DefaultLoadErrorHandlingPolicy implements LoadErrorHandlingPolicy {
|
||||
* streams.
|
||||
*/
|
||||
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT_PROGRESSIVE_LIVE = 6;
|
||||
/** The default duration for which a track is blacklisted in milliseconds. */
|
||||
/** The default duration for which a track is excluded in milliseconds. */
|
||||
public static final long DEFAULT_TRACK_BLACKLIST_MS = 60_000;
|
||||
|
||||
private static final int DEFAULT_BEHAVIOR_MIN_LOADABLE_RETRY_COUNT = -1;
|
||||
@ -61,8 +61,9 @@ public class DefaultLoadErrorHandlingPolicy implements LoadErrorHandlingPolicy {
|
||||
}
|
||||
|
||||
/**
|
||||
* Blacklists resources whose load error was an {@link InvalidResponseCodeException} with response
|
||||
* code HTTP 404 or 410. The duration of the blacklisting is {@link #DEFAULT_TRACK_BLACKLIST_MS}.
|
||||
* Returns the exclusion duration, given by {@link #DEFAULT_TRACK_BLACKLIST_MS}, if the load error
|
||||
* was an {@link InvalidResponseCodeException} with response code HTTP 404, 410 or 416, or {@link
|
||||
* C#TIME_UNSET} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public long getBlacklistDurationMsFor(LoadErrorInfo loadErrorInfo) {
|
||||
|
@ -23,18 +23,16 @@ import com.google.android.exoplayer2.upstream.Loader.Loadable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Defines how errors encountered by {@link Loader Loaders} are handled.
|
||||
* Defines how errors encountered by loaders are handled.
|
||||
*
|
||||
* <p>Loader clients may blacklist a resource when a load error occurs. Blacklisting works around
|
||||
* load errors by loading an alternative resource. Clients do not try blacklisting when a resource
|
||||
* does not have an alternative. When a resource does have valid alternatives, {@link
|
||||
* #getBlacklistDurationMsFor(int, long, IOException, int)} defines whether the resource should be
|
||||
* blacklisted. Blacklisting will succeed if any of the alternatives is not in the black list.
|
||||
* <p>A loader that can choose between one of a number of resources can exclude a resource when a
|
||||
* load error occurs. In this case, {@link #getBlacklistDurationMsFor(int, long, IOException, int)}
|
||||
* defines whether the resource should be excluded. Exclusion will succeed unless all of the
|
||||
* alternatives are already excluded.
|
||||
*
|
||||
* <p>When blacklisting does not take place, {@link #getRetryDelayMsFor(int, long, IOException,
|
||||
* int)} defines whether the load is retried. Errors whose load is not retried are propagated. Load
|
||||
* errors whose load is retried are propagated according to {@link
|
||||
* #getMinimumLoadableRetryCount(int)}.
|
||||
* <p>When exclusion does not take place, {@link #getRetryDelayMsFor(int, long, IOException, int)}
|
||||
* defines whether the load is retried. An error that's not retried will always be propagated. An
|
||||
* error that is retried will be propagated according to {@link #getMinimumLoadableRetryCount(int)}.
|
||||
*
|
||||
* <p>Methods are invoked on the playback thread.
|
||||
*/
|
||||
@ -74,11 +72,11 @@ public interface LoadErrorHandlingPolicy {
|
||||
|
||||
/**
|
||||
* Returns the number of milliseconds for which a resource associated to a provided load error
|
||||
* should be blacklisted, or {@link C#TIME_UNSET} if the resource should not be blacklisted.
|
||||
* should be excluded, or {@link C#TIME_UNSET} if the resource should not be excluded.
|
||||
*
|
||||
* @param loadErrorInfo A {@link LoadErrorInfo} holding information about the load error.
|
||||
* @return The blacklist duration in milliseconds, or {@link C#TIME_UNSET} if the resource should
|
||||
* not be blacklisted.
|
||||
* @return The exclusion duration in milliseconds, or {@link C#TIME_UNSET} if the resource should
|
||||
* not be excluded.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
default long getBlacklistDurationMsFor(LoadErrorInfo loadErrorInfo) {
|
||||
@ -100,9 +98,9 @@ public interface LoadErrorHandlingPolicy {
|
||||
* Returns the number of milliseconds to wait before attempting the load again, or {@link
|
||||
* C#TIME_UNSET} if the error is fatal and should not be retried.
|
||||
*
|
||||
* <p>{@link Loader} clients may ignore the retry delay returned by this method in order to wait
|
||||
* for a specific event before retrying. However, the load is retried if and only if this method
|
||||
* does not return {@link C#TIME_UNSET}.
|
||||
* <p>Loaders may ignore the retry delay returned by this method in order to wait for a specific
|
||||
* event before retrying. However, the load is retried if and only if this method does not return
|
||||
* {@link C#TIME_UNSET}.
|
||||
*
|
||||
* @param loadErrorInfo A {@link LoadErrorInfo} holding information about the load error.
|
||||
* @return The number of milliseconds to wait before attempting the load again, or {@link
|
||||
|
@ -47,35 +47,35 @@ public final class DefaultLoadErrorHandlingPolicyTest {
|
||||
new MediaLoadData(/* dataType= */ C.DATA_TYPE_UNKNOWN);
|
||||
|
||||
@Test
|
||||
public void getBlacklistDurationMsFor_blacklist404() {
|
||||
public void getExclusionDurationMsFor_responseCode404() {
|
||||
InvalidResponseCodeException exception =
|
||||
new InvalidResponseCodeException(
|
||||
404, "Not Found", Collections.emptyMap(), new DataSpec(Uri.EMPTY));
|
||||
assertThat(getDefaultPolicyBlacklistOutputFor(exception))
|
||||
assertThat(getDefaultPolicyExclusionDurationMsFor(exception))
|
||||
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBlacklistDurationMsFor_blacklist410() {
|
||||
public void getExclusionDurationMsFor_responseCode410() {
|
||||
InvalidResponseCodeException exception =
|
||||
new InvalidResponseCodeException(
|
||||
410, "Gone", Collections.emptyMap(), new DataSpec(Uri.EMPTY));
|
||||
assertThat(getDefaultPolicyBlacklistOutputFor(exception))
|
||||
assertThat(getDefaultPolicyExclusionDurationMsFor(exception))
|
||||
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBlacklistDurationMsFor_dontBlacklistUnexpectedHttpCodes() {
|
||||
public void getExclusionDurationMsFor_dontExcludeUnexpectedHttpCodes() {
|
||||
InvalidResponseCodeException exception =
|
||||
new InvalidResponseCodeException(
|
||||
500, "Internal Server Error", Collections.emptyMap(), new DataSpec(Uri.EMPTY));
|
||||
assertThat(getDefaultPolicyBlacklistOutputFor(exception)).isEqualTo(C.TIME_UNSET);
|
||||
assertThat(getDefaultPolicyExclusionDurationMsFor(exception)).isEqualTo(C.TIME_UNSET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBlacklistDurationMsFor_dontBlacklistUnexpectedExceptions() {
|
||||
public void getExclusionDurationMsFor_dontExcludeUnexpectedExceptions() {
|
||||
IOException exception = new IOException();
|
||||
assertThat(getDefaultPolicyBlacklistOutputFor(exception)).isEqualTo(C.TIME_UNSET);
|
||||
assertThat(getDefaultPolicyExclusionDurationMsFor(exception)).isEqualTo(C.TIME_UNSET);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -91,7 +91,7 @@ public final class DefaultLoadErrorHandlingPolicyTest {
|
||||
assertThat(getDefaultPolicyRetryDelayOutputFor(new IOException(), 9)).isEqualTo(5000);
|
||||
}
|
||||
|
||||
private static long getDefaultPolicyBlacklistOutputFor(IOException exception) {
|
||||
private static long getDefaultPolicyExclusionDurationMsFor(IOException exception) {
|
||||
LoadErrorInfo loadErrorInfo =
|
||||
new LoadErrorInfo(
|
||||
PLACEHOLDER_LOAD_EVENT_INFO,
|
||||
|
@ -415,7 +415,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
|
||||
|
||||
@Override
|
||||
public boolean onChunkLoadError(
|
||||
Chunk chunk, boolean cancelable, Exception e, long blacklistDurationMs) {
|
||||
Chunk chunk, boolean cancelable, Exception e, long exclusionDurationMs) {
|
||||
if (!cancelable) {
|
||||
return false;
|
||||
}
|
||||
@ -438,8 +438,8 @@ public class DefaultDashChunkSource implements DashChunkSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
return blacklistDurationMs != C.TIME_UNSET
|
||||
&& trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), blacklistDurationMs);
|
||||
return exclusionDurationMs != C.TIME_UNSET
|
||||
&& trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), exclusionDurationMs);
|
||||
}
|
||||
|
||||
// Internal methods.
|
||||
|
@ -265,10 +265,10 @@ public class DefaultSsChunkSource implements SsChunkSource {
|
||||
|
||||
@Override
|
||||
public boolean onChunkLoadError(
|
||||
Chunk chunk, boolean cancelable, Exception e, long blacklistDurationMs) {
|
||||
Chunk chunk, boolean cancelable, Exception e, long exclusionDurationMs) {
|
||||
return cancelable
|
||||
&& blacklistDurationMs != C.TIME_UNSET
|
||||
&& trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), blacklistDurationMs);
|
||||
&& exclusionDurationMs != C.TIME_UNSET
|
||||
&& trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), exclusionDurationMs);
|
||||
}
|
||||
|
||||
// Private methods.
|
||||
|
@ -146,7 +146,7 @@ public final class FakeChunkSource implements ChunkSource {
|
||||
|
||||
@Override
|
||||
public boolean onChunkLoadError(
|
||||
Chunk chunk, boolean cancelable, Exception e, long blacklistDurationMs) {
|
||||
Chunk chunk, boolean cancelable, Exception e, long exclusionDurationMs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ public final class FakeTrackSelection implements TrackSelection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blacklist(int index, long blacklistDurationMs) {
|
||||
public boolean blacklist(int index, long exclusionDurationMs) {
|
||||
assertThat(isEnabled).isTrue();
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user