From 2a187cbf568287ed9321cad9e1a9c8881ea17fe3 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 --- .../exoplayer2/transformer/DefaultEncoderFactory.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java index a4f298a463..2a6e385a40 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java @@ -174,7 +174,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); @@ -184,12 +184,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);