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