blob: f1e2c47fcc1923e15852db8b57bcf4c97ac78e28 [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"
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070036
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053037#ifdef DYNAMIC_LOG_ENABLED
38#include <log_xml_parser.h>
39#define LOG_MASK HAL_MOD_FILE_VOICE
40#include <log_utils.h>
41#endif
42
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070043struct pcm_config pcm_config_voice_call = {
44 .channels = 1,
45 .rate = 8000,
46 .period_size = 160,
47 .period_count = 2,
48 .format = PCM_FORMAT_S16_LE,
49};
50
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +053051struct pcm *voice_loopback_tx = NULL;
52struct pcm *voice_loopback_rx = NULL;
Pallavi Mishra5627c162020-02-15 19:00:40 +053053
54static bool voice_external_baseband_supported(struct audio_device *adev)
55{
56 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
57 * symbols. Voice call is handled by MDM and apps processor talks to
58 * MDM through CSD Client
59 */
Anurag Chouhand9867322020-03-09 13:26:25 +053060 char *snd_card_name = NULL;
Pallavi Mishra5627c162020-02-15 19:00:40 +053061 char baseband[100];
62 snd_card_name = strdup(mixer_get_name(adev->mixer));
Anurag Chouhand9867322020-03-09 13:26:25 +053063 if (!snd_card_name)
64 return 0;
Pallavi Mishra5627c162020-02-15 19:00:40 +053065 property_get("ro.baseband", baseband, "");
Anurag Chouhand9867322020-03-09 13:26:25 +053066 if (((!strncmp("hana55", snd_card_name, sizeof("hana55"))) &&
67 ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) ||
68 !strncmp("sdx", baseband, (sizeof("sdx")-1)))) ||
69 ((!strncmp("sm8150-pcie-snd-card", snd_card_name, sizeof("sm8150-pcie-snd-card"))) &&
70 ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) ||
71 !strncmp("sdx", baseband, (sizeof("sdx")-1))))) {
72 return 1;
73 } else {
74 return 0;
75 }
76}
77
78static bool voice_update_pcm_config(struct audio_device *adev)
79{
80 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
81 * symbols. Voice call is handled by MDM and apps processor talks to
82 * MDM through CSD Client
83 */
84 char *snd_card_name = NULL;
85 char baseband[100];
86 snd_card_name = strdup(mixer_get_name(adev->mixer));
87 if (!snd_card_name)
88 return 0;
89 property_get("ro.baseband", baseband, "");
90 if ((!strncmp("sm8150-pcie-snd-card", snd_card_name, sizeof("sm8150-pcie-snd-card"))) &&
Pallavi Mishra5627c162020-02-15 19:00:40 +053091 ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) ||
92 !strncmp("sdx", baseband, (sizeof("sdx")-1)))) {
93 return 1;
Anurag Chouhand9867322020-03-09 13:26:25 +053094 } else {
Pallavi Mishra5627c162020-02-15 19:00:40 +053095 return 0;
Anurag Chouhand9867322020-03-09 13:26:25 +053096 }
Pallavi Mishra5627c162020-02-15 19:00:40 +053097}
98
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070099static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev,
100 audio_usecase_t usecase_id)
101{
102 struct voice_session *session = NULL;
103 int ret = 0;
104
105 ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session);
106 if (ret == -ENOSYS) {
107 session = &adev->voice.session[VOICE_SESS_IDX];
108 }
109
110 return session;
111}
112
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700113static bool voice_is_sidetone_device(snd_device_t out_device,
114 char *mixer_path)
115{
116 bool is_sidetone_dev;
117
118 switch (out_device) {
119 case SND_DEVICE_OUT_VOICE_HANDSET:
120 is_sidetone_dev = true;
121 strlcpy(mixer_path, "sidetone-handset", MIXER_PATH_MAX_LENGTH);
122 break;
123 case SND_DEVICE_OUT_VOICE_HEADPHONES:
Samyak Jainfd24f1e2019-04-30 11:58:43 +0530124 case SND_DEVICE_OUT_VOICE_HEADSET:
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700125 case SND_DEVICE_OUT_VOICE_ANC_HEADSET:
126 case SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET:
127 is_sidetone_dev = true;
128 strlcpy(mixer_path, "sidetone-headphones", MIXER_PATH_MAX_LENGTH);
129 break;
Aalique Grahame22e49102018-12-18 14:23:57 -0800130 case SND_DEVICE_OUT_VOICE_USB_HEADSET:
Kuirong Wang1cad7142016-05-24 15:21:56 -0700131 case SND_DEVICE_OUT_USB_HEADSET:
Aalique Grahame22e49102018-12-18 14:23:57 -0800132 // USB does not use a QC mixer.
133 mixer_path[0] = '\0';
Kuirong Wang1cad7142016-05-24 15:21:56 -0700134 is_sidetone_dev = true;
135 break;
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700136 default:
Aalique Grahame22e49102018-12-18 14:23:57 -0800137 ALOGW("%s: %d is not a sidetone device", __func__, out_device);
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700138 is_sidetone_dev = false;
139 break;
140 }
141
142 return is_sidetone_dev;
143}
144
145void voice_set_sidetone(struct audio_device *adev,
146 snd_device_t out_snd_device, bool enable)
147{
148 char mixer_path[MIXER_PATH_MAX_LENGTH];
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700149 ALOGD("%s: %s, out_snd_device: %d\n",
150 __func__, (enable ? "enable" : "disable"),
151 out_snd_device);
Kuirong Wang1cad7142016-05-24 15:21:56 -0700152 if (voice_is_sidetone_device(out_snd_device, mixer_path))
153 platform_set_sidetone(adev, out_snd_device, enable, mixer_path);
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700154 return;
155}
156
Vidyakumar Athotaea269c62016-10-31 09:05:59 -0700157static bool voice_is_aanc_device(snd_device_t out_device,
158 char *mixer_path)
159{
160 bool is_aanc_dev;
161
162 switch (out_device) {
163 case SND_DEVICE_OUT_ANC_HANDSET:
164 is_aanc_dev = true;
165 strlcpy(mixer_path, "aanc-path", MIXER_PATH_MAX_LENGTH);
166 break;
167 default:
168 is_aanc_dev = false;
169 break;
170 }
171
172 return is_aanc_dev;
173}
174
175void voice_check_and_update_aanc_path(struct audio_device *adev,
176 snd_device_t out_snd_device,
177 bool enable)
178{
179 char mixer_path[MIXER_PATH_MAX_LENGTH];
180
181 ALOGV("%s: %s, out_snd_device: %d\n",
182 __func__, (enable ? "enable" : "disable"), out_snd_device);
183
184 if (voice_is_aanc_device(out_snd_device, mixer_path))
185 platform_update_aanc_path(adev, out_snd_device, enable, mixer_path);
186
187 return;
188}
189
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700190int voice_stop_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700191{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530192 int ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700193 struct audio_usecase *uc_info;
194 struct voice_session *session = NULL;
195
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800196 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700197
198 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700199 if (!session) {
200 ALOGE("stop_call: couldn't find voice session");
201 return -EINVAL;
202 }
203
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700204 uc_info = get_usecase_from_list(adev, usecase_id);
205 if (uc_info == NULL) {
206 ALOGE("%s: Could not find the usecase (%d) in the list",
207 __func__, usecase_id);
208 return -EINVAL;
209 }
210
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700211 session->state.current = CALL_INACTIVE;
212
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700213 /* Disable sidetone only when no calls are active */
214 if (!voice_is_call_state_active(adev))
215 voice_set_sidetone(adev, uc_info->out_snd_device, false);
216
Vidyakumar Athotaea269c62016-10-31 09:05:59 -0700217 /* Disable aanc only when no calls are active */
218 if (!voice_is_call_state_active(adev))
219 voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, false);
220
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800221 ret = platform_stop_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700222
223 /* 1. Close the PCM devices */
224 if (session->pcm_rx) {
225 pcm_close(session->pcm_rx);
226 session->pcm_rx = NULL;
227 }
228 if (session->pcm_tx) {
229 pcm_close(session->pcm_tx);
230 session->pcm_tx = NULL;
231 }
232
Pallavi Mishra5627c162020-02-15 19:00:40 +0530233 if (voice_external_baseband_supported(adev)) {
234 if(voice_loopback_rx) {
235 pcm_close(voice_loopback_rx);
236 voice_loopback_rx = NULL;
237 }
238 if(voice_loopback_tx) {
239 pcm_close(voice_loopback_tx);
240 voice_loopback_tx = NULL;
241 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530242 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700243 /* 2. Get and set stream specific mixer controls */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700244 disable_audio_route(adev, uc_info);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700245
246 /* 3. Disable the rx and tx devices */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700247 disable_snd_device(adev, uc_info->out_snd_device);
248 disable_snd_device(adev, uc_info->in_snd_device);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700249
250 list_remove(&uc_info->list);
251 free(uc_info);
252
253 ALOGD("%s: exit: status(%d)", __func__, ret);
254 return ret;
255}
256
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700257int voice_start_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700258{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530259 int ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700260 struct audio_usecase *uc_info;
261 int pcm_dev_rx_id, pcm_dev_tx_id;
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530262 int pcm_dev_loopback_rx_id, pcm_dev_loopback_tx_id;
Helen Zeng6a16ad72014-02-23 22:04:44 -0800263 uint32_t sample_rate = 8000;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700264 struct voice_session *session = NULL;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700265 struct pcm_config voice_config = pcm_config_voice_call;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800266
267 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700268
269 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700270 if (!session) {
271 ALOGE("start_call: couldn't find voice session");
272 return -EINVAL;
273 }
274
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700275 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700276 if (!uc_info) {
277 ALOGE("start_call: couldn't allocate mem for audio_usecase");
278 return -ENOMEM;
279 }
280
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700281 uc_info->id = usecase_id;
282 uc_info->type = VOICE_CALL;
kunleiz3251d232017-11-15 16:28:55 +0800283 uc_info->stream.out = adev->current_call_output;
284 uc_info->devices = adev->current_call_output->devices;
285
Anurag Chouhand9867322020-03-09 13:26:25 +0530286 if (voice_update_pcm_config(adev)) {
287 sample_rate = 48000;
288 voice_config.rate = 48000;
289 }
290
kunleiz3251d232017-11-15 16:28:55 +0800291 if (popcount(uc_info->devices) == 2) {
292 ALOGE("%s: Invalid combo device(%#x) for voice call", __func__,
293 uc_info->devices);
294 ret = -EIO;
295 goto error_start_voice;
296 }
297
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700298 uc_info->in_snd_device = SND_DEVICE_NONE;
299 uc_info->out_snd_device = SND_DEVICE_NONE;
Arun Mirpurief53ce52018-09-11 18:00:09 -0700300 adev->voice.use_device_mute = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700301
kunleizf175f672017-09-12 17:02:52 +0800302 if (audio_is_bluetooth_sco_device(uc_info->devices) && !adev->bt_sco_on) {
303 ALOGE("start_call: couldn't find BT SCO, SCO is not ready");
304 adev->voice.in_call = false;
305 ret = -EIO;
306 goto error_start_voice;
307 }
308
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700309 list_add_tail(&adev->usecase_list, &uc_info->list);
310
311 select_devices(adev, usecase_id);
312
Pallavi Mishra5627c162020-02-15 19:00:40 +0530313 if (voice_external_baseband_supported(adev)) {
314 pcm_dev_loopback_rx_id = HOST_LESS_RX_ID;
315 pcm_dev_loopback_tx_id = HOST_LESS_TX_ID;
316 }
317
Anurag Chouhand9867322020-03-09 13:26:25 +0530318 if (voice_update_pcm_config(adev)) {
319 pcm_dev_loopback_rx_id = PCIE_HOST_LESS_RX_ID;
320 pcm_dev_loopback_tx_id = PCIE_HOST_LESS_TX_ID;
321 }
322
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700323 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
324 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
325
326 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
327 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
328 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
329 ret = -EIO;
330 goto error_start_voice;
331 }
Helen Zeng6a16ad72014-02-23 22:04:44 -0800332 ret = platform_get_sample_rate(adev->platform, &sample_rate);
333 if (ret < 0) {
334 ALOGE("platform_get_sample_rate error %d\n", ret);
335 } else {
336 voice_config.rate = sample_rate;
337 }
338 ALOGD("voice_config.rate %d\n", voice_config.rate);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700339
Vidyakumar Athotab000e0b2015-04-09 17:45:20 -0700340 voice_set_mic_mute(adev, adev->voice.mic_mute);
341
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700342 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
343 __func__, adev->snd_card, pcm_dev_tx_id);
344 session->pcm_tx = pcm_open(adev->snd_card,
345 pcm_dev_tx_id,
346 PCM_IN, &voice_config);
347 if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) {
348 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
349 ret = -EIO;
350 goto error_start_voice;
351 }
352
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700353 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800354 __func__, adev->snd_card, pcm_dev_rx_id);
355 session->pcm_rx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700356 pcm_dev_rx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700357 PCM_OUT, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700358 if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) {
359 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
360 ret = -EIO;
361 goto error_start_voice;
362 }
363
Pallavi Mishra5627c162020-02-15 19:00:40 +0530364 if (voice_external_baseband_supported(adev)) {
365 voice_loopback_rx = pcm_open(adev->snd_card,
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530366 pcm_dev_loopback_rx_id,
367 PCM_OUT, &voice_config);
Pallavi Mishra5627c162020-02-15 19:00:40 +0530368 if (voice_loopback_rx < 0 || !pcm_is_ready(voice_loopback_rx)) {
369 ALOGE("%s: Either could not open pcm_dev_loopback_rx_id %d or %s",
370 __func__, pcm_dev_loopback_rx_id, pcm_get_error(voice_loopback_rx));
371 ret = -EIO;
372 goto error_start_voice;
373 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530374
Pallavi Mishra5627c162020-02-15 19:00:40 +0530375 voice_loopback_tx = pcm_open(adev->snd_card,
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530376 pcm_dev_loopback_tx_id,
377 PCM_IN, &voice_config);
Pallavi Mishra5627c162020-02-15 19:00:40 +0530378 if (voice_loopback_tx < 0 || !pcm_is_ready(voice_loopback_tx)) {
379 ALOGE("%s: Either could not open pcm_dev_loopback_tx_id %d or %s",
380 __func__, pcm_dev_loopback_tx_id, pcm_get_error(voice_loopback_tx));
381 ret = -EIO;
382 goto error_start_voice;
383 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530384 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530385
Weiyin Jiang095e4442019-07-15 11:49:15 +0800386 if (adev->mic_break_enabled)
Vignesh Kulothungan7d374312018-02-21 17:12:00 -0800387 platform_set_mic_break_det(adev->platform, true);
388
Vignesh Kulothungancf4b9322019-05-03 13:52:50 -0700389 ret = pcm_start(session->pcm_tx);
390 if (ret != 0) {
391 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
392 goto error_start_voice;
393 }
394
395 ret = pcm_start(session->pcm_rx);
396 if (ret != 0) {
397 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
398 goto error_start_voice;
399 }
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700400
Pallavi Mishra5627c162020-02-15 19:00:40 +0530401 if (voice_external_baseband_supported(adev)) {
402 ret = pcm_start(voice_loopback_tx);
403 if (ret != 0) {
404 ALOGE("%s: %s", __func__, pcm_get_error(voice_loopback_tx));
405 goto error_start_voice;
406 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530407
Pallavi Mishra5627c162020-02-15 19:00:40 +0530408 ret = pcm_start(voice_loopback_rx);
409 if (ret != 0) {
410 ALOGE("%s: %s", __func__, pcm_get_error(voice_loopback_rx));
411 goto error_start_voice;
412 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530413 }
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +0530414
Vidyakumar Athotaea269c62016-10-31 09:05:59 -0700415 /* Enable aanc only when no calls are active */
416 if (!voice_is_call_state_active(adev))
417 voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, true);
418
Bhalchandra Gajare45fee282015-06-09 22:23:45 -0700419 /* Enable sidetone only when no calls are already active */
420 if (!voice_is_call_state_active(adev))
421 voice_set_sidetone(adev, uc_info->out_snd_device, true);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700422
Shruthi Krishnaace10852013-10-25 14:32:12 -0700423 voice_set_volume(adev, adev->voice.volume);
424
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800425 ret = platform_start_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700426 if (ret < 0) {
427 ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
428 goto error_start_voice;
429 }
430
431 session->state.current = CALL_ACTIVE;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700432 goto done;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700433
434error_start_voice:
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700435 voice_stop_usecase(adev, usecase_id);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700436
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700437done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700438 ALOGD("%s: exit: status(%d)", __func__, ret);
439 return ret;
440}
441
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700442bool voice_is_call_state_active(struct audio_device *adev)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700443{
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700444 bool call_state = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700445 int ret = 0;
446
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700447 ret = voice_extn_is_call_state_active(adev, &call_state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700448 if (ret == -ENOSYS) {
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700449 call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700450 }
451
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700452 return call_state;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700453}
454
Alexy Josephb1379942016-01-29 15:49:38 -0800455bool voice_is_in_call(const struct audio_device *adev)
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700456{
457 return adev->voice.in_call;
458}
459
Alexy Josephb1379942016-01-29 15:49:38 -0800460bool voice_is_in_call_rec_stream(const struct stream_in *in)
kunleizc5a639b2014-04-24 18:46:22 +0800461{
462 bool in_call_rec = false;
kunleizc5a639b2014-04-24 18:46:22 +0800463
Anish Kumar50ebcbf2014-12-09 04:01:39 +0530464 if (!in) {
465 ALOGE("%s: input stream is NULL", __func__);
466 return in_call_rec;
467 }
468
Arun Mirpurief53ce52018-09-11 18:00:09 -0700469 if (in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
470 in->source == AUDIO_SOURCE_VOICE_UPLINK ||
471 in->source == AUDIO_SOURCE_VOICE_CALL) {
472 in_call_rec = true;
kunleizc5a639b2014-04-24 18:46:22 +0800473 }
474
475 return in_call_rec;
476}
477
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700478uint32_t voice_get_active_session_id(struct audio_device *adev)
479{
480 int ret = 0;
481 uint32_t session_id;
482
483 ret = voice_extn_get_active_session_id(adev, &session_id);
484 if (ret == -ENOSYS) {
485 session_id = VOICE_VSID;
486 }
487 return session_id;
488}
489
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +0800490bool voice_check_voicecall_usecases_active(struct audio_device *adev)
491{
492 struct listnode *node;
493 struct audio_usecase *usecase = NULL;
494
495 list_for_each(node, &adev->usecase_list) {
496 usecase = node_to_item(node, struct audio_usecase, list);
497 if (usecase->type == VOICE_CALL) {
498 ALOGV("%s: voice usecase:%s is active", __func__,
499 use_case_table[usecase->id]);
500 return true;
501 }
502 }
503 return false;
504}
505
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700506int voice_check_and_set_incall_rec_usecase(struct audio_device *adev,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800507 struct stream_in *in)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700508{
509 int ret = 0;
510 uint32_t session_id;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800511 int rec_mode = INCALL_REC_NONE;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700512
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700513 if (voice_is_call_state_active(adev)) {
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700514 switch (in->source) {
515 case AUDIO_SOURCE_VOICE_UPLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800516 if (audio_extn_compr_cap_enabled() &&
517 audio_extn_compr_cap_format_supported(in->config.format)) {
518 in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS;
519 } else
520 in->usecase = USECASE_INCALL_REC_UPLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800521 rec_mode = INCALL_REC_UPLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700522 break;
523 case AUDIO_SOURCE_VOICE_DOWNLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800524 if (audio_extn_compr_cap_enabled() &&
525 audio_extn_compr_cap_format_supported(in->config.format)) {
526 in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS;
527 } else
528 in->usecase = USECASE_INCALL_REC_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800529 rec_mode = INCALL_REC_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700530 break;
531 case AUDIO_SOURCE_VOICE_CALL:
Helen Zenge56b4852013-12-03 16:54:40 -0800532 if (audio_extn_compr_cap_enabled() &&
533 audio_extn_compr_cap_format_supported(in->config.format)) {
534 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS;
535 } else
536 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800537 rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700538 break;
539 default:
540 ALOGV("%s: Source type %d doesnt match incall recording criteria",
541 __func__, in->source);
542 return ret;
543 }
544
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700545 session_id = voice_get_active_session_id(adev);
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800546 ret = platform_set_incall_recording_session_id(adev->platform,
547 session_id, rec_mode);
Yunfei Zhang3714bd12019-04-11 09:04:28 +0800548 platform_set_incall_recording_session_channels(adev->platform,
549 in->config.channels);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700550 ALOGV("%s: Update usecase to %d",__func__, in->usecase);
551 } else {
Venkata Narendra Kumar Gutta76440ba2015-03-30 19:16:14 +0530552 /*
553 * Reject the recording instances, where the recording is started
554 * with In-call voice recording source types but voice call is not
555 * active by the time input is started
556 */
557 if ((in->source == AUDIO_SOURCE_VOICE_UPLINK) ||
558 (in->source == AUDIO_SOURCE_VOICE_DOWNLINK) ||
559 (in->source == AUDIO_SOURCE_VOICE_CALL)) {
560 ret = -EINVAL;
561 ALOGE("%s: As voice call is not active, Incall rec usecase can't be \
562 selected for requested source:%d",__func__, in->source);
563 }
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700564 ALOGV("%s: voice call not active", __func__);
565 }
566
567 return ret;
568}
569
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800570int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev,
571 struct stream_in *in)
572{
573 int ret = 0;
574
575 if (in->source == AUDIO_SOURCE_VOICE_UPLINK ||
576 in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
577 in->source == AUDIO_SOURCE_VOICE_CALL) {
578 ret = platform_stop_incall_recording_usecase(adev->platform);
579 ALOGV("%s: Stop In-call recording", __func__);
580 }
581
582 return ret;
583}
584
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +0530585snd_device_t voice_get_incall_rec_backend_device(struct stream_in *in)
586{
587 snd_device_t incall_record_device = {0};
588
Aditya Bavanari9e957d82019-01-29 17:47:13 +0530589 if (!in) {
590 ALOGE("%s: input stream is NULL", __func__);
591 return 0;
592 }
593
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +0530594 switch(in->source) {
595 case AUDIO_SOURCE_VOICE_UPLINK:
596 incall_record_device = SND_DEVICE_IN_INCALL_REC_TX;
597 break;
598 case AUDIO_SOURCE_VOICE_DOWNLINK:
599 incall_record_device = SND_DEVICE_IN_INCALL_REC_RX;
600 break;
601 case AUDIO_SOURCE_VOICE_CALL:
602 incall_record_device = SND_DEVICE_IN_INCALL_REC_RX_TX;
603 break;
604 default:
605 ALOGI("Invalid source %d", in->source);
606 }
607
608 return incall_record_device;
609}
610
Narsinga Rao Chella212e2542014-11-17 19:57:04 -0800611snd_device_t voice_get_incall_rec_snd_device(snd_device_t in_snd_device)
612{
613 snd_device_t incall_record_device = in_snd_device;
614
615 /*
616 * For incall recording stream, AUDIO_COPP topology will be picked up
617 * from the calibration data of the input sound device which is nothing
618 * but the voice call's input device. But there are requirements to use
619 * AUDIO_COPP_MONO topology even if the voice call's input device is
620 * different. Hence override the input device with the one which uses
621 * the AUDIO_COPP_MONO topology.
622 */
623 switch(in_snd_device) {
624 case SND_DEVICE_IN_HANDSET_MIC:
625 case SND_DEVICE_IN_VOICE_DMIC:
626 case SND_DEVICE_IN_AANC_HANDSET_MIC:
627 incall_record_device = SND_DEVICE_IN_HANDSET_MIC;
Shiv Maliyappanahalli4d2d97c2015-02-19 14:29:01 -0800628 break;
Narsinga Rao Chella212e2542014-11-17 19:57:04 -0800629 case SND_DEVICE_IN_VOICE_SPEAKER_MIC:
630 case SND_DEVICE_IN_VOICE_SPEAKER_DMIC:
631 case SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE:
632 case SND_DEVICE_IN_VOICE_SPEAKER_QMIC:
633 incall_record_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Shiv Maliyappanahalli4d2d97c2015-02-19 14:29:01 -0800634 break;
Narsinga Rao Chella212e2542014-11-17 19:57:04 -0800635 default:
636 incall_record_device = in_snd_device;
637 }
638
Shiv Maliyappanahalli4d2d97c2015-02-19 14:29:01 -0800639 ALOGD("%s: in_snd_device(%d: %s) incall_record_device(%d: %s)", __func__,
640 in_snd_device, platform_get_snd_device_name(in_snd_device),
641 incall_record_device, platform_get_snd_device_name(incall_record_device));
642
Narsinga Rao Chella212e2542014-11-17 19:57:04 -0800643 return incall_record_device;
644}
645
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700646int voice_set_mic_mute(struct audio_device *adev, bool state)
647{
648 int err = 0;
649
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800650 adev->voice.mic_mute = state;
Arun Mirpurief53ce52018-09-11 18:00:09 -0700651
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530652 if (audio_extn_hfp_is_active(adev)) {
Arun Mirpurie008ed22019-03-21 11:21:04 -0700653 err = audio_extn_hfp_set_mic_mute2(adev, state);
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530654 } else if (adev->mode == AUDIO_MODE_IN_CALL) {
Arun Mirpurief53ce52018-09-11 18:00:09 -0700655 /* Use device mute if incall music delivery usecase is in progress */
656 if (adev->voice.use_device_mute)
657 err = platform_set_device_mute(adev->platform, state, "tx");
658 else
659 err = platform_set_mic_mute(adev->platform, state);
660 ALOGV("%s: voice mute status=%d, use_device_mute flag=%d",
661 __func__, state, adev->voice.use_device_mute);
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530662 } else if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800663 err = voice_extn_compress_voip_set_mic_mute(adev, state);
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530664 }
Arun Mirpurief53ce52018-09-11 18:00:09 -0700665
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700666 return err;
667}
668
669bool voice_get_mic_mute(struct audio_device *adev)
670{
671 return adev->voice.mic_mute;
672}
673
Arun Mirpurief53ce52018-09-11 18:00:09 -0700674/*
675 * Following function is called when incall music uplink usecase is
676 * created or destroyed while mic is muted. If incall music uplink
677 * usecase is active, apply voice device mute to mute only voice Tx
678 * path and not the mixed voice Tx + inncall-music path. Revert to
679 * voice stream mute once incall music uplink usecase is inactive
680 */
681void voice_set_device_mute_flag(struct audio_device *adev, bool state)
682{
683 if (adev->voice.mic_mute) {
684 if (state) {
685 platform_set_device_mute(adev->platform, true, "tx");
686 platform_set_mic_mute(adev->platform, false);
687 } else {
688 platform_set_mic_mute(adev->platform, true);
689 platform_set_device_mute(adev->platform, false, "tx");
690 }
691 }
692 adev->voice.use_device_mute = state;
693}
694
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700695int voice_set_volume(struct audio_device *adev, float volume)
696{
697 int vol, err = 0;
698
Shruthi Krishnaace10852013-10-25 14:32:12 -0700699 adev->voice.volume = volume;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700700 if (adev->mode == AUDIO_MODE_IN_CALL) {
701 if (volume < 0.0) {
702 volume = 0.0;
703 } else if (volume > 1.0) {
704 volume = 1.0;
705 }
706
707 vol = lrint(volume * 100.0);
708
709 // Voice volume levels from android are mapped to driver volume levels as follows.
710 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
711 // So adjust the volume to get the correct volume index in driver
712 vol = 100 - vol;
713
714 err = platform_set_voice_volume(adev->platform, vol);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700715 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800716 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
717 err = voice_extn_compress_voip_set_volume(adev, volume);
718
Shruthi Krishnaace10852013-10-25 14:32:12 -0700719
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700720 return err;
721}
722
723int voice_start_call(struct audio_device *adev)
724{
725 int ret = 0;
726
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -0700727 adev->voice.in_call = true;
Aalique Grahame22e49102018-12-18 14:23:57 -0800728
729 voice_set_mic_mute(adev, adev->voice.mic_mute);
730
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800731 ret = voice_extn_start_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700732 if (ret == -ENOSYS) {
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700733 ret = voice_start_usecase(adev, USECASE_VOICE_CALL);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700734 }
735
736 return ret;
737}
738
739int voice_stop_call(struct audio_device *adev)
740{
741 int ret = 0;
742
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700743 adev->voice.in_call = false;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800744 ret = voice_extn_stop_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700745 if (ret == -ENOSYS) {
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700746 ret = voice_stop_usecase(adev, USECASE_VOICE_CALL);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700747 }
748
749 return ret;
750}
751
Shiv Maliyappanahallif9308492013-12-12 12:18:09 -0800752void voice_get_parameters(struct audio_device *adev,
753 struct str_parms *query,
754 struct str_parms *reply)
755{
756 voice_extn_get_parameters(adev, query, reply);
757}
758
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700759int voice_set_parameters(struct audio_device *adev, struct str_parms *parms)
760{
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700761 char value[32];
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800762 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800763 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700764
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800765 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700766
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800767 ret = voice_extn_set_parameters(adev, parms);
Vidyakumar Athota8d931f02014-07-21 14:51:44 -0700768 if (ret != 0) {
769 if (ret == -ENOSYS)
770 ret = 0;
771 else
772 goto done;
773 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700774
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800775 ret = voice_extn_compress_voip_set_parameters(adev, parms);
Vidyakumar Athota8d931f02014-07-21 14:51:44 -0700776 if (ret != 0) {
777 if (ret == -ENOSYS)
778 ret = 0;
779 else
780 goto done;
781 }
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800782
783 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
784 if (err >= 0) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700785 int tty_mode;
786 str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE);
787 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
788 tty_mode = TTY_MODE_OFF;
789 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
790 tty_mode = TTY_MODE_VCO;
791 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
792 tty_mode = TTY_MODE_HCO;
793 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
794 tty_mode = TTY_MODE_FULL;
795 else {
796 ret = -EINVAL;
797 goto done;
798 }
799
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700800 if (tty_mode != adev->voice.tty_mode) {
801 adev->voice.tty_mode = tty_mode;
802 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700803 if (voice_is_call_state_active(adev))
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800804 voice_update_devices_for_all_voice_usecases(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700805 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700806 }
807
Aalique Grahame22e49102018-12-18 14:23:57 -0800808 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HAC,
809 value, sizeof(value));
810 if (err >= 0) {
811 bool hac = false;
812 str_parms_del(parms, AUDIO_PARAMETER_KEY_HAC);
813 if (strcmp(value, AUDIO_PARAMETER_VALUE_HAC_ON) == 0)
814 hac = true;
815
816 if (hac != adev->voice.hac) {
817 adev->voice.hac = hac;
818 if (voice_is_in_call(adev))
819 voice_update_devices_for_all_voice_usecases(adev);
820 }
821 }
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800822 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800823 value, sizeof(value));
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800824 if (err >= 0) {
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800825 str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC);
826 if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0)
827 platform_start_incall_music_usecase(adev->platform);
828 else
829 platform_stop_incall_music_usecase(adev->platform);
Vidyakumar Athota8d931f02014-07-21 14:51:44 -0700830 }
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800831
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700832done:
833 ALOGV("%s: exit with code(%d)", __func__, ret);
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800834 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700835 return ret;
836}
837
838void voice_init(struct audio_device *adev)
839{
840 int i = 0;
Weiyin Jiang095e4442019-07-15 11:49:15 +0800841 int max_voice_sessions = MAX_VOICE_SESSIONS;
842
843 if (!voice_extn_is_multi_session_supported())
844 max_voice_sessions = 1;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700845
846 memset(&adev->voice, 0, sizeof(adev->voice));
847 adev->voice.tty_mode = TTY_MODE_OFF;
Aalique Grahame22e49102018-12-18 14:23:57 -0800848 adev->voice.hac = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700849 adev->voice.volume = 1.0f;
850 adev->voice.mic_mute = false;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700851 adev->voice.in_call = false;
Weiyin Jiang095e4442019-07-15 11:49:15 +0800852 for (i = 0; i < max_voice_sessions; i++) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700853 adev->voice.session[i].pcm_rx = NULL;
854 adev->voice.session[i].pcm_tx = NULL;
855 adev->voice.session[i].state.current = CALL_INACTIVE;
856 adev->voice.session[i].state.new = CALL_INACTIVE;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700857 adev->voice.session[i].vsid = VOICE_VSID;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700858 }
859
860 voice_extn_init(adev);
861}
862
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800863void voice_update_devices_for_all_voice_usecases(struct audio_device *adev)
864{
865 struct listnode *node;
866 struct audio_usecase *usecase;
867
868 list_for_each(node, &adev->usecase_list) {
869 usecase = node_to_item(node, struct audio_usecase, list);
870 if (usecase->type == VOICE_CALL) {
871 ALOGV("%s: updating device for usecase:%s", __func__,
872 use_case_table[usecase->id]);
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700873 usecase->stream.out = adev->current_call_output;
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800874 select_devices(adev, usecase->id);
875 }
876 }
877}
878
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700879
Pallavi Mishra5627c162020-02-15 19:00:40 +0530880