mirror of
https://github.com/androidx/media.git
synced 2025-05-10 09:12:16 +08:00
Clarify case where HDR encoder and muxer have no shared mime type.
The prior version (with the call to createEncodingException) could never occur as select...SupportedMimeType already checks for HDR editing support. This change ensures we throw before creating an encoder, gives a better error code and allows future simplifications around createForCodec (see child CL). PiperOrigin-RevId: 506308290
This commit is contained in:
parent
b8ec982ee3
commit
83bc474f3c
@ -134,7 +134,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
// TODO(b/259570024): investigate overhauling fallback.
|
// TODO(b/259570024): investigate overhauling fallback.
|
||||||
@Nullable
|
@Nullable
|
||||||
String supportedMimeType =
|
String supportedMimeType =
|
||||||
selectEncoderAndMuxerSupportedMimeType(requestedMimeType, muxerSupportedMimeTypes);
|
findSupportedMimeTypeForEncoderAndMuxer(requestedMimeType, muxerSupportedMimeTypes);
|
||||||
if (supportedMimeType == null) {
|
if (supportedMimeType == null) {
|
||||||
throw createNoSupportedMimeTypeException(requestedOutputFormat);
|
throw createNoSupportedMimeTypeException(requestedOutputFormat);
|
||||||
}
|
}
|
||||||
@ -340,12 +340,12 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static String selectEncoderAndMuxerSupportedMimeType(
|
private static String findSupportedMimeTypeForEncoderAndMuxer(
|
||||||
String requestedMimeType, List<String> muxerSupportedMimeTypes) {
|
String preferredMimeType, List<String> muxerSupportedMimeTypes) {
|
||||||
if (!EncoderUtil.getSupportedEncoders(requestedMimeType).isEmpty()) {
|
if (!EncoderUtil.getSupportedEncoders(preferredMimeType).isEmpty()) {
|
||||||
return requestedMimeType;
|
return preferredMimeType;
|
||||||
} else {
|
} else {
|
||||||
// No encoder supports the requested MIME type.
|
// No encoder supports the preferred MIME type.
|
||||||
for (int i = 0; i < muxerSupportedMimeTypes.size(); i++) {
|
for (int i = 0; i < muxerSupportedMimeTypes.size(); i++) {
|
||||||
String mimeType = muxerSupportedMimeTypes.get(i);
|
String mimeType = muxerSupportedMimeTypes.get(i);
|
||||||
if (!EncoderUtil.getSupportedEncoders(mimeType).isEmpty()) {
|
if (!EncoderUtil.getSupportedEncoders(mimeType).isEmpty()) {
|
||||||
|
@ -436,10 +436,22 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
String supportedMimeType =
|
String supportedMimeType =
|
||||||
selectEncoderAndMuxerSupportedMimeType(
|
findSupportedMimeTypeForEncoderAndMuxer(
|
||||||
requestedOutputMimeType, muxerSupportedMimeTypes, requestedEncoderFormat.colorInfo);
|
requestedOutputMimeType, muxerSupportedMimeTypes, requestedEncoderFormat.colorInfo);
|
||||||
if (supportedMimeType == null) {
|
if (supportedMimeType == null) {
|
||||||
throw createNoSupportedMimeTypeException(requestedEncoderFormat);
|
if (ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo)) {
|
||||||
|
throw TransformationException.createForCodec(
|
||||||
|
new IllegalStateException(
|
||||||
|
"No MIME type supported by both encoder and muxer for requested HDR colorInfo: "
|
||||||
|
+ requestedEncoderFormat.colorInfo),
|
||||||
|
/* isVideo= */ true,
|
||||||
|
/* isDecoder= */ false,
|
||||||
|
requestedEncoderFormat,
|
||||||
|
/* mediaCodecName= */ null,
|
||||||
|
TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED);
|
||||||
|
} else {
|
||||||
|
throw createNoSupportedMimeTypeException(requestedEncoderFormat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encoder =
|
encoder =
|
||||||
@ -448,12 +460,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
|
|
||||||
Format encoderSupportedFormat = encoder.getConfigurationFormat();
|
Format encoderSupportedFormat = encoder.getConfigurationFormat();
|
||||||
checkState(supportedMimeType.equals(encoderSupportedFormat.sampleMimeType));
|
checkState(supportedMimeType.equals(encoderSupportedFormat.sampleMimeType));
|
||||||
if (ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo)
|
|
||||||
&& !supportedEncoderNamesForHdrEditing.contains(encoder.getName())) {
|
|
||||||
throw createEncodingException(
|
|
||||||
new IllegalStateException("Selected encoder doesn't support HDR editing"),
|
|
||||||
encoderSupportedFormat);
|
|
||||||
}
|
|
||||||
boolean isInputToneMapped =
|
boolean isInputToneMapped =
|
||||||
ColorInfo.isTransferHdr(inputFormat.colorInfo)
|
ColorInfo.isTransferHdr(inputFormat.colorInfo)
|
||||||
&& !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo);
|
&& !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo);
|
||||||
@ -531,34 +538,28 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
releaseEncoder = true;
|
releaseEncoder = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TransformationException createEncodingException(Exception cause, Format format) {
|
|
||||||
return TransformationException.createForCodec(
|
|
||||||
cause,
|
|
||||||
/* isVideo= */ true,
|
|
||||||
/* isDecoder= */ false,
|
|
||||||
format,
|
|
||||||
checkNotNull(encoder).getName(),
|
|
||||||
TransformationException.ERROR_CODE_ENCODING_FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a {@linkplain MimeTypes MIME type} that is supported by both the encoder and the muxer.
|
* Finds a {@linkplain MimeTypes MIME type} that is supported by the encoder and the muxer.
|
||||||
*
|
*
|
||||||
* @param requestedMimeType The requested {@linkplain MimeTypes MIME type}.
|
* <p>HDR editing support is checked if the {@link ColorInfo} is HDR.
|
||||||
|
*
|
||||||
|
* @param preferredMimeType The preferred {@linkplain MimeTypes MIME type}, returned if
|
||||||
|
* supported.
|
||||||
* @param muxerSupportedMimeTypes The list of sample {@linkplain MimeTypes MIME types} that the
|
* @param muxerSupportedMimeTypes The list of sample {@linkplain MimeTypes MIME types} that the
|
||||||
* muxer supports.
|
* muxer supports.
|
||||||
* @param colorInfo The requested encoding {@link ColorInfo}, if available.
|
* @param colorInfo The optional encoding {@link ColorInfo}. If a HDR color info is provided,
|
||||||
|
* only encoders that support it will be considered.
|
||||||
* @return A {@linkplain MimeTypes MIME type} that is supported by an encoder and the muxer, or
|
* @return A {@linkplain MimeTypes MIME type} that is supported by an encoder and the muxer, or
|
||||||
* {@code null} if no such {@linkplain MimeTypes MIME type} exists.
|
* {@code null} if no such {@linkplain MimeTypes MIME type} exists.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private static String selectEncoderAndMuxerSupportedMimeType(
|
private static String findSupportedMimeTypeForEncoderAndMuxer(
|
||||||
String requestedMimeType,
|
String preferredMimeType,
|
||||||
List<String> muxerSupportedMimeTypes,
|
List<String> muxerSupportedMimeTypes,
|
||||||
@Nullable ColorInfo colorInfo) {
|
@Nullable ColorInfo colorInfo) {
|
||||||
ImmutableList<String> mimeTypesToCheck =
|
ImmutableList<String> mimeTypesToCheck =
|
||||||
new ImmutableList.Builder<String>()
|
new ImmutableList.Builder<String>()
|
||||||
.add(requestedMimeType)
|
.add(preferredMimeType)
|
||||||
.add(MimeTypes.VIDEO_H265)
|
.add(MimeTypes.VIDEO_H265)
|
||||||
.add(MimeTypes.VIDEO_H264)
|
.add(MimeTypes.VIDEO_H264)
|
||||||
.addAll(muxerSupportedMimeTypes)
|
.addAll(muxerSupportedMimeTypes)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user