blob: 33e0d2c3868ca59511f9537a3381bed4e389fced [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 Georgeb51ceb12014-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;
Venkata Narendra Kumar Gutta5f64eea2014-05-28 17:42:10 +053075 if (adev->mode == AUDIO_MODE_NORMAL)
76 adev->voice.is_in_call = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070077
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -080078 ret = platform_stop_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070079
80 /* 1. Close the PCM devices */
81 if (session->pcm_rx) {
82 pcm_close(session->pcm_rx);
83 session->pcm_rx = NULL;
84 }
85 if (session->pcm_tx) {
86 pcm_close(session->pcm_tx);
87 session->pcm_tx = NULL;
88 }
89
90 uc_info = get_usecase_from_list(adev, usecase_id);
91 if (uc_info == NULL) {
92 ALOGE("%s: Could not find the usecase (%d) in the list",
93 __func__, usecase_id);
94 return -EINVAL;
95 }
96
97 /* 2. Get and set stream specific mixer controls */
Haynes Mathew George1376ca62014-04-24 11:55:48 -070098 disable_audio_route(adev, uc_info);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070099
100 /* 3. Disable the rx and tx devices */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700101 disable_snd_device(adev, uc_info->out_snd_device);
102 disable_snd_device(adev, uc_info->in_snd_device);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700103
104 list_remove(&uc_info->list);
105 free(uc_info);
106
107 ALOGD("%s: exit: status(%d)", __func__, ret);
108 return ret;
109}
110
111int start_call(struct audio_device *adev, audio_usecase_t usecase_id)
112{
113 int i, ret = 0;
114 struct audio_usecase *uc_info;
115 int pcm_dev_rx_id, pcm_dev_tx_id;
Helen Zeng6a16ad72014-02-23 22:04:44 -0800116 uint32_t sample_rate = 8000;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700117 struct voice_session *session = NULL;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700118 struct pcm_config voice_config = pcm_config_voice_call;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800119
120 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700121
122 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700123 if (!session) {
124 ALOGE("start_call: couldn't find voice session");
125 return -EINVAL;
126 }
127
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700128 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700129 if (!uc_info) {
130 ALOGE("start_call: couldn't allocate mem for audio_usecase");
131 return -ENOMEM;
132 }
133
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700134 uc_info->id = usecase_id;
135 uc_info->type = VOICE_CALL;
136 uc_info->stream.out = adev->primary_output;
137 uc_info->devices = adev->primary_output->devices;
138 uc_info->in_snd_device = SND_DEVICE_NONE;
139 uc_info->out_snd_device = SND_DEVICE_NONE;
140
141 list_add_tail(&adev->usecase_list, &uc_info->list);
142
143 select_devices(adev, usecase_id);
144
145 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
146 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
147
148 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
149 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
150 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
151 ret = -EIO;
152 goto error_start_voice;
153 }
Helen Zeng6a16ad72014-02-23 22:04:44 -0800154 ret = platform_get_sample_rate(adev->platform, &sample_rate);
155 if (ret < 0) {
156 ALOGE("platform_get_sample_rate error %d\n", ret);
157 } else {
158 voice_config.rate = sample_rate;
159 }
160 ALOGD("voice_config.rate %d\n", voice_config.rate);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700161
162 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800163 __func__, adev->snd_card, pcm_dev_rx_id);
164 session->pcm_rx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700165 pcm_dev_rx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700166 PCM_OUT, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700167 if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) {
168 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
169 ret = -EIO;
170 goto error_start_voice;
171 }
172
173 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800174 __func__, adev->snd_card, pcm_dev_tx_id);
175 session->pcm_tx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700176 pcm_dev_tx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700177 PCM_IN, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700178 if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) {
179 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
180 ret = -EIO;
181 goto error_start_voice;
182 }
183 pcm_start(session->pcm_rx);
184 pcm_start(session->pcm_tx);
185
Shruthi Krishnaace10852013-10-25 14:32:12 -0700186 voice_set_volume(adev, adev->voice.volume);
187
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800188 ret = platform_start_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700189 if (ret < 0) {
190 ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
191 goto error_start_voice;
192 }
193
194 session->state.current = CALL_ACTIVE;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700195 goto done;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700196
197error_start_voice:
198 stop_call(adev, usecase_id);
199
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700200done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700201 ALOGD("%s: exit: status(%d)", __func__, ret);
202 return ret;
203}
204
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700205bool voice_is_call_state_active(struct audio_device *adev)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700206{
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700207 bool call_state = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700208 int ret = 0;
209
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700210 ret = voice_extn_is_call_state_active(adev, &call_state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700211 if (ret == -ENOSYS) {
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700212 call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700213 }
214
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700215 return call_state;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700216}
217
kunleizc5a639b2014-04-24 18:46:22 +0800218bool voice_is_in_call_rec_stream(struct stream_in *in)
219{
220 bool in_call_rec = false;
221 int ret = 0;
222
223 ret = voice_extn_is_in_call_rec_stream(in, &in_call_rec);
224 if (ret == -ENOSYS) {
225 in_call_rec = false;
226 }
227
228 return in_call_rec;
229}
230
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700231uint32_t voice_get_active_session_id(struct audio_device *adev)
232{
233 int ret = 0;
234 uint32_t session_id;
235
236 ret = voice_extn_get_active_session_id(adev, &session_id);
237 if (ret == -ENOSYS) {
238 session_id = VOICE_VSID;
239 }
240 return session_id;
241}
242
243int voice_check_and_set_incall_rec_usecase(struct audio_device *adev,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800244 struct stream_in *in)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700245{
246 int ret = 0;
247 uint32_t session_id;
248 int usecase_id;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800249 int rec_mode = INCALL_REC_NONE;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700250
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700251 if (voice_is_call_state_active(adev)) {
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700252 switch (in->source) {
253 case AUDIO_SOURCE_VOICE_UPLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800254 if (audio_extn_compr_cap_enabled() &&
255 audio_extn_compr_cap_format_supported(in->config.format)) {
256 in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS;
257 } else
258 in->usecase = USECASE_INCALL_REC_UPLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800259 rec_mode = INCALL_REC_UPLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700260 break;
261 case AUDIO_SOURCE_VOICE_DOWNLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800262 if (audio_extn_compr_cap_enabled() &&
263 audio_extn_compr_cap_format_supported(in->config.format)) {
264 in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS;
265 } else
266 in->usecase = USECASE_INCALL_REC_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800267 rec_mode = INCALL_REC_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700268 break;
269 case AUDIO_SOURCE_VOICE_CALL:
Helen Zenge56b4852013-12-03 16:54:40 -0800270 if (audio_extn_compr_cap_enabled() &&
271 audio_extn_compr_cap_format_supported(in->config.format)) {
272 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS;
273 } else
274 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800275 rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700276 break;
277 default:
278 ALOGV("%s: Source type %d doesnt match incall recording criteria",
279 __func__, in->source);
280 return ret;
281 }
282
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700283 session_id = voice_get_active_session_id(adev);
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800284 ret = platform_set_incall_recording_session_id(adev->platform,
285 session_id, rec_mode);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700286 ALOGV("%s: Update usecase to %d",__func__, in->usecase);
287 } else {
288 ALOGV("%s: voice call not active", __func__);
289 }
290
291 return ret;
292}
293
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800294int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev,
295 struct stream_in *in)
296{
297 int ret = 0;
298
299 if (in->source == AUDIO_SOURCE_VOICE_UPLINK ||
300 in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
301 in->source == AUDIO_SOURCE_VOICE_CALL) {
302 ret = platform_stop_incall_recording_usecase(adev->platform);
303 ALOGV("%s: Stop In-call recording", __func__);
304 }
305
306 return ret;
307}
308
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700309int voice_check_and_set_incall_music_usecase(struct audio_device *adev,
310 struct stream_out *out)
311{
312 int ret = 0;
313
314 ret = voice_extn_check_and_set_incall_music_usecase(adev, out);
315 if (ret == -ENOSYS) {
316 /* Incall music delivery is used only for LCH call state */
317 ret = -EINVAL;
318 }
319
320 return ret;
321}
322
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700323int voice_set_mic_mute(struct audio_device *adev, bool state)
324{
325 int err = 0;
326
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800327 adev->voice.mic_mute = state;
328 if (adev->mode == AUDIO_MODE_IN_CALL)
329 err = platform_set_mic_mute(adev->platform, state);
330 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
331 err = voice_extn_compress_voip_set_mic_mute(adev, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700332
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700333 return err;
334}
335
336bool voice_get_mic_mute(struct audio_device *adev)
337{
338 return adev->voice.mic_mute;
339}
340
341int voice_set_volume(struct audio_device *adev, float volume)
342{
343 int vol, err = 0;
344
Shruthi Krishnaace10852013-10-25 14:32:12 -0700345 adev->voice.volume = volume;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700346 if (adev->mode == AUDIO_MODE_IN_CALL) {
347 if (volume < 0.0) {
348 volume = 0.0;
349 } else if (volume > 1.0) {
350 volume = 1.0;
351 }
352
353 vol = lrint(volume * 100.0);
354
355 // Voice volume levels from android are mapped to driver volume levels as follows.
356 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
357 // So adjust the volume to get the correct volume index in driver
358 vol = 100 - vol;
359
360 err = platform_set_voice_volume(adev->platform, vol);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700361 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800362 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
363 err = voice_extn_compress_voip_set_volume(adev, volume);
364
Shruthi Krishnaace10852013-10-25 14:32:12 -0700365
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700366 return err;
367}
368
369int voice_start_call(struct audio_device *adev)
370{
371 int ret = 0;
372
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800373 ret = voice_extn_start_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700374 if (ret == -ENOSYS) {
375 ret = start_call(adev, USECASE_VOICE_CALL);
376 }
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700377 adev->voice.in_call = true;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700378
379 return ret;
380}
381
382int voice_stop_call(struct audio_device *adev)
383{
384 int ret = 0;
385
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700386 adev->voice.in_call = false;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800387 ret = voice_extn_stop_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700388 if (ret == -ENOSYS) {
389 ret = stop_call(adev, USECASE_VOICE_CALL);
390 }
391
392 return ret;
393}
394
Shiv Maliyappanahallif9308492013-12-12 12:18:09 -0800395void voice_get_parameters(struct audio_device *adev,
396 struct str_parms *query,
397 struct str_parms *reply)
398{
399 voice_extn_get_parameters(adev, query, reply);
400}
401
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700402int voice_set_parameters(struct audio_device *adev, struct str_parms *parms)
403{
404 char *str;
405 char value[32];
406 int val;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800407 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800408 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700409
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800410 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700411
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800412 ret = voice_extn_set_parameters(adev, parms);
413 if (ret != 0)
414 goto done;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700415
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800416 ret = voice_extn_compress_voip_set_parameters(adev, parms);
417 if (ret != 0)
418 goto done;
419
420 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
421 if (err >= 0) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700422 int tty_mode;
423 str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE);
424 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
425 tty_mode = TTY_MODE_OFF;
426 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
427 tty_mode = TTY_MODE_VCO;
428 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
429 tty_mode = TTY_MODE_HCO;
430 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
431 tty_mode = TTY_MODE_FULL;
432 else {
433 ret = -EINVAL;
434 goto done;
435 }
436
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700437 if (tty_mode != adev->voice.tty_mode) {
438 adev->voice.tty_mode = tty_mode;
439 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700440 if (voice_is_call_state_active(adev))
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800441 voice_update_devices_for_all_voice_usecases(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700442 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700443 }
444
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800445 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800446 value, sizeof(value));
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800447 if (err >= 0) {
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800448 str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC);
449 if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0)
450 platform_start_incall_music_usecase(adev->platform);
451 else
452 platform_stop_incall_music_usecase(adev->platform);
453 }
454
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700455done:
456 ALOGV("%s: exit with code(%d)", __func__, ret);
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800457 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700458 return ret;
459}
460
461void voice_init(struct audio_device *adev)
462{
463 int i = 0;
464
465 memset(&adev->voice, 0, sizeof(adev->voice));
466 adev->voice.tty_mode = TTY_MODE_OFF;
467 adev->voice.volume = 1.0f;
468 adev->voice.mic_mute = false;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700469 adev->voice.in_call = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700470 for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
471 adev->voice.session[i].pcm_rx = NULL;
472 adev->voice.session[i].pcm_tx = NULL;
473 adev->voice.session[i].state.current = CALL_INACTIVE;
474 adev->voice.session[i].state.new = CALL_INACTIVE;
475 adev->voice.session[i].vsid = 0;
476 }
477
478 voice_extn_init(adev);
479}
480
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800481void voice_update_devices_for_all_voice_usecases(struct audio_device *adev)
482{
483 struct listnode *node;
484 struct audio_usecase *usecase;
485
486 list_for_each(node, &adev->usecase_list) {
487 usecase = node_to_item(node, struct audio_usecase, list);
488 if (usecase->type == VOICE_CALL) {
489 ALOGV("%s: updating device for usecase:%s", __func__,
490 use_case_table[usecase->id]);
491 select_devices(adev, usecase->id);
492 }
493 }
494}
495
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700496