From b84a9bed2caade60a06ac5b91bd66a5f3af6449d Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Tue, 12 Nov 2019 11:36:29 +0000 Subject: [PATCH] Add a parameter object for LoadErrorHandlingPolicy methods PiperOrigin-RevId: 279928178 --- .../upstream/LoadErrorHandlingPolicy.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) 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 293d1e7510..68ab2a7a47 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 @@ -38,6 +38,30 @@ import java.io.IOException; */ public interface LoadErrorHandlingPolicy { + /** Holds information about a load task error. */ + final class LoadErrorInfo { + + /** One of the {@link C C.DATA_TYPE_*} constants indicating the type of data to load. */ + public final int dataType; + /** + * The duration in milliseconds of the load from the start of the first load attempt up to the + * point at which the error occurred. + */ + public final long loadDurationMs; + /** The exception associated to the load error. */ + public final IOException exception; + /** The number of errors this load task has encountered, including this one. */ + public final int errorCount; + + /** Creates an instance with the given values. */ + public LoadErrorInfo(int dataType, long loadDurationMs, IOException exception, int errorCount) { + this.dataType = dataType; + this.loadDurationMs = loadDurationMs; + this.exception = exception; + this.errorCount = errorCount; + } + } + /** * 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. @@ -54,6 +78,22 @@ public interface LoadErrorHandlingPolicy { long getBlacklistDurationMsFor( int dataType, long loadDurationMs, IOException exception, int errorCount); + /** + * 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. + * + * @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. + */ + default long getBlacklistDurationMsFor(LoadErrorInfo loadErrorInfo) { + return getBlacklistDurationMsFor( + loadErrorInfo.dataType, + loadErrorInfo.loadDurationMs, + loadErrorInfo.exception, + loadErrorInfo.errorCount); + } + /** * 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. @@ -73,6 +113,26 @@ public interface LoadErrorHandlingPolicy { */ long getRetryDelayMsFor(int dataType, long loadDurationMs, IOException exception, int errorCount); + /** + * 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}. + * + * @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 + * C#TIME_UNSET} if the error is fatal and should not be retried. + */ + default long getRetryDelayMsFor(LoadErrorInfo loadErrorInfo) { + return getRetryDelayMsFor( + loadErrorInfo.dataType, + loadErrorInfo.loadDurationMs, + loadErrorInfo.exception, + loadErrorInfo.errorCount); + } + /** * Returns the minimum number of times to retry a load in the case of a load error, before * propagating the error.