Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [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 | #define LOG_TAG "Hal2AidlMapper" |
| 18 | // #define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <algorithm> |
| 21 | |
| 22 | #include <media/audiohal/StreamHalInterface.h> |
| 23 | #include <error/expected_utils.h> |
| 24 | #include <system/audio.h> // For AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS |
| 25 | #include <Utils.h> |
| 26 | #include <utils/Log.h> |
| 27 | |
| 28 | #include "Hal2AidlMapper.h" |
| 29 | |
| 30 | using aidl::android::aidl_utils::statusTFromBinderStatus; |
| 31 | using aidl::android::media::audio::common::AudioChannelLayout; |
| 32 | using aidl::android::media::audio::common::AudioConfig; |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 33 | using aidl::android::media::audio::common::AudioConfigBase; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 34 | using aidl::android::media::audio::common::AudioDevice; |
| 35 | using aidl::android::media::audio::common::AudioDeviceAddress; |
| 36 | using aidl::android::media::audio::common::AudioDeviceDescription; |
| 37 | using aidl::android::media::audio::common::AudioDeviceType; |
| 38 | using aidl::android::media::audio::common::AudioFormatDescription; |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 39 | using aidl::android::media::audio::common::AudioFormatType; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 40 | using aidl::android::media::audio::common::AudioInputFlags; |
| 41 | using aidl::android::media::audio::common::AudioIoFlags; |
| 42 | using aidl::android::media::audio::common::AudioOutputFlags; |
| 43 | using aidl::android::media::audio::common::AudioPort; |
| 44 | using aidl::android::media::audio::common::AudioPortConfig; |
| 45 | using aidl::android::media::audio::common::AudioPortDeviceExt; |
| 46 | using aidl::android::media::audio::common::AudioPortExt; |
| 47 | using aidl::android::media::audio::common::AudioPortMixExt; |
| 48 | using aidl::android::media::audio::common::AudioPortMixExtUseCase; |
| 49 | using aidl::android::media::audio::common::AudioProfile; |
| 50 | using aidl::android::media::audio::common::AudioSource; |
| 51 | using aidl::android::media::audio::common::Int; |
| 52 | using aidl::android::hardware::audio::common::isBitPositionFlagSet; |
| 53 | using aidl::android::hardware::audio::common::isDefaultAudioFormat; |
| 54 | using aidl::android::hardware::audio::common::makeBitPositionFlagMask; |
| 55 | using aidl::android::hardware::audio::core::AudioPatch; |
| 56 | using aidl::android::hardware::audio::core::AudioRoute; |
| 57 | using aidl::android::hardware::audio::core::IModule; |
| 58 | |
| 59 | namespace android { |
| 60 | |
| 61 | namespace { |
| 62 | |
| 63 | bool isConfigEqualToPortConfig(const AudioConfig& config, const AudioPortConfig& portConfig) { |
| 64 | return portConfig.sampleRate.value().value == config.base.sampleRate && |
| 65 | portConfig.channelMask.value() == config.base.channelMask && |
| 66 | portConfig.format.value() == config.base.format; |
| 67 | } |
| 68 | |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 69 | AudioConfig* setConfigFromPortConfig(AudioConfig* config, const AudioPortConfig& portConfig) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 70 | config->base.sampleRate = portConfig.sampleRate.value().value; |
| 71 | config->base.channelMask = portConfig.channelMask.value(); |
| 72 | config->base.format = portConfig.format.value(); |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 73 | return config; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void setPortConfigFromConfig(AudioPortConfig* portConfig, const AudioConfig& config) { |
| 77 | if (config.base.sampleRate != 0) { |
| 78 | portConfig->sampleRate = Int{ .value = config.base.sampleRate }; |
| 79 | } |
| 80 | if (config.base.channelMask != AudioChannelLayout{}) { |
| 81 | portConfig->channelMask = config.base.channelMask; |
| 82 | } |
| 83 | if (config.base.format != AudioFormatDescription{}) { |
| 84 | portConfig->format = config.base.format; |
| 85 | } |
| 86 | } |
| 87 | |
jiabin | 8079700 | 2023-12-01 22:02:41 +0000 | [diff] [blame] | 88 | bool containHapticChannel(AudioChannelLayout channel) { |
| 89 | return channel.getTag() == AudioChannelLayout::Tag::layoutMask && |
| 90 | ((channel.get<AudioChannelLayout::Tag::layoutMask>() |
| 91 | & AudioChannelLayout::CHANNEL_HAPTIC_A) |
| 92 | == AudioChannelLayout::CHANNEL_HAPTIC_A || |
| 93 | (channel.get<AudioChannelLayout::Tag::layoutMask>() |
| 94 | & AudioChannelLayout::CHANNEL_HAPTIC_B) |
| 95 | == AudioChannelLayout::CHANNEL_HAPTIC_B); |
| 96 | } |
| 97 | |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 98 | } // namespace |
| 99 | |
| 100 | Hal2AidlMapper::Hal2AidlMapper(const std::string& instance, const std::shared_ptr<IModule>& module) |
| 101 | : mInstance(instance), mModule(module) { |
| 102 | } |
| 103 | |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 104 | void Hal2AidlMapper::addStream( |
| 105 | const sp<StreamHalInterface>& stream, int32_t portConfigId, int32_t patchId) { |
| 106 | mStreams.insert(std::pair(stream, std::pair(portConfigId, patchId))); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | bool Hal2AidlMapper::audioDeviceMatches(const AudioDevice& device, const AudioPort& p) { |
| 110 | if (p.ext.getTag() != AudioPortExt::Tag::device) return false; |
| 111 | return p.ext.get<AudioPortExt::Tag::device>().device == device; |
| 112 | } |
| 113 | |
| 114 | bool Hal2AidlMapper::audioDeviceMatches(const AudioDevice& device, const AudioPortConfig& p) { |
| 115 | if (p.ext.getTag() != AudioPortExt::Tag::device) return false; |
| 116 | if (device.type.type == AudioDeviceType::IN_DEFAULT) { |
| 117 | return p.portId == mDefaultInputPortId; |
| 118 | } else if (device.type.type == AudioDeviceType::OUT_DEFAULT) { |
| 119 | return p.portId == mDefaultOutputPortId; |
| 120 | } |
| 121 | return p.ext.get<AudioPortExt::Tag::device>().device == device; |
| 122 | } |
| 123 | |
| 124 | status_t Hal2AidlMapper::createOrUpdatePatch( |
| 125 | const std::vector<AudioPortConfig>& sources, |
| 126 | const std::vector<AudioPortConfig>& sinks, |
| 127 | int32_t* patchId, Cleanups* cleanups) { |
| 128 | auto existingPatchIt = *patchId != 0 ? mPatches.find(*patchId): mPatches.end(); |
| 129 | AudioPatch patch; |
| 130 | if (existingPatchIt != mPatches.end()) { |
| 131 | patch = existingPatchIt->second; |
| 132 | patch.sourcePortConfigIds.clear(); |
| 133 | patch.sinkPortConfigIds.clear(); |
| 134 | } |
| 135 | // The IDs will be found by 'fillPortConfigs', however the original 'sources' and |
| 136 | // 'sinks' will not be updated because 'setAudioPatch' only needs IDs. Here we log |
| 137 | // the source arguments, where only the audio configuration and device specifications |
| 138 | // are relevant. |
| 139 | ALOGD("%s: [disregard IDs] sources: %s, sinks: %s", |
| 140 | __func__, ::android::internal::ToString(sources).c_str(), |
| 141 | ::android::internal::ToString(sinks).c_str()); |
| 142 | auto fillPortConfigs = [&]( |
| 143 | const std::vector<AudioPortConfig>& configs, |
| 144 | const std::set<int32_t>& destinationPortIds, |
| 145 | std::vector<int32_t>* ids, std::set<int32_t>* portIds) -> status_t { |
| 146 | for (const auto& s : configs) { |
| 147 | AudioPortConfig portConfig; |
Mikhail Naganov | 38220af | 2023-12-07 14:00:48 -0800 | [diff] [blame^] | 148 | if (status_t status = setPortConfig( |
| 149 | s, destinationPortIds, &portConfig, cleanups); status != OK) { |
| 150 | if (s.ext.getTag() == AudioPortExt::mix) { |
| 151 | // See b/315528763. Despite that the framework knows the actual format of |
| 152 | // the mix port, it still uses the original format. Luckily, there is |
| 153 | // the I/O handle which can be used to find the mix port. |
| 154 | ALOGI("fillPortConfigs: retrying to find a mix port config with default " |
| 155 | "configuration"); |
| 156 | if (auto it = findPortConfig(std::nullopt, s.flags, |
| 157 | s.ext.get<AudioPortExt::mix>().handle); |
| 158 | it != mPortConfigs.end()) { |
| 159 | portConfig = it->second; |
| 160 | } else { |
| 161 | const std::string flags = s.flags.has_value() ? |
| 162 | s.flags->toString() : "<unspecified>"; |
| 163 | ALOGE("fillPortConfigs: existing port config for flags %s, handle %d " |
| 164 | "not found in module %s", flags.c_str(), |
| 165 | s.ext.get<AudioPortExt::mix>().handle, mInstance.c_str()); |
| 166 | return BAD_VALUE; |
| 167 | } |
| 168 | } else { |
| 169 | return status; |
| 170 | } |
| 171 | } |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 172 | LOG_ALWAYS_FATAL_IF(portConfig.id == 0, |
| 173 | "fillPortConfigs: initial config: %s, port config: %s", |
| 174 | s.toString().c_str(), portConfig.toString().c_str()); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 175 | ids->push_back(portConfig.id); |
| 176 | if (portIds != nullptr) { |
| 177 | portIds->insert(portConfig.portId); |
| 178 | } |
| 179 | } |
| 180 | return OK; |
| 181 | }; |
| 182 | // When looking up port configs, the destinationPortId is only used for mix ports. |
| 183 | // Thus, we process device port configs first, and look up the destination port ID from them. |
| 184 | bool sourceIsDevice = std::any_of(sources.begin(), sources.end(), |
| 185 | [](const auto& config) { return config.ext.getTag() == AudioPortExt::device; }); |
| 186 | const std::vector<AudioPortConfig>& devicePortConfigs = |
| 187 | sourceIsDevice ? sources : sinks; |
| 188 | std::vector<int32_t>* devicePortConfigIds = |
| 189 | sourceIsDevice ? &patch.sourcePortConfigIds : &patch.sinkPortConfigIds; |
| 190 | const std::vector<AudioPortConfig>& mixPortConfigs = |
| 191 | sourceIsDevice ? sinks : sources; |
| 192 | std::vector<int32_t>* mixPortConfigIds = |
| 193 | sourceIsDevice ? &patch.sinkPortConfigIds : &patch.sourcePortConfigIds; |
| 194 | std::set<int32_t> devicePortIds; |
| 195 | RETURN_STATUS_IF_ERROR(fillPortConfigs( |
| 196 | devicePortConfigs, std::set<int32_t>(), devicePortConfigIds, &devicePortIds)); |
| 197 | RETURN_STATUS_IF_ERROR(fillPortConfigs( |
| 198 | mixPortConfigs, devicePortIds, mixPortConfigIds, nullptr)); |
| 199 | if (existingPatchIt != mPatches.end()) { |
| 200 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 201 | mModule->setAudioPatch(patch, &patch))); |
| 202 | existingPatchIt->second = patch; |
| 203 | } else { |
| 204 | bool created = false; |
| 205 | RETURN_STATUS_IF_ERROR(findOrCreatePatch(patch, &patch, &created)); |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 206 | // No cleanup of the patch is needed, it is managed by the framework. |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 207 | *patchId = patch.id; |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 208 | if (!created) { |
| 209 | // The framework might have "created" a patch which already existed due to |
| 210 | // stream creation. Need to release the ownership from the stream. |
| 211 | for (auto& s : mStreams) { |
| 212 | if (s.second.second == patch.id) s.second.second = -1; |
| 213 | } |
| 214 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 215 | } |
| 216 | return OK; |
| 217 | } |
| 218 | |
| 219 | status_t Hal2AidlMapper::createOrUpdatePortConfig( |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 220 | const AudioPortConfig& requestedPortConfig, AudioPortConfig* result, bool* created) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 221 | bool applied = false; |
| 222 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->setAudioPortConfig( |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 223 | requestedPortConfig, result, &applied))); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 224 | if (!applied) { |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 225 | result->id = 0; |
| 226 | *created = false; |
| 227 | return OK; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 230 | int32_t id = result->id; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 231 | if (requestedPortConfig.id != 0 && requestedPortConfig.id != id) { |
| 232 | LOG_ALWAYS_FATAL("%s: requested port config id %d changed to %d", __func__, |
| 233 | requestedPortConfig.id, id); |
| 234 | } |
| 235 | |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 236 | auto [_, inserted] = mPortConfigs.insert_or_assign(id, *result); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 237 | *created = inserted; |
| 238 | return OK; |
| 239 | } |
| 240 | |
| 241 | void Hal2AidlMapper::eraseConnectedPort(int32_t portId) { |
| 242 | mPorts.erase(portId); |
| 243 | mConnectedPorts.erase(portId); |
| 244 | if (mDisconnectedPortReplacement.first == portId) { |
| 245 | const auto& port = mDisconnectedPortReplacement.second; |
| 246 | mPorts.insert(std::make_pair(port.id, port)); |
| 247 | ALOGD("%s: disconnected port replacement: %s", __func__, port.toString().c_str()); |
| 248 | mDisconnectedPortReplacement = std::pair<int32_t, AudioPort>(); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | status_t Hal2AidlMapper::findOrCreatePatch( |
| 253 | const AudioPatch& requestedPatch, AudioPatch* patch, bool* created) { |
| 254 | std::set<int32_t> sourcePortConfigIds(requestedPatch.sourcePortConfigIds.begin(), |
| 255 | requestedPatch.sourcePortConfigIds.end()); |
| 256 | std::set<int32_t> sinkPortConfigIds(requestedPatch.sinkPortConfigIds.begin(), |
| 257 | requestedPatch.sinkPortConfigIds.end()); |
| 258 | return findOrCreatePatch(sourcePortConfigIds, sinkPortConfigIds, patch, created); |
| 259 | } |
| 260 | |
| 261 | status_t Hal2AidlMapper::findOrCreatePatch( |
| 262 | const std::set<int32_t>& sourcePortConfigIds, const std::set<int32_t>& sinkPortConfigIds, |
| 263 | AudioPatch* patch, bool* created) { |
| 264 | auto patchIt = findPatch(sourcePortConfigIds, sinkPortConfigIds); |
| 265 | if (patchIt == mPatches.end()) { |
| 266 | AudioPatch requestedPatch, appliedPatch; |
| 267 | requestedPatch.sourcePortConfigIds.insert(requestedPatch.sourcePortConfigIds.end(), |
| 268 | sourcePortConfigIds.begin(), sourcePortConfigIds.end()); |
| 269 | requestedPatch.sinkPortConfigIds.insert(requestedPatch.sinkPortConfigIds.end(), |
| 270 | sinkPortConfigIds.begin(), sinkPortConfigIds.end()); |
| 271 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->setAudioPatch( |
| 272 | requestedPatch, &appliedPatch))); |
| 273 | patchIt = mPatches.insert(mPatches.end(), std::make_pair(appliedPatch.id, appliedPatch)); |
| 274 | *created = true; |
| 275 | } else { |
| 276 | *created = false; |
| 277 | } |
| 278 | *patch = patchIt->second; |
| 279 | return OK; |
| 280 | } |
| 281 | |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 282 | status_t Hal2AidlMapper::findOrCreateDevicePortConfig( |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 283 | const AudioDevice& device, const AudioConfig* config, AudioPortConfig* portConfig, |
| 284 | bool* created) { |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 285 | if (auto portConfigIt = findPortConfig(device); portConfigIt == mPortConfigs.end()) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 286 | auto portsIt = findPort(device); |
| 287 | if (portsIt == mPorts.end()) { |
| 288 | ALOGE("%s: device port for device %s is not found in the module %s", |
| 289 | __func__, device.toString().c_str(), mInstance.c_str()); |
| 290 | return BAD_VALUE; |
| 291 | } |
| 292 | AudioPortConfig requestedPortConfig; |
| 293 | requestedPortConfig.portId = portsIt->first; |
| 294 | if (config != nullptr) { |
| 295 | setPortConfigFromConfig(&requestedPortConfig, *config); |
| 296 | } |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 297 | AudioPortConfig suggestedOrAppliedPortConfig; |
| 298 | RETURN_STATUS_IF_ERROR(createOrUpdatePortConfig(requestedPortConfig, |
| 299 | &suggestedOrAppliedPortConfig, created)); |
| 300 | if (suggestedOrAppliedPortConfig.id == 0) { |
| 301 | // Try again with the suggested config |
| 302 | suggestedOrAppliedPortConfig.id = requestedPortConfig.id; |
| 303 | AudioPortConfig appliedPortConfig; |
| 304 | RETURN_STATUS_IF_ERROR(createOrUpdatePortConfig(suggestedOrAppliedPortConfig, |
| 305 | &appliedPortConfig, created)); |
| 306 | if (appliedPortConfig.id == 0) { |
| 307 | ALOGE("%s: module %s did not apply suggested config %s", __func__, |
| 308 | mInstance.c_str(), suggestedOrAppliedPortConfig.toString().c_str()); |
| 309 | return NO_INIT; |
| 310 | } |
| 311 | *portConfig = appliedPortConfig; |
| 312 | } else { |
| 313 | *portConfig = suggestedOrAppliedPortConfig; |
| 314 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 315 | } else { |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 316 | *portConfig = portConfigIt->second; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 317 | *created = false; |
| 318 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 319 | return OK; |
| 320 | } |
| 321 | |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 322 | status_t Hal2AidlMapper::findOrCreateMixPortConfig( |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 323 | const AudioConfig& config, const std::optional<AudioIoFlags>& flags, int32_t ioHandle, |
| 324 | AudioSource source, const std::set<int32_t>& destinationPortIds, |
| 325 | AudioPortConfig* portConfig, bool* created) { |
| 326 | // These flags get removed one by one in this order when retrying port finding. |
| 327 | static const std::vector<AudioInputFlags> kOptionalInputFlags{ |
| 328 | AudioInputFlags::FAST, AudioInputFlags::RAW, AudioInputFlags::VOIP_TX }; |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 329 | if (auto portConfigIt = findPortConfig(config, flags, ioHandle); |
| 330 | portConfigIt == mPortConfigs.end() && flags.has_value()) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 331 | auto optionalInputFlagsIt = kOptionalInputFlags.begin(); |
| 332 | AudioIoFlags matchFlags = flags.value(); |
| 333 | auto portsIt = findPort(config, matchFlags, destinationPortIds); |
| 334 | while (portsIt == mPorts.end() && matchFlags.getTag() == AudioIoFlags::Tag::input |
| 335 | && optionalInputFlagsIt != kOptionalInputFlags.end()) { |
| 336 | if (!isBitPositionFlagSet( |
| 337 | matchFlags.get<AudioIoFlags::Tag::input>(), *optionalInputFlagsIt)) { |
| 338 | ++optionalInputFlagsIt; |
| 339 | continue; |
| 340 | } |
| 341 | matchFlags.set<AudioIoFlags::Tag::input>(matchFlags.get<AudioIoFlags::Tag::input>() & |
| 342 | ~makeBitPositionFlagMask(*optionalInputFlagsIt++)); |
| 343 | portsIt = findPort(config, matchFlags, destinationPortIds); |
| 344 | ALOGI("%s: mix port for config %s, flags %s was not found in the module %s, " |
| 345 | "retried with flags %s", __func__, config.toString().c_str(), |
| 346 | flags.value().toString().c_str(), mInstance.c_str(), |
| 347 | matchFlags.toString().c_str()); |
| 348 | } |
| 349 | if (portsIt == mPorts.end()) { |
| 350 | ALOGE("%s: mix port for config %s, flags %s is not found in the module %s", |
| 351 | __func__, config.toString().c_str(), matchFlags.toString().c_str(), |
| 352 | mInstance.c_str()); |
| 353 | return BAD_VALUE; |
| 354 | } |
| 355 | AudioPortConfig requestedPortConfig; |
| 356 | requestedPortConfig.portId = portsIt->first; |
| 357 | setPortConfigFromConfig(&requestedPortConfig, config); |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 358 | requestedPortConfig.flags = portsIt->second.flags; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 359 | requestedPortConfig.ext = AudioPortMixExt{ .handle = ioHandle }; |
| 360 | if (matchFlags.getTag() == AudioIoFlags::Tag::input |
| 361 | && source != AudioSource::SYS_RESERVED_INVALID) { |
| 362 | requestedPortConfig.ext.get<AudioPortExt::Tag::mix>().usecase = |
| 363 | AudioPortMixExtUseCase::make<AudioPortMixExtUseCase::Tag::source>(source); |
| 364 | } |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 365 | return createOrUpdatePortConfig(requestedPortConfig, portConfig, created); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 366 | } else if (portConfigIt == mPortConfigs.end() && !flags.has_value()) { |
| 367 | ALOGW("%s: mix port config for %s, handle %d not found in the module %s, " |
| 368 | "and was not created as flags are not specified", |
| 369 | __func__, config.toString().c_str(), ioHandle, mInstance.c_str()); |
| 370 | return BAD_VALUE; |
| 371 | } else { |
| 372 | AudioPortConfig requestedPortConfig = portConfigIt->second; |
| 373 | if (requestedPortConfig.ext.getTag() == AudioPortExt::Tag::mix) { |
| 374 | AudioPortMixExt& mixExt = requestedPortConfig.ext.get<AudioPortExt::Tag::mix>(); |
| 375 | if (mixExt.usecase.getTag() == AudioPortMixExtUseCase::Tag::source && |
| 376 | source != AudioSource::SYS_RESERVED_INVALID) { |
| 377 | mixExt.usecase.get<AudioPortMixExtUseCase::Tag::source>() = source; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if (requestedPortConfig != portConfigIt->second) { |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 382 | return createOrUpdatePortConfig(requestedPortConfig, portConfig, created); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 383 | } else { |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 384 | *portConfig = portConfigIt->second; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 385 | *created = false; |
| 386 | } |
| 387 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 388 | return OK; |
| 389 | } |
| 390 | |
| 391 | status_t Hal2AidlMapper::findOrCreatePortConfig( |
| 392 | const AudioPortConfig& requestedPortConfig, const std::set<int32_t>& destinationPortIds, |
| 393 | AudioPortConfig* portConfig, bool* created) { |
| 394 | using Tag = AudioPortExt::Tag; |
| 395 | if (requestedPortConfig.ext.getTag() == Tag::mix) { |
| 396 | if (const auto& p = requestedPortConfig; |
| 397 | !p.sampleRate.has_value() || !p.channelMask.has_value() || |
| 398 | !p.format.has_value()) { |
| 399 | ALOGW("%s: provided mix port config is not fully specified: %s", |
| 400 | __func__, p.toString().c_str()); |
| 401 | return BAD_VALUE; |
| 402 | } |
| 403 | AudioConfig config; |
| 404 | setConfigFromPortConfig(&config, requestedPortConfig); |
| 405 | AudioSource source = requestedPortConfig.ext.get<Tag::mix>().usecase.getTag() == |
| 406 | AudioPortMixExtUseCase::Tag::source ? |
| 407 | requestedPortConfig.ext.get<Tag::mix>().usecase. |
| 408 | get<AudioPortMixExtUseCase::Tag::source>() : AudioSource::SYS_RESERVED_INVALID; |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 409 | return findOrCreateMixPortConfig(config, requestedPortConfig.flags, |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 410 | requestedPortConfig.ext.get<Tag::mix>().handle, source, destinationPortIds, |
| 411 | portConfig, created); |
| 412 | } else if (requestedPortConfig.ext.getTag() == Tag::device) { |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 413 | return findOrCreateDevicePortConfig( |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 414 | requestedPortConfig.ext.get<Tag::device>().device, nullptr /*config*/, |
| 415 | portConfig, created); |
| 416 | } |
| 417 | ALOGW("%s: unsupported audio port config: %s", |
| 418 | __func__, requestedPortConfig.toString().c_str()); |
| 419 | return BAD_VALUE; |
| 420 | } |
| 421 | |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 422 | status_t Hal2AidlMapper::findPortConfig(const AudioDevice& device, AudioPortConfig* portConfig) { |
| 423 | if (auto it = findPortConfig(device); it != mPortConfigs.end()) { |
| 424 | *portConfig = it->second; |
| 425 | return OK; |
| 426 | } |
| 427 | ALOGE("%s: could not find a configured device port for device %s", |
| 428 | __func__, device.toString().c_str()); |
| 429 | return BAD_VALUE; |
| 430 | } |
| 431 | |
| 432 | Hal2AidlMapper::Patches::iterator Hal2AidlMapper::findPatch( |
| 433 | const std::set<int32_t>& sourcePortConfigIds, const std::set<int32_t>& sinkPortConfigIds) { |
| 434 | return std::find_if(mPatches.begin(), mPatches.end(), |
| 435 | [&](const auto& pair) { |
| 436 | const auto& p = pair.second; |
| 437 | std::set<int32_t> patchSrcs( |
| 438 | p.sourcePortConfigIds.begin(), p.sourcePortConfigIds.end()); |
| 439 | std::set<int32_t> patchSinks( |
| 440 | p.sinkPortConfigIds.begin(), p.sinkPortConfigIds.end()); |
| 441 | return sourcePortConfigIds == patchSrcs && sinkPortConfigIds == patchSinks; }); |
| 442 | } |
| 443 | |
| 444 | Hal2AidlMapper::Ports::iterator Hal2AidlMapper::findPort(const AudioDevice& device) { |
| 445 | if (device.type.type == AudioDeviceType::IN_DEFAULT) { |
| 446 | return mPorts.find(mDefaultInputPortId); |
| 447 | } else if (device.type.type == AudioDeviceType::OUT_DEFAULT) { |
| 448 | return mPorts.find(mDefaultOutputPortId); |
| 449 | } |
| 450 | if (device.address.getTag() != AudioDeviceAddress::id || |
| 451 | !device.address.get<AudioDeviceAddress::id>().empty()) { |
| 452 | return std::find_if(mPorts.begin(), mPorts.end(), |
| 453 | [&](const auto& pair) { return audioDeviceMatches(device, pair.second); }); |
| 454 | } |
| 455 | // For connection w/o an address, two ports can be found: the template port, |
| 456 | // and a connected port (if exists). Make sure we return the connected port. |
| 457 | Hal2AidlMapper::Ports::iterator portIt = mPorts.end(); |
| 458 | for (auto it = mPorts.begin(); it != mPorts.end(); ++it) { |
| 459 | if (audioDeviceMatches(device, it->second)) { |
| 460 | if (mConnectedPorts.find(it->first) != mConnectedPorts.end()) { |
| 461 | return it; |
| 462 | } else { |
| 463 | // Will return 'it' if there is no connected port. |
| 464 | portIt = it; |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | return portIt; |
| 469 | } |
| 470 | |
| 471 | Hal2AidlMapper::Ports::iterator Hal2AidlMapper::findPort( |
| 472 | const AudioConfig& config, const AudioIoFlags& flags, |
| 473 | const std::set<int32_t>& destinationPortIds) { |
jiabin | 8079700 | 2023-12-01 22:02:41 +0000 | [diff] [blame] | 474 | auto channelMaskMatches = [](const std::vector<AudioChannelLayout>& channelMasks, |
| 475 | const AudioChannelLayout& channelMask) { |
| 476 | // Return true when 1) the channel mask is none and none of the channel mask from the |
| 477 | // collection contains haptic channel mask, or 2) the channel mask collection contains |
| 478 | // the queried channel mask. |
| 479 | return (channelMask.getTag() == AudioChannelLayout::none && |
| 480 | std::none_of(channelMasks.begin(), channelMasks.end(), |
| 481 | containHapticChannel)) || |
| 482 | std::find(channelMasks.begin(), channelMasks.end(), channelMask) |
| 483 | != channelMasks.end(); |
| 484 | }; |
| 485 | auto belongsToProfile = [&config, &channelMaskMatches](const AudioProfile& prof) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 486 | return (isDefaultAudioFormat(config.base.format) || prof.format == config.base.format) && |
jiabin | 8079700 | 2023-12-01 22:02:41 +0000 | [diff] [blame] | 487 | channelMaskMatches(prof.channelMasks, config.base.channelMask) && |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 488 | (config.base.sampleRate == 0 || |
| 489 | std::find(prof.sampleRates.begin(), prof.sampleRates.end(), |
| 490 | config.base.sampleRate) != prof.sampleRates.end()); |
| 491 | }; |
| 492 | static const std::vector<AudioOutputFlags> kOptionalOutputFlags{AudioOutputFlags::BIT_PERFECT}; |
| 493 | int optionalFlags = 0; |
| 494 | auto flagMatches = [&flags, &optionalFlags](const AudioIoFlags& portFlags) { |
| 495 | // Ports should be able to match if the optional flags are not requested. |
| 496 | return portFlags == flags || |
| 497 | (portFlags.getTag() == AudioIoFlags::Tag::output && |
| 498 | AudioIoFlags::make<AudioIoFlags::Tag::output>( |
| 499 | portFlags.get<AudioIoFlags::Tag::output>() & |
| 500 | ~optionalFlags) == flags); |
| 501 | }; |
| 502 | auto matcher = [&](const auto& pair) { |
| 503 | const auto& p = pair.second; |
| 504 | return p.ext.getTag() == AudioPortExt::Tag::mix && |
| 505 | flagMatches(p.flags) && |
| 506 | (destinationPortIds.empty() || |
| 507 | std::any_of(destinationPortIds.begin(), destinationPortIds.end(), |
| 508 | [&](const int32_t destId) { return mRoutingMatrix.count( |
| 509 | std::make_pair(p.id, destId)) != 0; })) && |
| 510 | (p.profiles.empty() || |
| 511 | std::find_if(p.profiles.begin(), p.profiles.end(), belongsToProfile) != |
| 512 | p.profiles.end()); }; |
| 513 | auto result = std::find_if(mPorts.begin(), mPorts.end(), matcher); |
| 514 | if (result == mPorts.end() && flags.getTag() == AudioIoFlags::Tag::output) { |
| 515 | auto optionalOutputFlagsIt = kOptionalOutputFlags.begin(); |
| 516 | while (result == mPorts.end() && optionalOutputFlagsIt != kOptionalOutputFlags.end()) { |
| 517 | if (isBitPositionFlagSet( |
| 518 | flags.get<AudioIoFlags::Tag::output>(), *optionalOutputFlagsIt)) { |
| 519 | // If the flag is set by the request, it must be matched. |
| 520 | ++optionalOutputFlagsIt; |
| 521 | continue; |
| 522 | } |
| 523 | optionalFlags |= makeBitPositionFlagMask(*optionalOutputFlagsIt++); |
| 524 | result = std::find_if(mPorts.begin(), mPorts.end(), matcher); |
| 525 | ALOGI("%s: port for config %s, flags %s was not found in the module %s, " |
| 526 | "retried with excluding optional flags %#x", __func__, config.toString().c_str(), |
| 527 | flags.toString().c_str(), mInstance.c_str(), optionalFlags); |
| 528 | } |
| 529 | } |
| 530 | return result; |
| 531 | } |
| 532 | |
| 533 | Hal2AidlMapper::PortConfigs::iterator Hal2AidlMapper::findPortConfig(const AudioDevice& device) { |
| 534 | return std::find_if(mPortConfigs.begin(), mPortConfigs.end(), |
| 535 | [&](const auto& pair) { return audioDeviceMatches(device, pair.second); }); |
| 536 | } |
| 537 | |
| 538 | Hal2AidlMapper::PortConfigs::iterator Hal2AidlMapper::findPortConfig( |
| 539 | const std::optional<AudioConfig>& config, |
| 540 | const std::optional<AudioIoFlags>& flags, |
| 541 | int32_t ioHandle) { |
| 542 | using Tag = AudioPortExt::Tag; |
| 543 | return std::find_if(mPortConfigs.begin(), mPortConfigs.end(), |
| 544 | [&](const auto& pair) { |
| 545 | const auto& p = pair.second; |
| 546 | LOG_ALWAYS_FATAL_IF(p.ext.getTag() == Tag::mix && |
| 547 | (!p.sampleRate.has_value() || !p.channelMask.has_value() || |
| 548 | !p.format.has_value() || !p.flags.has_value()), |
| 549 | "%s: stored mix port config is not fully specified: %s", |
| 550 | __func__, p.toString().c_str()); |
| 551 | return p.ext.getTag() == Tag::mix && |
| 552 | (!config.has_value() || |
| 553 | isConfigEqualToPortConfig(config.value(), p)) && |
| 554 | (!flags.has_value() || p.flags.value() == flags.value()) && |
| 555 | p.ext.template get<Tag::mix>().handle == ioHandle; }); |
| 556 | } |
| 557 | |
| 558 | status_t Hal2AidlMapper::getAudioMixPort(int32_t ioHandle, AudioPort* port) { |
| 559 | auto it = findPortConfig(std::nullopt /*config*/, std::nullopt /*flags*/, ioHandle); |
| 560 | if (it == mPortConfigs.end()) { |
| 561 | ALOGE("%s, cannot find mix port config for handle %u", __func__, ioHandle); |
| 562 | return BAD_VALUE; |
| 563 | } |
| 564 | return updateAudioPort(it->second.portId, port); |
| 565 | } |
| 566 | |
| 567 | status_t Hal2AidlMapper::getAudioPortCached( |
| 568 | const ::aidl::android::media::audio::common::AudioDevice& device, |
| 569 | ::aidl::android::media::audio::common::AudioPort* port) { |
| 570 | |
| 571 | if (auto portsIt = findPort(device); portsIt != mPorts.end()) { |
| 572 | *port = portsIt->second; |
| 573 | return OK; |
| 574 | } |
| 575 | ALOGE("%s: device port for device %s is not found in the module %s", |
| 576 | __func__, device.toString().c_str(), mInstance.c_str()); |
| 577 | return BAD_VALUE; |
| 578 | } |
| 579 | |
| 580 | status_t Hal2AidlMapper::initialize() { |
| 581 | std::vector<AudioPort> ports; |
| 582 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->getAudioPorts(&ports))); |
| 583 | ALOGW_IF(ports.empty(), "%s: module %s returned an empty list of audio ports", |
| 584 | __func__, mInstance.c_str()); |
| 585 | mDefaultInputPortId = mDefaultOutputPortId = -1; |
| 586 | const int defaultDeviceFlag = 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE; |
| 587 | for (auto it = ports.begin(); it != ports.end(); ) { |
| 588 | const auto& port = *it; |
| 589 | if (port.ext.getTag() != AudioPortExt::Tag::device) { |
| 590 | ++it; |
| 591 | continue; |
| 592 | } |
| 593 | const AudioPortDeviceExt& deviceExt = port.ext.get<AudioPortExt::Tag::device>(); |
| 594 | if ((deviceExt.flags & defaultDeviceFlag) != 0) { |
| 595 | if (port.flags.getTag() == AudioIoFlags::Tag::input) { |
| 596 | mDefaultInputPortId = port.id; |
| 597 | } else if (port.flags.getTag() == AudioIoFlags::Tag::output) { |
| 598 | mDefaultOutputPortId = port.id; |
| 599 | } |
| 600 | } |
| 601 | // For compatibility with HIDL, hide "template" remote submix ports from ports list. |
| 602 | if (const auto& devDesc = deviceExt.device; |
| 603 | (devDesc.type.type == AudioDeviceType::IN_SUBMIX || |
| 604 | devDesc.type.type == AudioDeviceType::OUT_SUBMIX) && |
| 605 | devDesc.type.connection == AudioDeviceDescription::CONNECTION_VIRTUAL) { |
| 606 | if (devDesc.type.type == AudioDeviceType::IN_SUBMIX) { |
| 607 | mRemoteSubmixIn = port; |
| 608 | } else { |
| 609 | mRemoteSubmixOut = port; |
| 610 | } |
| 611 | it = ports.erase(it); |
| 612 | } else { |
| 613 | ++it; |
| 614 | } |
| 615 | } |
| 616 | if (mRemoteSubmixIn.has_value() != mRemoteSubmixOut.has_value()) { |
| 617 | ALOGE("%s: The configuration only has input or output remote submix device, must have both", |
| 618 | __func__); |
| 619 | mRemoteSubmixIn.reset(); |
| 620 | mRemoteSubmixOut.reset(); |
| 621 | } |
| 622 | if (mRemoteSubmixIn.has_value()) { |
| 623 | AudioPort connectedRSubmixIn = *mRemoteSubmixIn; |
| 624 | connectedRSubmixIn.ext.get<AudioPortExt::Tag::device>().device.address = |
| 625 | AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS; |
| 626 | ALOGD("%s: connecting remote submix input", __func__); |
| 627 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->connectExternalDevice( |
| 628 | connectedRSubmixIn, &connectedRSubmixIn))); |
| 629 | // The template port for the remote submix input couldn't be "default" because it is not |
| 630 | // attached. The connected port can now be made default because we never disconnect it. |
| 631 | if (mDefaultInputPortId == -1) { |
| 632 | mDefaultInputPortId = connectedRSubmixIn.id; |
| 633 | } |
| 634 | ports.push_back(std::move(connectedRSubmixIn)); |
| 635 | |
| 636 | // Remote submix output must not be connected until the framework actually starts |
| 637 | // using it, however for legacy compatibility we need to provide an "augmented template" |
| 638 | // port with an address and profiles. It is obtained by connecting the output and then |
| 639 | // immediately disconnecting it. This is a cheap operation as we don't open any streams. |
| 640 | AudioPort tempConnectedRSubmixOut = *mRemoteSubmixOut; |
| 641 | tempConnectedRSubmixOut.ext.get<AudioPortExt::Tag::device>().device.address = |
| 642 | AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS; |
| 643 | ALOGD("%s: temporarily connecting and disconnecting remote submix output", __func__); |
| 644 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->connectExternalDevice( |
| 645 | tempConnectedRSubmixOut, &tempConnectedRSubmixOut))); |
| 646 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->disconnectExternalDevice( |
| 647 | tempConnectedRSubmixOut.id))); |
| 648 | tempConnectedRSubmixOut.id = mRemoteSubmixOut->id; |
| 649 | ports.push_back(std::move(tempConnectedRSubmixOut)); |
| 650 | } |
| 651 | |
| 652 | ALOGI("%s: module %s default port ids: input %d, output %d", |
| 653 | __func__, mInstance.c_str(), mDefaultInputPortId, mDefaultOutputPortId); |
| 654 | std::transform(ports.begin(), ports.end(), std::inserter(mPorts, mPorts.end()), |
| 655 | [](const auto& p) { return std::make_pair(p.id, p); }); |
| 656 | RETURN_STATUS_IF_ERROR(updateRoutes()); |
| 657 | std::vector<AudioPortConfig> portConfigs; |
| 658 | RETURN_STATUS_IF_ERROR( |
| 659 | statusTFromBinderStatus(mModule->getAudioPortConfigs(&portConfigs))); // OK if empty |
| 660 | std::transform(portConfigs.begin(), portConfigs.end(), |
| 661 | std::inserter(mPortConfigs, mPortConfigs.end()), |
| 662 | [](const auto& p) { return std::make_pair(p.id, p); }); |
| 663 | std::transform(mPortConfigs.begin(), mPortConfigs.end(), |
| 664 | std::inserter(mInitialPortConfigIds, mInitialPortConfigIds.end()), |
| 665 | [](const auto& pcPair) { return pcPair.first; }); |
| 666 | std::vector<AudioPatch> patches; |
| 667 | RETURN_STATUS_IF_ERROR( |
| 668 | statusTFromBinderStatus(mModule->getAudioPatches(&patches))); // OK if empty |
| 669 | std::transform(patches.begin(), patches.end(), |
| 670 | std::inserter(mPatches, mPatches.end()), |
| 671 | [](const auto& p) { return std::make_pair(p.id, p); }); |
| 672 | return OK; |
| 673 | } |
| 674 | |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 675 | bool Hal2AidlMapper::isPortBeingHeld(int32_t portId) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 676 | // It is assumed that mStreams has already been cleaned up. |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 677 | for (const auto& s : mStreams) { |
| 678 | if (portConfigBelongsToPort(s.second.first, portId)) return true; |
| 679 | } |
| 680 | for (const auto& [_, patch] : mPatches) { |
| 681 | for (int32_t id : patch.sourcePortConfigIds) { |
| 682 | if (portConfigBelongsToPort(id, portId)) return true; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 683 | } |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 684 | for (int32_t id : patch.sinkPortConfigIds) { |
| 685 | if (portConfigBelongsToPort(id, portId)) return true; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | return false; |
| 689 | } |
| 690 | |
| 691 | status_t Hal2AidlMapper::prepareToOpenStream( |
| 692 | int32_t ioHandle, const AudioDevice& device, const AudioIoFlags& flags, |
| 693 | AudioSource source, Cleanups* cleanups, AudioConfig* config, |
| 694 | AudioPortConfig* mixPortConfig, AudioPatch* patch) { |
| 695 | ALOGD("%p %s: handle %d, device %s, flags %s, source %s, config %s, mix port config %s", |
| 696 | this, __func__, ioHandle, device.toString().c_str(), |
| 697 | flags.toString().c_str(), toString(source).c_str(), |
| 698 | config->toString().c_str(), mixPortConfig->toString().c_str()); |
| 699 | resetUnusedPatchesAndPortConfigs(); |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 700 | const AudioConfig initialConfig = *config; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 701 | // Find / create AudioPortConfigs for the device port and the mix port, |
| 702 | // then find / create a patch between them, and open a stream on the mix port. |
| 703 | AudioPortConfig devicePortConfig; |
| 704 | bool created = false; |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 705 | RETURN_STATUS_IF_ERROR(findOrCreateDevicePortConfig(device, config, |
| 706 | &devicePortConfig, &created)); |
| 707 | LOG_ALWAYS_FATAL_IF(devicePortConfig.id == 0); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 708 | if (created) { |
| 709 | cleanups->add(&Hal2AidlMapper::resetPortConfig, devicePortConfig.id); |
| 710 | } |
Mikhail Naganov | 38220af | 2023-12-07 14:00:48 -0800 | [diff] [blame^] | 711 | status_t status = prepareToOpenStreamHelper(ioHandle, devicePortConfig.portId, |
| 712 | devicePortConfig.id, flags, source, initialConfig, cleanups, config, |
| 713 | mixPortConfig, patch); |
| 714 | if (status != OK) { |
| 715 | // If using the client-provided config did not work out for establishing a mix port config |
| 716 | // or patching, try with the device port config. Note that in general device port config and |
| 717 | // mix port config are not required to be the same, however they must match if the HAL |
| 718 | // module can't perform audio stream conversions. |
| 719 | AudioConfig deviceConfig = initialConfig; |
| 720 | if (setConfigFromPortConfig(&deviceConfig, devicePortConfig)->base != initialConfig.base) { |
| 721 | ALOGD("%s: retrying with device port config: %s", __func__, |
| 722 | devicePortConfig.toString().c_str()); |
| 723 | status = prepareToOpenStreamHelper(ioHandle, devicePortConfig.portId, |
| 724 | devicePortConfig.id, flags, source, initialConfig, cleanups, |
| 725 | &deviceConfig, mixPortConfig, patch); |
| 726 | if (status == OK) { |
| 727 | *config = deviceConfig; |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | return status; |
| 732 | } |
| 733 | |
| 734 | status_t Hal2AidlMapper::prepareToOpenStreamHelper( |
| 735 | int32_t ioHandle, int32_t devicePortId, int32_t devicePortConfigId, |
| 736 | const AudioIoFlags& flags, AudioSource source, const AudioConfig& initialConfig, |
| 737 | Cleanups* cleanups, AudioConfig* config, AudioPortConfig* mixPortConfig, |
| 738 | AudioPatch* patch) { |
| 739 | const bool isInput = flags.getTag() == AudioIoFlags::Tag::input; |
| 740 | bool created = false; |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 741 | RETURN_STATUS_IF_ERROR(findOrCreateMixPortConfig(*config, flags, ioHandle, source, |
Mikhail Naganov | 38220af | 2023-12-07 14:00:48 -0800 | [diff] [blame^] | 742 | std::set<int32_t>{devicePortId}, mixPortConfig, &created)); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 743 | if (created) { |
| 744 | cleanups->add(&Hal2AidlMapper::resetPortConfig, mixPortConfig->id); |
| 745 | } |
| 746 | setConfigFromPortConfig(config, *mixPortConfig); |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 747 | bool retryWithSuggestedConfig = false; // By default, let the framework to retry. |
| 748 | if (mixPortConfig->id == 0 && config->base == AudioConfigBase{}) { |
| 749 | // The HAL proposes a default config, can retry here. |
| 750 | retryWithSuggestedConfig = true; |
| 751 | } else if (isInput && config->base != initialConfig.base) { |
| 752 | // If the resulting config is different, we must stop and provide the config to the |
| 753 | // framework so that it can retry. |
| 754 | mixPortConfig->id = 0; |
| 755 | } else if (!isInput && mixPortConfig->id == 0 && |
| 756 | (initialConfig.base.format.type == AudioFormatType::PCM || |
| 757 | !isBitPositionFlagSet(flags.get<AudioIoFlags::output>(), |
| 758 | AudioOutputFlags::DIRECT) || |
| 759 | isBitPositionFlagSet(flags.get<AudioIoFlags::output>(), |
| 760 | AudioOutputFlags::COMPRESS_OFFLOAD))) { |
| 761 | // The framework does not retry opening non-direct PCM and IEC61937 outputs, need to retry |
| 762 | // here (see 'AudioHwDevice::openOutputStream'). |
| 763 | retryWithSuggestedConfig = true; |
| 764 | } |
| 765 | if (mixPortConfig->id == 0 && retryWithSuggestedConfig) { |
| 766 | ALOGD("%s: retrying to find/create a mix port config using config %s", __func__, |
| 767 | config->toString().c_str()); |
| 768 | RETURN_STATUS_IF_ERROR(findOrCreateMixPortConfig(*config, flags, ioHandle, source, |
Mikhail Naganov | 38220af | 2023-12-07 14:00:48 -0800 | [diff] [blame^] | 769 | std::set<int32_t>{devicePortId}, mixPortConfig, &created)); |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 770 | if (created) { |
| 771 | cleanups->add(&Hal2AidlMapper::resetPortConfig, mixPortConfig->id); |
| 772 | } |
| 773 | setConfigFromPortConfig(config, *mixPortConfig); |
| 774 | } |
| 775 | if (mixPortConfig->id == 0) { |
| 776 | ALOGD("%p %s: returning suggested config for the stream: %s", this, __func__, |
| 777 | config->toString().c_str()); |
| 778 | return OK; |
| 779 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 780 | if (isInput) { |
| 781 | RETURN_STATUS_IF_ERROR(findOrCreatePatch( |
Mikhail Naganov | 38220af | 2023-12-07 14:00:48 -0800 | [diff] [blame^] | 782 | {devicePortConfigId}, {mixPortConfig->id}, patch, &created)); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 783 | } else { |
| 784 | RETURN_STATUS_IF_ERROR(findOrCreatePatch( |
Mikhail Naganov | 38220af | 2023-12-07 14:00:48 -0800 | [diff] [blame^] | 785 | {mixPortConfig->id}, {devicePortConfigId}, patch, &created)); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 786 | } |
| 787 | if (created) { |
| 788 | cleanups->add(&Hal2AidlMapper::resetPatch, patch->id); |
| 789 | } |
| 790 | if (config->frameCount <= 0) { |
| 791 | config->frameCount = patch->minimumStreamBufferSizeFrames; |
| 792 | } |
| 793 | return OK; |
| 794 | } |
| 795 | |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 796 | status_t Hal2AidlMapper::setPortConfig( |
| 797 | const AudioPortConfig& requestedPortConfig, const std::set<int32_t>& destinationPortIds, |
| 798 | AudioPortConfig* portConfig, Cleanups* cleanups) { |
| 799 | bool created = false; |
| 800 | RETURN_STATUS_IF_ERROR(findOrCreatePortConfig( |
| 801 | requestedPortConfig, destinationPortIds, portConfig, &created)); |
| 802 | if (created && cleanups != nullptr) { |
| 803 | cleanups->add(&Hal2AidlMapper::resetPortConfig, portConfig->id); |
| 804 | } |
| 805 | return OK; |
| 806 | } |
| 807 | |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 808 | status_t Hal2AidlMapper::releaseAudioPatch(int32_t patchId) { |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 809 | return releaseAudioPatches({patchId}); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 812 | status_t Hal2AidlMapper::releaseAudioPatches(const std::set<int32_t>& patchIds) { |
| 813 | status_t result = OK; |
| 814 | for (const auto patchId : patchIds) { |
| 815 | if (auto it = mPatches.find(patchId); it != mPatches.end()) { |
| 816 | mPatches.erase(it); |
| 817 | if (ndk::ScopedAStatus status = mModule->resetAudioPatch(patchId); !status.isOk()) { |
| 818 | ALOGE("%s: error while resetting patch %d: %s", |
| 819 | __func__, patchId, status.getDescription().c_str()); |
| 820 | result = statusTFromBinderStatus(status); |
| 821 | } |
| 822 | } else { |
| 823 | ALOGE("%s: patch id %d not found", __func__, patchId); |
| 824 | result = BAD_VALUE; |
| 825 | } |
| 826 | } |
| 827 | resetUnusedPortConfigs(); |
| 828 | return result; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | void Hal2AidlMapper::resetPortConfig(int32_t portConfigId) { |
| 832 | if (auto it = mPortConfigs.find(portConfigId); it != mPortConfigs.end()) { |
| 833 | mPortConfigs.erase(it); |
| 834 | if (ndk::ScopedAStatus status = mModule->resetAudioPortConfig(portConfigId); |
| 835 | !status.isOk()) { |
| 836 | ALOGE("%s: error while resetting port config %d: %s", |
| 837 | __func__, portConfigId, status.getDescription().c_str()); |
| 838 | } |
| 839 | return; |
| 840 | } |
| 841 | ALOGE("%s: port config id %d not found", __func__, portConfigId); |
| 842 | } |
| 843 | |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 844 | void Hal2AidlMapper::resetUnusedPatchesAndPortConfigs() { |
| 845 | // Since patches can be created independently of streams via 'createOrUpdatePatch', |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 846 | // here we only clean up patches for released streams. |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 847 | std::set<int32_t> patchesToRelease; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 848 | for (auto it = mStreams.begin(); it != mStreams.end(); ) { |
| 849 | if (auto streamSp = it->first.promote(); streamSp) { |
| 850 | ++it; |
| 851 | } else { |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 852 | if (const int32_t patchId = it->second.second; patchId != -1) { |
| 853 | patchesToRelease.insert(patchId); |
| 854 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 855 | it = mStreams.erase(it); |
| 856 | } |
| 857 | } |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 858 | // 'releaseAudioPatches' also resets unused port configs. |
| 859 | releaseAudioPatches(patchesToRelease); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | void Hal2AidlMapper::resetUnusedPortConfigs() { |
| 863 | // The assumption is that port configs are used to create patches |
| 864 | // (or to open streams, but that involves creation of patches, too). Thus, |
| 865 | // orphaned port configs can and should be reset. |
| 866 | std::map<int32_t, int32_t /*portID*/> portConfigIds; |
| 867 | std::transform(mPortConfigs.begin(), mPortConfigs.end(), |
| 868 | std::inserter(portConfigIds, portConfigIds.end()), |
| 869 | [](const auto& pcPair) { return std::make_pair(pcPair.first, pcPair.second.portId); }); |
| 870 | for (const auto& p : mPatches) { |
| 871 | for (int32_t id : p.second.sourcePortConfigIds) portConfigIds.erase(id); |
| 872 | for (int32_t id : p.second.sinkPortConfigIds) portConfigIds.erase(id); |
| 873 | } |
| 874 | for (int32_t id : mInitialPortConfigIds) { |
| 875 | portConfigIds.erase(id); |
| 876 | } |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 877 | for (const auto& s : mStreams) { |
| 878 | portConfigIds.erase(s.second.first); |
| 879 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 880 | std::set<int32_t> retryDeviceDisconnection; |
| 881 | for (const auto& portConfigAndIdPair : portConfigIds) { |
| 882 | resetPortConfig(portConfigAndIdPair.first); |
| 883 | if (const auto it = mConnectedPorts.find(portConfigAndIdPair.second); |
| 884 | it != mConnectedPorts.end() && it->second) { |
| 885 | retryDeviceDisconnection.insert(portConfigAndIdPair.second); |
| 886 | } |
| 887 | } |
| 888 | for (int32_t portId : retryDeviceDisconnection) { |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 889 | if (!isPortBeingHeld(portId)) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 890 | if (auto status = mModule->disconnectExternalDevice(portId); status.isOk()) { |
| 891 | eraseConnectedPort(portId); |
| 892 | ALOGD("%s: executed postponed external device disconnection for port ID %d", |
| 893 | __func__, portId); |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | if (!retryDeviceDisconnection.empty()) { |
| 898 | updateRoutes(); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | status_t Hal2AidlMapper::setDevicePortConnectedState(const AudioPort& devicePort, bool connected) { |
| 903 | if (connected) { |
| 904 | AudioDevice matchDevice = devicePort.ext.get<AudioPortExt::device>().device; |
| 905 | std::optional<AudioPort> templatePort; |
| 906 | auto erasePortAfterConnectionIt = mPorts.end(); |
| 907 | // Connection of remote submix out with address "0" is a special case. Since there is |
| 908 | // already an "augmented template" port with this address in mPorts, we need to replace |
| 909 | // it with a connected port. |
| 910 | // Connection of remote submix outs with any other address is done as usual except that |
| 911 | // the template port is in `mRemoteSubmixOut`. |
| 912 | if (mRemoteSubmixOut.has_value() && matchDevice.type.type == AudioDeviceType::OUT_SUBMIX) { |
| 913 | if (matchDevice.address == AudioDeviceAddress::make<AudioDeviceAddress::id>( |
| 914 | AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS)) { |
| 915 | erasePortAfterConnectionIt = findPort(matchDevice); |
| 916 | } |
| 917 | templatePort = mRemoteSubmixOut; |
| 918 | } else if (mRemoteSubmixIn.has_value() && |
| 919 | matchDevice.type.type == AudioDeviceType::IN_SUBMIX) { |
| 920 | templatePort = mRemoteSubmixIn; |
| 921 | } else { |
| 922 | // Reset the device address to find the "template" port. |
| 923 | matchDevice.address = AudioDeviceAddress::make<AudioDeviceAddress::id>(); |
| 924 | } |
| 925 | if (!templatePort.has_value()) { |
| 926 | auto portsIt = findPort(matchDevice); |
| 927 | if (portsIt == mPorts.end()) { |
| 928 | // Since 'setConnectedState' is called for all modules, it is normal when the device |
| 929 | // port not found in every one of them. |
| 930 | return BAD_VALUE; |
| 931 | } else { |
| 932 | ALOGD("%s: device port for device %s found in the module %s", |
| 933 | __func__, matchDevice.toString().c_str(), mInstance.c_str()); |
| 934 | } |
| 935 | templatePort = portsIt->second; |
| 936 | } |
| 937 | resetUnusedPatchesAndPortConfigs(); |
| 938 | |
| 939 | // Use the ID of the "template" port, use all the information from the provided port. |
| 940 | AudioPort connectedPort = devicePort; |
| 941 | connectedPort.id = templatePort->id; |
| 942 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->connectExternalDevice( |
| 943 | connectedPort, &connectedPort))); |
| 944 | const auto [it, inserted] = mPorts.insert(std::make_pair(connectedPort.id, connectedPort)); |
| 945 | LOG_ALWAYS_FATAL_IF(!inserted, |
| 946 | "%s: module %s, duplicate port ID received from HAL: %s, existing port: %s", |
| 947 | __func__, mInstance.c_str(), connectedPort.toString().c_str(), |
| 948 | it->second.toString().c_str()); |
| 949 | mConnectedPorts[connectedPort.id] = false; |
| 950 | if (erasePortAfterConnectionIt != mPorts.end()) { |
| 951 | mPorts.erase(erasePortAfterConnectionIt); |
| 952 | } |
| 953 | } else { // !connected |
| 954 | AudioDevice matchDevice = devicePort.ext.get<AudioPortExt::device>().device; |
| 955 | auto portsIt = findPort(matchDevice); |
| 956 | if (portsIt == mPorts.end()) { |
| 957 | // Since 'setConnectedState' is called for all modules, it is normal when the device |
| 958 | // port not found in every one of them. |
| 959 | return BAD_VALUE; |
| 960 | } else { |
| 961 | ALOGD("%s: device port for device %s found in the module %s", |
| 962 | __func__, matchDevice.toString().c_str(), mInstance.c_str()); |
| 963 | } |
| 964 | resetUnusedPatchesAndPortConfigs(); |
| 965 | |
| 966 | // Disconnection of remote submix out with address "0" is a special case. We need to replace |
| 967 | // the connected port entry with the "augmented template". |
| 968 | const int32_t portId = portsIt->second.id; |
| 969 | if (mRemoteSubmixOut.has_value() && matchDevice.type.type == AudioDeviceType::OUT_SUBMIX && |
| 970 | matchDevice.address == AudioDeviceAddress::make<AudioDeviceAddress::id>( |
| 971 | AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS)) { |
| 972 | mDisconnectedPortReplacement = std::make_pair(portId, *mRemoteSubmixOut); |
| 973 | auto& port = mDisconnectedPortReplacement.second; |
| 974 | port.ext.get<AudioPortExt::Tag::device>().device = matchDevice; |
| 975 | port.profiles = portsIt->second.profiles; |
| 976 | } |
| 977 | // Streams are closed by AudioFlinger independently from device disconnections. |
| 978 | // It is possible that the stream has not been closed yet. |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 979 | if (!isPortBeingHeld(portId)) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 980 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 981 | mModule->disconnectExternalDevice(portId))); |
| 982 | eraseConnectedPort(portId); |
| 983 | } else { |
| 984 | ALOGD("%s: since device port ID %d is used by a stream, " |
| 985 | "external device disconnection postponed", __func__, portId); |
| 986 | mConnectedPorts[portId] = true; |
| 987 | } |
| 988 | } |
| 989 | return updateRoutes(); |
| 990 | } |
| 991 | |
| 992 | status_t Hal2AidlMapper::updateAudioPort(int32_t portId, AudioPort* port) { |
| 993 | const status_t status = statusTFromBinderStatus(mModule->getAudioPort(portId, port)); |
| 994 | if (status == OK) { |
| 995 | auto portIt = mPorts.find(portId); |
| 996 | if (portIt != mPorts.end()) { |
| 997 | portIt->second = *port; |
| 998 | } else { |
| 999 | ALOGW("%s, port(%d) returned successfully from the HAL but not it is not cached", |
| 1000 | __func__, portId); |
| 1001 | } |
| 1002 | } |
| 1003 | return status; |
| 1004 | } |
| 1005 | |
| 1006 | status_t Hal2AidlMapper::updateRoutes() { |
| 1007 | RETURN_STATUS_IF_ERROR( |
| 1008 | statusTFromBinderStatus(mModule->getAudioRoutes(&mRoutes))); |
| 1009 | ALOGW_IF(mRoutes.empty(), "%s: module %s returned an empty list of audio routes", |
| 1010 | __func__, mInstance.c_str()); |
| 1011 | if (mRemoteSubmixIn.has_value()) { |
| 1012 | // Remove mentions of the template remote submix input from routes. |
| 1013 | int32_t rSubmixInId = mRemoteSubmixIn->id; |
| 1014 | // Remove mentions of the template remote submix out only if it is not in mPorts |
| 1015 | // (that means there is a connected port in mPorts). |
| 1016 | int32_t rSubmixOutId = mPorts.find(mRemoteSubmixOut->id) == mPorts.end() ? |
| 1017 | mRemoteSubmixOut->id : -1; |
| 1018 | for (auto it = mRoutes.begin(); it != mRoutes.end();) { |
| 1019 | auto& route = *it; |
| 1020 | if (route.sinkPortId == rSubmixOutId) { |
| 1021 | it = mRoutes.erase(it); |
| 1022 | continue; |
| 1023 | } |
| 1024 | if (auto routeIt = std::find(route.sourcePortIds.begin(), route.sourcePortIds.end(), |
| 1025 | rSubmixInId); routeIt != route.sourcePortIds.end()) { |
| 1026 | route.sourcePortIds.erase(routeIt); |
| 1027 | if (route.sourcePortIds.empty()) { |
| 1028 | it = mRoutes.erase(it); |
| 1029 | continue; |
| 1030 | } |
| 1031 | } |
| 1032 | ++it; |
| 1033 | } |
| 1034 | } |
| 1035 | mRoutingMatrix.clear(); |
| 1036 | for (const auto& r : mRoutes) { |
| 1037 | for (auto portId : r.sourcePortIds) { |
| 1038 | mRoutingMatrix.emplace(r.sinkPortId, portId); |
| 1039 | mRoutingMatrix.emplace(portId, r.sinkPortId); |
| 1040 | } |
| 1041 | } |
| 1042 | return OK; |
| 1043 | } |
| 1044 | |
| 1045 | } // namespace android |