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 | 5eea7fb | 2023-10-13 23:38:25 +0000 | [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 | |
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 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 138 | // Primary (default) configuration: |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 139 | // |
| 140 | // Device ports: |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 141 | // * "Speaker", OUT_SPEAKER, default |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 142 | // - no profiles specified |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 143 | // * "Built-In Mic", IN_MICROPHONE, default |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 144 | // - no profiles specified |
| 145 | // * "Telephony Tx", OUT_TELEPHONY_TX |
| 146 | // - no profiles specified |
| 147 | // * "Telephony Rx", IN_TELEPHONY_RX |
| 148 | // - no profiles specified |
| 149 | // * "FM Tuner", IN_FM_TUNER |
| 150 | // - no profiles specified |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 151 | // |
| 152 | // Mix ports: |
| 153 | // * "primary output", PRIMARY, 1 max open, 1 max active stream |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 154 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 155 | // * "primary input", 1 max open, 1 max active stream |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 156 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 157 | // * "telephony_tx", 1 max open, 1 max active stream |
| 158 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 159 | // * "telephony_rx", 1 max open, 1 max active stream |
| 160 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 161 | // * "fm_tuner", 1 max open, 1 max active stream |
| 162 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 163 | // |
| 164 | // Routes: |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 165 | // "primary out" -> "Speaker" |
| 166 | // "Built-In Mic" -> "primary input" |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 167 | // "Telephony Rx" -> "telephony_rx" |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 168 | // "telephony_tx" -> "Telephony Tx" |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 169 | // "FM Tuner" -> "fm_tuner" |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 170 | // |
| 171 | // Initial port configs: |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 172 | // * "Speaker" device port: dynamic configuration |
| 173 | // * "Built-In Mic" device port: dynamic configuration |
| 174 | // * "Telephony Tx" device port: dynamic configuration |
| 175 | // * "Telephony Rx" device port: dynamic configuration |
| 176 | // * "FM Tuner" device port: dynamic configuration |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 177 | // |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 178 | std::unique_ptr<Configuration> getPrimaryConfiguration() { |
| 179 | static const Configuration configuration = []() { |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 180 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 181 | createProfile(PcmType::INT_16_BIT, |
| 182 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 183 | {8000, 11025, 16000, 32000, 44100, 48000})}; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 184 | Configuration c; |
| 185 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 186 | // Device ports |
| 187 | |
| 188 | AudioPort speakerOutDevice = |
| 189 | createPort(c.nextPortId++, "Speaker", 0, false, |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 190 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, |
| 191 | 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 192 | c.ports.push_back(speakerOutDevice); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 193 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 194 | createDynamicPortConfig(speakerOutDevice.id, speakerOutDevice.id, 0, false, |
| 195 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, 0))); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 196 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 197 | AudioPort micInDevice = |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 198 | createPort(c.nextPortId++, "Built-In Mic", 0, true, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 199 | createDeviceExt(AudioDeviceType::IN_MICROPHONE, |
| 200 | 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE)); |
| 201 | c.ports.push_back(micInDevice); |
| 202 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 203 | createDynamicPortConfig(micInDevice.id, micInDevice.id, 0, true, |
| 204 | createDeviceExt(AudioDeviceType::IN_MICROPHONE, 0))); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 205 | |
| 206 | AudioPort telephonyTxOutDevice = |
| 207 | createPort(c.nextPortId++, "Telephony Tx", 0, false, |
| 208 | createDeviceExt(AudioDeviceType::OUT_TELEPHONY_TX, 0)); |
| 209 | c.ports.push_back(telephonyTxOutDevice); |
| 210 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 211 | createDynamicPortConfig(telephonyTxOutDevice.id, telephonyTxOutDevice.id, 0, false, |
| 212 | createDeviceExt(AudioDeviceType::OUT_TELEPHONY_TX, 0))); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 213 | |
| 214 | AudioPort telephonyRxInDevice = |
| 215 | createPort(c.nextPortId++, "Telephony Rx", 0, true, |
| 216 | createDeviceExt(AudioDeviceType::IN_TELEPHONY_RX, 0)); |
| 217 | c.ports.push_back(telephonyRxInDevice); |
| 218 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 219 | createDynamicPortConfig(telephonyRxInDevice.id, telephonyRxInDevice.id, 0, true, |
| 220 | createDeviceExt(AudioDeviceType::IN_TELEPHONY_RX, 0))); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 221 | |
| 222 | AudioPort fmTunerInDevice = createPort(c.nextPortId++, "FM Tuner", 0, true, |
| 223 | createDeviceExt(AudioDeviceType::IN_FM_TUNER, 0)); |
| 224 | c.ports.push_back(fmTunerInDevice); |
| 225 | c.initialConfigs.push_back( |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 226 | createDynamicPortConfig(fmTunerInDevice.id, fmTunerInDevice.id, 0, true, |
| 227 | createDeviceExt(AudioDeviceType::IN_FM_TUNER, 0))); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 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 = |
Mikhail Naganov | 8dbc511 | 2023-10-02 14:51:50 -0700 | [diff] [blame] | 240 | createPort(c.nextPortId++, "primary input", 0, true, createPortMixExt(0, 1)); |
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 = |
Mikhail Naganov | 8dbc511 | 2023-10-02 14:51:50 -0700 | [diff] [blame] | 255 | createPort(c.nextPortId++, "telephony_rx", 0, true, createPortMixExt(0, 1)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 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 = |
Mikhail Naganov | 8dbc511 | 2023-10-02 14:51:50 -0700 | [diff] [blame] | 262 | createPort(c.nextPortId++, "fm_tuner", 0, true, createPortMixExt(0, 1)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 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 | |
Mikhail Naganov | 5eea7fb | 2023-10-13 23:38:25 +0000 | [diff] [blame] | 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 |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 290 | // config to match it. There are several reasons for that: |
| 291 | // 1. The "Remote Submix In" device is listed in the XML config as "attached", |
| 292 | // however in the AIDL scheme its device type has a "virtual" connection. |
| 293 | // 2. The canonical r_submix configuration only lists 'STEREO' and '48000', |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 294 | // however the framework attempts to open streams for other sample rates |
| 295 | // as well. The legacy r_submix implementation allowed that, but libaudiohal@aidl |
| 296 | // will not find a mix port to use. Because of that, list all channel |
| 297 | // masks and sample rates that the legacy implementation allowed. |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 298 | // 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] | 299 | // and this is checked indirectly by AudioPlaybackCaptureTest#testPlaybackCaptureDoS |
| 300 | // CTS test. Instead of hardcoding the number of routes, we can use |
| 301 | // "maxOpen/ActiveStreamCount" to enforce a similar limit. However, the canonical |
| 302 | // XML file lacks this specification. |
| 303 | // |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 304 | // Remote Submix configuration: |
| 305 | // |
| 306 | // Device ports: |
| 307 | // * "Remote Submix Out", OUT_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 | // * "Remote Submix In", IN_SUBMIX |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 310 | // - no profiles specified |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 311 | // |
| 312 | // Mix ports: |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 313 | // * "r_submix output", 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 | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 315 | // * "r_submix input", maximum 20 opened streams, maximum 10 active streams |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 316 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 317 | // |
| 318 | // Routes: |
| 319 | // "r_submix output" -> "Remote Submix Out" |
| 320 | // "Remote Submix In" -> "r_submix input" |
| 321 | // |
| 322 | std::unique_ptr<Configuration> getRSubmixConfiguration() { |
| 323 | static const Configuration configuration = []() { |
| 324 | Configuration c; |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 325 | const std::vector<AudioProfile> standardPcmAudioProfiles{ |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 326 | createProfile(PcmType::INT_16_BIT, |
| 327 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 328 | {8000, 11025, 16000, 32000, 44100, 48000})}; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 329 | |
| 330 | // Device ports |
| 331 | |
Mikhail Naganov | 26526f1 | 2023-05-12 13:51:06 -0700 | [diff] [blame] | 332 | AudioPort rsubmixOutDevice = |
| 333 | createPort(c.nextPortId++, "Remote Submix Out", 0, false, |
| 334 | createDeviceExt(AudioDeviceType::OUT_SUBMIX, 0, |
| 335 | AudioDeviceDescription::CONNECTION_VIRTUAL)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 336 | c.ports.push_back(rsubmixOutDevice); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 337 | c.connectedProfiles[rsubmixOutDevice.id] = standardPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 338 | |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 339 | AudioPort rsubmixInDevice = |
| 340 | createPort(c.nextPortId++, "Remote Submix In", 0, true, |
| 341 | createDeviceExt(AudioDeviceType::IN_SUBMIX, 0, |
| 342 | AudioDeviceDescription::CONNECTION_VIRTUAL)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 343 | c.ports.push_back(rsubmixInDevice); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 344 | c.connectedProfiles[rsubmixInDevice.id] = standardPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 345 | |
| 346 | // Mix ports |
| 347 | |
| 348 | AudioPort rsubmixOutMix = |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 349 | createPort(c.nextPortId++, "r_submix output", 0, false, createPortMixExt(20, 10)); |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 350 | rsubmixOutMix.profiles = standardPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 351 | c.ports.push_back(rsubmixOutMix); |
| 352 | |
| 353 | AudioPort rsubmixInMix = |
Mikhail Naganov | 21d4b96 | 2023-09-18 17:00:10 -0700 | [diff] [blame] | 354 | createPort(c.nextPortId++, "r_submix input", 0, true, createPortMixExt(20, 10)); |
David Li | b089c0c | 2023-08-10 12:47:44 +0800 | [diff] [blame] | 355 | rsubmixInMix.profiles = standardPcmAudioProfiles; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 356 | c.ports.push_back(rsubmixInMix); |
| 357 | |
| 358 | c.routes.push_back(createRoute({rsubmixOutMix}, rsubmixOutDevice)); |
| 359 | c.routes.push_back(createRoute({rsubmixInDevice}, rsubmixInMix)); |
| 360 | |
| 361 | return c; |
| 362 | }(); |
| 363 | return std::make_unique<Configuration>(configuration); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 364 | } |
| 365 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 366 | // Usb configuration: |
| 367 | // |
| 368 | // Device ports: |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 369 | // * "USB Device Out", OUT_DEVICE, CONNECTION_USB |
| 370 | // - no profiles specified |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 371 | // * "USB Headset Out", OUT_HEADSET, CONNECTION_USB |
| 372 | // - no profiles specified |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 373 | // * "USB Device In", IN_DEVICE, CONNECTION_USB |
| 374 | // - no profiles specified |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 375 | // * "USB Headset In", IN_HEADSET, CONNECTION_USB |
| 376 | // - no profiles specified |
| 377 | // |
| 378 | // Mix ports: |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 379 | // * "usb_device output", 1 max open, 1 max active stream |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 380 | // - no profiles specified |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 381 | // * "usb_device input", 1 max open, 1 max active stream |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 382 | // - no profiles specified |
| 383 | // |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 384 | // Routes: |
| 385 | // * "usb_device output" -> "USB Device Out" |
| 386 | // * "usb_device output" -> "USB Headset Out" |
| 387 | // * "USB Device In", "USB Headset In" -> "usb_device input" |
| 388 | // |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 389 | // Profiles for device port connected state (when simulating connections): |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 390 | // * "USB Device Out", "USB Headset Out": |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 391 | // - profile PCM 16-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 392 | // - 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] | 393 | // * "USB Device In", "USB Headset In": |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 394 | // - profile PCM 16-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 395 | // - profile PCM 24-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 396 | // |
| 397 | std::unique_ptr<Configuration> getUsbConfiguration() { |
| 398 | static const Configuration configuration = []() { |
| 399 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 400 | createProfile(PcmType::INT_16_BIT, |
| 401 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 402 | AudioChannelLayout::INDEX_MASK_1, AudioChannelLayout::INDEX_MASK_2}, |
| 403 | {44100, 48000}), |
| 404 | createProfile(PcmType::INT_24_BIT, |
| 405 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 406 | AudioChannelLayout::INDEX_MASK_1, AudioChannelLayout::INDEX_MASK_2}, |
| 407 | {44100, 48000})}; |
| 408 | Configuration c; |
| 409 | |
| 410 | // Device ports |
| 411 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 412 | AudioPort usbOutDevice = |
| 413 | createPort(c.nextPortId++, "USB Device Out", 0, false, |
| 414 | createDeviceExt(AudioDeviceType::OUT_DEVICE, 0, |
| 415 | AudioDeviceDescription::CONNECTION_USB)); |
| 416 | c.ports.push_back(usbOutDevice); |
| 417 | c.connectedProfiles[usbOutDevice.id] = standardPcmAudioProfiles; |
| 418 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 419 | AudioPort usbOutHeadset = |
| 420 | createPort(c.nextPortId++, "USB Headset Out", 0, false, |
| 421 | createDeviceExt(AudioDeviceType::OUT_HEADSET, 0, |
| 422 | AudioDeviceDescription::CONNECTION_USB)); |
| 423 | c.ports.push_back(usbOutHeadset); |
| 424 | c.connectedProfiles[usbOutHeadset.id] = standardPcmAudioProfiles; |
| 425 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 426 | AudioPort usbInDevice = createPort(c.nextPortId++, "USB Device In", 0, true, |
| 427 | createDeviceExt(AudioDeviceType::IN_DEVICE, 0, |
| 428 | AudioDeviceDescription::CONNECTION_USB)); |
| 429 | c.ports.push_back(usbInDevice); |
| 430 | c.connectedProfiles[usbInDevice.id] = standardPcmAudioProfiles; |
| 431 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 432 | AudioPort usbInHeadset = |
| 433 | createPort(c.nextPortId++, "USB Headset In", 0, true, |
| 434 | createDeviceExt(AudioDeviceType::IN_HEADSET, 0, |
| 435 | AudioDeviceDescription::CONNECTION_USB)); |
| 436 | c.ports.push_back(usbInHeadset); |
| 437 | c.connectedProfiles[usbInHeadset.id] = standardPcmAudioProfiles; |
| 438 | |
| 439 | // Mix ports |
| 440 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 441 | AudioPort usbDeviceOutMix = |
| 442 | createPort(c.nextPortId++, "usb_device output", 0, false, createPortMixExt(1, 1)); |
| 443 | c.ports.push_back(usbDeviceOutMix); |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 444 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 445 | AudioPort usbDeviceInMix = |
Mikhail Naganov | 8dbc511 | 2023-10-02 14:51:50 -0700 | [diff] [blame] | 446 | createPort(c.nextPortId++, "usb_device input", 0, true, createPortMixExt(0, 1)); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 447 | c.ports.push_back(usbDeviceInMix); |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 448 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 449 | c.routes.push_back(createRoute({usbDeviceOutMix}, usbOutDevice)); |
| 450 | c.routes.push_back(createRoute({usbDeviceOutMix}, usbOutHeadset)); |
| 451 | c.routes.push_back(createRoute({usbInDevice, usbInHeadset}, usbDeviceInMix)); |
| 452 | |
| 453 | return c; |
| 454 | }(); |
| 455 | return std::make_unique<Configuration>(configuration); |
| 456 | } |
| 457 | |
| 458 | // Stub configuration: |
| 459 | // |
| 460 | // Device ports: |
| 461 | // * "Test Out", OUT_AFE_PROXY |
| 462 | // - no profiles specified |
| 463 | // * "Test In", IN_AFE_PROXY |
| 464 | // - no profiles specified |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 465 | // * "Wired Headset", OUT_HEADSET |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 466 | // - no profiles specified |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 467 | // * "Wired Headset Mic", IN_HEADSET |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 468 | // - no profiles specified |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 469 | // |
| 470 | // Mix ports: |
| 471 | // * "test output", 1 max open, 1 max active stream |
| 472 | // - profile PCM 24-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 473 | // * "test fast output", 1 max open, 1 max active stream |
| 474 | // - profile PCM 24-bit; STEREO; 44100, 48000 |
| 475 | // * "test compressed offload", DIRECT|COMPRESS_OFFLOAD|NON_BLOCKING, 1 max open, 1 max active |
| 476 | // stream |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 477 | // - profile MP3; MONO, STEREO; 44100, 48000 |
| 478 | // * "test input", 2 max open, 2 max active streams |
| 479 | // - profile PCM 24-bit; MONO, STEREO, FRONT_BACK; |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 480 | // 8000, 11025, 16000, 22050, 32000, 44100, 48000 |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 481 | // |
| 482 | // Routes: |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 483 | // "test output", "test fast output", "test compressed offload" -> "Test Out" |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 484 | // "test output" -> "Wired Headset" |
| 485 | // "Test In", "Wired Headset Mic" -> "test input" |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 486 | // |
| 487 | // Initial port configs: |
| 488 | // * "Test Out" device port: PCM 24-bit; STEREO; 48000 |
| 489 | // * "Test In" device port: PCM 24-bit; MONO; 48000 |
| 490 | // |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 491 | // Profiles for device port connected state (when simulating connections): |
| 492 | // * "Wired Headset": dynamic profiles |
| 493 | // * "Wired Headset Mic": dynamic profiles |
| 494 | // |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 495 | std::unique_ptr<Configuration> getStubConfiguration() { |
| 496 | static const Configuration configuration = []() { |
| 497 | Configuration c; |
| 498 | |
| 499 | // Device ports |
| 500 | |
| 501 | AudioPort testOutDevice = createPort(c.nextPortId++, "Test Out", 0, false, |
| 502 | createDeviceExt(AudioDeviceType::OUT_AFE_PROXY, 0)); |
| 503 | c.ports.push_back(testOutDevice); |
| 504 | c.initialConfigs.push_back( |
| 505 | createPortConfig(testOutDevice.id, testOutDevice.id, PcmType::INT_24_BIT, |
| 506 | AudioChannelLayout::LAYOUT_STEREO, 48000, 0, false, |
| 507 | createDeviceExt(AudioDeviceType::OUT_AFE_PROXY, 0))); |
| 508 | |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 509 | AudioPort headsetOutDevice = |
| 510 | createPort(c.nextPortId++, "Wired Headset", 0, false, |
| 511 | createDeviceExt(AudioDeviceType::OUT_HEADSET, 0, |
| 512 | AudioDeviceDescription::CONNECTION_ANALOG)); |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 513 | c.ports.push_back(headsetOutDevice); |
| 514 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 515 | AudioPort testInDevice = createPort(c.nextPortId++, "Test In", 0, true, |
| 516 | createDeviceExt(AudioDeviceType::IN_AFE_PROXY, 0)); |
| 517 | c.ports.push_back(testInDevice); |
| 518 | c.initialConfigs.push_back( |
| 519 | createPortConfig(testInDevice.id, testInDevice.id, PcmType::INT_24_BIT, |
| 520 | AudioChannelLayout::LAYOUT_MONO, 48000, 0, true, |
| 521 | createDeviceExt(AudioDeviceType::IN_AFE_PROXY, 0))); |
| 522 | |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 523 | AudioPort headsetInDevice = |
| 524 | createPort(c.nextPortId++, "Wired Headset Mic", 0, true, |
| 525 | createDeviceExt(AudioDeviceType::IN_HEADSET, 0, |
| 526 | AudioDeviceDescription::CONNECTION_ANALOG)); |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 527 | c.ports.push_back(headsetInDevice); |
| 528 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 529 | // Mix ports |
| 530 | |
| 531 | AudioPort testOutMix = |
| 532 | createPort(c.nextPortId++, "test output", 0, false, createPortMixExt(1, 1)); |
| 533 | testOutMix.profiles.push_back( |
| 534 | createProfile(PcmType::INT_24_BIT, |
| 535 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 536 | {8000, 11025, 16000, 32000, 44100, 48000})); |
| 537 | c.ports.push_back(testOutMix); |
| 538 | |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 539 | AudioPort testFastOutMix = createPort(c.nextPortId++, "test fast output", |
| 540 | makeBitPositionFlagMask({AudioOutputFlags::FAST}), |
| 541 | false, createPortMixExt(1, 1)); |
| 542 | testFastOutMix.profiles.push_back(createProfile( |
| 543 | PcmType::INT_24_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {44100, 48000})); |
| 544 | c.ports.push_back(testFastOutMix); |
| 545 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 546 | AudioPort compressedOffloadOutMix = |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 547 | createPort(c.nextPortId++, "test compressed offload", |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 548 | makeBitPositionFlagMask({AudioOutputFlags::DIRECT, |
| 549 | AudioOutputFlags::COMPRESS_OFFLOAD, |
| 550 | AudioOutputFlags::NON_BLOCKING}), |
| 551 | false, createPortMixExt(1, 1)); |
| 552 | compressedOffloadOutMix.profiles.push_back( |
| 553 | createProfile(::android::MEDIA_MIMETYPE_AUDIO_MPEG, |
| 554 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 555 | {44100, 48000})); |
| 556 | c.ports.push_back(compressedOffloadOutMix); |
| 557 | |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 558 | AudioPort testInMix = |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 559 | createPort(c.nextPortId++, "test input", 0, true, createPortMixExt(2, 2)); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 560 | testInMix.profiles.push_back( |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 561 | createProfile(PcmType::INT_16_BIT, |
| 562 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 563 | AudioChannelLayout::LAYOUT_FRONT_BACK}, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 564 | {8000, 11025, 16000, 22050, 32000, 44100, 48000})); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 565 | testInMix.profiles.push_back( |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 566 | createProfile(PcmType::INT_24_BIT, |
| 567 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 568 | AudioChannelLayout::LAYOUT_FRONT_BACK}, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 569 | {8000, 11025, 16000, 22050, 32000, 44100, 48000})); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 570 | c.ports.push_back(testInMix); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 571 | |
Mikhail Naganov | 4bf6899 | 2023-08-07 17:11:14 -0700 | [diff] [blame] | 572 | c.routes.push_back( |
| 573 | createRoute({testOutMix, testFastOutMix, compressedOffloadOutMix}, testOutDevice)); |
Mikhail Naganov | fe47b00 | 2023-09-15 18:53:42 -0700 | [diff] [blame] | 574 | c.routes.push_back(createRoute({testOutMix}, headsetOutDevice)); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 575 | c.routes.push_back(createRoute({testInDevice, headsetInDevice}, testInMix)); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 576 | |
| 577 | c.portConfigs.insert(c.portConfigs.end(), c.initialConfigs.begin(), c.initialConfigs.end()); |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 578 | |
| 579 | return c; |
| 580 | }(); |
| 581 | return std::make_unique<Configuration>(configuration); |
| 582 | } |
| 583 | |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 584 | // Bluetooth configuration: |
| 585 | // |
| 586 | // Device ports: |
| 587 | // * "BT A2DP Out", OUT_DEVICE, CONNECTION_BT_A2DP |
| 588 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 589 | // * "BT A2DP Headphones", OUT_HEADPHONE, CONNECTION_BT_A2DP |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 590 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
| 591 | // * "BT A2DP Speaker", OUT_SPEAKER, CONNECTION_BT_A2DP |
| 592 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
| 593 | // * "BT Hearing Aid Out", OUT_HEARING_AID, CONNECTION_WIRELESS |
| 594 | // - no profiles specified |
| 595 | // |
| 596 | // Mix ports: |
| 597 | // * "a2dp output", 1 max open, 1 max active stream |
| 598 | // - no profiles specified |
| 599 | // * "hearing aid output", 1 max open, 1 max active stream |
| 600 | // - profile PCM 16-bit; STEREO; 16000, 24000 |
| 601 | // |
| 602 | // Routes: |
| 603 | // "a2dp output" -> "BT A2DP Out" |
| 604 | // "a2dp output" -> "BT A2DP Headphones" |
| 605 | // "a2dp output" -> "BT A2DP Speaker" |
| 606 | // "hearing aid output" -> "BT Hearing Aid Out" |
| 607 | // |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 608 | // Profiles for device port connected state (when simulating connections): |
| 609 | // * "BT A2DP Out", "BT A2DP Headphones", "BT A2DP Speaker": |
| 610 | // - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000 |
| 611 | // * "BT Hearing Aid Out": |
| 612 | // - profile PCM 16-bit; STEREO; 16000, 24000 |
| 613 | // |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 614 | std::unique_ptr<Configuration> getBluetoothConfiguration() { |
| 615 | static const Configuration configuration = []() { |
| 616 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 617 | createProfile(PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, |
| 618 | {44100, 48000, 88200, 96000})}; |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 619 | const std::vector<AudioProfile> hearingAidAudioProfiles = {createProfile( |
| 620 | PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {16000, 24000})}; |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 621 | Configuration c; |
| 622 | |
| 623 | // Device ports |
| 624 | AudioPort btOutDevice = |
| 625 | createPort(c.nextPortId++, "BT A2DP Out", 0, false, |
| 626 | createDeviceExt(AudioDeviceType::OUT_DEVICE, 0, |
| 627 | AudioDeviceDescription::CONNECTION_BT_A2DP)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 628 | btOutDevice.profiles.insert(btOutDevice.profiles.begin(), standardPcmAudioProfiles.begin(), |
| 629 | standardPcmAudioProfiles.end()); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 630 | c.ports.push_back(btOutDevice); |
| 631 | c.connectedProfiles[btOutDevice.id] = standardPcmAudioProfiles; |
| 632 | |
| 633 | AudioPort btOutHeadphone = |
| 634 | createPort(c.nextPortId++, "BT A2DP Headphones", 0, false, |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 635 | createDeviceExt(AudioDeviceType::OUT_HEADPHONE, 0, |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 636 | AudioDeviceDescription::CONNECTION_BT_A2DP)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 637 | btOutHeadphone.profiles.insert(btOutHeadphone.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(btOutHeadphone); |
| 641 | c.connectedProfiles[btOutHeadphone.id] = standardPcmAudioProfiles; |
| 642 | |
| 643 | AudioPort btOutSpeaker = |
| 644 | createPort(c.nextPortId++, "BT A2DP Speaker", 0, false, |
| 645 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, 0, |
| 646 | AudioDeviceDescription::CONNECTION_BT_A2DP)); |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 647 | btOutSpeaker.profiles.insert(btOutSpeaker.profiles.begin(), |
| 648 | standardPcmAudioProfiles.begin(), |
| 649 | standardPcmAudioProfiles.end()); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 650 | c.ports.push_back(btOutSpeaker); |
| 651 | c.connectedProfiles[btOutSpeaker.id] = standardPcmAudioProfiles; |
| 652 | |
| 653 | AudioPort btOutHearingAid = |
| 654 | createPort(c.nextPortId++, "BT Hearing Aid Out", 0, false, |
| 655 | createDeviceExt(AudioDeviceType::OUT_HEARING_AID, 0, |
| 656 | AudioDeviceDescription::CONNECTION_WIRELESS)); |
| 657 | c.ports.push_back(btOutHearingAid); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 658 | c.connectedProfiles[btOutHearingAid.id] = hearingAidAudioProfiles; |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 659 | |
| 660 | // Mix ports |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 661 | AudioPort btOutMix = |
| 662 | createPort(c.nextPortId++, "a2dp output", 0, false, createPortMixExt(1, 1)); |
| 663 | c.ports.push_back(btOutMix); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 664 | |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 665 | AudioPort btHearingOutMix = |
| 666 | createPort(c.nextPortId++, "hearing aid output", 0, false, createPortMixExt(1, 1)); |
Mikhail Naganov | 84bcc04 | 2023-10-05 17:36:57 -0700 | [diff] [blame] | 667 | btHearingOutMix.profiles = hearingAidAudioProfiles; |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 668 | c.ports.push_back(btHearingOutMix); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 669 | |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 670 | c.routes.push_back(createRoute({btOutMix}, btOutDevice)); |
| 671 | c.routes.push_back(createRoute({btOutMix}, btOutHeadphone)); |
| 672 | c.routes.push_back(createRoute({btOutMix}, btOutSpeaker)); |
| 673 | c.routes.push_back(createRoute({btHearingOutMix}, btOutHearingAid)); |
Mikhail Naganov | b03b5c4 | 2023-07-26 13:13:35 -0700 | [diff] [blame] | 674 | |
| 675 | return c; |
| 676 | }(); |
| 677 | return std::make_unique<Configuration>(configuration); |
| 678 | } |
| 679 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 680 | } // namespace aidl::android::hardware::audio::core::internal |