Commit ee0d905e by claincly Committed by kim-vde

Add ERROR_CODE_TIMEOUT.

Also remove the method for creating a TYPE_RENDERER ExoPlaybackException
with unknown renderer name and index.

PiperOrigin-RevId: 382589655
parent dda1d373
...@@ -46,6 +46,7 @@ public class PlaybackException extends Exception implements Bundleable { ...@@ -46,6 +46,7 @@ public class PlaybackException extends Exception implements Bundleable {
ERROR_CODE_UNSPECIFIED, ERROR_CODE_UNSPECIFIED,
ERROR_CODE_REMOTE_ERROR, ERROR_CODE_REMOTE_ERROR,
ERROR_CODE_BEHIND_LIVE_WINDOW, ERROR_CODE_BEHIND_LIVE_WINDOW,
ERROR_CODE_TIMEOUT,
ERROR_CODE_IO_UNSPECIFIED, ERROR_CODE_IO_UNSPECIFIED,
ERROR_CODE_IO_NETWORK_UNAVAILABLE, ERROR_CODE_IO_NETWORK_UNAVAILABLE,
ERROR_CODE_IO_NETWORK_CONNECTION_FAILED, ERROR_CODE_IO_NETWORK_CONNECTION_FAILED,
...@@ -89,6 +90,8 @@ public class PlaybackException extends Exception implements Bundleable { ...@@ -89,6 +90,8 @@ public class PlaybackException extends Exception implements Bundleable {
public static final int ERROR_CODE_REMOTE_ERROR = 1001; public static final int ERROR_CODE_REMOTE_ERROR = 1001;
/** Caused by the loading position falling behind the sliding window of available live content. */ /** Caused by the loading position falling behind the sliding window of available live content. */
public static final int ERROR_CODE_BEHIND_LIVE_WINDOW = 1002; 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). // Input/Output errors (2xxx).
...@@ -199,6 +202,8 @@ public class PlaybackException extends Exception implements Bundleable { ...@@ -199,6 +202,8 @@ public class PlaybackException extends Exception implements Bundleable {
return "ERROR_CODE_REMOTE_ERROR"; return "ERROR_CODE_REMOTE_ERROR";
case ERROR_CODE_BEHIND_LIVE_WINDOW: case ERROR_CODE_BEHIND_LIVE_WINDOW:
return "ERROR_CODE_BEHIND_LIVE_WINDOW"; return "ERROR_CODE_BEHIND_LIVE_WINDOW";
case ERROR_CODE_TIMEOUT:
return "ERROR_CODE_TIMEOUT";
case ERROR_CODE_IO_UNSPECIFIED: case ERROR_CODE_IO_UNSPECIFIED:
return "ERROR_CODE_IO_UNSPECIFIED"; return "ERROR_CODE_IO_UNSPECIFIED";
case ERROR_CODE_IO_NETWORK_UNAVAILABLE: case ERROR_CODE_IO_NETWORK_UNAVAILABLE:
......
...@@ -60,10 +60,12 @@ public class ExoPlaybackExceptionTest { ...@@ -60,10 +60,12 @@ public class ExoPlaybackExceptionTest {
@Test @Test
public void public void
roundTripViaBundle_ofExoPlaybackExceptionTypeRendererWithPrivateCause_yieldsRemoteExceptionWithSameMessage() { roundTripViaBundle_ofExoPlaybackExceptionTypeUnexpectedWithPrivateCause_yieldsRemoteExceptionWithSameMessage() {
ExoPlaybackException before = ExoPlaybackException before =
ExoPlaybackException.createForRenderer( ExoPlaybackException.createForUnexpected(
new Exception(/* message= */ "anonymous exception that class loader cannot know") {}); new RuntimeException(
/* message= */ "anonymous exception that class loader cannot know") {},
PlaybackException.ERROR_CODE_TIMEOUT);
ExoPlaybackException after = ExoPlaybackException.CREATOR.fromBundle(before.toBundle()); ExoPlaybackException after = ExoPlaybackException.CREATOR.fromBundle(before.toBundle());
assertThat(after.getCause()).isInstanceOf(RemoteException.class); assertThat(after.getCause()).isInstanceOf(RemoteException.class);
......
...@@ -71,16 +71,10 @@ public final class ExoPlaybackException extends PlaybackException { ...@@ -71,16 +71,10 @@ public final class ExoPlaybackException extends PlaybackException {
/** The {@link Type} of the playback failure. */ /** The {@link Type} of the playback failure. */
@Type public final int type; @Type public final int type;
/** /** If {@link #type} is {@link #TYPE_RENDERER}, this is the name of the renderer. */
* If {@link #type} is {@link #TYPE_RENDERER}, this is the name of the renderer, or null if
* unknown.
*/
@Nullable public final String rendererName; @Nullable public final String rendererName;
/** /** If {@link #type} is {@link #TYPE_RENDERER}, this is the index of the renderer. */
* If {@link #type} is {@link #TYPE_RENDERER}, this is the index of the renderer, or {@link
* C#INDEX_UNSET} if unknown.
*/
public final int rendererIndex; public final int rendererIndex;
/** /**
...@@ -128,26 +122,8 @@ public final class ExoPlaybackException extends PlaybackException { ...@@ -128,26 +122,8 @@ public final class ExoPlaybackException extends PlaybackException {
} }
/** /**
* Creates an instance of type {@link #TYPE_RENDERER} for an unknown 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.
* @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}.
* *
* @param cause The cause of the failure. * @param cause The cause of the failure.
* @param rendererIndex The index of the renderer in which the failure occurred. * @param rendererIndex The index of the renderer in which the failure occurred.
...@@ -208,13 +184,24 @@ public final class ExoPlaybackException extends PlaybackException { ...@@ -208,13 +184,24 @@ public final class ExoPlaybackException extends PlaybackException {
} }
/** /**
* @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}. * Creates an instance of type {@link #TYPE_UNEXPECTED}.
* *
* @param cause The cause of the failure. * @param cause The cause of the failure.
* @param errorCode See {@link #errorCode}.
* @return The created instance. * @return The created instance.
*/ */
public static ExoPlaybackException createForUnexpected(RuntimeException cause) { public static ExoPlaybackException createForUnexpected(
return new ExoPlaybackException(TYPE_UNEXPECTED, cause, ERROR_CODE_UNSPECIFIED); RuntimeException cause, @ErrorCode int errorCode) {
return new ExoPlaybackException(TYPE_UNEXPECTED, cause, errorCode);
} }
/** /**
......
...@@ -804,9 +804,9 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -804,9 +804,9 @@ import java.util.concurrent.CopyOnWriteArraySet;
// One of the renderers timed out releasing its resources. // One of the renderers timed out releasing its resources.
stop( stop(
/* reset= */ false, /* reset= */ false,
ExoPlaybackException.createForRenderer( ExoPlaybackException.createForUnexpected(
new ExoTimeoutException( new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_SET_FOREGROUND_MODE),
ExoTimeoutException.TIMEOUT_OPERATION_SET_FOREGROUND_MODE))); PlaybackException.ERROR_CODE_TIMEOUT));
} }
} }
} }
...@@ -873,8 +873,9 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -873,8 +873,9 @@ import java.util.concurrent.CopyOnWriteArraySet;
Player.EVENT_PLAYER_ERROR, Player.EVENT_PLAYER_ERROR,
listener -> listener ->
listener.onPlayerError( listener.onPlayerError(
ExoPlaybackException.createForRenderer( ExoPlaybackException.createForUnexpected(
new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_RELEASE)))); new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_RELEASE),
PlaybackException.ERROR_CODE_TIMEOUT)));
} }
listeners.release(); listeners.release();
playbackInfoUpdateHandler.removeCallbacksAndMessages(null); playbackInfoUpdateHandler.removeCallbacksAndMessages(null);
......
...@@ -21,7 +21,7 @@ import java.lang.annotation.Retention; ...@@ -21,7 +21,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
/** A timeout of an operation on the ExoPlayer playback thread. */ /** 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}, * The operation which produced the timeout error. One of {@link #TIMEOUT_OPERATION_RELEASE},
......
...@@ -1953,8 +1953,9 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -1953,8 +1953,9 @@ public class SimpleExoPlayer extends BasePlayer
// One of the renderers timed out releasing its resources. // One of the renderers timed out releasing its resources.
player.stop( player.stop(
/* reset= */ false, /* reset= */ false,
ExoPlaybackException.createForRenderer( ExoPlaybackException.createForUnexpected(
new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_DETACH_SURFACE))); new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_DETACH_SURFACE),
PlaybackException.ERROR_CODE_TIMEOUT));
} }
if (this.videoOutput == ownedSurface) { if (this.videoOutput == ownedSurface) {
// We're replacing a surface that we are responsible for releasing. // We're replacing a surface that we are responsible for releasing.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment