From e510d9903ff30c4ec308bdcfba114e8889aad20c Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Mon, 7 Nov 2022 19:21:21 +0000 Subject: [PATCH] HDR: Set decoder codec profile and level if available. This should be necessary to ensure decoders see fewer errors. Setting this resulted in removing native_dequeueOutputBuffer errors on OMX.MTK decoders for in-app tone mapping prototyping. PiperOrigin-RevId: 486715941 --- .../media3/transformer/DefaultDecoderFactory.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java index 277f00e261..ce0fbcfc76 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java @@ -22,11 +22,13 @@ import static androidx.media3.common.util.Util.SDK_INT; import android.annotation.SuppressLint; import android.content.Context; import android.media.MediaFormat; +import android.util.Pair; import android.view.Surface; import androidx.annotation.Nullable; import androidx.media3.common.Format; import androidx.media3.common.MimeTypes; import androidx.media3.common.util.MediaFormatUtil; +import androidx.media3.exoplayer.mediacodec.MediaCodecUtil; import org.checkerframework.checker.nullness.qual.RequiresNonNull; /** A default implementation of {@link Codec.DecoderFactory}. */ @@ -90,6 +92,13 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; MediaFormat.KEY_COLOR_TRANSFER_REQUEST, MediaFormat.COLOR_TRANSFER_SDR_VIDEO); } + @Nullable + Pair codecProfileAndLevel = MediaCodecUtil.getCodecProfileAndLevel(format); + if (codecProfileAndLevel != null) { + MediaFormatUtil.maybeSetInteger( + mediaFormat, MediaFormat.KEY_PROFILE, codecProfileAndLevel.first); + } + @Nullable String mediaCodecName = EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ true); if (mediaCodecName == null) {