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