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; |
| 44 | using aidl::android::media::audio::common::PcmType; |
Lorena Torres-Huerta | 394e252 | 2022-12-20 02:21:41 +0000 | [diff] [blame] | 45 | using Configuration = aidl::android::hardware::audio::core::Module::Configuration; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 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 | |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 108 | static AudioPortConfig createDynamicPortConfig(int32_t id, int32_t portId, int32_t flags, |
| 109 | bool isInput, const AudioPortExt& ext) { |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 110 | AudioPortConfig config; |
| 111 | config.id = id; |
| 112 | config.portId = portId; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 113 | config.gain = AudioGainConfig(); |
| 114 | config.flags = isInput ? AudioIoFlags::make<AudioIoFlags::Tag::input>(flags) |
| 115 | : AudioIoFlags::make<AudioIoFlags::Tag::output>(flags); |
| 116 | config.ext = ext; |
| 117 | return config; |
| 118 | } |
| 119 | |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 120 | static AudioPortConfig createPortConfig(int32_t id, int32_t portId, PcmType pcmType, int32_t layout, |
| 121 | int32_t sampleRate, int32_t flags, bool isInput, |
| 122 | const AudioPortExt& ext) { |
| 123 | AudioPortConfig config = createDynamicPortConfig(id, portId, flags, isInput, ext); |
| 124 | config.sampleRate = Int{.value = sampleRate}; |
| 125 | config.channelMask = AudioChannelLayout::make<AudioChannelLayout::layoutMask>(layout); |
| 126 | config.format = AudioFormatDescription{.type = AudioFormatType::PCM, .pcm = pcmType}; |
| 127 | return config; |
| 128 | } |
| 129 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 130 | static AudioRoute createRoute(const std::vector<AudioPort>& sources, const AudioPort& sink) { |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 131 | AudioRoute route; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 132 | route.sinkPortId = sink.id; |
| 133 | std::transform(sources.begin(), sources.end(), std::back_inserter(route.sourcePortIds), |
| 134 | [](const auto& port) { return port.id; }); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 135 | return route; |
| 136 | } |
| 137 | |
Lorena Torres-Huerta | f749251 | 2023-01-14 02:49:41 +0000 | [diff] [blame] | 138 | std::vector<AudioProfile> getStandard16And24BitPcmAudioProfiles() { |
| 139 | auto createStdPcmAudioProfile = [](const PcmType& pcmType) { |
| 140 | return AudioProfile{ |
| 141 | .format = AudioFormatDescription{.type = AudioFormatType::PCM, .pcm = pcmType}, |
| 142 | .channelMasks = {AudioChannelLayout::make<AudioChannelLayout::layoutMask>( |
| 143 | AudioChannelLayout::LAYOUT_MONO), |
| 144 | AudioChannelLayout::make<AudioChannelLayout::layoutMask>( |
| 145 | AudioChannelLayout::LAYOUT_STEREO)}, |
| 146 | .sampleRates = {8000, 11025, 16000, 32000, 44100, 48000}}; |
| 147 | }; |
| 148 | return { |
| 149 | createStdPcmAudioProfile(PcmType::INT_16_BIT), |
| 150 | createStdPcmAudioProfile(PcmType::INT_24_BIT), |
| 151 | }; |
| 152 | } |
| 153 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 154 | // Primary (default) configuration: |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 155 | // |
| 156 | // Device ports: |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 157 | // * "Speaker", OUT_SPEAKER, default |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 158 | // - no profiles specified |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 159 | // * "Built-In Mic", IN_MICROPHONE, default |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 160 | // - no profiles specified |
| 161 | // * "Telephony Tx", OUT_TELEPHONY_TX |
| 162 | // - no profiles specified |
| 163 | // * "Telephony Rx", IN_TELEPHONY_RX |
| 164 | // - no profiles specified |
| 165 | // * "FM Tuner", IN_FM_TUNER |
| 166 | // - no profiles specified |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 167 | // |
| 168 | // Mix ports: |
| 169 | // * "primary output", PRIMARY, 1 max open, 1 max active stream |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 170 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 171 | // * "primary input", 1 max open, 1 max active stream |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 172 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 173 | // * "telephony_tx", 1 max open, 1 max active stream |
| 174 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 175 | // * "telephony_rx", 1 max open, 1 max active stream |
| 176 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 177 | // * "fm_tuner", 1 max open, 1 max active stream |
| 178 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 179 | // |
| 180 | // Routes: |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 181 | // "primary out" -> "Speaker" |
| 182 | // "Built-In Mic" -> "primary input" |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 183 | // "Telephony Rx" -> "telephony_rx" |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 184 | // "telephony_tx" -> "Telephony Tx" |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 185 | // "FM Tuner" -> "fm_tuner" |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 186 | // |
| 187 | // Initial port configs: |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 188 | // * "Speaker" device port: dynamic configuration |
| 189 | // * "Built-In Mic" device port: dynamic configuration |
| 190 | // * "Telephony Tx" device port: dynamic configuration |
| 191 | // * "Telephony Rx" device port: dynamic configuration |
| 192 | // * "FM Tuner" device port: dynamic configuration |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 193 | // |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 194 | std::unique_ptr<Configuration> getPrimaryConfiguration() { |
| 195 | static const Configuration configuration = []() { |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 196 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 197 | createProfile(PcmType::INT_16_BIT, |
| 198 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 199 | {8000, 11025, 16000, 32000, 44100, 48000})}; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 200 | Configuration c; |
| 201 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 202 | // Device ports |
| 203 | |
| 204 | AudioPort speakerOutDevice = |
| 205 | createPort(c.nextPortId++, "Speaker", 0, false, |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 206 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, |
| 207 | 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 208 | c.ports.push_back(speakerOutDevice); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 209 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 210 | createDynamicPortConfig(speakerOutDevice.id, speakerOutDevice.id, 0, false, |
| 211 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, 0))); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 212 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 213 | AudioPort micInDevice = |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 214 | createPort(c.nextPortId++, "Built-In Mic", 0, true, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 215 | createDeviceExt(AudioDeviceType::IN_MICROPHONE, |
| 216 | 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE)); |
| 217 | c.ports.push_back(micInDevice); |
| 218 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 219 | createDynamicPortConfig(micInDevice.id, micInDevice.id, 0, true, |
| 220 | createDeviceExt(AudioDeviceType::IN_MICROPHONE, 0))); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 221 | |
| 222 | AudioPort telephonyTxOutDevice = |
| 223 | createPort(c.nextPortId++, "Telephony Tx", 0, false, |
| 224 | createDeviceExt(AudioDeviceType::OUT_TELEPHONY_TX, 0)); |
| 225 | c.ports.push_back(telephonyTxOutDevice); |
| 226 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 227 | createDynamicPortConfig(telephonyTxOutDevice.id, telephonyTxOutDevice.id, 0, false, |
| 228 | createDeviceExt(AudioDeviceType::OUT_TELEPHONY_TX, 0))); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 229 | |
| 230 | AudioPort telephonyRxInDevice = |
| 231 | createPort(c.nextPortId++, "Telephony Rx", 0, true, |
| 232 | createDeviceExt(AudioDeviceType::IN_TELEPHONY_RX, 0)); |
| 233 | c.ports.push_back(telephonyRxInDevice); |
| 234 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 235 | createDynamicPortConfig(telephonyRxInDevice.id, telephonyRxInDevice.id, 0, true, |
| 236 | createDeviceExt(AudioDeviceType::IN_TELEPHONY_RX, 0))); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 237 | |
| 238 | AudioPort fmTunerInDevice = createPort(c.nextPortId++, "FM Tuner", 0, true, |
| 239 | createDeviceExt(AudioDeviceType::IN_FM_TUNER, 0)); |
| 240 | c.ports.push_back(fmTunerInDevice); |
| 241 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 242 | createDynamicPortConfig(fmTunerInDevice.id, fmTunerInDevice.id, 0, true, |
| 243 | createDeviceExt(AudioDeviceType::IN_FM_TUNER, 0))); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 244 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 245 | // Mix ports |
| 246 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 247 | AudioPort primaryOutMix = createPort(c.nextPortId++, "primary output", |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 248 | makeBitPositionFlagMask(AudioOutputFlags::PRIMARY), |
Shunkai Yao | 2461891 | 2023-08-18 23:58:05 +0000 | [diff] [blame] | 249 | false, createPortMixExt(0, 0)); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 250 | primaryOutMix.profiles.insert(primaryOutMix.profiles.begin(), |
| 251 | standardPcmAudioProfiles.begin(), |
| 252 | standardPcmAudioProfiles.end()); |
| 253 | c.ports.push_back(primaryOutMix); |
| 254 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 255 | AudioPort primaryInMix = |
Mikhail Naganov | 8dbc511 | 2023-10-02 14:51:50 -0700 | [diff] [blame] | 256 | createPort(c.nextPortId++, "primary input", 0, true, createPortMixExt(0, 1)); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 257 | primaryInMix.profiles.push_back( |
| 258 | createProfile(PcmType::INT_16_BIT, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 259 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 260 | {8000, 11025, 16000, 32000, 44100, 48000})); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 261 | c.ports.push_back(primaryInMix); |
| 262 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 263 | AudioPort telephonyTxOutMix = |
| 264 | createPort(c.nextPortId++, "telephony_tx", 0, false, createPortMixExt(1, 1)); |
| 265 | telephonyTxOutMix.profiles.insert(telephonyTxOutMix.profiles.begin(), |
| 266 | standardPcmAudioProfiles.begin(), |
| 267 | standardPcmAudioProfiles.end()); |
| 268 | c.ports.push_back(telephonyTxOutMix); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 269 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 270 | AudioPort telephonyRxInMix = |
Mikhail Naganov | 8dbc511 | 2023-10-02 14:51:50 -0700 | [diff] [blame] | 271 | createPort(c.nextPortId++, "telephony_rx", 0, true, createPortMixExt(0, 1)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 272 | telephonyRxInMix.profiles.insert(telephonyRxInMix.profiles.begin(), |
| 273 | standardPcmAudioProfiles.begin(), |
| 274 | standardPcmAudioProfiles.end()); |
| 275 | c.ports.push_back(telephonyRxInMix); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 276 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 277 | AudioPort fmTunerInMix = |
Mikhail Naganov | 8dbc511 | 2023-10-02 14:51:50 -0700 | [diff] [blame] | 278 | createPort(c.nextPortId++, "fm_tuner", 0, true, createPortMixExt(0, 1)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 279 | fmTunerInMix.profiles.insert(fmTunerInMix.profiles.begin(), |
| 280 | standardPcmAudioProfiles.begin(), |
| 281 | standardPcmAudioProfiles.end()); |
| 282 | c.ports.push_back(fmTunerInMix); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 283 | |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 284 | c.routes.push_back(createRoute({primaryOutMix}, speakerOutDevice)); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 285 | c.routes.push_back(createRoute({micInDevice}, primaryInMix)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 286 | c.routes.push_back(createRoute({telephonyRxInDevice}, telephonyRxInMix)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 287 | c.routes.push_back(createRoute({telephonyTxOutMix}, telephonyTxOutDevice)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 288 | c.routes.push_back(createRoute({fmTunerInDevice}, fmTunerInMix)); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 289 | |
| 290 | c.portConfigs.insert(c.portConfigs.end(), c.initialConfigs.begin(), c.initialConfigs.end()); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 291 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 292 | return c; |
| 293 | }(); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 294 | return std::make_unique<Configuration>(configuration); |
| 295 | } |
| 296 | |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 297 | // Note: When transitioning to loading of XML configs, either keep the configuration |
| 298 | // of the remote submix sources from this static configuration, or update the XML |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 299 | // config to match it. There are several reasons for that: |
| 300 | // 1. The "Remote Submix In" device is listed in the XML config as "attached", |
| 301 | // however in the AIDL scheme its device type has a "virtual" connection. |
| 302 | // 2. The canonical r_submix configuration only lists 'STEREO' and '48000', |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 303 | // however the framework attempts to open streams for other sample rates |
| 304 | // as well. The legacy r_submix implementation allowed that, but libaudiohal@aidl |
Mikhail Naganov | 2ebe390 | 2023-11-07 16:43:26 -0800 | [diff] [blame] | 305 | // will not find a mix port to use. Because of that, list all sample rates that |
| 306 | // the legacy implementation allowed (note that mono was not allowed, the framework |
| 307 | // is expected to upmix mono tracks into stereo if needed). |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 308 | // 3. The legacy implementation had a hard limit on the number of routes (10), |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 309 | // and this is checked indirectly by AudioPlaybackCaptureTest#testPlaybackCaptureDoS |
| 310 | // CTS test. Instead of hardcoding the number of routes, we can use |
| 311 | // "maxOpen/ActiveStreamCount" to enforce a similar limit. However, the canonical |
| 312 | // XML file lacks this specification. |
| 313 | // |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 314 | // Remote Submix configuration: |
| 315 | // |
| 316 | // Device ports: |
| 317 | // * "Remote Submix Out", OUT_SUBMIX |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 318 | // - no profiles specified |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 319 | // * "Remote Submix In", IN_SUBMIX |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 320 | // - no profiles specified |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 321 | // |
| 322 | // Mix ports: |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 323 | // * "r_submix output", maximum 20 opened streams, maximum 10 active streams |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 324 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 325 | // * "r_submix input", maximum 20 opened streams, maximum 10 active streams |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 326 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 327 | // |
| 328 | // Routes: |
| 329 | // "r_submix output" -> "Remote Submix Out" |
| 330 | // "Remote Submix In" -> "r_submix input" |
| 331 | // |
| 332 | std::unique_ptr<Configuration> getRSubmixConfiguration() { |
| 333 | static const Configuration configuration = []() { |
| 334 | Configuration c; |
Mikhail Naganov | 2ebe390 | 2023-11-07 16:43:26 -0800 | [diff] [blame] | 335 | const std::vector<AudioProfile> remoteSubmixPcmAudioProfiles{ |
| 336 | createProfile(PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 337 | {8000, 11025, 16000, 32000, 44100, 48000})}; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 338 | |
| 339 | // Device ports |
| 340 | |
Mikhail Naganov | 26526f1 | 2023-05-12 13:51:06 -0700 | [diff] [blame] | 341 | AudioPort rsubmixOutDevice = |
| 342 | createPort(c.nextPortId++, "Remote Submix Out", 0, false, |
| 343 | createDeviceExt(AudioDeviceType::OUT_SUBMIX, 0, |
| 344 | AudioDeviceDescription::CONNECTION_VIRTUAL)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 345 | c.ports.push_back(rsubmixOutDevice); |
Mikhail Naganov | 2ebe390 | 2023-11-07 16:43:26 -0800 | [diff] [blame] | 346 | c.connectedProfiles[rsubmixOutDevice.id] = remoteSubmixPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 347 | |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 348 | AudioPort rsubmixInDevice = |
| 349 | createPort(c.nextPortId++, "Remote Submix In", 0, true, |
| 350 | createDeviceExt(AudioDeviceType::IN_SUBMIX, 0, |
| 351 | AudioDeviceDescription::CONNECTION_VIRTUAL)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 352 | c.ports.push_back(rsubmixInDevice); |
Mikhail Naganov | 2ebe390 | 2023-11-07 16:43:26 -0800 | [diff] [blame] | 353 | c.connectedProfiles[rsubmixInDevice.id] = remoteSubmixPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 354 | |
| 355 | // Mix ports |
| 356 | |
| 357 | AudioPort rsubmixOutMix = |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 358 | createPort(c.nextPortId++, "r_submix output", 0, false, createPortMixExt(20, 10)); |
Mikhail Naganov | 2ebe390 | 2023-11-07 16:43:26 -0800 | [diff] [blame] | 359 | rsubmixOutMix.profiles = remoteSubmixPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 360 | c.ports.push_back(rsubmixOutMix); |
| 361 | |
| 362 | AudioPort rsubmixInMix = |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 363 | createPort(c.nextPortId++, "r_submix input", 0, true, createPortMixExt(20, 10)); |
Mikhail Naganov | 2ebe390 | 2023-11-07 16:43:26 -0800 | [diff] [blame] | 364 | rsubmixInMix.profiles = remoteSubmixPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 365 | c.ports.push_back(rsubmixInMix); |
| 366 | |
| 367 | c.routes.push_back(createRoute({rsubmixOutMix}, rsubmixOutDevice)); |
| 368 | c.routes.push_back(createRoute({rsubmixInDevice}, rsubmixInMix)); |
| 369 | |
| 370 | return c; |
| 371 | }(); |
| 372 | return std::make_unique<Configuration>(configuration); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 373 | } |
| 374 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 375 | // Usb configuration: |
| 376 | // |
| 377 | // Device ports: |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 378 | // * "USB Device Out", OUT_DEVICE, CONNECTION_USB |
| 379 | // - no profiles specified |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 380 | // * "USB Headset Out", OUT_HEADSET, CONNECTION_USB |
| 381 | // - no profiles specified |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 382 | // * "USB Device In", IN_DEVICE, CONNECTION_USB |
| 383 | // - no profiles specified |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 384 | // * "USB Headset In", IN_HEADSET, CONNECTION_USB |
| 385 | // - no profiles specified |
| 386 | // |
| 387 | // Mix ports: |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 388 | // * "usb_device output", 1 max open, 1 max active stream |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 389 | // - no profiles specified |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 390 | // * "usb_device input", 1 max open, 1 max active stream |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 391 | // - no profiles specified |
| 392 | // |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 393 | // Routes: |
| 394 | // * "usb_device output" -> "USB Device Out" |
| 395 | // * "usb_device output" -> "USB Headset Out" |
| 396 | // * "USB Device In", "USB Headset In" -> "usb_device input" |
| 397 | // |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 398 | // Profiles for device port connected state (when simulating connections): |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 399 | // * "USB Device Out", "USB Headset Out": |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 400 | // - profile PCM 16-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 401 | // - 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] | 402 | // * "USB Device In", "USB Headset In": |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 403 | // - profile PCM 16-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 404 | // - profile PCM 24-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 405 | // |
| 406 | std::unique_ptr<Configuration> getUsbConfiguration() { |
| 407 | static const Configuration configuration = []() { |
| 408 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 409 | createProfile(PcmType::INT_16_BIT, |
| 410 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 411 | AudioChannelLayout::INDEX_MASK_1, AudioChannelLayout::INDEX_MASK_2}, |
| 412 | {44100, 48000}), |
| 413 | createProfile(PcmType::INT_24_BIT, |
| 414 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 415 | AudioChannelLayout::INDEX_MASK_1, AudioChannelLayout::INDEX_MASK_2}, |
| 416 | {44100, 48000})}; |
| 417 | Configuration c; |
| 418 | |
| 419 | // Device ports |
| 420 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 421 | AudioPort usbOutDevice = |
| 422 | createPort(c.nextPortId++, "USB Device Out", 0, false, |
| 423 | createDeviceExt(AudioDeviceType::OUT_DEVICE, 0, |
| 424 | AudioDeviceDescription::CONNECTION_USB)); |
| 425 | c.ports.push_back(usbOutDevice); |
| 426 | c.connectedProfiles[usbOutDevice.id] = standardPcmAudioProfiles; |
| 427 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 428 | AudioPort usbOutHeadset = |
| 429 | createPort(c.nextPortId++, "USB Headset Out", 0, false, |
| 430 | createDeviceExt(AudioDeviceType::OUT_HEADSET, 0, |
| 431 | AudioDeviceDescription::CONNECTION_USB)); |
| 432 | c.ports.push_back(usbOutHeadset); |
| 433 | c.connectedProfiles[usbOutHeadset.id] = standardPcmAudioProfiles; |
| 434 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 435 | AudioPort usbInDevice = createPort(c.nextPortId++, "USB Device In", 0, true, |
| 436 | createDeviceExt(AudioDeviceType::IN_DEVICE, 0, |
| 437 | AudioDeviceDescription::CONNECTION_USB)); |
| 438 | c.ports.push_back(usbInDevice); |
| 439 | c.connectedProfiles[usbInDevice.id] = standardPcmAudioProfiles; |
| 440 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 441 | AudioPort usbInHeadset = |
| 442 | createPort(c.nextPortId++, "USB Headset In", 0, true, |
| 443 | createDeviceExt(AudioDeviceType::IN_HEADSET, 0, |
| 444 | AudioDeviceDescription::CONNECTION_USB)); |
| 445 | c.ports.push_back(usbInHeadset); |
| 446 | c.connectedProfiles[usbInHeadset.id] = standardPcmAudioProfiles; |
| 447 | |
| 448 | // Mix ports |
| 449 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 450 | AudioPort usbDeviceOutMix = |
| 451 | createPort(c.nextPortId++, "usb_device output", 0, false, createPortMixExt(1, 1)); |
| 452 | c.ports.push_back(usbDeviceOutMix); |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 453 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 454 | AudioPort usbDeviceInMix = |
Mikhail Naganov | 8dbc511 | 2023-10-02 14:51:50 -0700 | [diff] [blame] | 455 | createPort(c.nextPortId++, "usb_device input", 0, true, createPortMixExt(0, 1)); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 456 | c.ports.push_back(usbDeviceInMix); |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 457 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 458 | c.routes.push_back(createRoute({usbDeviceOutMix}, usbOutDevice)); |
| 459 | c.routes.push_back(createRoute({usbDeviceOutMix}, usbOutHeadset)); |
| 460 | c.routes.push_back(createRoute({usbInDevice, usbInHeadset}, usbDeviceInMix)); |
| 461 | |
| 462 | return c; |
| 463 | }(); |
| 464 | return std::make_unique<Configuration>(configuration); |
| 465 | } |
| 466 | |
| 467 | // Stub configuration: |
| 468 | // |
| 469 | // Device ports: |
| 470 | // * "Test Out", OUT_AFE_PROXY |
| 471 | // - no profiles specified |
| 472 | // * "Test In", IN_AFE_PROXY |
| 473 | // - no profiles specified |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 474 | // * "Wired Headset", OUT_HEADSET |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 475 | // - no profiles specified |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 476 | // * "Wired Headset Mic", IN_HEADSET |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 477 | // - no profiles specified |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 478 | // |
| 479 | // Mix ports: |
| 480 | // * "test output", 1 max open, 1 max active stream |
| 481 | // - profile PCM 24-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 482 | // * "test fast output", 1 max open, 1 max active stream |
| 483 | // - profile PCM 24-bit; STEREO; 44100, 48000 |
| 484 | // * "test compressed offload", DIRECT|COMPRESS_OFFLOAD|NON_BLOCKING, 1 max open, 1 max active |
| 485 | // stream |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 486 | // - profile MP3; MONO, STEREO; 44100, 48000 |
| 487 | // * "test input", 2 max open, 2 max active streams |
| 488 | // - profile PCM 24-bit; MONO, STEREO, FRONT_BACK; |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 489 | // 8000, 11025, 16000, 22050, 32000, 44100, 48000 |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 490 | // |
| 491 | // Routes: |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 492 | // "test output", "test fast output", "test compressed offload" -> "Test Out" |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 493 | // "test output" -> "Wired Headset" |
| 494 | // "Test In", "Wired Headset Mic" -> "test input" |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 495 | // |
| 496 | // Initial port configs: |
| 497 | // * "Test Out" device port: PCM 24-bit; STEREO; 48000 |
| 498 | // * "Test In" device port: PCM 24-bit; MONO; 48000 |
| 499 | // |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 500 | // Profiles for device port connected state (when simulating connections): |
| 501 | // * "Wired Headset": dynamic profiles |
| 502 | // * "Wired Headset Mic": dynamic profiles |
| 503 | // |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 504 | std::unique_ptr<Configuration> getStubConfiguration() { |
| 505 | static const Configuration configuration = []() { |
| 506 | Configuration c; |
| 507 | |
| 508 | // Device ports |
| 509 | |
| 510 | AudioPort testOutDevice = createPort(c.nextPortId++, "Test Out", 0, false, |
| 511 | createDeviceExt(AudioDeviceType::OUT_AFE_PROXY, 0)); |
| 512 | c.ports.push_back(testOutDevice); |
| 513 | c.initialConfigs.push_back( |
| 514 | createPortConfig(testOutDevice.id, testOutDevice.id, PcmType::INT_24_BIT, |
| 515 | AudioChannelLayout::LAYOUT_STEREO, 48000, 0, false, |
| 516 | createDeviceExt(AudioDeviceType::OUT_AFE_PROXY, 0))); |
| 517 | |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 518 | AudioPort headsetOutDevice = |
| 519 | createPort(c.nextPortId++, "Wired Headset", 0, false, |
| 520 | createDeviceExt(AudioDeviceType::OUT_HEADSET, 0, |
| 521 | AudioDeviceDescription::CONNECTION_ANALOG)); |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 522 | c.ports.push_back(headsetOutDevice); |
| 523 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 524 | AudioPort testInDevice = createPort(c.nextPortId++, "Test In", 0, true, |
| 525 | createDeviceExt(AudioDeviceType::IN_AFE_PROXY, 0)); |
| 526 | c.ports.push_back(testInDevice); |
| 527 | c.initialConfigs.push_back( |
| 528 | createPortConfig(testInDevice.id, testInDevice.id, PcmType::INT_24_BIT, |
| 529 | AudioChannelLayout::LAYOUT_MONO, 48000, 0, true, |
| 530 | createDeviceExt(AudioDeviceType::IN_AFE_PROXY, 0))); |
| 531 | |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 532 | AudioPort headsetInDevice = |
| 533 | createPort(c.nextPortId++, "Wired Headset Mic", 0, true, |
| 534 | createDeviceExt(AudioDeviceType::IN_HEADSET, 0, |
| 535 | AudioDeviceDescription::CONNECTION_ANALOG)); |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 536 | c.ports.push_back(headsetInDevice); |
| 537 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 538 | // Mix ports |
| 539 | |
| 540 | AudioPort testOutMix = |
| 541 | createPort(c.nextPortId++, "test output", 0, false, createPortMixExt(1, 1)); |
| 542 | testOutMix.profiles.push_back( |
| 543 | createProfile(PcmType::INT_24_BIT, |
| 544 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 545 | {8000, 11025, 16000, 32000, 44100, 48000})); |
| 546 | c.ports.push_back(testOutMix); |
| 547 | |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 548 | AudioPort testFastOutMix = createPort(c.nextPortId++, "test fast output", |
| 549 | makeBitPositionFlagMask({AudioOutputFlags::FAST}), |
| 550 | false, createPortMixExt(1, 1)); |
| 551 | testFastOutMix.profiles.push_back(createProfile( |
| 552 | PcmType::INT_24_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {44100, 48000})); |
| 553 | c.ports.push_back(testFastOutMix); |
| 554 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 555 | AudioPort compressedOffloadOutMix = |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 556 | createPort(c.nextPortId++, "test compressed offload", |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 557 | makeBitPositionFlagMask({AudioOutputFlags::DIRECT, |
| 558 | AudioOutputFlags::COMPRESS_OFFLOAD, |
| 559 | AudioOutputFlags::NON_BLOCKING}), |
| 560 | false, createPortMixExt(1, 1)); |
| 561 | compressedOffloadOutMix.profiles.push_back( |
| 562 | createProfile(::android::MEDIA_MIMETYPE_AUDIO_MPEG, |
| 563 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 564 | {44100, 48000})); |
| 565 | c.ports.push_back(compressedOffloadOutMix); |
| 566 | |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 567 | AudioPort testInMix = |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 568 | createPort(c.nextPortId++, "test input", 0, true, createPortMixExt(2, 2)); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 569 | testInMix.profiles.push_back( |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 570 | createProfile(PcmType::INT_16_BIT, |
| 571 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 572 | AudioChannelLayout::LAYOUT_FRONT_BACK}, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 573 | {8000, 11025, 16000, 22050, 32000, 44100, 48000})); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 574 | testInMix.profiles.push_back( |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 575 | createProfile(PcmType::INT_24_BIT, |
| 576 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 577 | AudioChannelLayout::LAYOUT_FRONT_BACK}, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 578 | {8000, 11025, 16000, 22050, 32000, 44100, 48000})); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 579 | c.ports.push_back(testInMix); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 580 | |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 581 | c.routes.push_back( |
| 582 | createRoute({testOutMix, testFastOutMix, compressedOffloadOutMix}, testOutDevice)); |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 583 | c.routes.push_back(createRoute({testOutMix}, headsetOutDevice)); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 584 | c.routes.push_back(createRoute({testInDevice, headsetInDevice}, testInMix)); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 585 | |
| 586 | c.portConfigs.insert(c.portConfigs.end(), c.initialConfigs.begin(), c.initialConfigs.end()); |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 587 | |
| 588 | return c; |
| 589 | }(); |
| 590 | return std::make_unique<Configuration>(configuration); |
| 591 | } |
| 592 | |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 593 | // Bluetooth configuration: |
| 594 | // |
| 595 | // Device ports: |
| 596 | // * "BT A2DP Out", OUT_DEVICE, CONNECTION_BT_A2DP |
| 597 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 598 | // * "BT A2DP Headphones", OUT_HEADPHONE, CONNECTION_BT_A2DP |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 599 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
| 600 | // * "BT A2DP Speaker", OUT_SPEAKER, CONNECTION_BT_A2DP |
| 601 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
| 602 | // * "BT Hearing Aid Out", OUT_HEARING_AID, CONNECTION_WIRELESS |
| 603 | // - no profiles specified |
| 604 | // |
| 605 | // Mix ports: |
| 606 | // * "a2dp output", 1 max open, 1 max active stream |
| 607 | // - no profiles specified |
| 608 | // * "hearing aid output", 1 max open, 1 max active stream |
| 609 | // - profile PCM 16-bit; STEREO; 16000, 24000 |
| 610 | // |
| 611 | // Routes: |
| 612 | // "a2dp output" -> "BT A2DP Out" |
| 613 | // "a2dp output" -> "BT A2DP Headphones" |
| 614 | // "a2dp output" -> "BT A2DP Speaker" |
| 615 | // "hearing aid output" -> "BT Hearing Aid Out" |
| 616 | // |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 617 | // Profiles for device port connected state (when simulating connections): |
| 618 | // * "BT A2DP Out", "BT A2DP Headphones", "BT A2DP Speaker": |
| 619 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
| 620 | // * "BT Hearing Aid Out": |
| 621 | // - profile PCM 16-bit; STEREO; 16000, 24000 |
| 622 | // |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 623 | std::unique_ptr<Configuration> getBluetoothConfiguration() { |
| 624 | static const Configuration configuration = []() { |
| 625 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 626 | createProfile(PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, |
| 627 | {44100, 48000, 88200, 96000})}; |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 628 | const std::vector<AudioProfile> hearingAidAudioProfiles = {createProfile( |
| 629 | PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {16000, 24000})}; |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 630 | Configuration c; |
| 631 | |
| 632 | // Device ports |
| 633 | AudioPort btOutDevice = |
| 634 | createPort(c.nextPortId++, "BT A2DP Out", 0, false, |
| 635 | createDeviceExt(AudioDeviceType::OUT_DEVICE, 0, |
| 636 | AudioDeviceDescription::CONNECTION_BT_A2DP)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 637 | btOutDevice.profiles.insert(btOutDevice.profiles.begin(), standardPcmAudioProfiles.begin(), |
| 638 | standardPcmAudioProfiles.end()); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 639 | c.ports.push_back(btOutDevice); |
| 640 | c.connectedProfiles[btOutDevice.id] = standardPcmAudioProfiles; |
| 641 | |
| 642 | AudioPort btOutHeadphone = |
| 643 | createPort(c.nextPortId++, "BT A2DP Headphones", 0, false, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 644 | createDeviceExt(AudioDeviceType::OUT_HEADPHONE, 0, |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 645 | AudioDeviceDescription::CONNECTION_BT_A2DP)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 646 | btOutHeadphone.profiles.insert(btOutHeadphone.profiles.begin(), |
| 647 | standardPcmAudioProfiles.begin(), |
| 648 | standardPcmAudioProfiles.end()); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 649 | c.ports.push_back(btOutHeadphone); |
| 650 | c.connectedProfiles[btOutHeadphone.id] = standardPcmAudioProfiles; |
| 651 | |
| 652 | AudioPort btOutSpeaker = |
| 653 | createPort(c.nextPortId++, "BT A2DP Speaker", 0, false, |
| 654 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, 0, |
| 655 | AudioDeviceDescription::CONNECTION_BT_A2DP)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 656 | btOutSpeaker.profiles.insert(btOutSpeaker.profiles.begin(), |
| 657 | standardPcmAudioProfiles.begin(), |
| 658 | standardPcmAudioProfiles.end()); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 659 | c.ports.push_back(btOutSpeaker); |
| 660 | c.connectedProfiles[btOutSpeaker.id] = standardPcmAudioProfiles; |
| 661 | |
| 662 | AudioPort btOutHearingAid = |
| 663 | createPort(c.nextPortId++, "BT Hearing Aid Out", 0, false, |
| 664 | createDeviceExt(AudioDeviceType::OUT_HEARING_AID, 0, |
| 665 | AudioDeviceDescription::CONNECTION_WIRELESS)); |
| 666 | c.ports.push_back(btOutHearingAid); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 667 | c.connectedProfiles[btOutHearingAid.id] = hearingAidAudioProfiles; |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 668 | |
| 669 | // Mix ports |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 670 | AudioPort btOutMix = |
| 671 | createPort(c.nextPortId++, "a2dp output", 0, false, createPortMixExt(1, 1)); |
| 672 | c.ports.push_back(btOutMix); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 673 | |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 674 | AudioPort btHearingOutMix = |
| 675 | createPort(c.nextPortId++, "hearing aid output", 0, false, createPortMixExt(1, 1)); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 676 | btHearingOutMix.profiles = hearingAidAudioProfiles; |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 677 | c.ports.push_back(btHearingOutMix); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 678 | |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 679 | c.routes.push_back(createRoute({btOutMix}, btOutDevice)); |
| 680 | c.routes.push_back(createRoute({btOutMix}, btOutHeadphone)); |
| 681 | c.routes.push_back(createRoute({btOutMix}, btOutSpeaker)); |
| 682 | c.routes.push_back(createRoute({btHearingOutMix}, btOutHearingAid)); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 683 | |
| 684 | return c; |
| 685 | }(); |
| 686 | return std::make_unique<Configuration>(configuration); |
| 687 | } |
| 688 | |
Lorena Torres-Huerta | 394e252 | 2022-12-20 02:21:41 +0000 | [diff] [blame] | 689 | std::unique_ptr<Module::Configuration> getConfiguration(Module::Type moduleType) { |
| 690 | switch (moduleType) { |
| 691 | case Module::Type::DEFAULT: |
| 692 | return getPrimaryConfiguration(); |
| 693 | case Module::Type::R_SUBMIX: |
| 694 | return getRSubmixConfiguration(); |
| 695 | case Module::Type::STUB: |
| 696 | return getStubConfiguration(); |
| 697 | case Module::Type::USB: |
| 698 | return getUsbConfiguration(); |
| 699 | case Module::Type::BLUETOOTH: |
| 700 | return getBluetoothConfiguration(); |
| 701 | } |
| 702 | } |
| 703 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 704 | } // namespace aidl::android::hardware::audio::core::internal |