summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNishanth Menon2014-11-11 17:28:38 -0600
committerNishanth Menon2014-11-11 17:28:38 -0600
commit88fc70c0850794fb0bce52f63dfcc0d8f3d5062e (patch)
treebd2acd9a43827c481dfcca8049f0206c2f7979ef /audio/multizone/audio_hw.cpp
downloaddevice-ti-x15-88fc70c0850794fb0bce52f63dfcc0d8f3d5062e.tar.gz
device-ti-x15-88fc70c0850794fb0bce52f63dfcc0d8f3d5062e.tar.xz
device-ti-x15-88fc70c0850794fb0bce52f63dfcc0d8f3d5062e.zip
initial baseline from TI's code
Signed-off-by: Nishanth Menon <nm@ti.com>
Diffstat (limited to 'audio/multizone/audio_hw.cpp')
-rw-r--r--audio/multizone/audio_hw.cpp562
1 files changed, 562 insertions, 0 deletions
diff --git a/audio/multizone/audio_hw.cpp b/audio/multizone/audio_hw.cpp
new file mode 100644
index 0000000..3e429c4
--- /dev/null
+++ b/audio/multizone/audio_hw.cpp
@@ -0,0 +1,562 @@
1/*
2 * Copyright (C) 2013 Texas Instruments
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_primary"
18/* #define LOG_NDEBUG 0 */
19
20#include <errno.h>
21#include <stdint.h>
22#include <stdlib.h>
23#include <sys/time.h>
24
25#include <cutils/log.h>
26#include <cutils/str_parms.h>
27#include <cutils/properties.h>
28
29#include <system/audio.h>
30#include <hardware/hardware.h>
31#include <hardware/audio.h>
32#include <hardware/audio_effect.h>
33
34#include <AudioHw.h>
35
36extern "C" {
37
38namespace android {
39
40struct mz_audio_device {
41 struct audio_hw_device device;
42 AudioHwDevice *hwDev;
43};
44
45struct mz_stream_in {
46 struct audio_stream_in stream;
47 AudioStreamIn *streamIn;
48};
49
50struct mz_stream_out {
51 struct audio_stream_out stream;
52 AudioStreamOut *streamOut;
53};
54
55static inline AudioHwDevice *toAudioHwDev(struct audio_hw_device *dev)
56{
57 return reinterpret_cast<struct mz_audio_device *>(dev)->hwDev;
58}
59
60static inline const AudioHwDevice *tocAudioHwDev(const struct audio_hw_device *dev)
61{
62 return reinterpret_cast<const struct mz_audio_device *>(dev)->hwDev;
63}
64
65static inline AudioStreamIn *toStreamIn(struct audio_stream_in *in)
66{
67 return reinterpret_cast<struct mz_stream_in *>(in)->streamIn;
68}
69
70static inline const AudioStreamIn *tocStreamIn(const struct audio_stream_in *in)
71{
72 return reinterpret_cast<const struct mz_stream_in *>(in)->streamIn;
73}
74
75static inline AudioStreamOut *toStreamOut(struct audio_stream_out *out)
76{
77 return reinterpret_cast<struct mz_stream_out *>(out)->streamOut;
78}
79
80static inline const AudioStreamOut *tocStreamOut(const struct audio_stream_out *out)
81{
82 return reinterpret_cast<const struct mz_stream_out *>(out)->streamOut;
83}
84
85/* audio HAL functions */
86
87/* audio_stream_out implementation */
88
89static uint32_t out_get_sample_rate(const struct audio_stream *stream)
90{
91 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
92 return out->getSampleRate();
93}
94
95static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
96{
97 AudioStreamOut *out = toStreamOut((audio_stream_out *)stream);
98 return out->setSampleRate(rate);
99}
100
101static size_t out_get_buffer_size(const struct audio_stream *stream)
102{
103 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
104 return out->getBufferSize();
105}
106
107static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
108{
109 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
110 return out->getChannels();
111}
112
113static audio_format_t out_get_format(const struct audio_stream *stream)
114{
115 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
116 return out->getFormat();
117}
118
119static int out_set_format(struct audio_stream *stream, audio_format_t format)
120{
121 AudioStreamOut *out = toStreamOut((audio_stream_out *)stream);
122 return out->setFormat(format);
123}
124
125static int out_standby(struct audio_stream *stream)
126{
127 AudioStreamOut *out = toStreamOut((audio_stream_out *)stream);
128 return out->standby();
129}
130
131static int out_dump(const struct audio_stream *stream, int fd)
132{
133 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
134 return out->dump(fd);
135}
136
137static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
138{
139 AudioStreamOut *out = toStreamOut((audio_stream_out *)stream);
140 return out->setParameters(kvpairs);
141}
142
143static char* out_get_parameters(const struct audio_stream *stream, const char *keys)
144{
145 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
146 return out->getParameters(keys);
147}
148
149static uint32_t out_get_latency(const struct audio_stream_out *stream)
150{
151 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
152 return out->getLatency();
153}
154
155static int out_set_volume(struct audio_stream_out *stream, float left,
156 float right)
157{
158 AudioStreamOut *out = toStreamOut((audio_stream_out *)stream);
159 return out->setVolume(left, right);
160}
161
162static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
163 size_t bytes)
164{
165 AudioStreamOut *out = toStreamOut((audio_stream_out *)stream);
166 return out->write(buffer, bytes);
167}
168
169static int out_get_render_position(const struct audio_stream_out *stream,
170 uint32_t *dsp_frames)
171{
172 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
173 return out->getRenderPosition(dsp_frames);
174}
175
176static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
177{
178 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
179 return out->addAudioEffect(effect);
180}
181
182static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
183{
184 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
185 return out->removeAudioEffect(effect);
186}
187
188static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
189 int64_t *timestamp)
190{
191 const AudioStreamOut *out = tocStreamOut((audio_stream_out *)stream);
192 return out->getNextWriteTimestamp(timestamp);
193}
194
195/* audio_stream_in implementation */
196
197static uint32_t in_get_sample_rate(const struct audio_stream *stream)
198{
199 const AudioStreamIn *in = tocStreamIn((audio_stream_in *)stream);
200 return in->getSampleRate();
201}
202
203static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
204{
205 AudioStreamIn *in = toStreamIn((audio_stream_in *)stream);
206 return in->setSampleRate(rate);
207}
208
209static size_t in_get_buffer_size(const struct audio_stream *stream)
210{
211 const AudioStreamIn *in = tocStreamIn((audio_stream_in *)stream);
212 return in->getBufferSize();
213}
214
215static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
216{
217 const AudioStreamIn *in = tocStreamIn((audio_stream_in *)stream);
218 return in->getChannels();
219}
220
221static audio_format_t in_get_format(const struct audio_stream *stream)
222{
223 const AudioStreamIn *in = tocStreamIn((audio_stream_in *)stream);
224 return in->getFormat();
225}
226
227static int in_set_format(struct audio_stream *stream, audio_format_t format)
228{
229 AudioStreamIn *in = toStreamIn((audio_stream_in *)stream);
230 return in->setFormat(format);
231}
232
233static int in_standby(struct audio_stream *stream)
234{
235 AudioStreamIn *in = toStreamIn((audio_stream_in *)stream);
236 return in->standby();
237}
238
239static int in_dump(const struct audio_stream *stream, int fd)
240{
241 const AudioStreamIn *in = tocStreamIn((audio_stream_in *)stream);
242 return in->dump(fd);
243}
244
245static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
246{
247 AudioStreamIn *in = toStreamIn((audio_stream_in *)stream);
248 return in->setParameters(kvpairs);
249}
250
251static char * in_get_parameters(const struct audio_stream *stream,
252 const char *keys)
253{
254 const AudioStreamIn *in = tocStreamIn((audio_stream_in *)stream);
255 return in->getParameters(keys);
256}
257
258static int in_set_gain(struct audio_stream_in *stream, float gain)
259{
260 AudioStreamIn *in = toStreamIn(stream);
261 return in->setGain(gain);
262}
263
264static ssize_t in_read(struct audio_stream_in *stream, void* buffer, size_t bytes)
265{
266 AudioStreamIn *in = toStreamIn(stream);
267 return in->read(buffer, bytes);
268}
269
270static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
271{
272 AudioStreamIn *in = toStreamIn(stream);
273 return in->getInputFramesLost();
274}
275
276static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
277{
278 const AudioStreamIn *in = tocStreamIn((audio_stream_in *)stream);
279 return in->addAudioEffect(effect);
280}
281
282static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
283{
284 const AudioStreamIn *in = tocStreamIn((audio_stream_in *)stream);
285 return in->removeAudioEffect(effect);
286}
287
288/* audio_hw_device implementation */
289
290static int adev_open_output_stream(struct audio_hw_device *dev,
291 audio_io_handle_t handle,
292 audio_devices_t devices,
293 audio_output_flags_t flags,
294 struct audio_config *config,
295 struct audio_stream_out **stream_out)
296{
297 AudioHwDevice *hwDev = toAudioHwDev(dev);
298 struct mz_stream_out *out;
299
300 out = (struct mz_stream_out *)malloc(sizeof(*out));
301 if (!out)
302 return -ENOMEM;
303
304 ALOGV("adev_open_output_stream() stream %p, %u Hz, %u channels, "
305 "%u bits/sample, flags 0x%08x",
306 out, config->sample_rate, popcount(config->channel_mask),
307 audio_bytes_per_sample(config->format) * 8, flags);
308
309 out->stream.common.get_sample_rate = out_get_sample_rate;
310 out->stream.common.set_sample_rate = out_set_sample_rate;
311 out->stream.common.get_buffer_size = out_get_buffer_size;
312 out->stream.common.get_channels = out_get_channels;
313 out->stream.common.get_format = out_get_format;
314 out->stream.common.set_format = out_set_format;
315 out->stream.common.standby = out_standby;
316 out->stream.common.dump = out_dump;
317 out->stream.common.set_parameters = out_set_parameters;
318 out->stream.common.get_parameters = out_get_parameters;
319 out->stream.common.add_audio_effect = out_add_audio_effect;
320 out->stream.common.remove_audio_effect = out_remove_audio_effect;
321 out->stream.get_latency = out_get_latency;
322 out->stream.set_volume = out_set_volume;
323 out->stream.write = out_write;
324 out->stream.get_render_position = out_get_render_position;
325 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
326
327 out->streamOut = hwDev->openOutputStream(handle, devices, flags, config);
328 if (!out->streamOut) {
329 ALOGE("adev_open_output_stream() failed to open stream");
330 free(out);
331 return -ENODEV;
332 }
333
334 *stream_out = &out->stream;
335
336 return 0;
337}
338
339static void adev_close_output_stream(struct audio_hw_device *dev,
340 struct audio_stream_out *stream)
341{
342 AudioHwDevice *hwDev = toAudioHwDev(dev);
343 AudioStreamOut *out = toStreamOut(stream);
344
345 ALOGV("adev_close_output_stream() stream %p", stream);
346
347 out_standby(&stream->common);
348
349 /* closeOutputStream() also deletes the out object */
350 hwDev->closeOutputStream(out);
351
352 free(stream);
353}
354
355static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
356{
357 AudioHwDevice *hwDev = toAudioHwDev(dev);
358 return hwDev->setParameters(kvpairs);
359}
360
361static char *adev_get_parameters(const struct audio_hw_device *dev,
362 const char *keys)
363{
364 const AudioHwDevice *hwDev = tocAudioHwDev(dev);
365 return hwDev->getParameters(keys);
366}
367
368static int adev_init_check(const struct audio_hw_device *dev)
369{
370 const AudioHwDevice *hwDev = tocAudioHwDev(dev);
371 return hwDev->initCheck();
372}
373
374static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
375{
376 AudioHwDevice *hwDev = toAudioHwDev(dev);
377 return hwDev->setVoiceVolume(volume);
378}
379
380static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
381{
382 AudioHwDevice *hwDev = toAudioHwDev(dev);
383 return hwDev->setMasterVolume(volume);
384}
385
386static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
387{
388 AudioHwDevice *hwDev = toAudioHwDev(dev);
389 return hwDev->setMasterMute(muted);
390}
391
392static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
393{
394 AudioHwDevice *hwDev = toAudioHwDev(dev);
395 return hwDev->setMode(mode);
396}
397
398static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
399{
400 AudioHwDevice *hwDev = toAudioHwDev(dev);
401 return hwDev->setMicMute(state);
402}
403
404static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
405{
406 const AudioHwDevice *hwDev = tocAudioHwDev(dev);
407 return hwDev->getMicMute(state);
408}
409
410static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
411 const struct audio_config *config)
412{
413 const AudioHwDevice *hwDev = tocAudioHwDev(dev);
414 return hwDev->getInputBufferSize(config);
415}
416
417static int adev_open_input_stream(struct audio_hw_device *dev,
418 audio_io_handle_t handle,
419 audio_devices_t devices,
420 struct audio_config *config,
421 struct audio_stream_in **stream_in)
422{
423 AudioHwDevice *hwDev = toAudioHwDev(dev);
424 struct mz_stream_in *in;
425 int ret;
426
427 in = (struct mz_stream_in *)malloc(sizeof(*in));
428 if (!in)
429 return -ENOMEM;
430
431 ALOGV("adev_open_input_stream() stream %p, %u Hz, %u channels, "
432 "%u bits/sample",
433 in, config->sample_rate, popcount(config->channel_mask),
434 audio_bytes_per_sample(config->format) * 8);
435
436 in->stream.common.get_sample_rate = in_get_sample_rate;
437 in->stream.common.set_sample_rate = in_set_sample_rate;
438 in->stream.common.get_buffer_size = in_get_buffer_size;
439 in->stream.common.get_channels = in_get_channels;
440 in->stream.common.get_format = in_get_format;
441 in->stream.common.set_format = in_set_format;
442 in->stream.common.standby = in_standby;
443 in->stream.common.dump = in_dump;
444 in->stream.common.set_parameters = in_set_parameters;
445 in->stream.common.get_parameters = in_get_parameters;
446 in->stream.common.add_audio_effect = in_add_audio_effect;
447 in->stream.common.remove_audio_effect = in_remove_audio_effect;
448 in->stream.set_gain = in_set_gain;
449 in->stream.read = in_read;
450 in->stream.get_input_frames_lost = in_get_input_frames_lost;
451
452 in->streamIn = hwDev->openInputStream(handle, devices, config);
453 if (!in->streamIn) {
454 ALOGE("adev_open_input_stream() failed to open stream");
455 free(in);
456 return -ENODEV;
457 }
458
459 *stream_in = &in->stream;
460
461 return 0;
462}
463
464static void adev_close_input_stream(struct audio_hw_device *dev,
465 struct audio_stream_in *stream)
466{
467 AudioHwDevice *hwDev = toAudioHwDev(dev);
468 AudioStreamIn *in = toStreamIn(stream);
469
470 ALOGV("adev_close_input_stream() stream %p", stream);
471
472 in_standby(&stream->common);
473
474 /* closeInputStream() also deletes the in object */
475 hwDev->closeInputStream(in);
476
477 free(stream);
478}
479
480static int adev_dump(const audio_hw_device_t *device, int fd)
481{
482 return 0;
483}
484
485static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev)
486{
487 const AudioHwDevice *hwDev = tocAudioHwDev(dev);
488 return hwDev->getSupportedDevices();
489}
490
491static int adev_close(hw_device_t *device)
492{
493 ALOGI("adev_close()");
494
495 free(device);
496
497 return 0;
498}
499
500static int adev_open(const hw_module_t* module, const char* name, hw_device_t** device)
501{
502 struct mz_audio_device *adev;
503
504 ALOGI("adev_open() %s", name);
505
506 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
507 return -EINVAL;
508
509 adev = (struct mz_audio_device*)calloc(1, sizeof(*adev));
510 if (!adev)
511 return -ENOMEM;
512
513 adev->device.common.tag = HARDWARE_DEVICE_TAG;
514 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
515 adev->device.common.module = (struct hw_module_t *) module;
516 adev->device.common.close = adev_close;
517
518 adev->device.get_supported_devices = adev_get_supported_devices;
519 adev->device.init_check = adev_init_check;
520 adev->device.set_voice_volume = adev_set_voice_volume;
521 adev->device.set_master_volume = adev_set_master_volume;
522 adev->device.set_master_mute = adev_set_master_mute;
523 adev->device.set_mode = adev_set_mode;
524 adev->device.set_mic_mute = adev_set_mic_mute;
525 adev->device.get_mic_mute = adev_get_mic_mute;
526 adev->device.set_parameters = adev_set_parameters;
527 adev->device.get_parameters = adev_get_parameters;
528 adev->device.get_input_buffer_size = adev_get_input_buffer_size;
529 adev->device.open_output_stream = adev_open_output_stream;
530 adev->device.close_output_stream = adev_close_output_stream;
531 adev->device.open_input_stream = adev_open_input_stream;
532 adev->device.close_input_stream = adev_close_input_stream;
533 adev->device.dump = adev_dump;
534
535 adev->hwDev = new AudioHwDevice(0);
536
537 *device = &adev->device.common;
538
539 return 0;
540}
541
542static struct hw_module_methods_t hal_module_methods = {
543 /* open */ adev_open,
544};
545
546struct audio_module HAL_MODULE_INFO_SYM = {
547 /* common */ {
548 /* tag*/ HARDWARE_MODULE_TAG,
549 /* module_api_version */AUDIO_MODULE_API_VERSION_0_1,
550 /* hal_api_version */ HARDWARE_HAL_API_VERSION,
551 /* id */ AUDIO_HARDWARE_MODULE_ID,
552 /* name */ "Jacinto6 Multizone Audio HAL",
553 /* author */ "Texas Instruments Inc.",
554 /* methods */ &hal_module_methods,
555 /* dso */ NULL,
556 /* reserved */ {0},
557 },
558};
559
560} /* namespace android */
561
562} /* extern "C" */