blob: 3c288cab55d9140e36f1fed9d06d0d033874f6b8 [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>
Mark Salyzynd88dfe82017-04-11 08:56:09 -070024#include <stdlib.h>
25#include <string.h>
26#include <time.h>
27#include <unistd.h>
Dima Zavin8cc353a2011-04-20 16:38:05 -070028
Mark Salyzynd88dfe82017-04-11 08:56:09 -070029#include <log/log.h>
Dima Zavin8cc353a2011-04-20 16:38:05 -070030
Mark Salyzynd88dfe82017-04-11 08:56:09 -070031#include <hardware/audio.h>
Dima Zavin8cc353a2011-04-20 16:38:05 -070032#include <hardware/hardware.h>
Dima Zavinaa211722011-05-11 14:15:53 -070033#include <system/audio.h>
Dima Zavin8cc353a2011-04-20 16:38:05 -070034
35struct stub_audio_device {
36 struct audio_hw_device device;
37};
38
39struct stub_stream_out {
40 struct audio_stream_out stream;
Andy Hung0caeee82016-06-24 19:41:06 -070041 int64_t last_write_time_us;
Dima Zavin8cc353a2011-04-20 16:38:05 -070042};
43
44struct stub_stream_in {
45 struct audio_stream_in stream;
Andy Hung0caeee82016-06-24 19:41:06 -070046 int64_t last_read_time_us;
Dima Zavin8cc353a2011-04-20 16:38:05 -070047};
48
49static uint32_t out_get_sample_rate(const struct audio_stream *stream)
50{
51 return 44100;
52}
53
54static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
55{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080056 ALOGV("out_set_sample_rate: %d", 0);
57 return -ENOSYS;
Dima Zavin8cc353a2011-04-20 16:38:05 -070058}
59
60static size_t out_get_buffer_size(const struct audio_stream *stream)
61{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080062 ALOGV("out_get_buffer_size: %d", 4096);
Dima Zavin8cc353a2011-04-20 16:38:05 -070063 return 4096;
64}
65
Glenn Kastena6354492012-06-19 12:16:04 -070066static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
Dima Zavin8cc353a2011-04-20 16:38:05 -070067{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080068 ALOGV("out_get_channels");
Dima Zavin8cc353a2011-04-20 16:38:05 -070069 return AUDIO_CHANNEL_OUT_STEREO;
70}
71
Glenn Kastenfe79eb32012-01-12 14:55:57 -080072static audio_format_t out_get_format(const struct audio_stream *stream)
Dima Zavin8cc353a2011-04-20 16:38:05 -070073{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080074 ALOGV("out_get_format");
Dima Zavin8cc353a2011-04-20 16:38:05 -070075 return AUDIO_FORMAT_PCM_16_BIT;
76}
77
Glenn Kastenfe79eb32012-01-12 14:55:57 -080078static int out_set_format(struct audio_stream *stream, audio_format_t format)
Dima Zavin8cc353a2011-04-20 16:38:05 -070079{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080080 ALOGV("out_set_format: %d",format);
81 return -ENOSYS;
Dima Zavin8cc353a2011-04-20 16:38:05 -070082}
83
84static int out_standby(struct audio_stream *stream)
85{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080086 ALOGV("out_standby");
Andy Hung0caeee82016-06-24 19:41:06 -070087 // out->last_write_time_us = 0; unnecessary as a stale write time has same effect
Dima Zavin8cc353a2011-04-20 16:38:05 -070088 return 0;
89}
90
91static int out_dump(const struct audio_stream *stream, int fd)
92{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080093 ALOGV("out_dump");
Dima Zavin8cc353a2011-04-20 16:38:05 -070094 return 0;
95}
96
97static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
98{
Ricardo Garcia37cd7722015-02-23 15:42:26 -080099 ALOGV("out_set_parameters");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700100 return 0;
101}
102
103static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
104{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800105 ALOGV("out_get_parameters");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700106 return strdup("");
107}
108
109static uint32_t out_get_latency(const struct audio_stream_out *stream)
110{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800111 ALOGV("out_get_latency");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700112 return 0;
113}
114
115static int out_set_volume(struct audio_stream_out *stream, float left,
116 float right)
117{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800118 ALOGV("out_set_volume: Left:%f Right:%f", left, right);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700119 return 0;
120}
121
122static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
123 size_t bytes)
124{
Dmitry Shmidta898f932016-10-26 13:54:25 -0700125 ALOGV("out_write: bytes: %zu", bytes);
Andy Hung0caeee82016-06-24 19:41:06 -0700126
Dima Zavin8cc353a2011-04-20 16:38:05 -0700127 /* XXX: fake timing for audio output */
Andy Hung0caeee82016-06-24 19:41:06 -0700128 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 Zavin8cc353a2011-04-20 16:38:05 -0700151 return bytes;
152}
153
154static int out_get_render_position(const struct audio_stream_out *stream,
155 uint32_t *dsp_frames)
156{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800157 *dsp_frames = 0;
Glenn Kastene03bfa42015-03-23 10:52:31 -0700158 ALOGV("out_get_render_position: dsp_frames: %p", dsp_frames);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700159 return -EINVAL;
160}
161
Eric Laurentf3008aa2011-06-17 16:53:12 -0700162static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
163{
Glenn Kastene03bfa42015-03-23 10:52:31 -0700164 ALOGV("out_add_audio_effect: %p", effect);
Eric Laurentf3008aa2011-06-17 16:53:12 -0700165 return 0;
166}
167
168static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
169{
Glenn Kastene03bfa42015-03-23 10:52:31 -0700170 ALOGV("out_remove_audio_effect: %p", effect);
Eric Laurentf3008aa2011-06-17 16:53:12 -0700171 return 0;
172}
173
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700174static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
175 int64_t *timestamp)
176{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800177 *timestamp = 0;
178 ALOGV("out_get_next_write_timestamp: %ld", (long int)(*timestamp));
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700179 return -EINVAL;
180}
181
Dima Zavin8cc353a2011-04-20 16:38:05 -0700182/** audio_stream_in implementation **/
183static uint32_t in_get_sample_rate(const struct audio_stream *stream)
184{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800185 ALOGV("in_get_sample_rate");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700186 return 8000;
187}
188
189static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
190{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800191 ALOGV("in_set_sample_rate: %d", rate);
192 return -ENOSYS;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700193}
194
195static size_t in_get_buffer_size(const struct audio_stream *stream)
196{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800197 ALOGV("in_get_buffer_size: %d", 320);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700198 return 320;
199}
200
Glenn Kastena6354492012-06-19 12:16:04 -0700201static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700202{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800203 ALOGV("in_get_channels: %d", AUDIO_CHANNEL_IN_MONO);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700204 return AUDIO_CHANNEL_IN_MONO;
205}
206
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800207static audio_format_t in_get_format(const struct audio_stream *stream)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700208{
209 return AUDIO_FORMAT_PCM_16_BIT;
210}
211
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800212static int in_set_format(struct audio_stream *stream, audio_format_t format)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700213{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800214 return -ENOSYS;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700215}
216
217static int in_standby(struct audio_stream *stream)
218{
Andy Hung0caeee82016-06-24 19:41:06 -0700219 struct stub_stream_in *in = (struct stub_stream_in *)stream;
220 in->last_read_time_us = 0;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700221 return 0;
222}
223
224static int in_dump(const struct audio_stream *stream, int fd)
225{
226 return 0;
227}
228
229static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
230{
231 return 0;
232}
233
234static char * in_get_parameters(const struct audio_stream *stream,
235 const char *keys)
236{
237 return strdup("");
238}
239
240static int in_set_gain(struct audio_stream_in *stream, float gain)
241{
242 return 0;
243}
244
245static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
246 size_t bytes)
247{
Dmitry Shmidta898f932016-10-26 13:54:25 -0700248 ALOGV("in_read: bytes %zu", bytes);
Andy Hung0caeee82016-06-24 19:41:06 -0700249
Dima Zavin8cc353a2011-04-20 16:38:05 -0700250 /* XXX: fake timing for audio input */
Andy Hung0caeee82016-06-24 19:41:06 -0700251 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 Garcia37cd7722015-02-23 15:42:26 -0800274 memset(buffer, 0, bytes);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700275 return bytes;
276}
277
278static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
279{
280 return 0;
281}
282
Eric Laurentf3008aa2011-06-17 16:53:12 -0700283static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
284{
285 return 0;
286}
287
288static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
289{
290 return 0;
291}
Dima Zavin8cc353a2011-04-20 16:38:05 -0700292
293static int adev_open_output_stream(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700294 audio_io_handle_t handle,
295 audio_devices_t devices,
296 audio_output_flags_t flags,
297 struct audio_config *config,
Eric Laurentf5e24692014-07-27 16:14:57 -0700298 struct audio_stream_out **stream_out,
299 const char *address __unused)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700300{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800301 ALOGV("adev_open_output_stream...");
302
Dima Zavin8cc353a2011-04-20 16:38:05 -0700303 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 Laurentf3008aa2011-06-17 16:53:12 -0700321 out->stream.common.add_audio_effect = out_add_audio_effect;
322 out->stream.common.remove_audio_effect = out_remove_audio_effect;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700323 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. Chen5ad38a92011-08-15 12:05:00 -0700327 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700328
329 *stream_out = &out->stream;
330 return 0;
331
332err_open:
333 free(out);
334 *stream_out = NULL;
335 return ret;
336}
337
338static void adev_close_output_stream(struct audio_hw_device *dev,
339 struct audio_stream_out *stream)
340{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800341 ALOGV("adev_close_output_stream...");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700342 free(stream);
343}
344
345static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
346{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800347 ALOGV("adev_set_parameters");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700348 return -ENOSYS;
349}
350
351static char * adev_get_parameters(const struct audio_hw_device *dev,
352 const char *keys)
353{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800354 ALOGV("adev_get_parameters");
355 return strdup("");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700356}
357
358static int adev_init_check(const struct audio_hw_device *dev)
359{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800360 ALOGV("adev_init_check");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700361 return 0;
362}
363
364static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
365{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800366 ALOGV("adev_set_voice_volume: %f", volume);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700367 return -ENOSYS;
368}
369
370static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
371{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800372 ALOGV("adev_set_master_volume: %f", volume);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700373 return -ENOSYS;
374}
375
John Grossman47bf3d72012-07-17 11:54:04 -0700376static int adev_get_master_volume(struct audio_hw_device *dev, float *volume)
377{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800378 ALOGV("adev_get_master_volume: %f", *volume);
John Grossman47bf3d72012-07-17 11:54:04 -0700379 return -ENOSYS;
380}
381
382static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
383{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800384 ALOGV("adev_set_master_mute: %d", muted);
John Grossman47bf3d72012-07-17 11:54:04 -0700385 return -ENOSYS;
386}
387
388static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700389{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800390 ALOGV("adev_get_master_mute: %d", *muted);
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700391 return -ENOSYS;
392}
393
Glenn Kasten6df641e2012-01-09 10:41:30 -0800394static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700395{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800396 ALOGV("adev_set_mode: %d", mode);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700397 return 0;
398}
399
400static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
401{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800402 ALOGV("adev_set_mic_mute: %d",state);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700403 return -ENOSYS;
404}
405
406static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
407{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800408 ALOGV("adev_get_mic_mute");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700409 return -ENOSYS;
410}
411
412static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700413 const struct audio_config *config)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700414{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800415 ALOGV("adev_get_input_buffer_size: %d", 320);
Dima Zavin8cc353a2011-04-20 16:38:05 -0700416 return 320;
417}
418
Eric Laurent55786bc2012-04-10 16:56:32 -0700419static 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 Kasten7d973ad2014-07-15 11:10:38 -0700423 struct audio_stream_in **stream_in,
Eric Laurentf5e24692014-07-27 16:14:57 -0700424 audio_input_flags_t flags __unused,
425 const char *address __unused,
426 audio_source_t source __unused)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700427{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800428 ALOGV("adev_open_input_stream...");
429
Dima Zavin8cc353a2011-04-20 16:38:05 -0700430 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 Laurentf3008aa2011-06-17 16:53:12 -0700448 in->stream.common.add_audio_effect = in_add_audio_effect;
449 in->stream.common.remove_audio_effect = in_remove_audio_effect;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700450 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
457err_open:
458 free(in);
459 *stream_in = NULL;
460 return ret;
461}
462
463static void adev_close_input_stream(struct audio_hw_device *dev,
464 struct audio_stream_in *in)
465{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800466 ALOGV("adev_close_input_stream...");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700467 return;
468}
469
470static int adev_dump(const audio_hw_device_t *device, int fd)
471{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800472 ALOGV("adev_dump");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700473 return 0;
474}
475
476static int adev_close(hw_device_t *device)
477{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800478 ALOGV("adev_close");
Dima Zavin8cc353a2011-04-20 16:38:05 -0700479 free(device);
480 return 0;
481}
482
Dima Zavin8cc353a2011-04-20 16:38:05 -0700483static int adev_open(const hw_module_t* module, const char* name,
484 hw_device_t** device)
485{
Ricardo Garcia37cd7722015-02-23 15:42:26 -0800486 ALOGV("adev_open: %s", name);
487
Dima Zavin8cc353a2011-04-20 16:38:05 -0700488 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 Laurent85e08e22012-08-28 14:30:35 -0700499 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700500 adev->device.common.module = (struct hw_module_t *) module;
501 adev->device.common.close = adev_close;
502
Dima Zavin8cc353a2011-04-20 16:38:05 -0700503 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. Chen5ad38a92011-08-15 12:05:00 -0700506 adev->device.get_master_volume = adev_get_master_volume;
John Grossman47bf3d72012-07-17 11:54:04 -0700507 adev->device.set_master_mute = adev_set_master_mute;
508 adev->device.get_master_mute = adev_get_master_mute;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700509 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
526static struct hw_module_methods_t hal_module_methods = {
527 .open = adev_open,
528};
529
530struct audio_module HAL_MODULE_INFO_SYM = {
531 .common = {
532 .tag = HARDWARE_MODULE_TAG,
Eric Laurent55786bc2012-04-10 16:56:32 -0700533 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
534 .hal_api_version = HARDWARE_HAL_API_VERSION,
Dima Zavin8cc353a2011-04-20 16:38:05 -0700535 .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};