blob: b0afb0c5ef8369c14e76bcdf4abf3fe7045b1606 [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 Alamanda75d924d2013-02-20 21:30:08 -080019#define LOG_NDDEBUG 0
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080020
21#include <errno.h>
22#include <pthread.h>
23#include <stdint.h>
24#include <sys/time.h>
25#include <stdlib.h>
26#include <dlfcn.h>
27#include <math.h>
28
29#include <cutils/log.h>
30#include <cutils/str_parms.h>
31#include <cutils/properties.h>
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -080032#include <cutils/list.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080033
34#include "audio_hw.h"
35
36#define LIB_ACDB_LOADER "/system/lib/libacdbloader.so"
37#define LIB_CSD_CLIENT "/system/lib/libcsd-client.so"
38#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
39#define MIXER_CARD 0
40
41#define STRING_TO_ENUM(string) { #string, string }
42
43/* Flags used to initialize acdb_settings variable that goes to ACDB library */
44#define DMIC_FLAG 0x00000002
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -080045#define TTY_MODE_OFF 0x00000010
46#define TTY_MODE_FULL 0x00000020
47#define TTY_MODE_VCO 0x00000040
48#define TTY_MODE_HCO 0x00000080
49#define TTY_MODE_CLEAR 0xFFFFFF0F
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080050
51struct string_to_enum {
52 const char *name;
53 uint32_t value;
54};
55
56static const struct string_to_enum out_channels_name_to_enum_table[] = {
57 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO),
58 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
59 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
60};
61
62static const char * const use_case_table[AUDIO_USECASE_MAX] = {
63 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback",
64 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
65 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback",
66 [USECASE_AUDIO_RECORD] = "audio-record",
67 [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
68 [USECASE_VOICE_CALL] = "voice-call",
69};
70
71static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
72 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0},
73 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {14, 14},
74 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1},
75 [USECASE_AUDIO_RECORD] = {0, 0},
76 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {14, 14},
77 [USECASE_VOICE_CALL] = {12, 12},
78};
79
80/* Array to store sound devices */
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -080081static const char * const device_table[SND_DEVICE_MAX] = {
82 [SND_DEVICE_NONE] = "none",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080083 /* Playback sound devices */
84 [SND_DEVICE_OUT_HANDSET] = "handset",
85 [SND_DEVICE_OUT_SPEAKER] = "speaker",
86 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
87 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
88 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
89 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -080090 [SND_DEVICE_OUT_HDMI] = "hdmi",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080091 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
92 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -080093 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -080094 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
95 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
96 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080097
98 /* Capture sound devices */
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -080099 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800100 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
101 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
102 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
103 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
104 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800105 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800106 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800107 [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef",
108 [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs",
109 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus",
110 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef",
111 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs",
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800112 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
113 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
114 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800115 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800116 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef",
117 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs",
Eric Laurentc8400632013-02-14 19:04:54 -0800118 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence",
119 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800120};
121
Eric Laurentc8400632013-02-14 19:04:54 -0800122/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800123static const int acdb_device_table[SND_DEVICE_MAX] = {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800124 [SND_DEVICE_OUT_HANDSET] = 7,
125 [SND_DEVICE_OUT_SPEAKER] = 14,
126 [SND_DEVICE_OUT_HEADPHONES] = 10,
127 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
128 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
129 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800130 [SND_DEVICE_OUT_HDMI] = 18,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800131 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
132 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800133 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81,
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800134 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
135 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
136 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800137
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800138 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800139 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
140 [SND_DEVICE_IN_HEADSET_MIC] = 8,
141 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
142 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
143 [SND_DEVICE_IN_HDMI_MIC] = 4,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800144 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800145 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800146 [SND_DEVICE_IN_VOICE_DMIC_EF] = 6,
147 [SND_DEVICE_IN_VOICE_DMIC_BS] = 5,
148 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91,
149 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13,
150 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12,
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800151 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
152 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
153 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800154 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800155 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62,
156 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62,
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800157 /* TODO: Update with proper acdb ids */
Eric Laurentc8400632013-02-14 19:04:54 -0800158 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 62,
159 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 62,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800160};
161
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800162int edid_get_max_channels(void);
163
Ravi Kumar Alamanda37718842013-02-22 18:44:45 -0800164static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
165static bool is_tmus = false;
166
167static void check_operator()
168{
169 char value[PROPERTY_VALUE_MAX];
170 int mccmnc;
171 property_get("gsm.sim.operator.numeric",value,"0");
172 mccmnc = atoi(value);
173 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
174 switch(mccmnc) {
175 /* TMUS MCC(310), MNC(490, 260, 026) */
176 case 310490:
177 case 310260:
178 case 310026:
179 is_tmus = true;
180 break;
181 }
182}
183
184static bool is_operator_tmus()
185{
186 pthread_once(&check_op_once_ctl, check_operator);
187 return is_tmus;
188}
189
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800190static int get_pcm_device_id(struct audio_route *ar,
191 audio_usecase_t usecase,
192 int device_type)
193{
194 ALOGV("%s: enter: usecase(%d)", __func__, usecase);
195 int device_id;
196 if (device_type == PCM_PLAYBACK)
197 device_id = pcm_device_table[usecase][0];
198 else
199 device_id = pcm_device_table[usecase][1];
200 ALOGV("%s: exit: device_id(%d)", __func__, device_id);
201 return device_id;
202}
203
204static int get_acdb_device_id(snd_device_t snd_device)
205{
206 ALOGV("%s: enter: snd_devie(%d)", __func__, snd_device);
207 int acdb_dev_id = acdb_device_table[snd_device];
208 ALOGV("%s: exit: acdb_dev_id(%d)", __func__, acdb_dev_id);
209 return acdb_dev_id;
210}
211
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800212static void add_backend_name(char *mixer_path,
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800213 struct audio_usecase *usecase)
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800214{
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800215 audio_devices_t in_device;
216 if (usecase->devices & AUDIO_DEVICE_BIT_IN) {
217 in_device = usecase->devices & ~AUDIO_DEVICE_BIT_IN;
218 if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
219 strcat(mixer_path, " bt-sco");
220 }
221 } else {
222 if (usecase->devices & AUDIO_DEVICE_OUT_ALL_SCO) {
223 strcat(mixer_path, " bt-sco");
224 } else if ((usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) &&
225 (usecase->devices & AUDIO_DEVICE_OUT_SPEAKER)) {
226 strcat(mixer_path, " speaker-and-hdmi");
227 } else if (usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
228 strcat(mixer_path, " hdmi");
229 }
230 }
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800231}
232
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800233static int enable_audio_route(struct audio_route *ar,
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800234 struct audio_usecase *usecase)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800235{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800236 char mixer_path[50];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800237
238 if (usecase == NULL)
239 return -EINVAL;
240
241 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
242
243 /* Get the updated devices from associated stream */
244 if (usecase->type == PCM_CAPTURE)
245 usecase->devices = usecase->stream.in->device;
246 else
247 usecase->devices = usecase->stream.out->devices;
248
249 strcpy(mixer_path, use_case_table[usecase->id]);
250 add_backend_name(mixer_path, usecase);
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800251 ALOGD("%s: apply mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800252 audio_route_apply_path(ar, mixer_path);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800253
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800254 ALOGV("%s: exit", __func__);
255 return 0;
256}
257
258static int disable_audio_route(struct audio_route *ar,
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800259 struct audio_usecase *usecase)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800260{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800261 char mixer_path[50];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800262
263 if (usecase == NULL)
264 return -EINVAL;
265
266 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
267
268 strcpy(mixer_path, use_case_table[usecase->id]);
269 add_backend_name(mixer_path, usecase);
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800270 ALOGD("%s: reset mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800271 audio_route_reset_path(ar, mixer_path);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800272
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800273 ALOGV("%s: exit", __func__);
274 return 0;
275}
276
277static int enable_snd_device(struct audio_device *adev,
278 snd_device_t snd_device)
279{
280 int acdb_dev_id, acdb_dev_type;
281
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800282 ALOGD("%s: snd_device(%d: %s)", __func__,
283 snd_device, device_table[snd_device]);
284 if (snd_device < SND_DEVICE_MIN ||
285 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800286 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800287 return -EINVAL;
288 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800289 acdb_dev_id = get_acdb_device_id(snd_device);
290 if (acdb_dev_id < 0) {
291 ALOGE("%s: Could not find acdb id for device(%d)",
292 __func__, snd_device);
293 return -EINVAL;
294 }
295 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800296 snd_device < SND_DEVICE_OUT_END) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800297 acdb_dev_type = ACDB_DEV_TYPE_OUT;
298 } else {
299 acdb_dev_type = ACDB_DEV_TYPE_IN;
300 }
301 if (adev->acdb_send_audio_cal) {
302 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
303 __func__, snd_device, acdb_dev_id);
304 adev->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
305 } else {
306 ALOGW("%s: Could find the symbol acdb_send_audio_cal from %s",
307 __func__, LIB_ACDB_LOADER);
308 }
309
310 audio_route_apply_path(adev->audio_route, device_table[snd_device]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800311 return 0;
312}
313
314static int disable_snd_device(struct audio_route *ar,
315 snd_device_t snd_device)
316{
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800317 ALOGD("%s: snd_device(%d: %s)", __func__,
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800318 snd_device, device_table[snd_device]);
319 if (snd_device < SND_DEVICE_MIN ||
320 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800321 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800322 return -EINVAL;
323 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800324 audio_route_reset_path(ar, device_table[snd_device]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800325 return 0;
326}
327
328static int set_hdmi_channels(struct mixer *mixer,
329 int channel_count)
330{
331 struct mixer_ctl *ctl;
332 const char *channel_cnt_str = NULL;
333 const char *mixer_ctl_name = "HDMI_RX Channels";
334 switch (channel_count) {
335 case 8:
336 channel_cnt_str = "Eight"; break;
337 case 7:
338 channel_cnt_str = "Seven"; break;
339 case 6:
340 channel_cnt_str = "Six"; break;
341 case 5:
342 channel_cnt_str = "Five"; break;
343 case 4:
344 channel_cnt_str = "Four"; break;
345 case 3:
346 channel_cnt_str = "Three"; break;
347 default:
348 channel_cnt_str = "Two"; break;
349 }
350 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
351 if (!ctl) {
352 ALOGE("%s: Could not get ctl for mixer cmd - %s",
353 __func__, mixer_ctl_name);
354 return -EINVAL;
355 }
356 ALOGV("HDMI channel count: %s", channel_cnt_str);
357 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
358 return 0;
359}
360
361/* must be called with hw device mutex locked */
362static void read_hdmi_channel_masks(struct stream_out *out)
363{
364 int channels = edid_get_max_channels();
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800365 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800366
367 switch (channels) {
368 /*
369 * Do not handle stereo output in Multi-channel cases
370 * Stereo case is handled in normal playback path
371 */
372 case 6:
373 ALOGV("%s: HDMI supports 5.1", __func__);
374 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
375 break;
376 case 8:
377 ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__);
378 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
379 out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1;
380 break;
381 default:
382 ALOGE("Unsupported number of channels (%d)", channels);
383 break;
384 }
385
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800386 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800387}
388
389static snd_device_t get_output_snd_device(struct audio_device *adev)
390{
Eric Laurentc8400632013-02-14 19:04:54 -0800391 audio_source_t source = (adev->active_input == NULL) ?
392 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800393 audio_mode_t mode = adev->mode;
394 audio_devices_t devices = adev->out_device;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800395 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800396
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800397 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800398 if (devices == AUDIO_DEVICE_NONE ||
399 devices & AUDIO_DEVICE_BIT_IN) {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800400 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800401 goto exit;
402 }
403
404 if (mode == AUDIO_MODE_IN_CALL) {
405 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
406 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800407 if (adev->tty_mode == TTY_MODE_FULL)
408 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
409 else if (adev->tty_mode == TTY_MODE_VCO)
410 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
411 else if (adev->tty_mode == TTY_MODE_HCO)
412 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
413 else
414 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800415 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
416 snd_device = SND_DEVICE_OUT_BT_SCO;
417 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
418 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
419 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamanda37718842013-02-22 18:44:45 -0800420 if (is_operator_tmus())
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800421 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
422 else
423 snd_device = SND_DEVICE_OUT_HANDSET;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800424 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800425 if (snd_device != SND_DEVICE_NONE) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800426 goto exit;
427 }
428 }
429
430 if (popcount(devices) == 2) {
431 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
432 AUDIO_DEVICE_OUT_SPEAKER)) {
433 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
434 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
435 AUDIO_DEVICE_OUT_SPEAKER)) {
436 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
437 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
438 AUDIO_DEVICE_OUT_SPEAKER)) {
439 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
440 } else {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800441 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800442 goto exit;
443 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800444 if (snd_device != SND_DEVICE_NONE) {
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800445 goto exit;
446 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800447 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800448
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800449 if (popcount(devices) != 1) {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800450 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800451 goto exit;
452 }
453
454 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
455 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
456 snd_device = SND_DEVICE_OUT_HEADPHONES;
457 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
458 snd_device = SND_DEVICE_OUT_SPEAKER;
459 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
460 snd_device = SND_DEVICE_OUT_BT_SCO;
461 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
462 snd_device = SND_DEVICE_OUT_HDMI ;
463 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
464 snd_device = SND_DEVICE_OUT_HANDSET;
465 } else {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800466 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800467 }
468exit:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800469 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800470 return snd_device;
471}
472
473static snd_device_t get_input_snd_device(struct audio_device *adev)
474{
Eric Laurentc8400632013-02-14 19:04:54 -0800475 audio_source_t source = (adev->active_input == NULL) ?
476 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
477
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800478 audio_mode_t mode = adev->mode;
479 audio_devices_t out_device = adev->out_device;
Eric Laurentc8400632013-02-14 19:04:54 -0800480 audio_devices_t in_device = ((adev->active_input == NULL) ?
481 AUDIO_DEVICE_NONE : adev->active_input->device)
482 & ~AUDIO_DEVICE_BIT_IN;
483 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
484 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800485 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800486
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800487 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800488 __func__, out_device, in_device);
489 if (mode == AUDIO_MODE_IN_CALL) {
490 if (out_device == AUDIO_DEVICE_NONE) {
491 ALOGE("%s: No output device set for voice call", __func__);
492 goto exit;
493 }
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800494 if (adev->tty_mode != TTY_MODE_OFF) {
495 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
496 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
497 switch (adev->tty_mode) {
498 case TTY_MODE_FULL:
499 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
500 break;
501 case TTY_MODE_VCO:
502 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
503 break;
504 case TTY_MODE_HCO:
505 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
506 break;
507 default:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800508 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800509 }
510 goto exit;
511 }
512 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800513 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
514 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800515 if (adev->mic_type_analog || adev->fluence_in_voice_call == false) {
516 snd_device = SND_DEVICE_IN_HANDSET_MIC;
517 } else {
518 if (adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
Ravi Kumar Alamanda37718842013-02-22 18:44:45 -0800519 if (is_operator_tmus())
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800520 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
521 else
522 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
523 } else if(adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
524 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
525 else
526 snd_device = SND_DEVICE_IN_HANDSET_MIC;
527 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800528 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
529 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
530 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
531 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
532 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800533 if (adev->fluence_in_voice_call &&
534 adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
535 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
536 } else if (adev->fluence_in_voice_call &&
537 adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
538 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
539 } else {
540 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
541 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800542 }
543 } else if (source == AUDIO_SOURCE_CAMCORDER) {
544 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
545 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
546 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
547 }
548 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
549 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Eric Laurentc8400632013-02-14 19:04:54 -0800550 if (adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
551 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
552 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
553 else if (adev->fluence_in_voice_rec)
554 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
555 else
556 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
557 } else if (adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
558 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
559 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
560 else if (adev->fluence_in_voice_rec)
561 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
562 else
563 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
564 } else
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800565 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800566 }
Ravi Kumar Alamanda8455fa72013-02-19 14:53:19 -0800567 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
568 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
569 in_device = AUDIO_DEVICE_IN_BACK_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800570 } else if (source == AUDIO_SOURCE_DEFAULT) {
571 goto exit;
572 }
573
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800574 if (snd_device != SND_DEVICE_NONE) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800575 goto exit;
576 }
577
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800578 if (in_device != AUDIO_DEVICE_NONE &&
Ravi Kumar Alamanda8455fa72013-02-19 14:53:19 -0800579 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
580 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800581 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800582 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800583 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800584 if (adev->mic_type_analog)
585 snd_device = SND_DEVICE_IN_HANDSET_MIC;
586 else
587 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800588 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
589 snd_device = SND_DEVICE_IN_HEADSET_MIC;
590 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
591 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
592 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
593 snd_device = SND_DEVICE_IN_HDMI_MIC;
594 } else {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800595 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800596 ALOGW("%s: Using default handset-mic", __func__);
597 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800598 }
599 } else {
600 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800601 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800602 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
603 snd_device = SND_DEVICE_IN_HEADSET_MIC;
604 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
605 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
606 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800607 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800608 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800609 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800610 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
611 snd_device = SND_DEVICE_IN_HDMI_MIC;
612 } else {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800613 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800614 ALOGW("%s: Using default handset-mic", __func__);
615 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800616 }
617 }
618exit:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800619 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800620 return snd_device;
621}
622
623static int select_devices(struct audio_device *adev)
624{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800625 snd_device_t out_snd_device = SND_DEVICE_NONE;
626 snd_device_t in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800627 struct audio_usecase *usecase;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800628 struct listnode *node;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800629 int status = 0;
630 int acdb_rx_id, acdb_tx_id;
631 bool in_call_device_switch = false;
632
633 ALOGV("%s: enter", __func__);
634 out_snd_device = get_output_snd_device(adev);
635 in_snd_device = get_input_snd_device(adev);
636
637 if (out_snd_device == adev->cur_out_snd_device && adev->out_snd_device_active &&
638 in_snd_device == adev->cur_in_snd_device && adev->in_snd_device_active) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800639 ALOGV("%s: exit: snd_devices (%d and %d) are already active",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800640 __func__, out_snd_device, in_snd_device);
641 return 0;
642 }
643
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800644 ALOGD("%s: out_snd_device(%d: %s) in_snd_device(%d: %s)", __func__,
645 out_snd_device, device_table[out_snd_device],
646 in_snd_device, device_table[in_snd_device]);
647
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800648 /*
649 * Limitation: While in call, to do a device switch we need to disable
650 * and enable both RX and TX devices though one of them is same as current
651 * device.
652 */
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800653 if (adev->in_call && adev->csd_client != NULL) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800654 in_call_device_switch = true;
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800655 /* This must be called before disabling the mixer controls on APQ side */
656 if (adev->csd_disable_device == NULL) {
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800657 ALOGE("%s: dlsym error for csd_client_disable_device", __func__);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800658 } else {
659 status = adev->csd_disable_device();
660 if (status < 0) {
661 ALOGE("%s: csd_client_disable_device, failed, error %d",
662 __func__, status);
663 }
664 }
665 }
666
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800667 if ((out_snd_device != adev->cur_out_snd_device || in_call_device_switch)
668 && adev->out_snd_device_active) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800669 list_for_each(node, &adev->usecase_list) {
670 usecase = node_to_item(node, struct audio_usecase, list);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800671 if (usecase->type == PCM_PLAYBACK || usecase->type == VOICE_CALL)
672 disable_audio_route(adev->audio_route, usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800673 }
674 audio_route_update_mixer(adev->audio_route);
675 /* Disable current rx device */
676 disable_snd_device(adev->audio_route, adev->cur_out_snd_device);
677 adev->out_snd_device_active = false;
678 }
679
680 if ((in_snd_device != adev->cur_in_snd_device || in_call_device_switch)
681 && adev->in_snd_device_active) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800682 list_for_each(node, &adev->usecase_list) {
683 usecase = node_to_item(node, struct audio_usecase, list);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800684 if (usecase->type == PCM_CAPTURE)
685 disable_audio_route(adev->audio_route, usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800686 }
687 audio_route_update_mixer(adev->audio_route);
688 /* Disable current tx device */
689 disable_snd_device(adev->audio_route, adev->cur_in_snd_device);
690 adev->in_snd_device_active = false;
691 }
692
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800693 if (out_snd_device != SND_DEVICE_NONE && !adev->out_snd_device_active) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800694 /* Enable new rx device */
695 status = enable_snd_device(adev, out_snd_device);
696 if (status != 0) {
697 ALOGE("%s: Failed to set mixer ctls for snd_device(%d)",
698 __func__, out_snd_device);
699 return status;
700 }
701 adev->out_snd_device_active = true;
702 adev->cur_out_snd_device = out_snd_device;
703 }
704
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800705 if (in_snd_device != SND_DEVICE_NONE && !adev->in_snd_device_active) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800706 /* Enable new tx device */
707 status = enable_snd_device(adev, in_snd_device);
708 if (status != 0) {
709 ALOGE("%s: Failed to set mixer ctls for snd_device(%d)",
710 __func__, out_snd_device);
711 return status;
712 }
713 adev->in_snd_device_active = true;
714 adev->cur_in_snd_device = in_snd_device;
715 }
716 audio_route_update_mixer(adev->audio_route);
717
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800718 if (!list_empty(&adev->usecase_list)) {
719 list_for_each(node, &adev->usecase_list) {
720 usecase = node_to_item(node, struct audio_usecase, list);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800721 enable_audio_route(adev->audio_route, usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800722 }
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800723 audio_route_update_mixer(adev->audio_route);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800724 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800725
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800726 if (adev->mode == AUDIO_MODE_IN_CALL && adev->csd_client) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800727 if (adev->csd_enable_device == NULL) {
728 ALOGE("%s: dlsym error for csd_client_enable_device",
729 __func__);
730 } else {
731 acdb_rx_id = get_acdb_device_id(out_snd_device);
732 acdb_tx_id = get_acdb_device_id(in_snd_device);
733
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800734 status = adev->csd_enable_device(acdb_rx_id, acdb_tx_id,
735 adev->acdb_settings);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800736 if (status < 0) {
737 ALOGE("%s: csd_client_enable_device, failed, error %d",
738 __func__, status);
739 }
740 }
741 }
742
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800743 ALOGV("%s: exit: status(%d)", __func__, status);
744 return status;
745}
746
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800747static struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
748 audio_usecase_t uc_id)
749{
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800750 struct audio_usecase *usecase = NULL;
751 struct listnode *node;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800752
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800753 list_for_each(node, &adev->usecase_list) {
754 usecase = node_to_item(node, struct audio_usecase, list);
755 if (usecase->id == uc_id)
756 break;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800757 }
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800758 return usecase;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800759}
760
761static audio_devices_t get_active_out_devices(struct audio_device *adev,
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800762 audio_usecase_t uc_id)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800763{
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800764 audio_devices_t devices = AUDIO_DEVICE_NONE;
765 struct audio_usecase *usecase;
766 struct listnode *node;
767
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800768 /* Return the output devices of usecases other than given usecase */
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800769 list_for_each(node, &adev->usecase_list) {
770 usecase = node_to_item(node, struct audio_usecase, list);
771 if (usecase->type == PCM_PLAYBACK && usecase->id != uc_id)
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800772 devices |= usecase->stream.out->devices;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800773 }
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800774
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800775 return devices;
776}
777
778static audio_devices_t get_voice_call_out_device(struct audio_device *adev)
779{
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800780 struct audio_usecase *usecase;
781 struct listnode *node;
782
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800783 list_for_each(node, &adev->usecase_list) {
784 usecase = node_to_item(node, struct audio_usecase, list);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800785 if (usecase->type == VOICE_CALL)
786 return usecase->stream.out->devices;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800787 }
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800788
789 return AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800790}
791
792static int stop_input_stream(struct stream_in *in)
793{
794 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800795 struct audio_usecase *uc_info;
796 struct audio_device *adev = in->dev;
797
Eric Laurentc8400632013-02-14 19:04:54 -0800798 adev->active_input = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800799
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800800 ALOGD("%s: enter: usecase(%d)", __func__, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800801 uc_info = get_usecase_from_list(adev, in->usecase);
802 if (uc_info == NULL) {
803 ALOGE("%s: Could not find the usecase (%d) in the list",
804 __func__, in->usecase);
805 return -EINVAL;
806 }
807
Eric Laurent150dbfe2013-02-27 14:31:02 -0800808 /* 1. Disable stream specific mixer controls */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800809 disable_audio_route(adev->audio_route, uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800810 audio_route_update_mixer(adev->audio_route);
811
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800812 list_remove(&uc_info->list);
813 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800814
Eric Laurent150dbfe2013-02-27 14:31:02 -0800815 /* 2. Disable the tx device */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800816 ret = select_devices(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800817
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800818 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800819 return ret;
820}
821
822int start_input_stream(struct stream_in *in)
823{
824 /* 1. Enable output device and stream routing controls */
Eric Laurentc8400632013-02-14 19:04:54 -0800825 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800826 snd_device_t in_snd_device;
827 struct audio_usecase *uc_info;
828 struct audio_device *adev = in->dev;
829
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800830 ALOGD("%s: enter: usecase(%d)", __func__, in->usecase);
Eric Laurentc8400632013-02-14 19:04:54 -0800831 adev->active_input = in;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800832 in_snd_device = get_input_snd_device(adev);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800833 if (in_snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800834 ALOGE("%s: Could not get valid input sound device", __func__);
Eric Laurentc8400632013-02-14 19:04:54 -0800835 ret = -EINVAL;
836 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800837 }
838
839 in->pcm_device_id = get_pcm_device_id(adev->audio_route,
840 in->usecase,
841 PCM_CAPTURE);
842 if (in->pcm_device_id < 0) {
843 ALOGE("%s: Could not find PCM device id for the usecase(%d)",
844 __func__, in->usecase);
Eric Laurentc8400632013-02-14 19:04:54 -0800845 ret = -EINVAL;
846 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800847 }
848 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
849 uc_info->id = in->usecase;
850 uc_info->type = PCM_CAPTURE;
851 uc_info->devices = in->device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800852 uc_info->stream.in = in;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800853
854 /* 1. Enable the TX device */
855 ret = select_devices(adev);
856 if (ret) {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800857 ALOGE("%s: Failed to enable device(%#x)",
Eric Laurentc8400632013-02-14 19:04:54 -0800858 __func__, in->device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800859 free(uc_info);
Eric Laurentc8400632013-02-14 19:04:54 -0800860 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800861 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800862
863 /* 2. Enable the mixer controls for the audio route */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800864 enable_audio_route(adev->audio_route, uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800865 audio_route_update_mixer(adev->audio_route);
866
867 /* 3. Add the usecase info to usecase list */
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800868 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800869
870 /* 2. Open the pcm device */
Eric Laurentc8400632013-02-14 19:04:54 -0800871 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d",
872 __func__, SOUND_CARD, in->pcm_device_id, in->config.channels);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800873 in->pcm = pcm_open(SOUND_CARD, in->pcm_device_id,
874 PCM_IN, &in->config);
875 if (in->pcm && !pcm_is_ready(in->pcm)) {
876 ALOGE("%s: %s", __func__, pcm_get_error(in->pcm));
877 pcm_close(in->pcm);
878 in->pcm = NULL;
Eric Laurentc8400632013-02-14 19:04:54 -0800879 ret = -EIO;
880 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800881 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800882 ALOGD("%s: exit", __func__);
Eric Laurentc8400632013-02-14 19:04:54 -0800883 return ret;
884
885error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800886 stop_input_stream(in);
Eric Laurentc8400632013-02-14 19:04:54 -0800887
888error_config:
889 adev->active_input = NULL;
890 ALOGV("%s: exit: status(%d)", __func__, ret);
891
892 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800893}
894
895static int stop_output_stream(struct stream_out *out)
896{
897 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800898 struct audio_usecase *uc_info;
899 struct audio_device *adev = out->dev;
900
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800901 ALOGD("%s: enter: usecase(%d)", __func__, out->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800902 uc_info = get_usecase_from_list(adev, out->usecase);
903 if (uc_info == NULL) {
904 ALOGE("%s: Could not find the usecase (%d) in the list",
905 __func__, out->usecase);
906 return -EINVAL;
907 }
908
Eric Laurent150dbfe2013-02-27 14:31:02 -0800909 /* 1. Get and set stream specific mixer controls */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800910 disable_audio_route(adev->audio_route, uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800911 audio_route_update_mixer(adev->audio_route);
912
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800913 list_remove(&uc_info->list);
914 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800915
Eric Laurent150dbfe2013-02-27 14:31:02 -0800916 /* 2. Disable the rx device */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800917 adev->out_device = get_active_out_devices(adev, out->usecase);
918 adev->out_device |= get_voice_call_out_device(adev);
919 ret = select_devices(adev);
920
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800921 ALOGD("%s: exit: status(%d) adev->out_device(%#x)",
922 __func__, ret, adev->out_device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800923 return ret;
924}
925
926int start_output_stream(struct stream_out *out)
927{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800928 int ret = 0;
929 snd_device_t out_snd_device;
930 struct audio_usecase *uc_info;
931 struct audio_device *adev = out->dev;
932
933 /* 1. Enable output device and stream routing controls */
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800934 ALOGD("%s: enter: usecase(%d) devices(%#x)",
935 __func__, out->usecase, out->devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800936 adev->out_device |= out->devices;
937 out_snd_device = get_output_snd_device(adev);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800938 if (out_snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800939 ALOGE("%s: Could not get valid output sound device", __func__);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800940 ret = -EINVAL;
941 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800942 }
943
944 out->pcm_device_id = get_pcm_device_id(adev->audio_route,
945 out->usecase,
946 PCM_PLAYBACK);
947 if (out->pcm_device_id < 0) {
948 ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)",
949 __func__, out->pcm_device_id, out->usecase);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800950 ret = -EINVAL;
951 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800952 }
953
954 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
955 uc_info->id = out->usecase;
956 uc_info->type = PCM_PLAYBACK;
957 uc_info->devices = out->devices;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800958 uc_info->stream.out = out;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800959
960 ret = select_devices(adev);
961 if (ret) {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800962 ALOGE("%s: Failed to enable device(%#x)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800963 __func__, adev->out_device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800964 free(uc_info);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800965 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800966 }
967
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800968 enable_audio_route(adev->audio_route, uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800969 audio_route_update_mixer(adev->audio_route);
970
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800971 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800972
973 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
974 __func__, 0, out->pcm_device_id);
975 out->pcm = pcm_open(SOUND_CARD, out->pcm_device_id,
976 PCM_OUT, &out->config);
977 if (out->pcm && !pcm_is_ready(out->pcm)) {
978 ALOGE("%s: %s", __func__, pcm_get_error(out->pcm));
979 pcm_close(out->pcm);
980 out->pcm = NULL;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800981 ret = -EIO;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800982 goto error;
983 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800984 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800985 return 0;
986error:
987 stop_output_stream(out);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800988error_config:
989 adev->out_device = get_active_out_devices(adev, out->usecase);
990 adev->out_device |= get_voice_call_out_device(adev);
991 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800992}
993
994static int stop_voice_call(struct audio_device *adev)
995{
996 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800997 struct audio_usecase *uc_info;
998
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800999 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001000 adev->in_call = false;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001001 if (adev->csd_client) {
1002 if (adev->csd_stop_voice == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001003 ALOGE("dlsym error for csd_client_disable_device");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001004 } else {
1005 ret = adev->csd_stop_voice();
1006 if (ret < 0) {
1007 ALOGE("%s: csd_client error %d\n", __func__, ret);
1008 }
1009 }
1010 }
1011
1012 /* 1. Close the PCM devices */
1013 if (adev->voice_call_rx) {
1014 pcm_close(adev->voice_call_rx);
1015 adev->voice_call_rx = NULL;
1016 }
1017 if (adev->voice_call_tx) {
1018 pcm_close(adev->voice_call_tx);
1019 adev->voice_call_tx = NULL;
1020 }
1021
1022 uc_info = get_usecase_from_list(adev, USECASE_VOICE_CALL);
1023 if (uc_info == NULL) {
1024 ALOGE("%s: Could not find the usecase (%d) in the list",
1025 __func__, USECASE_VOICE_CALL);
1026 return -EINVAL;
1027 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001028
1029 /* 2. Get and set stream specific mixer controls */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001030 disable_audio_route(adev->audio_route, uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001031 audio_route_update_mixer(adev->audio_route);
1032
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001033 list_remove(&uc_info->list);
1034 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001035
1036 /* 3. Disable the rx and tx devices */
1037 ret = select_devices(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001038
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001039 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001040 return ret;
1041}
1042
1043static int start_voice_call(struct audio_device *adev)
1044{
1045 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001046 struct audio_usecase *uc_info;
1047 int pcm_dev_rx_id, pcm_dev_tx_id;
1048
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001049 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001050
1051 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
1052 uc_info->id = USECASE_VOICE_CALL;
1053 uc_info->type = VOICE_CALL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001054 uc_info->devices = adev->primary_output->devices;
1055 uc_info->stream.out = adev->primary_output;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001056
1057 ret = select_devices(adev);
1058 if (ret) {
1059 free(uc_info);
1060 return ret;
1061 }
1062
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001063 enable_audio_route(adev->audio_route, uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001064 audio_route_update_mixer(adev->audio_route);
1065
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001066 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001067
1068 pcm_dev_rx_id = get_pcm_device_id(adev->audio_route, uc_info->id,
1069 PCM_PLAYBACK);
1070 pcm_dev_tx_id = get_pcm_device_id(adev->audio_route, uc_info->id,
1071 PCM_CAPTURE);
1072
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001073 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
1074 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
1075 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001076 ret = -EIO;
1077 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001078 }
1079
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001080 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001081 __func__, SOUND_CARD, pcm_dev_rx_id);
1082 adev->voice_call_rx = pcm_open(SOUND_CARD,
1083 pcm_dev_rx_id,
1084 PCM_OUT, &pcm_config_voice_call);
1085 if (adev->voice_call_rx && !pcm_is_ready(adev->voice_call_rx)) {
1086 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_rx));
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001087 ret = -EIO;
1088 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001089 }
1090
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001091 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001092 __func__, SOUND_CARD, pcm_dev_tx_id);
1093 adev->voice_call_tx = pcm_open(SOUND_CARD,
1094 pcm_dev_tx_id,
1095 PCM_IN, &pcm_config_voice_call);
1096 if (adev->voice_call_tx && !pcm_is_ready(adev->voice_call_tx)) {
1097 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_tx));
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001098 ret = -EIO;
1099 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001100 }
1101 pcm_start(adev->voice_call_rx);
1102 pcm_start(adev->voice_call_tx);
1103
1104 if (adev->csd_client) {
1105 if (adev->csd_start_voice == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001106 ALOGE("dlsym error for csd_client_start_voice");
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001107 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001108 } else {
1109 ret = adev->csd_start_voice();
1110 if (ret < 0) {
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001111 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1112 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001113 }
1114 }
1115 }
1116
1117 adev->in_call = true;
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001118 return 0;
1119
1120error_start_voice:
1121 stop_voice_call(adev);
1122
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001123 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001124 return ret;
1125}
1126
1127static int check_input_parameters(uint32_t sample_rate,
1128 audio_format_t format,
1129 int channel_count)
1130{
1131 if (format != AUDIO_FORMAT_PCM_16_BIT) return -EINVAL;
1132
1133 if ((channel_count < 1) || (channel_count > 2)) return -EINVAL;
1134
1135 switch (sample_rate) {
1136 case 8000:
1137 case 11025:
1138 case 12000:
1139 case 16000:
1140 case 22050:
1141 case 24000:
1142 case 32000:
1143 case 44100:
1144 case 48000:
1145 break;
1146 default:
1147 return -EINVAL;
1148 }
1149
1150 return 0;
1151}
1152
1153static size_t get_input_buffer_size(uint32_t sample_rate,
1154 audio_format_t format,
1155 int channel_count)
1156{
1157 size_t size = 0;
1158
1159 if (check_input_parameters(sample_rate, format, channel_count) != 0) return 0;
1160
1161 if (sample_rate == 8000 || sample_rate == 16000 || sample_rate == 32000) {
1162 size = (sample_rate * 20) / 1000;
1163 } else if (sample_rate == 11025 || sample_rate == 12000) {
1164 size = 256;
1165 } else if (sample_rate == 22050 || sample_rate == 24000) {
1166 size = 512;
1167 } else if (sample_rate == 44100 || sample_rate == 48000) {
1168 size = 1024;
1169 }
1170
1171 return size * sizeof(short) * channel_count;
1172}
1173
1174static uint32_t out_get_sample_rate(const struct audio_stream *stream)
1175{
1176 struct stream_out *out = (struct stream_out *)stream;
1177
1178 return out->config.rate;
1179}
1180
1181static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1182{
1183 return -ENOSYS;
1184}
1185
1186static size_t out_get_buffer_size(const struct audio_stream *stream)
1187{
1188 struct stream_out *out = (struct stream_out *)stream;
1189
1190 return out->config.period_size * audio_stream_frame_size(stream);
1191}
1192
1193static uint32_t out_get_channels(const struct audio_stream *stream)
1194{
1195 struct stream_out *out = (struct stream_out *)stream;
1196
1197 return out->channel_mask;
1198}
1199
1200static audio_format_t out_get_format(const struct audio_stream *stream)
1201{
1202 return AUDIO_FORMAT_PCM_16_BIT;
1203}
1204
1205static int out_set_format(struct audio_stream *stream, audio_format_t format)
1206{
1207 return -ENOSYS;
1208}
1209
1210static int out_standby(struct audio_stream *stream)
1211{
1212 struct stream_out *out = (struct stream_out *)stream;
1213 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001214 ALOGD("%s: enter: usecase(%d)", __func__, out->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001215 pthread_mutex_lock(&out->lock);
1216
1217 if (!out->standby) {
1218 out->standby = true;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001219 if (out->pcm) {
1220 pcm_close(out->pcm);
1221 out->pcm = NULL;
1222 }
1223 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001224 stop_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001225 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001226 }
1227 pthread_mutex_unlock(&out->lock);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001228 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001229 return 0;
1230}
1231
1232static int out_dump(const struct audio_stream *stream, int fd)
1233{
1234 return 0;
1235}
1236
1237static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
1238{
1239 struct stream_out *out = (struct stream_out *)stream;
1240 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001241 struct audio_usecase *usecase;
1242 struct listnode *node;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001243 struct str_parms *parms;
1244 char value[32];
1245 int ret, val = 0;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001246 bool select_new_device = false;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001247
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001248 ALOGD("%s: enter: usecase(%d) kvpairs: %s",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001249 __func__, out->usecase, kvpairs);
1250 parms = str_parms_create_str(kvpairs);
1251 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1252 if (ret >= 0) {
1253 val = atoi(value);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001254 pthread_mutex_lock(&out->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001255 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001256
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001257 if (val != 0) {
1258 /* ToDo: Fix device updation logic */
1259 list_for_each(node, &adev->usecase_list) {
1260 usecase = node_to_item(node, struct audio_usecase, list);
1261 if ((usecase->type == PCM_PLAYBACK || usecase->type == VOICE_CALL)
1262 && usecase->stream.out != out)
1263 usecase->stream.out->devices = val;
1264 }
1265 }
1266
1267 adev->out_device = get_active_out_devices(adev, out->usecase) | val;
1268 if ((adev->mode == AUDIO_MODE_IN_CALL) && !adev->in_call &&
1269 (out == adev->primary_output) && (val != 0)) {
Ravi Kumar Alamanda8455fa72013-02-19 14:53:19 -08001270 out->devices = val;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001271 start_voice_call(adev);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001272 } else if ((adev->mode != AUDIO_MODE_IN_CALL) && adev->in_call &&
1273 (out == adev->primary_output)) {
Ravi Kumar Alamanda8455fa72013-02-19 14:53:19 -08001274 if (val != 0) {
Ravi Kumar Alamanda8455fa72013-02-19 14:53:19 -08001275 out->devices = val;
1276 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001277 stop_voice_call(adev);
Ravi Kumar Alamandaa995a352013-02-22 13:00:21 -08001278 } else if ((out->devices != (audio_devices_t)val) && (val != 0)) {
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001279 /* Update the devices so that select_devices() enables the new devies */
1280 out->devices = val;
1281 if ((adev->in_call && (out == adev->primary_output)) ||
1282 !out->standby) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001283 ret = select_devices(adev);
1284 }
1285 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001286
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001287 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001288 pthread_mutex_unlock(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001289 }
1290 str_parms_destroy(parms);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001291 ALOGD("%s: exit: code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001292 return ret;
1293}
1294
1295static char* out_get_parameters(const struct audio_stream *stream, const char *keys)
1296{
1297 struct stream_out *out = (struct stream_out *)stream;
1298 struct str_parms *query = str_parms_create_str(keys);
1299 char *str;
1300 char value[256];
1301 struct str_parms *reply = str_parms_create();
1302 size_t i, j;
1303 int ret;
1304 bool first = true;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001305 ALOGD("%s: enter: keys - %s", __func__, keys);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001306 ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value));
1307 if (ret >= 0) {
1308 value[0] = '\0';
1309 i = 0;
1310 while (out->supported_channel_masks[i] != 0) {
1311 for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) {
1312 if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) {
1313 if (!first) {
1314 strcat(value, "|");
1315 }
1316 strcat(value, out_channels_name_to_enum_table[j].name);
1317 first = false;
1318 break;
1319 }
1320 }
1321 i++;
1322 }
1323 str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value);
1324 str = str_parms_to_str(reply);
1325 } else {
1326 str = strdup(keys);
1327 }
1328 str_parms_destroy(query);
1329 str_parms_destroy(reply);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001330 ALOGD("%s: exit: returns - %s", __func__, str);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001331 return str;
1332}
1333
1334static uint32_t out_get_latency(const struct audio_stream_out *stream)
1335{
1336 struct stream_out *out = (struct stream_out *)stream;
1337
1338 return (out->config.period_count * out->config.period_size * 1000) / (out->config.rate);
1339}
1340
1341static int out_set_volume(struct audio_stream_out *stream, float left,
1342 float right)
1343{
1344 return -ENOSYS;
1345}
1346
1347static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
1348 size_t bytes)
1349{
1350 struct stream_out *out = (struct stream_out *)stream;
1351 struct audio_device *adev = out->dev;
1352 int i, ret = -1;
1353
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001354 pthread_mutex_lock(&out->lock);
1355 if (out->standby) {
Eric Laurent150dbfe2013-02-27 14:31:02 -08001356 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001357 ret = start_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001358 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001359 if (ret != 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001360 goto exit;
1361 }
1362 out->standby = false;
1363 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001364
1365 if (out->pcm) {
1366 //ALOGV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes);
1367 ret = pcm_write(out->pcm, (void *)buffer, bytes);
1368 }
1369
1370exit:
1371 pthread_mutex_unlock(&out->lock);
1372
1373 if (ret != 0) {
1374 out_standby(&out->stream.common);
1375 usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) /
1376 out_get_sample_rate(&out->stream.common));
1377 }
1378 return bytes;
1379}
1380
1381static int out_get_render_position(const struct audio_stream_out *stream,
1382 uint32_t *dsp_frames)
1383{
1384 return -EINVAL;
1385}
1386
1387static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1388{
1389 return 0;
1390}
1391
1392static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1393{
1394 return 0;
1395}
1396
1397static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
1398 int64_t *timestamp)
1399{
1400 return -EINVAL;
1401}
1402
1403/** audio_stream_in implementation **/
1404static uint32_t in_get_sample_rate(const struct audio_stream *stream)
1405{
1406 struct stream_in *in = (struct stream_in *)stream;
1407
1408 return in->config.rate;
1409}
1410
1411static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1412{
1413 return -ENOSYS;
1414}
1415
1416static size_t in_get_buffer_size(const struct audio_stream *stream)
1417{
1418 struct stream_in *in = (struct stream_in *)stream;
1419
1420 return in->config.period_size * audio_stream_frame_size(stream);
1421}
1422
1423static uint32_t in_get_channels(const struct audio_stream *stream)
1424{
1425 struct stream_in *in = (struct stream_in *)stream;
1426
1427 return in->channel_mask;
1428}
1429
1430static audio_format_t in_get_format(const struct audio_stream *stream)
1431{
1432 return AUDIO_FORMAT_PCM_16_BIT;
1433}
1434
1435static int in_set_format(struct audio_stream *stream, audio_format_t format)
1436{
1437 return -ENOSYS;
1438}
1439
1440static int in_standby(struct audio_stream *stream)
1441{
1442 struct stream_in *in = (struct stream_in *)stream;
1443 struct audio_device *adev = in->dev;
1444 int status = 0;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001445 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001446 pthread_mutex_lock(&in->lock);
1447 if (!in->standby) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001448 in->standby = true;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001449 if (in->pcm) {
1450 pcm_close(in->pcm);
1451 in->pcm = NULL;
1452 }
1453 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001454 status = stop_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001455 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001456 }
1457 pthread_mutex_unlock(&in->lock);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001458 ALOGD("%s: exit: status(%d)", __func__, status);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001459 return status;
1460}
1461
1462static int in_dump(const struct audio_stream *stream, int fd)
1463{
1464 return 0;
1465}
1466
1467static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
1468{
1469 struct stream_in *in = (struct stream_in *)stream;
1470 struct audio_device *adev = in->dev;
1471 struct str_parms *parms;
1472 char *str;
1473 char value[32];
1474 int ret, val = 0;
1475
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001476 ALOGD("%s: enter: kvpairs=%s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001477 parms = str_parms_create_str(kvpairs);
1478
1479 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value));
1480
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001481 pthread_mutex_lock(&in->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001482 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001483 if (ret >= 0) {
1484 val = atoi(value);
1485 /* no audio source uses val == 0 */
1486 if ((in->source != val) && (val != 0)) {
1487 in->source = val;
1488 }
1489 }
1490
1491 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1492 if (ret >= 0) {
1493 val = atoi(value);
1494 if ((in->device != val) && (val != 0)) {
1495 in->device = val;
1496 /* If recording is in progress, change the tx device to new device */
1497 if (!in->standby) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001498 ret = select_devices(adev);
1499 }
1500 }
1501 }
1502
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001503 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001504 pthread_mutex_unlock(&in->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001505
1506 str_parms_destroy(parms);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001507 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001508 return ret;
1509}
1510
1511static char* in_get_parameters(const struct audio_stream *stream,
1512 const char *keys)
1513{
1514 return strdup("");
1515}
1516
1517static int in_set_gain(struct audio_stream_in *stream, float gain)
1518{
1519 return 0;
1520}
1521
1522static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
1523 size_t bytes)
1524{
1525 struct stream_in *in = (struct stream_in *)stream;
1526 struct audio_device *adev = in->dev;
1527 int i, ret = -1;
1528
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001529 //ALOGV("%s: buffer(%p) bytes(%d)", __func__, buffer, bytes);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001530 pthread_mutex_lock(&in->lock);
1531 if (in->standby) {
Eric Laurent150dbfe2013-02-27 14:31:02 -08001532 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001533 ret = start_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001534 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001535 if (ret != 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001536 goto exit;
1537 }
1538 in->standby = 0;
1539 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001540
1541 if (in->pcm) {
1542 ret = pcm_read(in->pcm, buffer, bytes);
1543 }
1544
1545 /*
1546 * Instead of writing zeroes here, we could trust the hardware
1547 * to always provide zeroes when muted.
1548 */
1549 if (ret == 0 && adev->mic_mute)
1550 memset(buffer, 0, bytes);
1551
1552exit:
1553 pthread_mutex_unlock(&in->lock);
1554
1555 if (ret != 0) {
1556 in_standby(&in->stream.common);
1557 ALOGV("%s: read failed - sleeping for buffer duration", __func__);
1558 usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) /
1559 in_get_sample_rate(&in->stream.common));
1560 }
1561 return bytes;
1562}
1563
1564static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
1565{
1566 return 0;
1567}
1568
1569static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1570{
1571 return 0;
1572}
1573
1574static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1575{
1576 return 0;
1577}
1578
1579static int adev_open_output_stream(struct audio_hw_device *dev,
1580 audio_io_handle_t handle,
1581 audio_devices_t devices,
1582 audio_output_flags_t flags,
1583 struct audio_config *config,
1584 struct audio_stream_out **stream_out)
1585{
1586 struct audio_device *adev = (struct audio_device *)dev;
1587 struct stream_out *out;
1588 int i, ret;
1589
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001590 ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001591 __func__, config->sample_rate, config->channel_mask, devices, flags);
1592 *stream_out = NULL;
1593 out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
1594
1595 if (devices == AUDIO_DEVICE_NONE)
1596 devices = AUDIO_DEVICE_OUT_SPEAKER;
1597
1598 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;
1599 out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
1600 out->flags = flags;
1601 out->devices = devices;
1602
1603 /* Init use case and pcm_config */
1604 if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT &&
1605 out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1606 out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH;
1607 out->config = pcm_config_hdmi_multi;
1608
1609 pthread_mutex_lock(&adev->lock);
1610 read_hdmi_channel_masks(out);
1611 pthread_mutex_unlock(&adev->lock);
1612
1613 if (config->sample_rate == 0) config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
1614 if (config->channel_mask == 0) config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1;
1615 out->channel_mask = config->channel_mask;
1616 out->config.rate = config->sample_rate;
1617 out->config.channels = popcount(out->channel_mask);
1618 out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2);
1619 set_hdmi_channels(adev->mixer, out->config.channels);
1620 } else if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) {
1621 out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER;
1622 out->config = pcm_config_deep_buffer;
1623 } else {
1624 out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY;
1625 out->config = pcm_config_low_latency;
1626 }
1627
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001628 if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) {
1629 if(adev->primary_output == NULL)
1630 adev->primary_output = out;
1631 else {
1632 ALOGE("%s: Primary output is already opened", __func__);
1633 return -EEXIST;
1634 }
1635 }
1636
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001637 /* Check if this usecase is already existing */
1638 pthread_mutex_lock(&adev->lock);
1639 if (get_usecase_from_list(adev, out->usecase) != NULL) {
1640 ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase);
1641 free(out);
1642 *stream_out = NULL;
1643 pthread_mutex_unlock(&adev->lock);
1644 return -EEXIST;
1645 }
1646 pthread_mutex_unlock(&adev->lock);
1647
1648 out->stream.common.get_sample_rate = out_get_sample_rate;
1649 out->stream.common.set_sample_rate = out_set_sample_rate;
1650 out->stream.common.get_buffer_size = out_get_buffer_size;
1651 out->stream.common.get_channels = out_get_channels;
1652 out->stream.common.get_format = out_get_format;
1653 out->stream.common.set_format = out_set_format;
1654 out->stream.common.standby = out_standby;
1655 out->stream.common.dump = out_dump;
1656 out->stream.common.set_parameters = out_set_parameters;
1657 out->stream.common.get_parameters = out_get_parameters;
1658 out->stream.common.add_audio_effect = out_add_audio_effect;
1659 out->stream.common.remove_audio_effect = out_remove_audio_effect;
1660 out->stream.get_latency = out_get_latency;
1661 out->stream.set_volume = out_set_volume;
1662 out->stream.write = out_write;
1663 out->stream.get_render_position = out_get_render_position;
1664 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
1665
1666 out->dev = adev;
1667 out->standby = 1;
1668
1669 config->format = out->stream.common.get_format(&out->stream.common);
1670 config->channel_mask = out->stream.common.get_channels(&out->stream.common);
1671 config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common);
1672
1673 *stream_out = &out->stream;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001674 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001675 return 0;
1676}
1677
1678static void adev_close_output_stream(struct audio_hw_device *dev,
1679 struct audio_stream_out *stream)
1680{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001681 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001682 out_standby(&stream->common);
1683 free(stream);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001684 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001685}
1686
1687static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
1688{
1689 struct audio_device *adev = (struct audio_device *)dev;
1690 struct str_parms *parms;
1691 char *str;
1692 char value[32];
1693 int ret;
1694
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001695 ALOGD("%s: enter: %s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001696
1697 parms = str_parms_create_str(kvpairs);
1698 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
1699 if (ret >= 0) {
1700 int tty_mode;
1701
1702 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
1703 tty_mode = TTY_MODE_OFF;
1704 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
1705 tty_mode = TTY_MODE_VCO;
1706 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
1707 tty_mode = TTY_MODE_HCO;
1708 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
1709 tty_mode = TTY_MODE_FULL;
1710 else
1711 return -EINVAL;
1712
1713 pthread_mutex_lock(&adev->lock);
1714 if (tty_mode != adev->tty_mode) {
1715 adev->tty_mode = tty_mode;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08001716 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
1717 if (adev->in_call)
1718 select_devices(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001719 }
1720 pthread_mutex_unlock(&adev->lock);
1721 }
1722
1723 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
1724 if (ret >= 0) {
1725 /* When set to false, HAL should disable EC and NS
1726 * But it is currently not supported.
1727 */
1728 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1729 adev->bluetooth_nrec = true;
1730 else
1731 adev->bluetooth_nrec = false;
1732 }
1733
1734 ret = str_parms_get_str(parms, "screen_state", value, sizeof(value));
1735 if (ret >= 0) {
1736 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1737 adev->screen_off = false;
1738 else
1739 adev->screen_off = true;
1740 }
1741
1742 str_parms_destroy(parms);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001743 ALOGD("%s: exit with code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001744 return ret;
1745}
1746
1747static char* adev_get_parameters(const struct audio_hw_device *dev,
1748 const char *keys)
1749{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001750 return strdup("");
1751}
1752
1753static int adev_init_check(const struct audio_hw_device *dev)
1754{
1755 return 0;
1756}
1757
1758static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
1759{
1760 struct audio_device *adev = (struct audio_device *)dev;
1761 int vol, err = 0;
1762
1763 pthread_mutex_lock(&adev->lock);
1764 adev->voice_volume = volume;
1765 if (adev->mode == AUDIO_MODE_IN_CALL) {
1766 if (volume < 0.0) {
1767 volume = 0.0;
1768 } else if (volume > 1.0) {
1769 volume = 1.0;
1770 }
1771
1772 vol = lrint(volume * 100.0);
1773
1774 // Voice volume levels from android are mapped to driver volume levels as follows.
1775 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
1776 // So adjust the volume to get the correct volume index in driver
1777 vol = 100 - vol;
1778
1779 if (adev->csd_client) {
1780 if (adev->csd_volume == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001781 ALOGE("%s: dlsym error for csd_client_volume", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001782 } else {
1783 err = adev->csd_volume(vol);
1784 if (err < 0) {
1785 ALOGE("%s: csd_client error %d", __func__, err);
1786 }
1787 }
1788 } else {
1789 ALOGE("%s: No CSD Client present", __func__);
1790 }
1791 }
1792 pthread_mutex_unlock(&adev->lock);
1793 return err;
1794}
1795
1796static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
1797{
1798 return -ENOSYS;
1799}
1800
1801static int adev_get_master_volume(struct audio_hw_device *dev,
1802 float *volume)
1803{
1804 return -ENOSYS;
1805}
1806
1807static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
1808{
1809 return -ENOSYS;
1810}
1811
1812static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
1813{
1814 return -ENOSYS;
1815}
1816
1817static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
1818{
1819 struct audio_device *adev = (struct audio_device *)dev;
1820
1821 pthread_mutex_lock(&adev->lock);
1822 if (adev->mode != mode) {
1823 adev->mode = mode;
1824 }
1825 pthread_mutex_unlock(&adev->lock);
1826 return 0;
1827}
1828
1829static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
1830{
1831 struct audio_device *adev = (struct audio_device *)dev;
1832 int err = 0;
1833
1834 adev->mic_mute = state;
1835 if (adev->mode == AUDIO_MODE_IN_CALL) {
1836 if (adev->csd_client) {
1837 if (adev->csd_mic_mute == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001838 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001839 } else {
1840 err = adev->csd_mic_mute(state);
1841 if (err < 0) {
1842 ALOGE("%s: csd_client error %d", __func__, err);
1843 }
1844 }
1845 } else {
1846 ALOGE("%s: No CSD Client present", __func__);
1847 }
1848 }
1849 return err;
1850}
1851
1852static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
1853{
1854 struct audio_device *adev = (struct audio_device *)dev;
1855
1856 *state = adev->mic_mute;
1857
1858 return 0;
1859}
1860
1861static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
1862 const struct audio_config *config)
1863{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001864 int channel_count = popcount(config->channel_mask);
1865
1866 return get_input_buffer_size(config->sample_rate, config->format, channel_count);
1867}
1868
1869static int adev_open_input_stream(struct audio_hw_device *dev,
1870 audio_io_handle_t handle,
1871 audio_devices_t devices,
1872 struct audio_config *config,
1873 struct audio_stream_in **stream_in)
1874{
1875 struct audio_device *adev = (struct audio_device *)dev;
1876 struct stream_in *in;
1877 int ret, buffer_size, frame_size;
1878 int channel_count = popcount(config->channel_mask);
1879
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001880 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001881 *stream_in = NULL;
1882 if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
1883 return -EINVAL;
1884
1885 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
1886
1887 in->stream.common.get_sample_rate = in_get_sample_rate;
1888 in->stream.common.set_sample_rate = in_set_sample_rate;
1889 in->stream.common.get_buffer_size = in_get_buffer_size;
1890 in->stream.common.get_channels = in_get_channels;
1891 in->stream.common.get_format = in_get_format;
1892 in->stream.common.set_format = in_set_format;
1893 in->stream.common.standby = in_standby;
1894 in->stream.common.dump = in_dump;
1895 in->stream.common.set_parameters = in_set_parameters;
1896 in->stream.common.get_parameters = in_get_parameters;
1897 in->stream.common.add_audio_effect = in_add_audio_effect;
1898 in->stream.common.remove_audio_effect = in_remove_audio_effect;
1899 in->stream.set_gain = in_set_gain;
1900 in->stream.read = in_read;
1901 in->stream.get_input_frames_lost = in_get_input_frames_lost;
1902
1903 in->device = devices;
1904 in->source = AUDIO_SOURCE_DEFAULT;
1905 in->dev = adev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001906 in->standby = 1;
1907 in->channel_mask = config->channel_mask;
1908
1909 /* Update config params with the requested sample rate and channels */
1910 in->usecase = USECASE_AUDIO_RECORD;
1911 in->config = pcm_config_audio_capture;
1912 in->config.channels = channel_count;
1913 in->config.rate = config->sample_rate;
1914
1915 frame_size = audio_stream_frame_size((struct audio_stream *)in);
1916 buffer_size = get_input_buffer_size(config->sample_rate,
1917 config->format,
1918 channel_count);
1919 in->config.period_size = buffer_size / frame_size;
1920
1921 *stream_in = &in->stream;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001922 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001923 return 0;
1924
1925err_open:
1926 free(in);
1927 *stream_in = NULL;
1928 return ret;
1929}
1930
1931static void adev_close_input_stream(struct audio_hw_device *dev,
1932 struct audio_stream_in *stream)
1933{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001934 ALOGD("%s", __func__);
1935
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001936 in_standby(&stream->common);
1937 free(stream);
1938
1939 return;
1940}
1941
1942static int adev_dump(const audio_hw_device_t *device, int fd)
1943{
1944 return 0;
1945}
1946
1947static int adev_close(hw_device_t *device)
1948{
1949 struct audio_device *adev = (struct audio_device *)device;
1950 audio_route_free(adev->audio_route);
1951 free(device);
1952 return 0;
1953}
1954
1955static void init_platform_data(struct audio_device *adev)
1956{
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08001957 char platform[PROPERTY_VALUE_MAX];
1958 char baseband[PROPERTY_VALUE_MAX];
1959 char value[PROPERTY_VALUE_MAX];
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08001960
1961 adev->dualmic_config = DUALMIC_CONFIG_NONE;
1962 adev->fluence_in_voice_call = false;
1963 adev->fluence_in_voice_rec = false;
1964 adev->mic_type_analog = false;
1965
1966 property_get("persist.audio.handset.mic.type",value,"");
1967 if (!strncmp("analog", value, 6))
1968 adev->mic_type_analog = true;
1969
1970 property_get("persist.audio.dualmic.config",value,"");
1971 if (!strncmp("broadside", value, 9)) {
1972 adev->dualmic_config = DUALMIC_CONFIG_BROADSIDE;
1973 adev->acdb_settings |= DMIC_FLAG;
1974 } else if (!strncmp("endfire", value, 7)) {
1975 adev->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
1976 adev->acdb_settings |= DMIC_FLAG;
1977 }
1978
1979 if (adev->dualmic_config != DUALMIC_CONFIG_NONE) {
1980 property_get("persist.audio.fluence.voicecall",value,"");
1981 if (!strncmp("true", value, 4)) {
1982 adev->fluence_in_voice_call = true;
1983 }
1984
1985 property_get("persist.audio.fluence.voicerec",value,"");
1986 if (!strncmp("true", value, 4)) {
1987 adev->fluence_in_voice_rec = true;
1988 }
1989 }
1990
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001991 adev->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1992 if (adev->acdb_handle == NULL) {
1993 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1994 } else {
1995 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001996 adev->acdb_deallocate = (acdb_deallocate_t)dlsym(adev->acdb_handle,
1997 "acdb_loader_deallocate_ACDB");
1998 adev->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(adev->acdb_handle,
1999 "acdb_loader_send_audio_cal");
2000 adev->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(adev->acdb_handle,
2001 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002002 adev->acdb_init = (acdb_init_t)dlsym(adev->acdb_handle,
2003 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002004 if (adev->acdb_init == NULL)
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002005 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002006 else
2007 adev->acdb_init();
2008 }
2009
2010 /* If platform is Fusion3, load CSD Client specific symbols
2011 * Voice call is handled by MDM and apps processor talks to
2012 * MDM through CSD Client
2013 */
2014 property_get("ro.board.platform", platform, "");
2015 property_get("ro.baseband", baseband, "");
2016 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
2017 adev->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
2018 if (adev->csd_client == NULL)
2019 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
2020 }
2021
2022 if (adev->csd_client) {
2023 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002024 adev->csd_client_deinit = (csd_client_deinit_t)dlsym(adev->csd_client,
2025 "csd_client_deinit");
2026 adev->csd_disable_device = (csd_disable_device_t)dlsym(adev->csd_client,
2027 "csd_client_disable_device");
2028 adev->csd_enable_device = (csd_enable_device_t)dlsym(adev->csd_client,
2029 "csd_client_enable_device");
2030 adev->csd_start_voice = (csd_start_voice_t)dlsym(adev->csd_client,
2031 "csd_client_start_voice");
2032 adev->csd_stop_voice = (csd_stop_voice_t)dlsym(adev->csd_client,
2033 "csd_client_stop_voice");
2034 adev->csd_volume = (csd_volume_t)dlsym(adev->csd_client,
2035 "csd_client_volume");
2036 adev->csd_mic_mute = (csd_mic_mute_t)dlsym(adev->csd_client,
2037 "csd_client_mic_mute");
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002038 adev->csd_client_init = (csd_client_init_t)dlsym(adev->csd_client,
2039 "csd_client_init");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002040
2041 if (adev->csd_client_init == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002042 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002043 } else {
2044 adev->csd_client_init();
2045 }
2046 }
2047}
2048
2049static int adev_open(const hw_module_t *module, const char *name,
2050 hw_device_t **device)
2051{
2052 struct audio_device *adev;
2053 int ret;
2054
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002055 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002056 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;
2057
2058 adev = calloc(1, sizeof(struct audio_device));
2059
2060 adev->mixer = mixer_open(MIXER_CARD);
2061 if (!adev->mixer) {
2062 ALOGE("Unable to open the mixer, aborting.");
2063 return -ENOSYS;
2064 }
2065
2066 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
2067 if (!adev->audio_route) {
2068 free(adev);
2069 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
2070 *device = NULL;
2071 return -EINVAL;
2072 }
2073
2074 adev->device.common.tag = HARDWARE_DEVICE_TAG;
2075 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
2076 adev->device.common.module = (struct hw_module_t *)module;
2077 adev->device.common.close = adev_close;
2078
2079 adev->device.init_check = adev_init_check;
2080 adev->device.set_voice_volume = adev_set_voice_volume;
2081 adev->device.set_master_volume = adev_set_master_volume;
2082 adev->device.get_master_volume = adev_get_master_volume;
2083 adev->device.set_master_mute = adev_set_master_mute;
2084 adev->device.get_master_mute = adev_get_master_mute;
2085 adev->device.set_mode = adev_set_mode;
2086 adev->device.set_mic_mute = adev_set_mic_mute;
2087 adev->device.get_mic_mute = adev_get_mic_mute;
2088 adev->device.set_parameters = adev_set_parameters;
2089 adev->device.get_parameters = adev_get_parameters;
2090 adev->device.get_input_buffer_size = adev_get_input_buffer_size;
2091 adev->device.open_output_stream = adev_open_output_stream;
2092 adev->device.close_output_stream = adev_close_output_stream;
2093 adev->device.open_input_stream = adev_open_input_stream;
2094 adev->device.close_input_stream = adev_close_input_stream;
2095 adev->device.dump = adev_dump;
2096
2097 /* Set the default route before the PCM stream is opened */
2098 pthread_mutex_lock(&adev->lock);
2099 adev->mode = AUDIO_MODE_NORMAL;
Eric Laurentc8400632013-02-14 19:04:54 -08002100 adev->active_input = NULL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08002101 adev->primary_output = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002102 adev->out_device = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002103 adev->voice_call_rx = NULL;
2104 adev->voice_call_tx = NULL;
2105 adev->voice_volume = 1.0f;
2106 adev->tty_mode = TTY_MODE_OFF;
2107 adev->bluetooth_nrec = true;
2108 adev->cur_out_snd_device = 0;
2109 adev->cur_in_snd_device = 0;
2110 adev->out_snd_device_active = false;
2111 adev->in_snd_device_active = false;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002112 adev->in_call = false;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08002113 adev->acdb_settings = TTY_MODE_OFF;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08002114 list_init(&adev->usecase_list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002115 pthread_mutex_unlock(&adev->lock);
2116
2117 /* Loads platform specific libraries dynamically */
2118 init_platform_data(adev);
2119
2120 *device = &adev->device.common;
2121
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002122 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002123 return 0;
2124}
2125
2126static struct hw_module_methods_t hal_module_methods = {
2127 .open = adev_open,
2128};
2129
2130struct audio_module HAL_MODULE_INFO_SYM = {
2131 .common = {
2132 .tag = HARDWARE_MODULE_TAG,
2133 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
2134 .hal_api_version = HARDWARE_HAL_API_VERSION,
2135 .id = AUDIO_HARDWARE_MODULE_ID,
2136 .name = "QCOM Audio HAL",
2137 .author = "Code Aurora Forum",
2138 .methods = &hal_module_methods,
2139 },
2140};