Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1 | /* |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2 | * Copyright (c) 2015-2019, 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 | */ |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 29 | #define LOG_TAG "a2dp_offload" |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 30 | /*#define LOG_NDEBUG 0*/ |
| 31 | #define LOG_NDDEBUG 0 |
| 32 | #include <errno.h> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 33 | #include <log/log.h> |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 34 | #include <dlfcn.h> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 35 | #include <pthread.h> |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 36 | #include "audio_hw.h" |
| 37 | #include "platform.h" |
| 38 | #include "platform_api.h" |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 39 | #include "audio_extn.h" |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 40 | #include <stdlib.h> |
| 41 | #include <cutils/str_parms.h> |
| 42 | #include <hardware/audio.h> |
| 43 | #include <hardware/hardware.h> |
| 44 | #include <cutils/properties.h> |
| 45 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 46 | #ifdef DYNAMIC_LOG_ENABLED |
| 47 | #include <log_xml_parser.h> |
| 48 | #define LOG_MASK HAL_MOD_FILE_A2DP |
| 49 | #include <log_utils.h> |
| 50 | #endif |
| 51 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 52 | #ifdef A2DP_OFFLOAD_ENABLED |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 53 | #define AUDIO_PARAMETER_A2DP_STARTED "A2dpStarted" |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 54 | #define BT_IPC_SOURCE_LIB_NAME "libbthost_if.so" |
| 55 | #define BT_IPC_SINK_LIB_NAME "libbthost_if_sink.so" |
| 56 | #define MEDIA_FMT_NONE 0 |
| 57 | #define MEDIA_FMT_AAC 0x00010DA6 |
| 58 | #define MEDIA_FMT_APTX 0x000131ff |
| 59 | #define MEDIA_FMT_APTX_HD 0x00013200 |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 60 | #define MEDIA_FMT_APTX_AD 0x00013204 |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 61 | #define MEDIA_FMT_SBC 0x00010BF2 |
| 62 | #define MEDIA_FMT_CELT 0x00013221 |
| 63 | #define MEDIA_FMT_LDAC 0x00013224 |
| 64 | #define MEDIA_FMT_MP3 0x00010BE9 |
| 65 | #define MEDIA_FMT_APTX_ADAPTIVE 0x00013204 |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 66 | #define MEDIA_FMT_AAC_AOT_LC 2 |
| 67 | #define MEDIA_FMT_AAC_AOT_SBR 5 |
| 68 | #define MEDIA_FMT_AAC_AOT_PS 29 |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 69 | #define PCM_CHANNEL_L 1 |
| 70 | #define PCM_CHANNEL_R 2 |
| 71 | #define PCM_CHANNEL_C 3 |
| 72 | #define MEDIA_FMT_SBC_CHANNEL_MODE_MONO 1 |
| 73 | #define MEDIA_FMT_SBC_CHANNEL_MODE_STEREO 2 |
| 74 | #define MEDIA_FMT_SBC_CHANNEL_MODE_DUAL_MONO 8 |
| 75 | #define MEDIA_FMT_SBC_CHANNEL_MODE_JOINT_STEREO 9 |
| 76 | #define MEDIA_FMT_SBC_ALLOCATION_METHOD_LOUDNESS 0 |
| 77 | #define MEDIA_FMT_SBC_ALLOCATION_METHOD_SNR 1 |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 78 | #define MIXER_ENC_CONFIG_BLOCK "SLIM_7_RX Encoder Config" |
| 79 | #define MIXER_SOURCE_DEC_CONFIG_BLOCK "SLIM_7_TX Decoder Config" |
| 80 | #define MIXER_SINK_DEC_CONFIG_BLOCK "SLIM_9_TX Decoder Config" |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 81 | #define MIXER_ENC_BIT_FORMAT "AFE Input Bit Format" |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 82 | #define MIXER_DEC_BIT_FORMAT "AFE Output Bit Format" |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 83 | #define MIXER_SCRAMBLER_MODE "AFE Scrambler Mode" |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 84 | #define MIXER_SAMPLE_RATE_RX "BT SampleRate RX" |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 85 | #define MIXER_SOURCE_SAMPLE_RATE_TX "BT SampleRate TX" |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 86 | #define MIXER_SAMPLE_RATE_DEFAULT "BT SampleRate" |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 87 | #define MIXER_AFE_IN_CHANNELS "AFE Input Channels" |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 88 | #define MIXER_ABR_TX_FEEDBACK_PATH "A2DP_SLIM7_UL_HL Switch" |
| 89 | #define MIXER_SET_FEEDBACK_CHANNEL "BT set feedback channel" |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 90 | #define MIXER_SINK_SAMPLE_RATE "BT_TX SampleRate" |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 91 | #define MIXER_AFE_SINK_CHANNELS "AFE Output Channels" |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 92 | #define MIXER_ENC_FMT_SBC "SBC" |
| 93 | #define MIXER_ENC_FMT_AAC "AAC" |
| 94 | #define MIXER_ENC_FMT_APTX "APTX" |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 95 | #define MIXER_FMT_TWS_CHANNEL_MODE "TWS Channel Mode" |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 96 | #define MIXER_ENC_FMT_APTXHD "APTXHD" |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 97 | #define MIXER_END_FMT_LDAC "LDAC" |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 98 | #define MIXER_ENC_FMT_NONE "NONE" |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 99 | #define ENCODER_LATENCY_SBC 10 |
| 100 | #define ENCODER_LATENCY_APTX 40 |
| 101 | #define ENCODER_LATENCY_APTX_HD 20 |
| 102 | #define ENCODER_LATENCY_AAC 70 |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 103 | //To Do: Fine Tune Encoder CELT/LDAC latency. |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 104 | #define ENCODER_LATENCY_CELT 40 |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 105 | #define ENCODER_LATENCY_LDAC 40 |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 106 | #define ENCODER_LATENCY_PCM 50 |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 107 | #define DEFAULT_SINK_LATENCY_SBC 140 |
| 108 | #define DEFAULT_SINK_LATENCY_APTX 160 |
| 109 | #define DEFAULT_SINK_LATENCY_APTX_HD 180 |
| 110 | #define DEFAULT_SINK_LATENCY_AAC 180 |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 111 | //To Do: Fine Tune Default CELT/LDAC Latency. |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 112 | #define DEFAULT_SINK_LATENCY_CELT 180 |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 113 | #define DEFAULT_SINK_LATENCY_LDAC 180 |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 114 | #define DEFAULT_SINK_LATENCY_PCM 140 |
| 115 | |
| 116 | #define SYSPROP_A2DP_OFFLOAD_SUPPORTED "ro.bluetooth.a2dp_offload.supported" |
| 117 | #define SYSPROP_A2DP_OFFLOAD_DISABLED "persist.bluetooth.a2dp_offload.disabled" |
| 118 | #define SYSPROP_A2DP_CODEC_LATENCIES "vendor.audio.a2dp.codec.latency" |
| 119 | |
| 120 | // Default encoder bit width |
| 121 | #define DEFAULT_ENCODER_BIT_FORMAT 16 |
| 122 | |
| 123 | // Default encoder latency |
| 124 | #define DEFAULT_ENCODER_LATENCY 200 |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 125 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 126 | // Slimbus Tx sample rate for ABR feedback channel |
| 127 | #define ABR_TX_SAMPLE_RATE "KHZ_8" |
| 128 | |
| 129 | // Purpose ID for Inter Module Communication (IMC) in AFE |
| 130 | #define IMC_PURPOSE_ID_BT_INFO 0x000132E2 |
| 131 | |
| 132 | // Maximum quality levels for ABR |
| 133 | #define MAX_ABR_QUALITY_LEVELS 5 |
| 134 | |
| 135 | // Instance identifier for A2DP |
| 136 | #define MAX_INSTANCE_ID (UINT32_MAX / 2) |
| 137 | |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 138 | #define SAMPLING_RATE_48K 48000 |
| 139 | #define SAMPLING_RATE_441K 44100 |
| 140 | #define CH_STEREO 2 |
| 141 | #define CH_MONO 1 |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 142 | #define SOURCE 0 |
| 143 | #define SINK 1 |
| 144 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 145 | /* |
| 146 | * Below enum values are extended from audio_base.h to |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 147 | * to keep encoder and decoder type local to bthost_ipc |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 148 | * and audio_hal as these are intended only for handshake |
| 149 | * between IPC lib and Audio HAL. |
| 150 | */ |
| 151 | typedef enum { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 152 | CODEC_TYPE_INVALID = AUDIO_FORMAT_INVALID, // 0xFFFFFFFFUL |
| 153 | CODEC_TYPE_AAC = AUDIO_FORMAT_AAC, // 0x04000000UL |
| 154 | CODEC_TYPE_SBC = AUDIO_FORMAT_SBC, // 0x1F000000UL |
| 155 | CODEC_TYPE_APTX = AUDIO_FORMAT_APTX, // 0x20000000UL |
| 156 | CODEC_TYPE_APTX_HD = AUDIO_FORMAT_APTX_HD, // 0x21000000UL |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 157 | #ifndef LINUX_ENABLED |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 158 | CODEC_TYPE_APTX_DUAL_MONO = 570425344u, // 0x22000000UL |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 159 | #endif |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 160 | CODEC_TYPE_LDAC = AUDIO_FORMAT_LDAC, // 0x23000000UL |
| 161 | CODEC_TYPE_CELT = 603979776u, // 0x24000000UL |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 162 | CODEC_TYPE_APTX_AD = 620756992u, // 0x25000000UL |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 163 | CODEC_TYPE_PCM = AUDIO_FORMAT_PCM_16_BIT, // 0x1u |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 164 | }codec_t; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 165 | |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 166 | /* |
| 167 | * enums which describes the APTX Adaptive |
| 168 | * channel mode, these values are used by encoder |
| 169 | */ |
| 170 | typedef enum { |
| 171 | APTX_AD_CHANNEL_UNCHANGED = -1, |
| 172 | APTX_AD_CHANNEL_JOINT_STEREO = 0, // default |
| 173 | APTX_AD_CHANNEL_MONO = 1, |
| 174 | APTX_AD_CHANNEL_DUAL_MONO = 2, |
| 175 | APTX_AD_CHANNEL_STEREO_TWS = 4, |
| 176 | APTX_AD_CHANNEL_EARBUD = 8, |
| 177 | } enc_aptx_ad_channel_mode; |
| 178 | |
| 179 | /* |
| 180 | * enums which describes the APTX Adaptive |
| 181 | * sampling frequency, these values are used |
| 182 | * by encoder |
| 183 | */ |
| 184 | typedef enum { |
| 185 | APTX_AD_SR_UNCHANGED = 0x0, |
| 186 | APTX_AD_48 = 0x1, // 48 KHz default |
| 187 | APTX_AD_44_1 = 0x2, // 44.1kHz |
| 188 | } enc_aptx_ad_s_rate; |
| 189 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 190 | typedef int (*audio_source_open_t)(void); |
| 191 | typedef int (*audio_source_close_t)(void); |
| 192 | typedef int (*audio_source_start_t)(void); |
| 193 | typedef int (*audio_source_stop_t)(void); |
| 194 | typedef int (*audio_source_suspend_t)(void); |
| 195 | typedef void (*audio_source_handoff_triggered_t)(void); |
| 196 | typedef void (*clear_source_a2dpsuspend_flag_t)(void); |
| 197 | typedef void * (*audio_get_enc_config_t)(uint8_t *multicast_status, |
| 198 | uint8_t *num_dev, codec_t *codec_type); |
| 199 | typedef int (*audio_source_check_a2dp_ready_t)(void); |
| 200 | typedef int (*audio_is_source_scrambling_enabled_t)(void); |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 201 | typedef bool (*audio_is_tws_mono_mode_enable_t)(void); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 202 | typedef int (*audio_sink_start_t)(void); |
| 203 | typedef int (*audio_sink_stop_t)(void); |
| 204 | typedef void * (*audio_get_dec_config_t)(codec_t *codec_type); |
| 205 | typedef void * (*audio_sink_session_setup_complete_t)(uint64_t system_latency); |
| 206 | typedef int (*audio_sink_check_a2dp_ready_t)(void); |
| 207 | typedef uint16_t (*audio_sink_get_a2dp_latency_t)(void); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 208 | |
| 209 | enum A2DP_STATE { |
| 210 | A2DP_STATE_CONNECTED, |
| 211 | A2DP_STATE_STARTED, |
| 212 | A2DP_STATE_STOPPED, |
| 213 | A2DP_STATE_DISCONNECTED, |
| 214 | }; |
| 215 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 216 | typedef enum { |
| 217 | IMC_TRANSMIT, |
| 218 | IMC_RECEIVE, |
| 219 | } imc_direction_t; |
| 220 | |
| 221 | typedef enum { |
| 222 | IMC_DISABLE, |
| 223 | IMC_ENABLE, |
| 224 | } imc_status_t; |
| 225 | |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 226 | typedef enum { |
| 227 | MTU_SIZE, |
| 228 | PEAK_BIT_RATE, |
| 229 | } frame_control_type_t; |
| 230 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 231 | /* PCM config for ABR Feedback hostless front end */ |
| 232 | static struct pcm_config pcm_config_abr = { |
| 233 | .channels = 1, |
| 234 | .rate = 8000, |
| 235 | .period_size = 240, |
| 236 | .period_count = 2, |
| 237 | .format = PCM_FORMAT_S16_LE, |
| 238 | .start_threshold = 0, |
| 239 | .stop_threshold = INT_MAX, |
| 240 | .avail_min = 0, |
| 241 | }; |
| 242 | |
| 243 | /* Adaptive bitrate config for A2DP codecs */ |
| 244 | struct a2dp_abr_config { |
| 245 | /* Flag to denote whether Adaptive bitrate is enabled for codec */ |
| 246 | bool is_abr_enabled; |
| 247 | /* Flag to denote whether front end has been opened for ABR */ |
| 248 | bool abr_started; |
| 249 | /* ABR Tx path pcm handle */ |
| 250 | struct pcm *abr_tx_handle; |
| 251 | /* ABR Inter Module Communication (IMC) instance ID */ |
| 252 | uint32_t imc_instance; |
| 253 | }; |
| 254 | |
| 255 | static uint32_t instance_id = MAX_INSTANCE_ID; |
| 256 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 257 | /* structure used to update a2dp state machine |
| 258 | * to communicate IPC library |
| 259 | * to store DSP encoder configuration information |
| 260 | */ |
| 261 | struct a2dp_data { |
| 262 | struct audio_device *adev; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 263 | void *bt_lib_source_handle; |
| 264 | audio_source_open_t audio_source_open; |
| 265 | audio_source_close_t audio_source_close; |
| 266 | audio_source_start_t audio_source_start; |
| 267 | audio_source_stop_t audio_source_stop; |
| 268 | audio_source_suspend_t audio_source_suspend; |
| 269 | audio_source_handoff_triggered_t audio_source_handoff_triggered; |
| 270 | clear_source_a2dpsuspend_flag_t clear_source_a2dpsuspend_flag; |
| 271 | audio_get_enc_config_t audio_get_enc_config; |
| 272 | audio_source_check_a2dp_ready_t audio_source_check_a2dp_ready; |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 273 | audio_is_tws_mono_mode_enable_t audio_is_tws_mono_mode_enable; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 274 | audio_is_source_scrambling_enabled_t audio_is_source_scrambling_enabled; |
| 275 | enum A2DP_STATE bt_state_source; |
| 276 | codec_t bt_encoder_format; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 277 | uint32_t enc_sampling_rate; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 278 | uint32_t enc_channels; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 279 | bool a2dp_source_started; |
| 280 | bool a2dp_source_suspended; |
| 281 | int a2dp_source_total_active_session_requests; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 282 | bool is_a2dp_offload_supported; |
| 283 | bool is_handoff_in_progress; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 284 | bool is_aptx_dual_mono_supported; |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 285 | /* Mono Mode support for TWS+ */ |
| 286 | bool is_tws_mono_mode_on; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 287 | bool is_aptx_adaptive; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 288 | /* Adaptive bitrate config for A2DP codecs */ |
| 289 | struct a2dp_abr_config abr_config; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 290 | |
| 291 | void *bt_lib_sink_handle; |
| 292 | audio_sink_start_t audio_sink_start; |
| 293 | audio_sink_stop_t audio_sink_stop; |
| 294 | audio_get_dec_config_t audio_get_dec_config; |
| 295 | audio_sink_session_setup_complete_t audio_sink_session_setup_complete; |
| 296 | audio_sink_check_a2dp_ready_t audio_sink_check_a2dp_ready; |
| 297 | audio_sink_get_a2dp_latency_t audio_sink_get_a2dp_latency; |
| 298 | enum A2DP_STATE bt_state_sink; |
| 299 | codec_t bt_decoder_format; |
| 300 | uint32_t dec_sampling_rate; |
| 301 | uint32_t dec_channels; |
| 302 | bool a2dp_sink_started; |
| 303 | int a2dp_sink_total_active_session_requests; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | struct a2dp_data a2dp; |
| 307 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 308 | /* Adaptive bitrate (ABR) is supported by certain Bluetooth codecs. |
| 309 | * Structures sent to configure DSP for ABR are defined below. |
| 310 | * This data helps DSP configure feedback path (BTSoC to LPASS) |
| 311 | * for link quality levels and mapping quality levels to codec |
| 312 | * specific bitrate. |
| 313 | */ |
| 314 | |
| 315 | /* Key value pair for link quality level to bitrate mapping. */ |
| 316 | struct bit_rate_level_map_t { |
| 317 | uint32_t link_quality_level; |
| 318 | uint32_t bitrate; |
| 319 | }; |
| 320 | |
| 321 | /* Link quality level to bitrate mapping info sent to DSP. */ |
| 322 | struct quality_level_to_bitrate_info { |
| 323 | /* Number of quality levels being mapped. |
| 324 | * This will be equal to the size of mapping table. |
| 325 | */ |
| 326 | uint32_t num_levels; |
| 327 | /* Quality level to bitrate mapping table */ |
| 328 | struct bit_rate_level_map_t bit_rate_level_map[MAX_ABR_QUALITY_LEVELS]; |
| 329 | }; |
| 330 | |
| 331 | /* Structure to set up Inter Module Communication (IMC) between |
| 332 | * AFE Decoder and Encoder. |
| 333 | */ |
| 334 | struct imc_dec_enc_info { |
| 335 | /* Decoder to encoder communication direction. |
| 336 | * Transmit = 0 / Receive = 1 |
| 337 | */ |
| 338 | uint32_t direction; |
| 339 | /* Enable / disable IMC between decoder and encoder */ |
| 340 | uint32_t enable; |
| 341 | /* Purpose of IMC being set up between decoder and encoder. |
| 342 | * IMC_PURPOSE_ID_BT_INFO defined for link quality feedback |
| 343 | * is the default value to be sent as purpose. |
| 344 | */ |
| 345 | uint32_t purpose; |
| 346 | /* Unique communication instance ID. |
| 347 | * purpose and comm_instance together form the actual key |
| 348 | * used in IMC registration, which must be the same for |
| 349 | * encoder and decoder for which IMC is being set up. |
| 350 | */ |
| 351 | uint32_t comm_instance; |
| 352 | }; |
| 353 | |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 354 | /* Structure to control frame size of AAC encoded frames. */ |
| 355 | struct aac_frame_size_control_t { |
| 356 | /* Type of frame size control: MTU_SIZE / PEAK_BIT_RATE*/ |
| 357 | uint32_t ctl_type; |
| 358 | /* Control value |
| 359 | * MTU_SIZE: MTU size in bytes |
| 360 | * PEAK_BIT_RATE: Peak bitrate in bits per second. |
| 361 | */ |
| 362 | uint32_t ctl_value; |
| 363 | }; |
| 364 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 365 | /* Structure used for ABR config of AFE encoder and decoder. */ |
| 366 | struct abr_enc_cfg_t { |
| 367 | /* Link quality level to bitrate mapping info sent to DSP. */ |
| 368 | struct quality_level_to_bitrate_info mapping_info; |
| 369 | /* Information to set up IMC between decoder and encoder */ |
| 370 | struct imc_dec_enc_info imc_info; |
Aniket Kumar Lata | 8c884eb | 2018-08-06 15:30:50 -0700 | [diff] [blame] | 371 | /* Flag to indicate whether ABR is enabled */ |
| 372 | bool is_abr_enabled; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 373 | } __attribute__ ((packed)); |
| 374 | |
| 375 | /* Structure to send configuration for decoder introduced |
| 376 | * on AFE Tx path for ABR link quality feedback to BT encoder. |
| 377 | */ |
| 378 | struct abr_dec_cfg_t { |
| 379 | /* Decoder media format */ |
| 380 | uint32_t dec_format; |
| 381 | /* Information to set up IMC between decoder and encoder */ |
| 382 | struct imc_dec_enc_info imc_info; |
| 383 | } __attribute__ ((packed)); |
| 384 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 385 | /* START of DSP configurable structures |
| 386 | * These values should match with DSP interface defintion |
| 387 | */ |
| 388 | |
| 389 | /* AAC encoder configuration structure. */ |
| 390 | typedef struct aac_enc_cfg_t aac_enc_cfg_t; |
| 391 | |
| 392 | /* supported enc_mode are AAC_LC, AAC_SBR, AAC_PS |
| 393 | * supported aac_fmt_flag are ADTS/RAW |
| 394 | * supported channel_cfg are Native mode, Mono , Stereo |
| 395 | */ |
| 396 | struct aac_enc_cfg_t { |
| 397 | uint32_t enc_format; |
| 398 | uint32_t bit_rate; |
| 399 | uint32_t enc_mode; |
| 400 | uint16_t aac_fmt_flag; |
Naresh Tanniru | a42d0bd | 2016-09-21 15:30:46 +0530 | [diff] [blame] | 401 | uint16_t channel_cfg; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 402 | uint32_t sample_rate; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 403 | } __attribute__ ((packed)); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 404 | |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 405 | struct aac_enc_cfg_v2_t { |
| 406 | struct aac_enc_cfg_t aac_enc_cfg; |
| 407 | struct aac_frame_size_control_t frame_ctl; |
| 408 | } __attribute__ ((packed)); |
| 409 | |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 410 | typedef struct audio_aac_decoder_config_t audio_aac_decoder_config_t; |
| 411 | struct audio_aac_decoder_config_t { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 412 | uint16_t aac_fmt_flag; /* LATM*/ |
| 413 | uint16_t audio_object_type; /* LC */ |
| 414 | uint16_t channels; /* Stereo */ |
| 415 | uint16_t total_size_of_pce_bits; /* 0 - only for channel conf PCE */ |
| 416 | uint32_t sampling_rate; /* 8k, 11.025k, 12k, 16k, 22.05k, 24k, 32k, |
| 417 | 44.1k, 48k, 64k, 88.2k, 96k */ |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 418 | } __attribute__ ((packed)); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 419 | |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 420 | typedef struct audio_sbc_decoder_config_t audio_sbc_decoder_config_t; |
| 421 | struct audio_sbc_decoder_config_t { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 422 | uint16_t channels; /* Mono, Stereo */ |
| 423 | uint32_t sampling_rate; /* 8k, 11.025k, 12k, 16k, 22.05k, 24k, 32k, |
| 424 | 44.1k, 48k, 64k, 88.2k, 96k */ |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 425 | } __attribute__ ((packed)); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 426 | |
| 427 | /* AAC decoder configuration structure. */ |
| 428 | typedef struct aac_dec_cfg_t aac_dec_cfg_t; |
| 429 | struct aac_dec_cfg_t { |
| 430 | uint32_t dec_format; |
| 431 | audio_aac_decoder_config_t data; |
| 432 | } __attribute__ ((packed)); |
| 433 | |
| 434 | /* SBC decoder configuration structure. */ |
| 435 | typedef struct sbc_dec_cfg_t sbc_dec_cfg_t; |
| 436 | struct sbc_dec_cfg_t { |
| 437 | uint32_t dec_format; |
| 438 | audio_sbc_decoder_config_t data; |
| 439 | } __attribute__ ((packed)); |
| 440 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 441 | /* SBC encoder configuration structure. */ |
| 442 | typedef struct sbc_enc_cfg_t sbc_enc_cfg_t; |
| 443 | |
| 444 | /* supported num_subbands are 4/8 |
| 445 | * supported blk_len are 4, 8, 12, 16 |
| 446 | * supported channel_mode are MONO, STEREO, DUAL_MONO, JOINT_STEREO |
| 447 | * supported alloc_method are LOUNDNESS/SNR |
| 448 | * supported bit_rate for mono channel is max 320kbps |
| 449 | * supported bit rate for stereo channel is max 512 kbps |
| 450 | */ |
| 451 | struct sbc_enc_cfg_t{ |
| 452 | uint32_t enc_format; |
| 453 | uint32_t num_subbands; |
| 454 | uint32_t blk_len; |
| 455 | uint32_t channel_mode; |
| 456 | uint32_t alloc_method; |
| 457 | uint32_t bit_rate; |
| 458 | uint32_t sample_rate; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 459 | } __attribute__ ((packed)); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 460 | |
| 461 | |
| 462 | /* supported num_channels are Mono/Stereo |
| 463 | * supported channel_mapping for mono is CHANNEL_C |
| 464 | * supported channel mapping for stereo is CHANNEL_L and CHANNEL_R |
| 465 | * custom size and reserved are not used(for future enhancement) |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 466 | */ |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 467 | struct custom_enc_cfg_t |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 468 | { |
| 469 | uint32_t enc_format; |
| 470 | uint32_t sample_rate; |
| 471 | uint16_t num_channels; |
| 472 | uint16_t reserved; |
| 473 | uint8_t channel_mapping[8]; |
| 474 | uint32_t custom_size; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 475 | } __attribute__ ((packed)); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 476 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 477 | struct celt_specific_enc_cfg_t |
| 478 | { |
| 479 | uint32_t bit_rate; |
| 480 | uint16_t frame_size; |
| 481 | uint16_t complexity; |
| 482 | uint16_t prediction_mode; |
| 483 | uint16_t vbr_flag; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 484 | } __attribute__ ((packed)); |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 485 | |
| 486 | struct celt_enc_cfg_t |
| 487 | { |
| 488 | struct custom_enc_cfg_t custom_cfg; |
| 489 | struct celt_specific_enc_cfg_t celt_cfg; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 490 | } __attribute__ ((packed)); |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 491 | |
| 492 | /* sync_mode introduced with APTX V2 libraries |
| 493 | * sync mode: 0x0 = stereo sync mode |
| 494 | * 0x01 = dual mono sync mode |
| 495 | * 0x02 = dual mono with no sync on either L or R codewords |
| 496 | */ |
| 497 | struct aptx_v2_enc_cfg_ext_t |
| 498 | { |
| 499 | uint32_t sync_mode; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 500 | } __attribute__ ((packed)); |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 501 | |
| 502 | /* APTX struct for combining custom enc and V2 fields */ |
| 503 | struct aptx_enc_cfg_t |
| 504 | { |
| 505 | struct custom_enc_cfg_t custom_cfg; |
| 506 | struct aptx_v2_enc_cfg_ext_t aptx_v2_cfg; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 507 | } __attribute__ ((packed)); |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 508 | |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 509 | /* APTX AD structure */ |
| 510 | struct aptx_ad_enc_cfg_ext_t |
| 511 | { |
| 512 | uint32_t sampling_freq; |
| 513 | uint32_t mtu; |
| 514 | uint32_t channel_mode; |
| 515 | uint32_t min_sink_modeA; |
| 516 | uint32_t max_sink_modeA; |
| 517 | uint32_t min_sink_modeB; |
| 518 | uint32_t max_sink_modeB; |
| 519 | uint32_t min_sink_modeC; |
| 520 | uint32_t max_sink_modeC; |
Sharad Sangle | e378afe | 2018-09-03 20:04:17 +0530 | [diff] [blame] | 521 | uint32_t mode; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 522 | } __attribute__ ((packed)); |
| 523 | |
| 524 | struct aptx_ad_enc_cfg_t |
| 525 | { |
| 526 | struct custom_enc_cfg_t custom_cfg; |
| 527 | struct aptx_ad_enc_cfg_ext_t aptx_ad_cfg; |
| 528 | struct abr_enc_cfg_t abr_cfg; |
| 529 | } __attribute__ ((packed)); |
| 530 | |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 531 | struct ldac_specific_enc_cfg_t |
| 532 | { |
| 533 | uint32_t bit_rate; |
| 534 | uint16_t channel_mode; |
| 535 | uint16_t mtu; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 536 | } __attribute__ ((packed)); |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 537 | |
| 538 | struct ldac_enc_cfg_t |
| 539 | { |
| 540 | struct custom_enc_cfg_t custom_cfg; |
| 541 | struct ldac_specific_enc_cfg_t ldac_cfg; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 542 | struct abr_enc_cfg_t abr_cfg; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 543 | } __attribute__ ((packed)); |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 544 | |
Sachin Mohan Gadag | 1657c05 | 2017-09-13 16:00:27 +0530 | [diff] [blame] | 545 | /* In LE BT source code uses system/audio.h for below |
| 546 | * structure definition. To avoid multiple definition |
| 547 | * compilation error for audiohal in LE , masking structure |
| 548 | * definition under "LINUX_ENABLED" which is defined only |
| 549 | * in LE |
| 550 | */ |
| 551 | #ifndef LINUX_ENABLED |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 552 | /* TODO: Define the following structures only for O using PLATFORM_VERSION */ |
| 553 | /* Information about BT SBC encoder configuration |
| 554 | * This data is used between audio HAL module and |
| 555 | * BT IPC library to configure DSP encoder |
| 556 | */ |
| 557 | typedef struct { |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 558 | uint32_t subband; /* 4, 8 */ |
| 559 | uint32_t blk_len; /* 4, 8, 12, 16 */ |
| 560 | uint16_t sampling_rate; /*44.1khz,48khz*/ |
| 561 | uint8_t channels; /*0(Mono),1(Dual_mono),2(Stereo),3(JS)*/ |
| 562 | uint8_t alloc; /*0(Loudness),1(SNR)*/ |
| 563 | uint8_t min_bitpool; /* 2 */ |
| 564 | uint8_t max_bitpool; /*53(44.1khz),51 (48khz) */ |
| 565 | uint32_t bitrate; /* 320kbps to 512kbps */ |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 566 | uint32_t bits_per_sample; |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 567 | } audio_sbc_encoder_config; |
| 568 | |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 569 | /* Information about BT APTX encoder configuration |
| 570 | * This data is used between audio HAL module and |
| 571 | * BT IPC library to configure DSP encoder |
| 572 | */ |
| 573 | typedef struct { |
| 574 | uint16_t sampling_rate; |
| 575 | uint8_t channels; |
| 576 | uint32_t bitrate; |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 577 | uint32_t bits_per_sample; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 578 | } audio_aptx_default_config; |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 579 | |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 580 | typedef struct { |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 581 | uint8_t sampling_rate; |
| 582 | uint8_t channel_mode; |
| 583 | uint16_t mtu; |
| 584 | uint8_t min_sink_modeA; |
| 585 | uint8_t max_sink_modeA; |
| 586 | uint8_t min_sink_modeB; |
| 587 | uint8_t max_sink_modeB; |
| 588 | uint8_t min_sink_modeC; |
| 589 | uint8_t max_sink_modeC; |
| 590 | uint8_t TTP_modeA_low; |
| 591 | uint8_t TTP_modeA_high; |
| 592 | uint8_t TTP_modeB_low; |
| 593 | uint8_t TTP_modeB_high; |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 594 | uint32_t bits_per_sample; |
Sharad Sangle | e378afe | 2018-09-03 20:04:17 +0530 | [diff] [blame] | 595 | uint16_t encoder_mode; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 596 | } audio_aptx_ad_config; |
| 597 | |
| 598 | typedef struct { |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 599 | uint16_t sampling_rate; |
| 600 | uint8_t channels; |
| 601 | uint32_t bitrate; |
| 602 | uint32_t sync_mode; |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 603 | uint32_t bits_per_sample; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 604 | } audio_aptx_dual_mono_config; |
| 605 | |
| 606 | typedef union { |
| 607 | audio_aptx_default_config *default_cfg; |
| 608 | audio_aptx_dual_mono_config *dual_mono_cfg; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 609 | audio_aptx_ad_config *ad_cfg; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 610 | } audio_aptx_encoder_config; |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 611 | |
| 612 | /* Information about BT AAC encoder configuration |
| 613 | * This data is used between audio HAL module and |
| 614 | * BT IPC library to configure DSP encoder |
| 615 | */ |
| 616 | typedef struct { |
| 617 | uint32_t enc_mode; /* LC, SBR, PS */ |
| 618 | uint16_t format_flag; /* RAW, ADTS */ |
| 619 | uint16_t channels; /* 1-Mono, 2-Stereo */ |
| 620 | uint32_t sampling_rate; |
| 621 | uint32_t bitrate; |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 622 | uint32_t bits_per_sample; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 623 | struct aac_frame_size_control_t frame_ctl; |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 624 | } audio_aac_encoder_config; |
Ramu Gottipati | 08d82e7 | 2018-12-17 11:52:14 +0530 | [diff] [blame] | 625 | #endif |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 626 | |
| 627 | typedef struct { |
| 628 | audio_aac_encoder_config audio_aac_enc_cfg; |
| 629 | struct aac_frame_size_control_t frame_ctl; |
| 630 | } audio_aac_encoder_config_v2; |
Satya Krishna Pindiproli | f7d6571 | 2017-04-26 14:24:53 +0530 | [diff] [blame] | 631 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 632 | /* Information about BT CELT encoder configuration |
| 633 | * This data is used between audio HAL module and |
| 634 | * BT IPC library to configure DSP encoder |
| 635 | */ |
| 636 | typedef struct { |
| 637 | uint32_t sampling_rate; /* 32000 - 48000, 48000 */ |
| 638 | uint16_t channels; /* 1-Mono, 2-Stereo, 2*/ |
| 639 | uint16_t frame_size; /* 64-128-256-512, 512 */ |
| 640 | uint16_t complexity; /* 0-10, 1 */ |
| 641 | uint16_t prediction_mode; /* 0-1-2, 0 */ |
| 642 | uint16_t vbr_flag; /* 0-1, 0*/ |
| 643 | uint32_t bitrate; /*32000 - 1536000, 139500*/ |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 644 | uint32_t bits_per_sample; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 645 | } audio_celt_encoder_config; |
| 646 | |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 647 | /* Information about BT LDAC encoder configuration |
| 648 | * This data is used between audio HAL module and |
| 649 | * BT IPC library to configure DSP encoder |
| 650 | */ |
| 651 | typedef struct { |
| 652 | uint32_t sampling_rate; /*44100,48000,88200,96000*/ |
| 653 | uint32_t bit_rate; /*303000,606000,909000(in bits per second)*/ |
| 654 | uint16_t channel_mode; /* 0, 4, 2, 1*/ |
| 655 | uint16_t mtu; /*679*/ |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 656 | bool is_abr_enabled; |
| 657 | struct quality_level_to_bitrate_info level_to_bitrate_map; |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 658 | uint32_t bits_per_sample; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 659 | } audio_ldac_encoder_config; |
| 660 | |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 661 | /* Information about BT AAC decoder configuration |
| 662 | * This data is used between audio HAL module and |
| 663 | * BT IPC library to configure DSP decoder |
| 664 | */ |
| 665 | typedef struct { |
| 666 | uint16_t aac_fmt_flag; /* LATM*/ |
| 667 | uint16_t audio_object_type; /* LC */ |
| 668 | uint16_t channels; /* Stereo */ |
| 669 | uint16_t total_size_of_pce_bits; /* 0 - only for channel conf PCE */ |
| 670 | uint32_t sampling_rate; /* 8k, 11.025k, 12k, 16k, 22.05k, 24k, 32k, |
| 671 | 44.1k, 48k, 64k, 88.2k, 96k */ |
| 672 | } audio_aac_dec_config_t; |
| 673 | |
| 674 | /* Information about BT SBC decoder configuration |
| 675 | * This data is used between audio HAL module and |
| 676 | * BT IPC library to configure DSP decoder |
| 677 | */ |
| 678 | typedef struct { |
| 679 | uint16_t channels; /* Mono, Stereo */ |
| 680 | uint32_t sampling_rate; /* 8k, 11.025k, 12k, 16k, 22.05k, 24k, 32k, |
| 681 | 44.1k, 48k, 64k, 88.2k, 96k */ |
| 682 | }audio_sbc_dec_config_t; |
| 683 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 684 | /*********** END of DSP configurable structures ********************/ |
| 685 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 686 | static void update_offload_codec_capabilities() |
| 687 | { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 688 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 689 | a2dp.is_a2dp_offload_supported = |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 690 | property_get_bool(SYSPROP_A2DP_OFFLOAD_SUPPORTED, false) && |
| 691 | !property_get_bool(SYSPROP_A2DP_OFFLOAD_DISABLED, false); |
| 692 | |
| 693 | ALOGD("%s: A2DP offload supported = %d",__func__, |
| 694 | a2dp.is_a2dp_offload_supported); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 695 | } |
| 696 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 697 | static int stop_abr() |
| 698 | { |
| 699 | struct mixer_ctl *ctl_abr_tx_path = NULL; |
| 700 | struct mixer_ctl *ctl_set_bt_feedback_channel = NULL; |
| 701 | |
| 702 | /* This function can be used if !abr_started for clean up */ |
| 703 | ALOGV("%s: enter", __func__); |
| 704 | |
| 705 | // Close hostless front end |
| 706 | if (a2dp.abr_config.abr_tx_handle != NULL) { |
| 707 | pcm_close(a2dp.abr_config.abr_tx_handle); |
| 708 | a2dp.abr_config.abr_tx_handle = NULL; |
| 709 | } |
| 710 | a2dp.abr_config.abr_started = false; |
| 711 | a2dp.abr_config.imc_instance = 0; |
| 712 | |
| 713 | // Reset BT driver mixer control for ABR usecase |
| 714 | ctl_set_bt_feedback_channel = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 715 | MIXER_SET_FEEDBACK_CHANNEL); |
| 716 | if (!ctl_set_bt_feedback_channel) { |
| 717 | ALOGE("%s: ERROR Set usecase mixer control not identifed", __func__); |
| 718 | return -ENOSYS; |
| 719 | } |
| 720 | if (mixer_ctl_set_value(ctl_set_bt_feedback_channel, 0, 0) != 0) { |
| 721 | ALOGE("%s: Failed to set BT usecase", __func__); |
| 722 | return -ENOSYS; |
| 723 | } |
| 724 | |
| 725 | // Reset ABR Tx feedback path |
| 726 | ALOGV("%s: Disable ABR Tx feedback path", __func__); |
| 727 | ctl_abr_tx_path = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 728 | MIXER_ABR_TX_FEEDBACK_PATH); |
| 729 | if (!ctl_abr_tx_path) { |
| 730 | ALOGE("%s: ERROR ABR Tx feedback path mixer control not identifed", __func__); |
| 731 | return -ENOSYS; |
| 732 | } |
| 733 | if (mixer_ctl_set_value(ctl_abr_tx_path, 0, 0) != 0) { |
| 734 | ALOGE("%s: Failed to set ABR Tx feedback path", __func__); |
| 735 | return -ENOSYS; |
| 736 | } |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | static int start_abr() |
| 742 | { |
| 743 | struct mixer_ctl *ctl_abr_tx_path = NULL; |
| 744 | struct mixer_ctl *ctl_set_bt_feedback_channel = NULL; |
| 745 | int abr_device_id; |
| 746 | int ret = 0; |
| 747 | |
| 748 | if (!a2dp.abr_config.is_abr_enabled) { |
| 749 | ALOGE("%s: Cannot start if ABR is not enabled", __func__); |
| 750 | return -ENOSYS; |
| 751 | } |
| 752 | |
| 753 | if (a2dp.abr_config.abr_started) { |
| 754 | ALOGI("%s: ABR has already started", __func__); |
| 755 | return ret; |
| 756 | } |
| 757 | |
| 758 | // Enable Slimbus 7 Tx feedback path |
| 759 | ALOGV("%s: Enable ABR Tx feedback path", __func__); |
| 760 | ctl_abr_tx_path = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 761 | MIXER_ABR_TX_FEEDBACK_PATH); |
| 762 | if (!ctl_abr_tx_path) { |
| 763 | ALOGE("%s: ERROR ABR Tx feedback path mixer control not identifed", __func__); |
| 764 | return -ENOSYS; |
| 765 | } |
| 766 | if (mixer_ctl_set_value(ctl_abr_tx_path, 0, 1) != 0) { |
| 767 | ALOGE("%s: Failed to set ABR Tx feedback path", __func__); |
| 768 | return -ENOSYS; |
| 769 | } |
| 770 | |
| 771 | // Notify ABR usecase information to BT driver to distinguish |
| 772 | // between SCO and feedback usecase |
| 773 | ctl_set_bt_feedback_channel = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 774 | MIXER_SET_FEEDBACK_CHANNEL); |
| 775 | if (!ctl_set_bt_feedback_channel) { |
| 776 | ALOGE("%s: ERROR Set usecase mixer control not identifed", __func__); |
| 777 | return -ENOSYS; |
| 778 | } |
| 779 | if (mixer_ctl_set_value(ctl_set_bt_feedback_channel, 0, 1) != 0) { |
| 780 | ALOGE("%s: Failed to set BT usecase", __func__); |
| 781 | return -ENOSYS; |
| 782 | } |
| 783 | |
| 784 | // Open hostless front end and prepare ABR Tx path |
| 785 | abr_device_id = platform_get_pcm_device_id(USECASE_AUDIO_A2DP_ABR_FEEDBACK, |
| 786 | PCM_CAPTURE); |
| 787 | if (!a2dp.abr_config.abr_tx_handle) { |
| 788 | a2dp.abr_config.abr_tx_handle = pcm_open(a2dp.adev->snd_card, |
| 789 | abr_device_id, PCM_IN, |
| 790 | &pcm_config_abr); |
| 791 | if (a2dp.abr_config.abr_tx_handle == NULL || |
| 792 | !pcm_is_ready(a2dp.abr_config.abr_tx_handle)) |
| 793 | goto fail; |
| 794 | } |
| 795 | ret = pcm_start(a2dp.abr_config.abr_tx_handle); |
| 796 | if (ret < 0) |
| 797 | goto fail; |
| 798 | a2dp.abr_config.abr_started = true; |
| 799 | |
| 800 | return ret; |
| 801 | |
| 802 | fail: |
| 803 | ALOGE("%s: %s", __func__, pcm_get_error(a2dp.abr_config.abr_tx_handle)); |
| 804 | stop_abr(); |
| 805 | return -ENOSYS; |
| 806 | } |
| 807 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 808 | /* API to open BT IPC library to start IPC communication for BT Source*/ |
| 809 | static void open_a2dp_source() |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 810 | { |
| 811 | int ret = 0; |
| 812 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 813 | ALOGD(" Open A2DP source start "); |
| 814 | if (a2dp.bt_lib_source_handle == NULL){ |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 815 | ALOGD(" Requesting for BT lib handle"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 816 | 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] | 817 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 818 | if (a2dp.bt_lib_source_handle == NULL) { |
| 819 | ALOGE("%s: DLOPEN failed for %s", __func__, BT_IPC_SOURCE_LIB_NAME); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 820 | ret = -ENOSYS; |
| 821 | goto init_fail; |
| 822 | } else { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 823 | a2dp.audio_source_open = (audio_source_open_t) |
| 824 | dlsym(a2dp.bt_lib_source_handle, "audio_stream_open"); |
| 825 | a2dp.audio_source_start = (audio_source_start_t) |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 826 | dlsym(a2dp.bt_lib_source_handle, "audio_stream_start"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 827 | a2dp.audio_get_enc_config = (audio_get_enc_config_t) |
| 828 | dlsym(a2dp.bt_lib_source_handle, "audio_get_codec_config"); |
| 829 | a2dp.audio_source_suspend = (audio_source_suspend_t) |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 830 | dlsym(a2dp.bt_lib_source_handle, "audio_stream_suspend"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 831 | a2dp.audio_source_handoff_triggered = (audio_source_handoff_triggered_t) |
| 832 | dlsym(a2dp.bt_lib_source_handle, "audio_handoff_triggered"); |
| 833 | a2dp.clear_source_a2dpsuspend_flag = (clear_source_a2dpsuspend_flag_t) |
| 834 | dlsym(a2dp.bt_lib_source_handle, "clear_a2dpsuspend_flag"); |
| 835 | a2dp.audio_source_stop = (audio_source_stop_t) |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 836 | dlsym(a2dp.bt_lib_source_handle, "audio_stream_stop"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 837 | a2dp.audio_source_close = (audio_source_close_t) |
| 838 | dlsym(a2dp.bt_lib_source_handle, "audio_stream_close"); |
| 839 | a2dp.audio_source_check_a2dp_ready = (audio_source_check_a2dp_ready_t) |
| 840 | dlsym(a2dp.bt_lib_source_handle,"audio_check_a2dp_ready"); |
| 841 | a2dp.audio_sink_get_a2dp_latency = (audio_sink_get_a2dp_latency_t) |
| 842 | dlsym(a2dp.bt_lib_source_handle,"audio_sink_get_a2dp_latency"); |
| 843 | a2dp.audio_is_source_scrambling_enabled = (audio_is_source_scrambling_enabled_t) |
| 844 | dlsym(a2dp.bt_lib_source_handle,"audio_is_scrambling_enabled"); |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 845 | a2dp.audio_is_tws_mono_mode_enable = (audio_is_tws_mono_mode_enable_t) |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 846 | dlsym(a2dp.bt_lib_source_handle,"isTwsMonomodeEnable"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 850 | if (a2dp.bt_lib_source_handle && a2dp.audio_source_open) { |
| 851 | if (a2dp.bt_state_source == A2DP_STATE_DISCONNECTED) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 852 | ALOGD("calling BT stream open"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 853 | ret = a2dp.audio_source_open(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 854 | if(ret != 0) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 855 | ALOGE("Failed to open source stream for a2dp: status %d", ret); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 856 | goto init_fail; |
| 857 | } |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 858 | a2dp.bt_state_source = A2DP_STATE_CONNECTED; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 859 | } else { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 860 | 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] | 861 | } |
| 862 | } else { |
| 863 | ALOGE("a2dp handle is not identified, Ignoring open request"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 864 | a2dp.bt_state_source = A2DP_STATE_DISCONNECTED; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 865 | goto init_fail; |
| 866 | } |
| 867 | |
| 868 | init_fail: |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 869 | if(ret != 0 && (a2dp.bt_lib_source_handle != NULL)) { |
| 870 | dlclose(a2dp.bt_lib_source_handle); |
| 871 | a2dp.bt_lib_source_handle = NULL; |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | /* API to open BT IPC library to start IPC communication for BT Sink*/ |
| 876 | static void open_a2dp_sink() |
| 877 | { |
| 878 | ALOGD(" Open A2DP input start "); |
| 879 | if (a2dp.bt_lib_sink_handle == NULL){ |
| 880 | ALOGD(" Requesting for BT lib handle"); |
| 881 | a2dp.bt_lib_sink_handle = dlopen(BT_IPC_SINK_LIB_NAME, RTLD_NOW); |
| 882 | |
| 883 | if (a2dp.bt_lib_sink_handle == NULL) { |
| 884 | ALOGE("%s: DLOPEN failed for %s", __func__, BT_IPC_SINK_LIB_NAME); |
| 885 | } else { |
| 886 | a2dp.audio_sink_start = (audio_sink_start_t) |
| 887 | dlsym(a2dp.bt_lib_sink_handle, "audio_sink_start_capture"); |
| 888 | a2dp.audio_get_dec_config = (audio_get_dec_config_t) |
| 889 | dlsym(a2dp.bt_lib_sink_handle, "audio_get_decoder_config"); |
| 890 | a2dp.audio_sink_stop = (audio_sink_stop_t) |
| 891 | dlsym(a2dp.bt_lib_sink_handle, "audio_sink_stop_capture"); |
| 892 | a2dp.audio_sink_check_a2dp_ready = (audio_sink_check_a2dp_ready_t) |
| 893 | dlsym(a2dp.bt_lib_sink_handle,"audio_sink_check_a2dp_ready"); |
| 894 | a2dp.audio_sink_session_setup_complete = (audio_sink_session_setup_complete_t) |
| 895 | dlsym(a2dp.bt_lib_sink_handle, "audio_sink_session_setup_complete"); |
| 896 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | |
| 900 | static int close_a2dp_output() |
| 901 | { |
| 902 | ALOGV("%s\n",__func__); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 903 | |
| 904 | if (!(a2dp.bt_lib_source_handle && a2dp.audio_source_close)) { |
| 905 | ALOGE("a2dp source handle is not identified, Ignoring close request"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 906 | return -ENOSYS; |
| 907 | } |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 908 | |
| 909 | if (a2dp.bt_state_source != A2DP_STATE_DISCONNECTED) { |
| 910 | ALOGD("calling BT source stream close"); |
| 911 | if(a2dp.audio_source_close() == false) |
| 912 | ALOGE("failed close a2dp source control path from BT library"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 913 | } |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 914 | a2dp.a2dp_source_started = false; |
| 915 | a2dp.a2dp_source_total_active_session_requests = 0; |
| 916 | a2dp.a2dp_source_suspended = false; |
| 917 | a2dp.bt_encoder_format = CODEC_TYPE_INVALID; |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 918 | a2dp.enc_sampling_rate = 48000; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 919 | a2dp.enc_channels = 2; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 920 | a2dp.bt_state_source = A2DP_STATE_DISCONNECTED; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 921 | if (a2dp.abr_config.is_abr_enabled && a2dp.abr_config.abr_started) |
| 922 | stop_abr(); |
| 923 | a2dp.abr_config.is_abr_enabled = false; |
| 924 | a2dp.abr_config.abr_started = false; |
| 925 | a2dp.abr_config.imc_instance = 0; |
| 926 | a2dp.abr_config.abr_tx_handle = NULL; |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 927 | a2dp.bt_state_source = A2DP_STATE_DISCONNECTED; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 928 | |
| 929 | return 0; |
| 930 | } |
| 931 | |
| 932 | static int close_a2dp_input() |
| 933 | { |
| 934 | ALOGV("%s\n",__func__); |
| 935 | |
| 936 | if (!(a2dp.bt_lib_sink_handle && a2dp.audio_source_close)) { |
| 937 | ALOGE("a2dp sink handle is not identified, Ignoring close request"); |
| 938 | return -ENOSYS; |
| 939 | } |
| 940 | |
| 941 | if (a2dp.bt_state_sink != A2DP_STATE_DISCONNECTED) { |
| 942 | ALOGD("calling BT sink stream close"); |
| 943 | if(a2dp.audio_source_close() == false) |
| 944 | ALOGE("failed close a2dp sink control path from BT library"); |
| 945 | } |
| 946 | a2dp.a2dp_sink_started = false; |
| 947 | a2dp.a2dp_sink_total_active_session_requests = 0; |
| 948 | a2dp.bt_decoder_format = CODEC_TYPE_INVALID; |
| 949 | a2dp.dec_sampling_rate = 48000; |
| 950 | a2dp.dec_channels = 2; |
| 951 | a2dp.bt_state_sink = A2DP_STATE_DISCONNECTED; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 952 | |
| 953 | return 0; |
| 954 | } |
| 955 | |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 956 | static void a2dp_check_and_set_scrambler() |
| 957 | { |
| 958 | bool scrambler_mode = false; |
| 959 | struct mixer_ctl *ctrl_scrambler_mode = NULL; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 960 | if (a2dp.audio_is_source_scrambling_enabled && (a2dp.bt_state_source != A2DP_STATE_DISCONNECTED)) |
| 961 | scrambler_mode = a2dp.audio_is_source_scrambling_enabled(); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 962 | |
| 963 | if (scrambler_mode) { |
| 964 | //enable scrambler in dsp |
| 965 | ctrl_scrambler_mode = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 966 | MIXER_SCRAMBLER_MODE); |
| 967 | if (!ctrl_scrambler_mode) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 968 | ALOGE(" ERROR scrambler mode mixer control not identified"); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 969 | return; |
| 970 | } else { |
| 971 | if (mixer_ctl_set_value(ctrl_scrambler_mode, 0, true) != 0) { |
| 972 | ALOGE("%s: Could not set scrambler mode", __func__); |
| 973 | return; |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 979 | static bool a2dp_set_backend_cfg(uint8_t direction) |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 980 | { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 981 | char *rate_str = NULL, *channels = NULL; |
| 982 | uint32_t sampling_rate; |
| 983 | struct mixer_ctl *ctl_sample_rate = NULL, *ctrl_channels = NULL; |
| 984 | bool is_configured = false; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 985 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 986 | if (direction == SINK) { |
| 987 | sampling_rate = a2dp.dec_sampling_rate; |
| 988 | } else { |
| 989 | sampling_rate = a2dp.enc_sampling_rate; |
| 990 | } |
| 991 | //For LDAC encoder and AAC decoder open slimbus port at |
| 992 | //96Khz for 48Khz input and 88.2Khz for 44.1Khz input. |
| 993 | if (((a2dp.bt_encoder_format == CODEC_TYPE_LDAC) || |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 994 | (a2dp.bt_decoder_format == CODEC_TYPE_SBC) || |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 995 | (a2dp.bt_decoder_format == AUDIO_FORMAT_AAC)) && |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 996 | (sampling_rate == 48000 || sampling_rate == 44100 )) { |
| 997 | sampling_rate = sampling_rate *2; |
| 998 | } |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 999 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 1000 | // No need to configure backend for PCM format. |
| 1001 | if (a2dp.bt_encoder_format == CODEC_TYPE_PCM) { |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1005 | //Configure backend sampling rate |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1006 | switch (sampling_rate) { |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1007 | case 44100: |
| 1008 | rate_str = "KHZ_44P1"; |
| 1009 | break; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1010 | case 88200: |
| 1011 | rate_str = "KHZ_88P2"; |
| 1012 | break; |
| 1013 | case 96000: |
| 1014 | rate_str = "KHZ_96"; |
| 1015 | break; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1016 | case 48000: |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1017 | default: |
| 1018 | rate_str = "KHZ_48"; |
| 1019 | break; |
| 1020 | } |
| 1021 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1022 | if (direction == SINK) { |
| 1023 | ALOGD("%s: set sink backend sample rate =%s", __func__, rate_str); |
| 1024 | ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer, |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1025 | MIXER_SINK_SAMPLE_RATE); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1026 | } else { |
| 1027 | ALOGD("%s: set source backend sample rate =%s", __func__, rate_str); |
| 1028 | ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer, |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1029 | MIXER_SAMPLE_RATE_RX); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1030 | } |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1031 | if (ctl_sample_rate) { |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1032 | |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1033 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) { |
| 1034 | ALOGE("%s: Failed to set backend sample rate = %s", __func__, rate_str); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1035 | is_configured = false; |
| 1036 | goto fail; |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1037 | } |
| 1038 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1039 | if (direction == SOURCE) { |
| 1040 | /* Set Tx backend sample rate */ |
| 1041 | if (a2dp.abr_config.is_abr_enabled) |
| 1042 | rate_str = ABR_TX_SAMPLE_RATE; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1043 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1044 | ALOGD("%s: set backend tx sample rate = %s", __func__, rate_str); |
| 1045 | ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1046 | MIXER_SOURCE_SAMPLE_RATE_TX); |
| 1047 | if (!ctl_sample_rate) { |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1048 | ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1049 | is_configured = false; |
| 1050 | goto fail; |
| 1051 | } |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1052 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1053 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) { |
| 1054 | ALOGE("%s: Failed to set backend sample rate = %s", __func__, rate_str); |
| 1055 | is_configured = false; |
| 1056 | goto fail; |
| 1057 | } |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1058 | } |
| 1059 | } else { |
| 1060 | /* Fallback to legacy approch if MIXER_SAMPLE_RATE_RX and |
| 1061 | MIXER_SAMPLE_RATE_TX is not supported */ |
| 1062 | ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1063 | MIXER_SAMPLE_RATE_DEFAULT); |
| 1064 | if (!ctl_sample_rate) { |
| 1065 | ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1066 | is_configured = false; |
| 1067 | goto fail; |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) { |
| 1071 | ALOGE("%s: Failed to set backend sample rate = %s", __func__, rate_str); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1072 | is_configured = false; |
| 1073 | goto fail; |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1074 | } |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1075 | } |
| 1076 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1077 | if (direction == SINK) { |
| 1078 | switch (a2dp.dec_channels) { |
| 1079 | case 1: |
| 1080 | channels = "One"; |
| 1081 | break; |
| 1082 | case 2: |
| 1083 | default: |
| 1084 | channels = "Two"; |
| 1085 | break; |
| 1086 | } |
| 1087 | |
Ramu Gottipati | 0280968 | 2018-12-19 16:46:12 +0530 | [diff] [blame] | 1088 | ALOGD("%s: set afe dec channels =%s", __func__, channels); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1089 | ctrl_channels = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1090 | MIXER_AFE_SINK_CHANNELS); |
| 1091 | } else { |
| 1092 | //Configure AFE enc channels |
| 1093 | switch (a2dp.enc_channels) { |
| 1094 | case 1: |
| 1095 | channels = "One"; |
| 1096 | break; |
| 1097 | case 2: |
| 1098 | default: |
| 1099 | channels = "Two"; |
| 1100 | break; |
| 1101 | } |
| 1102 | |
Ramu Gottipati | 0280968 | 2018-12-19 16:46:12 +0530 | [diff] [blame] | 1103 | ALOGD("%s: set afe enc channels =%s", __func__, channels); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1104 | ctrl_channels = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1105 | MIXER_AFE_IN_CHANNELS); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1106 | } |
| 1107 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1108 | if (!ctrl_channels) { |
| 1109 | ALOGE(" ERROR AFE channels mixer control not identified"); |
| 1110 | } else { |
| 1111 | if (mixer_ctl_set_enum_by_string(ctrl_channels, channels) != 0) { |
Ramu Gottipati | 0280968 | 2018-12-19 16:46:12 +0530 | [diff] [blame] | 1112 | ALOGE("%s: Failed to set AFE channels =%s", __func__, channels); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1113 | is_configured = false; |
| 1114 | goto fail; |
| 1115 | } |
| 1116 | } |
| 1117 | is_configured = true; |
| 1118 | fail: |
| 1119 | return is_configured; |
| 1120 | } |
| 1121 | |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 1122 | 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] | 1123 | { |
| 1124 | struct mixer_ctl *ctl_dec_data = NULL, *ctrl_bit_format = NULL; |
| 1125 | struct aac_dec_cfg_t aac_dsp_cfg; |
| 1126 | bool is_configured = false; |
| 1127 | int ret = 0; |
| 1128 | |
| 1129 | if(aac_bt_cfg == NULL) |
| 1130 | return false; |
| 1131 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1132 | ctl_dec_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_SINK_DEC_CONFIG_BLOCK); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1133 | if (!ctl_dec_data) { |
| 1134 | ALOGE(" ERROR a2dp decoder CONFIG data mixer control not identified"); |
| 1135 | is_configured = false; |
| 1136 | goto fail; |
| 1137 | } |
| 1138 | |
| 1139 | memset(&aac_dsp_cfg, 0x0, sizeof(struct aac_dec_cfg_t)); |
| 1140 | aac_dsp_cfg.dec_format = MEDIA_FMT_AAC; |
| 1141 | aac_dsp_cfg.data.aac_fmt_flag = aac_bt_cfg->aac_fmt_flag; |
| 1142 | aac_dsp_cfg.data.channels = aac_bt_cfg->channels; |
| 1143 | switch(aac_bt_cfg->audio_object_type) { |
| 1144 | case 0: |
| 1145 | aac_dsp_cfg.data.audio_object_type = MEDIA_FMT_AAC_AOT_LC; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1146 | break; |
| 1147 | case 2: |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1148 | aac_dsp_cfg.data.audio_object_type = MEDIA_FMT_AAC_AOT_PS; |
| 1149 | break; |
| 1150 | case 1: |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1151 | default: |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1152 | aac_dsp_cfg.data.audio_object_type = MEDIA_FMT_AAC_AOT_SBR; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1153 | break; |
| 1154 | } |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1155 | aac_dsp_cfg.data.total_size_of_pce_bits = aac_bt_cfg->total_size_of_pce_bits; |
| 1156 | aac_dsp_cfg.data.sampling_rate = aac_bt_cfg->sampling_rate; |
| 1157 | ret = mixer_ctl_set_array(ctl_dec_data, (void *)&aac_dsp_cfg, |
| 1158 | sizeof(struct aac_dec_cfg_t)); |
| 1159 | if (ret != 0) { |
| 1160 | ALOGE("%s: failed to set AAC decoder config", __func__); |
| 1161 | is_configured = false; |
| 1162 | goto fail; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1163 | } |
| 1164 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1165 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1166 | MIXER_DEC_BIT_FORMAT); |
| 1167 | if (!ctrl_bit_format) { |
| 1168 | ALOGE(" ERROR Dec bit format mixer control not identified"); |
| 1169 | is_configured = false; |
| 1170 | goto fail; |
| 1171 | } |
| 1172 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 1173 | if (ret != 0) { |
| 1174 | ALOGE("%s: Failed to set bit format to decoder", __func__); |
| 1175 | is_configured = false; |
| 1176 | goto fail; |
| 1177 | } |
| 1178 | |
| 1179 | is_configured = true; |
| 1180 | a2dp.bt_decoder_format = CODEC_TYPE_AAC; |
| 1181 | a2dp.dec_channels = aac_dsp_cfg.data.channels; |
| 1182 | a2dp.dec_sampling_rate = aac_dsp_cfg.data.sampling_rate; |
| 1183 | ALOGV("Successfully updated AAC dec format with sampling_rate: %d channels:%d", |
| 1184 | aac_dsp_cfg.data.sampling_rate, aac_dsp_cfg.data.channels); |
| 1185 | fail: |
| 1186 | return is_configured; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1187 | } |
| 1188 | |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1189 | static int a2dp_set_bit_format(uint32_t enc_bit_format) |
| 1190 | { |
| 1191 | const char *bit_format = NULL; |
| 1192 | struct mixer_ctl *ctrl_bit_format = NULL; |
| 1193 | |
| 1194 | // Configure AFE Input Bit Format |
| 1195 | switch (enc_bit_format) { |
| 1196 | case 32: |
| 1197 | bit_format = "S32_LE"; |
| 1198 | break; |
| 1199 | case 24: |
| 1200 | bit_format = "S24_LE"; |
| 1201 | break; |
| 1202 | case 16: |
| 1203 | default: |
| 1204 | bit_format = "S16_LE"; |
| 1205 | break; |
| 1206 | } |
| 1207 | |
| 1208 | ALOGD("%s: set AFE input bit format = %d", __func__, enc_bit_format); |
| 1209 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1210 | MIXER_ENC_BIT_FORMAT); |
| 1211 | if (!ctrl_bit_format) { |
| 1212 | ALOGE("%s: ERROR AFE input bit format mixer control not identifed", __func__); |
| 1213 | return -ENOSYS; |
| 1214 | } |
| 1215 | if (mixer_ctl_set_enum_by_string(ctrl_bit_format, bit_format) != 0) { |
| 1216 | ALOGE("%s: Failed to set AFE input bit format = %d", __func__, enc_bit_format); |
| 1217 | return -ENOSYS; |
| 1218 | } |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1222 | static int a2dp_reset_backend_cfg(uint8_t direction) |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1223 | { |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1224 | const char *rate_str = "KHZ_8", *channels = "Zero"; |
| 1225 | struct mixer_ctl *ctl_sample_rate = NULL, *ctl_sample_rate_tx = NULL; |
| 1226 | struct mixer_ctl *ctrl_channels = NULL; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1227 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1228 | // Reset backend sampling rate |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1229 | if (direction == SINK) { |
| 1230 | ALOGD("%s: reset sink backend sample rate =%s", __func__, rate_str); |
| 1231 | ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1232 | MIXER_SINK_SAMPLE_RATE); |
| 1233 | } else { |
| 1234 | ALOGD("%s: reset source backend sample rate =%s", __func__, rate_str); |
| 1235 | ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1236 | MIXER_SAMPLE_RATE_RX); |
| 1237 | } |
| 1238 | if (ctl_sample_rate) { |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1239 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1240 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) { |
| 1241 | ALOGE("%s: Failed to reset backend sample rate = %s", __func__, rate_str); |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1242 | return -ENOSYS; |
| 1243 | } |
| 1244 | |
| 1245 | ctl_sample_rate_tx = mixer_get_ctl_by_name(a2dp.adev->mixer, |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1246 | MIXER_SOURCE_SAMPLE_RATE_TX); |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1247 | if (!ctl_sample_rate_tx) { |
| 1248 | ALOGE("%s: ERROR Tx backend sample rate mixer control not identifed", __func__); |
| 1249 | return -ENOSYS; |
| 1250 | } |
| 1251 | |
| 1252 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate_tx, rate_str) != 0) { |
| 1253 | ALOGE("%s: Failed to reset Tx backend sample rate = %s", __func__, rate_str); |
| 1254 | return -ENOSYS; |
| 1255 | } |
| 1256 | } else { |
| 1257 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1258 | ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer, |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1259 | MIXER_SAMPLE_RATE_DEFAULT); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1260 | if (!ctl_sample_rate) { |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1261 | ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__); |
| 1262 | return -ENOSYS; |
| 1263 | } |
| 1264 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1265 | if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) { |
Samyak Jain | f69e9ef | 2018-06-12 12:26:37 +0530 | [diff] [blame] | 1266 | ALOGE("%s: Failed to reset backend sample rate = %s", __func__, rate_str); |
| 1267 | return -ENOSYS; |
| 1268 | } |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | // Reset AFE input channels |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1272 | if (direction == SINK) { |
| 1273 | ALOGD("%s: reset afe sink channels =%s", __func__, channels); |
| 1274 | ctrl_channels = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1275 | MIXER_AFE_SINK_CHANNELS); |
| 1276 | } else { |
| 1277 | ALOGD("%s: reset afe source channels =%s", __func__, channels); |
| 1278 | ctrl_channels = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1279 | MIXER_AFE_IN_CHANNELS); |
| 1280 | } |
| 1281 | if (!ctrl_channels) { |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1282 | ALOGE("%s: ERROR AFE input channels mixer control not identifed", __func__); |
| 1283 | return -ENOSYS; |
| 1284 | } |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1285 | if (mixer_ctl_set_enum_by_string(ctrl_channels, channels) != 0) { |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1286 | ALOGE("%s: Failed to reset AFE in channels = %d", __func__, a2dp.enc_channels); |
| 1287 | return -ENOSYS; |
| 1288 | } |
| 1289 | |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
| 1293 | /* API to configure AFE decoder in DSP */ |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1294 | static bool configure_a2dp_source_decoder_format(int dec_format) |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1295 | { |
| 1296 | struct mixer_ctl *ctl_dec_data = NULL; |
| 1297 | struct abr_dec_cfg_t dec_cfg; |
| 1298 | int ret = 0; |
| 1299 | |
| 1300 | if (a2dp.abr_config.is_abr_enabled) { |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1301 | ctl_dec_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_SOURCE_DEC_CONFIG_BLOCK); |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1302 | if (!ctl_dec_data) { |
| 1303 | ALOGE("%s: ERROR A2DP codec config data mixer control not identifed", __func__); |
| 1304 | return false; |
| 1305 | } |
| 1306 | memset(&dec_cfg, 0x0, sizeof(dec_cfg)); |
| 1307 | dec_cfg.dec_format = dec_format; |
| 1308 | dec_cfg.imc_info.direction = IMC_TRANSMIT; |
| 1309 | dec_cfg.imc_info.enable = IMC_ENABLE; |
| 1310 | dec_cfg.imc_info.purpose = IMC_PURPOSE_ID_BT_INFO; |
| 1311 | dec_cfg.imc_info.comm_instance = a2dp.abr_config.imc_instance; |
| 1312 | |
| 1313 | ret = mixer_ctl_set_array(ctl_dec_data, &dec_cfg, |
| 1314 | sizeof(dec_cfg)); |
| 1315 | if (ret != 0) { |
| 1316 | ALOGE("%s: Failed to set decoder config", __func__); |
| 1317 | return false; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1318 | } |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | return true; |
| 1322 | } |
| 1323 | |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 1324 | 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] | 1325 | { |
| 1326 | struct mixer_ctl *ctl_dec_data = NULL, *ctrl_bit_format = NULL; |
| 1327 | struct sbc_dec_cfg_t sbc_dsp_cfg; |
| 1328 | bool is_configured = false; |
| 1329 | int ret = 0; |
| 1330 | |
| 1331 | if(sbc_bt_cfg == NULL) |
| 1332 | goto fail; |
| 1333 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1334 | ctl_dec_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_SINK_DEC_CONFIG_BLOCK); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1335 | if (!ctl_dec_data) { |
| 1336 | ALOGE(" ERROR a2dp decoder CONFIG data mixer control not identified"); |
| 1337 | is_configured = false; |
| 1338 | goto fail; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1339 | } |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1340 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1341 | memset(&sbc_dsp_cfg, 0x0, sizeof(struct sbc_dec_cfg_t)); |
| 1342 | sbc_dsp_cfg.dec_format = MEDIA_FMT_SBC; |
| 1343 | sbc_dsp_cfg.data.channels = sbc_bt_cfg->channels; |
| 1344 | sbc_dsp_cfg.data.sampling_rate = sbc_bt_cfg->sampling_rate; |
| 1345 | ret = mixer_ctl_set_array(ctl_dec_data, (void *)&sbc_dsp_cfg, |
| 1346 | sizeof(struct sbc_dec_cfg_t)); |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 1347 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1348 | if (ret != 0) { |
| 1349 | ALOGE("%s: failed to set SBC decoder config", __func__); |
| 1350 | is_configured = false; |
| 1351 | goto fail; |
| 1352 | } |
| 1353 | |
| 1354 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 1355 | MIXER_DEC_BIT_FORMAT); |
| 1356 | if (!ctrl_bit_format) { |
| 1357 | ALOGE(" ERROR Dec bit format mixer control not identified"); |
| 1358 | is_configured = false; |
| 1359 | goto fail; |
| 1360 | } |
| 1361 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 1362 | if (ret != 0) { |
| 1363 | ALOGE("%s: Failed to set bit format to decoder", __func__); |
| 1364 | is_configured = false; |
| 1365 | goto fail; |
| 1366 | } |
| 1367 | |
| 1368 | is_configured = true; |
| 1369 | a2dp.bt_decoder_format = CODEC_TYPE_SBC; |
| 1370 | if (sbc_dsp_cfg.data.channels == MEDIA_FMT_SBC_CHANNEL_MODE_MONO) |
| 1371 | a2dp.dec_channels = 1; |
| 1372 | else |
| 1373 | a2dp.dec_channels = 2; |
| 1374 | a2dp.dec_sampling_rate = sbc_dsp_cfg.data.sampling_rate; |
| 1375 | ALOGV("Successfully updated SBC dec format"); |
| 1376 | fail: |
| 1377 | return is_configured; |
| 1378 | } |
| 1379 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1380 | /* API to configure AFE decoder in DSP */ |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1381 | static bool configure_a2dp_sink_decoder_format() |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1382 | { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1383 | void *codec_info = NULL; |
| 1384 | codec_t codec_type = CODEC_TYPE_INVALID; |
| 1385 | bool is_configured = false; |
| 1386 | struct mixer_ctl *ctl_dec_data = NULL; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1387 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1388 | if (!a2dp.audio_get_dec_config) { |
| 1389 | ALOGE(" a2dp handle is not identified, ignoring a2dp decoder config"); |
| 1390 | return false; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1391 | } |
| 1392 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1393 | ctl_dec_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_SINK_DEC_CONFIG_BLOCK); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1394 | if (!ctl_dec_data) { |
| 1395 | ALOGE(" ERROR a2dp decoder CONFIG data mixer control not identified"); |
| 1396 | is_configured = false; |
| 1397 | return false; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1398 | } |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1399 | codec_info = a2dp.audio_get_dec_config(&codec_type); |
| 1400 | switch(codec_type) { |
| 1401 | case CODEC_TYPE_SBC: |
| 1402 | ALOGD(" SBC decoder supported BT device"); |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 1403 | 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] | 1404 | break; |
| 1405 | case CODEC_TYPE_AAC: |
| 1406 | ALOGD(" AAC decoder supported BT device"); |
| 1407 | is_configured = |
Surendar Karka | bbb3c82 | 2018-11-12 13:00:38 +0530 | [diff] [blame] | 1408 | configure_aac_dec_format((audio_aac_dec_config_t *)codec_info); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1409 | break; |
| 1410 | default: |
| 1411 | ALOGD(" Received Unsupported decoder format"); |
| 1412 | is_configured = false; |
| 1413 | break; |
| 1414 | } |
| 1415 | return is_configured; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1416 | } |
| 1417 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1418 | /* API to configure SBC DSP encoder */ |
| 1419 | bool configure_sbc_enc_format(audio_sbc_encoder_config *sbc_bt_cfg) |
| 1420 | { |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1421 | struct mixer_ctl *ctl_enc_data = NULL; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1422 | struct sbc_enc_cfg_t sbc_dsp_cfg; |
| 1423 | bool is_configured = false; |
| 1424 | int ret = 0; |
| 1425 | |
| 1426 | if(sbc_bt_cfg == NULL) |
| 1427 | return false; |
| 1428 | |
| 1429 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1430 | if (!ctl_enc_data) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1431 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identified"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1432 | is_configured = false; |
| 1433 | goto fail; |
| 1434 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1435 | memset(&sbc_dsp_cfg, 0x0, sizeof(struct sbc_enc_cfg_t)); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1436 | sbc_dsp_cfg.enc_format = MEDIA_FMT_SBC; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1437 | sbc_dsp_cfg.num_subbands = sbc_bt_cfg->subband; |
| 1438 | sbc_dsp_cfg.blk_len = sbc_bt_cfg->blk_len; |
| 1439 | switch(sbc_bt_cfg->channels) { |
| 1440 | case 0: |
| 1441 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_MONO; |
| 1442 | break; |
| 1443 | case 1: |
| 1444 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_DUAL_MONO; |
| 1445 | break; |
| 1446 | case 3: |
| 1447 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_JOINT_STEREO; |
| 1448 | break; |
| 1449 | case 2: |
| 1450 | default: |
| 1451 | sbc_dsp_cfg.channel_mode = MEDIA_FMT_SBC_CHANNEL_MODE_STEREO; |
| 1452 | break; |
| 1453 | } |
| 1454 | if (sbc_bt_cfg->alloc) |
| 1455 | sbc_dsp_cfg.alloc_method = MEDIA_FMT_SBC_ALLOCATION_METHOD_LOUDNESS; |
| 1456 | else |
| 1457 | sbc_dsp_cfg.alloc_method = MEDIA_FMT_SBC_ALLOCATION_METHOD_SNR; |
| 1458 | sbc_dsp_cfg.bit_rate = sbc_bt_cfg->bitrate; |
| 1459 | sbc_dsp_cfg.sample_rate = sbc_bt_cfg->sampling_rate; |
| 1460 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&sbc_dsp_cfg, |
| 1461 | sizeof(struct sbc_enc_cfg_t)); |
| 1462 | if (ret != 0) { |
| 1463 | ALOGE("%s: failed to set SBC encoder config", __func__); |
| 1464 | is_configured = false; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1465 | goto fail; |
| 1466 | } |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1467 | ret = a2dp_set_bit_format(sbc_bt_cfg->bits_per_sample); |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1468 | if (ret != 0) { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1469 | is_configured = false; |
| 1470 | goto fail; |
| 1471 | } |
| 1472 | is_configured = true; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1473 | a2dp.bt_encoder_format = CODEC_TYPE_SBC; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1474 | a2dp.enc_sampling_rate = sbc_bt_cfg->sampling_rate; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1475 | |
| 1476 | if (sbc_dsp_cfg.channel_mode == MEDIA_FMT_SBC_CHANNEL_MODE_MONO) |
| 1477 | a2dp.enc_channels = 1; |
| 1478 | else |
| 1479 | a2dp.enc_channels = 2; |
| 1480 | |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1481 | ALOGV("Successfully updated SBC enc format with samplingrate: %d channelmode:%d", |
| 1482 | sbc_dsp_cfg.sample_rate, sbc_dsp_cfg.channel_mode); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1483 | fail: |
| 1484 | return is_configured; |
| 1485 | } |
| 1486 | |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1487 | #ifndef LINUX_ENABLED |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 1488 | static int update_aptx_ad_dsp_config(struct aptx_ad_enc_cfg_t *aptx_dsp_cfg, |
| 1489 | audio_aptx_encoder_config *aptx_bt_cfg) |
| 1490 | { |
| 1491 | int ret = 0; |
| 1492 | |
| 1493 | if(aptx_dsp_cfg == NULL || aptx_bt_cfg == NULL) { |
| 1494 | ALOGE("Invalid param, aptx_dsp_cfg %p aptx_bt_cfg %p", |
| 1495 | aptx_dsp_cfg, aptx_bt_cfg); |
| 1496 | return -EINVAL; |
| 1497 | } |
| 1498 | |
| 1499 | memset(aptx_dsp_cfg, 0x0, sizeof(struct aptx_ad_enc_cfg_t)); |
Ramu Gottipati | 0280968 | 2018-12-19 16:46:12 +0530 | [diff] [blame] | 1500 | aptx_dsp_cfg->custom_cfg.enc_format = MEDIA_FMT_APTX_AD; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 1501 | |
| 1502 | |
| 1503 | aptx_dsp_cfg->aptx_ad_cfg.sampling_freq = aptx_bt_cfg->ad_cfg->sampling_rate; |
| 1504 | aptx_dsp_cfg->aptx_ad_cfg.mtu = aptx_bt_cfg->ad_cfg->mtu; |
| 1505 | aptx_dsp_cfg->aptx_ad_cfg.channel_mode = aptx_bt_cfg->ad_cfg->channel_mode; |
| 1506 | aptx_dsp_cfg->aptx_ad_cfg.min_sink_modeA = aptx_bt_cfg->ad_cfg->min_sink_modeA; |
| 1507 | aptx_dsp_cfg->aptx_ad_cfg.max_sink_modeA = aptx_bt_cfg->ad_cfg->max_sink_modeA; |
| 1508 | aptx_dsp_cfg->aptx_ad_cfg.min_sink_modeB = aptx_bt_cfg->ad_cfg->min_sink_modeB; |
| 1509 | aptx_dsp_cfg->aptx_ad_cfg.max_sink_modeB = aptx_bt_cfg->ad_cfg->max_sink_modeB; |
| 1510 | aptx_dsp_cfg->aptx_ad_cfg.min_sink_modeC = aptx_bt_cfg->ad_cfg->min_sink_modeC; |
| 1511 | aptx_dsp_cfg->aptx_ad_cfg.max_sink_modeC = aptx_bt_cfg->ad_cfg->max_sink_modeC; |
Sharad Sangle | e378afe | 2018-09-03 20:04:17 +0530 | [diff] [blame] | 1512 | aptx_dsp_cfg->aptx_ad_cfg.mode = aptx_bt_cfg->ad_cfg->encoder_mode; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 1513 | aptx_dsp_cfg->abr_cfg.imc_info.direction = IMC_RECEIVE; |
| 1514 | aptx_dsp_cfg->abr_cfg.imc_info.enable = IMC_ENABLE; |
| 1515 | aptx_dsp_cfg->abr_cfg.imc_info.purpose = IMC_PURPOSE_ID_BT_INFO; |
| 1516 | aptx_dsp_cfg->abr_cfg.imc_info.comm_instance = a2dp.abr_config.imc_instance; |
| 1517 | |
| 1518 | |
| 1519 | switch(aptx_dsp_cfg->aptx_ad_cfg.channel_mode) { |
| 1520 | case APTX_AD_CHANNEL_UNCHANGED: |
| 1521 | case APTX_AD_CHANNEL_JOINT_STEREO: |
| 1522 | case APTX_AD_CHANNEL_DUAL_MONO: |
| 1523 | case APTX_AD_CHANNEL_STEREO_TWS: |
| 1524 | case APTX_AD_CHANNEL_EARBUD: |
| 1525 | default: |
| 1526 | a2dp.enc_channels = CH_STEREO; |
| 1527 | aptx_dsp_cfg->custom_cfg.num_channels = CH_STEREO; |
| 1528 | aptx_dsp_cfg->custom_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 1529 | aptx_dsp_cfg->custom_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 1530 | break; |
| 1531 | case APTX_AD_CHANNEL_MONO: |
| 1532 | a2dp.enc_channels = CH_MONO; |
| 1533 | aptx_dsp_cfg->custom_cfg.num_channels = CH_MONO; |
| 1534 | aptx_dsp_cfg->custom_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 1535 | break; |
| 1536 | } |
| 1537 | switch(aptx_dsp_cfg->aptx_ad_cfg.sampling_freq) { |
| 1538 | case APTX_AD_SR_UNCHANGED: |
| 1539 | case APTX_AD_48: |
| 1540 | default: |
| 1541 | a2dp.enc_sampling_rate = SAMPLING_RATE_48K; |
| 1542 | aptx_dsp_cfg->custom_cfg.sample_rate = SAMPLING_RATE_48K; |
| 1543 | break; |
| 1544 | case APTX_AD_44_1: |
| 1545 | a2dp.enc_sampling_rate = SAMPLING_RATE_441K; |
| 1546 | aptx_dsp_cfg->custom_cfg.sample_rate = SAMPLING_RATE_441K; |
| 1547 | break; |
| 1548 | } |
| 1549 | ALOGV("Successfully updated APTX AD enc format with \ |
| 1550 | samplingrate: %d channels:%d", |
| 1551 | aptx_dsp_cfg->custom_cfg.sample_rate, |
| 1552 | aptx_dsp_cfg->custom_cfg.num_channels); |
| 1553 | |
| 1554 | return ret; |
| 1555 | } |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 1556 | |
| 1557 | static void audio_a2dp_update_tws_channel_mode() |
| 1558 | { |
| 1559 | char* channel_mode; |
| 1560 | struct mixer_ctl *ctl_channel_mode; |
| 1561 | if (a2dp.is_tws_mono_mode_on) |
| 1562 | channel_mode = "One"; |
| 1563 | else |
| 1564 | channel_mode = "Two"; |
| 1565 | ctl_channel_mode = mixer_get_ctl_by_name(a2dp.adev->mixer,MIXER_FMT_TWS_CHANNEL_MODE); |
| 1566 | if (!ctl_channel_mode) { |
| 1567 | ALOGE("failed to get tws mixer ctl"); |
| 1568 | return; |
| 1569 | } |
| 1570 | if (mixer_ctl_set_enum_by_string(ctl_channel_mode, channel_mode) != 0) { |
| 1571 | ALOGE("%s: Failed to set the channel mode = %s", __func__, channel_mode); |
| 1572 | return; |
| 1573 | } |
| 1574 | } |
| 1575 | |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1576 | static int update_aptx_dsp_config_v2(struct aptx_enc_cfg_t *aptx_dsp_cfg, |
| 1577 | audio_aptx_encoder_config *aptx_bt_cfg) |
| 1578 | { |
| 1579 | int ret = 0; |
| 1580 | |
| 1581 | if(aptx_dsp_cfg == NULL || aptx_bt_cfg == NULL) { |
| 1582 | ALOGE("Invalid param, aptx_dsp_cfg %p aptx_bt_cfg %p", |
| 1583 | aptx_dsp_cfg, aptx_bt_cfg); |
| 1584 | return -EINVAL; |
| 1585 | } |
| 1586 | |
| 1587 | memset(aptx_dsp_cfg, 0x0, sizeof(struct aptx_enc_cfg_t)); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1588 | aptx_dsp_cfg->custom_cfg.enc_format = MEDIA_FMT_APTX; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1589 | |
| 1590 | if (!a2dp.is_aptx_dual_mono_supported) { |
| 1591 | aptx_dsp_cfg->custom_cfg.sample_rate = aptx_bt_cfg->default_cfg->sampling_rate; |
| 1592 | aptx_dsp_cfg->custom_cfg.num_channels = aptx_bt_cfg->default_cfg->channels; |
| 1593 | } else { |
| 1594 | aptx_dsp_cfg->custom_cfg.sample_rate = aptx_bt_cfg->dual_mono_cfg->sampling_rate; |
| 1595 | aptx_dsp_cfg->custom_cfg.num_channels = aptx_bt_cfg->dual_mono_cfg->channels; |
| 1596 | aptx_dsp_cfg->aptx_v2_cfg.sync_mode = aptx_bt_cfg->dual_mono_cfg->sync_mode; |
| 1597 | } |
| 1598 | |
| 1599 | switch(aptx_dsp_cfg->custom_cfg.num_channels) { |
| 1600 | case 1: |
| 1601 | aptx_dsp_cfg->custom_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 1602 | break; |
| 1603 | case 2: |
| 1604 | default: |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 1605 | if (!a2dp.is_tws_mono_mode_on) { |
| 1606 | aptx_dsp_cfg->custom_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 1607 | aptx_dsp_cfg->custom_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 1608 | } |
| 1609 | else { |
| 1610 | a2dp.is_tws_mono_mode_on = true; |
| 1611 | ALOGD("Update tws for mono_mode_on: %d",a2dp.is_tws_mono_mode_on); |
| 1612 | audio_a2dp_update_tws_channel_mode(); |
| 1613 | } |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1614 | break; |
| 1615 | } |
| 1616 | a2dp.enc_channels = aptx_dsp_cfg->custom_cfg.num_channels; |
| 1617 | if (!a2dp.is_aptx_dual_mono_supported) { |
| 1618 | a2dp.enc_sampling_rate = aptx_bt_cfg->default_cfg->sampling_rate; |
| 1619 | ALOGV("Successfully updated APTX enc format with samplingrate: %d \ |
| 1620 | channels:%d", aptx_dsp_cfg->custom_cfg.sample_rate, |
| 1621 | aptx_dsp_cfg->custom_cfg.num_channels); |
| 1622 | } else { |
| 1623 | a2dp.enc_sampling_rate = aptx_bt_cfg->dual_mono_cfg->sampling_rate; |
| 1624 | ALOGV("Successfully updated APTX dual mono enc format with \ |
| 1625 | samplingrate: %d channels:%d syncmode %d", |
| 1626 | aptx_dsp_cfg->custom_cfg.sample_rate, |
| 1627 | aptx_dsp_cfg->custom_cfg.num_channels, |
| 1628 | aptx_dsp_cfg->aptx_v2_cfg.sync_mode); |
| 1629 | } |
| 1630 | return ret; |
| 1631 | } |
| 1632 | #else |
| 1633 | static int update_aptx_dsp_config_v1(struct custom_enc_cfg_t *aptx_dsp_cfg, |
| 1634 | audio_aptx_encoder_config *aptx_bt_cfg) |
| 1635 | { |
| 1636 | int ret = 0; |
| 1637 | |
| 1638 | if(aptx_dsp_cfg == NULL || aptx_bt_cfg == NULL) { |
| 1639 | ALOGE("Invalid param, aptx_dsp_cfg %p aptx_bt_cfg %p", |
| 1640 | aptx_dsp_cfg, aptx_bt_cfg); |
| 1641 | return -EINVAL; |
| 1642 | } |
| 1643 | |
| 1644 | memset(&aptx_dsp_cfg, 0x0, sizeof(struct custom_enc_cfg_t)); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1645 | aptx_dsp_cfg->enc_format = MEDIA_FMT_APTX; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1646 | aptx_dsp_cfg->sample_rate = aptx_bt_cfg->sampling_rate; |
| 1647 | aptx_dsp_cfg->num_channels = aptx_bt_cfg->channels; |
| 1648 | switch(aptx_dsp_cfg->num_channels) { |
| 1649 | case 1: |
| 1650 | aptx_dsp_cfg->channel_mapping[0] = PCM_CHANNEL_C; |
| 1651 | break; |
| 1652 | case 2: |
| 1653 | default: |
| 1654 | aptx_dsp_cfg->channel_mapping[0] = PCM_CHANNEL_L; |
| 1655 | aptx_dsp_cfg->channel_mapping[1] = PCM_CHANNEL_R; |
| 1656 | break; |
| 1657 | } |
| 1658 | |
| 1659 | ALOGV("Updated APTX enc format with samplingrate: %d channels:%d", |
| 1660 | aptx_dsp_cfg->sample_rate, aptx_dsp_cfg->num_channels); |
| 1661 | |
| 1662 | return ret; |
| 1663 | } |
| 1664 | #endif |
| 1665 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1666 | /* API to configure APTX DSP encoder */ |
| 1667 | bool configure_aptx_enc_format(audio_aptx_encoder_config *aptx_bt_cfg) |
| 1668 | { |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1669 | struct mixer_ctl *ctl_enc_data = NULL; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1670 | int mixer_size; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1671 | bool is_configured = false; |
| 1672 | int ret = 0; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1673 | int sample_rate_backup; |
Preetam Singh Ranawat | 109bb3c | 2018-01-30 12:12:02 +0530 | [diff] [blame] | 1674 | |
| 1675 | if(aptx_bt_cfg == NULL) |
| 1676 | return false; |
| 1677 | |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 1678 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1679 | if (!ctl_enc_data) { |
| 1680 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 1681 | return false; |
| 1682 | } |
| 1683 | |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1684 | #ifndef LINUX_ENABLED |
| 1685 | struct aptx_enc_cfg_t aptx_dsp_cfg; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 1686 | struct aptx_ad_enc_cfg_t aptx_ad_dsp_cfg; |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 1687 | if(a2dp.is_aptx_adaptive) { |
| 1688 | mixer_size = sizeof(struct aptx_ad_enc_cfg_t); |
| 1689 | ret = update_aptx_ad_dsp_config(&aptx_ad_dsp_cfg, aptx_bt_cfg); |
| 1690 | sample_rate_backup = aptx_ad_dsp_cfg.custom_cfg.sample_rate; |
| 1691 | } else { |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 1692 | mixer_size = sizeof(struct aptx_enc_cfg_t); |
| 1693 | sample_rate_backup = aptx_bt_cfg->default_cfg->sampling_rate; |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 1694 | ret = update_aptx_dsp_config_v2(&aptx_dsp_cfg, aptx_bt_cfg); |
| 1695 | } |
| 1696 | if (ret) { |
| 1697 | is_configured = false; |
| 1698 | goto fail; |
| 1699 | } |
| 1700 | |
| 1701 | if(a2dp.is_aptx_adaptive) { |
| 1702 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_ad_dsp_cfg, |
| 1703 | mixer_size); |
| 1704 | } else { |
| 1705 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg, |
| 1706 | mixer_size); |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 1707 | } |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1708 | #else |
| 1709 | struct custom_enc_cfg_t aptx_dsp_cfg; |
| 1710 | mixer_size = sizeof(struct custom_enc_cfg_t); |
| 1711 | sample_rate_backup = aptx_bt_cfg->sampling_rate; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1712 | ret = update_aptx_dsp_config_v1(&aptx_dsp_cfg, aptx_bt_cfg); |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1713 | if (ret) { |
| 1714 | is_configured = false; |
| 1715 | goto fail; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1716 | } |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 1717 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg, |
| 1718 | mixer_size); |
| 1719 | #endif |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1720 | if (ret != 0) { |
| 1721 | ALOGE("%s: Failed to set APTX encoder config", __func__); |
| 1722 | is_configured = false; |
| 1723 | goto fail; |
| 1724 | } |
Ramu Gottipati | 3e0d4c3 | 2018-11-05 15:57:28 +0530 | [diff] [blame] | 1725 | #ifndef LINUX_ENABLED //Temporarily disabled for LE, need to take care while doing VT FR |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1726 | if(a2dp.is_aptx_adaptive) |
| 1727 | ret = a2dp_set_bit_format(aptx_bt_cfg->ad_cfg->bits_per_sample); |
| 1728 | else if(a2dp.is_aptx_dual_mono_supported) |
| 1729 | ret = a2dp_set_bit_format(aptx_bt_cfg->dual_mono_cfg->bits_per_sample); |
| 1730 | else |
| 1731 | ret = a2dp_set_bit_format(aptx_bt_cfg->default_cfg->bits_per_sample); |
Ramu Gottipati | 3e0d4c3 | 2018-11-05 15:57:28 +0530 | [diff] [blame] | 1732 | #endif |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1733 | if (ret != 0) { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1734 | is_configured = false; |
| 1735 | goto fail; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1736 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1737 | is_configured = true; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 1738 | if (a2dp.is_aptx_adaptive) |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1739 | a2dp.bt_encoder_format = CODEC_TYPE_APTX_AD; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 1740 | else |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 1741 | a2dp.bt_encoder_format = CODEC_TYPE_APTX; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1742 | fail: |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1743 | /*restore sample rate */ |
| 1744 | if(!is_configured) |
| 1745 | a2dp.enc_sampling_rate = sample_rate_backup; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1746 | return is_configured; |
| 1747 | } |
| 1748 | |
| 1749 | /* API to configure APTX HD DSP encoder |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1750 | */ |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 1751 | #ifndef LINUX_ENABLED |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 1752 | 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] | 1753 | #else |
| 1754 | bool configure_aptx_hd_enc_format(audio_aptx_encoder_config *aptx_bt_cfg) |
| 1755 | #endif |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1756 | { |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1757 | struct mixer_ctl *ctl_enc_data = NULL; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1758 | struct custom_enc_cfg_t aptx_dsp_cfg; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1759 | bool is_configured = false; |
| 1760 | int ret = 0; |
| 1761 | |
| 1762 | if(aptx_bt_cfg == NULL) |
| 1763 | return false; |
| 1764 | |
| 1765 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1766 | if (!ctl_enc_data) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1767 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identified"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1768 | is_configured = false; |
| 1769 | goto fail; |
| 1770 | } |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1771 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1772 | memset(&aptx_dsp_cfg, 0x0, sizeof(struct custom_enc_cfg_t)); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1773 | aptx_dsp_cfg.enc_format = MEDIA_FMT_APTX_HD; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1774 | aptx_dsp_cfg.sample_rate = aptx_bt_cfg->sampling_rate; |
| 1775 | aptx_dsp_cfg.num_channels = aptx_bt_cfg->channels; |
| 1776 | switch(aptx_dsp_cfg.num_channels) { |
| 1777 | case 1: |
| 1778 | aptx_dsp_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 1779 | break; |
| 1780 | case 2: |
| 1781 | default: |
| 1782 | aptx_dsp_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 1783 | aptx_dsp_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 1784 | break; |
| 1785 | } |
| 1786 | 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] | 1787 | sizeof(struct custom_enc_cfg_t)); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1788 | if (ret != 0) { |
| 1789 | ALOGE("%s: Failed to set APTX HD encoder config", __func__); |
| 1790 | is_configured = false; |
| 1791 | goto fail; |
| 1792 | } |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1793 | ret = a2dp_set_bit_format(aptx_bt_cfg->bits_per_sample); |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1794 | if (ret != 0) { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1795 | is_configured = false; |
| 1796 | goto fail; |
| 1797 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1798 | is_configured = true; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1799 | a2dp.bt_encoder_format = CODEC_TYPE_APTX_HD; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1800 | a2dp.enc_sampling_rate = aptx_bt_cfg->sampling_rate; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1801 | a2dp.enc_channels = aptx_bt_cfg->channels; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1802 | ALOGV("Successfully updated APTX HD encformat with samplingrate: %d channels:%d", |
| 1803 | aptx_dsp_cfg.sample_rate, aptx_dsp_cfg.num_channels); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1804 | fail: |
| 1805 | return is_configured; |
| 1806 | } |
| 1807 | |
| 1808 | /* API to configure AAC DSP encoder */ |
| 1809 | bool configure_aac_enc_format(audio_aac_encoder_config *aac_bt_cfg) |
| 1810 | { |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1811 | struct mixer_ctl *ctl_enc_data = NULL; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1812 | struct aac_enc_cfg_t aac_dsp_cfg; |
| 1813 | bool is_configured = false; |
| 1814 | int ret = 0; |
| 1815 | |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 1816 | if (aac_bt_cfg == NULL) |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1817 | return false; |
| 1818 | |
| 1819 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1820 | if (!ctl_enc_data) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1821 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identified"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1822 | is_configured = false; |
| 1823 | goto fail; |
| 1824 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1825 | memset(&aac_dsp_cfg, 0x0, sizeof(struct aac_enc_cfg_t)); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1826 | aac_dsp_cfg.enc_format = MEDIA_FMT_AAC; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1827 | aac_dsp_cfg.bit_rate = aac_bt_cfg->bitrate; |
Naresh Tanniru | a42d0bd | 2016-09-21 15:30:46 +0530 | [diff] [blame] | 1828 | aac_dsp_cfg.sample_rate = aac_bt_cfg->sampling_rate; |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 1829 | switch (aac_bt_cfg->enc_mode) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1830 | case 0: |
| 1831 | aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_LC; |
| 1832 | break; |
| 1833 | case 2: |
| 1834 | aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_PS; |
| 1835 | break; |
| 1836 | case 1: |
| 1837 | default: |
| 1838 | aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_SBR; |
| 1839 | break; |
| 1840 | } |
Naresh Tanniru | a42d0bd | 2016-09-21 15:30:46 +0530 | [diff] [blame] | 1841 | aac_dsp_cfg.aac_fmt_flag = aac_bt_cfg->format_flag; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1842 | aac_dsp_cfg.channel_cfg = aac_bt_cfg->channels; |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 1843 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1844 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aac_dsp_cfg, |
| 1845 | sizeof(struct aac_enc_cfg_t)); |
| 1846 | if (ret != 0) { |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 1847 | ALOGE("%s: Failed to set AAC encoder config", __func__); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1848 | is_configured = false; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1849 | goto fail; |
| 1850 | } |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1851 | ret = a2dp_set_bit_format(aac_bt_cfg->bits_per_sample); |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1852 | if (ret != 0) { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1853 | is_configured = false; |
| 1854 | goto fail; |
| 1855 | } |
| 1856 | is_configured = true; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1857 | a2dp.bt_encoder_format = CODEC_TYPE_AAC; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 1858 | a2dp.enc_sampling_rate = aac_bt_cfg->sampling_rate; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 1859 | a2dp.enc_channels = aac_bt_cfg->channels; |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 1860 | ALOGV("%s: Successfully updated AAC enc format with sampling rate: %d channels:%d", |
| 1861 | __func__, aac_dsp_cfg.sample_rate, aac_dsp_cfg.channel_cfg); |
| 1862 | fail: |
| 1863 | return is_configured; |
| 1864 | } |
| 1865 | |
| 1866 | bool configure_aac_enc_format_v2(audio_aac_encoder_config_v2 *aac_bt_cfg) |
| 1867 | { |
| 1868 | struct mixer_ctl *ctl_enc_data = NULL; |
| 1869 | struct aac_enc_cfg_v2_t aac_dsp_cfg; |
| 1870 | bool is_configured = false; |
| 1871 | int ret = 0; |
| 1872 | |
| 1873 | if (aac_bt_cfg == NULL) |
| 1874 | return false; |
| 1875 | |
| 1876 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1877 | if (!ctl_enc_data) { |
| 1878 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed"); |
| 1879 | is_configured = false; |
| 1880 | goto fail; |
| 1881 | } |
| 1882 | memset(&aac_dsp_cfg, 0x0, sizeof(struct aac_enc_cfg_v2_t)); |
Ramu Gottipati | 08d82e7 | 2018-12-17 11:52:14 +0530 | [diff] [blame] | 1883 | aac_dsp_cfg.aac_enc_cfg.enc_format = MEDIA_FMT_AAC; |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 1884 | aac_dsp_cfg.aac_enc_cfg.bit_rate = aac_bt_cfg->audio_aac_enc_cfg.bitrate; |
| 1885 | aac_dsp_cfg.aac_enc_cfg.sample_rate = aac_bt_cfg->audio_aac_enc_cfg.sampling_rate; |
| 1886 | switch (aac_bt_cfg->audio_aac_enc_cfg.enc_mode) { |
| 1887 | case 0: |
| 1888 | aac_dsp_cfg.aac_enc_cfg.enc_mode = MEDIA_FMT_AAC_AOT_LC; |
| 1889 | break; |
| 1890 | case 2: |
| 1891 | aac_dsp_cfg.aac_enc_cfg.enc_mode = MEDIA_FMT_AAC_AOT_PS; |
| 1892 | break; |
| 1893 | case 1: |
| 1894 | default: |
| 1895 | aac_dsp_cfg.aac_enc_cfg.enc_mode = MEDIA_FMT_AAC_AOT_SBR; |
| 1896 | break; |
| 1897 | } |
| 1898 | aac_dsp_cfg.aac_enc_cfg.aac_fmt_flag = aac_bt_cfg->audio_aac_enc_cfg.format_flag; |
| 1899 | aac_dsp_cfg.aac_enc_cfg.channel_cfg = aac_bt_cfg->audio_aac_enc_cfg.channels; |
| 1900 | aac_dsp_cfg.frame_ctl.ctl_type = aac_bt_cfg->frame_ctl.ctl_type; |
| 1901 | aac_dsp_cfg.frame_ctl.ctl_value = aac_bt_cfg->frame_ctl.ctl_value; |
| 1902 | |
| 1903 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aac_dsp_cfg, |
| 1904 | sizeof(struct aac_enc_cfg_v2_t)); |
| 1905 | if (ret != 0) { |
| 1906 | ALOGE("%s: Failed to set AAC encoder config", __func__); |
| 1907 | is_configured = false; |
| 1908 | goto fail; |
| 1909 | } |
| 1910 | ret = a2dp_set_bit_format(aac_bt_cfg->audio_aac_enc_cfg.bits_per_sample); |
| 1911 | if (ret != 0) { |
| 1912 | is_configured = false; |
| 1913 | goto fail; |
| 1914 | } |
| 1915 | is_configured = true; |
Ramu Gottipati | 08d82e7 | 2018-12-17 11:52:14 +0530 | [diff] [blame] | 1916 | a2dp.bt_encoder_format = CODEC_TYPE_AAC; |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 1917 | a2dp.enc_sampling_rate = aac_bt_cfg->audio_aac_enc_cfg.sampling_rate; |
| 1918 | a2dp.enc_channels = aac_bt_cfg->audio_aac_enc_cfg.channels; |
| 1919 | ALOGV("%s: Successfully updated AAC enc format with sampling rate: %d channels:%d", |
| 1920 | __func__, aac_dsp_cfg.aac_enc_cfg.sample_rate, aac_dsp_cfg.aac_enc_cfg.channel_cfg); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1921 | fail: |
| 1922 | return is_configured; |
| 1923 | } |
| 1924 | |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1925 | bool configure_celt_enc_format(audio_celt_encoder_config *celt_bt_cfg) |
| 1926 | { |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1927 | struct mixer_ctl *ctl_enc_data = NULL; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1928 | struct celt_enc_cfg_t celt_dsp_cfg; |
| 1929 | bool is_configured = false; |
| 1930 | int ret = 0; |
| 1931 | if(celt_bt_cfg == NULL) |
| 1932 | return false; |
| 1933 | |
| 1934 | ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1935 | if (!ctl_enc_data) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1936 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identified"); |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1937 | is_configured = false; |
| 1938 | goto fail; |
| 1939 | } |
| 1940 | memset(&celt_dsp_cfg, 0x0, sizeof(struct celt_enc_cfg_t)); |
| 1941 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1942 | celt_dsp_cfg.custom_cfg.enc_format = MEDIA_FMT_CELT; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1943 | celt_dsp_cfg.custom_cfg.sample_rate = celt_bt_cfg->sampling_rate; |
| 1944 | celt_dsp_cfg.custom_cfg.num_channels = celt_bt_cfg->channels; |
| 1945 | switch(celt_dsp_cfg.custom_cfg.num_channels) { |
| 1946 | case 1: |
| 1947 | celt_dsp_cfg.custom_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 1948 | break; |
| 1949 | case 2: |
| 1950 | default: |
| 1951 | celt_dsp_cfg.custom_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 1952 | celt_dsp_cfg.custom_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 1953 | break; |
| 1954 | } |
| 1955 | |
| 1956 | celt_dsp_cfg.custom_cfg.custom_size = sizeof(struct celt_enc_cfg_t); |
| 1957 | |
| 1958 | celt_dsp_cfg.celt_cfg.frame_size = celt_bt_cfg->frame_size; |
| 1959 | celt_dsp_cfg.celt_cfg.complexity = celt_bt_cfg->complexity; |
| 1960 | celt_dsp_cfg.celt_cfg.prediction_mode = celt_bt_cfg->prediction_mode; |
| 1961 | celt_dsp_cfg.celt_cfg.vbr_flag = celt_bt_cfg->vbr_flag; |
| 1962 | celt_dsp_cfg.celt_cfg.bit_rate = celt_bt_cfg->bitrate; |
| 1963 | |
| 1964 | ret = mixer_ctl_set_array(ctl_enc_data, (void *)&celt_dsp_cfg, |
| 1965 | sizeof(struct celt_enc_cfg_t)); |
| 1966 | if (ret != 0) { |
| 1967 | ALOGE("%s: Failed to set CELT encoder config", __func__); |
| 1968 | is_configured = false; |
| 1969 | goto fail; |
| 1970 | } |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1971 | ret = a2dp_set_bit_format(celt_bt_cfg->bits_per_sample); |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1972 | if (ret != 0) { |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1973 | is_configured = false; |
| 1974 | goto fail; |
| 1975 | } |
| 1976 | is_configured = true; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1977 | a2dp.bt_encoder_format = CODEC_TYPE_CELT; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1978 | a2dp.enc_sampling_rate = celt_bt_cfg->sampling_rate; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 1979 | a2dp.enc_channels = celt_bt_cfg->channels; |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 1980 | ALOGV("Successfully updated CELT encformat with samplingrate: %d channels:%d", |
| 1981 | celt_dsp_cfg.custom_cfg.sample_rate, celt_dsp_cfg.custom_cfg.num_channels); |
| 1982 | fail: |
| 1983 | return is_configured; |
| 1984 | } |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1985 | |
| 1986 | bool configure_ldac_enc_format(audio_ldac_encoder_config *ldac_bt_cfg) |
| 1987 | { |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 1988 | struct mixer_ctl *ldac_enc_data = NULL; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1989 | struct ldac_enc_cfg_t ldac_dsp_cfg; |
| 1990 | bool is_configured = false; |
| 1991 | int ret = 0; |
| 1992 | if(ldac_bt_cfg == NULL) |
| 1993 | return false; |
| 1994 | |
| 1995 | ldac_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK); |
| 1996 | if (!ldac_enc_data) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 1997 | ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identified"); |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 1998 | is_configured = false; |
| 1999 | goto fail; |
| 2000 | } |
| 2001 | memset(&ldac_dsp_cfg, 0x0, sizeof(struct ldac_enc_cfg_t)); |
| 2002 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2003 | ldac_dsp_cfg.custom_cfg.enc_format = MEDIA_FMT_LDAC; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2004 | ldac_dsp_cfg.custom_cfg.sample_rate = ldac_bt_cfg->sampling_rate; |
| 2005 | ldac_dsp_cfg.ldac_cfg.channel_mode = ldac_bt_cfg->channel_mode; |
| 2006 | switch(ldac_dsp_cfg.ldac_cfg.channel_mode) { |
| 2007 | case 4: |
| 2008 | ldac_dsp_cfg.custom_cfg.channel_mapping[0] = PCM_CHANNEL_C; |
| 2009 | ldac_dsp_cfg.custom_cfg.num_channels = 1; |
| 2010 | break; |
| 2011 | case 2: |
| 2012 | case 1: |
| 2013 | default: |
| 2014 | ldac_dsp_cfg.custom_cfg.channel_mapping[0] = PCM_CHANNEL_L; |
| 2015 | ldac_dsp_cfg.custom_cfg.channel_mapping[1] = PCM_CHANNEL_R; |
| 2016 | ldac_dsp_cfg.custom_cfg.num_channels = 2; |
| 2017 | break; |
| 2018 | } |
| 2019 | |
| 2020 | ldac_dsp_cfg.custom_cfg.custom_size = sizeof(struct ldac_enc_cfg_t); |
| 2021 | ldac_dsp_cfg.ldac_cfg.mtu = ldac_bt_cfg->mtu; |
| 2022 | ldac_dsp_cfg.ldac_cfg.bit_rate = ldac_bt_cfg->bit_rate; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2023 | if (ldac_bt_cfg->is_abr_enabled) { |
| 2024 | ldac_dsp_cfg.abr_cfg.mapping_info = ldac_bt_cfg->level_to_bitrate_map; |
| 2025 | ldac_dsp_cfg.abr_cfg.imc_info.direction = IMC_RECEIVE; |
| 2026 | ldac_dsp_cfg.abr_cfg.imc_info.enable = IMC_ENABLE; |
| 2027 | ldac_dsp_cfg.abr_cfg.imc_info.purpose = IMC_PURPOSE_ID_BT_INFO; |
| 2028 | ldac_dsp_cfg.abr_cfg.imc_info.comm_instance = a2dp.abr_config.imc_instance; |
Aniket Kumar Lata | 8c884eb | 2018-08-06 15:30:50 -0700 | [diff] [blame] | 2029 | ldac_dsp_cfg.abr_cfg.is_abr_enabled = ldac_bt_cfg->is_abr_enabled; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2030 | } |
| 2031 | |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2032 | ret = mixer_ctl_set_array(ldac_enc_data, (void *)&ldac_dsp_cfg, |
| 2033 | sizeof(struct ldac_enc_cfg_t)); |
| 2034 | if (ret != 0) { |
| 2035 | ALOGE("%s: Failed to set LDAC encoder config", __func__); |
| 2036 | is_configured = false; |
| 2037 | goto fail; |
| 2038 | } |
Samyak Jain | 2cddc0e | 2018-07-18 15:22:27 +0530 | [diff] [blame] | 2039 | ret = a2dp_set_bit_format(ldac_bt_cfg->bits_per_sample); |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2040 | if (ret != 0) { |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2041 | is_configured = false; |
| 2042 | goto fail; |
| 2043 | } |
| 2044 | is_configured = true; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2045 | a2dp.bt_encoder_format = CODEC_TYPE_LDAC; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2046 | a2dp.enc_sampling_rate = ldac_bt_cfg->sampling_rate; |
| 2047 | a2dp.enc_channels = ldac_dsp_cfg.custom_cfg.num_channels; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2048 | a2dp.abr_config.is_abr_enabled = ldac_bt_cfg->is_abr_enabled; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2049 | ALOGV("Successfully updated LDAC encformat with samplingrate: %d channels:%d", |
| 2050 | ldac_dsp_cfg.custom_cfg.sample_rate, ldac_dsp_cfg.custom_cfg.num_channels); |
| 2051 | fail: |
| 2052 | return is_configured; |
| 2053 | } |
| 2054 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2055 | bool configure_a2dp_encoder_format() |
| 2056 | { |
| 2057 | void *codec_info = NULL; |
| 2058 | uint8_t multi_cast = 0, num_dev = 1; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2059 | codec_t codec_type = CODEC_TYPE_INVALID; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2060 | bool is_configured = false; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 2061 | audio_aptx_encoder_config aptx_encoder_cfg; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2062 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2063 | if (!a2dp.audio_get_enc_config) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2064 | ALOGE(" a2dp handle is not identified, ignoring a2dp encoder config"); |
| 2065 | return false; |
| 2066 | } |
| 2067 | ALOGD("configure_a2dp_encoder_format start"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2068 | codec_info = a2dp.audio_get_enc_config(&multi_cast, &num_dev, |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2069 | &codec_type); |
| 2070 | |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2071 | // ABR disabled by default for all codecs |
| 2072 | a2dp.abr_config.is_abr_enabled = false; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 2073 | a2dp.is_aptx_adaptive = false; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2074 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2075 | switch(codec_type) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2076 | case CODEC_TYPE_SBC: |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2077 | ALOGD(" Received SBC encoder supported BT device"); |
| 2078 | is_configured = |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 2079 | configure_sbc_enc_format((audio_sbc_encoder_config *)codec_info); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2080 | break; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2081 | case CODEC_TYPE_APTX: |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2082 | ALOGD(" Received APTX encoder supported BT device"); |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 2083 | #ifndef LINUX_ENABLED |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 2084 | a2dp.is_aptx_dual_mono_supported = false; |
| 2085 | aptx_encoder_cfg.default_cfg = (audio_aptx_default_config *)codec_info; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 2086 | #endif |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2087 | is_configured = |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 2088 | configure_aptx_enc_format(&aptx_encoder_cfg); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2089 | break; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2090 | case CODEC_TYPE_APTX_HD: |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2091 | ALOGD(" Received APTX HD encoder supported BT device"); |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 2092 | #ifndef LINUX_ENABLED |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2093 | is_configured = |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 2094 | configure_aptx_hd_enc_format((audio_aptx_default_config *)codec_info); |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 2095 | #else |
| 2096 | is_configured = |
| 2097 | configure_aptx_hd_enc_format((audio_aptx_encoder_config *)codec_info); |
| 2098 | #endif |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 2099 | break; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 2100 | #ifndef LINUX_ENABLED |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2101 | case CODEC_TYPE_APTX_DUAL_MONO: |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 2102 | ALOGD(" Received APTX dual mono encoder supported BT device"); |
| 2103 | a2dp.is_aptx_dual_mono_supported = true; |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 2104 | if (a2dp.audio_is_tws_mono_mode_enable != NULL) |
| 2105 | a2dp.is_tws_mono_mode_on = a2dp.audio_is_tws_mono_mode_enable(); |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 2106 | aptx_encoder_cfg.dual_mono_cfg = (audio_aptx_dual_mono_config *)codec_info; |
| 2107 | is_configured = |
| 2108 | configure_aptx_enc_format(&aptx_encoder_cfg); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2109 | break; |
Manish Dewangan | 6a25263 | 2017-12-04 17:27:44 +0530 | [diff] [blame] | 2110 | #endif |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2111 | case CODEC_TYPE_AAC: |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2112 | ALOGD(" Received AAC encoder supported BT device"); |
Preetam Singh Ranawat | 3d78f52 | 2018-06-20 14:41:26 -0700 | [diff] [blame] | 2113 | bool is_aac_frame_ctl_enabled = |
| 2114 | property_get_bool("persist.vendor.bt.aac_frm_ctl.enabled", false); |
| 2115 | is_configured = is_aac_frame_ctl_enabled ? |
| 2116 | configure_aac_enc_format_v2((audio_aac_encoder_config_v2 *) codec_info) : |
| 2117 | configure_aac_enc_format((audio_aac_encoder_config *) codec_info); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2118 | break; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2119 | case CODEC_TYPE_CELT: |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 2120 | ALOGD(" Received CELT encoder supported BT device"); |
| 2121 | is_configured = |
| 2122 | configure_celt_enc_format((audio_celt_encoder_config *)codec_info); |
| 2123 | break; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2124 | case CODEC_TYPE_LDAC: |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2125 | ALOGD(" Received LDAC encoder supported BT device"); |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2126 | if (!instance_id || instance_id > MAX_INSTANCE_ID) |
| 2127 | instance_id = MAX_INSTANCE_ID; |
| 2128 | a2dp.abr_config.imc_instance = instance_id--; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2129 | is_configured = |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2130 | (configure_ldac_enc_format((audio_ldac_encoder_config *)codec_info) && |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2131 | configure_a2dp_source_decoder_format(CODEC_TYPE_LDAC)); |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2132 | break; |
Ramu Gottipati | 3e0d4c3 | 2018-11-05 15:57:28 +0530 | [diff] [blame] | 2133 | #ifndef LINUX_ENABLED //Temporarily disabled for LE, need to take care while doing VT FR |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2134 | case CODEC_TYPE_APTX_AD: |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 2135 | ALOGD(" Received APTX AD encoder supported BT device"); |
| 2136 | if (!instance_id || instance_id > MAX_INSTANCE_ID) |
| 2137 | instance_id = MAX_INSTANCE_ID; |
| 2138 | a2dp.abr_config.imc_instance = instance_id--; |
| 2139 | a2dp.abr_config.is_abr_enabled = true; // for APTX Adaptive ABR is Always on |
| 2140 | a2dp.is_aptx_adaptive = true; |
| 2141 | aptx_encoder_cfg.ad_cfg = (audio_aptx_ad_config *)codec_info; |
| 2142 | is_configured = |
| 2143 | (configure_aptx_enc_format(&aptx_encoder_cfg) && |
Ramu Gottipati | 0280968 | 2018-12-19 16:46:12 +0530 | [diff] [blame] | 2144 | configure_a2dp_source_decoder_format(MEDIA_FMT_APTX_AD)); |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 2145 | break; |
Ramu Gottipati | 3e0d4c3 | 2018-11-05 15:57:28 +0530 | [diff] [blame] | 2146 | #endif |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2147 | case CODEC_TYPE_PCM: |
| 2148 | ALOGD("Received PCM format for BT device"); |
| 2149 | a2dp.bt_encoder_format = CODEC_TYPE_PCM; |
| 2150 | is_configured = true; |
| 2151 | break; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2152 | default: |
| 2153 | ALOGD(" Received Unsupported encoder formar"); |
| 2154 | is_configured = false; |
| 2155 | break; |
| 2156 | } |
| 2157 | return is_configured; |
| 2158 | } |
| 2159 | |
| 2160 | int audio_extn_a2dp_start_playback() |
| 2161 | { |
| 2162 | int ret = 0; |
| 2163 | |
| 2164 | ALOGD("audio_extn_a2dp_start_playback start"); |
| 2165 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2166 | if(!(a2dp.bt_lib_source_handle && a2dp.audio_source_start |
| 2167 | && a2dp.audio_get_enc_config)) { |
| 2168 | ALOGE("a2dp handle is not identified, Ignoring start playback request"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2169 | return -ENOSYS; |
| 2170 | } |
| 2171 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2172 | if(a2dp.a2dp_source_suspended == true) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2173 | //session will be restarted after suspend completion |
| 2174 | ALOGD("a2dp start requested during suspend state"); |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 2175 | return -ENOSYS; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2176 | } |
| 2177 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2178 | if (!a2dp.a2dp_source_started && !a2dp.a2dp_source_total_active_session_requests) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2179 | ALOGD("calling BT module stream start"); |
| 2180 | /* This call indicates BT IPC lib to start playback */ |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2181 | ret = a2dp.audio_source_start(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2182 | ALOGE("BT controller start return = %d",ret); |
| 2183 | if (ret != 0 ) { |
| 2184 | ALOGE("BT controller start failed"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2185 | a2dp.a2dp_source_started = false; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2186 | } else { |
| 2187 | if(configure_a2dp_encoder_format() == true) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2188 | a2dp.a2dp_source_started = true; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2189 | ret = 0; |
| 2190 | ALOGD("Start playback successful to BT library"); |
| 2191 | } else { |
| 2192 | ALOGD(" unable to configure DSP encoder"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2193 | a2dp.a2dp_source_started = false; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2194 | ret = -ETIMEDOUT; |
| 2195 | } |
| 2196 | } |
| 2197 | } |
| 2198 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2199 | if (a2dp.a2dp_source_started) { |
| 2200 | a2dp.a2dp_source_total_active_session_requests++; |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 2201 | a2dp_check_and_set_scrambler(); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2202 | a2dp_set_backend_cfg(SOURCE); |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2203 | if (a2dp.abr_config.is_abr_enabled) |
| 2204 | start_abr(); |
Preetam Singh Ranawat | c2bef79 | 2017-11-22 10:59:15 +0530 | [diff] [blame] | 2205 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2206 | |
| 2207 | ALOGD("start A2DP playback total active sessions :%d", |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2208 | a2dp.a2dp_source_total_active_session_requests); |
| 2209 | return ret; |
| 2210 | } |
| 2211 | |
| 2212 | uint64_t audio_extn_a2dp_get_decoder_latency() |
| 2213 | { |
| 2214 | uint32_t latency = 0; |
| 2215 | |
| 2216 | switch(a2dp.bt_decoder_format) { |
| 2217 | case CODEC_TYPE_SBC: |
| 2218 | latency = DEFAULT_SINK_LATENCY_SBC; |
| 2219 | break; |
| 2220 | case CODEC_TYPE_AAC: |
| 2221 | latency = DEFAULT_SINK_LATENCY_AAC; |
| 2222 | break; |
| 2223 | default: |
| 2224 | latency = 200; |
| 2225 | ALOGD("No valid decoder defined, setting latency to %dms", latency); |
| 2226 | break; |
| 2227 | } |
| 2228 | return (uint64_t)latency; |
| 2229 | } |
| 2230 | |
| 2231 | bool a2dp_send_sink_setup_complete(void) { |
| 2232 | uint64_t system_latency = 0; |
| 2233 | bool is_complete = false; |
| 2234 | |
| 2235 | system_latency = audio_extn_a2dp_get_decoder_latency(); |
| 2236 | |
| 2237 | if (a2dp.audio_sink_session_setup_complete(system_latency) == 0) { |
| 2238 | is_complete = true; |
| 2239 | } |
| 2240 | return is_complete; |
| 2241 | } |
| 2242 | |
| 2243 | int audio_extn_a2dp_start_capture() |
| 2244 | { |
| 2245 | int ret = 0; |
| 2246 | |
| 2247 | ALOGD("audio_extn_a2dp_start_capture start"); |
| 2248 | |
| 2249 | if(!(a2dp.bt_lib_sink_handle && a2dp.audio_sink_start |
| 2250 | && a2dp.audio_get_dec_config)) { |
| 2251 | ALOGE("a2dp handle is not identified, Ignoring start capture request"); |
| 2252 | return -ENOSYS; |
| 2253 | } |
| 2254 | |
| 2255 | if (!a2dp.a2dp_sink_started && !a2dp.a2dp_sink_total_active_session_requests) { |
| 2256 | ALOGD("calling BT module stream start"); |
| 2257 | /* This call indicates BT IPC lib to start capture */ |
| 2258 | ret = a2dp.audio_sink_start(); |
| 2259 | ALOGE("BT controller start capture return = %d",ret); |
| 2260 | if (ret != 0 ) { |
| 2261 | ALOGE("BT controller start capture failed"); |
| 2262 | a2dp.a2dp_sink_started = false; |
| 2263 | } else { |
| 2264 | |
| 2265 | if(!audio_extn_a2dp_sink_is_ready()) { |
| 2266 | ALOGD("Wait for capture ready not successful"); |
| 2267 | ret = -ETIMEDOUT; |
| 2268 | } |
| 2269 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2270 | if(configure_a2dp_sink_decoder_format() == true) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2271 | a2dp.a2dp_sink_started = true; |
| 2272 | ret = 0; |
| 2273 | ALOGD("Start capture successful to BT library"); |
| 2274 | } else { |
| 2275 | ALOGD(" unable to configure DSP decoder"); |
| 2276 | a2dp.a2dp_sink_started = false; |
| 2277 | ret = -ETIMEDOUT; |
| 2278 | } |
| 2279 | |
| 2280 | if (!a2dp_send_sink_setup_complete()) { |
| 2281 | ALOGD("sink_setup_complete not successful"); |
| 2282 | ret = -ETIMEDOUT; |
| 2283 | } |
| 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | if (a2dp.a2dp_sink_started) { |
| 2288 | if (a2dp_set_backend_cfg(SINK) == true) { |
| 2289 | a2dp.a2dp_sink_total_active_session_requests++; |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | ALOGD("start A2DP sink total active sessions :%d", |
| 2294 | a2dp.a2dp_sink_total_active_session_requests); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2295 | return ret; |
| 2296 | } |
| 2297 | |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2298 | static void reset_a2dp_enc_config_params() |
| 2299 | { |
| 2300 | int ret =0; |
| 2301 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2302 | struct mixer_ctl *ctl_enc_config, *ctl_channel_mode; |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2303 | struct sbc_enc_cfg_t dummy_reset_config; |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 2304 | char* channel_mode; |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2305 | |
| 2306 | memset(&dummy_reset_config, 0x0, sizeof(struct sbc_enc_cfg_t)); |
| 2307 | ctl_enc_config = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 2308 | MIXER_ENC_CONFIG_BLOCK); |
| 2309 | if (!ctl_enc_config) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2310 | ALOGE(" ERROR a2dp encoder format mixer control not identified"); |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2311 | } else { |
| 2312 | ret = mixer_ctl_set_array(ctl_enc_config, (void *)&dummy_reset_config, |
| 2313 | sizeof(struct sbc_enc_cfg_t)); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2314 | a2dp.bt_encoder_format = MEDIA_FMT_NONE; |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2315 | } |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2316 | |
| 2317 | a2dp_set_bit_format(DEFAULT_ENCODER_BIT_FORMAT); |
| 2318 | |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 2319 | ctl_channel_mode = mixer_get_ctl_by_name(a2dp.adev->mixer,MIXER_FMT_TWS_CHANNEL_MODE); |
| 2320 | |
| 2321 | if (!ctl_channel_mode) { |
| 2322 | ALOGE("failed to get tws mixer ctl"); |
| 2323 | } else { |
| 2324 | channel_mode = "Two"; |
| 2325 | if (mixer_ctl_set_enum_by_string(ctl_channel_mode, channel_mode) != 0) { |
| 2326 | ALOGE("%s: Failed to set the channel mode = %s", __func__, channel_mode); |
| 2327 | } |
| 2328 | a2dp.is_tws_mono_mode_on = false; |
| 2329 | } |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2330 | } |
| 2331 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2332 | static int reset_a2dp_source_dec_config_params() |
Aniket Kumar Lata | e1220c3 | 2018-05-29 14:55:47 -0700 | [diff] [blame] | 2333 | { |
| 2334 | struct mixer_ctl *ctl_dec_data = NULL; |
| 2335 | struct abr_dec_cfg_t dummy_reset_cfg; |
| 2336 | int ret = 0; |
| 2337 | |
| 2338 | if (a2dp.abr_config.is_abr_enabled) { |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2339 | ctl_dec_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_SOURCE_DEC_CONFIG_BLOCK); |
Aniket Kumar Lata | e1220c3 | 2018-05-29 14:55:47 -0700 | [diff] [blame] | 2340 | if (!ctl_dec_data) { |
| 2341 | ALOGE("%s: ERROR A2DP decoder config mixer control not identifed", __func__); |
| 2342 | return -EINVAL; |
| 2343 | } |
| 2344 | memset(&dummy_reset_cfg, 0x0, sizeof(dummy_reset_cfg)); |
| 2345 | ret = mixer_ctl_set_array(ctl_dec_data, (void *)&dummy_reset_cfg, |
| 2346 | sizeof(dummy_reset_cfg)); |
| 2347 | if (ret != 0) { |
| 2348 | ALOGE("%s: Failed to set dummy decoder config", __func__); |
| 2349 | return ret; |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | return ret; |
| 2354 | } |
| 2355 | |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2356 | static void reset_a2dp_sink_dec_config_params() |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2357 | { |
| 2358 | int ret =0; |
| 2359 | |
| 2360 | struct mixer_ctl *ctl_dec_config, *ctrl_bit_format; |
| 2361 | struct aac_dec_cfg_t dummy_reset_config; |
| 2362 | |
| 2363 | memset(&dummy_reset_config, 0x0, sizeof(struct aac_dec_cfg_t)); |
| 2364 | ctl_dec_config = mixer_get_ctl_by_name(a2dp.adev->mixer, |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2365 | MIXER_SINK_DEC_CONFIG_BLOCK); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2366 | if (!ctl_dec_config) { |
| 2367 | ALOGE(" ERROR a2dp decoder format mixer control not identified"); |
| 2368 | } else { |
| 2369 | ret = mixer_ctl_set_array(ctl_dec_config, (void *)&dummy_reset_config, |
| 2370 | sizeof(struct aac_dec_cfg_t)); |
| 2371 | a2dp.bt_decoder_format = MEDIA_FMT_NONE; |
| 2372 | } |
| 2373 | ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer, |
| 2374 | MIXER_DEC_BIT_FORMAT); |
| 2375 | if (!ctrl_bit_format) { |
| 2376 | ALOGE(" ERROR bit format CONFIG data mixer control not identified"); |
| 2377 | } else { |
| 2378 | ret = mixer_ctl_set_enum_by_string(ctrl_bit_format, "S16_LE"); |
| 2379 | if (ret != 0) { |
| 2380 | ALOGE("%s: Failed to set bit format to decoder", __func__); |
| 2381 | } |
| 2382 | } |
| 2383 | } |
| 2384 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2385 | int audio_extn_a2dp_stop_playback() |
| 2386 | { |
| 2387 | int ret =0; |
| 2388 | |
| 2389 | ALOGV("audio_extn_a2dp_stop_playback start"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2390 | if(!(a2dp.bt_lib_source_handle && a2dp.audio_source_stop)) { |
| 2391 | ALOGE("a2dp handle is not identified, Ignoring stop request"); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2392 | return -ENOSYS; |
| 2393 | } |
| 2394 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2395 | if (a2dp.a2dp_source_total_active_session_requests > 0) |
| 2396 | a2dp.a2dp_source_total_active_session_requests--; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2397 | else |
| 2398 | ALOGE("%s: No active playback session requests on A2DP", __func__); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2399 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2400 | if ( a2dp.a2dp_source_started && !a2dp.a2dp_source_total_active_session_requests) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2401 | ALOGV("calling BT module stream stop"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2402 | ret = a2dp.audio_source_stop(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2403 | if (ret < 0) |
| 2404 | ALOGE("stop stream to BT IPC lib failed"); |
| 2405 | else |
| 2406 | ALOGV("stop steam to BT IPC lib successful"); |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2407 | reset_a2dp_enc_config_params(); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2408 | reset_a2dp_source_dec_config_params(); |
| 2409 | a2dp_reset_backend_cfg(SOURCE); |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2410 | if (a2dp.abr_config.is_abr_enabled && a2dp.abr_config.abr_started) |
| 2411 | stop_abr(); |
| 2412 | a2dp.abr_config.is_abr_enabled = false; |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2413 | a2dp.a2dp_source_started = false; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2414 | a2dp_reset_backend_cfg(SOURCE); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2415 | } |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2416 | if(!a2dp.a2dp_source_total_active_session_requests) |
| 2417 | a2dp.a2dp_source_started = false; |
| 2418 | ALOGD("Stop A2DP playback, total active sessions :%d", |
| 2419 | a2dp.a2dp_source_total_active_session_requests); |
| 2420 | return 0; |
| 2421 | } |
| 2422 | |
| 2423 | int audio_extn_a2dp_stop_capture() |
| 2424 | { |
| 2425 | int ret =0; |
| 2426 | |
| 2427 | ALOGV("audio_extn_a2dp_stop_capture start"); |
| 2428 | if(!(a2dp.bt_lib_sink_handle && a2dp.audio_sink_stop)) { |
| 2429 | ALOGE("a2dp handle is not identified, Ignoring stop request"); |
| 2430 | return -ENOSYS; |
| 2431 | } |
| 2432 | |
| 2433 | if (a2dp.a2dp_sink_total_active_session_requests > 0) |
| 2434 | a2dp.a2dp_sink_total_active_session_requests--; |
| 2435 | |
| 2436 | if ( a2dp.a2dp_sink_started && !a2dp.a2dp_sink_total_active_session_requests) { |
| 2437 | ALOGV("calling BT module stream stop"); |
| 2438 | ret = a2dp.audio_sink_stop(); |
| 2439 | if (ret < 0) |
| 2440 | ALOGE("stop stream to BT IPC lib failed"); |
| 2441 | else |
| 2442 | ALOGV("stop steam to BT IPC lib successful"); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2443 | reset_a2dp_sink_dec_config_params(); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2444 | a2dp_reset_backend_cfg(SINK); |
| 2445 | } |
| 2446 | if(!a2dp.a2dp_sink_total_active_session_requests) |
| 2447 | a2dp.a2dp_source_started = false; |
| 2448 | ALOGD("Stop A2DP capture, total active sessions :%d", |
| 2449 | a2dp.a2dp_sink_total_active_session_requests); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2450 | return 0; |
| 2451 | } |
| 2452 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2453 | int audio_extn_a2dp_set_parameters(struct str_parms *parms, bool *reconfig) |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2454 | { |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2455 | int ret = 0, val, status = 0; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2456 | char value[32]={0}; |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 2457 | struct audio_usecase *uc_info; |
| 2458 | struct listnode *node; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2459 | |
| 2460 | if(a2dp.is_a2dp_offload_supported == false) { |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2461 | ALOGV("no supported encoders identified,ignoring a2dp setparam"); |
| 2462 | status = -EINVAL; |
| 2463 | goto param_handled; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, |
| 2467 | sizeof(value)); |
Zhou Song | 681350a | 2017-10-19 16:28:42 +0800 | [diff] [blame] | 2468 | if (ret >= 0) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2469 | val = atoi(value); |
Zhou Song | 681350a | 2017-10-19 16:28:42 +0800 | [diff] [blame] | 2470 | if (audio_is_a2dp_out_device(val)) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2471 | ALOGV("Received device connect request for A2DP source"); |
| 2472 | open_a2dp_source(); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2473 | } |
| 2474 | goto param_handled; |
| 2475 | } |
| 2476 | |
| 2477 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, |
| 2478 | sizeof(value)); |
| 2479 | |
Zhou Song | 681350a | 2017-10-19 16:28:42 +0800 | [diff] [blame] | 2480 | if (ret >= 0) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2481 | val = atoi(value); |
Zhou Song | 681350a | 2017-10-19 16:28:42 +0800 | [diff] [blame] | 2482 | if (audio_is_a2dp_out_device(val)) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2483 | ALOGV("Received source device dis- connect request"); |
Samyak Jain | 4828f4c | 2018-08-24 16:31:06 +0530 | [diff] [blame] | 2484 | close_a2dp_output(); |
kunleiz | 4a1fad6 | 2018-02-08 18:00:16 +0800 | [diff] [blame] | 2485 | reset_a2dp_enc_config_params(); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2486 | reset_a2dp_source_dec_config_params(); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2487 | a2dp_reset_backend_cfg(SOURCE); |
| 2488 | } else if (audio_is_a2dp_in_device(val)) { |
| 2489 | ALOGV("Received sink device dis- connect request"); |
| 2490 | close_a2dp_input(); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2491 | reset_a2dp_sink_dec_config_params(); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2492 | a2dp_reset_backend_cfg(SINK); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2493 | } |
| 2494 | goto param_handled; |
| 2495 | } |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2496 | #ifndef LINUX_ENABLED |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 2497 | ret = str_parms_get_str(parms, "TwsChannelConfig", value, sizeof(value)); |
| 2498 | if (ret>=0) { |
| 2499 | ALOGD("Setting tws channel mode to %s",value); |
| 2500 | if(!(strncmp(value,"mono",strlen(value)))) |
| 2501 | a2dp.is_tws_mono_mode_on = true; |
| 2502 | else if(!(strncmp(value,"dual-mono",strlen(value)))) |
| 2503 | a2dp.is_tws_mono_mode_on = false; |
| 2504 | audio_a2dp_update_tws_channel_mode(); |
| 2505 | goto param_handled; |
| 2506 | } |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2507 | #endif |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2508 | ret = str_parms_get_str(parms, "A2dpSuspended", value, sizeof(value)); |
| 2509 | if (ret >= 0) { |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2510 | if (a2dp.bt_lib_source_handle) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2511 | if ((!strncmp(value,"true",sizeof(value)))) { |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2512 | if (a2dp.a2dp_source_suspended) { |
| 2513 | ALOGD("%s: A2DP is already suspended", __func__); |
| 2514 | goto param_handled; |
| 2515 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2516 | ALOGD("Setting a2dp to suspend state"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2517 | a2dp.a2dp_source_suspended = true; |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2518 | if (a2dp.bt_state_source == A2DP_STATE_DISCONNECTED) |
yidongh | 7203cca | 2018-09-19 16:12:25 +0800 | [diff] [blame] | 2519 | goto param_handled; |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 2520 | list_for_each(node, &a2dp.adev->usecase_list) { |
| 2521 | uc_info = node_to_item(node, struct audio_usecase, list); |
Zhou Song | c66eb7e | 2017-08-08 18:29:07 +0800 | [diff] [blame] | 2522 | if (uc_info->type == PCM_PLAYBACK && |
| 2523 | (uc_info->stream.out->devices & AUDIO_DEVICE_OUT_ALL_A2DP)) { |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 2524 | pthread_mutex_unlock(&a2dp.adev->lock); |
| 2525 | check_a2dp_restore(a2dp.adev, uc_info->stream.out, false); |
| 2526 | pthread_mutex_lock(&a2dp.adev->lock); |
| 2527 | } |
| 2528 | } |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2529 | reset_a2dp_enc_config_params(); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2530 | reset_a2dp_source_dec_config_params(); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2531 | if(a2dp.audio_source_suspend) |
| 2532 | a2dp.audio_source_suspend(); |
| 2533 | } else if (a2dp.a2dp_source_suspended == true) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2534 | ALOGD("Resetting a2dp suspend state"); |
Zhou Song | 10617ed | 2017-05-26 13:28:48 +0800 | [diff] [blame] | 2535 | struct audio_usecase *uc_info; |
| 2536 | struct listnode *node; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2537 | if(a2dp.clear_source_a2dpsuspend_flag) |
| 2538 | a2dp.clear_source_a2dpsuspend_flag(); |
| 2539 | a2dp.a2dp_source_suspended = false; |
Naresh Tanniru | 649871a | 2016-11-04 18:08:32 +0530 | [diff] [blame] | 2540 | /* |
| 2541 | * It is possible that before suspend,a2dp sessions can be active |
| 2542 | * for example during music + voice activation concurrency |
| 2543 | * a2dp suspend will be called & BT will change to sco mode |
| 2544 | * though music is paused as a part of voice activation |
| 2545 | * compress session close happens only after pause timeout(10secs) |
| 2546 | * so if resume request comes before pause timeout as a2dp session |
| 2547 | * is already active IPC start will not be called from APM/audio_hw |
| 2548 | * Fix is to call a2dp start for IPC library post suspend |
| 2549 | * based on number of active session count |
| 2550 | */ |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2551 | if (a2dp.a2dp_source_total_active_session_requests > 0) { |
Naresh Tanniru | 649871a | 2016-11-04 18:08:32 +0530 | [diff] [blame] | 2552 | ALOGD(" Calling IPC lib start post suspend state"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2553 | if(a2dp.audio_source_start) { |
| 2554 | ret = a2dp.audio_source_start(); |
Naresh Tanniru | 649871a | 2016-11-04 18:08:32 +0530 | [diff] [blame] | 2555 | if (ret != 0) { |
| 2556 | ALOGE("BT controller start failed"); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2557 | a2dp.a2dp_source_started = false; |
Naresh Tanniru | 649871a | 2016-11-04 18:08:32 +0530 | [diff] [blame] | 2558 | } |
| 2559 | } |
| 2560 | } |
Zhou Song | 10617ed | 2017-05-26 13:28:48 +0800 | [diff] [blame] | 2561 | list_for_each(node, &a2dp.adev->usecase_list) { |
| 2562 | uc_info = node_to_item(node, struct audio_usecase, list); |
Zhou Song | c66eb7e | 2017-08-08 18:29:07 +0800 | [diff] [blame] | 2563 | if (uc_info->type == PCM_PLAYBACK && |
| 2564 | (uc_info->stream.out->devices & AUDIO_DEVICE_OUT_ALL_A2DP)) { |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 2565 | pthread_mutex_unlock(&a2dp.adev->lock); |
| 2566 | check_a2dp_restore(a2dp.adev, uc_info->stream.out, true); |
| 2567 | pthread_mutex_lock(&a2dp.adev->lock); |
| 2568 | } |
Zhou Song | 10617ed | 2017-05-26 13:28:48 +0800 | [diff] [blame] | 2569 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2570 | } |
| 2571 | } |
| 2572 | goto param_handled; |
| 2573 | } |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2574 | |
| 2575 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_RECONFIG_A2DP, value, |
| 2576 | sizeof(value)); |
| 2577 | if (ret >= 0) { |
| 2578 | if (a2dp.is_a2dp_offload_supported && |
| 2579 | a2dp.bt_state_source != A2DP_STATE_DISCONNECTED) { |
| 2580 | *reconfig = true; |
| 2581 | } |
| 2582 | goto param_handled; |
| 2583 | } |
| 2584 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2585 | param_handled: |
| 2586 | ALOGV("end of a2dp setparam"); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2587 | return status; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2588 | } |
| 2589 | |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 2590 | void audio_extn_a2dp_set_handoff_mode(bool is_on) |
| 2591 | { |
| 2592 | a2dp.is_handoff_in_progress = is_on; |
| 2593 | } |
| 2594 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2595 | bool audio_extn_a2dp_is_force_device_switch() |
| 2596 | { |
| 2597 | //During encoder reconfiguration mode, force a2dp device switch |
Ashish Jain | c597d10 | 2016-12-12 10:31:34 +0530 | [diff] [blame] | 2598 | // Or if a2dp device is selected but earlier start failed ( as a2dp |
| 2599 | // was suspended, force retry. |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2600 | return a2dp.is_handoff_in_progress || !a2dp.a2dp_source_started; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2601 | } |
| 2602 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2603 | void audio_extn_a2dp_get_enc_sample_rate(int *sample_rate) |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 2604 | { |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 2605 | *sample_rate = a2dp.enc_sampling_rate; |
| 2606 | } |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 2607 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2608 | void audio_extn_a2dp_get_dec_sample_rate(int *sample_rate) |
| 2609 | { |
| 2610 | *sample_rate = a2dp.dec_sampling_rate; |
| 2611 | } |
| 2612 | |
| 2613 | bool audio_extn_a2dp_source_is_ready() |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 2614 | { |
| 2615 | bool ret = false; |
| 2616 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2617 | if (a2dp.a2dp_source_suspended) |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 2618 | return ret; |
| 2619 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2620 | if ((a2dp.bt_state_source != A2DP_STATE_DISCONNECTED) && |
Aniket Kumar Lata | 901bcb8 | 2017-03-10 15:42:46 -0800 | [diff] [blame] | 2621 | (a2dp.is_a2dp_offload_supported) && |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2622 | (a2dp.audio_source_check_a2dp_ready)) |
| 2623 | ret = a2dp.audio_source_check_a2dp_ready(); |
Preetam Singh Ranawat | a1849ba | 2017-02-06 14:10:11 +0530 | [diff] [blame] | 2624 | return ret; |
| 2625 | } |
| 2626 | |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2627 | bool audio_extn_a2dp_sink_is_ready() |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 2628 | { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2629 | bool ret = false; |
| 2630 | |
| 2631 | if ((a2dp.bt_state_sink != A2DP_STATE_DISCONNECTED) && |
| 2632 | (a2dp.is_a2dp_offload_supported) && |
| 2633 | (a2dp.audio_sink_check_a2dp_ready)) |
| 2634 | ret = a2dp.audio_sink_check_a2dp_ready(); |
| 2635 | return ret; |
| 2636 | } |
| 2637 | |
| 2638 | bool audio_extn_a2dp_source_is_suspended() |
| 2639 | { |
| 2640 | return a2dp.a2dp_source_suspended; |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 2641 | } |
| 2642 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2643 | void audio_extn_a2dp_init (void *adev) |
| 2644 | { |
| 2645 | a2dp.adev = (struct audio_device*)adev; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2646 | a2dp.bt_lib_source_handle = NULL; |
| 2647 | a2dp.a2dp_source_started = false; |
| 2648 | a2dp.bt_state_source = A2DP_STATE_DISCONNECTED; |
| 2649 | a2dp.a2dp_source_total_active_session_requests = 0; |
| 2650 | a2dp.a2dp_source_suspended = false; |
| 2651 | a2dp.bt_encoder_format = CODEC_TYPE_INVALID; |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 2652 | a2dp.enc_sampling_rate = 48000; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2653 | a2dp.is_handoff_in_progress = false; |
Aniket Kumar Lata | 53e54b1 | 2017-08-24 17:45:38 -0700 | [diff] [blame] | 2654 | a2dp.is_aptx_dual_mono_supported = false; |
Sharad Sangle | 95d451b | 2018-06-19 12:24:20 +0530 | [diff] [blame] | 2655 | a2dp.is_aptx_adaptive = false; |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 2656 | a2dp.abr_config.is_abr_enabled = false; |
| 2657 | a2dp.abr_config.abr_started = false; |
| 2658 | a2dp.abr_config.imc_instance = 0; |
| 2659 | a2dp.abr_config.abr_tx_handle = NULL; |
Manisha Agarwal | a51768b | 2018-11-01 16:30:52 +0530 | [diff] [blame] | 2660 | a2dp.is_tws_mono_mode_on = false; |
kunleiz | 5a12726 | 2017-09-08 14:47:48 +0800 | [diff] [blame] | 2661 | reset_a2dp_enc_config_params(); |
Surendar Karka | 2febd45 | 2018-12-13 17:56:43 +0530 | [diff] [blame] | 2662 | reset_a2dp_source_dec_config_params(); |
| 2663 | reset_a2dp_sink_dec_config_params(); |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2664 | |
| 2665 | a2dp.bt_lib_sink_handle = NULL; |
| 2666 | a2dp.a2dp_sink_started = false; |
| 2667 | a2dp.bt_state_sink = A2DP_STATE_DISCONNECTED; |
| 2668 | a2dp.a2dp_sink_total_active_session_requests = 0; |
| 2669 | open_a2dp_sink(); |
| 2670 | |
| 2671 | a2dp.is_a2dp_offload_supported = false; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2672 | update_offload_codec_capabilities(); |
| 2673 | } |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2674 | |
| 2675 | uint32_t audio_extn_a2dp_get_encoder_latency() |
| 2676 | { |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2677 | uint32_t latency = 0; |
| 2678 | int avsync_runtime_prop = 0; |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2679 | int sbc_offset = 0, aptx_offset = 0, aptxhd_offset = 0, |
| 2680 | aac_offset = 0, celt_offset = 0, ldac_offset = 0; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2681 | char value[PROPERTY_VALUE_MAX]; |
| 2682 | |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2683 | memset(value, '\0', sizeof(char)*PROPERTY_VALUE_MAX); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2684 | avsync_runtime_prop = property_get(SYSPROP_A2DP_CODEC_LATENCIES, value, NULL); |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2685 | if (avsync_runtime_prop > 0) { |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2686 | if (sscanf(value, "%d/%d/%d/%d/%d%d", |
| 2687 | &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] | 2688 | ALOGI("Failed to parse avsync offset params from '%s'.", value); |
| 2689 | avsync_runtime_prop = 0; |
| 2690 | } |
| 2691 | } |
| 2692 | |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 2693 | uint32_t slatency = 0; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2694 | if (a2dp.audio_sink_get_a2dp_latency && a2dp.bt_state_source != A2DP_STATE_DISCONNECTED) { |
| 2695 | slatency = a2dp.audio_sink_get_a2dp_latency(); |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 2696 | } |
| 2697 | |
Aniket Kumar Lata | faaffde | 2017-03-22 19:18:15 -0700 | [diff] [blame] | 2698 | switch(a2dp.bt_encoder_format) { |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2699 | case CODEC_TYPE_SBC: |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 2700 | latency = (avsync_runtime_prop > 0) ? sbc_offset : ENCODER_LATENCY_SBC; |
| 2701 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_SBC : slatency; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2702 | break; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2703 | case CODEC_TYPE_APTX: |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 2704 | latency = (avsync_runtime_prop > 0) ? aptx_offset : ENCODER_LATENCY_APTX; |
| 2705 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_APTX : slatency; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2706 | break; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2707 | case CODEC_TYPE_APTX_HD: |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 2708 | latency = (avsync_runtime_prop > 0) ? aptxhd_offset : ENCODER_LATENCY_APTX_HD; |
| 2709 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_APTX_HD : slatency; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2710 | break; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2711 | case CODEC_TYPE_AAC: |
yidongh | 0515e04 | 2017-07-06 15:00:34 +0800 | [diff] [blame] | 2712 | latency = (avsync_runtime_prop > 0) ? aac_offset : ENCODER_LATENCY_AAC; |
| 2713 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_AAC : slatency; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2714 | break; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2715 | case CODEC_TYPE_CELT: |
Preetam Singh Ranawat | 0d645ea | 2017-08-07 18:12:07 +0530 | [diff] [blame] | 2716 | latency = (avsync_runtime_prop > 0) ? celt_offset : ENCODER_LATENCY_CELT; |
| 2717 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_CELT : slatency; |
| 2718 | break; |
Florian Pfister | 1a84f31 | 2018-07-19 14:38:18 +0200 | [diff] [blame] | 2719 | case CODEC_TYPE_LDAC: |
Preetam Singh Ranawat | d058a3d | 2017-10-25 17:31:37 +0530 | [diff] [blame] | 2720 | latency = (avsync_runtime_prop > 0) ? ldac_offset : ENCODER_LATENCY_LDAC; |
| 2721 | latency += (slatency <= 0) ? DEFAULT_SINK_LATENCY_LDAC : slatency; |
| 2722 | break; |
Ramu Gottipati | b729cf8 | 2018-12-20 15:36:46 +0530 | [diff] [blame] | 2723 | case CODEC_TYPE_APTX_AD: // for aptx adaptive the latency depends on the mode (HQ/LL) and |
Sharad Sangle | e378afe | 2018-09-03 20:04:17 +0530 | [diff] [blame] | 2724 | latency = slatency; // BT IPC will take care of accomodating the mode factor and return latency |
Preetam Singh Ranawat | 79c514e | 2018-12-16 18:49:34 +0530 | [diff] [blame] | 2725 | break; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2726 | case CODEC_TYPE_PCM: |
| 2727 | latency = ENCODER_LATENCY_PCM; |
| 2728 | latency += DEFAULT_SINK_LATENCY_PCM; |
| 2729 | break; |
Aniket Kumar Lata | d5972fa | 2017-02-08 13:53:48 -0800 | [diff] [blame] | 2730 | default: |
| 2731 | latency = 200; |
| 2732 | break; |
| 2733 | } |
| 2734 | return latency; |
| 2735 | } |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2736 | |
| 2737 | int audio_extn_a2dp_get_parameters(struct str_parms *query, |
| 2738 | struct str_parms *reply) |
| 2739 | { |
| 2740 | int ret, val = 0; |
| 2741 | char value[32]={0}; |
| 2742 | |
| 2743 | ret = str_parms_get_str(query, AUDIO_PARAMETER_A2DP_RECONFIG_SUPPORTED, |
| 2744 | value, sizeof(value)); |
| 2745 | if (ret >= 0) { |
| 2746 | val = a2dp.is_a2dp_offload_supported; |
| 2747 | str_parms_add_int(reply, AUDIO_PARAMETER_A2DP_RECONFIG_SUPPORTED, val); |
| 2748 | ALOGV("%s: called ... isReconfigA2dpSupported %d", __func__, val); |
| 2749 | } |
| 2750 | |
| 2751 | return 0; |
| 2752 | } |
| 2753 | #endif // A2DP_OFFLOAD_ENABLED |