From 15f0865d6205384495cb0c853d5282525f26576d Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Mon, 13 Feb 2023 12:22:55 +0000 Subject: [PATCH] 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 --- .../mh/ForceInterpretHdrVideoAsSdrTest.java | 6 ++--- .../transformer/DefaultDecoderFactory.java | 16 ++++++-------- .../transformer/DefaultEncoderFactory.java | 22 ++++++++----------- .../transformer/SamplePipeline.java | 1 - .../transformer/TransformationException.java | 7 ------ .../transformer/TransformationRequest.java | 4 +--- .../transformer/VideoSamplePipeline.java | 5 +++-- 7 files changed, 22 insertions(+), 39 deletions(-) diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/ForceInterpretHdrVideoAsSdrTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/ForceInterpretHdrVideoAsSdrTest.java index f3e7fc37d0..8127de6390 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/ForceInterpretHdrVideoAsSdrTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/ForceInterpretHdrVideoAsSdrTest.java @@ -76,8 +76,7 @@ public class ForceInterpretHdrVideoAsSdrTest { assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR); Log.i(TAG, "Transformed."); } catch (TransformationException exception) { - if (exception.errorCode != TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED - && exception.errorCode != TransformationException.ERROR_CODE_HDR_DECODING_UNSUPPORTED) { + if (exception.errorCode != TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) { throw exception; } } @@ -113,8 +112,7 @@ public class ForceInterpretHdrVideoAsSdrTest { assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR); Log.i(TAG, "Transformed."); } catch (TransformationException exception) { - if (exception.errorCode != TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED - && exception.errorCode != TransformationException.ERROR_CODE_HDR_DECODING_UNSUPPORTED) { + if (exception.errorCode != TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) { throw exception; } } diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultDecoderFactory.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultDecoderFactory.java index 5fc3732aa4..a0a1eccfc2 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultDecoderFactory.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultDecoderFactory.java @@ -61,7 +61,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; @Nullable String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ true); if (mediaCodecName == null) { - throw createTransformationException(format); + throw createTransformationException( + format, /* reason= */ "The requested decoding format is not supported."); } return new DefaultCodec( context, @@ -81,11 +82,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; if (ColorInfo.isTransferHdr(format.colorInfo)) { if (requestSdrToneMapping && (SDK_INT < 31 || deviceNeedsNoToneMappingWorkaround())) { 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) { // 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 String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ true); if (mediaCodecName == null) { - throw createTransformationException(format); + throw createTransformationException( + format, /* reason= */ "The requested video decoding format is not supported."); } return new DefaultCodec( 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")); } - @RequiresNonNull("#1.sampleMimeType") - private static TransformationException createTransformationException(Format format) { - return createTransformationException(format, "The requested decoding format is not supported."); - } - @RequiresNonNull("#1.sampleMimeType") private static TransformationException createTransformationException( Format format, String reason) { diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java index 7369a9d76d..77de20e6ae 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java @@ -16,7 +16,6 @@ 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.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkState; @@ -182,7 +181,8 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory { @Nullable String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ false); if (mediaCodecName == null) { - throw createTransformationException(format); + throw createTransformationException( + format, /* errorString= */ "The requested audio encoding format is not supported."); } return new DefaultCodec( context, @@ -221,7 +221,8 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory { format, requestedVideoEncoderSettings, videoEncoderSelector, enableFallback); if (encoderAndClosestFormatSupport == null) { - throw createTransformationException(format); + throw createTransformationException( + format, /* errorString= */ "The requested video encoding format is not supported."); } MediaCodecInfo encoderInfo = encoderAndClosestFormatSupport.encoder; @@ -289,7 +290,8 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory { MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_Format32bitABGR2101010); } else { - throw createTransformationException(format, ERROR_CODE_HDR_ENCODING_UNSUPPORTED); + throw createTransformationException( + format, /* errorString= */ "Encoding HDR is not supported on this device."); } } else { mediaFormat.setInteger( @@ -665,18 +667,12 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory { 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") private static TransformationException createTransformationException( - Format format, @TransformationException.ErrorCode int errorCode) { + Format format, String errorString) { return TransformationException.createForCodec( - new IllegalArgumentException("The requested encoding format is not supported."), - errorCode, + new IllegalArgumentException(errorString), + TransformationException.ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED, MimeTypes.isVideo(format.sampleMimeType), /* isDecoder= */ false, format); diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/SamplePipeline.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/SamplePipeline.java index ca76eed9b1..edb0ca9bb3 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/SamplePipeline.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/SamplePipeline.java @@ -55,7 +55,6 @@ import com.google.android.exoplayer2.video.ColorInfo; if (isVideo && ColorInfo.isTransferHdr(format.colorInfo)) { errorMessage += " Requested HDR colorInfo: " + format.colorInfo; - errorCode = TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED; } return TransformationException.createForCodec( diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationException.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationException.java index b812ab84d2..03f033c928 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationException.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationException.java @@ -64,7 +64,6 @@ public final class TransformationException extends Exception { ERROR_CODE_ENCODER_INIT_FAILED, ERROR_CODE_ENCODING_FAILED, ERROR_CODE_ENCODING_FORMAT_UNSUPPORTED, - ERROR_CODE_HDR_ENCODING_UNSUPPORTED, ERROR_CODE_FRAME_PROCESSING_FAILED, ERROR_CODE_AUDIO_PROCESSING_FAILED, ERROR_CODE_MUXING_FAILED, @@ -133,8 +132,6 @@ public final class TransformationException extends Exception { public static final int ERROR_CODE_DECODING_FAILED = 3002; /** Caused by trying to decode content whose format is not supported. */ 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). @@ -149,8 +146,6 @@ public final class TransformationException extends Exception { * available. */ 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). @@ -182,11 +177,9 @@ public final class TransformationException extends Exception { .put("ERROR_CODE_DECODER_INIT_FAILED", ERROR_CODE_DECODER_INIT_FAILED) .put("ERROR_CODE_DECODING_FAILED", ERROR_CODE_DECODING_FAILED) .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_ENCODING_FAILED", ERROR_CODE_ENCODING_FAILED) .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_AUDIO_PROCESSING_FAILED", ERROR_CODE_AUDIO_PROCESSING_FAILED) .put("ERROR_CODE_MUXING_FAILED", ERROR_CODE_MUXING_FAILED) diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationRequest.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationRequest.java index 5b11fc860a..c3da5015a3 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationRequest.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationRequest.java @@ -95,9 +95,7 @@ public final class TransformationRequest { * metadata will be ignored, contents will be displayed incorrectly, likely with a washed out * look. * - *

Use of this flag may result in {@code - * TransformationException.ERROR_CODE_HDR_DECODING_UNSUPPORTED} or {@code - * ERROR_CODE_DECODING_FORMAT_UNSUPPORTED}. + *

Use of this flag may result in {@code ERROR_CODE_DECODING_FORMAT_UNSUPPORTED}. * *

This field is experimental, and will be renamed or removed in a future release. */ diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java index b520e9142b..30b6fa3c16 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java @@ -88,8 +88,9 @@ import org.checkerframework.dataflow.qual.Pure; if (transformationRequest.hdrMode == HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR) { if (SDK_INT < 29) { throw TransformationException.createForCodec( - new IllegalArgumentException("Interpreting HDR video as SDR is not supported."), - TransformationException.ERROR_CODE_HDR_DECODING_UNSUPPORTED, + new IllegalArgumentException( + "Interpreting HDR video as SDR is not supported on this device."), + TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED, /* isVideo= */ true, /* isDecoder= */ true, firstInputFormat);