blob: 0628e76a9b43795b3a93f5ef90ee489c62d0af30 [file] [log] [blame]
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001/*
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003 * Not a contribution.
4 *
Shiv Maliyappanahalli8911f282014-01-10 15:56:19 -08005 * Copyright (C) 2013 The Android Open Source Project
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#define LOG_TAG "voice"
21/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <errno.h>
25#include <math.h>
26#include <cutils/log.h>
27#include <cutils/str_parms.h>
28
29#include "audio_hw.h"
30#include "voice.h"
31#include "voice_extn/voice_extn.h"
32#include "platform.h"
33#include "platform_api.h"
Kiran Kandi910e1862013-10-29 13:29:42 -070034#include "audio_extn.h"
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070035
36struct pcm_config pcm_config_voice_call = {
37 .channels = 1,
38 .rate = 8000,
39 .period_size = 160,
40 .period_count = 2,
41 .format = PCM_FORMAT_S16_LE,
42};
43
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -080044extern const char * const use_case_table[AUDIO_USECASE_MAX];
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070045
46static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev,
47 audio_usecase_t usecase_id)
48{
49 struct voice_session *session = NULL;
50 int ret = 0;
51
52 ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session);
53 if (ret == -ENOSYS) {
54 session = &adev->voice.session[VOICE_SESS_IDX];
55 }
56
57 return session;
58}
59
60int stop_call(struct audio_device *adev, audio_usecase_t usecase_id)
61{
62 int i, ret = 0;
63 struct audio_usecase *uc_info;
64 struct voice_session *session = NULL;
65
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -080066 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070067
68 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew Georgebac2cba2014-06-30 13:56:18 -070069 if (!session) {
70 ALOGE("stop_call: couldn't find voice session");
71 return -EINVAL;
72 }
73
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070074 session->state.current = CALL_INACTIVE;
75
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -080076 ret = platform_stop_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070077
78 /* 1. Close the PCM devices */
79 if (session->pcm_rx) {
80 pcm_close(session->pcm_rx);
81 session->pcm_rx = NULL;
82 }
83 if (session->pcm_tx) {
84 pcm_close(session->pcm_tx);
85 session->pcm_tx = NULL;
86 }
87
88 uc_info = get_usecase_from_list(adev, usecase_id);
89 if (uc_info == NULL) {
90 ALOGE("%s: Could not find the usecase (%d) in the list",
91 __func__, usecase_id);
92 return -EINVAL;
93 }
94
95 /* 2. Get and set stream specific mixer controls */
Haynes Mathew Georgeea098922014-04-24 17:53:50 -070096 disable_audio_route(adev, uc_info);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070097
98 /* 3. Disable the rx and tx devices */
Haynes Mathew Georgeea098922014-04-24 17:53:50 -070099 disable_snd_device(adev, uc_info->out_snd_device);
100 disable_snd_device(adev, uc_info->in_snd_device);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700101
102 list_remove(&uc_info->list);
103 free(uc_info);
104
105 ALOGD("%s: exit: status(%d)", __func__, ret);
106 return ret;
107}
108
109int start_call(struct audio_device *adev, audio_usecase_t usecase_id)
110{
111 int i, ret = 0;
112 struct audio_usecase *uc_info;
113 int pcm_dev_rx_id, pcm_dev_tx_id;
114 struct voice_session *session = NULL;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700115 struct pcm_config voice_config = pcm_config_voice_call;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800116
117 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700118
119 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew Georgebac2cba2014-06-30 13:56:18 -0700120 if (!session) {
121 ALOGE("start_call: couldn't find voice session");
122 return -EINVAL;
123 }
124
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700125 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew Georgebac2cba2014-06-30 13:56:18 -0700126 if (!uc_info) {
127 ALOGE("start_call: couldn't allocate mem for audio_usecase");
128 return -ENOMEM;
129 }
130
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700131 uc_info->id = usecase_id;
132 uc_info->type = VOICE_CALL;
Divya Narayanan Poojaryab9b1ef2014-09-12 15:52:36 +0530133 uc_info->stream.out = adev->current_call_output;
134 uc_info->devices = adev->current_call_output->devices;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700135 uc_info->in_snd_device = SND_DEVICE_NONE;
136 uc_info->out_snd_device = SND_DEVICE_NONE;
137
138 list_add_tail(&adev->usecase_list, &uc_info->list);
139
140 select_devices(adev, usecase_id);
141
142 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
143 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
144
145 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
146 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
147 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
148 ret = -EIO;
149 goto error_start_voice;
150 }
151
152 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800153 __func__, adev->snd_card, pcm_dev_rx_id);
154 session->pcm_rx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700155 pcm_dev_rx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700156 PCM_OUT, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700157 if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) {
158 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
159 ret = -EIO;
160 goto error_start_voice;
161 }
162
163 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800164 __func__, adev->snd_card, pcm_dev_tx_id);
165 session->pcm_tx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700166 pcm_dev_tx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700167 PCM_IN, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700168 if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) {
169 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
170 ret = -EIO;
171 goto error_start_voice;
172 }
173 pcm_start(session->pcm_rx);
174 pcm_start(session->pcm_tx);
175
Shruthi Krishnaace10852013-10-25 14:32:12 -0700176 voice_set_volume(adev, adev->voice.volume);
177
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800178 ret = platform_start_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700179 if (ret < 0) {
180 ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
181 goto error_start_voice;
182 }
183
184 session->state.current = CALL_ACTIVE;
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700185 goto done;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700186
187error_start_voice:
188 stop_call(adev, usecase_id);
189
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700190done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700191 ALOGD("%s: exit: status(%d)", __func__, ret);
192 return ret;
193}
194
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700195bool voice_is_call_state_active(struct audio_device *adev)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700196{
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700197 bool call_state = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700198 int ret = 0;
199
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700200 ret = voice_extn_is_call_state_active(adev, &call_state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700201 if (ret == -ENOSYS) {
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700202 call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700203 }
204
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700205 return call_state;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700206}
207
kunleiza1a9ee02014-04-24 18:46:22 +0800208bool voice_is_in_call_rec_stream(struct stream_in *in)
209{
210 bool in_call_rec = false;
211 int ret = 0;
212
213 ret = voice_extn_is_in_call_rec_stream(in, &in_call_rec);
214 if (ret == -ENOSYS) {
215 in_call_rec = false;
216 }
217
218 return in_call_rec;
219}
220
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700221uint32_t voice_get_active_session_id(struct audio_device *adev)
222{
223 int ret = 0;
224 uint32_t session_id;
225
226 ret = voice_extn_get_active_session_id(adev, &session_id);
227 if (ret == -ENOSYS) {
228 session_id = VOICE_VSID;
229 }
230 return session_id;
231}
232
233int voice_check_and_set_incall_rec_usecase(struct audio_device *adev,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800234 struct stream_in *in)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700235{
236 int ret = 0;
237 uint32_t session_id;
238 int usecase_id;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800239 int rec_mode = INCALL_REC_NONE;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700240
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700241 if (voice_is_call_state_active(adev)) {
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700242 switch (in->source) {
243 case AUDIO_SOURCE_VOICE_UPLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800244 if (audio_extn_compr_cap_enabled() &&
245 audio_extn_compr_cap_format_supported(in->config.format)) {
246 in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS;
247 } else
248 in->usecase = USECASE_INCALL_REC_UPLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800249 rec_mode = INCALL_REC_UPLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700250 break;
251 case AUDIO_SOURCE_VOICE_DOWNLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800252 if (audio_extn_compr_cap_enabled() &&
253 audio_extn_compr_cap_format_supported(in->config.format)) {
254 in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS;
255 } else
256 in->usecase = USECASE_INCALL_REC_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800257 rec_mode = INCALL_REC_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700258 break;
259 case AUDIO_SOURCE_VOICE_CALL:
Helen Zenge56b4852013-12-03 16:54:40 -0800260 if (audio_extn_compr_cap_enabled() &&
261 audio_extn_compr_cap_format_supported(in->config.format)) {
262 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS;
263 } else
264 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800265 rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700266 break;
267 default:
268 ALOGV("%s: Source type %d doesnt match incall recording criteria",
269 __func__, in->source);
270 return ret;
271 }
272
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700273 session_id = voice_get_active_session_id(adev);
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800274 ret = platform_set_incall_recording_session_id(adev->platform,
275 session_id, rec_mode);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700276 ALOGV("%s: Update usecase to %d",__func__, in->usecase);
277 } else {
Venkata Narendra Kumar Gutta5501ffa2015-03-30 19:16:14 +0530278 /*
279 * Reject the recording instances, where the recording is started
280 * with In-call voice recording source types but voice call is not
281 * active by the time input is started
282 */
283 if ((in->source == AUDIO_SOURCE_VOICE_UPLINK) ||
284 (in->source == AUDIO_SOURCE_VOICE_DOWNLINK) ||
285 (in->source == AUDIO_SOURCE_VOICE_CALL)) {
286 ret = -EINVAL;
287 ALOGE("%s: As voice call is not active, Incall rec usecase can't be \
288 selected for requested source:%d",__func__, in->source);
289 }
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700290 ALOGV("%s: voice call not active", __func__);
291 }
292
293 return ret;
294}
295
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800296int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev,
297 struct stream_in *in)
298{
299 int ret = 0;
300
301 if (in->source == AUDIO_SOURCE_VOICE_UPLINK ||
302 in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
303 in->source == AUDIO_SOURCE_VOICE_CALL) {
304 ret = platform_stop_incall_recording_usecase(adev->platform);
305 ALOGV("%s: Stop In-call recording", __func__);
306 }
307
308 return ret;
309}
310
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700311int voice_check_and_set_incall_music_usecase(struct audio_device *adev,
312 struct stream_out *out)
313{
314 int ret = 0;
315
316 ret = voice_extn_check_and_set_incall_music_usecase(adev, out);
317 if (ret == -ENOSYS) {
318 /* Incall music delivery is used only for LCH call state */
319 ret = -EINVAL;
320 }
321
322 return ret;
323}
324
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700325int voice_set_mic_mute(struct audio_device *adev, bool state)
326{
327 int err = 0;
328
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800329 adev->voice.mic_mute = state;
330 if (adev->mode == AUDIO_MODE_IN_CALL)
331 err = platform_set_mic_mute(adev->platform, state);
332 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
333 err = voice_extn_compress_voip_set_mic_mute(adev, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700334
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700335 return err;
336}
337
338bool voice_get_mic_mute(struct audio_device *adev)
339{
340 return adev->voice.mic_mute;
341}
342
343int voice_set_volume(struct audio_device *adev, float volume)
344{
345 int vol, err = 0;
346
Shruthi Krishnaace10852013-10-25 14:32:12 -0700347 adev->voice.volume = volume;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700348 if (adev->mode == AUDIO_MODE_IN_CALL) {
349 if (volume < 0.0) {
350 volume = 0.0;
351 } else if (volume > 1.0) {
352 volume = 1.0;
353 }
354
355 vol = lrint(volume * 100.0);
356
357 // Voice volume levels from android are mapped to driver volume levels as follows.
358 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
359 // So adjust the volume to get the correct volume index in driver
360 vol = 100 - vol;
361
362 err = platform_set_voice_volume(adev->platform, vol);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700363 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800364 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
365 err = voice_extn_compress_voip_set_volume(adev, volume);
366
Shruthi Krishnaace10852013-10-25 14:32:12 -0700367
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700368 return err;
369}
370
371int voice_start_call(struct audio_device *adev)
372{
373 int ret = 0;
374
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800375 ret = voice_extn_start_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700376 if (ret == -ENOSYS) {
377 ret = start_call(adev, USECASE_VOICE_CALL);
378 }
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700379 adev->voice.in_call = true;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700380
381 return ret;
382}
383
384int voice_stop_call(struct audio_device *adev)
385{
386 int ret = 0;
387
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700388 adev->voice.in_call = false;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800389 ret = voice_extn_stop_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700390 if (ret == -ENOSYS) {
391 ret = stop_call(adev, USECASE_VOICE_CALL);
392 }
393
394 return ret;
395}
396
Shiv Maliyappanahallif9308492013-12-12 12:18:09 -0800397void voice_get_parameters(struct audio_device *adev,
398 struct str_parms *query,
399 struct str_parms *reply)
400{
401 voice_extn_get_parameters(adev, query, reply);
402}
403
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700404int voice_set_parameters(struct audio_device *adev, struct str_parms *parms)
405{
406 char *str;
407 char value[32];
408 int val;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800409 int ret = 0, err;
Krishnankutty Kolathappilly301cc362014-01-31 18:12:13 -0800410 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700411
Krishnankutty Kolathappilly301cc362014-01-31 18:12:13 -0800412 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700413
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800414 ret = voice_extn_set_parameters(adev, parms);
Vidyakumar Athota7992b8e2014-07-21 14:51:44 -0700415 if (ret != 0) {
416 if (ret == -ENOSYS)
417 ret = 0;
418 else
419 goto done;
420 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700421
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800422 ret = voice_extn_compress_voip_set_parameters(adev, parms);
Vidyakumar Athota7992b8e2014-07-21 14:51:44 -0700423 if (ret != 0) {
424 if (ret == -ENOSYS)
425 ret = 0;
426 else
427 goto done;
428 }
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800429
430 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
431 if (err >= 0) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700432 int tty_mode;
433 str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE);
434 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
435 tty_mode = TTY_MODE_OFF;
436 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
437 tty_mode = TTY_MODE_VCO;
438 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
439 tty_mode = TTY_MODE_HCO;
440 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
441 tty_mode = TTY_MODE_FULL;
442 else {
443 ret = -EINVAL;
444 goto done;
445 }
446
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700447 if (tty_mode != adev->voice.tty_mode) {
448 adev->voice.tty_mode = tty_mode;
449 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700450 if (voice_is_call_state_active(adev))
Narsinga Rao Chellac9bf40d2014-02-06 14:05:14 -0800451 voice_update_devices_for_all_voice_usecases(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700452 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700453 }
454
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800455 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800456 value, sizeof(value));
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800457 if (err >= 0) {
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800458 str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC);
459 if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0)
460 platform_start_incall_music_usecase(adev->platform);
461 else
462 platform_stop_incall_music_usecase(adev->platform);
Vidyakumar Athota7992b8e2014-07-21 14:51:44 -0700463 }
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800464
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700465done:
466 ALOGV("%s: exit with code(%d)", __func__, ret);
Krishnankutty Kolathappilly301cc362014-01-31 18:12:13 -0800467 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700468 return ret;
469}
470
471void voice_init(struct audio_device *adev)
472{
473 int i = 0;
474
475 memset(&adev->voice, 0, sizeof(adev->voice));
476 adev->voice.tty_mode = TTY_MODE_OFF;
477 adev->voice.volume = 1.0f;
478 adev->voice.mic_mute = false;
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700479 adev->voice.in_call = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700480 for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
481 adev->voice.session[i].pcm_rx = NULL;
482 adev->voice.session[i].pcm_tx = NULL;
483 adev->voice.session[i].state.current = CALL_INACTIVE;
484 adev->voice.session[i].state.new = CALL_INACTIVE;
Tony Layher209c7af2015-01-03 13:16:45 -0500485#ifdef PLATFORM_APQ8084
486 adev->voice.session[i].vsid = VOICE_VSID;
487#else
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700488 adev->voice.session[i].vsid = 0;
Tony Layher209c7af2015-01-03 13:16:45 -0500489#endif
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700490 }
491
492 voice_extn_init(adev);
493}
494
Narsinga Rao Chellac9bf40d2014-02-06 14:05:14 -0800495void voice_update_devices_for_all_voice_usecases(struct audio_device *adev)
496{
497 struct listnode *node;
498 struct audio_usecase *usecase;
499
500 list_for_each(node, &adev->usecase_list) {
501 usecase = node_to_item(node, struct audio_usecase, list);
502 if (usecase->type == VOICE_CALL) {
503 ALOGV("%s: updating device for usecase:%s", __func__,
504 use_case_table[usecase->id]);
Divya Narayanan Poojaryab9b1ef2014-09-12 15:52:36 +0530505 usecase->stream.out = adev->current_call_output;
Narsinga Rao Chellac9bf40d2014-02-06 14:05:14 -0800506 select_devices(adev, usecase->id);
507 }
508 }
509}
510
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700511