Daniel Hillenbrand | d81f36f | 2013-04-06 18:56:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
Arne Coucheron | 0de404b | 2013-04-23 11:42:42 +0200 | [diff] [blame] | 3 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Arne Coucheron | 0c85f77 | 2013-04-23 12:18:53 +0200 | [diff] [blame] | 4 | * Copyright (c) 2012-2013, The CyanogenMod Project |
Daniel Hillenbrand | d81f36f | 2013-04-06 18:56:57 +0000 | [diff] [blame] | 5 | * Not a Contribution, Apache license notifications and license are retained |
| 6 | * for attribution purposes only. |
| 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
| 20 | |
| 21 | #define LOG_TAG "audio.primary.msm7x30" |
| 22 | //#define LOG_NDEBUG 0 |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | #include <hardware/hardware.h> |
| 27 | #include <system/audio.h> |
| 28 | #include <hardware/audio.h> |
| 29 | |
| 30 | #include <hardware_legacy/AudioHardwareInterface.h> |
| 31 | #include <hardware_legacy/AudioSystemLegacy.h> |
| 32 | |
| 33 | namespace android_audio_legacy { |
| 34 | |
| 35 | extern "C" { |
| 36 | |
| 37 | struct qcom_audio_module { |
| 38 | struct audio_module module; |
| 39 | }; |
| 40 | |
| 41 | struct qcom_audio_device { |
| 42 | struct audio_hw_device device; |
| 43 | |
| 44 | struct AudioHardwareInterface *hwif; |
| 45 | }; |
| 46 | |
| 47 | struct qcom_stream_out { |
| 48 | struct audio_stream_out stream; |
| 49 | |
| 50 | AudioStreamOut *qcom_out; |
| 51 | }; |
| 52 | |
| 53 | struct qcom_stream_in { |
| 54 | struct audio_stream_in stream; |
| 55 | |
| 56 | AudioStreamIn *qcom_in; |
| 57 | }; |
| 58 | |
| 59 | enum { |
| 60 | HAL_API_REV_1_0, |
| 61 | HAL_API_REV_2_0, |
| 62 | HAL_API_REV_NUM |
| 63 | } hal_api_rev; |
| 64 | static uint32_t audio_device_conv_table[][HAL_API_REV_NUM] = |
| 65 | { |
| 66 | /* output devices */ |
| 67 | { AudioSystem::DEVICE_OUT_EARPIECE, AUDIO_DEVICE_OUT_EARPIECE }, |
| 68 | { AudioSystem::DEVICE_OUT_SPEAKER, AUDIO_DEVICE_OUT_SPEAKER }, |
| 69 | { AudioSystem::DEVICE_OUT_WIRED_HEADSET, AUDIO_DEVICE_OUT_WIRED_HEADSET }, |
| 70 | { AudioSystem::DEVICE_OUT_WIRED_HEADPHONE, AUDIO_DEVICE_OUT_WIRED_HEADPHONE }, |
| 71 | { AudioSystem::DEVICE_OUT_BLUETOOTH_SCO, AUDIO_DEVICE_OUT_BLUETOOTH_SCO }, |
| 72 | { AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET }, |
| 73 | { AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT }, |
| 74 | { AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP }, |
| 75 | { AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES }, |
| 76 | { AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER }, |
| 77 | { AudioSystem::DEVICE_OUT_AUX_DIGITAL, AUDIO_DEVICE_OUT_AUX_DIGITAL }, |
| 78 | { AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET, AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET }, |
| 79 | { AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET, AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET }, |
| 80 | { AudioSystem::DEVICE_OUT_DEFAULT, AUDIO_DEVICE_OUT_DEFAULT }, |
| 81 | /* input devices */ |
| 82 | { AudioSystem::DEVICE_IN_COMMUNICATION, AUDIO_DEVICE_IN_COMMUNICATION }, |
| 83 | { AudioSystem::DEVICE_IN_AMBIENT, AUDIO_DEVICE_IN_AMBIENT }, |
| 84 | { AudioSystem::DEVICE_IN_BUILTIN_MIC, AUDIO_DEVICE_IN_BUILTIN_MIC }, |
| 85 | { AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET }, |
| 86 | { AudioSystem::DEVICE_IN_WIRED_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET }, |
| 87 | { AudioSystem::DEVICE_IN_AUX_DIGITAL, AUDIO_DEVICE_IN_AUX_DIGITAL }, |
| 88 | { AudioSystem::DEVICE_IN_VOICE_CALL, AUDIO_DEVICE_IN_VOICE_CALL }, |
| 89 | { AudioSystem::DEVICE_IN_BACK_MIC, AUDIO_DEVICE_IN_BACK_MIC }, |
| 90 | { AudioSystem::DEVICE_IN_DEFAULT, AUDIO_DEVICE_IN_DEFAULT }, |
| 91 | }; |
| 92 | |
| 93 | static uint32_t convert_audio_device(uint32_t from_device, int from_rev, int to_rev) |
| 94 | { |
| 95 | const uint32_t k_num_devices = sizeof(audio_device_conv_table)/sizeof(uint32_t)/HAL_API_REV_NUM; |
| 96 | uint32_t to_device = AUDIO_DEVICE_NONE; |
| 97 | uint32_t in_bit = 0; |
| 98 | |
| 99 | if (from_rev != HAL_API_REV_1_0) { |
| 100 | in_bit = from_device & AUDIO_DEVICE_BIT_IN; |
| 101 | from_device &= ~AUDIO_DEVICE_BIT_IN; |
| 102 | } |
| 103 | |
| 104 | while (from_device) { |
| 105 | uint32_t i = 31 - __builtin_clz(from_device); |
| 106 | uint32_t cur_device = (1 << i) | in_bit; |
| 107 | |
| 108 | for (i = 0; i < k_num_devices; i++) { |
| 109 | if (audio_device_conv_table[i][from_rev] == cur_device) { |
| 110 | to_device |= audio_device_conv_table[i][to_rev]; |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | from_device &= ~cur_device; |
| 115 | } |
| 116 | return to_device; |
| 117 | } |
| 118 | /** audio_stream_out implementation **/ |
| 119 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 120 | { |
| 121 | const struct qcom_stream_out *out = |
| 122 | reinterpret_cast<const struct qcom_stream_out *>(stream); |
| 123 | return out->qcom_out->sampleRate(); |
| 124 | } |
| 125 | |
| 126 | static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 127 | { |
| 128 | struct qcom_stream_out *out = |
| 129 | reinterpret_cast<struct qcom_stream_out *>(stream); |
| 130 | |
| 131 | ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__); |
| 132 | /* TODO: implement this */ |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 137 | { |
| 138 | const struct qcom_stream_out *out = |
| 139 | reinterpret_cast<const struct qcom_stream_out *>(stream); |
| 140 | return out->qcom_out->bufferSize(); |
| 141 | } |
| 142 | |
| 143 | static audio_channel_mask_t out_get_channels(const struct audio_stream *stream) |
| 144 | { |
| 145 | const struct qcom_stream_out *out = |
| 146 | reinterpret_cast<const struct qcom_stream_out *>(stream); |
| 147 | return (audio_channel_mask_t) out->qcom_out->channels(); |
| 148 | } |
| 149 | |
| 150 | static audio_format_t out_get_format(const struct audio_stream *stream) |
| 151 | { |
| 152 | const struct qcom_stream_out *out = |
| 153 | reinterpret_cast<const struct qcom_stream_out *>(stream); |
| 154 | return (audio_format_t)out->qcom_out->format(); |
| 155 | } |
| 156 | |
| 157 | static int out_set_format(struct audio_stream *stream, audio_format_t format) |
| 158 | { |
| 159 | struct qcom_stream_out *out = |
| 160 | reinterpret_cast<struct qcom_stream_out *>(stream); |
| 161 | ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__); |
| 162 | /* TODO: implement me */ |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static int out_standby(struct audio_stream *stream) |
| 167 | { |
| 168 | struct qcom_stream_out *out = |
| 169 | reinterpret_cast<struct qcom_stream_out *>(stream); |
| 170 | return out->qcom_out->standby(); |
| 171 | } |
| 172 | |
| 173 | static int out_dump(const struct audio_stream *stream, int fd) |
| 174 | { |
| 175 | const struct qcom_stream_out *out = |
| 176 | reinterpret_cast<const struct qcom_stream_out *>(stream); |
| 177 | Vector<String16> args; |
| 178 | return out->qcom_out->dump(fd, args); |
| 179 | } |
| 180 | |
| 181 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 182 | { |
| 183 | struct qcom_stream_out *out = |
| 184 | reinterpret_cast<struct qcom_stream_out *>(stream); |
| 185 | int val; |
| 186 | String8 s8 = String8(kvpairs); |
| 187 | AudioParameter parms = AudioParameter(String8(kvpairs)); |
| 188 | |
| 189 | if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) { |
| 190 | val = convert_audio_device(val, HAL_API_REV_2_0, HAL_API_REV_1_0); |
| 191 | parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING)); |
| 192 | parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val); |
| 193 | s8 = parms.toString(); |
| 194 | } |
| 195 | return out->qcom_out->setParameters(s8); |
| 196 | } |
| 197 | |
| 198 | static char * out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 199 | { |
| 200 | const struct qcom_stream_out *out = |
| 201 | reinterpret_cast<const struct qcom_stream_out *>(stream); |
| 202 | String8 s8; |
| 203 | int val; |
| 204 | s8 = out->qcom_out->getParameters(String8(keys)); |
| 205 | AudioParameter parms = AudioParameter(s8); |
| 206 | if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) { |
| 207 | val = convert_audio_device(val, HAL_API_REV_1_0, HAL_API_REV_2_0); |
| 208 | parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING)); |
| 209 | parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val); |
| 210 | s8 = parms.toString(); |
| 211 | } |
| 212 | return strdup(s8.string()); |
| 213 | } |
| 214 | |
| 215 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 216 | { |
| 217 | const struct qcom_stream_out *out = |
| 218 | reinterpret_cast<const struct qcom_stream_out *>(stream); |
| 219 | return out->qcom_out->latency(); |
| 220 | } |
| 221 | |
| 222 | static int out_set_volume(struct audio_stream_out *stream, float left, |
| 223 | float right) |
| 224 | { |
| 225 | struct qcom_stream_out *out = |
| 226 | reinterpret_cast<struct qcom_stream_out *>(stream); |
| 227 | return out->qcom_out->setVolume(left, right); |
| 228 | } |
| 229 | |
| 230 | static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, |
| 231 | size_t bytes) |
| 232 | { |
| 233 | struct qcom_stream_out *out = |
| 234 | reinterpret_cast<struct qcom_stream_out *>(stream); |
| 235 | usleep(5); |
| 236 | return out->qcom_out->write(buffer, bytes); |
| 237 | } |
| 238 | |
| 239 | static int out_get_render_position(const struct audio_stream_out *stream, |
| 240 | uint32_t *dsp_frames) |
| 241 | { |
| 242 | const struct qcom_stream_out *out = |
| 243 | reinterpret_cast<const struct qcom_stream_out *>(stream); |
| 244 | return out->qcom_out->getRenderPosition(dsp_frames); |
| 245 | } |
| 246 | |
Daniel Hillenbrand | d81f36f | 2013-04-06 18:56:57 +0000 | [diff] [blame] | 247 | static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 248 | { |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 253 | { |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int out_get_next_write_timestamp(const struct audio_stream_out *stream, |
| 258 | int64_t *timestamp) |
| 259 | { |
Arne Coucheron | 0de404b | 2013-04-23 11:42:42 +0200 | [diff] [blame] | 260 | return -EINVAL; |
Daniel Hillenbrand | d81f36f | 2013-04-06 18:56:57 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /** audio_stream_in implementation **/ |
| 264 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 265 | { |
| 266 | const struct qcom_stream_in *in = |
| 267 | reinterpret_cast<const struct qcom_stream_in *>(stream); |
| 268 | return in->qcom_in->sampleRate(); |
| 269 | } |
| 270 | |
| 271 | static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 272 | { |
| 273 | struct qcom_stream_in *in = |
| 274 | reinterpret_cast<struct qcom_stream_in *>(stream); |
| 275 | |
| 276 | ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__); |
| 277 | /* TODO: implement this */ |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 282 | { |
| 283 | const struct qcom_stream_in *in = |
| 284 | reinterpret_cast<const struct qcom_stream_in *>(stream); |
| 285 | return in->qcom_in->bufferSize(); |
| 286 | } |
| 287 | |
| 288 | static audio_channel_mask_t in_get_channels(const struct audio_stream *stream) |
| 289 | { |
| 290 | const struct qcom_stream_in *in = |
| 291 | reinterpret_cast<const struct qcom_stream_in *>(stream); |
| 292 | return (audio_channel_mask_t) in->qcom_in->channels(); |
| 293 | } |
| 294 | |
| 295 | static audio_format_t in_get_format(const struct audio_stream *stream) |
| 296 | { |
| 297 | const struct qcom_stream_in *in = |
| 298 | reinterpret_cast<const struct qcom_stream_in *>(stream); |
| 299 | return (audio_format_t)in->qcom_in->format(); |
| 300 | } |
| 301 | |
| 302 | static int in_set_format(struct audio_stream *stream, audio_format_t format) |
| 303 | { |
| 304 | struct qcom_stream_in *in = |
| 305 | reinterpret_cast<struct qcom_stream_in *>(stream); |
| 306 | ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__); |
| 307 | /* TODO: implement me */ |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static int in_standby(struct audio_stream *stream) |
| 312 | { |
| 313 | struct qcom_stream_in *in = reinterpret_cast<struct qcom_stream_in *>(stream); |
| 314 | return in->qcom_in->standby(); |
| 315 | } |
| 316 | |
| 317 | static int in_dump(const struct audio_stream *stream, int fd) |
| 318 | { |
| 319 | const struct qcom_stream_in *in = |
| 320 | reinterpret_cast<const struct qcom_stream_in *>(stream); |
| 321 | Vector<String16> args; |
| 322 | return in->qcom_in->dump(fd, args); |
| 323 | } |
| 324 | |
| 325 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 326 | { |
| 327 | struct qcom_stream_in *in = |
| 328 | reinterpret_cast<struct qcom_stream_in *>(stream); |
| 329 | int val; |
| 330 | AudioParameter parms = AudioParameter(String8(kvpairs)); |
| 331 | String8 s8 = String8(kvpairs); |
| 332 | |
| 333 | if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) { |
| 334 | val = convert_audio_device(val, HAL_API_REV_2_0, HAL_API_REV_1_0); |
| 335 | parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING)); |
| 336 | parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val); |
| 337 | s8 = parms.toString(); |
| 338 | } |
| 339 | return in->qcom_in->setParameters(s8); |
| 340 | } |
| 341 | |
| 342 | static char * in_get_parameters(const struct audio_stream *stream, |
| 343 | const char *keys) |
| 344 | { |
| 345 | const struct qcom_stream_in *in = |
| 346 | reinterpret_cast<const struct qcom_stream_in *>(stream); |
| 347 | String8 s8; |
| 348 | int val; |
| 349 | s8 = in->qcom_in->getParameters(String8(keys)); |
| 350 | AudioParameter parms = AudioParameter(s8); |
| 351 | if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) { |
| 352 | val = convert_audio_device(val, HAL_API_REV_1_0, HAL_API_REV_2_0); |
| 353 | parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING)); |
| 354 | parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val); |
| 355 | s8 = parms.toString(); |
| 356 | } |
| 357 | return strdup(s8.string()); |
| 358 | } |
| 359 | |
| 360 | static int in_set_gain(struct audio_stream_in *stream, float gain) |
| 361 | { |
| 362 | struct qcom_stream_in *in = |
| 363 | reinterpret_cast<struct qcom_stream_in *>(stream); |
| 364 | return in->qcom_in->setGain(gain); |
| 365 | } |
| 366 | |
| 367 | static ssize_t in_read(struct audio_stream_in *stream, void* buffer, |
| 368 | size_t bytes) |
| 369 | { |
| 370 | struct qcom_stream_in *in = |
| 371 | reinterpret_cast<struct qcom_stream_in *>(stream); |
| 372 | return in->qcom_in->read(buffer, bytes); |
| 373 | } |
| 374 | |
| 375 | static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) |
| 376 | { |
| 377 | struct qcom_stream_in *in = |
| 378 | reinterpret_cast<struct qcom_stream_in *>(stream); |
| 379 | return in->qcom_in->getInputFramesLost(); |
| 380 | } |
| 381 | |
| 382 | static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 383 | { |
| 384 | const struct qcom_stream_in *in = |
| 385 | reinterpret_cast<const struct qcom_stream_in *>(stream); |
| 386 | return in->qcom_in->addAudioEffect(effect); |
| 387 | } |
| 388 | |
| 389 | static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 390 | { |
| 391 | const struct qcom_stream_in *in = |
| 392 | reinterpret_cast<const struct qcom_stream_in *>(stream); |
| 393 | return in->qcom_in->removeAudioEffect(effect); |
| 394 | } |
| 395 | |
| 396 | /** audio_hw_device implementation **/ |
| 397 | static inline struct qcom_audio_device * to_ladev(struct audio_hw_device *dev) |
| 398 | { |
| 399 | return reinterpret_cast<struct qcom_audio_device *>(dev); |
| 400 | } |
| 401 | |
| 402 | static inline const struct qcom_audio_device * to_cladev(const struct audio_hw_device *dev) |
| 403 | { |
| 404 | return reinterpret_cast<const struct qcom_audio_device *>(dev); |
| 405 | } |
| 406 | |
| 407 | |
| 408 | static int adev_init_check(const struct audio_hw_device *dev) |
| 409 | { |
| 410 | const struct qcom_audio_device *qadev = to_cladev(dev); |
| 411 | |
| 412 | return qadev->hwif->initCheck(); |
| 413 | } |
| 414 | |
| 415 | static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 416 | { |
| 417 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 418 | return qadev->hwif->setVoiceVolume(volume); |
| 419 | } |
| 420 | |
| 421 | static int adev_set_master_volume(struct audio_hw_device *dev, float volume) |
| 422 | { |
| 423 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 424 | return qadev->hwif->setMasterVolume(volume); |
| 425 | } |
| 426 | static int adev_get_master_volume(struct audio_hw_device *dev, float *volume) { |
| 427 | |
| 428 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 429 | return qadev->hwif->getMasterVolume(volume); |
| 430 | } |
| 431 | |
| 432 | #ifdef QCOM_FM_ENABLED |
| 433 | static int adev_set_fm_volume(struct audio_hw_device *dev, float volume) |
| 434 | { |
| 435 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 436 | return qadev->hwif->setFmVolume(volume); |
| 437 | } |
| 438 | #endif |
| 439 | static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 440 | { |
| 441 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 442 | return qadev->hwif->setMode((int)mode); |
| 443 | } |
| 444 | |
| 445 | static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 446 | { |
| 447 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 448 | return qadev->hwif->setMicMute(state); |
| 449 | } |
| 450 | |
| 451 | static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 452 | { |
| 453 | const struct qcom_audio_device *qadev = to_cladev(dev); |
| 454 | return qadev->hwif->getMicMute(state); |
| 455 | } |
| 456 | |
| 457 | static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) |
| 458 | { |
| 459 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 460 | return qadev->hwif->setParameters(String8(kvpairs)); |
| 461 | } |
| 462 | |
| 463 | static char * adev_get_parameters(const struct audio_hw_device *dev, |
| 464 | const char *keys) |
| 465 | { |
| 466 | const struct qcom_audio_device *qadev = to_cladev(dev); |
| 467 | String8 s8; |
| 468 | |
| 469 | s8 = qadev->hwif->getParameters(String8(keys)); |
| 470 | return strdup(s8.string()); |
| 471 | } |
| 472 | |
| 473 | static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, |
| 474 | const struct audio_config *config) |
| 475 | { |
| 476 | const struct qcom_audio_device *qadev = to_cladev(dev); |
| 477 | uint8_t channelCount = popcount(config->channel_mask); |
| 478 | return qadev->hwif->getInputBufferSize(config->sample_rate,config->format,channelCount); |
| 479 | } |
| 480 | |
Arne Coucheron | 0de404b | 2013-04-23 11:42:42 +0200 | [diff] [blame] | 481 | #ifdef QCOM_TUNNEL_LPA_ENABLED |
| 482 | static int adev_open_output_session(struct audio_hw_device *dev, |
| 483 | uint32_t devices, |
| 484 | int *format, |
| 485 | int sessionId, |
| 486 | uint32_t samplingRate, |
| 487 | uint32_t channels, |
| 488 | struct audio_stream_out **stream_out) |
| 489 | { |
| 490 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 491 | status_t status; |
| 492 | struct qcom_stream_out *out; |
| 493 | int ret; |
Daniel Hillenbrand | d81f36f | 2013-04-06 18:56:57 +0000 | [diff] [blame] | 494 | |
Arne Coucheron | 0de404b | 2013-04-23 11:42:42 +0200 | [diff] [blame] | 495 | out = (struct qcom_stream_out *)calloc(1, sizeof(*out)); |
| 496 | if (!out) |
| 497 | return -ENOMEM; |
| 498 | |
| 499 | devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0); |
| 500 | status = static_cast<audio_output_flags_t> (flags); |
| 501 | |
| 502 | out->qcom_out = qadev->hwif->openOutputSession(devices, format,&status,sessionId,samplingRate,channels); |
| 503 | if (!out->qcom_out) { |
| 504 | ret = status; |
| 505 | goto err_open; |
| 506 | } |
| 507 | |
| 508 | out->stream.common.standby = out_standby; |
| 509 | out->stream.common.set_parameters = out_set_parameters; |
| 510 | out->stream.set_volume = out_set_volume; |
| 511 | |
| 512 | *stream_out = &out->stream; |
| 513 | return 0; |
| 514 | |
| 515 | err_open: |
| 516 | free(out); |
| 517 | *stream_out = NULL; |
| 518 | return ret; |
| 519 | } |
| 520 | #endif /* QCOM_TUNNEL_LPA_ENABLED */ |
Daniel Hillenbrand | d81f36f | 2013-04-06 18:56:57 +0000 | [diff] [blame] | 521 | static int adev_open_output_stream(struct audio_hw_device *dev, |
| 522 | audio_io_handle_t handle, |
| 523 | audio_devices_t devices, |
| 524 | audio_output_flags_t flags, |
| 525 | struct audio_config *config, |
| 526 | struct audio_stream_out **stream_out) |
| 527 | { |
| 528 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 529 | status_t status; |
| 530 | struct qcom_stream_out *out; |
| 531 | int ret; |
| 532 | |
| 533 | out = (struct qcom_stream_out *)calloc(1, sizeof(*out)); |
| 534 | if (!out) |
| 535 | return -ENOMEM; |
| 536 | |
| 537 | devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0); |
| 538 | status = static_cast<audio_output_flags_t> (flags); |
| 539 | |
| 540 | out->qcom_out = qadev->hwif->openOutputStream(devices, (int *) &config->format, |
| 541 | &config->channel_mask, |
| 542 | &config->sample_rate, |
| 543 | &status); |
| 544 | if (!out->qcom_out) { |
| 545 | ret = status; |
| 546 | goto err_open; |
| 547 | } |
| 548 | |
| 549 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 550 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 551 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 552 | out->stream.common.get_channels = out_get_channels; |
| 553 | out->stream.common.get_format = out_get_format; |
| 554 | out->stream.common.set_format = out_set_format; |
| 555 | out->stream.common.standby = out_standby; |
| 556 | out->stream.common.dump = out_dump; |
| 557 | out->stream.common.set_parameters = out_set_parameters; |
| 558 | out->stream.common.get_parameters = out_get_parameters; |
| 559 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 560 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
| 561 | out->stream.get_latency = out_get_latency; |
| 562 | out->stream.set_volume = out_set_volume; |
| 563 | out->stream.write = out_write; |
| 564 | out->stream.get_render_position = out_get_render_position; |
| 565 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
Daniel Hillenbrand | d81f36f | 2013-04-06 18:56:57 +0000 | [diff] [blame] | 566 | |
| 567 | *stream_out = &out->stream; |
| 568 | return 0; |
| 569 | |
| 570 | err_open: |
| 571 | free(out); |
| 572 | *stream_out = NULL; |
| 573 | return ret; |
| 574 | } |
| 575 | |
| 576 | static void adev_close_output_stream(struct audio_hw_device *dev, |
| 577 | struct audio_stream_out* stream) |
| 578 | { |
| 579 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 580 | struct qcom_stream_out *out = reinterpret_cast<struct qcom_stream_out *>(stream); |
| 581 | |
| 582 | qadev->hwif->closeOutputStream(out->qcom_out); |
| 583 | free(out); |
| 584 | } |
| 585 | |
| 586 | /** This method creates and opens the audio hardware input stream */ |
| 587 | static int adev_open_input_stream(struct audio_hw_device *dev, |
| 588 | audio_io_handle_t handle, |
| 589 | audio_devices_t devices, |
| 590 | struct audio_config *config, |
| 591 | struct audio_stream_in **stream_in) |
| 592 | { |
| 593 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 594 | status_t status; |
| 595 | struct qcom_stream_in *in; |
| 596 | int ret; |
| 597 | |
| 598 | in = (struct qcom_stream_in *)calloc(1, sizeof(*in)); |
| 599 | if (!in) |
| 600 | return -ENOMEM; |
| 601 | |
Sunil Joseph | 672734e | 2012-10-26 17:19:49 +0530 | [diff] [blame] | 602 | devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0); |
Daniel Hillenbrand | d81f36f | 2013-04-06 18:56:57 +0000 | [diff] [blame] | 603 | in->qcom_in = qadev->hwif->openInputStream(devices, (int *)&config->format, |
| 604 | &config->channel_mask, |
| 605 | &config->sample_rate, |
| 606 | &status, |
| 607 | (AudioSystem::audio_in_acoustics)0); |
| 608 | if (!in->qcom_in) { |
| 609 | ret = status; |
| 610 | goto err_open; |
| 611 | } |
| 612 | |
| 613 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 614 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 615 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 616 | in->stream.common.get_channels = in_get_channels; |
| 617 | in->stream.common.get_format = in_get_format; |
| 618 | in->stream.common.set_format = in_set_format; |
| 619 | in->stream.common.standby = in_standby; |
| 620 | in->stream.common.dump = in_dump; |
| 621 | in->stream.common.set_parameters = in_set_parameters; |
| 622 | in->stream.common.get_parameters = in_get_parameters; |
| 623 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 624 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
| 625 | in->stream.set_gain = in_set_gain; |
| 626 | in->stream.read = in_read; |
| 627 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
| 628 | |
| 629 | *stream_in = &in->stream; |
| 630 | return 0; |
| 631 | |
| 632 | err_open: |
| 633 | free(in); |
| 634 | *stream_in = NULL; |
| 635 | return ret; |
| 636 | } |
| 637 | |
| 638 | static void adev_close_input_stream(struct audio_hw_device *dev, |
| 639 | struct audio_stream_in *stream) |
| 640 | { |
| 641 | struct qcom_audio_device *qadev = to_ladev(dev); |
| 642 | struct qcom_stream_in *in = |
| 643 | reinterpret_cast<struct qcom_stream_in *>(stream); |
| 644 | |
| 645 | qadev->hwif->closeInputStream(in->qcom_in); |
| 646 | free(in); |
| 647 | } |
| 648 | |
| 649 | static int adev_dump(const struct audio_hw_device *dev, int fd) |
| 650 | { |
| 651 | const struct qcom_audio_device *qadev = to_cladev(dev); |
| 652 | Vector<String16> args; |
| 653 | |
| 654 | return qadev->hwif->dumpState(fd, args); |
| 655 | } |
| 656 | |
| 657 | static int qcom_adev_close(hw_device_t* device) |
| 658 | { |
| 659 | struct audio_hw_device *hwdev = |
| 660 | reinterpret_cast<struct audio_hw_device *>(device); |
| 661 | struct qcom_audio_device *qadev = to_ladev(hwdev); |
| 662 | |
| 663 | if (!qadev) |
| 664 | return 0; |
| 665 | |
| 666 | if (qadev->hwif) |
| 667 | delete qadev->hwif; |
| 668 | |
| 669 | free(qadev); |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | static int qcom_adev_open(const hw_module_t* module, const char* name, |
| 674 | hw_device_t** device) |
| 675 | { |
| 676 | struct qcom_audio_device *qadev; |
| 677 | int ret; |
| 678 | |
| 679 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) |
| 680 | return -EINVAL; |
| 681 | |
| 682 | qadev = (struct qcom_audio_device *)calloc(1, sizeof(*qadev)); |
| 683 | if (!qadev) |
| 684 | return -ENOMEM; |
| 685 | |
| 686 | qadev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 687 | qadev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
| 688 | qadev->device.common.module = const_cast<hw_module_t*>(module); |
| 689 | qadev->device.common.close = qcom_adev_close; |
| 690 | |
| 691 | qadev->device.init_check = adev_init_check; |
| 692 | qadev->device.set_voice_volume = adev_set_voice_volume; |
| 693 | qadev->device.set_master_volume = adev_set_master_volume; |
| 694 | qadev->device.get_master_volume = adev_get_master_volume; |
| 695 | #ifdef QCOM_FM_ENABLED |
| 696 | qadev->device.set_fm_volume = adev_set_fm_volume; |
| 697 | #endif |
| 698 | qadev->device.set_mode = adev_set_mode; |
| 699 | qadev->device.set_mic_mute = adev_set_mic_mute; |
| 700 | qadev->device.get_mic_mute = adev_get_mic_mute; |
| 701 | qadev->device.set_parameters = adev_set_parameters; |
| 702 | qadev->device.get_parameters = adev_get_parameters; |
| 703 | qadev->device.get_input_buffer_size = adev_get_input_buffer_size; |
| 704 | qadev->device.open_output_stream = adev_open_output_stream; |
Arne Coucheron | 0de404b | 2013-04-23 11:42:42 +0200 | [diff] [blame] | 705 | #ifdef QCOM_TUNNEL_LPA_ENABLED |
| 706 | qadev->device.open_output_session = adev_open_output_session; |
| 707 | #endif /* QCOM_TUNNEL_LPA_ENABLED */ |
Daniel Hillenbrand | d81f36f | 2013-04-06 18:56:57 +0000 | [diff] [blame] | 708 | qadev->device.close_output_stream = adev_close_output_stream; |
| 709 | qadev->device.open_input_stream = adev_open_input_stream; |
| 710 | qadev->device.close_input_stream = adev_close_input_stream; |
| 711 | qadev->device.dump = adev_dump; |
| 712 | |
| 713 | qadev->hwif = createAudioHardware(); |
| 714 | if (!qadev->hwif) { |
| 715 | ret = -EIO; |
| 716 | goto err_create_audio_hw; |
| 717 | } |
| 718 | |
| 719 | *device = &qadev->device.common; |
| 720 | |
| 721 | return 0; |
| 722 | |
| 723 | err_create_audio_hw: |
| 724 | free(qadev); |
| 725 | return ret; |
| 726 | } |
| 727 | |
| 728 | static struct hw_module_methods_t qcom_audio_module_methods = { |
| 729 | open: qcom_adev_open |
| 730 | }; |
| 731 | |
| 732 | struct qcom_audio_module HAL_MODULE_INFO_SYM = { |
| 733 | module: { |
| 734 | common: { |
| 735 | tag: HARDWARE_MODULE_TAG, |
| 736 | module_api_version: AUDIO_DEVICE_API_VERSION_1_0, |
| 737 | hal_api_version: HARDWARE_HAL_API_VERSION, |
| 738 | id: AUDIO_HARDWARE_MODULE_ID, |
| 739 | name: "QCOM Audio HW HAL", |
| 740 | author: "Code Aurora Forum", |
| 741 | methods: &qcom_audio_module_methods, |
| 742 | dso : NULL, |
| 743 | reserved : {0}, |
| 744 | }, |
| 745 | }, |
| 746 | }; |
| 747 | |
| 748 | }; // extern "C" |
| 749 | |
| 750 | }; // namespace android_audio_legacy |