mirror of
https://github.com/androidx/media.git
synced 2025-05-04 14:10:40 +08:00
Remove mentions of player in TransformationException
PiperOrigin-RevId: 497921432
This commit is contained in:
parent
967e44c066
commit
8e6daec955
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
}
|
||||
} catch (TransformationException e) {
|
||||
isTransformationRunning = false;
|
||||
assetLoaderListener.onError(e);
|
||||
assetLoaderListener.onTransformationError(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
* <p>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".
|
||||
* <p>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<String, @ErrorCode Integer> NAME_TO_ERROR_CODE =
|
||||
/* package */ static final ImmutableBiMap<String, @ErrorCode Integer> NAME_TO_ERROR_CODE =
|
||||
new ImmutableBiMap.Builder<String, @ErrorCode Integer>()
|
||||
.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}.
|
||||
*
|
||||
* <p>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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -85,7 +85,7 @@ public class ExoPlayerAssetLoaderTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
public void onTransformationError(TransformationException e) {
|
||||
exceptionRef.set(e);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user