Avoid encoder default color info when tone-mapping

The encoder color info [defaults](https://cs.android.com/android/platform/superproject/+/master:frameworks/av/media/libstagefright/foundation/ColorUtils.cpp;l=377;drc=891c19ccfa4953b5e5f7b87118e007b994d8074c) to a value that depends on the input resolution, but when tone-mapping is enabled we should always get BT.709 color space. Hard-code this constant for now to avoid behavior depending on the resolution. A future change should use the decoder output media format to populate the color info.

PiperOrigin-RevId: 465070378
This commit is contained in:
andrewlewis 2022-08-03 16:06:45 +00:00 committed by tonihei
parent a28a508d2d
commit 3c4ee51e10
2 changed files with 15 additions and 1 deletions

View File

@ -31,6 +31,15 @@ import org.checkerframework.dataflow.qual.Pure;
/** Stores color info. */
@UnstableApi
public final class ColorInfo implements Bundleable {
/** Color info representing SDR BT.709 limited range, which is a common SDR video color format. */
public static final ColorInfo SDR_BT709_LIMITED =
new ColorInfo(
C.COLOR_SPACE_BT709,
C.COLOR_RANGE_LIMITED,
C.COLOR_TRANSFER_SDR,
/* hdrStaticInfo= */ null);
/**
* Returns the {@link C.ColorSpace} corresponding to the given ISO color primary code, as per
* table A.7.21.1 in Rec. ITU-T T.832 (03/2009), or {@link Format#NO_VALUE} if no mapping can be

View File

@ -384,6 +384,11 @@ import org.checkerframework.dataflow.qual.Pure;
}
boolean isInputToneMapped = ColorInfo.isHdr(inputFormat.colorInfo) && !isHdrEditingEnabled();
// When tone-mapping HDR to SDR is enabled, assume we get BT.709 to avoid having the encoder
// populate default color info, which depends on the resolution.
// TODO(b/237674316): Get the color info from the decoder output media format instead.
ColorInfo outputColorInfo =
isInputToneMapped ? ColorInfo.SDR_BT709_LIMITED : inputFormat.colorInfo;
Format requestedEncoderFormat =
new Format.Builder()
.setWidth(requestedWidth)
@ -391,7 +396,7 @@ import org.checkerframework.dataflow.qual.Pure;
.setRotationDegrees(0)
.setFrameRate(inputFormat.frameRate)
.setSampleMimeType(requestedOutputMimeType)
.setColorInfo(isInputToneMapped ? null : inputFormat.colorInfo)
.setColorInfo(outputColorInfo)
.build();
encoder =