Avoid crash when testing spatialization of high channel count audio

For audio with more than 12 channels, no channel mask was determined, which
meant that the code to check spatializability would throw because of creating
an invalid audio format.

Return early if the channel mask was invalid instead (and assume spatialization
isn't possible).

PiperOrigin-RevId: 625618683
This commit is contained in:
andrewlewis 2024-04-17 03:00:55 -07:00 committed by Copybara-Service
parent a58a99e84d
commit 2f8ce053b9

View File

@ -4249,10 +4249,14 @@ public class DefaultTrackSelector extends MappingTrackSelector
MimeTypes.AUDIO_E_AC3_JOC.equals(format.sampleMimeType) && format.channelCount == 16 MimeTypes.AUDIO_E_AC3_JOC.equals(format.sampleMimeType) && format.channelCount == 16
? 12 ? 12
: format.channelCount; : format.channelCount;
int channelConfig = Util.getAudioTrackChannelConfig(linearChannelCount);
if (channelConfig == AudioFormat.CHANNEL_INVALID) {
return false;
}
AudioFormat.Builder builder = AudioFormat.Builder builder =
new AudioFormat.Builder() new AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_16BIT) .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setChannelMask(Util.getAudioTrackChannelConfig(linearChannelCount)); .setChannelMask(channelConfig);
if (format.sampleRate != Format.NO_VALUE) { if (format.sampleRate != Format.NO_VALUE) {
builder.setSampleRate(format.sampleRate); builder.setSampleRate(format.sampleRate);
} }