blob: 05c06018a97d699d9a8fa66be3bd1ccd830867b2 [file] [log] [blame]
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001/*
Aalique Grahame22e49102018-12-18 14:23:57 -08002 * Copyright (c) 2013-2019, 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>
Sharad Sangleb27354b2015-06-18 15:58:55 +053025#include <stdlib.h>
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070026#include <math.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080027#include <log/log.h>
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070028#include <cutils/str_parms.h>
Pallavi Mishra5627c162020-02-15 19:00:40 +053029#include <cutils/properties.h>
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070030#include "audio_hw.h"
31#include "voice.h"
32#include "voice_extn/voice_extn.h"
33#include "platform.h"
34#include "platform_api.h"
Kiran Kandi910e1862013-10-29 13:29:42 -070035#include "audio_extn.h"
Pallavi009b5212020-10-01 22:53:09 +053036#ifndef LINUX_ENABLED
37#include <hardware_legacy/power.h>
38#else
39#define acquire_wake_lock(a, b) (0)
40#define release_wake_lock(a) (0)
41#define PARTIAL_WAKE_LOCK 1
42#endif
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070043
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053044#ifdef DYNAMIC_LOG_ENABLED
45#include <log_xml_parser.h>
46#define LOG_MASK HAL_MOD_FILE_VOICE
47#include <log_utils.h>
48#endif
49
Pallavi009b5212020-10-01 22:53:09 +053050#define TRANSIT_WAKE_LOCK_NAME "audiohal_transit_wake_lock"
51
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070052struct pcm_config pcm_config_voice_call = {
53 .channels = 1,
54 .rate = 8000,
55 .period_size = 160,
56 .period_count = 2,
57 .format = PCM_FORMAT_S16_LE,
58};
59
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +053060struct pcm *voice_loopback_tx = NULL;
61struct pcm *voice_loopback_rx = NULL;
Pallavi Mishra5627c162020-02-15 19:00:40 +053062
63static bool voice_external_baseband_supported(struct audio_device *adev)
64{
65 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
66 * symbols. Voice call is handled by MDM and apps processor talks to
67 * MDM through CSD Client
68 */
Anurag Chouhand9867322020-03-09 13:26:25 +053069 char *snd_card_name = NULL;
Pallavi Mishra5627c162020-02-15 19:00:40 +053070 char baseband[100];
71 snd_card_name = strdup(mixer_get_name(adev->mixer));
Anurag Chouhand9867322020-03-09 13:26:25 +053072 if (!snd_card_name)
73 return 0;
Pallavi Mishra5627c162020-02-15 19:00:40 +053074 property_get("ro.baseband", baseband, "");
Anurag Chouhand9867322020-03-09 13:26:25 +053075 if (((!strncmp("hana55", snd_card_name, sizeof("hana55"))) &&
76 ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) ||
77 !strncmp("sdx", baseband, (sizeof("sdx")-1)))) ||
78 ((!strncmp("sm8150-pcie-snd-card", snd_card_name, sizeof("sm8150-pcie-snd-card"))) &&
79 ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) ||
80 !strncmp("sdx", baseband, (sizeof("sdx")-1))))) {
81 return 1;
82 } else {
83 return 0;
84 }
85}
86
87static bool voice_update_pcm_config(struct audio_device *adev)
88{
89 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
90 * symbols. Voice call is handled by MDM and apps processor talks to
91 * MDM through CSD Client
92 */
93 char *snd_card_name = NULL;
94 char baseband[100];
95 snd_card_name = strdup(mixer_get_name(adev->mixer));
96 if (!snd_card_name)
97 return 0;
98 property_get("ro.baseband", baseband, "");
99 if ((!strncmp("sm8150-pcie-snd-card", snd_card_name, sizeof("sm8150-pcie-snd-card"))) &&
Pallavi Mishra5627c162020-02-15 19:00:40 +0530100 ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) ||
101 !strncmp("sdx", baseband, (sizeof("sdx")-1)))) {
102 return 1;
Anurag Chouhand9867322020-03-09 13:26:25 +0530103 } else {
Pallavi Mishra5627c162020-02-15 19:00:40 +0530104 return 0;
Anurag Chouhand9867322020-03-09 13:26:25 +0530105 }
Pallavi Mishra5627c162020-02-15 19:00:40 +0530106}
107
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700108static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev,
109 audio_usecase_t usecase_id)
110{
111 struct voice_session *session = NULL;
112 int ret = 0;
113
114 ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session);
115 if (ret == -ENOSYS) {
116 session = &adev->voice.session[VOICE_SESS_IDX];
117 }
118
119 return session;
120}
121
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700122static bool voice_is_sidetone_device(snd_device_t out_device,
123 char *mixer_path)
124{
125 bool is_sidetone_dev;
126
127 switch (out_device) {
128 case SND_DEVICE_OUT_VOICE_HANDSET:
129 is_sidetone_dev = true;
130 strlcpy(mixer_path, "sidetone-handset", MIXER_PATH_MAX_LENGTH);
131 break;
132 case SND_DEVICE_OUT_VOICE_HEADPHONES:
Samyak Jainfd24f1e2019-04-30 11:58:43 +0530133 case SND_DEVICE_OUT_VOICE_HEADSET:
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700134 case SND_DEVICE_OUT_VOICE_ANC_HEADSET:
135 case SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET:
136 is_sidetone_dev = true;
137 strlcpy(mixer_path, "sidetone-headphones", MIXER_PATH_MAX_LENGTH);
138 break;
Aalique Grahame22e49102018-12-18 14:23:57 -0800139 case SND_DEVICE_OUT_VOICE_USB_HEADSET:
Kuirong Wang1cad7142016-05-24 15:21:56 -0700140 case SND_DEVICE_OUT_USB_HEADSET:
Aalique Grahame22e49102018-12-18 14:23:57 -0800141 // USB does not use a QC mixer.
142 mixer_path[0] = '\0';
Kuirong Wang1cad7142016-05-24 15:21:56 -0700143 is_sidetone_dev = true;
144 break;
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700145 default:
Aalique Grahame22e49102018-12-18 14:23:57 -0800146 ALOGW("%s: %d is not a sidetone device", __func__, out_device);
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700147 is_sidetone_dev = false;
148 break;
149 }
150
151 return is_sidetone_dev;
152}
153
154void voice_set_sidetone(struct audio_device *adev,
155 snd_device_t out_snd_device, bool enable)
156{
157 char mixer_path[MIXER_PATH_MAX_LENGTH];
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700158 ALOGD("%s: %s, out_snd_device: %d\n",
159 __func__, (enable ? "enable" : "disable"),
160 out_snd_device);
Kuirong Wang1cad7142016-05-24 15:21:56 -0700161 if (voice_is_sidetone_device(out_snd_device, mixer_path))
162 platform_set_sidetone(adev, out_snd_device, enable, mixer_path);
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700163 return;
164}
165
Vidyakumar Athotaea269c62016-10-31 09:05:59 -0700166static bool voice_is_aanc_device(snd_device_t out_device,
167 char *mixer_path)
168{
169 bool is_aanc_dev;
170
171 switch (out_device) {
172 case SND_DEVICE_OUT_ANC_HANDSET:
173 is_aanc_dev = true;
174 strlcpy(mixer_path, "aanc-path", MIXER_PATH_MAX_LENGTH);
175 break;
176 default:
177 is_aanc_dev = false;
178 break;
179 }
180
181 return is_aanc_dev;
182}
183
184void voice_check_and_update_aanc_path(struct audio_device *adev,
185 snd_device_t out_snd_device,
186 bool enable)
187{
188 char mixer_path[MIXER_PATH_MAX_LENGTH];
189
190 ALOGV("%s: %s, out_snd_device: %d\n",
191 __func__, (enable ? "enable" : "disable"), out_snd_device);
192
193 if (voice_is_aanc_device(out_snd_device, mixer_path))
194 platform_update_aanc_path(adev, out_snd_device, enable, mixer_path);
195
196 return;
197}
198
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700199int voice_stop_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700200{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530201 int ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700202 struct audio_usecase *uc_info;
203 struct voice_session *session = NULL;
204
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800205 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700206
207 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700208 if (!session) {
209 ALOGE("stop_call: couldn't find voice session");
210 return -EINVAL;
211 }
212
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700213 uc_info = get_usecase_from_list(adev, usecase_id);
214 if (uc_info == NULL) {
215 ALOGE("%s: Could not find the usecase (%d) in the list",
216 __func__, usecase_id);
217 return -EINVAL;
218 }
219
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700220 session->state.current = CALL_INACTIVE;
221
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700222 /* Disable sidetone only when no calls are active */
223 if (!voice_is_call_state_active(adev))
224 voice_set_sidetone(adev, uc_info->out_snd_device, false);
225
Vidyakumar Athotaea269c62016-10-31 09:05:59 -0700226 /* Disable aanc only when no calls are active */
227 if (!voice_is_call_state_active(adev))
228 voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, false);
229
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800230 ret = platform_stop_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700231
232 /* 1. Close the PCM devices */
233 if (session->pcm_rx) {
234 pcm_close(session->pcm_rx);
235 session->pcm_rx = NULL;
236 }
237 if (session->pcm_tx) {
238 pcm_close(session->pcm_tx);
239 session->pcm_tx = NULL;
240 }
241
Pallavi Mishra5627c162020-02-15 19:00:40 +0530242 if (voice_external_baseband_supported(adev)) {
243 if(voice_loopback_rx) {
244 pcm_close(voice_loopback_rx);
245 voice_loopback_rx = NULL;
246 }
247 if(voice_loopback_tx) {
248 pcm_close(voice_loopback_tx);
249 voice_loopback_tx = NULL;
250 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530251 }
Pallavi009b5212020-10-01 22:53:09 +0530252
253 if (voice_update_pcm_config(adev)) {
254 ret = release_wake_lock(TRANSIT_WAKE_LOCK_NAME);
255 if (ret)
256 ALOGE("%s: failed to release voicecall wake lock. ret: %d",__func__, ret);
257 }
258
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700259 /* 2. Get and set stream specific mixer controls */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700260 disable_audio_route(adev, uc_info);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700261
262 /* 3. Disable the rx and tx devices */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700263 disable_snd_device(adev, uc_info->out_snd_device);
264 disable_snd_device(adev, uc_info->in_snd_device);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700265
266 list_remove(&uc_info->list);
267 free(uc_info);
268
269 ALOGD("%s: exit: status(%d)", __func__, ret);
270 return ret;
271}
272
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700273int voice_start_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700274{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530275 int ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700276 struct audio_usecase *uc_info;
277 int pcm_dev_rx_id, pcm_dev_tx_id;
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530278 int pcm_dev_loopback_rx_id, pcm_dev_loopback_tx_id;
Helen Zeng6a16ad72014-02-23 22:04:44 -0800279 uint32_t sample_rate = 8000;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700280 struct voice_session *session = NULL;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700281 struct pcm_config voice_config = pcm_config_voice_call;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800282
283 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700284
285 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700286 if (!session) {
287 ALOGE("start_call: couldn't find voice session");
288 return -EINVAL;
289 }
290
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700291 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700292 if (!uc_info) {
293 ALOGE("start_call: couldn't allocate mem for audio_usecase");
294 return -ENOMEM;
295 }
296
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700297 uc_info->id = usecase_id;
298 uc_info->type = VOICE_CALL;
kunleiz3251d232017-11-15 16:28:55 +0800299 uc_info->stream.out = adev->current_call_output;
300 uc_info->devices = adev->current_call_output->devices;
301
Anurag Chouhand9867322020-03-09 13:26:25 +0530302 if (voice_update_pcm_config(adev)) {
303 sample_rate = 48000;
304 voice_config.rate = 48000;
305 }
306
kunleiz3251d232017-11-15 16:28:55 +0800307 if (popcount(uc_info->devices) == 2) {
308 ALOGE("%s: Invalid combo device(%#x) for voice call", __func__,
309 uc_info->devices);
310 ret = -EIO;
311 goto error_start_voice;
312 }
313
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700314 uc_info->in_snd_device = SND_DEVICE_NONE;
315 uc_info->out_snd_device = SND_DEVICE_NONE;
Arun Mirpurief53ce52018-09-11 18:00:09 -0700316 adev->voice.use_device_mute = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700317
kunleizf175f672017-09-12 17:02:52 +0800318 if (audio_is_bluetooth_sco_device(uc_info->devices) && !adev->bt_sco_on) {
319 ALOGE("start_call: couldn't find BT SCO, SCO is not ready");
320 adev->voice.in_call = false;
321 ret = -EIO;
322 goto error_start_voice;
323 }
324
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700325 list_add_tail(&adev->usecase_list, &uc_info->list);
326
327 select_devices(adev, usecase_id);
328
Pallavi Mishra5627c162020-02-15 19:00:40 +0530329 if (voice_external_baseband_supported(adev)) {
330 pcm_dev_loopback_rx_id = HOST_LESS_RX_ID;
331 pcm_dev_loopback_tx_id = HOST_LESS_TX_ID;
332 }
333
Anurag Chouhand9867322020-03-09 13:26:25 +0530334 if (voice_update_pcm_config(adev)) {
335 pcm_dev_loopback_rx_id = PCIE_HOST_LESS_RX_ID;
336 pcm_dev_loopback_tx_id = PCIE_HOST_LESS_TX_ID;
337 }
338
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700339 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
340 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
341
342 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
343 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
344 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
345 ret = -EIO;
346 goto error_start_voice;
347 }
Helen Zeng6a16ad72014-02-23 22:04:44 -0800348 ret = platform_get_sample_rate(adev->platform, &sample_rate);
349 if (ret < 0) {
350 ALOGE("platform_get_sample_rate error %d\n", ret);
351 } else {
352 voice_config.rate = sample_rate;
353 }
354 ALOGD("voice_config.rate %d\n", voice_config.rate);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700355
Vidyakumar Athotab000e0b2015-04-09 17:45:20 -0700356 voice_set_mic_mute(adev, adev->voice.mic_mute);
357
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700358 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
359 __func__, adev->snd_card, pcm_dev_tx_id);
360 session->pcm_tx = pcm_open(adev->snd_card,
361 pcm_dev_tx_id,
362 PCM_IN, &voice_config);
363 if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) {
364 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
365 ret = -EIO;
366 goto error_start_voice;
367 }
368
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700369 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800370 __func__, adev->snd_card, pcm_dev_rx_id);
371 session->pcm_rx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700372 pcm_dev_rx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700373 PCM_OUT, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700374 if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) {
375 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
376 ret = -EIO;
377 goto error_start_voice;
378 }
379
Pallavi Mishra5627c162020-02-15 19:00:40 +0530380 if (voice_external_baseband_supported(adev)) {
381 voice_loopback_rx = pcm_open(adev->snd_card,
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530382 pcm_dev_loopback_rx_id,
383 PCM_OUT, &voice_config);
Pallavi Mishra5627c162020-02-15 19:00:40 +0530384 if (voice_loopback_rx < 0 || !pcm_is_ready(voice_loopback_rx)) {
385 ALOGE("%s: Either could not open pcm_dev_loopback_rx_id %d or %s",
386 __func__, pcm_dev_loopback_rx_id, pcm_get_error(voice_loopback_rx));
387 ret = -EIO;
388 goto error_start_voice;
389 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530390
Pallavi Mishra5627c162020-02-15 19:00:40 +0530391 voice_loopback_tx = pcm_open(adev->snd_card,
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530392 pcm_dev_loopback_tx_id,
393 PCM_IN, &voice_config);
Pallavi Mishra5627c162020-02-15 19:00:40 +0530394 if (voice_loopback_tx < 0 || !pcm_is_ready(voice_loopback_tx)) {
395 ALOGE("%s: Either could not open pcm_dev_loopback_tx_id %d or %s",
396 __func__, pcm_dev_loopback_tx_id, pcm_get_error(voice_loopback_tx));
397 ret = -EIO;
398 goto error_start_voice;
399 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530400 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530401
Pallavi009b5212020-10-01 22:53:09 +0530402 if (voice_update_pcm_config(adev)) {
403 ret = acquire_wake_lock(PARTIAL_WAKE_LOCK, TRANSIT_WAKE_LOCK_NAME);
404 if (ret)
405 ALOGE("%s: acquiring wake lock failed for voice call ret: %d",__func__, ret);
406 }
407
Weiyin Jiang095e4442019-07-15 11:49:15 +0800408 if (adev->mic_break_enabled)
Vignesh Kulothungan7d374312018-02-21 17:12:00 -0800409 platform_set_mic_break_det(adev->platform, true);
410
Vignesh Kulothungancf4b9322019-05-03 13:52:50 -0700411 ret = pcm_start(session->pcm_tx);
412 if (ret != 0) {
413 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
414 goto error_start_voice;
415 }
416
417 ret = pcm_start(session->pcm_rx);
418 if (ret != 0) {
419 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
420 goto error_start_voice;
421 }
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700422
Pallavi Mishra5627c162020-02-15 19:00:40 +0530423 if (voice_external_baseband_supported(adev)) {
424 ret = pcm_start(voice_loopback_tx);
425 if (ret != 0) {
426 ALOGE("%s: %s", __func__, pcm_get_error(voice_loopback_tx));
427 goto error_start_voice;
428 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530429
Pallavi Mishra5627c162020-02-15 19:00:40 +0530430 ret = pcm_start(voice_loopback_rx);
431 if (ret != 0) {
432 ALOGE("%s: %s", __func__, pcm_get_error(voice_loopback_rx));
433 goto error_start_voice;
434 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530435 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530436
Vidyakumar Athotaea269c62016-10-31 09:05:59 -0700437 /* Enable aanc only when no calls are active */
438 if (!voice_is_call_state_active(adev))
439 voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, true);
440
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700441 /* Enable sidetone only when no calls are already active */
442 if (!voice_is_call_state_active(adev))
443 voice_set_sidetone(adev, uc_info->out_snd_device, true);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700444
Shruthi Krishnaace10852013-10-25 14:32:12 -0700445 voice_set_volume(adev, adev->voice.volume);
446
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800447 ret = platform_start_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700448 if (ret < 0) {
449 ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
450 goto error_start_voice;
451 }
452
453 session->state.current = CALL_ACTIVE;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700454 goto done;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700455
456error_start_voice:
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700457 voice_stop_usecase(adev, usecase_id);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700458
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700459done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700460 ALOGD("%s: exit: status(%d)", __func__, ret);
461 return ret;
462}
463
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700464bool voice_is_call_state_active(struct audio_device *adev)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700465{
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700466 bool call_state = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700467 int ret = 0;
468
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700469 ret = voice_extn_is_call_state_active(adev, &call_state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700470 if (ret == -ENOSYS) {
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700471 call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700472 }
473
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700474 return call_state;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700475}
476
Alexy Josephb1379942016-01-29 15:49:38 -0800477bool voice_is_in_call(const struct audio_device *adev)
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700478{
479 return adev->voice.in_call;
480}
481
Alexy Josephb1379942016-01-29 15:49:38 -0800482bool voice_is_in_call_rec_stream(const struct stream_in *in)
kunleizc5a639b2014-04-24 18:46:22 +0800483{
484 bool in_call_rec = false;
kunleizc5a639b2014-04-24 18:46:22 +0800485
Anish Kumar50ebcbf2014-12-09 04:01:39 +0530486 if (!in) {
487 ALOGE("%s: input stream is NULL", __func__);
488 return in_call_rec;
489 }
490
Arun Mirpurief53ce52018-09-11 18:00:09 -0700491 if (in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
492 in->source == AUDIO_SOURCE_VOICE_UPLINK ||
493 in->source == AUDIO_SOURCE_VOICE_CALL) {
494 in_call_rec = true;
kunleizc5a639b2014-04-24 18:46:22 +0800495 }
496
497 return in_call_rec;
498}
499
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700500uint32_t voice_get_active_session_id(struct audio_device *adev)
501{
502 int ret = 0;
503 uint32_t session_id;
504
505 ret = voice_extn_get_active_session_id(adev, &session_id);
506 if (ret == -ENOSYS) {
507 session_id = VOICE_VSID;
508 }
509 return session_id;
510}
511
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +0800512bool voice_check_voicecall_usecases_active(struct audio_device *adev)
513{
514 struct listnode *node;
515 struct audio_usecase *usecase = NULL;
516
517 list_for_each(node, &adev->usecase_list) {
518 usecase = node_to_item(node, struct audio_usecase, list);
519 if (usecase->type == VOICE_CALL) {
520 ALOGV("%s: voice usecase:%s is active", __func__,
521 use_case_table[usecase->id]);
522 return true;
523 }
524 }
525 return false;
526}
527
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700528int voice_check_and_set_incall_rec_usecase(struct audio_device *adev,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800529 struct stream_in *in)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700530{
531 int ret = 0;
532 uint32_t session_id;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800533 int rec_mode = INCALL_REC_NONE;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700534
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700535 if (voice_is_call_state_active(adev)) {
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700536 switch (in->source) {
537 case AUDIO_SOURCE_VOICE_UPLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800538 if (audio_extn_compr_cap_enabled() &&
539 audio_extn_compr_cap_format_supported(in->config.format)) {
540 in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS;
541 } else
542 in->usecase = USECASE_INCALL_REC_UPLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800543 rec_mode = INCALL_REC_UPLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700544 break;
545 case AUDIO_SOURCE_VOICE_DOWNLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800546 if (audio_extn_compr_cap_enabled() &&
547 audio_extn_compr_cap_format_supported(in->config.format)) {
548 in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS;
549 } else
550 in->usecase = USECASE_INCALL_REC_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800551 rec_mode = INCALL_REC_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700552 break;
553 case AUDIO_SOURCE_VOICE_CALL:
Helen Zenge56b4852013-12-03 16:54:40 -0800554 if (audio_extn_compr_cap_enabled() &&
555 audio_extn_compr_cap_format_supported(in->config.format)) {
556 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS;
557 } else
558 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800559 rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700560 break;
561 default:
562 ALOGV("%s: Source type %d doesnt match incall recording criteria",
563 __func__, in->source);
564 return ret;
565 }
566
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700567 session_id = voice_get_active_session_id(adev);
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800568 ret = platform_set_incall_recording_session_id(adev->platform,
569 session_id, rec_mode);
Yunfei Zhang3714bd12019-04-11 09:04:28 +0800570 platform_set_incall_recording_session_channels(adev->platform,
571 in->config.channels);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700572 ALOGV("%s: Update usecase to %d",__func__, in->usecase);
573 } else {
Venkata Narendra Kumar Gutta76440ba2015-03-30 19:16:14 +0530574 /*
575 * Reject the recording instances, where the recording is started
576 * with In-call voice recording source types but voice call is not
577 * active by the time input is started
578 */
579 if ((in->source == AUDIO_SOURCE_VOICE_UPLINK) ||
580 (in->source == AUDIO_SOURCE_VOICE_DOWNLINK) ||
581 (in->source == AUDIO_SOURCE_VOICE_CALL)) {
582 ret = -EINVAL;
583 ALOGE("%s: As voice call is not active, Incall rec usecase can't be \
584 selected for requested source:%d",__func__, in->source);
585 }
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700586 ALOGV("%s: voice call not active", __func__);
587 }
588
589 return ret;
590}
591
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800592int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev,
593 struct stream_in *in)
594{
595 int ret = 0;
596
597 if (in->source == AUDIO_SOURCE_VOICE_UPLINK ||
598 in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
599 in->source == AUDIO_SOURCE_VOICE_CALL) {
600 ret = platform_stop_incall_recording_usecase(adev->platform);
601 ALOGV("%s: Stop In-call recording", __func__);
602 }
603
604 return ret;
605}
606
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +0530607snd_device_t voice_get_incall_rec_backend_device(struct stream_in *in)
608{
609 snd_device_t incall_record_device = {0};
610
Aditya Bavanari9e957d82019-01-29 17:47:13 +0530611 if (!in) {
612 ALOGE("%s: input stream is NULL", __func__);
613 return 0;
614 }
615
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +0530616 switch(in->source) {
617 case AUDIO_SOURCE_VOICE_UPLINK:
618 incall_record_device = SND_DEVICE_IN_INCALL_REC_TX;
619 break;
620 case AUDIO_SOURCE_VOICE_DOWNLINK:
621 incall_record_device = SND_DEVICE_IN_INCALL_REC_RX;
622 break;
623 case AUDIO_SOURCE_VOICE_CALL:
624 incall_record_device = SND_DEVICE_IN_INCALL_REC_RX_TX;
625 break;
626 default:
627 ALOGI("Invalid source %d", in->source);
628 }
629
630 return incall_record_device;
631}
632
Narsinga Rao Chella212e2542014-11-17 19:57:04 -0800633snd_device_t voice_get_incall_rec_snd_device(snd_device_t in_snd_device)
634{
635 snd_device_t incall_record_device = in_snd_device;
636
637 /*
638 * For incall recording stream, AUDIO_COPP topology will be picked up
639 * from the calibration data of the input sound device which is nothing
640 * but the voice call's input device. But there are requirements to use
641 * AUDIO_COPP_MONO topology even if the voice call's input device is
642 * different. Hence override the input device with the one which uses
643 * the AUDIO_COPP_MONO topology.
644 */
645 switch(in_snd_device) {
646 case SND_DEVICE_IN_HANDSET_MIC:
647 case SND_DEVICE_IN_VOICE_DMIC:
648 case SND_DEVICE_IN_AANC_HANDSET_MIC:
649 incall_record_device = SND_DEVICE_IN_HANDSET_MIC;
Shiv Maliyappanahalli4d2d97c2015-02-19 14:29:01 -0800650 break;
Narsinga Rao Chella212e2542014-11-17 19:57:04 -0800651 case SND_DEVICE_IN_VOICE_SPEAKER_MIC:
652 case SND_DEVICE_IN_VOICE_SPEAKER_DMIC:
653 case SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE:
654 case SND_DEVICE_IN_VOICE_SPEAKER_QMIC:
655 incall_record_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Shiv Maliyappanahalli4d2d97c2015-02-19 14:29:01 -0800656 break;
Narsinga Rao Chella212e2542014-11-17 19:57:04 -0800657 default:
658 incall_record_device = in_snd_device;
659 }
660
Shiv Maliyappanahalli4d2d97c2015-02-19 14:29:01 -0800661 ALOGD("%s: in_snd_device(%d: %s) incall_record_device(%d: %s)", __func__,
662 in_snd_device, platform_get_snd_device_name(in_snd_device),
663 incall_record_device, platform_get_snd_device_name(incall_record_device));
664
Narsinga Rao Chella212e2542014-11-17 19:57:04 -0800665 return incall_record_device;
666}
667
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700668int voice_set_mic_mute(struct audio_device *adev, bool state)
669{
670 int err = 0;
671
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800672 adev->voice.mic_mute = state;
Arun Mirpurief53ce52018-09-11 18:00:09 -0700673
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530674 if (audio_extn_hfp_is_active(adev)) {
Arun Mirpurie008ed22019-03-21 11:21:04 -0700675 err = audio_extn_hfp_set_mic_mute2(adev, state);
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530676 } else if (adev->mode == AUDIO_MODE_IN_CALL) {
Arun Mirpurief53ce52018-09-11 18:00:09 -0700677 /* Use device mute if incall music delivery usecase is in progress */
678 if (adev->voice.use_device_mute)
679 err = platform_set_device_mute(adev->platform, state, "tx");
680 else
681 err = platform_set_mic_mute(adev->platform, state);
682 ALOGV("%s: voice mute status=%d, use_device_mute flag=%d",
683 __func__, state, adev->voice.use_device_mute);
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530684 } else if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800685 err = voice_extn_compress_voip_set_mic_mute(adev, state);
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530686 }
Arun Mirpurief53ce52018-09-11 18:00:09 -0700687
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700688 return err;
689}
690
691bool voice_get_mic_mute(struct audio_device *adev)
692{
693 return adev->voice.mic_mute;
694}
695
Arun Mirpurief53ce52018-09-11 18:00:09 -0700696/*
697 * Following function is called when incall music uplink usecase is
698 * created or destroyed while mic is muted. If incall music uplink
699 * usecase is active, apply voice device mute to mute only voice Tx
700 * path and not the mixed voice Tx + inncall-music path. Revert to
701 * voice stream mute once incall music uplink usecase is inactive
702 */
703void voice_set_device_mute_flag(struct audio_device *adev, bool state)
704{
705 if (adev->voice.mic_mute) {
706 if (state) {
707 platform_set_device_mute(adev->platform, true, "tx");
708 platform_set_mic_mute(adev->platform, false);
709 } else {
710 platform_set_mic_mute(adev->platform, true);
711 platform_set_device_mute(adev->platform, false, "tx");
712 }
713 }
714 adev->voice.use_device_mute = state;
715}
716
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700717int voice_set_volume(struct audio_device *adev, float volume)
718{
719 int vol, err = 0;
720
Shruthi Krishnaace10852013-10-25 14:32:12 -0700721 adev->voice.volume = volume;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700722 if (adev->mode == AUDIO_MODE_IN_CALL) {
723 if (volume < 0.0) {
724 volume = 0.0;
725 } else if (volume > 1.0) {
726 volume = 1.0;
727 }
728
729 vol = lrint(volume * 100.0);
730
731 // Voice volume levels from android are mapped to driver volume levels as follows.
732 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
733 // So adjust the volume to get the correct volume index in driver
734 vol = 100 - vol;
735
736 err = platform_set_voice_volume(adev->platform, vol);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700737 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800738 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
739 err = voice_extn_compress_voip_set_volume(adev, volume);
740
Shruthi Krishnaace10852013-10-25 14:32:12 -0700741
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700742 return err;
743}
744
745int voice_start_call(struct audio_device *adev)
746{
747 int ret = 0;
748
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -0700749 adev->voice.in_call = true;
Aalique Grahame22e49102018-12-18 14:23:57 -0800750
751 voice_set_mic_mute(adev, adev->voice.mic_mute);
752
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800753 ret = voice_extn_start_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700754 if (ret == -ENOSYS) {
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700755 ret = voice_start_usecase(adev, USECASE_VOICE_CALL);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700756 }
757
758 return ret;
759}
760
761int voice_stop_call(struct audio_device *adev)
762{
763 int ret = 0;
764
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700765 adev->voice.in_call = false;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800766 ret = voice_extn_stop_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700767 if (ret == -ENOSYS) {
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700768 ret = voice_stop_usecase(adev, USECASE_VOICE_CALL);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700769 }
770
771 return ret;
772}
773
Shiv Maliyappanahallif9308492013-12-12 12:18:09 -0800774void voice_get_parameters(struct audio_device *adev,
775 struct str_parms *query,
776 struct str_parms *reply)
777{
778 voice_extn_get_parameters(adev, query, reply);
779}
780
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700781int voice_set_parameters(struct audio_device *adev, struct str_parms *parms)
782{
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700783 char value[32];
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800784 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800785 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700786
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800787 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700788
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800789 ret = voice_extn_set_parameters(adev, parms);
Vidyakumar Athota8d931f02014-07-21 14:51:44 -0700790 if (ret != 0) {
791 if (ret == -ENOSYS)
792 ret = 0;
793 else
794 goto done;
795 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700796
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800797 ret = voice_extn_compress_voip_set_parameters(adev, parms);
Vidyakumar Athota8d931f02014-07-21 14:51:44 -0700798 if (ret != 0) {
799 if (ret == -ENOSYS)
800 ret = 0;
801 else
802 goto done;
803 }
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800804
805 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
806 if (err >= 0) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700807 int tty_mode;
808 str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE);
809 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
810 tty_mode = TTY_MODE_OFF;
811 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
812 tty_mode = TTY_MODE_VCO;
813 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
814 tty_mode = TTY_MODE_HCO;
815 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
816 tty_mode = TTY_MODE_FULL;
817 else {
818 ret = -EINVAL;
819 goto done;
820 }
821
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700822 if (tty_mode != adev->voice.tty_mode) {
823 adev->voice.tty_mode = tty_mode;
824 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700825 if (voice_is_call_state_active(adev))
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800826 voice_update_devices_for_all_voice_usecases(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700827 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700828 }
829
Aalique Grahame22e49102018-12-18 14:23:57 -0800830 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HAC,
831 value, sizeof(value));
832 if (err >= 0) {
833 bool hac = false;
834 str_parms_del(parms, AUDIO_PARAMETER_KEY_HAC);
835 if (strcmp(value, AUDIO_PARAMETER_VALUE_HAC_ON) == 0)
836 hac = true;
837
838 if (hac != adev->voice.hac) {
839 adev->voice.hac = hac;
840 if (voice_is_in_call(adev))
841 voice_update_devices_for_all_voice_usecases(adev);
842 }
843 }
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800844 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800845 value, sizeof(value));
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800846 if (err >= 0) {
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800847 str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC);
848 if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0)
849 platform_start_incall_music_usecase(adev->platform);
850 else
851 platform_stop_incall_music_usecase(adev->platform);
Vidyakumar Athota8d931f02014-07-21 14:51:44 -0700852 }
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800853
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700854done:
855 ALOGV("%s: exit with code(%d)", __func__, ret);
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800856 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700857 return ret;
858}
859
860void voice_init(struct audio_device *adev)
861{
862 int i = 0;
Weiyin Jiang095e4442019-07-15 11:49:15 +0800863 int max_voice_sessions = MAX_VOICE_SESSIONS;
864
865 if (!voice_extn_is_multi_session_supported())
866 max_voice_sessions = 1;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700867
868 memset(&adev->voice, 0, sizeof(adev->voice));
869 adev->voice.tty_mode = TTY_MODE_OFF;
Aalique Grahame22e49102018-12-18 14:23:57 -0800870 adev->voice.hac = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700871 adev->voice.volume = 1.0f;
872 adev->voice.mic_mute = false;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700873 adev->voice.in_call = false;
Weiyin Jiang095e4442019-07-15 11:49:15 +0800874 for (i = 0; i < max_voice_sessions; i++) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700875 adev->voice.session[i].pcm_rx = NULL;
876 adev->voice.session[i].pcm_tx = NULL;
877 adev->voice.session[i].state.current = CALL_INACTIVE;
878 adev->voice.session[i].state.new = CALL_INACTIVE;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700879 adev->voice.session[i].vsid = VOICE_VSID;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700880 }
881
882 voice_extn_init(adev);
883}
884
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800885void voice_update_devices_for_all_voice_usecases(struct audio_device *adev)
886{
887 struct listnode *node;
888 struct audio_usecase *usecase;
889
890 list_for_each(node, &adev->usecase_list) {
891 usecase = node_to_item(node, struct audio_usecase, list);
892 if (usecase->type == VOICE_CALL) {
893 ALOGV("%s: updating device for usecase:%s", __func__,
894 use_case_table[usecase->id]);
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700895 usecase->stream.out = adev->current_call_output;
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800896 select_devices(adev, usecase->id);
897 }
898 }
899}
900
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700901
Pallavi Mishra5627c162020-02-15 19:00:40 +0530902