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