From b30e2b961f67252d1f30e51ab0e83799c5e6fb31 Mon Sep 17 00:00:00 2001 From: kimvde Date: Mon, 6 Jul 2020 09:09:44 +0100 Subject: [PATCH] Rename some white/blacklist occurrences in core library ISSUE: #7565 PiperOrigin-RevId: 319734842 --- .../source/chunk/ChunkSampleStream.java | 4 +-- .../exoplayer2/source/chunk/ChunkSource.java | 6 ++-- .../AdaptiveTrackSelection.java | 8 ++--- .../trackselection/BaseTrackSelection.java | 28 ++++++++--------- .../trackselection/RandomTrackSelection.java | 16 +++++----- .../trackselection/TrackSelection.java | 14 ++++----- .../DefaultLoadErrorHandlingPolicy.java | 7 +++-- .../upstream/LoadErrorHandlingPolicy.java | 30 +++++++++---------- .../DefaultLoadErrorHandlingPolicyTest.java | 18 +++++------ .../source/dash/DefaultDashChunkSource.java | 6 ++-- .../smoothstreaming/DefaultSsChunkSource.java | 6 ++-- .../exoplayer2/testutil/FakeChunkSource.java | 2 +- .../testutil/FakeTrackSelection.java | 2 +- 13 files changed, 72 insertions(+), 75 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java index 0e193a1a2a..155c51eca3 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java @@ -489,12 +489,12 @@ public class ChunkSampleStream 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) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSource.java index f32f5debfe..e05dab69d3 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSource.java @@ -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); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java index 8b2bd4581c..e88de430b7 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java @@ -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) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/BaseTrackSelection.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/BaseTrackSelection.java index dc0b3f6747..0fe001df0a 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/BaseTrackSelection.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/BaseTrackSelection.java @@ -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. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/RandomTrackSelection.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/RandomTrackSelection.java index f35e7ec755..4b9b72715a 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/RandomTrackSelection.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/RandomTrackSelection.java @@ -102,21 +102,21 @@ public final class RandomTrackSelection extends BaseTrackSelection { long availableDurationUs, List 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; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelection.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelection.java index 1b92a37f54..5e703438f8 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelection.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelection.java @@ -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. * - *

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 + *

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[])}. * *

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); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicy.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicy.java index b623d7bfe1..2afbe417d4 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicy.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicy.java @@ -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) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoadErrorHandlingPolicy.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoadErrorHandlingPolicy.java index 9705437419..0102ea7871 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoadErrorHandlingPolicy.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoadErrorHandlingPolicy.java @@ -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. * - *

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. + *

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. * - *

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)}. + *

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)}. * *

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. * - *

{@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}. + *

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 diff --git a/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java b/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java index 28ae4f748f..4adeab560a 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java @@ -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, diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java index 7328a2992a..ff62aabef2 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java @@ -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. diff --git a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/DefaultSsChunkSource.java b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/DefaultSsChunkSource.java index 10e725fb58..c7df39033b 100644 --- a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/DefaultSsChunkSource.java +++ b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/DefaultSsChunkSource.java @@ -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. diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeChunkSource.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeChunkSource.java index 24a6efb670..844823205a 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeChunkSource.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeChunkSource.java @@ -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; } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelection.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelection.java index 5e034058a0..be78616e8e 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelection.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelection.java @@ -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; }