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 | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 44 | extern const char * const use_case_table[AUDIO_USECASE_MAX]; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 45 | |
| 46 | static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev, |
| 47 | audio_usecase_t usecase_id) |
| 48 | { |
| 49 | struct voice_session *session = NULL; |
| 50 | int ret = 0; |
| 51 | |
| 52 | ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session); |
| 53 | if (ret == -ENOSYS) { |
| 54 | session = &adev->voice.session[VOICE_SESS_IDX]; |
| 55 | } |
| 56 | |
| 57 | return session; |
| 58 | } |
| 59 | |
| 60 | int stop_call(struct audio_device *adev, audio_usecase_t usecase_id) |
| 61 | { |
| 62 | int i, ret = 0; |
| 63 | struct audio_usecase *uc_info; |
| 64 | struct voice_session *session = NULL; |
| 65 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 66 | ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 67 | |
| 68 | session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id); |
Haynes Mathew George | bac2cba | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 69 | if (!session) { |
| 70 | ALOGE("stop_call: couldn't find voice session"); |
| 71 | return -EINVAL; |
| 72 | } |
| 73 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 74 | session->state.current = CALL_INACTIVE; |
| 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 | ea09892 | 2014-04-24 17:53:50 -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 | ea09892 | 2014-04-24 17:53:50 -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 | |
| 109 | int start_call(struct audio_device *adev, audio_usecase_t usecase_id) |
| 110 | { |
| 111 | int i, ret = 0; |
| 112 | struct audio_usecase *uc_info; |
| 113 | int pcm_dev_rx_id, pcm_dev_tx_id; |
| 114 | struct voice_session *session = NULL; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 115 | struct pcm_config voice_config = pcm_config_voice_call; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 116 | |
| 117 | ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 118 | |
| 119 | session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id); |
Haynes Mathew George | bac2cba | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 120 | if (!session) { |
| 121 | ALOGE("start_call: couldn't find voice session"); |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 125 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | bac2cba | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 126 | if (!uc_info) { |
| 127 | ALOGE("start_call: couldn't allocate mem for audio_usecase"); |
| 128 | return -ENOMEM; |
| 129 | } |
| 130 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 131 | uc_info->id = usecase_id; |
| 132 | uc_info->type = VOICE_CALL; |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 133 | uc_info->stream.out = adev->current_call_output; |
| 134 | uc_info->devices = adev->current_call_output->devices; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 135 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 136 | uc_info->out_snd_device = SND_DEVICE_NONE; |
| 137 | |
| 138 | list_add_tail(&adev->usecase_list, &uc_info->list); |
| 139 | |
| 140 | select_devices(adev, usecase_id); |
| 141 | |
| 142 | pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK); |
| 143 | pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE); |
| 144 | |
| 145 | if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) { |
| 146 | ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)", |
| 147 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id); |
| 148 | ret = -EIO; |
| 149 | goto error_start_voice; |
| 150 | } |
| 151 | |
| 152 | ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 153 | __func__, adev->snd_card, pcm_dev_rx_id); |
| 154 | session->pcm_rx = pcm_open(adev->snd_card, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 155 | pcm_dev_rx_id, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 156 | PCM_OUT, &voice_config); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 157 | if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) { |
| 158 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx)); |
| 159 | ret = -EIO; |
| 160 | goto error_start_voice; |
| 161 | } |
| 162 | |
| 163 | ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 164 | __func__, adev->snd_card, pcm_dev_tx_id); |
| 165 | session->pcm_tx = pcm_open(adev->snd_card, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 166 | pcm_dev_tx_id, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 167 | PCM_IN, &voice_config); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 168 | if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) { |
| 169 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx)); |
| 170 | ret = -EIO; |
| 171 | goto error_start_voice; |
| 172 | } |
| 173 | pcm_start(session->pcm_rx); |
| 174 | pcm_start(session->pcm_tx); |
| 175 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 176 | voice_set_volume(adev, adev->voice.volume); |
| 177 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 178 | ret = platform_start_voice_call(adev->platform, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 179 | if (ret < 0) { |
| 180 | ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret); |
| 181 | goto error_start_voice; |
| 182 | } |
| 183 | |
| 184 | session->state.current = CALL_ACTIVE; |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 185 | goto done; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 186 | |
| 187 | error_start_voice: |
| 188 | stop_call(adev, usecase_id); |
| 189 | |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 190 | done: |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 191 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 192 | return ret; |
| 193 | } |
| 194 | |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 195 | bool voice_is_call_state_active(struct audio_device *adev) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 196 | { |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 197 | bool call_state = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 198 | int ret = 0; |
| 199 | |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 200 | ret = voice_extn_is_call_state_active(adev, &call_state); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 201 | if (ret == -ENOSYS) { |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 202 | 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] | 203 | } |
| 204 | |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 205 | return call_state; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 206 | } |
| 207 | |
kunleiz | a1a9ee0 | 2014-04-24 18:46:22 +0800 | [diff] [blame] | 208 | bool voice_is_in_call_rec_stream(struct stream_in *in) |
| 209 | { |
| 210 | bool in_call_rec = false; |
| 211 | int ret = 0; |
| 212 | |
| 213 | ret = voice_extn_is_in_call_rec_stream(in, &in_call_rec); |
| 214 | if (ret == -ENOSYS) { |
| 215 | in_call_rec = false; |
| 216 | } |
| 217 | |
| 218 | return in_call_rec; |
| 219 | } |
| 220 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 221 | uint32_t voice_get_active_session_id(struct audio_device *adev) |
| 222 | { |
| 223 | int ret = 0; |
| 224 | uint32_t session_id; |
| 225 | |
| 226 | ret = voice_extn_get_active_session_id(adev, &session_id); |
| 227 | if (ret == -ENOSYS) { |
| 228 | session_id = VOICE_VSID; |
| 229 | } |
| 230 | return session_id; |
| 231 | } |
| 232 | |
| 233 | int voice_check_and_set_incall_rec_usecase(struct audio_device *adev, |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 234 | struct stream_in *in) |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 235 | { |
| 236 | int ret = 0; |
| 237 | uint32_t session_id; |
| 238 | int usecase_id; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 239 | int rec_mode = INCALL_REC_NONE; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 240 | |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 241 | if (voice_is_call_state_active(adev)) { |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 242 | switch (in->source) { |
| 243 | case AUDIO_SOURCE_VOICE_UPLINK: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 244 | if (audio_extn_compr_cap_enabled() && |
| 245 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 246 | in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS; |
| 247 | } else |
| 248 | in->usecase = USECASE_INCALL_REC_UPLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 249 | rec_mode = INCALL_REC_UPLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 250 | break; |
| 251 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 252 | if (audio_extn_compr_cap_enabled() && |
| 253 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 254 | in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS; |
| 255 | } else |
| 256 | in->usecase = USECASE_INCALL_REC_DOWNLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 257 | rec_mode = INCALL_REC_DOWNLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 258 | break; |
| 259 | case AUDIO_SOURCE_VOICE_CALL: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 260 | if (audio_extn_compr_cap_enabled() && |
| 261 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 262 | in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS; |
| 263 | } else |
| 264 | in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 265 | rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 266 | break; |
| 267 | default: |
| 268 | ALOGV("%s: Source type %d doesnt match incall recording criteria", |
| 269 | __func__, in->source); |
| 270 | return ret; |
| 271 | } |
| 272 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 273 | session_id = voice_get_active_session_id(adev); |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 274 | ret = platform_set_incall_recording_session_id(adev->platform, |
| 275 | session_id, rec_mode); |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 276 | ALOGV("%s: Update usecase to %d",__func__, in->usecase); |
| 277 | } else { |
Venkata Narendra Kumar Gutta | 5501ffa | 2015-03-30 19:16:14 +0530 | [diff] [blame] | 278 | /* |
| 279 | * Reject the recording instances, where the recording is started |
| 280 | * with In-call voice recording source types but voice call is not |
| 281 | * active by the time input is started |
| 282 | */ |
| 283 | if ((in->source == AUDIO_SOURCE_VOICE_UPLINK) || |
| 284 | (in->source == AUDIO_SOURCE_VOICE_DOWNLINK) || |
| 285 | (in->source == AUDIO_SOURCE_VOICE_CALL)) { |
| 286 | ret = -EINVAL; |
| 287 | ALOGE("%s: As voice call is not active, Incall rec usecase can't be \ |
| 288 | selected for requested source:%d",__func__, in->source); |
| 289 | } |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 290 | ALOGV("%s: voice call not active", __func__); |
| 291 | } |
| 292 | |
| 293 | return ret; |
| 294 | } |
| 295 | |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 296 | int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev, |
| 297 | struct stream_in *in) |
| 298 | { |
| 299 | int ret = 0; |
| 300 | |
| 301 | if (in->source == AUDIO_SOURCE_VOICE_UPLINK || |
| 302 | in->source == AUDIO_SOURCE_VOICE_DOWNLINK || |
| 303 | in->source == AUDIO_SOURCE_VOICE_CALL) { |
| 304 | ret = platform_stop_incall_recording_usecase(adev->platform); |
| 305 | ALOGV("%s: Stop In-call recording", __func__); |
| 306 | } |
| 307 | |
| 308 | return ret; |
| 309 | } |
| 310 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 311 | int voice_check_and_set_incall_music_usecase(struct audio_device *adev, |
| 312 | struct stream_out *out) |
| 313 | { |
| 314 | int ret = 0; |
| 315 | |
| 316 | ret = voice_extn_check_and_set_incall_music_usecase(adev, out); |
| 317 | if (ret == -ENOSYS) { |
| 318 | /* Incall music delivery is used only for LCH call state */ |
| 319 | ret = -EINVAL; |
| 320 | } |
| 321 | |
| 322 | return ret; |
| 323 | } |
| 324 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 325 | int voice_set_mic_mute(struct audio_device *adev, bool state) |
| 326 | { |
| 327 | int err = 0; |
| 328 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 329 | adev->voice.mic_mute = state; |
| 330 | if (adev->mode == AUDIO_MODE_IN_CALL) |
| 331 | err = platform_set_mic_mute(adev->platform, state); |
| 332 | if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) |
| 333 | err = voice_extn_compress_voip_set_mic_mute(adev, state); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 334 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 335 | return err; |
| 336 | } |
| 337 | |
| 338 | bool voice_get_mic_mute(struct audio_device *adev) |
| 339 | { |
| 340 | return adev->voice.mic_mute; |
| 341 | } |
| 342 | |
| 343 | int voice_set_volume(struct audio_device *adev, float volume) |
| 344 | { |
| 345 | int vol, err = 0; |
| 346 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 347 | adev->voice.volume = volume; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 348 | if (adev->mode == AUDIO_MODE_IN_CALL) { |
| 349 | if (volume < 0.0) { |
| 350 | volume = 0.0; |
| 351 | } else if (volume > 1.0) { |
| 352 | volume = 1.0; |
| 353 | } |
| 354 | |
| 355 | vol = lrint(volume * 100.0); |
| 356 | |
| 357 | // Voice volume levels from android are mapped to driver volume levels as follows. |
| 358 | // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0 |
| 359 | // So adjust the volume to get the correct volume index in driver |
| 360 | vol = 100 - vol; |
| 361 | |
| 362 | err = platform_set_voice_volume(adev->platform, vol); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 363 | } |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 364 | if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) |
| 365 | err = voice_extn_compress_voip_set_volume(adev, volume); |
| 366 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 367 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 368 | return err; |
| 369 | } |
| 370 | |
| 371 | int voice_start_call(struct audio_device *adev) |
| 372 | { |
| 373 | int ret = 0; |
| 374 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 375 | ret = voice_extn_start_call(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 376 | if (ret == -ENOSYS) { |
| 377 | ret = start_call(adev, USECASE_VOICE_CALL); |
| 378 | } |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 379 | adev->voice.in_call = true; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 380 | |
| 381 | return ret; |
| 382 | } |
| 383 | |
| 384 | int voice_stop_call(struct audio_device *adev) |
| 385 | { |
| 386 | int ret = 0; |
| 387 | |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 388 | adev->voice.in_call = false; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 389 | ret = voice_extn_stop_call(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 390 | if (ret == -ENOSYS) { |
| 391 | ret = stop_call(adev, USECASE_VOICE_CALL); |
| 392 | } |
| 393 | |
| 394 | return ret; |
| 395 | } |
| 396 | |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 397 | void voice_get_parameters(struct audio_device *adev, |
| 398 | struct str_parms *query, |
| 399 | struct str_parms *reply) |
| 400 | { |
| 401 | voice_extn_get_parameters(adev, query, reply); |
| 402 | } |
| 403 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 404 | int voice_set_parameters(struct audio_device *adev, struct str_parms *parms) |
| 405 | { |
| 406 | char *str; |
| 407 | char value[32]; |
| 408 | int val; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 409 | int ret = 0, err; |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 410 | char *kv_pairs = str_parms_to_str(parms); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 411 | |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 412 | ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 413 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 414 | ret = voice_extn_set_parameters(adev, parms); |
Vidyakumar Athota | 7992b8e | 2014-07-21 14:51:44 -0700 | [diff] [blame] | 415 | if (ret != 0) { |
| 416 | if (ret == -ENOSYS) |
| 417 | ret = 0; |
| 418 | else |
| 419 | goto done; |
| 420 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 421 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 422 | ret = voice_extn_compress_voip_set_parameters(adev, parms); |
Vidyakumar Athota | 7992b8e | 2014-07-21 14:51:44 -0700 | [diff] [blame] | 423 | if (ret != 0) { |
| 424 | if (ret == -ENOSYS) |
| 425 | ret = 0; |
| 426 | else |
| 427 | goto done; |
| 428 | } |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 429 | |
| 430 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value)); |
| 431 | if (err >= 0) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 432 | int tty_mode; |
| 433 | str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE); |
| 434 | if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0) |
| 435 | tty_mode = TTY_MODE_OFF; |
| 436 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0) |
| 437 | tty_mode = TTY_MODE_VCO; |
| 438 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0) |
| 439 | tty_mode = TTY_MODE_HCO; |
| 440 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0) |
| 441 | tty_mode = TTY_MODE_FULL; |
| 442 | else { |
| 443 | ret = -EINVAL; |
| 444 | goto done; |
| 445 | } |
| 446 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 447 | if (tty_mode != adev->voice.tty_mode) { |
| 448 | adev->voice.tty_mode = tty_mode; |
| 449 | adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode; |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 450 | if (voice_is_call_state_active(adev)) |
Narsinga Rao Chella | c9bf40d | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 451 | voice_update_devices_for_all_voice_usecases(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 452 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 455 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC, |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 456 | value, sizeof(value)); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 457 | if (err >= 0) { |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 458 | str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC); |
| 459 | if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0) |
| 460 | platform_start_incall_music_usecase(adev->platform); |
| 461 | else |
| 462 | platform_stop_incall_music_usecase(adev->platform); |
Vidyakumar Athota | 7992b8e | 2014-07-21 14:51:44 -0700 | [diff] [blame] | 463 | } |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 464 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 465 | done: |
| 466 | ALOGV("%s: exit with code(%d)", __func__, ret); |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 467 | free(kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 468 | return ret; |
| 469 | } |
| 470 | |
| 471 | void voice_init(struct audio_device *adev) |
| 472 | { |
| 473 | int i = 0; |
| 474 | |
| 475 | memset(&adev->voice, 0, sizeof(adev->voice)); |
| 476 | adev->voice.tty_mode = TTY_MODE_OFF; |
| 477 | adev->voice.volume = 1.0f; |
| 478 | adev->voice.mic_mute = false; |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 479 | adev->voice.in_call = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 480 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 481 | adev->voice.session[i].pcm_rx = NULL; |
| 482 | adev->voice.session[i].pcm_tx = NULL; |
| 483 | adev->voice.session[i].state.current = CALL_INACTIVE; |
| 484 | adev->voice.session[i].state.new = CALL_INACTIVE; |
Tony Layher | 209c7af | 2015-01-03 13:16:45 -0500 | [diff] [blame^] | 485 | #ifdef PLATFORM_APQ8084 |
| 486 | adev->voice.session[i].vsid = VOICE_VSID; |
| 487 | #else |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 488 | adev->voice.session[i].vsid = 0; |
Tony Layher | 209c7af | 2015-01-03 13:16:45 -0500 | [diff] [blame^] | 489 | #endif |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | voice_extn_init(adev); |
| 493 | } |
| 494 | |
Narsinga Rao Chella | c9bf40d | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 495 | void voice_update_devices_for_all_voice_usecases(struct audio_device *adev) |
| 496 | { |
| 497 | struct listnode *node; |
| 498 | struct audio_usecase *usecase; |
| 499 | |
| 500 | list_for_each(node, &adev->usecase_list) { |
| 501 | usecase = node_to_item(node, struct audio_usecase, list); |
| 502 | if (usecase->type == VOICE_CALL) { |
| 503 | ALOGV("%s: updating device for usecase:%s", __func__, |
| 504 | use_case_table[usecase->id]); |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 505 | usecase->stream.out = adev->current_call_output; |
Narsinga Rao Chella | c9bf40d | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 506 | select_devices(adev, usecase->id); |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 511 | |