Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [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 | #define LOG_TAG "audio_hw_hikey" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <errno.h> |
| 21 | #include <malloc.h> |
| 22 | #include <pthread.h> |
| 23 | #include <stdint.h> |
| 24 | #include <sys/time.h> |
| 25 | #include <stdlib.h> |
| 26 | |
| 27 | #include <cutils/log.h> |
| 28 | #include <cutils/str_parms.h> |
| 29 | #include <cutils/properties.h> |
| 30 | |
| 31 | #include <hardware/hardware.h> |
| 32 | #include <system/audio.h> |
| 33 | #include <hardware/audio.h> |
| 34 | |
| 35 | #include <sound/asound.h> |
| 36 | #include <tinyalsa/asoundlib.h> |
| 37 | #include <audio_utils/resampler.h> |
| 38 | #include <audio_utils/echo_reference.h> |
| 39 | #include <hardware/audio_effect.h> |
| 40 | #include <hardware/audio_alsaops.h> |
| 41 | #include <audio_effects/effect_aec.h> |
| 42 | |
Niranjan Yadla | efa6b4d | 2017-09-18 13:31:35 -0700 | [diff] [blame] | 43 | #include <sys/ioctl.h> |
| 44 | #include <linux/audio_hifi.h> |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 45 | |
| 46 | #define CARD_OUT 0 |
| 47 | #define PORT_CODEC 0 |
| 48 | /* Minimum granularity - Arbitrary but small value */ |
| 49 | #define CODEC_BASE_FRAME_COUNT 32 |
| 50 | |
| 51 | /* number of base blocks in a short period (low latency) */ |
| 52 | #define PERIOD_MULTIPLIER 32 /* 21 ms */ |
| 53 | /* number of frames per short period (low latency) */ |
| 54 | #define PERIOD_SIZE (CODEC_BASE_FRAME_COUNT * PERIOD_MULTIPLIER) |
| 55 | /* number of pseudo periods for low latency playback */ |
| 56 | #define PLAYBACK_PERIOD_COUNT 4 |
| 57 | #define PLAYBACK_PERIOD_START_THRESHOLD 2 |
| 58 | #define CODEC_SAMPLING_RATE 48000 |
| 59 | #define CHANNEL_STEREO 2 |
| 60 | #define MIN_WRITE_SLEEP_US 5000 |
| 61 | |
| 62 | struct stub_stream_in { |
| 63 | struct audio_stream_in stream; |
| 64 | }; |
| 65 | |
| 66 | struct alsa_audio_device { |
| 67 | struct audio_hw_device hw_device; |
| 68 | |
| 69 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 70 | int devices; |
| 71 | struct alsa_stream_in *active_input; |
| 72 | struct alsa_stream_out *active_output; |
| 73 | bool mic_mute; |
| 74 | }; |
| 75 | |
| 76 | struct alsa_stream_out { |
| 77 | struct audio_stream_out stream; |
| 78 | |
| 79 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 80 | struct pcm_config config; |
| 81 | struct pcm *pcm; |
| 82 | bool unavailable; |
| 83 | int standby; |
| 84 | struct alsa_audio_device *dev; |
| 85 | int write_threshold; |
| 86 | unsigned int written; |
| 87 | }; |
| 88 | |
| 89 | |
| 90 | /* must be called with hw device and output stream mutexes locked */ |
| 91 | static int start_output_stream(struct alsa_stream_out *out) |
| 92 | { |
| 93 | struct alsa_audio_device *adev = out->dev; |
| 94 | |
| 95 | if (out->unavailable) |
| 96 | return -ENODEV; |
| 97 | |
| 98 | /* default to low power: will be corrected in out_write if necessary before first write to |
| 99 | * tinyalsa. |
| 100 | */ |
| 101 | out->write_threshold = PLAYBACK_PERIOD_COUNT * PERIOD_SIZE; |
| 102 | out->config.start_threshold = PLAYBACK_PERIOD_START_THRESHOLD * PERIOD_SIZE; |
| 103 | out->config.avail_min = PERIOD_SIZE; |
| 104 | |
| 105 | out->pcm = pcm_open(CARD_OUT, PORT_CODEC, PCM_OUT | PCM_MMAP | PCM_NOIRQ | PCM_MONOTONIC, &out->config); |
| 106 | |
| 107 | if (!pcm_is_ready(out->pcm)) { |
| 108 | ALOGE("cannot open pcm_out driver: %s", pcm_get_error(out->pcm)); |
| 109 | pcm_close(out->pcm); |
| 110 | adev->active_output = NULL; |
| 111 | out->unavailable = true; |
| 112 | return -ENODEV; |
| 113 | } |
| 114 | |
| 115 | adev->active_output = out; |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 120 | { |
| 121 | struct alsa_stream_out *out = (struct alsa_stream_out *)stream; |
| 122 | return out->config.rate; |
| 123 | } |
| 124 | |
| 125 | static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 126 | { |
| 127 | ALOGV("out_set_sample_rate: %d", 0); |
| 128 | return -ENOSYS; |
| 129 | } |
| 130 | |
| 131 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 132 | { |
| 133 | ALOGV("out_get_buffer_size: %d", 4096); |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 134 | |
| 135 | /* return the closest majoring multiple of 16 frames, as |
| 136 | * audioflinger expects audio buffers to be a multiple of 16 frames */ |
| 137 | size_t size = PERIOD_SIZE; |
| 138 | size = ((size + 15) / 16) * 16; |
| 139 | return size * audio_stream_out_frame_size((struct audio_stream_out *)stream); |
| 140 | } |
| 141 | |
| 142 | static audio_channel_mask_t out_get_channels(const struct audio_stream *stream) |
| 143 | { |
| 144 | ALOGV("out_get_channels"); |
| 145 | struct alsa_stream_out *out = (struct alsa_stream_out *)stream; |
| 146 | return audio_channel_out_mask_from_count(out->config.channels); |
| 147 | } |
| 148 | |
| 149 | static audio_format_t out_get_format(const struct audio_stream *stream) |
| 150 | { |
| 151 | ALOGV("out_get_format"); |
| 152 | struct alsa_stream_out *out = (struct alsa_stream_out *)stream; |
| 153 | return audio_format_from_pcm_format(out->config.format); |
| 154 | } |
| 155 | |
| 156 | static int out_set_format(struct audio_stream *stream, audio_format_t format) |
| 157 | { |
| 158 | ALOGV("out_set_format: %d",format); |
| 159 | return -ENOSYS; |
| 160 | } |
| 161 | |
| 162 | static int do_output_standby(struct alsa_stream_out *out) |
| 163 | { |
| 164 | struct alsa_audio_device *adev = out->dev; |
| 165 | |
| 166 | if (!out->standby) { |
| 167 | pcm_close(out->pcm); |
| 168 | out->pcm = NULL; |
| 169 | adev->active_output = NULL; |
| 170 | out->standby = 1; |
| 171 | } |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static int out_standby(struct audio_stream *stream) |
| 176 | { |
| 177 | ALOGV("out_standby"); |
| 178 | struct alsa_stream_out *out = (struct alsa_stream_out *)stream; |
| 179 | int status; |
| 180 | |
| 181 | pthread_mutex_lock(&out->dev->lock); |
| 182 | pthread_mutex_lock(&out->lock); |
| 183 | status = do_output_standby(out); |
| 184 | pthread_mutex_unlock(&out->lock); |
| 185 | pthread_mutex_unlock(&out->dev->lock); |
| 186 | return status; |
| 187 | } |
| 188 | |
| 189 | static int out_dump(const struct audio_stream *stream, int fd) |
| 190 | { |
| 191 | ALOGV("out_dump"); |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 196 | { |
| 197 | ALOGV("out_set_parameters"); |
| 198 | struct alsa_stream_out *out = (struct alsa_stream_out *)stream; |
| 199 | struct alsa_audio_device *adev = out->dev; |
| 200 | struct str_parms *parms; |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 201 | char value[32]; |
| 202 | int ret, val = 0; |
| 203 | |
| 204 | parms = str_parms_create_str(kvpairs); |
| 205 | |
| 206 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
| 207 | if (ret >= 0) { |
| 208 | val = atoi(value); |
| 209 | pthread_mutex_lock(&adev->lock); |
| 210 | pthread_mutex_lock(&out->lock); |
| 211 | if (((adev->devices & AUDIO_DEVICE_OUT_ALL) != val) && (val != 0)) { |
| 212 | adev->devices &= ~AUDIO_DEVICE_OUT_ALL; |
| 213 | adev->devices |= val; |
| 214 | } |
| 215 | pthread_mutex_unlock(&out->lock); |
| 216 | pthread_mutex_unlock(&adev->lock); |
| 217 | } |
| 218 | |
| 219 | str_parms_destroy(parms); |
| 220 | return ret; |
| 221 | } |
| 222 | |
| 223 | static char * out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 224 | { |
| 225 | ALOGV("out_get_parameters"); |
| 226 | return strdup(""); |
| 227 | } |
| 228 | |
| 229 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 230 | { |
| 231 | ALOGV("out_get_latency"); |
| 232 | struct alsa_stream_out *out = (struct alsa_stream_out *)stream; |
| 233 | return (PERIOD_SIZE * PLAYBACK_PERIOD_COUNT * 1000) / out->config.rate; |
| 234 | } |
| 235 | |
| 236 | static int out_set_volume(struct audio_stream_out *stream, float left, |
| 237 | float right) |
| 238 | { |
| 239 | ALOGV("out_set_volume: Left:%f Right:%f", left, right); |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, |
| 244 | size_t bytes) |
| 245 | { |
| 246 | int ret; |
| 247 | struct alsa_stream_out *out = (struct alsa_stream_out *)stream; |
| 248 | struct alsa_audio_device *adev = out->dev; |
| 249 | size_t frame_size = audio_stream_out_frame_size(stream); |
| 250 | size_t out_frames = bytes / frame_size; |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 251 | |
| 252 | /* acquiring hw device mutex systematically is useful if a low priority thread is waiting |
| 253 | * on the output stream mutex - e.g. executing select_mode() while holding the hw device |
| 254 | * mutex |
| 255 | */ |
| 256 | pthread_mutex_lock(&adev->lock); |
| 257 | pthread_mutex_lock(&out->lock); |
| 258 | if (out->standby) { |
| 259 | ret = start_output_stream(out); |
| 260 | if (ret != 0) { |
| 261 | pthread_mutex_unlock(&adev->lock); |
| 262 | goto exit; |
| 263 | } |
| 264 | out->standby = 0; |
| 265 | } |
| 266 | |
| 267 | pthread_mutex_unlock(&adev->lock); |
| 268 | |
Niranjan Yadla | efa6b4d | 2017-09-18 13:31:35 -0700 | [diff] [blame] | 269 | |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 270 | ret = pcm_mmap_write(out->pcm, buffer, out_frames * frame_size); |
| 271 | if (ret == 0) { |
| 272 | out->written += out_frames; |
| 273 | } |
| 274 | exit: |
| 275 | pthread_mutex_unlock(&out->lock); |
| 276 | |
| 277 | if (ret != 0) { |
| 278 | usleep((int64_t)bytes * 1000000 / audio_stream_out_frame_size(stream) / |
| 279 | out_get_sample_rate(&stream->common)); |
| 280 | } |
| 281 | |
| 282 | return bytes; |
| 283 | } |
| 284 | |
| 285 | static int out_get_render_position(const struct audio_stream_out *stream, |
| 286 | uint32_t *dsp_frames) |
| 287 | { |
| 288 | *dsp_frames = 0; |
| 289 | ALOGV("out_get_render_position: dsp_frames: %p", dsp_frames); |
| 290 | return -EINVAL; |
| 291 | } |
| 292 | |
| 293 | static int out_get_presentation_position(const struct audio_stream_out *stream, |
| 294 | uint64_t *frames, struct timespec *timestamp) |
| 295 | { |
| 296 | struct alsa_stream_out *out = (struct alsa_stream_out *)stream; |
| 297 | int ret = -1; |
| 298 | |
| 299 | if (out->pcm) { |
| 300 | unsigned int avail; |
| 301 | if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) { |
| 302 | size_t kernel_buffer_size = out->config.period_size * out->config.period_count; |
| 303 | int64_t signed_frames = out->written - kernel_buffer_size + avail; |
| 304 | if (signed_frames >= 0) { |
| 305 | *frames = signed_frames; |
| 306 | ret = 0; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | |
| 315 | static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 316 | { |
| 317 | ALOGV("out_add_audio_effect: %p", effect); |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 322 | { |
| 323 | ALOGV("out_remove_audio_effect: %p", effect); |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static int out_get_next_write_timestamp(const struct audio_stream_out *stream, |
| 328 | int64_t *timestamp) |
| 329 | { |
| 330 | *timestamp = 0; |
| 331 | ALOGV("out_get_next_write_timestamp: %ld", (long int)(*timestamp)); |
| 332 | return -EINVAL; |
| 333 | } |
| 334 | |
| 335 | /** audio_stream_in implementation **/ |
| 336 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 337 | { |
| 338 | ALOGV("in_get_sample_rate"); |
| 339 | return 8000; |
| 340 | } |
| 341 | |
| 342 | static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 343 | { |
| 344 | ALOGV("in_set_sample_rate: %d", rate); |
| 345 | return -ENOSYS; |
| 346 | } |
| 347 | |
| 348 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 349 | { |
| 350 | ALOGV("in_get_buffer_size: %d", 320); |
| 351 | return 320; |
| 352 | } |
| 353 | |
| 354 | static audio_channel_mask_t in_get_channels(const struct audio_stream *stream) |
| 355 | { |
| 356 | ALOGV("in_get_channels: %d", AUDIO_CHANNEL_IN_MONO); |
| 357 | return AUDIO_CHANNEL_IN_MONO; |
| 358 | } |
| 359 | |
| 360 | static audio_format_t in_get_format(const struct audio_stream *stream) |
| 361 | { |
| 362 | return AUDIO_FORMAT_PCM_16_BIT; |
| 363 | } |
| 364 | |
| 365 | static int in_set_format(struct audio_stream *stream, audio_format_t format) |
| 366 | { |
| 367 | return -ENOSYS; |
| 368 | } |
| 369 | |
| 370 | static int in_standby(struct audio_stream *stream) |
| 371 | { |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | static int in_dump(const struct audio_stream *stream, int fd) |
| 376 | { |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 381 | { |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | static char * in_get_parameters(const struct audio_stream *stream, |
| 386 | const char *keys) |
| 387 | { |
| 388 | return strdup(""); |
| 389 | } |
| 390 | |
| 391 | static int in_set_gain(struct audio_stream_in *stream, float gain) |
| 392 | { |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static ssize_t in_read(struct audio_stream_in *stream, void* buffer, |
| 397 | size_t bytes) |
| 398 | { |
| 399 | ALOGV("in_read: bytes %zu", bytes); |
| 400 | /* XXX: fake timing for audio input */ |
| 401 | usleep((int64_t)bytes * 1000000 / audio_stream_in_frame_size(stream) / |
| 402 | in_get_sample_rate(&stream->common)); |
| 403 | memset(buffer, 0, bytes); |
| 404 | return bytes; |
| 405 | } |
| 406 | |
| 407 | static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) |
| 408 | { |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 413 | { |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 418 | { |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static int adev_open_output_stream(struct audio_hw_device *dev, |
| 423 | audio_io_handle_t handle, |
| 424 | audio_devices_t devices, |
| 425 | audio_output_flags_t flags, |
| 426 | struct audio_config *config, |
| 427 | struct audio_stream_out **stream_out, |
| 428 | const char *address __unused) |
| 429 | { |
| 430 | ALOGV("adev_open_output_stream..."); |
| 431 | |
| 432 | struct alsa_audio_device *ladev = (struct alsa_audio_device *)dev; |
| 433 | struct alsa_stream_out *out; |
| 434 | struct pcm_params *params; |
| 435 | int ret = 0; |
| 436 | |
| 437 | params = pcm_params_get(CARD_OUT, PORT_CODEC, PCM_OUT); |
| 438 | if (!params) |
| 439 | return -ENOSYS; |
| 440 | |
| 441 | out = (struct alsa_stream_out *)calloc(1, sizeof(struct alsa_stream_out)); |
| 442 | if (!out) |
| 443 | return -ENOMEM; |
| 444 | |
| 445 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 446 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 447 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 448 | out->stream.common.get_channels = out_get_channels; |
| 449 | out->stream.common.get_format = out_get_format; |
| 450 | out->stream.common.set_format = out_set_format; |
| 451 | out->stream.common.standby = out_standby; |
| 452 | out->stream.common.dump = out_dump; |
| 453 | out->stream.common.set_parameters = out_set_parameters; |
| 454 | out->stream.common.get_parameters = out_get_parameters; |
| 455 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 456 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
| 457 | out->stream.get_latency = out_get_latency; |
| 458 | out->stream.set_volume = out_set_volume; |
| 459 | out->stream.write = out_write; |
| 460 | out->stream.get_render_position = out_get_render_position; |
| 461 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
| 462 | out->stream.get_presentation_position = out_get_presentation_position; |
| 463 | |
| 464 | out->config.channels = CHANNEL_STEREO; |
| 465 | out->config.rate = CODEC_SAMPLING_RATE; |
| 466 | out->config.format = PCM_FORMAT_S16_LE; |
| 467 | out->config.period_size = PERIOD_SIZE; |
| 468 | out->config.period_count = PLAYBACK_PERIOD_COUNT; |
| 469 | |
| 470 | if (out->config.rate != config->sample_rate || |
| 471 | audio_channel_count_from_out_mask(config->channel_mask) != CHANNEL_STEREO || |
| 472 | out->config.format != pcm_format_from_audio_format(config->format) ) { |
| 473 | config->sample_rate = out->config.rate; |
| 474 | config->format = audio_format_from_pcm_format(out->config.format); |
| 475 | config->channel_mask = audio_channel_out_mask_from_count(CHANNEL_STEREO); |
| 476 | ret = -EINVAL; |
| 477 | } |
| 478 | |
| 479 | ALOGI("adev_open_output_stream selects channels=%d rate=%d format=%d", |
| 480 | out->config.channels, out->config.rate, out->config.format); |
| 481 | |
| 482 | out->dev = ladev; |
| 483 | out->standby = 1; |
| 484 | out->unavailable = false; |
| 485 | |
| 486 | config->format = out_get_format(&out->stream.common); |
| 487 | config->channel_mask = out_get_channels(&out->stream.common); |
| 488 | config->sample_rate = out_get_sample_rate(&out->stream.common); |
| 489 | |
| 490 | *stream_out = &out->stream; |
| 491 | |
| 492 | /* TODO The retry mechanism isn't implemented in AudioPolicyManager/AudioFlinger. */ |
| 493 | ret = 0; |
| 494 | |
| 495 | return ret; |
| 496 | } |
| 497 | |
| 498 | static void adev_close_output_stream(struct audio_hw_device *dev, |
| 499 | struct audio_stream_out *stream) |
| 500 | { |
| 501 | ALOGV("adev_close_output_stream..."); |
| 502 | free(stream); |
| 503 | } |
| 504 | |
| 505 | static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) |
| 506 | { |
| 507 | ALOGV("adev_set_parameters"); |
| 508 | return -ENOSYS; |
| 509 | } |
| 510 | |
| 511 | static char * adev_get_parameters(const struct audio_hw_device *dev, |
| 512 | const char *keys) |
| 513 | { |
| 514 | ALOGV("adev_get_parameters"); |
| 515 | return strdup(""); |
| 516 | } |
| 517 | |
| 518 | static int adev_init_check(const struct audio_hw_device *dev) |
| 519 | { |
| 520 | ALOGV("adev_init_check"); |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 525 | { |
| 526 | ALOGV("adev_set_voice_volume: %f", volume); |
| 527 | return -ENOSYS; |
| 528 | } |
| 529 | |
| 530 | static int adev_set_master_volume(struct audio_hw_device *dev, float volume) |
| 531 | { |
| 532 | ALOGV("adev_set_master_volume: %f", volume); |
| 533 | return -ENOSYS; |
| 534 | } |
| 535 | |
| 536 | static int adev_get_master_volume(struct audio_hw_device *dev, float *volume) |
| 537 | { |
| 538 | ALOGV("adev_get_master_volume: %f", *volume); |
| 539 | return -ENOSYS; |
| 540 | } |
| 541 | |
| 542 | static int adev_set_master_mute(struct audio_hw_device *dev, bool muted) |
| 543 | { |
| 544 | ALOGV("adev_set_master_mute: %d", muted); |
| 545 | return -ENOSYS; |
| 546 | } |
| 547 | |
| 548 | static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted) |
| 549 | { |
| 550 | ALOGV("adev_get_master_mute: %d", *muted); |
| 551 | return -ENOSYS; |
| 552 | } |
| 553 | |
| 554 | static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 555 | { |
| 556 | ALOGV("adev_set_mode: %d", mode); |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 561 | { |
| 562 | ALOGV("adev_set_mic_mute: %d",state); |
| 563 | return -ENOSYS; |
| 564 | } |
| 565 | |
| 566 | static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 567 | { |
| 568 | ALOGV("adev_get_mic_mute"); |
| 569 | return -ENOSYS; |
| 570 | } |
| 571 | |
| 572 | static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, |
| 573 | const struct audio_config *config) |
| 574 | { |
| 575 | ALOGV("adev_get_input_buffer_size: %d", 320); |
| 576 | return 320; |
| 577 | } |
| 578 | |
Dmitry Shmidt | 6b34f04 | 2017-11-29 13:23:01 -0800 | [diff] [blame] | 579 | static int adev_open_input_stream(struct audio_hw_device __unused *dev, |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 580 | audio_io_handle_t handle, |
| 581 | audio_devices_t devices, |
| 582 | struct audio_config *config, |
| 583 | struct audio_stream_in **stream_in, |
| 584 | audio_input_flags_t flags __unused, |
| 585 | const char *address __unused, |
| 586 | audio_source_t source __unused) |
| 587 | { |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 588 | struct stub_stream_in *in; |
Dmitry Shmidt | 6b34f04 | 2017-11-29 13:23:01 -0800 | [diff] [blame] | 589 | |
| 590 | ALOGV("adev_open_input_stream..."); |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 591 | |
| 592 | in = (struct stub_stream_in *)calloc(1, sizeof(struct stub_stream_in)); |
| 593 | if (!in) |
| 594 | return -ENOMEM; |
| 595 | |
| 596 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 597 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 598 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 599 | in->stream.common.get_channels = in_get_channels; |
| 600 | in->stream.common.get_format = in_get_format; |
| 601 | in->stream.common.set_format = in_set_format; |
| 602 | in->stream.common.standby = in_standby; |
| 603 | in->stream.common.dump = in_dump; |
| 604 | in->stream.common.set_parameters = in_set_parameters; |
| 605 | in->stream.common.get_parameters = in_get_parameters; |
| 606 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 607 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
| 608 | in->stream.set_gain = in_set_gain; |
| 609 | in->stream.read = in_read; |
| 610 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
| 611 | |
| 612 | *stream_in = &in->stream; |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | static void adev_close_input_stream(struct audio_hw_device *dev, |
| 617 | struct audio_stream_in *in) |
| 618 | { |
| 619 | ALOGV("adev_close_input_stream..."); |
| 620 | return; |
| 621 | } |
| 622 | |
| 623 | static int adev_dump(const audio_hw_device_t *device, int fd) |
| 624 | { |
| 625 | ALOGV("adev_dump"); |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | static int adev_close(hw_device_t *device) |
| 630 | { |
| 631 | ALOGV("adev_close"); |
| 632 | free(device); |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int adev_open(const hw_module_t* module, const char* name, |
| 637 | hw_device_t** device) |
| 638 | { |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 639 | struct alsa_audio_device *adev; |
Dmitry Shmidt | 6b34f04 | 2017-11-29 13:23:01 -0800 | [diff] [blame] | 640 | |
| 641 | ALOGV("adev_open: %s", name); |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 642 | |
| 643 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) |
| 644 | return -EINVAL; |
| 645 | |
| 646 | adev = calloc(1, sizeof(struct alsa_audio_device)); |
| 647 | if (!adev) |
| 648 | return -ENOMEM; |
| 649 | |
| 650 | adev->hw_device.common.tag = HARDWARE_DEVICE_TAG; |
| 651 | adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
| 652 | adev->hw_device.common.module = (struct hw_module_t *) module; |
| 653 | adev->hw_device.common.close = adev_close; |
| 654 | adev->hw_device.init_check = adev_init_check; |
| 655 | adev->hw_device.set_voice_volume = adev_set_voice_volume; |
| 656 | adev->hw_device.set_master_volume = adev_set_master_volume; |
| 657 | adev->hw_device.get_master_volume = adev_get_master_volume; |
| 658 | adev->hw_device.set_master_mute = adev_set_master_mute; |
| 659 | adev->hw_device.get_master_mute = adev_get_master_mute; |
| 660 | adev->hw_device.set_mode = adev_set_mode; |
| 661 | adev->hw_device.set_mic_mute = adev_set_mic_mute; |
| 662 | adev->hw_device.get_mic_mute = adev_get_mic_mute; |
| 663 | adev->hw_device.set_parameters = adev_set_parameters; |
| 664 | adev->hw_device.get_parameters = adev_get_parameters; |
| 665 | adev->hw_device.get_input_buffer_size = adev_get_input_buffer_size; |
| 666 | adev->hw_device.open_output_stream = adev_open_output_stream; |
| 667 | adev->hw_device.close_output_stream = adev_close_output_stream; |
| 668 | adev->hw_device.open_input_stream = adev_open_input_stream; |
| 669 | adev->hw_device.close_input_stream = adev_close_input_stream; |
| 670 | adev->hw_device.dump = adev_dump; |
| 671 | |
| 672 | adev->devices = AUDIO_DEVICE_NONE; |
| 673 | |
| 674 | *device = &adev->hw_device.common; |
| 675 | |
Vishal Bhoj | 2cf4939 | 2016-01-13 14:01:08 +0000 | [diff] [blame] | 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | static struct hw_module_methods_t hal_module_methods = { |
| 680 | .open = adev_open, |
| 681 | }; |
| 682 | |
| 683 | struct audio_module HAL_MODULE_INFO_SYM = { |
| 684 | .common = { |
| 685 | .tag = HARDWARE_MODULE_TAG, |
| 686 | .module_api_version = AUDIO_MODULE_API_VERSION_0_1, |
| 687 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
| 688 | .id = AUDIO_HARDWARE_MODULE_ID, |
| 689 | .name = "Hikey audio HW HAL", |
| 690 | .author = "The Android Open Source Project", |
| 691 | .methods = &hal_module_methods, |
| 692 | }, |
| 693 | }; |