HDR: Update HdrMode fallback to use OpenGL tone-mapping.

OpenGL tone-mapping is more reliable and widely supported than
MediaCodec tone-mapping.

PiperOrigin-RevId: 567267389
This commit is contained in:
huangdarwin 2023-09-21 04:30:53 -07:00 committed by Copybara-Service
parent 603d36726f
commit 0675e48685
3 changed files with 14 additions and 15 deletions

View File

@ -25,7 +25,7 @@ import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR_FORMAT; import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped; import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static androidx.media3.transformer.Composition.HDR_MODE_KEEP_HDR; import static androidx.media3.transformer.Composition.HDR_MODE_KEEP_HDR;
import static androidx.media3.transformer.Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC; import static androidx.media3.transformer.Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL;
import static androidx.media3.transformer.mh.FileUtil.assertFileHasColorTransfer; import static androidx.media3.transformer.mh.FileUtil.assertFileHasColorTransfer;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@ -252,7 +252,7 @@ public final class HdrEditingTest {
assertThat(originalTransformationRequest.hdrMode).isEqualTo(HDR_MODE_KEEP_HDR); assertThat(originalTransformationRequest.hdrMode).isEqualTo(HDR_MODE_KEEP_HDR);
isToneMappingFallbackApplied.set( isToneMappingFallbackApplied.set(
fallbackTransformationRequest.hdrMode fallbackTransformationRequest.hdrMode
== HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC); == HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL);
} }
}) })
.build(); .build();
@ -318,7 +318,7 @@ public final class HdrEditingTest {
assertThat(originalTransformationRequest.hdrMode).isEqualTo(HDR_MODE_KEEP_HDR); assertThat(originalTransformationRequest.hdrMode).isEqualTo(HDR_MODE_KEEP_HDR);
isToneMappingFallbackApplied.set( isToneMappingFallbackApplied.set(
fallbackTransformationRequest.hdrMode fallbackTransformationRequest.hdrMode
== HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC); == HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL);
} }
}) })
.build(); .build();

View File

@ -255,7 +255,7 @@ public final class Composition {
* <p>Supported on API 31+, by some device and HDR format combinations. * <p>Supported on API 31+, by some device and HDR format combinations.
* *
* <p>If not supported, {@link Transformer} will attempt to use {@link * <p>If not supported, {@link Transformer} will attempt to use {@link
* #HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC}. * #HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL}.
*/ */
public static final int HDR_MODE_KEEP_HDR = 0; public static final int HDR_MODE_KEEP_HDR = 0;
@ -288,10 +288,10 @@ public final class Composition {
/** /**
* Interpret HDR input as SDR, likely with a washed out look. * Interpret HDR input as SDR, likely with a washed out look.
* *
* <p>This is much more widely supported than {@link #HDR_MODE_KEEP_HDR} and {@link * <p>This is much more widely supported than {@link #HDR_MODE_KEEP_HDR}, {@link
* #HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC}. However, as HDR transfer functions and * #HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC}, and {@link
* metadata will be ignored, contents will be displayed incorrectly, likely with a washed out * #HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL}. However, as HDR transfer functions and metadata
* look. * will be ignored, contents will be displayed incorrectly, likely with a washed out look.
* *
* <p>Using this API may lead to codec errors before API 29. * <p>Using this API may lead to codec errors before API 29.
* *

View File

@ -100,7 +100,6 @@ import org.checkerframework.dataflow.qual.Pure;
} else { } else {
decoderInputColor = firstInputFormat.colorInfo; decoderInputColor = firstInputFormat.colorInfo;
} }
encoderWrapper = encoderWrapper =
new EncoderWrapper( new EncoderWrapper(
encoderFactory, encoderFactory,
@ -108,19 +107,19 @@ import org.checkerframework.dataflow.qual.Pure;
muxerWrapper.getSupportedSampleMimeTypes(C.TRACK_TYPE_VIDEO), muxerWrapper.getSupportedSampleMimeTypes(C.TRACK_TYPE_VIDEO),
transformationRequest, transformationRequest,
fallbackListener); fallbackListener);
encoderOutputBuffer = encoderOutputBuffer =
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED); new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
@Composition.HdrMode int hdrModeAfterFallback = encoderWrapper.getHdrModeAfterFallback();
boolean isMediaCodecToneMapping = boolean isMediaCodecToneMapping =
encoderWrapper.getHdrModeAfterFallback() == HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC hdrModeAfterFallback == HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC
&& ColorInfo.isTransferHdr(decoderInputColor); && ColorInfo.isTransferHdr(decoderInputColor);
ColorInfo videoGraphInputColor = ColorInfo videoGraphInputColor =
isMediaCodecToneMapping ? SDR_BT709_LIMITED : decoderInputColor; isMediaCodecToneMapping ? SDR_BT709_LIMITED : decoderInputColor;
boolean isGlToneMapping = boolean isGlToneMapping =
ColorInfo.isTransferHdr(decoderInputColor) hdrModeAfterFallback == HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL
&& transformationRequest.hdrMode == HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL; && ColorInfo.isTransferHdr(decoderInputColor);
ColorInfo videoGraphOutputColor; ColorInfo videoGraphOutputColor;
if (videoGraphInputColor.colorTransfer == C.COLOR_TRANSFER_SRGB) { if (videoGraphInputColor.colorTransfer == C.COLOR_TRANSFER_SRGB) {
// The sRGB color transfer is only used for images, so when an image gets transcoded into a // The sRGB color transfer is only used for images, so when an image gets transcoded into a
@ -274,7 +273,7 @@ import org.checkerframework.dataflow.qual.Pure;
} }
// HdrMode fallback is only supported from HDR_MODE_KEEP_HDR to // HdrMode fallback is only supported from HDR_MODE_KEEP_HDR to
// HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC. // HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL.
@Composition.HdrMode int hdrMode = transformationRequest.hdrMode; @Composition.HdrMode int hdrMode = transformationRequest.hdrMode;
if (hdrMode == HDR_MODE_KEEP_HDR && isTransferHdr(inputFormat.colorInfo)) { if (hdrMode == HDR_MODE_KEEP_HDR && isTransferHdr(inputFormat.colorInfo)) {
ImmutableList<MediaCodecInfo> hdrEncoders = ImmutableList<MediaCodecInfo> hdrEncoders =
@ -289,7 +288,7 @@ import org.checkerframework.dataflow.qual.Pure;
} }
} }
if (hdrEncoders.isEmpty()) { if (hdrEncoders.isEmpty()) {
hdrMode = HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC; hdrMode = HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL;
} }
} }