blob: 2ad5c88316c13946c0af1e0baf463f977a1d0f62 [file] [log] [blame]
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "audio_hw_primary"
18/*#define LOG_NDEBUG 0*/
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070019/*#define VERY_VERY_VERBOSE_LOGGING*/
20#ifdef VERY_VERY_VERBOSE_LOGGING
21#define ALOGVV ALOGV
22#else
23#define ALOGVV(a...) do { } while(0)
24#endif
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080025
26#include <errno.h>
27#include <pthread.h>
28#include <stdint.h>
29#include <sys/time.h>
30#include <stdlib.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080031#include <math.h>
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070032#include <sys/resource.h>
33#include <sys/prctl.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080034
35#include <cutils/log.h>
36#include <cutils/str_parms.h>
37#include <cutils/properties.h>
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070038#include <cutils/atomic.h>
39#include <cutils/sched_policy.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080040
Eric Laurentb23d5282013-05-14 15:27:20 -070041#include <hardware/audio_effect.h>
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070042#include <system/thread_defs.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070043#include <audio_effects/effect_aec.h>
44#include <audio_effects/effect_ns.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080045#include "audio_hw.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070046#include "platform_api.h"
47#include <platform.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080048
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070049#include "sound/compress_params.h"
50
51#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
52#define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4
53/* ToDo: Check and update a proper value in msec */
54#define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96
55#define COMPRESS_PLAYBACK_VOLUME_MAX 0x2000
56
Eric Laurentb23d5282013-05-14 15:27:20 -070057struct pcm_config pcm_config_deep_buffer = {
58 .channels = 2,
59 .rate = DEFAULT_OUTPUT_SAMPLING_RATE,
60 .period_size = DEEP_BUFFER_OUTPUT_PERIOD_SIZE,
61 .period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT,
62 .format = PCM_FORMAT_S16_LE,
63 .start_threshold = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
64 .stop_threshold = INT_MAX,
65 .avail_min = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
66};
67
68struct pcm_config pcm_config_low_latency = {
69 .channels = 2,
70 .rate = DEFAULT_OUTPUT_SAMPLING_RATE,
71 .period_size = LOW_LATENCY_OUTPUT_PERIOD_SIZE,
72 .period_count = LOW_LATENCY_OUTPUT_PERIOD_COUNT,
73 .format = PCM_FORMAT_S16_LE,
74 .start_threshold = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4,
75 .stop_threshold = INT_MAX,
76 .avail_min = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4,
77};
78
79struct pcm_config pcm_config_hdmi_multi = {
80 .channels = HDMI_MULTI_DEFAULT_CHANNEL_COUNT, /* changed when the stream is opened */
81 .rate = DEFAULT_OUTPUT_SAMPLING_RATE, /* changed when the stream is opened */
82 .period_size = HDMI_MULTI_PERIOD_SIZE,
83 .period_count = HDMI_MULTI_PERIOD_COUNT,
84 .format = PCM_FORMAT_S16_LE,
85 .start_threshold = 0,
86 .stop_threshold = INT_MAX,
87 .avail_min = 0,
88};
89
90struct pcm_config pcm_config_audio_capture = {
91 .channels = 2,
Eric Laurentb23d5282013-05-14 15:27:20 -070092 .period_count = AUDIO_CAPTURE_PERIOD_COUNT,
93 .format = PCM_FORMAT_S16_LE,
94};
95
96struct pcm_config pcm_config_voice_call = {
97 .channels = 1,
98 .rate = 8000,
99 .period_size = 160,
100 .period_count = 2,
101 .format = PCM_FORMAT_S16_LE,
102};
103
104static const char * const use_case_table[AUDIO_USECASE_MAX] = {
105 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback",
106 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
107 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback",
108 [USECASE_AUDIO_RECORD] = "audio-record",
109 [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
110 [USECASE_VOICE_CALL] = "voice-call",
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700111 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = "compress-offload-playback",
Eric Laurentb23d5282013-05-14 15:27:20 -0700112};
113
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800114
115#define STRING_TO_ENUM(string) { #string, string }
116
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800117struct string_to_enum {
118 const char *name;
119 uint32_t value;
120};
121
122static const struct string_to_enum out_channels_name_to_enum_table[] = {
123 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO),
124 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
125 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
126};
127
Haynes Mathew George5191a852013-09-11 14:19:36 -0700128static int set_voice_volume_l(struct audio_device *adev, float volume);
129
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700130static bool is_supported_format(audio_format_t format)
131{
132 if (format == AUDIO_FORMAT_MP3 /*||
133 format == AUDIO_FORMAT_AAC */)
134 return true;
135
136 return false;
137}
138
139static int get_snd_codec_id(audio_format_t format)
140{
141 int id = 0;
142
143 switch (format) {
144 case AUDIO_FORMAT_MP3:
145 id = SND_AUDIOCODEC_MP3;
146 break;
147 case AUDIO_FORMAT_AAC:
148 id = SND_AUDIOCODEC_AAC;
149 break;
150 default:
151 ALOGE("%s: Unsupported audio format", __func__);
152 }
153
154 return id;
155}
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800156
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700157static int enable_audio_route(struct audio_device *adev,
158 struct audio_usecase *usecase,
159 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800160{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700161 snd_device_t snd_device;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800162 char mixer_path[50];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800163
164 if (usecase == NULL)
165 return -EINVAL;
166
167 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
168
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800169 if (usecase->type == PCM_CAPTURE)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700170 snd_device = usecase->in_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800171 else
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700172 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800173
174 strcpy(mixer_path, use_case_table[usecase->id]);
Eric Laurentb23d5282013-05-14 15:27:20 -0700175 platform_add_backend_name(mixer_path, snd_device);
Eric Laurent994a6932013-07-17 11:51:42 -0700176 ALOGV("%s: apply mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700177 audio_route_apply_path(adev->audio_route, mixer_path);
178 if (update_mixer)
179 audio_route_update_mixer(adev->audio_route);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800180
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800181 ALOGV("%s: exit", __func__);
182 return 0;
183}
184
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700185static int disable_audio_route(struct audio_device *adev,
186 struct audio_usecase *usecase,
187 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800188{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700189 snd_device_t snd_device;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800190 char mixer_path[50];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800191
192 if (usecase == NULL)
193 return -EINVAL;
194
195 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700196 if (usecase->type == PCM_CAPTURE)
197 snd_device = usecase->in_snd_device;
198 else
199 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800200 strcpy(mixer_path, use_case_table[usecase->id]);
Eric Laurentb23d5282013-05-14 15:27:20 -0700201 platform_add_backend_name(mixer_path, snd_device);
Eric Laurent994a6932013-07-17 11:51:42 -0700202 ALOGV("%s: reset mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700203 audio_route_reset_path(adev->audio_route, mixer_path);
204 if (update_mixer)
205 audio_route_update_mixer(adev->audio_route);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800206
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800207 ALOGV("%s: exit", __func__);
208 return 0;
209}
210
211static int enable_snd_device(struct audio_device *adev,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700212 snd_device_t snd_device,
213 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800214{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800215 if (snd_device < SND_DEVICE_MIN ||
216 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800217 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800218 return -EINVAL;
219 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700220
221 adev->snd_dev_ref_cnt[snd_device]++;
222 if (adev->snd_dev_ref_cnt[snd_device] > 1) {
Eric Laurent994a6932013-07-17 11:51:42 -0700223 ALOGV("%s: snd_device(%d: %s) is already active",
Eric Laurentb23d5282013-05-14 15:27:20 -0700224 __func__, snd_device, platform_get_snd_device_name(snd_device));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700225 return 0;
226 }
227
Eric Laurentb23d5282013-05-14 15:27:20 -0700228 if (platform_send_audio_calibration(adev->platform, snd_device) < 0) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700229 adev->snd_dev_ref_cnt[snd_device]--;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800230 return -EINVAL;
231 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800232
Eric Laurent994a6932013-07-17 11:51:42 -0700233 ALOGV("%s: snd_device(%d: %s)", __func__,
Eric Laurentb23d5282013-05-14 15:27:20 -0700234 snd_device, platform_get_snd_device_name(snd_device));
235 audio_route_apply_path(adev->audio_route, platform_get_snd_device_name(snd_device));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700236 if (update_mixer)
237 audio_route_update_mixer(adev->audio_route);
238
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800239 return 0;
240}
241
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700242static int disable_snd_device(struct audio_device *adev,
243 snd_device_t snd_device,
244 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800245{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800246 if (snd_device < SND_DEVICE_MIN ||
247 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800248 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800249 return -EINVAL;
250 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700251 if (adev->snd_dev_ref_cnt[snd_device] <= 0) {
252 ALOGE("%s: device ref cnt is already 0", __func__);
253 return -EINVAL;
254 }
255 adev->snd_dev_ref_cnt[snd_device]--;
256 if (adev->snd_dev_ref_cnt[snd_device] == 0) {
Eric Laurent994a6932013-07-17 11:51:42 -0700257 ALOGV("%s: snd_device(%d: %s)", __func__,
Eric Laurentb23d5282013-05-14 15:27:20 -0700258 snd_device, platform_get_snd_device_name(snd_device));
259 audio_route_reset_path(adev->audio_route, platform_get_snd_device_name(snd_device));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700260 if (update_mixer)
261 audio_route_update_mixer(adev->audio_route);
262 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800263 return 0;
264}
265
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700266static void check_usecases_codec_backend(struct audio_device *adev,
267 struct audio_usecase *uc_info,
268 snd_device_t snd_device)
269{
270 struct listnode *node;
271 struct audio_usecase *usecase;
272 bool switch_device[AUDIO_USECASE_MAX];
273 int i, num_uc_to_switch = 0;
274
275 /*
276 * This function is to make sure that all the usecases that are active on
277 * the hardware codec backend are always routed to any one device that is
278 * handled by the hardware codec.
279 * For example, if low-latency and deep-buffer usecases are currently active
280 * on speaker and out_set_parameters(headset) is received on low-latency
281 * output, then we have to make sure deep-buffer is also switched to headset,
282 * because of the limitation that both the devices cannot be enabled
283 * at the same time as they share the same backend.
284 */
285 /* Disable all the usecases on the shared backend other than the
286 specified usecase */
287 for (i = 0; i < AUDIO_USECASE_MAX; i++)
288 switch_device[i] = false;
289
290 list_for_each(node, &adev->usecase_list) {
291 usecase = node_to_item(node, struct audio_usecase, list);
292 if (usecase->type != PCM_CAPTURE &&
293 usecase != uc_info &&
294 usecase->out_snd_device != snd_device &&
295 usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
296 ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
297 __func__, use_case_table[usecase->id],
Eric Laurentb23d5282013-05-14 15:27:20 -0700298 platform_get_snd_device_name(usecase->out_snd_device));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700299 disable_audio_route(adev, usecase, false);
300 switch_device[usecase->id] = true;
301 num_uc_to_switch++;
302 }
303 }
304
305 if (num_uc_to_switch) {
306 /* Make sure all the streams are de-routed before disabling the device */
307 audio_route_update_mixer(adev->audio_route);
308
309 list_for_each(node, &adev->usecase_list) {
310 usecase = node_to_item(node, struct audio_usecase, list);
311 if (switch_device[usecase->id]) {
312 disable_snd_device(adev, usecase->out_snd_device, false);
313 enable_snd_device(adev, snd_device, false);
314 }
315 }
316
317 /* Make sure new snd device is enabled before re-routing the streams */
318 audio_route_update_mixer(adev->audio_route);
319
320 /* Re-route all the usecases on the shared backend other than the
321 specified usecase to new snd devices */
322 list_for_each(node, &adev->usecase_list) {
323 usecase = node_to_item(node, struct audio_usecase, list);
324 /* Update the out_snd_device only before enabling the audio route */
325 if (switch_device[usecase->id] ) {
326 usecase->out_snd_device = snd_device;
327 enable_audio_route(adev, usecase, false);
328 }
329 }
330
331 audio_route_update_mixer(adev->audio_route);
332 }
333}
334
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700335static void check_and_route_capture_usecases(struct audio_device *adev,
336 struct audio_usecase *uc_info,
337 snd_device_t snd_device)
338{
339 struct listnode *node;
340 struct audio_usecase *usecase;
341 bool switch_device[AUDIO_USECASE_MAX];
342 int i, num_uc_to_switch = 0;
343
344 /*
345 * This function is to make sure that all the active capture usecases
346 * are always routed to the same input sound device.
347 * For example, if audio-record and voice-call usecases are currently
348 * active on speaker(rx) and speaker-mic (tx) and out_set_parameters(earpiece)
349 * is received for voice call then we have to make sure that audio-record
350 * usecase is also switched to earpiece i.e. voice-dmic-ef,
351 * because of the limitation that two devices cannot be enabled
352 * at the same time if they share the same backend.
353 */
354 for (i = 0; i < AUDIO_USECASE_MAX; i++)
355 switch_device[i] = false;
356
357 list_for_each(node, &adev->usecase_list) {
358 usecase = node_to_item(node, struct audio_usecase, list);
359 if (usecase->type != PCM_PLAYBACK &&
360 usecase != uc_info &&
361 usecase->in_snd_device != snd_device) {
362 ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
363 __func__, use_case_table[usecase->id],
Devin Kim1e5f3532013-08-09 07:48:29 -0700364 platform_get_snd_device_name(usecase->in_snd_device));
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700365 disable_audio_route(adev, usecase, false);
366 switch_device[usecase->id] = true;
367 num_uc_to_switch++;
368 }
369 }
370
371 if (num_uc_to_switch) {
372 /* Make sure all the streams are de-routed before disabling the device */
373 audio_route_update_mixer(adev->audio_route);
374
375 list_for_each(node, &adev->usecase_list) {
376 usecase = node_to_item(node, struct audio_usecase, list);
377 if (switch_device[usecase->id]) {
378 disable_snd_device(adev, usecase->in_snd_device, false);
379 enable_snd_device(adev, snd_device, false);
380 }
381 }
382
383 /* Make sure new snd device is enabled before re-routing the streams */
384 audio_route_update_mixer(adev->audio_route);
385
386 /* Re-route all the usecases on the shared backend other than the
387 specified usecase to new snd devices */
388 list_for_each(node, &adev->usecase_list) {
389 usecase = node_to_item(node, struct audio_usecase, list);
390 /* Update the in_snd_device only before enabling the audio route */
391 if (switch_device[usecase->id] ) {
392 usecase->in_snd_device = snd_device;
393 enable_audio_route(adev, usecase, false);
394 }
395 }
396
397 audio_route_update_mixer(adev->audio_route);
398 }
399}
400
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800401
402/* must be called with hw device mutex locked */
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700403static int read_hdmi_channel_masks(struct stream_out *out)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800404{
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700405 int ret = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700406 int channels = platform_edid_get_max_channels(out->dev->platform);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800407
408 switch (channels) {
409 /*
410 * Do not handle stereo output in Multi-channel cases
411 * Stereo case is handled in normal playback path
412 */
413 case 6:
414 ALOGV("%s: HDMI supports 5.1", __func__);
415 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
416 break;
417 case 8:
418 ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__);
419 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
420 out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1;
421 break;
422 default:
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700423 ALOGE("HDMI does not support multi channel playback");
424 ret = -ENOSYS;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800425 break;
426 }
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700427 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800428}
429
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700430static struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
431 audio_usecase_t uc_id)
432{
433 struct audio_usecase *usecase;
434 struct listnode *node;
435
436 list_for_each(node, &adev->usecase_list) {
437 usecase = node_to_item(node, struct audio_usecase, list);
438 if (usecase->id == uc_id)
439 return usecase;
440 }
441 return NULL;
442}
443
444static int select_devices(struct audio_device *adev,
445 audio_usecase_t uc_id)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800446{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800447 snd_device_t out_snd_device = SND_DEVICE_NONE;
448 snd_device_t in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700449 struct audio_usecase *usecase = NULL;
450 struct audio_usecase *vc_usecase = NULL;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800451 struct listnode *node;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700452 int status = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800453
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700454 usecase = get_usecase_from_list(adev, uc_id);
455 if (usecase == NULL) {
456 ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id);
457 return -EINVAL;
458 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800459
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700460 if (usecase->type == VOICE_CALL) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700461 out_snd_device = platform_get_output_snd_device(adev->platform,
462 usecase->stream.out->devices);
463 in_snd_device = platform_get_input_snd_device(adev->platform, usecase->stream.out->devices);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700464 usecase->devices = usecase->stream.out->devices;
465 } else {
466 /*
467 * If the voice call is active, use the sound devices of voice call usecase
468 * so that it would not result any device switch. All the usecases will
469 * be switched to new device when select_devices() is called for voice call
470 * usecase. This is to avoid switching devices for voice call when
471 * check_usecases_codec_backend() is called below.
472 */
473 if (adev->in_call) {
474 vc_usecase = get_usecase_from_list(adev, USECASE_VOICE_CALL);
475 if (vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
476 in_snd_device = vc_usecase->in_snd_device;
477 out_snd_device = vc_usecase->out_snd_device;
478 }
479 }
480 if (usecase->type == PCM_PLAYBACK) {
481 usecase->devices = usecase->stream.out->devices;
482 in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700483 if (out_snd_device == SND_DEVICE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700484 out_snd_device = platform_get_output_snd_device(adev->platform,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700485 usecase->stream.out->devices);
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700486 if (usecase->stream.out == adev->primary_output &&
487 adev->active_input &&
488 adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
489 select_devices(adev, adev->active_input->usecase);
490 }
491 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700492 } else if (usecase->type == PCM_CAPTURE) {
493 usecase->devices = usecase->stream.in->device;
494 out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700495 if (in_snd_device == SND_DEVICE_NONE) {
496 if (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION &&
497 adev->primary_output && !adev->primary_output->standby) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700498 in_snd_device = platform_get_input_snd_device(adev->platform,
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700499 adev->primary_output->devices);
500 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -0700501 in_snd_device = platform_get_input_snd_device(adev->platform,
502 AUDIO_DEVICE_NONE);
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700503 }
504 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700505 }
506 }
507
508 if (out_snd_device == usecase->out_snd_device &&
509 in_snd_device == usecase->in_snd_device) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800510 return 0;
511 }
512
sangwoobc677242013-08-08 16:53:43 +0900513 ALOGD("%s: out_snd_device(%d: %s) in_snd_device(%d: %s)", __func__,
Eric Laurentb23d5282013-05-14 15:27:20 -0700514 out_snd_device, platform_get_snd_device_name(out_snd_device),
515 in_snd_device, platform_get_snd_device_name(in_snd_device));
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800516
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800517 /*
518 * Limitation: While in call, to do a device switch we need to disable
519 * and enable both RX and TX devices though one of them is same as current
520 * device.
521 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700522 if (usecase->type == VOICE_CALL) {
523 status = platform_switch_voice_call_device_pre(adev->platform);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800524 }
525
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700526 /* Disable current sound devices */
527 if (usecase->out_snd_device != SND_DEVICE_NONE) {
528 disable_audio_route(adev, usecase, true);
529 disable_snd_device(adev, usecase->out_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800530 }
531
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700532 if (usecase->in_snd_device != SND_DEVICE_NONE) {
533 disable_audio_route(adev, usecase, true);
534 disable_snd_device(adev, usecase->in_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800535 }
536
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700537 /* Enable new sound devices */
538 if (out_snd_device != SND_DEVICE_NONE) {
539 if (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)
540 check_usecases_codec_backend(adev, usecase, out_snd_device);
541 enable_snd_device(adev, out_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800542 }
543
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700544 if (in_snd_device != SND_DEVICE_NONE) {
545 check_and_route_capture_usecases(adev, usecase, in_snd_device);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700546 enable_snd_device(adev, in_snd_device, false);
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700547 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700548
Eric Laurentb23d5282013-05-14 15:27:20 -0700549 if (usecase->type == VOICE_CALL)
550 status = platform_switch_voice_call_device_post(adev->platform,
551 out_snd_device,
552 in_snd_device);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800553
sangwoo170731f2013-06-08 15:36:36 +0900554 audio_route_update_mixer(adev->audio_route);
555
556 usecase->in_snd_device = in_snd_device;
557 usecase->out_snd_device = out_snd_device;
558
559 enable_audio_route(adev, usecase, true);
560
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800561 return status;
562}
563
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800564static int stop_input_stream(struct stream_in *in)
565{
566 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800567 struct audio_usecase *uc_info;
568 struct audio_device *adev = in->dev;
569
Eric Laurentc8400632013-02-14 19:04:54 -0800570 adev->active_input = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800571
Eric Laurent994a6932013-07-17 11:51:42 -0700572 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700573 in->usecase, use_case_table[in->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800574 uc_info = get_usecase_from_list(adev, in->usecase);
575 if (uc_info == NULL) {
576 ALOGE("%s: Could not find the usecase (%d) in the list",
577 __func__, in->usecase);
578 return -EINVAL;
579 }
580
Eric Laurent150dbfe2013-02-27 14:31:02 -0800581 /* 1. Disable stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700582 disable_audio_route(adev, uc_info, true);
583
584 /* 2. Disable the tx device */
585 disable_snd_device(adev, uc_info->in_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800586
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800587 list_remove(&uc_info->list);
588 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800589
Eric Laurent994a6932013-07-17 11:51:42 -0700590 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800591 return ret;
592}
593
594int start_input_stream(struct stream_in *in)
595{
596 /* 1. Enable output device and stream routing controls */
Eric Laurentc8400632013-02-14 19:04:54 -0800597 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800598 struct audio_usecase *uc_info;
599 struct audio_device *adev = in->dev;
600
Eric Laurent994a6932013-07-17 11:51:42 -0700601 ALOGV("%s: enter: usecase(%d)", __func__, in->usecase);
Eric Laurentb23d5282013-05-14 15:27:20 -0700602 in->pcm_device_id = platform_get_pcm_device_id(in->usecase, PCM_CAPTURE);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800603 if (in->pcm_device_id < 0) {
604 ALOGE("%s: Could not find PCM device id for the usecase(%d)",
605 __func__, in->usecase);
Eric Laurentc8400632013-02-14 19:04:54 -0800606 ret = -EINVAL;
607 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800608 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700609
610 adev->active_input = in;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800611 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
612 uc_info->id = in->usecase;
613 uc_info->type = PCM_CAPTURE;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800614 uc_info->stream.in = in;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700615 uc_info->devices = in->device;
616 uc_info->in_snd_device = SND_DEVICE_NONE;
617 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800618
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800619 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700620 select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800621
Eric Laurentc8400632013-02-14 19:04:54 -0800622 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d",
623 __func__, SOUND_CARD, in->pcm_device_id, in->config.channels);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800624 in->pcm = pcm_open(SOUND_CARD, in->pcm_device_id,
625 PCM_IN, &in->config);
626 if (in->pcm && !pcm_is_ready(in->pcm)) {
627 ALOGE("%s: %s", __func__, pcm_get_error(in->pcm));
628 pcm_close(in->pcm);
629 in->pcm = NULL;
Eric Laurentc8400632013-02-14 19:04:54 -0800630 ret = -EIO;
631 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800632 }
Eric Laurent994a6932013-07-17 11:51:42 -0700633 ALOGV("%s: exit", __func__);
Eric Laurentc8400632013-02-14 19:04:54 -0800634 return ret;
635
636error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800637 stop_input_stream(in);
Eric Laurentc8400632013-02-14 19:04:54 -0800638
639error_config:
640 adev->active_input = NULL;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700641 ALOGD("%s: exit: status(%d)", __func__, ret);
Eric Laurentc8400632013-02-14 19:04:54 -0800642
643 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800644}
645
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700646/* must be called with out->lock locked */
647static int send_offload_cmd_l(struct stream_out* out, int command)
648{
649 struct offload_cmd *cmd = (struct offload_cmd *)calloc(1, sizeof(struct offload_cmd));
650
651 ALOGVV("%s %d", __func__, command);
652
653 cmd->cmd = command;
654 list_add_tail(&out->offload_cmd_list, &cmd->node);
655 pthread_cond_signal(&out->offload_cond);
656 return 0;
657}
658
659/* must be called iwth out->lock locked */
660static void stop_compressed_output_l(struct stream_out *out)
661{
662 out->offload_state = OFFLOAD_STATE_IDLE;
663 out->playback_started = 0;
664 if (out->compr != NULL) {
665 compress_stop(out->compr);
666 while (out->offload_thread_blocked) {
667 pthread_cond_wait(&out->cond, &out->lock);
668 }
669 }
670}
671
672static void *offload_thread_loop(void *context)
673{
674 struct stream_out *out = (struct stream_out *) context;
675 struct listnode *item;
676
677 out->offload_state = OFFLOAD_STATE_IDLE;
678 out->playback_started = 0;
679
680 setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
681 set_sched_policy(0, SP_FOREGROUND);
682 prctl(PR_SET_NAME, (unsigned long)"Offload Callback", 0, 0, 0);
683
684 ALOGV("%s", __func__);
685 pthread_mutex_lock(&out->lock);
686 for (;;) {
687 struct offload_cmd *cmd = NULL;
688 stream_callback_event_t event;
689 bool send_callback = false;
690
691 ALOGVV("%s offload_cmd_list %d out->offload_state %d",
692 __func__, list_empty(&out->offload_cmd_list),
693 out->offload_state);
694 if (list_empty(&out->offload_cmd_list)) {
695 ALOGV("%s SLEEPING", __func__);
696 pthread_cond_wait(&out->offload_cond, &out->lock);
697 ALOGV("%s RUNNING", __func__);
698 continue;
699 }
700
701 item = list_head(&out->offload_cmd_list);
702 cmd = node_to_item(item, struct offload_cmd, node);
703 list_remove(item);
704
705 ALOGVV("%s STATE %d CMD %d out->compr %p",
706 __func__, out->offload_state, cmd->cmd, out->compr);
707
708 if (cmd->cmd == OFFLOAD_CMD_EXIT) {
709 free(cmd);
710 break;
711 }
712
713 if (out->compr == NULL) {
714 ALOGE("%s: Compress handle is NULL", __func__);
715 pthread_cond_signal(&out->cond);
716 continue;
717 }
718 out->offload_thread_blocked = true;
719 pthread_mutex_unlock(&out->lock);
720 send_callback = false;
721 switch(cmd->cmd) {
722 case OFFLOAD_CMD_WAIT_FOR_BUFFER:
723 compress_wait(out->compr, -1);
724 send_callback = true;
725 event = STREAM_CBK_EVENT_WRITE_READY;
726 break;
727 case OFFLOAD_CMD_PARTIAL_DRAIN:
728 compress_drain(out->compr);
729//FIXME compress_partial_drain(out->compr);
730 send_callback = true;
731 event = STREAM_CBK_EVENT_DRAIN_READY;
732 break;
733 case OFFLOAD_CMD_DRAIN:
734 compress_drain(out->compr);
735 send_callback = true;
736 event = STREAM_CBK_EVENT_DRAIN_READY;
737 break;
738 default:
739 ALOGE("%s unknown command received: %d", __func__, cmd->cmd);
740 break;
741 }
742 pthread_mutex_lock(&out->lock);
743 out->offload_thread_blocked = false;
744 pthread_cond_signal(&out->cond);
Eric Laurent6e895242013-09-05 16:10:57 -0700745 if (send_callback) {
746 if (event == STREAM_CBK_EVENT_DRAIN_READY)
747 stop_compressed_output_l(out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700748 out->offload_callback(event, NULL, out->offload_cookie);
Eric Laurent6e895242013-09-05 16:10:57 -0700749 }
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700750 free(cmd);
751 }
752
753 pthread_cond_signal(&out->cond);
754 while (!list_empty(&out->offload_cmd_list)) {
755 item = list_head(&out->offload_cmd_list);
756 list_remove(item);
757 free(node_to_item(item, struct offload_cmd, node));
758 }
759 pthread_mutex_unlock(&out->lock);
760
761 return NULL;
762}
763
764static int create_offload_callback_thread(struct stream_out *out)
765{
766 pthread_cond_init(&out->offload_cond, (const pthread_condattr_t *) NULL);
767 list_init(&out->offload_cmd_list);
768 pthread_create(&out->offload_thread, (const pthread_attr_t *) NULL,
769 offload_thread_loop, out);
770 return 0;
771}
772
773static int destroy_offload_callback_thread(struct stream_out *out)
774{
775 pthread_mutex_lock(&out->lock);
776 stop_compressed_output_l(out);
777 send_offload_cmd_l(out, OFFLOAD_CMD_EXIT);
778
779 pthread_mutex_unlock(&out->lock);
780 pthread_join(out->offload_thread, (void **) NULL);
781 pthread_cond_destroy(&out->offload_cond);
782
783 return 0;
784}
785
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800786static int stop_output_stream(struct stream_out *out)
787{
788 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800789 struct audio_usecase *uc_info;
790 struct audio_device *adev = out->dev;
791
Eric Laurent994a6932013-07-17 11:51:42 -0700792 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700793 out->usecase, use_case_table[out->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800794 uc_info = get_usecase_from_list(adev, out->usecase);
795 if (uc_info == NULL) {
796 ALOGE("%s: Could not find the usecase (%d) in the list",
797 __func__, out->usecase);
798 return -EINVAL;
799 }
800
Eric Laurent150dbfe2013-02-27 14:31:02 -0800801 /* 1. Get and set stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700802 disable_audio_route(adev, uc_info, true);
803
804 /* 2. Disable the rx device */
805 disable_snd_device(adev, uc_info->out_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800806
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800807 list_remove(&uc_info->list);
808 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800809
Eric Laurent994a6932013-07-17 11:51:42 -0700810 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800811 return ret;
812}
813
814int start_output_stream(struct stream_out *out)
815{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800816 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800817 struct audio_usecase *uc_info;
818 struct audio_device *adev = out->dev;
819
Eric Laurent994a6932013-07-17 11:51:42 -0700820 ALOGV("%s: enter: usecase(%d: %s) devices(%#x)",
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700821 __func__, out->usecase, use_case_table[out->usecase], out->devices);
Eric Laurentb23d5282013-05-14 15:27:20 -0700822 out->pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800823 if (out->pcm_device_id < 0) {
824 ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)",
825 __func__, out->pcm_device_id, out->usecase);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800826 ret = -EINVAL;
827 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800828 }
829
830 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
831 uc_info->id = out->usecase;
832 uc_info->type = PCM_PLAYBACK;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800833 uc_info->stream.out = out;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700834 uc_info->devices = out->devices;
835 uc_info->in_snd_device = SND_DEVICE_NONE;
836 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800837
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800838 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800839
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700840 select_devices(adev, out->usecase);
841
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800842 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
843 __func__, 0, out->pcm_device_id);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700844 if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) {
845 out->pcm = pcm_open(SOUND_CARD, out->pcm_device_id,
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -0700846 PCM_OUT | PCM_MONOTONIC, &out->config);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700847 if (out->pcm && !pcm_is_ready(out->pcm)) {
848 ALOGE("%s: %s", __func__, pcm_get_error(out->pcm));
849 pcm_close(out->pcm);
850 out->pcm = NULL;
851 ret = -EIO;
852 goto error_open;
853 }
854 } else {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800855 out->pcm = NULL;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700856 out->compr = compress_open(SOUND_CARD, out->pcm_device_id,
857 COMPRESS_IN, &out->compr_config);
858 if (out->compr && !is_compress_ready(out->compr)) {
859 ALOGE("%s: %s", __func__, compress_get_error(out->compr));
860 compress_close(out->compr);
861 out->compr = NULL;
862 ret = -EIO;
863 goto error_open;
864 }
865 if (out->offload_callback)
866 compress_nonblock(out->compr, out->non_blocking);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800867 }
Eric Laurent994a6932013-07-17 11:51:42 -0700868 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800869 return 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700870error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800871 stop_output_stream(out);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800872error_config:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800873 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800874}
875
876static int stop_voice_call(struct audio_device *adev)
877{
878 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800879 struct audio_usecase *uc_info;
880
Eric Laurent994a6932013-07-17 11:51:42 -0700881 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800882 adev->in_call = false;
Eric Laurentb23d5282013-05-14 15:27:20 -0700883
884 ret = platform_stop_voice_call(adev->platform);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800885
886 /* 1. Close the PCM devices */
887 if (adev->voice_call_rx) {
888 pcm_close(adev->voice_call_rx);
889 adev->voice_call_rx = NULL;
890 }
891 if (adev->voice_call_tx) {
892 pcm_close(adev->voice_call_tx);
893 adev->voice_call_tx = NULL;
894 }
895
896 uc_info = get_usecase_from_list(adev, USECASE_VOICE_CALL);
897 if (uc_info == NULL) {
898 ALOGE("%s: Could not find the usecase (%d) in the list",
899 __func__, USECASE_VOICE_CALL);
900 return -EINVAL;
901 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800902
903 /* 2. Get and set stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700904 disable_audio_route(adev, uc_info, true);
905
906 /* 3. Disable the rx and tx devices */
907 disable_snd_device(adev, uc_info->out_snd_device, false);
908 disable_snd_device(adev, uc_info->in_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800909
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800910 list_remove(&uc_info->list);
911 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800912
Eric Laurent994a6932013-07-17 11:51:42 -0700913 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800914 return ret;
915}
916
917static int start_voice_call(struct audio_device *adev)
918{
919 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800920 struct audio_usecase *uc_info;
921 int pcm_dev_rx_id, pcm_dev_tx_id;
922
Eric Laurent994a6932013-07-17 11:51:42 -0700923 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800924
925 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
926 uc_info->id = USECASE_VOICE_CALL;
927 uc_info->type = VOICE_CALL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800928 uc_info->stream.out = adev->primary_output;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700929 uc_info->devices = adev->primary_output->devices;
930 uc_info->in_snd_device = SND_DEVICE_NONE;
931 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800932
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800933 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800934
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700935 select_devices(adev, USECASE_VOICE_CALL);
936
Eric Laurentb23d5282013-05-14 15:27:20 -0700937 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
938 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800939
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800940 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
941 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
942 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800943 ret = -EIO;
944 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800945 }
946
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800947 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800948 __func__, SOUND_CARD, pcm_dev_rx_id);
949 adev->voice_call_rx = pcm_open(SOUND_CARD,
950 pcm_dev_rx_id,
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -0700951 PCM_OUT | PCM_MONOTONIC, &pcm_config_voice_call);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800952 if (adev->voice_call_rx && !pcm_is_ready(adev->voice_call_rx)) {
953 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_rx));
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800954 ret = -EIO;
955 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800956 }
957
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800958 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800959 __func__, SOUND_CARD, pcm_dev_tx_id);
960 adev->voice_call_tx = pcm_open(SOUND_CARD,
961 pcm_dev_tx_id,
962 PCM_IN, &pcm_config_voice_call);
963 if (adev->voice_call_tx && !pcm_is_ready(adev->voice_call_tx)) {
964 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_tx));
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800965 ret = -EIO;
966 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800967 }
Haynes Mathew George5191a852013-09-11 14:19:36 -0700968
969 /* set cached volume */
970 set_voice_volume_l(adev, adev->voice_volume);
971
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800972 pcm_start(adev->voice_call_rx);
973 pcm_start(adev->voice_call_tx);
974
Eric Laurentb23d5282013-05-14 15:27:20 -0700975 ret = platform_start_voice_call(adev->platform);
976 if (ret < 0) {
977 ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
978 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800979 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800980 adev->in_call = true;
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800981 return 0;
982
983error_start_voice:
984 stop_voice_call(adev);
985
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800986 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800987 return ret;
988}
989
990static int check_input_parameters(uint32_t sample_rate,
991 audio_format_t format,
992 int channel_count)
993{
994 if (format != AUDIO_FORMAT_PCM_16_BIT) return -EINVAL;
995
996 if ((channel_count < 1) || (channel_count > 2)) return -EINVAL;
997
998 switch (sample_rate) {
999 case 8000:
1000 case 11025:
1001 case 12000:
1002 case 16000:
1003 case 22050:
1004 case 24000:
1005 case 32000:
1006 case 44100:
1007 case 48000:
1008 break;
1009 default:
1010 return -EINVAL;
1011 }
1012
1013 return 0;
1014}
1015
1016static size_t get_input_buffer_size(uint32_t sample_rate,
1017 audio_format_t format,
1018 int channel_count)
1019{
1020 size_t size = 0;
1021
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -07001022 if (check_input_parameters(sample_rate, format, channel_count) != 0)
1023 return 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001024
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -07001025 size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000;
1026 /* ToDo: should use frame_size computed based on the format and
1027 channel_count here. */
1028 size *= sizeof(short) * channel_count;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001029
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -07001030 /* make sure the size is multiple of 64 */
1031 size += 0x3f;
1032 size &= ~0x3f;
1033
1034 return size;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001035}
1036
1037static uint32_t out_get_sample_rate(const struct audio_stream *stream)
1038{
1039 struct stream_out *out = (struct stream_out *)stream;
1040
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001041 return out->sample_rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001042}
1043
1044static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1045{
1046 return -ENOSYS;
1047}
1048
1049static size_t out_get_buffer_size(const struct audio_stream *stream)
1050{
1051 struct stream_out *out = (struct stream_out *)stream;
1052
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001053 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1054 return out->compr_config.fragment_size;
1055 }
1056
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001057 return out->config.period_size * audio_stream_frame_size(stream);
1058}
1059
1060static uint32_t out_get_channels(const struct audio_stream *stream)
1061{
1062 struct stream_out *out = (struct stream_out *)stream;
1063
1064 return out->channel_mask;
1065}
1066
1067static audio_format_t out_get_format(const struct audio_stream *stream)
1068{
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001069 struct stream_out *out = (struct stream_out *)stream;
1070
1071 return out->format;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001072}
1073
1074static int out_set_format(struct audio_stream *stream, audio_format_t format)
1075{
1076 return -ENOSYS;
1077}
1078
1079static int out_standby(struct audio_stream *stream)
1080{
1081 struct stream_out *out = (struct stream_out *)stream;
1082 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001083
Eric Laurent994a6932013-07-17 11:51:42 -07001084 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001085 out->usecase, use_case_table[out->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001086
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001087 pthread_mutex_lock(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001088 if (!out->standby) {
1089 out->standby = true;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001090 if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1091 if (out->pcm) {
1092 pcm_close(out->pcm);
1093 out->pcm = NULL;
1094 }
1095 } else {
1096 stop_compressed_output_l(out);
1097 if (out->compr != NULL) {
1098 compress_close(out->compr);
1099 out->compr = NULL;
1100 }
Eric Laurent150dbfe2013-02-27 14:31:02 -08001101 }
1102 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001103 stop_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001104 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001105 }
1106 pthread_mutex_unlock(&out->lock);
Eric Laurent994a6932013-07-17 11:51:42 -07001107 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001108 return 0;
1109}
1110
1111static int out_dump(const struct audio_stream *stream, int fd)
1112{
1113 return 0;
1114}
1115
1116static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
1117{
1118 struct stream_out *out = (struct stream_out *)stream;
1119 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001120 struct audio_usecase *usecase;
1121 struct listnode *node;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001122 struct str_parms *parms;
1123 char value[32];
1124 int ret, val = 0;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001125 bool select_new_device = false;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001126
sangwoobc677242013-08-08 16:53:43 +09001127 ALOGD("%s: enter: usecase(%d: %s) kvpairs: %s",
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001128 __func__, out->usecase, use_case_table[out->usecase], kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001129 parms = str_parms_create_str(kvpairs);
1130 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1131 if (ret >= 0) {
1132 val = atoi(value);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001133 pthread_mutex_lock(&out->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001134 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001135
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001136 /*
1137 * When HDMI cable is unplugged the music playback is paused and
1138 * the policy manager sends routing=0. But the audioflinger
1139 * continues to write data until standby time (3sec).
1140 * As the HDMI core is turned off, the write gets blocked.
1141 * Avoid this by routing audio to speaker until standby.
1142 */
1143 if (out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL &&
1144 val == AUDIO_DEVICE_NONE) {
1145 val = AUDIO_DEVICE_OUT_SPEAKER;
1146 }
1147
1148 /*
1149 * select_devices() call below switches all the usecases on the same
1150 * backend to the new device. Refer to check_usecases_codec_backend() in
1151 * the select_devices(). But how do we undo this?
1152 *
1153 * For example, music playback is active on headset (deep-buffer usecase)
1154 * and if we go to ringtones and select a ringtone, low-latency usecase
1155 * will be started on headset+speaker. As we can't enable headset+speaker
1156 * and headset devices at the same time, select_devices() switches the music
1157 * playback to headset+speaker while starting low-lateny usecase for ringtone.
1158 * So when the ringtone playback is completed, how do we undo the same?
1159 *
1160 * We are relying on the out_set_parameters() call on deep-buffer output,
1161 * once the ringtone playback is ended.
1162 * NOTE: We should not check if the current devices are same as new devices.
1163 * Because select_devices() must be called to switch back the music
1164 * playback to headset.
1165 */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001166 if (val != 0) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001167 out->devices = val;
1168
1169 if (!out->standby)
1170 select_devices(adev, out->usecase);
1171
1172 if ((adev->mode == AUDIO_MODE_IN_CALL) && !adev->in_call &&
1173 (out == adev->primary_output)) {
1174 start_voice_call(adev);
1175 } else if ((adev->mode == AUDIO_MODE_IN_CALL) && adev->in_call &&
1176 (out == adev->primary_output)) {
1177 select_devices(adev, USECASE_VOICE_CALL);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001178 }
1179 }
1180
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001181 if ((adev->mode != AUDIO_MODE_IN_CALL) && adev->in_call &&
1182 (out == adev->primary_output)) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001183 stop_voice_call(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001184 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001185
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001186 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001187 pthread_mutex_unlock(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001188 }
1189 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -07001190 ALOGV("%s: exit: code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001191 return ret;
1192}
1193
1194static char* out_get_parameters(const struct audio_stream *stream, const char *keys)
1195{
1196 struct stream_out *out = (struct stream_out *)stream;
1197 struct str_parms *query = str_parms_create_str(keys);
1198 char *str;
1199 char value[256];
1200 struct str_parms *reply = str_parms_create();
1201 size_t i, j;
1202 int ret;
1203 bool first = true;
Eric Laurent994a6932013-07-17 11:51:42 -07001204 ALOGV("%s: enter: keys - %s", __func__, keys);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001205 ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value));
1206 if (ret >= 0) {
1207 value[0] = '\0';
1208 i = 0;
1209 while (out->supported_channel_masks[i] != 0) {
1210 for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) {
1211 if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) {
1212 if (!first) {
1213 strcat(value, "|");
1214 }
1215 strcat(value, out_channels_name_to_enum_table[j].name);
1216 first = false;
1217 break;
1218 }
1219 }
1220 i++;
1221 }
1222 str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value);
1223 str = str_parms_to_str(reply);
1224 } else {
1225 str = strdup(keys);
1226 }
1227 str_parms_destroy(query);
1228 str_parms_destroy(reply);
Eric Laurent994a6932013-07-17 11:51:42 -07001229 ALOGV("%s: exit: returns - %s", __func__, str);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001230 return str;
1231}
1232
1233static uint32_t out_get_latency(const struct audio_stream_out *stream)
1234{
1235 struct stream_out *out = (struct stream_out *)stream;
1236
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001237 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD)
1238 return COMPRESS_OFFLOAD_PLAYBACK_LATENCY;
1239
1240 return (out->config.period_count * out->config.period_size * 1000) /
1241 (out->config.rate);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001242}
1243
1244static int out_set_volume(struct audio_stream_out *stream, float left,
1245 float right)
1246{
Eric Laurenta9024de2013-04-04 09:19:12 -07001247 struct stream_out *out = (struct stream_out *)stream;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001248 int volume[2];
1249
Eric Laurenta9024de2013-04-04 09:19:12 -07001250 if (out->usecase == USECASE_AUDIO_PLAYBACK_MULTI_CH) {
1251 /* only take left channel into account: the API is for stereo anyway */
1252 out->muted = (left == 0.0f);
1253 return 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001254 } else if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1255 const char *mixer_ctl_name = "Compress Playback Volume";
1256 struct audio_device *adev = out->dev;
1257 struct mixer_ctl *ctl;
1258
1259 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1260 if (!ctl) {
1261 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1262 __func__, mixer_ctl_name);
1263 return -EINVAL;
1264 }
1265 volume[0] = (int)(left * COMPRESS_PLAYBACK_VOLUME_MAX);
1266 volume[1] = (int)(right * COMPRESS_PLAYBACK_VOLUME_MAX);
1267 mixer_ctl_set_array(ctl, volume, sizeof(volume)/sizeof(volume[0]));
1268 return 0;
Eric Laurenta9024de2013-04-04 09:19:12 -07001269 }
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001270
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001271 return -ENOSYS;
1272}
1273
1274static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
1275 size_t bytes)
1276{
1277 struct stream_out *out = (struct stream_out *)stream;
1278 struct audio_device *adev = out->dev;
Eric Laurent6e895242013-09-05 16:10:57 -07001279 ssize_t ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001280
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001281 pthread_mutex_lock(&out->lock);
1282 if (out->standby) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001283 out->standby = false;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001284 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001285 ret = start_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001286 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001287 /* ToDo: If use case is compress offload should return 0 */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001288 if (ret != 0) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001289 out->standby = true;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001290 goto exit;
1291 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001292 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001293
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001294 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1295 ret = compress_write(out->compr, buffer, bytes);
Eric Laurent6e895242013-09-05 16:10:57 -07001296 ALOGVV("%s: writing buffer (%d bytes) to pcm device returned %d", __func__, bytes, ret);
1297 if (ret >= 0 && ret < (ssize_t)bytes) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001298 send_offload_cmd_l(out, OFFLOAD_CMD_WAIT_FOR_BUFFER);
1299 }
1300 if (!out->playback_started) {
1301 compress_start(out->compr);
1302 out->playback_started = 1;
1303 out->offload_state = OFFLOAD_STATE_PLAYING;
1304 }
1305 pthread_mutex_unlock(&out->lock);
1306 return ret;
1307 } else {
1308 if (out->pcm) {
1309 if (out->muted)
1310 memset((void *)buffer, 0, bytes);
1311 ALOGVV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes);
1312 ret = pcm_write(out->pcm, (void *)buffer, bytes);
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001313 if (ret == 0)
1314 out->written += bytes / (out->config.channels * sizeof(short));
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001315 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001316 }
1317
1318exit:
1319 pthread_mutex_unlock(&out->lock);
1320
1321 if (ret != 0) {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001322 if (out->pcm)
1323 ALOGE("%s: error %d - %s", __func__, ret, pcm_get_error(out->pcm));
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001324 out_standby(&out->stream.common);
1325 usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) /
1326 out_get_sample_rate(&out->stream.common));
1327 }
1328 return bytes;
1329}
1330
1331static int out_get_render_position(const struct audio_stream_out *stream,
1332 uint32_t *dsp_frames)
1333{
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001334 struct stream_out *out = (struct stream_out *)stream;
1335 *dsp_frames = 0;
1336 if ((out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) && (dsp_frames != NULL)) {
1337 pthread_mutex_lock(&out->lock);
1338 if (out->compr != NULL) {
1339 compress_get_tstamp(out->compr, (unsigned long *)dsp_frames,
1340 &out->sample_rate);
1341 ALOGVV("%s rendered frames %d sample_rate %d",
1342 __func__, *dsp_frames, out->sample_rate);
1343 }
1344 pthread_mutex_unlock(&out->lock);
1345 return 0;
1346 } else
1347 return -EINVAL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001348}
1349
1350static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1351{
1352 return 0;
1353}
1354
1355static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1356{
1357 return 0;
1358}
1359
1360static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
1361 int64_t *timestamp)
1362{
1363 return -EINVAL;
1364}
1365
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001366static int out_get_presentation_position(const struct audio_stream_out *stream,
1367 uint64_t *frames, struct timespec *timestamp)
1368{
1369 struct stream_out *out = (struct stream_out *)stream;
1370 int ret = -1;
1371
1372 pthread_mutex_lock(&out->lock);
1373
1374 if (out->pcm) {
1375 size_t avail;
1376 if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) {
1377 size_t kernel_buffer_size = out->config.period_size * out->config.period_count;
1378 // FIXME This calculation is incorrect if there is buffering after app processor
1379 int64_t signed_frames = out->written - kernel_buffer_size + avail;
1380 // It would be unusual for this value to be negative, but check just in case ...
1381 if (signed_frames >= 0) {
1382 *frames = signed_frames;
1383 ret = 0;
1384 }
1385 }
1386 }
1387
1388 pthread_mutex_unlock(&out->lock);
1389
1390 return ret;
1391}
1392
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001393static int out_set_callback(struct audio_stream_out *stream,
1394 stream_callback_t callback, void *cookie)
1395{
1396 struct stream_out *out = (struct stream_out *)stream;
1397
1398 ALOGV("%s", __func__);
1399 pthread_mutex_lock(&out->lock);
1400 out->offload_callback = callback;
1401 out->offload_cookie = cookie;
1402 pthread_mutex_unlock(&out->lock);
1403 return 0;
1404}
1405
1406static int out_pause(struct audio_stream_out* stream)
1407{
1408 struct stream_out *out = (struct stream_out *)stream;
1409 int status = -ENOSYS;
1410 ALOGV("%s", __func__);
1411 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1412 pthread_mutex_lock(&out->lock);
1413 if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PLAYING) {
1414 status = compress_pause(out->compr);
1415 out->offload_state = OFFLOAD_STATE_PAUSED;
1416 }
1417 pthread_mutex_unlock(&out->lock);
1418 }
1419 return status;
1420}
1421
1422static int out_resume(struct audio_stream_out* stream)
1423{
1424 struct stream_out *out = (struct stream_out *)stream;
1425 int status = -ENOSYS;
1426 ALOGV("%s", __func__);
1427 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1428 status = 0;
1429 pthread_mutex_lock(&out->lock);
1430 if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PAUSED) {
1431 status = compress_resume(out->compr);
1432 out->offload_state = OFFLOAD_STATE_PLAYING;
1433 }
1434 pthread_mutex_unlock(&out->lock);
1435 }
1436 return status;
1437}
1438
1439static int out_drain(struct audio_stream_out* stream, audio_drain_type_t type )
1440{
1441 struct stream_out *out = (struct stream_out *)stream;
1442 int status = -ENOSYS;
1443 ALOGV("%s", __func__);
1444 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1445 pthread_mutex_lock(&out->lock);
1446 if (type == AUDIO_DRAIN_EARLY_NOTIFY)
1447 status = send_offload_cmd_l(out, OFFLOAD_CMD_PARTIAL_DRAIN);
1448 else
1449 status = send_offload_cmd_l(out, OFFLOAD_CMD_DRAIN);
1450 pthread_mutex_unlock(&out->lock);
1451 }
1452 return status;
1453}
1454
1455static int out_flush(struct audio_stream_out* stream)
1456{
1457 struct stream_out *out = (struct stream_out *)stream;
1458 ALOGV("%s", __func__);
1459 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1460 pthread_mutex_lock(&out->lock);
1461 stop_compressed_output_l(out);
1462 pthread_mutex_unlock(&out->lock);
1463 return 0;
1464 }
1465 return -ENOSYS;
1466}
1467
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001468/** audio_stream_in implementation **/
1469static uint32_t in_get_sample_rate(const struct audio_stream *stream)
1470{
1471 struct stream_in *in = (struct stream_in *)stream;
1472
1473 return in->config.rate;
1474}
1475
1476static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1477{
1478 return -ENOSYS;
1479}
1480
1481static size_t in_get_buffer_size(const struct audio_stream *stream)
1482{
1483 struct stream_in *in = (struct stream_in *)stream;
1484
1485 return in->config.period_size * audio_stream_frame_size(stream);
1486}
1487
1488static uint32_t in_get_channels(const struct audio_stream *stream)
1489{
1490 struct stream_in *in = (struct stream_in *)stream;
1491
1492 return in->channel_mask;
1493}
1494
1495static audio_format_t in_get_format(const struct audio_stream *stream)
1496{
1497 return AUDIO_FORMAT_PCM_16_BIT;
1498}
1499
1500static int in_set_format(struct audio_stream *stream, audio_format_t format)
1501{
1502 return -ENOSYS;
1503}
1504
1505static int in_standby(struct audio_stream *stream)
1506{
1507 struct stream_in *in = (struct stream_in *)stream;
1508 struct audio_device *adev = in->dev;
1509 int status = 0;
Eric Laurent994a6932013-07-17 11:51:42 -07001510 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001511 pthread_mutex_lock(&in->lock);
1512 if (!in->standby) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001513 in->standby = true;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001514 if (in->pcm) {
1515 pcm_close(in->pcm);
1516 in->pcm = NULL;
1517 }
1518 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001519 status = stop_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001520 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001521 }
1522 pthread_mutex_unlock(&in->lock);
Eric Laurent994a6932013-07-17 11:51:42 -07001523 ALOGV("%s: exit: status(%d)", __func__, status);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001524 return status;
1525}
1526
1527static int in_dump(const struct audio_stream *stream, int fd)
1528{
1529 return 0;
1530}
1531
1532static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
1533{
1534 struct stream_in *in = (struct stream_in *)stream;
1535 struct audio_device *adev = in->dev;
1536 struct str_parms *parms;
1537 char *str;
1538 char value[32];
1539 int ret, val = 0;
1540
Eric Laurent994a6932013-07-17 11:51:42 -07001541 ALOGV("%s: enter: kvpairs=%s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001542 parms = str_parms_create_str(kvpairs);
1543
1544 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value));
1545
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001546 pthread_mutex_lock(&in->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001547 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001548 if (ret >= 0) {
1549 val = atoi(value);
1550 /* no audio source uses val == 0 */
1551 if ((in->source != val) && (val != 0)) {
1552 in->source = val;
1553 }
1554 }
1555
1556 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1557 if (ret >= 0) {
1558 val = atoi(value);
1559 if ((in->device != val) && (val != 0)) {
1560 in->device = val;
1561 /* If recording is in progress, change the tx device to new device */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001562 if (!in->standby)
1563 ret = select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001564 }
1565 }
1566
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001567 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001568 pthread_mutex_unlock(&in->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001569
1570 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -07001571 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001572 return ret;
1573}
1574
1575static char* in_get_parameters(const struct audio_stream *stream,
1576 const char *keys)
1577{
1578 return strdup("");
1579}
1580
1581static int in_set_gain(struct audio_stream_in *stream, float gain)
1582{
1583 return 0;
1584}
1585
1586static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
1587 size_t bytes)
1588{
1589 struct stream_in *in = (struct stream_in *)stream;
1590 struct audio_device *adev = in->dev;
1591 int i, ret = -1;
1592
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001593 pthread_mutex_lock(&in->lock);
1594 if (in->standby) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001595 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001596 ret = start_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001597 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001598 if (ret != 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001599 goto exit;
1600 }
1601 in->standby = 0;
1602 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001603
1604 if (in->pcm) {
1605 ret = pcm_read(in->pcm, buffer, bytes);
1606 }
1607
1608 /*
1609 * Instead of writing zeroes here, we could trust the hardware
1610 * to always provide zeroes when muted.
1611 */
1612 if (ret == 0 && adev->mic_mute)
1613 memset(buffer, 0, bytes);
1614
1615exit:
1616 pthread_mutex_unlock(&in->lock);
1617
1618 if (ret != 0) {
1619 in_standby(&in->stream.common);
1620 ALOGV("%s: read failed - sleeping for buffer duration", __func__);
1621 usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) /
1622 in_get_sample_rate(&in->stream.common));
1623 }
1624 return bytes;
1625}
1626
1627static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
1628{
1629 return 0;
1630}
1631
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001632static int add_remove_audio_effect(const struct audio_stream *stream,
1633 effect_handle_t effect,
1634 bool enable)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001635{
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001636 struct stream_in *in = (struct stream_in *)stream;
1637 int status = 0;
1638 effect_descriptor_t desc;
1639
1640 status = (*effect)->get_descriptor(effect, &desc);
1641 if (status != 0)
1642 return status;
1643
1644 pthread_mutex_lock(&in->lock);
1645 pthread_mutex_lock(&in->dev->lock);
1646 if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
1647 in->enable_aec != enable &&
1648 (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0)) {
1649 in->enable_aec = enable;
1650 if (!in->standby)
1651 select_devices(in->dev, in->usecase);
1652 }
1653 pthread_mutex_unlock(&in->dev->lock);
1654 pthread_mutex_unlock(&in->lock);
1655
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001656 return 0;
1657}
1658
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001659static int in_add_audio_effect(const struct audio_stream *stream,
1660 effect_handle_t effect)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001661{
Eric Laurent994a6932013-07-17 11:51:42 -07001662 ALOGV("%s: effect %p", __func__, effect);
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001663 return add_remove_audio_effect(stream, effect, true);
1664}
1665
1666static int in_remove_audio_effect(const struct audio_stream *stream,
1667 effect_handle_t effect)
1668{
Eric Laurent994a6932013-07-17 11:51:42 -07001669 ALOGV("%s: effect %p", __func__, effect);
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001670 return add_remove_audio_effect(stream, effect, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001671}
1672
1673static int adev_open_output_stream(struct audio_hw_device *dev,
1674 audio_io_handle_t handle,
1675 audio_devices_t devices,
1676 audio_output_flags_t flags,
1677 struct audio_config *config,
1678 struct audio_stream_out **stream_out)
1679{
1680 struct audio_device *adev = (struct audio_device *)dev;
1681 struct stream_out *out;
1682 int i, ret;
1683
Eric Laurent994a6932013-07-17 11:51:42 -07001684 ALOGV("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001685 __func__, config->sample_rate, config->channel_mask, devices, flags);
1686 *stream_out = NULL;
1687 out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
1688
1689 if (devices == AUDIO_DEVICE_NONE)
1690 devices = AUDIO_DEVICE_OUT_SPEAKER;
1691
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001692 out->flags = flags;
1693 out->devices = devices;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001694 out->dev = adev;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001695 out->format = config->format;
1696 out->sample_rate = config->sample_rate;
1697 out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
1698 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001699
1700 /* Init use case and pcm_config */
1701 if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT &&
1702 out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001703 pthread_mutex_lock(&adev->lock);
1704 ret = read_hdmi_channel_masks(out);
1705 pthread_mutex_unlock(&adev->lock);
1706 if (ret != 0) {
1707 /* If HDMI does not support multi channel playback, set the default */
1708 out->config.channels = popcount(out->channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001709 platform_set_hdmi_channels(adev->platform, out->config.channels);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001710 goto error_open;
1711 }
1712
1713 if (config->sample_rate == 0)
1714 config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
1715 if (config->channel_mask == 0)
1716 config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1;
1717
1718 out->channel_mask = config->channel_mask;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001719 out->sample_rate = config->sample_rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001720 out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH;
1721 out->config = pcm_config_hdmi_multi;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001722 out->config.rate = config->sample_rate;
1723 out->config.channels = popcount(out->channel_mask);
1724 out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2);
Eric Laurentb23d5282013-05-14 15:27:20 -07001725 platform_set_hdmi_channels(adev->platform, out->config.channels);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001726 } else if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) {
1727 out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER;
1728 out->config = pcm_config_deep_buffer;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001729 out->sample_rate = out->config.rate;
1730 } else if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
1731 if (config->offload_info.version != AUDIO_INFO_INITIALIZER.version ||
1732 config->offload_info.size != AUDIO_INFO_INITIALIZER.size) {
1733 ALOGE("%s: Unsupported Offload information", __func__);
1734 ret = -EINVAL;
1735 goto error_open;
1736 }
1737 if (!is_supported_format(config->offload_info.format)) {
1738 ALOGE("%s: Unsupported audio format", __func__);
1739 ret = -EINVAL;
1740 goto error_open;
1741 }
1742
1743 out->compr_config.codec = (struct snd_codec *)
1744 calloc(1, sizeof(struct snd_codec));
1745
1746 out->usecase = USECASE_AUDIO_PLAYBACK_OFFLOAD;
1747 if (config->offload_info.channel_mask)
1748 out->channel_mask = config->offload_info.channel_mask;
1749 else if (config->channel_mask)
1750 out->channel_mask = config->channel_mask;
1751 out->format = config->offload_info.format;
1752 out->sample_rate = config->offload_info.sample_rate;
1753
1754 out->stream.set_callback = out_set_callback;
1755 out->stream.pause = out_pause;
1756 out->stream.resume = out_resume;
1757 out->stream.drain = out_drain;
1758 out->stream.flush = out_flush;
1759
1760 out->compr_config.codec->id =
1761 get_snd_codec_id(config->offload_info.format);
1762 out->compr_config.fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1763 out->compr_config.fragments = COMPRESS_OFFLOAD_NUM_FRAGMENTS;
1764 out->compr_config.codec->sample_rate =
1765 compress_get_alsa_rate(config->offload_info.sample_rate);
1766 out->compr_config.codec->bit_rate =
1767 config->offload_info.bit_rate;
1768 out->compr_config.codec->ch_in =
1769 popcount(config->channel_mask);
1770 out->compr_config.codec->ch_out = out->compr_config.codec->ch_in;
1771
1772 if (flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING)
1773 out->non_blocking = 1;
1774 create_offload_callback_thread(out);
1775 ALOGV("%s: offloaded output offload_info version %04x bit rate %d",
1776 __func__, config->offload_info.version,
1777 config->offload_info.bit_rate);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001778 } else {
1779 out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY;
1780 out->config = pcm_config_low_latency;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001781 out->sample_rate = out->config.rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001782 }
1783
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001784 if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) {
1785 if(adev->primary_output == NULL)
1786 adev->primary_output = out;
1787 else {
1788 ALOGE("%s: Primary output is already opened", __func__);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001789 ret = -EEXIST;
1790 goto error_open;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001791 }
1792 }
1793
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001794 /* Check if this usecase is already existing */
1795 pthread_mutex_lock(&adev->lock);
1796 if (get_usecase_from_list(adev, out->usecase) != NULL) {
1797 ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001798 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001799 ret = -EEXIST;
1800 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001801 }
1802 pthread_mutex_unlock(&adev->lock);
1803
1804 out->stream.common.get_sample_rate = out_get_sample_rate;
1805 out->stream.common.set_sample_rate = out_set_sample_rate;
1806 out->stream.common.get_buffer_size = out_get_buffer_size;
1807 out->stream.common.get_channels = out_get_channels;
1808 out->stream.common.get_format = out_get_format;
1809 out->stream.common.set_format = out_set_format;
1810 out->stream.common.standby = out_standby;
1811 out->stream.common.dump = out_dump;
1812 out->stream.common.set_parameters = out_set_parameters;
1813 out->stream.common.get_parameters = out_get_parameters;
1814 out->stream.common.add_audio_effect = out_add_audio_effect;
1815 out->stream.common.remove_audio_effect = out_remove_audio_effect;
1816 out->stream.get_latency = out_get_latency;
1817 out->stream.set_volume = out_set_volume;
1818 out->stream.write = out_write;
1819 out->stream.get_render_position = out_get_render_position;
1820 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001821 out->stream.get_presentation_position = out_get_presentation_position;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001822
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001823 out->standby = 1;
Eric Laurenta9024de2013-04-04 09:19:12 -07001824 /* out->muted = false; by calloc() */
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001825 /* out->written = 0; by calloc() */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001826
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001827 pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL);
1828 pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL);
1829
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001830 config->format = out->stream.common.get_format(&out->stream.common);
1831 config->channel_mask = out->stream.common.get_channels(&out->stream.common);
1832 config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common);
1833
1834 *stream_out = &out->stream;
Eric Laurent994a6932013-07-17 11:51:42 -07001835 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001836 return 0;
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001837
1838error_open:
1839 free(out);
1840 *stream_out = NULL;
1841 ALOGD("%s: exit: ret %d", __func__, ret);
1842 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001843}
1844
1845static void adev_close_output_stream(struct audio_hw_device *dev,
1846 struct audio_stream_out *stream)
1847{
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001848 struct stream_out *out = (struct stream_out *)stream;
1849 struct audio_device *adev = out->dev;
1850
Eric Laurent994a6932013-07-17 11:51:42 -07001851 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001852 out_standby(&stream->common);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001853 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1854 destroy_offload_callback_thread(out);
1855
1856 if (out->compr_config.codec != NULL)
1857 free(out->compr_config.codec);
1858 }
1859 pthread_cond_destroy(&out->cond);
1860 pthread_mutex_destroy(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001861 free(stream);
Eric Laurent994a6932013-07-17 11:51:42 -07001862 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001863}
1864
1865static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
1866{
1867 struct audio_device *adev = (struct audio_device *)dev;
1868 struct str_parms *parms;
1869 char *str;
1870 char value[32];
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07001871 int val;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001872 int ret;
1873
Eric Laurent994a6932013-07-17 11:51:42 -07001874 ALOGV("%s: enter: %s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001875
1876 parms = str_parms_create_str(kvpairs);
1877 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
1878 if (ret >= 0) {
1879 int tty_mode;
1880
1881 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
1882 tty_mode = TTY_MODE_OFF;
1883 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
1884 tty_mode = TTY_MODE_VCO;
1885 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
1886 tty_mode = TTY_MODE_HCO;
1887 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
1888 tty_mode = TTY_MODE_FULL;
1889 else
1890 return -EINVAL;
1891
1892 pthread_mutex_lock(&adev->lock);
1893 if (tty_mode != adev->tty_mode) {
1894 adev->tty_mode = tty_mode;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08001895 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
1896 if (adev->in_call)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001897 select_devices(adev, USECASE_VOICE_CALL);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001898 }
1899 pthread_mutex_unlock(&adev->lock);
1900 }
1901
1902 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
1903 if (ret >= 0) {
1904 /* When set to false, HAL should disable EC and NS
1905 * But it is currently not supported.
1906 */
1907 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1908 adev->bluetooth_nrec = true;
1909 else
1910 adev->bluetooth_nrec = false;
1911 }
1912
1913 ret = str_parms_get_str(parms, "screen_state", value, sizeof(value));
1914 if (ret >= 0) {
1915 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1916 adev->screen_off = false;
1917 else
1918 adev->screen_off = true;
1919 }
1920
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07001921 ret = str_parms_get_int(parms, "rotation", &val);
1922 if (ret >= 0) {
1923 bool reverse_speakers = false;
1924 switch(val) {
1925 // FIXME: note that the code below assumes that the speakers are in the correct placement
1926 // relative to the user when the device is rotated 90deg from its default rotation. This
1927 // assumption is device-specific, not platform-specific like this code.
1928 case 270:
1929 reverse_speakers = true;
1930 break;
1931 case 0:
1932 case 90:
1933 case 180:
1934 break;
1935 default:
1936 ALOGE("%s: unexpected rotation of %d", __func__, val);
1937 }
1938 pthread_mutex_lock(&adev->lock);
1939 if (adev->speaker_lr_swap != reverse_speakers) {
1940 adev->speaker_lr_swap = reverse_speakers;
1941 // only update the selected device if there is active pcm playback
1942 struct audio_usecase *usecase;
1943 struct listnode *node;
1944 list_for_each(node, &adev->usecase_list) {
1945 usecase = node_to_item(node, struct audio_usecase, list);
1946 if (usecase->type == PCM_PLAYBACK) {
1947 select_devices(adev, usecase->id);
1948 break;
1949 }
1950 }
1951 }
1952 pthread_mutex_unlock(&adev->lock);
1953 }
1954
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001955 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -07001956 ALOGV("%s: exit with code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001957 return ret;
1958}
1959
1960static char* adev_get_parameters(const struct audio_hw_device *dev,
1961 const char *keys)
1962{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001963 return strdup("");
1964}
1965
1966static int adev_init_check(const struct audio_hw_device *dev)
1967{
1968 return 0;
1969}
1970
Haynes Mathew George5191a852013-09-11 14:19:36 -07001971/* always called with adev lock held */
1972static int set_voice_volume_l(struct audio_device *adev, float volume)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001973{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001974 int vol, err = 0;
1975
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001976 if (adev->mode == AUDIO_MODE_IN_CALL) {
1977 if (volume < 0.0) {
1978 volume = 0.0;
1979 } else if (volume > 1.0) {
1980 volume = 1.0;
1981 }
1982
1983 vol = lrint(volume * 100.0);
1984
1985 // Voice volume levels from android are mapped to driver volume levels as follows.
1986 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
1987 // So adjust the volume to get the correct volume index in driver
1988 vol = 100 - vol;
Eric Laurentb23d5282013-05-14 15:27:20 -07001989
1990 err = platform_set_voice_volume(adev->platform, vol);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001991 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001992 return err;
1993}
1994
Haynes Mathew George5191a852013-09-11 14:19:36 -07001995static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
1996{
1997 int ret;
1998 struct audio_device *adev = (struct audio_device *)dev;
1999 pthread_mutex_lock(&adev->lock);
2000 /* cache volume */
2001 adev->voice_volume = volume;
2002 ret = set_voice_volume_l(adev, adev->voice_volume);
2003 pthread_mutex_unlock(&adev->lock);
2004 return ret;
2005}
2006
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002007static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
2008{
2009 return -ENOSYS;
2010}
2011
2012static int adev_get_master_volume(struct audio_hw_device *dev,
2013 float *volume)
2014{
2015 return -ENOSYS;
2016}
2017
2018static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
2019{
2020 return -ENOSYS;
2021}
2022
2023static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
2024{
2025 return -ENOSYS;
2026}
2027
2028static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
2029{
2030 struct audio_device *adev = (struct audio_device *)dev;
2031
2032 pthread_mutex_lock(&adev->lock);
2033 if (adev->mode != mode) {
2034 adev->mode = mode;
2035 }
2036 pthread_mutex_unlock(&adev->lock);
2037 return 0;
2038}
2039
2040static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
2041{
2042 struct audio_device *adev = (struct audio_device *)dev;
2043 int err = 0;
2044
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002045 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002046 adev->mic_mute = state;
Eric Laurentb23d5282013-05-14 15:27:20 -07002047
2048 err = platform_set_mic_mute(adev->platform, state);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002049 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002050 return err;
2051}
2052
2053static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
2054{
2055 struct audio_device *adev = (struct audio_device *)dev;
2056
2057 *state = adev->mic_mute;
2058
2059 return 0;
2060}
2061
2062static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
2063 const struct audio_config *config)
2064{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002065 int channel_count = popcount(config->channel_mask);
2066
2067 return get_input_buffer_size(config->sample_rate, config->format, channel_count);
2068}
2069
2070static int adev_open_input_stream(struct audio_hw_device *dev,
2071 audio_io_handle_t handle,
2072 audio_devices_t devices,
2073 struct audio_config *config,
2074 struct audio_stream_in **stream_in)
2075{
2076 struct audio_device *adev = (struct audio_device *)dev;
2077 struct stream_in *in;
2078 int ret, buffer_size, frame_size;
2079 int channel_count = popcount(config->channel_mask);
2080
Eric Laurent994a6932013-07-17 11:51:42 -07002081 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002082 *stream_in = NULL;
2083 if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
2084 return -EINVAL;
2085
2086 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
2087
2088 in->stream.common.get_sample_rate = in_get_sample_rate;
2089 in->stream.common.set_sample_rate = in_set_sample_rate;
2090 in->stream.common.get_buffer_size = in_get_buffer_size;
2091 in->stream.common.get_channels = in_get_channels;
2092 in->stream.common.get_format = in_get_format;
2093 in->stream.common.set_format = in_set_format;
2094 in->stream.common.standby = in_standby;
2095 in->stream.common.dump = in_dump;
2096 in->stream.common.set_parameters = in_set_parameters;
2097 in->stream.common.get_parameters = in_get_parameters;
2098 in->stream.common.add_audio_effect = in_add_audio_effect;
2099 in->stream.common.remove_audio_effect = in_remove_audio_effect;
2100 in->stream.set_gain = in_set_gain;
2101 in->stream.read = in_read;
2102 in->stream.get_input_frames_lost = in_get_input_frames_lost;
2103
2104 in->device = devices;
2105 in->source = AUDIO_SOURCE_DEFAULT;
2106 in->dev = adev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002107 in->standby = 1;
2108 in->channel_mask = config->channel_mask;
2109
2110 /* Update config params with the requested sample rate and channels */
2111 in->usecase = USECASE_AUDIO_RECORD;
2112 in->config = pcm_config_audio_capture;
2113 in->config.channels = channel_count;
2114 in->config.rate = config->sample_rate;
2115
2116 frame_size = audio_stream_frame_size((struct audio_stream *)in);
2117 buffer_size = get_input_buffer_size(config->sample_rate,
2118 config->format,
2119 channel_count);
2120 in->config.period_size = buffer_size / frame_size;
2121
2122 *stream_in = &in->stream;
Eric Laurent994a6932013-07-17 11:51:42 -07002123 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002124 return 0;
2125
2126err_open:
2127 free(in);
2128 *stream_in = NULL;
2129 return ret;
2130}
2131
2132static void adev_close_input_stream(struct audio_hw_device *dev,
2133 struct audio_stream_in *stream)
2134{
Eric Laurent994a6932013-07-17 11:51:42 -07002135 ALOGV("%s", __func__);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002136
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002137 in_standby(&stream->common);
2138 free(stream);
2139
2140 return;
2141}
2142
2143static int adev_dump(const audio_hw_device_t *device, int fd)
2144{
2145 return 0;
2146}
2147
2148static int adev_close(hw_device_t *device)
2149{
2150 struct audio_device *adev = (struct audio_device *)device;
2151 audio_route_free(adev->audio_route);
Eric Laurentb23d5282013-05-14 15:27:20 -07002152 free(adev->snd_dev_ref_cnt);
2153 platform_deinit(adev->platform);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002154 free(device);
2155 return 0;
2156}
2157
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002158static int adev_open(const hw_module_t *module, const char *name,
2159 hw_device_t **device)
2160{
2161 struct audio_device *adev;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002162 int i, ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002163
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002164 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002165 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;
2166
2167 adev = calloc(1, sizeof(struct audio_device));
2168
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002169 adev->device.common.tag = HARDWARE_DEVICE_TAG;
2170 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
2171 adev->device.common.module = (struct hw_module_t *)module;
2172 adev->device.common.close = adev_close;
2173
2174 adev->device.init_check = adev_init_check;
2175 adev->device.set_voice_volume = adev_set_voice_volume;
2176 adev->device.set_master_volume = adev_set_master_volume;
2177 adev->device.get_master_volume = adev_get_master_volume;
2178 adev->device.set_master_mute = adev_set_master_mute;
2179 adev->device.get_master_mute = adev_get_master_mute;
2180 adev->device.set_mode = adev_set_mode;
2181 adev->device.set_mic_mute = adev_set_mic_mute;
2182 adev->device.get_mic_mute = adev_get_mic_mute;
2183 adev->device.set_parameters = adev_set_parameters;
2184 adev->device.get_parameters = adev_get_parameters;
2185 adev->device.get_input_buffer_size = adev_get_input_buffer_size;
2186 adev->device.open_output_stream = adev_open_output_stream;
2187 adev->device.close_output_stream = adev_close_output_stream;
2188 adev->device.open_input_stream = adev_open_input_stream;
2189 adev->device.close_input_stream = adev_close_input_stream;
2190 adev->device.dump = adev_dump;
2191
2192 /* Set the default route before the PCM stream is opened */
2193 pthread_mutex_lock(&adev->lock);
2194 adev->mode = AUDIO_MODE_NORMAL;
Eric Laurentc8400632013-02-14 19:04:54 -08002195 adev->active_input = NULL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08002196 adev->primary_output = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002197 adev->out_device = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002198 adev->voice_call_rx = NULL;
2199 adev->voice_call_tx = NULL;
2200 adev->voice_volume = 1.0f;
2201 adev->tty_mode = TTY_MODE_OFF;
2202 adev->bluetooth_nrec = true;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002203 adev->in_call = false;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08002204 adev->acdb_settings = TTY_MODE_OFF;
Eric Laurentb23d5282013-05-14 15:27:20 -07002205 adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int));
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08002206 list_init(&adev->usecase_list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002207 pthread_mutex_unlock(&adev->lock);
2208
2209 /* Loads platform specific libraries dynamically */
Eric Laurentb23d5282013-05-14 15:27:20 -07002210 adev->platform = platform_init(adev);
2211 if (!adev->platform) {
2212 free(adev->snd_dev_ref_cnt);
2213 free(adev);
2214 ALOGE("%s: Failed to init platform data, aborting.", __func__);
2215 *device = NULL;
2216 return -EINVAL;
2217 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002218 *device = &adev->device.common;
2219
Eric Laurent994a6932013-07-17 11:51:42 -07002220 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002221 return 0;
2222}
2223
2224static struct hw_module_methods_t hal_module_methods = {
2225 .open = adev_open,
2226};
2227
2228struct audio_module HAL_MODULE_INFO_SYM = {
2229 .common = {
2230 .tag = HARDWARE_MODULE_TAG,
2231 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
2232 .hal_api_version = HARDWARE_HAL_API_VERSION,
2233 .id = AUDIO_HARDWARE_MODULE_ID,
2234 .name = "QCOM Audio HAL",
2235 .author = "Code Aurora Forum",
2236 .methods = &hal_module_methods,
2237 },
2238};