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 | |
| 17 | #include <algorithm> |
| 18 | #include <set> |
| 19 | |
| 20 | #define LOG_TAG "AHAL_Module" |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 21 | #include <android-base/logging.h> |
Shunkai Yao | 39bf2c3 | 2022-12-06 03:25:59 +0000 | [diff] [blame] | 22 | #include <android/binder_ibinder_platform.h> |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 23 | |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 24 | #include <Utils.h> |
| 25 | #include <aidl/android/media/audio/common/AudioInputFlags.h> |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 26 | #include <aidl/android/media/audio/common/AudioOutputFlags.h> |
| 27 | |
Mikhail Naganov | 10c6fe2 | 2022-09-30 23:49:17 +0000 | [diff] [blame] | 28 | #include "core-impl/Bluetooth.h" |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 29 | #include "core-impl/Module.h" |
Vlad Popa | 943b7e2 | 2022-12-08 14:24:12 +0100 | [diff] [blame] | 30 | #include "core-impl/SoundDose.h" |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 31 | #include "core-impl/Telephony.h" |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 32 | #include "core-impl/utils.h" |
| 33 | |
| 34 | using aidl::android::hardware::audio::common::SinkMetadata; |
| 35 | using aidl::android::hardware::audio::common::SourceMetadata; |
Vlad Popa | 2afbd1e | 2022-12-28 17:04:58 +0100 | [diff] [blame] | 36 | using aidl::android::hardware::audio::core::sounddose::ISoundDose; |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 37 | using aidl::android::media::audio::common::AudioChannelLayout; |
Mikhail Naganov | ef6bc74 | 2022-10-06 00:14:19 +0000 | [diff] [blame] | 38 | using aidl::android::media::audio::common::AudioDevice; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 39 | using aidl::android::media::audio::common::AudioFormatDescription; |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 40 | using aidl::android::media::audio::common::AudioFormatType; |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 41 | using aidl::android::media::audio::common::AudioInputFlags; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 42 | using aidl::android::media::audio::common::AudioIoFlags; |
| 43 | using aidl::android::media::audio::common::AudioOffloadInfo; |
| 44 | using aidl::android::media::audio::common::AudioOutputFlags; |
| 45 | using aidl::android::media::audio::common::AudioPort; |
| 46 | using aidl::android::media::audio::common::AudioPortConfig; |
| 47 | using aidl::android::media::audio::common::AudioPortExt; |
| 48 | using aidl::android::media::audio::common::AudioProfile; |
Mikhail Naganov | 20047bc | 2023-01-05 20:16:07 +0000 | [diff] [blame^] | 49 | using aidl::android::media::audio::common::Boolean; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 50 | using aidl::android::media::audio::common::Int; |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 51 | using aidl::android::media::audio::common::PcmType; |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 52 | using android::hardware::audio::common::getFrameSizeInBytes; |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 53 | using android::hardware::audio::common::isBitPositionFlagSet; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 54 | |
| 55 | namespace aidl::android::hardware::audio::core { |
| 56 | |
| 57 | namespace { |
| 58 | |
| 59 | bool generateDefaultPortConfig(const AudioPort& port, AudioPortConfig* config) { |
| 60 | *config = {}; |
| 61 | config->portId = port.id; |
| 62 | if (port.profiles.empty()) { |
| 63 | LOG(ERROR) << __func__ << ": port " << port.id << " has no profiles"; |
| 64 | return false; |
| 65 | } |
| 66 | const auto& profile = port.profiles.begin(); |
| 67 | config->format = profile->format; |
| 68 | if (profile->channelMasks.empty()) { |
| 69 | LOG(ERROR) << __func__ << ": the first profile in port " << port.id |
| 70 | << " has no channel masks"; |
| 71 | return false; |
| 72 | } |
| 73 | config->channelMask = *profile->channelMasks.begin(); |
| 74 | if (profile->sampleRates.empty()) { |
| 75 | LOG(ERROR) << __func__ << ": the first profile in port " << port.id |
| 76 | << " has no sample rates"; |
| 77 | return false; |
| 78 | } |
| 79 | Int sampleRate; |
| 80 | sampleRate.value = *profile->sampleRates.begin(); |
| 81 | config->sampleRate = sampleRate; |
| 82 | config->flags = port.flags; |
| 83 | config->ext = port.ext; |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | bool findAudioProfile(const AudioPort& port, const AudioFormatDescription& format, |
| 88 | AudioProfile* profile) { |
| 89 | if (auto profilesIt = |
| 90 | find_if(port.profiles.begin(), port.profiles.end(), |
| 91 | [&format](const auto& profile) { return profile.format == format; }); |
| 92 | profilesIt != port.profiles.end()) { |
| 93 | *profile = *profilesIt; |
| 94 | return true; |
| 95 | } |
| 96 | return false; |
| 97 | } |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 98 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 99 | } // namespace |
| 100 | |
| 101 | void Module::cleanUpPatch(int32_t patchId) { |
| 102 | erase_all_values(mPatches, std::set<int32_t>{patchId}); |
| 103 | } |
| 104 | |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 105 | ndk::ScopedAStatus Module::createStreamContext(int32_t in_portConfigId, int64_t in_bufferSizeFrames, |
Mikhail Naganov | 30301a4 | 2022-09-13 01:20:45 +0000 | [diff] [blame] | 106 | std::shared_ptr<IStreamCallback> asyncCallback, |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 107 | StreamContext* out_context) { |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 108 | if (in_bufferSizeFrames <= 0) { |
| 109 | LOG(ERROR) << __func__ << ": non-positive buffer size " << in_bufferSizeFrames; |
| 110 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 111 | } |
| 112 | if (in_bufferSizeFrames < kMinimumStreamBufferSizeFrames) { |
| 113 | LOG(ERROR) << __func__ << ": insufficient buffer size " << in_bufferSizeFrames |
| 114 | << ", must be at least " << kMinimumStreamBufferSizeFrames; |
| 115 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 116 | } |
| 117 | auto& configs = getConfig().portConfigs; |
| 118 | auto portConfigIt = findById<AudioPortConfig>(configs, in_portConfigId); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 119 | // Since this is a private method, it is assumed that |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 120 | // validity of the portConfigId has already been checked. |
| 121 | const size_t frameSize = |
| 122 | getFrameSizeInBytes(portConfigIt->format.value(), portConfigIt->channelMask.value()); |
| 123 | if (frameSize == 0) { |
| 124 | LOG(ERROR) << __func__ << ": could not calculate frame size for port config " |
| 125 | << portConfigIt->toString(); |
| 126 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 127 | } |
| 128 | LOG(DEBUG) << __func__ << ": frame size " << frameSize << " bytes"; |
| 129 | if (frameSize > kMaximumStreamBufferSizeBytes / in_bufferSizeFrames) { |
| 130 | LOG(ERROR) << __func__ << ": buffer size " << in_bufferSizeFrames |
| 131 | << " frames is too large, maximum size is " |
| 132 | << kMaximumStreamBufferSizeBytes / frameSize; |
| 133 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 134 | } |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 135 | const auto& flags = portConfigIt->flags.value(); |
| 136 | if ((flags.getTag() == AudioIoFlags::Tag::input && |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 137 | !isBitPositionFlagSet(flags.get<AudioIoFlags::Tag::input>(), |
| 138 | AudioInputFlags::MMAP_NOIRQ)) || |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 139 | (flags.getTag() == AudioIoFlags::Tag::output && |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 140 | !isBitPositionFlagSet(flags.get<AudioIoFlags::Tag::output>(), |
| 141 | AudioOutputFlags::MMAP_NOIRQ))) { |
Mikhail Naganov | 20047bc | 2023-01-05 20:16:07 +0000 | [diff] [blame^] | 142 | StreamContext::DebugParameters params{mDebug.streamTransientStateDelayMs, |
| 143 | mVendorDebug.forceTransientBurst}; |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 144 | StreamContext temp( |
| 145 | std::make_unique<StreamContext::CommandMQ>(1, true /*configureEventFlagWord*/), |
| 146 | std::make_unique<StreamContext::ReplyMQ>(1, true /*configureEventFlagWord*/), |
Mikhail Naganov | ef6bc74 | 2022-10-06 00:14:19 +0000 | [diff] [blame] | 147 | portConfigIt->format.value(), portConfigIt->channelMask.value(), |
| 148 | std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames), |
Mikhail Naganov | 20047bc | 2023-01-05 20:16:07 +0000 | [diff] [blame^] | 149 | asyncCallback, params); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 150 | if (temp.isValid()) { |
| 151 | *out_context = std::move(temp); |
| 152 | } else { |
| 153 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 154 | } |
| 155 | } else { |
| 156 | // TODO: Implement simulation of MMAP buffer allocation |
| 157 | } |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 158 | return ndk::ScopedAStatus::ok(); |
| 159 | } |
| 160 | |
Mikhail Naganov | ef6bc74 | 2022-10-06 00:14:19 +0000 | [diff] [blame] | 161 | std::vector<AudioDevice> Module::findConnectedDevices(int32_t portConfigId) { |
| 162 | std::vector<AudioDevice> result; |
| 163 | auto& ports = getConfig().ports; |
| 164 | auto portIds = portIdsFromPortConfigIds(findConnectedPortConfigIds(portConfigId)); |
| 165 | for (auto it = portIds.begin(); it != portIds.end(); ++it) { |
| 166 | auto portIt = findById<AudioPort>(ports, *it); |
| 167 | if (portIt != ports.end() && portIt->ext.getTag() == AudioPortExt::Tag::device) { |
| 168 | result.push_back(portIt->ext.template get<AudioPortExt::Tag::device>().device); |
| 169 | } |
| 170 | } |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | std::set<int32_t> Module::findConnectedPortConfigIds(int32_t portConfigId) { |
| 175 | std::set<int32_t> result; |
| 176 | auto patchIdsRange = mPatches.equal_range(portConfigId); |
| 177 | auto& patches = getConfig().patches; |
| 178 | for (auto it = patchIdsRange.first; it != patchIdsRange.second; ++it) { |
| 179 | auto patchIt = findById<AudioPatch>(patches, it->second); |
| 180 | if (patchIt == patches.end()) { |
| 181 | LOG(FATAL) << __func__ << ": patch with id " << it->second << " taken from mPatches " |
| 182 | << "not found in the configuration"; |
| 183 | } |
| 184 | if (std::find(patchIt->sourcePortConfigIds.begin(), patchIt->sourcePortConfigIds.end(), |
| 185 | portConfigId) != patchIt->sourcePortConfigIds.end()) { |
| 186 | result.insert(patchIt->sinkPortConfigIds.begin(), patchIt->sinkPortConfigIds.end()); |
| 187 | } else { |
| 188 | result.insert(patchIt->sourcePortConfigIds.begin(), patchIt->sourcePortConfigIds.end()); |
| 189 | } |
| 190 | } |
| 191 | return result; |
| 192 | } |
| 193 | |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 194 | ndk::ScopedAStatus Module::findPortIdForNewStream(int32_t in_portConfigId, AudioPort** port) { |
| 195 | auto& configs = getConfig().portConfigs; |
| 196 | auto portConfigIt = findById<AudioPortConfig>(configs, in_portConfigId); |
| 197 | if (portConfigIt == configs.end()) { |
| 198 | LOG(ERROR) << __func__ << ": existing port config id " << in_portConfigId << " not found"; |
| 199 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 200 | } |
| 201 | const int32_t portId = portConfigIt->portId; |
| 202 | // In our implementation, configs of mix ports always have unique IDs. |
| 203 | CHECK(portId != in_portConfigId); |
| 204 | auto& ports = getConfig().ports; |
| 205 | auto portIt = findById<AudioPort>(ports, portId); |
| 206 | if (portIt == ports.end()) { |
| 207 | LOG(ERROR) << __func__ << ": port id " << portId << " used by port config id " |
| 208 | << in_portConfigId << " not found"; |
| 209 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 210 | } |
| 211 | if (mStreams.count(in_portConfigId) != 0) { |
| 212 | LOG(ERROR) << __func__ << ": port config id " << in_portConfigId |
| 213 | << " already has a stream opened on it"; |
| 214 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 215 | } |
| 216 | if (portIt->ext.getTag() != AudioPortExt::Tag::mix) { |
| 217 | LOG(ERROR) << __func__ << ": port config id " << in_portConfigId |
| 218 | << " does not correspond to a mix port"; |
| 219 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 220 | } |
| 221 | const int32_t maxOpenStreamCount = portIt->ext.get<AudioPortExt::Tag::mix>().maxOpenStreamCount; |
| 222 | if (maxOpenStreamCount != 0 && mStreams.count(portId) >= maxOpenStreamCount) { |
| 223 | LOG(ERROR) << __func__ << ": port id " << portId |
| 224 | << " has already reached maximum allowed opened stream count: " |
| 225 | << maxOpenStreamCount; |
| 226 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 227 | } |
| 228 | *port = &(*portIt); |
| 229 | return ndk::ScopedAStatus::ok(); |
| 230 | } |
| 231 | |
Mikhail Naganov | ef6bc74 | 2022-10-06 00:14:19 +0000 | [diff] [blame] | 232 | template <typename C> |
| 233 | std::set<int32_t> Module::portIdsFromPortConfigIds(C portConfigIds) { |
| 234 | std::set<int32_t> result; |
| 235 | auto& portConfigs = getConfig().portConfigs; |
| 236 | for (auto it = portConfigIds.begin(); it != portConfigIds.end(); ++it) { |
| 237 | auto portConfigIt = findById<AudioPortConfig>(portConfigs, *it); |
| 238 | if (portConfigIt != portConfigs.end()) { |
| 239 | result.insert(portConfigIt->portId); |
| 240 | } |
| 241 | } |
| 242 | return result; |
| 243 | } |
| 244 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 245 | internal::Configuration& Module::getConfig() { |
| 246 | if (!mConfig) { |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 247 | switch (mType) { |
| 248 | case Type::DEFAULT: |
| 249 | mConfig = std::move(internal::getPrimaryConfiguration()); |
| 250 | break; |
| 251 | case Type::R_SUBMIX: |
| 252 | mConfig = std::move(internal::getRSubmixConfiguration()); |
| 253 | break; |
| 254 | } |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 255 | } |
| 256 | return *mConfig; |
| 257 | } |
| 258 | |
| 259 | void Module::registerPatch(const AudioPatch& patch) { |
| 260 | auto& configs = getConfig().portConfigs; |
| 261 | auto do_insert = [&](const std::vector<int32_t>& portConfigIds) { |
| 262 | for (auto portConfigId : portConfigIds) { |
| 263 | auto configIt = findById<AudioPortConfig>(configs, portConfigId); |
| 264 | if (configIt != configs.end()) { |
| 265 | mPatches.insert(std::pair{portConfigId, patch.id}); |
| 266 | if (configIt->portId != portConfigId) { |
| 267 | mPatches.insert(std::pair{configIt->portId, patch.id}); |
| 268 | } |
| 269 | } |
| 270 | }; |
| 271 | }; |
| 272 | do_insert(patch.sourcePortConfigIds); |
| 273 | do_insert(patch.sinkPortConfigIds); |
| 274 | } |
| 275 | |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 276 | void Module::updateStreamsConnectedState(const AudioPatch& oldPatch, const AudioPatch& newPatch) { |
| 277 | // Streams from the old patch need to be disconnected, streams from the new |
| 278 | // patch need to be connected. If the stream belongs to both patches, no need |
| 279 | // to update it. |
| 280 | std::set<int32_t> idsToDisconnect, idsToConnect; |
| 281 | idsToDisconnect.insert(oldPatch.sourcePortConfigIds.begin(), |
| 282 | oldPatch.sourcePortConfigIds.end()); |
| 283 | idsToDisconnect.insert(oldPatch.sinkPortConfigIds.begin(), oldPatch.sinkPortConfigIds.end()); |
| 284 | idsToConnect.insert(newPatch.sourcePortConfigIds.begin(), newPatch.sourcePortConfigIds.end()); |
| 285 | idsToConnect.insert(newPatch.sinkPortConfigIds.begin(), newPatch.sinkPortConfigIds.end()); |
| 286 | std::for_each(idsToDisconnect.begin(), idsToDisconnect.end(), [&](const auto& portConfigId) { |
| 287 | if (idsToConnect.count(portConfigId) == 0) { |
Mikhail Naganov | ef6bc74 | 2022-10-06 00:14:19 +0000 | [diff] [blame] | 288 | LOG(DEBUG) << "The stream on port config id " << portConfigId << " is not connected"; |
| 289 | mStreams.setStreamIsConnected(portConfigId, {}); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 290 | } |
| 291 | }); |
| 292 | std::for_each(idsToConnect.begin(), idsToConnect.end(), [&](const auto& portConfigId) { |
| 293 | if (idsToDisconnect.count(portConfigId) == 0) { |
Mikhail Naganov | ef6bc74 | 2022-10-06 00:14:19 +0000 | [diff] [blame] | 294 | const auto connectedDevices = findConnectedDevices(portConfigId); |
| 295 | LOG(DEBUG) << "The stream on port config id " << portConfigId |
| 296 | << " is connected to: " << ::android::internal::ToString(connectedDevices); |
| 297 | mStreams.setStreamIsConnected(portConfigId, connectedDevices); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 298 | } |
| 299 | }); |
| 300 | } |
| 301 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 302 | ndk::ScopedAStatus Module::setModuleDebug( |
| 303 | const ::aidl::android::hardware::audio::core::ModuleDebug& in_debug) { |
| 304 | LOG(DEBUG) << __func__ << ": old flags:" << mDebug.toString() |
| 305 | << ", new flags: " << in_debug.toString(); |
| 306 | if (mDebug.simulateDeviceConnections != in_debug.simulateDeviceConnections && |
| 307 | !mConnectedDevicePorts.empty()) { |
| 308 | LOG(ERROR) << __func__ << ": attempting to change device connections simulation " |
| 309 | << "while having external devices connected"; |
| 310 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 311 | } |
Mikhail Naganov | bd483c0 | 2022-11-17 20:33:39 +0000 | [diff] [blame] | 312 | if (in_debug.streamTransientStateDelayMs < 0) { |
| 313 | LOG(ERROR) << __func__ << ": streamTransientStateDelayMs is negative: " |
| 314 | << in_debug.streamTransientStateDelayMs; |
| 315 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 316 | } |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 317 | mDebug = in_debug; |
| 318 | return ndk::ScopedAStatus::ok(); |
| 319 | } |
| 320 | |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 321 | ndk::ScopedAStatus Module::getTelephony(std::shared_ptr<ITelephony>* _aidl_return) { |
| 322 | if (mTelephony == nullptr) { |
| 323 | mTelephony = ndk::SharedRefBase::make<Telephony>(); |
Mikhail Naganov | df5feba | 2022-12-15 00:11:14 +0000 | [diff] [blame] | 324 | mTelephonyBinder = mTelephony->asBinder(); |
| 325 | AIBinder_setMinSchedulerPolicy(mTelephonyBinder.get(), SCHED_NORMAL, |
Shunkai Yao | 39bf2c3 | 2022-12-06 03:25:59 +0000 | [diff] [blame] | 326 | ANDROID_PRIORITY_AUDIO); |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 327 | } |
| 328 | *_aidl_return = mTelephony; |
| 329 | LOG(DEBUG) << __func__ << ": returning instance of ITelephony: " << _aidl_return->get(); |
| 330 | return ndk::ScopedAStatus::ok(); |
| 331 | } |
| 332 | |
Mikhail Naganov | 10c6fe2 | 2022-09-30 23:49:17 +0000 | [diff] [blame] | 333 | ndk::ScopedAStatus Module::getBluetooth(std::shared_ptr<IBluetooth>* _aidl_return) { |
| 334 | if (mBluetooth == nullptr) { |
| 335 | mBluetooth = ndk::SharedRefBase::make<Bluetooth>(); |
| 336 | mBluetoothBinder = mBluetooth->asBinder(); |
| 337 | AIBinder_setMinSchedulerPolicy(mBluetoothBinder.get(), SCHED_NORMAL, |
| 338 | ANDROID_PRIORITY_AUDIO); |
| 339 | } |
| 340 | *_aidl_return = mBluetooth; |
| 341 | LOG(DEBUG) << __func__ << ": returning instance of IBluetooth: " << _aidl_return->get(); |
| 342 | return ndk::ScopedAStatus::ok(); |
| 343 | } |
| 344 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 345 | ndk::ScopedAStatus Module::connectExternalDevice(const AudioPort& in_templateIdAndAdditionalData, |
| 346 | AudioPort* _aidl_return) { |
| 347 | const int32_t templateId = in_templateIdAndAdditionalData.id; |
| 348 | auto& ports = getConfig().ports; |
| 349 | AudioPort connectedPort; |
| 350 | { // Scope the template port so that we don't accidentally modify it. |
| 351 | auto templateIt = findById<AudioPort>(ports, templateId); |
| 352 | if (templateIt == ports.end()) { |
| 353 | LOG(ERROR) << __func__ << ": port id " << templateId << " not found"; |
| 354 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 355 | } |
| 356 | if (templateIt->ext.getTag() != AudioPortExt::Tag::device) { |
| 357 | LOG(ERROR) << __func__ << ": port id " << templateId << " is not a device port"; |
| 358 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 359 | } |
| 360 | if (!templateIt->profiles.empty()) { |
| 361 | LOG(ERROR) << __func__ << ": port id " << templateId |
| 362 | << " does not have dynamic profiles"; |
| 363 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 364 | } |
| 365 | auto& templateDevicePort = templateIt->ext.get<AudioPortExt::Tag::device>(); |
| 366 | if (templateDevicePort.device.type.connection.empty()) { |
| 367 | LOG(ERROR) << __func__ << ": port id " << templateId << " is permanently attached"; |
| 368 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 369 | } |
| 370 | // Postpone id allocation until we ensure that there are no client errors. |
| 371 | connectedPort = *templateIt; |
| 372 | connectedPort.extraAudioDescriptors = in_templateIdAndAdditionalData.extraAudioDescriptors; |
| 373 | const auto& inputDevicePort = |
| 374 | in_templateIdAndAdditionalData.ext.get<AudioPortExt::Tag::device>(); |
| 375 | auto& connectedDevicePort = connectedPort.ext.get<AudioPortExt::Tag::device>(); |
| 376 | connectedDevicePort.device.address = inputDevicePort.device.address; |
| 377 | LOG(DEBUG) << __func__ << ": device port " << connectedPort.id << " device set to " |
| 378 | << connectedDevicePort.device.toString(); |
| 379 | // Check if there is already a connected port with for the same external device. |
| 380 | for (auto connectedPortId : mConnectedDevicePorts) { |
| 381 | auto connectedPortIt = findById<AudioPort>(ports, connectedPortId); |
| 382 | if (connectedPortIt->ext.get<AudioPortExt::Tag::device>().device == |
| 383 | connectedDevicePort.device) { |
| 384 | LOG(ERROR) << __func__ << ": device " << connectedDevicePort.device.toString() |
| 385 | << " is already connected at the device port id " << connectedPortId; |
| 386 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | if (!mDebug.simulateDeviceConnections) { |
| 392 | // In a real HAL here we would attempt querying the profiles from the device. |
| 393 | LOG(ERROR) << __func__ << ": failed to query supported device profiles"; |
| 394 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 395 | } |
| 396 | |
| 397 | connectedPort.id = ++getConfig().nextPortId; |
| 398 | mConnectedDevicePorts.insert(connectedPort.id); |
| 399 | LOG(DEBUG) << __func__ << ": template port " << templateId << " external device connected, " |
| 400 | << "connected port ID " << connectedPort.id; |
| 401 | auto& connectedProfiles = getConfig().connectedProfiles; |
| 402 | if (auto connectedProfilesIt = connectedProfiles.find(templateId); |
| 403 | connectedProfilesIt != connectedProfiles.end()) { |
| 404 | connectedPort.profiles = connectedProfilesIt->second; |
| 405 | } |
| 406 | ports.push_back(connectedPort); |
| 407 | *_aidl_return = std::move(connectedPort); |
| 408 | |
| 409 | std::vector<AudioRoute> newRoutes; |
| 410 | auto& routes = getConfig().routes; |
| 411 | for (auto& r : routes) { |
| 412 | if (r.sinkPortId == templateId) { |
| 413 | AudioRoute newRoute; |
| 414 | newRoute.sourcePortIds = r.sourcePortIds; |
| 415 | newRoute.sinkPortId = connectedPort.id; |
| 416 | newRoute.isExclusive = r.isExclusive; |
| 417 | newRoutes.push_back(std::move(newRoute)); |
| 418 | } else { |
| 419 | auto& srcs = r.sourcePortIds; |
| 420 | if (std::find(srcs.begin(), srcs.end(), templateId) != srcs.end()) { |
| 421 | srcs.push_back(connectedPort.id); |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | routes.insert(routes.end(), newRoutes.begin(), newRoutes.end()); |
| 426 | |
| 427 | return ndk::ScopedAStatus::ok(); |
| 428 | } |
| 429 | |
| 430 | ndk::ScopedAStatus Module::disconnectExternalDevice(int32_t in_portId) { |
| 431 | auto& ports = getConfig().ports; |
| 432 | auto portIt = findById<AudioPort>(ports, in_portId); |
| 433 | if (portIt == ports.end()) { |
| 434 | LOG(ERROR) << __func__ << ": port id " << in_portId << " not found"; |
| 435 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 436 | } |
| 437 | if (portIt->ext.getTag() != AudioPortExt::Tag::device) { |
| 438 | LOG(ERROR) << __func__ << ": port id " << in_portId << " is not a device port"; |
| 439 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 440 | } |
| 441 | if (mConnectedDevicePorts.count(in_portId) == 0) { |
| 442 | LOG(ERROR) << __func__ << ": port id " << in_portId << " is not a connected device port"; |
| 443 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 444 | } |
| 445 | auto& configs = getConfig().portConfigs; |
| 446 | auto& initials = getConfig().initialConfigs; |
| 447 | auto configIt = std::find_if(configs.begin(), configs.end(), [&](const auto& config) { |
| 448 | if (config.portId == in_portId) { |
| 449 | // Check if the configuration was provided by the client. |
| 450 | const auto& initialIt = findById<AudioPortConfig>(initials, config.id); |
| 451 | return initialIt == initials.end() || config != *initialIt; |
| 452 | } |
| 453 | return false; |
| 454 | }); |
| 455 | if (configIt != configs.end()) { |
| 456 | LOG(ERROR) << __func__ << ": port id " << in_portId << " has a non-default config with id " |
| 457 | << configIt->id; |
| 458 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 459 | } |
| 460 | ports.erase(portIt); |
| 461 | mConnectedDevicePorts.erase(in_portId); |
| 462 | LOG(DEBUG) << __func__ << ": connected device port " << in_portId << " released"; |
| 463 | |
| 464 | auto& routes = getConfig().routes; |
| 465 | for (auto routesIt = routes.begin(); routesIt != routes.end();) { |
| 466 | if (routesIt->sinkPortId == in_portId) { |
| 467 | routesIt = routes.erase(routesIt); |
| 468 | } else { |
| 469 | // Note: the list of sourcePortIds can't become empty because there must |
| 470 | // be the id of the template port in the route. |
| 471 | erase_if(routesIt->sourcePortIds, [in_portId](auto src) { return src == in_portId; }); |
| 472 | ++routesIt; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | return ndk::ScopedAStatus::ok(); |
| 477 | } |
| 478 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 479 | ndk::ScopedAStatus Module::getAudioPatches(std::vector<AudioPatch>* _aidl_return) { |
| 480 | *_aidl_return = getConfig().patches; |
| 481 | LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " patches"; |
| 482 | return ndk::ScopedAStatus::ok(); |
| 483 | } |
| 484 | |
| 485 | ndk::ScopedAStatus Module::getAudioPort(int32_t in_portId, AudioPort* _aidl_return) { |
| 486 | auto& ports = getConfig().ports; |
| 487 | auto portIt = findById<AudioPort>(ports, in_portId); |
| 488 | if (portIt != ports.end()) { |
| 489 | *_aidl_return = *portIt; |
| 490 | LOG(DEBUG) << __func__ << ": returning port by id " << in_portId; |
| 491 | return ndk::ScopedAStatus::ok(); |
| 492 | } |
| 493 | LOG(ERROR) << __func__ << ": port id " << in_portId << " not found"; |
| 494 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 495 | } |
| 496 | |
| 497 | ndk::ScopedAStatus Module::getAudioPortConfigs(std::vector<AudioPortConfig>* _aidl_return) { |
| 498 | *_aidl_return = getConfig().portConfigs; |
| 499 | LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " port configs"; |
| 500 | return ndk::ScopedAStatus::ok(); |
| 501 | } |
| 502 | |
| 503 | ndk::ScopedAStatus Module::getAudioPorts(std::vector<AudioPort>* _aidl_return) { |
| 504 | *_aidl_return = getConfig().ports; |
| 505 | LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " ports"; |
| 506 | return ndk::ScopedAStatus::ok(); |
| 507 | } |
| 508 | |
| 509 | ndk::ScopedAStatus Module::getAudioRoutes(std::vector<AudioRoute>* _aidl_return) { |
| 510 | *_aidl_return = getConfig().routes; |
| 511 | LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " routes"; |
| 512 | return ndk::ScopedAStatus::ok(); |
| 513 | } |
| 514 | |
Mikhail Naganov | 00603d1 | 2022-05-02 22:52:13 +0000 | [diff] [blame] | 515 | ndk::ScopedAStatus Module::getAudioRoutesForAudioPort(int32_t in_portId, |
| 516 | std::vector<AudioRoute>* _aidl_return) { |
| 517 | auto& ports = getConfig().ports; |
| 518 | if (auto portIt = findById<AudioPort>(ports, in_portId); portIt == ports.end()) { |
| 519 | LOG(ERROR) << __func__ << ": port id " << in_portId << " not found"; |
| 520 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 521 | } |
| 522 | auto& routes = getConfig().routes; |
| 523 | std::copy_if(routes.begin(), routes.end(), std::back_inserter(*_aidl_return), |
| 524 | [&](const auto& r) { |
| 525 | const auto& srcs = r.sourcePortIds; |
| 526 | return r.sinkPortId == in_portId || |
| 527 | std::find(srcs.begin(), srcs.end(), in_portId) != srcs.end(); |
| 528 | }); |
| 529 | return ndk::ScopedAStatus::ok(); |
| 530 | } |
| 531 | |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 532 | ndk::ScopedAStatus Module::openInputStream(const OpenInputStreamArguments& in_args, |
| 533 | OpenInputStreamReturn* _aidl_return) { |
| 534 | LOG(DEBUG) << __func__ << ": port config id " << in_args.portConfigId << ", buffer size " |
| 535 | << in_args.bufferSizeFrames << " frames"; |
| 536 | AudioPort* port = nullptr; |
| 537 | if (auto status = findPortIdForNewStream(in_args.portConfigId, &port); !status.isOk()) { |
| 538 | return status; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 539 | } |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 540 | if (port->flags.getTag() != AudioIoFlags::Tag::input) { |
| 541 | LOG(ERROR) << __func__ << ": port config id " << in_args.portConfigId |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 542 | << " does not correspond to an input mix port"; |
| 543 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 544 | } |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 545 | StreamContext context; |
Mikhail Naganov | 30301a4 | 2022-09-13 01:20:45 +0000 | [diff] [blame] | 546 | if (auto status = createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames, nullptr, |
| 547 | &context); |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 548 | !status.isOk()) { |
| 549 | return status; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 550 | } |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 551 | context.fillDescriptor(&_aidl_return->desc); |
Mikhail Naganov | e9f10fc | 2022-10-14 23:31:52 +0000 | [diff] [blame] | 552 | std::shared_ptr<StreamIn> stream; |
| 553 | if (auto status = StreamIn::createInstance(in_args.sinkMetadata, std::move(context), |
| 554 | mConfig->microphones, &stream); |
| 555 | !status.isOk()) { |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 556 | return status; |
| 557 | } |
| 558 | StreamWrapper streamWrapper(stream); |
Mikhail Naganov | df5feba | 2022-12-15 00:11:14 +0000 | [diff] [blame] | 559 | AIBinder_setMinSchedulerPolicy(streamWrapper.getBinder().get(), SCHED_NORMAL, |
| 560 | ANDROID_PRIORITY_AUDIO); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 561 | auto patchIt = mPatches.find(in_args.portConfigId); |
| 562 | if (patchIt != mPatches.end()) { |
Mikhail Naganov | ef6bc74 | 2022-10-06 00:14:19 +0000 | [diff] [blame] | 563 | streamWrapper.setStreamIsConnected(findConnectedDevices(in_args.portConfigId)); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 564 | } |
| 565 | mStreams.insert(port->id, in_args.portConfigId, std::move(streamWrapper)); |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 566 | _aidl_return->stream = std::move(stream); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 567 | return ndk::ScopedAStatus::ok(); |
| 568 | } |
| 569 | |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 570 | ndk::ScopedAStatus Module::openOutputStream(const OpenOutputStreamArguments& in_args, |
| 571 | OpenOutputStreamReturn* _aidl_return) { |
| 572 | LOG(DEBUG) << __func__ << ": port config id " << in_args.portConfigId << ", has offload info? " |
| 573 | << (in_args.offloadInfo.has_value()) << ", buffer size " << in_args.bufferSizeFrames |
| 574 | << " frames"; |
| 575 | AudioPort* port = nullptr; |
| 576 | if (auto status = findPortIdForNewStream(in_args.portConfigId, &port); !status.isOk()) { |
| 577 | return status; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 578 | } |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 579 | if (port->flags.getTag() != AudioIoFlags::Tag::output) { |
| 580 | LOG(ERROR) << __func__ << ": port config id " << in_args.portConfigId |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 581 | << " does not correspond to an output mix port"; |
| 582 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 583 | } |
Mikhail Naganov | a2c5ddf | 2022-09-12 22:57:14 +0000 | [diff] [blame] | 584 | const bool isOffload = isBitPositionFlagSet(port->flags.get<AudioIoFlags::Tag::output>(), |
| 585 | AudioOutputFlags::COMPRESS_OFFLOAD); |
| 586 | if (isOffload && !in_args.offloadInfo.has_value()) { |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 587 | LOG(ERROR) << __func__ << ": port id " << port->id |
Mikhail Naganov | 111e0ce | 2022-06-17 21:41:19 +0000 | [diff] [blame] | 588 | << " has COMPRESS_OFFLOAD flag set, requires offload info"; |
| 589 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 590 | } |
Mikhail Naganov | 30301a4 | 2022-09-13 01:20:45 +0000 | [diff] [blame] | 591 | const bool isNonBlocking = isBitPositionFlagSet(port->flags.get<AudioIoFlags::Tag::output>(), |
| 592 | AudioOutputFlags::NON_BLOCKING); |
| 593 | if (isNonBlocking && in_args.callback == nullptr) { |
| 594 | LOG(ERROR) << __func__ << ": port id " << port->id |
| 595 | << " has NON_BLOCKING flag set, requires async callback"; |
| 596 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 597 | } |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 598 | StreamContext context; |
Mikhail Naganov | 30301a4 | 2022-09-13 01:20:45 +0000 | [diff] [blame] | 599 | if (auto status = createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames, |
| 600 | isNonBlocking ? in_args.callback : nullptr, &context); |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 601 | !status.isOk()) { |
| 602 | return status; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 603 | } |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 604 | context.fillDescriptor(&_aidl_return->desc); |
Mikhail Naganov | e9f10fc | 2022-10-14 23:31:52 +0000 | [diff] [blame] | 605 | std::shared_ptr<StreamOut> stream; |
| 606 | if (auto status = StreamOut::createInstance(in_args.sourceMetadata, std::move(context), |
| 607 | in_args.offloadInfo, &stream); |
| 608 | !status.isOk()) { |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 609 | return status; |
| 610 | } |
| 611 | StreamWrapper streamWrapper(stream); |
Mikhail Naganov | df5feba | 2022-12-15 00:11:14 +0000 | [diff] [blame] | 612 | AIBinder_setMinSchedulerPolicy(streamWrapper.getBinder().get(), SCHED_NORMAL, |
| 613 | ANDROID_PRIORITY_AUDIO); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 614 | auto patchIt = mPatches.find(in_args.portConfigId); |
| 615 | if (patchIt != mPatches.end()) { |
Mikhail Naganov | ef6bc74 | 2022-10-06 00:14:19 +0000 | [diff] [blame] | 616 | streamWrapper.setStreamIsConnected(findConnectedDevices(in_args.portConfigId)); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 617 | } |
| 618 | mStreams.insert(port->id, in_args.portConfigId, std::move(streamWrapper)); |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 619 | _aidl_return->stream = std::move(stream); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 620 | return ndk::ScopedAStatus::ok(); |
| 621 | } |
| 622 | |
Mikhail Naganov | 7492720 | 2022-12-19 16:37:14 +0000 | [diff] [blame] | 623 | ndk::ScopedAStatus Module::getSupportedPlaybackRateFactors( |
| 624 | SupportedPlaybackRateFactors* _aidl_return) { |
| 625 | LOG(DEBUG) << __func__; |
| 626 | (void)_aidl_return; |
| 627 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 628 | } |
| 629 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 630 | ndk::ScopedAStatus Module::setAudioPatch(const AudioPatch& in_requested, AudioPatch* _aidl_return) { |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 631 | LOG(DEBUG) << __func__ << ": requested patch " << in_requested.toString(); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 632 | if (in_requested.sourcePortConfigIds.empty()) { |
| 633 | LOG(ERROR) << __func__ << ": requested patch has empty sources list"; |
| 634 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 635 | } |
| 636 | if (!all_unique<int32_t>(in_requested.sourcePortConfigIds)) { |
| 637 | LOG(ERROR) << __func__ << ": requested patch has duplicate ids in the sources list"; |
| 638 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 639 | } |
| 640 | if (in_requested.sinkPortConfigIds.empty()) { |
| 641 | LOG(ERROR) << __func__ << ": requested patch has empty sinks list"; |
| 642 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 643 | } |
| 644 | if (!all_unique<int32_t>(in_requested.sinkPortConfigIds)) { |
| 645 | LOG(ERROR) << __func__ << ": requested patch has duplicate ids in the sinks list"; |
| 646 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 647 | } |
| 648 | |
| 649 | auto& configs = getConfig().portConfigs; |
| 650 | std::vector<int32_t> missingIds; |
| 651 | auto sources = |
| 652 | selectByIds<AudioPortConfig>(configs, in_requested.sourcePortConfigIds, &missingIds); |
| 653 | if (!missingIds.empty()) { |
| 654 | LOG(ERROR) << __func__ << ": following source port config ids not found: " |
| 655 | << ::android::internal::ToString(missingIds); |
| 656 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 657 | } |
| 658 | auto sinks = selectByIds<AudioPortConfig>(configs, in_requested.sinkPortConfigIds, &missingIds); |
| 659 | if (!missingIds.empty()) { |
| 660 | LOG(ERROR) << __func__ << ": following sink port config ids not found: " |
| 661 | << ::android::internal::ToString(missingIds); |
| 662 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 663 | } |
| 664 | // bool indicates whether a non-exclusive route is available. |
| 665 | // If only an exclusive route is available, that means the patch can not be |
| 666 | // established if there is any other patch which currently uses the sink port. |
| 667 | std::map<int32_t, bool> allowedSinkPorts; |
| 668 | auto& routes = getConfig().routes; |
| 669 | for (auto src : sources) { |
| 670 | for (const auto& r : routes) { |
| 671 | const auto& srcs = r.sourcePortIds; |
| 672 | if (std::find(srcs.begin(), srcs.end(), src->portId) != srcs.end()) { |
| 673 | if (!allowedSinkPorts[r.sinkPortId]) { // prefer non-exclusive |
| 674 | allowedSinkPorts[r.sinkPortId] = !r.isExclusive; |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | for (auto sink : sinks) { |
| 680 | if (allowedSinkPorts.count(sink->portId) == 0) { |
| 681 | LOG(ERROR) << __func__ << ": there is no route to the sink port id " << sink->portId; |
| 682 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | auto& patches = getConfig().patches; |
| 687 | auto existing = patches.end(); |
| 688 | std::optional<decltype(mPatches)> patchesBackup; |
| 689 | if (in_requested.id != 0) { |
| 690 | existing = findById<AudioPatch>(patches, in_requested.id); |
| 691 | if (existing != patches.end()) { |
| 692 | patchesBackup = mPatches; |
| 693 | cleanUpPatch(existing->id); |
| 694 | } else { |
| 695 | LOG(ERROR) << __func__ << ": not found existing patch id " << in_requested.id; |
| 696 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 697 | } |
| 698 | } |
| 699 | // Validate the requested patch. |
| 700 | for (const auto& [sinkPortId, nonExclusive] : allowedSinkPorts) { |
| 701 | if (!nonExclusive && mPatches.count(sinkPortId) != 0) { |
| 702 | LOG(ERROR) << __func__ << ": sink port id " << sinkPortId |
| 703 | << "is exclusive and is already used by some other patch"; |
| 704 | if (patchesBackup.has_value()) { |
| 705 | mPatches = std::move(*patchesBackup); |
| 706 | } |
| 707 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 708 | } |
| 709 | } |
| 710 | *_aidl_return = in_requested; |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 711 | _aidl_return->minimumStreamBufferSizeFrames = kMinimumStreamBufferSizeFrames; |
| 712 | _aidl_return->latenciesMs.clear(); |
| 713 | _aidl_return->latenciesMs.insert(_aidl_return->latenciesMs.end(), |
| 714 | _aidl_return->sinkPortConfigIds.size(), kLatencyMs); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 715 | AudioPatch oldPatch{}; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 716 | if (existing == patches.end()) { |
| 717 | _aidl_return->id = getConfig().nextPatchId++; |
| 718 | patches.push_back(*_aidl_return); |
| 719 | existing = patches.begin() + (patches.size() - 1); |
| 720 | } else { |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 721 | oldPatch = *existing; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 722 | *existing = *_aidl_return; |
| 723 | } |
| 724 | registerPatch(*existing); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 725 | updateStreamsConnectedState(oldPatch, *_aidl_return); |
| 726 | |
| 727 | LOG(DEBUG) << __func__ << ": " << (oldPatch.id == 0 ? "created" : "updated") << " patch " |
| 728 | << _aidl_return->toString(); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 729 | return ndk::ScopedAStatus::ok(); |
| 730 | } |
| 731 | |
| 732 | ndk::ScopedAStatus Module::setAudioPortConfig(const AudioPortConfig& in_requested, |
| 733 | AudioPortConfig* out_suggested, bool* _aidl_return) { |
| 734 | LOG(DEBUG) << __func__ << ": requested " << in_requested.toString(); |
| 735 | auto& configs = getConfig().portConfigs; |
| 736 | auto existing = configs.end(); |
| 737 | if (in_requested.id != 0) { |
| 738 | if (existing = findById<AudioPortConfig>(configs, in_requested.id); |
| 739 | existing == configs.end()) { |
| 740 | LOG(ERROR) << __func__ << ": existing port config id " << in_requested.id |
| 741 | << " not found"; |
| 742 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | const int portId = existing != configs.end() ? existing->portId : in_requested.portId; |
| 747 | if (portId == 0) { |
| 748 | LOG(ERROR) << __func__ << ": input port config does not specify portId"; |
| 749 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 750 | } |
| 751 | auto& ports = getConfig().ports; |
| 752 | auto portIt = findById<AudioPort>(ports, portId); |
| 753 | if (portIt == ports.end()) { |
| 754 | LOG(ERROR) << __func__ << ": input port config points to non-existent portId " << portId; |
| 755 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 756 | } |
| 757 | if (existing != configs.end()) { |
| 758 | *out_suggested = *existing; |
| 759 | } else { |
| 760 | AudioPortConfig newConfig; |
| 761 | if (generateDefaultPortConfig(*portIt, &newConfig)) { |
| 762 | *out_suggested = newConfig; |
| 763 | } else { |
| 764 | LOG(ERROR) << __func__ << ": unable generate a default config for port " << portId; |
| 765 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 766 | } |
| 767 | } |
| 768 | // From this moment, 'out_suggested' is either an existing port config, |
| 769 | // or a new generated config. Now attempt to update it according to the specified |
| 770 | // fields of 'in_requested'. |
| 771 | |
| 772 | bool requestedIsValid = true, requestedIsFullySpecified = true; |
| 773 | |
| 774 | AudioIoFlags portFlags = portIt->flags; |
| 775 | if (in_requested.flags.has_value()) { |
| 776 | if (in_requested.flags.value() != portFlags) { |
| 777 | LOG(WARNING) << __func__ << ": requested flags " |
| 778 | << in_requested.flags.value().toString() << " do not match port's " |
| 779 | << portId << " flags " << portFlags.toString(); |
| 780 | requestedIsValid = false; |
| 781 | } |
| 782 | } else { |
| 783 | requestedIsFullySpecified = false; |
| 784 | } |
| 785 | |
| 786 | AudioProfile portProfile; |
| 787 | if (in_requested.format.has_value()) { |
| 788 | const auto& format = in_requested.format.value(); |
| 789 | if (findAudioProfile(*portIt, format, &portProfile)) { |
| 790 | out_suggested->format = format; |
| 791 | } else { |
| 792 | LOG(WARNING) << __func__ << ": requested format " << format.toString() |
| 793 | << " is not found in port's " << portId << " profiles"; |
| 794 | requestedIsValid = false; |
| 795 | } |
| 796 | } else { |
| 797 | requestedIsFullySpecified = false; |
| 798 | } |
| 799 | if (!findAudioProfile(*portIt, out_suggested->format.value(), &portProfile)) { |
| 800 | LOG(ERROR) << __func__ << ": port " << portId << " does not support format " |
| 801 | << out_suggested->format.value().toString() << " anymore"; |
| 802 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 803 | } |
| 804 | |
| 805 | if (in_requested.channelMask.has_value()) { |
| 806 | const auto& channelMask = in_requested.channelMask.value(); |
| 807 | if (find(portProfile.channelMasks.begin(), portProfile.channelMasks.end(), channelMask) != |
| 808 | portProfile.channelMasks.end()) { |
| 809 | out_suggested->channelMask = channelMask; |
| 810 | } else { |
| 811 | LOG(WARNING) << __func__ << ": requested channel mask " << channelMask.toString() |
| 812 | << " is not supported for the format " << portProfile.format.toString() |
| 813 | << " by the port " << portId; |
| 814 | requestedIsValid = false; |
| 815 | } |
| 816 | } else { |
| 817 | requestedIsFullySpecified = false; |
| 818 | } |
| 819 | |
| 820 | if (in_requested.sampleRate.has_value()) { |
| 821 | const auto& sampleRate = in_requested.sampleRate.value(); |
| 822 | if (find(portProfile.sampleRates.begin(), portProfile.sampleRates.end(), |
| 823 | sampleRate.value) != portProfile.sampleRates.end()) { |
| 824 | out_suggested->sampleRate = sampleRate; |
| 825 | } else { |
| 826 | LOG(WARNING) << __func__ << ": requested sample rate " << sampleRate.value |
| 827 | << " is not supported for the format " << portProfile.format.toString() |
| 828 | << " by the port " << portId; |
| 829 | requestedIsValid = false; |
| 830 | } |
| 831 | } else { |
| 832 | requestedIsFullySpecified = false; |
| 833 | } |
| 834 | |
| 835 | if (in_requested.gain.has_value()) { |
| 836 | // Let's pretend that gain can always be applied. |
| 837 | out_suggested->gain = in_requested.gain.value(); |
| 838 | } |
| 839 | |
| 840 | if (existing == configs.end() && requestedIsValid && requestedIsFullySpecified) { |
| 841 | out_suggested->id = getConfig().nextPortId++; |
| 842 | configs.push_back(*out_suggested); |
| 843 | *_aidl_return = true; |
| 844 | LOG(DEBUG) << __func__ << ": created new port config " << out_suggested->toString(); |
| 845 | } else if (existing != configs.end() && requestedIsValid) { |
| 846 | *existing = *out_suggested; |
| 847 | *_aidl_return = true; |
| 848 | LOG(DEBUG) << __func__ << ": updated port config " << out_suggested->toString(); |
| 849 | } else { |
| 850 | LOG(DEBUG) << __func__ << ": not applied; existing config ? " << (existing != configs.end()) |
| 851 | << "; requested is valid? " << requestedIsValid << ", fully specified? " |
| 852 | << requestedIsFullySpecified; |
| 853 | *_aidl_return = false; |
| 854 | } |
| 855 | return ndk::ScopedAStatus::ok(); |
| 856 | } |
| 857 | |
| 858 | ndk::ScopedAStatus Module::resetAudioPatch(int32_t in_patchId) { |
| 859 | auto& patches = getConfig().patches; |
| 860 | auto patchIt = findById<AudioPatch>(patches, in_patchId); |
| 861 | if (patchIt != patches.end()) { |
| 862 | cleanUpPatch(patchIt->id); |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 863 | updateStreamsConnectedState(*patchIt, AudioPatch{}); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 864 | patches.erase(patchIt); |
| 865 | LOG(DEBUG) << __func__ << ": erased patch " << in_patchId; |
| 866 | return ndk::ScopedAStatus::ok(); |
| 867 | } |
| 868 | LOG(ERROR) << __func__ << ": patch id " << in_patchId << " not found"; |
| 869 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 870 | } |
| 871 | |
| 872 | ndk::ScopedAStatus Module::resetAudioPortConfig(int32_t in_portConfigId) { |
| 873 | auto& configs = getConfig().portConfigs; |
| 874 | auto configIt = findById<AudioPortConfig>(configs, in_portConfigId); |
| 875 | if (configIt != configs.end()) { |
| 876 | if (mStreams.count(in_portConfigId) != 0) { |
| 877 | LOG(ERROR) << __func__ << ": port config id " << in_portConfigId |
| 878 | << " has a stream opened on it"; |
| 879 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 880 | } |
| 881 | auto patchIt = mPatches.find(in_portConfigId); |
| 882 | if (patchIt != mPatches.end()) { |
| 883 | LOG(ERROR) << __func__ << ": port config id " << in_portConfigId |
| 884 | << " is used by the patch with id " << patchIt->second; |
| 885 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 886 | } |
| 887 | auto& initials = getConfig().initialConfigs; |
| 888 | auto initialIt = findById<AudioPortConfig>(initials, in_portConfigId); |
| 889 | if (initialIt == initials.end()) { |
| 890 | configs.erase(configIt); |
| 891 | LOG(DEBUG) << __func__ << ": erased port config " << in_portConfigId; |
| 892 | } else if (*configIt != *initialIt) { |
| 893 | *configIt = *initialIt; |
| 894 | LOG(DEBUG) << __func__ << ": reset port config " << in_portConfigId; |
| 895 | } |
| 896 | return ndk::ScopedAStatus::ok(); |
| 897 | } |
| 898 | LOG(ERROR) << __func__ << ": port config id " << in_portConfigId << " not found"; |
| 899 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 900 | } |
| 901 | |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 902 | ndk::ScopedAStatus Module::getMasterMute(bool* _aidl_return) { |
| 903 | *_aidl_return = mMasterMute; |
| 904 | LOG(DEBUG) << __func__ << ": returning " << *_aidl_return; |
| 905 | return ndk::ScopedAStatus::ok(); |
| 906 | } |
| 907 | |
| 908 | ndk::ScopedAStatus Module::setMasterMute(bool in_mute) { |
| 909 | LOG(DEBUG) << __func__ << ": " << in_mute; |
| 910 | mMasterMute = in_mute; |
| 911 | return ndk::ScopedAStatus::ok(); |
| 912 | } |
| 913 | |
| 914 | ndk::ScopedAStatus Module::getMasterVolume(float* _aidl_return) { |
| 915 | *_aidl_return = mMasterVolume; |
| 916 | LOG(DEBUG) << __func__ << ": returning " << *_aidl_return; |
| 917 | return ndk::ScopedAStatus::ok(); |
| 918 | } |
| 919 | |
| 920 | ndk::ScopedAStatus Module::setMasterVolume(float in_volume) { |
| 921 | LOG(DEBUG) << __func__ << ": " << in_volume; |
| 922 | if (in_volume >= 0.0f && in_volume <= 1.0f) { |
| 923 | mMasterVolume = in_volume; |
| 924 | return ndk::ScopedAStatus::ok(); |
| 925 | } |
| 926 | LOG(ERROR) << __func__ << ": invalid master volume value: " << in_volume; |
| 927 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 928 | } |
| 929 | |
| 930 | ndk::ScopedAStatus Module::getMicMute(bool* _aidl_return) { |
| 931 | *_aidl_return = mMicMute; |
| 932 | LOG(DEBUG) << __func__ << ": returning " << *_aidl_return; |
| 933 | return ndk::ScopedAStatus::ok(); |
| 934 | } |
| 935 | |
| 936 | ndk::ScopedAStatus Module::setMicMute(bool in_mute) { |
| 937 | LOG(DEBUG) << __func__ << ": " << in_mute; |
| 938 | mMicMute = in_mute; |
| 939 | return ndk::ScopedAStatus::ok(); |
| 940 | } |
| 941 | |
Mikhail Naganov | ef6bc74 | 2022-10-06 00:14:19 +0000 | [diff] [blame] | 942 | ndk::ScopedAStatus Module::getMicrophones(std::vector<MicrophoneInfo>* _aidl_return) { |
| 943 | *_aidl_return = mConfig->microphones; |
| 944 | LOG(DEBUG) << __func__ << ": returning " << ::android::internal::ToString(*_aidl_return); |
| 945 | return ndk::ScopedAStatus::ok(); |
| 946 | } |
| 947 | |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 948 | ndk::ScopedAStatus Module::updateAudioMode(AudioMode in_mode) { |
| 949 | // No checks for supported audio modes here, it's an informative notification. |
| 950 | LOG(DEBUG) << __func__ << ": " << toString(in_mode); |
| 951 | return ndk::ScopedAStatus::ok(); |
| 952 | } |
| 953 | |
| 954 | ndk::ScopedAStatus Module::updateScreenRotation(ScreenRotation in_rotation) { |
| 955 | LOG(DEBUG) << __func__ << ": " << toString(in_rotation); |
| 956 | return ndk::ScopedAStatus::ok(); |
| 957 | } |
| 958 | |
| 959 | ndk::ScopedAStatus Module::updateScreenState(bool in_isTurnedOn) { |
| 960 | LOG(DEBUG) << __func__ << ": " << in_isTurnedOn; |
| 961 | return ndk::ScopedAStatus::ok(); |
| 962 | } |
| 963 | |
Vlad Popa | 83a6d82 | 2022-11-07 13:53:57 +0100 | [diff] [blame] | 964 | ndk::ScopedAStatus Module::getSoundDose(std::shared_ptr<ISoundDose>* _aidl_return) { |
Vlad Popa | 943b7e2 | 2022-12-08 14:24:12 +0100 | [diff] [blame] | 965 | if (mSoundDose == nullptr) { |
Vlad Popa | 2afbd1e | 2022-12-28 17:04:58 +0100 | [diff] [blame] | 966 | mSoundDose = ndk::SharedRefBase::make<sounddose::SoundDose>(); |
Mikhail Naganov | df5feba | 2022-12-15 00:11:14 +0000 | [diff] [blame] | 967 | mSoundDoseBinder = mSoundDose->asBinder(); |
| 968 | AIBinder_setMinSchedulerPolicy(mSoundDoseBinder.get(), SCHED_NORMAL, |
| 969 | ANDROID_PRIORITY_AUDIO); |
Vlad Popa | 943b7e2 | 2022-12-08 14:24:12 +0100 | [diff] [blame] | 970 | } |
| 971 | *_aidl_return = mSoundDose; |
| 972 | LOG(DEBUG) << __func__ << ": returning instance of ISoundDose: " << _aidl_return->get(); |
Vlad Popa | 83a6d82 | 2022-11-07 13:53:57 +0100 | [diff] [blame] | 973 | return ndk::ScopedAStatus::ok(); |
| 974 | } |
| 975 | |
Mikhail Naganov | e9f10fc | 2022-10-14 23:31:52 +0000 | [diff] [blame] | 976 | ndk::ScopedAStatus Module::generateHwAvSyncId(int32_t* _aidl_return) { |
| 977 | LOG(DEBUG) << __func__; |
| 978 | (void)_aidl_return; |
| 979 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 980 | } |
| 981 | |
Mikhail Naganov | 20047bc | 2023-01-05 20:16:07 +0000 | [diff] [blame^] | 982 | const std::string Module::VendorDebug::kForceTransientBurstName = "aosp.forceTransientBurst"; |
| 983 | |
Mikhail Naganov | e9f10fc | 2022-10-14 23:31:52 +0000 | [diff] [blame] | 984 | ndk::ScopedAStatus Module::getVendorParameters(const std::vector<std::string>& in_ids, |
| 985 | std::vector<VendorParameter>* _aidl_return) { |
| 986 | LOG(DEBUG) << __func__ << ": id count: " << in_ids.size(); |
Mikhail Naganov | 20047bc | 2023-01-05 20:16:07 +0000 | [diff] [blame^] | 987 | bool allParametersKnown = true; |
| 988 | for (const auto& id : in_ids) { |
| 989 | if (id == VendorDebug::kForceTransientBurstName) { |
| 990 | VendorParameter forceTransientBurst{.id = id}; |
| 991 | forceTransientBurst.ext.setParcelable(Boolean{mVendorDebug.forceTransientBurst}); |
| 992 | _aidl_return->push_back(std::move(forceTransientBurst)); |
| 993 | } else { |
| 994 | allParametersKnown = false; |
| 995 | LOG(ERROR) << __func__ << ": unrecognized parameter \"" << id << "\""; |
| 996 | } |
| 997 | } |
| 998 | if (allParametersKnown) return ndk::ScopedAStatus::ok(); |
| 999 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
Mikhail Naganov | e9f10fc | 2022-10-14 23:31:52 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | ndk::ScopedAStatus Module::setVendorParameters(const std::vector<VendorParameter>& in_parameters, |
| 1003 | bool in_async) { |
| 1004 | LOG(DEBUG) << __func__ << ": parameter count " << in_parameters.size() |
| 1005 | << ", async: " << in_async; |
Mikhail Naganov | 20047bc | 2023-01-05 20:16:07 +0000 | [diff] [blame^] | 1006 | bool allParametersKnown = true; |
| 1007 | for (const auto& p : in_parameters) { |
| 1008 | if (p.id == VendorDebug::kForceTransientBurstName) { |
| 1009 | std::optional<Boolean> value; |
| 1010 | binder_status_t result = p.ext.getParcelable(&value); |
| 1011 | if (result == STATUS_OK) { |
| 1012 | mVendorDebug.forceTransientBurst = value.value().value; |
| 1013 | } else { |
| 1014 | LOG(ERROR) << __func__ << ": failed to read the value of the parameter \"" << p.id |
| 1015 | << "\""; |
| 1016 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 1017 | } |
| 1018 | } else { |
| 1019 | allParametersKnown = false; |
| 1020 | LOG(ERROR) << __func__ << ": unrecognized parameter \"" << p.id << "\""; |
| 1021 | } |
| 1022 | } |
| 1023 | if (allParametersKnown) return ndk::ScopedAStatus::ok(); |
| 1024 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
Mikhail Naganov | e9f10fc | 2022-10-14 23:31:52 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Mikhail Naganov | fb1acde | 2022-12-12 18:57:36 +0000 | [diff] [blame] | 1027 | ndk::ScopedAStatus Module::addDeviceEffect( |
| 1028 | int32_t in_portConfigId, |
| 1029 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& in_effect) { |
| 1030 | if (in_effect == nullptr) { |
| 1031 | LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", null effect"; |
| 1032 | } else { |
| 1033 | LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", effect Binder " |
| 1034 | << in_effect->asBinder().get(); |
| 1035 | } |
| 1036 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 1037 | } |
| 1038 | |
| 1039 | ndk::ScopedAStatus Module::removeDeviceEffect( |
| 1040 | int32_t in_portConfigId, |
| 1041 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& in_effect) { |
| 1042 | if (in_effect == nullptr) { |
| 1043 | LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", null effect"; |
| 1044 | } else { |
| 1045 | LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", effect Binder " |
| 1046 | << in_effect->asBinder().get(); |
| 1047 | } |
| 1048 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 1049 | } |
| 1050 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 1051 | } // namespace aidl::android::hardware::audio::core |