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