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