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 | |
| 28 | using aidl::android::media::audio::common::AudioChannelLayout; |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 29 | using aidl::android::media::audio::common::AudioDeviceDescription; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 30 | using aidl::android::media::audio::common::AudioDeviceType; |
| 31 | using aidl::android::media::audio::common::AudioFormatDescription; |
| 32 | using aidl::android::media::audio::common::AudioFormatType; |
| 33 | using aidl::android::media::audio::common::AudioGainConfig; |
| 34 | using aidl::android::media::audio::common::AudioIoFlags; |
| 35 | using aidl::android::media::audio::common::AudioOutputFlags; |
| 36 | using aidl::android::media::audio::common::AudioPort; |
| 37 | using aidl::android::media::audio::common::AudioPortConfig; |
| 38 | using aidl::android::media::audio::common::AudioPortDeviceExt; |
| 39 | using aidl::android::media::audio::common::AudioPortExt; |
| 40 | using aidl::android::media::audio::common::AudioPortMixExt; |
| 41 | using aidl::android::media::audio::common::AudioProfile; |
| 42 | using aidl::android::media::audio::common::Int; |
Mikhail Naganov | 6725ef5 | 2023-02-09 17:52:50 -0800 | [diff] [blame] | 43 | using aidl::android::media::audio::common::MicrophoneInfo; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 44 | using aidl::android::media::audio::common::PcmType; |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 45 | using android::hardware::audio::common::makeBitPositionFlagMask; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 46 | |
| 47 | namespace aidl::android::hardware::audio::core::internal { |
| 48 | |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 49 | static void fillProfile(AudioProfile* profile, const std::vector<int32_t>& channelLayouts, |
| 50 | const std::vector<int32_t>& sampleRates) { |
| 51 | for (auto layout : channelLayouts) { |
| 52 | profile->channelMasks.push_back( |
| 53 | AudioChannelLayout::make<AudioChannelLayout::layoutMask>(layout)); |
| 54 | } |
| 55 | profile->sampleRates.insert(profile->sampleRates.end(), sampleRates.begin(), sampleRates.end()); |
| 56 | } |
| 57 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 58 | static AudioProfile createProfile(PcmType pcmType, const std::vector<int32_t>& channelLayouts, |
| 59 | const std::vector<int32_t>& sampleRates) { |
| 60 | AudioProfile profile; |
| 61 | profile.format.type = AudioFormatType::PCM; |
| 62 | profile.format.pcm = pcmType; |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 63 | fillProfile(&profile, channelLayouts, sampleRates); |
| 64 | return profile; |
| 65 | } |
| 66 | |
| 67 | static AudioProfile createProfile(const std::string& encodingType, |
| 68 | const std::vector<int32_t>& channelLayouts, |
| 69 | const std::vector<int32_t>& sampleRates) { |
| 70 | AudioProfile profile; |
| 71 | profile.format.encoding = encodingType; |
| 72 | fillProfile(&profile, channelLayouts, sampleRates); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 73 | return profile; |
| 74 | } |
| 75 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 76 | static AudioPortExt createDeviceExt(AudioDeviceType devType, int32_t flags, |
| 77 | std::string connection = "") { |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 78 | AudioPortDeviceExt deviceExt; |
| 79 | deviceExt.device.type.type = devType; |
Mikhail Naganov | b0f3d97 | 2023-01-27 16:08:29 -0800 | [diff] [blame] | 80 | if (devType == AudioDeviceType::IN_MICROPHONE && connection.empty()) { |
| 81 | deviceExt.device.address = "bottom"; |
| 82 | } else if (devType == AudioDeviceType::IN_MICROPHONE_BACK && connection.empty()) { |
| 83 | deviceExt.device.address = "back"; |
| 84 | } |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 85 | deviceExt.device.type.connection = std::move(connection); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 86 | deviceExt.flags = flags; |
| 87 | return AudioPortExt::make<AudioPortExt::Tag::device>(deviceExt); |
| 88 | } |
| 89 | |
| 90 | static AudioPortExt createPortMixExt(int32_t maxOpenStreamCount, int32_t maxActiveStreamCount) { |
| 91 | AudioPortMixExt mixExt; |
| 92 | mixExt.maxOpenStreamCount = maxOpenStreamCount; |
| 93 | mixExt.maxActiveStreamCount = maxActiveStreamCount; |
| 94 | return AudioPortExt::make<AudioPortExt::Tag::mix>(mixExt); |
| 95 | } |
| 96 | |
| 97 | static AudioPort createPort(int32_t id, const std::string& name, int32_t flags, bool isInput, |
| 98 | const AudioPortExt& ext) { |
| 99 | AudioPort port; |
| 100 | port.id = id; |
| 101 | port.name = name; |
| 102 | port.flags = isInput ? AudioIoFlags::make<AudioIoFlags::Tag::input>(flags) |
| 103 | : AudioIoFlags::make<AudioIoFlags::Tag::output>(flags); |
| 104 | port.ext = ext; |
| 105 | return port; |
| 106 | } |
| 107 | |
| 108 | static AudioPortConfig createPortConfig(int32_t id, int32_t portId, PcmType pcmType, int32_t layout, |
| 109 | int32_t sampleRate, int32_t flags, bool isInput, |
| 110 | const AudioPortExt& ext) { |
| 111 | AudioPortConfig config; |
| 112 | config.id = id; |
| 113 | config.portId = portId; |
| 114 | config.sampleRate = Int{.value = sampleRate}; |
| 115 | config.channelMask = AudioChannelLayout::make<AudioChannelLayout::layoutMask>(layout); |
| 116 | config.format = AudioFormatDescription{.type = AudioFormatType::PCM, .pcm = pcmType}; |
| 117 | config.gain = AudioGainConfig(); |
| 118 | config.flags = isInput ? AudioIoFlags::make<AudioIoFlags::Tag::input>(flags) |
| 119 | : AudioIoFlags::make<AudioIoFlags::Tag::output>(flags); |
| 120 | config.ext = ext; |
| 121 | return config; |
| 122 | } |
| 123 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 124 | static AudioRoute createRoute(const std::vector<AudioPort>& sources, const AudioPort& sink) { |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 125 | AudioRoute route; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 126 | route.sinkPortId = sink.id; |
| 127 | std::transform(sources.begin(), sources.end(), std::back_inserter(route.sourcePortIds), |
| 128 | [](const auto& port) { return port.id; }); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 129 | return route; |
| 130 | } |
| 131 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 132 | // Primary (default) configuration: |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 133 | // |
| 134 | // Device ports: |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 135 | // * "Speaker", OUT_SPEAKER, default |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 136 | // - no profiles specified |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 137 | // * "Built-in Mic", IN_MICROPHONE, default |
| 138 | // - no profiles specified |
| 139 | // * "Telephony Tx", OUT_TELEPHONY_TX |
| 140 | // - no profiles specified |
| 141 | // * "Telephony Rx", IN_TELEPHONY_RX |
| 142 | // - no profiles specified |
| 143 | // * "FM Tuner", IN_FM_TUNER |
| 144 | // - no profiles specified |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 145 | // * "USB Out", OUT_DEVICE, CONNECTION_USB |
| 146 | // - no profiles specified |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 147 | // * "USB In", IN_DEVICE, CONNECTION_USB |
| 148 | // - no profiles specified |
| 149 | // |
| 150 | // Mix ports: |
| 151 | // * "primary output", PRIMARY, 1 max open, 1 max active stream |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 152 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
| 153 | // - profile PCM 24-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 154 | // * "compressed offload", DIRECT|COMPRESS_OFFLOAD|NON_BLOCKING, 1 max open, 1 max active stream |
| 155 | // - profile MP3; MONO, STEREO; 44100, 48000 |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 156 | // * "primary input", 2 max open, 2 max active streams |
| 157 | // - profile PCM 16-bit; MONO, STEREO, FRONT_BACK; |
| 158 | // 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 |
| 159 | // - profile PCM 24-bit; MONO, STEREO, FRONT_BACK; |
| 160 | // 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 161 | // * "telephony_tx", 1 max open, 1 max active stream |
| 162 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
| 163 | // - profile PCM 24-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
| 164 | // * "telephony_rx", 1 max open, 1 max active stream |
| 165 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
| 166 | // - profile PCM 24-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
| 167 | // * "fm_tuner", 1 max open, 1 max active stream |
| 168 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
| 169 | // - profile PCM 24-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 170 | // |
| 171 | // Routes: |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 172 | // "primary out", "compressed offload" -> "Speaker" |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 173 | // "primary out", "compressed offload" -> "USB Out" |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 174 | // "Built-in Mic", "USB In" -> "primary input" |
| 175 | // "telephony_tx" -> "Telephony Tx" |
| 176 | // "Telephony Rx" -> "telephony_rx" |
| 177 | // "FM Tuner" -> "fm_tuner" |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 178 | // |
| 179 | // Initial port configs: |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 180 | // * "Speaker" device port: PCM 24-bit; STEREO; 48000 |
| 181 | // * "Built-in Mic" device port: PCM 24-bit; MONO; 48000 |
| 182 | // * "Telephony Tx" device port: PCM 24-bit; MONO; 48000 |
| 183 | // * "Telephony Rx" device port: PCM 24-bit; MONO; 48000 |
| 184 | // * "FM Tuner" device port: PCM 24-bit; STEREO; 48000 |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 185 | // |
| 186 | // Profiles for device port connected state: |
| 187 | // * USB Out": |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 188 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
| 189 | // - profile PCM 24-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 190 | // * USB In": |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 191 | // - profile PCM 16-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
| 192 | // - profile PCM 24-bit; MONO, STEREO; 8000, 11025, 16000, 32000, 44100, 48000 |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 193 | // |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 194 | std::unique_ptr<Configuration> getPrimaryConfiguration() { |
| 195 | static const Configuration configuration = []() { |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 196 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 197 | createProfile(PcmType::INT_16_BIT, |
| 198 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 199 | {8000, 11025, 16000, 32000, 44100, 48000}), |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 200 | createProfile(PcmType::INT_24_BIT, |
| 201 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 202 | {8000, 11025, 16000, 32000, 44100, 48000})}; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 203 | Configuration c; |
| 204 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 205 | // Device ports |
| 206 | |
| 207 | AudioPort speakerOutDevice = |
| 208 | createPort(c.nextPortId++, "Speaker", 0, false, |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 209 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, |
| 210 | 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE)); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 211 | c.ports.push_back(speakerOutDevice); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 212 | c.initialConfigs.push_back( |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 213 | createPortConfig(speakerOutDevice.id, speakerOutDevice.id, PcmType::INT_24_BIT, |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 214 | AudioChannelLayout::LAYOUT_STEREO, 48000, 0, false, |
| 215 | createDeviceExt(AudioDeviceType::OUT_SPEAKER, 0))); |
| 216 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 217 | AudioPort micInDevice = |
| 218 | createPort(c.nextPortId++, "Built-in Mic", 0, true, |
| 219 | createDeviceExt(AudioDeviceType::IN_MICROPHONE, |
| 220 | 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE)); |
| 221 | c.ports.push_back(micInDevice); |
| 222 | c.initialConfigs.push_back( |
| 223 | createPortConfig(micInDevice.id, micInDevice.id, PcmType::INT_24_BIT, |
| 224 | AudioChannelLayout::LAYOUT_MONO, 48000, 0, true, |
| 225 | createDeviceExt(AudioDeviceType::IN_MICROPHONE, 0))); |
| 226 | |
| 227 | AudioPort telephonyTxOutDevice = |
| 228 | createPort(c.nextPortId++, "Telephony Tx", 0, false, |
| 229 | createDeviceExt(AudioDeviceType::OUT_TELEPHONY_TX, 0)); |
| 230 | c.ports.push_back(telephonyTxOutDevice); |
| 231 | c.initialConfigs.push_back( |
| 232 | createPortConfig(telephonyTxOutDevice.id, telephonyTxOutDevice.id, |
| 233 | PcmType::INT_24_BIT, AudioChannelLayout::LAYOUT_MONO, 48000, 0, |
| 234 | false, createDeviceExt(AudioDeviceType::OUT_TELEPHONY_TX, 0))); |
| 235 | |
| 236 | AudioPort telephonyRxInDevice = |
| 237 | createPort(c.nextPortId++, "Telephony Rx", 0, true, |
| 238 | createDeviceExt(AudioDeviceType::IN_TELEPHONY_RX, 0)); |
| 239 | c.ports.push_back(telephonyRxInDevice); |
| 240 | c.initialConfigs.push_back( |
| 241 | createPortConfig(telephonyRxInDevice.id, telephonyRxInDevice.id, |
| 242 | PcmType::INT_24_BIT, AudioChannelLayout::LAYOUT_MONO, 48000, 0, |
| 243 | true, createDeviceExt(AudioDeviceType::IN_TELEPHONY_RX, 0))); |
| 244 | |
| 245 | AudioPort fmTunerInDevice = createPort(c.nextPortId++, "FM Tuner", 0, true, |
| 246 | createDeviceExt(AudioDeviceType::IN_FM_TUNER, 0)); |
| 247 | c.ports.push_back(fmTunerInDevice); |
| 248 | c.initialConfigs.push_back( |
| 249 | createPortConfig(fmTunerInDevice.id, fmTunerInDevice.id, PcmType::INT_24_BIT, |
| 250 | AudioChannelLayout::LAYOUT_STEREO, 48000, 0, true, |
| 251 | createDeviceExt(AudioDeviceType::IN_FM_TUNER, 0))); |
| 252 | |
| 253 | AudioPort usbOutDevice = |
| 254 | createPort(c.nextPortId++, "USB Out", 0, false, |
| 255 | createDeviceExt(AudioDeviceType::OUT_DEVICE, 0, |
| 256 | AudioDeviceDescription::CONNECTION_USB)); |
| 257 | c.ports.push_back(usbOutDevice); |
| 258 | c.connectedProfiles[usbOutDevice.id] = standardPcmAudioProfiles; |
| 259 | |
| 260 | AudioPort usbInDevice = createPort(c.nextPortId++, "USB In", 0, true, |
| 261 | createDeviceExt(AudioDeviceType::IN_DEVICE, 0, |
| 262 | AudioDeviceDescription::CONNECTION_USB)); |
| 263 | c.ports.push_back(usbInDevice); |
| 264 | c.connectedProfiles[usbInDevice.id] = standardPcmAudioProfiles; |
| 265 | |
| 266 | // Mix ports |
| 267 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 268 | AudioPort primaryOutMix = createPort(c.nextPortId++, "primary output", |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 269 | makeBitPositionFlagMask(AudioOutputFlags::PRIMARY), |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 270 | false, createPortMixExt(1, 1)); |
| 271 | primaryOutMix.profiles.insert(primaryOutMix.profiles.begin(), |
| 272 | standardPcmAudioProfiles.begin(), |
| 273 | standardPcmAudioProfiles.end()); |
| 274 | c.ports.push_back(primaryOutMix); |
| 275 | |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 276 | AudioPort compressedOffloadOutMix = |
| 277 | createPort(c.nextPortId++, "compressed offload", |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 278 | makeBitPositionFlagMask({AudioOutputFlags::DIRECT, |
| 279 | AudioOutputFlags::COMPRESS_OFFLOAD, |
| 280 | AudioOutputFlags::NON_BLOCKING}), |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 281 | false, createPortMixExt(1, 1)); |
| 282 | compressedOffloadOutMix.profiles.push_back( |
| 283 | createProfile(::android::MEDIA_MIMETYPE_AUDIO_MPEG, |
| 284 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO}, |
| 285 | {44100, 48000})); |
| 286 | c.ports.push_back(compressedOffloadOutMix); |
| 287 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 288 | AudioPort primaryInMix = |
| 289 | createPort(c.nextPortId++, "primary input", 0, true, createPortMixExt(2, 2)); |
| 290 | primaryInMix.profiles.push_back( |
| 291 | createProfile(PcmType::INT_16_BIT, |
| 292 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 293 | AudioChannelLayout::LAYOUT_FRONT_BACK}, |
| 294 | {8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000})); |
| 295 | primaryInMix.profiles.push_back( |
| 296 | createProfile(PcmType::INT_24_BIT, |
| 297 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 298 | AudioChannelLayout::LAYOUT_FRONT_BACK}, |
| 299 | {8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000})); |
| 300 | c.ports.push_back(primaryInMix); |
| 301 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 302 | AudioPort telephonyTxOutMix = |
| 303 | createPort(c.nextPortId++, "telephony_tx", 0, false, createPortMixExt(1, 1)); |
| 304 | telephonyTxOutMix.profiles.insert(telephonyTxOutMix.profiles.begin(), |
| 305 | standardPcmAudioProfiles.begin(), |
| 306 | standardPcmAudioProfiles.end()); |
| 307 | c.ports.push_back(telephonyTxOutMix); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 308 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 309 | AudioPort telephonyRxInMix = |
| 310 | createPort(c.nextPortId++, "telephony_rx", 0, true, createPortMixExt(1, 1)); |
| 311 | telephonyRxInMix.profiles.insert(telephonyRxInMix.profiles.begin(), |
| 312 | standardPcmAudioProfiles.begin(), |
| 313 | standardPcmAudioProfiles.end()); |
| 314 | c.ports.push_back(telephonyRxInMix); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 315 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 316 | AudioPort fmTunerInMix = |
| 317 | createPort(c.nextPortId++, "fm_tuner", 0, true, createPortMixExt(1, 1)); |
| 318 | fmTunerInMix.profiles.insert(fmTunerInMix.profiles.begin(), |
| 319 | standardPcmAudioProfiles.begin(), |
| 320 | standardPcmAudioProfiles.end()); |
| 321 | c.ports.push_back(fmTunerInMix); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 322 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 323 | c.routes.push_back(createRoute({primaryOutMix, compressedOffloadOutMix}, speakerOutDevice)); |
| 324 | c.routes.push_back(createRoute({primaryOutMix, compressedOffloadOutMix}, usbOutDevice)); |
| 325 | c.routes.push_back(createRoute({micInDevice, usbInDevice}, primaryInMix)); |
| 326 | c.routes.push_back(createRoute({telephonyTxOutMix}, telephonyTxOutDevice)); |
| 327 | c.routes.push_back(createRoute({telephonyRxInDevice}, telephonyRxInMix)); |
| 328 | c.routes.push_back(createRoute({fmTunerInDevice}, fmTunerInMix)); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 329 | |
| 330 | c.portConfigs.insert(c.portConfigs.end(), c.initialConfigs.begin(), c.initialConfigs.end()); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 331 | |
| 332 | MicrophoneInfo mic; |
| 333 | mic.id = "mic"; |
| 334 | mic.device = micInDevice.ext.get<AudioPortExt::Tag::device>().device; |
| 335 | mic.group = 0; |
| 336 | mic.indexInTheGroup = 0; |
| 337 | c.microphones = std::vector<MicrophoneInfo>{mic}; |
| 338 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 339 | return c; |
| 340 | }(); |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 341 | return std::make_unique<Configuration>(configuration); |
| 342 | } |
| 343 | |
| 344 | // Remote Submix configuration: |
| 345 | // |
| 346 | // Device ports: |
| 347 | // * "Remote Submix Out", OUT_SUBMIX |
| 348 | // - profile PCM 24-bit; STEREO; 48000 |
| 349 | // * "Remote Submix In", IN_SUBMIX |
| 350 | // - profile PCM 24-bit; STEREO; 48000 |
| 351 | // |
| 352 | // Mix ports: |
| 353 | // * "r_submix output", stream count unlimited |
| 354 | // - profile PCM 24-bit; STEREO; 48000 |
| 355 | // * "r_submix input", stream count unlimited |
| 356 | // - profile PCM 24-bit; STEREO; 48000 |
| 357 | // |
| 358 | // Routes: |
| 359 | // "r_submix output" -> "Remote Submix Out" |
| 360 | // "Remote Submix In" -> "r_submix input" |
| 361 | // |
| 362 | std::unique_ptr<Configuration> getRSubmixConfiguration() { |
| 363 | static const Configuration configuration = []() { |
| 364 | Configuration c; |
| 365 | |
| 366 | // Device ports |
| 367 | |
| 368 | AudioPort rsubmixOutDevice = createPort(c.nextPortId++, "Remote Submix Out", 0, false, |
| 369 | createDeviceExt(AudioDeviceType::OUT_SUBMIX, 0)); |
| 370 | rsubmixOutDevice.profiles.push_back( |
| 371 | createProfile(PcmType::INT_24_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {48000})); |
| 372 | c.ports.push_back(rsubmixOutDevice); |
| 373 | |
| 374 | AudioPort rsubmixInDevice = createPort(c.nextPortId++, "Remote Submix In", 0, true, |
| 375 | createDeviceExt(AudioDeviceType::IN_SUBMIX, 0)); |
| 376 | rsubmixInDevice.profiles.push_back( |
| 377 | createProfile(PcmType::INT_24_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {48000})); |
| 378 | c.ports.push_back(rsubmixInDevice); |
| 379 | |
| 380 | // Mix ports |
| 381 | |
| 382 | AudioPort rsubmixOutMix = |
| 383 | createPort(c.nextPortId++, "r_submix output", 0, false, createPortMixExt(0, 0)); |
| 384 | rsubmixOutMix.profiles.push_back( |
| 385 | createProfile(PcmType::INT_24_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {48000})); |
| 386 | c.ports.push_back(rsubmixOutMix); |
| 387 | |
| 388 | AudioPort rsubmixInMix = |
| 389 | createPort(c.nextPortId++, "r_submix input", 0, true, createPortMixExt(0, 0)); |
| 390 | rsubmixInMix.profiles.push_back( |
| 391 | createProfile(PcmType::INT_24_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {48000})); |
| 392 | c.ports.push_back(rsubmixInMix); |
| 393 | |
| 394 | c.routes.push_back(createRoute({rsubmixOutMix}, rsubmixOutDevice)); |
| 395 | c.routes.push_back(createRoute({rsubmixInDevice}, rsubmixInMix)); |
| 396 | |
| 397 | return c; |
| 398 | }(); |
| 399 | return std::make_unique<Configuration>(configuration); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 400 | } |
| 401 | |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 402 | // Usb configuration: |
| 403 | // |
| 404 | // Device ports: |
| 405 | // * "USB Headset Out", OUT_HEADSET, CONNECTION_USB |
| 406 | // - no profiles specified |
| 407 | // * "USB Headset In", IN_HEADSET, CONNECTION_USB |
| 408 | // - no profiles specified |
| 409 | // |
| 410 | // Mix ports: |
| 411 | // * "usb_headset output", 1 max open, 1 max active stream |
| 412 | // - no profiles specified |
| 413 | // * "usb_headset input", 1 max open, 1 max active stream |
| 414 | // - no profiles specified |
| 415 | // |
| 416 | // Profiles for device port connected state: |
| 417 | // * USB Headset Out": |
| 418 | // - profile PCM 16-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 419 | // - profile PCM 24-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 420 | // * USB Headset In": |
| 421 | // - profile PCM 16-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 422 | // - profile PCM 24-bit; MONO, STEREO, INDEX_MASK_1, INDEX_MASK_2; 44100, 48000 |
| 423 | // |
| 424 | std::unique_ptr<Configuration> getUsbConfiguration() { |
| 425 | static const Configuration configuration = []() { |
| 426 | const std::vector<AudioProfile> standardPcmAudioProfiles = { |
| 427 | createProfile(PcmType::INT_16_BIT, |
| 428 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 429 | AudioChannelLayout::INDEX_MASK_1, AudioChannelLayout::INDEX_MASK_2}, |
| 430 | {44100, 48000}), |
| 431 | createProfile(PcmType::INT_24_BIT, |
| 432 | {AudioChannelLayout::LAYOUT_MONO, AudioChannelLayout::LAYOUT_STEREO, |
| 433 | AudioChannelLayout::INDEX_MASK_1, AudioChannelLayout::INDEX_MASK_2}, |
| 434 | {44100, 48000})}; |
| 435 | Configuration c; |
| 436 | |
| 437 | // Device ports |
| 438 | |
| 439 | AudioPort usbOutHeadset = |
| 440 | createPort(c.nextPortId++, "USB Headset Out", 0, false, |
| 441 | createDeviceExt(AudioDeviceType::OUT_HEADSET, 0, |
| 442 | AudioDeviceDescription::CONNECTION_USB)); |
| 443 | c.ports.push_back(usbOutHeadset); |
| 444 | c.connectedProfiles[usbOutHeadset.id] = standardPcmAudioProfiles; |
| 445 | |
| 446 | AudioPort usbInHeadset = |
| 447 | createPort(c.nextPortId++, "USB Headset In", 0, true, |
| 448 | createDeviceExt(AudioDeviceType::IN_HEADSET, 0, |
| 449 | AudioDeviceDescription::CONNECTION_USB)); |
| 450 | c.ports.push_back(usbInHeadset); |
| 451 | c.connectedProfiles[usbInHeadset.id] = standardPcmAudioProfiles; |
| 452 | |
| 453 | // Mix ports |
| 454 | |
| 455 | AudioPort usbHeadsetOutMix = |
| 456 | createPort(c.nextPortId++, "usb_headset output", 0, false, createPortMixExt(1, 1)); |
| 457 | c.ports.push_back(usbHeadsetOutMix); |
| 458 | |
| 459 | AudioPort usbHeadsetInMix = |
| 460 | createPort(c.nextPortId++, "usb_headset input", 0, true, createPortMixExt(1, 1)); |
| 461 | c.ports.push_back(usbHeadsetInMix); |
| 462 | |
| 463 | c.routes.push_back(createRoute({usbHeadsetOutMix}, usbOutHeadset)); |
| 464 | c.routes.push_back(createRoute({usbInHeadset}, usbHeadsetInMix)); |
| 465 | |
| 466 | return c; |
| 467 | }(); |
| 468 | return std::make_unique<Configuration>(configuration); |
| 469 | } |
| 470 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 471 | } // namespace aidl::android::hardware::audio::core::internal |