Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +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 | |
| 17 | #include <algorithm> |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 18 | #include <chrono> |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 19 | |
Mikhail Naganov | f84d640 | 2022-06-16 00:35:31 +0000 | [diff] [blame] | 20 | #include <aidl/android/media/audio/common/AudioIoFlags.h> |
| 21 | #include <aidl/android/media/audio/common/AudioOutputFlags.h> |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 22 | |
| 23 | #include "ModuleConfig.h" |
| 24 | |
| 25 | using namespace android; |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 26 | using namespace std::chrono_literals; |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 27 | |
Mikhail Naganov | f84d640 | 2022-06-16 00:35:31 +0000 | [diff] [blame] | 28 | using aidl::android::hardware::audio::core::IModule; |
| 29 | using aidl::android::media::audio::common::AudioChannelLayout; |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 30 | using aidl::android::media::audio::common::AudioEncapsulationMode; |
Mikhail Naganov | f84d640 | 2022-06-16 00:35:31 +0000 | [diff] [blame] | 31 | using aidl::android::media::audio::common::AudioFormatDescription; |
| 32 | using aidl::android::media::audio::common::AudioFormatType; |
| 33 | using aidl::android::media::audio::common::AudioIoFlags; |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 34 | using aidl::android::media::audio::common::AudioOffloadInfo; |
Mikhail Naganov | f84d640 | 2022-06-16 00:35:31 +0000 | [diff] [blame] | 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::AudioPortExt; |
| 39 | using aidl::android::media::audio::common::AudioProfile; |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 40 | using aidl::android::media::audio::common::AudioUsage; |
Mikhail Naganov | f84d640 | 2022-06-16 00:35:31 +0000 | [diff] [blame] | 41 | using aidl::android::media::audio::common::Int; |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 42 | |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 43 | // static |
| 44 | std::optional<AudioOffloadInfo> ModuleConfig::generateOffloadInfoIfNeeded( |
| 45 | const AudioPortConfig& portConfig) { |
| 46 | if (portConfig.flags.has_value() && |
| 47 | portConfig.flags.value().getTag() == AudioIoFlags::Tag::output && |
| 48 | (portConfig.flags.value().get<AudioIoFlags::Tag::output>() & |
| 49 | 1 << static_cast<int>(AudioOutputFlags::COMPRESS_OFFLOAD)) != 0) { |
| 50 | AudioOffloadInfo offloadInfo; |
| 51 | offloadInfo.base.sampleRate = portConfig.sampleRate.value().value; |
| 52 | offloadInfo.base.channelMask = portConfig.channelMask.value(); |
| 53 | offloadInfo.base.format = portConfig.format.value(); |
| 54 | offloadInfo.bitRatePerSecond = 256; // Arbitrary value. |
| 55 | offloadInfo.durationUs = std::chrono::microseconds(1min).count(); // Arbitrary value. |
| 56 | offloadInfo.usage = AudioUsage::MEDIA; |
| 57 | offloadInfo.encapsulationMode = AudioEncapsulationMode::NONE; |
| 58 | return offloadInfo; |
| 59 | } |
| 60 | return {}; |
| 61 | } |
| 62 | |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 63 | template <typename T> |
| 64 | auto findById(const std::vector<T>& v, int32_t id) { |
| 65 | return std::find_if(v.begin(), v.end(), [&](const auto& p) { return p.id == id; }); |
| 66 | } |
| 67 | |
| 68 | ModuleConfig::ModuleConfig(IModule* module) { |
| 69 | mStatus = module->getAudioPorts(&mPorts); |
| 70 | if (!mStatus.isOk()) return; |
| 71 | for (const auto& port : mPorts) { |
| 72 | if (port.ext.getTag() != AudioPortExt::Tag::device) continue; |
| 73 | const auto& devicePort = port.ext.get<AudioPortExt::Tag::device>(); |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 74 | if (devicePort.device.type.connection.empty()) { |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 75 | const bool isInput = port.flags.getTag() == AudioIoFlags::Tag::input; |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 76 | // Permanently attached device. |
| 77 | if (isInput) { |
| 78 | mAttachedSourceDevicePorts.insert(port.id); |
| 79 | } else { |
| 80 | mAttachedSinkDevicePorts.insert(port.id); |
| 81 | } |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 82 | } else if (port.profiles.empty()) { |
| 83 | mExternalDevicePorts.insert(port.id); |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | if (!mStatus.isOk()) return; |
| 87 | mStatus = module->getAudioRoutes(&mRoutes); |
| 88 | if (!mStatus.isOk()) return; |
| 89 | mStatus = module->getAudioPortConfigs(&mInitialConfigs); |
| 90 | } |
| 91 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 92 | std::vector<AudioPort> ModuleConfig::getAttachedDevicePorts() const { |
| 93 | std::vector<AudioPort> result; |
| 94 | std::copy_if(mPorts.begin(), mPorts.end(), std::back_inserter(result), [&](const auto& port) { |
| 95 | return mAttachedSinkDevicePorts.count(port.id) != 0 || |
| 96 | mAttachedSourceDevicePorts.count(port.id) != 0; |
| 97 | }); |
| 98 | return result; |
| 99 | } |
| 100 | |
| 101 | std::vector<AudioPort> ModuleConfig::getExternalDevicePorts() const { |
| 102 | std::vector<AudioPort> result; |
| 103 | std::copy_if(mPorts.begin(), mPorts.end(), std::back_inserter(result), |
| 104 | [&](const auto& port) { return mExternalDevicePorts.count(port.id) != 0; }); |
| 105 | return result; |
| 106 | } |
| 107 | |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 108 | std::vector<AudioPort> ModuleConfig::getInputMixPorts() const { |
| 109 | std::vector<AudioPort> result; |
| 110 | std::copy_if(mPorts.begin(), mPorts.end(), std::back_inserter(result), [](const auto& port) { |
| 111 | return port.ext.getTag() == AudioPortExt::Tag::mix && |
| 112 | port.flags.getTag() == AudioIoFlags::Tag::input; |
| 113 | }); |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | std::vector<AudioPort> ModuleConfig::getOutputMixPorts() const { |
| 118 | std::vector<AudioPort> result; |
| 119 | std::copy_if(mPorts.begin(), mPorts.end(), std::back_inserter(result), [](const auto& port) { |
| 120 | return port.ext.getTag() == AudioPortExt::Tag::mix && |
| 121 | port.flags.getTag() == AudioIoFlags::Tag::output; |
| 122 | }); |
| 123 | return result; |
| 124 | } |
| 125 | |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 126 | std::vector<AudioPort> ModuleConfig::getAttachedDevicesPortsForMixPort( |
| 127 | bool isInput, const AudioPortConfig& mixPortConfig) const { |
| 128 | const auto mixPortIt = findById<AudioPort>(mPorts, mixPortConfig.portId); |
| 129 | if (mixPortIt != mPorts.end()) { |
| 130 | return getAttachedDevicesPortsForMixPort(isInput, *mixPortIt); |
| 131 | } |
| 132 | return {}; |
| 133 | } |
| 134 | |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 135 | std::vector<AudioPort> ModuleConfig::getAttachedSinkDevicesPortsForMixPort( |
| 136 | const AudioPort& mixPort) const { |
| 137 | std::vector<AudioPort> result; |
| 138 | for (const auto& route : mRoutes) { |
| 139 | if (mAttachedSinkDevicePorts.count(route.sinkPortId) != 0 && |
| 140 | std::find(route.sourcePortIds.begin(), route.sourcePortIds.end(), mixPort.id) != |
| 141 | route.sourcePortIds.end()) { |
| 142 | const auto devicePortIt = findById<AudioPort>(mPorts, route.sinkPortId); |
| 143 | if (devicePortIt != mPorts.end()) result.push_back(*devicePortIt); |
| 144 | } |
| 145 | } |
| 146 | return result; |
| 147 | } |
| 148 | |
| 149 | std::vector<AudioPort> ModuleConfig::getAttachedSourceDevicesPortsForMixPort( |
| 150 | const AudioPort& mixPort) const { |
| 151 | std::vector<AudioPort> result; |
| 152 | for (const auto& route : mRoutes) { |
| 153 | if (route.sinkPortId == mixPort.id) { |
| 154 | for (const auto srcId : route.sourcePortIds) { |
| 155 | if (mAttachedSourceDevicePorts.count(srcId) != 0) { |
| 156 | const auto devicePortIt = findById<AudioPort>(mPorts, srcId); |
| 157 | if (devicePortIt != mPorts.end()) result.push_back(*devicePortIt); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | return result; |
| 163 | } |
| 164 | |
| 165 | std::optional<AudioPort> ModuleConfig::getSourceMixPortForAttachedDevice() const { |
| 166 | for (const auto& route : mRoutes) { |
| 167 | if (mAttachedSinkDevicePorts.count(route.sinkPortId) != 0) { |
| 168 | const auto mixPortIt = findById<AudioPort>(mPorts, route.sourcePortIds[0]); |
| 169 | if (mixPortIt != mPorts.end()) return *mixPortIt; |
| 170 | } |
| 171 | } |
| 172 | return {}; |
| 173 | } |
| 174 | |
| 175 | std::optional<ModuleConfig::SrcSinkPair> ModuleConfig::getNonRoutableSrcSinkPair( |
| 176 | bool isInput) const { |
| 177 | const auto mixPorts = getMixPorts(isInput); |
| 178 | std::set<std::pair<int32_t, int32_t>> allowedRoutes; |
| 179 | for (const auto& route : mRoutes) { |
| 180 | for (const auto srcPortId : route.sourcePortIds) { |
| 181 | allowedRoutes.emplace(std::make_pair(srcPortId, route.sinkPortId)); |
| 182 | } |
| 183 | } |
| 184 | auto make_pair = [isInput](auto& device, auto& mix) { |
| 185 | return isInput ? std::make_pair(device, mix) : std::make_pair(mix, device); |
| 186 | }; |
| 187 | for (const auto portId : isInput ? mAttachedSourceDevicePorts : mAttachedSinkDevicePorts) { |
| 188 | const auto devicePortIt = findById<AudioPort>(mPorts, portId); |
| 189 | if (devicePortIt == mPorts.end()) continue; |
| 190 | auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt); |
| 191 | for (const auto& mixPort : mixPorts) { |
| 192 | if (std::find(allowedRoutes.begin(), allowedRoutes.end(), |
| 193 | make_pair(portId, mixPort.id)) == allowedRoutes.end()) { |
| 194 | auto mixPortConfig = getSingleConfigForMixPort(isInput, mixPort); |
| 195 | if (mixPortConfig.has_value()) { |
| 196 | return make_pair(devicePortConfig, mixPortConfig.value()); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | return {}; |
| 202 | } |
| 203 | |
| 204 | std::optional<ModuleConfig::SrcSinkPair> ModuleConfig::getRoutableSrcSinkPair(bool isInput) const { |
| 205 | if (isInput) { |
| 206 | for (const auto& route : mRoutes) { |
| 207 | auto srcPortIdIt = std::find_if( |
| 208 | route.sourcePortIds.begin(), route.sourcePortIds.end(), |
| 209 | [&](const auto& portId) { return mAttachedSourceDevicePorts.count(portId); }); |
| 210 | if (srcPortIdIt == route.sourcePortIds.end()) continue; |
| 211 | const auto devicePortIt = findById<AudioPort>(mPorts, *srcPortIdIt); |
| 212 | const auto mixPortIt = findById<AudioPort>(mPorts, route.sinkPortId); |
| 213 | if (devicePortIt == mPorts.end() || mixPortIt == mPorts.end()) continue; |
| 214 | auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt); |
| 215 | auto mixPortConfig = getSingleConfigForMixPort(isInput, *mixPortIt); |
| 216 | if (!mixPortConfig.has_value()) continue; |
| 217 | return std::make_pair(devicePortConfig, mixPortConfig.value()); |
| 218 | } |
| 219 | } else { |
| 220 | for (const auto& route : mRoutes) { |
| 221 | if (mAttachedSinkDevicePorts.count(route.sinkPortId) == 0) continue; |
| 222 | const auto mixPortIt = findById<AudioPort>(mPorts, route.sourcePortIds[0]); |
| 223 | const auto devicePortIt = findById<AudioPort>(mPorts, route.sinkPortId); |
| 224 | if (devicePortIt == mPorts.end() || mixPortIt == mPorts.end()) continue; |
| 225 | auto mixPortConfig = getSingleConfigForMixPort(isInput, *mixPortIt); |
| 226 | auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt); |
| 227 | if (!mixPortConfig.has_value()) continue; |
| 228 | return std::make_pair(mixPortConfig.value(), devicePortConfig); |
| 229 | } |
| 230 | } |
| 231 | return {}; |
| 232 | } |
| 233 | |
| 234 | std::vector<ModuleConfig::SrcSinkGroup> ModuleConfig::getRoutableSrcSinkGroups(bool isInput) const { |
| 235 | std::vector<SrcSinkGroup> result; |
| 236 | if (isInput) { |
| 237 | for (const auto& route : mRoutes) { |
| 238 | std::vector<int32_t> srcPortIds; |
| 239 | std::copy_if(route.sourcePortIds.begin(), route.sourcePortIds.end(), |
| 240 | std::back_inserter(srcPortIds), [&](const auto& portId) { |
| 241 | return mAttachedSourceDevicePorts.count(portId); |
| 242 | }); |
| 243 | if (srcPortIds.empty()) continue; |
| 244 | const auto mixPortIt = findById<AudioPort>(mPorts, route.sinkPortId); |
| 245 | if (mixPortIt == mPorts.end()) continue; |
| 246 | auto mixPortConfig = getSingleConfigForMixPort(isInput, *mixPortIt); |
| 247 | if (!mixPortConfig.has_value()) continue; |
| 248 | std::vector<SrcSinkPair> pairs; |
| 249 | for (const auto srcPortId : srcPortIds) { |
| 250 | const auto devicePortIt = findById<AudioPort>(mPorts, srcPortId); |
| 251 | if (devicePortIt == mPorts.end()) continue; |
| 252 | // Using all configs for every source would be too much. |
| 253 | auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt); |
| 254 | pairs.emplace_back(devicePortConfig, mixPortConfig.value()); |
| 255 | } |
| 256 | if (!pairs.empty()) { |
| 257 | result.emplace_back(route, std::move(pairs)); |
| 258 | } |
| 259 | } |
| 260 | } else { |
| 261 | for (const auto& route : mRoutes) { |
| 262 | if (mAttachedSinkDevicePorts.count(route.sinkPortId) == 0) continue; |
| 263 | const auto devicePortIt = findById<AudioPort>(mPorts, route.sinkPortId); |
| 264 | if (devicePortIt == mPorts.end()) continue; |
| 265 | auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt); |
| 266 | std::vector<SrcSinkPair> pairs; |
| 267 | for (const auto srcPortId : route.sourcePortIds) { |
| 268 | const auto mixPortIt = findById<AudioPort>(mPorts, srcPortId); |
| 269 | if (mixPortIt == mPorts.end()) continue; |
| 270 | // Using all configs for every source would be too much. |
| 271 | auto mixPortConfig = getSingleConfigForMixPort(isInput, *mixPortIt); |
| 272 | if (mixPortConfig.has_value()) { |
| 273 | pairs.emplace_back(mixPortConfig.value(), devicePortConfig); |
| 274 | } |
| 275 | } |
| 276 | if (!pairs.empty()) { |
| 277 | result.emplace_back(route, std::move(pairs)); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | return result; |
| 282 | } |
| 283 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 284 | std::string ModuleConfig::toString() const { |
| 285 | std::string result; |
| 286 | result.append("Ports: "); |
| 287 | result.append(android::internal::ToString(mPorts)); |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 288 | result.append("\nInitial configs: "); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 289 | result.append(android::internal::ToString(mInitialConfigs)); |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 290 | result.append("\nAttached sink device ports: "); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 291 | result.append(android::internal::ToString(mAttachedSinkDevicePorts)); |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 292 | result.append("\nAttached source device ports: "); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 293 | result.append(android::internal::ToString(mAttachedSourceDevicePorts)); |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 294 | result.append("\nExternal device ports: "); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 295 | result.append(android::internal::ToString(mExternalDevicePorts)); |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 296 | result.append("\nRoutes: "); |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 297 | result.append(android::internal::ToString(mRoutes)); |
| 298 | return result; |
| 299 | } |
| 300 | |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 301 | static size_t combineAudioConfigs(const AudioPort& port, const AudioProfile& profile, |
| 302 | std::vector<AudioPortConfig>* result) { |
| 303 | const size_t newConfigCount = profile.channelMasks.size() * profile.sampleRates.size(); |
| 304 | result->reserve(result->capacity() + newConfigCount); |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 305 | for (auto channelMask : profile.channelMasks) { |
| 306 | for (auto sampleRate : profile.sampleRates) { |
| 307 | AudioPortConfig config{}; |
| 308 | config.portId = port.id; |
| 309 | Int sr; |
| 310 | sr.value = sampleRate; |
| 311 | config.sampleRate = sr; |
| 312 | config.channelMask = channelMask; |
| 313 | config.format = profile.format; |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 314 | config.flags = port.flags; |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 315 | config.ext = port.ext; |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 316 | result->push_back(std::move(config)); |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 319 | return newConfigCount; |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 322 | static bool isDynamicProfile(const AudioProfile& profile) { |
| 323 | return (profile.format.type == AudioFormatType::DEFAULT && profile.format.encoding.empty()) || |
| 324 | profile.sampleRates.empty() || profile.channelMasks.empty(); |
| 325 | } |
| 326 | |
| 327 | std::vector<AudioPortConfig> ModuleConfig::generateAudioMixPortConfigs( |
| 328 | const std::vector<AudioPort>& ports, bool isInput, bool singleProfile) const { |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 329 | std::vector<AudioPortConfig> result; |
| 330 | for (const auto& mixPort : ports) { |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 331 | if (getAttachedDevicesPortsForMixPort(isInput, mixPort).empty()) { |
| 332 | continue; |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 333 | } |
| 334 | for (const auto& profile : mixPort.profiles) { |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 335 | if (isDynamicProfile(profile)) continue; |
| 336 | combineAudioConfigs(mixPort, profile, &result); |
| 337 | if (singleProfile && !result.empty()) { |
| 338 | result.resize(1); |
| 339 | return result; |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | } |
| 343 | return result; |
| 344 | } |
| 345 | |
| 346 | std::vector<AudioPortConfig> ModuleConfig::generateAudioDevicePortConfigs( |
| 347 | const std::vector<AudioPort>& ports, bool singleProfile) const { |
| 348 | std::vector<AudioPortConfig> result; |
| 349 | for (const auto& devicePort : ports) { |
| 350 | const size_t resultSizeBefore = result.size(); |
| 351 | for (const auto& profile : devicePort.profiles) { |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 352 | combineAudioConfigs(devicePort, profile, &result); |
| 353 | if (singleProfile && !result.empty()) { |
| 354 | result.resize(1); |
| 355 | return result; |
| 356 | } |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 357 | } |
| 358 | if (resultSizeBefore == result.size()) { |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 359 | std::copy_if(mInitialConfigs.begin(), mInitialConfigs.end(), std::back_inserter(result), |
| 360 | [&](const auto& config) { return config.portId == devicePort.id; }); |
| 361 | if (resultSizeBefore == result.size()) { |
| 362 | AudioPortConfig empty; |
| 363 | empty.portId = devicePort.id; |
| 364 | empty.ext = devicePort.ext; |
| 365 | result.push_back(empty); |
| 366 | } |
Mikhail Naganov | e5d747e | 2021-11-16 01:31:03 +0000 | [diff] [blame] | 367 | } |
| 368 | if (singleProfile) return result; |
| 369 | } |
| 370 | return result; |
| 371 | } |