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