HDR: Throw error if attempting HDR editing under API 31.

HDR editing is not supported under API 31

PiperOrigin-RevId: 459211106
This commit is contained in:
huangdarwin 2022-07-06 10:25:30 +00:00 committed by Rohit Singh
parent 656eaf74d1
commit ab7747d953
4 changed files with 22 additions and 6 deletions

View File

@ -83,6 +83,11 @@ public final class ColorInfo implements Bundleable {
} }
} }
/** Returns whether the {@code ColorInfo} uses an HDR {@link C.ColorTransfer}. */
public static boolean isHdr(@Nullable ColorInfo colorInfo) {
return colorInfo != null && colorInfo.colorTransfer != C.COLOR_TRANSFER_SDR;
}
/** /**
* The color space of the video. Valid values are {@link C#COLOR_SPACE_BT601}, {@link * The color space of the video. Valid values are {@link C#COLOR_SPACE_BT601}, {@link
* C#COLOR_SPACE_BT709}, {@link C#COLOR_SPACE_BT2020} or {@link Format#NO_VALUE} if unknown. * C#COLOR_SPACE_BT709}, {@link C#COLOR_SPACE_BT2020} or {@link Format#NO_VALUE} if unknown.

View File

@ -69,6 +69,7 @@ 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_OUTPUT_FORMAT_UNSUPPORTED, ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED,
ERROR_CODE_HDR_EDITING_UNSUPPORTED,
ERROR_CODE_GL_INIT_FAILED, ERROR_CODE_GL_INIT_FAILED,
ERROR_CODE_GL_PROCESSING_FAILED, ERROR_CODE_GL_PROCESSING_FAILED,
ERROR_CODE_MUXING_FAILED, ERROR_CODE_MUXING_FAILED,
@ -151,6 +152,8 @@ public final class TransformationException extends Exception {
* Codec.DecoderFactory encoders} available. * Codec.DecoderFactory encoders} available.
*/ */
public static final int ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED = 4003; public static final int ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED = 4003;
/** Caused by the encoder not supporting HDR formats. */
public static final int ERROR_CODE_HDR_EDITING_UNSUPPORTED = 4004;
// Video editing errors (5xxx). // Video editing errors (5xxx).
@ -181,6 +184,7 @@ public final class TransformationException extends Exception {
.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_OUTPUT_FORMAT_UNSUPPORTED", ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED) .put("ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED", ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED)
.put("ERROR_CODE_HDR_EDITING_UNSUPPORTED", ERROR_CODE_HDR_EDITING_UNSUPPORTED)
.put("ERROR_CODE_GL_INIT_FAILED", ERROR_CODE_GL_INIT_FAILED) .put("ERROR_CODE_GL_INIT_FAILED", ERROR_CODE_GL_INIT_FAILED)
.put("ERROR_CODE_GL_PROCESSING_FAILED", ERROR_CODE_GL_PROCESSING_FAILED) .put("ERROR_CODE_GL_PROCESSING_FAILED", ERROR_CODE_GL_PROCESSING_FAILED)
.put("ERROR_CODE_MUXING_FAILED", ERROR_CODE_MUXING_FAILED) .put("ERROR_CODE_MUXING_FAILED", ERROR_CODE_MUXING_FAILED)

View File

@ -17,10 +17,12 @@
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Util.SDK_INT;
import static androidx.media3.exoplayer.source.SampleStream.FLAG_REQUIRE_FORMAT; import static androidx.media3.exoplayer.source.SampleStream.FLAG_REQUIRE_FORMAT;
import android.content.Context; import android.content.Context;
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.decoder.DecoderInputBuffer; import androidx.media3.decoder.DecoderInputBuffer;
import androidx.media3.exoplayer.FormatHolder; import androidx.media3.exoplayer.FormatHolder;
@ -91,6 +93,15 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
return false; return false;
} }
Format inputFormat = checkNotNull(formatHolder.format); Format inputFormat = checkNotNull(formatHolder.format);
if (SDK_INT < 31 && ColorInfo.isHdr(inputFormat.colorInfo)) {
throw TransformationException.createForCodec(
new IllegalArgumentException("HDR editing not supported under API 31."),
/* isVideo= */ true,
/* isDecoder= */ false,
inputFormat,
/* mediaCodecName= */ null,
TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED);
}
if (shouldPassthrough(inputFormat)) { if (shouldPassthrough(inputFormat)) {
samplePipeline = samplePipeline =
new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener); new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);

View File

@ -108,7 +108,8 @@ import org.checkerframework.dataflow.qual.Pure;
boolean enableRequestSdrToneMapping = transformationRequest.enableRequestSdrToneMapping; boolean enableRequestSdrToneMapping = transformationRequest.enableRequestSdrToneMapping;
// TODO(b/237674316): While HLG10 is correctly reported, HDR10 currently will be incorrectly // TODO(b/237674316): While HLG10 is correctly reported, HDR10 currently will be incorrectly
// processed as SDR, because the inputFormat.colorInfo reports the wrong value. // processed as SDR, because the inputFormat.colorInfo reports the wrong value.
boolean useHdr = transformationRequest.enableHdrEditing && isHdr(inputFormat.colorInfo); boolean useHdr =
transformationRequest.enableHdrEditing && ColorInfo.isHdr(inputFormat.colorInfo);
if (useHdr && !encoderWrapper.supportsHdr()) { if (useHdr && !encoderWrapper.supportsHdr()) {
// TODO(b/236316454): Also check whether GlEffectsFrameProcessor supports HDR, i.e., whether // TODO(b/236316454): Also check whether GlEffectsFrameProcessor supports HDR, i.e., whether
// EXT_YUV_target is supported. // EXT_YUV_target is supported.
@ -167,11 +168,6 @@ import org.checkerframework.dataflow.qual.Pure;
maxPendingFrameCount = decoder.getMaxPendingFrameCount(); maxPendingFrameCount = decoder.getMaxPendingFrameCount();
} }
/** Whether this is a supported HDR format. */
private static boolean isHdr(@Nullable ColorInfo colorInfo) {
return colorInfo != null && colorInfo.colorTransfer != C.COLOR_TRANSFER_SDR;
}
@Override @Override
@Nullable @Nullable
public DecoderInputBuffer dequeueInputBuffer() throws TransformationException { public DecoderInputBuffer dequeueInputBuffer() throws TransformationException {