Skip to content

Commit

Permalink
HDR: Throw error if attempting HDR editing under API 31.
Browse files Browse the repository at this point in the history
HDR editing is not supported under API 31

PiperOrigin-RevId: 459211106
  • Loading branch information
dway123 authored and rohitjoins committed Jul 7, 2022
1 parent bf88f28 commit 77d353b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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
* C#COLOR_SPACE_BT709}, {@link C#COLOR_SPACE_BT2020} or {@link Format#NO_VALUE} if unknown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public final class TransformationException extends Exception {
ERROR_CODE_ENCODER_INIT_FAILED,
ERROR_CODE_ENCODING_FAILED,
ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED,
ERROR_CODE_HDR_EDITING_UNSUPPORTED,
ERROR_CODE_GL_INIT_FAILED,
ERROR_CODE_GL_PROCESSING_FAILED,
ERROR_CODE_MUXING_FAILED,
Expand Down Expand Up @@ -149,6 +150,8 @@ public final class TransformationException extends Exception {
* Codec.DecoderFactory encoders} available.
*/
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).

Expand Down Expand Up @@ -179,6 +182,7 @@ public final class TransformationException extends Exception {
.put("ERROR_CODE_ENCODER_INIT_FAILED", ERROR_CODE_ENCODER_INIT_FAILED)
.put("ERROR_CODE_ENCODING_FAILED", ERROR_CODE_ENCODING_FAILED)
.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_PROCESSING_FAILED", ERROR_CODE_GL_PROCESSING_FAILED)
.put("ERROR_CODE_MUXING_FAILED", ERROR_CODE_MUXING_FAILED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import static com.google.android.exoplayer2.source.SampleStream.FLAG_REQUIRE_FORMAT;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Util.SDK_INT;

import android.content.Context;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
import com.google.android.exoplayer2.video.ColorInfo;
import com.google.common.collect.ImmutableList;
import java.nio.ByteBuffer;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
Expand Down Expand Up @@ -91,6 +93,15 @@ protected boolean ensureConfigured() throws TransformationException {
return false;
}
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)) {
samplePipeline =
new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public VideoTranscodingSamplePipeline(
boolean enableRequestSdrToneMapping = transformationRequest.enableRequestSdrToneMapping;
// TODO(b/237674316): While HLG10 is correctly reported, HDR10 currently will be incorrectly
// 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()) {
// TODO(b/236316454): Also check whether GlEffectsFrameProcessor supports HDR, i.e., whether
// EXT_YUV_target is supported.
Expand Down Expand Up @@ -167,11 +168,6 @@ public void onFrameProcessingEnded() {
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
@Nullable
public DecoderInputBuffer dequeueInputBuffer() throws TransformationException {
Expand Down

0 comments on commit 77d353b

Please sign in to comment.