Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 1 | /* hfp.c |
Banajit Goswami | 4c0dff2 | 2016-03-04 18:31:22 -0800 | [diff] [blame] | 2 | Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are |
| 6 | met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above |
| 10 | copyright notice, this list of conditions and the following |
| 11 | disclaimer in the documentation and/or other materials provided |
| 12 | with the distribution. |
| 13 | * Neither the name of The Linux Foundation nor the names of its |
| 14 | contributors may be used to endorse or promote products derived |
| 15 | from this software without specific prior written permission. |
| 16 | |
| 17 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ |
| 28 | |
| 29 | #define LOG_TAG "audio_hw_hfp" |
| 30 | /*#define LOG_NDEBUG 0*/ |
| 31 | #define LOG_NDDEBUG 0 |
| 32 | |
| 33 | #include <errno.h> |
| 34 | #include <math.h> |
| 35 | #include <cutils/log.h> |
| 36 | |
| 37 | #include "audio_hw.h" |
| 38 | #include "platform.h" |
| 39 | #include "platform_api.h" |
| 40 | #include <stdlib.h> |
| 41 | #include <cutils/str_parms.h> |
| 42 | |
| 43 | #ifdef HFP_ENABLED |
| 44 | #define AUDIO_PARAMETER_HFP_ENABLE "hfp_enable" |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 45 | #define AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE "hfp_set_sampling_rate" |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 46 | #define AUDIO_PARAMETER_KEY_HFP_VOLUME "hfp_volume" |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 47 | |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 48 | #ifdef PLATFORM_MSM8994 |
| 49 | #define HFP_RX_VOLUME "SEC AUXPCM LOOPBACK Volume" |
Banajit Goswami | da77c45 | 2015-10-14 20:45:22 -0700 | [diff] [blame] | 50 | #elif defined PLATFORM_MSM8996 |
| 51 | #define HFP_RX_VOLUME "PRI AUXPCM LOOPBACK Volume" |
Dhananjay Kumar | d3ab9f4 | 2016-07-20 17:05:47 +0530 | [diff] [blame] | 52 | #elif defined (PLATFORM_MSMCOBALT) || defined (PLATFORM_MSMFALCON) |
Banajit Goswami | 4c0dff2 | 2016-03-04 18:31:22 -0800 | [diff] [blame] | 53 | #define HFP_RX_VOLUME "SLIMBUS_7 LOOPBACK Volume" |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 54 | #else |
| 55 | #define HFP_RX_VOLUME "Internal HFP RX Volume" |
| 56 | #endif |
| 57 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 58 | static int32_t start_hfp(struct audio_device *adev, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 59 | struct str_parms *parms); |
| 60 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 61 | static int32_t stop_hfp(struct audio_device *adev); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 62 | |
| 63 | struct hfp_module { |
| 64 | struct pcm *hfp_sco_rx; |
| 65 | struct pcm *hfp_sco_tx; |
| 66 | struct pcm *hfp_pcm_rx; |
| 67 | struct pcm *hfp_pcm_tx; |
| 68 | bool is_hfp_running; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 69 | float hfp_volume; |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 70 | audio_usecase_t ucid; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | static struct hfp_module hfpmod = { |
| 74 | .hfp_sco_rx = NULL, |
| 75 | .hfp_sco_tx = NULL, |
| 76 | .hfp_pcm_rx = NULL, |
| 77 | .hfp_pcm_tx = NULL, |
| 78 | .hfp_volume = 0, |
| 79 | .is_hfp_running = 0, |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 80 | .ucid = USECASE_AUDIO_HFP_SCO, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 81 | }; |
| 82 | static struct pcm_config pcm_config_hfp = { |
| 83 | .channels = 1, |
| 84 | .rate = 8000, |
| 85 | .period_size = 240, |
| 86 | .period_count = 2, |
| 87 | .format = PCM_FORMAT_S16_LE, |
| 88 | .start_threshold = 0, |
| 89 | .stop_threshold = INT_MAX, |
| 90 | .avail_min = 0, |
| 91 | }; |
| 92 | |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 93 | static int32_t hfp_set_volume(struct audio_device *adev, float value) |
| 94 | { |
| 95 | int32_t vol, ret = 0; |
| 96 | struct mixer_ctl *ctl; |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 97 | const char *mixer_ctl_name = HFP_RX_VOLUME; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 98 | |
| 99 | ALOGV("%s: entry", __func__); |
| 100 | ALOGD("%s: (%f)\n", __func__, value); |
| 101 | |
Satya Krishna Pindiproli | 3ed6d79 | 2014-09-09 15:32:25 +0530 | [diff] [blame] | 102 | hfpmod.hfp_volume = value; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 103 | if (value < 0.0) { |
| 104 | ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value); |
| 105 | value = 0.0; |
| 106 | } else { |
| 107 | value = ((value > 15.000000) ? 1.0 : (value / 15)); |
| 108 | ALOGW("%s: Volume brought with in range (%f)\n", __func__, value); |
| 109 | } |
| 110 | vol = lrint((value * 0x2000) + 0.5); |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 111 | |
| 112 | if (!hfpmod.is_hfp_running) { |
| 113 | ALOGV("%s: HFP not active, ignoring set_hfp_volume call", __func__); |
| 114 | return -EIO; |
| 115 | } |
| 116 | |
| 117 | ALOGD("%s: Setting HFP volume to %d \n", __func__, vol); |
| 118 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 119 | if (!ctl) { |
| 120 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 121 | __func__, mixer_ctl_name); |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | if(mixer_ctl_set_value(ctl, 0, vol) < 0) { |
| 125 | ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, vol); |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | |
| 129 | ALOGV("%s: exit", __func__); |
| 130 | return ret; |
| 131 | } |
| 132 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 133 | static int32_t start_hfp(struct audio_device *adev, |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 134 | struct str_parms *parms __unused) |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 135 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 136 | int32_t ret = 0; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 137 | struct audio_usecase *uc_info; |
| 138 | int32_t pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, pcm_dev_asm_tx_id; |
| 139 | |
| 140 | ALOGD("%s: enter", __func__); |
| 141 | |
| 142 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 143 | |
| 144 | if (!uc_info) |
| 145 | return -ENOMEM; |
| 146 | |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 147 | uc_info->id = hfpmod.ucid; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 148 | uc_info->type = PCM_HFP_CALL; |
| 149 | uc_info->stream.out = adev->primary_output; |
| 150 | uc_info->devices = adev->primary_output->devices; |
| 151 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 152 | uc_info->out_snd_device = SND_DEVICE_NONE; |
| 153 | |
| 154 | list_add_tail(&adev->usecase_list, &uc_info->list); |
| 155 | |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 156 | select_devices(adev, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 157 | |
| 158 | pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK); |
| 159 | pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE); |
| 160 | pcm_dev_asm_rx_id = HFP_ASM_RX_TX; |
| 161 | pcm_dev_asm_tx_id = HFP_ASM_RX_TX; |
| 162 | if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0 || |
| 163 | pcm_dev_asm_rx_id < 0 || pcm_dev_asm_tx_id < 0 ) { |
| 164 | ALOGE("%s: Invalid PCM devices (rx: %d tx: %d asm: rx tx %d) for the usecase(%d)", |
| 165 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, uc_info->id); |
| 166 | ret = -EIO; |
| 167 | goto exit; |
| 168 | } |
| 169 | |
| 170 | ALOGV("%s: HFP PCM devices (hfp rx tx: %d pcm rx tx: %d) for the usecase(%d)", |
| 171 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id); |
| 172 | |
| 173 | ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 174 | __func__, adev->snd_card, pcm_dev_rx_id); |
| 175 | hfpmod.hfp_sco_rx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 176 | pcm_dev_asm_rx_id, |
| 177 | PCM_OUT, &pcm_config_hfp); |
| 178 | if (hfpmod.hfp_sco_rx && !pcm_is_ready(hfpmod.hfp_sco_rx)) { |
| 179 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_rx)); |
| 180 | ret = -EIO; |
| 181 | goto exit; |
| 182 | } |
| 183 | ALOGD("%s: Opening PCM capture device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 184 | __func__, adev->snd_card, pcm_dev_tx_id); |
| 185 | hfpmod.hfp_pcm_rx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 186 | pcm_dev_rx_id, |
| 187 | PCM_OUT, &pcm_config_hfp); |
| 188 | if (hfpmod.hfp_pcm_rx && !pcm_is_ready(hfpmod.hfp_pcm_rx)) { |
| 189 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_rx)); |
| 190 | ret = -EIO; |
| 191 | goto exit; |
| 192 | } |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 193 | hfpmod.hfp_sco_tx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 194 | pcm_dev_asm_tx_id, |
| 195 | PCM_IN, &pcm_config_hfp); |
| 196 | if (hfpmod.hfp_sco_tx && !pcm_is_ready(hfpmod.hfp_sco_tx)) { |
| 197 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_tx)); |
| 198 | ret = -EIO; |
| 199 | goto exit; |
| 200 | } |
| 201 | ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 202 | __func__, adev->snd_card, pcm_dev_tx_id); |
| 203 | hfpmod.hfp_pcm_tx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 204 | pcm_dev_tx_id, |
| 205 | PCM_IN, &pcm_config_hfp); |
| 206 | if (hfpmod.hfp_pcm_tx && !pcm_is_ready(hfpmod.hfp_pcm_tx)) { |
| 207 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_tx)); |
| 208 | ret = -EIO; |
| 209 | goto exit; |
| 210 | } |
Satya Krishna Pindiproli | ce903a0 | 2014-07-28 12:40:56 +0530 | [diff] [blame] | 211 | if (pcm_start(hfpmod.hfp_sco_rx) < 0) { |
| 212 | ALOGE("%s: pcm start for hfp sco rx failed", __func__); |
| 213 | ret = -EINVAL; |
| 214 | goto exit; |
| 215 | } |
| 216 | if (pcm_start(hfpmod.hfp_sco_tx) < 0) { |
| 217 | ALOGE("%s: pcm start for hfp sco tx failed", __func__); |
| 218 | ret = -EINVAL; |
| 219 | goto exit; |
| 220 | } |
| 221 | if (pcm_start(hfpmod.hfp_pcm_rx) < 0) { |
| 222 | ALOGE("%s: pcm start for hfp pcm rx failed", __func__); |
| 223 | ret = -EINVAL; |
| 224 | goto exit; |
| 225 | } |
| 226 | if (pcm_start(hfpmod.hfp_pcm_tx) < 0) { |
| 227 | ALOGE("%s: pcm start for hfp pcm tx failed", __func__); |
| 228 | ret = -EINVAL; |
| 229 | goto exit; |
| 230 | } |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 231 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 232 | hfpmod.is_hfp_running = true; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 233 | hfp_set_volume(adev, hfpmod.hfp_volume); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 234 | |
| 235 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 236 | return 0; |
| 237 | |
| 238 | exit: |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 239 | stop_hfp(adev); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 240 | ALOGE("%s: Problem in HFP start: status(%d)", __func__, ret); |
| 241 | return ret; |
| 242 | } |
| 243 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 244 | static int32_t stop_hfp(struct audio_device *adev) |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 245 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 246 | int32_t ret = 0; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 247 | struct audio_usecase *uc_info; |
| 248 | |
| 249 | ALOGD("%s: enter", __func__); |
| 250 | hfpmod.is_hfp_running = false; |
| 251 | |
| 252 | /* 1. Close the PCM devices */ |
| 253 | if (hfpmod.hfp_sco_rx) { |
| 254 | pcm_close(hfpmod.hfp_sco_rx); |
| 255 | hfpmod.hfp_sco_rx = NULL; |
| 256 | } |
| 257 | if (hfpmod.hfp_sco_tx) { |
| 258 | pcm_close(hfpmod.hfp_sco_tx); |
| 259 | hfpmod.hfp_sco_tx = NULL; |
| 260 | } |
| 261 | if (hfpmod.hfp_pcm_rx) { |
| 262 | pcm_close(hfpmod.hfp_pcm_rx); |
| 263 | hfpmod.hfp_pcm_rx = NULL; |
| 264 | } |
| 265 | if (hfpmod.hfp_pcm_tx) { |
| 266 | pcm_close(hfpmod.hfp_pcm_tx); |
| 267 | hfpmod.hfp_pcm_tx = NULL; |
| 268 | } |
| 269 | |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 270 | uc_info = get_usecase_from_list(adev, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 271 | if (uc_info == NULL) { |
| 272 | ALOGE("%s: Could not find the usecase (%d) in the list", |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 273 | __func__, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 274 | return -EINVAL; |
| 275 | } |
| 276 | |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 277 | /* 2. Disable echo reference while stopping hfp */ |
Apoorv Raghuvanshi | 924b302 | 2015-07-06 15:07:14 -0700 | [diff] [blame] | 278 | platform_set_echo_reference(adev, false, uc_info->devices); |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 279 | |
| 280 | /* 3. Get and set stream specific mixer controls */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 281 | disable_audio_route(adev, uc_info); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 282 | |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 283 | /* 4. Disable the rx and tx devices */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 284 | disable_snd_device(adev, uc_info->out_snd_device); |
| 285 | disable_snd_device(adev, uc_info->in_snd_device); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 286 | |
| 287 | list_remove(&uc_info->list); |
| 288 | free(uc_info); |
| 289 | |
| 290 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 291 | return ret; |
| 292 | } |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 293 | |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 294 | bool audio_extn_hfp_is_active(struct audio_device *adev) |
| 295 | { |
| 296 | struct audio_usecase *hfp_usecase = NULL; |
Vimal Puthanveed | 41fcff2 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 297 | hfp_usecase = get_usecase_from_list(adev, hfpmod.ucid); |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 298 | |
| 299 | if (hfp_usecase != NULL) |
| 300 | return true; |
| 301 | else |
| 302 | return false; |
| 303 | } |
| 304 | |
Vimal Puthanveed | 41fcff2 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 305 | audio_usecase_t audio_extn_hfp_get_usecase() |
| 306 | { |
| 307 | return hfpmod.ucid; |
| 308 | } |
| 309 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 310 | void audio_extn_hfp_set_parameters(struct audio_device *adev, struct str_parms *parms) |
| 311 | { |
| 312 | int ret; |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 313 | int rate; |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 314 | int val; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 315 | float vol; |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 316 | char value[32]={0}; |
| 317 | |
| 318 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_ENABLE, value, |
| 319 | sizeof(value)); |
| 320 | if (ret >= 0) { |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 321 | if (!strncmp(value,"true",sizeof(value))) |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 322 | ret = start_hfp(adev,parms); |
| 323 | else |
| 324 | stop_hfp(adev); |
| 325 | } |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 326 | memset(value, 0, sizeof(value)); |
| 327 | ret = str_parms_get_str(parms,AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE, value, |
| 328 | sizeof(value)); |
| 329 | if (ret >= 0) { |
| 330 | rate = atoi(value); |
| 331 | if (rate == 8000){ |
| 332 | hfpmod.ucid = USECASE_AUDIO_HFP_SCO; |
| 333 | pcm_config_hfp.rate = rate; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 334 | } else if (rate == 16000){ |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 335 | hfpmod.ucid = USECASE_AUDIO_HFP_SCO_WB; |
| 336 | pcm_config_hfp.rate = rate; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 337 | } else |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 338 | ALOGE("Unsupported rate.."); |
| 339 | } |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 340 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 341 | if (hfpmod.is_hfp_running) { |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 342 | memset(value, 0, sizeof(value)); |
| 343 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, |
| 344 | value, sizeof(value)); |
| 345 | if (ret >= 0) { |
| 346 | val = atoi(value); |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 347 | if (val > 0) |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 348 | select_devices(adev, hfpmod.ucid); |
| 349 | } |
| 350 | } |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 351 | |
| 352 | memset(value, 0, sizeof(value)); |
| 353 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HFP_VOLUME, |
| 354 | value, sizeof(value)); |
| 355 | if (ret >= 0) { |
| 356 | if (sscanf(value, "%f", &vol) != 1){ |
| 357 | ALOGE("%s: error in retrieving hfp volume", __func__); |
| 358 | ret = -EIO; |
| 359 | goto exit; |
| 360 | } |
| 361 | ALOGD("%s: set_hfp_volume usecase, Vol: [%f]", __func__, vol); |
| 362 | hfp_set_volume(adev, vol); |
| 363 | } |
| 364 | exit: |
| 365 | ALOGV("%s Exit",__func__); |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 366 | } |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 367 | #endif /*HFP_ENABLED*/ |