blob: d3e89038ba28786f2e42e97173466566e582de7c [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"
Bruno Martinse2078812015-08-03 22:52:51 +010032#include "voice_extn/msim_voice_extn.h"
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070033#include "platform.h"
34#include "platform_api.h"
Kiran Kandi910e1862013-10-29 13:29:42 -070035#include "audio_extn.h"
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070036
37struct pcm_config pcm_config_voice_call = {
38 .channels = 1,
39 .rate = 8000,
40 .period_size = 160,
41 .period_count = 2,
42 .format = PCM_FORMAT_S16_LE,
43};
44
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -080045extern const char * const use_case_table[AUDIO_USECASE_MAX];
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070046
47static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev,
48 audio_usecase_t usecase_id)
49{
50 struct voice_session *session = NULL;
51 int ret = 0;
52
Bruno Martinse2078812015-08-03 22:52:51 +010053 ret = msim_voice_extn_get_session_from_use_case(adev, usecase_id, &session);
ljzyala53260b2015-07-25 00:41:56 -070054 if (ret == 0) {
55 return session;
56 }
57
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070058 ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session);
59 if (ret == -ENOSYS) {
60 session = &adev->voice.session[VOICE_SESS_IDX];
61 }
62
63 return session;
64}
65
66int stop_call(struct audio_device *adev, audio_usecase_t usecase_id)
67{
68 int i, ret = 0;
69 struct audio_usecase *uc_info;
70 struct voice_session *session = NULL;
71
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -080072 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070073
74 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew George9f0254a2014-06-30 13:56:18 -070075 if (!session) {
76 ALOGE("stop_call: couldn't find voice session");
77 return -EINVAL;
78 }
79
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070080 session->state.current = CALL_INACTIVE;
81
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -080082 ret = platform_stop_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070083
84 /* 1. Close the PCM devices */
85 if (session->pcm_rx) {
86 pcm_close(session->pcm_rx);
87 session->pcm_rx = NULL;
88 }
89 if (session->pcm_tx) {
90 pcm_close(session->pcm_tx);
91 session->pcm_tx = NULL;
92 }
93
94 uc_info = get_usecase_from_list(adev, usecase_id);
95 if (uc_info == NULL) {
96 ALOGE("%s: Could not find the usecase (%d) in the list",
97 __func__, usecase_id);
98 return -EINVAL;
99 }
100
101 /* 2. Get and set stream specific mixer controls */
Haynes Mathew Georgeea098922014-04-24 17:53:50 -0700102 disable_audio_route(adev, uc_info);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700103
104 /* 3. Disable the rx and tx devices */
Haynes Mathew Georgeea098922014-04-24 17:53:50 -0700105 disable_snd_device(adev, uc_info->out_snd_device);
106 disable_snd_device(adev, uc_info->in_snd_device);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700107
108 list_remove(&uc_info->list);
109 free(uc_info);
110
111 ALOGD("%s: exit: status(%d)", __func__, ret);
112 return ret;
113}
114
115int start_call(struct audio_device *adev, audio_usecase_t usecase_id)
116{
117 int i, ret = 0;
118 struct audio_usecase *uc_info;
119 int pcm_dev_rx_id, pcm_dev_tx_id;
120 struct voice_session *session = NULL;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700121 struct pcm_config voice_config = pcm_config_voice_call;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800122
123 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700124
125 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew George9f0254a2014-06-30 13:56:18 -0700126 if (!session) {
127 ALOGE("start_call: couldn't find voice session");
128 return -EINVAL;
129 }
130
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700131 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew George9f0254a2014-06-30 13:56:18 -0700132 if (!uc_info) {
133 ALOGE("start_call: couldn't allocate mem for audio_usecase");
134 return -ENOMEM;
135 }
136
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700137 uc_info->id = usecase_id;
138 uc_info->type = VOICE_CALL;
Divya Narayanan Poojaryab9b1ef2014-09-12 15:52:36 +0530139 uc_info->stream.out = adev->current_call_output;
140 uc_info->devices = adev->current_call_output->devices;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700141 uc_info->in_snd_device = SND_DEVICE_NONE;
142 uc_info->out_snd_device = SND_DEVICE_NONE;
143
144 list_add_tail(&adev->usecase_list, &uc_info->list);
145
146 select_devices(adev, usecase_id);
147
148 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
149 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
150
151 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
152 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
153 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
154 ret = -EIO;
155 goto error_start_voice;
156 }
157
158 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800159 __func__, adev->snd_card, pcm_dev_rx_id);
160 session->pcm_rx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700161 pcm_dev_rx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700162 PCM_OUT, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700163 if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) {
164 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
165 ret = -EIO;
166 goto error_start_voice;
167 }
168
169 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800170 __func__, adev->snd_card, pcm_dev_tx_id);
171 session->pcm_tx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700172 pcm_dev_tx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700173 PCM_IN, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700174 if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) {
175 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
176 ret = -EIO;
177 goto error_start_voice;
178 }
179 pcm_start(session->pcm_rx);
180 pcm_start(session->pcm_tx);
181
Shruthi Krishnaace10852013-10-25 14:32:12 -0700182 voice_set_volume(adev, adev->voice.volume);
183
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800184 ret = platform_start_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700185 if (ret < 0) {
186 ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
187 goto error_start_voice;
188 }
189
190 session->state.current = CALL_ACTIVE;
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700191 goto done;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700192
193error_start_voice:
194 stop_call(adev, usecase_id);
195
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700196done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700197 ALOGD("%s: exit: status(%d)", __func__, ret);
198 return ret;
199}
200
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700201bool voice_is_call_state_active(struct audio_device *adev)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700202{
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700203 bool call_state = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700204 int ret = 0;
205
Bruno Martinse2078812015-08-03 22:52:51 +0100206 ret = msim_voice_extn_is_call_state_active(adev, &call_state);
ljzyala53260b2015-07-25 00:41:56 -0700207 if (ret == 0) {
208 return call_state;
209 }
210
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700211 ret = voice_extn_is_call_state_active(adev, &call_state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700212 if (ret == -ENOSYS) {
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700213 call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700214 }
215
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700216 return call_state;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700217}
218
kunleiza1a9ee02014-04-24 18:46:22 +0800219bool voice_is_in_call_rec_stream(struct stream_in *in)
220{
221 bool in_call_rec = false;
222 int ret = 0;
223
224 ret = voice_extn_is_in_call_rec_stream(in, &in_call_rec);
225 if (ret == -ENOSYS) {
226 in_call_rec = false;
227 }
228
229 return in_call_rec;
230}
231
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700232uint32_t voice_get_active_session_id(struct audio_device *adev)
233{
234 int ret = 0;
235 uint32_t session_id;
236
Bruno Martinse2078812015-08-03 22:52:51 +0100237 ret = msim_voice_extn_get_active_session_id(adev, &session_id);
ljzyala53260b2015-07-25 00:41:56 -0700238 if (ret == 0) {
239 return session_id;
240 }
241
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700242 ret = voice_extn_get_active_session_id(adev, &session_id);
243 if (ret == -ENOSYS) {
244 session_id = VOICE_VSID;
245 }
246 return session_id;
247}
248
249int voice_check_and_set_incall_rec_usecase(struct audio_device *adev,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800250 struct stream_in *in)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700251{
252 int ret = 0;
253 uint32_t session_id;
254 int usecase_id;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800255 int rec_mode = INCALL_REC_NONE;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700256
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700257 if (voice_is_call_state_active(adev)) {
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700258 switch (in->source) {
259 case AUDIO_SOURCE_VOICE_UPLINK:
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_COMPRESS;
263 } else
264 in->usecase = USECASE_INCALL_REC_UPLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800265 rec_mode = INCALL_REC_UPLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700266 break;
267 case AUDIO_SOURCE_VOICE_DOWNLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800268 if (audio_extn_compr_cap_enabled() &&
269 audio_extn_compr_cap_format_supported(in->config.format)) {
270 in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS;
271 } else
272 in->usecase = USECASE_INCALL_REC_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800273 rec_mode = INCALL_REC_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700274 break;
275 case AUDIO_SOURCE_VOICE_CALL:
Helen Zenge56b4852013-12-03 16:54:40 -0800276 if (audio_extn_compr_cap_enabled() &&
277 audio_extn_compr_cap_format_supported(in->config.format)) {
278 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS;
279 } else
280 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800281 rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700282 break;
283 default:
284 ALOGV("%s: Source type %d doesnt match incall recording criteria",
285 __func__, in->source);
286 return ret;
287 }
288
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700289 session_id = voice_get_active_session_id(adev);
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800290 ret = platform_set_incall_recording_session_id(adev->platform,
291 session_id, rec_mode);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700292 ALOGV("%s: Update usecase to %d",__func__, in->usecase);
293 } else {
Venkata Narendra Kumar Gutta5501ffa2015-03-30 19:16:14 +0530294 /*
295 * Reject the recording instances, where the recording is started
296 * with In-call voice recording source types but voice call is not
297 * active by the time input is started
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 = -EINVAL;
303 ALOGE("%s: As voice call is not active, Incall rec usecase can't be \
304 selected for requested source:%d",__func__, in->source);
305 }
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700306 ALOGV("%s: voice call not active", __func__);
307 }
308
309 return ret;
310}
311
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800312int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev,
313 struct stream_in *in)
314{
315 int ret = 0;
316
317 if (in->source == AUDIO_SOURCE_VOICE_UPLINK ||
318 in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
319 in->source == AUDIO_SOURCE_VOICE_CALL) {
320 ret = platform_stop_incall_recording_usecase(adev->platform);
321 ALOGV("%s: Stop In-call recording", __func__);
322 }
323
324 return ret;
325}
326
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700327int voice_check_and_set_incall_music_usecase(struct audio_device *adev,
328 struct stream_out *out)
329{
330 int ret = 0;
331
332 ret = voice_extn_check_and_set_incall_music_usecase(adev, out);
333 if (ret == -ENOSYS) {
334 /* Incall music delivery is used only for LCH call state */
335 ret = -EINVAL;
336 }
337
338 return ret;
339}
340
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700341int voice_set_mic_mute(struct audio_device *adev, bool state)
342{
343 int err = 0;
344
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800345 adev->voice.mic_mute = state;
346 if (adev->mode == AUDIO_MODE_IN_CALL)
347 err = platform_set_mic_mute(adev->platform, state);
348 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
349 err = voice_extn_compress_voip_set_mic_mute(adev, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700350
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700351 return err;
352}
353
354bool voice_get_mic_mute(struct audio_device *adev)
355{
356 return adev->voice.mic_mute;
357}
358
359int voice_set_volume(struct audio_device *adev, float volume)
360{
361 int vol, err = 0;
362
Shruthi Krishnaace10852013-10-25 14:32:12 -0700363 adev->voice.volume = volume;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700364 if (adev->mode == AUDIO_MODE_IN_CALL) {
365 if (volume < 0.0) {
366 volume = 0.0;
367 } else if (volume > 1.0) {
368 volume = 1.0;
369 }
370
371 vol = lrint(volume * 100.0);
Tony Layherbe228ca2014-12-23 10:58:58 -0500372#ifndef USE_ES705
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700373 // Voice volume levels from android are mapped to driver volume levels as follows.
374 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
375 // So adjust the volume to get the correct volume index in driver
376 vol = 100 - vol;
Tony Layherbe228ca2014-12-23 10:58:58 -0500377#endif
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700378 err = platform_set_voice_volume(adev->platform, vol);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700379 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800380 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
381 err = voice_extn_compress_voip_set_volume(adev, volume);
382
Shruthi Krishnaace10852013-10-25 14:32:12 -0700383
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700384 return err;
385}
386
387int voice_start_call(struct audio_device *adev)
388{
389 int ret = 0;
390
Bruno Martinse2078812015-08-03 22:52:51 +0100391 ret = msim_voice_extn_start_call(adev);
ljzyala53260b2015-07-25 00:41:56 -0700392 if (ret != -ENOSYS) {
393 adev->voice.in_call = true;
394 return ret;
395 }
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800396 ret = voice_extn_start_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700397 if (ret == -ENOSYS) {
398 ret = start_call(adev, USECASE_VOICE_CALL);
399 }
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700400 adev->voice.in_call = true;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700401
402 return ret;
403}
404
405int voice_stop_call(struct audio_device *adev)
406{
407 int ret = 0;
408
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700409 adev->voice.in_call = false;
Bruno Martinse2078812015-08-03 22:52:51 +0100410 ret = msim_voice_extn_stop_call(adev);
ljzyala53260b2015-07-25 00:41:56 -0700411 if (ret != -ENOSYS) {
412 return 0;
413 }
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800414 ret = voice_extn_stop_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700415 if (ret == -ENOSYS) {
416 ret = stop_call(adev, USECASE_VOICE_CALL);
417 }
418
419 return ret;
420}
421
Shiv Maliyappanahallif9308492013-12-12 12:18:09 -0800422void voice_get_parameters(struct audio_device *adev,
423 struct str_parms *query,
424 struct str_parms *reply)
425{
426 voice_extn_get_parameters(adev, query, reply);
427}
428
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700429int voice_set_parameters(struct audio_device *adev, struct str_parms *parms)
430{
431 char *str;
432 char value[32];
433 int val;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800434 int ret = 0, err;
Krishnankutty Kolathappilly301cc362014-01-31 18:12:13 -0800435 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700436
Krishnankutty Kolathappilly301cc362014-01-31 18:12:13 -0800437 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700438
Bruno Martinse2078812015-08-03 22:52:51 +0100439 ret = msim_voice_extn_set_parameters(adev, parms);
ljzyala53260b2015-07-25 00:41:56 -0700440 if (ret != 0 && ret != -ENOSYS)
441 goto done;
442
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800443 ret = voice_extn_set_parameters(adev, parms);
Vidyakumar Athota7992b8e2014-07-21 14:51:44 -0700444 if (ret != 0) {
445 if (ret == -ENOSYS)
446 ret = 0;
447 else
448 goto done;
449 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700450
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800451 ret = voice_extn_compress_voip_set_parameters(adev, parms);
Vidyakumar Athota7992b8e2014-07-21 14:51:44 -0700452 if (ret != 0) {
453 if (ret == -ENOSYS)
454 ret = 0;
455 else
456 goto done;
457 }
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800458
459 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
460 if (err >= 0) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700461 int tty_mode;
462 str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE);
463 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
464 tty_mode = TTY_MODE_OFF;
465 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
466 tty_mode = TTY_MODE_VCO;
467 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
468 tty_mode = TTY_MODE_HCO;
469 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
470 tty_mode = TTY_MODE_FULL;
471 else {
472 ret = -EINVAL;
473 goto done;
474 }
475
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700476 if (tty_mode != adev->voice.tty_mode) {
477 adev->voice.tty_mode = tty_mode;
478 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700479 if (voice_is_call_state_active(adev))
Narsinga Rao Chellac9bf40d2014-02-06 14:05:14 -0800480 voice_update_devices_for_all_voice_usecases(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700481 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700482 }
483
Eric Laurenta6c91142016-08-11 12:32:06 +0200484 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HAC,
485 value, sizeof(value));
486 if (err >= 0) {
487 bool hac = false;
488 str_parms_del(parms, AUDIO_PARAMETER_KEY_HAC);
489 if (strcmp(value, AUDIO_PARAMETER_VALUE_HAC_ON) == 0)
490 hac = true;
491
492 if (hac != adev->voice.hac) {
493 adev->voice.hac = hac;
494 if (voice_is_call_state_active(adev))
495 voice_update_devices_for_all_voice_usecases(adev);
496 }
497 }
498
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800499 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800500 value, sizeof(value));
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800501 if (err >= 0) {
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800502 str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC);
503 if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0)
504 platform_start_incall_music_usecase(adev->platform);
505 else
506 platform_stop_incall_music_usecase(adev->platform);
Vidyakumar Athota7992b8e2014-07-21 14:51:44 -0700507 }
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800508
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700509done:
510 ALOGV("%s: exit with code(%d)", __func__, ret);
Krishnankutty Kolathappilly301cc362014-01-31 18:12:13 -0800511 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700512 return ret;
513}
514
515void voice_init(struct audio_device *adev)
516{
517 int i = 0;
518
519 memset(&adev->voice, 0, sizeof(adev->voice));
520 adev->voice.tty_mode = TTY_MODE_OFF;
Eric Laurenta6c91142016-08-11 12:32:06 +0200521 adev->voice.hac = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700522 adev->voice.volume = 1.0f;
523 adev->voice.mic_mute = false;
Vidyakumar Athotaf85f6a22014-08-05 18:20:42 -0700524 adev->voice.in_call = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700525 for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
526 adev->voice.session[i].pcm_rx = NULL;
527 adev->voice.session[i].pcm_tx = NULL;
528 adev->voice.session[i].state.current = CALL_INACTIVE;
529 adev->voice.session[i].state.new = CALL_INACTIVE;
Tony Layher692f19a2015-01-03 13:16:45 -0500530#ifdef PLATFORM_APQ8084
531 adev->voice.session[i].vsid = VOICE_VSID;
532#else
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700533 adev->voice.session[i].vsid = 0;
Tony Layher692f19a2015-01-03 13:16:45 -0500534#endif
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700535 }
536
537 voice_extn_init(adev);
538}
539
Narsinga Rao Chellac9bf40d2014-02-06 14:05:14 -0800540void voice_update_devices_for_all_voice_usecases(struct audio_device *adev)
541{
542 struct listnode *node;
543 struct audio_usecase *usecase;
544
545 list_for_each(node, &adev->usecase_list) {
546 usecase = node_to_item(node, struct audio_usecase, list);
547 if (usecase->type == VOICE_CALL) {
548 ALOGV("%s: updating device for usecase:%s", __func__,
549 use_case_table[usecase->id]);
Divya Narayanan Poojaryab9b1ef2014-09-12 15:52:36 +0530550 usecase->stream.out = adev->current_call_output;
Narsinga Rao Chellac9bf40d2014-02-06 14:05:14 -0800551 select_devices(adev, usecase->id);
552 }
553 }
554}
555
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700556