Expand createNoSupportedMimeTypeException for HDR ColorInfo case.

PiperOrigin-RevId: 506900817
This commit is contained in:
samrobinson 2023-02-03 15:46:41 +00:00 committed by microkatz
parent 9fdc64785a
commit e2adb567bf
2 changed files with 16 additions and 18 deletions

View File

@ -20,6 +20,7 @@ import static androidx.media3.common.util.Assertions.checkStateNotNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes; import androidx.media3.common.MimeTypes;
import androidx.media3.decoder.DecoderInputBuffer; import androidx.media3.decoder.DecoderInputBuffer;
@ -44,14 +45,22 @@ import androidx.media3.decoder.DecoderInputBuffer;
trackType = MimeTypes.getTrackType(firstInputFormat.sampleMimeType); trackType = MimeTypes.getTrackType(firstInputFormat.sampleMimeType);
} }
protected static TransformationException createNoSupportedMimeTypeException( protected static TransformationException createNoSupportedMimeTypeException(Format format) {
Format requestedEncoderFormat) { String errorMessage = "No MIME type is supported by both encoder and muxer.";
int errorCode = TransformationException.ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED;
boolean isVideo = MimeTypes.isVideo(format.sampleMimeType);
if (isVideo && ColorInfo.isTransferHdr(format.colorInfo)) {
errorMessage += " Requested HDR colorInfo: " + format.colorInfo;
errorCode = TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED;
}
return TransformationException.createForCodec( return TransformationException.createForCodec(
new IllegalArgumentException("No MIME type is supported by both encoder and muxer."), new IllegalArgumentException(errorMessage),
TransformationException.ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED, errorCode,
MimeTypes.isVideo(requestedEncoderFormat.sampleMimeType), isVideo,
/* isDecoder= */ false, /* isDecoder= */ false,
requestedEncoderFormat); format);
} }
@Override @Override

View File

@ -441,18 +441,7 @@ import org.checkerframework.dataflow.qual.Pure;
findSupportedMimeTypeForEncoderAndMuxer( findSupportedMimeTypeForEncoderAndMuxer(
requestedOutputMimeType, muxerSupportedMimeTypes, requestedEncoderFormat.colorInfo); requestedOutputMimeType, muxerSupportedMimeTypes, requestedEncoderFormat.colorInfo);
if (supportedMimeType == null) { if (supportedMimeType == null) {
if (ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo)) { throw createNoSupportedMimeTypeException(requestedEncoderFormat);
throw TransformationException.createForCodec(
new IllegalStateException(
"No MIME type supported by both encoder and muxer for requested HDR colorInfo: "
+ requestedEncoderFormat.colorInfo),
TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED,
/* isVideo= */ true,
/* isDecoder= */ false,
requestedEncoderFormat);
} else {
throw createNoSupportedMimeTypeException(requestedEncoderFormat);
}
} }
encoder = encoder =