Rename some white/blacklist occurrences in core library

ISSUE: #7565
PiperOrigin-RevId: 319734842
This commit is contained in:
kimvde 2020-07-06 09:09:44 +01:00 committed by Ian Baker
parent 6872910d5a
commit b30e2b961f
13 changed files with 72 additions and 75 deletions

View File

@ -489,12 +489,12 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
LoadErrorInfo loadErrorInfo = LoadErrorInfo loadErrorInfo =
new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount); new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount);
long blacklistDurationMs = long exclusionDurationMs =
cancelable cancelable
? loadErrorHandlingPolicy.getBlacklistDurationMsFor(loadErrorInfo) ? loadErrorHandlingPolicy.getBlacklistDurationMsFor(loadErrorInfo)
: C.TIME_UNSET; : C.TIME_UNSET;
@Nullable LoadErrorAction loadErrorAction = null; @Nullable LoadErrorAction loadErrorAction = null;
if (chunkSource.onChunkLoadError(loadable, cancelable, error, blacklistDurationMs)) { if (chunkSource.onChunkLoadError(loadable, cancelable, error, exclusionDurationMs)) {
if (cancelable) { if (cancelable) {
loadErrorAction = Loader.DONT_RETRY; loadErrorAction = Loader.DONT_RETRY;
if (isMediaChunk) { if (isMediaChunk) {

View File

@ -96,12 +96,12 @@ public interface ChunkSource {
* @param chunk The chunk whose load encountered the error. * @param chunk The chunk whose load encountered the error.
* @param cancelable Whether the load can be canceled. * @param cancelable Whether the load can be canceled.
* @param e The error. * @param e The error.
* @param blacklistDurationMs The duration for which the associated track may be blacklisted, or * @param exclusionDurationMs The duration for which the associated track may be excluded, or
* {@link C#TIME_UNSET} if the track may not be blacklisted. * {@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. * @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 * 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 * #getNextChunk(long, long, List, ChunkHolder)} will be called to obtain the replacement
* chunk. * chunk.
*/ */
boolean onChunkLoadError(Chunk chunk, boolean cancelable, Exception e, long blacklistDurationMs); boolean onChunkLoadError(Chunk chunk, boolean cancelable, Exception e, long exclusionDurationMs);
} }

View File

@ -569,22 +569,22 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* Computes the ideal selected index ignoring buffer health. * Computes the ideal selected index ignoring buffer health.
* *
* @param nowMs The current time in the timebase of {@link Clock#elapsedRealtime()}, or {@link * @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) { private int determineIdealSelectedIndex(long nowMs) {
long effectiveBitrate = bandwidthProvider.getAllocatedBandwidth(); long effectiveBitrate = bandwidthProvider.getAllocatedBandwidth();
int lowestBitrateNonBlacklistedIndex = 0; int lowestBitrateAllowedIndex = 0;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
if (nowMs == Long.MIN_VALUE || !isBlacklisted(i, nowMs)) { if (nowMs == Long.MIN_VALUE || !isBlacklisted(i, nowMs)) {
Format format = getFormat(i); Format format = getFormat(i);
if (canSelectFormat(format, format.bitrate, playbackSpeed, effectiveBitrate)) { if (canSelectFormat(format, format.bitrate, playbackSpeed, effectiveBitrate)) {
return i; return i;
} else { } else {
lowestBitrateNonBlacklistedIndex = i; lowestBitrateAllowedIndex = i;
} }
} }
} }
return lowestBitrateNonBlacklistedIndex; return lowestBitrateAllowedIndex;
} }
private long minDurationForQualityIncreaseUs(long availableDurationUs) { private long minDurationForQualityIncreaseUs(long availableDurationUs) {

View File

@ -49,10 +49,8 @@ public abstract class BaseTrackSelection implements TrackSelection {
* The {@link Format}s of the selected tracks, in order of decreasing bandwidth. * The {@link Format}s of the selected tracks, in order of decreasing bandwidth.
*/ */
private final Format[] formats; private final Format[] formats;
/** /** Selected track exclusion timestamps, in order of decreasing bandwidth. */
* Selected track blacklist timestamps, in order of decreasing bandwidth. private final long[] excludeUntilTimes;
*/
private final long[] blacklistUntilTimes;
// Lazily initialized hashcode. // Lazily initialized hashcode.
private int hashCode; private int hashCode;
@ -77,7 +75,7 @@ public abstract class BaseTrackSelection implements TrackSelection {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
this.tracks[i] = group.indexOf(formats[i]); this.tracks[i] = group.indexOf(formats[i]);
} }
blacklistUntilTimes = new long[length]; excludeUntilTimes = new long[length];
} }
@Override @Override
@ -152,30 +150,30 @@ public abstract class BaseTrackSelection implements TrackSelection {
} }
@Override @Override
public final boolean blacklist(int index, long blacklistDurationMs) { public final boolean blacklist(int index, long exclusionDurationMs) {
long nowMs = SystemClock.elapsedRealtime(); long nowMs = SystemClock.elapsedRealtime();
boolean canBlacklist = isBlacklisted(index, nowMs); boolean canExclude = isBlacklisted(index, nowMs);
for (int i = 0; i < length && !canBlacklist; i++) { for (int i = 0; i < length && !canExclude; i++) {
canBlacklist = i != index && !isBlacklisted(i, nowMs); canExclude = i != index && !isBlacklisted(i, nowMs);
} }
if (!canBlacklist) { if (!canExclude) {
return false; return false;
} }
blacklistUntilTimes[index] = excludeUntilTimes[index] =
Math.max( Math.max(
blacklistUntilTimes[index], excludeUntilTimes[index],
Util.addWithOverflowDefault(nowMs, blacklistDurationMs, Long.MAX_VALUE)); Util.addWithOverflowDefault(nowMs, exclusionDurationMs, Long.MAX_VALUE));
return true; 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 index The index of the track in the selection.
* @param nowMs The current time in the timebase of {@link SystemClock#elapsedRealtime()}. * @param nowMs The current time in the timebase of {@link SystemClock#elapsedRealtime()}.
*/ */
protected final boolean isBlacklisted(int index, long nowMs) { protected final boolean isBlacklisted(int index, long nowMs) {
return blacklistUntilTimes[index] > nowMs; return excludeUntilTimes[index] > nowMs;
} }
// Object overrides. // Object overrides.

View File

@ -102,21 +102,21 @@ public final class RandomTrackSelection extends BaseTrackSelection {
long availableDurationUs, long availableDurationUs,
List<? extends MediaChunk> queue, List<? extends MediaChunk> queue,
MediaChunkIterator[] mediaChunkIterators) { MediaChunkIterator[] mediaChunkIterators) {
// Count the number of non-blacklisted formats. // Count the number of allowed formats.
long nowMs = SystemClock.elapsedRealtime(); long nowMs = SystemClock.elapsedRealtime();
int nonBlacklistedFormatCount = 0; int allowedFormatCount = 0;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
if (!isBlacklisted(i, nowMs)) { if (!isBlacklisted(i, nowMs)) {
nonBlacklistedFormatCount++; allowedFormatCount++;
} }
} }
selectedIndex = random.nextInt(nonBlacklistedFormatCount); selectedIndex = random.nextInt(allowedFormatCount);
if (nonBlacklistedFormatCount != length) { if (allowedFormatCount != length) {
// Adjust the format index to account for blacklisted formats. // Adjust the format index to account for excluded formats.
nonBlacklistedFormatCount = 0; allowedFormatCount = 0;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
if (!isBlacklisted(i, nowMs) && selectedIndex == nonBlacklistedFormatCount++) { if (!isBlacklisted(i, nowMs) && selectedIndex == allowedFormatCount++) {
selectedIndex = i; selectedIndex = i;
return; return;
} }

View File

@ -294,20 +294,20 @@ public interface TrackSelection {
} }
/** /**
* Attempts to blacklist the track at the specified index in the selection, making it ineligible * Attempts to exclude the track at the specified index in the selection, making it ineligible for
* for selection by calls to {@link #updateSelectedTrack(long, long, long, List, * selection by calls to {@link #updateSelectedTrack(long, long, long, List,
* MediaChunkIterator[])} for the specified period of time. * MediaChunkIterator[])} for the specified period of time.
* *
* <p>Blacklisting will fail if all other tracks are currently blacklisted. If blacklisting the * <p>Exclusion will fail if all other tracks are currently excluded. If excluding the currently
* currently selected track, note that it will remain selected until the next call to {@link * selected track, note that it will remain selected until the next call to {@link
* #updateSelectedTrack(long, long, long, List, MediaChunkIterator[])}. * #updateSelectedTrack(long, long, long, List, MediaChunkIterator[])}.
* *
* <p>This method will only be called when the selection is enabled. * <p>This method will only be called when the selection is enabled.
* *
* @param index The index of the track in the selection. * @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. * milliseconds.
* @return Whether blacklisting was successful. * @return Whether exclusion was successful.
*/ */
boolean blacklist(int index, long blacklistDurationMs); boolean blacklist(int index, long exclusionDurationMs);
} }

View File

@ -32,7 +32,7 @@ public class DefaultLoadErrorHandlingPolicy implements LoadErrorHandlingPolicy {
* streams. * streams.
*/ */
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT_PROGRESSIVE_LIVE = 6; 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; public static final long DEFAULT_TRACK_BLACKLIST_MS = 60_000;
private static final int DEFAULT_BEHAVIOR_MIN_LOADABLE_RETRY_COUNT = -1; 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 * Returns the exclusion duration, given by {@link #DEFAULT_TRACK_BLACKLIST_MS}, if the load error
* code HTTP 404 or 410. The duration of the blacklisting is {@link #DEFAULT_TRACK_BLACKLIST_MS}. * was an {@link InvalidResponseCodeException} with response code HTTP 404, 410 or 416, or {@link
* C#TIME_UNSET} otherwise.
*/ */
@Override @Override
public long getBlacklistDurationMsFor(LoadErrorInfo loadErrorInfo) { public long getBlacklistDurationMsFor(LoadErrorInfo loadErrorInfo) {

View File

@ -23,18 +23,16 @@ import com.google.android.exoplayer2.upstream.Loader.Loadable;
import java.io.IOException; 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 * <p>A loader that can choose between one of a number of resources can exclude a resource when a
* load errors by loading an alternative resource. Clients do not try blacklisting when a resource * load error occurs. In this case, {@link #getBlacklistDurationMsFor(int, long, IOException, int)}
* does not have an alternative. When a resource does have valid alternatives, {@link * defines whether the resource should be excluded. Exclusion will succeed unless all of the
* #getBlacklistDurationMsFor(int, long, IOException, int)} defines whether the resource should be * alternatives are already excluded.
* blacklisted. Blacklisting will succeed if any of the alternatives is not in the black list.
* *
* <p>When blacklisting does not take place, {@link #getRetryDelayMsFor(int, long, IOException, * <p>When exclusion does not take place, {@link #getRetryDelayMsFor(int, long, IOException, int)}
* int)} defines whether the load is retried. Errors whose load is not retried are propagated. Load * defines whether the load is retried. An error that's not retried will always be propagated. An
* errors whose load is retried are propagated according to {@link * error that is retried will be propagated according to {@link #getMinimumLoadableRetryCount(int)}.
* #getMinimumLoadableRetryCount(int)}.
* *
* <p>Methods are invoked on the playback thread. * <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 * 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. * @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 * @return The exclusion duration in milliseconds, or {@link C#TIME_UNSET} if the resource should
* not be blacklisted. * not be excluded.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
default long getBlacklistDurationMsFor(LoadErrorInfo loadErrorInfo) { 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 * 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. * 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 * <p>Loaders may ignore the retry delay returned by this method in order to wait for a specific
* for a specific event before retrying. However, the load is retried if and only if this method * event before retrying. However, the load is retried if and only if this method does not return
* does not return {@link C#TIME_UNSET}. * {@link C#TIME_UNSET}.
* *
* @param loadErrorInfo A {@link LoadErrorInfo} holding information about the load error. * @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 * @return The number of milliseconds to wait before attempting the load again, or {@link

View File

@ -47,35 +47,35 @@ public final class DefaultLoadErrorHandlingPolicyTest {
new MediaLoadData(/* dataType= */ C.DATA_TYPE_UNKNOWN); new MediaLoadData(/* dataType= */ C.DATA_TYPE_UNKNOWN);
@Test @Test
public void getBlacklistDurationMsFor_blacklist404() { public void getExclusionDurationMsFor_responseCode404() {
InvalidResponseCodeException exception = InvalidResponseCodeException exception =
new InvalidResponseCodeException( new InvalidResponseCodeException(
404, "Not Found", Collections.emptyMap(), new DataSpec(Uri.EMPTY)); 404, "Not Found", Collections.emptyMap(), new DataSpec(Uri.EMPTY));
assertThat(getDefaultPolicyBlacklistOutputFor(exception)) assertThat(getDefaultPolicyExclusionDurationMsFor(exception))
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS); .isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
} }
@Test @Test
public void getBlacklistDurationMsFor_blacklist410() { public void getExclusionDurationMsFor_responseCode410() {
InvalidResponseCodeException exception = InvalidResponseCodeException exception =
new InvalidResponseCodeException( new InvalidResponseCodeException(
410, "Gone", Collections.emptyMap(), new DataSpec(Uri.EMPTY)); 410, "Gone", Collections.emptyMap(), new DataSpec(Uri.EMPTY));
assertThat(getDefaultPolicyBlacklistOutputFor(exception)) assertThat(getDefaultPolicyExclusionDurationMsFor(exception))
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS); .isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
} }
@Test @Test
public void getBlacklistDurationMsFor_dontBlacklistUnexpectedHttpCodes() { public void getExclusionDurationMsFor_dontExcludeUnexpectedHttpCodes() {
InvalidResponseCodeException exception = InvalidResponseCodeException exception =
new InvalidResponseCodeException( new InvalidResponseCodeException(
500, "Internal Server Error", Collections.emptyMap(), new DataSpec(Uri.EMPTY)); 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 @Test
public void getBlacklistDurationMsFor_dontBlacklistUnexpectedExceptions() { public void getExclusionDurationMsFor_dontExcludeUnexpectedExceptions() {
IOException exception = new IOException(); IOException exception = new IOException();
assertThat(getDefaultPolicyBlacklistOutputFor(exception)).isEqualTo(C.TIME_UNSET); assertThat(getDefaultPolicyExclusionDurationMsFor(exception)).isEqualTo(C.TIME_UNSET);
} }
@Test @Test
@ -91,7 +91,7 @@ public final class DefaultLoadErrorHandlingPolicyTest {
assertThat(getDefaultPolicyRetryDelayOutputFor(new IOException(), 9)).isEqualTo(5000); assertThat(getDefaultPolicyRetryDelayOutputFor(new IOException(), 9)).isEqualTo(5000);
} }
private static long getDefaultPolicyBlacklistOutputFor(IOException exception) { private static long getDefaultPolicyExclusionDurationMsFor(IOException exception) {
LoadErrorInfo loadErrorInfo = LoadErrorInfo loadErrorInfo =
new LoadErrorInfo( new LoadErrorInfo(
PLACEHOLDER_LOAD_EVENT_INFO, PLACEHOLDER_LOAD_EVENT_INFO,

View File

@ -415,7 +415,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
@Override @Override
public boolean onChunkLoadError( public boolean onChunkLoadError(
Chunk chunk, boolean cancelable, Exception e, long blacklistDurationMs) { Chunk chunk, boolean cancelable, Exception e, long exclusionDurationMs) {
if (!cancelable) { if (!cancelable) {
return false; return false;
} }
@ -438,8 +438,8 @@ public class DefaultDashChunkSource implements DashChunkSource {
} }
} }
} }
return blacklistDurationMs != C.TIME_UNSET return exclusionDurationMs != C.TIME_UNSET
&& trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), blacklistDurationMs); && trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), exclusionDurationMs);
} }
// Internal methods. // Internal methods.

View File

@ -265,10 +265,10 @@ public class DefaultSsChunkSource implements SsChunkSource {
@Override @Override
public boolean onChunkLoadError( public boolean onChunkLoadError(
Chunk chunk, boolean cancelable, Exception e, long blacklistDurationMs) { Chunk chunk, boolean cancelable, Exception e, long exclusionDurationMs) {
return cancelable return cancelable
&& blacklistDurationMs != C.TIME_UNSET && exclusionDurationMs != C.TIME_UNSET
&& trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), blacklistDurationMs); && trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), exclusionDurationMs);
} }
// Private methods. // Private methods.

View File

@ -146,7 +146,7 @@ public final class FakeChunkSource implements ChunkSource {
@Override @Override
public boolean onChunkLoadError( public boolean onChunkLoadError(
Chunk chunk, boolean cancelable, Exception e, long blacklistDurationMs) { Chunk chunk, boolean cancelable, Exception e, long exclusionDurationMs) {
return false; return false;
} }

View File

@ -137,7 +137,7 @@ public final class FakeTrackSelection implements TrackSelection {
} }
@Override @Override
public boolean blacklist(int index, long blacklistDurationMs) { public boolean blacklist(int index, long exclusionDurationMs) {
assertThat(isEnabled).isTrue(); assertThat(isEnabled).isTrue();
return false; return false;
} }