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