Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1 | /* |
Naresh Tanniru | ed694c8 | 2017-02-07 17:01:28 +0530 | [diff] [blame^] | 2 | * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [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 "split_a2dp" |
| 30 | /*#define LOG_NDEBUG 0*/ |
| 31 | #define LOG_NDDEBUG 0 |
| 32 | #include <errno.h> |
| 33 | #include <cutils/log.h> |
| 34 | #include <dlfcn.h> |
| 35 | #include "audio_hw.h" |
| 36 | #include "platform.h" |
| 37 | #include "platform_api.h" |
| 38 | #include <stdlib.h> |
| 39 | #include <cutils/str_parms.h> |
| 40 | #include <hardware/audio.h> |
| 41 | #include <hardware/hardware.h> |
| 42 | #include <cutils/properties.h> |
| 43 | |
| 44 | #ifdef SPLIT_A2DP_ENABLED |
| 45 | #define AUDIO_PARAMETER_A2DP_STARTED "A2dpStarted" |
| 46 | #define BT_IPC_LIB_NAME "libbthost_if.so" |
| 47 | #define ENC_MEDIA_FMT_NONE 0 |
| 48 | #define ENC_MEDIA_FMT_AAC 0x00010DA6 |
| 49 | #define ENC_MEDIA_FMT_APTX 0x000131ff |
| 50 | #define ENC_MEDIA_FMT_APTX_HD 0x00013200 |
| 51 | #define ENC_MEDIA_FMT_SBC 0x00010BF2 |
| 52 | #define MEDIA_FMT_AAC_AOT_LC 2 |
| 53 | #define MEDIA_FMT_AAC_AOT_SBR 5 |
| 54 | #define MEDIA_FMT_AAC_AOT_PS 29 |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 55 | #define PCM_CHANNEL_L 1 |
| 56 | #define PCM_CHANNEL_R 2 |
| 57 | #define PCM_CHANNEL_C 3 |
| 58 | #define MEDIA_FMT_SBC_CHANNEL_MODE_MONO 1 |
| 59 | #define MEDIA_FMT_SBC_CHANNEL_MODE_STEREO 2 |
| 60 | #define MEDIA_FMT_SBC_CHANNEL_MODE_DUAL_MONO 8 |
| 61 | #define MEDIA_FMT_SBC_CHANNEL_MODE_JOINT_STEREO 9 |
| 62 | #define MEDIA_FMT_SBC_ALLOCATION_METHOD_LOUDNESS 0 |
| 63 | #define MEDIA_FMT_SBC_ALLOCATION_METHOD_SNR 1 |
| 64 | #define MIXER_ENC_CONFIG_BLOCK "SLIM_7_RX Encoder Config" |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 65 | #define MIXER_ENC_BIT_FORMAT "AFE Input Bit Format" |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 66 | #define MIXER_ENC_FMT_SBC "SBC" |
| 67 | #define MIXER_ENC_FMT_AAC "AAC" |
| 68 | #define MIXER_ENC_FMT_APTX "APTX" |
| 69 | #define MIXER_ENC_FMT_APTXHD "APTXHD" |
| 70 | #define MIXER_ENC_FMT_NONE "NONE" |
| 71 | |
| 72 | |
| 73 | typedef int (*audio_stream_open_t)(void); |
| 74 | typedef int (*audio_stream_close_t)(void); |
| 75 | typedef int (*audio_start_stream_t)(void); |
| 76 | typedef int (*audio_stop_stream_t)(void); |
| 77 | typedef int (*audio_suspend_stream_t)(void); |
| 78 | typedef void (*audio_handoff_triggered_t)(void); |
| 79 | typedef void (*clear_a2dpsuspend_flag_t)(void); |
| 80 | typedef void * (*audio_get_codec_config_t)(uint8_t *multicast_status,uint8_t *num_dev, |
| 81 | audio_format_t *codec_type); |
| 82 | |
| 83 | enum A2DP_STATE { |
| 84 | A2DP_STATE_CONNECTED, |
| 85 | A2DP_STATE_STARTED, |
| 86 | A2DP_STATE_STOPPED, |
| 87 | A2DP_STATE_DISCONNECTED, |
| 88 | }; |
| 89 | |
| 90 | /* structure used to update a2dp state machine |
| 91 | * to communicate IPC library |
| 92 | * to store DSP encoder configuration information |
| 93 | */ |
| 94 | struct a2dp_data { |
| 95 | struct audio_device *adev; |
| 96 | void *bt_lib_handle; |
| 97 | audio_stream_open_t audio_stream_open; |
| 98 | audio_stream_close_t audio_stream_close; |
| 99 | audio_start_stream_t audio_start_stream; |
| 100 | audio_stop_stream_t audio_stop_stream; |
| 101 | audio_suspend_stream_t audio_suspend_stream; |
| 102 | audio_handoff_triggered_t audio_handoff_triggered; |
| 103 | clear_a2dpsuspend_flag_t clear_a2dpsuspend_flag; |
| 104 | audio_get_codec_config_t audio_get_codec_config; |
| 105 | enum A2DP_STATE bt_state; |
| 106 | audio_format_t bt_encoder_format; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 107 | uint32_t enc_sampling_rate; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 108 | bool a2dp_started; |
| 109 | bool a2dp_suspended; |
| 110 | int a2dp_total_active_session_request; |
| 111 | bool is_a2dp_offload_supported; |
| 112 | bool is_handoff_in_progress; |
| 113 | }; |
| 114 | |
| 115 | struct a2dp_data a2dp; |
| 116 | |
| 117 | /* START of DSP configurable structures |
| 118 | * These values should match with DSP interface defintion |
| 119 | */ |
| 120 | |
| 121 | /* AAC encoder configuration structure. */ |
| 122 | typedef struct aac_enc_cfg_t aac_enc_cfg_t; |
| 123 | |
| 124 | /* supported enc_mode are AAC_LC, AAC_SBR, AAC_PS |
| 125 | * supported aac_fmt_flag are ADTS/RAW |
| 126 | * supported channel_cfg are Native mode, Mono , Stereo |
| 127 | */ |
| 128 | struct aac_enc_cfg_t { |
| 129 | uint32_t enc_format; |
| 130 | uint32_t bit_rate; |
| 131 | uint32_t enc_mode; |
| 132 | uint16_t aac_fmt_flag; |
Naresh Tanniru | a42d0bd | 2016-09-21 15:30:46 +0530 | [diff] [blame] | 133 | uint16_t channel_cfg; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 134 | uint32_t sample_rate; |
| 135 | } ; |
| 136 | |
| 137 | /* SBC encoder configuration structure. */ |
| 138 | typedef struct sbc_enc_cfg_t sbc_enc_cfg_t; |
| 139 | |
| 140 | /* supported num_subbands are 4/8 |
| 141 | * supported blk_len are 4, 8, 12, 16 |
| 142 | * supported channel_mode are MONO, STEREO, DUAL_MONO, JOINT_STEREO |
| 143 | * supported alloc_method are LOUNDNESS/SNR |
| 144 | * supported bit_rate for mono channel is max 320kbps |
| 145 | * supported bit rate for stereo channel is max 512 kbps |
| 146 | */ |
| 147 | struct sbc_enc_cfg_t{ |
| 148 | uint32_t enc_format; |
| 149 | uint32_t num_subbands; |
| 150 | uint32_t blk_len; |
| 151 | uint32_t channel_mode; |
| 152 | uint32_t alloc_method; |
| 153 | uint32_t bit_rate; |
| 154 | uint32_t sample_rate; |
| 155 | }; |
| 156 | |
| 157 | |
| 158 | /* supported num_channels are Mono/Stereo |
| 159 | * supported channel_mapping for mono is CHANNEL_C |
| 160 | * supported channel mapping for stereo is CHANNEL_L and CHANNEL_R |
| 161 | * custom size and reserved are not used(for future enhancement) |
| 162 | */ |
| 163 | struct custom_enc_cfg_aptx_t |
| 164 | { |
| 165 | uint32_t enc_format; |
| 166 | uint32_t sample_rate; |
| 167 | uint16_t num_channels; |
| 168 | uint16_t reserved; |
| 169 | uint8_t channel_mapping[8]; |
| 170 | uint32_t custom_size; |
| 171 | }; |
| 172 | |
| 173 | /*********** END of DSP configurable structures ********************/ |
| 174 | |
| 175 | /* API to identify DSP encoder captabilities */ |
| 176 | static void a2dp_offload_codec_cap_parser(char *value) |
| 177 | { |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 178 | char *tok = NULL,*saveptr; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 179 | |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 180 | tok = strtok_r(value, "-", &saveptr); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 181 | while (tok != NULL) { |
| 182 | if (strcmp(tok, "sbc") == 0) { |
| 183 | ALOGD("%s: SBC offload supported\n",__func__); |
| 184 | a2dp.is_a2dp_offload_supported = true; |
| 185 | break; |
| 186 | } else if (strcmp(tok, "aptx") == 0) { |
| 187 | ALOGD("%s: aptx offload supported\n",__func__); |
| 188 | a2dp.is_a2dp_offload_supported = true; |
| 189 | break; |
Naresh Tanniru | ed694c8 | 2017-02-07 17:01:28 +0530 | [diff] [blame^] | 190 | } else if (strcmp(tok, "aptxhd") == 0) { |
| 191 | ALOGD("%s: aptx HD offload supported\n",__func__); |
| 192 | a2dp.is_a2dp_offload_supported = true; |
| 193 | break; |
| 194 | } else if (strcmp(tok, "aac") == 0) { |
| 195 | ALOGD("%s: aac offload supported\n",__func__); |
| 196 | a2dp.is_a2dp_offload_supported = true; |
| 197 | break; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 198 | } |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 199 | tok = strtok_r(NULL, "-", &saveptr); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 200 | }; |
| 201 | } |
| 202 | |
| 203 | static void update_offload_codec_capabilities() |
| 204 | { |
| 205 | char value[PROPERTY_VALUE_MAX] = {'\0'}; |
| 206 | |
| 207 | property_get("persist.bt.a2dp_offload_cap", value, "false"); |
| 208 | ALOGD("get_offload_codec_capabilities = %s",value); |
| 209 | a2dp.is_a2dp_offload_supported = |
| 210 | property_get_bool("persist.bt.a2dp_offload_cap", false); |
| 211 | if (strcmp(value, "false") != 0) |
| 212 | a2dp_offload_codec_cap_parser(value); |
| 213 | ALOGD("%s: codec cap = %s",__func__,value); |
| 214 | } |
| 215 | |
| 216 | /* API to open BT IPC library to start IPC communication */ |
| 217 | static void open_a2dp_output() |
| 218 | { |
| 219 | int ret = 0; |
| 220 | |
| 221 | ALOGD(" Open A2DP output start "); |
| 222 | if (a2dp.bt_lib_handle == NULL){ |
| 223 | ALOGD(" Requesting for BT lib handle"); |
| 224 | a2dp.bt_lib_handle = dlopen(BT_IPC_LIB_NAME, RTLD_NOW); |
| 225 | |
| 226 | if (a2dp.bt_lib_handle == NULL) { |
| 227 | ALOGE("%s: DLOPEN failed for %s", __func__, BT_IPC_LIB_NAME); |
| 228 | ret = -ENOSYS; |
| 229 | goto init_fail; |
| 230 | } else { |
| 231 | a2dp.audio_stream_open = (audio_stream_open_t) |
| 232 | dlsym(a2dp.bt_lib_handle, "audio_stream_open"); |
| 233 | a2dp.audio_start_stream = (audio_start_stream_t) |
| 234 | dlsym(a2dp.bt_lib_handle, "audio_start_stream"); |
| 235 | a2dp.audio_get_codec_config = (audio_get_codec_config_t) |
| 236 | dlsym(a2dp.bt_lib_handle, "audio_get_codec_config"); |
| 237 | a2dp.audio_suspend_stream = (audio_suspend_stream_t) |
| 238 | dlsym(a2dp.bt_lib_handle, "audio_suspend_stream"); |
| 239 | a2dp.audio_handoff_triggered = (audio_handoff_triggered_t) |
| 240 | dlsym(a2dp.bt_lib_handle, "audio_handoff_triggered"); |
| 241 | a2dp.clear_a2dpsuspend_flag = (clear_a2dpsuspend_flag_t) |
| 242 | dlsym(a2dp.bt_lib_handle, "clear_a2dpsuspend_flag"); |
| 243 | a2dp.audio_stop_stream = (audio_stop_stream_t) |
| 244 | dlsym(a2dp.bt_lib_handle, "audio_stop_stream"); |
| 245 | a2dp.audio_stream_close = (audio_stream_close_t) |
| 246 | dlsym(a2dp.bt_lib_handle, "audio_stream_close"); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if (a2dp.bt_lib_handle && a2dp.audio_stream_open) { |
| 251 | if (a2dp.bt_state == A2DP_STATE_DISCONNECTED) { |
| 252 | ALOGD("calling BT stream open"); |
| 253 | ret = a2dp.audio_stream_open(); |
| 254 | if(ret != 0) { |
| 255 | ALOGE("Failed to open output stream for a2dp: status %d", ret); |
| 256 | goto init_fail; |
| 257 | } |
| 258 | a2dp.bt_state = A2DP_STATE_CONNECTED; |
| 259 | } else { |
| 260 | ALOGD("Called a2dp open with improper state, Ignoring request state %d", a2dp.bt_state); |
| 261 | } |
| 262 | } else { |
| 263 | ALOGE("a2dp handle is not identified, Ignoring open request"); |
| 264 | a2dp.bt_state = A2DP_STATE_DISCONNECTED; |
| 265 | goto init_fail; |
| 266 | } |
| 267 | |
| 268 | init_fail: |
| 269 | if(ret != 0 && (a2dp.bt_lib_handle != NULL)) { |
| 270 | dlclose(a2dp.bt_lib_handle); |
| 271 | a2dp.bt_lib_handle = NULL; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | static int close_a2dp_output() |
| 276 | { |
| 277 | ALOGV("%s\n",__func__); |
| 278 | if (!(a2dp.bt_lib_handle && a2dp.audio_stream_close)) { |
| 279 | ALOGE("a2dp handle is not identified, Ignoring close request"); |
| 280 | return -ENOSYS; |
| 281 | } |
| 282 | if ((a2dp.bt_state == A2DP_STATE_CONNECTED) && |
| 283 | (a2dp.bt_state == A2DP_STATE_STARTED) && |
| 284 | (a2dp.bt_state == A2DP_STATE_STOPPED)) { |
| 285 | ALOGD("calling BT stream close"); |
| 286 | if(a2dp.audio_stream_close() == false) |
| 287 | ALOGE("failed close a2dp control path from BT library"); |
| 288 | a2dp.a2dp_started = false; |
| 289 | a2dp.a2dp_total_active_session_request = 0; |
| 290 | a2dp.a2dp_suspended = false; |
| 291 | a2dp.bt_encoder_format = AUDIO_FORMAT_INVALID; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 292 | a2dp.enc_sampling_rate = 48000; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 293 | a2dp.bt_state = A2DP_STATE_DISCONNECTED; |
| 294 | } else { |
| 295 | ALOGD("close a2dp called in improper state"); |
| 296 | a2dp.a2dp_started = false; |
| 297 | a2dp.a2dp_total_active_session_request = 0; |
| 298 | a2dp.a2dp_suspended = false; |
| 299 | a2dp.bt_encoder_format = AUDIO_FORMAT_INVALID; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 300 | a2dp.enc_sampling_rate = 48000; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 301 | a2dp.bt_state = A2DP_STATE_DISCONNECTED; |
| 302 | } |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | /* API to configure SBC DSP encoder */ |
| 308 | bool configure_sbc_enc_format(audio_sbc_encoder_config *sbc_bt_cfg) |
| 309 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 310 | struct mixer_ctl *ctl_enc_data = NULL, *ctrl_bit_format = NULL; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 311 | struct sbc_enc_cfg_t sbc_dsp_cfg; |
| 312 | bool is_configured = false; |
| 313 | int ret = 0; |
| 314 | |
| 315 | if(sbc_bt_cfg == NULL) |
| 316 | return false; |
| 317 | |
| 318 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 319 | if (!ctl_enc_data) { |
| 320 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 321 | is_configured = false; |
| 322 | goto fail; |
| 323 | } |
| 324 | a2dp.bt_encoder_format = AUDIO_FORMAT_SBC; |
| 325 | memset(&sbc_dsp_cfg, 0x0, sizeof(struct sbc_enc_cfg_t)); |
| 326 | sbc_dsp_cfg.enc_format = ENC_MEDIA_FMT_SBC; |
| 327 | sbc_dsp_cfg.num_subbands = sbc_bt_cfg->subband; |
| 328 | sbc_dsp_cfg.blk_len = sbc_bt_cfg->blk_len; |
| 329 | switch(sbc_bt_cfg->channels) { |
| 330 | case 0: |
| 331 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_MONO; |
| 332 | break; |
| 333 | case 1: |
| 334 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_DUAL_MONO; |
| 335 | break; |
| 336 | case 3: |
| 337 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_JOINT_STEREO; |
| 338 | break; |
| 339 | case 2: |
| 340 | default: |
| 341 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_STEREO; |
| 342 | break; |
| 343 | } |
| 344 | if (sbc_bt_cfg->alloc) |
| 345 | sbc_dsp_cfg.alloc_method = MEDIA_FMT_SBC_ALLOCATION_METHOD_LOUDNESS; |
| 346 | else |
| 347 | sbc_dsp_cfg.alloc_method = MEDIA_FMT_SBC_ALLOCATION_METHOD_SNR; |
| 348 | sbc_dsp_cfg.bit_rate = sbc_bt_cfg->bitrate; |
| 349 | sbc_dsp_cfg.sample_rate = sbc_bt_cfg->sampling_rate; |
| 350 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&sbc_dsp_cfg, |
| 351 | sizeof(struct sbc_enc_cfg_t)); |
| 352 | if (ret != 0) { |
| 353 | ALOGE("%s: failed to set SBC encoder config", __func__); |
| 354 | is_configured = false; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 355 | goto fail; |
| 356 | } |
| 357 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 358 | MIXER_ENC_BIT_FORMAT); |
| 359 | if (!ctrl_bit_format) { |
| 360 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 361 | is_configured = false; |
| 362 | goto fail; |
| 363 | } |
| 364 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 365 | if (ret != 0) { |
| 366 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 367 | is_configured = false; |
| 368 | goto fail; |
| 369 | } |
| 370 | is_configured = true; |
| 371 | a2dp.enc_sampling_rate = sbc_bt_cfg->sampling_rate; |
| 372 | ALOGV("Successfully updated SBC enc format with samplingrate: %d channelmode:%d", |
| 373 | sbc_dsp_cfg.sample_rate, sbc_dsp_cfg.channel_mode); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 374 | fail: |
| 375 | return is_configured; |
| 376 | } |
| 377 | |
| 378 | /* API to configure APTX DSP encoder */ |
| 379 | bool configure_aptx_enc_format(audio_aptx_encoder_config *aptx_bt_cfg) |
| 380 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 381 | struct mixer_ctl *ctl_enc_data = NULL, *ctrl_bit_format = NULL; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 382 | struct custom_enc_cfg_aptx_t aptx_dsp_cfg; |
| 383 | bool is_configured = false; |
| 384 | int ret = 0; |
| 385 | |
| 386 | if(aptx_bt_cfg == NULL) |
| 387 | return false; |
| 388 | |
| 389 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 390 | if (!ctl_enc_data) { |
| 391 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 392 | is_configured = false; |
| 393 | goto fail; |
| 394 | } |
| 395 | a2dp.bt_encoder_format = AUDIO_FORMAT_APTX; |
| 396 | memset(&aptx_dsp_cfg, 0x0, sizeof(struct custom_enc_cfg_aptx_t)); |
| 397 | aptx_dsp_cfg.enc_format = ENC_MEDIA_FMT_APTX; |
| 398 | aptx_dsp_cfg.sample_rate = aptx_bt_cfg->sampling_rate; |
| 399 | aptx_dsp_cfg.num_channels = aptx_bt_cfg->channels; |
| 400 | switch(aptx_dsp_cfg.num_channels) { |
| 401 | case 1: |
| 402 | aptx_dsp_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 403 | break; |
| 404 | case 2: |
| 405 | default: |
| 406 | aptx_dsp_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 407 | aptx_dsp_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 408 | break; |
| 409 | } |
| 410 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg, |
| 411 | sizeof(struct custom_enc_cfg_aptx_t)); |
| 412 | if (ret != 0) { |
| 413 | ALOGE("%s: Failed to set APTX encoder config", __func__); |
| 414 | is_configured = false; |
| 415 | goto fail; |
| 416 | } |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 417 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 418 | MIXER_ENC_BIT_FORMAT); |
| 419 | if (!ctrl_bit_format) { |
| 420 | ALOGE("ERROR bit format CONFIG data mixer control not identifed"); |
| 421 | is_configured = false; |
| 422 | goto fail; |
| 423 | } else { |
| 424 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 425 | if (ret != 0) { |
| 426 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 427 | is_configured = false; |
| 428 | goto fail; |
| 429 | } |
| 430 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 431 | is_configured = true; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 432 | a2dp.enc_sampling_rate = aptx_bt_cfg->sampling_rate; |
| 433 | ALOGV("Successfully updated APTX enc format with samplingrate: %d channels:%d", |
| 434 | aptx_dsp_cfg.sample_rate, aptx_dsp_cfg.num_channels); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 435 | fail: |
| 436 | return is_configured; |
| 437 | } |
| 438 | |
| 439 | /* API to configure APTX HD DSP encoder |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 440 | */ |
| 441 | bool configure_aptx_hd_enc_format(audio_aptx_encoder_config *aptx_bt_cfg) |
| 442 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 443 | struct mixer_ctl *ctl_enc_data = NULL, *ctrl_bit_format = NULL; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 444 | struct custom_enc_cfg_aptx_t aptx_dsp_cfg; |
| 445 | bool is_configured = false; |
| 446 | int ret = 0; |
| 447 | |
| 448 | if(aptx_bt_cfg == NULL) |
| 449 | return false; |
| 450 | |
| 451 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 452 | if (!ctl_enc_data) { |
| 453 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 454 | is_configured = false; |
| 455 | goto fail; |
| 456 | } |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 457 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 458 | a2dp.bt_encoder_format = AUDIO_FORMAT_APTX_HD; |
| 459 | memset(&aptx_dsp_cfg, 0x0, sizeof(struct custom_enc_cfg_aptx_t)); |
| 460 | aptx_dsp_cfg.enc_format = ENC_MEDIA_FMT_APTX_HD; |
| 461 | aptx_dsp_cfg.sample_rate = aptx_bt_cfg->sampling_rate; |
| 462 | aptx_dsp_cfg.num_channels = aptx_bt_cfg->channels; |
| 463 | switch(aptx_dsp_cfg.num_channels) { |
| 464 | case 1: |
| 465 | aptx_dsp_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 466 | break; |
| 467 | case 2: |
| 468 | default: |
| 469 | aptx_dsp_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 470 | aptx_dsp_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 471 | break; |
| 472 | } |
| 473 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg, |
| 474 | sizeof(struct custom_enc_cfg_aptx_t)); |
| 475 | if (ret != 0) { |
| 476 | ALOGE("%s: Failed to set APTX HD encoder config", __func__); |
| 477 | is_configured = false; |
| 478 | goto fail; |
| 479 | } |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 480 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_BIT_FORMAT); |
| 481 | if (!ctrl_bit_format) { |
| 482 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 483 | is_configured = false; |
| 484 | goto fail; |
| 485 | } |
| 486 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S24_LE"); |
| 487 | if (ret != 0) { |
| 488 | ALOGE("%s: Failed to set APTX HD encoder config", __func__); |
| 489 | is_configured = false; |
| 490 | goto fail; |
| 491 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 492 | is_configured = true; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 493 | a2dp.enc_sampling_rate = aptx_bt_cfg->sampling_rate; |
| 494 | ALOGV("Successfully updated APTX HD encformat with samplingrate: %d channels:%d", |
| 495 | aptx_dsp_cfg.sample_rate, aptx_dsp_cfg.num_channels); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 496 | fail: |
| 497 | return is_configured; |
| 498 | } |
| 499 | |
| 500 | /* API to configure AAC DSP encoder */ |
| 501 | bool configure_aac_enc_format(audio_aac_encoder_config *aac_bt_cfg) |
| 502 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 503 | struct mixer_ctl *ctl_enc_data = NULL, *ctrl_bit_format = NULL; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 504 | struct aac_enc_cfg_t aac_dsp_cfg; |
| 505 | bool is_configured = false; |
| 506 | int ret = 0; |
| 507 | |
| 508 | if(aac_bt_cfg == NULL) |
| 509 | return false; |
| 510 | |
| 511 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 512 | if (!ctl_enc_data) { |
| 513 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 514 | is_configured = false; |
| 515 | goto fail; |
| 516 | } |
| 517 | a2dp.bt_encoder_format = AUDIO_FORMAT_AAC; |
| 518 | memset(&aac_dsp_cfg, 0x0, sizeof(struct aac_enc_cfg_t)); |
| 519 | aac_dsp_cfg.enc_format = ENC_MEDIA_FMT_AAC; |
| 520 | aac_dsp_cfg.bit_rate = aac_bt_cfg->bitrate; |
Naresh Tanniru | a42d0bd | 2016-09-21 15:30:46 +0530 | [diff] [blame] | 521 | aac_dsp_cfg.sample_rate = aac_bt_cfg->sampling_rate; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 522 | switch(aac_bt_cfg->enc_mode) { |
| 523 | case 0: |
| 524 | aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_LC; |
| 525 | break; |
| 526 | case 2: |
| 527 | aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_PS; |
| 528 | break; |
| 529 | case 1: |
| 530 | default: |
| 531 | aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_SBR; |
| 532 | break; |
| 533 | } |
Naresh Tanniru | a42d0bd | 2016-09-21 15:30:46 +0530 | [diff] [blame] | 534 | aac_dsp_cfg.aac_fmt_flag = aac_bt_cfg->format_flag; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 535 | aac_dsp_cfg.channel_cfg = aac_bt_cfg->channels; |
| 536 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aac_dsp_cfg, |
| 537 | sizeof(struct aac_enc_cfg_t)); |
| 538 | if (ret != 0) { |
| 539 | ALOGE("%s: failed to set SBC encoder config", __func__); |
| 540 | is_configured = false; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 541 | goto fail; |
| 542 | } |
| 543 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 544 | MIXER_ENC_BIT_FORMAT); |
| 545 | if (!ctrl_bit_format) { |
| 546 | is_configured = false; |
| 547 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 548 | goto fail; |
| 549 | } |
| 550 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 551 | if (ret != 0) { |
| 552 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 553 | is_configured = false; |
| 554 | goto fail; |
| 555 | } |
| 556 | is_configured = true; |
| 557 | a2dp.enc_sampling_rate = aac_bt_cfg->sampling_rate; |
| 558 | ALOGV("Successfully updated AAC enc format with samplingrate: %d channels:%d", |
| 559 | aac_dsp_cfg.sample_rate, aac_dsp_cfg.channel_cfg); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 560 | fail: |
| 561 | return is_configured; |
| 562 | } |
| 563 | |
| 564 | bool configure_a2dp_encoder_format() |
| 565 | { |
| 566 | void *codec_info = NULL; |
| 567 | uint8_t multi_cast = 0, num_dev = 1; |
| 568 | audio_format_t codec_type = AUDIO_FORMAT_INVALID; |
| 569 | bool is_configured = false; |
| 570 | |
| 571 | if (!a2dp.audio_get_codec_config) { |
| 572 | ALOGE(" a2dp handle is not identified, ignoring a2dp encoder config"); |
| 573 | return false; |
| 574 | } |
| 575 | ALOGD("configure_a2dp_encoder_format start"); |
| 576 | codec_info = a2dp.audio_get_codec_config(&multi_cast, &num_dev, |
| 577 | &codec_type); |
| 578 | |
| 579 | switch(codec_type) { |
| 580 | case AUDIO_FORMAT_SBC: |
| 581 | ALOGD(" Received SBC encoder supported BT device"); |
| 582 | is_configured = |
| 583 | configure_sbc_enc_format((audio_sbc_encoder_config *)codec_info); |
| 584 | break; |
| 585 | case AUDIO_FORMAT_APTX: |
| 586 | ALOGD(" Received APTX encoder supported BT device"); |
| 587 | is_configured = |
| 588 | configure_aptx_enc_format((audio_aptx_encoder_config *)codec_info); |
| 589 | break; |
| 590 | case AUDIO_FORMAT_APTX_HD: |
| 591 | ALOGD(" Received APTX HD encoder supported BT device"); |
| 592 | is_configured = |
| 593 | configure_aptx_hd_enc_format((audio_aptx_encoder_config *)codec_info); |
| 594 | break; |
| 595 | case AUDIO_FORMAT_AAC: |
| 596 | ALOGD(" Received AAC encoder supported BT device"); |
| 597 | is_configured = |
| 598 | configure_aac_enc_format((audio_aac_encoder_config *)codec_info); |
| 599 | break; |
| 600 | default: |
| 601 | ALOGD(" Received Unsupported encoder formar"); |
| 602 | is_configured = false; |
| 603 | break; |
| 604 | } |
| 605 | return is_configured; |
| 606 | } |
| 607 | |
| 608 | int audio_extn_a2dp_start_playback() |
| 609 | { |
| 610 | int ret = 0; |
| 611 | |
| 612 | ALOGD("audio_extn_a2dp_start_playback start"); |
| 613 | |
| 614 | if(!(a2dp.bt_lib_handle && a2dp.audio_start_stream |
| 615 | && a2dp.audio_get_codec_config)) { |
| 616 | ALOGE("a2dp handle is not identified, Ignoring start request"); |
| 617 | return -ENOSYS; |
| 618 | } |
| 619 | |
| 620 | if(a2dp.a2dp_suspended == true) { |
| 621 | //session will be restarted after suspend completion |
| 622 | ALOGD("a2dp start requested during suspend state"); |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 623 | return -ENOSYS; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | if (!a2dp.a2dp_started && !a2dp.a2dp_total_active_session_request) { |
| 627 | ALOGD("calling BT module stream start"); |
| 628 | /* This call indicates BT IPC lib to start playback */ |
| 629 | ret = a2dp.audio_start_stream(); |
| 630 | ALOGE("BT controller start return = %d",ret); |
| 631 | if (ret != 0 ) { |
| 632 | ALOGE("BT controller start failed"); |
| 633 | a2dp.a2dp_started = false; |
| 634 | ret = -ETIMEDOUT; |
| 635 | } else { |
| 636 | if(configure_a2dp_encoder_format() == true) { |
| 637 | a2dp.a2dp_started = true; |
| 638 | ret = 0; |
| 639 | ALOGD("Start playback successful to BT library"); |
| 640 | } else { |
| 641 | ALOGD(" unable to configure DSP encoder"); |
| 642 | a2dp.a2dp_started = false; |
| 643 | ret = -ETIMEDOUT; |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | if (a2dp.a2dp_started) |
| 649 | a2dp.a2dp_total_active_session_request++; |
| 650 | |
| 651 | ALOGD("start A2DP playback total active sessions :%d", |
| 652 | a2dp.a2dp_total_active_session_request); |
| 653 | return ret; |
| 654 | } |
| 655 | |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 656 | static void reset_a2dp_enc_config_params() |
| 657 | { |
| 658 | int ret =0; |
| 659 | |
| 660 | struct mixer_ctl *ctl_enc_config, *ctrl_bit_format; |
| 661 | struct sbc_enc_cfg_t dummy_reset_config; |
| 662 | |
| 663 | memset(&dummy_reset_config, 0x0, sizeof(struct sbc_enc_cfg_t)); |
| 664 | ctl_enc_config = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 665 | MIXER_ENC_CONFIG_BLOCK); |
| 666 | if (!ctl_enc_config) { |
| 667 | ALOGE(" ERROR a2dp encoder format mixer control not identifed"); |
| 668 | } else { |
| 669 | ret = mixer_ctl_set_array(ctl_enc_config, (void *)&dummy_reset_config, |
| 670 | sizeof(struct sbc_enc_cfg_t)); |
| 671 | a2dp.bt_encoder_format = ENC_MEDIA_FMT_NONE; |
| 672 | } |
| 673 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 674 | MIXER_ENC_BIT_FORMAT); |
| 675 | if (!ctrl_bit_format) { |
| 676 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 677 | } else { |
| 678 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 679 | if (ret != 0) { |
| 680 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 685 | int audio_extn_a2dp_stop_playback() |
| 686 | { |
| 687 | int ret =0; |
| 688 | |
| 689 | ALOGV("audio_extn_a2dp_stop_playback start"); |
| 690 | if(!(a2dp.bt_lib_handle && a2dp.audio_stop_stream)) { |
| 691 | ALOGE("a2dp handle is not identified, Ignoring start request"); |
| 692 | return -ENOSYS; |
| 693 | } |
| 694 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 695 | if (a2dp.a2dp_started && (a2dp.a2dp_total_active_session_request > 0)) |
| 696 | a2dp.a2dp_total_active_session_request--; |
| 697 | |
| 698 | if ( a2dp.a2dp_started && !a2dp.a2dp_total_active_session_request) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 699 | ALOGV("calling BT module stream stop"); |
| 700 | ret = a2dp.audio_stop_stream(); |
| 701 | if (ret < 0) |
| 702 | ALOGE("stop stream to BT IPC lib failed"); |
| 703 | else |
| 704 | ALOGV("stop steam to BT IPC lib successful"); |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 705 | reset_a2dp_enc_config_params(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 706 | } |
| 707 | if(!a2dp.a2dp_total_active_session_request) |
| 708 | a2dp.a2dp_started = false; |
| 709 | ALOGD("Stop A2DP playback total active sessions :%d", |
| 710 | a2dp.a2dp_total_active_session_request); |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | void audio_extn_a2dp_set_parameters(struct str_parms *parms) |
| 715 | { |
| 716 | int ret, val; |
| 717 | char value[32]={0}; |
| 718 | |
| 719 | if(a2dp.is_a2dp_offload_supported == false) { |
| 720 | ALOGV("no supported encoders identified,ignoring a2dp setparam"); |
| 721 | return; |
| 722 | } |
| 723 | |
| 724 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, |
| 725 | sizeof(value)); |
| 726 | if( ret >= 0) { |
| 727 | val = atoi(value); |
| 728 | if (val & AUDIO_DEVICE_OUT_ALL_A2DP) { |
| 729 | ALOGV("Received device connect request for A2DP"); |
| 730 | open_a2dp_output(); |
| 731 | } |
| 732 | goto param_handled; |
| 733 | } |
| 734 | |
| 735 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, |
| 736 | sizeof(value)); |
| 737 | |
| 738 | if( ret >= 0) { |
| 739 | val = atoi(value); |
| 740 | if (val & AUDIO_DEVICE_OUT_ALL_A2DP) { |
| 741 | ALOGV("Received device dis- connect request"); |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 742 | reset_a2dp_enc_config_params(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 743 | close_a2dp_output(); |
| 744 | } |
| 745 | goto param_handled; |
| 746 | } |
| 747 | |
| 748 | ret = str_parms_get_str(parms, "A2dpSuspended", value, sizeof(value)); |
| 749 | if (ret >= 0) { |
| 750 | if (a2dp.bt_lib_handle && (a2dp.bt_state != A2DP_STATE_DISCONNECTED) ) { |
| 751 | if ((!strncmp(value,"true",sizeof(value)))) { |
| 752 | ALOGD("Setting a2dp to suspend state"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 753 | a2dp.a2dp_suspended = true; |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 754 | reset_a2dp_enc_config_params(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 755 | if(a2dp.audio_suspend_stream) |
| 756 | a2dp.audio_suspend_stream(); |
| 757 | } else if (a2dp.a2dp_suspended == true) { |
| 758 | ALOGD("Resetting a2dp suspend state"); |
| 759 | if(a2dp.clear_a2dpsuspend_flag) |
| 760 | a2dp.clear_a2dpsuspend_flag(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 761 | a2dp.a2dp_suspended = false; |
Naresh Tanniru | 649871a | 2016-11-04 18:08:32 +0530 | [diff] [blame] | 762 | /* |
| 763 | * It is possible that before suspend,a2dp sessions can be active |
| 764 | * for example during music + voice activation concurrency |
| 765 | * a2dp suspend will be called & BT will change to sco mode |
| 766 | * though music is paused as a part of voice activation |
| 767 | * compress session close happens only after pause timeout(10secs) |
| 768 | * so if resume request comes before pause timeout as a2dp session |
| 769 | * is already active IPC start will not be called from APM/audio_hw |
| 770 | * Fix is to call a2dp start for IPC library post suspend |
| 771 | * based on number of active session count |
| 772 | */ |
| 773 | if (a2dp.a2dp_total_active_session_request > 0) { |
| 774 | ALOGD(" Calling IPC lib start post suspend state"); |
| 775 | if(a2dp.audio_start_stream) { |
| 776 | ret = a2dp.audio_start_stream(); |
| 777 | if (ret != 0) { |
| 778 | ALOGE("BT controller start failed"); |
| 779 | a2dp.a2dp_started = false; |
| 780 | } |
| 781 | } |
| 782 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | goto param_handled; |
| 786 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 787 | param_handled: |
| 788 | ALOGV("end of a2dp setparam"); |
| 789 | } |
| 790 | |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 791 | void audio_extn_a2dp_set_handoff_mode(bool is_on) |
| 792 | { |
| 793 | a2dp.is_handoff_in_progress = is_on; |
| 794 | } |
| 795 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 796 | bool audio_extn_a2dp_is_force_device_switch() |
| 797 | { |
| 798 | //During encoder reconfiguration mode, force a2dp device switch |
Ashish Jain | c597d10 | 2016-12-12 10:31:34 +0530 | [diff] [blame] | 799 | // Or if a2dp device is selected but earlier start failed ( as a2dp |
| 800 | // was suspended, force retry. |
| 801 | return a2dp.is_handoff_in_progress || !a2dp.a2dp_started; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 802 | } |
| 803 | |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 804 | void audio_extn_a2dp_get_apptype_params(uint32_t *sample_rate, |
| 805 | uint32_t *bit_width) |
| 806 | { |
| 807 | if(a2dp.bt_encoder_format == AUDIO_FORMAT_APTX_HD) |
| 808 | *bit_width = 24; |
| 809 | else |
| 810 | *bit_width = 16; |
| 811 | *sample_rate = a2dp.enc_sampling_rate; |
| 812 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 813 | void audio_extn_a2dp_init (void *adev) |
| 814 | { |
| 815 | a2dp.adev = (struct audio_device*)adev; |
| 816 | a2dp.bt_lib_handle = NULL; |
| 817 | a2dp.a2dp_started = false; |
| 818 | a2dp.bt_state = A2DP_STATE_DISCONNECTED; |
| 819 | a2dp.a2dp_total_active_session_request = 0; |
| 820 | a2dp.a2dp_suspended = false; |
| 821 | a2dp.bt_encoder_format = AUDIO_FORMAT_INVALID; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 822 | a2dp.enc_sampling_rate = 48000; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 823 | a2dp.is_a2dp_offload_supported = false; |
| 824 | a2dp.is_handoff_in_progress = false; |
| 825 | update_offload_codec_capabilities(); |
| 826 | } |
| 827 | #endif // SPLIT_A2DP_ENABLED |