Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [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 | */ |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 16 | |
| 17 | #define LOG_TAG "DeviceHAL" |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 19 | |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 20 | #include <memory.h> |
| 21 | #include <string.h> |
Mikhail Naganov | 6c0f76a | 2017-05-03 12:08:22 -0700 | [diff] [blame] | 22 | #include <algorithm> |
| 23 | #include <mutex> |
| 24 | #include <vector> |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 25 | |
Yifan Hong | f9d3034 | 2016-11-30 13:45:34 -0800 | [diff] [blame] | 26 | #include <android/log.h> |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 27 | |
| 28 | #include "Conversions.h" |
| 29 | #include "Device.h" |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 30 | #include "HidlUtils.h" |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 31 | #include "StreamIn.h" |
| 32 | #include "StreamOut.h" |
| 33 | |
| 34 | namespace android { |
| 35 | namespace hardware { |
| 36 | namespace audio { |
| 37 | namespace V2_0 { |
| 38 | namespace implementation { |
| 39 | |
Mikhail Naganov | 6c0f76a | 2017-05-03 12:08:22 -0700 | [diff] [blame] | 40 | namespace { |
| 41 | |
| 42 | class Diagnostics { |
| 43 | public: |
| 44 | static Diagnostics& getInstance() { |
| 45 | std::lock_guard<std::mutex> _(mLock); |
| 46 | if (mInstance == nullptr) { |
| 47 | mInstance = new Diagnostics; |
| 48 | } |
| 49 | return *mInstance; |
| 50 | } |
| 51 | |
| 52 | void registerDevice(Device* dev) { |
| 53 | std::lock_guard<std::mutex> _(mLock); |
| 54 | mDevices.push_back(wp<Device>(dev)); |
| 55 | } |
| 56 | |
| 57 | void checkForErasedHalCblk(const Device* dev) { |
| 58 | if (dev->version() != 0) return; // all OK |
| 59 | |
| 60 | std::ostringstream ss; |
| 61 | ss << "Zero HAL CB for " << dev->type() << ":" << std::hex |
| 62 | << dev->device() << "; Others: "; |
| 63 | { |
| 64 | std::lock_guard<std::mutex> _(mLock); |
| 65 | for (auto wp : mDevices) { |
| 66 | sp<Device> other{wp.promote()}; |
| 67 | if (other.get() == nullptr || other.get() == dev) continue; |
| 68 | ss << other->type() << ":" << other->version() << ":" |
| 69 | << std::hex << other->device() << "; "; |
| 70 | } |
| 71 | } |
| 72 | ALOGE("%s", ss.str().c_str()); |
| 73 | } |
| 74 | |
| 75 | private: |
| 76 | Diagnostics() {} |
| 77 | |
| 78 | static std::mutex mLock; |
| 79 | static Diagnostics* mInstance; |
| 80 | std::vector<wp<Device>> mDevices; |
| 81 | }; |
| 82 | |
| 83 | std::mutex Diagnostics::mLock; |
| 84 | Diagnostics* Diagnostics::mInstance{nullptr}; |
| 85 | |
| 86 | } // namespace |
| 87 | |
| 88 | Device::Device(audio_hw_device_t* device, const char* type) |
| 89 | : mDevice{device}, mType{type} { |
| 90 | Diagnostics::getInstance().registerDevice(this); |
Mikhail Naganov | 86685f5 | 2017-05-03 16:39:28 +0000 | [diff] [blame] | 91 | } |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 92 | |
| 93 | Device::~Device() { |
| 94 | int status = audio_hw_device_close(mDevice); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 95 | ALOGW_IF(status, "Error closing audio hw device %p: %s", mDevice, |
| 96 | strerror(-status)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 97 | mDevice = nullptr; |
| 98 | } |
| 99 | |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 100 | Result Device::analyzeStatus(const char* funcName, int status) { |
| 101 | if (status != 0) { |
| 102 | ALOGW("Device %p %s: %s", mDevice, funcName, strerror(-status)); |
| 103 | } |
| 104 | switch (status) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 105 | case 0: |
| 106 | return Result::OK; |
| 107 | case -EINVAL: |
| 108 | return Result::INVALID_ARGUMENTS; |
| 109 | case -ENODATA: |
| 110 | return Result::INVALID_STATE; |
| 111 | case -ENODEV: |
| 112 | return Result::NOT_INITIALIZED; |
| 113 | case -ENOSYS: |
| 114 | return Result::NOT_SUPPORTED; |
| 115 | default: |
| 116 | return Result::INVALID_STATE; |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Mikhail Naganov | 936279e | 2017-03-29 09:31:18 -0700 | [diff] [blame] | 120 | void Device::closeInputStream(audio_stream_in_t* stream) { |
| 121 | mDevice->close_input_stream(mDevice, stream); |
| 122 | } |
| 123 | |
| 124 | void Device::closeOutputStream(audio_stream_out_t* stream) { |
| 125 | mDevice->close_output_stream(mDevice, stream); |
| 126 | } |
| 127 | |
Mikhail Naganov | 86685f5 | 2017-05-03 16:39:28 +0000 | [diff] [blame] | 128 | char* Device::halGetParameters(const char* keys) { |
Mikhail Naganov | 6c0f76a | 2017-05-03 12:08:22 -0700 | [diff] [blame] | 129 | Diagnostics::getInstance().checkForErasedHalCblk(this); |
Mikhail Naganov | 86685f5 | 2017-05-03 16:39:28 +0000 | [diff] [blame] | 130 | return mDevice->get_parameters(mDevice, keys); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Mikhail Naganov | 86685f5 | 2017-05-03 16:39:28 +0000 | [diff] [blame] | 133 | int Device::halSetParameters(const char* keysAndValues) { |
Mikhail Naganov | 6c0f76a | 2017-05-03 12:08:22 -0700 | [diff] [blame] | 134 | Diagnostics::getInstance().checkForErasedHalCblk(this); |
Mikhail Naganov | 86685f5 | 2017-05-03 16:39:28 +0000 | [diff] [blame] | 135 | return mDevice->set_parameters(mDevice, keysAndValues); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // Methods from ::android::hardware::audio::V2_0::IDevice follow. |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 139 | Return<Result> Device::initCheck() { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 140 | return analyzeStatus("init_check", mDevice->init_check(mDevice)); |
| 141 | } |
| 142 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 143 | Return<Result> Device::setMasterVolume(float volume) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 144 | Result retval(Result::NOT_SUPPORTED); |
| 145 | if (mDevice->set_master_volume != NULL) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 146 | retval = analyzeStatus("set_master_volume", |
| 147 | mDevice->set_master_volume(mDevice, volume)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 148 | } |
| 149 | return retval; |
| 150 | } |
| 151 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 152 | Return<void> Device::getMasterVolume(getMasterVolume_cb _hidl_cb) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 153 | Result retval(Result::NOT_SUPPORTED); |
| 154 | float volume = 0; |
| 155 | if (mDevice->get_master_volume != NULL) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 156 | retval = analyzeStatus("get_master_volume", |
| 157 | mDevice->get_master_volume(mDevice, &volume)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 158 | } |
| 159 | _hidl_cb(retval, volume); |
| 160 | return Void(); |
| 161 | } |
| 162 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 163 | Return<Result> Device::setMicMute(bool mute) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 164 | return analyzeStatus("set_mic_mute", mDevice->set_mic_mute(mDevice, mute)); |
| 165 | } |
| 166 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 167 | Return<void> Device::getMicMute(getMicMute_cb _hidl_cb) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 168 | bool mute = false; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 169 | Result retval = |
| 170 | analyzeStatus("get_mic_mute", mDevice->get_mic_mute(mDevice, &mute)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 171 | _hidl_cb(retval, mute); |
| 172 | return Void(); |
| 173 | } |
| 174 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 175 | Return<Result> Device::setMasterMute(bool mute) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 176 | Result retval(Result::NOT_SUPPORTED); |
| 177 | if (mDevice->set_master_mute != NULL) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 178 | retval = analyzeStatus("set_master_mute", |
| 179 | mDevice->set_master_mute(mDevice, mute)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 180 | } |
| 181 | return retval; |
| 182 | } |
| 183 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 184 | Return<void> Device::getMasterMute(getMasterMute_cb _hidl_cb) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 185 | Result retval(Result::NOT_SUPPORTED); |
| 186 | bool mute = false; |
| 187 | if (mDevice->get_master_mute != NULL) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 188 | retval = analyzeStatus("get_master_mute", |
| 189 | mDevice->get_master_mute(mDevice, &mute)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 190 | } |
| 191 | _hidl_cb(retval, mute); |
| 192 | return Void(); |
| 193 | } |
| 194 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 195 | Return<void> Device::getInputBufferSize(const AudioConfig& config, |
| 196 | getInputBufferSize_cb _hidl_cb) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 197 | audio_config_t halConfig; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 198 | HidlUtils::audioConfigToHal(config, &halConfig); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 199 | size_t halBufferSize = mDevice->get_input_buffer_size(mDevice, &halConfig); |
| 200 | Result retval(Result::INVALID_ARGUMENTS); |
| 201 | uint64_t bufferSize = 0; |
| 202 | if (halBufferSize != 0) { |
| 203 | retval = Result::OK; |
| 204 | bufferSize = halBufferSize; |
| 205 | } |
| 206 | _hidl_cb(retval, bufferSize); |
| 207 | return Void(); |
| 208 | } |
| 209 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 210 | Return<void> Device::openOutputStream(int32_t ioHandle, |
| 211 | const DeviceAddress& device, |
| 212 | const AudioConfig& config, |
| 213 | AudioOutputFlag flags, |
| 214 | openOutputStream_cb _hidl_cb) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 215 | audio_config_t halConfig; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 216 | HidlUtils::audioConfigToHal(config, &halConfig); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 217 | audio_stream_out_t* halStream; |
| 218 | ALOGV( |
| 219 | "open_output_stream handle: %d devices: %x flags: %#x " |
| 220 | "srate: %d format %#x channels %x address %s", |
| 221 | ioHandle, static_cast<audio_devices_t>(device.device), |
| 222 | static_cast<audio_output_flags_t>(flags), halConfig.sample_rate, |
| 223 | halConfig.format, halConfig.channel_mask, |
| 224 | deviceAddressToHal(device).c_str()); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 225 | int status = mDevice->open_output_stream( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 226 | mDevice, ioHandle, static_cast<audio_devices_t>(device.device), |
| 227 | static_cast<audio_output_flags_t>(flags), &halConfig, &halStream, |
| 228 | deviceAddressToHal(device).c_str()); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 229 | ALOGV("open_output_stream status %d stream %p", status, halStream); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 230 | sp<IStreamOut> streamOut; |
| 231 | if (status == OK) { |
Mikhail Naganov | 936279e | 2017-03-29 09:31:18 -0700 | [diff] [blame] | 232 | streamOut = new StreamOut(this, halStream); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 233 | } |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 234 | AudioConfig suggestedConfig; |
| 235 | HidlUtils::audioConfigFromHal(halConfig, &suggestedConfig); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 236 | _hidl_cb(analyzeStatus("open_output_stream", status), streamOut, |
| 237 | suggestedConfig); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 238 | return Void(); |
| 239 | } |
| 240 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 241 | Return<void> Device::openInputStream(int32_t ioHandle, |
| 242 | const DeviceAddress& device, |
| 243 | const AudioConfig& config, |
| 244 | AudioInputFlag flags, AudioSource source, |
| 245 | openInputStream_cb _hidl_cb) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 246 | audio_config_t halConfig; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 247 | HidlUtils::audioConfigToHal(config, &halConfig); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 248 | audio_stream_in_t* halStream; |
| 249 | ALOGV( |
| 250 | "open_input_stream handle: %d devices: %x flags: %#x " |
| 251 | "srate: %d format %#x channels %x address %s source %d", |
| 252 | ioHandle, static_cast<audio_devices_t>(device.device), |
| 253 | static_cast<audio_input_flags_t>(flags), halConfig.sample_rate, |
| 254 | halConfig.format, halConfig.channel_mask, |
| 255 | deviceAddressToHal(device).c_str(), |
| 256 | static_cast<audio_source_t>(source)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 257 | int status = mDevice->open_input_stream( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 258 | mDevice, ioHandle, static_cast<audio_devices_t>(device.device), |
| 259 | &halConfig, &halStream, static_cast<audio_input_flags_t>(flags), |
| 260 | deviceAddressToHal(device).c_str(), |
| 261 | static_cast<audio_source_t>(source)); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 262 | ALOGV("open_input_stream status %d stream %p", status, halStream); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 263 | sp<IStreamIn> streamIn; |
| 264 | if (status == OK) { |
Mikhail Naganov | 936279e | 2017-03-29 09:31:18 -0700 | [diff] [blame] | 265 | streamIn = new StreamIn(this, halStream); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 266 | } |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 267 | AudioConfig suggestedConfig; |
| 268 | HidlUtils::audioConfigFromHal(halConfig, &suggestedConfig); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 269 | _hidl_cb(analyzeStatus("open_input_stream", status), streamIn, |
| 270 | suggestedConfig); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 271 | return Void(); |
| 272 | } |
| 273 | |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 274 | Return<bool> Device::supportsAudioPatches() { |
| 275 | return version() >= AUDIO_DEVICE_API_VERSION_3_0; |
| 276 | } |
| 277 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 278 | Return<void> Device::createAudioPatch(const hidl_vec<AudioPortConfig>& sources, |
| 279 | const hidl_vec<AudioPortConfig>& sinks, |
| 280 | createAudioPatch_cb _hidl_cb) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 281 | Result retval(Result::NOT_SUPPORTED); |
| 282 | AudioPatchHandle patch = 0; |
| 283 | if (version() >= AUDIO_DEVICE_API_VERSION_3_0) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 284 | std::unique_ptr<audio_port_config[]> halSources( |
| 285 | HidlUtils::audioPortConfigsToHal(sources)); |
| 286 | std::unique_ptr<audio_port_config[]> halSinks( |
| 287 | HidlUtils::audioPortConfigsToHal(sinks)); |
Derek Chen | ab24ecd | 2017-04-03 19:00:50 -0400 | [diff] [blame] | 288 | audio_patch_handle_t halPatch = AUDIO_PATCH_HANDLE_NONE; |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 289 | retval = analyzeStatus( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 290 | "create_audio_patch", |
| 291 | mDevice->create_audio_patch(mDevice, sources.size(), &halSources[0], |
| 292 | sinks.size(), &halSinks[0], &halPatch)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 293 | if (retval == Result::OK) { |
| 294 | patch = static_cast<AudioPatchHandle>(halPatch); |
| 295 | } |
| 296 | } |
| 297 | _hidl_cb(retval, patch); |
| 298 | return Void(); |
| 299 | } |
| 300 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 301 | Return<Result> Device::releaseAudioPatch(int32_t patch) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 302 | if (version() >= AUDIO_DEVICE_API_VERSION_3_0) { |
| 303 | return analyzeStatus( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 304 | "release_audio_patch", |
| 305 | mDevice->release_audio_patch( |
| 306 | mDevice, static_cast<audio_patch_handle_t>(patch))); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 307 | } |
| 308 | return Result::NOT_SUPPORTED; |
| 309 | } |
| 310 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 311 | Return<void> Device::getAudioPort(const AudioPort& port, |
| 312 | getAudioPort_cb _hidl_cb) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 313 | audio_port halPort; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 314 | HidlUtils::audioPortToHal(port, &halPort); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 315 | Result retval = analyzeStatus("get_audio_port", |
| 316 | mDevice->get_audio_port(mDevice, &halPort)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 317 | AudioPort resultPort = port; |
| 318 | if (retval == Result::OK) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 319 | HidlUtils::audioPortFromHal(halPort, &resultPort); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 320 | } |
| 321 | _hidl_cb(retval, resultPort); |
| 322 | return Void(); |
| 323 | } |
| 324 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 325 | Return<Result> Device::setAudioPortConfig(const AudioPortConfig& config) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 326 | if (version() >= AUDIO_DEVICE_API_VERSION_3_0) { |
| 327 | struct audio_port_config halPortConfig; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 328 | HidlUtils::audioPortConfigToHal(config, &halPortConfig); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 329 | return analyzeStatus( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 330 | "set_audio_port_config", |
| 331 | mDevice->set_audio_port_config(mDevice, &halPortConfig)); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 332 | } |
| 333 | return Result::NOT_SUPPORTED; |
| 334 | } |
| 335 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 336 | Return<AudioHwSync> Device::getHwAvSync() { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 337 | int halHwAvSync; |
Mikhail Naganov | 86685f5 | 2017-05-03 16:39:28 +0000 | [diff] [blame] | 338 | Result retval = getParam(AudioParameter::keyHwAvSync, &halHwAvSync); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 339 | return retval == Result::OK ? halHwAvSync : AUDIO_HW_SYNC_INVALID; |
| 340 | } |
| 341 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 342 | Return<Result> Device::setScreenState(bool turnedOn) { |
Mikhail Naganov | 86685f5 | 2017-05-03 16:39:28 +0000 | [diff] [blame] | 343 | return setParam(AudioParameter::keyScreenState, turnedOn); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 346 | Return<void> Device::getParameters(const hidl_vec<hidl_string>& keys, |
| 347 | getParameters_cb _hidl_cb) { |
Mikhail Naganov | 86685f5 | 2017-05-03 16:39:28 +0000 | [diff] [blame] | 348 | getParametersImpl(keys, _hidl_cb); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 349 | return Void(); |
| 350 | } |
| 351 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 352 | Return<Result> Device::setParameters( |
| 353 | const hidl_vec<ParameterValue>& parameters) { |
Mikhail Naganov | 86685f5 | 2017-05-03 16:39:28 +0000 | [diff] [blame] | 354 | return setParametersImpl(parameters); |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 357 | Return<void> Device::debugDump(const hidl_handle& fd) { |
Mikhail Naganov | 3e6fe75 | 2017-04-24 10:44:08 -0700 | [diff] [blame] | 358 | if (fd.getNativeHandle() != nullptr && fd->numFds == 1) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 359 | analyzeStatus("dump", mDevice->dump(mDevice, fd->data[0])); |
| 360 | } |
| 361 | return Void(); |
| 362 | } |
| 363 | |
| 364 | } // namespace implementation |
| 365 | } // namespace V2_0 |
| 366 | } // namespace audio |
| 367 | } // namespace hardware |
| 368 | } // namespace android |