From e1fa0d0fb44237b866a6bdfab804b16c030ca8f3 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Thu, 29 Jul 2021 17:34:52 -0700 Subject: [PATCH] AudioMix: Always produce output channel masks from Builder Ensure that AudioMix.Builder always produces and AudioMix which uses an output channel mask. There are assumptions in the framework that this is the case, however clients can actually pass an input mask. Bug: 194910301 Test: gts-tradefed run gts -m GtsGmscoreHostTestCases \ -t com.google.android.gts.audio.AudioHostTest Change-Id: I698eef509a0e3427b7cfc4bf8b045379416f7964 --- media/java/android/media/audiopolicy/AudioMix.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/media/java/android/media/audiopolicy/AudioMix.java b/media/java/android/media/audiopolicy/AudioMix.java index d00e5b55fd14e..fbd2d8d031fdf 100644 --- a/media/java/android/media/audiopolicy/AudioMix.java +++ b/media/java/android/media/audiopolicy/AudioMix.java @@ -420,6 +420,20 @@ public class AudioMix { rate = 44100; } mFormat = new AudioFormat.Builder().setSampleRate(rate).build(); + } else { + // Ensure that 'mFormat' uses an output channel mask. Using an input channel + // mask was not made 'illegal' initially, however the framework code + // assumes usage in AudioMixes of output channel masks only (b/194910301). + if ((mFormat.getPropertySetMask() + & AudioFormat.AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK) != 0) { + if (mFormat.getChannelCount() == 1 + && mFormat.getChannelMask() == AudioFormat.CHANNEL_IN_MONO) { + mFormat = new AudioFormat.Builder(mFormat).setChannelMask( + AudioFormat.CHANNEL_OUT_MONO).build(); + } + // CHANNEL_IN_STEREO == CHANNEL_OUT_STEREO so no need to correct. + // CHANNEL_IN_FRONT_BACK is hidden, should not appear. + } } if ((mDeviceSystemType != AudioSystem.DEVICE_NONE) && (mDeviceSystemType != AudioSystem.DEVICE_OUT_REMOTE_SUBMIX)