blob: 708ce6cfb09d6fb9bdeb7f1b6889b1f96716ddf5 [file] [log] [blame]
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001/*
2 * Copyright (C) 2014 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 "voice"
18/*#define LOG_NDEBUG 0*/
19#define LOG_NDDEBUG 0
20
Vineeta Srivastava7c685a12015-03-20 15:34:33 -070021#include <stdlib.h>
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070022#include <errno.h>
23#include <math.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080024#include <log/log.h>
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070025#include <cutils/str_parms.h>
26
27#include "audio_hw.h"
28#include "voice.h"
29#include "voice_extn/voice_extn.h"
30#include "platform.h"
31#include "platform_api.h"
Alain Vongsouvanh13f26e82016-11-18 14:39:11 -080032#include "audio_extn/tfa_98xx.h"
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070033
34struct pcm_config pcm_config_voice_call = {
35 .channels = 1,
36 .rate = 8000,
37 .period_size = 160,
38 .period_count = 2,
39 .format = PCM_FORMAT_S16_LE,
40};
41
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070042static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev,
43 audio_usecase_t usecase_id)
44{
45 struct voice_session *session = NULL;
46 int ret = 0;
47
48 ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session);
49 if (ret == -ENOSYS) {
50 session = &adev->voice.session[VOICE_SESS_IDX];
51 }
52
53 return session;
54}
55
vivek mehta765eb642015-08-07 19:46:06 -070056static bool voice_is_sidetone_device(snd_device_t out_device,
57 char *mixer_path)
58{
59 bool is_sidetone_dev = true;
60
61 switch (out_device) {
62 case SND_DEVICE_OUT_VOICE_HAC_HANDSET:
63 strlcpy(mixer_path, "sidetone-hac-handset", MIXER_PATH_MAX_LENGTH);
64 break;
65 case SND_DEVICE_OUT_VOICE_HANDSET:
66 strlcpy(mixer_path, "sidetone-handset", MIXER_PATH_MAX_LENGTH);
67 break;
68 case SND_DEVICE_OUT_VOICE_HEADPHONES:
yixuanjiang9536e672018-09-06 18:43:36 +080069 case SND_DEVICE_OUT_VOICE_HEADSET:
vivek mehta765eb642015-08-07 19:46:06 -070070 strlcpy(mixer_path, "sidetone-headphones", MIXER_PATH_MAX_LENGTH);
71 break;
vivek mehta90933872017-06-15 18:04:39 -070072 case SND_DEVICE_OUT_VOICE_USB_HEADSET:
73 case SND_DEVICE_OUT_USB_HEADSET:
74 // USB does not use a QC mixer.
75 mixer_path[0] = '\0';
76 break;
vivek mehta765eb642015-08-07 19:46:06 -070077 default:
vivek mehta90933872017-06-15 18:04:39 -070078 ALOGW("%s: %d is not a sidetone device", __func__, out_device);
vivek mehta765eb642015-08-07 19:46:06 -070079 is_sidetone_dev = false;
80 break;
81 }
82
83 return is_sidetone_dev;
84}
85
86void voice_set_sidetone(struct audio_device *adev,
87 snd_device_t out_snd_device, bool enable)
88{
89 char mixer_path[MIXER_PATH_MAX_LENGTH];
90 bool is_sidetone_dev;
91
92 ALOGD("%s: %s, out_snd_device: %d\n",
93 __func__, (enable ? "enable" : "disable"),
94 out_snd_device);
95
vivek mehta90933872017-06-15 18:04:39 -070096 if (voice_is_sidetone_device(out_snd_device, mixer_path))
97 platform_set_sidetone(adev, out_snd_device, enable, mixer_path);
vivek mehta765eb642015-08-07 19:46:06 -070098
99 return;
100}
101
Ravi Kumar Alamanda08dbcfc2014-08-20 16:24:38 -0700102int voice_stop_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700103{
104 int i, ret = 0;
105 struct audio_usecase *uc_info;
106 struct voice_session *session = NULL;
107
108 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
109
110 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
vivek mehta765eb642015-08-07 19:46:06 -0700111
112 uc_info = get_usecase_from_list(adev, usecase_id);
113 if (uc_info == NULL) {
114 ALOGE("%s: Could not find the usecase (%d) in the list",
115 __func__, usecase_id);
116 return -EINVAL;
117 }
118
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700119 session->state.current = CALL_INACTIVE;
120
vivek mehta765eb642015-08-07 19:46:06 -0700121 /* Disable sidetone only when no calls are active */
Vineeta Srivastava6ed310d2016-08-03 11:56:35 -0700122 if (!voice_is_call_state_active(adev))
vivek mehta765eb642015-08-07 19:46:06 -0700123 voice_set_sidetone(adev, uc_info->out_snd_device, false);
124
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700125 ret = platform_stop_voice_call(adev->platform, session->vsid);
126
127 /* 1. Close the PCM devices */
128 if (session->pcm_rx) {
129 pcm_close(session->pcm_rx);
130 session->pcm_rx = NULL;
131 }
132 if (session->pcm_tx) {
133 pcm_close(session->pcm_tx);
134 session->pcm_tx = NULL;
135 }
136
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700137 /* 2. Get and set stream specific mixer controls */
138 disable_audio_route(adev, uc_info);
139
140 /* 3. Disable the rx and tx devices */
141 disable_snd_device(adev, uc_info->out_snd_device);
142 disable_snd_device(adev, uc_info->in_snd_device);
143
Alain Vongsouvanh13f26e82016-11-18 14:39:11 -0800144 if (audio_extn_tfa_98xx_is_supported() && voice_get_mic_mute(adev)) {
145 voice_set_mic_mute(adev, false);
146 ALOGD("%s: unMute voice Tx", __func__);
147 }
148
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700149 list_remove(&uc_info->list);
150 free(uc_info);
151
152 ALOGD("%s: exit: status(%d)", __func__, ret);
153 return ret;
154}
155
Eric Laurent75a2e1d2014-08-29 12:38:47 -0700156int voice_start_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700157{
158 int i, ret = 0;
159 struct audio_usecase *uc_info;
160 int pcm_dev_rx_id, pcm_dev_tx_id;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700161 struct voice_session *session = NULL;
162 struct pcm_config voice_config = pcm_config_voice_call;
163
164 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
165
166 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
167 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
168 uc_info->id = usecase_id;
169 uc_info->type = VOICE_CALL;
Eric Laurent75a2e1d2014-08-29 12:38:47 -0700170 uc_info->stream.out = adev->current_call_output ;
171 uc_info->devices = adev->current_call_output ->devices;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700172 uc_info->in_snd_device = SND_DEVICE_NONE;
173 uc_info->out_snd_device = SND_DEVICE_NONE;
Arun Mirpuri0cc2f312018-05-29 17:26:07 -0700174 adev->use_voice_device_mute = false;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700175
176 list_add_tail(&adev->usecase_list, &uc_info->list);
177
178 select_devices(adev, usecase_id);
179
180 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
181 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
182
183 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
184 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
185 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
186 ret = -EIO;
187 goto error_start_voice;
188 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700189
vivek mehta765eb642015-08-07 19:46:06 -0700190 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
191 __func__, adev->snd_card, pcm_dev_tx_id);
192 session->pcm_tx = pcm_open(adev->snd_card,
193 pcm_dev_tx_id,
194 PCM_IN, &voice_config);
195 if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) {
196 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
197 ret = -EIO;
198 goto error_start_voice;
199 }
200
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700201 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
202 __func__, adev->snd_card, pcm_dev_rx_id);
203 session->pcm_rx = pcm_open(adev->snd_card,
204 pcm_dev_rx_id,
205 PCM_OUT, &voice_config);
206 if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) {
207 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
208 ret = -EIO;
209 goto error_start_voice;
210 }
211
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -0700212 if (adev->mic_break_enabled)
213 platform_set_mic_break_det(adev->platform, true);
214
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700215 pcm_start(session->pcm_tx);
vivek mehta765eb642015-08-07 19:46:06 -0700216 pcm_start(session->pcm_rx);
217
Alain Vongsouvanh13f26e82016-11-18 14:39:11 -0800218 audio_extn_tfa_98xx_enable_speaker();
219
vivek mehta765eb642015-08-07 19:46:06 -0700220 /* Enable sidetone only when no calls are already active */
221 if (!voice_is_call_state_active(adev))
222 voice_set_sidetone(adev, uc_info->out_snd_device, true);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700223
224 voice_set_volume(adev, adev->voice.volume);
225
226 ret = platform_start_voice_call(adev->platform, session->vsid);
227 if (ret < 0) {
228 ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
229 goto error_start_voice;
230 }
231
232 session->state.current = CALL_ACTIVE;
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700233 goto done;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700234
235error_start_voice:
Ravi Kumar Alamanda08dbcfc2014-08-20 16:24:38 -0700236 voice_stop_usecase(adev, usecase_id);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700237
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700238done:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700239 ALOGD("%s: exit: status(%d)", __func__, ret);
240 return ret;
241}
242
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700243bool voice_is_call_state_active(struct audio_device *adev)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700244{
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700245 bool call_state = false;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700246 int ret = 0;
247
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700248 ret = voice_extn_is_call_state_active(adev, &call_state);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700249 if (ret == -ENOSYS) {
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700250 call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700251 }
252
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700253 return call_state;
254}
255
256bool voice_is_in_call(struct audio_device *adev)
257{
258 return adev->voice.in_call;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700259}
260
261bool voice_is_in_call_rec_stream(struct stream_in *in)
262{
263 bool in_call_rec = false;
264 int ret = 0;
265
266 ret = voice_extn_is_in_call_rec_stream(in, &in_call_rec);
267 if (ret == -ENOSYS) {
268 in_call_rec = false;
269 }
270
271 return in_call_rec;
272}
273
274uint32_t voice_get_active_session_id(struct audio_device *adev)
275{
276 int ret = 0;
277 uint32_t session_id;
278
279 ret = voice_extn_get_active_session_id(adev, &session_id);
280 if (ret == -ENOSYS) {
281 session_id = VOICE_VSID;
282 }
283 return session_id;
284}
285
286int voice_check_and_set_incall_rec_usecase(struct audio_device *adev,
287 struct stream_in *in)
288{
289 int ret = 0;
290 uint32_t session_id;
291 int usecase_id;
292 int rec_mode = INCALL_REC_NONE;
293
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700294 if (voice_is_call_state_active(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700295 switch (in->source) {
296 case AUDIO_SOURCE_VOICE_UPLINK:
297 in->usecase = USECASE_INCALL_REC_UPLINK;
298 rec_mode = INCALL_REC_UPLINK;
299 break;
300 case AUDIO_SOURCE_VOICE_DOWNLINK:
301 in->usecase = USECASE_INCALL_REC_DOWNLINK;
302 rec_mode = INCALL_REC_DOWNLINK;
303 break;
304 case AUDIO_SOURCE_VOICE_CALL:
305 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK;
306 rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK;
307 break;
308 default:
309 ALOGV("%s: Source type %d doesnt match incall recording criteria",
310 __func__, in->source);
311 return ret;
312 }
313
314 session_id = voice_get_active_session_id(adev);
315 ret = platform_set_incall_recording_session_id(adev->platform,
316 session_id, rec_mode);
Arun Mirpuriba2749a2018-04-17 14:32:24 -0700317#ifdef INCALL_STEREO_CAPTURE_ENABLED
318 ret = platform_set_incall_recording_session_channels(adev->platform,
319 in->config.channels);
320#endif
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700321 ALOGV("%s: Update usecase to %d",__func__, in->usecase);
322 } else {
323 ALOGV("%s: voice call not active", __func__);
324 }
325
326 return ret;
327}
328
329int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev,
330 struct stream_in *in)
331{
332 int ret = 0;
333
334 if (in->source == AUDIO_SOURCE_VOICE_UPLINK ||
335 in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
336 in->source == AUDIO_SOURCE_VOICE_CALL) {
337 ret = platform_stop_incall_recording_usecase(adev->platform);
338 ALOGV("%s: Stop In-call recording", __func__);
339 }
340
341 return ret;
342}
343
344int voice_check_and_set_incall_music_usecase(struct audio_device *adev,
345 struct stream_out *out)
346{
347 int ret = 0;
348
349 ret = voice_extn_check_and_set_incall_music_usecase(adev, out);
350 if (ret == -ENOSYS) {
351 /* Incall music delivery is used only for LCH call state */
352 ret = -EINVAL;
353 }
354
355 return ret;
356}
357
358int voice_set_mic_mute(struct audio_device *adev, bool state)
359{
360 int err = 0;
Arun Mirpuri0cc2f312018-05-29 17:26:07 -0700361 struct audio_usecase *usecase = NULL;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700362
363 adev->voice.mic_mute = state;
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +0900364 if (adev->mode == AUDIO_MODE_IN_CALL ||
Arun Mirpuri0cc2f312018-05-29 17:26:07 -0700365 adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
366 /* Use device mute if incall music delivery usecase is in progress */
367 if (adev->use_voice_device_mute)
368 err = platform_set_device_mute(adev->platform, state, "tx");
369 else
370 err = platform_set_mic_mute(adev->platform, state);
371 ALOGV("%s: voice mute status=%d, use_voice_device_mute_flag=%d",
372 __func__, state, adev->use_voice_device_mute);
373 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700374
375 return err;
376}
377
378bool voice_get_mic_mute(struct audio_device *adev)
379{
380 return adev->voice.mic_mute;
381}
382
Arun Mirpuri0cc2f312018-05-29 17:26:07 -0700383// Following function is called when incall music uplink usecase is
384// created or destroyed while mic is muted. If incall music uplink
385// usecase is active, apply voice device mute to mute only voice Tx
386// path and not the mixed voice Tx + inncall-music path. Revert to
387// voice stream mute once incall music uplink usecase is inactive
388void voice_set_device_mute_flag (struct audio_device *adev, bool state)
389{
390 if (adev->voice.mic_mute) {
391 if (state) {
392 platform_set_device_mute(adev->platform, true, "tx");
393 platform_set_mic_mute(adev->platform, false);
394 } else {
395 platform_set_mic_mute(adev->platform, true);
396 platform_set_device_mute(adev->platform, false, "tx");
397 }
398 }
399 adev->use_voice_device_mute = state;
400}
401
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700402int voice_set_volume(struct audio_device *adev, float volume)
403{
404 int vol, err = 0;
405
406 adev->voice.volume = volume;
407 if (adev->mode == AUDIO_MODE_IN_CALL) {
408 if (volume < 0.0) {
409 volume = 0.0;
410 } else if (volume > 1.0) {
411 volume = 1.0;
412 }
413
414 vol = lrint(volume * 100.0);
415
416 // Voice volume levels from android are mapped to driver volume levels as follows.
417 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
418 // So adjust the volume to get the correct volume index in driver
419 vol = 100 - vol;
420
421 err = platform_set_voice_volume(adev->platform, vol);
422 }
423
424 return err;
425}
426
Eric Laurent75a2e1d2014-08-29 12:38:47 -0700427int voice_start_call(struct audio_device *adev)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700428{
429 int ret = 0;
430
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700431 adev->voice.in_call = true;
Ravi Kumar Alamandaeecfa9a2015-03-20 17:31:46 -0700432
433 voice_set_mic_mute(adev, adev->voice.mic_mute);
434
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700435 ret = voice_extn_start_call(adev);
436 if (ret == -ENOSYS) {
Eric Laurent75a2e1d2014-08-29 12:38:47 -0700437 ret = voice_start_usecase(adev, USECASE_VOICE_CALL);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700438 }
439
440 return ret;
441}
442
443int voice_stop_call(struct audio_device *adev)
444{
445 int ret = 0;
446
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700447 adev->voice.in_call = false;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700448 ret = voice_extn_stop_call(adev);
449 if (ret == -ENOSYS) {
Ravi Kumar Alamanda08dbcfc2014-08-20 16:24:38 -0700450 ret = voice_stop_usecase(adev, USECASE_VOICE_CALL);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700451 }
452
453 return ret;
454}
455
456void voice_get_parameters(struct audio_device *adev,
457 struct str_parms *query,
458 struct str_parms *reply)
459{
460 voice_extn_get_parameters(adev, query, reply);
461}
462
463int voice_set_parameters(struct audio_device *adev, struct str_parms *parms)
464{
465 char *str;
466 char value[32];
467 int val;
468 int ret = 0, err;
469 char *kv_pairs = str_parms_to_str(parms);
470
471 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
472
473 ret = voice_extn_set_parameters(adev, parms);
Haynes Mathew Georgeff5d6512014-07-18 15:31:44 -0700474 if (ret != 0) {
475 if (ret == -ENOSYS) {
476 ret = 0; /* ignore error */
477 } else {
478 goto done;
479 }
480 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700481
482 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
483 if (err >= 0) {
484 int tty_mode;
485 str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE);
486 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
487 tty_mode = TTY_MODE_OFF;
488 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
489 tty_mode = TTY_MODE_VCO;
490 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
491 tty_mode = TTY_MODE_HCO;
492 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
493 tty_mode = TTY_MODE_FULL;
494 else {
495 ret = -EINVAL;
496 goto done;
497 }
498
499 if (tty_mode != adev->voice.tty_mode) {
500 adev->voice.tty_mode = tty_mode;
501 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700502 if (voice_is_call_state_active(adev))
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700503 voice_update_devices_for_all_voice_usecases(adev);
504 }
505 }
506
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500507 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HAC,
508 value, sizeof(value));
509 if (err >= 0) {
510 bool hac = false;
511 str_parms_del(parms, AUDIO_PARAMETER_KEY_HAC);
512 if (strcmp(value, AUDIO_PARAMETER_VALUE_HAC_ON) == 0)
513 hac = true;
514
515 if (hac != adev->voice.hac) {
516 adev->voice.hac = hac;
517 if (voice_is_in_call(adev))
518 voice_update_devices_for_all_voice_usecases(adev);
519 }
520 }
521
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700522 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC,
523 value, sizeof(value));
524 if (err >= 0) {
525 str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC);
526 if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0)
527 platform_start_incall_music_usecase(adev->platform);
528 else
529 platform_stop_incall_music_usecase(adev->platform);
530 }
531
532done:
533 ALOGV("%s: exit with code(%d)", __func__, ret);
534 free(kv_pairs);
535 return ret;
536}
537
538void voice_init(struct audio_device *adev)
539{
540 int i = 0;
541
542 memset(&adev->voice, 0, sizeof(adev->voice));
543 adev->voice.tty_mode = TTY_MODE_OFF;
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500544 adev->voice.hac = false;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700545 adev->voice.volume = 1.0f;
546 adev->voice.mic_mute = false;
Ravi Kumar Alamandaf1819242014-08-05 18:20:42 -0700547 adev->voice.in_call = false;
Arun Mirpuri0cc2f312018-05-29 17:26:07 -0700548 adev->use_voice_device_mute = false;
549
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700550 for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
551 adev->voice.session[i].pcm_rx = NULL;
552 adev->voice.session[i].pcm_tx = NULL;
553 adev->voice.session[i].state.current = CALL_INACTIVE;
554 adev->voice.session[i].state.new = CALL_INACTIVE;
555 adev->voice.session[i].vsid = VOICE_VSID;
556 }
557
558 voice_extn_init(adev);
559}
560
561void voice_update_devices_for_all_voice_usecases(struct audio_device *adev)
562{
563 struct listnode *node;
564 struct audio_usecase *usecase;
565
566 list_for_each(node, &adev->usecase_list) {
567 usecase = node_to_item(node, struct audio_usecase, list);
568 if (usecase->type == VOICE_CALL) {
569 ALOGV("%s: updating device for usecase:%s", __func__,
570 use_case_table[usecase->id]);
Ravi Kumar Alamandaa4fc9022014-10-08 18:57:46 -0700571 usecase->stream.out = adev->current_call_output;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700572 select_devices(adev, usecase->id);
Alain Vongsouvanh13f26e82016-11-18 14:39:11 -0800573 audio_extn_tfa_98xx_update();
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700574 }
575 }
576}
577
578