From c744fe9f8f4d59564cab2280c17e641c689d6333 Mon Sep 17 00:00:00 2001 From: rohks Date: Wed, 9 Oct 2024 05:47:29 -0700 Subject: [PATCH] Recognize IAMF format and enhance channel count constraints - Updated `DefaultTrackSelector.SpatializerWrapperV32.canBeSpatialized` to handle IAMF format. - Modified `isAudioFormatWithinAudioChannelCountConstraints` to check for `NO_VALUE` of `channelCount` to improve readability. Note: `DefaultTrackSelector.SpatializerWrapperV32.canBeSpatialized` is not triggered for the IAMF format due to the unset channel count (`Format.NO_VALUE`). The update ensures completeness. #cherrypick PiperOrigin-RevId: 684003980 --- .../trackselection/DefaultTrackSelector.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/trackselection/DefaultTrackSelector.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/trackselection/DefaultTrackSelector.java index 21c3fcdf10..c0aea35814 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/trackselection/DefaultTrackSelector.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/trackselection/DefaultTrackSelector.java @@ -84,6 +84,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; // LINT.IfChange(javadoc) @@ -2816,7 +2817,7 @@ public class DefaultTrackSelector extends MappingTrackSelector synchronized (lock) { return !parameters.constrainAudioChannelCountToDeviceCapabilities || deviceIsTV - || format.channelCount <= 2 + || (format.channelCount == Format.NO_VALUE || format.channelCount <= 2) || (isDolbyAudio(format) && (Util.SDK_INT < 32 || spatializer == null @@ -4198,13 +4199,23 @@ public class DefaultTrackSelector extends MappingTrackSelector } public boolean canBeSpatialized(AudioAttributes audioAttributes, Format format) { - // For E-AC3 JOC, the format is object based. When the channel count is 16, this maps to 12 - // linear channels and the rest are used for objects. See - // https://github.com/google/ExoPlayer/pull/10322#discussion_r895265881 - int linearChannelCount = - MimeTypes.AUDIO_E_AC3_JOC.equals(format.sampleMimeType) && format.channelCount == 16 - ? 12 - : format.channelCount; + int linearChannelCount; + if (Objects.equals(format.sampleMimeType, MimeTypes.AUDIO_E_AC3_JOC) + && format.channelCount == 16) { + // For E-AC3 JOC, the format is object based. When the channel count is 16, this maps to 12 + // linear channels and the rest are used for objects. See + // https://github.com/google/ExoPlayer/pull/10322#discussion_r895265881 + linearChannelCount = 12; + } else if (Objects.equals(format.sampleMimeType, MimeTypes.AUDIO_IAMF) + && format.channelCount == Format.NO_VALUE) { + // IAMF with no channel count specified, assume 5.1 channels. This depends on + // IamfDecoder.SPATIALIZED_OUTPUT_LAYOUT being set to AudioFormat.CHANNEL_OUT_5POINT1. Any + // changes to that constant will require updates to this logic. + linearChannelCount = 6; + } else { + linearChannelCount = format.channelCount; + } + int channelConfig = Util.getAudioTrackChannelConfig(linearChannelCount); if (channelConfig == AudioFormat.CHANNEL_INVALID) { return false;