OSDN Git Service

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