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