blob: 87392d7782522c7b51dd3271d94f98fcf821b546 [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*/
19
20#include <errno.h>
21#include <pthread.h>
22#include <stdint.h>
23#include <sys/time.h>
24#include <stdlib.h>
25#include <dlfcn.h>
26#include <math.h>
27
28#include <cutils/log.h>
29#include <cutils/str_parms.h>
30#include <cutils/properties.h>
31
32#include "audio_hw.h"
33
34#define LIB_ACDB_LOADER "/system/lib/libacdbloader.so"
35#define LIB_CSD_CLIENT "/system/lib/libcsd-client.so"
36#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
37#define MIXER_CARD 0
38
39#define STRING_TO_ENUM(string) { #string, string }
40
41/* Flags used to initialize acdb_settings variable that goes to ACDB library */
42#define DMIC_FLAG 0x00000002
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -080043#define TTY_MODE_OFF 0x00000010
44#define TTY_MODE_FULL 0x00000020
45#define TTY_MODE_VCO 0x00000040
46#define TTY_MODE_HCO 0x00000080
47#define TTY_MODE_CLEAR 0xFFFFFF0F
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080048
49struct string_to_enum {
50 const char *name;
51 uint32_t value;
52};
53
54static const struct string_to_enum out_channels_name_to_enum_table[] = {
55 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO),
56 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
57 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
58};
59
60static const char * const use_case_table[AUDIO_USECASE_MAX] = {
61 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback",
62 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
63 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback",
64 [USECASE_AUDIO_RECORD] = "audio-record",
65 [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
66 [USECASE_VOICE_CALL] = "voice-call",
67};
68
69static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
70 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0},
71 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {14, 14},
72 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1},
73 [USECASE_AUDIO_RECORD] = {0, 0},
74 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {14, 14},
75 [USECASE_VOICE_CALL] = {12, 12},
76};
77
78/* Array to store sound devices */
79static const char * const device_table[SND_DEVICE_ALL] = {
80 /* Playback sound devices */
81 [SND_DEVICE_OUT_HANDSET] = "handset",
82 [SND_DEVICE_OUT_SPEAKER] = "speaker",
83 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
84 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
85 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
86 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -080087 [SND_DEVICE_OUT_HDMI] = "hdmi",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080088 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
89 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -080090 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -080091 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
92 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
93 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080094
95 /* Capture sound devices */
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -080096 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080097 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
98 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
99 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
100 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
101 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800102 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800103 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800104 [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef",
105 [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs",
106 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus",
107 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef",
108 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs",
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800109 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
110 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
111 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800112 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800113 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef",
114 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs",
Eric Laurentc8400632013-02-14 19:04:54 -0800115 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence",
116 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800117};
118
Eric Laurentc8400632013-02-14 19:04:54 -0800119/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800120static const int acdb_device_table[SND_DEVICE_ALL] = {
121 [SND_DEVICE_OUT_HANDSET] = 7,
122 [SND_DEVICE_OUT_SPEAKER] = 14,
123 [SND_DEVICE_OUT_HEADPHONES] = 10,
124 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
125 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
126 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800127 [SND_DEVICE_OUT_HDMI] = 18,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800128 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
129 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800130 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81,
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800131 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
132 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
133 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800134
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800135 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800136 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
137 [SND_DEVICE_IN_HEADSET_MIC] = 8,
138 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
139 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
140 [SND_DEVICE_IN_HDMI_MIC] = 4,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800141 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800142 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800143 [SND_DEVICE_IN_VOICE_DMIC_EF] = 6,
144 [SND_DEVICE_IN_VOICE_DMIC_BS] = 5,
145 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91,
146 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13,
147 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12,
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800148 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
149 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
150 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800151 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800152 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62,
153 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62,
Eric Laurentc8400632013-02-14 19:04:54 -0800154 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 62,
155 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 62,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800156};
157
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800158int edid_get_max_channels(void);
159
160static int get_pcm_device_id(struct audio_route *ar,
161 audio_usecase_t usecase,
162 int device_type)
163{
164 ALOGV("%s: enter: usecase(%d)", __func__, usecase);
165 int device_id;
166 if (device_type == PCM_PLAYBACK)
167 device_id = pcm_device_table[usecase][0];
168 else
169 device_id = pcm_device_table[usecase][1];
170 ALOGV("%s: exit: device_id(%d)", __func__, device_id);
171 return device_id;
172}
173
174static int get_acdb_device_id(snd_device_t snd_device)
175{
176 ALOGV("%s: enter: snd_devie(%d)", __func__, snd_device);
177 int acdb_dev_id = acdb_device_table[snd_device];
178 ALOGV("%s: exit: acdb_dev_id(%d)", __func__, acdb_dev_id);
179 return acdb_dev_id;
180}
181
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800182static void add_backend_name(char *mixer_path,
183 snd_device_t snd_device)
184{
185 if (snd_device == SND_DEVICE_OUT_HDMI ||
186 snd_device == SND_DEVICE_IN_HDMI_MIC)
187 strcat(mixer_path, " hdmi");
188 else if(snd_device == SND_DEVICE_OUT_BT_SCO ||
189 snd_device == SND_DEVICE_IN_BT_SCO_MIC)
190 strcat(mixer_path, " bt-sco");
191 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
192 strcat(mixer_path, " speaker-and-hdmi");
193}
194
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800195static int enable_audio_route(struct audio_route *ar,
196 audio_usecase_t usecase,
197 snd_device_t snd_device)
198{
199 ALOGV("%s: enter: usecase(%d) snd_device(%d)",
200 __func__, usecase, snd_device);
201 char mixer_path[50];
202 strcpy(mixer_path, use_case_table[usecase]);
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800203 add_backend_name(mixer_path, snd_device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800204 audio_route_apply_path(ar, mixer_path);
205 ALOGV("%s: exit", __func__);
206 return 0;
207}
208
209static int disable_audio_route(struct audio_route *ar,
210 audio_usecase_t usecase,
211 snd_device_t snd_device)
212{
213 ALOGV("%s: enter: usecase(%d) snd_device(%d)",
214 __func__, usecase, snd_device);
215 char mixer_path[50];
216 strcpy(mixer_path, use_case_table[usecase]);
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800217 add_backend_name(mixer_path, snd_device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800218 audio_route_reset_path(ar, mixer_path);
219 ALOGV("%s: exit", __func__);
220 return 0;
221}
222
223static int enable_snd_device(struct audio_device *adev,
224 snd_device_t snd_device)
225{
226 int acdb_dev_id, acdb_dev_type;
227
228 ALOGV("%s: enter: snd_device(%d)", __func__, snd_device);
229 acdb_dev_id = get_acdb_device_id(snd_device);
230 if (acdb_dev_id < 0) {
231 ALOGE("%s: Could not find acdb id for device(%d)",
232 __func__, snd_device);
233 return -EINVAL;
234 }
235 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
236 snd_device < SND_DEVICE_OUT_END) {
237 acdb_dev_type = ACDB_DEV_TYPE_OUT;
238 } else {
239 acdb_dev_type = ACDB_DEV_TYPE_IN;
240 }
241 if (adev->acdb_send_audio_cal) {
242 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
243 __func__, snd_device, acdb_dev_id);
244 adev->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
245 } else {
246 ALOGW("%s: Could find the symbol acdb_send_audio_cal from %s",
247 __func__, LIB_ACDB_LOADER);
248 }
249
250 audio_route_apply_path(adev->audio_route, device_table[snd_device]);
251 ALOGV("%s: exit", __func__);
252 return 0;
253}
254
255static int disable_snd_device(struct audio_route *ar,
256 snd_device_t snd_device)
257{
258 ALOGV("%s: enter: snd_device(%d)", __func__, snd_device);
259 audio_route_reset_path(ar, device_table[snd_device]);
260 ALOGV("%s: exit", __func__);
261 return 0;
262}
263
264static int set_hdmi_channels(struct mixer *mixer,
265 int channel_count)
266{
267 struct mixer_ctl *ctl;
268 const char *channel_cnt_str = NULL;
269 const char *mixer_ctl_name = "HDMI_RX Channels";
270 switch (channel_count) {
271 case 8:
272 channel_cnt_str = "Eight"; break;
273 case 7:
274 channel_cnt_str = "Seven"; break;
275 case 6:
276 channel_cnt_str = "Six"; break;
277 case 5:
278 channel_cnt_str = "Five"; break;
279 case 4:
280 channel_cnt_str = "Four"; break;
281 case 3:
282 channel_cnt_str = "Three"; break;
283 default:
284 channel_cnt_str = "Two"; break;
285 }
286 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
287 if (!ctl) {
288 ALOGE("%s: Could not get ctl for mixer cmd - %s",
289 __func__, mixer_ctl_name);
290 return -EINVAL;
291 }
292 ALOGV("HDMI channel count: %s", channel_cnt_str);
293 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
294 return 0;
295}
296
297/* must be called with hw device mutex locked */
298static void read_hdmi_channel_masks(struct stream_out *out)
299{
300 int channels = edid_get_max_channels();
301 ALOGE("%s: enter", __func__);
302
303 switch (channels) {
304 /*
305 * Do not handle stereo output in Multi-channel cases
306 * Stereo case is handled in normal playback path
307 */
308 case 6:
309 ALOGV("%s: HDMI supports 5.1", __func__);
310 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
311 break;
312 case 8:
313 ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__);
314 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
315 out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1;
316 break;
317 default:
318 ALOGE("Unsupported number of channels (%d)", channels);
319 break;
320 }
321
322 ALOGE("%s: exit", __func__);
323}
324
325static snd_device_t get_output_snd_device(struct audio_device *adev)
326{
Eric Laurentc8400632013-02-14 19:04:54 -0800327 audio_source_t source = (adev->active_input == NULL) ?
328 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800329 audio_mode_t mode = adev->mode;
330 audio_devices_t devices = adev->out_device;
331 snd_device_t snd_device = SND_DEVICE_INVALID;
332
333 ALOGV("%s: enter: output devices(0x%x)", __func__, devices);
334 if (devices == AUDIO_DEVICE_NONE ||
335 devices & AUDIO_DEVICE_BIT_IN) {
336 ALOGV("%s: Invalid output devices (0x%x)", __func__, devices);
337 goto exit;
338 }
339
340 if (mode == AUDIO_MODE_IN_CALL) {
341 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
342 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800343 if (adev->tty_mode == TTY_MODE_FULL)
344 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
345 else if (adev->tty_mode == TTY_MODE_VCO)
346 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
347 else if (adev->tty_mode == TTY_MODE_HCO)
348 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
349 else
350 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800351 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
352 snd_device = SND_DEVICE_OUT_BT_SCO;
353 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
354 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
355 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800356 if (adev->is_tmus)
357 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
358 else
359 snd_device = SND_DEVICE_OUT_HANDSET;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800360 }
361 if (snd_device != SND_DEVICE_INVALID) {
362 goto exit;
363 }
364 }
365
366 if (popcount(devices) == 2) {
367 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
368 AUDIO_DEVICE_OUT_SPEAKER)) {
369 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
370 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
371 AUDIO_DEVICE_OUT_SPEAKER)) {
372 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
373 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
374 AUDIO_DEVICE_OUT_SPEAKER)) {
375 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
376 } else {
377 ALOGE("%s: Invalid combo device(0x%x)", __func__, devices);
378 goto exit;
379 }
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800380 if (snd_device != SND_DEVICE_INVALID) {
381 goto exit;
382 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800383 }
384 if (popcount(devices) != 1) {
385 ALOGE("%s: Invalid output devices(0x%x)", __func__, devices);
386 goto exit;
387 }
388
389 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
390 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
391 snd_device = SND_DEVICE_OUT_HEADPHONES;
392 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
393 snd_device = SND_DEVICE_OUT_SPEAKER;
394 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
395 snd_device = SND_DEVICE_OUT_BT_SCO;
396 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
397 snd_device = SND_DEVICE_OUT_HDMI ;
398 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
399 snd_device = SND_DEVICE_OUT_HANDSET;
400 } else {
401 ALOGE("%s: Unknown device(s) 0x%x", __func__, devices);
402 }
403exit:
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800404 ALOGV("%s: exit: snd_device(%s)", __func__,
405 (snd_device == SND_DEVICE_INVALID) ?
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800406 "none" : device_table[snd_device]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800407 return snd_device;
408}
409
410static snd_device_t get_input_snd_device(struct audio_device *adev)
411{
Eric Laurentc8400632013-02-14 19:04:54 -0800412 audio_source_t source = (adev->active_input == NULL) ?
413 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
414
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800415 audio_mode_t mode = adev->mode;
416 audio_devices_t out_device = adev->out_device;
Eric Laurentc8400632013-02-14 19:04:54 -0800417 audio_devices_t in_device = ((adev->active_input == NULL) ?
418 AUDIO_DEVICE_NONE : adev->active_input->device)
419 & ~AUDIO_DEVICE_BIT_IN;
420 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
421 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800422 snd_device_t snd_device = SND_DEVICE_INVALID;
423
424 ALOGV("%s: enter: out_device(0x%x) in_device(0x%x)",
425 __func__, out_device, in_device);
426 if (mode == AUDIO_MODE_IN_CALL) {
427 if (out_device == AUDIO_DEVICE_NONE) {
428 ALOGE("%s: No output device set for voice call", __func__);
429 goto exit;
430 }
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800431 if (adev->tty_mode != TTY_MODE_OFF) {
432 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
433 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
434 switch (adev->tty_mode) {
435 case TTY_MODE_FULL:
436 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
437 break;
438 case TTY_MODE_VCO:
439 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
440 break;
441 case TTY_MODE_HCO:
442 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
443 break;
444 default:
445 ALOGE("%s: Invalid TTY mode (0x%x)", __func__, adev->tty_mode);
446 }
447 goto exit;
448 }
449 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800450 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
451 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800452 if (adev->mic_type_analog || adev->fluence_in_voice_call == false) {
453 snd_device = SND_DEVICE_IN_HANDSET_MIC;
454 } else {
455 if (adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
456 if (adev->is_tmus)
457 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
458 else
459 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
460 } else if(adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
461 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
462 else
463 snd_device = SND_DEVICE_IN_HANDSET_MIC;
464 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800465 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
466 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
467 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
468 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
469 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800470 if (adev->fluence_in_voice_call &&
471 adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
472 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
473 } else if (adev->fluence_in_voice_call &&
474 adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
475 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
476 } else {
477 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
478 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800479 }
480 } else if (source == AUDIO_SOURCE_CAMCORDER) {
481 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
482 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
483 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
484 }
485 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
486 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Eric Laurentc8400632013-02-14 19:04:54 -0800487 if (adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
488 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
489 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
490 else if (adev->fluence_in_voice_rec)
491 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
492 else
493 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
494 } else if (adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
495 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
496 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
497 else if (adev->fluence_in_voice_rec)
498 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
499 else
500 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
501 } else
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800502 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800503 }
504 } else if (source == AUDIO_SOURCE_DEFAULT) {
505 goto exit;
506 }
507
508 if (snd_device != SND_DEVICE_INVALID) {
509 goto exit;
510 }
511
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800512 if (in_device != AUDIO_DEVICE_NONE &&
513 in_device != AUDIO_DEVICE_IN_VOICE_CALL &&
514 in_device != AUDIO_DEVICE_IN_COMMUNICATION) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800515 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800516 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800517 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800518 /*
519 * PolicyManager selects BACK_MIC only for camcorder recording.
520 * Ideally this condition shouldn't be met.
521 */
522 if (adev->mic_type_analog)
523 snd_device = SND_DEVICE_IN_HANDSET_MIC;
524 else
525 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800526 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
527 snd_device = SND_DEVICE_IN_HEADSET_MIC;
528 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
529 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
530 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
531 snd_device = SND_DEVICE_IN_HDMI_MIC;
532 } else {
533 ALOGE("%s: Unknown input device(s) 0x%x", __func__, in_device);
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800534 ALOGW("%s: Using default handset-mic", __func__);
535 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800536 }
537 } else {
538 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800539 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800540 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
541 snd_device = SND_DEVICE_IN_HEADSET_MIC;
542 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
543 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
544 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800545 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800546 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800547 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800548 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
549 snd_device = SND_DEVICE_IN_HDMI_MIC;
550 } else {
551 ALOGE("%s: Unknown output device(s) 0x%x", __func__, out_device);
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800552 ALOGW("%s: Using default handset-mic", __func__);
553 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800554 }
555 }
556exit:
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800557 ALOGV("%s: exit: in_snd_device(%s)", __func__,
558 (snd_device == SND_DEVICE_INVALID) ?
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800559 "none" : device_table[snd_device]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800560 return snd_device;
561}
562
563static int select_devices(struct audio_device *adev)
564{
565 snd_device_t out_snd_device = SND_DEVICE_INVALID;
566 snd_device_t in_snd_device = SND_DEVICE_INVALID;
567 struct audio_usecase *usecase;
568 int status = 0;
569 int acdb_rx_id, acdb_tx_id;
570 bool in_call_device_switch = false;
571
572 ALOGV("%s: enter", __func__);
573 out_snd_device = get_output_snd_device(adev);
574 in_snd_device = get_input_snd_device(adev);
575
576 if (out_snd_device == adev->cur_out_snd_device && adev->out_snd_device_active &&
577 in_snd_device == adev->cur_in_snd_device && adev->in_snd_device_active) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800578 ALOGV("%s: exit: snd_devices (%d and %d) are already active",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800579 __func__, out_snd_device, in_snd_device);
580 return 0;
581 }
582
583 /*
584 * Limitation: While in call, to do a device switch we need to disable
585 * and enable both RX and TX devices though one of them is same as current
586 * device.
587 */
588 if (adev->mode == AUDIO_MODE_IN_CALL &&
589 adev->csd_client != NULL &&
590 out_snd_device != SND_DEVICE_INVALID &&
591 in_snd_device != SND_DEVICE_INVALID &&
592 adev->cur_out_snd_device != SND_DEVICE_INVALID &&
593 adev->cur_in_snd_device != SND_DEVICE_INVALID) {
594 in_call_device_switch = true;
595 }
596
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800597 if (in_call_device_switch) {
598 /* This must be called before disabling the mixer controls on APQ side */
599 if (adev->csd_disable_device == NULL) {
600 ALOGE("%s: dlsym error for csd_client_disable_device",
601 __func__);
602 } else {
603 status = adev->csd_disable_device();
604 if (status < 0) {
605 ALOGE("%s: csd_client_disable_device, failed, error %d",
606 __func__, status);
607 }
608 }
609 }
610
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800611 if ((out_snd_device != adev->cur_out_snd_device || in_call_device_switch)
612 && adev->out_snd_device_active) {
613 usecase = &adev->usecase_list;
614 while (usecase->next != NULL) {
615 usecase = usecase->next;
616 if (usecase->type == PCM_PLAYBACK || usecase->type == VOICE_CALL) {
617 disable_audio_route(adev->audio_route, usecase->id,
618 adev->cur_out_snd_device);
619 }
620 }
621 audio_route_update_mixer(adev->audio_route);
622 /* Disable current rx device */
623 disable_snd_device(adev->audio_route, adev->cur_out_snd_device);
624 adev->out_snd_device_active = false;
625 }
626
627 if ((in_snd_device != adev->cur_in_snd_device || in_call_device_switch)
628 && adev->in_snd_device_active) {
629 usecase = &adev->usecase_list;
630 while (usecase->next != NULL) {
631 usecase = usecase->next;
632 if (usecase->type == PCM_CAPTURE) {
633 disable_audio_route(adev->audio_route, usecase->id,
634 adev->cur_in_snd_device);
635 }
636 }
637 audio_route_update_mixer(adev->audio_route);
638 /* Disable current tx device */
639 disable_snd_device(adev->audio_route, adev->cur_in_snd_device);
640 adev->in_snd_device_active = false;
641 }
642
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800643 if (out_snd_device != SND_DEVICE_INVALID && !adev->out_snd_device_active) {
644 /* Enable new rx device */
645 status = enable_snd_device(adev, out_snd_device);
646 if (status != 0) {
647 ALOGE("%s: Failed to set mixer ctls for snd_device(%d)",
648 __func__, out_snd_device);
649 return status;
650 }
651 adev->out_snd_device_active = true;
652 adev->cur_out_snd_device = out_snd_device;
653 }
654
655 if (in_snd_device != SND_DEVICE_INVALID && !adev->in_snd_device_active) {
656 /* Enable new tx device */
657 status = enable_snd_device(adev, in_snd_device);
658 if (status != 0) {
659 ALOGE("%s: Failed to set mixer ctls for snd_device(%d)",
660 __func__, out_snd_device);
661 return status;
662 }
663 adev->in_snd_device_active = true;
664 adev->cur_in_snd_device = in_snd_device;
665 }
666 audio_route_update_mixer(adev->audio_route);
667
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800668 usecase = &adev->usecase_list;
669 while (usecase->next != NULL) {
670 usecase = usecase->next;
671 if (usecase->type == PCM_PLAYBACK || usecase->type == VOICE_CALL) {
672 usecase->devices = adev->out_device; /* TODO: fix device logic */
673 status = enable_audio_route(adev->audio_route, usecase->id,
674 adev->cur_out_snd_device);
675 } else {
676 status = enable_audio_route(adev->audio_route, usecase->id,
677 adev->cur_in_snd_device);
678 }
679 }
680 audio_route_update_mixer(adev->audio_route);
681
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800682 if (in_call_device_switch) {
683 if (adev->csd_enable_device == NULL) {
684 ALOGE("%s: dlsym error for csd_client_enable_device",
685 __func__);
686 } else {
687 acdb_rx_id = get_acdb_device_id(out_snd_device);
688 acdb_tx_id = get_acdb_device_id(in_snd_device);
689
690 /* ToDo: To make sure acdb_settings is updated properly based on TTY mode */
691 status = adev->csd_enable_device(acdb_rx_id, acdb_tx_id, adev->acdb_settings);
692 if (status < 0) {
693 ALOGE("%s: csd_client_enable_device, failed, error %d",
694 __func__, status);
695 }
696 }
697 }
698
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800699 ALOGV("%s: exit: status(%d)", __func__, status);
700 return status;
701}
702
703static void add_usecase_to_list(struct audio_device *adev,
704 struct audio_usecase *uc_info)
705{
706 struct audio_usecase *first_entry = adev->usecase_list.next;
707 ALOGV("%s: enter: usecase(%d)", __func__, uc_info->id);
708 /* Insert the new entry on the top of the list */
709 adev->usecase_list.next = uc_info;
710 uc_info->next = first_entry;
711 ALOGV("%s: exit", __func__);
712}
713
714static void remove_usecase_from_list(struct audio_device *adev,
715 audio_usecase_t uc_id)
716{
717 struct audio_usecase *uc_to_remove = NULL;
718 struct audio_usecase *list_head = &adev->usecase_list;
719 ALOGV("%s: enter: usecase(%d)", __func__, uc_id);
720 while (list_head->next != NULL) {
721 if (list_head->next->id == uc_id) {
722 uc_to_remove = list_head->next;
723 list_head->next = list_head->next->next;
724 free(uc_to_remove);
725 break;
726 }
727 list_head = list_head->next;
728 }
729 ALOGV("%s: exit", __func__);
730}
731
732static struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
733 audio_usecase_t uc_id)
734{
735 struct audio_usecase *uc_info = NULL;
736 struct audio_usecase *list_head = &adev->usecase_list;
737 ALOGV("%s: enter: uc_id(%d)", __func__, uc_id);
738 while (list_head->next != NULL) {
739 list_head = list_head->next;
740 if (list_head->id == uc_id) {
741 uc_info = list_head;
742 break;
743 }
744 }
745 ALOGV("%s: exit: uc_info(%p)", __func__, uc_info);
746 return uc_info;
747}
748
749static int get_num_active_usecases(struct audio_device *adev)
750{
751 int num_uc = 0;
752 struct audio_usecase *list_head = &adev->usecase_list;
753 while (list_head->next != NULL) {
754 num_uc++;
755 list_head = list_head->next;
756 }
757 return num_uc;
758}
759
760static audio_devices_t get_active_out_devices(struct audio_device *adev,
761 audio_usecase_t usecase)
762{
763 audio_devices_t devices = 0;
764 struct audio_usecase *list_head = &adev->usecase_list;
765 /* Return the output devices of usecases other than given usecase */
766 while (list_head->next != NULL) {
767 list_head = list_head->next;
768 if (list_head->type == PCM_PLAYBACK && list_head->id != usecase) {
769 devices |= list_head->devices;
770 }
771 }
772 return devices;
773}
774
775static audio_devices_t get_voice_call_out_device(struct audio_device *adev)
776{
777 audio_devices_t devices = 0;
778 struct audio_usecase *list_head = &adev->usecase_list;
779 /* Return the output devices of usecases other than given usecase */
780 while (list_head->next != NULL) {
781 list_head = list_head->next;
782 if (list_head->id == USECASE_VOICE_CALL) {
783 devices = list_head->devices;
784 break;
785 }
786 }
787 return devices;
788}
789
790static int stop_input_stream(struct stream_in *in)
791{
792 int i, ret = 0;
793 snd_device_t in_snd_device;
794 struct audio_usecase *uc_info;
795 struct audio_device *adev = in->dev;
796
Eric Laurentc8400632013-02-14 19:04:54 -0800797 adev->active_input = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800798
Eric Laurentc8400632013-02-14 19:04:54 -0800799 ALOGV("%s: enter: usecase(%d)", __func__, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800800 uc_info = get_usecase_from_list(adev, in->usecase);
801 if (uc_info == NULL) {
802 ALOGE("%s: Could not find the usecase (%d) in the list",
803 __func__, in->usecase);
804 return -EINVAL;
805 }
806
807 /* 1. Close the PCM device first */
808 if (in->pcm) {
809 pcm_close(in->pcm);
810 in->pcm = NULL;
811 }
812
813 /* 2. Disable stream specific mixer controls */
814 in_snd_device = adev->cur_in_snd_device;
815 disable_audio_route(adev->audio_route, in->usecase, in_snd_device);
816 audio_route_update_mixer(adev->audio_route);
817
818 remove_usecase_from_list(adev, in->usecase);
819
820 /* 3. Disable the tx device */
821 select_devices(adev);
822
823 ALOGV("%s: exit: status(%d)", __func__, ret);
824 return ret;
825}
826
827int start_input_stream(struct stream_in *in)
828{
829 /* 1. Enable output device and stream routing controls */
Eric Laurentc8400632013-02-14 19:04:54 -0800830 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800831 snd_device_t in_snd_device;
832 struct audio_usecase *uc_info;
833 struct audio_device *adev = in->dev;
834
835 ALOGV("%s: enter: usecase(%d)", __func__, in->usecase);
Eric Laurentc8400632013-02-14 19:04:54 -0800836 adev->active_input = in;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800837 in_snd_device = get_input_snd_device(adev);
838 if (in_snd_device == SND_DEVICE_INVALID) {
839 ALOGE("%s: Could not get valid input sound device", __func__);
Eric Laurentc8400632013-02-14 19:04:54 -0800840 ret = -EINVAL;
841 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800842 }
843
844 in->pcm_device_id = get_pcm_device_id(adev->audio_route,
845 in->usecase,
846 PCM_CAPTURE);
847 if (in->pcm_device_id < 0) {
848 ALOGE("%s: Could not find PCM device id for the usecase(%d)",
849 __func__, in->usecase);
Eric Laurentc8400632013-02-14 19:04:54 -0800850 ret = -EINVAL;
851 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800852 }
853 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
854 uc_info->id = in->usecase;
855 uc_info->type = PCM_CAPTURE;
856 uc_info->devices = in->device;
857
858 /* 1. Enable the TX device */
859 ret = select_devices(adev);
860 if (ret) {
861 ALOGE("%s: Failed to enable device(0x%x)",
Eric Laurentc8400632013-02-14 19:04:54 -0800862 __func__, in->device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800863 free(uc_info);
Eric Laurentc8400632013-02-14 19:04:54 -0800864 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800865 }
866 in_snd_device = adev->cur_in_snd_device;
867
868 /* 2. Enable the mixer controls for the audio route */
869 enable_audio_route(adev->audio_route, in->usecase, in_snd_device);
870 audio_route_update_mixer(adev->audio_route);
871
872 /* 3. Add the usecase info to usecase list */
873 add_usecase_to_list(adev, uc_info);
874
875 /* 2. Open the pcm device */
Eric Laurentc8400632013-02-14 19:04:54 -0800876 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d",
877 __func__, SOUND_CARD, in->pcm_device_id, in->config.channels);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800878 in->pcm = pcm_open(SOUND_CARD, in->pcm_device_id,
879 PCM_IN, &in->config);
880 if (in->pcm && !pcm_is_ready(in->pcm)) {
881 ALOGE("%s: %s", __func__, pcm_get_error(in->pcm));
882 pcm_close(in->pcm);
883 in->pcm = NULL;
Eric Laurentc8400632013-02-14 19:04:54 -0800884 ret = -EIO;
885 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800886 }
887 ALOGV("%s: exit", __func__);
Eric Laurentc8400632013-02-14 19:04:54 -0800888 return ret;
889
890error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800891 stop_input_stream(in);
Eric Laurentc8400632013-02-14 19:04:54 -0800892
893error_config:
894 adev->active_input = NULL;
895 ALOGV("%s: exit: status(%d)", __func__, ret);
896
897 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800898}
899
900static int stop_output_stream(struct stream_out *out)
901{
902 int i, ret = 0;
903 snd_device_t out_snd_device;
904 struct audio_usecase *uc_info;
905 struct audio_device *adev = out->dev;
906
907 ALOGV("%s: enter: usecase(%d)", __func__, out->usecase);
908 uc_info = get_usecase_from_list(adev, out->usecase);
909 if (uc_info == NULL) {
910 ALOGE("%s: Could not find the usecase (%d) in the list",
911 __func__, out->usecase);
912 return -EINVAL;
913 }
914
915 /* 1. Close the PCM device first */
916 if (out->pcm) {
917 pcm_close(out->pcm);
918 out->pcm = NULL;
919 }
920
921 /* 2. Get and set stream specific mixer controls */
922 out_snd_device = adev->cur_out_snd_device;
923 disable_audio_route(adev->audio_route, out->usecase, out_snd_device);
924 audio_route_update_mixer(adev->audio_route);
925
926 remove_usecase_from_list(adev, uc_info->id);
927
928 /* 3. Disable the rx device */
929 adev->out_device = get_active_out_devices(adev, out->usecase);
930 adev->out_device |= get_voice_call_out_device(adev);
931 ret = select_devices(adev);
932
933 ALOGV("%s: exit: status(%d)", __func__, ret);
934 return ret;
935}
936
937int start_output_stream(struct stream_out *out)
938{
939 int status;
940 int ret = 0;
941 snd_device_t out_snd_device;
942 struct audio_usecase *uc_info;
943 struct audio_device *adev = out->dev;
944
945 /* 1. Enable output device and stream routing controls */
946 ALOGV("%s: enter: usecase(%d)", __func__, out->usecase);
947 adev->out_device |= out->devices;
948 out_snd_device = get_output_snd_device(adev);
949 if (out_snd_device == SND_DEVICE_INVALID) {
950 ALOGE("%s: Could not get valid output sound device", __func__);
951 /*
952 * TODO: use a single exit point to avoid duplicating code to
953 * reset output device
954 */
955 adev->out_device = get_active_out_devices(adev, out->usecase);
956 adev->out_device |= get_voice_call_out_device(adev);
957 return -EINVAL;
958 }
959
960 out->pcm_device_id = get_pcm_device_id(adev->audio_route,
961 out->usecase,
962 PCM_PLAYBACK);
963 if (out->pcm_device_id < 0) {
964 ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)",
965 __func__, out->pcm_device_id, out->usecase);
966 adev->out_device = get_active_out_devices(adev, out->usecase);
967 adev->out_device |= get_voice_call_out_device(adev);
968 return -EINVAL;
969 }
970
971 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
972 uc_info->id = out->usecase;
973 uc_info->type = PCM_PLAYBACK;
974 uc_info->devices = out->devices;
975
976 ret = select_devices(adev);
977 if (ret) {
978 ALOGE("%s: Failed to enable device(0x%x)",
979 __func__, adev->out_device);
980 adev->out_device = get_active_out_devices(adev, out->usecase);
981 adev->out_device |= get_voice_call_out_device(adev);
982 free(uc_info);
983 return ret;
984 }
985
986 out_snd_device = adev->cur_out_snd_device;
987 enable_audio_route(adev->audio_route, out->usecase, out_snd_device);
988 audio_route_update_mixer(adev->audio_route);
989
990 add_usecase_to_list(adev, uc_info);
991
992 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
993 __func__, 0, out->pcm_device_id);
994 out->pcm = pcm_open(SOUND_CARD, out->pcm_device_id,
995 PCM_OUT, &out->config);
996 if (out->pcm && !pcm_is_ready(out->pcm)) {
997 ALOGE("%s: %s", __func__, pcm_get_error(out->pcm));
998 pcm_close(out->pcm);
999 out->pcm = NULL;
1000 status = -EIO;
1001 goto error;
1002 }
1003 ALOGV("%s: exit", __func__);
1004 return 0;
1005error:
1006 stop_output_stream(out);
1007 ALOGE("%s: exit: status(%d)", __func__, status);
1008 return status;
1009}
1010
1011static int stop_voice_call(struct audio_device *adev)
1012{
1013 int i, ret = 0;
1014 snd_device_t out_snd_device;
1015 struct audio_usecase *uc_info;
1016
1017 ALOGV("%s: enter: usecase(%d)", __func__, USECASE_VOICE_CALL);
1018 if (adev->csd_client) {
1019 if (adev->csd_stop_voice == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001020 ALOGE("dlsym error for csd_client_disable_device");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001021 } else {
1022 ret = adev->csd_stop_voice();
1023 if (ret < 0) {
1024 ALOGE("%s: csd_client error %d\n", __func__, ret);
1025 }
1026 }
1027 }
1028
1029 /* 1. Close the PCM devices */
1030 if (adev->voice_call_rx) {
1031 pcm_close(adev->voice_call_rx);
1032 adev->voice_call_rx = NULL;
1033 }
1034 if (adev->voice_call_tx) {
1035 pcm_close(adev->voice_call_tx);
1036 adev->voice_call_tx = NULL;
1037 }
1038
1039 uc_info = get_usecase_from_list(adev, USECASE_VOICE_CALL);
1040 if (uc_info == NULL) {
1041 ALOGE("%s: Could not find the usecase (%d) in the list",
1042 __func__, USECASE_VOICE_CALL);
1043 return -EINVAL;
1044 }
1045 out_snd_device = adev->cur_out_snd_device;
1046
1047 /* 2. Get and set stream specific mixer controls */
1048 /* ToDo: Status check ?*/
1049 disable_audio_route(adev->audio_route, USECASE_VOICE_CALL, out_snd_device);
1050 audio_route_update_mixer(adev->audio_route);
1051
1052 remove_usecase_from_list(adev, uc_info->id);
1053
1054 /* 3. Disable the rx and tx devices */
1055 ret = select_devices(adev);
1056 adev->in_call = false;
1057
1058 ALOGV("%s: exit: status(%d)", __func__, ret);
1059 return ret;
1060}
1061
1062static int start_voice_call(struct audio_device *adev)
1063{
1064 int i, ret = 0;
1065 snd_device_t out_snd_device;
1066 struct audio_usecase *uc_info;
1067 int pcm_dev_rx_id, pcm_dev_tx_id;
1068
1069 ALOGV("%s: enter", __func__);
1070
1071 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
1072 uc_info->id = USECASE_VOICE_CALL;
1073 uc_info->type = VOICE_CALL;
1074 uc_info->devices = adev->out_device;
1075
1076 ret = select_devices(adev);
1077 if (ret) {
1078 free(uc_info);
1079 return ret;
1080 }
1081
1082 /* 2. Get and set stream specific mixer controls */
1083 out_snd_device = adev->cur_out_snd_device;
1084 /* ToDo: Status check ?*/
1085 enable_audio_route(adev->audio_route, uc_info->id, out_snd_device);
1086 audio_route_update_mixer(adev->audio_route);
1087
1088 add_usecase_to_list(adev, uc_info);
1089
1090 pcm_dev_rx_id = get_pcm_device_id(adev->audio_route, uc_info->id,
1091 PCM_PLAYBACK);
1092 pcm_dev_tx_id = get_pcm_device_id(adev->audio_route, uc_info->id,
1093 PCM_CAPTURE);
1094
1095 /* 2. Open the pcm device */
1096 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
1097 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
1098 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
1099 stop_voice_call(adev);
1100 goto error;
1101 }
1102
1103 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
1104 __func__, SOUND_CARD, pcm_dev_rx_id);
1105 adev->voice_call_rx = pcm_open(SOUND_CARD,
1106 pcm_dev_rx_id,
1107 PCM_OUT, &pcm_config_voice_call);
1108 if (adev->voice_call_rx && !pcm_is_ready(adev->voice_call_rx)) {
1109 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_rx));
1110 /* ToDo: Check return status ??*/
1111 stop_voice_call(adev);
1112 return -EIO;
1113 }
1114
1115 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
1116 __func__, SOUND_CARD, pcm_dev_tx_id);
1117 adev->voice_call_tx = pcm_open(SOUND_CARD,
1118 pcm_dev_tx_id,
1119 PCM_IN, &pcm_config_voice_call);
1120 if (adev->voice_call_tx && !pcm_is_ready(adev->voice_call_tx)) {
1121 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_tx));
1122 /* ToDo: Check return status ??*/
1123 stop_voice_call(adev);
1124 return -EIO;
1125 }
1126 pcm_start(adev->voice_call_rx);
1127 pcm_start(adev->voice_call_tx);
1128
1129 if (adev->csd_client) {
1130 if (adev->csd_start_voice == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001131 ALOGE("dlsym error for csd_client_start_voice");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001132 } else {
1133 ret = adev->csd_start_voice();
1134 if (ret < 0) {
1135 ALOGE("%s: csd_client error %d\n", __func__, ret);
1136 }
1137 }
1138 }
1139
1140 adev->in_call = true;
1141error:
1142 ALOGV("%s: exit: status(%d)", __func__, ret);
1143 return ret;
1144}
1145
1146static int check_input_parameters(uint32_t sample_rate,
1147 audio_format_t format,
1148 int channel_count)
1149{
1150 if (format != AUDIO_FORMAT_PCM_16_BIT) return -EINVAL;
1151
1152 if ((channel_count < 1) || (channel_count > 2)) return -EINVAL;
1153
1154 switch (sample_rate) {
1155 case 8000:
1156 case 11025:
1157 case 12000:
1158 case 16000:
1159 case 22050:
1160 case 24000:
1161 case 32000:
1162 case 44100:
1163 case 48000:
1164 break;
1165 default:
1166 return -EINVAL;
1167 }
1168
1169 return 0;
1170}
1171
1172static size_t get_input_buffer_size(uint32_t sample_rate,
1173 audio_format_t format,
1174 int channel_count)
1175{
1176 size_t size = 0;
1177
1178 if (check_input_parameters(sample_rate, format, channel_count) != 0) return 0;
1179
1180 if (sample_rate == 8000 || sample_rate == 16000 || sample_rate == 32000) {
1181 size = (sample_rate * 20) / 1000;
1182 } else if (sample_rate == 11025 || sample_rate == 12000) {
1183 size = 256;
1184 } else if (sample_rate == 22050 || sample_rate == 24000) {
1185 size = 512;
1186 } else if (sample_rate == 44100 || sample_rate == 48000) {
1187 size = 1024;
1188 }
1189
1190 return size * sizeof(short) * channel_count;
1191}
1192
1193static uint32_t out_get_sample_rate(const struct audio_stream *stream)
1194{
1195 struct stream_out *out = (struct stream_out *)stream;
1196
1197 return out->config.rate;
1198}
1199
1200static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1201{
1202 return -ENOSYS;
1203}
1204
1205static size_t out_get_buffer_size(const struct audio_stream *stream)
1206{
1207 struct stream_out *out = (struct stream_out *)stream;
1208
1209 return out->config.period_size * audio_stream_frame_size(stream);
1210}
1211
1212static uint32_t out_get_channels(const struct audio_stream *stream)
1213{
1214 struct stream_out *out = (struct stream_out *)stream;
1215
1216 return out->channel_mask;
1217}
1218
1219static audio_format_t out_get_format(const struct audio_stream *stream)
1220{
1221 return AUDIO_FORMAT_PCM_16_BIT;
1222}
1223
1224static int out_set_format(struct audio_stream *stream, audio_format_t format)
1225{
1226 return -ENOSYS;
1227}
1228
1229static int out_standby(struct audio_stream *stream)
1230{
1231 struct stream_out *out = (struct stream_out *)stream;
1232 struct audio_device *adev = out->dev;
1233 ALOGV("%s: enter: usecase(%d)", __func__, out->usecase);
1234 pthread_mutex_lock(&out->dev->lock);
1235 pthread_mutex_lock(&out->lock);
1236
1237 if (!out->standby) {
1238 out->standby = true;
1239 stop_output_stream(out);
1240 }
1241 pthread_mutex_unlock(&out->lock);
1242 pthread_mutex_unlock(&out->dev->lock);
1243 ALOGV("%s: exit", __func__);
1244 return 0;
1245}
1246
1247static int out_dump(const struct audio_stream *stream, int fd)
1248{
1249 return 0;
1250}
1251
1252static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
1253{
1254 struct stream_out *out = (struct stream_out *)stream;
1255 struct audio_device *adev = out->dev;
1256 struct str_parms *parms;
1257 char value[32];
1258 int ret, val = 0;
1259
1260 ALOGV("%s: enter: usecase(%d) kvpairs: %s",
1261 __func__, out->usecase, kvpairs);
1262 parms = str_parms_create_str(kvpairs);
1263 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1264 if (ret >= 0) {
1265 val = atoi(value);
1266 pthread_mutex_lock(&adev->lock);
1267 pthread_mutex_lock(&out->lock);
1268
1269 if (adev->mode == AUDIO_MODE_IN_CALL && !adev->in_call) {
1270 adev->out_device = get_active_out_devices(adev, out->usecase) | val;
1271 start_voice_call(adev);
1272 } else if (adev->mode != AUDIO_MODE_IN_CALL && adev->in_call) {
1273 adev->out_device = get_active_out_devices(adev, out->usecase) | val;
1274 stop_voice_call(adev);
1275 } else if ((adev->out_device != (audio_devices_t)val) && (val != 0)) {
1276 if (!out->standby || adev->in_call) {
1277 adev->out_device = get_active_out_devices(adev, out->usecase) | val;
1278 ret = select_devices(adev);
1279 }
1280 }
1281 out->devices = val;
1282
1283 pthread_mutex_unlock(&out->lock);
1284 pthread_mutex_unlock(&adev->lock);
1285 }
1286 str_parms_destroy(parms);
1287 ALOGV("%s: exit: code(%d)", __func__, ret);
1288 return ret;
1289}
1290
1291static char* out_get_parameters(const struct audio_stream *stream, const char *keys)
1292{
1293 struct stream_out *out = (struct stream_out *)stream;
1294 struct str_parms *query = str_parms_create_str(keys);
1295 char *str;
1296 char value[256];
1297 struct str_parms *reply = str_parms_create();
1298 size_t i, j;
1299 int ret;
1300 bool first = true;
1301 ALOGV("%s: enter: keys - %s", __func__, keys);
1302 ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value));
1303 if (ret >= 0) {
1304 value[0] = '\0';
1305 i = 0;
1306 while (out->supported_channel_masks[i] != 0) {
1307 for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) {
1308 if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) {
1309 if (!first) {
1310 strcat(value, "|");
1311 }
1312 strcat(value, out_channels_name_to_enum_table[j].name);
1313 first = false;
1314 break;
1315 }
1316 }
1317 i++;
1318 }
1319 str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value);
1320 str = str_parms_to_str(reply);
1321 } else {
1322 str = strdup(keys);
1323 }
1324 str_parms_destroy(query);
1325 str_parms_destroy(reply);
1326 ALOGV("%s: exit: returns - %s", __func__, str);
1327 return str;
1328}
1329
1330static uint32_t out_get_latency(const struct audio_stream_out *stream)
1331{
1332 struct stream_out *out = (struct stream_out *)stream;
1333
1334 return (out->config.period_count * out->config.period_size * 1000) / (out->config.rate);
1335}
1336
1337static int out_set_volume(struct audio_stream_out *stream, float left,
1338 float right)
1339{
1340 return -ENOSYS;
1341}
1342
1343static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
1344 size_t bytes)
1345{
1346 struct stream_out *out = (struct stream_out *)stream;
1347 struct audio_device *adev = out->dev;
1348 int i, ret = -1;
1349
1350 /* acquiring hw device mutex systematically is useful if a low priority thread is waiting
1351 * on the output stream mutex - e.g. executing select_mode() while holding the hw device
1352 * mutex
1353 */
1354 pthread_mutex_lock(&adev->lock);
1355 pthread_mutex_lock(&out->lock);
1356 if (out->standby) {
1357 ret = start_output_stream(out);
1358 if (ret != 0) {
1359 pthread_mutex_unlock(&adev->lock);
1360 goto exit;
1361 }
1362 out->standby = false;
1363 }
1364 pthread_mutex_unlock(&adev->lock);
1365
1366 if (out->pcm) {
1367 //ALOGV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes);
1368 ret = pcm_write(out->pcm, (void *)buffer, bytes);
1369 }
1370
1371exit:
1372 pthread_mutex_unlock(&out->lock);
1373
1374 if (ret != 0) {
1375 out_standby(&out->stream.common);
1376 usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) /
1377 out_get_sample_rate(&out->stream.common));
1378 }
1379 return bytes;
1380}
1381
1382static int out_get_render_position(const struct audio_stream_out *stream,
1383 uint32_t *dsp_frames)
1384{
1385 return -EINVAL;
1386}
1387
1388static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1389{
1390 return 0;
1391}
1392
1393static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1394{
1395 return 0;
1396}
1397
1398static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
1399 int64_t *timestamp)
1400{
1401 return -EINVAL;
1402}
1403
1404/** audio_stream_in implementation **/
1405static uint32_t in_get_sample_rate(const struct audio_stream *stream)
1406{
1407 struct stream_in *in = (struct stream_in *)stream;
1408
1409 return in->config.rate;
1410}
1411
1412static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1413{
1414 return -ENOSYS;
1415}
1416
1417static size_t in_get_buffer_size(const struct audio_stream *stream)
1418{
1419 struct stream_in *in = (struct stream_in *)stream;
1420
1421 return in->config.period_size * audio_stream_frame_size(stream);
1422}
1423
1424static uint32_t in_get_channels(const struct audio_stream *stream)
1425{
1426 struct stream_in *in = (struct stream_in *)stream;
1427
1428 return in->channel_mask;
1429}
1430
1431static audio_format_t in_get_format(const struct audio_stream *stream)
1432{
1433 return AUDIO_FORMAT_PCM_16_BIT;
1434}
1435
1436static int in_set_format(struct audio_stream *stream, audio_format_t format)
1437{
1438 return -ENOSYS;
1439}
1440
1441static int in_standby(struct audio_stream *stream)
1442{
1443 struct stream_in *in = (struct stream_in *)stream;
1444 struct audio_device *adev = in->dev;
1445 int status = 0;
1446 ALOGV("%s: enter", __func__);
1447 pthread_mutex_lock(&adev->lock);
1448 pthread_mutex_lock(&in->lock);
1449 if (!in->standby) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001450 in->standby = true;
1451 status = stop_input_stream(in);
1452 }
1453 pthread_mutex_unlock(&in->lock);
1454 pthread_mutex_unlock(&adev->lock);
1455 ALOGV("%s: exit: status(%d)", __func__, status);
1456 return status;
1457}
1458
1459static int in_dump(const struct audio_stream *stream, int fd)
1460{
1461 return 0;
1462}
1463
1464static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
1465{
1466 struct stream_in *in = (struct stream_in *)stream;
1467 struct audio_device *adev = in->dev;
1468 struct str_parms *parms;
1469 char *str;
1470 char value[32];
1471 int ret, val = 0;
1472
1473 ALOGV("%s: enter: kvpairs=%s", __func__, kvpairs);
1474 parms = str_parms_create_str(kvpairs);
1475
1476 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value));
1477
1478 pthread_mutex_lock(&adev->lock);
1479 pthread_mutex_lock(&in->lock);
1480 if (ret >= 0) {
1481 val = atoi(value);
1482 /* no audio source uses val == 0 */
1483 if ((in->source != val) && (val != 0)) {
1484 in->source = val;
1485 }
1486 }
1487
1488 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1489 if (ret >= 0) {
1490 val = atoi(value);
1491 if ((in->device != val) && (val != 0)) {
1492 in->device = val;
1493 /* If recording is in progress, change the tx device to new device */
1494 if (!in->standby) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001495 ret = select_devices(adev);
1496 }
1497 }
1498 }
1499
1500 pthread_mutex_unlock(&in->lock);
1501 pthread_mutex_unlock(&adev->lock);
1502
1503 str_parms_destroy(parms);
1504 ALOGV("%s: exit: status(%d)", __func__, ret);
1505 return ret;
1506}
1507
1508static char* in_get_parameters(const struct audio_stream *stream,
1509 const char *keys)
1510{
1511 return strdup("");
1512}
1513
1514static int in_set_gain(struct audio_stream_in *stream, float gain)
1515{
1516 return 0;
1517}
1518
1519static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
1520 size_t bytes)
1521{
1522 struct stream_in *in = (struct stream_in *)stream;
1523 struct audio_device *adev = in->dev;
1524 int i, ret = -1;
1525
1526 /* acquiring hw device mutex systematically is useful if a low priority thread is waiting
1527 * on the output stream mutex - e.g. executing select_mode() while holding the hw device
1528 * mutex
1529 */
1530 //ALOGV("%s: buffer(%p) bytes(%d)", __func__, buffer, bytes);
1531 pthread_mutex_lock(&adev->lock);
1532 pthread_mutex_lock(&in->lock);
1533 if (in->standby) {
1534 ret = start_input_stream(in);
1535 if (ret != 0) {
1536 pthread_mutex_unlock(&adev->lock);
1537 goto exit;
1538 }
1539 in->standby = 0;
1540 }
1541 pthread_mutex_unlock(&adev->lock);
1542
1543 if (in->pcm) {
1544 ret = pcm_read(in->pcm, buffer, bytes);
1545 }
1546
1547 /*
1548 * Instead of writing zeroes here, we could trust the hardware
1549 * to always provide zeroes when muted.
1550 */
1551 if (ret == 0 && adev->mic_mute)
1552 memset(buffer, 0, bytes);
1553
1554exit:
1555 pthread_mutex_unlock(&in->lock);
1556
1557 if (ret != 0) {
1558 in_standby(&in->stream.common);
1559 ALOGV("%s: read failed - sleeping for buffer duration", __func__);
1560 usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) /
1561 in_get_sample_rate(&in->stream.common));
1562 }
1563 return bytes;
1564}
1565
1566static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
1567{
1568 return 0;
1569}
1570
1571static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1572{
1573 return 0;
1574}
1575
1576static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1577{
1578 return 0;
1579}
1580
1581static int adev_open_output_stream(struct audio_hw_device *dev,
1582 audio_io_handle_t handle,
1583 audio_devices_t devices,
1584 audio_output_flags_t flags,
1585 struct audio_config *config,
1586 struct audio_stream_out **stream_out)
1587{
1588 struct audio_device *adev = (struct audio_device *)dev;
1589 struct stream_out *out;
1590 int i, ret;
1591
1592 ALOGV("%s: enter: sample_rate(%d) channel_mask(0x%x) devices(0x%x) flags(0x%x)",
1593 __func__, config->sample_rate, config->channel_mask, devices, flags);
1594 *stream_out = NULL;
1595 out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
1596
1597 if (devices == AUDIO_DEVICE_NONE)
1598 devices = AUDIO_DEVICE_OUT_SPEAKER;
1599
1600 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;
1601 out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
1602 out->flags = flags;
1603 out->devices = devices;
1604
1605 /* Init use case and pcm_config */
1606 if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT &&
1607 out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1608 out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH;
1609 out->config = pcm_config_hdmi_multi;
1610
1611 pthread_mutex_lock(&adev->lock);
1612 read_hdmi_channel_masks(out);
1613 pthread_mutex_unlock(&adev->lock);
1614
1615 if (config->sample_rate == 0) config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
1616 if (config->channel_mask == 0) config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1;
1617 out->channel_mask = config->channel_mask;
1618 out->config.rate = config->sample_rate;
1619 out->config.channels = popcount(out->channel_mask);
1620 out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2);
1621 set_hdmi_channels(adev->mixer, out->config.channels);
1622 } else if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) {
1623 out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER;
1624 out->config = pcm_config_deep_buffer;
1625 } else {
1626 out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY;
1627 out->config = pcm_config_low_latency;
1628 }
1629
1630 /* Check if this usecase is already existing */
1631 pthread_mutex_lock(&adev->lock);
1632 if (get_usecase_from_list(adev, out->usecase) != NULL) {
1633 ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase);
1634 free(out);
1635 *stream_out = NULL;
1636 pthread_mutex_unlock(&adev->lock);
1637 return -EEXIST;
1638 }
1639 pthread_mutex_unlock(&adev->lock);
1640
1641 out->stream.common.get_sample_rate = out_get_sample_rate;
1642 out->stream.common.set_sample_rate = out_set_sample_rate;
1643 out->stream.common.get_buffer_size = out_get_buffer_size;
1644 out->stream.common.get_channels = out_get_channels;
1645 out->stream.common.get_format = out_get_format;
1646 out->stream.common.set_format = out_set_format;
1647 out->stream.common.standby = out_standby;
1648 out->stream.common.dump = out_dump;
1649 out->stream.common.set_parameters = out_set_parameters;
1650 out->stream.common.get_parameters = out_get_parameters;
1651 out->stream.common.add_audio_effect = out_add_audio_effect;
1652 out->stream.common.remove_audio_effect = out_remove_audio_effect;
1653 out->stream.get_latency = out_get_latency;
1654 out->stream.set_volume = out_set_volume;
1655 out->stream.write = out_write;
1656 out->stream.get_render_position = out_get_render_position;
1657 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
1658
1659 out->dev = adev;
1660 out->standby = 1;
1661
1662 config->format = out->stream.common.get_format(&out->stream.common);
1663 config->channel_mask = out->stream.common.get_channels(&out->stream.common);
1664 config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common);
1665
1666 *stream_out = &out->stream;
1667 ALOGV("%s: exit", __func__);
1668 return 0;
1669}
1670
1671static void adev_close_output_stream(struct audio_hw_device *dev,
1672 struct audio_stream_out *stream)
1673{
1674 ALOGV("%s: enter", __func__);
1675 out_standby(&stream->common);
1676 free(stream);
1677 ALOGV("%s: exit", __func__);
1678}
1679
1680static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
1681{
1682 struct audio_device *adev = (struct audio_device *)dev;
1683 struct str_parms *parms;
1684 char *str;
1685 char value[32];
1686 int ret;
1687
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08001688 ALOGV("%s: enter: %s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001689
1690 parms = str_parms_create_str(kvpairs);
1691 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
1692 if (ret >= 0) {
1693 int tty_mode;
1694
1695 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
1696 tty_mode = TTY_MODE_OFF;
1697 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
1698 tty_mode = TTY_MODE_VCO;
1699 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
1700 tty_mode = TTY_MODE_HCO;
1701 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
1702 tty_mode = TTY_MODE_FULL;
1703 else
1704 return -EINVAL;
1705
1706 pthread_mutex_lock(&adev->lock);
1707 if (tty_mode != adev->tty_mode) {
1708 adev->tty_mode = tty_mode;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08001709 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
1710 if (adev->in_call)
1711 select_devices(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001712 }
1713 pthread_mutex_unlock(&adev->lock);
1714 }
1715
1716 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
1717 if (ret >= 0) {
1718 /* When set to false, HAL should disable EC and NS
1719 * But it is currently not supported.
1720 */
1721 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1722 adev->bluetooth_nrec = true;
1723 else
1724 adev->bluetooth_nrec = false;
1725 }
1726
1727 ret = str_parms_get_str(parms, "screen_state", value, sizeof(value));
1728 if (ret >= 0) {
1729 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1730 adev->screen_off = false;
1731 else
1732 adev->screen_off = true;
1733 }
1734
1735 str_parms_destroy(parms);
1736 ALOGV("%s: exit with code(%d)", __func__, ret);
1737 return ret;
1738}
1739
1740static char* adev_get_parameters(const struct audio_hw_device *dev,
1741 const char *keys)
1742{
1743 /* ToDo: Return requested params */
1744 return strdup("");
1745}
1746
1747static int adev_init_check(const struct audio_hw_device *dev)
1748{
1749 return 0;
1750}
1751
1752static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
1753{
1754 struct audio_device *adev = (struct audio_device *)dev;
1755 int vol, err = 0;
1756
1757 pthread_mutex_lock(&adev->lock);
1758 adev->voice_volume = volume;
1759 if (adev->mode == AUDIO_MODE_IN_CALL) {
1760 if (volume < 0.0) {
1761 volume = 0.0;
1762 } else if (volume > 1.0) {
1763 volume = 1.0;
1764 }
1765
1766 vol = lrint(volume * 100.0);
1767
1768 // Voice volume levels from android are mapped to driver volume levels as follows.
1769 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
1770 // So adjust the volume to get the correct volume index in driver
1771 vol = 100 - vol;
1772
1773 if (adev->csd_client) {
1774 if (adev->csd_volume == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001775 ALOGE("%s: dlsym error for csd_client_volume", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001776 } else {
1777 err = adev->csd_volume(vol);
1778 if (err < 0) {
1779 ALOGE("%s: csd_client error %d", __func__, err);
1780 }
1781 }
1782 } else {
1783 ALOGE("%s: No CSD Client present", __func__);
1784 }
1785 }
1786 pthread_mutex_unlock(&adev->lock);
1787 return err;
1788}
1789
1790static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
1791{
1792 return -ENOSYS;
1793}
1794
1795static int adev_get_master_volume(struct audio_hw_device *dev,
1796 float *volume)
1797{
1798 return -ENOSYS;
1799}
1800
1801static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
1802{
1803 return -ENOSYS;
1804}
1805
1806static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
1807{
1808 return -ENOSYS;
1809}
1810
1811static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
1812{
1813 struct audio_device *adev = (struct audio_device *)dev;
1814
1815 pthread_mutex_lock(&adev->lock);
1816 if (adev->mode != mode) {
1817 adev->mode = mode;
1818 }
1819 pthread_mutex_unlock(&adev->lock);
1820 return 0;
1821}
1822
1823static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
1824{
1825 struct audio_device *adev = (struct audio_device *)dev;
1826 int err = 0;
1827
1828 adev->mic_mute = state;
1829 if (adev->mode == AUDIO_MODE_IN_CALL) {
1830 if (adev->csd_client) {
1831 if (adev->csd_mic_mute == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001832 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001833 } else {
1834 err = adev->csd_mic_mute(state);
1835 if (err < 0) {
1836 ALOGE("%s: csd_client error %d", __func__, err);
1837 }
1838 }
1839 } else {
1840 ALOGE("%s: No CSD Client present", __func__);
1841 }
1842 }
1843 return err;
1844}
1845
1846static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
1847{
1848 struct audio_device *adev = (struct audio_device *)dev;
1849
1850 *state = adev->mic_mute;
1851
1852 return 0;
1853}
1854
1855static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
1856 const struct audio_config *config)
1857{
1858 size_t size;
1859 int channel_count = popcount(config->channel_mask);
1860
1861 return get_input_buffer_size(config->sample_rate, config->format, channel_count);
1862}
1863
1864static int adev_open_input_stream(struct audio_hw_device *dev,
1865 audio_io_handle_t handle,
1866 audio_devices_t devices,
1867 struct audio_config *config,
1868 struct audio_stream_in **stream_in)
1869{
1870 struct audio_device *adev = (struct audio_device *)dev;
1871 struct stream_in *in;
1872 int ret, buffer_size, frame_size;
1873 int channel_count = popcount(config->channel_mask);
1874
1875 ALOGV("%s: enter", __func__);
1876 *stream_in = NULL;
1877 if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
1878 return -EINVAL;
1879
1880 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
1881
1882 in->stream.common.get_sample_rate = in_get_sample_rate;
1883 in->stream.common.set_sample_rate = in_set_sample_rate;
1884 in->stream.common.get_buffer_size = in_get_buffer_size;
1885 in->stream.common.get_channels = in_get_channels;
1886 in->stream.common.get_format = in_get_format;
1887 in->stream.common.set_format = in_set_format;
1888 in->stream.common.standby = in_standby;
1889 in->stream.common.dump = in_dump;
1890 in->stream.common.set_parameters = in_set_parameters;
1891 in->stream.common.get_parameters = in_get_parameters;
1892 in->stream.common.add_audio_effect = in_add_audio_effect;
1893 in->stream.common.remove_audio_effect = in_remove_audio_effect;
1894 in->stream.set_gain = in_set_gain;
1895 in->stream.read = in_read;
1896 in->stream.get_input_frames_lost = in_get_input_frames_lost;
1897
1898 in->device = devices;
1899 in->source = AUDIO_SOURCE_DEFAULT;
1900 in->dev = adev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001901 in->standby = 1;
1902 in->channel_mask = config->channel_mask;
1903
1904 /* Update config params with the requested sample rate and channels */
1905 in->usecase = USECASE_AUDIO_RECORD;
1906 in->config = pcm_config_audio_capture;
1907 in->config.channels = channel_count;
1908 in->config.rate = config->sample_rate;
1909
1910 frame_size = audio_stream_frame_size((struct audio_stream *)in);
1911 buffer_size = get_input_buffer_size(config->sample_rate,
1912 config->format,
1913 channel_count);
1914 in->config.period_size = buffer_size / frame_size;
1915
1916 *stream_in = &in->stream;
1917 ALOGV("%s: exit", __func__);
1918 return 0;
1919
1920err_open:
1921 free(in);
1922 *stream_in = NULL;
1923 return ret;
1924}
1925
1926static void adev_close_input_stream(struct audio_hw_device *dev,
1927 struct audio_stream_in *stream)
1928{
1929 in_standby(&stream->common);
1930 free(stream);
1931
1932 return;
1933}
1934
1935static int adev_dump(const audio_hw_device_t *device, int fd)
1936{
1937 return 0;
1938}
1939
1940static int adev_close(hw_device_t *device)
1941{
1942 struct audio_device *adev = (struct audio_device *)device;
1943 audio_route_free(adev->audio_route);
1944 free(device);
1945 return 0;
1946}
1947
1948static void init_platform_data(struct audio_device *adev)
1949{
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08001950 char platform[PROPERTY_VALUE_MAX];
1951 char baseband[PROPERTY_VALUE_MAX];
1952 char value[PROPERTY_VALUE_MAX];
1953 int mccmnc;
1954
1955 adev->dualmic_config = DUALMIC_CONFIG_NONE;
1956 adev->fluence_in_voice_call = false;
1957 adev->fluence_in_voice_rec = false;
1958 adev->mic_type_analog = false;
1959
1960 property_get("persist.audio.handset.mic.type",value,"");
1961 if (!strncmp("analog", value, 6))
1962 adev->mic_type_analog = true;
1963
1964 property_get("persist.audio.dualmic.config",value,"");
1965 if (!strncmp("broadside", value, 9)) {
1966 adev->dualmic_config = DUALMIC_CONFIG_BROADSIDE;
1967 adev->acdb_settings |= DMIC_FLAG;
1968 } else if (!strncmp("endfire", value, 7)) {
1969 adev->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
1970 adev->acdb_settings |= DMIC_FLAG;
1971 }
1972
1973 if (adev->dualmic_config != DUALMIC_CONFIG_NONE) {
1974 property_get("persist.audio.fluence.voicecall",value,"");
1975 if (!strncmp("true", value, 4)) {
1976 adev->fluence_in_voice_call = true;
1977 }
1978
1979 property_get("persist.audio.fluence.voicerec",value,"");
1980 if (!strncmp("true", value, 4)) {
1981 adev->fluence_in_voice_rec = true;
1982 }
1983 }
1984
1985 property_get("gsm.sim.operator.numeric",value,"0");
1986 mccmnc = atoi(value);
1987 ALOGV("%s: tmus mccmnc %d", __func__, mccmnc);
1988 switch(mccmnc) {
1989 /* TMUS MCC(310), MNC(490, 260, 026) */
1990 case 310490:
1991 case 310260:
1992 case 310026:
1993 adev->is_tmus = true;
1994 break;
1995 default:
1996 adev->is_tmus = false;
1997 break;
1998 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001999
2000 adev->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
2001 if (adev->acdb_handle == NULL) {
2002 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
2003 } else {
2004 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002005 adev->acdb_deallocate = (acdb_deallocate_t)dlsym(adev->acdb_handle,
2006 "acdb_loader_deallocate_ACDB");
2007 adev->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(adev->acdb_handle,
2008 "acdb_loader_send_audio_cal");
2009 adev->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(adev->acdb_handle,
2010 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002011 adev->acdb_init = (acdb_init_t)dlsym(adev->acdb_handle,
2012 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002013 if (adev->acdb_init == NULL)
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002014 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002015 else
2016 adev->acdb_init();
2017 }
2018
2019 /* If platform is Fusion3, load CSD Client specific symbols
2020 * Voice call is handled by MDM and apps processor talks to
2021 * MDM through CSD Client
2022 */
2023 property_get("ro.board.platform", platform, "");
2024 property_get("ro.baseband", baseband, "");
2025 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
2026 adev->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
2027 if (adev->csd_client == NULL)
2028 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
2029 }
2030
2031 if (adev->csd_client) {
2032 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002033 adev->csd_client_deinit = (csd_client_deinit_t)dlsym(adev->csd_client,
2034 "csd_client_deinit");
2035 adev->csd_disable_device = (csd_disable_device_t)dlsym(adev->csd_client,
2036 "csd_client_disable_device");
2037 adev->csd_enable_device = (csd_enable_device_t)dlsym(adev->csd_client,
2038 "csd_client_enable_device");
2039 adev->csd_start_voice = (csd_start_voice_t)dlsym(adev->csd_client,
2040 "csd_client_start_voice");
2041 adev->csd_stop_voice = (csd_stop_voice_t)dlsym(adev->csd_client,
2042 "csd_client_stop_voice");
2043 adev->csd_volume = (csd_volume_t)dlsym(adev->csd_client,
2044 "csd_client_volume");
2045 adev->csd_mic_mute = (csd_mic_mute_t)dlsym(adev->csd_client,
2046 "csd_client_mic_mute");
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002047 adev->csd_client_init = (csd_client_init_t)dlsym(adev->csd_client,
2048 "csd_client_init");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002049
2050 if (adev->csd_client_init == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002051 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002052 } else {
2053 adev->csd_client_init();
2054 }
2055 }
2056}
2057
2058static int adev_open(const hw_module_t *module, const char *name,
2059 hw_device_t **device)
2060{
2061 struct audio_device *adev;
2062 int ret;
2063
2064 ALOGV("%s: enter", __func__);
2065 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;
2066
2067 adev = calloc(1, sizeof(struct audio_device));
2068
2069 adev->mixer = mixer_open(MIXER_CARD);
2070 if (!adev->mixer) {
2071 ALOGE("Unable to open the mixer, aborting.");
2072 return -ENOSYS;
2073 }
2074
2075 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
2076 if (!adev->audio_route) {
2077 free(adev);
2078 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
2079 *device = NULL;
2080 return -EINVAL;
2081 }
2082
2083 adev->device.common.tag = HARDWARE_DEVICE_TAG;
2084 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
2085 adev->device.common.module = (struct hw_module_t *)module;
2086 adev->device.common.close = adev_close;
2087
2088 adev->device.init_check = adev_init_check;
2089 adev->device.set_voice_volume = adev_set_voice_volume;
2090 adev->device.set_master_volume = adev_set_master_volume;
2091 adev->device.get_master_volume = adev_get_master_volume;
2092 adev->device.set_master_mute = adev_set_master_mute;
2093 adev->device.get_master_mute = adev_get_master_mute;
2094 adev->device.set_mode = adev_set_mode;
2095 adev->device.set_mic_mute = adev_set_mic_mute;
2096 adev->device.get_mic_mute = adev_get_mic_mute;
2097 adev->device.set_parameters = adev_set_parameters;
2098 adev->device.get_parameters = adev_get_parameters;
2099 adev->device.get_input_buffer_size = adev_get_input_buffer_size;
2100 adev->device.open_output_stream = adev_open_output_stream;
2101 adev->device.close_output_stream = adev_close_output_stream;
2102 adev->device.open_input_stream = adev_open_input_stream;
2103 adev->device.close_input_stream = adev_close_input_stream;
2104 adev->device.dump = adev_dump;
2105
2106 /* Set the default route before the PCM stream is opened */
2107 pthread_mutex_lock(&adev->lock);
2108 adev->mode = AUDIO_MODE_NORMAL;
Eric Laurentc8400632013-02-14 19:04:54 -08002109 adev->active_input = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002110 adev->out_device = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002111 adev->voice_call_rx = NULL;
2112 adev->voice_call_tx = NULL;
2113 adev->voice_volume = 1.0f;
2114 adev->tty_mode = TTY_MODE_OFF;
2115 adev->bluetooth_nrec = true;
2116 adev->cur_out_snd_device = 0;
2117 adev->cur_in_snd_device = 0;
2118 adev->out_snd_device_active = false;
2119 adev->in_snd_device_active = false;
2120 adev->usecase_list.next = NULL;
2121 adev->usecase_list.id = USECASE_INVALID;
2122 adev->in_call = false;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08002123 adev->acdb_settings = TTY_MODE_OFF;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002124 pthread_mutex_unlock(&adev->lock);
2125
2126 /* Loads platform specific libraries dynamically */
2127 init_platform_data(adev);
2128
2129 *device = &adev->device.common;
2130
2131 ALOGV("%s: exit", __func__);
2132 return 0;
2133}
2134
2135static struct hw_module_methods_t hal_module_methods = {
2136 .open = adev_open,
2137};
2138
2139struct audio_module HAL_MODULE_INFO_SYM = {
2140 .common = {
2141 .tag = HARDWARE_MODULE_TAG,
2142 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
2143 .hal_api_version = HARDWARE_HAL_API_VERSION,
2144 .id = AUDIO_HARDWARE_MODULE_ID,
2145 .name = "QCOM Audio HAL",
2146 .author = "Code Aurora Forum",
2147 .methods = &hal_module_methods,
2148 },
2149};