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