Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1 | /* |
Preetam Singh Ranawat | 109bb3c | 2018-01-30 12:12:02 +0530 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, 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" |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 38 | #include "audio_extn.h" |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 39 | #include <stdlib.h> |
| 40 | #include <cutils/str_parms.h> |
| 41 | #include <hardware/audio.h> |
| 42 | #include <hardware/hardware.h> |
| 43 | #include <cutils/properties.h> |
| 44 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 45 | #ifdef DYNAMIC_LOG_ENABLED |
| 46 | #include <log_xml_parser.h> |
| 47 | #define LOG_MASK HAL_MOD_FILE_A2DP |
| 48 | #include <log_utils.h> |
| 49 | #endif |
| 50 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 51 | #ifdef SPLIT_A2DP_ENABLED |
| 52 | #define AUDIO_PARAMETER_A2DP_STARTED "A2dpStarted" |
| 53 | #define BT_IPC_LIB_NAME "libbthost_if.so" |
| 54 | #define ENC_MEDIA_FMT_NONE 0 |
| 55 | #define ENC_MEDIA_FMT_AAC 0x00010DA6 |
| 56 | #define ENC_MEDIA_FMT_APTX 0x000131ff |
| 57 | #define ENC_MEDIA_FMT_APTX_HD 0x00013200 |
| 58 | #define ENC_MEDIA_FMT_SBC 0x00010BF2 |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 59 | #define ENC_MEDIA_FMT_CELT 0x00013221 |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 60 | #define ENC_MEDIA_FMT_LDAC 0x00013224 |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 61 | #define MEDIA_FMT_AAC_AOT_LC 2 |
| 62 | #define MEDIA_FMT_AAC_AOT_SBR 5 |
| 63 | #define MEDIA_FMT_AAC_AOT_PS 29 |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 64 | #define PCM_CHANNEL_L 1 |
| 65 | #define PCM_CHANNEL_R 2 |
| 66 | #define PCM_CHANNEL_C 3 |
| 67 | #define MEDIA_FMT_SBC_CHANNEL_MODE_MONO 1 |
| 68 | #define MEDIA_FMT_SBC_CHANNEL_MODE_STEREO 2 |
| 69 | #define MEDIA_FMT_SBC_CHANNEL_MODE_DUAL_MONO 8 |
| 70 | #define MEDIA_FMT_SBC_CHANNEL_MODE_JOINT_STEREO 9 |
| 71 | #define MEDIA_FMT_SBC_ALLOCATION_METHOD_LOUDNESS 0 |
| 72 | #define MEDIA_FMT_SBC_ALLOCATION_METHOD_SNR 1 |
| 73 | #define MIXER_ENC_CONFIG_BLOCK "SLIM_7_RX Encoder Config" |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 74 | #define MIXER_DEC_CONFIG_BLOCK "SLIM_7_TX Decoder Config" |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 75 | #define MIXER_ENC_BIT_FORMAT "AFE Input Bit Format" |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 76 | #define MIXER_SCRAMBLER_MODE "AFE Scrambler Mode" |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 77 | #define MIXER_SAMPLE_RATE_RX "BT SampleRate RX" |
| 78 | #define MIXER_SAMPLE_RATE_TX "BT SampleRate TX" |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 79 | #define MIXER_AFE_IN_CHANNELS "AFE Input Channels" |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 80 | #define MIXER_ABR_TX_FEEDBACK_PATH "A2DP_SLIM7_UL_HL Switch" |
| 81 | #define MIXER_SET_FEEDBACK_CHANNEL "BT set feedback channel" |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 82 | #define MIXER_ENC_FMT_SBC "SBC" |
| 83 | #define MIXER_ENC_FMT_AAC "AAC" |
| 84 | #define MIXER_ENC_FMT_APTX "APTX" |
| 85 | #define MIXER_ENC_FMT_APTXHD "APTXHD" |
| 86 | #define MIXER_ENC_FMT_NONE "NONE" |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 87 | #define ENCODER_LATENCY_SBC 10 |
| 88 | #define ENCODER_LATENCY_APTX 40 |
| 89 | #define ENCODER_LATENCY_APTX_HD 20 |
| 90 | #define ENCODER_LATENCY_AAC 70 |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 91 | //To Do: Fine Tune Encoder CELT/LDAC latency. |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 92 | #define ENCODER_LATENCY_CELT 40 |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 93 | #define ENCODER_LATENCY_LDAC 40 |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 94 | #define DEFAULT_SINK_LATENCY_SBC 140 |
| 95 | #define DEFAULT_SINK_LATENCY_APTX 160 |
| 96 | #define DEFAULT_SINK_LATENCY_APTX_HD 180 |
| 97 | #define DEFAULT_SINK_LATENCY_AAC 180 |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 98 | //To Do: Fine Tune Default CELT/LDAC Latency. |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 99 | #define DEFAULT_SINK_LATENCY_CELT 180 |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 100 | #define DEFAULT_SINK_LATENCY_LDAC 180 |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 101 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 102 | // Slimbus Tx sample rate for ABR feedback channel |
| 103 | #define ABR_TX_SAMPLE_RATE "KHZ_8" |
| 104 | |
| 105 | // Purpose ID for Inter Module Communication (IMC) in AFE |
| 106 | #define IMC_PURPOSE_ID_BT_INFO 0x000132E2 |
| 107 | |
| 108 | // Maximum quality levels for ABR |
| 109 | #define MAX_ABR_QUALITY_LEVELS 5 |
| 110 | |
| 111 | // Instance identifier for A2DP |
| 112 | #define MAX_INSTANCE_ID (UINT32_MAX / 2) |
| 113 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 114 | /* |
| 115 | * Below enum values are extended from audio_base.h to |
| 116 | * to keep encoder codec type local to bthost_ipc |
| 117 | * and audio_hal as these are intended only for handshake |
| 118 | * between IPC lib and Audio HAL. |
| 119 | */ |
| 120 | typedef enum { |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 121 | ENC_CODEC_TYPE_INVALID = AUDIO_FORMAT_INVALID, // 0xFFFFFFFFUL |
| 122 | ENC_CODEC_TYPE_AAC = AUDIO_FORMAT_AAC, // 0x04000000UL |
| 123 | ENC_CODEC_TYPE_SBC = AUDIO_FORMAT_SBC, // 0x1F000000UL |
| 124 | ENC_CODEC_TYPE_APTX = AUDIO_FORMAT_APTX, // 0x20000000UL |
| 125 | ENC_CODEC_TYPE_APTX_HD = AUDIO_FORMAT_APTX_HD, // 0x21000000UL |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 126 | #ifndef LINUX_ENABLED |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 127 | ENC_CODEC_TYPE_APTX_DUAL_MONO = 570425344u, // 0x22000000UL |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 128 | #endif |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 129 | ENC_CODEC_TYPE_LDAC = AUDIO_FORMAT_LDAC, // 0x23000000UL |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 130 | ENC_CODEC_TYPE_CELT = 603979776u, // 0x24000000UL |
| 131 | }enc_codec_t; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 132 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 133 | typedef int (*audio_stream_open_t)(void); |
| 134 | typedef int (*audio_stream_close_t)(void); |
| 135 | typedef int (*audio_start_stream_t)(void); |
| 136 | typedef int (*audio_stop_stream_t)(void); |
| 137 | typedef int (*audio_suspend_stream_t)(void); |
| 138 | typedef void (*audio_handoff_triggered_t)(void); |
| 139 | typedef void (*clear_a2dpsuspend_flag_t)(void); |
| 140 | typedef void * (*audio_get_codec_config_t)(uint8_t *multicast_status,uint8_t *num_dev, |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 141 | enc_codec_t *codec_type); |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 142 | typedef int (*audio_check_a2dp_ready_t)(void); |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 143 | typedef uint16_t (*audio_get_a2dp_sink_latency_t)(void); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 144 | typedef int (*audio_is_scrambling_enabled_t)(void); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 145 | |
| 146 | enum A2DP_STATE { |
| 147 | A2DP_STATE_CONNECTED, |
| 148 | A2DP_STATE_STARTED, |
| 149 | A2DP_STATE_STOPPED, |
| 150 | A2DP_STATE_DISCONNECTED, |
| 151 | }; |
| 152 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 153 | typedef enum { |
| 154 | IMC_TRANSMIT, |
| 155 | IMC_RECEIVE, |
| 156 | } imc_direction_t; |
| 157 | |
| 158 | typedef enum { |
| 159 | IMC_DISABLE, |
| 160 | IMC_ENABLE, |
| 161 | } imc_status_t; |
| 162 | |
| 163 | /* PCM config for ABR Feedback hostless front end */ |
| 164 | static struct pcm_config pcm_config_abr = { |
| 165 | .channels = 1, |
| 166 | .rate = 8000, |
| 167 | .period_size = 240, |
| 168 | .period_count = 2, |
| 169 | .format = PCM_FORMAT_S16_LE, |
| 170 | .start_threshold = 0, |
| 171 | .stop_threshold = INT_MAX, |
| 172 | .avail_min = 0, |
| 173 | }; |
| 174 | |
| 175 | /* Adaptive bitrate config for A2DP codecs */ |
| 176 | struct a2dp_abr_config { |
| 177 | /* Flag to denote whether Adaptive bitrate is enabled for codec */ |
| 178 | bool is_abr_enabled; |
| 179 | /* Flag to denote whether front end has been opened for ABR */ |
| 180 | bool abr_started; |
| 181 | /* ABR Tx path pcm handle */ |
| 182 | struct pcm *abr_tx_handle; |
| 183 | /* ABR Inter Module Communication (IMC) instance ID */ |
| 184 | uint32_t imc_instance; |
| 185 | }; |
| 186 | |
| 187 | static uint32_t instance_id = MAX_INSTANCE_ID; |
| 188 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 189 | /* structure used to update a2dp state machine |
| 190 | * to communicate IPC library |
| 191 | * to store DSP encoder configuration information |
| 192 | */ |
| 193 | struct a2dp_data { |
| 194 | struct audio_device *adev; |
| 195 | void *bt_lib_handle; |
| 196 | audio_stream_open_t audio_stream_open; |
| 197 | audio_stream_close_t audio_stream_close; |
| 198 | audio_start_stream_t audio_start_stream; |
| 199 | audio_stop_stream_t audio_stop_stream; |
| 200 | audio_suspend_stream_t audio_suspend_stream; |
| 201 | audio_handoff_triggered_t audio_handoff_triggered; |
| 202 | clear_a2dpsuspend_flag_t clear_a2dpsuspend_flag; |
| 203 | audio_get_codec_config_t audio_get_codec_config; |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 204 | audio_check_a2dp_ready_t audio_check_a2dp_ready; |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 205 | audio_get_a2dp_sink_latency_t audio_get_a2dp_sink_latency; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 206 | audio_is_scrambling_enabled_t audio_is_scrambling_enabled; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 207 | enum A2DP_STATE bt_state; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 208 | enc_codec_t bt_encoder_format; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 209 | uint32_t enc_sampling_rate; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 210 | uint32_t enc_channels; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 211 | bool a2dp_started; |
| 212 | bool a2dp_suspended; |
| 213 | int a2dp_total_active_session_request; |
| 214 | bool is_a2dp_offload_supported; |
| 215 | bool is_handoff_in_progress; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 216 | bool is_aptx_dual_mono_supported; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 217 | /* Adaptive bitrate config for A2DP codecs */ |
| 218 | struct a2dp_abr_config abr_config; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | struct a2dp_data a2dp; |
| 222 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 223 | /* Adaptive bitrate (ABR) is supported by certain Bluetooth codecs. |
| 224 | * Structures sent to configure DSP for ABR are defined below. |
| 225 | * This data helps DSP configure feedback path (BTSoC to LPASS) |
| 226 | * for link quality levels and mapping quality levels to codec |
| 227 | * specific bitrate. |
| 228 | */ |
| 229 | |
| 230 | /* Key value pair for link quality level to bitrate mapping. */ |
| 231 | struct bit_rate_level_map_t { |
| 232 | uint32_t link_quality_level; |
| 233 | uint32_t bitrate; |
| 234 | }; |
| 235 | |
| 236 | /* Link quality level to bitrate mapping info sent to DSP. */ |
| 237 | struct quality_level_to_bitrate_info { |
| 238 | /* Number of quality levels being mapped. |
| 239 | * This will be equal to the size of mapping table. |
| 240 | */ |
| 241 | uint32_t num_levels; |
| 242 | /* Quality level to bitrate mapping table */ |
| 243 | struct bit_rate_level_map_t bit_rate_level_map[MAX_ABR_QUALITY_LEVELS]; |
| 244 | }; |
| 245 | |
| 246 | /* Structure to set up Inter Module Communication (IMC) between |
| 247 | * AFE Decoder and Encoder. |
| 248 | */ |
| 249 | struct imc_dec_enc_info { |
| 250 | /* Decoder to encoder communication direction. |
| 251 | * Transmit = 0 / Receive = 1 |
| 252 | */ |
| 253 | uint32_t direction; |
| 254 | /* Enable / disable IMC between decoder and encoder */ |
| 255 | uint32_t enable; |
| 256 | /* Purpose of IMC being set up between decoder and encoder. |
| 257 | * IMC_PURPOSE_ID_BT_INFO defined for link quality feedback |
| 258 | * is the default value to be sent as purpose. |
| 259 | */ |
| 260 | uint32_t purpose; |
| 261 | /* Unique communication instance ID. |
| 262 | * purpose and comm_instance together form the actual key |
| 263 | * used in IMC registration, which must be the same for |
| 264 | * encoder and decoder for which IMC is being set up. |
| 265 | */ |
| 266 | uint32_t comm_instance; |
| 267 | }; |
| 268 | |
| 269 | /* Structure used for ABR config of AFE encoder and decoder. */ |
| 270 | struct abr_enc_cfg_t { |
| 271 | /* Link quality level to bitrate mapping info sent to DSP. */ |
| 272 | struct quality_level_to_bitrate_info mapping_info; |
| 273 | /* Information to set up IMC between decoder and encoder */ |
| 274 | struct imc_dec_enc_info imc_info; |
| 275 | } __attribute__ ((packed)); |
| 276 | |
| 277 | /* Structure to send configuration for decoder introduced |
| 278 | * on AFE Tx path for ABR link quality feedback to BT encoder. |
| 279 | */ |
| 280 | struct abr_dec_cfg_t { |
| 281 | /* Decoder media format */ |
| 282 | uint32_t dec_format; |
| 283 | /* Information to set up IMC between decoder and encoder */ |
| 284 | struct imc_dec_enc_info imc_info; |
| 285 | } __attribute__ ((packed)); |
| 286 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 287 | /* START of DSP configurable structures |
| 288 | * These values should match with DSP interface defintion |
| 289 | */ |
| 290 | |
| 291 | /* AAC encoder configuration structure. */ |
| 292 | typedef struct aac_enc_cfg_t aac_enc_cfg_t; |
| 293 | |
| 294 | /* supported enc_mode are AAC_LC, AAC_SBR, AAC_PS |
| 295 | * supported aac_fmt_flag are ADTS/RAW |
| 296 | * supported channel_cfg are Native mode, Mono , Stereo |
| 297 | */ |
| 298 | struct aac_enc_cfg_t { |
| 299 | uint32_t enc_format; |
| 300 | uint32_t bit_rate; |
| 301 | uint32_t enc_mode; |
| 302 | uint16_t aac_fmt_flag; |
Naresh Tanniru | a42d0bd | 2016-09-21 15:30:46 +0530 | [diff] [blame] | 303 | uint16_t channel_cfg; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 304 | uint32_t sample_rate; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 305 | } __attribute__ ((packed)); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 306 | |
| 307 | /* SBC encoder configuration structure. */ |
| 308 | typedef struct sbc_enc_cfg_t sbc_enc_cfg_t; |
| 309 | |
| 310 | /* supported num_subbands are 4/8 |
| 311 | * supported blk_len are 4, 8, 12, 16 |
| 312 | * supported channel_mode are MONO, STEREO, DUAL_MONO, JOINT_STEREO |
| 313 | * supported alloc_method are LOUNDNESS/SNR |
| 314 | * supported bit_rate for mono channel is max 320kbps |
| 315 | * supported bit rate for stereo channel is max 512 kbps |
| 316 | */ |
| 317 | struct sbc_enc_cfg_t{ |
| 318 | uint32_t enc_format; |
| 319 | uint32_t num_subbands; |
| 320 | uint32_t blk_len; |
| 321 | uint32_t channel_mode; |
| 322 | uint32_t alloc_method; |
| 323 | uint32_t bit_rate; |
| 324 | uint32_t sample_rate; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 325 | } __attribute__ ((packed)); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 326 | |
| 327 | |
| 328 | /* supported num_channels are Mono/Stereo |
| 329 | * supported channel_mapping for mono is CHANNEL_C |
| 330 | * supported channel mapping for stereo is CHANNEL_L and CHANNEL_R |
| 331 | * custom size and reserved are not used(for future enhancement) |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 332 | */ |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 333 | struct custom_enc_cfg_t |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 334 | { |
| 335 | uint32_t enc_format; |
| 336 | uint32_t sample_rate; |
| 337 | uint16_t num_channels; |
| 338 | uint16_t reserved; |
| 339 | uint8_t channel_mapping[8]; |
| 340 | uint32_t custom_size; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 341 | } __attribute__ ((packed)); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 342 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 343 | struct celt_specific_enc_cfg_t |
| 344 | { |
| 345 | uint32_t bit_rate; |
| 346 | uint16_t frame_size; |
| 347 | uint16_t complexity; |
| 348 | uint16_t prediction_mode; |
| 349 | uint16_t vbr_flag; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 350 | } __attribute__ ((packed)); |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 351 | |
| 352 | struct celt_enc_cfg_t |
| 353 | { |
| 354 | struct custom_enc_cfg_t custom_cfg; |
| 355 | struct celt_specific_enc_cfg_t celt_cfg; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 356 | } __attribute__ ((packed)); |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 357 | |
| 358 | /* sync_mode introduced with APTX V2 libraries |
| 359 | * sync mode: 0x0 = stereo sync mode |
| 360 | * 0x01 = dual mono sync mode |
| 361 | * 0x02 = dual mono with no sync on either L or R codewords |
| 362 | */ |
| 363 | struct aptx_v2_enc_cfg_ext_t |
| 364 | { |
| 365 | uint32_t sync_mode; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 366 | } __attribute__ ((packed)); |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 367 | |
| 368 | /* APTX struct for combining custom enc and V2 fields */ |
| 369 | struct aptx_enc_cfg_t |
| 370 | { |
| 371 | struct custom_enc_cfg_t custom_cfg; |
| 372 | struct aptx_v2_enc_cfg_ext_t aptx_v2_cfg; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 373 | } __attribute__ ((packed)); |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 374 | |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 375 | struct ldac_specific_enc_cfg_t |
| 376 | { |
| 377 | uint32_t bit_rate; |
| 378 | uint16_t channel_mode; |
| 379 | uint16_t mtu; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 380 | } __attribute__ ((packed)); |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 381 | |
| 382 | struct ldac_enc_cfg_t |
| 383 | { |
| 384 | struct custom_enc_cfg_t custom_cfg; |
| 385 | struct ldac_specific_enc_cfg_t ldac_cfg; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 386 | struct abr_enc_cfg_t abr_cfg; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 387 | } __attribute__ ((packed)); |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 388 | |
Sachin Mohan Gadag | 1657c05 | 2017-09-13 16:00:27 +0530 | [diff] [blame] | 389 | /* In LE BT source code uses system/audio.h for below |
| 390 | * structure definition. To avoid multiple definition |
| 391 | * compilation error for audiohal in LE , masking structure |
| 392 | * definition under "LINUX_ENABLED" which is defined only |
| 393 | * in LE |
| 394 | */ |
| 395 | #ifndef LINUX_ENABLED |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 396 | /* TODO: Define the following structures only for O using PLATFORM_VERSION */ |
| 397 | /* Information about BT SBC encoder configuration |
| 398 | * This data is used between audio HAL module and |
| 399 | * BT IPC library to configure DSP encoder |
| 400 | */ |
| 401 | typedef struct { |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 402 | uint32_t subband; /* 4, 8 */ |
| 403 | uint32_t blk_len; /* 4, 8, 12, 16 */ |
| 404 | uint16_t sampling_rate; /*44.1khz,48khz*/ |
| 405 | uint8_t channels; /*0(Mono),1(Dual_mono),2(Stereo),3(JS)*/ |
| 406 | uint8_t alloc; /*0(Loudness),1(SNR)*/ |
| 407 | uint8_t min_bitpool; /* 2 */ |
| 408 | uint8_t max_bitpool; /*53(44.1khz),51 (48khz) */ |
| 409 | uint32_t bitrate; /* 320kbps to 512kbps */ |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 410 | } audio_sbc_encoder_config; |
| 411 | |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 412 | /* Information about BT APTX encoder configuration |
| 413 | * This data is used between audio HAL module and |
| 414 | * BT IPC library to configure DSP encoder |
| 415 | */ |
| 416 | typedef struct { |
| 417 | uint16_t sampling_rate; |
| 418 | uint8_t channels; |
| 419 | uint32_t bitrate; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 420 | } audio_aptx_default_config; |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 421 | |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 422 | typedef struct { |
| 423 | uint16_t sampling_rate; |
| 424 | uint8_t channels; |
| 425 | uint32_t bitrate; |
| 426 | uint32_t sync_mode; |
| 427 | } audio_aptx_dual_mono_config; |
| 428 | |
| 429 | typedef union { |
| 430 | audio_aptx_default_config *default_cfg; |
| 431 | audio_aptx_dual_mono_config *dual_mono_cfg; |
| 432 | } audio_aptx_encoder_config; |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 433 | |
| 434 | /* Information about BT AAC encoder configuration |
| 435 | * This data is used between audio HAL module and |
| 436 | * BT IPC library to configure DSP encoder |
| 437 | */ |
| 438 | typedef struct { |
| 439 | uint32_t enc_mode; /* LC, SBR, PS */ |
| 440 | uint16_t format_flag; /* RAW, ADTS */ |
| 441 | uint16_t channels; /* 1-Mono, 2-Stereo */ |
| 442 | uint32_t sampling_rate; |
| 443 | uint32_t bitrate; |
| 444 | } audio_aac_encoder_config; |
Sachin Mohan Gadag | 1657c05 | 2017-09-13 16:00:27 +0530 | [diff] [blame] | 445 | #endif |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 446 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 447 | /* Information about BT CELT encoder configuration |
| 448 | * This data is used between audio HAL module and |
| 449 | * BT IPC library to configure DSP encoder |
| 450 | */ |
| 451 | typedef struct { |
| 452 | uint32_t sampling_rate; /* 32000 - 48000, 48000 */ |
| 453 | uint16_t channels; /* 1-Mono, 2-Stereo, 2*/ |
| 454 | uint16_t frame_size; /* 64-128-256-512, 512 */ |
| 455 | uint16_t complexity; /* 0-10, 1 */ |
| 456 | uint16_t prediction_mode; /* 0-1-2, 0 */ |
| 457 | uint16_t vbr_flag; /* 0-1, 0*/ |
| 458 | uint32_t bitrate; /*32000 - 1536000, 139500*/ |
| 459 | } audio_celt_encoder_config; |
| 460 | |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 461 | /* Information about BT LDAC encoder configuration |
| 462 | * This data is used between audio HAL module and |
| 463 | * BT IPC library to configure DSP encoder |
| 464 | */ |
| 465 | typedef struct { |
| 466 | uint32_t sampling_rate; /*44100,48000,88200,96000*/ |
| 467 | uint32_t bit_rate; /*303000,606000,909000(in bits per second)*/ |
| 468 | uint16_t channel_mode; /* 0, 4, 2, 1*/ |
| 469 | uint16_t mtu; /*679*/ |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 470 | bool is_abr_enabled; |
| 471 | struct quality_level_to_bitrate_info level_to_bitrate_map; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 472 | } audio_ldac_encoder_config; |
| 473 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 474 | /*********** END of DSP configurable structures ********************/ |
| 475 | |
| 476 | /* API to identify DSP encoder captabilities */ |
| 477 | static void a2dp_offload_codec_cap_parser(char *value) |
| 478 | { |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 479 | char *tok = NULL,*saveptr; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 480 | |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 481 | tok = strtok_r(value, "-", &saveptr); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 482 | while (tok != NULL) { |
| 483 | if (strcmp(tok, "sbc") == 0) { |
| 484 | ALOGD("%s: SBC offload supported\n",__func__); |
| 485 | a2dp.is_a2dp_offload_supported = true; |
| 486 | break; |
| 487 | } else if (strcmp(tok, "aptx") == 0) { |
| 488 | ALOGD("%s: aptx offload supported\n",__func__); |
| 489 | a2dp.is_a2dp_offload_supported = true; |
| 490 | break; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 491 | } else if (strcmp(tok, "aptxtws") == 0) { |
| 492 | ALOGD("%s: aptx dual mono offload supported\n",__func__); |
| 493 | a2dp.is_a2dp_offload_supported = true; |
| 494 | break; |
Naresh Tanniru | ed694c8 | 2017-02-07 17:01:28 +0530 | [diff] [blame] | 495 | } else if (strcmp(tok, "aptxhd") == 0) { |
| 496 | ALOGD("%s: aptx HD offload supported\n",__func__); |
| 497 | a2dp.is_a2dp_offload_supported = true; |
| 498 | break; |
| 499 | } else if (strcmp(tok, "aac") == 0) { |
| 500 | ALOGD("%s: aac offload supported\n",__func__); |
| 501 | a2dp.is_a2dp_offload_supported = true; |
| 502 | break; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 503 | } else if (strcmp(tok, "celt") == 0) { |
| 504 | ALOGD("%s: celt offload supported\n",__func__); |
| 505 | a2dp.is_a2dp_offload_supported = true; |
| 506 | break; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 507 | } else if (strcmp(tok, "ldac") == 0) { |
| 508 | ALOGD("%s: ldac offload supported\n",__func__); |
| 509 | a2dp.is_a2dp_offload_supported = true; |
| 510 | break; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 511 | } |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 512 | tok = strtok_r(NULL, "-", &saveptr); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 513 | }; |
| 514 | } |
| 515 | |
| 516 | static void update_offload_codec_capabilities() |
| 517 | { |
| 518 | char value[PROPERTY_VALUE_MAX] = {'\0'}; |
| 519 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 520 | property_get("persist.vendor.bt.a2dp_offload_cap", value, "false"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 521 | ALOGD("get_offload_codec_capabilities = %s",value); |
| 522 | a2dp.is_a2dp_offload_supported = |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 523 | property_get_bool("persist.vendor.bt.a2dp_offload_cap", false); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 524 | if (strcmp(value, "false") != 0) |
| 525 | a2dp_offload_codec_cap_parser(value); |
| 526 | ALOGD("%s: codec cap = %s",__func__,value); |
| 527 | } |
| 528 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 529 | static int stop_abr() |
| 530 | { |
| 531 | struct mixer_ctl *ctl_abr_tx_path = NULL; |
| 532 | struct mixer_ctl *ctl_set_bt_feedback_channel = NULL; |
| 533 | |
| 534 | /* This function can be used if !abr_started for clean up */ |
| 535 | ALOGV("%s: enter", __func__); |
| 536 | |
| 537 | // Close hostless front end |
| 538 | if (a2dp.abr_config.abr_tx_handle != NULL) { |
| 539 | pcm_close(a2dp.abr_config.abr_tx_handle); |
| 540 | a2dp.abr_config.abr_tx_handle = NULL; |
| 541 | } |
| 542 | a2dp.abr_config.abr_started = false; |
| 543 | a2dp.abr_config.imc_instance = 0; |
| 544 | |
| 545 | // Reset BT driver mixer control for ABR usecase |
| 546 | ctl_set_bt_feedback_channel = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 547 | MIXER_SET_FEEDBACK_CHANNEL); |
| 548 | if (!ctl_set_bt_feedback_channel) { |
| 549 | ALOGE("%s: ERROR Set usecase mixer control not identifed", __func__); |
| 550 | return -ENOSYS; |
| 551 | } |
| 552 | if (mixer_ctl_set_value(ctl_set_bt_feedback_channel, 0, 0) != 0) { |
| 553 | ALOGE("%s: Failed to set BT usecase", __func__); |
| 554 | return -ENOSYS; |
| 555 | } |
| 556 | |
| 557 | // Reset ABR Tx feedback path |
| 558 | ALOGV("%s: Disable ABR Tx feedback path", __func__); |
| 559 | ctl_abr_tx_path = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 560 | MIXER_ABR_TX_FEEDBACK_PATH); |
| 561 | if (!ctl_abr_tx_path) { |
| 562 | ALOGE("%s: ERROR ABR Tx feedback path mixer control not identifed", __func__); |
| 563 | return -ENOSYS; |
| 564 | } |
| 565 | if (mixer_ctl_set_value(ctl_abr_tx_path, 0, 0) != 0) { |
| 566 | ALOGE("%s: Failed to set ABR Tx feedback path", __func__); |
| 567 | return -ENOSYS; |
| 568 | } |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | static int start_abr() |
| 574 | { |
| 575 | struct mixer_ctl *ctl_abr_tx_path = NULL; |
| 576 | struct mixer_ctl *ctl_set_bt_feedback_channel = NULL; |
| 577 | int abr_device_id; |
| 578 | int ret = 0; |
| 579 | |
| 580 | if (!a2dp.abr_config.is_abr_enabled) { |
| 581 | ALOGE("%s: Cannot start if ABR is not enabled", __func__); |
| 582 | return -ENOSYS; |
| 583 | } |
| 584 | |
| 585 | if (a2dp.abr_config.abr_started) { |
| 586 | ALOGI("%s: ABR has already started", __func__); |
| 587 | return ret; |
| 588 | } |
| 589 | |
| 590 | // Enable Slimbus 7 Tx feedback path |
| 591 | ALOGV("%s: Enable ABR Tx feedback path", __func__); |
| 592 | ctl_abr_tx_path = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 593 | MIXER_ABR_TX_FEEDBACK_PATH); |
| 594 | if (!ctl_abr_tx_path) { |
| 595 | ALOGE("%s: ERROR ABR Tx feedback path mixer control not identifed", __func__); |
| 596 | return -ENOSYS; |
| 597 | } |
| 598 | if (mixer_ctl_set_value(ctl_abr_tx_path, 0, 1) != 0) { |
| 599 | ALOGE("%s: Failed to set ABR Tx feedback path", __func__); |
| 600 | return -ENOSYS; |
| 601 | } |
| 602 | |
| 603 | // Notify ABR usecase information to BT driver to distinguish |
| 604 | // between SCO and feedback usecase |
| 605 | ctl_set_bt_feedback_channel = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 606 | MIXER_SET_FEEDBACK_CHANNEL); |
| 607 | if (!ctl_set_bt_feedback_channel) { |
| 608 | ALOGE("%s: ERROR Set usecase mixer control not identifed", __func__); |
| 609 | return -ENOSYS; |
| 610 | } |
| 611 | if (mixer_ctl_set_value(ctl_set_bt_feedback_channel, 0, 1) != 0) { |
| 612 | ALOGE("%s: Failed to set BT usecase", __func__); |
| 613 | return -ENOSYS; |
| 614 | } |
| 615 | |
| 616 | // Open hostless front end and prepare ABR Tx path |
| 617 | abr_device_id = platform_get_pcm_device_id(USECASE_AUDIO_A2DP_ABR_FEEDBACK, |
| 618 | PCM_CAPTURE); |
| 619 | if (!a2dp.abr_config.abr_tx_handle) { |
| 620 | a2dp.abr_config.abr_tx_handle = pcm_open(a2dp.adev->snd_card, |
| 621 | abr_device_id, PCM_IN, |
| 622 | &pcm_config_abr); |
| 623 | if (a2dp.abr_config.abr_tx_handle == NULL || |
| 624 | !pcm_is_ready(a2dp.abr_config.abr_tx_handle)) |
| 625 | goto fail; |
| 626 | } |
| 627 | ret = pcm_start(a2dp.abr_config.abr_tx_handle); |
| 628 | if (ret < 0) |
| 629 | goto fail; |
| 630 | a2dp.abr_config.abr_started = true; |
| 631 | |
| 632 | return ret; |
| 633 | |
| 634 | fail: |
| 635 | ALOGE("%s: %s", __func__, pcm_get_error(a2dp.abr_config.abr_tx_handle)); |
| 636 | stop_abr(); |
| 637 | return -ENOSYS; |
| 638 | } |
| 639 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 640 | /* API to open BT IPC library to start IPC communication */ |
| 641 | static void open_a2dp_output() |
| 642 | { |
| 643 | int ret = 0; |
| 644 | |
| 645 | ALOGD(" Open A2DP output start "); |
| 646 | if (a2dp.bt_lib_handle == NULL){ |
| 647 | ALOGD(" Requesting for BT lib handle"); |
| 648 | a2dp.bt_lib_handle = dlopen(BT_IPC_LIB_NAME, RTLD_NOW); |
| 649 | |
| 650 | if (a2dp.bt_lib_handle == NULL) { |
| 651 | ALOGE("%s: DLOPEN failed for %s", __func__, BT_IPC_LIB_NAME); |
| 652 | ret = -ENOSYS; |
| 653 | goto init_fail; |
| 654 | } else { |
| 655 | a2dp.audio_stream_open = (audio_stream_open_t) |
| 656 | dlsym(a2dp.bt_lib_handle, "audio_stream_open"); |
| 657 | a2dp.audio_start_stream = (audio_start_stream_t) |
| 658 | dlsym(a2dp.bt_lib_handle, "audio_start_stream"); |
| 659 | a2dp.audio_get_codec_config = (audio_get_codec_config_t) |
| 660 | dlsym(a2dp.bt_lib_handle, "audio_get_codec_config"); |
| 661 | a2dp.audio_suspend_stream = (audio_suspend_stream_t) |
| 662 | dlsym(a2dp.bt_lib_handle, "audio_suspend_stream"); |
| 663 | a2dp.audio_handoff_triggered = (audio_handoff_triggered_t) |
| 664 | dlsym(a2dp.bt_lib_handle, "audio_handoff_triggered"); |
| 665 | a2dp.clear_a2dpsuspend_flag = (clear_a2dpsuspend_flag_t) |
| 666 | dlsym(a2dp.bt_lib_handle, "clear_a2dpsuspend_flag"); |
| 667 | a2dp.audio_stop_stream = (audio_stop_stream_t) |
| 668 | dlsym(a2dp.bt_lib_handle, "audio_stop_stream"); |
| 669 | a2dp.audio_stream_close = (audio_stream_close_t) |
| 670 | dlsym(a2dp.bt_lib_handle, "audio_stream_close"); |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 671 | a2dp.audio_check_a2dp_ready = (audio_check_a2dp_ready_t) |
| 672 | dlsym(a2dp.bt_lib_handle,"audio_check_a2dp_ready"); |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 673 | a2dp.audio_get_a2dp_sink_latency = (audio_get_a2dp_sink_latency_t) |
| 674 | dlsym(a2dp.bt_lib_handle,"audio_get_a2dp_sink_latency"); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 675 | a2dp.audio_is_scrambling_enabled = (audio_is_scrambling_enabled_t) |
| 676 | dlsym(a2dp.bt_lib_handle,"audio_is_scrambling_enabled"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| 680 | if (a2dp.bt_lib_handle && a2dp.audio_stream_open) { |
| 681 | if (a2dp.bt_state == A2DP_STATE_DISCONNECTED) { |
| 682 | ALOGD("calling BT stream open"); |
| 683 | ret = a2dp.audio_stream_open(); |
| 684 | if(ret != 0) { |
| 685 | ALOGE("Failed to open output stream for a2dp: status %d", ret); |
| 686 | goto init_fail; |
| 687 | } |
| 688 | a2dp.bt_state = A2DP_STATE_CONNECTED; |
| 689 | } else { |
| 690 | ALOGD("Called a2dp open with improper state, Ignoring request state %d", a2dp.bt_state); |
| 691 | } |
| 692 | } else { |
| 693 | ALOGE("a2dp handle is not identified, Ignoring open request"); |
| 694 | a2dp.bt_state = A2DP_STATE_DISCONNECTED; |
| 695 | goto init_fail; |
| 696 | } |
| 697 | |
| 698 | init_fail: |
| 699 | if(ret != 0 && (a2dp.bt_lib_handle != NULL)) { |
| 700 | dlclose(a2dp.bt_lib_handle); |
| 701 | a2dp.bt_lib_handle = NULL; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | static int close_a2dp_output() |
| 706 | { |
| 707 | ALOGV("%s\n",__func__); |
| 708 | if (!(a2dp.bt_lib_handle && a2dp.audio_stream_close)) { |
| 709 | ALOGE("a2dp handle is not identified, Ignoring close request"); |
| 710 | return -ENOSYS; |
| 711 | } |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 712 | if (a2dp.bt_state != A2DP_STATE_DISCONNECTED) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 713 | ALOGD("calling BT stream close"); |
| 714 | if(a2dp.audio_stream_close() == false) |
| 715 | ALOGE("failed close a2dp control path from BT library"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 716 | } |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 717 | a2dp.a2dp_started = false; |
| 718 | a2dp.a2dp_total_active_session_request = 0; |
| 719 | a2dp.a2dp_suspended = false; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 720 | a2dp.bt_encoder_format = ENC_CODEC_TYPE_INVALID; |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 721 | a2dp.enc_sampling_rate = 48000; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 722 | a2dp.enc_channels = 2; |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 723 | a2dp.bt_state = A2DP_STATE_DISCONNECTED; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 724 | if (a2dp.abr_config.is_abr_enabled && a2dp.abr_config.abr_started) |
| 725 | stop_abr(); |
| 726 | a2dp.abr_config.is_abr_enabled = false; |
| 727 | a2dp.abr_config.abr_started = false; |
| 728 | a2dp.abr_config.imc_instance = 0; |
| 729 | a2dp.abr_config.abr_tx_handle = NULL; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 734 | static void a2dp_check_and_set_scrambler() |
| 735 | { |
| 736 | bool scrambler_mode = false; |
| 737 | struct mixer_ctl *ctrl_scrambler_mode = NULL; |
| 738 | if (a2dp.audio_is_scrambling_enabled && (a2dp.bt_state != A2DP_STATE_DISCONNECTED)) |
| 739 | scrambler_mode = a2dp.audio_is_scrambling_enabled(); |
| 740 | |
| 741 | if (scrambler_mode) { |
| 742 | //enable scrambler in dsp |
| 743 | ctrl_scrambler_mode = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 744 | MIXER_SCRAMBLER_MODE); |
| 745 | if (!ctrl_scrambler_mode) { |
| 746 | ALOGE(" ERROR scrambler mode mixer control not identifed"); |
| 747 | return; |
| 748 | } else { |
| 749 | if (mixer_ctl_set_value(ctrl_scrambler_mode, 0, true) != 0) { |
| 750 | ALOGE("%s: Could not set scrambler mode", __func__); |
| 751 | return; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 757 | static int a2dp_set_backend_cfg() |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 758 | { |
| 759 | char *rate_str = NULL, *in_channels = NULL; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 760 | uint32_t sampling_rate_rx = a2dp.enc_sampling_rate; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 761 | struct mixer_ctl *ctl_sample_rate = NULL, *ctrl_in_channels = NULL; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 762 | |
| 763 | //For LDAC encoder open slimbus port at 96Khz for 48Khz input |
| 764 | //and 88.2Khz for 44.1Khz input. |
| 765 | if ((a2dp.bt_encoder_format == ENC_CODEC_TYPE_LDAC) && |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 766 | (sampling_rate_rx == 48000 || sampling_rate_rx == 44100 )) { |
| 767 | sampling_rate_rx *= 2; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 768 | } |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 769 | |
| 770 | // Set Rx backend sample rate |
| 771 | switch (sampling_rate_rx) { |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 772 | case 44100: |
| 773 | rate_str = "KHZ_44P1"; |
| 774 | break; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 775 | case 88200: |
| 776 | rate_str = "KHZ_88P2"; |
| 777 | break; |
| 778 | case 96000: |
| 779 | rate_str = "KHZ_96"; |
| 780 | break; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 781 | case 48000: |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 782 | default: |
| 783 | rate_str = "KHZ_48"; |
| 784 | break; |
| 785 | } |
| 786 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 787 | ALOGD("%s: set backend rx sample rate = %s", __func__, rate_str); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 788 | ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer, |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 789 | MIXER_SAMPLE_RATE_RX); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 790 | if (!ctl_sample_rate) { |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 791 | ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__); |
| 792 | return -ENOSYS; |
| 793 | } |
| 794 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) { |
| 795 | ALOGE("%s: Failed to set backend sample rate = %s", __func__, rate_str); |
| 796 | return -ENOSYS; |
| 797 | } |
| 798 | |
| 799 | // Set Tx backend sample rate |
| 800 | if (a2dp.abr_config.is_abr_enabled) |
| 801 | rate_str = ABR_TX_SAMPLE_RATE; |
| 802 | |
| 803 | ALOGD("%s: set backend tx sample rate = %s", __func__, rate_str); |
| 804 | ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 805 | MIXER_SAMPLE_RATE_TX); |
| 806 | if (!ctl_sample_rate) { |
| 807 | ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__); |
| 808 | return -ENOSYS; |
| 809 | } |
| 810 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) { |
| 811 | ALOGE("%s: Failed to set backend sample rate = %s", |
| 812 | __func__, rate_str); |
| 813 | return -ENOSYS; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | //Configure AFE input channels |
| 817 | switch (a2dp.enc_channels) { |
| 818 | case 1: |
| 819 | in_channels = "One"; |
| 820 | break; |
| 821 | case 2: |
| 822 | default: |
| 823 | in_channels = "Two"; |
| 824 | break; |
| 825 | } |
| 826 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 827 | ALOGD("%s: set AFE input channels = %d", __func__, a2dp.enc_channels); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 828 | ctrl_in_channels = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 829 | MIXER_AFE_IN_CHANNELS); |
| 830 | if (!ctrl_in_channels) { |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 831 | ALOGE("%s: ERROR AFE input channels mixer control not identifed", __func__); |
| 832 | return -ENOSYS; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 833 | } |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 834 | if (mixer_ctl_set_enum_by_string(ctrl_in_channels, in_channels) != 0) { |
| 835 | ALOGE("%s: Failed to set AFE in channels = %d", __func__, a2dp.enc_channels); |
| 836 | return -ENOSYS; |
| 837 | } |
| 838 | |
| 839 | return 0; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 840 | } |
| 841 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 842 | static int a2dp_reset_backend_cfg() |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 843 | { |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 844 | const char *rate_str = "KHZ_8", *in_channels = "Zero"; |
| 845 | struct mixer_ctl *ctl_sample_rate_rx = NULL, *ctl_sample_rate_tx = NULL; |
| 846 | struct mixer_ctl *ctrl_in_channels = NULL; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 847 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 848 | // Reset backend sampling rate |
| 849 | ALOGD("%s: reset backend sample rate = %s", __func__, rate_str); |
| 850 | ctl_sample_rate_rx = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 851 | MIXER_SAMPLE_RATE_RX); |
| 852 | if (!ctl_sample_rate_rx) { |
| 853 | ALOGE("%s: ERROR Rx backend sample rate mixer control not identifed", __func__); |
| 854 | return -ENOSYS; |
| 855 | } |
| 856 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate_rx, rate_str) != 0) { |
| 857 | ALOGE("%s: Failed to reset Rx backend sample rate = %s", __func__, rate_str); |
| 858 | return -ENOSYS; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 859 | } |
| 860 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 861 | ctl_sample_rate_tx = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 862 | MIXER_SAMPLE_RATE_TX); |
| 863 | if (!ctl_sample_rate_tx) { |
| 864 | ALOGE("%s: ERROR Tx backend sample rate mixer control not identifed", __func__); |
| 865 | return -ENOSYS; |
| 866 | } |
| 867 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate_tx, rate_str) != 0) { |
| 868 | ALOGE("%s: Failed to reset Tx backend sample rate = %s", __func__, rate_str); |
| 869 | return -ENOSYS; |
| 870 | } |
| 871 | |
| 872 | // Reset AFE input channels |
| 873 | ALOGD("%s: reset AFE input channels = %s", __func__, in_channels); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 874 | ctrl_in_channels = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 875 | MIXER_AFE_IN_CHANNELS); |
| 876 | if (!ctrl_in_channels) { |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 877 | ALOGE("%s: ERROR AFE input channels mixer control not identifed", __func__); |
| 878 | return -ENOSYS; |
| 879 | } |
| 880 | if (mixer_ctl_set_enum_by_string(ctrl_in_channels, in_channels) != 0) { |
| 881 | ALOGE("%s: Failed to reset AFE in channels = %d", __func__, a2dp.enc_channels); |
| 882 | return -ENOSYS; |
| 883 | } |
| 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | /* API to configure AFE decoder in DSP */ |
| 889 | static bool configure_a2dp_decoder_format(int dec_format) |
| 890 | { |
| 891 | struct mixer_ctl *ctl_dec_data = NULL; |
| 892 | struct abr_dec_cfg_t dec_cfg; |
| 893 | int ret = 0; |
| 894 | |
| 895 | if (a2dp.abr_config.is_abr_enabled) { |
| 896 | ctl_dec_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_DEC_CONFIG_BLOCK); |
| 897 | if (!ctl_dec_data) { |
| 898 | ALOGE("%s: ERROR A2DP codec config data mixer control not identifed", __func__); |
| 899 | return false; |
| 900 | } |
| 901 | memset(&dec_cfg, 0x0, sizeof(dec_cfg)); |
| 902 | dec_cfg.dec_format = dec_format; |
| 903 | dec_cfg.imc_info.direction = IMC_TRANSMIT; |
| 904 | dec_cfg.imc_info.enable = IMC_ENABLE; |
| 905 | dec_cfg.imc_info.purpose = IMC_PURPOSE_ID_BT_INFO; |
| 906 | dec_cfg.imc_info.comm_instance = a2dp.abr_config.imc_instance; |
| 907 | |
| 908 | ret = mixer_ctl_set_array(ctl_dec_data, &dec_cfg, |
| 909 | sizeof(dec_cfg)); |
| 910 | if (ret != 0) { |
| 911 | ALOGE("%s: Failed to set decoder config", __func__); |
| 912 | return false; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 913 | } |
| 914 | } |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 915 | |
| 916 | return true; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 917 | } |
| 918 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 919 | /* API to configure SBC DSP encoder */ |
| 920 | bool configure_sbc_enc_format(audio_sbc_encoder_config *sbc_bt_cfg) |
| 921 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 922 | struct mixer_ctl *ctl_enc_data = NULL, *ctrl_bit_format = NULL; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 923 | struct sbc_enc_cfg_t sbc_dsp_cfg; |
| 924 | bool is_configured = false; |
| 925 | int ret = 0; |
| 926 | |
| 927 | if(sbc_bt_cfg == NULL) |
| 928 | return false; |
| 929 | |
| 930 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 931 | if (!ctl_enc_data) { |
| 932 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 933 | is_configured = false; |
| 934 | goto fail; |
| 935 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 936 | memset(&sbc_dsp_cfg, 0x0, sizeof(struct sbc_enc_cfg_t)); |
| 937 | sbc_dsp_cfg.enc_format = ENC_MEDIA_FMT_SBC; |
| 938 | sbc_dsp_cfg.num_subbands = sbc_bt_cfg->subband; |
| 939 | sbc_dsp_cfg.blk_len = sbc_bt_cfg->blk_len; |
| 940 | switch(sbc_bt_cfg->channels) { |
| 941 | case 0: |
| 942 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_MONO; |
| 943 | break; |
| 944 | case 1: |
| 945 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_DUAL_MONO; |
| 946 | break; |
| 947 | case 3: |
| 948 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_JOINT_STEREO; |
| 949 | break; |
| 950 | case 2: |
| 951 | default: |
| 952 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_STEREO; |
| 953 | break; |
| 954 | } |
| 955 | if (sbc_bt_cfg->alloc) |
| 956 | sbc_dsp_cfg.alloc_method = MEDIA_FMT_SBC_ALLOCATION_METHOD_LOUDNESS; |
| 957 | else |
| 958 | sbc_dsp_cfg.alloc_method = MEDIA_FMT_SBC_ALLOCATION_METHOD_SNR; |
| 959 | sbc_dsp_cfg.bit_rate = sbc_bt_cfg->bitrate; |
| 960 | sbc_dsp_cfg.sample_rate = sbc_bt_cfg->sampling_rate; |
| 961 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&sbc_dsp_cfg, |
| 962 | sizeof(struct sbc_enc_cfg_t)); |
| 963 | if (ret != 0) { |
| 964 | ALOGE("%s: failed to set SBC encoder config", __func__); |
| 965 | is_configured = false; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 966 | goto fail; |
| 967 | } |
| 968 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 969 | MIXER_ENC_BIT_FORMAT); |
| 970 | if (!ctrl_bit_format) { |
| 971 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 972 | is_configured = false; |
| 973 | goto fail; |
| 974 | } |
| 975 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 976 | if (ret != 0) { |
| 977 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 978 | is_configured = false; |
| 979 | goto fail; |
| 980 | } |
| 981 | is_configured = true; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 982 | a2dp.bt_encoder_format = ENC_CODEC_TYPE_SBC; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 983 | a2dp.enc_sampling_rate = sbc_bt_cfg->sampling_rate; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 984 | |
| 985 | if (sbc_dsp_cfg.channel_mode == MEDIA_FMT_SBC_CHANNEL_MODE_MONO) |
| 986 | a2dp.enc_channels = 1; |
| 987 | else |
| 988 | a2dp.enc_channels = 2; |
| 989 | |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 990 | ALOGV("Successfully updated SBC enc format with samplingrate: %d channelmode:%d", |
| 991 | sbc_dsp_cfg.sample_rate, sbc_dsp_cfg.channel_mode); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 992 | fail: |
| 993 | return is_configured; |
| 994 | } |
| 995 | |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 996 | #ifndef LINUX_ENABLED |
| 997 | static int update_aptx_dsp_config_v2(struct aptx_enc_cfg_t *aptx_dsp_cfg, |
| 998 | audio_aptx_encoder_config *aptx_bt_cfg) |
| 999 | { |
| 1000 | int ret = 0; |
| 1001 | |
| 1002 | if(aptx_dsp_cfg == NULL || aptx_bt_cfg == NULL) { |
| 1003 | ALOGE("Invalid param, aptx_dsp_cfg %p aptx_bt_cfg %p", |
| 1004 | aptx_dsp_cfg, aptx_bt_cfg); |
| 1005 | return -EINVAL; |
| 1006 | } |
| 1007 | |
| 1008 | memset(aptx_dsp_cfg, 0x0, sizeof(struct aptx_enc_cfg_t)); |
| 1009 | aptx_dsp_cfg->custom_cfg.enc_format = ENC_MEDIA_FMT_APTX; |
| 1010 | |
| 1011 | if (!a2dp.is_aptx_dual_mono_supported) { |
| 1012 | aptx_dsp_cfg->custom_cfg.sample_rate = aptx_bt_cfg->default_cfg->sampling_rate; |
| 1013 | aptx_dsp_cfg->custom_cfg.num_channels = aptx_bt_cfg->default_cfg->channels; |
| 1014 | } else { |
| 1015 | aptx_dsp_cfg->custom_cfg.sample_rate = aptx_bt_cfg->dual_mono_cfg->sampling_rate; |
| 1016 | aptx_dsp_cfg->custom_cfg.num_channels = aptx_bt_cfg->dual_mono_cfg->channels; |
| 1017 | aptx_dsp_cfg->aptx_v2_cfg.sync_mode = aptx_bt_cfg->dual_mono_cfg->sync_mode; |
| 1018 | } |
| 1019 | |
| 1020 | switch(aptx_dsp_cfg->custom_cfg.num_channels) { |
| 1021 | case 1: |
| 1022 | aptx_dsp_cfg->custom_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 1023 | break; |
| 1024 | case 2: |
| 1025 | default: |
| 1026 | aptx_dsp_cfg->custom_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 1027 | aptx_dsp_cfg->custom_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 1028 | break; |
| 1029 | } |
| 1030 | a2dp.enc_channels = aptx_dsp_cfg->custom_cfg.num_channels; |
| 1031 | if (!a2dp.is_aptx_dual_mono_supported) { |
| 1032 | a2dp.enc_sampling_rate = aptx_bt_cfg->default_cfg->sampling_rate; |
| 1033 | ALOGV("Successfully updated APTX enc format with samplingrate: %d \ |
| 1034 | channels:%d", aptx_dsp_cfg->custom_cfg.sample_rate, |
| 1035 | aptx_dsp_cfg->custom_cfg.num_channels); |
| 1036 | } else { |
| 1037 | a2dp.enc_sampling_rate = aptx_bt_cfg->dual_mono_cfg->sampling_rate; |
| 1038 | ALOGV("Successfully updated APTX dual mono enc format with \ |
| 1039 | samplingrate: %d channels:%d syncmode %d", |
| 1040 | aptx_dsp_cfg->custom_cfg.sample_rate, |
| 1041 | aptx_dsp_cfg->custom_cfg.num_channels, |
| 1042 | aptx_dsp_cfg->aptx_v2_cfg.sync_mode); |
| 1043 | } |
| 1044 | return ret; |
| 1045 | } |
| 1046 | #else |
| 1047 | static int update_aptx_dsp_config_v1(struct custom_enc_cfg_t *aptx_dsp_cfg, |
| 1048 | audio_aptx_encoder_config *aptx_bt_cfg) |
| 1049 | { |
| 1050 | int ret = 0; |
| 1051 | |
| 1052 | if(aptx_dsp_cfg == NULL || aptx_bt_cfg == NULL) { |
| 1053 | ALOGE("Invalid param, aptx_dsp_cfg %p aptx_bt_cfg %p", |
| 1054 | aptx_dsp_cfg, aptx_bt_cfg); |
| 1055 | return -EINVAL; |
| 1056 | } |
| 1057 | |
| 1058 | memset(&aptx_dsp_cfg, 0x0, sizeof(struct custom_enc_cfg_t)); |
| 1059 | aptx_dsp_cfg->enc_format = ENC_MEDIA_FMT_APTX; |
| 1060 | aptx_dsp_cfg->sample_rate = aptx_bt_cfg->sampling_rate; |
| 1061 | aptx_dsp_cfg->num_channels = aptx_bt_cfg->channels; |
| 1062 | switch(aptx_dsp_cfg->num_channels) { |
| 1063 | case 1: |
| 1064 | aptx_dsp_cfg->channel_mapping[0] = PCM_CHANNEL_C; |
| 1065 | break; |
| 1066 | case 2: |
| 1067 | default: |
| 1068 | aptx_dsp_cfg->channel_mapping[0] = PCM_CHANNEL_L; |
| 1069 | aptx_dsp_cfg->channel_mapping[1] = PCM_CHANNEL_R; |
| 1070 | break; |
| 1071 | } |
| 1072 | |
| 1073 | ALOGV("Updated APTX enc format with samplingrate: %d channels:%d", |
| 1074 | aptx_dsp_cfg->sample_rate, aptx_dsp_cfg->num_channels); |
| 1075 | |
| 1076 | return ret; |
| 1077 | } |
| 1078 | #endif |
| 1079 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1080 | /* API to configure APTX DSP encoder */ |
| 1081 | bool configure_aptx_enc_format(audio_aptx_encoder_config *aptx_bt_cfg) |
| 1082 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1083 | struct mixer_ctl *ctl_enc_data = NULL, *ctrl_bit_format = NULL; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1084 | int mixer_size; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1085 | bool is_configured = false; |
| 1086 | int ret = 0; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1087 | int sample_rate_backup; |
Preetam Singh Ranawat | 109bb3c | 2018-01-30 12:12:02 +0530 | [diff] [blame] | 1088 | |
| 1089 | if(aptx_bt_cfg == NULL) |
| 1090 | return false; |
| 1091 | |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1092 | #ifndef LINUX_ENABLED |
| 1093 | struct aptx_enc_cfg_t aptx_dsp_cfg; |
| 1094 | mixer_size = sizeof(struct aptx_enc_cfg_t); |
| 1095 | sample_rate_backup = aptx_bt_cfg->default_cfg->sampling_rate; |
| 1096 | #else |
| 1097 | struct custom_enc_cfg_t aptx_dsp_cfg; |
| 1098 | mixer_size = sizeof(struct custom_enc_cfg_t); |
| 1099 | sample_rate_backup = aptx_bt_cfg->sampling_rate; |
| 1100 | #endif |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1101 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1102 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1103 | if (!ctl_enc_data) { |
| 1104 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 1105 | is_configured = false; |
| 1106 | goto fail; |
| 1107 | } |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1108 | |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1109 | #ifndef LINUX_ENABLED |
| 1110 | ret = update_aptx_dsp_config_v2(&aptx_dsp_cfg, aptx_bt_cfg); |
| 1111 | #else |
| 1112 | ret = update_aptx_dsp_config_v1(&aptx_dsp_cfg, aptx_bt_cfg); |
| 1113 | #endif |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1114 | |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1115 | if (ret) { |
| 1116 | is_configured = false; |
| 1117 | goto fail; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1118 | } |
| 1119 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg, |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1120 | mixer_size); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1121 | if (ret != 0) { |
| 1122 | ALOGE("%s: Failed to set APTX encoder config", __func__); |
| 1123 | is_configured = false; |
| 1124 | goto fail; |
| 1125 | } |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1126 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1127 | MIXER_ENC_BIT_FORMAT); |
| 1128 | if (!ctrl_bit_format) { |
| 1129 | ALOGE("ERROR bit format CONFIG data mixer control not identifed"); |
| 1130 | is_configured = false; |
| 1131 | goto fail; |
| 1132 | } else { |
| 1133 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 1134 | if (ret != 0) { |
| 1135 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 1136 | is_configured = false; |
| 1137 | goto fail; |
| 1138 | } |
| 1139 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1140 | is_configured = true; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1141 | a2dp.bt_encoder_format = ENC_CODEC_TYPE_APTX; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1142 | fail: |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1143 | /*restore sample rate */ |
| 1144 | if(!is_configured) |
| 1145 | a2dp.enc_sampling_rate = sample_rate_backup; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1146 | return is_configured; |
| 1147 | } |
| 1148 | |
| 1149 | /* API to configure APTX HD DSP encoder |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1150 | */ |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1151 | #ifndef LINUX_ENABLED |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1152 | bool configure_aptx_hd_enc_format(audio_aptx_default_config *aptx_bt_cfg) |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1153 | #else |
| 1154 | bool configure_aptx_hd_enc_format(audio_aptx_encoder_config *aptx_bt_cfg) |
| 1155 | #endif |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1156 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1157 | struct mixer_ctl *ctl_enc_data = NULL, *ctrl_bit_format = NULL; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1158 | struct custom_enc_cfg_t aptx_dsp_cfg; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1159 | bool is_configured = false; |
| 1160 | int ret = 0; |
| 1161 | |
| 1162 | if(aptx_bt_cfg == NULL) |
| 1163 | return false; |
| 1164 | |
| 1165 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1166 | if (!ctl_enc_data) { |
| 1167 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 1168 | is_configured = false; |
| 1169 | goto fail; |
| 1170 | } |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1171 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1172 | memset(&aptx_dsp_cfg, 0x0, sizeof(struct custom_enc_cfg_t)); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1173 | aptx_dsp_cfg.enc_format = ENC_MEDIA_FMT_APTX_HD; |
| 1174 | aptx_dsp_cfg.sample_rate = aptx_bt_cfg->sampling_rate; |
| 1175 | aptx_dsp_cfg.num_channels = aptx_bt_cfg->channels; |
| 1176 | switch(aptx_dsp_cfg.num_channels) { |
| 1177 | case 1: |
| 1178 | aptx_dsp_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 1179 | break; |
| 1180 | case 2: |
| 1181 | default: |
| 1182 | aptx_dsp_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 1183 | aptx_dsp_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 1184 | break; |
| 1185 | } |
| 1186 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg, |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1187 | sizeof(struct custom_enc_cfg_t)); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1188 | if (ret != 0) { |
| 1189 | ALOGE("%s: Failed to set APTX HD encoder config", __func__); |
| 1190 | is_configured = false; |
| 1191 | goto fail; |
| 1192 | } |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1193 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_BIT_FORMAT); |
| 1194 | if (!ctrl_bit_format) { |
| 1195 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 1196 | is_configured = false; |
| 1197 | goto fail; |
| 1198 | } |
| 1199 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S24_LE"); |
| 1200 | if (ret != 0) { |
| 1201 | ALOGE("%s: Failed to set APTX HD encoder config", __func__); |
| 1202 | is_configured = false; |
| 1203 | goto fail; |
| 1204 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1205 | is_configured = true; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1206 | a2dp.bt_encoder_format = ENC_CODEC_TYPE_APTX_HD; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1207 | a2dp.enc_sampling_rate = aptx_bt_cfg->sampling_rate; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1208 | a2dp.enc_channels = aptx_bt_cfg->channels; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1209 | ALOGV("Successfully updated APTX HD encformat with samplingrate: %d channels:%d", |
| 1210 | aptx_dsp_cfg.sample_rate, aptx_dsp_cfg.num_channels); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1211 | fail: |
| 1212 | return is_configured; |
| 1213 | } |
| 1214 | |
| 1215 | /* API to configure AAC DSP encoder */ |
| 1216 | bool configure_aac_enc_format(audio_aac_encoder_config *aac_bt_cfg) |
| 1217 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1218 | struct mixer_ctl *ctl_enc_data = NULL, *ctrl_bit_format = NULL; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1219 | struct aac_enc_cfg_t aac_dsp_cfg; |
| 1220 | bool is_configured = false; |
| 1221 | int ret = 0; |
| 1222 | |
| 1223 | if(aac_bt_cfg == NULL) |
| 1224 | return false; |
| 1225 | |
| 1226 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1227 | if (!ctl_enc_data) { |
| 1228 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 1229 | is_configured = false; |
| 1230 | goto fail; |
| 1231 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1232 | memset(&aac_dsp_cfg, 0x0, sizeof(struct aac_enc_cfg_t)); |
| 1233 | aac_dsp_cfg.enc_format = ENC_MEDIA_FMT_AAC; |
| 1234 | aac_dsp_cfg.bit_rate = aac_bt_cfg->bitrate; |
Naresh Tanniru | a42d0bd | 2016-09-21 15:30:46 +0530 | [diff] [blame] | 1235 | aac_dsp_cfg.sample_rate = aac_bt_cfg->sampling_rate; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1236 | switch(aac_bt_cfg->enc_mode) { |
| 1237 | case 0: |
| 1238 | aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_LC; |
| 1239 | break; |
| 1240 | case 2: |
| 1241 | aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_PS; |
| 1242 | break; |
| 1243 | case 1: |
| 1244 | default: |
| 1245 | aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_SBR; |
| 1246 | break; |
| 1247 | } |
Naresh Tanniru | a42d0bd | 2016-09-21 15:30:46 +0530 | [diff] [blame] | 1248 | aac_dsp_cfg.aac_fmt_flag = aac_bt_cfg->format_flag; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1249 | aac_dsp_cfg.channel_cfg = aac_bt_cfg->channels; |
| 1250 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aac_dsp_cfg, |
| 1251 | sizeof(struct aac_enc_cfg_t)); |
| 1252 | if (ret != 0) { |
| 1253 | ALOGE("%s: failed to set SBC encoder config", __func__); |
| 1254 | is_configured = false; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1255 | goto fail; |
| 1256 | } |
| 1257 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1258 | MIXER_ENC_BIT_FORMAT); |
| 1259 | if (!ctrl_bit_format) { |
| 1260 | is_configured = false; |
| 1261 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 1262 | goto fail; |
| 1263 | } |
| 1264 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 1265 | if (ret != 0) { |
| 1266 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 1267 | is_configured = false; |
| 1268 | goto fail; |
| 1269 | } |
| 1270 | is_configured = true; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1271 | a2dp.bt_encoder_format = ENC_CODEC_TYPE_AAC; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1272 | a2dp.enc_sampling_rate = aac_bt_cfg->sampling_rate; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1273 | a2dp.enc_channels = aac_bt_cfg->channels; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1274 | ALOGV("Successfully updated AAC enc format with samplingrate: %d channels:%d", |
| 1275 | aac_dsp_cfg.sample_rate, aac_dsp_cfg.channel_cfg); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1276 | fail: |
| 1277 | return is_configured; |
| 1278 | } |
| 1279 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1280 | bool configure_celt_enc_format(audio_celt_encoder_config *celt_bt_cfg) |
| 1281 | { |
| 1282 | struct mixer_ctl *ctl_enc_data = NULL, *ctrl_bit_format = NULL; |
| 1283 | struct celt_enc_cfg_t celt_dsp_cfg; |
| 1284 | bool is_configured = false; |
| 1285 | int ret = 0; |
| 1286 | if(celt_bt_cfg == NULL) |
| 1287 | return false; |
| 1288 | |
| 1289 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1290 | if (!ctl_enc_data) { |
| 1291 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 1292 | is_configured = false; |
| 1293 | goto fail; |
| 1294 | } |
| 1295 | memset(&celt_dsp_cfg, 0x0, sizeof(struct celt_enc_cfg_t)); |
| 1296 | |
| 1297 | celt_dsp_cfg.custom_cfg.enc_format = ENC_MEDIA_FMT_CELT; |
| 1298 | celt_dsp_cfg.custom_cfg.sample_rate = celt_bt_cfg->sampling_rate; |
| 1299 | celt_dsp_cfg.custom_cfg.num_channels = celt_bt_cfg->channels; |
| 1300 | switch(celt_dsp_cfg.custom_cfg.num_channels) { |
| 1301 | case 1: |
| 1302 | celt_dsp_cfg.custom_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 1303 | break; |
| 1304 | case 2: |
| 1305 | default: |
| 1306 | celt_dsp_cfg.custom_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 1307 | celt_dsp_cfg.custom_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 1308 | break; |
| 1309 | } |
| 1310 | |
| 1311 | celt_dsp_cfg.custom_cfg.custom_size = sizeof(struct celt_enc_cfg_t); |
| 1312 | |
| 1313 | celt_dsp_cfg.celt_cfg.frame_size = celt_bt_cfg->frame_size; |
| 1314 | celt_dsp_cfg.celt_cfg.complexity = celt_bt_cfg->complexity; |
| 1315 | celt_dsp_cfg.celt_cfg.prediction_mode = celt_bt_cfg->prediction_mode; |
| 1316 | celt_dsp_cfg.celt_cfg.vbr_flag = celt_bt_cfg->vbr_flag; |
| 1317 | celt_dsp_cfg.celt_cfg.bit_rate = celt_bt_cfg->bitrate; |
| 1318 | |
| 1319 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&celt_dsp_cfg, |
| 1320 | sizeof(struct celt_enc_cfg_t)); |
| 1321 | if (ret != 0) { |
| 1322 | ALOGE("%s: Failed to set CELT encoder config", __func__); |
| 1323 | is_configured = false; |
| 1324 | goto fail; |
| 1325 | } |
| 1326 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_BIT_FORMAT); |
| 1327 | if (!ctrl_bit_format) { |
| 1328 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 1329 | is_configured = false; |
| 1330 | goto fail; |
| 1331 | } |
| 1332 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 1333 | if (ret != 0) { |
| 1334 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 1335 | is_configured = false; |
| 1336 | goto fail; |
| 1337 | } |
| 1338 | is_configured = true; |
| 1339 | a2dp.bt_encoder_format = ENC_CODEC_TYPE_CELT; |
| 1340 | a2dp.enc_sampling_rate = celt_bt_cfg->sampling_rate; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1341 | a2dp.enc_channels = celt_bt_cfg->channels; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1342 | ALOGV("Successfully updated CELT encformat with samplingrate: %d channels:%d", |
| 1343 | celt_dsp_cfg.custom_cfg.sample_rate, celt_dsp_cfg.custom_cfg.num_channels); |
| 1344 | fail: |
| 1345 | return is_configured; |
| 1346 | } |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1347 | |
| 1348 | bool configure_ldac_enc_format(audio_ldac_encoder_config *ldac_bt_cfg) |
| 1349 | { |
| 1350 | struct mixer_ctl *ldac_enc_data = NULL, *ctrl_bit_format = NULL; |
| 1351 | struct ldac_enc_cfg_t ldac_dsp_cfg; |
| 1352 | bool is_configured = false; |
| 1353 | int ret = 0; |
| 1354 | if(ldac_bt_cfg == NULL) |
| 1355 | return false; |
| 1356 | |
| 1357 | ldac_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1358 | if (!ldac_enc_data) { |
| 1359 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 1360 | is_configured = false; |
| 1361 | goto fail; |
| 1362 | } |
| 1363 | memset(&ldac_dsp_cfg, 0x0, sizeof(struct ldac_enc_cfg_t)); |
| 1364 | |
| 1365 | ldac_dsp_cfg.custom_cfg.enc_format = ENC_MEDIA_FMT_LDAC; |
| 1366 | ldac_dsp_cfg.custom_cfg.sample_rate = ldac_bt_cfg->sampling_rate; |
| 1367 | ldac_dsp_cfg.ldac_cfg.channel_mode = ldac_bt_cfg->channel_mode; |
| 1368 | switch(ldac_dsp_cfg.ldac_cfg.channel_mode) { |
| 1369 | case 4: |
| 1370 | ldac_dsp_cfg.custom_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 1371 | ldac_dsp_cfg.custom_cfg.num_channels = 1; |
| 1372 | break; |
| 1373 | case 2: |
| 1374 | case 1: |
| 1375 | default: |
| 1376 | ldac_dsp_cfg.custom_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 1377 | ldac_dsp_cfg.custom_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 1378 | ldac_dsp_cfg.custom_cfg.num_channels = 2; |
| 1379 | break; |
| 1380 | } |
| 1381 | |
| 1382 | ldac_dsp_cfg.custom_cfg.custom_size = sizeof(struct ldac_enc_cfg_t); |
| 1383 | ldac_dsp_cfg.ldac_cfg.mtu = ldac_bt_cfg->mtu; |
| 1384 | ldac_dsp_cfg.ldac_cfg.bit_rate = ldac_bt_cfg->bit_rate; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1385 | if (ldac_bt_cfg->is_abr_enabled) { |
| 1386 | ldac_dsp_cfg.abr_cfg.mapping_info = ldac_bt_cfg->level_to_bitrate_map; |
| 1387 | ldac_dsp_cfg.abr_cfg.imc_info.direction = IMC_RECEIVE; |
| 1388 | ldac_dsp_cfg.abr_cfg.imc_info.enable = IMC_ENABLE; |
| 1389 | ldac_dsp_cfg.abr_cfg.imc_info.purpose = IMC_PURPOSE_ID_BT_INFO; |
| 1390 | ldac_dsp_cfg.abr_cfg.imc_info.comm_instance = a2dp.abr_config.imc_instance; |
| 1391 | } |
| 1392 | |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1393 | ret = mixer_ctl_set_array(ldac_enc_data, (void *)&ldac_dsp_cfg, |
| 1394 | sizeof(struct ldac_enc_cfg_t)); |
| 1395 | if (ret != 0) { |
| 1396 | ALOGE("%s: Failed to set LDAC encoder config", __func__); |
| 1397 | is_configured = false; |
| 1398 | goto fail; |
| 1399 | } |
| 1400 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_BIT_FORMAT); |
| 1401 | if (!ctrl_bit_format) { |
| 1402 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 1403 | is_configured = false; |
| 1404 | goto fail; |
| 1405 | } |
| 1406 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 1407 | if (ret != 0) { |
| 1408 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 1409 | is_configured = false; |
| 1410 | goto fail; |
| 1411 | } |
| 1412 | is_configured = true; |
| 1413 | a2dp.bt_encoder_format = ENC_CODEC_TYPE_LDAC; |
| 1414 | a2dp.enc_sampling_rate = ldac_bt_cfg->sampling_rate; |
| 1415 | a2dp.enc_channels = ldac_dsp_cfg.custom_cfg.num_channels; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1416 | a2dp.abr_config.is_abr_enabled = ldac_bt_cfg->is_abr_enabled; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1417 | ALOGV("Successfully updated LDAC encformat with samplingrate: %d channels:%d", |
| 1418 | ldac_dsp_cfg.custom_cfg.sample_rate, ldac_dsp_cfg.custom_cfg.num_channels); |
| 1419 | fail: |
| 1420 | return is_configured; |
| 1421 | } |
| 1422 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1423 | bool configure_a2dp_encoder_format() |
| 1424 | { |
| 1425 | void *codec_info = NULL; |
| 1426 | uint8_t multi_cast = 0, num_dev = 1; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1427 | enc_codec_t codec_type = ENC_CODEC_TYPE_INVALID; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1428 | bool is_configured = false; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1429 | audio_aptx_encoder_config aptx_encoder_cfg; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1430 | |
| 1431 | if (!a2dp.audio_get_codec_config) { |
| 1432 | ALOGE(" a2dp handle is not identified, ignoring a2dp encoder config"); |
| 1433 | return false; |
| 1434 | } |
| 1435 | ALOGD("configure_a2dp_encoder_format start"); |
| 1436 | codec_info = a2dp.audio_get_codec_config(&multi_cast, &num_dev, |
| 1437 | &codec_type); |
| 1438 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1439 | // ABR disabled by default for all codecs |
| 1440 | a2dp.abr_config.is_abr_enabled = false; |
| 1441 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1442 | switch(codec_type) { |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1443 | case ENC_CODEC_TYPE_SBC: |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1444 | ALOGD(" Received SBC encoder supported BT device"); |
| 1445 | is_configured = |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1446 | configure_sbc_enc_format((audio_sbc_encoder_config *)codec_info); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1447 | break; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1448 | case ENC_CODEC_TYPE_APTX: |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1449 | ALOGD(" Received APTX encoder supported BT device"); |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1450 | #ifndef LINUX_ENABLED |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1451 | a2dp.is_aptx_dual_mono_supported = false; |
| 1452 | aptx_encoder_cfg.default_cfg = (audio_aptx_default_config *)codec_info; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1453 | #endif |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1454 | is_configured = |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1455 | configure_aptx_enc_format(&aptx_encoder_cfg); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1456 | break; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1457 | case ENC_CODEC_TYPE_APTX_HD: |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1458 | ALOGD(" Received APTX HD encoder supported BT device"); |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1459 | #ifndef LINUX_ENABLED |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1460 | is_configured = |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1461 | configure_aptx_hd_enc_format((audio_aptx_default_config *)codec_info); |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1462 | #else |
| 1463 | is_configured = |
| 1464 | configure_aptx_hd_enc_format((audio_aptx_encoder_config *)codec_info); |
| 1465 | #endif |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1466 | break; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1467 | #ifndef LINUX_ENABLED |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1468 | case ENC_CODEC_TYPE_APTX_DUAL_MONO: |
| 1469 | ALOGD(" Received APTX dual mono encoder supported BT device"); |
| 1470 | a2dp.is_aptx_dual_mono_supported = true; |
| 1471 | aptx_encoder_cfg.dual_mono_cfg = (audio_aptx_dual_mono_config *)codec_info; |
| 1472 | is_configured = |
| 1473 | configure_aptx_enc_format(&aptx_encoder_cfg); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1474 | break; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1475 | #endif |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1476 | case ENC_CODEC_TYPE_AAC: |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1477 | ALOGD(" Received AAC encoder supported BT device"); |
| 1478 | is_configured = |
| 1479 | configure_aac_enc_format((audio_aac_encoder_config *)codec_info); |
| 1480 | break; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1481 | case ENC_CODEC_TYPE_CELT: |
| 1482 | ALOGD(" Received CELT encoder supported BT device"); |
| 1483 | is_configured = |
| 1484 | configure_celt_enc_format((audio_celt_encoder_config *)codec_info); |
| 1485 | break; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1486 | case ENC_CODEC_TYPE_LDAC: |
| 1487 | ALOGD(" Received LDAC encoder supported BT device"); |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1488 | if (!instance_id || instance_id > MAX_INSTANCE_ID) |
| 1489 | instance_id = MAX_INSTANCE_ID; |
| 1490 | a2dp.abr_config.imc_instance = instance_id--; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1491 | is_configured = |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1492 | (configure_ldac_enc_format((audio_ldac_encoder_config *)codec_info) && |
| 1493 | configure_a2dp_decoder_format(ENC_CODEC_TYPE_LDAC)); |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1494 | break; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1495 | default: |
| 1496 | ALOGD(" Received Unsupported encoder formar"); |
| 1497 | is_configured = false; |
| 1498 | break; |
| 1499 | } |
| 1500 | return is_configured; |
| 1501 | } |
| 1502 | |
| 1503 | int audio_extn_a2dp_start_playback() |
| 1504 | { |
| 1505 | int ret = 0; |
| 1506 | |
| 1507 | ALOGD("audio_extn_a2dp_start_playback start"); |
| 1508 | |
| 1509 | if(!(a2dp.bt_lib_handle && a2dp.audio_start_stream |
| 1510 | && a2dp.audio_get_codec_config)) { |
| 1511 | ALOGE("a2dp handle is not identified, Ignoring start request"); |
| 1512 | return -ENOSYS; |
| 1513 | } |
| 1514 | |
| 1515 | if(a2dp.a2dp_suspended == true) { |
| 1516 | //session will be restarted after suspend completion |
| 1517 | ALOGD("a2dp start requested during suspend state"); |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 1518 | return -ENOSYS; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | if (!a2dp.a2dp_started && !a2dp.a2dp_total_active_session_request) { |
| 1522 | ALOGD("calling BT module stream start"); |
| 1523 | /* This call indicates BT IPC lib to start playback */ |
| 1524 | ret = a2dp.audio_start_stream(); |
| 1525 | ALOGE("BT controller start return = %d",ret); |
| 1526 | if (ret != 0 ) { |
| 1527 | ALOGE("BT controller start failed"); |
| 1528 | a2dp.a2dp_started = false; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1529 | } else { |
| 1530 | if(configure_a2dp_encoder_format() == true) { |
| 1531 | a2dp.a2dp_started = true; |
| 1532 | ret = 0; |
| 1533 | ALOGD("Start playback successful to BT library"); |
| 1534 | } else { |
| 1535 | ALOGD(" unable to configure DSP encoder"); |
| 1536 | a2dp.a2dp_started = false; |
| 1537 | ret = -ETIMEDOUT; |
| 1538 | } |
| 1539 | } |
| 1540 | } |
| 1541 | |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1542 | if (a2dp.a2dp_started) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1543 | a2dp.a2dp_total_active_session_request++; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1544 | a2dp_check_and_set_scrambler(); |
| 1545 | a2dp_set_backend_cfg(); |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1546 | if (a2dp.abr_config.is_abr_enabled) |
| 1547 | start_abr(); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1548 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1549 | |
| 1550 | ALOGD("start A2DP playback total active sessions :%d", |
| 1551 | a2dp.a2dp_total_active_session_request); |
| 1552 | return ret; |
| 1553 | } |
| 1554 | |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 1555 | static void reset_a2dp_enc_config_params() |
| 1556 | { |
| 1557 | int ret =0; |
| 1558 | |
| 1559 | struct mixer_ctl *ctl_enc_config, *ctrl_bit_format; |
| 1560 | struct sbc_enc_cfg_t dummy_reset_config; |
| 1561 | |
| 1562 | memset(&dummy_reset_config, 0x0, sizeof(struct sbc_enc_cfg_t)); |
| 1563 | ctl_enc_config = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1564 | MIXER_ENC_CONFIG_BLOCK); |
| 1565 | if (!ctl_enc_config) { |
| 1566 | ALOGE(" ERROR a2dp encoder format mixer control not identifed"); |
| 1567 | } else { |
| 1568 | ret = mixer_ctl_set_array(ctl_enc_config, (void *)&dummy_reset_config, |
| 1569 | sizeof(struct sbc_enc_cfg_t)); |
| 1570 | a2dp.bt_encoder_format = ENC_MEDIA_FMT_NONE; |
| 1571 | } |
| 1572 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1573 | MIXER_ENC_BIT_FORMAT); |
| 1574 | if (!ctrl_bit_format) { |
| 1575 | ALOGE(" ERROR bit format CONFIG data mixer control not identifed"); |
| 1576 | } else { |
| 1577 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 1578 | if (ret != 0) { |
| 1579 | ALOGE("%s: Failed to set bit format to encoder", __func__); |
| 1580 | } |
| 1581 | } |
| 1582 | } |
| 1583 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1584 | int audio_extn_a2dp_stop_playback() |
| 1585 | { |
| 1586 | int ret =0; |
| 1587 | |
| 1588 | ALOGV("audio_extn_a2dp_stop_playback start"); |
| 1589 | if(!(a2dp.bt_lib_handle && a2dp.audio_stop_stream)) { |
| 1590 | ALOGE("a2dp handle is not identified, Ignoring start request"); |
| 1591 | return -ENOSYS; |
| 1592 | } |
| 1593 | |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 1594 | if (a2dp.a2dp_total_active_session_request > 0) |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1595 | a2dp.a2dp_total_active_session_request--; |
| 1596 | |
| 1597 | if ( a2dp.a2dp_started && !a2dp.a2dp_total_active_session_request) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1598 | ALOGV("calling BT module stream stop"); |
| 1599 | ret = a2dp.audio_stop_stream(); |
| 1600 | if (ret < 0) |
| 1601 | ALOGE("stop stream to BT IPC lib failed"); |
| 1602 | else |
| 1603 | ALOGV("stop steam to BT IPC lib successful"); |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 1604 | reset_a2dp_enc_config_params(); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1605 | a2dp_reset_backend_cfg(); |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1606 | if (a2dp.abr_config.is_abr_enabled && a2dp.abr_config.abr_started) |
| 1607 | stop_abr(); |
| 1608 | a2dp.abr_config.is_abr_enabled = false; |
| 1609 | a2dp.a2dp_started = false; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1610 | } |
| 1611 | if(!a2dp.a2dp_total_active_session_request) |
| 1612 | a2dp.a2dp_started = false; |
| 1613 | ALOGD("Stop A2DP playback total active sessions :%d", |
| 1614 | a2dp.a2dp_total_active_session_request); |
| 1615 | return 0; |
| 1616 | } |
| 1617 | |
| 1618 | void audio_extn_a2dp_set_parameters(struct str_parms *parms) |
| 1619 | { |
| 1620 | int ret, val; |
| 1621 | char value[32]={0}; |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 1622 | struct audio_usecase *uc_info; |
| 1623 | struct listnode *node; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1624 | |
| 1625 | if(a2dp.is_a2dp_offload_supported == false) { |
| 1626 | ALOGV("no supported encoders identified,ignoring a2dp setparam"); |
| 1627 | return; |
| 1628 | } |
| 1629 | |
| 1630 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, |
| 1631 | sizeof(value)); |
Zhou Song | 681350a | 2017-10-19 16:28:42 +0800 | [diff] [blame] | 1632 | if (ret >= 0) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1633 | val = atoi(value); |
Zhou Song | 681350a | 2017-10-19 16:28:42 +0800 | [diff] [blame] | 1634 | if (audio_is_a2dp_out_device(val)) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1635 | ALOGV("Received device connect request for A2DP"); |
| 1636 | open_a2dp_output(); |
| 1637 | } |
| 1638 | goto param_handled; |
| 1639 | } |
| 1640 | |
| 1641 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, |
| 1642 | sizeof(value)); |
| 1643 | |
Zhou Song | 681350a | 2017-10-19 16:28:42 +0800 | [diff] [blame] | 1644 | if (ret >= 0) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1645 | val = atoi(value); |
Zhou Song | 681350a | 2017-10-19 16:28:42 +0800 | [diff] [blame] | 1646 | if (audio_is_a2dp_out_device(val)) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1647 | ALOGV("Received device dis- connect request"); |
| 1648 | close_a2dp_output(); |
kunleiz | 4a1fad6 | 2018-02-08 18:00:16 +0800 | [diff] [blame] | 1649 | reset_a2dp_enc_config_params(); |
| 1650 | a2dp_reset_backend_cfg(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1651 | } |
| 1652 | goto param_handled; |
| 1653 | } |
| 1654 | |
| 1655 | ret = str_parms_get_str(parms, "A2dpSuspended", value, sizeof(value)); |
| 1656 | if (ret >= 0) { |
| 1657 | if (a2dp.bt_lib_handle && (a2dp.bt_state != A2DP_STATE_DISCONNECTED) ) { |
| 1658 | if ((!strncmp(value,"true",sizeof(value)))) { |
| 1659 | ALOGD("Setting a2dp to suspend state"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1660 | a2dp.a2dp_suspended = true; |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 1661 | list_for_each(node, &a2dp.adev->usecase_list) { |
| 1662 | uc_info = node_to_item(node, struct audio_usecase, list); |
Zhou Song | c66eb7e | 2017-08-08 18:29:07 +0800 | [diff] [blame] | 1663 | if (uc_info->type == PCM_PLAYBACK && |
| 1664 | (uc_info->stream.out->devices & AUDIO_DEVICE_OUT_ALL_A2DP)) { |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 1665 | pthread_mutex_unlock(&a2dp.adev->lock); |
| 1666 | check_a2dp_restore(a2dp.adev, uc_info->stream.out, false); |
| 1667 | pthread_mutex_lock(&a2dp.adev->lock); |
| 1668 | } |
| 1669 | } |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 1670 | reset_a2dp_enc_config_params(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1671 | if(a2dp.audio_suspend_stream) |
| 1672 | a2dp.audio_suspend_stream(); |
| 1673 | } else if (a2dp.a2dp_suspended == true) { |
| 1674 | ALOGD("Resetting a2dp suspend state"); |
Zhou Song | 10617ed | 2017-05-26 13:28:48 +0800 | [diff] [blame] | 1675 | struct audio_usecase *uc_info; |
| 1676 | struct listnode *node; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1677 | if(a2dp.clear_a2dpsuspend_flag) |
| 1678 | a2dp.clear_a2dpsuspend_flag(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1679 | a2dp.a2dp_suspended = false; |
Naresh Tanniru | 649871a | 2016-11-04 18:08:32 +0530 | [diff] [blame] | 1680 | /* |
| 1681 | * It is possible that before suspend,a2dp sessions can be active |
| 1682 | * for example during music + voice activation concurrency |
| 1683 | * a2dp suspend will be called & BT will change to sco mode |
| 1684 | * though music is paused as a part of voice activation |
| 1685 | * compress session close happens only after pause timeout(10secs) |
| 1686 | * so if resume request comes before pause timeout as a2dp session |
| 1687 | * is already active IPC start will not be called from APM/audio_hw |
| 1688 | * Fix is to call a2dp start for IPC library post suspend |
| 1689 | * based on number of active session count |
| 1690 | */ |
| 1691 | if (a2dp.a2dp_total_active_session_request > 0) { |
| 1692 | ALOGD(" Calling IPC lib start post suspend state"); |
| 1693 | if(a2dp.audio_start_stream) { |
| 1694 | ret = a2dp.audio_start_stream(); |
| 1695 | if (ret != 0) { |
| 1696 | ALOGE("BT controller start failed"); |
| 1697 | a2dp.a2dp_started = false; |
| 1698 | } |
| 1699 | } |
| 1700 | } |
Zhou Song | 10617ed | 2017-05-26 13:28:48 +0800 | [diff] [blame] | 1701 | list_for_each(node, &a2dp.adev->usecase_list) { |
| 1702 | uc_info = node_to_item(node, struct audio_usecase, list); |
Zhou Song | c66eb7e | 2017-08-08 18:29:07 +0800 | [diff] [blame] | 1703 | if (uc_info->type == PCM_PLAYBACK && |
| 1704 | (uc_info->stream.out->devices & AUDIO_DEVICE_OUT_ALL_A2DP)) { |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 1705 | pthread_mutex_unlock(&a2dp.adev->lock); |
| 1706 | check_a2dp_restore(a2dp.adev, uc_info->stream.out, true); |
| 1707 | pthread_mutex_lock(&a2dp.adev->lock); |
| 1708 | } |
Zhou Song | 10617ed | 2017-05-26 13:28:48 +0800 | [diff] [blame] | 1709 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1710 | } |
| 1711 | } |
| 1712 | goto param_handled; |
| 1713 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1714 | param_handled: |
| 1715 | ALOGV("end of a2dp setparam"); |
| 1716 | } |
| 1717 | |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 1718 | void audio_extn_a2dp_set_handoff_mode(bool is_on) |
| 1719 | { |
| 1720 | a2dp.is_handoff_in_progress = is_on; |
| 1721 | } |
| 1722 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1723 | bool audio_extn_a2dp_is_force_device_switch() |
| 1724 | { |
| 1725 | //During encoder reconfiguration mode, force a2dp device switch |
Ashish Jain | c597d10 | 2016-12-12 10:31:34 +0530 | [diff] [blame] | 1726 | // Or if a2dp device is selected but earlier start failed ( as a2dp |
| 1727 | // was suspended, force retry. |
| 1728 | return a2dp.is_handoff_in_progress || !a2dp.a2dp_started; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1729 | } |
| 1730 | |
Preetam Singh Ranawat | b7475ba | 2017-02-24 18:17:06 +0530 | [diff] [blame] | 1731 | void audio_extn_a2dp_get_sample_rate(int *sample_rate) |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1732 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1733 | *sample_rate = a2dp.enc_sampling_rate; |
| 1734 | } |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 1735 | |
| 1736 | bool audio_extn_a2dp_is_ready() |
| 1737 | { |
| 1738 | bool ret = false; |
| 1739 | |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 1740 | if (a2dp.a2dp_suspended) |
| 1741 | return ret; |
| 1742 | |
Aniket Kumar Lata | 901bcb8 | 2017-03-10 15:42:46 -0800 | [diff] [blame] | 1743 | if ((a2dp.bt_state != A2DP_STATE_DISCONNECTED) && |
| 1744 | (a2dp.is_a2dp_offload_supported) && |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 1745 | (a2dp.audio_check_a2dp_ready)) |
| 1746 | ret = a2dp.audio_check_a2dp_ready(); |
| 1747 | return ret; |
| 1748 | } |
| 1749 | |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 1750 | bool audio_extn_a2dp_is_suspended() |
| 1751 | { |
| 1752 | return a2dp.a2dp_suspended; |
| 1753 | } |
| 1754 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1755 | void audio_extn_a2dp_init (void *adev) |
| 1756 | { |
| 1757 | a2dp.adev = (struct audio_device*)adev; |
| 1758 | a2dp.bt_lib_handle = NULL; |
| 1759 | a2dp.a2dp_started = false; |
| 1760 | a2dp.bt_state = A2DP_STATE_DISCONNECTED; |
| 1761 | a2dp.a2dp_total_active_session_request = 0; |
| 1762 | a2dp.a2dp_suspended = false; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1763 | a2dp.bt_encoder_format = ENC_CODEC_TYPE_INVALID; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1764 | a2dp.enc_sampling_rate = 48000; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1765 | a2dp.is_a2dp_offload_supported = false; |
| 1766 | a2dp.is_handoff_in_progress = false; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1767 | a2dp.is_aptx_dual_mono_supported = false; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1768 | a2dp.abr_config.is_abr_enabled = false; |
| 1769 | a2dp.abr_config.abr_started = false; |
| 1770 | a2dp.abr_config.imc_instance = 0; |
| 1771 | a2dp.abr_config.abr_tx_handle = NULL; |
kunleiz | 5a12726 | 2017-09-08 14:47:48 +0800 | [diff] [blame] | 1772 | reset_a2dp_enc_config_params(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1773 | update_offload_codec_capabilities(); |
| 1774 | } |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1775 | |
| 1776 | uint32_t audio_extn_a2dp_get_encoder_latency() |
| 1777 | { |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1778 | uint32_t latency = 0; |
| 1779 | int avsync_runtime_prop = 0; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1780 | int sbc_offset = 0, aptx_offset = 0, aptxhd_offset = 0, |
| 1781 | aac_offset = 0, celt_offset = 0, ldac_offset = 0; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1782 | char value[PROPERTY_VALUE_MAX]; |
| 1783 | |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1784 | memset(value, '\0', sizeof(char)*PROPERTY_VALUE_MAX); |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 1785 | avsync_runtime_prop = property_get("vendor.audio.a2dp.codec.latency", value, NULL); |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1786 | if (avsync_runtime_prop > 0) { |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1787 | if (sscanf(value, "%d/%d/%d/%d/%d%d", |
| 1788 | &sbc_offset, &aptx_offset, &aptxhd_offset, &aac_offset, &celt_offset, &ldac_offset) != 6) { |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1789 | ALOGI("Failed to parse avsync offset params from '%s'.", value); |
| 1790 | avsync_runtime_prop = 0; |
| 1791 | } |
| 1792 | } |
| 1793 | |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 1794 | uint32_t slatency = 0; |
| 1795 | if (a2dp.audio_get_a2dp_sink_latency && a2dp.bt_state != A2DP_STATE_DISCONNECTED) { |
| 1796 | slatency = a2dp.audio_get_a2dp_sink_latency(); |
| 1797 | } |
| 1798 | |
Aniket Kumar Lata | faaffde | 2017-03-22 19:18:15 -0700 | [diff] [blame] | 1799 | switch(a2dp.bt_encoder_format) { |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1800 | case ENC_CODEC_TYPE_SBC: |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 1801 | latency = (avsync_runtime_prop > 0) ? sbc_offset : ENCODER_LATENCY_SBC; |
| 1802 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_SBC : slatency; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1803 | break; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1804 | case ENC_CODEC_TYPE_APTX: |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 1805 | latency = (avsync_runtime_prop > 0) ? aptx_offset : ENCODER_LATENCY_APTX; |
| 1806 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_APTX : slatency; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1807 | break; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1808 | case ENC_CODEC_TYPE_APTX_HD: |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 1809 | latency = (avsync_runtime_prop > 0) ? aptxhd_offset : ENCODER_LATENCY_APTX_HD; |
| 1810 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_APTX_HD : slatency; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1811 | break; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1812 | case ENC_CODEC_TYPE_AAC: |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 1813 | latency = (avsync_runtime_prop > 0) ? aac_offset : ENCODER_LATENCY_AAC; |
| 1814 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_AAC : slatency; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1815 | break; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1816 | case ENC_CODEC_TYPE_CELT: |
| 1817 | latency = (avsync_runtime_prop > 0) ? celt_offset : ENCODER_LATENCY_CELT; |
| 1818 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_CELT : slatency; |
| 1819 | break; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1820 | case ENC_CODEC_TYPE_LDAC: |
| 1821 | latency = (avsync_runtime_prop > 0) ? ldac_offset : ENCODER_LATENCY_LDAC; |
| 1822 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_LDAC : slatency; |
| 1823 | break; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 1824 | default: |
| 1825 | latency = 200; |
| 1826 | break; |
| 1827 | } |
| 1828 | return latency; |
| 1829 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1830 | #endif // SPLIT_A2DP_ENABLED |