From 7424cffce19580fbbd4349a4d94b11d708a7c0e5 Mon Sep 17 00:00:00 2001 From: tofunmi Date: Fri, 26 Jan 2024 09:14:38 -0800 Subject: [PATCH] Support changing input colorinfo for images since we now can support taking in the inputColor upon registering the stream, there is no need to hardcode the image input color anymore. We should now be able to support switching between texture and image input which we couldn't before, but this is untested and not necessary. PiperOrigin-RevId: 601784149 --- .../main/java/androidx/media3/effect/InputSwitcher.java | 8 ++------ .../media3/transformer/VideoFrameProcessingWrapper.java | 6 +++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/effect/src/main/java/androidx/media3/effect/InputSwitcher.java b/libraries/effect/src/main/java/androidx/media3/effect/InputSwitcher.java index afdb7ebfa8..3b4bd0de46 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/InputSwitcher.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/InputSwitcher.java @@ -28,7 +28,6 @@ import static androidx.media3.common.util.Util.contains; import android.content.Context; import android.util.SparseArray; import android.view.Surface; -import androidx.media3.common.C; import androidx.media3.common.ColorInfo; import androidx.media3.common.FrameInfo; import androidx.media3.common.GlObjectsProvider; @@ -99,16 +98,13 @@ import org.checkerframework.checker.nullness.qual.Nullable; context, inputColorInfo, outputColorInfo, enableColorTransfers); break; case INPUT_TYPE_BITMAP: - // HDR bitmap input is not supported. Bitmaps are always sRGB/Full range/BT.709. + // HDR bitmap input is not supported. checkState(!ColorInfo.isTransferHdr(inputColorInfo)); - ColorInfo bitmapColorInfo = ColorInfo.SRGB_BT709_FULL; samplingShaderProgram = DefaultShaderProgram.createWithInternalSampler( - context, bitmapColorInfo, outputColorInfo, enableColorTransfers, inputType); + context, inputColorInfo, outputColorInfo, enableColorTransfers, inputType); break; case INPUT_TYPE_TEXTURE_ID: - // Image and textureId concatenation not supported. - checkState(inputColorInfo.colorTransfer != C.COLOR_TRANSFER_SRGB); samplingShaderProgram = DefaultShaderProgram.createWithInternalSampler( context, inputColorInfo, outputColorInfo, enableColorTransfers, inputType); diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/VideoFrameProcessingWrapper.java b/libraries/transformer/src/main/java/androidx/media3/transformer/VideoFrameProcessingWrapper.java index e45fc263bf..69beafcece 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/VideoFrameProcessingWrapper.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/VideoFrameProcessingWrapper.java @@ -68,10 +68,14 @@ import java.util.concurrent.atomic.AtomicLong; boolean isLast) { if (trackFormat != null) { Size decodedSize = getDecodedSize(trackFormat); + ColorInfo colorInfo = + trackFormat.colorInfo == null || !trackFormat.colorInfo.isDataSpaceValid() + ? inputColorInfo + : trackFormat.colorInfo; videoFrameProcessor.registerInputStream( getInputType(checkNotNull(trackFormat.sampleMimeType)), createEffectListWithPresentation(editedMediaItem.effects.videoEffects, presentation), - new FrameInfo.Builder(inputColorInfo, decodedSize.getWidth(), decodedSize.getHeight()) + new FrameInfo.Builder(colorInfo, decodedSize.getWidth(), decodedSize.getHeight()) .setPixelWidthHeightRatio(trackFormat.pixelWidthHeightRatio) .setOffsetToAddUs(initialTimestampOffsetUs + mediaItemOffsetUs.get()) .build());