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
This commit is contained in:
rohks 2024-10-09 05:47:29 -07:00 committed by Copybara-Service
parent 4df7216bc0
commit c744fe9f8f

View file

@ -84,6 +84,7 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
// LINT.IfChange(javadoc) // LINT.IfChange(javadoc)
@ -2816,7 +2817,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
synchronized (lock) { synchronized (lock) {
return !parameters.constrainAudioChannelCountToDeviceCapabilities return !parameters.constrainAudioChannelCountToDeviceCapabilities
|| deviceIsTV || deviceIsTV
|| format.channelCount <= 2 || (format.channelCount == Format.NO_VALUE || format.channelCount <= 2)
|| (isDolbyAudio(format) || (isDolbyAudio(format)
&& (Util.SDK_INT < 32 && (Util.SDK_INT < 32
|| spatializer == null || spatializer == null
@ -4198,13 +4199,23 @@ public class DefaultTrackSelector extends MappingTrackSelector
} }
public boolean canBeSpatialized(AudioAttributes audioAttributes, Format format) { 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 int linearChannelCount;
// linear channels and the rest are used for objects. See if (Objects.equals(format.sampleMimeType, MimeTypes.AUDIO_E_AC3_JOC)
// https://github.com/google/ExoPlayer/pull/10322#discussion_r895265881 && format.channelCount == 16) {
int linearChannelCount = // For E-AC3 JOC, the format is object based. When the channel count is 16, this maps to 12
MimeTypes.AUDIO_E_AC3_JOC.equals(format.sampleMimeType) && format.channelCount == 16 // linear channels and the rest are used for objects. See
? 12 // https://github.com/google/ExoPlayer/pull/10322#discussion_r895265881
: format.channelCount; 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); int channelConfig = Util.getAudioTrackChannelConfig(linearChannelCount);
if (channelConfig == AudioFormat.CHANNEL_INVALID) { if (channelConfig == AudioFormat.CHANNEL_INVALID) {
return false; return false;