From 27eb204542dd461a8d77ff58d4ec9599ce336a33 Mon Sep 17 00:00:00 2001 From: ibaker Date: Mon, 17 Mar 2025 04:44:35 -0700 Subject: [PATCH] Indicate MediaCodec FLAC decoder doesn't support 32-bit below API 34 This transforms the reported format support from `supported=YES` to `supported=NO_EXCEEDS_CAPABILITIES`. Playback is still attempted in the main demo app, and hangs as described in https://github.com/androidx/media/issues/2197#issuecomment-2722322954. PiperOrigin-RevId: 737568955 --- .../exoplayer/mediacodec/MediaCodecInfo.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecInfo.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecInfo.java index dc347ce6aa..08ef1d5be6 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecInfo.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecInfo.java @@ -43,6 +43,7 @@ import android.util.Pair; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.VisibleForTesting; +import androidx.media3.common.C; import androidx.media3.common.ColorInfo; import androidx.media3.common.Format; import androidx.media3.common.MimeTypes; @@ -268,6 +269,10 @@ public final class MediaCodecInfo { return false; } + if (!isCompressedAudioBitDepthSupported(format)) { + return false; + } + if (isVideo) { if (format.width <= 0 || format.height <= 0) { return true; @@ -289,7 +294,8 @@ public final class MediaCodecInfo { */ public boolean isFormatFunctionallySupported(Format format) { return isSampleMimeTypeSupported(format) - && isCodecProfileAndLevelSupported(format, /* checkPerformanceCapabilities= */ false); + && isCodecProfileAndLevelSupported(format, /* checkPerformanceCapabilities= */ false) + && isCompressedAudioBitDepthSupported(format); } private boolean isSampleMimeTypeSupported(Format format) { @@ -365,6 +371,17 @@ public final class MediaCodecInfo { return false; } + private boolean isCompressedAudioBitDepthSupported(Format format) { + // MediaCodec doesn't have a way to query FLAC decoder bit-depth support. + // c2.android.flac.decoder is known not to support 32-bit until API 34. We optimistically assume + // that another (unrecognized) FLAC decoder does support 32-bit on all API levels where it + // exists. + return !Objects.equals(format.sampleMimeType, MimeTypes.AUDIO_FLAC) + || format.pcmEncoding != C.ENCODING_PCM_32BIT + || Util.SDK_INT >= 34 + || !name.equals("c2.android.flac.decoder"); + } + /** Whether the codec handles HDR10+ out-of-band metadata. */ public boolean isHdr10PlusOutOfBandMetadataSupported() { if (Util.SDK_INT >= 29 && MimeTypes.VIDEO_VP9.equals(mimeType)) {