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