From ba3558c0c6f45add5fcfaebd8b55fa0d112e760e Mon Sep 17 00:00:00 2001 From: claincly Date: Thu, 10 Feb 2022 18:50:14 +0000 Subject: [PATCH] Disable setting profile/level for API level < 24. We have seen devices running on API21/23 fail transcoding because of setting encoding profile/level. Some devices (ale-123/nexus 7) on API21 returns ENOSYS (Function not implemented) when being configured with a profile setting. (although API21 introduced the capability of setting encoding profile) Some devices (nexus 5) on API23 fails configuration with a specific parameter set, despite advertising support for it. Not setting the baseline profile has no effect on encoding, because when not set, the encoding will pick a suitable profile to use. Since baseline is the lowest possible profile, the auto-picked value can't be worse than baseline. Ref: b/218696352 PiperOrigin-RevId: 427792124 --- .../media3/transformer/DefaultEncoderFactory.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultEncoderFactory.java b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultEncoderFactory.java index 639e9728bc..f901efe5e0 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultEncoderFactory.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultEncoderFactory.java @@ -176,7 +176,7 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory { // in-app muxing. mediaFormat.setInteger(MediaFormat.KEY_LATENCY, 1); } - } else if (Util.SDK_INT >= 23) { + } else if (Util.SDK_INT >= 24) { int supportedLevel = EncoderUtil.findHighestSupportedEncodingLevel( encoderInfo, mimeType, MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline); @@ -186,12 +186,9 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory { mediaFormat.setInteger( MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline); mediaFormat.setInteger(MediaFormat.KEY_LEVEL, supportedLevel); - } else { - // Use the baseline profile for safest results, as encoding in baseline is required per - // https://source.android.com/compatibility/5.0/android-5.0-cdd#5_2_video_encoding - mediaFormat.setInteger( - MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline); } + // For API levels below 24, setting profile and level can lead to failures in MediaCodec + // configuration. The encoder selects the profile/level when we don't set them. } mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, DEFAULT_COLOR_FORMAT);