mirror of
https://github.com/androidx/media.git
synced 2025-05-07 23:50:44 +08:00
HDR: Remove HDR-specific error codes.
It may be confusing for 3P apps, for us to have separate error codes for (1) if encoding HDR is not supported at all by the device, and (2) if encoding the format, which happens to be HDR, is not supported by the device. Instead, we can communicate this in the error message. PiperOrigin-RevId: 509188666
This commit is contained in:
parent
88a97fdb6f
commit
15f0865d62
@ -76,8 +76,7 @@ public class ForceInterpretHdrVideoAsSdrTest {
|
|||||||
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
|
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
|
||||||
Log.i(TAG, "Transformed.");
|
Log.i(TAG, "Transformed.");
|
||||||
} catch (TransformationException exception) {
|
} catch (TransformationException exception) {
|
||||||
if (exception.errorCode != TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED
|
if (exception.errorCode != TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) {
|
||||||
&& exception.errorCode != TransformationException.ERROR_CODE_HDR_DECODING_UNSUPPORTED) {
|
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,8 +112,7 @@ public class ForceInterpretHdrVideoAsSdrTest {
|
|||||||
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
|
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
|
||||||
Log.i(TAG, "Transformed.");
|
Log.i(TAG, "Transformed.");
|
||||||
} catch (TransformationException exception) {
|
} catch (TransformationException exception) {
|
||||||
if (exception.errorCode != TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED
|
if (exception.errorCode != TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) {
|
||||||
&& exception.errorCode != TransformationException.ERROR_CODE_HDR_DECODING_UNSUPPORTED) {
|
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
@Nullable
|
@Nullable
|
||||||
String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ true);
|
String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ true);
|
||||||
if (mediaCodecName == null) {
|
if (mediaCodecName == null) {
|
||||||
throw createTransformationException(format);
|
throw createTransformationException(
|
||||||
|
format, /* reason= */ "The requested decoding format is not supported.");
|
||||||
}
|
}
|
||||||
return new DefaultCodec(
|
return new DefaultCodec(
|
||||||
context,
|
context,
|
||||||
@ -81,11 +82,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
if (ColorInfo.isTransferHdr(format.colorInfo)) {
|
if (ColorInfo.isTransferHdr(format.colorInfo)) {
|
||||||
if (requestSdrToneMapping && (SDK_INT < 31 || deviceNeedsNoToneMappingWorkaround())) {
|
if (requestSdrToneMapping && (SDK_INT < 31 || deviceNeedsNoToneMappingWorkaround())) {
|
||||||
throw createTransformationException(
|
throw createTransformationException(
|
||||||
format, /* reason= */ "Tone-mapping HDR is not supported.");
|
format, /* reason= */ "Tone-mapping HDR is not supported on this device.");
|
||||||
}
|
}
|
||||||
if (SDK_INT < 29) {
|
if (SDK_INT < 29) {
|
||||||
// TODO(b/266837571, b/267171669): Remove API version restriction after fixing linked bugs.
|
// TODO(b/266837571, b/267171669): Remove API version restriction after fixing linked bugs.
|
||||||
throw createTransformationException(format, /* reason= */ "Decoding HDR is not supported.");
|
throw createTransformationException(
|
||||||
|
format, /* reason= */ "Decoding HDR is not supported on this device.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +118,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
@Nullable
|
@Nullable
|
||||||
String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ true);
|
String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ true);
|
||||||
if (mediaCodecName == null) {
|
if (mediaCodecName == null) {
|
||||||
throw createTransformationException(format);
|
throw createTransformationException(
|
||||||
|
format, /* reason= */ "The requested video decoding format is not supported.");
|
||||||
}
|
}
|
||||||
return new DefaultCodec(
|
return new DefaultCodec(
|
||||||
context, format, mediaFormat, mediaCodecName, /* isDecoder= */ true, outputSurface);
|
context, format, mediaFormat, mediaCodecName, /* isDecoder= */ true, outputSurface);
|
||||||
@ -130,11 +133,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
|| Build.ID.startsWith(/* Pixel Watch */ "rwd9.220429.053"));
|
|| Build.ID.startsWith(/* Pixel Watch */ "rwd9.220429.053"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresNonNull("#1.sampleMimeType")
|
|
||||||
private static TransformationException createTransformationException(Format format) {
|
|
||||||
return createTransformationException(format, "The requested decoding format is not supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresNonNull("#1.sampleMimeType")
|
@RequiresNonNull("#1.sampleMimeType")
|
||||||
private static TransformationException createTransformationException(
|
private static TransformationException createTransformationException(
|
||||||
Format format, String reason) {
|
Format format, String reason) {
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.google.android.exoplayer2.transformer;
|
package com.google.android.exoplayer2.transformer;
|
||||||
|
|
||||||
import static com.google.android.exoplayer2.transformer.TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED;
|
|
||||||
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
|
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
|
||||||
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||||
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
||||||
@ -182,7 +181,8 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
|||||||
@Nullable
|
@Nullable
|
||||||
String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ false);
|
String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ false);
|
||||||
if (mediaCodecName == null) {
|
if (mediaCodecName == null) {
|
||||||
throw createTransformationException(format);
|
throw createTransformationException(
|
||||||
|
format, /* errorString= */ "The requested audio encoding format is not supported.");
|
||||||
}
|
}
|
||||||
return new DefaultCodec(
|
return new DefaultCodec(
|
||||||
context,
|
context,
|
||||||
@ -221,7 +221,8 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
|||||||
format, requestedVideoEncoderSettings, videoEncoderSelector, enableFallback);
|
format, requestedVideoEncoderSettings, videoEncoderSelector, enableFallback);
|
||||||
|
|
||||||
if (encoderAndClosestFormatSupport == null) {
|
if (encoderAndClosestFormatSupport == null) {
|
||||||
throw createTransformationException(format);
|
throw createTransformationException(
|
||||||
|
format, /* errorString= */ "The requested video encoding format is not supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaCodecInfo encoderInfo = encoderAndClosestFormatSupport.encoder;
|
MediaCodecInfo encoderInfo = encoderAndClosestFormatSupport.encoder;
|
||||||
@ -289,7 +290,8 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
|||||||
MediaFormat.KEY_COLOR_FORMAT,
|
MediaFormat.KEY_COLOR_FORMAT,
|
||||||
MediaCodecInfo.CodecCapabilities.COLOR_Format32bitABGR2101010);
|
MediaCodecInfo.CodecCapabilities.COLOR_Format32bitABGR2101010);
|
||||||
} else {
|
} else {
|
||||||
throw createTransformationException(format, ERROR_CODE_HDR_ENCODING_UNSUPPORTED);
|
throw createTransformationException(
|
||||||
|
format, /* errorString= */ "Encoding HDR is not supported on this device.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mediaFormat.setInteger(
|
mediaFormat.setInteger(
|
||||||
@ -665,18 +667,12 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
|||||||
return (int) (width * height * frameRate * 0.07 * 2);
|
return (int) (width * height * frameRate * 0.07 * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresNonNull("#1.sampleMimeType")
|
|
||||||
private static TransformationException createTransformationException(Format format) {
|
|
||||||
return createTransformationException(
|
|
||||||
format, TransformationException.ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresNonNull("#1.sampleMimeType")
|
@RequiresNonNull("#1.sampleMimeType")
|
||||||
private static TransformationException createTransformationException(
|
private static TransformationException createTransformationException(
|
||||||
Format format, @TransformationException.ErrorCode int errorCode) {
|
Format format, String errorString) {
|
||||||
return TransformationException.createForCodec(
|
return TransformationException.createForCodec(
|
||||||
new IllegalArgumentException("The requested encoding format is not supported."),
|
new IllegalArgumentException(errorString),
|
||||||
errorCode,
|
TransformationException.ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED,
|
||||||
MimeTypes.isVideo(format.sampleMimeType),
|
MimeTypes.isVideo(format.sampleMimeType),
|
||||||
/* isDecoder= */ false,
|
/* isDecoder= */ false,
|
||||||
format);
|
format);
|
||||||
|
@ -55,7 +55,6 @@ import com.google.android.exoplayer2.video.ColorInfo;
|
|||||||
|
|
||||||
if (isVideo && ColorInfo.isTransferHdr(format.colorInfo)) {
|
if (isVideo && ColorInfo.isTransferHdr(format.colorInfo)) {
|
||||||
errorMessage += " Requested HDR colorInfo: " + format.colorInfo;
|
errorMessage += " Requested HDR colorInfo: " + format.colorInfo;
|
||||||
errorCode = TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TransformationException.createForCodec(
|
return TransformationException.createForCodec(
|
||||||
|
@ -64,7 +64,6 @@ public final class TransformationException extends Exception {
|
|||||||
ERROR_CODE_ENCODER_INIT_FAILED,
|
ERROR_CODE_ENCODER_INIT_FAILED,
|
||||||
ERROR_CODE_ENCODING_FAILED,
|
ERROR_CODE_ENCODING_FAILED,
|
||||||
ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED,
|
ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED,
|
||||||
ERROR_CODE_HDR_ENCODING_UNSUPPORTED,
|
|
||||||
ERROR_CODE_FRAME_PROCESSING_FAILED,
|
ERROR_CODE_FRAME_PROCESSING_FAILED,
|
||||||
ERROR_CODE_AUDIO_PROCESSING_FAILED,
|
ERROR_CODE_AUDIO_PROCESSING_FAILED,
|
||||||
ERROR_CODE_MUXING_FAILED,
|
ERROR_CODE_MUXING_FAILED,
|
||||||
@ -133,8 +132,6 @@ public final class TransformationException extends Exception {
|
|||||||
public static final int ERROR_CODE_DECODING_FAILED = 3002;
|
public static final int ERROR_CODE_DECODING_FAILED = 3002;
|
||||||
/** Caused by trying to decode content whose format is not supported. */
|
/** Caused by trying to decode content whose format is not supported. */
|
||||||
public static final int ERROR_CODE_DECODING_FORMAT_UNSUPPORTED = 3003;
|
public static final int ERROR_CODE_DECODING_FORMAT_UNSUPPORTED = 3003;
|
||||||
/** Caused by the decoder not supporting HDR formats. */
|
|
||||||
public static final int ERROR_CODE_HDR_DECODING_UNSUPPORTED = 3004;
|
|
||||||
|
|
||||||
// Encoding errors (4xxx).
|
// Encoding errors (4xxx).
|
||||||
|
|
||||||
@ -149,8 +146,6 @@ public final class TransformationException extends Exception {
|
|||||||
* available.
|
* available.
|
||||||
*/
|
*/
|
||||||
public static final int ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED = 4003;
|
public static final int ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED = 4003;
|
||||||
/** Caused by the encoder not supporting HDR formats. */
|
|
||||||
public static final int ERROR_CODE_HDR_ENCODING_UNSUPPORTED = 4004;
|
|
||||||
|
|
||||||
// Video editing errors (5xxx).
|
// Video editing errors (5xxx).
|
||||||
|
|
||||||
@ -182,11 +177,9 @@ public final class TransformationException extends Exception {
|
|||||||
.put("ERROR_CODE_DECODER_INIT_FAILED", ERROR_CODE_DECODER_INIT_FAILED)
|
.put("ERROR_CODE_DECODER_INIT_FAILED", ERROR_CODE_DECODER_INIT_FAILED)
|
||||||
.put("ERROR_CODE_DECODING_FAILED", ERROR_CODE_DECODING_FAILED)
|
.put("ERROR_CODE_DECODING_FAILED", ERROR_CODE_DECODING_FAILED)
|
||||||
.put("ERROR_CODE_DECODING_FORMAT_UNSUPPORTED", ERROR_CODE_DECODING_FORMAT_UNSUPPORTED)
|
.put("ERROR_CODE_DECODING_FORMAT_UNSUPPORTED", ERROR_CODE_DECODING_FORMAT_UNSUPPORTED)
|
||||||
.put("ERROR_CODE_HDR_DECODING_UNSUPPORTED", ERROR_CODE_HDR_DECODING_UNSUPPORTED)
|
|
||||||
.put("ERROR_CODE_ENCODER_INIT_FAILED", ERROR_CODE_ENCODER_INIT_FAILED)
|
.put("ERROR_CODE_ENCODER_INIT_FAILED", ERROR_CODE_ENCODER_INIT_FAILED)
|
||||||
.put("ERROR_CODE_ENCODING_FAILED", ERROR_CODE_ENCODING_FAILED)
|
.put("ERROR_CODE_ENCODING_FAILED", ERROR_CODE_ENCODING_FAILED)
|
||||||
.put("ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED", ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED)
|
.put("ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED", ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED)
|
||||||
.put("ERROR_CODE_HDR_ENCODING_UNSUPPORTED", ERROR_CODE_HDR_ENCODING_UNSUPPORTED)
|
|
||||||
.put("ERROR_CODE_FRAME_PROCESSING_FAILED", ERROR_CODE_FRAME_PROCESSING_FAILED)
|
.put("ERROR_CODE_FRAME_PROCESSING_FAILED", ERROR_CODE_FRAME_PROCESSING_FAILED)
|
||||||
.put("ERROR_CODE_AUDIO_PROCESSING_FAILED", ERROR_CODE_AUDIO_PROCESSING_FAILED)
|
.put("ERROR_CODE_AUDIO_PROCESSING_FAILED", ERROR_CODE_AUDIO_PROCESSING_FAILED)
|
||||||
.put("ERROR_CODE_MUXING_FAILED", ERROR_CODE_MUXING_FAILED)
|
.put("ERROR_CODE_MUXING_FAILED", ERROR_CODE_MUXING_FAILED)
|
||||||
|
@ -95,9 +95,7 @@ public final class TransformationRequest {
|
|||||||
* metadata will be ignored, contents will be displayed incorrectly, likely with a washed out
|
* metadata will be ignored, contents will be displayed incorrectly, likely with a washed out
|
||||||
* look.
|
* look.
|
||||||
*
|
*
|
||||||
* <p>Use of this flag may result in {@code
|
* <p>Use of this flag may result in {@code ERROR_CODE_DECODING_FORMAT_UNSUPPORTED}.
|
||||||
* TransformationException.ERROR_CODE_HDR_DECODING_UNSUPPORTED} or {@code
|
|
||||||
* ERROR_CODE_DECODING_FORMAT_UNSUPPORTED}.
|
|
||||||
*
|
*
|
||||||
* <p>This field is experimental, and will be renamed or removed in a future release.
|
* <p>This field is experimental, and will be renamed or removed in a future release.
|
||||||
*/
|
*/
|
||||||
|
@ -88,8 +88,9 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
if (transformationRequest.hdrMode == HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR) {
|
if (transformationRequest.hdrMode == HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR) {
|
||||||
if (SDK_INT < 29) {
|
if (SDK_INT < 29) {
|
||||||
throw TransformationException.createForCodec(
|
throw TransformationException.createForCodec(
|
||||||
new IllegalArgumentException("Interpreting HDR video as SDR is not supported."),
|
new IllegalArgumentException(
|
||||||
TransformationException.ERROR_CODE_HDR_DECODING_UNSUPPORTED,
|
"Interpreting HDR video as SDR is not supported on this device."),
|
||||||
|
TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED,
|
||||||
/* isVideo= */ true,
|
/* isVideo= */ true,
|
||||||
/* isDecoder= */ true,
|
/* isDecoder= */ true,
|
||||||
firstInputFormat);
|
firstInputFormat);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user