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 | 95213bf | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 22 | #include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h) |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 23 | #include <cutils/native_handle.h> |
| 24 | #include <hwbinder/IPCThreadState.h> |
| 25 | #include <utils/Log.h> |
| 26 | |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 27 | #include <common/all-versions/VersionUtils.h> |
| 28 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 29 | #include "DeviceHalHidl.h" |
| 30 | #include "HidlUtils.h" |
| 31 | #include "StreamHalHidl.h" |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 32 | #include "VersionUtils.h" |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 33 | |
Mikhail Naganov | 9ccaa16 | 2018-12-12 10:27:29 -0800 | [diff] [blame] | 34 | using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils; |
Kevin Rocard | 7a9f05a | 2018-11-28 16:52:25 -0800 | [diff] [blame] | 35 | using ::android::hardware::audio::common::utils::EnumBitfield; |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 36 | using ::android::hardware::hidl_string; |
| 37 | using ::android::hardware::hidl_vec; |
| 38 | |
| 39 | namespace android { |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 40 | namespace CPP_VERSION { |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 41 | |
Mikhail Naganov | 9ccaa16 | 2018-12-12 10:27:29 -0800 | [diff] [blame] | 42 | using namespace ::android::hardware::audio::common::CPP_VERSION; |
| 43 | using namespace ::android::hardware::audio::CPP_VERSION; |
| 44 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 45 | namespace { |
| 46 | |
| 47 | status_t deviceAddressFromHal( |
| 48 | audio_devices_t device, const char* halAddress, DeviceAddress* address) { |
| 49 | address->device = AudioDevice(device); |
| 50 | |
Kevin Rocard | 5915fa3 | 2018-03-29 10:32:44 -0700 | [diff] [blame] | 51 | if (halAddress == nullptr || strnlen(halAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0) { |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 52 | return OK; |
| 53 | } |
| 54 | const bool isInput = (device & AUDIO_DEVICE_BIT_IN) != 0; |
| 55 | if (isInput) device &= ~AUDIO_DEVICE_BIT_IN; |
| 56 | if ((!isInput && (device & AUDIO_DEVICE_OUT_ALL_A2DP) != 0) |
| 57 | || (isInput && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0)) { |
| 58 | int status = sscanf(halAddress, |
| 59 | "%hhX:%hhX:%hhX:%hhX:%hhX:%hhX", |
| 60 | &address->address.mac[0], &address->address.mac[1], &address->address.mac[2], |
| 61 | &address->address.mac[3], &address->address.mac[4], &address->address.mac[5]); |
| 62 | return status == 6 ? OK : BAD_VALUE; |
| 63 | } else if ((!isInput && (device & AUDIO_DEVICE_OUT_IP) != 0) |
| 64 | || (isInput && (device & AUDIO_DEVICE_IN_IP) != 0)) { |
| 65 | int status = sscanf(halAddress, |
| 66 | "%hhu.%hhu.%hhu.%hhu", |
| 67 | &address->address.ipv4[0], &address->address.ipv4[1], |
| 68 | &address->address.ipv4[2], &address->address.ipv4[3]); |
| 69 | return status == 4 ? OK : BAD_VALUE; |
| 70 | } else if ((!isInput && (device & AUDIO_DEVICE_OUT_ALL_USB)) != 0 |
| 71 | || (isInput && (device & AUDIO_DEVICE_IN_ALL_USB)) != 0) { |
| 72 | int status = sscanf(halAddress, |
| 73 | "card=%d;device=%d", |
| 74 | &address->address.alsa.card, &address->address.alsa.device); |
| 75 | return status == 2 ? OK : BAD_VALUE; |
| 76 | } else if ((!isInput && (device & AUDIO_DEVICE_OUT_BUS) != 0) |
| 77 | || (isInput && (device & AUDIO_DEVICE_IN_BUS) != 0)) { |
| 78 | if (halAddress != NULL) { |
| 79 | address->busAddress = halAddress; |
| 80 | return OK; |
| 81 | } |
| 82 | return BAD_VALUE; |
| 83 | } else if ((!isInput && (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0 |
| 84 | || (isInput && (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) { |
| 85 | if (halAddress != NULL) { |
| 86 | address->rSubmixAddress = halAddress; |
| 87 | return OK; |
| 88 | } |
| 89 | return BAD_VALUE; |
| 90 | } |
| 91 | return OK; |
| 92 | } |
| 93 | |
| 94 | } // namespace |
| 95 | |
| 96 | DeviceHalHidl::DeviceHalHidl(const sp<IDevice>& device) |
| 97 | : ConversionHelperHidl("Device"), mDevice(device), |
| 98 | mPrimaryDevice(IPrimaryDevice::castFrom(device)) { |
| 99 | } |
| 100 | |
| 101 | DeviceHalHidl::~DeviceHalHidl() { |
| 102 | if (mDevice != 0) { |
Mikhail Naganov | 3355e44 | 2019-11-20 14:20:01 -0800 | [diff] [blame] | 103 | #if MAJOR_VERSION <= 5 |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 104 | mDevice.clear(); |
| 105 | hardware::IPCThreadState::self()->flushCommands(); |
Mikhail Naganov | 3355e44 | 2019-11-20 14:20:01 -0800 | [diff] [blame] | 106 | #elif MAJOR_VERSION >= 6 |
| 107 | mDevice->close(); |
| 108 | #endif |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | status_t DeviceHalHidl::getSupportedDevices(uint32_t*) { |
| 113 | // Obsolete. |
| 114 | return INVALID_OPERATION; |
| 115 | } |
| 116 | |
| 117 | status_t DeviceHalHidl::initCheck() { |
| 118 | if (mDevice == 0) return NO_INIT; |
| 119 | return processReturn("initCheck", mDevice->initCheck()); |
| 120 | } |
| 121 | |
| 122 | status_t DeviceHalHidl::setVoiceVolume(float volume) { |
| 123 | if (mDevice == 0) return NO_INIT; |
| 124 | if (mPrimaryDevice == 0) return INVALID_OPERATION; |
| 125 | return processReturn("setVoiceVolume", mPrimaryDevice->setVoiceVolume(volume)); |
| 126 | } |
| 127 | |
| 128 | status_t DeviceHalHidl::setMasterVolume(float volume) { |
| 129 | if (mDevice == 0) return NO_INIT; |
Mikhail Naganov | ae1f662 | 2019-02-21 15:20:05 -0800 | [diff] [blame] | 130 | return processReturn("setMasterVolume", mDevice->setMasterVolume(volume)); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | status_t DeviceHalHidl::getMasterVolume(float *volume) { |
| 134 | if (mDevice == 0) return NO_INIT; |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 135 | Result retval; |
Mikhail Naganov | ae1f662 | 2019-02-21 15:20:05 -0800 | [diff] [blame] | 136 | Return<void> ret = mDevice->getMasterVolume( |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 137 | [&](Result r, float v) { |
| 138 | retval = r; |
| 139 | if (retval == Result::OK) { |
| 140 | *volume = v; |
| 141 | } |
| 142 | }); |
| 143 | return processReturn("getMasterVolume", ret, retval); |
| 144 | } |
| 145 | |
| 146 | status_t DeviceHalHidl::setMode(audio_mode_t mode) { |
| 147 | if (mDevice == 0) return NO_INIT; |
| 148 | if (mPrimaryDevice == 0) return INVALID_OPERATION; |
| 149 | return processReturn("setMode", mPrimaryDevice->setMode(AudioMode(mode))); |
| 150 | } |
| 151 | |
| 152 | status_t DeviceHalHidl::setMicMute(bool state) { |
| 153 | if (mDevice == 0) return NO_INIT; |
| 154 | return processReturn("setMicMute", mDevice->setMicMute(state)); |
| 155 | } |
| 156 | |
| 157 | status_t DeviceHalHidl::getMicMute(bool *state) { |
| 158 | if (mDevice == 0) return NO_INIT; |
| 159 | Result retval; |
| 160 | Return<void> ret = mDevice->getMicMute( |
| 161 | [&](Result r, bool mute) { |
| 162 | retval = r; |
| 163 | if (retval == Result::OK) { |
| 164 | *state = mute; |
| 165 | } |
| 166 | }); |
| 167 | return processReturn("getMicMute", ret, retval); |
| 168 | } |
| 169 | |
| 170 | status_t DeviceHalHidl::setMasterMute(bool state) { |
| 171 | if (mDevice == 0) return NO_INIT; |
| 172 | return processReturn("setMasterMute", mDevice->setMasterMute(state)); |
| 173 | } |
| 174 | |
| 175 | status_t DeviceHalHidl::getMasterMute(bool *state) { |
| 176 | if (mDevice == 0) return NO_INIT; |
| 177 | Result retval; |
| 178 | Return<void> ret = mDevice->getMasterMute( |
| 179 | [&](Result r, bool mute) { |
| 180 | retval = r; |
| 181 | if (retval == Result::OK) { |
| 182 | *state = mute; |
| 183 | } |
| 184 | }); |
| 185 | return processReturn("getMasterMute", ret, retval); |
| 186 | } |
| 187 | |
| 188 | status_t DeviceHalHidl::setParameters(const String8& kvPairs) { |
| 189 | if (mDevice == 0) return NO_INIT; |
| 190 | hidl_vec<ParameterValue> hidlParams; |
| 191 | status_t status = parametersFromHal(kvPairs, &hidlParams); |
| 192 | if (status != OK) return status; |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 193 | // TODO: change the API so that context and kvPairs are separated |
| 194 | return processReturn("setParameters", |
| 195 | utils::setParameters(mDevice, {} /* context */, hidlParams)); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | status_t DeviceHalHidl::getParameters(const String8& keys, String8 *values) { |
| 199 | values->clear(); |
| 200 | if (mDevice == 0) return NO_INIT; |
| 201 | hidl_vec<hidl_string> hidlKeys; |
| 202 | status_t status = keysFromHal(keys, &hidlKeys); |
| 203 | if (status != OK) return status; |
| 204 | Result retval; |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 205 | Return<void> ret = utils::getParameters(mDevice, |
| 206 | {} /* context */, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 207 | hidlKeys, |
| 208 | [&](Result r, const hidl_vec<ParameterValue>& parameters) { |
| 209 | retval = r; |
| 210 | if (retval == Result::OK) { |
| 211 | parametersToHal(parameters, values); |
| 212 | } |
| 213 | }); |
| 214 | return processReturn("getParameters", ret, retval); |
| 215 | } |
| 216 | |
| 217 | status_t DeviceHalHidl::getInputBufferSize( |
| 218 | const struct audio_config *config, size_t *size) { |
| 219 | if (mDevice == 0) return NO_INIT; |
| 220 | AudioConfig hidlConfig; |
| 221 | HidlUtils::audioConfigFromHal(*config, &hidlConfig); |
| 222 | Result retval; |
| 223 | Return<void> ret = mDevice->getInputBufferSize( |
| 224 | hidlConfig, |
| 225 | [&](Result r, uint64_t bufferSize) { |
| 226 | retval = r; |
| 227 | if (retval == Result::OK) { |
| 228 | *size = static_cast<size_t>(bufferSize); |
| 229 | } |
| 230 | }); |
| 231 | return processReturn("getInputBufferSize", ret, retval); |
| 232 | } |
| 233 | |
| 234 | status_t DeviceHalHidl::openOutputStream( |
| 235 | audio_io_handle_t handle, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 236 | audio_devices_t deviceType, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 237 | audio_output_flags_t flags, |
| 238 | struct audio_config *config, |
| 239 | const char *address, |
| 240 | sp<StreamOutHalInterface> *outStream) { |
| 241 | if (mDevice == 0) return NO_INIT; |
| 242 | DeviceAddress hidlDevice; |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 243 | status_t status = deviceAddressFromHal(deviceType, address, &hidlDevice); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 244 | if (status != OK) return status; |
| 245 | AudioConfig hidlConfig; |
| 246 | HidlUtils::audioConfigFromHal(*config, &hidlConfig); |
| 247 | Result retval = Result::NOT_INITIALIZED; |
| 248 | Return<void> ret = mDevice->openOutputStream( |
| 249 | handle, |
| 250 | hidlDevice, |
| 251 | hidlConfig, |
Kevin Rocard | 7a9f05a | 2018-11-28 16:52:25 -0800 | [diff] [blame] | 252 | EnumBitfield<AudioOutputFlag>(flags), |
Kevin Rocard | 3d48dce | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 253 | #if MAJOR_VERSION >= 4 |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 254 | {} /* metadata */, |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 255 | #endif |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 256 | [&](Result r, const sp<IStreamOut>& result, const AudioConfig& suggestedConfig) { |
| 257 | retval = r; |
| 258 | if (retval == Result::OK) { |
| 259 | *outStream = new StreamOutHalHidl(result); |
| 260 | } |
| 261 | HidlUtils::audioConfigToHal(suggestedConfig, config); |
| 262 | }); |
| 263 | return processReturn("openOutputStream", ret, retval); |
| 264 | } |
| 265 | |
| 266 | status_t DeviceHalHidl::openInputStream( |
| 267 | audio_io_handle_t handle, |
| 268 | audio_devices_t devices, |
| 269 | struct audio_config *config, |
| 270 | audio_input_flags_t flags, |
| 271 | const char *address, |
| 272 | audio_source_t source, |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 273 | audio_devices_t outputDevice, |
| 274 | const char *outputDeviceAddress, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 275 | sp<StreamInHalInterface> *inStream) { |
| 276 | if (mDevice == 0) return NO_INIT; |
| 277 | DeviceAddress hidlDevice; |
| 278 | status_t status = deviceAddressFromHal(devices, address, &hidlDevice); |
| 279 | if (status != OK) return status; |
| 280 | AudioConfig hidlConfig; |
| 281 | HidlUtils::audioConfigFromHal(*config, &hidlConfig); |
| 282 | Result retval = Result::NOT_INITIALIZED; |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 283 | #if MAJOR_VERSION == 2 |
Mikhail Naganov | d9499eb | 2018-12-17 16:23:22 -0800 | [diff] [blame] | 284 | auto sinkMetadata = AudioSource(source); |
Kevin Rocard | 3d48dce | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 285 | #elif MAJOR_VERSION >= 4 |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 286 | // TODO: correctly propagate the tracks sources and volume |
| 287 | // for now, only send the main source at 1dbfs |
Mikhail Naganov | d9499eb | 2018-12-17 16:23:22 -0800 | [diff] [blame] | 288 | SinkMetadata sinkMetadata = {{{ .source = AudioSource(source), .gain = 1 }}}; |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 289 | #endif |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 290 | #if MAJOR_VERSION < 5 |
| 291 | (void)outputDevice; |
| 292 | (void)outputDeviceAddress; |
| 293 | #else |
| 294 | if (outputDevice != AUDIO_DEVICE_NONE) { |
| 295 | DeviceAddress hidlOutputDevice; |
| 296 | status = deviceAddressFromHal(outputDevice, outputDeviceAddress, &hidlOutputDevice); |
| 297 | if (status != OK) return status; |
| 298 | sinkMetadata.tracks[0].destination.device(std::move(hidlOutputDevice)); |
| 299 | } |
| 300 | #endif |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 301 | Return<void> ret = mDevice->openInputStream( |
| 302 | handle, |
| 303 | hidlDevice, |
| 304 | hidlConfig, |
Kevin Rocard | 7a9f05a | 2018-11-28 16:52:25 -0800 | [diff] [blame] | 305 | EnumBitfield<AudioInputFlag>(flags), |
Mikhail Naganov | d9499eb | 2018-12-17 16:23:22 -0800 | [diff] [blame] | 306 | sinkMetadata, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 307 | [&](Result r, const sp<IStreamIn>& result, const AudioConfig& suggestedConfig) { |
| 308 | retval = r; |
| 309 | if (retval == Result::OK) { |
| 310 | *inStream = new StreamInHalHidl(result); |
| 311 | } |
| 312 | HidlUtils::audioConfigToHal(suggestedConfig, config); |
| 313 | }); |
| 314 | return processReturn("openInputStream", ret, retval); |
| 315 | } |
| 316 | |
| 317 | status_t DeviceHalHidl::supportsAudioPatches(bool *supportsPatches) { |
| 318 | if (mDevice == 0) return NO_INIT; |
| 319 | return processReturn("supportsAudioPatches", mDevice->supportsAudioPatches(), supportsPatches); |
| 320 | } |
| 321 | |
| 322 | status_t DeviceHalHidl::createAudioPatch( |
| 323 | unsigned int num_sources, |
| 324 | const struct audio_port_config *sources, |
| 325 | unsigned int num_sinks, |
| 326 | const struct audio_port_config *sinks, |
| 327 | audio_patch_handle_t *patch) { |
| 328 | if (mDevice == 0) return NO_INIT; |
Eric Laurent | 8711cfd | 2019-06-10 18:06:33 -0700 | [diff] [blame] | 329 | if (patch == nullptr) return BAD_VALUE; |
| 330 | |
| 331 | if (*patch != AUDIO_PATCH_HANDLE_NONE) { |
| 332 | status_t status = releaseAudioPatch(*patch); |
| 333 | ALOGW_IF(status != NO_ERROR, "%s error %d releasing patch handle %d", |
| 334 | __func__, status, *patch); |
| 335 | } |
| 336 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 337 | hidl_vec<AudioPortConfig> hidlSources, hidlSinks; |
| 338 | HidlUtils::audioPortConfigsFromHal(num_sources, sources, &hidlSources); |
| 339 | HidlUtils::audioPortConfigsFromHal(num_sinks, sinks, &hidlSinks); |
| 340 | Result retval; |
| 341 | Return<void> ret = mDevice->createAudioPatch( |
| 342 | hidlSources, hidlSinks, |
| 343 | [&](Result r, AudioPatchHandle hidlPatch) { |
| 344 | retval = r; |
| 345 | if (retval == Result::OK) { |
| 346 | *patch = static_cast<audio_patch_handle_t>(hidlPatch); |
| 347 | } |
| 348 | }); |
| 349 | return processReturn("createAudioPatch", ret, retval); |
| 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 |
| 396 | microphoneInfoToHal(micArrayHal[k], &dst); |
| 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 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 405 | status_t DeviceHalHidl::dump(int fd) { |
| 406 | if (mDevice == 0) return NO_INIT; |
| 407 | native_handle_t* hidlHandle = native_handle_create(1, 0); |
| 408 | hidlHandle->data[0] = fd; |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 409 | Return<void> ret = mDevice->debug(hidlHandle, {} /* options */); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 410 | native_handle_delete(hidlHandle); |
| 411 | return processReturn("dump", ret); |
| 412 | } |
| 413 | |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 414 | } // namespace CPP_VERSION |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 415 | } // namespace android |