From ee0d905eed1067d1721c26da684849eb2868a601 Mon Sep 17 00:00:00 2001 From: claincly Date: Thu, 1 Jul 2021 21:11:27 +0100 Subject: [PATCH] Add ERROR_CODE_TIMEOUT. Also remove the method for creating a TYPE_RENDERER ExoPlaybackException with unknown renderer name and index. PiperOrigin-RevId: 382589655 --- .../android/exoplayer2/PlaybackException.java | 5 ++ .../exoplayer2/ExoPlaybackExceptionTest.java | 8 ++-- .../exoplayer2/ExoPlaybackException.java | 47 +++++++------------ .../android/exoplayer2/ExoPlayerImpl.java | 11 +++-- .../exoplayer2/ExoTimeoutException.java | 2 +- .../android/exoplayer2/SimpleExoPlayer.java | 5 +- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java b/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java index fbd8e55739..1a5eaecc75 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java @@ -46,6 +46,7 @@ public class PlaybackException extends Exception implements Bundleable { ERROR_CODE_UNSPECIFIED, ERROR_CODE_REMOTE_ERROR, ERROR_CODE_BEHIND_LIVE_WINDOW, + ERROR_CODE_TIMEOUT, ERROR_CODE_IO_UNSPECIFIED, ERROR_CODE_IO_NETWORK_UNAVAILABLE, ERROR_CODE_IO_NETWORK_CONNECTION_FAILED, @@ -89,6 +90,8 @@ public class PlaybackException extends Exception implements Bundleable { public static final int ERROR_CODE_REMOTE_ERROR = 1001; /** Caused by the loading position falling behind the sliding window of available live content. */ public static final int ERROR_CODE_BEHIND_LIVE_WINDOW = 1002; + /** Caused by a generic timeout. */ + public static final int ERROR_CODE_TIMEOUT = 1003; // Input/Output errors (2xxx). @@ -199,6 +202,8 @@ public class PlaybackException extends Exception implements Bundleable { return "ERROR_CODE_REMOTE_ERROR"; case ERROR_CODE_BEHIND_LIVE_WINDOW: return "ERROR_CODE_BEHIND_LIVE_WINDOW"; + case ERROR_CODE_TIMEOUT: + return "ERROR_CODE_TIMEOUT"; case ERROR_CODE_IO_UNSPECIFIED: return "ERROR_CODE_IO_UNSPECIFIED"; case ERROR_CODE_IO_NETWORK_UNAVAILABLE: diff --git a/library/common/src/test/java/com/google/android/exoplayer2/ExoPlaybackExceptionTest.java b/library/common/src/test/java/com/google/android/exoplayer2/ExoPlaybackExceptionTest.java index b5b8e2a7b9..3ebc7bbcbc 100644 --- a/library/common/src/test/java/com/google/android/exoplayer2/ExoPlaybackExceptionTest.java +++ b/library/common/src/test/java/com/google/android/exoplayer2/ExoPlaybackExceptionTest.java @@ -60,10 +60,12 @@ public class ExoPlaybackExceptionTest { @Test public void - roundTripViaBundle_ofExoPlaybackExceptionTypeRendererWithPrivateCause_yieldsRemoteExceptionWithSameMessage() { + roundTripViaBundle_ofExoPlaybackExceptionTypeUnexpectedWithPrivateCause_yieldsRemoteExceptionWithSameMessage() { ExoPlaybackException before = - ExoPlaybackException.createForRenderer( - new Exception(/* message= */ "anonymous exception that class loader cannot know") {}); + ExoPlaybackException.createForUnexpected( + new RuntimeException( + /* message= */ "anonymous exception that class loader cannot know") {}, + PlaybackException.ERROR_CODE_TIMEOUT); ExoPlaybackException after = ExoPlaybackException.CREATOR.fromBundle(before.toBundle()); assertThat(after.getCause()).isInstanceOf(RemoteException.class); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java index 291fce21cd..ab749375a4 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java @@ -71,16 +71,10 @@ public final class ExoPlaybackException extends PlaybackException { /** The {@link Type} of the playback failure. */ @Type public final int type; - /** - * If {@link #type} is {@link #TYPE_RENDERER}, this is the name of the renderer, or null if - * unknown. - */ + /** If {@link #type} is {@link #TYPE_RENDERER}, this is the name of the renderer. */ @Nullable public final String rendererName; - /** - * If {@link #type} is {@link #TYPE_RENDERER}, this is the index of the renderer, or {@link - * C#INDEX_UNSET} if unknown. - */ + /** If {@link #type} is {@link #TYPE_RENDERER}, this is the index of the renderer. */ public final int rendererIndex; /** @@ -128,26 +122,8 @@ public final class ExoPlaybackException extends PlaybackException { } /** - * Creates an instance of type {@link #TYPE_RENDERER} for an unknown renderer. - * - * @param cause The cause of the failure. - * @return The created instance. - */ - public static ExoPlaybackException createForRenderer(Exception cause) { - return new ExoPlaybackException( - TYPE_RENDERER, - cause, - /* customMessage= */ null, - ERROR_CODE_UNSPECIFIED, - /* rendererName */ null, - /* rendererIndex= */ C.INDEX_UNSET, - /* rendererFormat= */ null, - /* rendererFormatSupport= */ C.FORMAT_HANDLED, - /* isRecoverable= */ false); - } - - /** - * Creates an instance of type {@link #TYPE_RENDERER}. + * Creates an instance of type {@link #TYPE_RENDERER} in which {@link #isRecoverable} is {@code + * false} and {@link #errorCode} is {@link #ERROR_CODE_UNSPECIFIED}. * * @param cause The cause of the failure. * @param rendererIndex The index of the renderer in which the failure occurred. @@ -207,14 +183,25 @@ public final class ExoPlaybackException extends PlaybackException { isRecoverable); } + /** + * @deprecated Use {@link #createForUnexpected(RuntimeException, int) + * createForUnexpected(RuntimeException, ERROR_CODE_UNSPECIFIED)} instead. + */ + @Deprecated + public static ExoPlaybackException createForUnexpected(RuntimeException cause) { + return createForUnexpected(cause, ERROR_CODE_UNSPECIFIED); + } + /** * Creates an instance of type {@link #TYPE_UNEXPECTED}. * * @param cause The cause of the failure. + * @param errorCode See {@link #errorCode}. * @return The created instance. */ - public static ExoPlaybackException createForUnexpected(RuntimeException cause) { - return new ExoPlaybackException(TYPE_UNEXPECTED, cause, ERROR_CODE_UNSPECIFIED); + public static ExoPlaybackException createForUnexpected( + RuntimeException cause, @ErrorCode int errorCode) { + return new ExoPlaybackException(TYPE_UNEXPECTED, cause, errorCode); } /** diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java index 0745e8af81..d86cd8860e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java @@ -804,9 +804,9 @@ import java.util.concurrent.CopyOnWriteArraySet; // One of the renderers timed out releasing its resources. stop( /* reset= */ false, - ExoPlaybackException.createForRenderer( - new ExoTimeoutException( - ExoTimeoutException.TIMEOUT_OPERATION_SET_FOREGROUND_MODE))); + ExoPlaybackException.createForUnexpected( + new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_SET_FOREGROUND_MODE), + PlaybackException.ERROR_CODE_TIMEOUT)); } } } @@ -873,8 +873,9 @@ import java.util.concurrent.CopyOnWriteArraySet; Player.EVENT_PLAYER_ERROR, listener -> listener.onPlayerError( - ExoPlaybackException.createForRenderer( - new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_RELEASE)))); + ExoPlaybackException.createForUnexpected( + new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_RELEASE), + PlaybackException.ERROR_CODE_TIMEOUT))); } listeners.release(); playbackInfoUpdateHandler.removeCallbacksAndMessages(null); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoTimeoutException.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoTimeoutException.java index c35f6fa95e..dbc86bdb3d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoTimeoutException.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoTimeoutException.java @@ -21,7 +21,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** A timeout of an operation on the ExoPlayer playback thread. */ -public final class ExoTimeoutException extends Exception { +public final class ExoTimeoutException extends RuntimeException { /** * The operation which produced the timeout error. One of {@link #TIMEOUT_OPERATION_RELEASE}, diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java index 9b6cf5f3c6..72ce6c3ed7 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java @@ -1953,8 +1953,9 @@ public class SimpleExoPlayer extends BasePlayer // One of the renderers timed out releasing its resources. player.stop( /* reset= */ false, - ExoPlaybackException.createForRenderer( - new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_DETACH_SURFACE))); + ExoPlaybackException.createForUnexpected( + new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_DETACH_SURFACE), + PlaybackException.ERROR_CODE_TIMEOUT)); } if (this.videoOutput == ownedSurface) { // We're replacing a surface that we are responsible for releasing.