OSDN Git Service

android/audio: Add wrapper struct for struct audio_hw_dev
[android-x86/external-bluetooth-bluez.git] / android / hal-audio.c
1 /*
2  * Copyright (C) 2013 Intel Corporation
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
18 #include <errno.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include <hardware/audio.h>
24 #include <hardware/hardware.h>
25
26 #include "hal-log.h"
27
28 struct a2dp_audio_dev {
29         struct audio_hw_device dev;
30         struct audio_stream_out *out;
31 };
32
33 static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
34                                                                 size_t bytes)
35 {
36         DBG("");
37         return -ENOSYS;
38 }
39
40 static uint32_t out_get_sample_rate(const struct audio_stream *stream)
41 {
42         DBG("");
43         return -ENOSYS;
44 }
45
46 static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
47 {
48         DBG("");
49         return -ENOSYS;
50 }
51
52 static size_t out_get_buffer_size(const struct audio_stream *stream)
53 {
54         DBG("");
55         return -ENOSYS;
56 }
57
58 static uint32_t out_get_channels(const struct audio_stream *stream)
59 {
60         DBG("");
61         return -ENOSYS;
62 }
63
64 static audio_format_t out_get_format(const struct audio_stream *stream)
65 {
66         DBG("");
67         return -ENOSYS;
68 }
69
70 static int out_set_format(struct audio_stream *stream, audio_format_t format)
71 {
72         DBG("");
73         return -ENOSYS;
74 }
75
76 static int out_standby(struct audio_stream *stream)
77 {
78         DBG("");
79         return -ENOSYS;
80 }
81
82 static int out_dump(const struct audio_stream *stream, int fd)
83 {
84         DBG("");
85         return -ENOSYS;
86 }
87
88 static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
89 {
90         DBG("");
91         return -ENOSYS;
92 }
93
94 static char *out_get_parameters(const struct audio_stream *stream,
95                                                         const char *keys)
96 {
97         DBG("");
98         return strdup("");
99 }
100
101 static uint32_t out_get_latency(const struct audio_stream_out *stream)
102 {
103         DBG("");
104         return -ENOSYS;
105 }
106
107 static int out_set_volume(struct audio_stream_out *stream, float left,
108                                                                 float right)
109 {
110         DBG("");
111         /* volume controlled in audioflinger mixer (digital) */
112         return -ENOSYS;
113 }
114
115 static int out_get_render_position(const struct audio_stream_out *stream,
116                                                         uint32_t *dsp_frames)
117 {
118         DBG("");
119         return -ENOSYS;
120 }
121
122 static int out_add_audio_effect(const struct audio_stream *stream,
123                                                         effect_handle_t effect)
124 {
125         DBG("");
126         return -ENOSYS;
127 }
128
129 static int out_remove_audio_effect(const struct audio_stream *stream,
130                                                         effect_handle_t effect)
131 {
132         DBG("");
133         return -ENOSYS;
134 }
135
136 static uint32_t in_get_sample_rate(const struct audio_stream *stream)
137 {
138         DBG("");
139         return -ENOSYS;
140 }
141
142 static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
143 {
144         DBG("");
145         return -ENOSYS;
146 }
147
148 static size_t in_get_buffer_size(const struct audio_stream *stream)
149 {
150         DBG("");
151         return -ENOSYS;
152 }
153
154 static uint32_t in_get_channels(const struct audio_stream *stream)
155 {
156         DBG("");
157         return -ENOSYS;
158 }
159
160 static audio_format_t in_get_format(const struct audio_stream *stream)
161 {
162         DBG("");
163         return -ENOSYS;
164 }
165
166 static int in_set_format(struct audio_stream *stream, audio_format_t format)
167 {
168         DBG("");
169         return -ENOSYS;
170 }
171
172 static int in_standby(struct audio_stream *stream)
173 {
174         DBG("");
175         return -ENOSYS;
176 }
177
178 static int in_dump(const struct audio_stream *stream, int fd)
179 {
180         DBG("");
181         return -ENOSYS;
182 }
183
184 static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
185 {
186         DBG("");
187         return -ENOSYS;
188 }
189
190 static char *in_get_parameters(const struct audio_stream *stream,
191                                                         const char *keys)
192 {
193         DBG("");
194         return strdup("");
195 }
196
197 static int in_set_gain(struct audio_stream_in *stream, float gain)
198 {
199         DBG("");
200         return -ENOSYS;
201 }
202
203 static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
204                                                                 size_t bytes)
205 {
206         DBG("");
207         return -ENOSYS;
208 }
209
210 static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
211 {
212         DBG("");
213         return -ENOSYS;
214 }
215
216 static int in_add_audio_effect(const struct audio_stream *stream,
217                                                         effect_handle_t effect)
218 {
219         DBG("");
220         return -ENOSYS;
221 }
222
223 static int in_remove_audio_effect(const struct audio_stream *stream,
224                                                         effect_handle_t effect)
225 {
226         DBG("");
227         return -ENOSYS;
228 }
229
230 static int audio_open_output_stream(struct audio_hw_device *dev,
231                                         audio_io_handle_t handle,
232                                         audio_devices_t devices,
233                                         audio_output_flags_t flags,
234                                         struct audio_config *config,
235                                         struct audio_stream_out **stream_out)
236
237 {
238         struct a2dp_audio_dev *a2dp_dev = (struct a2dp_audio_dev *) dev;
239         struct audio_stream_out *out;
240
241         out = calloc(1, sizeof(struct audio_stream_out));
242         if (!out)
243                 return -ENOMEM;
244
245         DBG("");
246
247         out->common.get_sample_rate = out_get_sample_rate;
248         out->common.set_sample_rate = out_set_sample_rate;
249         out->common.get_buffer_size = out_get_buffer_size;
250         out->common.get_channels = out_get_channels;
251         out->common.get_format = out_get_format;
252         out->common.set_format = out_set_format;
253         out->common.standby = out_standby;
254         out->common.dump = out_dump;
255         out->common.set_parameters = out_set_parameters;
256         out->common.get_parameters = out_get_parameters;
257         out->common.add_audio_effect = out_add_audio_effect;
258         out->common.remove_audio_effect = out_remove_audio_effect;
259         out->get_latency = out_get_latency;
260         out->set_volume = out_set_volume;
261         out->write = out_write;
262         out->get_render_position = out_get_render_position;
263
264         *stream_out = out;
265         a2dp_dev->out = out;
266
267         return 0;
268 }
269
270 static void audio_close_output_stream(struct audio_hw_device *dev,
271                                         struct audio_stream_out *stream)
272 {
273         DBG("");
274         struct a2dp_audio_dev *a2dp_dev = (struct a2dp_audio_dev *)dev;
275
276         free(stream);
277         a2dp_dev->out = NULL;
278 }
279
280 static int audio_set_parameters(struct audio_hw_device *dev,
281                                                         const char *kvpairs)
282 {
283         DBG("");
284         return -ENOSYS;
285 }
286
287 static char *audio_get_parameters(const struct audio_hw_device *dev,
288                                                         const char *keys)
289 {
290         DBG("");
291         return strdup("");
292 }
293
294 static int audio_init_check(const struct audio_hw_device *dev)
295 {
296         DBG("");
297         return -ENOSYS;
298 }
299
300 static int audio_set_voice_volume(struct audio_hw_device *dev, float volume)
301 {
302         DBG("");
303         return -ENOSYS;
304 }
305
306 static int audio_set_master_volume(struct audio_hw_device *dev, float volume)
307 {
308         DBG("");
309         return -ENOSYS;
310 }
311
312 static int audio_set_mode(struct audio_hw_device *dev, int mode)
313 {
314         DBG("");
315         return -ENOSYS;
316 }
317
318 static int audio_set_mic_mute(struct audio_hw_device *dev, bool state)
319 {
320         DBG("");
321         return -ENOSYS;
322 }
323
324 static int audio_get_mic_mute(const struct audio_hw_device *dev, bool *state)
325 {
326         DBG("");
327         return -ENOSYS;
328 }
329
330 static size_t audio_get_input_buffer_size(const struct audio_hw_device *dev,
331                                         const struct audio_config *config)
332 {
333         DBG("");
334         return -ENOSYS;
335 }
336
337 static int audio_open_input_stream(struct audio_hw_device *dev,
338                                         audio_io_handle_t handle,
339                                         audio_devices_t devices,
340                                         struct audio_config *config,
341                                         struct audio_stream_in **stream_in)
342 {
343         struct audio_stream_in *in;
344
345         DBG("");
346
347         in = calloc(1, sizeof(struct audio_stream_in));
348         if (!in)
349                 return -ENOMEM;
350
351         in->common.get_sample_rate = in_get_sample_rate;
352         in->common.set_sample_rate = in_set_sample_rate;
353         in->common.get_buffer_size = in_get_buffer_size;
354         in->common.get_channels = in_get_channels;
355         in->common.get_format = in_get_format;
356         in->common.set_format = in_set_format;
357         in->common.standby = in_standby;
358         in->common.dump = in_dump;
359         in->common.set_parameters = in_set_parameters;
360         in->common.get_parameters = in_get_parameters;
361         in->common.add_audio_effect = in_add_audio_effect;
362         in->common.remove_audio_effect = in_remove_audio_effect;
363         in->set_gain = in_set_gain;
364         in->read = in_read;
365         in->get_input_frames_lost = in_get_input_frames_lost;
366
367         *stream_in = in;
368
369         return 0;
370 }
371
372 static void audio_close_input_stream(struct audio_hw_device *dev,
373                                         struct audio_stream_in *stream_in)
374 {
375         DBG("");
376         free(stream_in);
377 }
378
379 static int audio_dump(const audio_hw_device_t *device, int fd)
380 {
381         DBG("");
382         return -ENOSYS;
383 }
384
385 static int audio_close(hw_device_t *device)
386 {
387         DBG("");
388         free(device);
389         return 0;
390 }
391
392 static int audio_open(const hw_module_t *module, const char *name,
393                                                         hw_device_t **device)
394 {
395         struct a2dp_audio_dev *a2dp_dev;
396
397         DBG("");
398
399         if (strcmp(name, AUDIO_HARDWARE_INTERFACE)) {
400                 error("interface %s not matching [%s]", name,
401                                                 AUDIO_HARDWARE_INTERFACE);
402                 return -EINVAL;
403         }
404
405         a2dp_dev = calloc(1, sizeof(struct a2dp_audio_dev));
406         if (!a2dp_dev)
407                 return -ENOMEM;
408
409         a2dp_dev->dev.common.version = AUDIO_DEVICE_API_VERSION_CURRENT;
410         a2dp_dev->dev.common.module = (struct hw_module_t *) module;
411         a2dp_dev->dev.common.close = audio_close;
412
413         a2dp_dev->dev.init_check = audio_init_check;
414         a2dp_dev->dev.set_voice_volume = audio_set_voice_volume;
415         a2dp_dev->dev.set_master_volume = audio_set_master_volume;
416         a2dp_dev->dev.set_mode = audio_set_mode;
417         a2dp_dev->dev.set_mic_mute = audio_set_mic_mute;
418         a2dp_dev->dev.get_mic_mute = audio_get_mic_mute;
419         a2dp_dev->dev.set_parameters = audio_set_parameters;
420         a2dp_dev->dev.get_parameters = audio_get_parameters;
421         a2dp_dev->dev.get_input_buffer_size = audio_get_input_buffer_size;
422         a2dp_dev->dev.open_output_stream = audio_open_output_stream;
423         a2dp_dev->dev.close_output_stream = audio_close_output_stream;
424         a2dp_dev->dev.open_input_stream = audio_open_input_stream;
425         a2dp_dev->dev.close_input_stream = audio_close_input_stream;
426         a2dp_dev->dev.dump = audio_dump;
427
428         /* Note that &a2dp_dev->dev.common is the same pointer as a2dp_dev.
429          * This results from the structure of following structs:a2dp_audio_dev,
430          * audio_hw_device. We will rely on this later in the code.*/
431         *device = &a2dp_dev->dev.common;
432
433         return 0;
434 }
435
436 static struct hw_module_methods_t hal_module_methods = {
437         .open = audio_open,
438 };
439
440 struct audio_module HAL_MODULE_INFO_SYM = {
441         .common = {
442         .tag = HARDWARE_MODULE_TAG,
443         .version_major = 1,
444         .version_minor = 0,
445         .id = AUDIO_HARDWARE_MODULE_ID,
446         .name = "A2DP Bluez HW HAL",
447         .author = "Intel Corporation",
448         .methods = &hal_module_methods,
449         },
450 };