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