Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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_default" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <errno.h> |
Elliott Hughes | 07c0855 | 2015-01-29 21:19:10 -0800 | [diff] [blame] | 21 | #include <malloc.h> |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 22 | #include <pthread.h> |
| 23 | #include <stdint.h> |
| 24 | #include <sys/time.h> |
| 25 | |
Steven Moreland | 02b5d16 | 2017-04-11 09:36:38 -0700 | [diff] [blame^] | 26 | #include <log/log.h> |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 27 | |
| 28 | #include <hardware/hardware.h> |
Dima Zavin | aa21172 | 2011-05-11 14:15:53 -0700 | [diff] [blame] | 29 | #include <system/audio.h> |
Dima Zavin | 3bc1586 | 2011-06-13 17:59:54 -0700 | [diff] [blame] | 30 | #include <hardware/audio.h> |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 31 | |
| 32 | struct stub_audio_device { |
| 33 | struct audio_hw_device device; |
| 34 | }; |
| 35 | |
| 36 | struct stub_stream_out { |
| 37 | struct audio_stream_out stream; |
Andy Hung | 0caeee8 | 2016-06-24 19:41:06 -0700 | [diff] [blame] | 38 | int64_t last_write_time_us; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | struct stub_stream_in { |
| 42 | struct audio_stream_in stream; |
Andy Hung | 0caeee8 | 2016-06-24 19:41:06 -0700 | [diff] [blame] | 43 | int64_t last_read_time_us; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 47 | { |
| 48 | return 44100; |
| 49 | } |
| 50 | |
| 51 | static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 52 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 53 | ALOGV("out_set_sample_rate: %d", 0); |
| 54 | return -ENOSYS; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 58 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 59 | ALOGV("out_get_buffer_size: %d", 4096); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 60 | return 4096; |
| 61 | } |
| 62 | |
Glenn Kasten | a635449 | 2012-06-19 12:16:04 -0700 | [diff] [blame] | 63 | static audio_channel_mask_t out_get_channels(const struct audio_stream *stream) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 64 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 65 | ALOGV("out_get_channels"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 66 | return AUDIO_CHANNEL_OUT_STEREO; |
| 67 | } |
| 68 | |
Glenn Kasten | fe79eb3 | 2012-01-12 14:55:57 -0800 | [diff] [blame] | 69 | static audio_format_t out_get_format(const struct audio_stream *stream) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 70 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 71 | ALOGV("out_get_format"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 72 | return AUDIO_FORMAT_PCM_16_BIT; |
| 73 | } |
| 74 | |
Glenn Kasten | fe79eb3 | 2012-01-12 14:55:57 -0800 | [diff] [blame] | 75 | static int out_set_format(struct audio_stream *stream, audio_format_t format) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 76 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 77 | ALOGV("out_set_format: %d",format); |
| 78 | return -ENOSYS; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static int out_standby(struct audio_stream *stream) |
| 82 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 83 | ALOGV("out_standby"); |
Andy Hung | 0caeee8 | 2016-06-24 19:41:06 -0700 | [diff] [blame] | 84 | // out->last_write_time_us = 0; unnecessary as a stale write time has same effect |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static int out_dump(const struct audio_stream *stream, int fd) |
| 89 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 90 | ALOGV("out_dump"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 95 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 96 | ALOGV("out_set_parameters"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static char * out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 101 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 102 | ALOGV("out_get_parameters"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 103 | return strdup(""); |
| 104 | } |
| 105 | |
| 106 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 107 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 108 | ALOGV("out_get_latency"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static int out_set_volume(struct audio_stream_out *stream, float left, |
| 113 | float right) |
| 114 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 115 | ALOGV("out_set_volume: Left:%f Right:%f", left, right); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, |
| 120 | size_t bytes) |
| 121 | { |
Greg Kaiser | 6c59aad | 2016-06-30 16:08:53 -0700 | [diff] [blame] | 122 | ALOGV("out_write: bytes: %zu", bytes); |
Andy Hung | 0caeee8 | 2016-06-24 19:41:06 -0700 | [diff] [blame] | 123 | |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 124 | /* XXX: fake timing for audio output */ |
Andy Hung | 0caeee8 | 2016-06-24 19:41:06 -0700 | [diff] [blame] | 125 | struct stub_stream_out *out = (struct stub_stream_out *)stream; |
| 126 | struct timespec t = { .tv_sec = 0, .tv_nsec = 0 }; |
| 127 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 128 | const int64_t now = (t.tv_sec * 1000000000LL + t.tv_nsec) / 1000; |
| 129 | const int64_t elapsed_time_since_last_write = now - out->last_write_time_us; |
| 130 | int64_t sleep_time = bytes * 1000000LL / audio_stream_out_frame_size(stream) / |
| 131 | out_get_sample_rate(&stream->common) - elapsed_time_since_last_write; |
| 132 | if (sleep_time > 0) { |
| 133 | usleep(sleep_time); |
| 134 | } else { |
| 135 | // we don't sleep when we exit standby (this is typical for a real alsa buffer). |
| 136 | sleep_time = 0; |
| 137 | } |
| 138 | out->last_write_time_us = now + sleep_time; |
| 139 | // last_write_time_us is an approximation of when the (simulated) alsa |
| 140 | // buffer is believed completely full. The usleep above waits for more space |
| 141 | // in the buffer, but by the end of the sleep the buffer is considered |
| 142 | // topped-off. |
| 143 | // |
| 144 | // On the subsequent out_write(), we measure the elapsed time spent in |
| 145 | // the mixer. This is subtracted from the sleep estimate based on frames, |
| 146 | // thereby accounting for drain in the alsa buffer during mixing. |
| 147 | // This is a crude approximation; we don't handle underruns precisely. |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 148 | return bytes; |
| 149 | } |
| 150 | |
| 151 | static int out_get_render_position(const struct audio_stream_out *stream, |
| 152 | uint32_t *dsp_frames) |
| 153 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 154 | *dsp_frames = 0; |
Glenn Kasten | e03bfa4 | 2015-03-23 10:52:31 -0700 | [diff] [blame] | 155 | ALOGV("out_get_render_position: dsp_frames: %p", dsp_frames); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 156 | return -EINVAL; |
| 157 | } |
| 158 | |
Eric Laurent | f3008aa | 2011-06-17 16:53:12 -0700 | [diff] [blame] | 159 | static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 160 | { |
Glenn Kasten | e03bfa4 | 2015-03-23 10:52:31 -0700 | [diff] [blame] | 161 | ALOGV("out_add_audio_effect: %p", effect); |
Eric Laurent | f3008aa | 2011-06-17 16:53:12 -0700 | [diff] [blame] | 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 166 | { |
Glenn Kasten | e03bfa4 | 2015-03-23 10:52:31 -0700 | [diff] [blame] | 167 | ALOGV("out_remove_audio_effect: %p", effect); |
Eric Laurent | f3008aa | 2011-06-17 16:53:12 -0700 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 171 | static int out_get_next_write_timestamp(const struct audio_stream_out *stream, |
| 172 | int64_t *timestamp) |
| 173 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 174 | *timestamp = 0; |
| 175 | ALOGV("out_get_next_write_timestamp: %ld", (long int)(*timestamp)); |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 176 | return -EINVAL; |
| 177 | } |
| 178 | |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 179 | /** audio_stream_in implementation **/ |
| 180 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 181 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 182 | ALOGV("in_get_sample_rate"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 183 | return 8000; |
| 184 | } |
| 185 | |
| 186 | static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 187 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 188 | ALOGV("in_set_sample_rate: %d", rate); |
| 189 | return -ENOSYS; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 193 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 194 | ALOGV("in_get_buffer_size: %d", 320); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 195 | return 320; |
| 196 | } |
| 197 | |
Glenn Kasten | a635449 | 2012-06-19 12:16:04 -0700 | [diff] [blame] | 198 | static audio_channel_mask_t in_get_channels(const struct audio_stream *stream) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 199 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 200 | ALOGV("in_get_channels: %d", AUDIO_CHANNEL_IN_MONO); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 201 | return AUDIO_CHANNEL_IN_MONO; |
| 202 | } |
| 203 | |
Glenn Kasten | fe79eb3 | 2012-01-12 14:55:57 -0800 | [diff] [blame] | 204 | static audio_format_t in_get_format(const struct audio_stream *stream) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 205 | { |
| 206 | return AUDIO_FORMAT_PCM_16_BIT; |
| 207 | } |
| 208 | |
Glenn Kasten | fe79eb3 | 2012-01-12 14:55:57 -0800 | [diff] [blame] | 209 | static int in_set_format(struct audio_stream *stream, audio_format_t format) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 210 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 211 | return -ENOSYS; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static int in_standby(struct audio_stream *stream) |
| 215 | { |
Andy Hung | 0caeee8 | 2016-06-24 19:41:06 -0700 | [diff] [blame] | 216 | struct stub_stream_in *in = (struct stub_stream_in *)stream; |
| 217 | in->last_read_time_us = 0; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static int in_dump(const struct audio_stream *stream, int fd) |
| 222 | { |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 227 | { |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static char * in_get_parameters(const struct audio_stream *stream, |
| 232 | const char *keys) |
| 233 | { |
| 234 | return strdup(""); |
| 235 | } |
| 236 | |
| 237 | static int in_set_gain(struct audio_stream_in *stream, float gain) |
| 238 | { |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static ssize_t in_read(struct audio_stream_in *stream, void* buffer, |
| 243 | size_t bytes) |
| 244 | { |
Greg Kaiser | 6c59aad | 2016-06-30 16:08:53 -0700 | [diff] [blame] | 245 | ALOGV("in_read: bytes %zu", bytes); |
Andy Hung | 0caeee8 | 2016-06-24 19:41:06 -0700 | [diff] [blame] | 246 | |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 247 | /* XXX: fake timing for audio input */ |
Andy Hung | 0caeee8 | 2016-06-24 19:41:06 -0700 | [diff] [blame] | 248 | struct stub_stream_in *in = (struct stub_stream_in *)stream; |
| 249 | struct timespec t = { .tv_sec = 0, .tv_nsec = 0 }; |
| 250 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 251 | const int64_t now = (t.tv_sec * 1000000000LL + t.tv_nsec) / 1000; |
| 252 | |
| 253 | // we do a full sleep when exiting standby. |
| 254 | const bool standby = in->last_read_time_us == 0; |
| 255 | const int64_t elapsed_time_since_last_read = standby ? |
| 256 | 0 : now - in->last_read_time_us; |
| 257 | int64_t sleep_time = bytes * 1000000LL / audio_stream_in_frame_size(stream) / |
| 258 | in_get_sample_rate(&stream->common) - elapsed_time_since_last_read; |
| 259 | if (sleep_time > 0) { |
| 260 | usleep(sleep_time); |
| 261 | } else { |
| 262 | sleep_time = 0; |
| 263 | } |
| 264 | in->last_read_time_us = now + sleep_time; |
| 265 | // last_read_time_us is an approximation of when the (simulated) alsa |
| 266 | // buffer is drained by the read, and is empty. |
| 267 | // |
| 268 | // On the subsequent in_read(), we measure the elapsed time spent in |
| 269 | // the recording thread. This is subtracted from the sleep estimate based on frames, |
| 270 | // thereby accounting for fill in the alsa buffer during the interim. |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 271 | memset(buffer, 0, bytes); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 272 | return bytes; |
| 273 | } |
| 274 | |
| 275 | static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) |
| 276 | { |
| 277 | return 0; |
| 278 | } |
| 279 | |
Eric Laurent | f3008aa | 2011-06-17 16:53:12 -0700 | [diff] [blame] | 280 | static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 281 | { |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 286 | { |
| 287 | return 0; |
| 288 | } |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 289 | |
| 290 | static int adev_open_output_stream(struct audio_hw_device *dev, |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 291 | audio_io_handle_t handle, |
| 292 | audio_devices_t devices, |
| 293 | audio_output_flags_t flags, |
| 294 | struct audio_config *config, |
Eric Laurent | f5e2469 | 2014-07-27 16:14:57 -0700 | [diff] [blame] | 295 | struct audio_stream_out **stream_out, |
| 296 | const char *address __unused) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 297 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 298 | ALOGV("adev_open_output_stream..."); |
| 299 | |
Glenn Kasten | 2494cae | 2016-09-19 18:16:16 -0700 | [diff] [blame] | 300 | *stream_out = NULL; |
| 301 | struct stub_stream_out *out = |
| 302 | (struct stub_stream_out *)calloc(1, sizeof(struct stub_stream_out)); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 303 | if (!out) |
| 304 | return -ENOMEM; |
| 305 | |
| 306 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 307 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 308 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 309 | out->stream.common.get_channels = out_get_channels; |
| 310 | out->stream.common.get_format = out_get_format; |
| 311 | out->stream.common.set_format = out_set_format; |
| 312 | out->stream.common.standby = out_standby; |
| 313 | out->stream.common.dump = out_dump; |
| 314 | out->stream.common.set_parameters = out_set_parameters; |
| 315 | out->stream.common.get_parameters = out_get_parameters; |
Eric Laurent | f3008aa | 2011-06-17 16:53:12 -0700 | [diff] [blame] | 316 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 317 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 318 | out->stream.get_latency = out_get_latency; |
| 319 | out->stream.set_volume = out_set_volume; |
| 320 | out->stream.write = out_write; |
| 321 | out->stream.get_render_position = out_get_render_position; |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 322 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 323 | |
| 324 | *stream_out = &out->stream; |
| 325 | return 0; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static void adev_close_output_stream(struct audio_hw_device *dev, |
| 329 | struct audio_stream_out *stream) |
| 330 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 331 | ALOGV("adev_close_output_stream..."); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 332 | free(stream); |
| 333 | } |
| 334 | |
| 335 | static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) |
| 336 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 337 | ALOGV("adev_set_parameters"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 338 | return -ENOSYS; |
| 339 | } |
| 340 | |
| 341 | static char * adev_get_parameters(const struct audio_hw_device *dev, |
| 342 | const char *keys) |
| 343 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 344 | ALOGV("adev_get_parameters"); |
| 345 | return strdup(""); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static int adev_init_check(const struct audio_hw_device *dev) |
| 349 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 350 | ALOGV("adev_init_check"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 355 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 356 | ALOGV("adev_set_voice_volume: %f", volume); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 357 | return -ENOSYS; |
| 358 | } |
| 359 | |
| 360 | static int adev_set_master_volume(struct audio_hw_device *dev, float volume) |
| 361 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 362 | ALOGV("adev_set_master_volume: %f", volume); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 363 | return -ENOSYS; |
| 364 | } |
| 365 | |
John Grossman | 47bf3d7 | 2012-07-17 11:54:04 -0700 | [diff] [blame] | 366 | static int adev_get_master_volume(struct audio_hw_device *dev, float *volume) |
| 367 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 368 | ALOGV("adev_get_master_volume: %f", *volume); |
John Grossman | 47bf3d7 | 2012-07-17 11:54:04 -0700 | [diff] [blame] | 369 | return -ENOSYS; |
| 370 | } |
| 371 | |
| 372 | static int adev_set_master_mute(struct audio_hw_device *dev, bool muted) |
| 373 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 374 | ALOGV("adev_set_master_mute: %d", muted); |
John Grossman | 47bf3d7 | 2012-07-17 11:54:04 -0700 | [diff] [blame] | 375 | return -ENOSYS; |
| 376 | } |
| 377 | |
| 378 | static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted) |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 379 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 380 | ALOGV("adev_get_master_mute: %d", *muted); |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 381 | return -ENOSYS; |
| 382 | } |
| 383 | |
Glenn Kasten | 6df641e | 2012-01-09 10:41:30 -0800 | [diff] [blame] | 384 | static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 385 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 386 | ALOGV("adev_set_mode: %d", mode); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 391 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 392 | ALOGV("adev_set_mic_mute: %d",state); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 393 | return -ENOSYS; |
| 394 | } |
| 395 | |
| 396 | static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 397 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 398 | ALOGV("adev_get_mic_mute"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 399 | return -ENOSYS; |
| 400 | } |
| 401 | |
| 402 | static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 403 | const struct audio_config *config) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 404 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 405 | ALOGV("adev_get_input_buffer_size: %d", 320); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 406 | return 320; |
| 407 | } |
| 408 | |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 409 | static int adev_open_input_stream(struct audio_hw_device *dev, |
| 410 | audio_io_handle_t handle, |
| 411 | audio_devices_t devices, |
| 412 | struct audio_config *config, |
Glenn Kasten | 7d973ad | 2014-07-15 11:10:38 -0700 | [diff] [blame] | 413 | struct audio_stream_in **stream_in, |
Eric Laurent | f5e2469 | 2014-07-27 16:14:57 -0700 | [diff] [blame] | 414 | audio_input_flags_t flags __unused, |
| 415 | const char *address __unused, |
| 416 | audio_source_t source __unused) |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 417 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 418 | ALOGV("adev_open_input_stream..."); |
| 419 | |
Glenn Kasten | 2494cae | 2016-09-19 18:16:16 -0700 | [diff] [blame] | 420 | *stream_in = NULL; |
| 421 | struct stub_stream_in *in = (struct stub_stream_in *)calloc(1, sizeof(struct stub_stream_in)); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 422 | if (!in) |
| 423 | return -ENOMEM; |
| 424 | |
| 425 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 426 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 427 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 428 | in->stream.common.get_channels = in_get_channels; |
| 429 | in->stream.common.get_format = in_get_format; |
| 430 | in->stream.common.set_format = in_set_format; |
| 431 | in->stream.common.standby = in_standby; |
| 432 | in->stream.common.dump = in_dump; |
| 433 | in->stream.common.set_parameters = in_set_parameters; |
| 434 | in->stream.common.get_parameters = in_get_parameters; |
Eric Laurent | f3008aa | 2011-06-17 16:53:12 -0700 | [diff] [blame] | 435 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 436 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 437 | in->stream.set_gain = in_set_gain; |
| 438 | in->stream.read = in_read; |
| 439 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
| 440 | |
| 441 | *stream_in = &in->stream; |
| 442 | return 0; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static void adev_close_input_stream(struct audio_hw_device *dev, |
| 446 | struct audio_stream_in *in) |
| 447 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 448 | ALOGV("adev_close_input_stream..."); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 449 | return; |
| 450 | } |
| 451 | |
| 452 | static int adev_dump(const audio_hw_device_t *device, int fd) |
| 453 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 454 | ALOGV("adev_dump"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int adev_close(hw_device_t *device) |
| 459 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 460 | ALOGV("adev_close"); |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 461 | free(device); |
| 462 | return 0; |
| 463 | } |
| 464 | |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 465 | static int adev_open(const hw_module_t* module, const char* name, |
| 466 | hw_device_t** device) |
| 467 | { |
Ricardo Garcia | 37cd772 | 2015-02-23 15:42:26 -0800 | [diff] [blame] | 468 | ALOGV("adev_open: %s", name); |
| 469 | |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 470 | struct stub_audio_device *adev; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 471 | |
| 472 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) |
| 473 | return -EINVAL; |
| 474 | |
| 475 | adev = calloc(1, sizeof(struct stub_audio_device)); |
| 476 | if (!adev) |
| 477 | return -ENOMEM; |
| 478 | |
| 479 | adev->device.common.tag = HARDWARE_DEVICE_TAG; |
Eric Laurent | 85e08e2 | 2012-08-28 14:30:35 -0700 | [diff] [blame] | 480 | adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 481 | adev->device.common.module = (struct hw_module_t *) module; |
| 482 | adev->device.common.close = adev_close; |
| 483 | |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 484 | adev->device.init_check = adev_init_check; |
| 485 | adev->device.set_voice_volume = adev_set_voice_volume; |
| 486 | adev->device.set_master_volume = adev_set_master_volume; |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 487 | adev->device.get_master_volume = adev_get_master_volume; |
John Grossman | 47bf3d7 | 2012-07-17 11:54:04 -0700 | [diff] [blame] | 488 | adev->device.set_master_mute = adev_set_master_mute; |
| 489 | adev->device.get_master_mute = adev_get_master_mute; |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 490 | adev->device.set_mode = adev_set_mode; |
| 491 | adev->device.set_mic_mute = adev_set_mic_mute; |
| 492 | adev->device.get_mic_mute = adev_get_mic_mute; |
| 493 | adev->device.set_parameters = adev_set_parameters; |
| 494 | adev->device.get_parameters = adev_get_parameters; |
| 495 | adev->device.get_input_buffer_size = adev_get_input_buffer_size; |
| 496 | adev->device.open_output_stream = adev_open_output_stream; |
| 497 | adev->device.close_output_stream = adev_close_output_stream; |
| 498 | adev->device.open_input_stream = adev_open_input_stream; |
| 499 | adev->device.close_input_stream = adev_close_input_stream; |
| 500 | adev->device.dump = adev_dump; |
| 501 | |
| 502 | *device = &adev->device.common; |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | static struct hw_module_methods_t hal_module_methods = { |
| 508 | .open = adev_open, |
| 509 | }; |
| 510 | |
| 511 | struct audio_module HAL_MODULE_INFO_SYM = { |
| 512 | .common = { |
| 513 | .tag = HARDWARE_MODULE_TAG, |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 514 | .module_api_version = AUDIO_MODULE_API_VERSION_0_1, |
| 515 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
Dima Zavin | 8cc353a | 2011-04-20 16:38:05 -0700 | [diff] [blame] | 516 | .id = AUDIO_HARDWARE_MODULE_ID, |
| 517 | .name = "Default audio HW HAL", |
| 518 | .author = "The Android Open Source Project", |
| 519 | .methods = &hal_module_methods, |
| 520 | }, |
| 521 | }; |