blob: cf5ec657e2a71d1ed27cc0b00072f766596c1857 [file] [log] [blame]
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001/*
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003 * Not a contribution.
4 *
Shiv Maliyappanahalli8911f282014-01-10 15:56:19 -08005 * Copyright (C) 2013 The Android Open Source Project
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#define LOG_TAG "voice"
21/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <errno.h>
25#include <math.h>
26#include <cutils/log.h>
27#include <cutils/str_parms.h>
28
29#include "audio_hw.h"
30#include "voice.h"
31#include "voice_extn/voice_extn.h"
32#include "platform.h"
33#include "platform_api.h"
Kiran Kandi910e1862013-10-29 13:29:42 -070034#include "audio_extn.h"
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070035
36struct pcm_config pcm_config_voice_call = {
37 .channels = 1,
38 .rate = 8000,
39 .period_size = 160,
40 .period_count = 2,
41 .format = PCM_FORMAT_S16_LE,
42};
43
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070044static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev,
45 audio_usecase_t usecase_id)
46{
47 struct voice_session *session = NULL;
48 int ret = 0;
49
50 ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session);
51 if (ret == -ENOSYS) {
52 session = &adev->voice.session[VOICE_SESS_IDX];
53 }
54
55 return session;
56}
57
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -070058int voice_stop_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070059{
60 int i, ret = 0;
61 struct audio_usecase *uc_info;
62 struct voice_session *session = NULL;
63
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -080064 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070065
66 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -070067 if (!session) {
68 ALOGE("stop_call: couldn't find voice session");
69 return -EINVAL;
70 }
71
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070072 session->state.current = CALL_INACTIVE;
Venkata Narendra Kumar Gutta5f64eea2014-05-28 17:42:10 +053073 if (adev->mode == AUDIO_MODE_NORMAL)
74 adev->voice.is_in_call = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070075
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -080076 ret = platform_stop_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070077
78 /* 1. Close the PCM devices */
79 if (session->pcm_rx) {
80 pcm_close(session->pcm_rx);
81 session->pcm_rx = NULL;
82 }
83 if (session->pcm_tx) {
84 pcm_close(session->pcm_tx);
85 session->pcm_tx = NULL;
86 }
87
88 uc_info = get_usecase_from_list(adev, usecase_id);
89 if (uc_info == NULL) {
90 ALOGE("%s: Could not find the usecase (%d) in the list",
91 __func__, usecase_id);
92 return -EINVAL;
93 }
94
95 /* 2. Get and set stream specific mixer controls */
Haynes Mathew George1376ca62014-04-24 11:55:48 -070096 disable_audio_route(adev, uc_info);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070097
98 /* 3. Disable the rx and tx devices */
Haynes Mathew George1376ca62014-04-24 11:55:48 -070099 disable_snd_device(adev, uc_info->out_snd_device);
100 disable_snd_device(adev, uc_info->in_snd_device);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700101
102 list_remove(&uc_info->list);
103 free(uc_info);
104
105 ALOGD("%s: exit: status(%d)", __func__, ret);
106 return ret;
107}
108
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700109int voice_start_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700110{
111 int i, ret = 0;
112 struct audio_usecase *uc_info;
113 int pcm_dev_rx_id, pcm_dev_tx_id;
Helen Zeng6a16ad72014-02-23 22:04:44 -0800114 uint32_t sample_rate = 8000;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700115 struct voice_session *session = NULL;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700116 struct pcm_config voice_config = pcm_config_voice_call;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800117
118 ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700119
120 session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700121 if (!session) {
122 ALOGE("start_call: couldn't find voice session");
123 return -EINVAL;
124 }
125
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700126 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700127 if (!uc_info) {
128 ALOGE("start_call: couldn't allocate mem for audio_usecase");
129 return -ENOMEM;
130 }
131
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700132 uc_info->id = usecase_id;
133 uc_info->type = VOICE_CALL;
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700134 uc_info->stream.out = adev->current_call_output ;
135 uc_info->devices = adev->current_call_output ->devices;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700136 uc_info->in_snd_device = SND_DEVICE_NONE;
137 uc_info->out_snd_device = SND_DEVICE_NONE;
138
139 list_add_tail(&adev->usecase_list, &uc_info->list);
140
141 select_devices(adev, usecase_id);
142
143 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
144 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
145
146 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
147 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
148 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
149 ret = -EIO;
150 goto error_start_voice;
151 }
Helen Zeng6a16ad72014-02-23 22:04:44 -0800152 ret = platform_get_sample_rate(adev->platform, &sample_rate);
153 if (ret < 0) {
154 ALOGE("platform_get_sample_rate error %d\n", ret);
155 } else {
156 voice_config.rate = sample_rate;
157 }
158 ALOGD("voice_config.rate %d\n", voice_config.rate);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700159
160 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800161 __func__, adev->snd_card, pcm_dev_rx_id);
162 session->pcm_rx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700163 pcm_dev_rx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700164 PCM_OUT, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700165 if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) {
166 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
167 ret = -EIO;
168 goto error_start_voice;
169 }
170
171 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800172 __func__, adev->snd_card, pcm_dev_tx_id);
173 session->pcm_tx = pcm_open(adev->snd_card,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700174 pcm_dev_tx_id,
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700175 PCM_IN, &voice_config);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700176 if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) {
177 ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
178 ret = -EIO;
179 goto error_start_voice;
180 }
181 pcm_start(session->pcm_rx);
182 pcm_start(session->pcm_tx);
183
Shruthi Krishnaace10852013-10-25 14:32:12 -0700184 voice_set_volume(adev, adev->voice.volume);
185
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800186 ret = platform_start_voice_call(adev->platform, session->vsid);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700187 if (ret < 0) {
188 ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
189 goto error_start_voice;
190 }
191
192 session->state.current = CALL_ACTIVE;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700193 goto done;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700194
195error_start_voice:
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700196 voice_stop_usecase(adev, usecase_id);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700197
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700198done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700199 ALOGD("%s: exit: status(%d)", __func__, ret);
200 return ret;
201}
202
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700203bool voice_is_call_state_active(struct audio_device *adev)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700204{
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700205 bool call_state = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700206 int ret = 0;
207
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700208 ret = voice_extn_is_call_state_active(adev, &call_state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700209 if (ret == -ENOSYS) {
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700210 call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700211 }
212
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700213 return call_state;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700214}
215
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700216bool voice_is_in_call(struct audio_device *adev)
217{
218 return adev->voice.in_call;
219}
220
kunleizc5a639b2014-04-24 18:46:22 +0800221bool voice_is_in_call_rec_stream(struct stream_in *in)
222{
223 bool in_call_rec = false;
kunleizc5a639b2014-04-24 18:46:22 +0800224
Narsinga Rao Chellad06b0982014-11-20 16:59:57 -0800225 if(in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
226 in->source == AUDIO_SOURCE_VOICE_UPLINK ||
227 in->source == AUDIO_SOURCE_VOICE_CALL) {
228 in_call_rec = true;
kunleizc5a639b2014-04-24 18:46:22 +0800229 }
230
231 return in_call_rec;
232}
233
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700234uint32_t voice_get_active_session_id(struct audio_device *adev)
235{
236 int ret = 0;
237 uint32_t session_id;
238
239 ret = voice_extn_get_active_session_id(adev, &session_id);
240 if (ret == -ENOSYS) {
241 session_id = VOICE_VSID;
242 }
243 return session_id;
244}
245
246int voice_check_and_set_incall_rec_usecase(struct audio_device *adev,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800247 struct stream_in *in)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700248{
249 int ret = 0;
250 uint32_t session_id;
251 int usecase_id;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800252 int rec_mode = INCALL_REC_NONE;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700253
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700254 if (voice_is_call_state_active(adev)) {
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700255 switch (in->source) {
256 case AUDIO_SOURCE_VOICE_UPLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800257 if (audio_extn_compr_cap_enabled() &&
258 audio_extn_compr_cap_format_supported(in->config.format)) {
259 in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS;
260 } else
261 in->usecase = USECASE_INCALL_REC_UPLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800262 rec_mode = INCALL_REC_UPLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700263 break;
264 case AUDIO_SOURCE_VOICE_DOWNLINK:
Helen Zenge56b4852013-12-03 16:54:40 -0800265 if (audio_extn_compr_cap_enabled() &&
266 audio_extn_compr_cap_format_supported(in->config.format)) {
267 in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS;
268 } else
269 in->usecase = USECASE_INCALL_REC_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800270 rec_mode = INCALL_REC_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700271 break;
272 case AUDIO_SOURCE_VOICE_CALL:
Helen Zenge56b4852013-12-03 16:54:40 -0800273 if (audio_extn_compr_cap_enabled() &&
274 audio_extn_compr_cap_format_supported(in->config.format)) {
275 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS;
276 } else
277 in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK;
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800278 rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK;
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700279 break;
280 default:
281 ALOGV("%s: Source type %d doesnt match incall recording criteria",
282 __func__, in->source);
283 return ret;
284 }
285
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700286 session_id = voice_get_active_session_id(adev);
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800287 ret = platform_set_incall_recording_session_id(adev->platform,
288 session_id, rec_mode);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700289 ALOGV("%s: Update usecase to %d",__func__, in->usecase);
290 } else {
291 ALOGV("%s: voice call not active", __func__);
292 }
293
294 return ret;
295}
296
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800297int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev,
298 struct stream_in *in)
299{
300 int ret = 0;
301
302 if (in->source == AUDIO_SOURCE_VOICE_UPLINK ||
303 in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
304 in->source == AUDIO_SOURCE_VOICE_CALL) {
305 ret = platform_stop_incall_recording_usecase(adev->platform);
306 ALOGV("%s: Stop In-call recording", __func__);
307 }
308
309 return ret;
310}
311
Narsinga Rao Chella212e2542014-11-17 19:57:04 -0800312snd_device_t voice_get_incall_rec_snd_device(snd_device_t in_snd_device)
313{
314 snd_device_t incall_record_device = in_snd_device;
315
316 /*
317 * For incall recording stream, AUDIO_COPP topology will be picked up
318 * from the calibration data of the input sound device which is nothing
319 * but the voice call's input device. But there are requirements to use
320 * AUDIO_COPP_MONO topology even if the voice call's input device is
321 * different. Hence override the input device with the one which uses
322 * the AUDIO_COPP_MONO topology.
323 */
324 switch(in_snd_device) {
325 case SND_DEVICE_IN_HANDSET_MIC:
326 case SND_DEVICE_IN_VOICE_DMIC:
327 case SND_DEVICE_IN_AANC_HANDSET_MIC:
328 incall_record_device = SND_DEVICE_IN_HANDSET_MIC;
329 case SND_DEVICE_IN_VOICE_SPEAKER_MIC:
330 case SND_DEVICE_IN_VOICE_SPEAKER_DMIC:
331 case SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE:
332 case SND_DEVICE_IN_VOICE_SPEAKER_QMIC:
333 incall_record_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
334 default:
335 incall_record_device = in_snd_device;
336 }
337
338 return incall_record_device;
339}
340
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700341int voice_check_and_set_incall_music_usecase(struct audio_device *adev,
342 struct stream_out *out)
343{
344 int ret = 0;
345
346 ret = voice_extn_check_and_set_incall_music_usecase(adev, out);
347 if (ret == -ENOSYS) {
348 /* Incall music delivery is used only for LCH call state */
349 ret = -EINVAL;
350 }
351
352 return ret;
353}
354
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700355int voice_set_mic_mute(struct audio_device *adev, bool state)
356{
357 int err = 0;
358
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800359 adev->voice.mic_mute = state;
360 if (adev->mode == AUDIO_MODE_IN_CALL)
361 err = platform_set_mic_mute(adev->platform, state);
362 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
363 err = voice_extn_compress_voip_set_mic_mute(adev, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700364
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700365 return err;
366}
367
368bool voice_get_mic_mute(struct audio_device *adev)
369{
370 return adev->voice.mic_mute;
371}
372
373int voice_set_volume(struct audio_device *adev, float volume)
374{
375 int vol, err = 0;
376
Shruthi Krishnaace10852013-10-25 14:32:12 -0700377 adev->voice.volume = volume;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700378 if (adev->mode == AUDIO_MODE_IN_CALL) {
379 if (volume < 0.0) {
380 volume = 0.0;
381 } else if (volume > 1.0) {
382 volume = 1.0;
383 }
384
385 vol = lrint(volume * 100.0);
386
387 // Voice volume levels from android are mapped to driver volume levels as follows.
388 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
389 // So adjust the volume to get the correct volume index in driver
390 vol = 100 - vol;
391
392 err = platform_set_voice_volume(adev->platform, vol);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700393 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800394 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
395 err = voice_extn_compress_voip_set_volume(adev, volume);
396
Shruthi Krishnaace10852013-10-25 14:32:12 -0700397
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700398 return err;
399}
400
401int voice_start_call(struct audio_device *adev)
402{
403 int ret = 0;
404
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -0700405 adev->voice.in_call = true;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800406 ret = voice_extn_start_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700407 if (ret == -ENOSYS) {
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700408 ret = voice_start_usecase(adev, USECASE_VOICE_CALL);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700409 }
410
411 return ret;
412}
413
414int voice_stop_call(struct audio_device *adev)
415{
416 int ret = 0;
417
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700418 adev->voice.in_call = false;
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800419 ret = voice_extn_stop_call(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700420 if (ret == -ENOSYS) {
Ravi Kumar Alamanda263d80c2014-08-20 16:24:38 -0700421 ret = voice_stop_usecase(adev, USECASE_VOICE_CALL);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700422 }
423
424 return ret;
425}
426
Shiv Maliyappanahallif9308492013-12-12 12:18:09 -0800427void voice_get_parameters(struct audio_device *adev,
428 struct str_parms *query,
429 struct str_parms *reply)
430{
431 voice_extn_get_parameters(adev, query, reply);
432}
433
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700434int voice_set_parameters(struct audio_device *adev, struct str_parms *parms)
435{
436 char *str;
437 char value[32];
438 int val;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800439 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800440 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700441
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800442 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700443
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800444 ret = voice_extn_set_parameters(adev, parms);
Vidyakumar Athota8d931f02014-07-21 14:51:44 -0700445 if (ret != 0) {
446 if (ret == -ENOSYS)
447 ret = 0;
448 else
449 goto done;
450 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700451
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800452 ret = voice_extn_compress_voip_set_parameters(adev, parms);
Vidyakumar Athota8d931f02014-07-21 14:51:44 -0700453 if (ret != 0) {
454 if (ret == -ENOSYS)
455 ret = 0;
456 else
457 goto done;
458 }
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800459
460 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
461 if (err >= 0) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700462 int tty_mode;
463 str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE);
464 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
465 tty_mode = TTY_MODE_OFF;
466 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
467 tty_mode = TTY_MODE_VCO;
468 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
469 tty_mode = TTY_MODE_HCO;
470 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
471 tty_mode = TTY_MODE_FULL;
472 else {
473 ret = -EINVAL;
474 goto done;
475 }
476
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700477 if (tty_mode != adev->voice.tty_mode) {
478 adev->voice.tty_mode = tty_mode;
479 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700480 if (voice_is_call_state_active(adev))
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800481 voice_update_devices_for_all_voice_usecases(adev);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700482 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700483 }
484
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800485 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC,
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800486 value, sizeof(value));
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -0800487 if (err >= 0) {
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800488 str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC);
489 if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0)
490 platform_start_incall_music_usecase(adev->platform);
491 else
492 platform_stop_incall_music_usecase(adev->platform);
Vidyakumar Athota8d931f02014-07-21 14:51:44 -0700493 }
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800494
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700495done:
496 ALOGV("%s: exit with code(%d)", __func__, ret);
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -0800497 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700498 return ret;
499}
500
501void voice_init(struct audio_device *adev)
502{
503 int i = 0;
504
505 memset(&adev->voice, 0, sizeof(adev->voice));
506 adev->voice.tty_mode = TTY_MODE_OFF;
507 adev->voice.volume = 1.0f;
508 adev->voice.mic_mute = false;
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700509 adev->voice.in_call = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700510 for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
511 adev->voice.session[i].pcm_rx = NULL;
512 adev->voice.session[i].pcm_tx = NULL;
513 adev->voice.session[i].state.current = CALL_INACTIVE;
514 adev->voice.session[i].state.new = CALL_INACTIVE;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700515 adev->voice.session[i].vsid = VOICE_VSID;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700516 }
517
518 voice_extn_init(adev);
519}
520
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800521void voice_update_devices_for_all_voice_usecases(struct audio_device *adev)
522{
523 struct listnode *node;
524 struct audio_usecase *usecase;
525
526 list_for_each(node, &adev->usecase_list) {
527 usecase = node_to_item(node, struct audio_usecase, list);
528 if (usecase->type == VOICE_CALL) {
529 ALOGV("%s: updating device for usecase:%s", __func__,
530 use_case_table[usecase->id]);
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700531 usecase->stream.out = adev->current_call_output;
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -0800532 select_devices(adev, usecase->id);
533 }
534 }
535}
536
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700537