blob: 9083f324ba574396a593869c2b8cac27052ffda2 [file] [log] [blame]
Simon Wilson19957a32012-04-06 16:17:12 -07001/*
2 * Copyright (C) 2012 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
Paul McLean9ab869a2015-01-13 09:37:06 -080017#define LOG_TAG "modules.usbaudio.audio_hal"
Paul McLeancf611912014-04-28 13:03:18 -070018/*#define LOG_NDEBUG 0*/
Simon Wilson19957a32012-04-06 16:17:12 -070019
20#include <errno.h>
Mark Salyzyn88e458a2014-04-28 12:30:44 -070021#include <inttypes.h>
Simon Wilson19957a32012-04-06 16:17:12 -070022#include <pthread.h>
23#include <stdint.h>
Simon Wilson19957a32012-04-06 16:17:12 -070024#include <stdlib.h>
Mark Salyzyn88e458a2014-04-28 12:30:44 -070025#include <sys/time.h>
Tri Vo00a86732017-06-27 11:33:36 -070026#include <unistd.h>
Simon Wilson19957a32012-04-06 16:17:12 -070027
Mark Salyzyn88e458a2014-04-28 12:30:44 -070028#include <log/log.h>
Paul McLean6a75e4e2016-05-25 14:09:02 -060029#include <cutils/list.h>
Simon Wilson19957a32012-04-06 16:17:12 -070030#include <cutils/str_parms.h>
31#include <cutils/properties.h>
32
Simon Wilson19957a32012-04-06 16:17:12 -070033#include <hardware/audio.h>
Paul McLeane32cbc12014-06-25 10:42:07 -070034#include <hardware/audio_alsaops.h>
35#include <hardware/hardware.h>
36
37#include <system/audio.h>
Simon Wilson19957a32012-04-06 16:17:12 -070038
39#include <tinyalsa/asoundlib.h>
40
Paul McLeanc2201152014-07-16 13:46:07 -070041#include <audio_utils/channels.h>
42
Paul McLeanc88e6ae2014-07-16 09:48:34 -070043#include "alsa_device_profile.h"
44#include "alsa_device_proxy.h"
Paul McLean9ab869a2015-01-13 09:37:06 -080045#include "alsa_logging.h"
Paul McLeanf62d75e2014-07-11 15:14:19 -070046
Paul McLeanc88e6ae2014-07-16 09:48:34 -070047#define DEFAULT_INPUT_BUFFER_SIZE_MS 20
Paul McLeanf62d75e2014-07-11 15:14:19 -070048
Paul McLean1d585cc2016-05-24 11:28:10 -060049/* Lock play & record samples rates at or above this threshold */
50#define RATELOCK_THRESHOLD 96000
51
Simon Wilson19957a32012-04-06 16:17:12 -070052struct audio_device {
53 struct audio_hw_device hw_device;
54
55 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Paul McLeaneedc92e2013-12-19 15:46:15 -080056
57 /* output */
Paul McLeanc88e6ae2014-07-16 09:48:34 -070058 alsa_device_profile out_profile;
Paul McLean6a75e4e2016-05-25 14:09:02 -060059 struct listnode output_stream_list;
Paul McLeaneedc92e2013-12-19 15:46:15 -080060
61 /* input */
Paul McLeanc88e6ae2014-07-16 09:48:34 -070062 alsa_device_profile in_profile;
Paul McLean6a75e4e2016-05-25 14:09:02 -060063 struct listnode input_stream_list;
Paul McLeaneedc92e2013-12-19 15:46:15 -080064
Paul McLean1d585cc2016-05-24 11:28:10 -060065 /* lock input & output sample rates */
66 /*FIXME - How do we address multiple output streams? */
67 uint32_t device_sample_rate;
68
Eric Laurent253def92014-09-14 12:18:18 -070069 bool mic_muted;
70
Simon Wilson19957a32012-04-06 16:17:12 -070071 bool standby;
Andy Hungb10ce6d2017-10-27 19:37:58 -070072
73 int32_t inputs_open; /* number of input streams currently open. */
Simon Wilson19957a32012-04-06 16:17:12 -070074};
75
Paul McLean994ac072016-06-02 15:33:24 -060076struct stream_lock {
77 pthread_mutex_t lock; /* see note below on mutex acquisition order */
78 pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by playback thread */
79};
80
Simon Wilson19957a32012-04-06 16:17:12 -070081struct stream_out {
82 struct audio_stream_out stream;
83
Paul McLean994ac072016-06-02 15:33:24 -060084 struct stream_lock lock;
85
Paul McLeaneedc92e2013-12-19 15:46:15 -080086 bool standby;
87
Paul McLean76dba682016-06-01 12:29:11 -060088 struct audio_device *adev; /* hardware information - only using this for the lock */
Paul McLeanc88e6ae2014-07-16 09:48:34 -070089
Paul McLean65ec72b2015-02-18 09:13:24 -080090 alsa_device_profile * profile; /* Points to the alsa_device_profile in the audio_device */
Paul McLeanc88e6ae2014-07-16 09:48:34 -070091 alsa_device_proxy proxy; /* state of the stream */
Paul McLeaneedc92e2013-12-19 15:46:15 -080092
Andy Hung03576be2014-07-21 21:16:45 -070093 unsigned hal_channel_count; /* channel count exposed to AudioFlinger.
94 * This may differ from the device channel count when
95 * the device is not compatible with AudioFlinger
96 * capabilities, e.g. exposes too many channels or
97 * too few channels. */
Paul McLean64345f82016-06-06 13:26:05 -060098 audio_channel_mask_t hal_channel_mask; /* USB devices deal in channel counts, not masks
99 * so the proxy doesn't have a channel_mask, but
100 * audio HALs need to talk about channel masks
101 * so expose the one calculated by
102 * adev_open_output_stream */
Andy Hung182ddc72015-05-05 23:37:30 -0700103
Paul McLean6a75e4e2016-05-25 14:09:02 -0600104 struct listnode list_node;
105
Paul McLeaneedc92e2013-12-19 15:46:15 -0800106 void * conversion_buffer; /* any conversions are put into here
107 * they could come from here too if
108 * there was a previous conversion */
109 size_t conversion_buffer_size; /* in bytes */
110};
111
Paul McLeaneedc92e2013-12-19 15:46:15 -0800112struct stream_in {
113 struct audio_stream_in stream;
114
Paul McLean994ac072016-06-02 15:33:24 -0600115 struct stream_lock lock;
116
Simon Wilson19957a32012-04-06 16:17:12 -0700117 bool standby;
118
Paul McLean76dba682016-06-01 12:29:11 -0600119 struct audio_device *adev; /* hardware information - only using this for the lock */
Paul McLeaneedc92e2013-12-19 15:46:15 -0800120
Paul McLean65ec72b2015-02-18 09:13:24 -0800121 alsa_device_profile * profile; /* Points to the alsa_device_profile in the audio_device */
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700122 alsa_device_proxy proxy; /* state of the stream */
Paul McLeanf62d75e2014-07-11 15:14:19 -0700123
Paul McLean2cfd81b2014-09-15 12:32:23 -0700124 unsigned hal_channel_count; /* channel count exposed to AudioFlinger.
125 * This may differ from the device channel count when
126 * the device is not compatible with AudioFlinger
127 * capabilities, e.g. exposes too many channels or
128 * too few channels. */
Paul McLean64345f82016-06-06 13:26:05 -0600129 audio_channel_mask_t hal_channel_mask; /* USB devices deal in channel counts, not masks
130 * so the proxy doesn't have a channel_mask, but
131 * audio HALs need to talk about channel masks
132 * so expose the one calculated by
133 * adev_open_input_stream */
Andy Hung780f1f82015-04-22 22:14:39 -0700134
Paul McLean6a75e4e2016-05-25 14:09:02 -0600135 struct listnode list_node;
136
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700137 /* We may need to read more data from the device in order to data reduce to 16bit, 4chan */
Paul McLean30f41852014-04-16 15:44:20 -0700138 void * conversion_buffer; /* any conversions are put into here
139 * they could come from here too if
140 * there was a previous conversion */
141 size_t conversion_buffer_size; /* in bytes */
Simon Wilson19957a32012-04-06 16:17:12 -0700142};
143
Paul McLean994ac072016-06-02 15:33:24 -0600144/*
145 * Locking Helpers
146 */
Paul McLeaneedc92e2013-12-19 15:46:15 -0800147/*
Eric Laurent70318092015-06-19 17:49:17 -0700148 * NOTE: when multiple mutexes have to be acquired, always take the
149 * stream_in or stream_out mutex first, followed by the audio_device mutex.
150 * stream pre_lock is always acquired before stream lock to prevent starvation of control thread by
151 * higher priority playback or capture thread.
152 */
153
Paul McLean994ac072016-06-02 15:33:24 -0600154static void stream_lock_init(struct stream_lock *lock) {
155 pthread_mutex_init(&lock->lock, (const pthread_mutexattr_t *) NULL);
156 pthread_mutex_init(&lock->pre_lock, (const pthread_mutexattr_t *) NULL);
157}
158
159static void stream_lock(struct stream_lock *lock) {
160 pthread_mutex_lock(&lock->pre_lock);
161 pthread_mutex_lock(&lock->lock);
162 pthread_mutex_unlock(&lock->pre_lock);
163}
164
165static void stream_unlock(struct stream_lock *lock) {
166 pthread_mutex_unlock(&lock->lock);
167}
168
169static void device_lock(struct audio_device *adev) {
170 pthread_mutex_lock(&adev->lock);
171}
172
173static int device_try_lock(struct audio_device *adev) {
174 return pthread_mutex_trylock(&adev->lock);
175}
176
177static void device_unlock(struct audio_device *adev) {
178 pthread_mutex_unlock(&adev->lock);
179}
180
181/*
182 * streams list management
183 */
184static void adev_add_stream_to_list(
185 struct audio_device* adev, struct listnode* list, struct listnode* stream_node) {
186 device_lock(adev);
187
188 list_add_tail(list, stream_node);
189
190 device_unlock(adev);
191}
192
193static void adev_remove_stream_from_list(
194 struct audio_device* adev, struct listnode* stream_node) {
195 device_lock(adev);
196
197 list_remove(stream_node);
198
199 device_unlock(adev);
200}
201
Eric Laurent70318092015-06-19 17:49:17 -0700202/*
Paul McLean0f1753e2014-12-02 12:36:45 -0700203 * Extract the card and device numbers from the supplied key/value pairs.
204 * kvpairs A null-terminated string containing the key/value pairs or card and device.
205 * i.e. "card=1;device=42"
206 * card A pointer to a variable to receive the parsed-out card number.
207 * device A pointer to a variable to receive the parsed-out device number.
208 * NOTE: The variables pointed to by card and device return -1 (undefined) if the
209 * associated key/value pair is not found in the provided string.
Paul McLean65ec72b2015-02-18 09:13:24 -0800210 * Return true if the kvpairs string contain a card/device spec, false otherwise.
Paul McLean0f1753e2014-12-02 12:36:45 -0700211 */
Paul McLean65ec72b2015-02-18 09:13:24 -0800212static bool parse_card_device_params(const char *kvpairs, int *card, int *device)
Paul McLean0f1753e2014-12-02 12:36:45 -0700213{
214 struct str_parms * parms = str_parms_create_str(kvpairs);
215 char value[32];
216 int param_val;
217
218 // initialize to "undefined" state.
219 *card = -1;
220 *device = -1;
221
222 param_val = str_parms_get_str(parms, "card", value, sizeof(value));
223 if (param_val >= 0) {
224 *card = atoi(value);
225 }
226
227 param_val = str_parms_get_str(parms, "device", value, sizeof(value));
228 if (param_val >= 0) {
229 *device = atoi(value);
230 }
231
232 str_parms_destroy(parms);
Paul McLean65ec72b2015-02-18 09:13:24 -0800233
234 return *card >= 0 && *device >= 0;
Paul McLean0f1753e2014-12-02 12:36:45 -0700235}
236
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700237static char * device_get_parameters(alsa_device_profile * profile, const char * keys)
Paul McLeaneedc92e2013-12-19 15:46:15 -0800238{
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700239 if (profile->card < 0 || profile->device < 0) {
240 return strdup("");
Paul McLeaneedc92e2013-12-19 15:46:15 -0800241 }
Paul McLeane32cbc12014-06-25 10:42:07 -0700242
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700243 struct str_parms *query = str_parms_create_str(keys);
244 struct str_parms *result = str_parms_create();
Paul McLeane32cbc12014-06-25 10:42:07 -0700245
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700246 /* These keys are from hardware/libhardware/include/audio.h */
247 /* supported sample rates */
248 if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES)) {
249 char* rates_list = profile_get_sample_rate_strs(profile);
250 str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES,
251 rates_list);
252 free(rates_list);
Paul McLeane32cbc12014-06-25 10:42:07 -0700253 }
254
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700255 /* supported channel counts */
256 if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS)) {
257 char* channels_list = profile_get_channel_count_strs(profile);
258 str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_CHANNELS,
259 channels_list);
260 free(channels_list);
Paul McLeane32cbc12014-06-25 10:42:07 -0700261 }
262
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700263 /* supported sample formats */
264 if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_FORMATS)) {
265 char * format_params = profile_get_format_strs(profile);
266 str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_FORMATS,
267 format_params);
268 free(format_params);
Paul McLeanf62d75e2014-07-11 15:14:19 -0700269 }
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700270 str_parms_destroy(query);
Paul McLeanf62d75e2014-07-11 15:14:19 -0700271
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700272 char* result_str = str_parms_to_str(result);
273 str_parms_destroy(result);
Paul McLeanf62d75e2014-07-11 15:14:19 -0700274
Paul McLean65ec72b2015-02-18 09:13:24 -0800275 ALOGV("device_get_parameters = %s", result_str);
Paul McLeanf62d75e2014-07-11 15:14:19 -0700276
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700277 return result_str;
Paul McLeaneedc92e2013-12-19 15:46:15 -0800278}
279
280/*
281 * HAl Functions
282 */
Simon Wilson19957a32012-04-06 16:17:12 -0700283/**
284 * NOTE: when multiple mutexes have to be acquired, always respect the
285 * following order: hw device > out stream
286 */
287
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700288/*
289 * OUT functions
290 */
Simon Wilson19957a32012-04-06 16:17:12 -0700291static uint32_t out_get_sample_rate(const struct audio_stream *stream)
292{
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700293 uint32_t rate = proxy_get_sample_rate(&((struct stream_out*)stream)->proxy);
294 ALOGV("out_get_sample_rate() = %d", rate);
295 return rate;
Simon Wilson19957a32012-04-06 16:17:12 -0700296}
297
298static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
299{
300 return 0;
301}
302
303static size_t out_get_buffer_size(const struct audio_stream *stream)
304{
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700305 const struct stream_out* out = (const struct stream_out*)stream;
306 size_t buffer_size =
307 proxy_get_period_size(&out->proxy) * audio_stream_out_frame_size(&(out->stream));
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700308 return buffer_size;
Simon Wilson19957a32012-04-06 16:17:12 -0700309}
310
311static uint32_t out_get_channels(const struct audio_stream *stream)
312{
Andy Hung03576be2014-07-21 21:16:45 -0700313 const struct stream_out *out = (const struct stream_out*)stream;
Andy Hung182ddc72015-05-05 23:37:30 -0700314 return out->hal_channel_mask;
Simon Wilson19957a32012-04-06 16:17:12 -0700315}
316
317static audio_format_t out_get_format(const struct audio_stream *stream)
318{
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700319 /* Note: The HAL doesn't do any FORMAT conversion at this time. It
320 * Relies on the framework to provide data in the specified format.
321 * This could change in the future.
322 */
323 alsa_device_proxy * proxy = &((struct stream_out*)stream)->proxy;
324 audio_format_t format = audio_format_from_pcm_format(proxy_get_format(proxy));
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700325 return format;
Simon Wilson19957a32012-04-06 16:17:12 -0700326}
327
328static int out_set_format(struct audio_stream *stream, audio_format_t format)
329{
330 return 0;
331}
332
333static int out_standby(struct audio_stream *stream)
334{
335 struct stream_out *out = (struct stream_out *)stream;
336
Paul McLean994ac072016-06-02 15:33:24 -0600337 stream_lock(&out->lock);
Simon Wilson19957a32012-04-06 16:17:12 -0700338 if (!out->standby) {
Paul McLean994ac072016-06-02 15:33:24 -0600339 device_lock(out->adev);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700340 proxy_close(&out->proxy);
Paul McLean994ac072016-06-02 15:33:24 -0600341 device_unlock(out->adev);
Simon Wilson19957a32012-04-06 16:17:12 -0700342 out->standby = true;
343 }
Paul McLean994ac072016-06-02 15:33:24 -0600344 stream_unlock(&out->lock);
Simon Wilson19957a32012-04-06 16:17:12 -0700345 return 0;
346}
347
Paul McLean6a75e4e2016-05-25 14:09:02 -0600348static int out_dump(const struct audio_stream *stream, int fd) {
349 const struct stream_out* out_stream = (const struct stream_out*) stream;
350
351 if (out_stream != NULL) {
352 dprintf(fd, "Output Profile:\n");
353 profile_dump(out_stream->profile, fd);
354
355 dprintf(fd, "Output Proxy:\n");
356 proxy_dump(&out_stream->proxy, fd);
357 }
358
Simon Wilson19957a32012-04-06 16:17:12 -0700359 return 0;
360}
361
362static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
363{
Paul McLean65ec72b2015-02-18 09:13:24 -0800364 ALOGV("out_set_parameters() keys:%s", kvpairs);
Paul McLeaneedc92e2013-12-19 15:46:15 -0800365
Simon Wilson19957a32012-04-06 16:17:12 -0700366 struct stream_out *out = (struct stream_out *)stream;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700367
Simon Wilson19957a32012-04-06 16:17:12 -0700368 int routing = 0;
Paul McLeaneedc92e2013-12-19 15:46:15 -0800369 int ret_value = 0;
Eric Laurent05333d42014-08-04 20:29:17 -0700370 int card = -1;
371 int device = -1;
Simon Wilson19957a32012-04-06 16:17:12 -0700372
Paul McLean65ec72b2015-02-18 09:13:24 -0800373 if (!parse_card_device_params(kvpairs, &card, &device)) {
374 // nothing to do
375 return ret_value;
376 }
377
Paul McLean994ac072016-06-02 15:33:24 -0600378 stream_lock(&out->lock);
Paul McLean65ec72b2015-02-18 09:13:24 -0800379 /* Lock the device because that is where the profile lives */
Paul McLean994ac072016-06-02 15:33:24 -0600380 device_lock(out->adev);
Simon Wilson19957a32012-04-06 16:17:12 -0700381
Paul McLean65ec72b2015-02-18 09:13:24 -0800382 if (!profile_is_cached_for(out->profile, card, device)) {
Eric Laurent05333d42014-08-04 20:29:17 -0700383 /* cannot read pcm device info if playback is active */
384 if (!out->standby)
385 ret_value = -ENOSYS;
386 else {
387 int saved_card = out->profile->card;
388 int saved_device = out->profile->device;
389 out->profile->card = card;
390 out->profile->device = device;
391 ret_value = profile_read_device_info(out->profile) ? 0 : -EINVAL;
392 if (ret_value != 0) {
393 out->profile->card = saved_card;
394 out->profile->device = saved_device;
395 }
396 }
Paul McLeaneedc92e2013-12-19 15:46:15 -0800397 }
Paul McLean2c6196f2014-08-20 16:50:25 -0700398
Paul McLean994ac072016-06-02 15:33:24 -0600399 device_unlock(out->adev);
400 stream_unlock(&out->lock);
Simon Wilson19957a32012-04-06 16:17:12 -0700401
Paul McLeaneedc92e2013-12-19 15:46:15 -0800402 return ret_value;
Simon Wilson19957a32012-04-06 16:17:12 -0700403}
404
Paul McLeanf62d75e2014-07-11 15:14:19 -0700405static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
406{
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700407 struct stream_out *out = (struct stream_out *)stream;
Paul McLean994ac072016-06-02 15:33:24 -0600408 stream_lock(&out->lock);
409 device_lock(out->adev);
Paul McLeanf62d75e2014-07-11 15:14:19 -0700410
411 char * params_str = device_get_parameters(out->profile, keys);
412
Paul McLean994ac072016-06-02 15:33:24 -0600413 device_unlock(out->adev);
414 stream_unlock(&out->lock);
Paul McLeanf62d75e2014-07-11 15:14:19 -0700415 return params_str;
416}
417
Simon Wilson19957a32012-04-06 16:17:12 -0700418static uint32_t out_get_latency(const struct audio_stream_out *stream)
419{
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700420 alsa_device_proxy * proxy = &((struct stream_out*)stream)->proxy;
421 return proxy_get_latency(proxy);
Simon Wilson19957a32012-04-06 16:17:12 -0700422}
423
Paul McLean30f41852014-04-16 15:44:20 -0700424static int out_set_volume(struct audio_stream_out *stream, float left, float right)
Simon Wilson19957a32012-04-06 16:17:12 -0700425{
426 return -ENOSYS;
427}
428
Paul McLeaneedc92e2013-12-19 15:46:15 -0800429/* must be called with hw device and output stream mutexes locked */
430static int start_output_stream(struct stream_out *out)
431{
Paul McLean65ec72b2015-02-18 09:13:24 -0800432 ALOGV("start_output_stream(card:%d device:%d)", out->profile->card, out->profile->device);
Paul McLeaneedc92e2013-12-19 15:46:15 -0800433
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700434 return proxy_open(&out->proxy);
Paul McLeaneedc92e2013-12-19 15:46:15 -0800435}
436
437static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, size_t bytes)
Simon Wilson19957a32012-04-06 16:17:12 -0700438{
439 int ret;
440 struct stream_out *out = (struct stream_out *)stream;
441
Paul McLean994ac072016-06-02 15:33:24 -0600442 stream_lock(&out->lock);
Simon Wilson19957a32012-04-06 16:17:12 -0700443 if (out->standby) {
Paul McLean994ac072016-06-02 15:33:24 -0600444 device_lock(out->adev);
Simon Wilson19957a32012-04-06 16:17:12 -0700445 ret = start_output_stream(out);
Paul McLean994ac072016-06-02 15:33:24 -0600446 device_unlock(out->adev);
Simon Wilson19957a32012-04-06 16:17:12 -0700447 if (ret != 0) {
448 goto err;
449 }
450 out->standby = false;
451 }
Eric Laurent05333d42014-08-04 20:29:17 -0700452
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700453 alsa_device_proxy* proxy = &out->proxy;
Mark Salyzyn88e458a2014-04-28 12:30:44 -0700454 const void * write_buff = buffer;
Paul McLeaneedc92e2013-12-19 15:46:15 -0800455 int num_write_buff_bytes = bytes;
Andy Hung03576be2014-07-21 21:16:45 -0700456 const int num_device_channels = proxy_get_channel_count(proxy); /* what we told alsa */
457 const int num_req_channels = out->hal_channel_count; /* what we told AudioFlinger */
Paul McLean30f41852014-04-16 15:44:20 -0700458 if (num_device_channels != num_req_channels) {
Andy Hung03576be2014-07-21 21:16:45 -0700459 /* allocate buffer */
460 const size_t required_conversion_buffer_size =
461 bytes * num_device_channels / num_req_channels;
462 if (required_conversion_buffer_size > out->conversion_buffer_size) {
463 out->conversion_buffer_size = required_conversion_buffer_size;
464 out->conversion_buffer = realloc(out->conversion_buffer,
465 out->conversion_buffer_size);
466 }
467 /* convert data */
468 const audio_format_t audio_format = out_get_format(&(out->stream.common));
469 const unsigned sample_size_in_bytes = audio_bytes_per_sample(audio_format);
Paul McLeaneedc92e2013-12-19 15:46:15 -0800470 num_write_buff_bytes =
Andy Hung03576be2014-07-21 21:16:45 -0700471 adjust_channels(write_buff, num_req_channels,
472 out->conversion_buffer, num_device_channels,
473 sample_size_in_bytes, num_write_buff_bytes);
Paul McLeaneedc92e2013-12-19 15:46:15 -0800474 write_buff = out->conversion_buffer;
475 }
476
Paul McLeaneedc92e2013-12-19 15:46:15 -0800477 if (write_buff != NULL && num_write_buff_bytes != 0) {
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700478 proxy_write(&out->proxy, write_buff, num_write_buff_bytes);
Paul McLeaneedc92e2013-12-19 15:46:15 -0800479 }
Simon Wilson19957a32012-04-06 16:17:12 -0700480
Paul McLean994ac072016-06-02 15:33:24 -0600481 stream_unlock(&out->lock);
Simon Wilson19957a32012-04-06 16:17:12 -0700482
483 return bytes;
484
485err:
Paul McLean994ac072016-06-02 15:33:24 -0600486 stream_unlock(&out->lock);
Simon Wilson19957a32012-04-06 16:17:12 -0700487 if (ret != 0) {
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700488 usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) /
Simon Wilson19957a32012-04-06 16:17:12 -0700489 out_get_sample_rate(&stream->common));
490 }
491
492 return bytes;
493}
494
Paul McLean30f41852014-04-16 15:44:20 -0700495static int out_get_render_position(const struct audio_stream_out *stream, uint32_t *dsp_frames)
Simon Wilson19957a32012-04-06 16:17:12 -0700496{
497 return -EINVAL;
498}
499
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700500static int out_get_presentation_position(const struct audio_stream_out *stream,
501 uint64_t *frames, struct timespec *timestamp)
502{
Andy Hungc9515ce2015-08-04 15:05:19 -0700503 struct stream_out *out = (struct stream_out *)stream; // discard const qualifier
Paul McLean994ac072016-06-02 15:33:24 -0600504 stream_lock(&out->lock);
Andy Hungc9515ce2015-08-04 15:05:19 -0700505
506 const alsa_device_proxy *proxy = &out->proxy;
507 const int ret = proxy_get_presentation_position(proxy, frames, timestamp);
508
Paul McLean994ac072016-06-02 15:33:24 -0600509 stream_unlock(&out->lock);
Andy Hungc9515ce2015-08-04 15:05:19 -0700510 return ret;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700511}
512
Simon Wilson19957a32012-04-06 16:17:12 -0700513static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
514{
515 return 0;
516}
517
518static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
519{
520 return 0;
521}
522
Paul McLean30f41852014-04-16 15:44:20 -0700523static int out_get_next_write_timestamp(const struct audio_stream_out *stream, int64_t *timestamp)
Simon Wilson19957a32012-04-06 16:17:12 -0700524{
525 return -EINVAL;
526}
527
Paul McLean76dba682016-06-01 12:29:11 -0600528static int adev_open_output_stream(struct audio_hw_device *hw_dev,
Mike Lockwood46a98092012-04-24 16:41:18 -0700529 audio_io_handle_t handle,
Paul McLean76dba682016-06-01 12:29:11 -0600530 audio_devices_t devicesSpec __unused,
Mike Lockwood46a98092012-04-24 16:41:18 -0700531 audio_output_flags_t flags,
532 struct audio_config *config,
Eric Laurentf5e24692014-07-27 16:14:57 -0700533 struct audio_stream_out **stream_out,
Paul McLean0f1753e2014-12-02 12:36:45 -0700534 const char *address /*__unused*/)
Simon Wilson19957a32012-04-06 16:17:12 -0700535{
Paul McLean76dba682016-06-01 12:29:11 -0600536 ALOGV("adev_open_output_stream() handle:0x%X, devicesSpec:0x%X, flags:0x%X, addr:%s",
537 handle, devicesSpec, flags, address);
Paul McLeaneedc92e2013-12-19 15:46:15 -0800538
Simon Wilson19957a32012-04-06 16:17:12 -0700539 struct stream_out *out;
Simon Wilson19957a32012-04-06 16:17:12 -0700540
541 out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
Paul McLean76dba682016-06-01 12:29:11 -0600542 if (out == NULL) {
Simon Wilson19957a32012-04-06 16:17:12 -0700543 return -ENOMEM;
Paul McLean76dba682016-06-01 12:29:11 -0600544 }
Simon Wilson19957a32012-04-06 16:17:12 -0700545
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700546 /* setup function pointers */
Simon Wilson19957a32012-04-06 16:17:12 -0700547 out->stream.common.get_sample_rate = out_get_sample_rate;
548 out->stream.common.set_sample_rate = out_set_sample_rate;
549 out->stream.common.get_buffer_size = out_get_buffer_size;
550 out->stream.common.get_channels = out_get_channels;
551 out->stream.common.get_format = out_get_format;
552 out->stream.common.set_format = out_set_format;
553 out->stream.common.standby = out_standby;
554 out->stream.common.dump = out_dump;
555 out->stream.common.set_parameters = out_set_parameters;
556 out->stream.common.get_parameters = out_get_parameters;
557 out->stream.common.add_audio_effect = out_add_audio_effect;
558 out->stream.common.remove_audio_effect = out_remove_audio_effect;
559 out->stream.get_latency = out_get_latency;
560 out->stream.set_volume = out_set_volume;
561 out->stream.write = out_write;
562 out->stream.get_render_position = out_get_render_position;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700563 out->stream.get_presentation_position = out_get_presentation_position;
Simon Wilson19957a32012-04-06 16:17:12 -0700564 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
565
Paul McLean994ac072016-06-02 15:33:24 -0600566 stream_lock_init(&out->lock);
Eric Laurent70318092015-06-19 17:49:17 -0700567
Paul McLean76dba682016-06-01 12:29:11 -0600568 out->adev = (struct audio_device *)hw_dev;
Paul McLean994ac072016-06-02 15:33:24 -0600569 device_lock(out->adev);
Paul McLean76dba682016-06-01 12:29:11 -0600570 out->profile = &out->adev->out_profile;
Paul McLeanf62d75e2014-07-11 15:14:19 -0700571
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700572 // build this to hand to the alsa_device_proxy
573 struct pcm_config proxy_config;
Paul McLean2c6196f2014-08-20 16:50:25 -0700574 memset(&proxy_config, 0, sizeof(proxy_config));
Paul McLeaneedc92e2013-12-19 15:46:15 -0800575
Paul McLean0f1753e2014-12-02 12:36:45 -0700576 /* Pull out the card/device pair */
577 parse_card_device_params(address, &(out->profile->card), &(out->profile->device));
578
579 profile_read_device_info(out->profile);
580
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700581 int ret = 0;
Paul McLeaneedc92e2013-12-19 15:46:15 -0800582
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700583 /* Rate */
584 if (config->sample_rate == 0) {
585 proxy_config.rate = config->sample_rate = profile_get_default_sample_rate(out->profile);
586 } else if (profile_is_sample_rate_valid(out->profile, config->sample_rate)) {
587 proxy_config.rate = config->sample_rate;
Paul McLeaneedc92e2013-12-19 15:46:15 -0800588 } else {
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700589 proxy_config.rate = config->sample_rate = profile_get_default_sample_rate(out->profile);
590 ret = -EINVAL;
Paul McLeaneedc92e2013-12-19 15:46:15 -0800591 }
Paul McLeaneedc92e2013-12-19 15:46:15 -0800592
Paul McLean76dba682016-06-01 12:29:11 -0600593 out->adev->device_sample_rate = config->sample_rate;
Paul McLean994ac072016-06-02 15:33:24 -0600594 device_unlock(out->adev);
Paul McLean1d585cc2016-05-24 11:28:10 -0600595
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700596 /* Format */
597 if (config->format == AUDIO_FORMAT_DEFAULT) {
598 proxy_config.format = profile_get_default_format(out->profile);
599 config->format = audio_format_from_pcm_format(proxy_config.format);
600 } else {
601 enum pcm_format fmt = pcm_format_from_audio_format(config->format);
602 if (profile_is_format_valid(out->profile, fmt)) {
603 proxy_config.format = fmt;
604 } else {
605 proxy_config.format = profile_get_default_format(out->profile);
606 config->format = audio_format_from_pcm_format(proxy_config.format);
607 ret = -EINVAL;
608 }
609 }
610
611 /* Channels */
Paul McLean64345f82016-06-06 13:26:05 -0600612 bool calc_mask = false;
613 if (config->channel_mask == AUDIO_CHANNEL_NONE) {
614 /* query case */
615 out->hal_channel_count = profile_get_default_channel_count(out->profile);
616 calc_mask = true;
Andy Hung182ddc72015-05-05 23:37:30 -0700617 } else {
Paul McLean64345f82016-06-06 13:26:05 -0600618 /* explicit case */
619 out->hal_channel_count = audio_channel_count_from_out_mask(config->channel_mask);
Andy Hung182ddc72015-05-05 23:37:30 -0700620 }
Paul McLean698dbd72015-11-03 12:24:30 -0800621
Paul McLean64345f82016-06-06 13:26:05 -0600622 /* The Framework is currently limited to no more than this number of channels */
623 if (out->hal_channel_count > FCC_8) {
624 out->hal_channel_count = FCC_8;
625 calc_mask = true;
626 }
627
628 if (calc_mask) {
629 /* need to calculate the mask from channel count either because this is the query case
630 * or the specified mask isn't valid for this device, or is more then the FW can handle */
631 config->channel_mask = out->hal_channel_count <= FCC_2
632 /* position mask for mono and stereo*/
633 ? audio_channel_out_mask_from_count(out->hal_channel_count)
634 /* otherwise indexed */
635 : audio_channel_mask_for_index_assignment_from_count(out->hal_channel_count);
636 }
637
Andy Hung182ddc72015-05-05 23:37:30 -0700638 out->hal_channel_mask = config->channel_mask;
639
Paul McLean64345f82016-06-06 13:26:05 -0600640 // Validate the "logical" channel count against support in the "actual" profile.
641 // if they differ, choose the "actual" number of channels *closest* to the "logical".
642 // and store THAT in proxy_config.channels
643 proxy_config.channels = profile_get_closest_channel_count(out->profile, out->hal_channel_count);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700644 proxy_prepare(&out->proxy, out->profile, &proxy_config);
645
646 /* TODO The retry mechanism isn't implemented in AudioPolicyManager/AudioFlinger. */
647 ret = 0;
648
Paul McLeaneedc92e2013-12-19 15:46:15 -0800649 out->conversion_buffer = NULL;
650 out->conversion_buffer_size = 0;
Simon Wilson19957a32012-04-06 16:17:12 -0700651
652 out->standby = true;
653
Paul McLean6a75e4e2016-05-25 14:09:02 -0600654 /* Save the stream for adev_dump() */
Paul McLean76dba682016-06-01 12:29:11 -0600655 adev_add_stream_to_list(out->adev, &out->adev->output_stream_list, &out->list_node);
Paul McLean6a75e4e2016-05-25 14:09:02 -0600656
Simon Wilson19957a32012-04-06 16:17:12 -0700657 *stream_out = &out->stream;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700658
659 return ret;
Simon Wilson19957a32012-04-06 16:17:12 -0700660
661err_open:
662 free(out);
663 *stream_out = NULL;
Paul McLeaneedc92e2013-12-19 15:46:15 -0800664 return -ENOSYS;
Simon Wilson19957a32012-04-06 16:17:12 -0700665}
666
Paul McLean76dba682016-06-01 12:29:11 -0600667static void adev_close_output_stream(struct audio_hw_device *hw_dev,
Simon Wilson19957a32012-04-06 16:17:12 -0700668 struct audio_stream_out *stream)
669{
670 struct stream_out *out = (struct stream_out *)stream;
Paul McLean65ec72b2015-02-18 09:13:24 -0800671 ALOGV("adev_close_output_stream(c:%d d:%d)", out->profile->card, out->profile->device);
Simon Wilson19957a32012-04-06 16:17:12 -0700672
Paul McLean76dba682016-06-01 12:29:11 -0600673 adev_remove_stream_from_list(out->adev, &out->list_node);
Paul McLean6a75e4e2016-05-25 14:09:02 -0600674
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700675 /* Close the pcm device */
Simon Wilson19957a32012-04-06 16:17:12 -0700676 out_standby(&stream->common);
Paul McLeaneedc92e2013-12-19 15:46:15 -0800677
678 free(out->conversion_buffer);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700679
Paul McLeaneedc92e2013-12-19 15:46:15 -0800680 out->conversion_buffer = NULL;
681 out->conversion_buffer_size = 0;
682
Paul McLean994ac072016-06-02 15:33:24 -0600683 device_lock(out->adev);
Paul McLean76dba682016-06-01 12:29:11 -0600684 out->adev->device_sample_rate = 0;
Paul McLean994ac072016-06-02 15:33:24 -0600685 device_unlock(out->adev);
Paul McLean1d585cc2016-05-24 11:28:10 -0600686
Simon Wilson19957a32012-04-06 16:17:12 -0700687 free(stream);
688}
689
Paul McLean76dba682016-06-01 12:29:11 -0600690static size_t adev_get_input_buffer_size(const struct audio_hw_device *hw_dev,
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700691 const struct audio_config *config)
692{
693 /* TODO This needs to be calculated based on format/channels/rate */
694 return 320;
695}
696
697/*
698 * IN functions
699 */
700static uint32_t in_get_sample_rate(const struct audio_stream *stream)
701{
702 uint32_t rate = proxy_get_sample_rate(&((const struct stream_in *)stream)->proxy);
703 ALOGV("in_get_sample_rate() = %d", rate);
704 return rate;
705}
706
707static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
708{
709 ALOGV("in_set_sample_rate(%d) - NOPE", rate);
710 return -ENOSYS;
711}
712
713static size_t in_get_buffer_size(const struct audio_stream *stream)
714{
715 const struct stream_in * in = ((const struct stream_in*)stream);
Paul McLean2cfd81b2014-09-15 12:32:23 -0700716 return proxy_get_period_size(&in->proxy) * audio_stream_in_frame_size(&(in->stream));
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700717}
718
719static uint32_t in_get_channels(const struct audio_stream *stream)
720{
Paul McLean2cfd81b2014-09-15 12:32:23 -0700721 const struct stream_in *in = (const struct stream_in*)stream;
Andy Hung780f1f82015-04-22 22:14:39 -0700722 return in->hal_channel_mask;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700723}
724
725static audio_format_t in_get_format(const struct audio_stream *stream)
726{
Andy Hung780f1f82015-04-22 22:14:39 -0700727 alsa_device_proxy *proxy = &((struct stream_in*)stream)->proxy;
728 audio_format_t format = audio_format_from_pcm_format(proxy_get_format(proxy));
729 return format;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700730}
731
732static int in_set_format(struct audio_stream *stream, audio_format_t format)
733{
734 ALOGV("in_set_format(%d) - NOPE", format);
735
736 return -ENOSYS;
737}
738
739static int in_standby(struct audio_stream *stream)
740{
741 struct stream_in *in = (struct stream_in *)stream;
742
Paul McLean994ac072016-06-02 15:33:24 -0600743 stream_lock(&in->lock);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700744 if (!in->standby) {
Paul McLean994ac072016-06-02 15:33:24 -0600745 device_lock(in->adev);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700746 proxy_close(&in->proxy);
Paul McLean994ac072016-06-02 15:33:24 -0600747 device_unlock(in->adev);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700748 in->standby = true;
749 }
750
Paul McLean994ac072016-06-02 15:33:24 -0600751 stream_unlock(&in->lock);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700752
753 return 0;
754}
755
756static int in_dump(const struct audio_stream *stream, int fd)
757{
Paul McLean6a75e4e2016-05-25 14:09:02 -0600758 const struct stream_in* in_stream = (const struct stream_in*)stream;
759 if (in_stream != NULL) {
760 dprintf(fd, "Input Profile:\n");
761 profile_dump(in_stream->profile, fd);
762
763 dprintf(fd, "Input Proxy:\n");
764 proxy_dump(&in_stream->proxy, fd);
765 }
766
767 return 0;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700768}
769
770static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
771{
Paul McLean65ec72b2015-02-18 09:13:24 -0800772 ALOGV("in_set_parameters() keys:%s", kvpairs);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700773
774 struct stream_in *in = (struct stream_in *)stream;
775
776 char value[32];
777 int param_val;
778 int routing = 0;
779 int ret_value = 0;
Eric Laurent05333d42014-08-04 20:29:17 -0700780 int card = -1;
781 int device = -1;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700782
Paul McLean65ec72b2015-02-18 09:13:24 -0800783 if (!parse_card_device_params(kvpairs, &card, &device)) {
784 // nothing to do
785 return ret_value;
786 }
787
Paul McLean994ac072016-06-02 15:33:24 -0600788 stream_lock(&in->lock);
789 device_lock(in->adev);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700790
Paul McLean2c6196f2014-08-20 16:50:25 -0700791 if (card >= 0 && device >= 0 && !profile_is_cached_for(in->profile, card, device)) {
Andy Hungb10ce6d2017-10-27 19:37:58 -0700792 /* cannot read pcm device info if playback is active, or more than one open stream */
793 if (!in->standby || in->adev->inputs_open > 1)
Eric Laurent05333d42014-08-04 20:29:17 -0700794 ret_value = -ENOSYS;
795 else {
796 int saved_card = in->profile->card;
797 int saved_device = in->profile->device;
798 in->profile->card = card;
799 in->profile->device = device;
800 ret_value = profile_read_device_info(in->profile) ? 0 : -EINVAL;
801 if (ret_value != 0) {
802 in->profile->card = saved_card;
803 in->profile->device = saved_device;
804 }
805 }
Paul McLean2c6196f2014-08-20 16:50:25 -0700806 }
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700807
Paul McLean994ac072016-06-02 15:33:24 -0600808 device_unlock(in->adev);
809 stream_unlock(&in->lock);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700810
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700811 return ret_value;
812}
813
814static char * in_get_parameters(const struct audio_stream *stream, const char *keys)
815{
816 struct stream_in *in = (struct stream_in *)stream;
817
Paul McLean994ac072016-06-02 15:33:24 -0600818 stream_lock(&in->lock);
819 device_lock(in->adev);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700820
821 char * params_str = device_get_parameters(in->profile, keys);
822
Paul McLean994ac072016-06-02 15:33:24 -0600823 device_unlock(in->adev);
824 stream_unlock(&in->lock);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700825
826 return params_str;
827}
828
829static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
830{
831 return 0;
832}
833
834static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
835{
836 return 0;
837}
838
839static int in_set_gain(struct audio_stream_in *stream, float gain)
840{
841 return 0;
842}
843
844/* must be called with hw device and output stream mutexes locked */
845static int start_input_stream(struct stream_in *in)
846{
Paul McLean1d585cc2016-05-24 11:28:10 -0600847 ALOGV("start_input_stream(card:%d device:%d)", in->profile->card, in->profile->device);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700848
849 return proxy_open(&in->proxy);
850}
851
852/* TODO mutex stuff here (see out_write) */
853static ssize_t in_read(struct audio_stream_in *stream, void* buffer, size_t bytes)
854{
855 size_t num_read_buff_bytes = 0;
856 void * read_buff = buffer;
857 void * out_buff = buffer;
Pavan Chikkala83b47a62015-01-09 12:21:13 -0800858 int ret = 0;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700859
860 struct stream_in * in = (struct stream_in *)stream;
861
Paul McLean994ac072016-06-02 15:33:24 -0600862 stream_lock(&in->lock);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700863 if (in->standby) {
Paul McLean994ac072016-06-02 15:33:24 -0600864 device_lock(in->adev);
Eric Laurent70318092015-06-19 17:49:17 -0700865 ret = start_input_stream(in);
Paul McLean994ac072016-06-02 15:33:24 -0600866 device_unlock(in->adev);
Eric Laurent70318092015-06-19 17:49:17 -0700867 if (ret != 0) {
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700868 goto err;
869 }
870 in->standby = false;
871 }
872
873 alsa_device_profile * profile = in->profile;
874
875 /*
876 * OK, we need to figure out how much data to read to be able to output the requested
877 * number of bytes in the HAL format (16-bit, stereo).
878 */
879 num_read_buff_bytes = bytes;
Andy Hung780f1f82015-04-22 22:14:39 -0700880 int num_device_channels = proxy_get_channel_count(&in->proxy); /* what we told Alsa */
881 int num_req_channels = in->hal_channel_count; /* what we told AudioFlinger */
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700882
883 if (num_device_channels != num_req_channels) {
884 num_read_buff_bytes = (num_device_channels * num_read_buff_bytes) / num_req_channels;
885 }
886
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700887 /* Setup/Realloc the conversion buffer (if necessary). */
888 if (num_read_buff_bytes != bytes) {
889 if (num_read_buff_bytes > in->conversion_buffer_size) {
890 /*TODO Remove this when AudioPolicyManger/AudioFlinger support arbitrary formats
891 (and do these conversions themselves) */
892 in->conversion_buffer_size = num_read_buff_bytes;
893 in->conversion_buffer = realloc(in->conversion_buffer, in->conversion_buffer_size);
894 }
895 read_buff = in->conversion_buffer;
896 }
897
Pavan Chikkala83b47a62015-01-09 12:21:13 -0800898 ret = proxy_read(&in->proxy, read_buff, num_read_buff_bytes);
899 if (ret == 0) {
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700900 if (num_device_channels != num_req_channels) {
901 // ALOGV("chans dev:%d req:%d", num_device_channels, num_req_channels);
902
903 out_buff = buffer;
904 /* Num Channels conversion */
905 if (num_device_channels != num_req_channels) {
906 audio_format_t audio_format = in_get_format(&(in->stream.common));
907 unsigned sample_size_in_bytes = audio_bytes_per_sample(audio_format);
908
909 num_read_buff_bytes =
910 adjust_channels(read_buff, num_device_channels,
911 out_buff, num_req_channels,
912 sample_size_in_bytes, num_read_buff_bytes);
913 }
914 }
Eric Laurent253def92014-09-14 12:18:18 -0700915
Paul McLean76dba682016-06-01 12:29:11 -0600916 /* no need to acquire in->adev->lock to read mic_muted here as we don't change its state */
917 if (num_read_buff_bytes > 0 && in->adev->mic_muted)
Eric Laurent253def92014-09-14 12:18:18 -0700918 memset(buffer, 0, num_read_buff_bytes);
Viswanath L8c7e1112014-10-31 13:07:39 +0530919 } else {
Eric Laurente6499422015-01-09 17:03:27 -0800920 num_read_buff_bytes = 0; // reset the value after USB headset is unplugged
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700921 }
922
923err:
Paul McLean994ac072016-06-02 15:33:24 -0600924 stream_unlock(&in->lock);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700925 return num_read_buff_bytes;
926}
927
928static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
929{
930 return 0;
931}
932
Paul McLean76dba682016-06-01 12:29:11 -0600933static int adev_open_input_stream(struct audio_hw_device *hw_dev,
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700934 audio_io_handle_t handle,
Paul McLean76dba682016-06-01 12:29:11 -0600935 audio_devices_t devicesSpec __unused,
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700936 struct audio_config *config,
937 struct audio_stream_in **stream_in,
Eric Laurentf5e24692014-07-27 16:14:57 -0700938 audio_input_flags_t flags __unused,
Eric Laurent981f7742017-05-03 12:44:26 -0700939 const char *address,
Eric Laurentf5e24692014-07-27 16:14:57 -0700940 audio_source_t source __unused)
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700941{
Paul McLean1d585cc2016-05-24 11:28:10 -0600942 ALOGV("adev_open_input_stream() rate:%" PRIu32 ", chanMask:0x%" PRIX32 ", fmt:%" PRIu8,
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700943 config->sample_rate, config->channel_mask, config->format);
944
Andy Hungb10ce6d2017-10-27 19:37:58 -0700945 /* Pull out the card/device pair */
946 int32_t card, device;
947 if (!parse_card_device_params(address, &card, &device)) {
948 ALOGW("%s fail - invalid address %s", __func__, address);
949 *stream_in = NULL;
950 return -EINVAL;
951 }
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700952
Andy Hungb10ce6d2017-10-27 19:37:58 -0700953 struct stream_in * const in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
Paul McLean76dba682016-06-01 12:29:11 -0600954 if (in == NULL) {
Andy Hungb10ce6d2017-10-27 19:37:58 -0700955 *stream_in = NULL;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700956 return -ENOMEM;
Paul McLean76dba682016-06-01 12:29:11 -0600957 }
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700958
959 /* setup function pointers */
960 in->stream.common.get_sample_rate = in_get_sample_rate;
961 in->stream.common.set_sample_rate = in_set_sample_rate;
962 in->stream.common.get_buffer_size = in_get_buffer_size;
963 in->stream.common.get_channels = in_get_channels;
964 in->stream.common.get_format = in_get_format;
965 in->stream.common.set_format = in_set_format;
966 in->stream.common.standby = in_standby;
967 in->stream.common.dump = in_dump;
968 in->stream.common.set_parameters = in_set_parameters;
969 in->stream.common.get_parameters = in_get_parameters;
970 in->stream.common.add_audio_effect = in_add_audio_effect;
971 in->stream.common.remove_audio_effect = in_remove_audio_effect;
972
973 in->stream.set_gain = in_set_gain;
974 in->stream.read = in_read;
975 in->stream.get_input_frames_lost = in_get_input_frames_lost;
976
Paul McLean994ac072016-06-02 15:33:24 -0600977 stream_lock_init(&in->lock);
Eric Laurent70318092015-06-19 17:49:17 -0700978
Paul McLean76dba682016-06-01 12:29:11 -0600979 in->adev = (struct audio_device *)hw_dev;
Paul McLean994ac072016-06-02 15:33:24 -0600980 device_lock(in->adev);
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700981
Paul McLean76dba682016-06-01 12:29:11 -0600982 in->profile = &in->adev->in_profile;
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700983
984 struct pcm_config proxy_config;
Paul McLean2c6196f2014-08-20 16:50:25 -0700985 memset(&proxy_config, 0, sizeof(proxy_config));
Paul McLeanc88e6ae2014-07-16 09:48:34 -0700986
Andy Hungb10ce6d2017-10-27 19:37:58 -0700987 int ret = 0;
988 /* Check if an input stream is already open */
989 if (in->adev->inputs_open > 0) {
990 if (!profile_is_cached_for(in->profile, card, device)) {
991 ALOGW("%s fail - address card:%d device:%d doesn't match existing profile",
992 __func__, card, device);
993 ret = -EINVAL;
994 }
995 } else {
996 /* Read input profile only if necessary */
997 in->profile->card = card;
998 in->profile->device = device;
999 if (!profile_read_device_info(in->profile)) {
1000 ALOGW("%s fail - cannot read profile", __func__);
1001 ret = -EINVAL;
1002 }
1003 }
1004 if (ret != 0) {
1005 device_unlock(in->adev);
1006 free(in);
1007 *stream_in = NULL;
1008 return ret;
1009 }
Paul McLean0f1753e2014-12-02 12:36:45 -07001010
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001011 /* Rate */
1012 if (config->sample_rate == 0) {
Paul McLean9a1c3052016-05-25 13:30:54 -06001013 config->sample_rate = profile_get_default_sample_rate(in->profile);
1014 }
1015
Paul McLean76dba682016-06-01 12:29:11 -06001016 if (in->adev->device_sample_rate != 0 && /* we are playing, so lock the rate */
1017 in->adev->device_sample_rate >= RATELOCK_THRESHOLD) {/* but only for high sample rates */
1018 ret = config->sample_rate != in->adev->device_sample_rate ? -EINVAL : 0;
1019 proxy_config.rate = config->sample_rate = in->adev->device_sample_rate;
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001020 } else if (profile_is_sample_rate_valid(in->profile, config->sample_rate)) {
Eric Laurent981f7742017-05-03 12:44:26 -07001021 proxy_config.rate = config->sample_rate;
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001022 } else {
1023 proxy_config.rate = config->sample_rate = profile_get_default_sample_rate(in->profile);
1024 ret = -EINVAL;
1025 }
Paul McLean994ac072016-06-02 15:33:24 -06001026 device_unlock(in->adev);
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001027
1028 /* Format */
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001029 if (config->format == AUDIO_FORMAT_DEFAULT) {
Andy Hung780f1f82015-04-22 22:14:39 -07001030 proxy_config.format = profile_get_default_format(in->profile);
1031 config->format = audio_format_from_pcm_format(proxy_config.format);
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001032 } else {
Andy Hung780f1f82015-04-22 22:14:39 -07001033 enum pcm_format fmt = pcm_format_from_audio_format(config->format);
1034 if (profile_is_format_valid(in->profile, fmt)) {
1035 proxy_config.format = fmt;
1036 } else {
1037 proxy_config.format = profile_get_default_format(in->profile);
1038 config->format = audio_format_from_pcm_format(proxy_config.format);
1039 ret = -EINVAL;
1040 }
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001041 }
1042
Paul McLean2cfd81b2014-09-15 12:32:23 -07001043 /* Channels */
Paul McLean64345f82016-06-06 13:26:05 -06001044 bool calc_mask = false;
1045 if (config->channel_mask == AUDIO_CHANNEL_NONE) {
1046 /* query case */
1047 in->hal_channel_count = profile_get_default_channel_count(in->profile);
1048 calc_mask = true;
Andy Hung780f1f82015-04-22 22:14:39 -07001049 } else {
Paul McLean64345f82016-06-06 13:26:05 -06001050 /* explicit case */
Andy Hung780f1f82015-04-22 22:14:39 -07001051 in->hal_channel_count = audio_channel_count_from_in_mask(config->channel_mask);
1052 }
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001053
Paul McLean64345f82016-06-06 13:26:05 -06001054 /* The Framework is currently limited to no more than this number of channels */
1055 if (in->hal_channel_count > FCC_8) {
1056 in->hal_channel_count = FCC_8;
1057 calc_mask = true;
1058 }
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001059
Paul McLean64345f82016-06-06 13:26:05 -06001060 if (calc_mask) {
1061 /* need to calculate the mask from channel count either because this is the query case
1062 * or the specified mask isn't valid for this device, or is more then the FW can handle */
1063 in->hal_channel_mask = in->hal_channel_count <= FCC_2
1064 /* position mask for mono & stereo */
1065 ? audio_channel_in_mask_from_count(in->hal_channel_count)
1066 /* otherwise indexed */
1067 : audio_channel_mask_for_index_assignment_from_count(in->hal_channel_count);
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001068
Paul McLean64345f82016-06-06 13:26:05 -06001069 // if we change the mask...
1070 if (in->hal_channel_mask != config->channel_mask &&
1071 config->channel_mask != AUDIO_CHANNEL_NONE) {
1072 config->channel_mask = in->hal_channel_mask;
1073 ret = -EINVAL;
1074 }
1075 } else {
1076 in->hal_channel_mask = config->channel_mask;
1077 }
Paul McLean6a75e4e2016-05-25 14:09:02 -06001078
Paul McLean64345f82016-06-06 13:26:05 -06001079 if (ret == 0) {
1080 // Validate the "logical" channel count against support in the "actual" profile.
1081 // if they differ, choose the "actual" number of channels *closest* to the "logical".
1082 // and store THAT in proxy_config.channels
1083 proxy_config.channels =
1084 profile_get_closest_channel_count(in->profile, in->hal_channel_count);
Eric Laurent981f7742017-05-03 12:44:26 -07001085 ret = proxy_prepare(&in->proxy, in->profile, &proxy_config);
1086 if (ret == 0) {
1087 in->standby = true;
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001088
Eric Laurent981f7742017-05-03 12:44:26 -07001089 in->conversion_buffer = NULL;
1090 in->conversion_buffer_size = 0;
Paul McLean64345f82016-06-06 13:26:05 -06001091
Eric Laurent981f7742017-05-03 12:44:26 -07001092 *stream_in = &in->stream;
Paul McLean64345f82016-06-06 13:26:05 -06001093
Eric Laurent981f7742017-05-03 12:44:26 -07001094 /* Save this for adev_dump() */
1095 adev_add_stream_to_list(in->adev, &in->adev->input_stream_list, &in->list_node);
1096 } else {
1097 ALOGW("proxy_prepare error %d", ret);
1098 unsigned channel_count = proxy_get_channel_count(&in->proxy);
1099 config->channel_mask = channel_count <= FCC_2
1100 ? audio_channel_in_mask_from_count(channel_count)
1101 : audio_channel_mask_for_index_assignment_from_count(channel_count);
1102 config->format = audio_format_from_pcm_format(proxy_get_format(&in->proxy));
1103 config->sample_rate = proxy_get_sample_rate(&in->proxy);
1104 }
1105 }
Paul McLean64345f82016-06-06 13:26:05 -06001106
Eric Laurent981f7742017-05-03 12:44:26 -07001107 if (ret != 0) {
Paul McLean64345f82016-06-06 13:26:05 -06001108 // Deallocate this stream on error, because AudioFlinger won't call
1109 // adev_close_input_stream() in this case.
1110 *stream_in = NULL;
1111 free(in);
1112 }
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001113
Andy Hungb10ce6d2017-10-27 19:37:58 -07001114 device_lock(in->adev);
1115 ++in->adev->inputs_open;
1116 device_unlock(in->adev);
1117
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001118 return ret;
1119}
1120
Paul McLean76dba682016-06-01 12:29:11 -06001121static void adev_close_input_stream(struct audio_hw_device *hw_dev,
1122 struct audio_stream_in *stream)
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001123{
1124 struct stream_in *in = (struct stream_in *)stream;
Paul McLean6a75e4e2016-05-25 14:09:02 -06001125 ALOGV("adev_close_input_stream(c:%d d:%d)", in->profile->card, in->profile->device);
1126
Paul McLean76dba682016-06-01 12:29:11 -06001127 adev_remove_stream_from_list(in->adev, &in->list_node);
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001128
Andy Hungb10ce6d2017-10-27 19:37:58 -07001129 device_lock(in->adev);
1130 --in->adev->inputs_open;
1131 LOG_ALWAYS_FATAL_IF(in->adev->inputs_open < 0,
1132 "invalid inputs_open: %d", in->adev->inputs_open);
1133 device_unlock(in->adev);
1134
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001135 /* Close the pcm device */
1136 in_standby(&stream->common);
1137
1138 free(in->conversion_buffer);
1139
1140 free(stream);
1141}
1142
1143/*
1144 * ADEV Functions
1145 */
Paul McLean76dba682016-06-01 12:29:11 -06001146static int adev_set_parameters(struct audio_hw_device *hw_dev, const char *kvpairs)
Simon Wilson19957a32012-04-06 16:17:12 -07001147{
1148 return 0;
1149}
1150
Paul McLean76dba682016-06-01 12:29:11 -06001151static char * adev_get_parameters(const struct audio_hw_device *hw_dev, const char *keys)
Simon Wilson19957a32012-04-06 16:17:12 -07001152{
1153 return strdup("");
1154}
1155
Paul McLean76dba682016-06-01 12:29:11 -06001156static int adev_init_check(const struct audio_hw_device *hw_dev)
Simon Wilson19957a32012-04-06 16:17:12 -07001157{
1158 return 0;
1159}
1160
Paul McLean76dba682016-06-01 12:29:11 -06001161static int adev_set_voice_volume(struct audio_hw_device *hw_dev, float volume)
Simon Wilson19957a32012-04-06 16:17:12 -07001162{
1163 return -ENOSYS;
1164}
1165
Paul McLean76dba682016-06-01 12:29:11 -06001166static int adev_set_master_volume(struct audio_hw_device *hw_dev, float volume)
Simon Wilson19957a32012-04-06 16:17:12 -07001167{
1168 return -ENOSYS;
1169}
1170
Paul McLean76dba682016-06-01 12:29:11 -06001171static int adev_set_mode(struct audio_hw_device *hw_dev, audio_mode_t mode)
Simon Wilson19957a32012-04-06 16:17:12 -07001172{
1173 return 0;
1174}
1175
Paul McLean76dba682016-06-01 12:29:11 -06001176static int adev_set_mic_mute(struct audio_hw_device *hw_dev, bool state)
Simon Wilson19957a32012-04-06 16:17:12 -07001177{
Paul McLean76dba682016-06-01 12:29:11 -06001178 struct audio_device * adev = (struct audio_device *)hw_dev;
Paul McLean994ac072016-06-02 15:33:24 -06001179 device_lock(adev);
Eric Laurent253def92014-09-14 12:18:18 -07001180 adev->mic_muted = state;
Paul McLean994ac072016-06-02 15:33:24 -06001181 device_unlock(adev);
Simon Wilson19957a32012-04-06 16:17:12 -07001182 return -ENOSYS;
1183}
1184
Paul McLean76dba682016-06-01 12:29:11 -06001185static int adev_get_mic_mute(const struct audio_hw_device *hw_dev, bool *state)
Simon Wilson19957a32012-04-06 16:17:12 -07001186{
1187 return -ENOSYS;
1188}
1189
Paul McLean76dba682016-06-01 12:29:11 -06001190static int adev_dump(const struct audio_hw_device *device, int fd)
Simon Wilson19957a32012-04-06 16:17:12 -07001191{
Paul McLean6a75e4e2016-05-25 14:09:02 -06001192 dprintf(fd, "\nUSB audio module:\n");
1193
1194 struct audio_device* adev = (struct audio_device*)device;
1195 const int kNumRetries = 3;
1196 const int kSleepTimeMS = 500;
1197
Paul McLean994ac072016-06-02 15:33:24 -06001198 // use device_try_lock() in case we dumpsys during a deadlock
Paul McLean6a75e4e2016-05-25 14:09:02 -06001199 int retry = kNumRetries;
Paul McLean994ac072016-06-02 15:33:24 -06001200 while (retry > 0 && device_try_lock(adev) != 0) {
Paul McLean6a75e4e2016-05-25 14:09:02 -06001201 sleep(kSleepTimeMS);
1202 retry--;
1203 }
1204
1205 if (retry > 0) {
1206 if (list_empty(&adev->output_stream_list)) {
1207 dprintf(fd, " No output streams.\n");
1208 } else {
1209 struct listnode* node;
1210 list_for_each(node, &adev->output_stream_list) {
1211 struct audio_stream* stream =
1212 (struct audio_stream *)node_to_item(node, struct stream_out, list_node);
1213 out_dump(stream, fd);
1214 }
1215 }
1216
1217 if (list_empty(&adev->input_stream_list)) {
1218 dprintf(fd, "\n No input streams.\n");
1219 } else {
1220 struct listnode* node;
1221 list_for_each(node, &adev->input_stream_list) {
1222 struct audio_stream* stream =
1223 (struct audio_stream *)node_to_item(node, struct stream_in, list_node);
1224 in_dump(stream, fd);
1225 }
1226 }
1227
Paul McLean994ac072016-06-02 15:33:24 -06001228 device_unlock(adev);
Paul McLean6a75e4e2016-05-25 14:09:02 -06001229 } else {
1230 // Couldn't lock
1231 dprintf(fd, " Could not obtain device lock.\n");
1232 }
1233
Simon Wilson19957a32012-04-06 16:17:12 -07001234 return 0;
1235}
1236
1237static int adev_close(hw_device_t *device)
1238{
Paul McLeaneedc92e2013-12-19 15:46:15 -08001239 struct audio_device *adev = (struct audio_device *)device;
Simon Wilson19957a32012-04-06 16:17:12 -07001240 free(device);
Paul McLeaneedc92e2013-12-19 15:46:15 -08001241
Simon Wilson19957a32012-04-06 16:17:12 -07001242 return 0;
1243}
1244
Paul McLean30f41852014-04-16 15:44:20 -07001245static int adev_open(const hw_module_t* module, const char* name, hw_device_t** device)
Simon Wilson19957a32012-04-06 16:17:12 -07001246{
Simon Wilson19957a32012-04-06 16:17:12 -07001247 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
1248 return -EINVAL;
1249
Paul McLeaneedc92e2013-12-19 15:46:15 -08001250 struct audio_device *adev = calloc(1, sizeof(struct audio_device));
Simon Wilson19957a32012-04-06 16:17:12 -07001251 if (!adev)
1252 return -ENOMEM;
1253
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001254 profile_init(&adev->out_profile, PCM_OUT);
1255 profile_init(&adev->in_profile, PCM_IN);
1256
Paul McLean6a75e4e2016-05-25 14:09:02 -06001257 list_init(&adev->output_stream_list);
1258 list_init(&adev->input_stream_list);
1259
Simon Wilson19957a32012-04-06 16:17:12 -07001260 adev->hw_device.common.tag = HARDWARE_DEVICE_TAG;
Eric Laurent85e08e22012-08-28 14:30:35 -07001261 adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
Paul McLeanc88e6ae2014-07-16 09:48:34 -07001262 adev->hw_device.common.module = (struct hw_module_t *)module;
Simon Wilson19957a32012-04-06 16:17:12 -07001263 adev->hw_device.common.close = adev_close;
1264
Simon Wilson19957a32012-04-06 16:17:12 -07001265 adev->hw_device.init_check = adev_init_check;
1266 adev->hw_device.set_voice_volume = adev_set_voice_volume;
1267 adev->hw_device.set_master_volume = adev_set_master_volume;
1268 adev->hw_device.set_mode = adev_set_mode;
1269 adev->hw_device.set_mic_mute = adev_set_mic_mute;
1270 adev->hw_device.get_mic_mute = adev_get_mic_mute;
1271 adev->hw_device.set_parameters = adev_set_parameters;
1272 adev->hw_device.get_parameters = adev_get_parameters;
1273 adev->hw_device.get_input_buffer_size = adev_get_input_buffer_size;
1274 adev->hw_device.open_output_stream = adev_open_output_stream;
1275 adev->hw_device.close_output_stream = adev_close_output_stream;
1276 adev->hw_device.open_input_stream = adev_open_input_stream;
1277 adev->hw_device.close_input_stream = adev_close_input_stream;
1278 adev->hw_device.dump = adev_dump;
1279
1280 *device = &adev->hw_device.common;
1281
1282 return 0;
1283}
1284
1285static struct hw_module_methods_t hal_module_methods = {
1286 .open = adev_open,
1287};
1288
1289struct audio_module HAL_MODULE_INFO_SYM = {
1290 .common = {
1291 .tag = HARDWARE_MODULE_TAG,
Mike Lockwood46a98092012-04-24 16:41:18 -07001292 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
1293 .hal_api_version = HARDWARE_HAL_API_VERSION,
Simon Wilson19957a32012-04-06 16:17:12 -07001294 .id = AUDIO_HARDWARE_MODULE_ID,
1295 .name = "USB audio HW HAL",
1296 .author = "The Android Open Source Project",
1297 .methods = &hal_module_methods,
1298 },
1299};