From 8e6daec9559b02b04d5109b0a45e44eef52d49ed Mon Sep 17 00:00:00 2001 From: kimvde Date: Tue, 27 Dec 2022 09:38:51 +0000 Subject: [PATCH] Remove mentions of player in TransformationException PiperOrigin-RevId: 497921432 --- .../exoplayer2/transformer/AssetLoader.java | 2 +- .../transformer/ExoPlayerAssetLoader.java | 19 ++++++--- .../ExoPlayerAssetLoaderRenderer.java | 2 +- .../transformer/TransformationException.java | 42 +++++++------------ .../transformer/TransformerInternal.java | 21 +++------- .../transformer/ExoPlayerAssetLoaderTest.java | 2 +- 6 files changed, 37 insertions(+), 51 deletions(-) diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/AssetLoader.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/AssetLoader.java index 4588cfc4dd..15e2b13e04 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/AssetLoader.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/AssetLoader.java @@ -171,7 +171,7 @@ public interface AssetLoader { * Called if an error occurs in the asset loader. In this case, the asset loader will be * {@linkplain #release() released} automatically. */ - void onError(Exception e); + void onTransformationError(TransformationException exception); } /** diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoader.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoader.java index c8fb3f7c71..a534f84de3 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoader.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoader.java @@ -20,11 +20,13 @@ import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_BUFFER_FO import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS; import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_MAX_BUFFER_MS; import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; -import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_FAILED_RUNTIME_CHECK; +import static com.google.android.exoplayer2.transformer.TransformationException.ERROR_CODE_FAILED_RUNTIME_CHECK; +import static com.google.android.exoplayer2.transformer.TransformationException.ERROR_CODE_UNSPECIFIED; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_AVAILABLE; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_UNAVAILABLE; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_WAITING_FOR_AVAILABILITY; +import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static java.lang.Math.min; @@ -349,10 +351,9 @@ public final class ExoPlayerAssetLoader implements AssetLoader { trackCount++; } if (trackCount == 0) { - assetLoaderListener.onError( - new PlaybackException( - "The asset loader has no track to output.", - /* cause= */ null, + assetLoaderListener.onTransformationError( + TransformationException.createForAssetLoader( + new IllegalStateException("The asset loader has no track to output."), ERROR_CODE_FAILED_RUNTIME_CHECK)); return; } else { @@ -365,7 +366,13 @@ public final class ExoPlayerAssetLoader implements AssetLoader { @Override public void onPlayerError(PlaybackException error) { - assetLoaderListener.onError(error); + @TransformationException.ErrorCode + int errorCode = + checkNotNull( + TransformationException.NAME_TO_ERROR_CODE.getOrDefault( + error.getErrorCodeName(), ERROR_CODE_UNSPECIFIED)); + assetLoaderListener.onTransformationError( + TransformationException.createForAssetLoader(error, errorCode)); } } } diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoaderRenderer.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoaderRenderer.java index 52b9a0b33f..f6eaa5e132 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoaderRenderer.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoaderRenderer.java @@ -119,7 +119,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; } } catch (TransformationException e) { isTransformationRunning = false; - assetLoaderListener.onError(e); + assetLoaderListener.onTransformationError(e); } } diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationException.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationException.java index 9adb978738..036b246bef 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationException.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationException.java @@ -23,7 +23,6 @@ import android.os.SystemClock; import androidx.annotation.IntDef; import androidx.annotation.Nullable; import com.google.android.exoplayer2.Format; -import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat; import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.FrameProcessingException; @@ -107,8 +106,8 @@ public final class TransformationException extends Exception { /** * Caused by a server returning a resource with an invalid "Content-Type" HTTP header value. * - *

For example, this can happen when the player is expecting a piece of media, but the server - * returns a paywall HTML page, with content type "text/html". + *

For example, this can happen when the {@link AssetLoader} is expecting a piece of media, but + * the server returns a paywall HTML page, with content type "text/html". */ public static final int ERROR_CODE_IO_INVALID_HTTP_CONTENT_TYPE = 2003; /** Caused by an HTTP server returning an unexpected HTTP response status code. */ @@ -121,8 +120,8 @@ public final class TransformationException extends Exception { */ public static final int ERROR_CODE_IO_NO_PERMISSION = 2006; /** - * Caused by the player trying to access cleartext HTTP traffic (meaning http:// rather than - * https://) when the app's Network Security Configuration does not permit it. + * Caused by the {@link AssetLoader} trying to access cleartext HTTP traffic (meaning http:// + * rather than https://) when the app's Network Security Configuration does not permit it. */ public static final int ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED = 2007; /** Caused by reading data out of the data bound. */ @@ -170,7 +169,7 @@ public final class TransformationException extends Exception { /** Caused by a failure while muxing media samples. */ public static final int ERROR_CODE_MUXING_FAILED = 7001; - private static final ImmutableBiMap NAME_TO_ERROR_CODE = + /* package */ static final ImmutableBiMap NAME_TO_ERROR_CODE = new ImmutableBiMap.Builder() .put("ERROR_CODE_FAILED_RUNTIME_CHECK", ERROR_CODE_FAILED_RUNTIME_CHECK) .put("ERROR_CODE_IO_UNSPECIFIED", ERROR_CODE_IO_UNSPECIFIED) @@ -195,11 +194,6 @@ public final class TransformationException extends Exception { .put("ERROR_CODE_MUXING_FAILED", ERROR_CODE_MUXING_FAILED) .buildOrThrow(); - /** Returns the {@code errorCode} for a given name. */ - private static @ErrorCode int getErrorCodeForName(String errorCodeName) { - return NAME_TO_ERROR_CODE.getOrDefault(errorCodeName, ERROR_CODE_UNSPECIFIED); - } - /** Returns the name of a given {@code errorCode}. */ public static String getErrorCodeName(@ErrorCode int errorCode) { return NAME_TO_ERROR_CODE.inverse().getOrDefault(errorCode, "invalid error code"); @@ -213,6 +207,17 @@ public final class TransformationException extends Exception { return getErrorCodeName(errorCode); } + /** + * Creates an instance for an {@link AssetLoader} related exception. + * + * @param cause The cause of the failure. + * @param errorCode See {@link #errorCode}. + * @return The created instance. + */ + public static TransformationException createForAssetLoader(Throwable cause, int errorCode) { + return new TransformationException("Asset loader error", cause, errorCode); + } + /** * Creates an instance for a decoder or encoder related exception. * @@ -322,21 +327,6 @@ public final class TransformationException extends Exception { return new TransformationException("Unexpected error", cause, ERROR_CODE_UNSPECIFIED); } - /** - * Creates an instance for a {@link PlaybackException}. - * - *

If there is a corresponding {@link TransformationException.ErrorCode} for the {@link - * PlaybackException.ErrorCode}, this error code and the same message are used for the created - * instance. Otherwise, this is equivalent to {@link #createForUnexpected(Exception)}. - */ - /* package */ static TransformationException createForPlaybackException( - PlaybackException exception) { - @ErrorCode int errorCode = getErrorCodeForName(exception.getErrorCodeName()); - return errorCode == ERROR_CODE_UNSPECIFIED - ? createForUnexpected(exception) - : new TransformationException(exception.getMessage(), exception, errorCode); - } - /** An error code which identifies the cause of the transformation failure. */ public final @ErrorCode int errorCode; diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java index ef5ef719a7..42f9b22fdd 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java @@ -18,6 +18,7 @@ package com.google.android.exoplayer2.transformer; import static com.google.android.exoplayer2.transformer.AssetLoader.SUPPORTED_OUTPUT_TYPE_DECODED; import static com.google.android.exoplayer2.transformer.AssetLoader.SUPPORTED_OUTPUT_TYPE_ENCODED; +import static com.google.android.exoplayer2.transformer.TransformationException.ERROR_CODE_FAILED_RUNTIME_CHECK; import static com.google.android.exoplayer2.transformer.TransformationException.ERROR_CODE_MUXING_FAILED; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED; import static com.google.android.exoplayer2.util.Assertions.checkState; @@ -33,7 +34,6 @@ import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.MediaItem; -import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.audio.AudioProcessor; import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.metadata.Metadata; @@ -397,7 +397,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @Override public void onTrackCount(int trackCount) { if (trackCount <= 0) { - onError(new IllegalStateException("AssetLoader instances must provide at least 1 track.")); + onTransformationError( + TransformationException.createForAssetLoader( + new IllegalStateException("AssetLoader instances must provide at least 1 track."), + ERROR_CODE_FAILED_RUNTIME_CHECK)); return; } this.trackCount.set(trackCount); @@ -450,20 +453,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; return new SamplePipelineInput(samplePipelineIndex, samplePipeline.expectsDecodedData()); } - @Override - public void onError(Exception e) { - TransformationException transformationException; - if (e instanceof TransformationException) { - transformationException = (TransformationException) e; - } else if (e instanceof PlaybackException) { - transformationException = - TransformationException.createForPlaybackException((PlaybackException) e); - } else { - transformationException = TransformationException.createForUnexpected(e); - } - onTransformationError(transformationException); - } - // MuxerWrapper.Listener implementation. @Override diff --git a/library/transformer/src/test/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoaderTest.java b/library/transformer/src/test/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoaderTest.java index 9d1068c732..c920cbef83 100644 --- a/library/transformer/src/test/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoaderTest.java +++ b/library/transformer/src/test/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoaderTest.java @@ -85,7 +85,7 @@ public class ExoPlayerAssetLoaderTest { } @Override - public void onError(Exception e) { + public void onTransformationError(TransformationException e) { exceptionRef.set(e); }