Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1 | /* alsa_default.cpp |
| 2 | ** |
| 3 | ** Copyright 2009 Wind River Systems |
| 4 | ** Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
| 5 | ** |
| 6 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | ** you may not use this file except in compliance with the License. |
| 8 | ** You may obtain a copy of the License at |
| 9 | ** |
| 10 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | ** |
| 12 | ** Unless required by applicable law or agreed to in writing, software |
| 13 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | ** See the License for the specific language governing permissions and |
| 16 | ** limitations under the License. |
| 17 | */ |
| 18 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 19 | #define LOG_TAG "ALSAModule" |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 20 | //#define LOG_NDEBUG 0 |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 21 | #define LOG_NDDEBUG 0 |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 22 | #include <utils/Log.h> |
| 23 | #include <cutils/properties.h> |
| 24 | #include <linux/ioctl.h> |
| 25 | #include "AudioHardwareALSA.h" |
| 26 | #include <media/AudioRecord.h> |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 27 | #include <dlfcn.h> |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 28 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 29 | extern "C" { |
| 30 | #include "csd_client.h" |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 31 | static int (*csd_disable_device)(); |
| 32 | static int (*csd_enable_device)(int, int, uint32_t); |
| 33 | static int (*csd_volume)(int); |
| 34 | static int (*csd_mic_mute)(int); |
| 35 | static int (*csd_wide_voice)(uint8_t); |
| 36 | static int (*csd_slow_talk)(uint8_t); |
| 37 | static int (*csd_fens)(uint8_t); |
| 38 | static int (*csd_start_voice)(); |
| 39 | static int (*csd_stop_voice)(); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 40 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 41 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 42 | |
| 43 | #ifndef ALSA_DEFAULT_SAMPLE_RATE |
| 44 | #define ALSA_DEFAULT_SAMPLE_RATE 44100 // in Hz |
| 45 | #endif |
| 46 | |
| 47 | #define BTSCO_RATE_16KHZ 16000 |
| 48 | #define USECASE_TYPE_RX 1 |
| 49 | #define USECASE_TYPE_TX 2 |
| 50 | |
| 51 | namespace android_audio_legacy |
| 52 | { |
| 53 | |
| 54 | static int s_device_open(const hw_module_t*, const char*, hw_device_t**); |
| 55 | static int s_device_close(hw_device_t*); |
| 56 | static status_t s_init(alsa_device_t *, ALSAHandleList &); |
| 57 | static status_t s_open(alsa_handle_t *); |
| 58 | static status_t s_close(alsa_handle_t *); |
| 59 | static status_t s_standby(alsa_handle_t *); |
| 60 | static status_t s_route(alsa_handle_t *, uint32_t, int); |
| 61 | static status_t s_start_voice_call(alsa_handle_t *); |
| 62 | static status_t s_start_voip_call(alsa_handle_t *); |
| 63 | static status_t s_start_fm(alsa_handle_t *); |
| 64 | static void s_set_voice_volume(int); |
| 65 | static void s_set_voip_volume(int); |
| 66 | static void s_set_mic_mute(int); |
| 67 | static void s_set_voip_mic_mute(int); |
| 68 | static void s_set_voip_config(int, int); |
| 69 | static status_t s_set_fm_vol(int); |
| 70 | static void s_set_btsco_rate(int); |
| 71 | static status_t s_set_lpa_vol(int); |
| 72 | static void s_enable_wide_voice(bool flag); |
| 73 | static void s_enable_fens(bool flag); |
| 74 | static void s_set_flags(uint32_t flags); |
| 75 | static status_t s_set_compressed_vol(int); |
| 76 | static void s_enable_slow_talk(bool flag); |
| 77 | static void s_set_voc_rec_mode(uint8_t mode); |
| 78 | static void s_set_volte_mic_mute(int state); |
| 79 | static void s_set_volte_volume(int vol); |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 80 | #ifdef SEPERATED_AUDIO_INPUT |
| 81 | static void s_setInput(int); |
| 82 | |
| 83 | static int input_source; |
| 84 | #endif |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 85 | #ifdef QCOM_CSDCLIENT_ENABLED |
| 86 | static void s_set_csd_handle(void*); |
| 87 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 88 | |
| 89 | static char mic_type[25]; |
| 90 | static char curRxUCMDevice[50]; |
| 91 | static char curTxUCMDevice[50]; |
| 92 | static int fluence_mode; |
| 93 | static int fmVolume; |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 94 | #ifdef USES_FLUENCE_INCALL |
| 95 | static uint32_t mDevSettingsFlag = TTY_OFF | DMIC_FLAG; |
| 96 | #else |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 97 | static uint32_t mDevSettingsFlag = TTY_OFF; |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 98 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 99 | static int btsco_samplerate = 8000; |
| 100 | static bool pflag = false; |
| 101 | static ALSAUseCaseList mUseCaseList; |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 102 | static void *csd_handle; |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 103 | |
| 104 | static hw_module_methods_t s_module_methods = { |
| 105 | open : s_device_open |
| 106 | }; |
| 107 | |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 108 | extern "C" { |
| 109 | hw_module_t HAL_MODULE_INFO_SYM = { |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 110 | tag : HARDWARE_MODULE_TAG, |
| 111 | version_major : 1, |
| 112 | version_minor : 0, |
| 113 | id : ALSA_HARDWARE_MODULE_ID, |
| 114 | name : "QCOM ALSA module", |
| 115 | author : "QuIC Inc", |
| 116 | methods : &s_module_methods, |
| 117 | dso : 0, |
| 118 | reserved : {0,}, |
| 119 | }; |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 120 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 121 | |
| 122 | static int s_device_open(const hw_module_t* module, const char* name, |
| 123 | hw_device_t** device) |
| 124 | { |
| 125 | char value[128]; |
| 126 | alsa_device_t *dev; |
| 127 | dev = (alsa_device_t *) malloc(sizeof(*dev)); |
| 128 | if (!dev) return -ENOMEM; |
| 129 | |
| 130 | memset(dev, 0, sizeof(*dev)); |
| 131 | |
| 132 | /* initialize the procs */ |
| 133 | dev->common.tag = HARDWARE_DEVICE_TAG; |
| 134 | dev->common.version = 0; |
| 135 | dev->common.module = (hw_module_t *) module; |
| 136 | dev->common.close = s_device_close; |
| 137 | dev->init = s_init; |
| 138 | dev->open = s_open; |
| 139 | dev->close = s_close; |
| 140 | dev->route = s_route; |
| 141 | dev->standby = s_standby; |
| 142 | dev->startVoiceCall = s_start_voice_call; |
| 143 | dev->startVoipCall = s_start_voip_call; |
| 144 | dev->startFm = s_start_fm; |
| 145 | dev->setVoiceVolume = s_set_voice_volume; |
| 146 | dev->setVoipVolume = s_set_voip_volume; |
| 147 | dev->setMicMute = s_set_mic_mute; |
| 148 | dev->setVoipMicMute = s_set_voip_mic_mute; |
| 149 | dev->setVoipConfig = s_set_voip_config; |
| 150 | dev->setFmVolume = s_set_fm_vol; |
| 151 | dev->setBtscoRate = s_set_btsco_rate; |
| 152 | dev->setLpaVolume = s_set_lpa_vol; |
| 153 | dev->enableWideVoice = s_enable_wide_voice; |
| 154 | dev->enableFENS = s_enable_fens; |
| 155 | dev->setFlags = s_set_flags; |
| 156 | dev->setCompressedVolume = s_set_compressed_vol; |
| 157 | dev->enableSlowTalk = s_enable_slow_talk; |
| 158 | dev->setVocRecMode = s_set_voc_rec_mode; |
| 159 | dev->setVoLTEMicMute = s_set_volte_mic_mute; |
| 160 | dev->setVoLTEVolume = s_set_volte_volume; |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 161 | #ifdef SEPERATED_AUDIO_INPUT |
| 162 | dev->setInput = s_setInput; |
| 163 | #endif |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 164 | #ifdef QCOM_CSDCLIENT_ENABLED |
| 165 | dev->setCsdHandle = s_set_csd_handle; |
| 166 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 167 | *device = &dev->common; |
| 168 | |
| 169 | property_get("persist.audio.handset.mic",value,"0"); |
| 170 | strlcpy(mic_type, value, sizeof(mic_type)); |
| 171 | property_get("persist.audio.fluence.mode",value,"0"); |
| 172 | if (!strcmp("broadside", value)) { |
| 173 | fluence_mode = FLUENCE_MODE_BROADSIDE; |
| 174 | } else { |
| 175 | fluence_mode = FLUENCE_MODE_ENDFIRE; |
| 176 | } |
| 177 | strlcpy(curRxUCMDevice, "None", sizeof(curRxUCMDevice)); |
| 178 | strlcpy(curTxUCMDevice, "None", sizeof(curTxUCMDevice)); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 179 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 180 | ALOGD("ALSA module opened"); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 181 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int s_device_close(hw_device_t* device) |
| 187 | { |
| 188 | free(device); |
| 189 | device = NULL; |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | // ---------------------------------------------------------------------------- |
| 194 | |
| 195 | static const int DEFAULT_SAMPLE_RATE = ALSA_DEFAULT_SAMPLE_RATE; |
| 196 | |
| 197 | static void switchDevice(alsa_handle_t *handle, uint32_t devices, uint32_t mode); |
| 198 | static char *getUCMDevice(uint32_t devices, int input, char *rxDevice); |
| 199 | static void disableDevice(alsa_handle_t *handle); |
| 200 | int getUseCaseType(const char *useCase); |
| 201 | |
| 202 | static int callMode = AudioSystem::MODE_NORMAL; |
| 203 | // ---------------------------------------------------------------------------- |
| 204 | |
| 205 | bool platform_is_Fusion3() |
| 206 | { |
| 207 | char platform[128], baseband[128]; |
| 208 | property_get("ro.board.platform", platform, ""); |
| 209 | property_get("ro.baseband", baseband, ""); |
| 210 | if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) |
| 211 | return true; |
| 212 | else |
| 213 | return false; |
| 214 | } |
| 215 | |
| 216 | int deviceName(alsa_handle_t *handle, unsigned flags, char **value) |
| 217 | { |
| 218 | int ret = 0; |
| 219 | char ident[70]; |
| 220 | |
| 221 | if (flags & PCM_IN) { |
| 222 | strlcpy(ident, "CapturePCM/", sizeof(ident)); |
| 223 | } else { |
| 224 | strlcpy(ident, "PlaybackPCM/", sizeof(ident)); |
| 225 | } |
| 226 | strlcat(ident, handle->useCase, sizeof(ident)); |
| 227 | ret = snd_use_case_get(handle->ucMgr, ident, (const char **)value); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 228 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 229 | ALOGD("Device value returned is %s", (*value)); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 230 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 231 | return ret; |
| 232 | } |
| 233 | |
| 234 | status_t setHardwareParams(alsa_handle_t *handle) |
| 235 | { |
| 236 | struct snd_pcm_hw_params *params; |
| 237 | unsigned long bufferSize, reqBuffSize; |
| 238 | unsigned int periodTime, bufferTime; |
| 239 | unsigned int requestedRate = handle->sampleRate; |
| 240 | int status = 0; |
| 241 | int channels = handle->channels; |
| 242 | snd_pcm_format_t format = SNDRV_PCM_FORMAT_S16_LE; |
| 243 | |
| 244 | params = (snd_pcm_hw_params*) calloc(1, sizeof(struct snd_pcm_hw_params)); |
| 245 | if (!params) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 246 | ALOGE("Failed to allocate ALSA hardware parameters!"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 247 | return NO_INIT; |
| 248 | } |
| 249 | |
| 250 | reqBuffSize = handle->bufferSize; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 251 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 252 | ALOGD("setHardwareParams: reqBuffSize %d channels %d sampleRate %d", |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 253 | (int) reqBuffSize, handle->channels, handle->sampleRate); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 254 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 255 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 256 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 257 | if (channels == 6) { |
| 258 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 259 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 260 | ALOGV("HWParams: Use 4 channels in kernel for 5.1(%s) recording ", handle->useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 261 | channels = 4; |
| 262 | reqBuffSize = DEFAULT_IN_BUFFER_SIZE; |
| 263 | } |
| 264 | } |
| 265 | #endif |
| 266 | |
| 267 | param_init(params); |
| 268 | param_set_mask(params, SNDRV_PCM_HW_PARAM_ACCESS, |
| 269 | SNDRV_PCM_ACCESS_RW_INTERLEAVED); |
| 270 | if (handle->format != SNDRV_PCM_FORMAT_S16_LE) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 271 | if (handle->format == AudioSystem::AMR_NB |
| 272 | || handle->format == AudioSystem::AMR_WB |
| 273 | #ifdef QCOM_QCHAT_ENABLED |
| 274 | || handle->format == AudioSystem::EVRC |
| 275 | || handle->format == AudioSystem::EVRCB |
| 276 | || handle->format == AudioSystem::EVRCWB |
| 277 | #endif |
| 278 | ) |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 279 | format = SNDRV_PCM_FORMAT_SPECIAL; |
| 280 | } |
| 281 | param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, |
| 282 | format); |
| 283 | param_set_mask(params, SNDRV_PCM_HW_PARAM_SUBFORMAT, |
| 284 | SNDRV_PCM_SUBFORMAT_STD); |
| 285 | param_set_min(params, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, reqBuffSize); |
| 286 | param_set_int(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, 16); |
| 287 | param_set_int(params, SNDRV_PCM_HW_PARAM_FRAME_BITS, |
| 288 | channels * 16); |
| 289 | param_set_int(params, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 290 | channels); |
| 291 | param_set_int(params, SNDRV_PCM_HW_PARAM_RATE, handle->sampleRate); |
| 292 | param_set_hw_refine(handle->handle, params); |
| 293 | |
| 294 | if (param_set_hw_params(handle->handle, params)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 295 | ALOGE("cannot set hw params"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 296 | return NO_INIT; |
| 297 | } |
| 298 | param_dump(params); |
| 299 | |
| 300 | handle->handle->buffer_size = pcm_buffer_size(params); |
| 301 | handle->handle->period_size = pcm_period_size(params); |
| 302 | handle->handle->period_cnt = handle->handle->buffer_size/handle->handle->period_size; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 303 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 304 | ALOGD("setHardwareParams: buffer_size %d, period_size %d, period_cnt %d", |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 305 | handle->handle->buffer_size, handle->handle->period_size, |
| 306 | handle->handle->period_cnt); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 307 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 308 | handle->handle->rate = handle->sampleRate; |
| 309 | handle->handle->channels = handle->channels; |
| 310 | handle->periodSize = handle->handle->period_size; |
| 311 | if (strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC) && |
| 312 | strcmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC) && |
| 313 | (6 != handle->channels)) { |
| 314 | //Do not update buffersize for 5.1 recording |
| 315 | handle->bufferSize = handle->handle->period_size; |
| 316 | } |
| 317 | |
| 318 | return NO_ERROR; |
| 319 | } |
| 320 | |
| 321 | status_t setSoftwareParams(alsa_handle_t *handle) |
| 322 | { |
| 323 | struct snd_pcm_sw_params* params; |
| 324 | struct pcm* pcm = handle->handle; |
| 325 | |
| 326 | unsigned long periodSize = pcm->period_size; |
| 327 | int channels = handle->channels; |
| 328 | |
| 329 | params = (snd_pcm_sw_params*) calloc(1, sizeof(struct snd_pcm_sw_params)); |
| 330 | if (!params) { |
| 331 | LOG_ALWAYS_FATAL("Failed to allocate ALSA software parameters!"); |
| 332 | return NO_INIT; |
| 333 | } |
| 334 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 335 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 336 | if (channels == 6) { |
| 337 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 338 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 339 | ALOGV("SWParams: Use 4 channels in kernel for 5.1(%s) recording ", handle->useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 340 | channels = 4; |
| 341 | } |
| 342 | } |
| 343 | #endif |
| 344 | |
| 345 | // Get the current software parameters |
| 346 | params->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; |
| 347 | params->period_step = 1; |
| 348 | if(((!strcmp(handle->useCase,SND_USE_CASE_MOD_PLAY_VOIP)) || |
| 349 | (!strcmp(handle->useCase,SND_USE_CASE_VERB_IP_VOICECALL)))){ |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 350 | ALOGV("setparam: start & stop threshold for Voip "); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 351 | params->avail_min = handle->channels - 1 ? periodSize/4 : periodSize/2; |
| 352 | params->start_threshold = periodSize/2; |
| 353 | params->stop_threshold = INT_MAX; |
| 354 | } else { |
| 355 | params->avail_min = periodSize/2; |
| 356 | params->start_threshold = channels * (periodSize/4); |
| 357 | params->stop_threshold = INT_MAX; |
| 358 | } |
| 359 | params->silence_threshold = 0; |
| 360 | params->silence_size = 0; |
| 361 | |
| 362 | if (param_set_sw_params(handle->handle, params)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 363 | ALOGE("cannot set sw params"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 364 | return NO_INIT; |
| 365 | } |
| 366 | return NO_ERROR; |
| 367 | } |
| 368 | |
| 369 | void switchDevice(alsa_handle_t *handle, uint32_t devices, uint32_t mode) |
| 370 | { |
| 371 | const char **mods_list; |
| 372 | use_case_t useCaseNode; |
| 373 | unsigned usecase_type = 0; |
| 374 | bool inCallDevSwitch = false; |
| 375 | char *rxDevice, *txDevice, ident[70], *use_case = NULL; |
| 376 | int err = 0, index, mods_size; |
| 377 | int rx_dev_id, tx_dev_id; |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 378 | ALOGV("%s: device %d", __FUNCTION__, devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 379 | |
| 380 | if ((mode == AudioSystem::MODE_IN_CALL) || (mode == AudioSystem::MODE_IN_COMMUNICATION)) { |
| 381 | if ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
| 382 | (devices & AudioSystem::DEVICE_IN_WIRED_HEADSET)) { |
| 383 | devices = devices | (AudioSystem::DEVICE_OUT_WIRED_HEADSET | |
| 384 | AudioSystem::DEVICE_IN_WIRED_HEADSET); |
| 385 | } else if (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE) { |
| 386 | devices = devices | (AudioSystem::DEVICE_OUT_WIRED_HEADPHONE | |
| 387 | AudioSystem::DEVICE_IN_BUILTIN_MIC); |
| 388 | } else if ((devices & AudioSystem::DEVICE_OUT_EARPIECE) || |
| 389 | (devices & AudioSystem::DEVICE_IN_BUILTIN_MIC)) { |
| 390 | devices = devices | (AudioSystem::DEVICE_IN_BUILTIN_MIC | |
| 391 | AudioSystem::DEVICE_OUT_EARPIECE); |
| 392 | } else if (devices & AudioSystem::DEVICE_OUT_SPEAKER) { |
ty.lee | 10dfa85 | 2012-08-01 21:09:45 +0900 | [diff] [blame] | 393 | devices = devices | (AudioSystem::DEVICE_IN_BACK_MIC | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 394 | AudioSystem::DEVICE_OUT_SPEAKER); |
| 395 | } else if ((devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO) || |
| 396 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET) || |
| 397 | (devices & AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET)) { |
| 398 | devices = devices | (AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET | |
| 399 | AudioSystem::DEVICE_OUT_BLUETOOTH_SCO); |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 400 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 401 | } else if ((devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 402 | (devices & AudioSystem::DEVICE_IN_ANC_HEADSET)) { |
| 403 | devices = devices | (AudioSystem::DEVICE_OUT_ANC_HEADSET | |
| 404 | AudioSystem::DEVICE_IN_ANC_HEADSET); |
| 405 | } else if (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE) { |
| 406 | devices = devices | (AudioSystem::DEVICE_OUT_ANC_HEADPHONE | |
| 407 | AudioSystem::DEVICE_IN_BUILTIN_MIC); |
| 408 | #endif |
| 409 | } else if (devices & AudioSystem::DEVICE_OUT_AUX_DIGITAL) { |
| 410 | devices = devices | (AudioSystem::DEVICE_OUT_AUX_DIGITAL | |
| 411 | AudioSystem::DEVICE_IN_AUX_DIGITAL); |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 412 | #ifdef QCOM_PROXY_DEVICE_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 413 | } else if ((devices & AudioSystem::DEVICE_OUT_PROXY) || |
| 414 | (devices & AudioSystem::DEVICE_IN_PROXY)) { |
| 415 | devices = devices | (AudioSystem::DEVICE_OUT_PROXY | |
| 416 | AudioSystem::DEVICE_IN_PROXY); |
| 417 | #endif |
| 418 | } |
| 419 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 420 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 421 | if ((devices & AudioSystem::DEVICE_IN_BUILTIN_MIC) && ( 6 == handle->channels)) { |
| 422 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 423 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 424 | ALOGV(" switchDevice , use ssr devices for channels:%d usecase:%s",handle->channels,handle->useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 425 | s_set_flags(SSRQMIC_FLAG); |
| 426 | } |
| 427 | } |
| 428 | #endif |
| 429 | |
| 430 | rxDevice = getUCMDevice(devices & AudioSystem::DEVICE_OUT_ALL, 0, NULL); |
| 431 | txDevice = getUCMDevice(devices & AudioSystem::DEVICE_IN_ALL, 1, rxDevice); |
| 432 | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 433 | if ((rxDevice != NULL) && (txDevice != NULL)) { |
| 434 | if (((strncmp(rxDevice, curRxUCMDevice, MAX_STR_LEN)) || |
| 435 | (strncmp(txDevice, curTxUCMDevice, MAX_STR_LEN))) && (mode == AudioSystem::MODE_IN_CALL)) |
| 436 | inCallDevSwitch = true; |
| 437 | } |
Ajay Dudani | 91bf891 | 2012-08-20 18:48:13 -0700 | [diff] [blame] | 438 | |
| 439 | #ifdef QCOM_CSDCLIENT_ENABLED |
| 440 | if (mode == AudioSystem::MODE_IN_CALL && platform_is_Fusion3() && (inCallDevSwitch == true)) { |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 441 | if (csd_disable_device == NULL) { |
| 442 | ALOGE("dlsym:Error:%s Loading csd_client_disable_device", dlerror()); |
| 443 | } else { |
| 444 | err = csd_disable_device(); |
| 445 | if (err < 0) |
| 446 | { |
| 447 | ALOGE("csd_client_disable_device, failed, error %d", err); |
| 448 | } |
Ajay Dudani | 91bf891 | 2012-08-20 18:48:13 -0700 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | #endif |
| 452 | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 453 | snd_use_case_get(handle->ucMgr, "_verb", (const char **)&use_case); |
| 454 | mods_size = snd_use_case_get_list(handle->ucMgr, "_enamods", &mods_list); |
| 455 | if (rxDevice != NULL) { |
| 456 | if ((strncmp(curRxUCMDevice, "None", 4)) && |
| 457 | ((strncmp(rxDevice, curRxUCMDevice, MAX_STR_LEN)) || (inCallDevSwitch == true))) { |
| 458 | if ((use_case != NULL) && (strncmp(use_case, SND_USE_CASE_VERB_INACTIVE, |
| 459 | strlen(SND_USE_CASE_VERB_INACTIVE)))) { |
| 460 | usecase_type = getUseCaseType(use_case); |
| 461 | if (usecase_type & USECASE_TYPE_RX) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 462 | ALOGD("Deroute use case %s type is %d\n", use_case, usecase_type); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 463 | strlcpy(useCaseNode.useCase, use_case, MAX_STR_LEN); |
| 464 | snd_use_case_set(handle->ucMgr, "_verb", SND_USE_CASE_VERB_INACTIVE); |
| 465 | mUseCaseList.push_front(useCaseNode); |
| 466 | } |
| 467 | } |
| 468 | if (mods_size) { |
| 469 | for(index = 0; index < mods_size; index++) { |
| 470 | usecase_type = getUseCaseType(mods_list[index]); |
| 471 | if (usecase_type & USECASE_TYPE_RX) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 472 | ALOGD("Deroute use case %s type is %d\n", mods_list[index], usecase_type); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 473 | strlcpy(useCaseNode.useCase, mods_list[index], MAX_STR_LEN); |
| 474 | snd_use_case_set(handle->ucMgr, "_dismod", mods_list[index]); |
| 475 | mUseCaseList.push_back(useCaseNode); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | snd_use_case_set(handle->ucMgr, "_disdev", curRxUCMDevice); |
| 480 | } |
| 481 | } |
| 482 | if (txDevice != NULL) { |
| 483 | if ((strncmp(curTxUCMDevice, "None", 4)) && |
| 484 | ((strncmp(txDevice, curTxUCMDevice, MAX_STR_LEN)) || (inCallDevSwitch == true))) { |
| 485 | if ((use_case != NULL) && (strncmp(use_case, SND_USE_CASE_VERB_INACTIVE, |
| 486 | strlen(SND_USE_CASE_VERB_INACTIVE)))) { |
| 487 | usecase_type = getUseCaseType(use_case); |
| 488 | if ((usecase_type & USECASE_TYPE_TX) && (!(usecase_type & USECASE_TYPE_RX))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 489 | ALOGD("Deroute use case %s type is %d\n", use_case, usecase_type); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 490 | strlcpy(useCaseNode.useCase, use_case, MAX_STR_LEN); |
| 491 | snd_use_case_set(handle->ucMgr, "_verb", SND_USE_CASE_VERB_INACTIVE); |
| 492 | mUseCaseList.push_front(useCaseNode); |
| 493 | } |
| 494 | } |
| 495 | if (mods_size) { |
| 496 | for(index = 0; index < mods_size; index++) { |
| 497 | usecase_type = getUseCaseType(mods_list[index]); |
| 498 | if ((usecase_type & USECASE_TYPE_TX) && (!(usecase_type & USECASE_TYPE_RX))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 499 | ALOGD("Deroute use case %s type is %d\n", mods_list[index], usecase_type); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 500 | strlcpy(useCaseNode.useCase, mods_list[index], MAX_STR_LEN); |
| 501 | snd_use_case_set(handle->ucMgr, "_dismod", mods_list[index]); |
| 502 | mUseCaseList.push_back(useCaseNode); |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | snd_use_case_set(handle->ucMgr, "_disdev", curTxUCMDevice); |
| 507 | } |
| 508 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 509 | ALOGV("%s,rxDev:%s, txDev:%s, curRxDev:%s, curTxDev:%s\n", __FUNCTION__, rxDevice, txDevice, curRxUCMDevice, curTxUCMDevice); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 510 | |
| 511 | if (rxDevice != NULL) { |
| 512 | snd_use_case_set(handle->ucMgr, "_enadev", rxDevice); |
| 513 | strlcpy(curRxUCMDevice, rxDevice, sizeof(curRxUCMDevice)); |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 514 | #ifdef QCOM_FM_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 515 | if (devices & AudioSystem::DEVICE_OUT_FM) |
| 516 | s_set_fm_vol(fmVolume); |
| 517 | #endif |
| 518 | } |
| 519 | if (txDevice != NULL) { |
| 520 | snd_use_case_set(handle->ucMgr, "_enadev", txDevice); |
| 521 | strlcpy(curTxUCMDevice, txDevice, sizeof(curTxUCMDevice)); |
| 522 | } |
| 523 | for(ALSAUseCaseList::iterator it = mUseCaseList.begin(); it != mUseCaseList.end(); ++it) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 524 | ALOGD("Route use case %s\n", it->useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 525 | if ((use_case != NULL) && (strncmp(use_case, SND_USE_CASE_VERB_INACTIVE, |
| 526 | strlen(SND_USE_CASE_VERB_INACTIVE))) && (!strncmp(use_case, it->useCase, MAX_UC_LEN))) { |
| 527 | snd_use_case_set(handle->ucMgr, "_verb", it->useCase); |
| 528 | } else { |
| 529 | snd_use_case_set(handle->ucMgr, "_enamod", it->useCase); |
| 530 | } |
| 531 | } |
| 532 | if (!mUseCaseList.empty()) |
| 533 | mUseCaseList.clear(); |
| 534 | if (use_case != NULL) { |
| 535 | free(use_case); |
| 536 | use_case = NULL; |
| 537 | } |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 538 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 539 | ALOGD("switchDevice: curTxUCMDevivce %s curRxDevDevice %s", curTxUCMDevice, curRxUCMDevice); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 540 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 541 | |
| 542 | if (mode == AudioSystem::MODE_IN_CALL && platform_is_Fusion3() && (inCallDevSwitch == true)) { |
| 543 | /* get tx acdb id */ |
| 544 | memset(&ident,0,sizeof(ident)); |
| 545 | strlcpy(ident, "ACDBID/", sizeof(ident)); |
| 546 | strlcat(ident, curTxUCMDevice, sizeof(ident)); |
| 547 | tx_dev_id = snd_use_case_get(handle->ucMgr, ident, NULL); |
| 548 | |
| 549 | /* get rx acdb id */ |
| 550 | memset(&ident,0,sizeof(ident)); |
| 551 | strlcpy(ident, "ACDBID/", sizeof(ident)); |
| 552 | strlcat(ident, curRxUCMDevice, sizeof(ident)); |
| 553 | rx_dev_id = snd_use_case_get(handle->ucMgr, ident, NULL); |
| 554 | |
ehgrace.kim | 91e9fad | 2012-07-02 18:27:28 -0700 | [diff] [blame] | 555 | if (((rx_dev_id == DEVICE_SPEAKER_MONO_RX_ACDB_ID ) || (rx_dev_id == DEVICE_SPEAKER_STEREO_RX_ACDB_ID )) |
| 556 | && tx_dev_id == DEVICE_HANDSET_TX_ACDB_ID) { |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 557 | tx_dev_id = DEVICE_SPEAKER_TX_ACDB_ID; |
| 558 | } |
| 559 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 560 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 561 | ALOGV("rx_dev_id=%d, tx_dev_id=%d\n", rx_dev_id, tx_dev_id); |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 562 | if (csd_enable_device == NULL) { |
| 563 | ALOGE("dlsym:Error:%s Loading csd_client_enable_device", dlerror()); |
| 564 | } else { |
| 565 | err = csd_enable_device(rx_dev_id, tx_dev_id, mDevSettingsFlag); |
| 566 | if (err < 0) |
| 567 | { |
| 568 | ALOGE("csd_client_disable_device failed, error %d", err); |
| 569 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 570 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 571 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | if (rxDevice != NULL) { |
| 575 | if (pflag && (((!strncmp(rxDevice, DEVICE_SPEAKER_HEADSET, strlen(DEVICE_SPEAKER_HEADSET))) && |
| 576 | ((!strncmp(curRxUCMDevice, DEVICE_HEADPHONES, strlen(DEVICE_HEADPHONES))) || |
| 577 | (!strncmp(curRxUCMDevice, DEVICE_HEADSET, strlen(DEVICE_HEADSET))))) || |
| 578 | (((!strncmp(curRxUCMDevice, DEVICE_SPEAKER_HEADSET, strlen(DEVICE_SPEAKER_HEADSET))) && |
| 579 | ((!strncmp(rxDevice, DEVICE_HEADPHONES, strlen(DEVICE_HEADPHONES))) || |
| 580 | (!strncmp(rxDevice, DEVICE_HEADSET, strlen(DEVICE_HEADSET))))))) && |
| 581 | ((!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI, strlen(SND_USE_CASE_VERB_HIFI))) || |
| 582 | (!strncmp(handle->useCase, SND_USE_CASE_MOD_PLAY_MUSIC, strlen(SND_USE_CASE_MOD_PLAY_MUSIC))))) { |
| 583 | s_open(handle); |
| 584 | pflag = false; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | if (rxDevice != NULL) { |
| 589 | free(rxDevice); |
| 590 | rxDevice = NULL; |
| 591 | } |
| 592 | if (txDevice != NULL) { |
| 593 | free(txDevice); |
| 594 | txDevice = NULL; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | // ---------------------------------------------------------------------------- |
| 599 | |
| 600 | static status_t s_init(alsa_device_t *module, ALSAHandleList &list) |
| 601 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 602 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 603 | ALOGD("s_init: Initializing devices for ALSA module"); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 604 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 605 | |
| 606 | list.clear(); |
| 607 | |
| 608 | return NO_ERROR; |
| 609 | } |
| 610 | |
| 611 | static status_t s_open(alsa_handle_t *handle) |
| 612 | { |
| 613 | char *devName; |
| 614 | unsigned flags = 0; |
| 615 | int err = NO_ERROR; |
| 616 | |
| 617 | /* No need to call s_close for LPA as pcm device open and close is handled by LPAPlayer in stagefright */ |
| 618 | if((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) |
| 619 | ||(!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))) { |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 620 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 621 | ALOGD("s_open: Opening LPA /Tunnel playback"); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 622 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 623 | return NO_ERROR; |
| 624 | } |
| 625 | |
| 626 | s_close(handle); |
| 627 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 628 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 629 | ALOGD("s_open: handle %p", handle); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 630 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 631 | |
| 632 | // ASoC multicomponent requires a valid path (frontend/backend) for |
| 633 | // the device to be opened |
| 634 | |
| 635 | // The PCM stream is opened in blocking mode, per ALSA defaults. The |
| 636 | // AudioFlinger seems to assume blocking mode too, so asynchronous mode |
| 637 | // should not be used. |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 638 | if ((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 639 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) || |
| 640 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 641 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))) { |
| 642 | ALOGV("LPA/tunnel use case"); |
| 643 | flags |= PCM_MMAP; |
| 644 | flags |= DEBUG_ON; |
| 645 | } else if ((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI)) || |
| 646 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOWLATENCY_MUSIC)) || |
| 647 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LOWLATENCY_MUSIC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 648 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_MUSIC))) { |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 649 | ALOGV("Music case"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 650 | flags = PCM_OUT; |
| 651 | } else { |
| 652 | flags = PCM_IN; |
| 653 | } |
| 654 | if (handle->channels == 1) { |
| 655 | flags |= PCM_MONO; |
SathishKumar Mani | e42406e | 2012-08-29 16:25:54 -0700 | [diff] [blame] | 656 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 657 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 658 | else if (handle->channels == 4 ) { |
| 659 | flags |= PCM_QUAD; |
| 660 | } else if (handle->channels == 6 ) { |
| 661 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 662 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
| 663 | flags |= PCM_QUAD; |
| 664 | } else { |
| 665 | flags |= PCM_5POINT1; |
| 666 | } |
SathishKumar Mani | e42406e | 2012-08-29 16:25:54 -0700 | [diff] [blame] | 667 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 668 | #endif |
| 669 | else { |
| 670 | flags |= PCM_STEREO; |
| 671 | } |
| 672 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 673 | ALOGE("Failed to get pcm device node: %s", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 674 | return NO_INIT; |
| 675 | } |
| 676 | if (devName != NULL) { |
| 677 | handle->handle = pcm_open(flags, (char*)devName); |
| 678 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 679 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 680 | return NO_INIT; |
| 681 | } |
| 682 | |
| 683 | if (!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 684 | ALOGE("s_open: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 685 | free(devName); |
| 686 | return NO_INIT; |
| 687 | } |
| 688 | |
| 689 | handle->handle->flags = flags; |
| 690 | err = setHardwareParams(handle); |
| 691 | |
| 692 | if (err == NO_ERROR) { |
| 693 | err = setSoftwareParams(handle); |
| 694 | } |
| 695 | |
| 696 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 697 | ALOGE("Set HW/SW params failed: Closing the pcm stream"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 698 | s_standby(handle); |
| 699 | } |
| 700 | |
| 701 | free(devName); |
| 702 | return NO_ERROR; |
| 703 | } |
| 704 | |
| 705 | static status_t s_start_voip_call(alsa_handle_t *handle) |
| 706 | { |
| 707 | |
| 708 | char* devName; |
| 709 | char* devName1; |
| 710 | unsigned flags = 0; |
| 711 | int err = NO_ERROR; |
| 712 | uint8_t voc_pkt[VOIP_BUFFER_MAX_SIZE]; |
| 713 | |
| 714 | s_close(handle); |
| 715 | flags = PCM_OUT; |
| 716 | flags |= PCM_MONO; |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 717 | ALOGV("s_open:s_start_voip_call handle %p", handle); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 718 | |
| 719 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 720 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 721 | return NO_INIT; |
| 722 | } |
| 723 | |
| 724 | if (devName != NULL) { |
| 725 | handle->handle = pcm_open(flags, (char*)devName); |
| 726 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 727 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 728 | return NO_INIT; |
| 729 | } |
| 730 | |
| 731 | if (!handle->handle) { |
| 732 | free(devName); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 733 | ALOGE("s_open: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 734 | return NO_INIT; |
| 735 | } |
| 736 | |
| 737 | if (!pcm_ready(handle->handle)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 738 | ALOGE(" pcm ready failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | handle->handle->flags = flags; |
| 742 | err = setHardwareParams(handle); |
| 743 | |
| 744 | if (err == NO_ERROR) { |
| 745 | err = setSoftwareParams(handle); |
| 746 | } |
| 747 | |
| 748 | err = pcm_prepare(handle->handle); |
| 749 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 750 | ALOGE("DEVICE_OUT_DIRECTOUTPUT: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /* first write required start dsp */ |
| 754 | memset(&voc_pkt,0,sizeof(voc_pkt)); |
| 755 | pcm_write(handle->handle,&voc_pkt,handle->handle->period_size); |
| 756 | handle->rxHandle = handle->handle; |
| 757 | free(devName); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 758 | ALOGV("s_open: DEVICE_IN_COMMUNICATION "); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 759 | flags = PCM_IN; |
| 760 | flags |= PCM_MONO; |
| 761 | handle->handle = 0; |
| 762 | |
| 763 | if (deviceName(handle, flags, &devName1) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 764 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 765 | return NO_INIT; |
| 766 | } |
| 767 | if (devName != NULL) { |
| 768 | handle->handle = pcm_open(flags, (char*)devName1); |
| 769 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 770 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 771 | return NO_INIT; |
| 772 | } |
| 773 | |
| 774 | if (!handle->handle) { |
| 775 | free(devName); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 776 | ALOGE("s_open: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 777 | return NO_INIT; |
| 778 | } |
| 779 | |
| 780 | if (!pcm_ready(handle->handle)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 781 | ALOGE(" pcm ready in failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | handle->handle->flags = flags; |
| 785 | |
| 786 | err = setHardwareParams(handle); |
| 787 | |
| 788 | if (err == NO_ERROR) { |
| 789 | err = setSoftwareParams(handle); |
| 790 | } |
| 791 | |
| 792 | |
| 793 | err = pcm_prepare(handle->handle); |
| 794 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 795 | ALOGE("DEVICE_IN_COMMUNICATION: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /* first read required start dsp */ |
| 799 | memset(&voc_pkt,0,sizeof(voc_pkt)); |
| 800 | pcm_read(handle->handle,&voc_pkt,handle->handle->period_size); |
| 801 | return NO_ERROR; |
| 802 | } |
| 803 | |
| 804 | static status_t s_start_voice_call(alsa_handle_t *handle) |
| 805 | { |
| 806 | char* devName; |
| 807 | unsigned flags = 0; |
| 808 | int err = NO_ERROR; |
| 809 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 810 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 811 | ALOGD("s_start_voice_call: handle %p", handle); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 812 | #endif |
| 813 | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 814 | // ASoC multicomponent requires a valid path (frontend/backend) for |
| 815 | // the device to be opened |
| 816 | |
| 817 | flags = PCM_OUT | PCM_MONO; |
| 818 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 819 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 820 | return NO_INIT; |
| 821 | } |
| 822 | if (devName != NULL) { |
| 823 | handle->handle = pcm_open(flags, (char*)devName); |
| 824 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 825 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 826 | return NO_INIT; |
| 827 | } |
| 828 | if (!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 829 | ALOGE("s_start_voicecall: could not open PCM device"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 830 | goto Error; |
| 831 | } |
| 832 | |
| 833 | handle->handle->flags = flags; |
| 834 | err = setHardwareParams(handle); |
| 835 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 836 | ALOGE("s_start_voice_call: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 837 | goto Error; |
| 838 | } |
| 839 | |
| 840 | err = setSoftwareParams(handle); |
| 841 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 842 | ALOGE("s_start_voice_call: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 843 | goto Error; |
| 844 | } |
| 845 | |
| 846 | err = pcm_prepare(handle->handle); |
| 847 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 848 | ALOGE("s_start_voice_call: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 849 | goto Error; |
| 850 | } |
| 851 | |
| 852 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 853 | ALOGE("s_start_voice_call:SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 854 | goto Error; |
| 855 | } |
| 856 | |
| 857 | // Store the PCM playback device pointer in rxHandle |
| 858 | handle->rxHandle = handle->handle; |
| 859 | free(devName); |
| 860 | |
| 861 | // Open PCM capture device |
| 862 | flags = PCM_IN | PCM_MONO; |
| 863 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 864 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 865 | goto Error; |
| 866 | } |
| 867 | if (devName != NULL) { |
| 868 | handle->handle = pcm_open(flags, (char*)devName); |
| 869 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 870 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 871 | return NO_INIT; |
| 872 | } |
| 873 | if (!handle->handle) { |
| 874 | free(devName); |
| 875 | goto Error; |
| 876 | } |
| 877 | |
| 878 | handle->handle->flags = flags; |
| 879 | err = setHardwareParams(handle); |
| 880 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 881 | ALOGE("s_start_voice_call: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 882 | goto Error; |
| 883 | } |
| 884 | |
| 885 | err = setSoftwareParams(handle); |
| 886 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 887 | ALOGE("s_start_voice_call: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 888 | goto Error; |
| 889 | } |
| 890 | |
| 891 | err = pcm_prepare(handle->handle); |
| 892 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 893 | ALOGE("s_start_voice_call: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 894 | goto Error; |
| 895 | } |
| 896 | |
| 897 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 898 | ALOGE("s_start_voice_call:SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 899 | goto Error; |
| 900 | } |
| 901 | |
| 902 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 903 | #ifdef QCOM_CSDCLIENT_ENABLED |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 904 | if (csd_start_voice == NULL) { |
| 905 | ALOGE("dlsym:Error:%s Loading csd_client_start_voice", dlerror()); |
| 906 | } else { |
| 907 | err = csd_start_voice(); |
| 908 | if (err < 0){ |
| 909 | ALOGE("s_start_voice_call: csd_client error %d\n", err); |
| 910 | goto Error; |
| 911 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 912 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 913 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | free(devName); |
| 917 | return NO_ERROR; |
| 918 | |
| 919 | Error: |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 920 | ALOGE("s_start_voice_call: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 921 | free(devName); |
| 922 | s_close(handle); |
| 923 | return NO_INIT; |
| 924 | } |
| 925 | |
| 926 | static status_t s_start_fm(alsa_handle_t *handle) |
| 927 | { |
| 928 | char *devName; |
| 929 | unsigned flags = 0; |
| 930 | int err = NO_ERROR; |
| 931 | |
SathishKumar Mani | 0a01991 | 2012-09-11 12:33:11 -0700 | [diff] [blame] | 932 | ALOGD("s_start_fm: handle %p", handle); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 933 | |
| 934 | // ASoC multicomponent requires a valid path (frontend/backend) for |
| 935 | // the device to be opened |
| 936 | |
| 937 | flags = PCM_OUT | PCM_STEREO; |
| 938 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 939 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 940 | goto Error; |
| 941 | } |
| 942 | if (devName != NULL) { |
| 943 | handle->handle = pcm_open(flags, (char*)devName); |
| 944 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 945 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 946 | return NO_INIT; |
| 947 | } |
| 948 | if (!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 949 | ALOGE("s_start_fm: could not open PCM device"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 950 | goto Error; |
| 951 | } |
| 952 | |
| 953 | handle->handle->flags = flags; |
| 954 | err = setHardwareParams(handle); |
| 955 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 956 | ALOGE("s_start_fm: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 957 | goto Error; |
| 958 | } |
| 959 | |
| 960 | err = setSoftwareParams(handle); |
| 961 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 962 | ALOGE("s_start_fm: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 963 | goto Error; |
| 964 | } |
| 965 | |
| 966 | err = pcm_prepare(handle->handle); |
| 967 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 968 | ALOGE("s_start_fm: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 969 | goto Error; |
| 970 | } |
| 971 | |
| 972 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 973 | ALOGE("s_start_fm: SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 974 | goto Error; |
| 975 | } |
| 976 | |
| 977 | // Store the PCM playback device pointer in rxHandle |
| 978 | handle->rxHandle = handle->handle; |
| 979 | free(devName); |
| 980 | |
| 981 | // Open PCM capture device |
| 982 | flags = PCM_IN | PCM_STEREO; |
| 983 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 984 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 985 | goto Error; |
| 986 | } |
| 987 | if (devName != NULL) { |
| 988 | handle->handle = pcm_open(flags, (char*)devName); |
| 989 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 990 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 991 | return NO_INIT; |
| 992 | } |
| 993 | if (!handle->handle) { |
| 994 | goto Error; |
| 995 | } |
| 996 | |
| 997 | handle->handle->flags = flags; |
| 998 | err = setHardwareParams(handle); |
| 999 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1000 | ALOGE("s_start_fm: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1001 | goto Error; |
| 1002 | } |
| 1003 | |
| 1004 | err = setSoftwareParams(handle); |
| 1005 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1006 | ALOGE("s_start_fm: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1007 | goto Error; |
| 1008 | } |
| 1009 | |
| 1010 | err = pcm_prepare(handle->handle); |
| 1011 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1012 | ALOGE("s_start_fm: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1013 | goto Error; |
| 1014 | } |
| 1015 | |
| 1016 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1017 | ALOGE("s_start_fm: SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1018 | goto Error; |
| 1019 | } |
| 1020 | |
| 1021 | s_set_fm_vol(fmVolume); |
| 1022 | free(devName); |
| 1023 | return NO_ERROR; |
| 1024 | |
| 1025 | Error: |
| 1026 | free(devName); |
| 1027 | s_close(handle); |
| 1028 | return NO_INIT; |
| 1029 | } |
| 1030 | |
| 1031 | static status_t s_set_fm_vol(int value) |
| 1032 | { |
| 1033 | status_t err = NO_ERROR; |
| 1034 | |
| 1035 | ALSAControl control("/dev/snd/controlC0"); |
| 1036 | control.set("Internal FM RX Volume",value,0); |
| 1037 | fmVolume = value; |
| 1038 | |
| 1039 | return err; |
| 1040 | } |
| 1041 | |
| 1042 | static status_t s_set_lpa_vol(int value) |
| 1043 | { |
| 1044 | status_t err = NO_ERROR; |
| 1045 | |
| 1046 | ALSAControl control("/dev/snd/controlC0"); |
| 1047 | control.set("LPA RX Volume",value,0); |
| 1048 | |
| 1049 | return err; |
| 1050 | } |
| 1051 | |
| 1052 | static status_t s_start(alsa_handle_t *handle) |
| 1053 | { |
| 1054 | status_t err = NO_ERROR; |
| 1055 | |
| 1056 | if(!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1057 | ALOGE("No active PCM driver to start"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1058 | return err; |
| 1059 | } |
| 1060 | |
| 1061 | err = pcm_prepare(handle->handle); |
| 1062 | |
| 1063 | return err; |
| 1064 | } |
| 1065 | |
| 1066 | static status_t s_close(alsa_handle_t *handle) |
| 1067 | { |
| 1068 | int ret; |
| 1069 | status_t err = NO_ERROR; |
| 1070 | struct pcm *h = handle->rxHandle; |
| 1071 | |
| 1072 | handle->rxHandle = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1073 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1074 | ALOGD("s_close: handle %p h %p", handle, h); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1075 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1076 | if (h) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1077 | ALOGV("s_close rxHandle\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1078 | err = pcm_close(h); |
| 1079 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1080 | ALOGE("s_close: pcm_close failed for rxHandle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | h = handle->handle; |
| 1085 | handle->handle = 0; |
| 1086 | |
| 1087 | if (h) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1088 | ALOGV("s_close handle h %p\n", h); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1089 | err = pcm_close(h); |
| 1090 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1091 | ALOGE("s_close: pcm_close failed for handle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | if ((!strcmp(handle->useCase, SND_USE_CASE_VERB_VOICECALL) || |
| 1095 | !strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_VOICE)) && |
| 1096 | platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1097 | #ifdef QCOM_CSDCLIENT_ENABLED |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 1098 | if (csd_stop_voice == NULL) { |
| 1099 | ALOGE("dlsym:Error:%s Loading csd_client_disable_device", dlerror()); |
| 1100 | } else { |
| 1101 | err = csd_stop_voice(); |
| 1102 | if (err < 0) { |
| 1103 | ALOGE("s_close: csd_client error %d\n", err); |
| 1104 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1105 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1106 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | disableDevice(handle); |
| 1110 | } else if((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 1111 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) || |
| 1112 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 1113 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))){ |
| 1114 | disableDevice(handle); |
| 1115 | } |
| 1116 | |
| 1117 | return err; |
| 1118 | } |
| 1119 | |
| 1120 | /* |
| 1121 | this is same as s_close, but don't discard |
| 1122 | the device/mode info. This way we can still |
| 1123 | close the device, hit idle and power-save, reopen the pcm |
| 1124 | for the same device/mode after resuming |
| 1125 | */ |
| 1126 | static status_t s_standby(alsa_handle_t *handle) |
| 1127 | { |
| 1128 | int ret; |
SathishKumar Mani | e42406e | 2012-08-29 16:25:54 -0700 | [diff] [blame] | 1129 | status_t err = NO_ERROR; |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1130 | struct pcm *h = handle->rxHandle; |
| 1131 | handle->rxHandle = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1132 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1133 | ALOGD("s_standby: handle %p h %p", handle, h); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1134 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1135 | if (h) { |
SathishKumar Mani | 0a01991 | 2012-09-11 12:33:11 -0700 | [diff] [blame] | 1136 | ALOGD("s_standby rxHandle\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1137 | err = pcm_close(h); |
| 1138 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1139 | ALOGE("s_standby: pcm_close failed for rxHandle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | h = handle->handle; |
| 1144 | handle->handle = 0; |
| 1145 | |
| 1146 | if (h) { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1147 | #if LOCAL_LOGD |
| 1148 | ALOGD("s_standby handle h %p\n", h); |
| 1149 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1150 | err = pcm_close(h); |
| 1151 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1152 | ALOGE("s_standby: pcm_close failed for handle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1153 | } |
| 1154 | disableDevice(handle); |
| 1155 | } else if((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 1156 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) || |
| 1157 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 1158 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))) { |
| 1159 | disableDevice(handle); |
| 1160 | } |
| 1161 | |
| 1162 | return err; |
| 1163 | } |
| 1164 | |
| 1165 | static status_t s_route(alsa_handle_t *handle, uint32_t devices, int mode) |
| 1166 | { |
| 1167 | status_t status = NO_ERROR; |
| 1168 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1169 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1170 | ALOGD("s_route: devices 0x%x in mode %d", devices, mode); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1171 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1172 | callMode = mode; |
| 1173 | switchDevice(handle, devices, mode); |
| 1174 | return status; |
| 1175 | } |
| 1176 | |
| 1177 | int getUseCaseType(const char *useCase) |
| 1178 | { |
SathishKumar Mani | 0a01991 | 2012-09-11 12:33:11 -0700 | [diff] [blame] | 1179 | ALOGD("use case is %s\n", useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1180 | if (!strncmp(useCase, SND_USE_CASE_VERB_HIFI, |
| 1181 | strlen(SND_USE_CASE_VERB_HIFI)) || |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 1182 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_LOWLATENCY_MUSIC, |
| 1183 | strlen(SND_USE_CASE_VERB_HIFI_LOWLATENCY_MUSIC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1184 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER, |
| 1185 | strlen(SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 1186 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_TUNNEL, |
| 1187 | strlen(SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 1188 | !strncmp(useCase, SND_USE_CASE_VERB_DIGITAL_RADIO, |
| 1189 | strlen(SND_USE_CASE_VERB_DIGITAL_RADIO)) || |
| 1190 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_MUSIC, |
| 1191 | strlen(SND_USE_CASE_MOD_PLAY_MUSIC)) || |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 1192 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_LOWLATENCY_MUSIC, |
| 1193 | strlen(SND_USE_CASE_MOD_PLAY_LOWLATENCY_MUSIC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1194 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_LPA, |
| 1195 | strlen(SND_USE_CASE_MOD_PLAY_LPA)) || |
| 1196 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_TUNNEL, |
| 1197 | strlen(SND_USE_CASE_MOD_PLAY_TUNNEL)) || |
| 1198 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_FM, |
| 1199 | strlen(SND_USE_CASE_MOD_PLAY_FM))) { |
| 1200 | return USECASE_TYPE_RX; |
| 1201 | } else if (!strncmp(useCase, SND_USE_CASE_VERB_HIFI_REC, |
| 1202 | strlen(SND_USE_CASE_VERB_HIFI_REC)) || |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 1203 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_LOWLATENCY_REC, |
| 1204 | strlen(SND_USE_CASE_VERB_HIFI_LOWLATENCY_REC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1205 | !strncmp(useCase, SND_USE_CASE_VERB_FM_REC, |
| 1206 | strlen(SND_USE_CASE_VERB_FM_REC)) || |
| 1207 | !strncmp(useCase, SND_USE_CASE_VERB_FM_A2DP_REC, |
| 1208 | strlen(SND_USE_CASE_VERB_FM_A2DP_REC)) || |
| 1209 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, |
| 1210 | strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC)) || |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 1211 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_LOWLATENCY_MUSIC, |
| 1212 | strlen(SND_USE_CASE_MOD_CAPTURE_LOWLATENCY_MUSIC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1213 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_FM, |
| 1214 | strlen(SND_USE_CASE_MOD_CAPTURE_FM)) || |
| 1215 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_A2DP_FM, |
| 1216 | strlen(SND_USE_CASE_MOD_CAPTURE_A2DP_FM))) { |
| 1217 | return USECASE_TYPE_TX; |
| 1218 | } else if (!strncmp(useCase, SND_USE_CASE_VERB_VOICECALL, |
| 1219 | strlen(SND_USE_CASE_VERB_VOICECALL)) || |
| 1220 | !strncmp(useCase, SND_USE_CASE_VERB_IP_VOICECALL, |
| 1221 | strlen(SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 1222 | !strncmp(useCase, SND_USE_CASE_VERB_DL_REC, |
| 1223 | strlen(SND_USE_CASE_VERB_DL_REC)) || |
| 1224 | !strncmp(useCase, SND_USE_CASE_VERB_UL_DL_REC, |
| 1225 | strlen(SND_USE_CASE_VERB_UL_DL_REC)) || |
| 1226 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_VOICE, |
| 1227 | strlen(SND_USE_CASE_MOD_PLAY_VOICE)) || |
| 1228 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_VOIP, |
| 1229 | strlen(SND_USE_CASE_MOD_PLAY_VOIP)) || |
| 1230 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_VOICE_DL, |
| 1231 | strlen(SND_USE_CASE_MOD_CAPTURE_VOICE_DL)) || |
| 1232 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_VOICE_UL_DL, |
| 1233 | strlen(SND_USE_CASE_MOD_CAPTURE_VOICE_UL_DL)) || |
| 1234 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_VOICE, |
| 1235 | strlen(SND_USE_CASE_MOD_CAPTURE_VOICE)) || |
| 1236 | !strncmp(useCase, SND_USE_CASE_VERB_VOLTE, |
| 1237 | strlen(SND_USE_CASE_VERB_VOLTE)) || |
| 1238 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_VOLTE, |
| 1239 | strlen(SND_USE_CASE_MOD_PLAY_VOLTE))) { |
| 1240 | return (USECASE_TYPE_RX | USECASE_TYPE_TX); |
| 1241 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1242 | ALOGE("unknown use case %s\n", useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1243 | return 0; |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | static void disableDevice(alsa_handle_t *handle) |
| 1248 | { |
| 1249 | unsigned usecase_type = 0; |
| 1250 | int i, mods_size; |
| 1251 | char *useCase; |
| 1252 | const char **mods_list; |
| 1253 | |
| 1254 | snd_use_case_get(handle->ucMgr, "_verb", (const char **)&useCase); |
| 1255 | if (useCase != NULL) { |
| 1256 | if (!strncmp(useCase, handle->useCase, MAX_UC_LEN)) { |
| 1257 | snd_use_case_set(handle->ucMgr, "_verb", SND_USE_CASE_VERB_INACTIVE); |
| 1258 | } else { |
| 1259 | snd_use_case_set(handle->ucMgr, "_dismod", handle->useCase); |
| 1260 | } |
| 1261 | free(useCase); |
| 1262 | snd_use_case_get(handle->ucMgr, "_verb", (const char **)&useCase); |
| 1263 | if (strncmp(useCase, SND_USE_CASE_VERB_INACTIVE, |
| 1264 | strlen(SND_USE_CASE_VERB_INACTIVE))) |
| 1265 | usecase_type |= getUseCaseType(useCase); |
| 1266 | mods_size = snd_use_case_get_list(handle->ucMgr, "_enamods", &mods_list); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1267 | #if LOCAL_LOGD |
| 1268 | ALOGD("Number of modifiers %d\n", mods_size); |
| 1269 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1270 | if (mods_size) { |
| 1271 | for(i = 0; i < mods_size; i++) { |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 1272 | #if LOCAL_LOGD |
| 1273 | ALOGD("index %d modifier %s\n", i, mods_list[i]); |
| 1274 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1275 | usecase_type |= getUseCaseType(mods_list[i]); |
| 1276 | } |
| 1277 | } |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1278 | #if LOCAL_LOGD |
| 1279 | ALOGD("usecase_type is %d\n", usecase_type); |
| 1280 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1281 | if (!(usecase_type & USECASE_TYPE_TX) && (strncmp(curTxUCMDevice, "None", 4))) |
| 1282 | snd_use_case_set(handle->ucMgr, "_disdev", curTxUCMDevice); |
| 1283 | if (!(usecase_type & USECASE_TYPE_RX) && (strncmp(curRxUCMDevice, "None", 4))) |
| 1284 | snd_use_case_set(handle->ucMgr, "_disdev", curRxUCMDevice); |
| 1285 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1286 | ALOGE("Invalid state, no valid use case found to disable"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1287 | } |
| 1288 | free(useCase); |
| 1289 | } |
| 1290 | |
| 1291 | char *getUCMDevice(uint32_t devices, int input, char *rxDevice) |
| 1292 | { |
| 1293 | if (!input) { |
| 1294 | if (!(mDevSettingsFlag & TTY_OFF) && |
| 1295 | (callMode == AudioSystem::MODE_IN_CALL) && |
| 1296 | ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1297 | (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE))) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1298 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1299 | || |
| 1300 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 1301 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE))) { |
| 1302 | #endif |
| 1303 | if (mDevSettingsFlag & TTY_VCO) { |
| 1304 | return strdup(SND_USE_CASE_DEV_TTY_HEADSET_RX); |
| 1305 | } else if (mDevSettingsFlag & TTY_FULL) { |
| 1306 | return strdup(SND_USE_CASE_DEV_TTY_FULL_RX); |
| 1307 | } else if (mDevSettingsFlag & TTY_HCO) { |
| 1308 | return strdup(SND_USE_CASE_DEV_TTY_HANDSET_RX); /* HANDSET RX */ |
| 1309 | } |
| 1310 | }else if ((devices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET) || |
| 1311 | (devices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)) { |
| 1312 | return strdup(SND_USE_CASE_DEV_PROXY_RX); /* PROXY RX */ |
| 1313 | } else if ((devices & AudioSystem::DEVICE_OUT_SPEAKER) && |
| 1314 | ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
| 1315 | (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE))) { |
| 1316 | if (mDevSettingsFlag & ANC_FLAG) { |
| 1317 | return strdup(SND_USE_CASE_DEV_SPEAKER_ANC_HEADSET); /* COMBO SPEAKER+ANC HEADSET RX */ |
| 1318 | } else { |
| 1319 | return strdup(SND_USE_CASE_DEV_SPEAKER_HEADSET); /* COMBO SPEAKER+HEADSET RX */ |
| 1320 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1321 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1322 | } else if ((devices & AudioSystem::DEVICE_OUT_SPEAKER) && |
| 1323 | ((devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 1324 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE))) { |
| 1325 | return strdup(SND_USE_CASE_DEV_SPEAKER_ANC_HEADSET); /* COMBO SPEAKER+ANC HEADSET RX */ |
| 1326 | } else if ((devices & AudioSystem::DEVICE_OUT_SPEAKER) && |
| 1327 | (devices & AudioSystem::DEVICE_OUT_FM_TX)) { |
| 1328 | return strdup(SND_USE_CASE_DEV_SPEAKER_FM_TX); /* COMBO SPEAKER+FM_TX RX */ |
| 1329 | #endif |
| 1330 | } else if (devices & AudioSystem::DEVICE_OUT_EARPIECE) { |
| 1331 | return strdup(SND_USE_CASE_DEV_EARPIECE); /* HANDSET RX */ |
| 1332 | } else if (devices & AudioSystem::DEVICE_OUT_SPEAKER) { |
| 1333 | return strdup(SND_USE_CASE_DEV_SPEAKER); /* SPEAKER RX */ |
| 1334 | } else if ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
| 1335 | (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE)) { |
| 1336 | if (mDevSettingsFlag & ANC_FLAG) { |
| 1337 | return strdup(SND_USE_CASE_DEV_ANC_HEADSET); /* ANC HEADSET RX */ |
| 1338 | } else { |
| 1339 | return strdup(SND_USE_CASE_DEV_HEADPHONES); /* HEADSET RX */ |
| 1340 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1341 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1342 | } else if ((devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 1343 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE)) { |
| 1344 | return strdup(SND_USE_CASE_DEV_ANC_HEADSET); /* ANC HEADSET RX */ |
| 1345 | #endif |
| 1346 | } else if ((devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO) || |
| 1347 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET) || |
| 1348 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT)) { |
| 1349 | if (btsco_samplerate == BTSCO_RATE_16KHZ) |
| 1350 | return strdup(SND_USE_CASE_DEV_BTSCO_WB_RX); /* BTSCO RX*/ |
| 1351 | else |
| 1352 | return strdup(SND_USE_CASE_DEV_BTSCO_NB_RX); /* BTSCO RX*/ |
| 1353 | } else if ((devices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP) || |
| 1354 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES) || |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1355 | #ifdef QCOM_VOIP_ENABLED |
| 1356 | (devices & AudioSystem::DEVICE_OUT_DIRECTOUTPUT) || |
| 1357 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1358 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)) { |
| 1359 | /* Nothing to be done, use current active device */ |
| 1360 | if (strncmp(curRxUCMDevice, "None", 4)) { |
| 1361 | return strdup(curRxUCMDevice); |
| 1362 | } |
| 1363 | } else if (devices & AudioSystem::DEVICE_OUT_AUX_DIGITAL) { |
| 1364 | return strdup(SND_USE_CASE_DEV_HDMI); /* HDMI RX */ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1365 | #ifdef QCOM_PROXY_DEVICE_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1366 | } else if (devices & AudioSystem::DEVICE_OUT_PROXY) { |
| 1367 | return strdup(SND_USE_CASE_DEV_PROXY_RX); /* PROXY RX */ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1368 | #endif |
| 1369 | #ifdef QCOM_FM_TX_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1370 | } else if (devices & AudioSystem::DEVICE_OUT_FM_TX) { |
| 1371 | return strdup(SND_USE_CASE_DEV_FM_TX); /* FM Tx */ |
| 1372 | #endif |
| 1373 | } else if (devices & AudioSystem::DEVICE_OUT_DEFAULT) { |
| 1374 | return strdup(SND_USE_CASE_DEV_SPEAKER); /* SPEAKER RX */ |
| 1375 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1376 | ALOGD("No valid output device: %u", devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1377 | } |
| 1378 | } else { |
| 1379 | if (!(mDevSettingsFlag & TTY_OFF) && |
| 1380 | (callMode == AudioSystem::MODE_IN_CALL) && |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1381 | ((devices & AudioSystem::DEVICE_IN_WIRED_HEADSET))) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1382 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1383 | ||(devices & AudioSystem::DEVICE_IN_ANC_HEADSET))) { |
| 1384 | #endif |
| 1385 | if (mDevSettingsFlag & TTY_HCO) { |
| 1386 | return strdup(SND_USE_CASE_DEV_TTY_HEADSET_TX); |
| 1387 | } else if (mDevSettingsFlag & TTY_FULL) { |
| 1388 | return strdup(SND_USE_CASE_DEV_TTY_FULL_TX); |
| 1389 | } else if (mDevSettingsFlag & TTY_VCO) { |
| 1390 | if (!strncmp(mic_type, "analog", 6)) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1391 | return strdup(SND_USE_CASE_DEV_TTY_HANDSET_ANALOG_TX); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1392 | } else { |
| 1393 | return strdup(SND_USE_CASE_DEV_TTY_HANDSET_TX); |
| 1394 | } |
| 1395 | } |
| 1396 | } else if (devices & AudioSystem::DEVICE_IN_BUILTIN_MIC) { |
| 1397 | if (!strncmp(mic_type, "analog", 6)) { |
| 1398 | return strdup(SND_USE_CASE_DEV_HANDSET); /* HANDSET TX */ |
| 1399 | } else { |
| 1400 | if (mDevSettingsFlag & DMIC_FLAG) { |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1401 | #ifdef USES_FLUENCE_INCALL |
| 1402 | if(callMode == AudioSystem::MODE_IN_CALL) { |
| 1403 | if (fluence_mode == FLUENCE_MODE_ENDFIRE) { |
| 1404 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_ENDFIRE); /* DUALMIC EF TX */ |
| 1405 | } else if (fluence_mode == FLUENCE_MODE_BROADSIDE) { |
| 1406 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_BROADSIDE); /* DUALMIC BS TX */ |
| 1407 | } else { |
| 1408 | return strdup(SND_USE_CASE_DEV_HANDSET); /* BUILTIN-MIC TX */ |
| 1409 | } |
| 1410 | } |
| 1411 | #else |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1412 | if (((rxDevice != NULL) && |
| 1413 | !strncmp(rxDevice, SND_USE_CASE_DEV_SPEAKER, |
| 1414 | (strlen(SND_USE_CASE_DEV_SPEAKER)+1))) || |
| 1415 | !strncmp(curRxUCMDevice, SND_USE_CASE_DEV_SPEAKER, |
| 1416 | (strlen(SND_USE_CASE_DEV_SPEAKER)+1))) { |
| 1417 | if (fluence_mode == FLUENCE_MODE_ENDFIRE) { |
| 1418 | return strdup(SND_USE_CASE_DEV_SPEAKER_DUAL_MIC_ENDFIRE); /* DUALMIC EF TX */ |
| 1419 | } else if (fluence_mode == FLUENCE_MODE_BROADSIDE) { |
| 1420 | return strdup(SND_USE_CASE_DEV_SPEAKER_DUAL_MIC_BROADSIDE); /* DUALMIC BS TX */ |
| 1421 | } |
| 1422 | } else { |
| 1423 | if (fluence_mode == FLUENCE_MODE_ENDFIRE) { |
| 1424 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_ENDFIRE); /* DUALMIC EF TX */ |
| 1425 | } else if (fluence_mode == FLUENCE_MODE_BROADSIDE) { |
| 1426 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_BROADSIDE); /* DUALMIC BS TX */ |
| 1427 | } |
| 1428 | } |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1429 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1430 | } else if (mDevSettingsFlag & QMIC_FLAG){ |
| 1431 | return strdup(SND_USE_CASE_DEV_QUAD_MIC); |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1432 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1433 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1434 | else if (mDevSettingsFlag & SSRQMIC_FLAG){ |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1435 | ALOGV("return SSRQMIC_FLAG: 0x%x devices:0x%x",mDevSettingsFlag,devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1436 | // Mapping for quad mic input device. |
| 1437 | return strdup(SND_USE_CASE_DEV_SSR_QUAD_MIC); /* SSR Quad MIC */ |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1438 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1439 | #endif |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 1440 | #ifdef SEPERATED_AUDIO_INPUT |
| 1441 | if(input_source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 1442 | ALOGV("getUCMdevice returned the VOICE_RECOGNITION UCM by input source = %d", input_source); |
| 1443 | return strdup(SND_USE_CASE_DEV_VOICE_RECOGNITION ); /* VOICE RECOGNITION TX */ |
| 1444 | } else if(input_source == AUDIO_SOURCE_CAMCORDER) { |
| 1445 | ALOGV("getUCMdevice returned the Camcorder Tx UCM by input source = %d", input_source); |
| 1446 | return strdup(SND_USE_CASE_DEV_CAMCORDER_TX ); /* CAMCORDER TX */ |
| 1447 | } |
| 1448 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1449 | else { |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 1450 | return strdup(SND_USE_CASE_DEV_HANDSET); /* BUILTIN-MIC TX */ |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | } else if (devices & AudioSystem::DEVICE_IN_AUX_DIGITAL) { |
| 1454 | return strdup(SND_USE_CASE_DEV_HDMI_TX); /* HDMI TX */ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1455 | #ifdef QCOM_ANC_HEADSET_ENABLED |
ehgrace.kim | 249f87d | 2012-08-12 20:40:32 -0700 | [diff] [blame] | 1456 | } else if (devices & AudioSystem::DEVICE_IN_ANC_HEADSET) { |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1457 | return strdup(SND_USE_CASE_DEV_HEADSET); /* HEADSET TX */ |
| 1458 | #endif |
ehgrace.kim | 249f87d | 2012-08-12 20:40:32 -0700 | [diff] [blame] | 1459 | } else if (devices & AudioSystem::DEVICE_IN_WIRED_HEADSET) { |
| 1460 | return strdup(SND_USE_CASE_DEV_HEADSET); /* HEADSET TX */ |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1461 | } else if (devices & AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
| 1462 | if (btsco_samplerate == BTSCO_RATE_16KHZ) |
| 1463 | return strdup(SND_USE_CASE_DEV_BTSCO_WB_TX); /* BTSCO TX*/ |
| 1464 | else |
| 1465 | return strdup(SND_USE_CASE_DEV_BTSCO_NB_TX); /* BTSCO TX*/ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1466 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1467 | } else if ((devices & AudioSystem::DEVICE_IN_ANLG_DOCK_HEADSET) || |
| 1468 | (devices & AudioSystem::DEVICE_IN_PROXY)) { |
| 1469 | return strdup(SND_USE_CASE_DEV_PROXY_TX); /* PROXY TX */ |
| 1470 | #endif |
| 1471 | } else if ((devices & AudioSystem::DEVICE_IN_COMMUNICATION) || |
| 1472 | (devices & AudioSystem::DEVICE_IN_VOICE_CALL)) { |
| 1473 | /* Nothing to be done, use current active device */ |
| 1474 | if (strncmp(curTxUCMDevice, "None", 4)) { |
| 1475 | return strdup(curTxUCMDevice); |
| 1476 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1477 | #ifdef QCOM_FM_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1478 | } else if ((devices & AudioSystem::DEVICE_IN_FM_RX) || |
| 1479 | (devices & AudioSystem::DEVICE_IN_FM_RX_A2DP)) { |
| 1480 | /* Nothing to be done, use current tx device or set dummy device */ |
| 1481 | if (strncmp(curTxUCMDevice, "None", 4)) { |
| 1482 | return strdup(curTxUCMDevice); |
| 1483 | } else { |
| 1484 | return strdup(SND_USE_CASE_DEV_DUMMY_TX); |
| 1485 | } |
| 1486 | #endif |
| 1487 | } else if ((devices & AudioSystem::DEVICE_IN_AMBIENT) || |
| 1488 | (devices & AudioSystem::DEVICE_IN_BACK_MIC)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1489 | ALOGI("No proper mapping found with UCM device list, setting default"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1490 | if (!strncmp(mic_type, "analog", 6)) { |
| 1491 | return strdup(SND_USE_CASE_DEV_HANDSET); /* HANDSET TX */ |
| 1492 | } else { |
| 1493 | return strdup(SND_USE_CASE_DEV_LINE); /* BUILTIN-MIC TX */ |
| 1494 | } |
| 1495 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1496 | ALOGD("No valid input device: %u", devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1497 | } |
| 1498 | } |
| 1499 | return NULL; |
| 1500 | } |
| 1501 | |
| 1502 | void s_set_voice_volume(int vol) |
| 1503 | { |
| 1504 | int err = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1505 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1506 | ALOGD("s_set_voice_volume: volume %d", vol); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1507 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1508 | ALSAControl control("/dev/snd/controlC0"); |
| 1509 | control.set("Voice Rx Volume", vol, 0); |
| 1510 | |
| 1511 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1512 | #ifdef QCOM_CSDCLIENT_ENABLED |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 1513 | if (csd_volume == NULL) { |
| 1514 | ALOGE("dlsym:Error:%s Loading csd_client_volume", dlerror()); |
| 1515 | } else { |
| 1516 | err = csd_volume(vol); |
| 1517 | if (err < 0) { |
| 1518 | ALOGE("s_set_voice_volume: csd_client error %d", err); |
| 1519 | } |
SathishKumar Mani | e42406e | 2012-08-29 16:25:54 -0700 | [diff] [blame] | 1520 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1521 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | void s_set_volte_volume(int vol) |
| 1526 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1527 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1528 | ALOGD("s_set_volte_volume: volume %d", vol); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1529 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1530 | ALSAControl control("/dev/snd/controlC0"); |
| 1531 | control.set("VoLTE Rx Volume", vol, 0); |
| 1532 | } |
| 1533 | |
| 1534 | |
| 1535 | void s_set_voip_volume(int vol) |
| 1536 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1537 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1538 | ALOGD("s_set_voip_volume: volume %d", vol); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1539 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1540 | ALSAControl control("/dev/snd/controlC0"); |
| 1541 | control.set("Voip Rx Volume", vol, 0); |
| 1542 | } |
| 1543 | void s_set_mic_mute(int state) |
| 1544 | { |
| 1545 | int err = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1546 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1547 | ALOGD("s_set_mic_mute: state %d", state); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1548 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1549 | ALSAControl control("/dev/snd/controlC0"); |
| 1550 | control.set("Voice Tx Mute", state, 0); |
| 1551 | |
| 1552 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1553 | #ifdef QCOM_CSDCLIENT_ENABLED |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 1554 | if (csd_mic_mute == NULL) { |
| 1555 | ALOGE("dlsym:Error:%s Loading csd_mic_mute", dlerror()); |
| 1556 | } else { |
| 1557 | err=csd_mic_mute(state); |
| 1558 | if (err < 0) { |
| 1559 | ALOGE("s_set_mic_mute: csd_client error %d", err); |
| 1560 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1561 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1562 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1563 | } |
| 1564 | } |
| 1565 | void s_set_volte_mic_mute(int state) |
| 1566 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1567 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1568 | ALOGD("s_set_volte_mic_mute: state %d", state); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1569 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1570 | ALSAControl control("/dev/snd/controlC0"); |
| 1571 | control.set("VoLTE Tx Mute", state, 0); |
| 1572 | } |
| 1573 | |
| 1574 | void s_set_voip_mic_mute(int state) |
| 1575 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1576 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1577 | ALOGD("s_set_voip_mic_mute: state %d", state); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1578 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1579 | ALSAControl control("/dev/snd/controlC0"); |
| 1580 | control.set("Voip Tx Mute", state, 0); |
| 1581 | } |
| 1582 | |
| 1583 | void s_set_voip_config(int mode, int rate) |
| 1584 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1585 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1586 | ALOGD("s_set_voip_config: mode %d,rate %d", mode, rate); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1587 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1588 | ALSAControl control("/dev/snd/controlC0"); |
| 1589 | char** setValues; |
| 1590 | setValues = (char**)malloc(2*sizeof(char*)); |
| 1591 | if (setValues == NULL) { |
| 1592 | return; |
| 1593 | } |
| 1594 | setValues[0] = (char*)malloc(4*sizeof(char)); |
| 1595 | if (setValues[0] == NULL) { |
| 1596 | free(setValues); |
| 1597 | return; |
| 1598 | } |
| 1599 | |
| 1600 | setValues[1] = (char*)malloc(8*sizeof(char)); |
| 1601 | if (setValues[1] == NULL) { |
| 1602 | free(setValues); |
| 1603 | free(setValues[0]); |
| 1604 | return; |
| 1605 | } |
| 1606 | |
| 1607 | sprintf(setValues[0], "%d",mode); |
| 1608 | sprintf(setValues[1], "%d",rate); |
| 1609 | |
| 1610 | control.setext("Voip Mode Rate Config", 2, setValues); |
| 1611 | free(setValues[1]); |
| 1612 | free(setValues[0]); |
| 1613 | free(setValues); |
| 1614 | return; |
| 1615 | } |
| 1616 | |
| 1617 | void s_set_btsco_rate(int rate) |
| 1618 | { |
| 1619 | btsco_samplerate = rate; |
| 1620 | } |
| 1621 | |
| 1622 | void s_enable_wide_voice(bool flag) |
| 1623 | { |
| 1624 | int err = 0; |
| 1625 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1626 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1627 | ALOGD("s_enable_wide_voice: flag %d", flag); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1628 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1629 | ALSAControl control("/dev/snd/controlC0"); |
| 1630 | if(flag == true) { |
| 1631 | control.set("Widevoice Enable", 1, 0); |
| 1632 | } else { |
| 1633 | control.set("Widevoice Enable", 0, 0); |
| 1634 | } |
| 1635 | |
| 1636 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1637 | #ifdef QCOM_CSDCLIENT_ENABLED |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 1638 | if (csd_wide_voice == NULL) { |
| 1639 | ALOGE("dlsym:Error:%s Loading csd_wide_voice", dlerror()); |
| 1640 | } else { |
| 1641 | err = csd_wide_voice(flag); |
| 1642 | if (err < 0) { |
| 1643 | ALOGE("enableWideVoice: csd_client_wide_voice error %d", err); |
| 1644 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1645 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1646 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1647 | } |
| 1648 | } |
| 1649 | |
| 1650 | void s_set_voc_rec_mode(uint8_t mode) |
| 1651 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1652 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1653 | ALOGD("s_set_voc_rec_mode: mode %d", mode); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1654 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1655 | ALSAControl control("/dev/snd/controlC0"); |
| 1656 | control.set("Incall Rec Mode", mode, 0); |
| 1657 | } |
| 1658 | |
| 1659 | void s_enable_fens(bool flag) |
| 1660 | { |
| 1661 | int err = 0; |
| 1662 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1663 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1664 | ALOGD("s_enable_fens: flag %d", flag); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1665 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1666 | ALSAControl control("/dev/snd/controlC0"); |
| 1667 | if(flag == true) { |
| 1668 | control.set("FENS Enable", 1, 0); |
| 1669 | } else { |
| 1670 | control.set("FENS Enable", 0, 0); |
| 1671 | } |
| 1672 | |
| 1673 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1674 | #ifdef QCOM_CSDCLIENT_ENABLED |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 1675 | if (csd_fens == NULL) { |
| 1676 | ALOGE("dlsym:Error:%s Loading csd_fens", dlerror()); |
| 1677 | } else { |
| 1678 | err = csd_fens(flag); |
| 1679 | if (err < 0) { |
| 1680 | ALOGE("s_enable_fens: csd_client error %d", err); |
| 1681 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1682 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1683 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | void s_enable_slow_talk(bool flag) |
| 1688 | { |
| 1689 | int err = 0; |
| 1690 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1691 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1692 | ALOGD("s_enable_slow_talk: flag %d", flag); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1693 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1694 | ALSAControl control("/dev/snd/controlC0"); |
| 1695 | if(flag == true) { |
| 1696 | control.set("Slowtalk Enable", 1, 0); |
| 1697 | } else { |
| 1698 | control.set("Slowtalk Enable", 0, 0); |
| 1699 | } |
| 1700 | |
| 1701 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1702 | #ifdef QCOM_CSDCLIENT_ENABLED |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 1703 | if (csd_slow_talk == NULL) { |
| 1704 | ALOGE("dlsym:Error:%s Loading csd_slow_talk", dlerror()); |
| 1705 | } else { |
| 1706 | err = csd_slow_talk(flag); |
| 1707 | if (err < 0) { |
| 1708 | ALOGE("s_enable_slow_talk: csd_client error %d", err); |
| 1709 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1710 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1711 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | void s_set_flags(uint32_t flags) |
| 1716 | { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1717 | ALOGV("s_set_flags: flags %d", flags); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1718 | mDevSettingsFlag = flags; |
| 1719 | } |
| 1720 | |
| 1721 | static status_t s_set_compressed_vol(int value) |
| 1722 | { |
| 1723 | status_t err = NO_ERROR; |
| 1724 | |
| 1725 | ALSAControl control("/dev/snd/controlC0"); |
| 1726 | control.set("COMPRESSED RX Volume",value,0); |
| 1727 | |
| 1728 | return err; |
| 1729 | } |
| 1730 | |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 1731 | #ifdef SEPERATED_AUDIO_INPUT |
| 1732 | void s_setInput(int input) |
| 1733 | { |
| 1734 | input_source = input; |
| 1735 | ALOGD("s_setInput() : input_source = %d",input_source); |
| 1736 | } |
| 1737 | #endif |
SathishKumar Mani | 5ff7a02 | 2012-09-14 11:36:35 -0700 | [diff] [blame] | 1738 | |
| 1739 | #ifdef QCOM_CSDCLIENT_ENABLED |
| 1740 | static void s_set_csd_handle(void* handle) |
| 1741 | { |
| 1742 | csd_handle = static_cast<void*>(handle); |
| 1743 | ALOGI("%s csd_handle: %p", __func__, csd_handle); |
| 1744 | |
| 1745 | csd_disable_device = (int (*)())::dlsym(csd_handle,"csd_client_disable_device"); |
| 1746 | csd_enable_device = (int (*)(int,int,uint32_t))::dlsym(csd_handle,"csd_client_enable_device"); |
| 1747 | csd_start_voice = (int (*)())::dlsym(csd_handle,"csd_client_start_voice"); |
| 1748 | csd_stop_voice = (int (*)())::dlsym(csd_handle,"csd_client_stop_voice"); |
| 1749 | csd_volume = (int (*)(int))::dlsym(csd_handle,"csd_client_volume"); |
| 1750 | csd_mic_mute = (int (*)(int))::dlsym(csd_handle,"csd_client_mic_mute"); |
| 1751 | csd_wide_voice = (int (*)(uint8_t))::dlsym(csd_handle,"csd_client_wide_voice"); |
| 1752 | csd_fens = (int (*)(uint8_t))::dlsym(csd_handle,"csd_client_fens"); |
| 1753 | csd_slow_talk = (int (*)(uint8_t))::dlsym(csd_handle,"csd_client_slow_talk"); |
| 1754 | } |
| 1755 | #endif |
| 1756 | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1757 | } |