Improve exception message.
We use the `createForCodec` method that does not take a `MediaFormat` during transformation, the error message always includes "no configured MediaFormat", which is false. PiperOrigin-RevId: 429553573
This commit is contained in:
parent
9238dc758d
commit
99074f703a
@ -45,6 +45,9 @@ public final class DefaultCodec implements Codec {
|
||||
private static final int MEDIA_CODEC_PCM_ENCODING = C.ENCODING_PCM_16BIT;
|
||||
|
||||
private final BufferInfo outputBufferInfo;
|
||||
/** The {@link MediaFormat} used to configure the underlying {@link MediaCodec}. */
|
||||
private final MediaFormat configurationMediaFormat;
|
||||
|
||||
private final Format configurationFormat;
|
||||
private final MediaCodec mediaCodec;
|
||||
@Nullable private final Surface inputSurface;
|
||||
@ -63,7 +66,8 @@ public final class DefaultCodec implements Codec {
|
||||
* @param configurationFormat The {@link Format} to configure the {@code DefaultCodec}. See {@link
|
||||
* #getConfigurationFormat()}. The {@link Format#sampleMimeType sampleMimeType} must not be
|
||||
* {@code null}.
|
||||
* @param mediaFormat The {@link MediaFormat} to configure the underlying {@link MediaCodec}.
|
||||
* @param configurationMediaFormat The {@link MediaFormat} to configure the underlying {@link
|
||||
* MediaCodec}.
|
||||
* @param mediaCodecName The name of a specific {@link MediaCodec} to instantiate. If {@code
|
||||
* null}, {@code DefaultCodec} uses {@link Format#sampleMimeType
|
||||
* configurationFormat.sampleMimeType} to create the underlying {@link MediaCodec codec}.
|
||||
@ -72,12 +76,13 @@ public final class DefaultCodec implements Codec {
|
||||
*/
|
||||
public DefaultCodec(
|
||||
Format configurationFormat,
|
||||
MediaFormat mediaFormat,
|
||||
MediaFormat configurationMediaFormat,
|
||||
@Nullable String mediaCodecName,
|
||||
boolean isDecoder,
|
||||
@Nullable Surface outputSurface)
|
||||
throws TransformationException {
|
||||
this.configurationFormat = configurationFormat;
|
||||
this.configurationMediaFormat = configurationMediaFormat;
|
||||
outputBufferInfo = new BufferInfo();
|
||||
inputBufferIndex = C.INDEX_UNSET;
|
||||
outputBufferIndex = C.INDEX_UNSET;
|
||||
@ -93,7 +98,7 @@ public final class DefaultCodec implements Codec {
|
||||
: isDecoder
|
||||
? MediaCodec.createDecoderByType(sampleMimeType)
|
||||
: MediaCodec.createEncoderByType(sampleMimeType);
|
||||
configureCodec(mediaCodec, mediaFormat, isDecoder, outputSurface);
|
||||
configureCodec(mediaCodec, configurationMediaFormat, isDecoder, outputSurface);
|
||||
if (isVideo && !isDecoder) {
|
||||
inputSurface = mediaCodec.createInputSurface();
|
||||
}
|
||||
@ -108,7 +113,7 @@ public final class DefaultCodec implements Codec {
|
||||
}
|
||||
|
||||
throw createInitializationTransformationException(
|
||||
e, mediaFormat, configurationFormat, isVideo, isDecoder, mediaCodecName);
|
||||
e, configurationMediaFormat, isVideo, isDecoder, mediaCodecName);
|
||||
}
|
||||
this.mediaCodec = mediaCodec;
|
||||
this.inputSurface = inputSurface;
|
||||
@ -294,9 +299,9 @@ public final class DefaultCodec implements Codec {
|
||||
boolean isVideo = MimeTypes.isVideo(configurationFormat.sampleMimeType);
|
||||
return TransformationException.createForCodec(
|
||||
cause,
|
||||
configurationFormat,
|
||||
isVideo,
|
||||
isDecoder,
|
||||
configurationMediaFormat,
|
||||
mediaCodec.getName(),
|
||||
isDecoder
|
||||
? TransformationException.ERROR_CODE_DECODING_FAILED
|
||||
@ -306,17 +311,15 @@ public final class DefaultCodec implements Codec {
|
||||
private static TransformationException createInitializationTransformationException(
|
||||
Exception cause,
|
||||
MediaFormat mediaFormat,
|
||||
Format format,
|
||||
boolean isVideo,
|
||||
boolean isDecoder,
|
||||
@Nullable String mediaCodecName) {
|
||||
if (cause instanceof IOException || cause instanceof MediaCodec.CodecException) {
|
||||
return TransformationException.createForCodec(
|
||||
cause,
|
||||
mediaFormat,
|
||||
format,
|
||||
isVideo,
|
||||
isDecoder,
|
||||
mediaFormat,
|
||||
mediaCodecName,
|
||||
isDecoder
|
||||
? TransformationException.ERROR_CODE_DECODER_INIT_FAILED
|
||||
@ -325,10 +328,9 @@ public final class DefaultCodec implements Codec {
|
||||
if (cause instanceof IllegalArgumentException) {
|
||||
return TransformationException.createForCodec(
|
||||
cause,
|
||||
mediaFormat,
|
||||
format,
|
||||
isVideo,
|
||||
isDecoder,
|
||||
mediaFormat,
|
||||
mediaCodecName,
|
||||
isDecoder
|
||||
? TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED
|
||||
|
@ -81,9 +81,9 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
||||
} else {
|
||||
throw TransformationException.createForCodec(
|
||||
new IllegalArgumentException("The requested output format is not supported."),
|
||||
format,
|
||||
/* isVideo= */ false,
|
||||
/* isDecoder= */ false,
|
||||
format,
|
||||
/* mediaCodecName= */ null,
|
||||
TransformationException.ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED);
|
||||
}
|
||||
@ -121,9 +121,9 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
||||
if (encoderAndClosestFormatSupport == null) {
|
||||
throw TransformationException.createForCodec(
|
||||
new IllegalArgumentException("The requested output format is not supported."),
|
||||
format,
|
||||
/* isVideo= */ true,
|
||||
/* isDecoder= */ false,
|
||||
format,
|
||||
/* mediaCodecName= */ null,
|
||||
TransformationException.ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED);
|
||||
}
|
||||
|
@ -207,56 +207,55 @@ public final class TransformationException extends Exception {
|
||||
/**
|
||||
* Creates an instance for a decoder or encoder related exception.
|
||||
*
|
||||
* <p>Use this method after the {@link MediaFormat} used to configure the {@link Codec} is known.
|
||||
*
|
||||
* @param cause The cause of the failure.
|
||||
* @param mediaFormat The {@link MediaFormat} used for configuring the underlying {@link
|
||||
* MediaCodec}, if known.
|
||||
* @param format The {@link Format} used for configuring the {@link Codec}.
|
||||
* @param isVideo Whether the decoder or encoder is configured for video.
|
||||
* @param isDecoder Whether the exception is created for a decoder.
|
||||
* @param mediaFormat The {@link MediaFormat} used for configuring the underlying {@link
|
||||
* MediaCodec}.
|
||||
* @param mediaCodecName The name of the {@link MediaCodec} used, if known.
|
||||
* @param errorCode See {@link #errorCode}.
|
||||
* @return The created instance.
|
||||
*/
|
||||
public static TransformationException createForCodec(
|
||||
Throwable cause,
|
||||
@Nullable MediaFormat mediaFormat,
|
||||
Format format,
|
||||
boolean isVideo,
|
||||
boolean isDecoder,
|
||||
MediaFormat mediaFormat,
|
||||
@Nullable String mediaCodecName,
|
||||
int errorCode) {
|
||||
String componentName = (isVideo ? "Video" : "Audio") + (isDecoder ? "Decoder" : "Encoder");
|
||||
String errorMessage =
|
||||
componentName
|
||||
+ " error, format="
|
||||
+ format
|
||||
+ ", mediaCodecName="
|
||||
+ mediaCodecName
|
||||
+ ", mediaFormat="
|
||||
+ (mediaFormat == null ? "no configured MediaFormat" : mediaFormat.toString());
|
||||
componentName + ", mediaFormat=" + mediaFormat + ", mediaCodecName=" + mediaCodecName;
|
||||
return new TransformationException(errorMessage, cause, errorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance for a decoder or encoder related exception.
|
||||
*
|
||||
* <p>Use this method before configuring the {@link Codec}, or when the {@link Codec} is not
|
||||
* configured with a {@link MediaFormat}.
|
||||
*
|
||||
* @param cause The cause of the failure.
|
||||
* @param format The {@link Format} used for configuring the {@link Codec}.
|
||||
* @param isVideo Whether the decoder or encoder is configured for video.
|
||||
* @param isDecoder Whether the exception is created for a decoder.
|
||||
* @param format The {@link Format} used for configuring the {@link Codec}.
|
||||
* @param mediaCodecName The name of the {@link MediaCodec} used, if known.
|
||||
* @param errorCode See {@link #errorCode}.
|
||||
* @return The created instance.
|
||||
*/
|
||||
public static TransformationException createForCodec(
|
||||
Throwable cause,
|
||||
Format format,
|
||||
boolean isVideo,
|
||||
boolean isDecoder,
|
||||
Format format,
|
||||
@Nullable String mediaCodecName,
|
||||
int errorCode) {
|
||||
return createForCodec(
|
||||
cause, /* mediaFormat= */ null, format, isVideo, isDecoder, mediaCodecName, errorCode);
|
||||
String componentName = (isVideo ? "Video" : "Audio") + (isDecoder ? "Decoder" : "Encoder");
|
||||
String errorMessage =
|
||||
componentName + " error, format=" + format + ", mediaCodecName=" + mediaCodecName;
|
||||
return new TransformationException(errorMessage, cause, errorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user