Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1 | /* |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3 | * Not a contribution. |
| 4 | * |
Shiv Maliyappanahalli | 8911f28 | 2014-01-10 15:56:19 -0800 | [diff] [blame] | 5 | * Copyright (C) 2013 The Android Open Source Project |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 6 | * |
| 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 Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 34 | #include "audio_extn.h" |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 35 | |
| 36 | struct 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 Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 44 | static 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 Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 58 | int voice_stop_usecase(struct audio_device *adev, audio_usecase_t usecase_id) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 59 | { |
| 60 | int i, ret = 0; |
| 61 | struct audio_usecase *uc_info; |
| 62 | struct voice_session *session = NULL; |
| 63 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 64 | ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 65 | |
| 66 | session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 67 | if (!session) { |
| 68 | ALOGE("stop_call: couldn't find voice session"); |
| 69 | return -EINVAL; |
| 70 | } |
| 71 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 72 | session->state.current = CALL_INACTIVE; |
Venkata Narendra Kumar Gutta | 5f64eea | 2014-05-28 17:42:10 +0530 | [diff] [blame] | 73 | if (adev->mode == AUDIO_MODE_NORMAL) |
| 74 | adev->voice.is_in_call = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 75 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 76 | ret = platform_stop_voice_call(adev->platform, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 77 | |
| 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 George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 96 | disable_audio_route(adev, uc_info); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 97 | |
| 98 | /* 3. Disable the rx and tx devices */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 99 | disable_snd_device(adev, uc_info->out_snd_device); |
| 100 | disable_snd_device(adev, uc_info->in_snd_device); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 101 | |
| 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 Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 109 | int voice_start_usecase(struct audio_device *adev, audio_usecase_t usecase_id) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 110 | { |
| 111 | int i, ret = 0; |
| 112 | struct audio_usecase *uc_info; |
| 113 | int pcm_dev_rx_id, pcm_dev_tx_id; |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 114 | uint32_t sample_rate = 8000; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 115 | struct voice_session *session = NULL; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 116 | struct pcm_config voice_config = pcm_config_voice_call; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 117 | |
| 118 | ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 119 | |
| 120 | session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 121 | if (!session) { |
| 122 | ALOGE("start_call: couldn't find voice session"); |
| 123 | return -EINVAL; |
| 124 | } |
| 125 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 126 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 127 | if (!uc_info) { |
| 128 | ALOGE("start_call: couldn't allocate mem for audio_usecase"); |
| 129 | return -ENOMEM; |
| 130 | } |
| 131 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 132 | uc_info->id = usecase_id; |
| 133 | uc_info->type = VOICE_CALL; |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 134 | uc_info->stream.out = adev->current_call_output ; |
| 135 | uc_info->devices = adev->current_call_output ->devices; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 136 | 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 Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 152 | 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 Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 159 | |
Vidyakumar Athota | b000e0b | 2015-04-09 17:45:20 -0700 | [diff] [blame] | 160 | voice_set_mic_mute(adev, adev->voice.mic_mute); |
| 161 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 162 | ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 163 | __func__, adev->snd_card, pcm_dev_rx_id); |
| 164 | session->pcm_rx = pcm_open(adev->snd_card, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 165 | pcm_dev_rx_id, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 166 | PCM_OUT, &voice_config); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 167 | if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) { |
| 168 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx)); |
| 169 | ret = -EIO; |
| 170 | goto error_start_voice; |
| 171 | } |
| 172 | |
| 173 | ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 174 | __func__, adev->snd_card, pcm_dev_tx_id); |
| 175 | session->pcm_tx = pcm_open(adev->snd_card, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 176 | pcm_dev_tx_id, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 177 | PCM_IN, &voice_config); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 178 | if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) { |
| 179 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx)); |
| 180 | ret = -EIO; |
| 181 | goto error_start_voice; |
| 182 | } |
| 183 | pcm_start(session->pcm_rx); |
| 184 | pcm_start(session->pcm_tx); |
| 185 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 186 | voice_set_volume(adev, adev->voice.volume); |
| 187 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 188 | ret = platform_start_voice_call(adev->platform, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 189 | if (ret < 0) { |
| 190 | ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret); |
| 191 | goto error_start_voice; |
| 192 | } |
| 193 | |
| 194 | session->state.current = CALL_ACTIVE; |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 195 | goto done; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 196 | |
| 197 | error_start_voice: |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 198 | voice_stop_usecase(adev, usecase_id); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 199 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 200 | done: |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 201 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 202 | return ret; |
| 203 | } |
| 204 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 205 | bool voice_is_call_state_active(struct audio_device *adev) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 206 | { |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 207 | bool call_state = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 208 | int ret = 0; |
| 209 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 210 | ret = voice_extn_is_call_state_active(adev, &call_state); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 211 | if (ret == -ENOSYS) { |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 212 | call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 215 | return call_state; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 218 | bool voice_is_in_call(struct audio_device *adev) |
| 219 | { |
| 220 | return adev->voice.in_call; |
| 221 | } |
| 222 | |
kunleiz | c5a639b | 2014-04-24 18:46:22 +0800 | [diff] [blame] | 223 | bool voice_is_in_call_rec_stream(struct stream_in *in) |
| 224 | { |
| 225 | bool in_call_rec = false; |
kunleiz | c5a639b | 2014-04-24 18:46:22 +0800 | [diff] [blame] | 226 | |
Anish Kumar | 50ebcbf | 2014-12-09 04:01:39 +0530 | [diff] [blame] | 227 | if (!in) { |
| 228 | ALOGE("%s: input stream is NULL", __func__); |
| 229 | return in_call_rec; |
| 230 | } |
| 231 | |
Narsinga Rao Chella | d06b098 | 2014-11-20 16:59:57 -0800 | [diff] [blame] | 232 | if(in->source == AUDIO_SOURCE_VOICE_DOWNLINK || |
| 233 | in->source == AUDIO_SOURCE_VOICE_UPLINK || |
| 234 | in->source == AUDIO_SOURCE_VOICE_CALL) { |
| 235 | in_call_rec = true; |
kunleiz | c5a639b | 2014-04-24 18:46:22 +0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | return in_call_rec; |
| 239 | } |
| 240 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 241 | uint32_t voice_get_active_session_id(struct audio_device *adev) |
| 242 | { |
| 243 | int ret = 0; |
| 244 | uint32_t session_id; |
| 245 | |
| 246 | ret = voice_extn_get_active_session_id(adev, &session_id); |
| 247 | if (ret == -ENOSYS) { |
| 248 | session_id = VOICE_VSID; |
| 249 | } |
| 250 | return session_id; |
| 251 | } |
| 252 | |
| 253 | int voice_check_and_set_incall_rec_usecase(struct audio_device *adev, |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 254 | struct stream_in *in) |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 255 | { |
| 256 | int ret = 0; |
| 257 | uint32_t session_id; |
| 258 | int usecase_id; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 259 | int rec_mode = INCALL_REC_NONE; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 260 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 261 | if (voice_is_call_state_active(adev)) { |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 262 | switch (in->source) { |
| 263 | case AUDIO_SOURCE_VOICE_UPLINK: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 264 | if (audio_extn_compr_cap_enabled() && |
| 265 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 266 | in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS; |
| 267 | } else |
| 268 | in->usecase = USECASE_INCALL_REC_UPLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 269 | rec_mode = INCALL_REC_UPLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 270 | break; |
| 271 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 272 | if (audio_extn_compr_cap_enabled() && |
| 273 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 274 | in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS; |
| 275 | } else |
| 276 | in->usecase = USECASE_INCALL_REC_DOWNLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 277 | rec_mode = INCALL_REC_DOWNLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 278 | break; |
| 279 | case AUDIO_SOURCE_VOICE_CALL: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 280 | if (audio_extn_compr_cap_enabled() && |
| 281 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 282 | in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS; |
| 283 | } else |
| 284 | in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 285 | rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 286 | break; |
| 287 | default: |
| 288 | ALOGV("%s: Source type %d doesnt match incall recording criteria", |
| 289 | __func__, in->source); |
| 290 | return ret; |
| 291 | } |
| 292 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 293 | session_id = voice_get_active_session_id(adev); |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 294 | ret = platform_set_incall_recording_session_id(adev->platform, |
| 295 | session_id, rec_mode); |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 296 | ALOGV("%s: Update usecase to %d",__func__, in->usecase); |
| 297 | } else { |
Venkata Narendra Kumar Gutta | 76440ba | 2015-03-30 19:16:14 +0530 | [diff] [blame] | 298 | /* |
| 299 | * Reject the recording instances, where the recording is started |
| 300 | * with In-call voice recording source types but voice call is not |
| 301 | * active by the time input is started |
| 302 | */ |
| 303 | if ((in->source == AUDIO_SOURCE_VOICE_UPLINK) || |
| 304 | (in->source == AUDIO_SOURCE_VOICE_DOWNLINK) || |
| 305 | (in->source == AUDIO_SOURCE_VOICE_CALL)) { |
| 306 | ret = -EINVAL; |
| 307 | ALOGE("%s: As voice call is not active, Incall rec usecase can't be \ |
| 308 | selected for requested source:%d",__func__, in->source); |
| 309 | } |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 310 | ALOGV("%s: voice call not active", __func__); |
| 311 | } |
| 312 | |
| 313 | return ret; |
| 314 | } |
| 315 | |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 316 | int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev, |
| 317 | struct stream_in *in) |
| 318 | { |
| 319 | int ret = 0; |
| 320 | |
| 321 | if (in->source == AUDIO_SOURCE_VOICE_UPLINK || |
| 322 | in->source == AUDIO_SOURCE_VOICE_DOWNLINK || |
| 323 | in->source == AUDIO_SOURCE_VOICE_CALL) { |
| 324 | ret = platform_stop_incall_recording_usecase(adev->platform); |
| 325 | ALOGV("%s: Stop In-call recording", __func__); |
| 326 | } |
| 327 | |
| 328 | return ret; |
| 329 | } |
| 330 | |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 331 | snd_device_t voice_get_incall_rec_snd_device(snd_device_t in_snd_device) |
| 332 | { |
| 333 | snd_device_t incall_record_device = in_snd_device; |
| 334 | |
| 335 | /* |
| 336 | * For incall recording stream, AUDIO_COPP topology will be picked up |
| 337 | * from the calibration data of the input sound device which is nothing |
| 338 | * but the voice call's input device. But there are requirements to use |
| 339 | * AUDIO_COPP_MONO topology even if the voice call's input device is |
| 340 | * different. Hence override the input device with the one which uses |
| 341 | * the AUDIO_COPP_MONO topology. |
| 342 | */ |
| 343 | switch(in_snd_device) { |
| 344 | case SND_DEVICE_IN_HANDSET_MIC: |
| 345 | case SND_DEVICE_IN_VOICE_DMIC: |
| 346 | case SND_DEVICE_IN_AANC_HANDSET_MIC: |
| 347 | incall_record_device = SND_DEVICE_IN_HANDSET_MIC; |
Shiv Maliyappanahalli | 4d2d97c | 2015-02-19 14:29:01 -0800 | [diff] [blame] | 348 | break; |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 349 | case SND_DEVICE_IN_VOICE_SPEAKER_MIC: |
| 350 | case SND_DEVICE_IN_VOICE_SPEAKER_DMIC: |
| 351 | case SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE: |
| 352 | case SND_DEVICE_IN_VOICE_SPEAKER_QMIC: |
| 353 | incall_record_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
Shiv Maliyappanahalli | 4d2d97c | 2015-02-19 14:29:01 -0800 | [diff] [blame] | 354 | break; |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 355 | default: |
| 356 | incall_record_device = in_snd_device; |
| 357 | } |
| 358 | |
Shiv Maliyappanahalli | 4d2d97c | 2015-02-19 14:29:01 -0800 | [diff] [blame] | 359 | ALOGD("%s: in_snd_device(%d: %s) incall_record_device(%d: %s)", __func__, |
| 360 | in_snd_device, platform_get_snd_device_name(in_snd_device), |
| 361 | incall_record_device, platform_get_snd_device_name(incall_record_device)); |
| 362 | |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 363 | return incall_record_device; |
| 364 | } |
| 365 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 366 | int voice_check_and_set_incall_music_usecase(struct audio_device *adev, |
| 367 | struct stream_out *out) |
| 368 | { |
| 369 | int ret = 0; |
| 370 | |
| 371 | ret = voice_extn_check_and_set_incall_music_usecase(adev, out); |
| 372 | if (ret == -ENOSYS) { |
| 373 | /* Incall music delivery is used only for LCH call state */ |
| 374 | ret = -EINVAL; |
| 375 | } |
| 376 | |
| 377 | return ret; |
| 378 | } |
| 379 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 380 | int voice_set_mic_mute(struct audio_device *adev, bool state) |
| 381 | { |
| 382 | int err = 0; |
| 383 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 384 | adev->voice.mic_mute = state; |
| 385 | if (adev->mode == AUDIO_MODE_IN_CALL) |
| 386 | err = platform_set_mic_mute(adev->platform, state); |
| 387 | if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) |
| 388 | err = voice_extn_compress_voip_set_mic_mute(adev, state); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 389 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 390 | return err; |
| 391 | } |
| 392 | |
| 393 | bool voice_get_mic_mute(struct audio_device *adev) |
| 394 | { |
| 395 | return adev->voice.mic_mute; |
| 396 | } |
| 397 | |
| 398 | int voice_set_volume(struct audio_device *adev, float volume) |
| 399 | { |
| 400 | int vol, err = 0; |
| 401 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 402 | adev->voice.volume = volume; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 403 | if (adev->mode == AUDIO_MODE_IN_CALL) { |
| 404 | if (volume < 0.0) { |
| 405 | volume = 0.0; |
| 406 | } else if (volume > 1.0) { |
| 407 | volume = 1.0; |
| 408 | } |
| 409 | |
| 410 | vol = lrint(volume * 100.0); |
| 411 | |
| 412 | // Voice volume levels from android are mapped to driver volume levels as follows. |
| 413 | // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0 |
| 414 | // So adjust the volume to get the correct volume index in driver |
| 415 | vol = 100 - vol; |
| 416 | |
| 417 | err = platform_set_voice_volume(adev->platform, vol); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 418 | } |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 419 | if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) |
| 420 | err = voice_extn_compress_voip_set_volume(adev, volume); |
| 421 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 422 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 423 | return err; |
| 424 | } |
| 425 | |
| 426 | int voice_start_call(struct audio_device *adev) |
| 427 | { |
| 428 | int ret = 0; |
| 429 | |
Ravi Kumar Alamanda | be14939 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 430 | adev->voice.in_call = true; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 431 | ret = voice_extn_start_call(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 432 | if (ret == -ENOSYS) { |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 433 | ret = voice_start_usecase(adev, USECASE_VOICE_CALL); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | return ret; |
| 437 | } |
| 438 | |
| 439 | int voice_stop_call(struct audio_device *adev) |
| 440 | { |
| 441 | int ret = 0; |
| 442 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 443 | adev->voice.in_call = false; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 444 | ret = voice_extn_stop_call(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 445 | if (ret == -ENOSYS) { |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 446 | ret = voice_stop_usecase(adev, USECASE_VOICE_CALL); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | return ret; |
| 450 | } |
| 451 | |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 452 | void voice_get_parameters(struct audio_device *adev, |
| 453 | struct str_parms *query, |
| 454 | struct str_parms *reply) |
| 455 | { |
| 456 | voice_extn_get_parameters(adev, query, reply); |
| 457 | } |
| 458 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 459 | int voice_set_parameters(struct audio_device *adev, struct str_parms *parms) |
| 460 | { |
| 461 | char *str; |
| 462 | char value[32]; |
| 463 | int val; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 464 | int ret = 0, err; |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 465 | char *kv_pairs = str_parms_to_str(parms); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 466 | |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 467 | ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 468 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 469 | ret = voice_extn_set_parameters(adev, parms); |
Vidyakumar Athota | 8d931f0 | 2014-07-21 14:51:44 -0700 | [diff] [blame] | 470 | if (ret != 0) { |
| 471 | if (ret == -ENOSYS) |
| 472 | ret = 0; |
| 473 | else |
| 474 | goto done; |
| 475 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 476 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 477 | ret = voice_extn_compress_voip_set_parameters(adev, parms); |
Vidyakumar Athota | 8d931f0 | 2014-07-21 14:51:44 -0700 | [diff] [blame] | 478 | if (ret != 0) { |
| 479 | if (ret == -ENOSYS) |
| 480 | ret = 0; |
| 481 | else |
| 482 | goto done; |
| 483 | } |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 484 | |
| 485 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value)); |
| 486 | if (err >= 0) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 487 | int tty_mode; |
| 488 | str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE); |
| 489 | if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0) |
| 490 | tty_mode = TTY_MODE_OFF; |
| 491 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0) |
| 492 | tty_mode = TTY_MODE_VCO; |
| 493 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0) |
| 494 | tty_mode = TTY_MODE_HCO; |
| 495 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0) |
| 496 | tty_mode = TTY_MODE_FULL; |
| 497 | else { |
| 498 | ret = -EINVAL; |
| 499 | goto done; |
| 500 | } |
| 501 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 502 | if (tty_mode != adev->voice.tty_mode) { |
| 503 | adev->voice.tty_mode = tty_mode; |
| 504 | adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode; |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 505 | if (voice_is_call_state_active(adev)) |
Narsinga Rao Chella | 22d8d7a | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 506 | voice_update_devices_for_all_voice_usecases(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 507 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 510 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC, |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 511 | value, sizeof(value)); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 512 | if (err >= 0) { |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 513 | str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC); |
| 514 | if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0) |
| 515 | platform_start_incall_music_usecase(adev->platform); |
| 516 | else |
| 517 | platform_stop_incall_music_usecase(adev->platform); |
Vidyakumar Athota | 8d931f0 | 2014-07-21 14:51:44 -0700 | [diff] [blame] | 518 | } |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 519 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 520 | done: |
| 521 | ALOGV("%s: exit with code(%d)", __func__, ret); |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 522 | free(kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 523 | return ret; |
| 524 | } |
| 525 | |
| 526 | void voice_init(struct audio_device *adev) |
| 527 | { |
| 528 | int i = 0; |
| 529 | |
| 530 | memset(&adev->voice, 0, sizeof(adev->voice)); |
| 531 | adev->voice.tty_mode = TTY_MODE_OFF; |
| 532 | adev->voice.volume = 1.0f; |
| 533 | adev->voice.mic_mute = false; |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 534 | adev->voice.in_call = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 535 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 536 | adev->voice.session[i].pcm_rx = NULL; |
| 537 | adev->voice.session[i].pcm_tx = NULL; |
| 538 | adev->voice.session[i].state.current = CALL_INACTIVE; |
| 539 | adev->voice.session[i].state.new = CALL_INACTIVE; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 540 | adev->voice.session[i].vsid = VOICE_VSID; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | voice_extn_init(adev); |
| 544 | } |
| 545 | |
Narsinga Rao Chella | 22d8d7a | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 546 | void voice_update_devices_for_all_voice_usecases(struct audio_device *adev) |
| 547 | { |
| 548 | struct listnode *node; |
| 549 | struct audio_usecase *usecase; |
| 550 | |
| 551 | list_for_each(node, &adev->usecase_list) { |
| 552 | usecase = node_to_item(node, struct audio_usecase, list); |
| 553 | if (usecase->type == VOICE_CALL) { |
| 554 | ALOGV("%s: updating device for usecase:%s", __func__, |
| 555 | use_case_table[usecase->id]); |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 556 | usecase->stream.out = adev->current_call_output; |
Narsinga Rao Chella | 22d8d7a | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 557 | select_devices(adev, usecase->id); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 562 | |