blob: 35901e41262fdc6b007271e9d938a0ee5284177d [file] [log] [blame]
Dima Zavin8cc353a2011-04-20 16:38:05 -07001/*
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 Hughes07c08552015-01-29 21:19:10 -080021#include <malloc.h>
Dima Zavin8cc353a2011-04-20 16:38:05 -070022#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 Zavinaa211722011-05-11 14:15:53 -070029#include <system/audio.h>
Dima Zavin3bc15862011-06-13 17:59:54 -070030#include <hardware/audio.h>
Dima Zavin8cc353a2011-04-20 16:38:05 -070031
32struct stub_audio_device {
33 struct audio_hw_device device;
34};
35
36struct stub_stream_out {
37 struct audio_stream_out stream;
Andy Hung0caeee82016-06-24 19:41:06 -070038 int64_t last_write_time_us;
Dima Zavin8cc353a2011-04-20 16:38:05 -070039};
40
41struct stub_stream_in {
42 struct audio_stream_in stream;
Andy Hung0caeee82016-06-24 19:41:06 -070043 int64_t last_read_time_us;
Dima Zavin8cc353a2011-04-20 16:38:05 -070044};
45
46static uint32_t out_get_sample_rate(const struct audio_stream *stream)
47{
48 return 44100;
49}
50
51static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
52{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080053 ALOGV("out_set_sample_rate: %d", 0);
54 return -ENOSYS;
Dima Zavin8cc353a2011-04-20 16:38:05 -070055}
56
57static size_t out_get_buffer_size(const struct audio_stream *stream)
58{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080059 ALOGV("out_get_buffer_size: %d", 4096);
Dima Zavin8cc353a2011-04-20 16:38:05 -070060 return 4096;
61}
62
Glenn Kastena6354492012-06-19 12:16:04 -070063static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
Dima Zavin8cc353a2011-04-20 16:38:05 -070064{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080065 ALOGV("out_get_channels");
Dima Zavin8cc353a2011-04-20 16:38:05 -070066 return AUDIO_CHANNEL_OUT_STEREO;
67}
68
Glenn Kastenfe79eb32012-01-12 14:55:57 -080069static audio_format_t out_get_format(const struct audio_stream *stream)
Dima Zavin8cc353a2011-04-20 16:38:05 -070070{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080071 ALOGV("out_get_format");
Dima Zavin8cc353a2011-04-20 16:38:05 -070072 return AUDIO_FORMAT_PCM_16_BIT;
73}
74
Glenn Kastenfe79eb32012-01-12 14:55:57 -080075static int out_set_format(struct audio_stream *stream, audio_format_t format)
Dima Zavin8cc353a2011-04-20 16:38:05 -070076{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080077 ALOGV("out_set_format: %d",format);
78 return -ENOSYS;
Dima Zavin8cc353a2011-04-20 16:38:05 -070079}
80
81static int out_standby(struct audio_stream *stream)
82{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080083 ALOGV("out_standby");
Andy Hung0caeee82016-06-24 19:41:06 -070084 // out->last_write_time_us = 0; unnecessary as a stale write time has same effect
Dima Zavin8cc353a2011-04-20 16:38:05 -070085 return 0;
86}
87
88static int out_dump(const struct audio_stream *stream, int fd)
89{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080090 ALOGV("out_dump");
Dima Zavin8cc353a2011-04-20 16:38:05 -070091 return 0;
92}
93
94static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
95{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080096 ALOGV("out_set_parameters");
Dima Zavin8cc353a2011-04-20 16:38:05 -070097 return 0;
98}
99
100static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
101{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800102 ALOGV("out_get_parameters");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700103 return strdup("");
104}
105
106static uint32_t out_get_latency(const struct audio_stream_out *stream)
107{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800108 ALOGV("out_get_latency");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700109 return 0;
110}
111
112static int out_set_volume(struct audio_stream_out *stream, float left,
113 float right)
114{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800115 ALOGV("out_set_volume: Left:%f Right:%f", left, right);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700116 return 0;
117}
118
119static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
120 size_t bytes)
121{
Dmitry Shmidta898f932016-10-26 13:54:25 -0700122 ALOGV("out_write: bytes: %zu", bytes);
Andy Hung0caeee82016-06-24 19:41:06 -0700123
Dima Zavin8cc353a2011-04-20 16:38:05 -0700124 /* XXX: fake timing for audio output */
Andy Hung0caeee82016-06-24 19:41:06 -0700125 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 Zavin8cc353a2011-04-20 16:38:05 -0700148 return bytes;
149}
150
151static int out_get_render_position(const struct audio_stream_out *stream,
152 uint32_t *dsp_frames)
153{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800154 *dsp_frames = 0;
Glenn Kastene03bfa42015-03-23 10:52:31 -0700155 ALOGV("out_get_render_position: dsp_frames: %p", dsp_frames);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700156 return -EINVAL;
157}
158
Eric Laurentf3008aa2011-06-17 16:53:12 -0700159static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
160{
Glenn Kastene03bfa42015-03-23 10:52:31 -0700161 ALOGV("out_add_audio_effect: %p", effect);
Eric Laurentf3008aa2011-06-17 16:53:12 -0700162 return 0;
163}
164
165static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
166{
Glenn Kastene03bfa42015-03-23 10:52:31 -0700167 ALOGV("out_remove_audio_effect: %p", effect);
Eric Laurentf3008aa2011-06-17 16:53:12 -0700168 return 0;
169}
170
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700171static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
172 int64_t *timestamp)
173{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800174 *timestamp = 0;
175 ALOGV("out_get_next_write_timestamp: %ld", (long int)(*timestamp));
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700176 return -EINVAL;
177}
178
Dima Zavin8cc353a2011-04-20 16:38:05 -0700179/** audio_stream_in implementation **/
180static uint32_t in_get_sample_rate(const struct audio_stream *stream)
181{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800182 ALOGV("in_get_sample_rate");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700183 return 8000;
184}
185
186static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
187{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800188 ALOGV("in_set_sample_rate: %d", rate);
189 return -ENOSYS;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700190}
191
192static size_t in_get_buffer_size(const struct audio_stream *stream)
193{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800194 ALOGV("in_get_buffer_size: %d", 320);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700195 return 320;
196}
197
Glenn Kastena6354492012-06-19 12:16:04 -0700198static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700199{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800200 ALOGV("in_get_channels: %d", AUDIO_CHANNEL_IN_MONO);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700201 return AUDIO_CHANNEL_IN_MONO;
202}
203
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800204static audio_format_t in_get_format(const struct audio_stream *stream)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700205{
206 return AUDIO_FORMAT_PCM_16_BIT;
207}
208
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800209static int in_set_format(struct audio_stream *stream, audio_format_t format)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700210{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800211 return -ENOSYS;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700212}
213
214static int in_standby(struct audio_stream *stream)
215{
Andy Hung0caeee82016-06-24 19:41:06 -0700216 struct stub_stream_in *in = (struct stub_stream_in *)stream;
217 in->last_read_time_us = 0;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700218 return 0;
219}
220
221static int in_dump(const struct audio_stream *stream, int fd)
222{
223 return 0;
224}
225
226static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
227{
228 return 0;
229}
230
231static char * in_get_parameters(const struct audio_stream *stream,
232 const char *keys)
233{
234 return strdup("");
235}
236
237static int in_set_gain(struct audio_stream_in *stream, float gain)
238{
239 return 0;
240}
241
242static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
243 size_t bytes)
244{
Dmitry Shmidta898f932016-10-26 13:54:25 -0700245 ALOGV("in_read: bytes %zu", bytes);
Andy Hung0caeee82016-06-24 19:41:06 -0700246
Dima Zavin8cc353a2011-04-20 16:38:05 -0700247 /* XXX: fake timing for audio input */
Andy Hung0caeee82016-06-24 19:41:06 -0700248 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 Garcia37cd7722015-02-23 15:42:26 -0800271 memset(buffer, 0, bytes);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700272 return bytes;
273}
274
275static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
276{
277 return 0;
278}
279
Eric Laurentf3008aa2011-06-17 16:53:12 -0700280static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
281{
282 return 0;
283}
284
285static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
286{
287 return 0;
288}
Dima Zavin8cc353a2011-04-20 16:38:05 -0700289
290static int adev_open_output_stream(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700291 audio_io_handle_t handle,
292 audio_devices_t devices,
293 audio_output_flags_t flags,
294 struct audio_config *config,
Eric Laurentf5e24692014-07-27 16:14:57 -0700295 struct audio_stream_out **stream_out,
296 const char *address __unused)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700297{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800298 ALOGV("adev_open_output_stream...");
299
Dima Zavin8cc353a2011-04-20 16:38:05 -0700300 struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
301 struct stub_stream_out *out;
302 int ret;
303
304 out = (struct stub_stream_out *)calloc(1, sizeof(struct stub_stream_out));
305 if (!out)
306 return -ENOMEM;
307
308 out->stream.common.get_sample_rate = out_get_sample_rate;
309 out->stream.common.set_sample_rate = out_set_sample_rate;
310 out->stream.common.get_buffer_size = out_get_buffer_size;
311 out->stream.common.get_channels = out_get_channels;
312 out->stream.common.get_format = out_get_format;
313 out->stream.common.set_format = out_set_format;
314 out->stream.common.standby = out_standby;
315 out->stream.common.dump = out_dump;
316 out->stream.common.set_parameters = out_set_parameters;
317 out->stream.common.get_parameters = out_get_parameters;
Eric Laurentf3008aa2011-06-17 16:53:12 -0700318 out->stream.common.add_audio_effect = out_add_audio_effect;
319 out->stream.common.remove_audio_effect = out_remove_audio_effect;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700320 out->stream.get_latency = out_get_latency;
321 out->stream.set_volume = out_set_volume;
322 out->stream.write = out_write;
323 out->stream.get_render_position = out_get_render_position;
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700324 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700325
326 *stream_out = &out->stream;
327 return 0;
328
329err_open:
330 free(out);
331 *stream_out = NULL;
332 return ret;
333}
334
335static void adev_close_output_stream(struct audio_hw_device *dev,
336 struct audio_stream_out *stream)
337{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800338 ALOGV("adev_close_output_stream...");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700339 free(stream);
340}
341
342static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
343{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800344 ALOGV("adev_set_parameters");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700345 return -ENOSYS;
346}
347
348static char * adev_get_parameters(const struct audio_hw_device *dev,
349 const char *keys)
350{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800351 ALOGV("adev_get_parameters");
352 return strdup("");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700353}
354
355static int adev_init_check(const struct audio_hw_device *dev)
356{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800357 ALOGV("adev_init_check");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700358 return 0;
359}
360
361static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
362{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800363 ALOGV("adev_set_voice_volume: %f", volume);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700364 return -ENOSYS;
365}
366
367static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
368{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800369 ALOGV("adev_set_master_volume: %f", volume);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700370 return -ENOSYS;
371}
372
John Grossman47bf3d72012-07-17 11:54:04 -0700373static int adev_get_master_volume(struct audio_hw_device *dev, float *volume)
374{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800375 ALOGV("adev_get_master_volume: %f", *volume);
John Grossman47bf3d72012-07-17 11:54:04 -0700376 return -ENOSYS;
377}
378
379static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
380{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800381 ALOGV("adev_set_master_mute: %d", muted);
John Grossman47bf3d72012-07-17 11:54:04 -0700382 return -ENOSYS;
383}
384
385static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700386{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800387 ALOGV("adev_get_master_mute: %d", *muted);
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700388 return -ENOSYS;
389}
390
Glenn Kasten6df641e2012-01-09 10:41:30 -0800391static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700392{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800393 ALOGV("adev_set_mode: %d", mode);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700394 return 0;
395}
396
397static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
398{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800399 ALOGV("adev_set_mic_mute: %d",state);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700400 return -ENOSYS;
401}
402
403static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
404{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800405 ALOGV("adev_get_mic_mute");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700406 return -ENOSYS;
407}
408
409static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700410 const struct audio_config *config)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700411{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800412 ALOGV("adev_get_input_buffer_size: %d", 320);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700413 return 320;
414}
415
Eric Laurent55786bc2012-04-10 16:56:32 -0700416static int adev_open_input_stream(struct audio_hw_device *dev,
417 audio_io_handle_t handle,
418 audio_devices_t devices,
419 struct audio_config *config,
Glenn Kasten7d973ad2014-07-15 11:10:38 -0700420 struct audio_stream_in **stream_in,
Eric Laurentf5e24692014-07-27 16:14:57 -0700421 audio_input_flags_t flags __unused,
422 const char *address __unused,
423 audio_source_t source __unused)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700424{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800425 ALOGV("adev_open_input_stream...");
426
Dima Zavin8cc353a2011-04-20 16:38:05 -0700427 struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
428 struct stub_stream_in *in;
429 int ret;
430
431 in = (struct stub_stream_in *)calloc(1, sizeof(struct stub_stream_in));
432 if (!in)
433 return -ENOMEM;
434
435 in->stream.common.get_sample_rate = in_get_sample_rate;
436 in->stream.common.set_sample_rate = in_set_sample_rate;
437 in->stream.common.get_buffer_size = in_get_buffer_size;
438 in->stream.common.get_channels = in_get_channels;
439 in->stream.common.get_format = in_get_format;
440 in->stream.common.set_format = in_set_format;
441 in->stream.common.standby = in_standby;
442 in->stream.common.dump = in_dump;
443 in->stream.common.set_parameters = in_set_parameters;
444 in->stream.common.get_parameters = in_get_parameters;
Eric Laurentf3008aa2011-06-17 16:53:12 -0700445 in->stream.common.add_audio_effect = in_add_audio_effect;
446 in->stream.common.remove_audio_effect = in_remove_audio_effect;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700447 in->stream.set_gain = in_set_gain;
448 in->stream.read = in_read;
449 in->stream.get_input_frames_lost = in_get_input_frames_lost;
450
451 *stream_in = &in->stream;
452 return 0;
453
454err_open:
455 free(in);
456 *stream_in = NULL;
457 return ret;
458}
459
460static void adev_close_input_stream(struct audio_hw_device *dev,
461 struct audio_stream_in *in)
462{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800463 ALOGV("adev_close_input_stream...");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700464 return;
465}
466
467static int adev_dump(const audio_hw_device_t *device, int fd)
468{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800469 ALOGV("adev_dump");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700470 return 0;
471}
472
473static int adev_close(hw_device_t *device)
474{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800475 ALOGV("adev_close");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700476 free(device);
477 return 0;
478}
479
Dima Zavin8cc353a2011-04-20 16:38:05 -0700480static int adev_open(const hw_module_t* module, const char* name,
481 hw_device_t** device)
482{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800483 ALOGV("adev_open: %s", name);
484
Dima Zavin8cc353a2011-04-20 16:38:05 -0700485 struct stub_audio_device *adev;
486 int ret;
487
488 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
489 return -EINVAL;
490
491 adev = calloc(1, sizeof(struct stub_audio_device));
492 if (!adev)
493 return -ENOMEM;
494
495 adev->device.common.tag = HARDWARE_DEVICE_TAG;
Eric Laurent85e08e22012-08-28 14:30:35 -0700496 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700497 adev->device.common.module = (struct hw_module_t *) module;
498 adev->device.common.close = adev_close;
499
Dima Zavin8cc353a2011-04-20 16:38:05 -0700500 adev->device.init_check = adev_init_check;
501 adev->device.set_voice_volume = adev_set_voice_volume;
502 adev->device.set_master_volume = adev_set_master_volume;
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700503 adev->device.get_master_volume = adev_get_master_volume;
John Grossman47bf3d72012-07-17 11:54:04 -0700504 adev->device.set_master_mute = adev_set_master_mute;
505 adev->device.get_master_mute = adev_get_master_mute;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700506 adev->device.set_mode = adev_set_mode;
507 adev->device.set_mic_mute = adev_set_mic_mute;
508 adev->device.get_mic_mute = adev_get_mic_mute;
509 adev->device.set_parameters = adev_set_parameters;
510 adev->device.get_parameters = adev_get_parameters;
511 adev->device.get_input_buffer_size = adev_get_input_buffer_size;
512 adev->device.open_output_stream = adev_open_output_stream;
513 adev->device.close_output_stream = adev_close_output_stream;
514 adev->device.open_input_stream = adev_open_input_stream;
515 adev->device.close_input_stream = adev_close_input_stream;
516 adev->device.dump = adev_dump;
517
518 *device = &adev->device.common;
519
520 return 0;
521}
522
523static struct hw_module_methods_t hal_module_methods = {
524 .open = adev_open,
525};
526
527struct audio_module HAL_MODULE_INFO_SYM = {
528 .common = {
529 .tag = HARDWARE_MODULE_TAG,
Eric Laurent55786bc2012-04-10 16:56:32 -0700530 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
531 .hal_api_version = HARDWARE_HAL_API_VERSION,
Dima Zavin8cc353a2011-04-20 16:38:05 -0700532 .id = AUDIO_HARDWARE_MODULE_ID,
533 .name = "Default audio HW HAL",
534 .author = "The Android Open Source Project",
535 .methods = &hal_module_methods,
536 },
537};