From a0fe3b29c2078ed5d9e60edf981f3b13ff758101 Mon Sep 17 00:00:00 2001 From: claincly Date: Fri, 21 Apr 2023 18:49:53 +0100 Subject: [PATCH] Allow customizing VideoFrameProcessor input and output colors in MCVR. PiperOrigin-RevId: 526081541 --- .../video/MediaCodecVideoRenderer.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java index bca0edc2a2..4c43ad3f44 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java @@ -1509,6 +1509,28 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { videoFrameProcessingOffsetCount++; } + /** + * Returns a {@link Pair} of {@linkplain ColorInfo input color} and {@linkplain ColorInfo output + * color} to configure the {@code VideoFrameProcessor}. + */ + protected Pair experimentalGetVideoFrameProcessorColorConfiguration( + @Nullable ColorInfo inputColorInfo) { + // TODO(b/279163661) Remove this method after VideoFrameProcessor supports texture ID + // input/output. + if (!ColorInfo.isTransferHdr(inputColorInfo)) { + return Pair.create(ColorInfo.SDR_BT709_LIMITED, ColorInfo.SDR_BT709_LIMITED); + } + + if (inputColorInfo.colorTransfer == C.COLOR_TRANSFER_HLG) { + // SurfaceView only supports BT2020 PQ input, converting HLG to PQ. + return Pair.create( + inputColorInfo, + inputColorInfo.buildUpon().setColorTransfer(C.COLOR_TRANSFER_ST2084).build()); + } + + return Pair.create(inputColorInfo, inputColorInfo); + } + /** * Renders the output buffer with the specified index now. * @@ -1982,22 +2004,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { return false; } - ColorInfo inputColorInfo; - ColorInfo outputColorInfo; - if (inputFormat.colorInfo != null) { - inputColorInfo = inputFormat.colorInfo; - outputColorInfo = - inputColorInfo.colorTransfer == C.COLOR_TRANSFER_HLG - // SurfaceView only supports BT2020 PQ input, converting HLG to PQ. - ? inputColorInfo.buildUpon().setColorTransfer(C.COLOR_TRANSFER_ST2084).build() - : inputColorInfo; - } else { - inputColorInfo = ColorInfo.SDR_BT709_LIMITED; - outputColorInfo = ColorInfo.SDR_BT709_LIMITED; - } - // Playback thread handler. handler = Util.createHandlerForCurrentLooper(); + + Pair inputAndOutputColorInfos = + renderer.experimentalGetVideoFrameProcessorColorConfiguration(inputFormat.colorInfo); try { // TODO(b/243036513): Set rotation in setInputFormat() after supporting changing effects. if (!codecAppliesRotation() && inputFormat.rotationDegrees != 0) { @@ -2013,8 +2024,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { renderer.context, checkNotNull(videoEffects), DebugViewProvider.NONE, - inputColorInfo, - outputColorInfo, + inputAndOutputColorInfos.first, + inputAndOutputColorInfos.second, INPUT_TYPE_SURFACE, /* releaseFramesAutomatically= */ false, /* executor= */ handler::post,