Skip to content

Commit 9b4b008

Browse files
committed
Add AC-4 decoder capability assessment during track selection
Beginning with Android 16, some devices will expose AC-4 profile/level information. This update adds AC-4 decoder capability assessment during track selection.
1 parent 3271632 commit 9b4b008

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecInfo.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,22 @@ private boolean isCodecProfileAndLevelSupported(
357357
}
358358
}
359359

360-
if (!isVideo && profile != CodecProfileLevel.AACObjectXHE) {
360+
if (!isVideo &&
361+
!mimeType.equals(MimeTypes.AUDIO_AC4) &&
362+
profile != CodecProfileLevel.AACObjectXHE) {
363+
// AC-4 decoder reports profile levels or audio capabilities that determine whether input
364+
// format is supported or not.
361365
// Some devices/builds underreport audio capabilities, so assume support except for xHE-AAC
362366
// which may not be widely supported. See https://github.com/google/ExoPlayer/issues/5145.
363367
return true;
364368
}
365369

366370
CodecProfileLevel[] profileLevels = getProfileLevels();
371+
if (MimeTypes.AUDIO_AC4.equals(mimeType) && profileLevels.length == 0) {
372+
// Some older devices don't report profile levels for AC-4. Estimate them using other data
373+
// in the codec capabilities.
374+
profileLevels = estimateLegacyAc4ProfileLevels(capabilities);
375+
}
367376
if (SDK_INT <= 23 && MimeTypes.VIDEO_VP9.equals(mimeType) && profileLevels.length == 0) {
368377
// Some older devices don't report profile levels for VP9. Estimate them using other data in
369378
// the codec capabilities.
@@ -819,6 +828,39 @@ private static int getMaxSupportedInstancesV23(CodecCapabilities capabilities) {
819828
return capabilities.getMaxSupportedInstances();
820829
}
821830

831+
/**
832+
* Called on devices with AC-4 decoders whose {@link CodecCapabilities} do not report profile
833+
* levels. The returned {@link CodecProfileLevel CodecProfileLevels} are estimated based on other
834+
* data in the {@link CodecCapabilities}.
835+
*
836+
* @param capabilities The {@link CodecCapabilities} for an AC-4 decoder, or {@code null} if not
837+
* known.
838+
* @return The estimated {@link CodecProfileLevel CodecProfileLevels} for the decoder.
839+
*/
840+
private static CodecProfileLevel[] estimateLegacyAc4ProfileLevels(
841+
@Nullable CodecCapabilities capabilities) {
842+
int maxInChCount = 2;
843+
if (capabilities != null) {
844+
@Nullable AudioCapabilities audioCapabilities = capabilities.getAudioCapabilities();
845+
if (audioCapabilities != null) {
846+
maxInChCount = audioCapabilities.getMaxInputChannelCount();
847+
}
848+
}
849+
850+
int level = CodecProfileLevel.AC4Level3;
851+
if (maxInChCount > 18) { // AC-4 Level 3 stream is up to 17.1 channel
852+
level = CodecProfileLevel.AC4Level4;
853+
}
854+
855+
return new CodecProfileLevel[] {
856+
createCodecProfileLevel(CodecProfileLevel.AC4Profile00, level),
857+
createCodecProfileLevel(CodecProfileLevel.AC4Profile10, level),
858+
createCodecProfileLevel(CodecProfileLevel.AC4Profile11, level),
859+
createCodecProfileLevel(CodecProfileLevel.AC4Profile21, level),
860+
createCodecProfileLevel(CodecProfileLevel.AC4Profile22, level)
861+
};
862+
}
863+
822864
/**
823865
* Called on devices with {@link Build.VERSION#SDK_INT} 23 and below, for VP9 decoders whose
824866
* {@link CodecCapabilities} do not correctly report profile levels. The returned {@link

0 commit comments

Comments
 (0)