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