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
This commit is contained in:
ibaker 2025-03-17 04:44:35 -07:00 committed by Copybara-Service
parent cc4ffbe8cf
commit 27eb204542

View File

@ -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)) {