Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 17 | #include <Utils.h> |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 18 | #include <aidl/android/media/audio/common/AudioChannelLayout.h> |
| 19 | #include <aidl/android/media/audio/common/AudioDeviceType.h> |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 20 | #include <aidl/android/media/audio/common/AudioFormatDescription.h> |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 21 | #include <aidl/android/media/audio/common/AudioFormatType.h> |
| 22 | #include <aidl/android/media/audio/common/AudioIoFlags.h> |
| 23 | #include <aidl/android/media/audio/common/AudioOutputFlags.h> |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 24 | #include <media/stagefright/foundation/MediaDefs.h> |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 25 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 26 | #include "core-impl/Configuration.h" |
| 27 | |
Mikhail Naganov | 872d4a6 | 2023-03-09 18:19:01 -0800 | [diff] [blame] | 28 | using aidl::android::hardware::audio::common::makeBitPositionFlagMask; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 29 | using aidl::android::media::audio::common::AudioChannelLayout; |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 30 | using aidl::android::media::audio::common::AudioDeviceDescription; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 31 | using aidl::android::media::audio::common::AudioDeviceType; |
| 32 | using aidl::android::media::audio::common::AudioFormatDescription; |
| 33 | using aidl::android::media::audio::common::AudioFormatType; |
| 34 | using aidl::android::media::audio::common::AudioGainConfig; |
| 35 | using aidl::android::media::audio::common::AudioIoFlags; |
| 36 | using aidl::android::media::audio::common::AudioOutputFlags; |
| 37 | using aidl::android::media::audio::common::AudioPort; |
| 38 | using aidl::android::media::audio::common::AudioPortConfig; |
| 39 | using aidl::android::media::audio::common::AudioPortDeviceExt; |
| 40 | using aidl::android::media::audio::common::AudioPortExt; |
| 41 | using aidl::android::media::audio::common::AudioPortMixExt; |
| 42 | using aidl::android::media::audio::common::AudioProfile; |
| 43 | using aidl::android::media::audio::common::Int; |
Mikhail Naganov | 6725ef5 | 2023-02-09 17:52:50 -0800 | [diff] [blame] | 44 | using aidl::android::media::audio::common::MicrophoneInfo; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 45 | using aidl::android::media::audio::common::PcmType; |
| 46 | |
| 47 | namespace aidl::android::hardware::audio::core::internal { |
| 48 | |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 49 | static void fillProfile(AudioProfile* profile, const std::vector<int32_t>& channelLayouts, |
| 50 | const std::vector<int32_t>& sampleRates) { |
| 51 | for (auto layout : channelLayouts) { |
| 52 | profile->channelMasks.push_back( |
| 53 | AudioChannelLayout::make<AudioChannelLayout::layoutMask>(layout)); |
| 54 | } |
| 55 | profile->sampleRates.insert(profile->sampleRates.end(), sampleRates.begin(), sampleRates.end()); |
| 56 | } |
| 57 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 58 | static AudioProfile createProfile(PcmType pcmType, const std::vector<int32_t>& channelLayouts, |
| 59 | const std::vector<int32_t>& sampleRates) { |
| 60 | AudioProfile profile; |
| 61 | profile.format.type = AudioFormatType::PCM; |
| 62 | profile.format.pcm = pcmType; |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 63 | fillProfile(&profile, channelLayouts, sampleRates); |
| 64 | return profile; |
| 65 | } |
| 66 | |
| 67 | static AudioProfile createProfile(const std::string& encodingType, |
| 68 | const std::vector<int32_t>& channelLayouts, |
| 69 | const std::vector<int32_t>& sampleRates) { |
| 70 | AudioProfile profile; |
| 71 | profile.format.encoding = encodingType; |
| 72 | fillProfile(&profile, channelLayouts, sampleRates); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 73 | return profile; |
| 74 | } |
| 75 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 76 | static AudioPortExt createDeviceExt(AudioDeviceType devType, int32_t flags, |
| 77 | std::string connection = "") { |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 78 | AudioPortDeviceExt deviceExt; |
| 79 | deviceExt.device.type.type = devType; |
Mikhail Naganov | b0f3d97 | 2023-01-27 16:08:29 -0800 | [diff] [blame] | 80 | if (devType == AudioDeviceType::IN_MICROPHONE && connection.empty()) { |
| 81 | deviceExt.device.address = "bottom"; |
| 82 | } else if (devType == AudioDeviceType::IN_MICROPHONE_BACK && connection.empty()) { |
| 83 | deviceExt.device.address = "back"; |
| 84 | } |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 85 | deviceExt.device.type.connection = std::move(connection); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 86 | deviceExt.flags = flags; |
| 87 | return AudioPortExt::make<AudioPortExt::Tag::device>(deviceExt); |
| 88 | } |
| 89 | |
| 90 | static AudioPortExt createPortMixExt(int32_t maxOpenStreamCount, int32_t maxActiveStreamCount) { |
| 91 | AudioPortMixExt mixExt; |
| 92 | mixExt.maxOpenStreamCount = maxOpenStreamCount; |
| 93 | mixExt.maxActiveStreamCount = maxActiveStreamCount; |
| 94 | return AudioPortExt::make<AudioPortExt::Tag::mix>(mixExt); |
| 95 | } |
| 96 | |
| 97 | static AudioPort createPort(int32_t id, const std::string& name, int32_t flags, bool isInput, |
| 98 | const AudioPortExt& ext) { |
| 99 | AudioPort port; |
| 100 | port.id = id; |
| 101 | port.name = name; |
| 102 | port.flags = isInput ? AudioIoFlags::make<AudioIoFlags::Tag::input>(flags) |
| 103 | : AudioIoFlags::make<AudioIoFlags::Tag::output>(flags); |
| 104 | port.ext = ext; |
| 105 | return port; |
| 106 | } |
| 107 | |
| 108 | static AudioPortConfig createPortConfig(int32_t id, int32_t portId, PcmType pcmType, int32_t layout, |
| 109 | int32_t sampleRate, int32_t flags, bool isInput, |
| 110 | const AudioPortExt& ext) { |
| 111 | AudioPortConfig config; |
| 112 | config.id = id; |
| 113 | config.portId = portId; |
| 114 | config.sampleRate = Int{.value = sampleRate}; |
| 115 | config.channelMask = AudioChannelLayout::make<AudioChannelLayout::layoutMask>(layout); |
| 116 | config.format = AudioFormatDescription{.type = AudioFormatType::PCM, .pcm = pcmType}; |
| 117 | config.gain = AudioGainConfig(); |
| 118 | config.flags = isInput ? AudioIoFlags::make<AudioIoFlags::Tag::input>(flags) |
| 119 | : AudioIoFlags::make<AudioIoFlags::Tag::output>(flags); |
| 120 | config.ext = ext; |
| 121 | return config; |
| 122 | } |
| 123 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 124 | static AudioRoute createRoute(const std::vector<AudioPort>& sources, const AudioPort& sink) { |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 125 | AudioRoute route; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 126 | route.sinkPortId = sink.id; |
| 127 | std::transform(sources.begin(), sources.end(), std::back_inserter(route.sourcePortIds), |
| 128 | [](const auto& port) { return port.id; }); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 129 | return route; |
| 130 | } |
| 131 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 132 | // Primary (default) configuration: |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 133 | // |
| 134 | // Device ports: |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 135 | // * "Speaker", OUT_SPEAKER, default |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 136 | // - no profiles specified |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 137 | // * "Built-In Mic", IN_MICROPHONE, default |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 138 | // - no profiles specified |
| 139 | // * "Telephony Tx", OUT_TELEPHONY_TX |
| 140 | // - no profiles specified |
| 141 | // * "Telephony Rx", IN_TELEPHONY_RX |
| 142 | // - no profiles specified |
| 143 | // * "FM Tuner", IN_FM_TUNER |
| 144 | // - no profiles specified |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 145 | // |
| 146 | // Mix ports: |
| 147 | // * "primary output", PRIMARY, 1 max open, 1 max active stream |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 148 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 149 | // * "primary input", 1 max open, 1 max active stream |
| 150 | // - profile PCM 16-bit; MONO, STEREO; |
| 151 | // 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 152 | // * "telephony_tx", 1 max open, 1 max active stream |
| 153 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 154 | // * "telephony_rx", 1 max open, 1 max active stream |
| 155 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 156 | // * "fm_tuner", 1 max open, 1 max active stream |
| 157 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 158 | // |
| 159 | // Routes: |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 160 | // "primary out" -> "Speaker" |
| 161 | // "Built-In Mic" -> "primary input" |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 162 | // "Telephony Rx" -> "telephony_rx" |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 163 | // "telephony_tx" -> "Telephony Tx" |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 164 | // "FM Tuner" -> "fm_tuner" |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 165 | // |
| 166 | // Initial port configs: |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 167 | // * "Speaker" device port: PCM 16-bit; STEREO; 48000 |
| 168 | // * "Built-In Mic" device port: PCM 16-bit; MONO; 48000 |
| 169 | // * "Telephony Tx" device port: PCM 16-bit; MONO; 48000 |
| 170 | // * "Telephony Rx" device port: PCM 16-bit; MONO; 48000 |
| 171 | // * "FM Tuner" device port: PCM 16-bit; STEREO; 48000 |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 172 | // |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 173 | std::unique_ptr<Configuration> getPrimaryConfiguration() { |
| 174 | static const Configuration configuration = []() { |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 175 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 176 | createProfile(PcmType::INT_16_BIT, |
| 177 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 178 | {8000, 11025, 16000, 32000, 44100, 48000})}; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 179 | Configuration c; |
| 180 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 181 | // Device ports |
| 182 | |
| 183 | AudioPort speakerOutDevice = |
| 184 | createPort(c.nextPortId++, "Speaker", 0, false, |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 185 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, |
| 186 | 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 187 | c.ports.push_back(speakerOutDevice); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 188 | c.initialConfigs.push_back( |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 189 | createPortConfig(speakerOutDevice.id, speakerOutDevice.id, PcmType::INT_16_BIT, |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 190 | AudioChannelLayout::LAYOUT_STEREO, 48000, 0, false, |
| 191 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, 0))); |
| 192 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 193 | AudioPort micInDevice = |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 194 | createPort(c.nextPortId++, "Built-In Mic", 0, true, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 195 | createDeviceExt(AudioDeviceType::IN_MICROPHONE, |
| 196 | 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE)); |
| 197 | c.ports.push_back(micInDevice); |
| 198 | c.initialConfigs.push_back( |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 199 | createPortConfig(micInDevice.id, micInDevice.id, PcmType::INT_16_BIT, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 200 | AudioChannelLayout::LAYOUT_MONO, 48000, 0, true, |
| 201 | createDeviceExt(AudioDeviceType::IN_MICROPHONE, 0))); |
| 202 | |
| 203 | AudioPort telephonyTxOutDevice = |
| 204 | createPort(c.nextPortId++, "Telephony Tx", 0, false, |
| 205 | createDeviceExt(AudioDeviceType::OUT_TELEPHONY_TX, 0)); |
| 206 | c.ports.push_back(telephonyTxOutDevice); |
| 207 | c.initialConfigs.push_back( |
| 208 | createPortConfig(telephonyTxOutDevice.id, telephonyTxOutDevice.id, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 209 | PcmType::INT_16_BIT, AudioChannelLayout::LAYOUT_MONO, 48000, 0, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 210 | false, createDeviceExt(AudioDeviceType::OUT_TELEPHONY_TX, 0))); |
| 211 | |
| 212 | AudioPort telephonyRxInDevice = |
| 213 | createPort(c.nextPortId++, "Telephony Rx", 0, true, |
| 214 | createDeviceExt(AudioDeviceType::IN_TELEPHONY_RX, 0)); |
| 215 | c.ports.push_back(telephonyRxInDevice); |
| 216 | c.initialConfigs.push_back( |
| 217 | createPortConfig(telephonyRxInDevice.id, telephonyRxInDevice.id, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 218 | PcmType::INT_16_BIT, AudioChannelLayout::LAYOUT_MONO, 48000, 0, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 219 | true, createDeviceExt(AudioDeviceType::IN_TELEPHONY_RX, 0))); |
| 220 | |
| 221 | AudioPort fmTunerInDevice = createPort(c.nextPortId++, "FM Tuner", 0, true, |
| 222 | createDeviceExt(AudioDeviceType::IN_FM_TUNER, 0)); |
| 223 | c.ports.push_back(fmTunerInDevice); |
| 224 | c.initialConfigs.push_back( |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 225 | createPortConfig(fmTunerInDevice.id, fmTunerInDevice.id, PcmType::INT_16_BIT, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 226 | AudioChannelLayout::LAYOUT_STEREO, 48000, 0, true, |
| 227 | createDeviceExt(AudioDeviceType::IN_FM_TUNER, 0))); |
| 228 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 229 | // Mix ports |
| 230 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 231 | AudioPort primaryOutMix = createPort(c.nextPortId++, "primary output", |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 232 | makeBitPositionFlagMask(AudioOutputFlags::PRIMARY), |
Shunkai Yao | 2461891 | 2023-08-18 23:58:05 +0000 | [diff] [blame] | 233 | false, createPortMixExt(0, 0)); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 234 | primaryOutMix.profiles.insert(primaryOutMix.profiles.begin(), |
| 235 | standardPcmAudioProfiles.begin(), |
| 236 | standardPcmAudioProfiles.end()); |
| 237 | c.ports.push_back(primaryOutMix); |
| 238 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 239 | AudioPort primaryInMix = |
Shunkai Yao | 2461891 | 2023-08-18 23:58:05 +0000 | [diff] [blame] | 240 | createPort(c.nextPortId++, "primary input", 0, true, createPortMixExt(0, 0)); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 241 | primaryInMix.profiles.push_back( |
| 242 | createProfile(PcmType::INT_16_BIT, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 243 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 244 | {8000, 11025, 16000, 32000, 44100, 48000})); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 245 | c.ports.push_back(primaryInMix); |
| 246 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 247 | AudioPort telephonyTxOutMix = |
| 248 | createPort(c.nextPortId++, "telephony_tx", 0, false, createPortMixExt(1, 1)); |
| 249 | telephonyTxOutMix.profiles.insert(telephonyTxOutMix.profiles.begin(), |
| 250 | standardPcmAudioProfiles.begin(), |
| 251 | standardPcmAudioProfiles.end()); |
| 252 | c.ports.push_back(telephonyTxOutMix); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 253 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 254 | AudioPort telephonyRxInMix = |
| 255 | createPort(c.nextPortId++, "telephony_rx", 0, true, createPortMixExt(1, 1)); |
| 256 | telephonyRxInMix.profiles.insert(telephonyRxInMix.profiles.begin(), |
| 257 | standardPcmAudioProfiles.begin(), |
| 258 | standardPcmAudioProfiles.end()); |
| 259 | c.ports.push_back(telephonyRxInMix); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 260 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 261 | AudioPort fmTunerInMix = |
| 262 | createPort(c.nextPortId++, "fm_tuner", 0, true, createPortMixExt(1, 1)); |
| 263 | fmTunerInMix.profiles.insert(fmTunerInMix.profiles.begin(), |
| 264 | standardPcmAudioProfiles.begin(), |
| 265 | standardPcmAudioProfiles.end()); |
| 266 | c.ports.push_back(fmTunerInMix); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 267 | |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 268 | c.routes.push_back(createRoute({primaryOutMix}, speakerOutDevice)); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 269 | c.routes.push_back(createRoute({micInDevice}, primaryInMix)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 270 | c.routes.push_back(createRoute({telephonyRxInDevice}, telephonyRxInMix)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 271 | c.routes.push_back(createRoute({telephonyTxOutMix}, telephonyTxOutDevice)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 272 | c.routes.push_back(createRoute({fmTunerInDevice}, fmTunerInMix)); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 273 | |
| 274 | c.portConfigs.insert(c.portConfigs.end(), c.initialConfigs.begin(), c.initialConfigs.end()); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 275 | |
| 276 | MicrophoneInfo mic; |
| 277 | mic.id = "mic"; |
| 278 | mic.device = micInDevice.ext.get<AudioPortExt::Tag::device>().device; |
| 279 | mic.group = 0; |
| 280 | mic.indexInTheGroup = 0; |
| 281 | c.microphones = std::vector<MicrophoneInfo>{mic}; |
| 282 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 283 | return c; |
| 284 | }(); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 285 | return std::make_unique<Configuration>(configuration); |
| 286 | } |
| 287 | |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 288 | // Note: When transitioning to loading of XML configs, either keep the configuration |
| 289 | // of the remote submix sources from this static configuration, or update the XML |
| 290 | // config to match it. There are two reasons for that: |
| 291 | // 1. The canonical r_submix configuration only lists 'STEREO' and '48000', |
| 292 | // however the framework attempts to open streams for other sample rates |
| 293 | // as well. The legacy r_submix implementation allowed that, but libaudiohal@aidl |
| 294 | // will not find a mix port to use. Because of that, list all channel |
| 295 | // masks and sample rates that the legacy implementation allowed. |
| 296 | // 2. The legacy implementation had a hard limit on the number of routes (10), |
| 297 | // and this is checked indirectly by AudioPlaybackCaptureTest#testPlaybackCaptureDoS |
| 298 | // CTS test. Instead of hardcoding the number of routes, we can use |
| 299 | // "maxOpen/ActiveStreamCount" to enforce a similar limit. However, the canonical |
| 300 | // XML file lacks this specification. |
| 301 | // |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 302 | // Remote Submix configuration: |
| 303 | // |
| 304 | // Device ports: |
| 305 | // * "Remote Submix Out", OUT_SUBMIX |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 306 | // - no profiles specified |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 307 | // * "Remote Submix In", IN_SUBMIX |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 308 | // - no profiles specified |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 309 | // |
| 310 | // Mix ports: |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 311 | // * "r_submix output", maximum 20 opened streams, maximum 10 active streams |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 312 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 313 | // * "r_submix input", maximum 20 opened streams, maximum 10 active streams |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 314 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 315 | // |
| 316 | // Routes: |
| 317 | // "r_submix output" -> "Remote Submix Out" |
| 318 | // "Remote Submix In" -> "r_submix input" |
| 319 | // |
| 320 | std::unique_ptr<Configuration> getRSubmixConfiguration() { |
| 321 | static const Configuration configuration = []() { |
| 322 | Configuration c; |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 323 | const std::vector<AudioProfile> standardPcmAudioProfiles{ |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 324 | createProfile(PcmType::INT_16_BIT, |
| 325 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 326 | {8000, 11025, 16000, 32000, 44100, 48000})}; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 327 | |
| 328 | // Device ports |
| 329 | |
Mikhail Naganov | 26526f1 | 2023-05-12 13:51:06 -0700 | [diff] [blame] | 330 | AudioPort rsubmixOutDevice = |
| 331 | createPort(c.nextPortId++, "Remote Submix Out", 0, false, |
| 332 | createDeviceExt(AudioDeviceType::OUT_SUBMIX, 0, |
| 333 | AudioDeviceDescription::CONNECTION_VIRTUAL)); |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 334 | rsubmixOutDevice.profiles = standardPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 335 | c.ports.push_back(rsubmixOutDevice); |
| 336 | |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 337 | AudioPort rsubmixInDevice = |
| 338 | createPort(c.nextPortId++, "Remote Submix In", 0, true, |
| 339 | createDeviceExt(AudioDeviceType::IN_SUBMIX, 0, |
| 340 | AudioDeviceDescription::CONNECTION_VIRTUAL)); |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 341 | rsubmixInDevice.profiles = standardPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 342 | c.ports.push_back(rsubmixInDevice); |
| 343 | |
| 344 | // Mix ports |
| 345 | |
| 346 | AudioPort rsubmixOutMix = |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 347 | createPort(c.nextPortId++, "r_submix output", 0, false, createPortMixExt(20, 10)); |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 348 | rsubmixOutMix.profiles = standardPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 349 | c.ports.push_back(rsubmixOutMix); |
| 350 | |
| 351 | AudioPort rsubmixInMix = |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 352 | createPort(c.nextPortId++, "r_submix input", 0, true, createPortMixExt(20, 10)); |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 353 | rsubmixInMix.profiles = standardPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 354 | c.ports.push_back(rsubmixInMix); |
| 355 | |
| 356 | c.routes.push_back(createRoute({rsubmixOutMix}, rsubmixOutDevice)); |
| 357 | c.routes.push_back(createRoute({rsubmixInDevice}, rsubmixInMix)); |
| 358 | |
| 359 | return c; |
| 360 | }(); |
| 361 | return std::make_unique<Configuration>(configuration); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 362 | } |
| 363 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 364 | // Usb configuration: |
| 365 | // |
| 366 | // Device ports: |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 367 | // * "USB Device Out", OUT_DEVICE, CONNECTION_USB |
| 368 | // - no profiles specified |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 369 | // * "USB Headset Out", OUT_HEADSET, CONNECTION_USB |
| 370 | // - no profiles specified |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 371 | // * "USB Device In", IN_DEVICE, CONNECTION_USB |
| 372 | // - no profiles specified |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 373 | // * "USB Headset In", IN_HEADSET, CONNECTION_USB |
| 374 | // - no profiles specified |
| 375 | // |
| 376 | // Mix ports: |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 377 | // * "usb_device output", 1 max open, 1 max active stream |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 378 | // - no profiles specified |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 379 | // * "usb_device input", 1 max open, 1 max active stream |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 380 | // - no profiles specified |
| 381 | // |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 382 | // Routes: |
| 383 | // * "usb_device output" -> "USB Device Out" |
| 384 | // * "usb_device output" -> "USB Headset Out" |
| 385 | // * "USB Device In", "USB Headset In" -> "usb_device input" |
| 386 | // |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 387 | // Profiles for device port connected state: |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 388 | // * "USB Device Out", "USB Headset Out": |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 389 | // - profile PCM 16-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 390 | // - profile PCM 24-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 391 | // * "USB Device In", "USB Headset In": |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 392 | // - profile PCM 16-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 393 | // - profile PCM 24-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 394 | // |
| 395 | std::unique_ptr<Configuration> getUsbConfiguration() { |
| 396 | static const Configuration configuration = []() { |
| 397 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 398 | createProfile(PcmType::INT_16_BIT, |
| 399 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 400 | AudioChannelLayout::INDEX_MASK_1, AudioChannelLayout::INDEX_MASK_2}, |
| 401 | {44100, 48000}), |
| 402 | createProfile(PcmType::INT_24_BIT, |
| 403 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 404 | AudioChannelLayout::INDEX_MASK_1, AudioChannelLayout::INDEX_MASK_2}, |
| 405 | {44100, 48000})}; |
| 406 | Configuration c; |
| 407 | |
| 408 | // Device ports |
| 409 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 410 | AudioPort usbOutDevice = |
| 411 | createPort(c.nextPortId++, "USB Device Out", 0, false, |
| 412 | createDeviceExt(AudioDeviceType::OUT_DEVICE, 0, |
| 413 | AudioDeviceDescription::CONNECTION_USB)); |
| 414 | c.ports.push_back(usbOutDevice); |
| 415 | c.connectedProfiles[usbOutDevice.id] = standardPcmAudioProfiles; |
| 416 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 417 | AudioPort usbOutHeadset = |
| 418 | createPort(c.nextPortId++, "USB Headset Out", 0, false, |
| 419 | createDeviceExt(AudioDeviceType::OUT_HEADSET, 0, |
| 420 | AudioDeviceDescription::CONNECTION_USB)); |
| 421 | c.ports.push_back(usbOutHeadset); |
| 422 | c.connectedProfiles[usbOutHeadset.id] = standardPcmAudioProfiles; |
| 423 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 424 | AudioPort usbInDevice = createPort(c.nextPortId++, "USB Device In", 0, true, |
| 425 | createDeviceExt(AudioDeviceType::IN_DEVICE, 0, |
| 426 | AudioDeviceDescription::CONNECTION_USB)); |
| 427 | c.ports.push_back(usbInDevice); |
| 428 | c.connectedProfiles[usbInDevice.id] = standardPcmAudioProfiles; |
| 429 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 430 | AudioPort usbInHeadset = |
| 431 | createPort(c.nextPortId++, "USB Headset In", 0, true, |
| 432 | createDeviceExt(AudioDeviceType::IN_HEADSET, 0, |
| 433 | AudioDeviceDescription::CONNECTION_USB)); |
| 434 | c.ports.push_back(usbInHeadset); |
| 435 | c.connectedProfiles[usbInHeadset.id] = standardPcmAudioProfiles; |
| 436 | |
| 437 | // Mix ports |
| 438 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 439 | AudioPort usbDeviceOutMix = |
| 440 | createPort(c.nextPortId++, "usb_device output", 0, false, createPortMixExt(1, 1)); |
| 441 | c.ports.push_back(usbDeviceOutMix); |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 442 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 443 | AudioPort usbDeviceInMix = |
| 444 | createPort(c.nextPortId++, "usb_device input", 0, true, createPortMixExt(1, 1)); |
| 445 | c.ports.push_back(usbDeviceInMix); |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 446 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 447 | c.routes.push_back(createRoute({usbDeviceOutMix}, usbOutDevice)); |
| 448 | c.routes.push_back(createRoute({usbDeviceOutMix}, usbOutHeadset)); |
| 449 | c.routes.push_back(createRoute({usbInDevice, usbInHeadset}, usbDeviceInMix)); |
| 450 | |
| 451 | return c; |
| 452 | }(); |
| 453 | return std::make_unique<Configuration>(configuration); |
| 454 | } |
| 455 | |
| 456 | // Stub configuration: |
| 457 | // |
| 458 | // Device ports: |
| 459 | // * "Test Out", OUT_AFE_PROXY |
| 460 | // - no profiles specified |
| 461 | // * "Test In", IN_AFE_PROXY |
| 462 | // - no profiles specified |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 463 | // * "Wired Headset", OUT_HEADSET |
| 464 | // - profile PCM 24-bit; STEREO; 48000 |
| 465 | // * "Wired Headset Mic", IN_HEADSET |
| 466 | // - profile PCM 24-bit; MONO; 48000 |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 467 | // |
| 468 | // Mix ports: |
| 469 | // * "test output", 1 max open, 1 max active stream |
| 470 | // - profile PCM 24-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 471 | // * "test fast output", 1 max open, 1 max active stream |
| 472 | // - profile PCM 24-bit; STEREO; 44100, 48000 |
| 473 | // * "test compressed offload", DIRECT|COMPRESS_OFFLOAD|NON_BLOCKING, 1 max open, 1 max active |
| 474 | // stream |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 475 | // - profile MP3; MONO, STEREO; 44100, 48000 |
| 476 | // * "test input", 2 max open, 2 max active streams |
| 477 | // - profile PCM 24-bit; MONO, STEREO, FRONT_BACK; |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 478 | // 8000, 11025, 16000, 22050, 32000, 44100, 48000 |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 479 | // |
| 480 | // Routes: |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 481 | // "test output", "test fast output", "test compressed offload" -> "Test Out" |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 482 | // "test output" -> "Wired Headset" |
| 483 | // "Test In", "Wired Headset Mic" -> "test input" |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 484 | // |
| 485 | // Initial port configs: |
| 486 | // * "Test Out" device port: PCM 24-bit; STEREO; 48000 |
| 487 | // * "Test In" device port: PCM 24-bit; MONO; 48000 |
| 488 | // |
| 489 | std::unique_ptr<Configuration> getStubConfiguration() { |
| 490 | static const Configuration configuration = []() { |
| 491 | Configuration c; |
| 492 | |
| 493 | // Device ports |
| 494 | |
| 495 | AudioPort testOutDevice = createPort(c.nextPortId++, "Test Out", 0, false, |
| 496 | createDeviceExt(AudioDeviceType::OUT_AFE_PROXY, 0)); |
| 497 | c.ports.push_back(testOutDevice); |
| 498 | c.initialConfigs.push_back( |
| 499 | createPortConfig(testOutDevice.id, testOutDevice.id, PcmType::INT_24_BIT, |
| 500 | AudioChannelLayout::LAYOUT_STEREO, 48000, 0, false, |
| 501 | createDeviceExt(AudioDeviceType::OUT_AFE_PROXY, 0))); |
| 502 | |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 503 | AudioPort headsetOutDevice = |
| 504 | createPort(c.nextPortId++, "Wired Headset", 0, false, |
| 505 | createDeviceExt(AudioDeviceType::OUT_HEADSET, 0, |
| 506 | AudioDeviceDescription::CONNECTION_ANALOG)); |
| 507 | headsetOutDevice.profiles.push_back( |
| 508 | createProfile(PcmType::INT_24_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {48000})); |
| 509 | c.ports.push_back(headsetOutDevice); |
| 510 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 511 | AudioPort testInDevice = createPort(c.nextPortId++, "Test In", 0, true, |
| 512 | createDeviceExt(AudioDeviceType::IN_AFE_PROXY, 0)); |
| 513 | c.ports.push_back(testInDevice); |
| 514 | c.initialConfigs.push_back( |
| 515 | createPortConfig(testInDevice.id, testInDevice.id, PcmType::INT_24_BIT, |
| 516 | AudioChannelLayout::LAYOUT_MONO, 48000, 0, true, |
| 517 | createDeviceExt(AudioDeviceType::IN_AFE_PROXY, 0))); |
| 518 | |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 519 | AudioPort headsetInDevice = |
| 520 | createPort(c.nextPortId++, "Wired Headset Mic", 0, true, |
| 521 | createDeviceExt(AudioDeviceType::IN_HEADSET, 0, |
| 522 | AudioDeviceDescription::CONNECTION_ANALOG)); |
| 523 | headsetInDevice.profiles.push_back( |
| 524 | createProfile(PcmType::INT_24_BIT, {AudioChannelLayout::LAYOUT_MONO}, {48000})); |
| 525 | c.ports.push_back(headsetInDevice); |
| 526 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 527 | // Mix ports |
| 528 | |
| 529 | AudioPort testOutMix = |
| 530 | createPort(c.nextPortId++, "test output", 0, false, createPortMixExt(1, 1)); |
| 531 | testOutMix.profiles.push_back( |
| 532 | createProfile(PcmType::INT_24_BIT, |
| 533 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 534 | {8000, 11025, 16000, 32000, 44100, 48000})); |
| 535 | c.ports.push_back(testOutMix); |
| 536 | |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 537 | AudioPort testFastOutMix = createPort(c.nextPortId++, "test fast output", |
| 538 | makeBitPositionFlagMask({AudioOutputFlags::FAST}), |
| 539 | false, createPortMixExt(1, 1)); |
| 540 | testFastOutMix.profiles.push_back(createProfile( |
| 541 | PcmType::INT_24_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {44100, 48000})); |
| 542 | c.ports.push_back(testFastOutMix); |
| 543 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 544 | AudioPort compressedOffloadOutMix = |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 545 | createPort(c.nextPortId++, "test compressed offload", |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 546 | makeBitPositionFlagMask({AudioOutputFlags::DIRECT, |
| 547 | AudioOutputFlags::COMPRESS_OFFLOAD, |
| 548 | AudioOutputFlags::NON_BLOCKING}), |
| 549 | false, createPortMixExt(1, 1)); |
| 550 | compressedOffloadOutMix.profiles.push_back( |
| 551 | createProfile(::android::MEDIA_MIMETYPE_AUDIO_MPEG, |
| 552 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 553 | {44100, 48000})); |
| 554 | c.ports.push_back(compressedOffloadOutMix); |
| 555 | |
| 556 | AudioPort testInMIx = |
| 557 | createPort(c.nextPortId++, "test input", 0, true, createPortMixExt(2, 2)); |
| 558 | testInMIx.profiles.push_back( |
| 559 | createProfile(PcmType::INT_16_BIT, |
| 560 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 561 | AudioChannelLayout::LAYOUT_FRONT_BACK}, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 562 | {8000, 11025, 16000, 22050, 32000, 44100, 48000})); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 563 | testInMIx.profiles.push_back( |
| 564 | createProfile(PcmType::INT_24_BIT, |
| 565 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 566 | AudioChannelLayout::LAYOUT_FRONT_BACK}, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 567 | {8000, 11025, 16000, 22050, 32000, 44100, 48000})); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 568 | c.ports.push_back(testInMIx); |
| 569 | |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 570 | c.routes.push_back( |
| 571 | createRoute({testOutMix, testFastOutMix, compressedOffloadOutMix}, testOutDevice)); |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 572 | c.routes.push_back(createRoute({testOutMix}, headsetOutDevice)); |
| 573 | c.routes.push_back(createRoute({testInDevice, headsetInDevice}, testInMIx)); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 574 | |
| 575 | c.portConfigs.insert(c.portConfigs.end(), c.initialConfigs.begin(), c.initialConfigs.end()); |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 576 | |
| 577 | return c; |
| 578 | }(); |
| 579 | return std::make_unique<Configuration>(configuration); |
| 580 | } |
| 581 | |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 582 | // Bluetooth configuration: |
| 583 | // |
| 584 | // Device ports: |
| 585 | // * "BT A2DP Out", OUT_DEVICE, CONNECTION_BT_A2DP |
| 586 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 587 | // * "BT A2DP Headphones", OUT_HEADPHONE, CONNECTION_BT_A2DP |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 588 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
| 589 | // * "BT A2DP Speaker", OUT_SPEAKER, CONNECTION_BT_A2DP |
| 590 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
| 591 | // * "BT Hearing Aid Out", OUT_HEARING_AID, CONNECTION_WIRELESS |
| 592 | // - no profiles specified |
| 593 | // |
| 594 | // Mix ports: |
| 595 | // * "a2dp output", 1 max open, 1 max active stream |
| 596 | // - no profiles specified |
| 597 | // * "hearing aid output", 1 max open, 1 max active stream |
| 598 | // - profile PCM 16-bit; STEREO; 16000, 24000 |
| 599 | // |
| 600 | // Routes: |
| 601 | // "a2dp output" -> "BT A2DP Out" |
| 602 | // "a2dp output" -> "BT A2DP Headphones" |
| 603 | // "a2dp output" -> "BT A2DP Speaker" |
| 604 | // "hearing aid output" -> "BT Hearing Aid Out" |
| 605 | // |
| 606 | std::unique_ptr<Configuration> getBluetoothConfiguration() { |
| 607 | static const Configuration configuration = []() { |
| 608 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 609 | createProfile(PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, |
| 610 | {44100, 48000, 88200, 96000})}; |
| 611 | Configuration c; |
| 612 | |
| 613 | // Device ports |
| 614 | AudioPort btOutDevice = |
| 615 | createPort(c.nextPortId++, "BT A2DP Out", 0, false, |
| 616 | createDeviceExt(AudioDeviceType::OUT_DEVICE, 0, |
| 617 | AudioDeviceDescription::CONNECTION_BT_A2DP)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 618 | btOutDevice.profiles.insert(btOutDevice.profiles.begin(), standardPcmAudioProfiles.begin(), |
| 619 | standardPcmAudioProfiles.end()); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 620 | c.ports.push_back(btOutDevice); |
| 621 | c.connectedProfiles[btOutDevice.id] = standardPcmAudioProfiles; |
| 622 | |
| 623 | AudioPort btOutHeadphone = |
| 624 | createPort(c.nextPortId++, "BT A2DP Headphones", 0, false, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 625 | createDeviceExt(AudioDeviceType::OUT_HEADPHONE, 0, |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 626 | AudioDeviceDescription::CONNECTION_BT_A2DP)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 627 | btOutHeadphone.profiles.insert(btOutHeadphone.profiles.begin(), |
| 628 | standardPcmAudioProfiles.begin(), |
| 629 | standardPcmAudioProfiles.end()); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 630 | c.ports.push_back(btOutHeadphone); |
| 631 | c.connectedProfiles[btOutHeadphone.id] = standardPcmAudioProfiles; |
| 632 | |
| 633 | AudioPort btOutSpeaker = |
| 634 | createPort(c.nextPortId++, "BT A2DP Speaker", 0, false, |
| 635 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, 0, |
| 636 | AudioDeviceDescription::CONNECTION_BT_A2DP)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 637 | btOutSpeaker.profiles.insert(btOutSpeaker.profiles.begin(), |
| 638 | standardPcmAudioProfiles.begin(), |
| 639 | standardPcmAudioProfiles.end()); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 640 | c.ports.push_back(btOutSpeaker); |
| 641 | c.connectedProfiles[btOutSpeaker.id] = standardPcmAudioProfiles; |
| 642 | |
| 643 | AudioPort btOutHearingAid = |
| 644 | createPort(c.nextPortId++, "BT Hearing Aid Out", 0, false, |
| 645 | createDeviceExt(AudioDeviceType::OUT_HEARING_AID, 0, |
| 646 | AudioDeviceDescription::CONNECTION_WIRELESS)); |
| 647 | c.ports.push_back(btOutHearingAid); |
| 648 | c.connectedProfiles[btOutHearingAid.id] = std::vector<AudioProfile>( |
| 649 | {createProfile(PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {16000})}); |
| 650 | |
| 651 | // Mix ports |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 652 | AudioPort btOutMix = |
| 653 | createPort(c.nextPortId++, "a2dp output", 0, false, createPortMixExt(1, 1)); |
| 654 | c.ports.push_back(btOutMix); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 655 | |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 656 | AudioPort btHearingOutMix = |
| 657 | createPort(c.nextPortId++, "hearing aid output", 0, false, createPortMixExt(1, 1)); |
| 658 | btHearingOutMix.profiles.push_back(createProfile( |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 659 | PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {16000, 24000})); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 660 | c.ports.push_back(btHearingOutMix); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 661 | |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 662 | c.routes.push_back(createRoute({btOutMix}, btOutDevice)); |
| 663 | c.routes.push_back(createRoute({btOutMix}, btOutHeadphone)); |
| 664 | c.routes.push_back(createRoute({btOutMix}, btOutSpeaker)); |
| 665 | c.routes.push_back(createRoute({btHearingOutMix}, btOutHearingAid)); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 666 | |
| 667 | return c; |
| 668 | }(); |
| 669 | return std::make_unique<Configuration>(configuration); |
| 670 | } |
| 671 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 672 | } // namespace aidl::android::hardware::audio::core::internal |