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 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 20 | #define LOG_TAG "voice_extn" |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 21 | /*#define LOG_NDEBUG 0*/ |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 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 | #include <sys/ioctl.h> |
| 29 | #include <sound/voice_params.h> |
| 30 | |
| 31 | #include "audio_hw.h" |
| 32 | #include "voice.h" |
| 33 | #include "platform.h" |
| 34 | #include "platform_api.h" |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 35 | #include "voice_extn.h" |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 36 | |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 37 | #define AUDIO_PARAMETER_KEY_VSID "vsid" |
| 38 | #define AUDIO_PARAMETER_KEY_CALL_STATE "call_state" |
| 39 | #define AUDIO_PARAMETER_KEY_AUDIO_MODE "audio_mode" |
| 40 | #define AUDIO_PARAMETER_KEY_ALL_CALL_STATES "all_call_states" |
Shiv Maliyappanahalli | 575c155 | 2014-03-07 15:31:55 -0800 | [diff] [blame^] | 41 | #define AUDIO_PARAMETER_KEY_DEVICE_MUTE "device_mute" |
| 42 | #define AUDIO_PARAMETER_KEY_DIRECTION "direction" |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 43 | |
| 44 | #define VOICE_EXTN_PARAMETER_VALUE_MAX_LEN 256 |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 45 | |
| 46 | #define VOICE2_VSID 0x10DC1000 |
| 47 | #define VOLTE_VSID 0x10C02000 |
| 48 | #define QCHAT_VSID 0x10803000 |
Vicky Sehrawat | 111aeb3 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 49 | #define VOWLAN_VSID 0x10002000 |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 50 | #define ALL_VSID 0xFFFFFFFF |
| 51 | |
| 52 | /* Voice Session Indices */ |
| 53 | #define VOICE2_SESS_IDX (VOICE_SESS_IDX + 1) |
| 54 | #define VOLTE_SESS_IDX (VOICE_SESS_IDX + 2) |
| 55 | #define QCHAT_SESS_IDX (VOICE_SESS_IDX + 3) |
Vicky Sehrawat | 111aeb3 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 56 | #define VOWLAN_SESS_IDX (VOICE_SESS_IDX + 4) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 57 | |
| 58 | /* Call States */ |
| 59 | #define CALL_HOLD (BASE_CALL_STATE + 2) |
| 60 | #define CALL_LOCAL_HOLD (BASE_CALL_STATE + 3) |
| 61 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 62 | struct pcm_config pcm_config_incall_music = { |
| 63 | .channels = 1, |
| 64 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 65 | .period_size = LOW_LATENCY_OUTPUT_PERIOD_SIZE, |
| 66 | .period_count = LOW_LATENCY_OUTPUT_PERIOD_COUNT, |
| 67 | .format = PCM_FORMAT_S16_LE, |
| 68 | .start_threshold = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4, |
| 69 | .stop_threshold = INT_MAX, |
| 70 | .avail_min = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4, |
| 71 | }; |
| 72 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 73 | extern int start_call(struct audio_device *adev, audio_usecase_t usecase_id); |
| 74 | extern int stop_call(struct audio_device *adev, audio_usecase_t usecase_id); |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 75 | int voice_extn_is_in_call(struct audio_device *adev, bool *in_call); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 76 | |
| 77 | static bool is_valid_call_state(int call_state) |
| 78 | { |
| 79 | if (call_state < CALL_INACTIVE || call_state > CALL_LOCAL_HOLD) |
| 80 | return false; |
| 81 | else |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | static bool is_valid_vsid(uint32_t vsid) |
| 86 | { |
| 87 | if (vsid == VOICE_VSID || |
| 88 | vsid == VOICE2_VSID || |
| 89 | vsid == VOLTE_VSID || |
Vicky Sehrawat | 111aeb3 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 90 | vsid == QCHAT_VSID || |
| 91 | vsid == VOWLAN_VSID) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 92 | return true; |
| 93 | else |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | static audio_usecase_t voice_extn_get_usecase_for_session_idx(const int index) |
| 98 | { |
| 99 | audio_usecase_t usecase_id = -1; |
| 100 | |
| 101 | switch(index) { |
| 102 | case VOICE_SESS_IDX: |
| 103 | usecase_id = USECASE_VOICE_CALL; |
| 104 | break; |
| 105 | |
| 106 | case VOICE2_SESS_IDX: |
| 107 | usecase_id = USECASE_VOICE2_CALL; |
| 108 | break; |
| 109 | |
| 110 | case VOLTE_SESS_IDX: |
| 111 | usecase_id = USECASE_VOLTE_CALL; |
| 112 | break; |
| 113 | |
| 114 | case QCHAT_SESS_IDX: |
| 115 | usecase_id = USECASE_QCHAT_CALL; |
| 116 | break; |
| 117 | |
Vicky Sehrawat | 111aeb3 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 118 | case VOWLAN_SESS_IDX: |
| 119 | usecase_id = USECASE_VOWLAN_CALL; |
| 120 | break; |
| 121 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 122 | default: |
| 123 | ALOGE("%s: Invalid voice session index\n", __func__); |
| 124 | } |
| 125 | |
| 126 | return usecase_id; |
| 127 | } |
| 128 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 129 | static uint32_t get_session_id_with_state(struct audio_device *adev, |
| 130 | int call_state) |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 131 | { |
| 132 | struct voice_session *session = NULL; |
| 133 | int i = 0; |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 134 | uint32_t session_id = 0; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 135 | |
| 136 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 137 | session = &adev->voice.session[i]; |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 138 | if(session->state.current == call_state){ |
| 139 | session_id = session->vsid; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 144 | return session_id; |
| 145 | } |
| 146 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 147 | static int update_calls(struct audio_device *adev) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 148 | { |
| 149 | int i = 0; |
| 150 | audio_usecase_t usecase_id = 0; |
| 151 | enum voice_lch_mode lch_mode; |
| 152 | struct voice_session *session = NULL; |
| 153 | int fd = 0; |
| 154 | int ret = 0; |
Shiv Maliyappanahalli | 07a9ea2 | 2014-01-06 14:53:52 -0800 | [diff] [blame] | 155 | bool is_in_call = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 156 | |
| 157 | ALOGD("%s: enter:", __func__); |
| 158 | |
| 159 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 160 | usecase_id = voice_extn_get_usecase_for_session_idx(i); |
| 161 | session = &adev->voice.session[i]; |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 162 | ALOGD("%s: cur_state=%d new_state=%d vsid=%x", |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 163 | __func__, session->state.current, session->state.new, session->vsid); |
| 164 | |
| 165 | switch(session->state.new) |
| 166 | { |
| 167 | case CALL_ACTIVE: |
| 168 | switch(session->state.current) |
| 169 | { |
| 170 | case CALL_INACTIVE: |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 171 | ALOGD("%s: INACTIVE -> ACTIVE vsid:%x", __func__, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 172 | ret = start_call(adev, usecase_id); |
| 173 | if(ret < 0) { |
| 174 | ALOGE("%s: voice_start_call() failed for usecase: %d\n", |
| 175 | __func__, usecase_id); |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 176 | } else { |
| 177 | session->state.current = session->state.new; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 178 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 179 | break; |
| 180 | |
| 181 | case CALL_HOLD: |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 182 | ALOGD("%s: HOLD -> ACTIVE vsid:%x", __func__, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 183 | session->state.current = session->state.new; |
| 184 | break; |
| 185 | |
| 186 | case CALL_LOCAL_HOLD: |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 187 | ALOGD("%s: LOCAL_HOLD -> ACTIVE vsid:%x", __func__, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 188 | lch_mode = VOICE_LCH_STOP; |
| 189 | if (pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode) < 0) { |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 190 | ALOGE("LOCAL_HOLD -> ACTIVE failed"); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 191 | } else { |
| 192 | session->state.current = session->state.new; |
| 193 | } |
| 194 | break; |
| 195 | |
| 196 | default: |
| 197 | ALOGV("%s: CALL_ACTIVE cannot be handled in state=%d vsid:%x", |
| 198 | __func__, session->state.current, session->vsid); |
| 199 | break; |
| 200 | } |
| 201 | break; |
| 202 | |
| 203 | case CALL_INACTIVE: |
| 204 | switch(session->state.current) |
| 205 | { |
| 206 | case CALL_ACTIVE: |
| 207 | case CALL_HOLD: |
| 208 | case CALL_LOCAL_HOLD: |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 209 | ALOGD("%s: ACTIVE/HOLD/LOCAL_HOLD -> INACTIVE vsid:%x", __func__, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 210 | ret = stop_call(adev, usecase_id); |
| 211 | if(ret < 0) { |
| 212 | ALOGE("%s: voice_end_call() failed for usecase: %d\n", |
| 213 | __func__, usecase_id); |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 214 | } else { |
Shiv Maliyappanahalli | 07a9ea2 | 2014-01-06 14:53:52 -0800 | [diff] [blame] | 215 | voice_extn_is_in_call(adev, &is_in_call); |
| 216 | if (!is_in_call) { |
| 217 | adev->voice.voice_device_set = false; |
| 218 | } |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 219 | session->state.current = session->state.new; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 220 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 221 | break; |
| 222 | |
| 223 | default: |
| 224 | ALOGV("%s: CALL_INACTIVE cannot be handled in state=%d vsid:%x", |
| 225 | __func__, session->state.current, session->vsid); |
| 226 | break; |
| 227 | } |
| 228 | break; |
| 229 | |
| 230 | case CALL_HOLD: |
| 231 | switch(session->state.current) |
| 232 | { |
| 233 | case CALL_ACTIVE: |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 234 | ALOGD("%s: CALL_ACTIVE -> HOLD vsid:%x", __func__, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 235 | session->state.current = session->state.new; |
| 236 | break; |
| 237 | |
| 238 | case CALL_LOCAL_HOLD: |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 239 | ALOGD("%s: CALL_LOCAL_HOLD -> HOLD vsid:%x", __func__, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 240 | lch_mode = VOICE_LCH_STOP; |
| 241 | if (pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode) < 0) { |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 242 | ALOGE("LOCAL_HOLD -> HOLD failed"); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 243 | } else { |
| 244 | session->state.current = session->state.new; |
| 245 | } |
| 246 | break; |
| 247 | |
| 248 | default: |
| 249 | ALOGV("%s: CALL_HOLD cannot be handled in state=%d vsid:%x", |
| 250 | __func__, session->state.current, session->vsid); |
| 251 | break; |
| 252 | } |
| 253 | break; |
| 254 | |
| 255 | case CALL_LOCAL_HOLD: |
| 256 | switch(session->state.current) |
| 257 | { |
| 258 | case CALL_ACTIVE: |
| 259 | case CALL_HOLD: |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 260 | ALOGD("%s: ACTIVE/CALL_HOLD -> LOCAL_HOLD vsid:%x", __func__, |
| 261 | session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 262 | lch_mode = VOICE_LCH_START; |
| 263 | if (pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode) < 0) { |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 264 | ALOGE("LOCAL_HOLD -> HOLD failed"); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 265 | } else { |
| 266 | session->state.current = session->state.new; |
| 267 | } |
| 268 | break; |
| 269 | |
| 270 | default: |
| 271 | ALOGV("%s: CALL_LOCAL_HOLD cannot be handled in state=%d vsid:%x", |
| 272 | __func__, session->state.current, session->vsid); |
| 273 | break; |
| 274 | } |
| 275 | break; |
| 276 | |
| 277 | default: |
| 278 | break; |
| 279 | } //end out switch loop |
| 280 | } //end for loop |
| 281 | |
| 282 | return ret; |
| 283 | } |
| 284 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 285 | static int update_call_states(struct audio_device *adev, |
| 286 | const uint32_t vsid, const int call_state) |
| 287 | { |
| 288 | struct voice_session *session = NULL; |
| 289 | int i = 0; |
| 290 | bool is_in_call; |
Shiv Maliyappanahalli | 07a9ea2 | 2014-01-06 14:53:52 -0800 | [diff] [blame] | 291 | int no_of_calls_active = 0; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 292 | |
| 293 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 294 | if (vsid == adev->voice.session[i].vsid) { |
| 295 | session = &adev->voice.session[i]; |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | |
Shiv Maliyappanahalli | 07a9ea2 | 2014-01-06 14:53:52 -0800 | [diff] [blame] | 300 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 301 | if (CALL_INACTIVE != adev->voice.session[i].state.current) |
| 302 | no_of_calls_active++; |
| 303 | } |
| 304 | |
| 305 | /* When there is only one call active, wait for audio policy manager to set |
| 306 | * the mode to AUDIO_MODE_NORMAL and trigger routing to end the last call. |
| 307 | */ |
| 308 | if (no_of_calls_active == 1 && call_state == CALL_INACTIVE) |
| 309 | return 0; |
| 310 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 311 | if (session) { |
| 312 | session->state.new = call_state; |
| 313 | voice_extn_is_in_call(adev, &is_in_call); |
Shiv Maliyappanahalli | 07a9ea2 | 2014-01-06 14:53:52 -0800 | [diff] [blame] | 314 | ALOGD("%s is_in_call:%d voice_device_set:%d, mode:%d\n", |
| 315 | __func__, is_in_call, adev->voice.voice_device_set, adev->mode); |
Shiv Maliyappanahalli | 7a2545c | 2013-11-08 18:26:33 -0800 | [diff] [blame] | 316 | /* Dont start voice call before device routing for voice usescases has |
| 317 | * occured, otherwise voice calls will be started unintendedly on |
| 318 | * speaker. |
| 319 | */ |
Shiv Maliyappanahalli | 07a9ea2 | 2014-01-06 14:53:52 -0800 | [diff] [blame] | 320 | if (is_in_call || adev->voice.voice_device_set) { |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 321 | /* Device routing is not triggered for voice calls on the subsequent |
| 322 | * subs, Hence update the call states if voice call is already |
| 323 | * active on other sub. |
| 324 | */ |
| 325 | update_calls(adev); |
| 326 | } |
| 327 | } else { |
| 328 | return -EINVAL; |
| 329 | } |
| 330 | |
| 331 | return 0; |
| 332 | |
| 333 | } |
| 334 | |
| 335 | int voice_extn_get_active_session_id(struct audio_device *adev, |
| 336 | uint32_t *session_id) |
| 337 | { |
| 338 | *session_id = get_session_id_with_state(adev, CALL_ACTIVE); |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | int voice_extn_is_in_call(struct audio_device *adev, bool *in_call) |
| 343 | { |
| 344 | struct voice_session *session = NULL; |
| 345 | int i = 0; |
| 346 | *in_call = false; |
| 347 | |
| 348 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 349 | session = &adev->voice.session[i]; |
| 350 | if(session->state.current != CALL_INACTIVE){ |
| 351 | *in_call = true; |
| 352 | break; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | void voice_extn_init(struct audio_device *adev) |
| 360 | { |
| 361 | adev->voice.session[VOICE_SESS_IDX].vsid = VOICE_VSID; |
| 362 | adev->voice.session[VOICE2_SESS_IDX].vsid = VOICE2_VSID; |
| 363 | adev->voice.session[VOLTE_SESS_IDX].vsid = VOLTE_VSID; |
| 364 | adev->voice.session[QCHAT_SESS_IDX].vsid = QCHAT_VSID; |
Vicky Sehrawat | 111aeb3 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 365 | adev->voice.session[VOWLAN_SESS_IDX].vsid = VOWLAN_VSID; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | int voice_extn_get_session_from_use_case(struct audio_device *adev, |
| 369 | const audio_usecase_t usecase_id, |
| 370 | struct voice_session **session) |
| 371 | { |
| 372 | |
| 373 | switch(usecase_id) |
| 374 | { |
| 375 | case USECASE_VOICE_CALL: |
| 376 | *session = &adev->voice.session[VOICE_SESS_IDX]; |
| 377 | break; |
| 378 | |
| 379 | case USECASE_VOICE2_CALL: |
| 380 | *session = &adev->voice.session[VOICE2_SESS_IDX]; |
| 381 | break; |
| 382 | |
| 383 | case USECASE_VOLTE_CALL: |
| 384 | *session = &adev->voice.session[VOLTE_SESS_IDX]; |
| 385 | break; |
| 386 | |
| 387 | case USECASE_QCHAT_CALL: |
| 388 | *session = &adev->voice.session[QCHAT_SESS_IDX]; |
| 389 | break; |
| 390 | |
Vicky Sehrawat | 111aeb3 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 391 | case USECASE_VOWLAN_CALL: |
| 392 | *session = &adev->voice.session[VOWLAN_SESS_IDX]; |
| 393 | break; |
| 394 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 395 | default: |
| 396 | ALOGE("%s: Invalid usecase_id:%d\n", __func__, usecase_id); |
| 397 | *session = NULL; |
| 398 | return -EINVAL; |
| 399 | } |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | int voice_extn_start_call(struct audio_device *adev) |
| 405 | { |
| 406 | /* Start voice calls on sessions whose call state has been |
| 407 | * udpated. |
| 408 | */ |
| 409 | ALOGV("%s: enter:", __func__); |
Shiv Maliyappanahalli | 07a9ea2 | 2014-01-06 14:53:52 -0800 | [diff] [blame] | 410 | adev->voice.voice_device_set = true; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 411 | return update_calls(adev); |
| 412 | } |
| 413 | |
| 414 | int voice_extn_stop_call(struct audio_device *adev) |
| 415 | { |
| 416 | int i; |
| 417 | int ret = 0; |
| 418 | |
| 419 | ALOGV("%s: enter:", __func__); |
| 420 | |
| 421 | /* If BT device is enabled and voice calls are ended, telephony will call |
| 422 | * set_mode(AUDIO_MODE_NORMAL) which will trigger audio policy manager to |
| 423 | * set routing with device BT A2DP profile. Hence end all voice calls when |
| 424 | * set_mode(AUDIO_MODE_NORMAL) before BT A2DP profile is selected. |
| 425 | */ |
| 426 | if (adev->mode == AUDIO_MODE_NORMAL) { |
| 427 | ALOGD("%s: end all calls", __func__); |
| 428 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 429 | adev->voice.session[i].state.new = CALL_INACTIVE; |
| 430 | } |
| 431 | |
| 432 | ret = update_calls(adev); |
| 433 | } |
| 434 | |
| 435 | return ret; |
| 436 | } |
| 437 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 438 | int voice_extn_set_parameters(struct audio_device *adev, |
| 439 | struct str_parms *parms) |
| 440 | { |
| 441 | char *str; |
| 442 | int value; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 443 | int ret = 0, err; |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 444 | char *kv_pairs = str_parms_to_str(parms); |
Shiv Maliyappanahalli | 575c155 | 2014-03-07 15:31:55 -0800 | [diff] [blame^] | 445 | char str_value[256] = {0}; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 446 | |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 447 | ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 448 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 449 | err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_VSID, &value); |
| 450 | if (err >= 0) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 451 | str_parms_del(parms, AUDIO_PARAMETER_KEY_VSID); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 452 | uint32_t vsid = value; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 453 | int call_state = -1; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 454 | err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_CALL_STATE, &value); |
| 455 | if (err >= 0) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 456 | call_state = value; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 457 | } else { |
| 458 | ALOGE("%s: call_state key not found", __func__); |
| 459 | ret = -EINVAL; |
| 460 | goto done; |
| 461 | } |
| 462 | |
| 463 | if (is_valid_vsid(vsid) && is_valid_call_state(call_state)) { |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 464 | ret = update_call_states(adev, vsid, call_state); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 465 | } else { |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 466 | ALOGE("%s: invalid vsid:%x or call_state:%d", |
| 467 | __func__, vsid, call_state); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 468 | ret = -EINVAL; |
| 469 | goto done; |
| 470 | } |
Shiv Maliyappanahalli | 575c155 | 2014-03-07 15:31:55 -0800 | [diff] [blame^] | 471 | } |
| 472 | |
| 473 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_DEVICE_MUTE, str_value, |
| 474 | sizeof(str_value)); |
| 475 | if (err >= 0) { |
| 476 | str_parms_del(parms, AUDIO_PARAMETER_KEY_DEVICE_MUTE); |
| 477 | bool mute = false; |
| 478 | |
| 479 | if (!strncmp("true", str_value, sizeof("true"))) { |
| 480 | mute = true; |
| 481 | } |
| 482 | |
| 483 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_DIRECTION, str_value, |
| 484 | sizeof(str_value)); |
| 485 | if (err >= 0) { |
| 486 | str_parms_del(parms, AUDIO_PARAMETER_KEY_DIRECTION); |
| 487 | } else { |
| 488 | ALOGE("%s: direction key not found", __func__); |
| 489 | ret = -EINVAL; |
| 490 | goto done; |
| 491 | } |
| 492 | |
| 493 | ret = platform_set_device_mute(adev->platform, mute, str_value); |
| 494 | if (ret != 0) { |
| 495 | ALOGE("%s: Failed to set mute err:%d", __func__, ret); |
| 496 | ret = -EINVAL; |
| 497 | goto done; |
| 498 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | done: |
| 502 | ALOGV("%s: exit with code(%d)", __func__, ret); |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 503 | free(kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 504 | return ret; |
| 505 | } |
| 506 | |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 507 | int get_all_call_states_str(const struct audio_device *adev, |
| 508 | char *value) |
| 509 | { |
| 510 | int ret = 0; |
| 511 | char *cur_ptr = value; |
| 512 | int i, len=0; |
| 513 | |
| 514 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 515 | snprintf(cur_ptr, VOICE_EXTN_PARAMETER_VALUE_MAX_LEN - len, |
| 516 | "%d:%d,",adev->voice.session[i].vsid, |
| 517 | adev->voice.session[i].state.current); |
| 518 | len = strlen(cur_ptr); |
| 519 | cur_ptr = cur_ptr + len; |
| 520 | } |
| 521 | ALOGV("%s:value=%s", __func__, value); |
| 522 | return ret; |
| 523 | } |
| 524 | |
Narsinga Rao Chella | 1eceff8 | 2013-12-02 19:25:28 -0800 | [diff] [blame] | 525 | void voice_extn_get_parameters(const struct audio_device *adev, |
| 526 | struct str_parms *query, |
| 527 | struct str_parms *reply) |
| 528 | { |
| 529 | int ret; |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 530 | char value[VOICE_EXTN_PARAMETER_VALUE_MAX_LEN] = {0}; |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 531 | char *str = str_parms_to_str(query); |
Narsinga Rao Chella | 1eceff8 | 2013-12-02 19:25:28 -0800 | [diff] [blame] | 532 | |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 533 | ALOGV_IF(str != NULL, "%s: enter %s", __func__, str); |
| 534 | free(str); |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 535 | |
| 536 | ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_AUDIO_MODE, value, |
Narsinga Rao Chella | 1eceff8 | 2013-12-02 19:25:28 -0800 | [diff] [blame] | 537 | sizeof(value)); |
| 538 | if (ret >= 0) { |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 539 | str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUDIO_MODE, adev->mode); |
Narsinga Rao Chella | 1eceff8 | 2013-12-02 19:25:28 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 542 | ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_ALL_CALL_STATES, |
| 543 | value, sizeof(value)); |
| 544 | if (ret >= 0) { |
| 545 | ret = get_all_call_states_str(adev, value); |
| 546 | if (ret) { |
| 547 | ALOGE("%s: Error fetching call states, err:%d", __func__, ret); |
| 548 | return; |
| 549 | } |
| 550 | str_parms_add_str(reply, AUDIO_PARAMETER_KEY_ALL_CALL_STATES, value); |
| 551 | } |
Narsinga Rao Chella | 707e751 | 2014-01-10 10:18:13 -0800 | [diff] [blame] | 552 | voice_extn_compress_voip_get_parameters(adev, query, reply); |
| 553 | |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 554 | str = str_parms_to_str(reply); |
| 555 | ALOGV_IF(str != NULL, "%s: exit: returns \"%s\"", __func__, str); |
| 556 | free(str); |
Narsinga Rao Chella | 1eceff8 | 2013-12-02 19:25:28 -0800 | [diff] [blame] | 557 | } |
| 558 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 559 | void voice_extn_out_get_parameters(struct stream_out *out, |
| 560 | struct str_parms *query, |
| 561 | struct str_parms *reply) |
| 562 | { |
| 563 | voice_extn_compress_voip_out_get_parameters(out, query, reply); |
| 564 | } |
| 565 | |
| 566 | void voice_extn_in_get_parameters(struct stream_in *in, |
| 567 | struct str_parms *query, |
| 568 | struct str_parms *reply) |
| 569 | { |
| 570 | voice_extn_compress_voip_in_get_parameters(in, query, reply); |
| 571 | } |
| 572 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 573 | int voice_extn_check_and_set_incall_music_usecase(struct audio_device *adev, |
| 574 | struct stream_out *out) |
| 575 | { |
| 576 | uint32_t session_id = 0; |
| 577 | |
| 578 | session_id = get_session_id_with_state(adev, CALL_LOCAL_HOLD); |
| 579 | if (session_id == VOICE_VSID) { |
| 580 | out->usecase = USECASE_INCALL_MUSIC_UPLINK; |
| 581 | } else if (session_id == VOICE2_VSID) { |
| 582 | out->usecase = USECASE_INCALL_MUSIC_UPLINK2; |
| 583 | } else { |
| 584 | ALOGE("%s: Invalid session id %x", __func__, session_id); |
| 585 | return -EINVAL; |
| 586 | } |
| 587 | |
| 588 | out->config = pcm_config_incall_music; |
| 589 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_MONO; |
| 590 | out->channel_mask = AUDIO_CHANNEL_OUT_MONO; |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |