Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 <stdio.h> |
| 18 | |
| 19 | #define LOG_TAG "DeviceHalHidl" |
| 20 | //#define LOG_NDEBUG 0 |
| 21 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 22 | #include <cutils/native_handle.h> |
| 23 | #include <hwbinder/IPCThreadState.h> |
jiabin | daf4995 | 2019-11-22 14:10:57 -0800 | [diff] [blame] | 24 | #include <media/AudioContainers.h> |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 25 | #include <utils/Log.h> |
| 26 | |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 27 | #include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h) |
| 28 | #include <HidlUtils.h> |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 29 | #include <common/all-versions/VersionUtils.h> |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 30 | #include <util/CoreUtils.h> |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 31 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 32 | #include "DeviceHalHidl.h" |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 33 | #include "EffectHalHidl.h" |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 34 | #include "ParameterUtils.h" |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 35 | #include "StreamHalHidl.h" |
| 36 | |
Mikhail Naganov | 9ccaa16 | 2018-12-12 10:27:29 -0800 | [diff] [blame] | 37 | using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils; |
Kevin Rocard | 7a9f05a | 2018-11-28 16:52:25 -0800 | [diff] [blame] | 38 | using ::android::hardware::audio::common::utils::EnumBitfield; |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 39 | using ::android::hardware::audio::CPP_VERSION::implementation::CoreUtils; |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 40 | using ::android::hardware::hidl_string; |
| 41 | using ::android::hardware::hidl_vec; |
| 42 | |
| 43 | namespace android { |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 44 | namespace CPP_VERSION { |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 45 | |
Mikhail Naganov | 9ccaa16 | 2018-12-12 10:27:29 -0800 | [diff] [blame] | 46 | using namespace ::android::hardware::audio::common::CPP_VERSION; |
| 47 | using namespace ::android::hardware::audio::CPP_VERSION; |
| 48 | |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 49 | using EffectHalHidl = ::android::effect::CPP_VERSION::EffectHalHidl; |
| 50 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 51 | DeviceHalHidl::DeviceHalHidl(const sp<IDevice>& device) |
| 52 | : ConversionHelperHidl("Device"), mDevice(device), |
| 53 | mPrimaryDevice(IPrimaryDevice::castFrom(device)) { |
| 54 | } |
| 55 | |
| 56 | DeviceHalHidl::~DeviceHalHidl() { |
| 57 | if (mDevice != 0) { |
Mikhail Naganov | 3355e44 | 2019-11-20 14:20:01 -0800 | [diff] [blame] | 58 | #if MAJOR_VERSION <= 5 |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 59 | mDevice.clear(); |
| 60 | hardware::IPCThreadState::self()->flushCommands(); |
Mikhail Naganov | 3355e44 | 2019-11-20 14:20:01 -0800 | [diff] [blame] | 61 | #elif MAJOR_VERSION >= 6 |
| 62 | mDevice->close(); |
| 63 | #endif |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
| 67 | status_t DeviceHalHidl::getSupportedDevices(uint32_t*) { |
| 68 | // Obsolete. |
| 69 | return INVALID_OPERATION; |
| 70 | } |
| 71 | |
| 72 | status_t DeviceHalHidl::initCheck() { |
| 73 | if (mDevice == 0) return NO_INIT; |
| 74 | return processReturn("initCheck", mDevice->initCheck()); |
| 75 | } |
| 76 | |
| 77 | status_t DeviceHalHidl::setVoiceVolume(float volume) { |
| 78 | if (mDevice == 0) return NO_INIT; |
| 79 | if (mPrimaryDevice == 0) return INVALID_OPERATION; |
| 80 | return processReturn("setVoiceVolume", mPrimaryDevice->setVoiceVolume(volume)); |
| 81 | } |
| 82 | |
| 83 | status_t DeviceHalHidl::setMasterVolume(float volume) { |
| 84 | if (mDevice == 0) return NO_INIT; |
Mikhail Naganov | ae1f662 | 2019-02-21 15:20:05 -0800 | [diff] [blame] | 85 | return processReturn("setMasterVolume", mDevice->setMasterVolume(volume)); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | status_t DeviceHalHidl::getMasterVolume(float *volume) { |
| 89 | if (mDevice == 0) return NO_INIT; |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 90 | Result retval; |
Mikhail Naganov | ae1f662 | 2019-02-21 15:20:05 -0800 | [diff] [blame] | 91 | Return<void> ret = mDevice->getMasterVolume( |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 92 | [&](Result r, float v) { |
| 93 | retval = r; |
| 94 | if (retval == Result::OK) { |
| 95 | *volume = v; |
| 96 | } |
| 97 | }); |
| 98 | return processReturn("getMasterVolume", ret, retval); |
| 99 | } |
| 100 | |
| 101 | status_t DeviceHalHidl::setMode(audio_mode_t mode) { |
| 102 | if (mDevice == 0) return NO_INIT; |
| 103 | if (mPrimaryDevice == 0) return INVALID_OPERATION; |
| 104 | return processReturn("setMode", mPrimaryDevice->setMode(AudioMode(mode))); |
| 105 | } |
| 106 | |
| 107 | status_t DeviceHalHidl::setMicMute(bool state) { |
| 108 | if (mDevice == 0) return NO_INIT; |
| 109 | return processReturn("setMicMute", mDevice->setMicMute(state)); |
| 110 | } |
| 111 | |
| 112 | status_t DeviceHalHidl::getMicMute(bool *state) { |
| 113 | if (mDevice == 0) return NO_INIT; |
| 114 | Result retval; |
| 115 | Return<void> ret = mDevice->getMicMute( |
| 116 | [&](Result r, bool mute) { |
| 117 | retval = r; |
| 118 | if (retval == Result::OK) { |
| 119 | *state = mute; |
| 120 | } |
| 121 | }); |
| 122 | return processReturn("getMicMute", ret, retval); |
| 123 | } |
| 124 | |
| 125 | status_t DeviceHalHidl::setMasterMute(bool state) { |
| 126 | if (mDevice == 0) return NO_INIT; |
| 127 | return processReturn("setMasterMute", mDevice->setMasterMute(state)); |
| 128 | } |
| 129 | |
| 130 | status_t DeviceHalHidl::getMasterMute(bool *state) { |
| 131 | if (mDevice == 0) return NO_INIT; |
| 132 | Result retval; |
| 133 | Return<void> ret = mDevice->getMasterMute( |
| 134 | [&](Result r, bool mute) { |
| 135 | retval = r; |
| 136 | if (retval == Result::OK) { |
| 137 | *state = mute; |
| 138 | } |
| 139 | }); |
| 140 | return processReturn("getMasterMute", ret, retval); |
| 141 | } |
| 142 | |
| 143 | status_t DeviceHalHidl::setParameters(const String8& kvPairs) { |
| 144 | if (mDevice == 0) return NO_INIT; |
| 145 | hidl_vec<ParameterValue> hidlParams; |
| 146 | status_t status = parametersFromHal(kvPairs, &hidlParams); |
| 147 | if (status != OK) return status; |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 148 | // TODO: change the API so that context and kvPairs are separated |
| 149 | return processReturn("setParameters", |
| 150 | utils::setParameters(mDevice, {} /* context */, hidlParams)); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | status_t DeviceHalHidl::getParameters(const String8& keys, String8 *values) { |
| 154 | values->clear(); |
| 155 | if (mDevice == 0) return NO_INIT; |
| 156 | hidl_vec<hidl_string> hidlKeys; |
| 157 | status_t status = keysFromHal(keys, &hidlKeys); |
| 158 | if (status != OK) return status; |
| 159 | Result retval; |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 160 | Return<void> ret = utils::getParameters(mDevice, |
| 161 | {} /* context */, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 162 | hidlKeys, |
| 163 | [&](Result r, const hidl_vec<ParameterValue>& parameters) { |
| 164 | retval = r; |
| 165 | if (retval == Result::OK) { |
| 166 | parametersToHal(parameters, values); |
| 167 | } |
| 168 | }); |
| 169 | return processReturn("getParameters", ret, retval); |
| 170 | } |
| 171 | |
| 172 | status_t DeviceHalHidl::getInputBufferSize( |
| 173 | const struct audio_config *config, size_t *size) { |
| 174 | if (mDevice == 0) return NO_INIT; |
| 175 | AudioConfig hidlConfig; |
Mikhail Naganov | f242ab2 | 2020-12-14 23:19:54 +0000 | [diff] [blame] | 176 | HidlUtils::audioConfigFromHal(*config, true /*isInput*/, &hidlConfig); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 177 | Result retval; |
| 178 | Return<void> ret = mDevice->getInputBufferSize( |
| 179 | hidlConfig, |
| 180 | [&](Result r, uint64_t bufferSize) { |
| 181 | retval = r; |
| 182 | if (retval == Result::OK) { |
| 183 | *size = static_cast<size_t>(bufferSize); |
| 184 | } |
| 185 | }); |
| 186 | return processReturn("getInputBufferSize", ret, retval); |
| 187 | } |
| 188 | |
| 189 | status_t DeviceHalHidl::openOutputStream( |
| 190 | audio_io_handle_t handle, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 191 | audio_devices_t deviceType, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 192 | audio_output_flags_t flags, |
| 193 | struct audio_config *config, |
| 194 | const char *address, |
| 195 | sp<StreamOutHalInterface> *outStream) { |
| 196 | if (mDevice == 0) return NO_INIT; |
| 197 | DeviceAddress hidlDevice; |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 198 | if (status_t status = CoreUtils::deviceAddressFromHal(deviceType, address, &hidlDevice); |
| 199 | status != OK) { |
| 200 | return status; |
| 201 | } |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 202 | AudioConfig hidlConfig; |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 203 | if (status_t status = HidlUtils::audioConfigFromHal(*config, false /*isInput*/, &hidlConfig); |
| 204 | status != OK) { |
| 205 | return status; |
| 206 | } |
| 207 | CoreUtils::AudioOutputFlags hidlFlags; |
| 208 | if (status_t status = CoreUtils::audioOutputFlagsFromHal(flags, &hidlFlags); status != OK) { |
| 209 | return status; |
| 210 | } |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 211 | Result retval = Result::NOT_INITIALIZED; |
| 212 | Return<void> ret = mDevice->openOutputStream( |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 213 | handle, hidlDevice, hidlConfig, hidlFlags, |
Kevin Rocard | 3d48dce | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 214 | #if MAJOR_VERSION >= 4 |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 215 | {} /* metadata */, |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 216 | #endif |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 217 | [&](Result r, const sp<IStreamOut>& result, const AudioConfig& suggestedConfig) { |
| 218 | retval = r; |
| 219 | if (retval == Result::OK) { |
| 220 | *outStream = new StreamOutHalHidl(result); |
| 221 | } |
| 222 | HidlUtils::audioConfigToHal(suggestedConfig, config); |
| 223 | }); |
| 224 | return processReturn("openOutputStream", ret, retval); |
| 225 | } |
| 226 | |
| 227 | status_t DeviceHalHidl::openInputStream( |
| 228 | audio_io_handle_t handle, |
| 229 | audio_devices_t devices, |
| 230 | struct audio_config *config, |
| 231 | audio_input_flags_t flags, |
| 232 | const char *address, |
| 233 | audio_source_t source, |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 234 | audio_devices_t outputDevice, |
| 235 | const char *outputDeviceAddress, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 236 | sp<StreamInHalInterface> *inStream) { |
| 237 | if (mDevice == 0) return NO_INIT; |
| 238 | DeviceAddress hidlDevice; |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 239 | if (status_t status = CoreUtils::deviceAddressFromHal(devices, address, &hidlDevice); |
| 240 | status != OK) { |
| 241 | return status; |
| 242 | } |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 243 | AudioConfig hidlConfig; |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 244 | if (status_t status = HidlUtils::audioConfigFromHal(*config, true /*isInput*/, &hidlConfig); |
| 245 | status != OK) { |
| 246 | return status; |
| 247 | } |
| 248 | CoreUtils::AudioInputFlags hidlFlags; |
| 249 | if (status_t status = CoreUtils::audioInputFlagsFromHal(flags, &hidlFlags); status != OK) { |
| 250 | return status; |
| 251 | } |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 252 | Result retval = Result::NOT_INITIALIZED; |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 253 | #if MAJOR_VERSION == 2 |
Mikhail Naganov | d9499eb | 2018-12-17 16:23:22 -0800 | [diff] [blame] | 254 | auto sinkMetadata = AudioSource(source); |
Kevin Rocard | 3d48dce | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 255 | #elif MAJOR_VERSION >= 4 |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 256 | // TODO: correctly propagate the tracks sources and volume |
| 257 | // for now, only send the main source at 1dbfs |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 258 | AudioSource hidlSource; |
| 259 | if (status_t status = HidlUtils::audioSourceFromHal(source, &hidlSource); status != OK) { |
| 260 | return status; |
| 261 | } |
| 262 | SinkMetadata sinkMetadata = {{{ .source = std::move(hidlSource), .gain = 1 }}}; |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 263 | #endif |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 264 | #if MAJOR_VERSION < 5 |
| 265 | (void)outputDevice; |
| 266 | (void)outputDeviceAddress; |
| 267 | #else |
Mikhail Naganov | c425880 | 2021-02-08 17:14:17 -0800 | [diff] [blame^] | 268 | #if MAJOR_VERSION >= 7 |
| 269 | (void)HidlUtils::audioChannelMaskFromHal( |
| 270 | AUDIO_CHANNEL_NONE, true /*isInput*/, &sinkMetadata.tracks[0].channelMask); |
| 271 | #endif |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 272 | if (outputDevice != AUDIO_DEVICE_NONE) { |
| 273 | DeviceAddress hidlOutputDevice; |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 274 | if (status_t status = CoreUtils::deviceAddressFromHal( |
| 275 | outputDevice, outputDeviceAddress, &hidlOutputDevice); status != OK) { |
| 276 | return status; |
| 277 | } |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 278 | sinkMetadata.tracks[0].destination.device(std::move(hidlOutputDevice)); |
| 279 | } |
| 280 | #endif |
Mikhail Naganov | bad1510 | 2019-12-10 16:44:19 -0800 | [diff] [blame] | 281 | #if MAJOR_VERSION <= 5 |
| 282 | // Some flags were specific to framework and must not leak to the HAL. |
| 283 | flags = static_cast<audio_input_flags_t>(flags & ~AUDIO_INPUT_FLAG_DIRECT); |
| 284 | #endif |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 285 | Return<void> ret = mDevice->openInputStream( |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 286 | handle, hidlDevice, hidlConfig, hidlFlags, sinkMetadata, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 287 | [&](Result r, const sp<IStreamIn>& result, const AudioConfig& suggestedConfig) { |
| 288 | retval = r; |
| 289 | if (retval == Result::OK) { |
| 290 | *inStream = new StreamInHalHidl(result); |
| 291 | } |
| 292 | HidlUtils::audioConfigToHal(suggestedConfig, config); |
| 293 | }); |
| 294 | return processReturn("openInputStream", ret, retval); |
| 295 | } |
| 296 | |
| 297 | status_t DeviceHalHidl::supportsAudioPatches(bool *supportsPatches) { |
| 298 | if (mDevice == 0) return NO_INIT; |
| 299 | return processReturn("supportsAudioPatches", mDevice->supportsAudioPatches(), supportsPatches); |
| 300 | } |
| 301 | |
| 302 | status_t DeviceHalHidl::createAudioPatch( |
| 303 | unsigned int num_sources, |
| 304 | const struct audio_port_config *sources, |
| 305 | unsigned int num_sinks, |
| 306 | const struct audio_port_config *sinks, |
| 307 | audio_patch_handle_t *patch) { |
| 308 | if (mDevice == 0) return NO_INIT; |
Eric Laurent | 8711cfd | 2019-06-10 18:06:33 -0700 | [diff] [blame] | 309 | if (patch == nullptr) return BAD_VALUE; |
| 310 | |
Mikhail Naganov | 73bdf57 | 2019-12-11 12:34:15 -0800 | [diff] [blame] | 311 | #if MAJOR_VERSION < 6 |
Eric Laurent | 8711cfd | 2019-06-10 18:06:33 -0700 | [diff] [blame] | 312 | if (*patch != AUDIO_PATCH_HANDLE_NONE) { |
| 313 | status_t status = releaseAudioPatch(*patch); |
| 314 | ALOGW_IF(status != NO_ERROR, "%s error %d releasing patch handle %d", |
| 315 | __func__, status, *patch); |
Mikhail Naganov | 73bdf57 | 2019-12-11 12:34:15 -0800 | [diff] [blame] | 316 | *patch = AUDIO_PATCH_HANDLE_NONE; |
Eric Laurent | 8711cfd | 2019-06-10 18:06:33 -0700 | [diff] [blame] | 317 | } |
Mikhail Naganov | 73bdf57 | 2019-12-11 12:34:15 -0800 | [diff] [blame] | 318 | #endif |
Eric Laurent | 8711cfd | 2019-06-10 18:06:33 -0700 | [diff] [blame] | 319 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 320 | hidl_vec<AudioPortConfig> hidlSources, hidlSinks; |
| 321 | HidlUtils::audioPortConfigsFromHal(num_sources, sources, &hidlSources); |
| 322 | HidlUtils::audioPortConfigsFromHal(num_sinks, sinks, &hidlSinks); |
Mikhail Naganov | 73bdf57 | 2019-12-11 12:34:15 -0800 | [diff] [blame] | 323 | Result retval = Result::OK; |
| 324 | Return<void> ret; |
| 325 | std::string methodName = "createAudioPatch"; |
| 326 | if (*patch == AUDIO_PATCH_HANDLE_NONE) { // always true for MAJOR_VERSION < 6 |
| 327 | ret = mDevice->createAudioPatch( |
| 328 | hidlSources, hidlSinks, |
| 329 | [&](Result r, AudioPatchHandle hidlPatch) { |
| 330 | retval = r; |
| 331 | if (retval == Result::OK) { |
| 332 | *patch = static_cast<audio_patch_handle_t>(hidlPatch); |
| 333 | } |
| 334 | }); |
| 335 | } else { |
| 336 | #if MAJOR_VERSION >= 6 |
| 337 | ret = mDevice->updateAudioPatch( |
| 338 | *patch, |
| 339 | hidlSources, hidlSinks, |
| 340 | [&](Result r, AudioPatchHandle hidlPatch) { |
| 341 | retval = r; |
| 342 | if (retval == Result::OK) { |
| 343 | *patch = static_cast<audio_patch_handle_t>(hidlPatch); |
| 344 | } |
| 345 | }); |
| 346 | methodName = "updateAudioPatch"; |
| 347 | #endif |
| 348 | } |
| 349 | return processReturn(methodName.c_str(), ret, retval); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | status_t DeviceHalHidl::releaseAudioPatch(audio_patch_handle_t patch) { |
| 353 | if (mDevice == 0) return NO_INIT; |
| 354 | return processReturn("releaseAudioPatch", mDevice->releaseAudioPatch(patch)); |
| 355 | } |
| 356 | |
| 357 | status_t DeviceHalHidl::getAudioPort(struct audio_port *port) { |
| 358 | if (mDevice == 0) return NO_INIT; |
| 359 | AudioPort hidlPort; |
| 360 | HidlUtils::audioPortFromHal(*port, &hidlPort); |
| 361 | Result retval; |
| 362 | Return<void> ret = mDevice->getAudioPort( |
| 363 | hidlPort, |
| 364 | [&](Result r, const AudioPort& p) { |
| 365 | retval = r; |
| 366 | if (retval == Result::OK) { |
| 367 | HidlUtils::audioPortToHal(p, port); |
| 368 | } |
| 369 | }); |
| 370 | return processReturn("getAudioPort", ret, retval); |
| 371 | } |
| 372 | |
| 373 | status_t DeviceHalHidl::setAudioPortConfig(const struct audio_port_config *config) { |
| 374 | if (mDevice == 0) return NO_INIT; |
| 375 | AudioPortConfig hidlConfig; |
| 376 | HidlUtils::audioPortConfigFromHal(*config, &hidlConfig); |
| 377 | return processReturn("setAudioPortConfig", mDevice->setAudioPortConfig(hidlConfig)); |
| 378 | } |
| 379 | |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 380 | #if MAJOR_VERSION == 2 |
| 381 | status_t DeviceHalHidl::getMicrophones( |
| 382 | std::vector<media::MicrophoneInfo> *microphonesInfo __unused) { |
| 383 | if (mDevice == 0) return NO_INIT; |
| 384 | return INVALID_OPERATION; |
| 385 | } |
Kevin Rocard | 3d48dce | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 386 | #elif MAJOR_VERSION >= 4 |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 387 | status_t DeviceHalHidl::getMicrophones(std::vector<media::MicrophoneInfo> *microphonesInfo) { |
| 388 | if (mDevice == 0) return NO_INIT; |
| 389 | Result retval; |
| 390 | Return<void> ret = mDevice->getMicrophones( |
| 391 | [&](Result r, hidl_vec<MicrophoneInfo> micArrayHal) { |
| 392 | retval = r; |
| 393 | for (size_t k = 0; k < micArrayHal.size(); k++) { |
| 394 | audio_microphone_characteristic_t dst; |
| 395 | //convert |
Mikhail Naganov | cc73ef0 | 2020-11-06 10:09:52 -0800 | [diff] [blame] | 396 | (void)CoreUtils::microphoneInfoToHal(micArrayHal[k], &dst); |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 397 | media::MicrophoneInfo microphone = media::MicrophoneInfo(dst); |
| 398 | microphonesInfo->push_back(microphone); |
| 399 | } |
| 400 | }); |
| 401 | return processReturn("getMicrophones", ret, retval); |
| 402 | } |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 403 | #endif |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 404 | |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 405 | #if MAJOR_VERSION >= 6 |
| 406 | status_t DeviceHalHidl::addDeviceEffect( |
| 407 | audio_port_handle_t device, sp<EffectHalInterface> effect) { |
| 408 | if (mDevice == 0) return NO_INIT; |
| 409 | return processReturn("addDeviceEffect", mDevice->addDeviceEffect( |
| 410 | static_cast<AudioPortHandle>(device), |
| 411 | static_cast<EffectHalHidl*>(effect.get())->effectId())); |
| 412 | } |
| 413 | #else |
| 414 | status_t DeviceHalHidl::addDeviceEffect( |
| 415 | audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) { |
| 416 | return INVALID_OPERATION; |
| 417 | } |
| 418 | #endif |
| 419 | |
| 420 | #if MAJOR_VERSION >= 6 |
| 421 | status_t DeviceHalHidl::removeDeviceEffect( |
| 422 | audio_port_handle_t device, sp<EffectHalInterface> effect) { |
| 423 | if (mDevice == 0) return NO_INIT; |
| 424 | return processReturn("removeDeviceEffect", mDevice->removeDeviceEffect( |
| 425 | static_cast<AudioPortHandle>(device), |
| 426 | static_cast<EffectHalHidl*>(effect.get())->effectId())); |
| 427 | } |
| 428 | #else |
| 429 | status_t DeviceHalHidl::removeDeviceEffect( |
| 430 | audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) { |
| 431 | return INVALID_OPERATION; |
| 432 | } |
| 433 | #endif |
| 434 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 435 | status_t DeviceHalHidl::dump(int fd) { |
| 436 | if (mDevice == 0) return NO_INIT; |
| 437 | native_handle_t* hidlHandle = native_handle_create(1, 0); |
| 438 | hidlHandle->data[0] = fd; |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 439 | Return<void> ret = mDevice->debug(hidlHandle, {} /* options */); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 440 | native_handle_delete(hidlHandle); |
| 441 | return processReturn("dump", ret); |
| 442 | } |
| 443 | |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 444 | } // namespace CPP_VERSION |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 445 | } // namespace android |