Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1 | /* |
Susan Wang | 6dd1309 | 2021-01-25 10:27:11 -0500 | [diff] [blame] | 2 | * Copyright (c) 2013-2021, The Linux Foundation. All rights reserved. |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright (C) 2013 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 18 | * |
| 19 | * This file was modified by DTS, Inc. The portions of the |
| 20 | * code modified by DTS, Inc are copyrighted and |
| 21 | * licensed separately, as follows: |
| 22 | * |
| 23 | * (C) 2014 DTS, Inc. |
| 24 | * |
| 25 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 26 | * you may not use this file except in compliance with the License. |
| 27 | * You may obtain a copy of the License at |
| 28 | * |
| 29 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 30 | * |
| 31 | * Unless required by applicable law or agreed to in writing, software |
| 32 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 34 | * See the License for the specific language governing permissions and |
| 35 | * limitations under the License. |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 36 | */ |
| 37 | |
Xu,Baochu | 235aec6 | 2022-02-14 10:20:44 +0800 | [diff] [blame] | 38 | /* |
| 39 | * Changes from Qualcomm Innovation Center are provided under the following license: |
| 40 | * |
Subhadra Jagadeesan | 63a1e83 | 2023-01-13 11:26:38 +0530 | [diff] [blame] | 41 | * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. |
Xu,Baochu | 235aec6 | 2022-02-14 10:20:44 +0800 | [diff] [blame] | 42 | * |
| 43 | * Redistribution and use in source and binary forms, with or without |
| 44 | * modification, are permitted (subject to the limitations in the |
| 45 | * disclaimer below) provided that the following conditions are met: |
| 46 | * |
| 47 | * * Redistributions of source code must retain the above copyright |
| 48 | * notice, this list of conditions and the following disclaimer. |
| 49 | * |
| 50 | * * Redistributions in binary form must reproduce the above |
| 51 | * copyright notice, this list of conditions and the following |
| 52 | * disclaimer in the documentation and/or other materials provided |
| 53 | * with the distribution. |
| 54 | * |
| 55 | * * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its |
| 56 | * contributors may be used to endorse or promote products derived |
| 57 | * from this software without specific prior written permission. |
| 58 | * |
| 59 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE |
| 60 | * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT |
| 61 | * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
| 62 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 63 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 64 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 65 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 66 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 67 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 68 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 69 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 70 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 71 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 72 | */ |
| 73 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 74 | #define LOG_TAG "audio_hw_extn" |
| 75 | /*#define LOG_NDEBUG 0*/ |
| 76 | #define LOG_NDDEBUG 0 |
| 77 | |
| 78 | #include <stdlib.h> |
| 79 | #include <errno.h> |
Sudheer Papothi | 390bcf3 | 2014-12-04 01:25:17 +0530 | [diff] [blame] | 80 | #include <dlfcn.h> |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 81 | #include <fcntl.h> |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 82 | #include <cutils/properties.h> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 83 | #include <log/log.h> |
LuK1337 | 994b076 | 2021-05-28 08:01:40 +0200 | [diff] [blame] | 84 | #include <pthread.h> |
Vinay Verma | addfa4a | 2018-04-29 14:03:38 +0530 | [diff] [blame] | 85 | #include <unistd.h> |
Weiyin Jiang | 29c08a4 | 2019-04-30 17:11:10 +0800 | [diff] [blame] | 86 | #include <sched.h> |
Dhanalakshmi Siddani | 999d564 | 2019-03-22 15:27:44 +0530 | [diff] [blame] | 87 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 88 | #include "audio_hw.h" |
| 89 | #include "audio_extn.h" |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 90 | #include "voice_extn.h" |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 91 | #include "audio_defs.h" |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 92 | #include "platform.h" |
| 93 | #include "platform_api.h" |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 94 | #include "edid.h" |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 95 | #include "sound/compress_params.h" |
| 96 | |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 97 | #ifdef AUDIO_GKI_ENABLED |
| 98 | #include "sound/audio_compressed_formats.h" |
| 99 | #endif |
| 100 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 101 | #ifdef DYNAMIC_LOG_ENABLED |
| 102 | #include <log_xml_parser.h> |
| 103 | #define LOG_MASK HAL_MOD_FILE_AUDIO_EXTN |
| 104 | #include <log_utils.h> |
| 105 | #endif |
| 106 | |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 107 | #ifdef LINUX_ENABLED |
| 108 | #include "audio_stub.h" |
| 109 | #endif |
| 110 | |
Damir Didjusto | f1d46c7 | 2013-11-06 17:59:04 -0800 | [diff] [blame] | 111 | #define MAX_SLEEP_RETRY 100 |
| 112 | #define WIFI_INIT_WAIT_SLEEP 50 |
Surendar Karka | f51b584 | 2018-04-26 11:28:38 +0530 | [diff] [blame] | 113 | #define MAX_NUM_CHANNELS 8 |
| 114 | #define Q14_GAIN_UNITY 0x4000 |
Damir Didjusto | f1d46c7 | 2013-11-06 17:59:04 -0800 | [diff] [blame] | 115 | |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 116 | static int vendor_enhanced_info = 0; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 117 | static bool is_compress_meta_data_enabled = false; |
| 118 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 119 | struct snd_card_split cur_snd_card_split = { |
| 120 | .device = {0}, |
| 121 | .snd_card = {0}, |
| 122 | .form_factor = {0}, |
Sujin Panicker | b904fbe | 2019-04-04 13:28:07 +0530 | [diff] [blame] | 123 | .variant = {0}, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | struct snd_card_split *audio_extn_get_snd_card_split() |
| 127 | { |
| 128 | return &cur_snd_card_split; |
| 129 | } |
| 130 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 131 | void fm_set_parameters(struct audio_device *adev, |
| 132 | struct str_parms *parms); |
| 133 | void fm_get_parameters(struct str_parms *query, struct str_parms *reply); |
| 134 | |
| 135 | void keep_alive_init(struct audio_device *adev); |
| 136 | void keep_alive_deinit(); |
| 137 | void keep_alive_start(ka_mode_t ka_mode); |
| 138 | void keep_alive_stop(ka_mode_t ka_mode); |
| 139 | int keep_alive_set_parameters(struct audio_device *adev, |
| 140 | struct str_parms *parms); |
| 141 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 142 | bool cin_applicable_stream(struct stream_in *in); |
Dhananjay Kumar | 7dbe356 | 2019-08-30 05:49:33 +0530 | [diff] [blame] | 143 | bool cin_attached_usecase(struct stream_in *in); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 144 | bool cin_format_supported(audio_format_t format); |
Dhananjay Kumar | 7dbe356 | 2019-08-30 05:49:33 +0530 | [diff] [blame] | 145 | int cin_acquire_usecase(struct stream_in *in); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 146 | size_t cin_get_buffer_size(struct stream_in *in); |
Manish Dewangan | 46e0798 | 2018-12-13 18:18:59 +0530 | [diff] [blame] | 147 | int cin_open_input_stream(struct stream_in *in); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 148 | void cin_stop_input_stream(struct stream_in *in); |
| 149 | void cin_close_input_stream(struct stream_in *in); |
Manish Dewangan | 46e0798 | 2018-12-13 18:18:59 +0530 | [diff] [blame] | 150 | void cin_free_input_stream_resources(struct stream_in *in); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 151 | int cin_read(struct stream_in *in, void *buffer, |
| 152 | size_t bytes, size_t *bytes_read); |
Deeraj Soman | 1423092 | 2019-01-30 16:39:30 +0530 | [diff] [blame] | 153 | int cin_configure_input_stream(struct stream_in *in, struct audio_config *in_config); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 154 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 155 | void audio_extn_set_snd_card_split(const char* in_snd_card_name) |
| 156 | { |
| 157 | /* sound card name follows below mentioned convention |
| 158 | <target name>-<sound card name>-<form factor>-snd-card |
| 159 | parse target name, sound card name and form factor |
| 160 | */ |
Weiyin Jiang | 2995f66 | 2019-04-17 14:25:12 +0800 | [diff] [blame] | 161 | char *snd_card_name = NULL; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 162 | char *tmp = NULL; |
| 163 | char *device = NULL; |
| 164 | char *snd_card = NULL; |
| 165 | char *form_factor = NULL; |
Sujin Panicker | b904fbe | 2019-04-04 13:28:07 +0530 | [diff] [blame] | 166 | char *variant = NULL; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 167 | |
| 168 | if (in_snd_card_name == NULL) { |
| 169 | ALOGE("%s: snd_card_name passed is NULL", __func__); |
| 170 | goto on_error; |
| 171 | } |
Weiyin Jiang | 2995f66 | 2019-04-17 14:25:12 +0800 | [diff] [blame] | 172 | snd_card_name = strdup(in_snd_card_name); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 173 | |
| 174 | device = strtok_r(snd_card_name, "-", &tmp); |
| 175 | if (device == NULL) { |
| 176 | ALOGE("%s: called on invalid snd card name", __func__); |
| 177 | goto on_error; |
| 178 | } |
| 179 | strlcpy(cur_snd_card_split.device, device, HW_INFO_ARRAY_MAX_SIZE); |
| 180 | |
| 181 | snd_card = strtok_r(NULL, "-", &tmp); |
| 182 | if (snd_card == NULL) { |
| 183 | ALOGE("%s: called on invalid snd card name", __func__); |
| 184 | goto on_error; |
| 185 | } |
| 186 | strlcpy(cur_snd_card_split.snd_card, snd_card, HW_INFO_ARRAY_MAX_SIZE); |
| 187 | |
| 188 | form_factor = strtok_r(NULL, "-", &tmp); |
| 189 | if (form_factor == NULL) { |
| 190 | ALOGE("%s: called on invalid snd card name", __func__); |
| 191 | goto on_error; |
| 192 | } |
| 193 | strlcpy(cur_snd_card_split.form_factor, form_factor, HW_INFO_ARRAY_MAX_SIZE); |
| 194 | |
Sujin Panicker | b904fbe | 2019-04-04 13:28:07 +0530 | [diff] [blame] | 195 | variant = strtok_r(NULL, "-", &tmp); |
| 196 | if (variant != NULL) { |
| 197 | strlcpy(cur_snd_card_split.variant, variant, HW_INFO_ARRAY_MAX_SIZE); |
| 198 | } |
| 199 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 200 | ALOGI("%s: snd_card_name(%s) device(%s) snd_card(%s) form_factor(%s)", |
| 201 | __func__, in_snd_card_name, device, snd_card, form_factor); |
| 202 | |
| 203 | on_error: |
| 204 | if (snd_card_name) |
| 205 | free(snd_card_name); |
| 206 | } |
| 207 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 208 | struct audio_extn_module { |
| 209 | bool anc_enabled; |
| 210 | bool aanc_enabled; |
Jitendra Singh Naruka | 9a6a8d4 | 2014-02-10 20:07:12 -0800 | [diff] [blame] | 211 | bool custom_stereo_enabled; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 212 | uint32_t proxy_channel_num; |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 213 | bool hpx_enabled; |
Banajit Goswami | 20cdd21 | 2015-09-11 01:11:30 -0700 | [diff] [blame] | 214 | bool vbat_enabled; |
Aditya Bavanari | 9b58902 | 2018-09-20 08:47:55 +0530 | [diff] [blame] | 215 | bool bcl_enabled; |
Venkata Narendra Kumar Gutta | 4bd09d0 | 2016-01-29 15:31:04 +0530 | [diff] [blame] | 216 | bool hifi_audio_enabled; |
Srinivas Julakanti | 1ca769a | 2017-01-04 23:18:08 -0800 | [diff] [blame] | 217 | bool ras_enabled; |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 218 | struct aptx_dec_bt_addr addr; |
Aalique Grahame | 404a15e | 2017-05-18 11:28:27 -0700 | [diff] [blame] | 219 | struct audio_device *adev; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 220 | }; |
| 221 | |
Dhanalakshmi Siddani | 0b1488e | 2016-09-06 12:58:42 +0530 | [diff] [blame] | 222 | static struct audio_extn_module aextnmod; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 223 | static bool audio_extn_fm_power_opt_enabled = false; |
| 224 | static bool audio_extn_keep_alive_enabled = false; |
| 225 | static bool audio_extn_hifi_audio_enabled = false; |
| 226 | static bool audio_extn_ras_feature_enabled = false; |
| 227 | static bool audio_extn_kpi_optimize_feature_enabled = false; |
| 228 | static bool audio_extn_display_port_feature_enabled = false; |
| 229 | static bool audio_extn_fluence_feature_enabled = false; |
| 230 | static bool audio_extn_custom_stereo_feature_enabled = false; |
| 231 | static bool audio_extn_anc_headset_feature_enabled = false; |
| 232 | static bool audio_extn_vbat_enabled = false; |
Sujin Panicker | b904fbe | 2019-04-04 13:28:07 +0530 | [diff] [blame] | 233 | static bool audio_extn_wsa_enabled = false; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 234 | static bool audio_extn_record_play_concurrency_enabled = false; |
| 235 | static bool audio_extn_hdmi_passthru_enabled = false; |
| 236 | static bool audio_extn_concurrent_capture_enabled = false; |
| 237 | static bool audio_extn_compress_in_enabled = false; |
| 238 | static bool audio_extn_battery_listener_enabled = false; |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 239 | static bool audio_extn_maxx_audio_enabled = false; |
vivek mehta | ba5ed15 | 2019-05-03 17:28:25 -0700 | [diff] [blame] | 240 | static bool audio_extn_audiozoom_enabled = false; |
Ramlal Karra | ab51d04 | 2019-08-08 19:02:35 +0530 | [diff] [blame] | 241 | static bool audio_extn_hifi_filter_enabled = false; |
Krishna Kishor Jha | 0f4d848 | 2022-02-18 10:56:05 +0530 | [diff] [blame] | 242 | static bool audio_extn_concurrent_pcm_record_enabled = false; |
Kogara Naveen Kumar | c575823 | 2022-11-07 20:25:40 +0530 | [diff] [blame] | 243 | static bool audio_extn_concurrent_low_latency_pcm_record_enabled = false; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 244 | |
Sudheer Papothi | d63caef | 2018-05-15 00:41:52 +0530 | [diff] [blame] | 245 | #define AUDIO_PARAMETER_KEY_AANC_NOISE_LEVEL "aanc_noise_level" |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 246 | #define AUDIO_PARAMETER_KEY_ANC "anc_enabled" |
| 247 | #define AUDIO_PARAMETER_KEY_WFD "wfd_channel_cap" |
| 248 | #define AUDIO_PARAMETER_CAN_OPEN_PROXY "can_open_proxy" |
Jitendra Singh Naruka | 9a6a8d4 | 2014-02-10 20:07:12 -0800 | [diff] [blame] | 249 | #define AUDIO_PARAMETER_CUSTOM_STEREO "stereo_as_dual_mono" |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 250 | /* Query offload playback instances count */ |
| 251 | #define AUDIO_PARAMETER_OFFLOAD_NUM_ACTIVE "offload_num_active" |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 252 | #define AUDIO_PARAMETER_HPX "HPX" |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 253 | #define AUDIO_PARAMETER_APTX_DEC_BT_ADDR "bt_addr" |
Jitendra Singh Naruka | 9a6a8d4 | 2014-02-10 20:07:12 -0800 | [diff] [blame] | 254 | |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 255 | /* |
| 256 | * update sysfs node hdmi_audio_cb to enable notification acknowledge feature |
| 257 | * bit(5) set to 1 to enable this feature |
| 258 | * bit(4) set to 1 to enable acknowledgement |
| 259 | * this is done only once at the first connect event |
| 260 | * |
| 261 | * bit(0) set to 1 when HDMI cable is connected |
| 262 | * bit(0) set to 0 when HDMI cable is disconnected |
| 263 | * this is done when device switch happens by setting audioparamter |
| 264 | */ |
| 265 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 266 | #define IS_BIT_SET(NUM, bitno) (NUM & (1 << bitno)) |
| 267 | |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 268 | #define EXT_DISPLAY_PLUG_STATUS_NOTIFY_ENABLE 0x30 |
| 269 | #define EXT_DISPLAY_PLUG_STATUS_NOTIFY_CONNECT 0x01 |
| 270 | #define EXT_DISPLAY_PLUG_STATUS_NOTIFY_DISCONNECT 0x00 |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 271 | |
| 272 | static ssize_t update_sysfs_node(const char *path, const char *data, size_t len) |
| 273 | { |
| 274 | ssize_t err = 0; |
| 275 | int fd = -1; |
| 276 | |
| 277 | err = access(path, W_OK); |
| 278 | if (!err) { |
| 279 | fd = open(path, O_WRONLY); |
| 280 | errno = 0; |
| 281 | err = write(fd, data, len); |
| 282 | if (err < 0) { |
| 283 | err = -errno; |
| 284 | } |
| 285 | close(fd); |
| 286 | } else { |
| 287 | ALOGE("%s: Failed to access path: %s error: %s", |
| 288 | __FUNCTION__, path, strerror(errno)); |
| 289 | err = -errno; |
| 290 | } |
| 291 | |
| 292 | return err; |
| 293 | } |
| 294 | |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 295 | static int get_ext_disp_sysfs_node_index(int ext_disp_type) |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 296 | { |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 297 | int node_index = -1; |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 298 | char fbvalue[80] = {0}; |
| 299 | char fbpath[80] = {0}; |
| 300 | int i = 0; |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 301 | FILE *ext_disp_fd = NULL; |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 302 | |
Garmond Leung | 37850ab | 2016-10-06 11:42:18 -0700 | [diff] [blame] | 303 | while (1) { |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 304 | snprintf(fbpath, sizeof(fbpath), |
| 305 | "/sys/class/graphics/fb%d/msm_fb_type", i); |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 306 | ext_disp_fd = fopen(fbpath, "r"); |
| 307 | if (ext_disp_fd) { |
| 308 | if (fread(fbvalue, sizeof(char), 80, ext_disp_fd)) { |
| 309 | if(((strncmp(fbvalue, "dtv panel", strlen("dtv panel")) == 0) && |
| 310 | (ext_disp_type == EXT_DISPLAY_TYPE_HDMI)) || |
| 311 | ((strncmp(fbvalue, "dp panel", strlen("dp panel")) == 0) && |
| 312 | (ext_disp_type == EXT_DISPLAY_TYPE_DP))) { |
| 313 | node_index = i; |
| 314 | ALOGD("%s: Ext Disp:%d is at fb%d", __func__, ext_disp_type, i); |
| 315 | fclose(ext_disp_fd); |
| 316 | return node_index; |
| 317 | } |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 318 | } |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 319 | fclose(ext_disp_fd); |
Garmond Leung | 37850ab | 2016-10-06 11:42:18 -0700 | [diff] [blame] | 320 | i++; |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 321 | } else { |
Garmond Leung | 37850ab | 2016-10-06 11:42:18 -0700 | [diff] [blame] | 322 | ALOGE("%s: Scanned till end of fbs or Failed to open fb node %d", __func__, i); |
| 323 | break; |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
| 327 | return -1; |
| 328 | } |
| 329 | |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 330 | static int update_ext_disp_sysfs_node(const struct audio_device *adev, |
| 331 | int node_value, int controller, int stream) |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 332 | { |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 333 | char ext_disp_ack_path[80] = {0}; |
| 334 | char ext_disp_ack_value[3] = {0}; |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 335 | int index, ret = -1; |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 336 | int ext_disp_type = platform_get_ext_disp_type_v2(adev->platform, controller, |
| 337 | stream); |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 338 | |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 339 | if (ext_disp_type < 0) { |
| 340 | ALOGE("%s, Unable to get the external display type, err:%d", |
| 341 | __func__, ext_disp_type); |
| 342 | return -EINVAL; |
| 343 | } |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 344 | |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 345 | index = get_ext_disp_sysfs_node_index(ext_disp_type); |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 346 | if (index >= 0) { |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 347 | snprintf(ext_disp_ack_value, sizeof(ext_disp_ack_value), "%d", node_value); |
| 348 | snprintf(ext_disp_ack_path, sizeof(ext_disp_ack_path), |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 349 | "/sys/class/graphics/fb%d/hdmi_audio_cb", index); |
| 350 | |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 351 | ret = update_sysfs_node(ext_disp_ack_path, ext_disp_ack_value, |
| 352 | sizeof(ext_disp_ack_value)); |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 353 | |
| 354 | ALOGI("update hdmi_audio_cb at fb[%d] to:[%d] %s", |
| 355 | index, node_value, (ret >= 0) ? "success":"fail"); |
| 356 | } |
| 357 | |
| 358 | return ret; |
| 359 | } |
| 360 | |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 361 | static int update_audio_ack_state(const struct audio_device *adev, |
| 362 | int node_value, |
| 363 | int controller, |
| 364 | int stream) |
Kuirong Wang | 9426c29 | 2017-02-07 10:39:15 -0800 | [diff] [blame] | 365 | { |
Kuirong Wang | 9426c29 | 2017-02-07 10:39:15 -0800 | [diff] [blame] | 366 | int ret = 0; |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 367 | int ctl_index = 0; |
| 368 | struct mixer_ctl *ctl = NULL; |
| 369 | const char *ctl_prefix = "External Display"; |
| 370 | const char *ctl_suffix = "Audio Ack"; |
| 371 | char mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0}; |
Kuirong Wang | 9426c29 | 2017-02-07 10:39:15 -0800 | [diff] [blame] | 372 | |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 373 | ctl_index = platform_get_display_port_ctl_index(controller, stream); |
| 374 | if (-EINVAL == ctl_index) { |
| 375 | ALOGE("%s: Unknown controller/stream %d/%d", |
| 376 | __func__, controller, stream); |
| 377 | return -EINVAL; |
| 378 | } |
| 379 | |
| 380 | if (0 == ctl_index) |
| 381 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 382 | "%s %s", ctl_prefix, ctl_suffix); |
| 383 | else |
| 384 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 385 | "%s%d %s", ctl_prefix, ctl_index, ctl_suffix); |
| 386 | |
| 387 | ALOGV("%s: mixer ctl name: %s", __func__, mixer_ctl_name); |
Kuirong Wang | 9426c29 | 2017-02-07 10:39:15 -0800 | [diff] [blame] | 388 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 389 | /* If no mixer command support, fall back to sysfs node approach */ |
| 390 | if (!ctl) { |
| 391 | ALOGI("%s: could not get ctl for mixer cmd(%s), use sysfs node instead\n", |
| 392 | __func__, mixer_ctl_name); |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 393 | ret = update_ext_disp_sysfs_node(adev, node_value, controller, stream); |
Kuirong Wang | 9426c29 | 2017-02-07 10:39:15 -0800 | [diff] [blame] | 394 | } else { |
| 395 | char *ack_str = NULL; |
| 396 | |
| 397 | if (node_value == EXT_DISPLAY_PLUG_STATUS_NOTIFY_ENABLE) |
| 398 | ack_str = "Ack_Enable"; |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 399 | else if (node_value == EXT_DISPLAY_PLUG_STATUS_NOTIFY_CONNECT) |
Kuirong Wang | 9426c29 | 2017-02-07 10:39:15 -0800 | [diff] [blame] | 400 | ack_str = "Connect"; |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 401 | else if (node_value == EXT_DISPLAY_PLUG_STATUS_NOTIFY_DISCONNECT) |
Kuirong Wang | 9426c29 | 2017-02-07 10:39:15 -0800 | [diff] [blame] | 402 | ack_str = "Disconnect"; |
| 403 | else { |
| 404 | ALOGE("%s: Invalid input parameter - 0x%x\n", |
| 405 | __func__, node_value); |
| 406 | return -EINVAL; |
| 407 | } |
| 408 | |
| 409 | ret = mixer_ctl_set_enum_by_string(ctl, ack_str); |
| 410 | if (ret) |
| 411 | ALOGE("%s: Could not set ctl for mixer cmd - %s ret %d\n", |
| 412 | __func__, mixer_ctl_name, ret); |
| 413 | } |
| 414 | return ret; |
| 415 | } |
| 416 | |
Garmond Leung | e3b6d48 | 2016-10-25 16:48:01 -0700 | [diff] [blame] | 417 | static void audio_extn_ext_disp_set_parameters(const struct audio_device *adev, |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 418 | struct str_parms *parms) |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 419 | { |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 420 | int controller = 0; |
| 421 | int stream = 0; |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 422 | char value[32] = {0}; |
| 423 | static bool is_hdmi_sysfs_node_init = false; |
| 424 | |
| 425 | if (str_parms_get_str(parms, "connect", value, sizeof(value)) >= 0 |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 426 | && (atoi(value) & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { |
| 427 | //params = "connect=1024" for external display connection. |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 428 | platform_get_controller_stream_from_params(parms, &controller, &stream); |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 429 | if (is_hdmi_sysfs_node_init == false) { |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 430 | //check if this is different for dp and hdmi |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 431 | is_hdmi_sysfs_node_init = true; |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 432 | update_audio_ack_state(adev, |
| 433 | EXT_DISPLAY_PLUG_STATUS_NOTIFY_ENABLE, |
| 434 | controller, stream); |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 435 | } |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 436 | update_audio_ack_state(adev, EXT_DISPLAY_PLUG_STATUS_NOTIFY_CONNECT, |
| 437 | controller, stream); |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 438 | } else if(str_parms_get_str(parms, "disconnect", value, sizeof(value)) >= 0 |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 439 | && (atoi(value) & AUDIO_DEVICE_OUT_AUX_DIGITAL)){ |
| 440 | //params = "disconnect=1024" for external display disconnection. |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 441 | platform_get_controller_stream_from_params(parms, &controller, &stream); |
| 442 | update_audio_ack_state(adev, EXT_DISPLAY_PLUG_STATUS_NOTIFY_DISCONNECT, |
| 443 | controller, stream); |
Garmond Leung | e3b6d48 | 2016-10-25 16:48:01 -0700 | [diff] [blame] | 444 | ALOGV("invalidate cached edid"); |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 445 | platform_invalidate_hdmi_config_v2(adev->platform, controller, stream); |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 446 | } else { |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 447 | // handle ext disp devices only |
Mingming Yin | 00611c3 | 2015-10-30 17:10:53 -0700 | [diff] [blame] | 448 | return; |
| 449 | } |
| 450 | } |
| 451 | |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 452 | static int update_custom_mtmx_coefficients_v2(struct audio_device *adev, |
| 453 | struct audio_custom_mtmx_params *params, |
| 454 | int pcm_device_id) |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 455 | { |
| 456 | struct mixer_ctl *ctl = NULL; |
| 457 | char *mixer_name_prefix = "AudStr"; |
| 458 | char *mixer_name_suffix = "ChMixer Weight Ch"; |
| 459 | char mixer_ctl_name[128] = {0}; |
| 460 | struct audio_custom_mtmx_params_info *pinfo = ¶ms->info; |
| 461 | int i = 0, err = 0; |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 462 | int cust_ch_mixer_cfg[128], len = 0; |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 463 | |
| 464 | ALOGI("%s: ip_channels %d, op_channels %d, pcm_device_id %d", |
| 465 | __func__, pinfo->ip_channels, pinfo->op_channels, pcm_device_id); |
| 466 | |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 467 | if (adev->use_old_pspd_mix_ctrl) { |
| 468 | /* |
| 469 | * Below code is to ensure backward compatibilty with older |
| 470 | * kernel version. Use old mixer control to set mixer coefficients |
| 471 | */ |
| 472 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 473 | "Audio Stream %d Channel Mix Cfg", pcm_device_id); |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 474 | |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 475 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 476 | if (!ctl) { |
| 477 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 478 | __func__, mixer_ctl_name); |
| 479 | return -EINVAL; |
| 480 | } |
| 481 | cust_ch_mixer_cfg[len++] = pinfo->ip_channels; |
| 482 | cust_ch_mixer_cfg[len++] = pinfo->op_channels; |
| 483 | for (i = 0; i < (int) (pinfo->op_channels * pinfo->ip_channels); i++) { |
Avinash Chandra | d7296d4 | 2021-08-04 15:07:47 +0530 | [diff] [blame] | 484 | ALOGV("%s: coeff[%d] %lu", __func__, i, (unsigned long )params->coeffs[i]); |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 485 | cust_ch_mixer_cfg[len++] = params->coeffs[i]; |
| 486 | } |
| 487 | err = mixer_ctl_set_array(ctl, cust_ch_mixer_cfg, len); |
| 488 | if (err) { |
| 489 | ALOGE("%s: ERROR. Mixer ctl set failed", __func__); |
| 490 | return -EINVAL; |
| 491 | } |
| 492 | ALOGD("%s: Mixer ctl set for %s success", __func__, mixer_ctl_name); |
| 493 | } else { |
| 494 | for (i = 0; i < (int)pinfo->op_channels; i++) { |
| 495 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "%s %d %s %d", |
| 496 | mixer_name_prefix, pcm_device_id, mixer_name_suffix, i+1); |
| 497 | |
| 498 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 499 | if (!ctl) { |
| 500 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 501 | __func__, mixer_ctl_name); |
| 502 | return -EINVAL; |
| 503 | } |
| 504 | err = mixer_ctl_set_array(ctl, |
| 505 | ¶ms->coeffs[pinfo->ip_channels * i], |
| 506 | pinfo->ip_channels); |
| 507 | if (err) { |
| 508 | ALOGE("%s: ERROR. Mixer ctl set failed", __func__); |
| 509 | return -EINVAL; |
| 510 | } |
| 511 | } |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 512 | } |
| 513 | return 0; |
| 514 | } |
| 515 | |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 516 | static void set_custom_mtmx_params_v2(struct audio_device *adev, |
| 517 | struct audio_custom_mtmx_params_info *pinfo, |
| 518 | int pcm_device_id, bool enable) |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 519 | { |
| 520 | struct mixer_ctl *ctl = NULL; |
| 521 | char *mixer_name_prefix = "AudStr"; |
| 522 | char *mixer_name_suffix = "ChMixer Cfg"; |
| 523 | char mixer_ctl_name[128] = {0}; |
| 524 | int chmixer_cfg[5] = {0}, len = 0; |
| 525 | int be_id = -1, err = 0; |
| 526 | |
| 527 | be_id = platform_get_snd_device_backend_index(pinfo->snd_device); |
| 528 | |
| 529 | ALOGI("%s: ip_channels %d,op_channels %d,pcm_device_id %d,be_id %d", |
| 530 | __func__, pinfo->ip_channels, pinfo->op_channels, pcm_device_id, be_id); |
| 531 | |
| 532 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 533 | "%s %d %s", mixer_name_prefix, pcm_device_id, mixer_name_suffix); |
| 534 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 535 | if (!ctl) { |
| 536 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 537 | __func__, mixer_ctl_name); |
| 538 | return; |
| 539 | } |
| 540 | chmixer_cfg[len++] = enable ? 1 : 0; |
| 541 | chmixer_cfg[len++] = 0; /* rule index */ |
| 542 | chmixer_cfg[len++] = pinfo->ip_channels; |
| 543 | chmixer_cfg[len++] = pinfo->op_channels; |
| 544 | chmixer_cfg[len++] = be_id + 1; |
| 545 | |
| 546 | err = mixer_ctl_set_array(ctl, chmixer_cfg, len); |
| 547 | if (err) |
| 548 | ALOGE("%s: ERROR. Mixer ctl set failed", __func__); |
| 549 | } |
| 550 | |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 551 | void audio_extn_set_custom_mtmx_params_v2(struct audio_device *adev, |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 552 | struct audio_usecase *usecase, |
| 553 | bool enable) |
| 554 | { |
| 555 | struct audio_custom_mtmx_params_info info = {0}; |
| 556 | struct audio_custom_mtmx_params *params = NULL; |
| 557 | int num_devices = 0, pcm_device_id = -1, i = 0, ret = 0; |
| 558 | snd_device_t new_snd_devices[SND_DEVICE_OUT_END] = {0}; |
| 559 | struct audio_backend_cfg backend_cfg = {0}; |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 560 | uint32_t feature_id = 0, idx = 0; |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 561 | |
| 562 | switch(usecase->type) { |
| 563 | case PCM_PLAYBACK: |
| 564 | if (usecase->stream.out) { |
| 565 | pcm_device_id = |
| 566 | platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK); |
| 567 | if (platform_split_snd_device(adev->platform, |
| 568 | usecase->out_snd_device, |
| 569 | &num_devices, new_snd_devices)) { |
| 570 | new_snd_devices[0] = usecase->out_snd_device; |
| 571 | num_devices = 1; |
| 572 | } |
| 573 | } else { |
| 574 | ALOGE("%s: invalid output stream for playback usecase id:%d", |
| 575 | __func__, usecase->id); |
| 576 | return; |
| 577 | } |
| 578 | break; |
| 579 | case PCM_CAPTURE: |
| 580 | if (usecase->stream.in) { |
| 581 | pcm_device_id = |
| 582 | platform_get_pcm_device_id(usecase->id, PCM_CAPTURE); |
| 583 | if (platform_split_snd_device(adev->platform, |
| 584 | usecase->in_snd_device, |
| 585 | &num_devices, new_snd_devices)) { |
| 586 | new_snd_devices[0] = usecase->in_snd_device; |
| 587 | num_devices = 1; |
| 588 | } |
| 589 | } else { |
| 590 | ALOGE("%s: invalid input stream for capture usecase id:%d", |
| 591 | __func__, usecase->id); |
| 592 | return; |
| 593 | } |
| 594 | break; |
| 595 | default: |
| 596 | ALOGV("%s: unsupported usecase id:%d", __func__, usecase->id); |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | /* |
| 601 | * check and update feature_id before this assignment, |
| 602 | * if features like dual_mono is enabled and overrides the default(i.e. 0). |
| 603 | */ |
| 604 | info.id = feature_id; |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 605 | info.usecase_id[0] = usecase->id; |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 606 | for (i = 0, ret = 0; i < num_devices; i++) { |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 607 | info.snd_device = new_snd_devices[i]; |
| 608 | platform_get_codec_backend_cfg(adev, info.snd_device, &backend_cfg); |
| 609 | if (usecase->type == PCM_PLAYBACK) { |
| 610 | info.ip_channels = audio_channel_count_from_out_mask( |
| 611 | usecase->stream.out->channel_mask); |
| 612 | info.op_channels = backend_cfg.channels; |
| 613 | } else { |
| 614 | info.ip_channels = backend_cfg.channels; |
| 615 | info.op_channels = audio_channel_count_from_in_mask( |
| 616 | usecase->stream.in->channel_mask); |
| 617 | } |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 618 | params = platform_get_custom_mtmx_params(adev->platform, &info, &idx); |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 619 | if (params) { |
| 620 | if (enable) |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 621 | ret = update_custom_mtmx_coefficients_v2(adev, params, |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 622 | pcm_device_id); |
| 623 | if (ret < 0) |
| 624 | ALOGE("%s: error updating mtmx coeffs err:%d", __func__, ret); |
| 625 | else |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 626 | set_custom_mtmx_params_v2(adev, &info, pcm_device_id, enable); |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 627 | } |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 631 | static int set_custom_mtmx_output_channel_map(struct audio_device *adev, |
| 632 | char *mixer_name_prefix, |
| 633 | uint32_t ch_count, |
| 634 | bool enable) |
| 635 | { |
| 636 | struct mixer_ctl *ctl = NULL; |
| 637 | char mixer_ctl_name[128] = {0}; |
| 638 | int ret = 0; |
Vijay Kumar Maddula | dd0811f | 2022-09-06 22:30:24 +0530 | [diff] [blame] | 639 | int channel_map[AUDIO_MAX_DSP_CHANNELS] = {0}; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 640 | |
| 641 | ALOGV("%s channel_count %d", __func__, ch_count); |
| 642 | |
| 643 | if (!enable) { |
| 644 | ALOGV("%s: reset output channel map", __func__); |
| 645 | goto exit; |
| 646 | } |
| 647 | |
| 648 | switch (ch_count) { |
| 649 | case 2: |
| 650 | channel_map[0] = PCM_CHANNEL_FL; |
| 651 | channel_map[1] = PCM_CHANNEL_FR; |
| 652 | break; |
| 653 | case 4: |
| 654 | channel_map[0] = PCM_CHANNEL_FL; |
| 655 | channel_map[1] = PCM_CHANNEL_FR; |
| 656 | channel_map[2] = PCM_CHANNEL_LS; |
| 657 | channel_map[3] = PCM_CHANNEL_RS; |
| 658 | break; |
| 659 | case 6: |
| 660 | channel_map[0] = PCM_CHANNEL_FL; |
| 661 | channel_map[1] = PCM_CHANNEL_FR; |
| 662 | channel_map[2] = PCM_CHANNEL_FC; |
| 663 | channel_map[3] = PCM_CHANNEL_LFE; |
| 664 | channel_map[4] = PCM_CHANNEL_LS; |
| 665 | channel_map[5] = PCM_CHANNEL_RS; |
| 666 | break; |
| 667 | case 8: |
| 668 | channel_map[0] = PCM_CHANNEL_FL; |
| 669 | channel_map[1] = PCM_CHANNEL_FR; |
| 670 | channel_map[2] = PCM_CHANNEL_FC; |
| 671 | channel_map[3] = PCM_CHANNEL_LFE; |
| 672 | channel_map[4] = PCM_CHANNEL_LB; |
| 673 | channel_map[5] = PCM_CHANNEL_RB; |
| 674 | channel_map[6] = PCM_CHANNEL_LS; |
| 675 | channel_map[7] = PCM_CHANNEL_RS; |
| 676 | break; |
| 677 | case 10: |
| 678 | channel_map[0] = PCM_CHANNEL_FL; |
| 679 | channel_map[1] = PCM_CHANNEL_FR; |
| 680 | channel_map[2] = PCM_CHANNEL_LFE; |
| 681 | channel_map[3] = PCM_CHANNEL_FC; |
| 682 | channel_map[4] = PCM_CHANNEL_LB; |
| 683 | channel_map[5] = PCM_CHANNEL_RB; |
| 684 | channel_map[6] = PCM_CHANNEL_LS; |
| 685 | channel_map[7] = PCM_CHANNEL_RS; |
| 686 | channel_map[8] = PCM_CHANNEL_TFL; |
| 687 | channel_map[9] = PCM_CHANNEL_TFR; |
| 688 | break; |
| 689 | case 12: |
| 690 | channel_map[0] = PCM_CHANNEL_FL; |
| 691 | channel_map[1] = PCM_CHANNEL_FR; |
| 692 | channel_map[2] = PCM_CHANNEL_FC; |
| 693 | channel_map[3] = PCM_CHANNEL_LFE; |
| 694 | channel_map[4] = PCM_CHANNEL_LB; |
| 695 | channel_map[5] = PCM_CHANNEL_RB; |
| 696 | channel_map[6] = PCM_CHANNEL_LS; |
| 697 | channel_map[7] = PCM_CHANNEL_RS; |
| 698 | channel_map[8] = PCM_CHANNEL_TFL; |
| 699 | channel_map[9] = PCM_CHANNEL_TFR; |
| 700 | channel_map[10] = PCM_CHANNEL_TSL; |
| 701 | channel_map[11] = PCM_CHANNEL_TSR; |
| 702 | break; |
| 703 | case 14: |
| 704 | channel_map[0] = PCM_CHANNEL_FL; |
| 705 | channel_map[1] = PCM_CHANNEL_FR; |
| 706 | channel_map[2] = PCM_CHANNEL_LFE; |
| 707 | channel_map[3] = PCM_CHANNEL_FC; |
| 708 | channel_map[4] = PCM_CHANNEL_LB; |
| 709 | channel_map[5] = PCM_CHANNEL_RB; |
| 710 | channel_map[6] = PCM_CHANNEL_LS; |
| 711 | channel_map[7] = PCM_CHANNEL_RS; |
| 712 | channel_map[8] = PCM_CHANNEL_TFL; |
| 713 | channel_map[9] = PCM_CHANNEL_TFR; |
| 714 | channel_map[10] = PCM_CHANNEL_TSL; |
| 715 | channel_map[11] = PCM_CHANNEL_TSR; |
| 716 | channel_map[12] = PCM_CHANNEL_FLC; |
| 717 | channel_map[13] = PCM_CHANNEL_FRC; |
| 718 | break; |
| 719 | case 16: |
| 720 | channel_map[0] = PCM_CHANNEL_FL; |
| 721 | channel_map[1] = PCM_CHANNEL_FR; |
| 722 | channel_map[2] = PCM_CHANNEL_FC; |
| 723 | channel_map[3] = PCM_CHANNEL_LFE; |
| 724 | channel_map[4] = PCM_CHANNEL_LB; |
| 725 | channel_map[5] = PCM_CHANNEL_RB; |
| 726 | channel_map[6] = PCM_CHANNEL_LS; |
| 727 | channel_map[7] = PCM_CHANNEL_RS; |
| 728 | channel_map[8] = PCM_CHANNEL_TFL; |
| 729 | channel_map[9] = PCM_CHANNEL_TFR; |
| 730 | channel_map[10] = PCM_CHANNEL_TSL; |
| 731 | channel_map[11] = PCM_CHANNEL_TSR; |
| 732 | channel_map[12] = PCM_CHANNEL_FLC; |
| 733 | channel_map[13] = PCM_CHANNEL_FRC; |
| 734 | channel_map[14] = PCM_CHANNEL_RLC; |
| 735 | channel_map[15] = PCM_CHANNEL_RRC; |
| 736 | break; |
| 737 | default: |
| 738 | ALOGE("%s: unsupported channels(%d) for setting channel map", |
| 739 | __func__, ch_count); |
| 740 | return -EINVAL; |
| 741 | } |
| 742 | |
| 743 | exit: |
| 744 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "%s %s", |
| 745 | mixer_name_prefix, "Output Channel Map"); |
| 746 | |
| 747 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 748 | if (!ctl) { |
| 749 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 750 | __func__, mixer_ctl_name); |
| 751 | return -EINVAL; |
| 752 | } |
| 753 | |
| 754 | ret = mixer_ctl_set_array(ctl, channel_map, ch_count); |
| 755 | return ret; |
| 756 | } |
| 757 | |
| 758 | static int update_custom_mtmx_coefficients_v1(struct audio_device *adev, |
| 759 | struct audio_custom_mtmx_params *params, |
| 760 | struct audio_custom_mtmx_in_params *in_params, |
| 761 | int pcm_device_id, |
| 762 | usecase_type_t type, |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 763 | bool enable, |
| 764 | uint32_t idx) |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 765 | { |
| 766 | struct mixer_ctl *ctl = NULL; |
| 767 | char mixer_ctl_name[128] = {0}; |
| 768 | struct audio_custom_mtmx_params_info *pinfo = ¶ms->info; |
| 769 | char mixer_name_prefix[100]; |
| 770 | int i = 0, err = 0, rule = 0; |
| 771 | uint32_t mtrx_row_cnt = 0, mtrx_column_cnt = 0; |
| 772 | int reset_coeffs[AUDIO_MAX_DSP_CHANNELS] = {0}; |
| 773 | |
| 774 | ALOGI("%s: ip_channels %d, op_channels %d, pcm_device_id %d, usecase type %d, enable %d", |
| 775 | __func__, pinfo->ip_channels, pinfo->op_channels, pcm_device_id, |
| 776 | type, enable); |
| 777 | |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 778 | if (pinfo->fe_id[idx] == 0) { |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 779 | ALOGE("%s: Error. no front end defined", __func__); |
| 780 | return -EINVAL; |
| 781 | } |
| 782 | |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 783 | snprintf(mixer_name_prefix, sizeof(mixer_name_prefix), "%s%d", |
| 784 | "MultiMedia", pinfo->fe_id[idx]); |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 785 | /* |
| 786 | * Enable/Disable channel mixer. |
| 787 | * If enable, use params and in_params to configure mixer. |
| 788 | * If disable, reset previously configured mixer. |
| 789 | */ |
| 790 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "%s %s", |
| 791 | mixer_name_prefix, "Channel Mixer"); |
| 792 | |
| 793 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 794 | if (!ctl) { |
| 795 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 796 | __func__, mixer_ctl_name); |
| 797 | return -EINVAL; |
| 798 | } |
| 799 | |
| 800 | if (enable) |
| 801 | err = mixer_ctl_set_enum_by_string(ctl, "Enable"); |
| 802 | else |
| 803 | err = mixer_ctl_set_enum_by_string(ctl, "Disable"); |
| 804 | |
| 805 | if (err) { |
| 806 | ALOGE("%s: ERROR. %s channel mixer failed", __func__, |
| 807 | enable ? "Enable" : "Disable"); |
| 808 | return -EINVAL; |
| 809 | } |
| 810 | |
| 811 | /* Configure output channels of channel mixer */ |
| 812 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "%s %s", |
| 813 | mixer_name_prefix, "Channels"); |
| 814 | |
| 815 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 816 | if (!ctl) { |
| 817 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 818 | __func__, mixer_ctl_name); |
| 819 | return -EINVAL; |
| 820 | } |
| 821 | |
| 822 | mtrx_row_cnt = pinfo->op_channels; |
| 823 | mtrx_column_cnt = pinfo->ip_channels; |
| 824 | |
| 825 | if (enable) |
| 826 | err = mixer_ctl_set_value(ctl, 0, mtrx_row_cnt); |
| 827 | else |
| 828 | err = mixer_ctl_set_value(ctl, 0, 0); |
| 829 | |
| 830 | if (err) { |
| 831 | ALOGE("%s: ERROR. %s mixer output channels failed", __func__, |
| 832 | enable ? "Set" : "Reset"); |
| 833 | return -EINVAL; |
| 834 | } |
| 835 | |
| 836 | |
| 837 | /* To keep output channel map in sync with asm driver channel mapping */ |
| 838 | err = set_custom_mtmx_output_channel_map(adev, mixer_name_prefix, mtrx_row_cnt, |
| 839 | enable); |
| 840 | if (err) { |
| 841 | ALOGE("%s: ERROR. %s mtmx output channel map failed", __func__, |
| 842 | enable ? "Set" : "Reset"); |
| 843 | return -EINVAL; |
| 844 | } |
| 845 | |
| 846 | /* Send channel mixer rule */ |
| 847 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "%s %s", |
| 848 | mixer_name_prefix, "Channel Rule"); |
| 849 | |
| 850 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 851 | if (!ctl) { |
| 852 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 853 | __func__, mixer_ctl_name); |
| 854 | return -EINVAL; |
| 855 | } |
| 856 | |
| 857 | mixer_ctl_set_value(ctl, 0, rule); |
| 858 | |
| 859 | /* Send channel coefficients for each output channel */ |
| 860 | for (i = 0; i < mtrx_row_cnt; i++) { |
| 861 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "%s %s%d", |
| 862 | mixer_name_prefix, "Output Channel", i+1); |
| 863 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 864 | if (!ctl) { |
| 865 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 866 | __func__, mixer_ctl_name); |
| 867 | return -EINVAL; |
| 868 | } |
| 869 | |
| 870 | if (enable) |
| 871 | err = mixer_ctl_set_array(ctl, |
| 872 | ¶ms->coeffs[mtrx_column_cnt * i], |
| 873 | mtrx_column_cnt); |
| 874 | else |
| 875 | err = mixer_ctl_set_array(ctl, |
| 876 | reset_coeffs, |
| 877 | mtrx_column_cnt); |
| 878 | if (err) { |
| 879 | ALOGE("%s: ERROR. %s coefficients failed for output channel %d", |
| 880 | __func__, enable ? "Set" : "Reset", i); |
| 881 | return -EINVAL; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /* Configure backend interfaces with information provided in xml */ |
| 886 | i = 0; |
| 887 | while (in_params->in_ch_info[i].ch_count != 0) { |
| 888 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "%s %s%d", |
| 889 | mixer_name_prefix, "Channel", i+1); |
| 890 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 891 | if (!ctl) { |
| 892 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 893 | __func__, mixer_ctl_name); |
| 894 | return -EINVAL; |
| 895 | } |
| 896 | if (enable) { |
| 897 | ALOGD("%s: mixer %s, interface %s", __func__, mixer_ctl_name, |
| 898 | in_params->in_ch_info[i].hw_interface); |
| 899 | err = mixer_ctl_set_enum_by_string(ctl, |
| 900 | in_params->in_ch_info[i].hw_interface); |
| 901 | } else { |
| 902 | err = mixer_ctl_set_enum_by_string(ctl, "ZERO"); |
| 903 | } |
| 904 | |
| 905 | if (err) { |
| 906 | ALOGE("%s: ERROR. %s channel backend interface failed", __func__, |
| 907 | enable ? "Set" : "Reset"); |
| 908 | return -EINVAL; |
| 909 | } |
| 910 | i++; |
| 911 | } |
| 912 | |
| 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | |
| 917 | void audio_extn_set_custom_mtmx_params_v1(struct audio_device *adev, |
| 918 | struct audio_usecase *usecase, |
| 919 | bool enable) |
| 920 | { |
| 921 | struct audio_custom_mtmx_params_info info = {0}; |
| 922 | struct audio_custom_mtmx_params *params = NULL; |
| 923 | struct audio_custom_mtmx_in_params_info in_info = {0}; |
| 924 | struct audio_custom_mtmx_in_params *in_params = NULL; |
| 925 | int pcm_device_id = -1, ret = 0; |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 926 | uint32_t feature_id = 0, idx = 0; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 927 | |
| 928 | switch(usecase->type) { |
| 929 | case PCM_CAPTURE: |
| 930 | if (usecase->stream.in) { |
| 931 | pcm_device_id = |
| 932 | platform_get_pcm_device_id(usecase->id, PCM_CAPTURE); |
| 933 | info.snd_device = usecase->in_snd_device; |
| 934 | } else { |
| 935 | ALOGE("%s: invalid input stream for capture usecase id:%d", |
| 936 | __func__, usecase->id); |
| 937 | return; |
| 938 | } |
| 939 | break; |
| 940 | case PCM_PLAYBACK: |
| 941 | default: |
| 942 | ALOGV("%s: unsupported usecase id:%d", __func__, usecase->id); |
| 943 | return; |
| 944 | } |
| 945 | |
| 946 | ALOGD("%s: snd device %d", __func__, info.snd_device); |
| 947 | info.id = feature_id; |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 948 | info.usecase_id[0] = usecase->id; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 949 | info.op_channels = audio_channel_count_from_in_mask( |
| 950 | usecase->stream.in->channel_mask); |
| 951 | |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 952 | in_info.usecase_id[0] = info.usecase_id[0]; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 953 | in_info.op_channels = info.op_channels; |
| 954 | in_params = platform_get_custom_mtmx_in_params(adev->platform, &in_info); |
| 955 | if (!in_params) { |
| 956 | ALOGE("%s: Could not get in params for usecase %d, channels %d", |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 957 | __func__, in_info.usecase_id[0], in_info.op_channels); |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 958 | return; |
| 959 | } |
| 960 | |
| 961 | info.ip_channels = in_params->ip_channels; |
| 962 | ALOGD("%s: ip channels %d, op channels %d", __func__, info.ip_channels, info.op_channels); |
| 963 | |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 964 | params = platform_get_custom_mtmx_params(adev->platform, &info, &idx); |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 965 | if (params) { |
| 966 | ret = update_custom_mtmx_coefficients_v1(adev, params, in_params, |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 967 | pcm_device_id, usecase->type, enable, idx); |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 968 | if (ret < 0) |
| 969 | ALOGE("%s: error updating mtmx coeffs err:%d", __func__, ret); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | snd_device_t audio_extn_get_loopback_snd_device(struct audio_device *adev, |
| 974 | struct audio_usecase *usecase, |
| 975 | int channel_count) |
| 976 | { |
| 977 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 978 | struct audio_custom_mtmx_in_params_info in_info = {0}; |
| 979 | struct audio_custom_mtmx_in_params *in_params = NULL; |
| 980 | |
| 981 | if (!adev || !usecase) { |
| 982 | ALOGE("%s: Invalid params", __func__); |
| 983 | return snd_device; |
| 984 | } |
| 985 | |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 986 | in_info.usecase_id[0] = usecase->id; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 987 | in_info.op_channels = channel_count; |
| 988 | in_params = platform_get_custom_mtmx_in_params(adev->platform, &in_info); |
| 989 | if (!in_params) { |
| 990 | ALOGE("%s: Could not get in params for usecase %d, channels %d", |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 991 | __func__, in_info.usecase_id[0], in_info.op_channels); |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 992 | return snd_device; |
| 993 | } |
| 994 | |
| 995 | switch(in_params->mic_ch) { |
| 996 | case 2: |
| 997 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AND_EC_REF_LOOPBACK; |
| 998 | break; |
| 999 | case 4: |
| 1000 | snd_device = SND_DEVICE_IN_HANDSET_QMIC_AND_EC_REF_LOOPBACK; |
| 1001 | break; |
| 1002 | case 6: |
| 1003 | snd_device = SND_DEVICE_IN_HANDSET_6MIC_AND_EC_REF_LOOPBACK; |
| 1004 | break; |
| 1005 | case 8: |
| 1006 | snd_device = SND_DEVICE_IN_HANDSET_8MIC_AND_EC_REF_LOOPBACK; |
| 1007 | break; |
| 1008 | default: |
| 1009 | ALOGE("%s: Unsupported mic channels %d", |
| 1010 | __func__, in_params->mic_ch); |
| 1011 | break; |
| 1012 | } |
| 1013 | |
| 1014 | ALOGD("%s: return snd device %d", __func__, snd_device); |
| 1015 | return snd_device; |
| 1016 | } |
| 1017 | |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 1018 | #ifndef DTS_EAGLE |
| 1019 | #define audio_extn_hpx_set_parameters(adev, parms) (0) |
Alexy Joseph | 61300e6 | 2014-12-11 18:32:26 -0800 | [diff] [blame] | 1020 | #define audio_extn_hpx_get_parameters(query, reply) (0) |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 1021 | #define audio_extn_check_and_set_dts_hpx_state(adev) (0) |
| 1022 | #else |
| 1023 | void audio_extn_hpx_set_parameters(struct audio_device *adev, |
| 1024 | struct str_parms *parms) |
| 1025 | { |
| 1026 | int ret = 0; |
| 1027 | char value[32]={0}; |
| 1028 | char prop[PROPERTY_VALUE_MAX] = "false"; |
| 1029 | bool hpx_state = false; |
| 1030 | const char *mixer_ctl_name = "Set HPX OnOff"; |
| 1031 | struct mixer_ctl *ctl = NULL; |
| 1032 | ALOGV("%s", __func__); |
| 1033 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 1034 | property_get("vendor.audio.use.dts_eagle", prop, "0"); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 1035 | if (strncmp("true", prop, sizeof("true"))) |
| 1036 | return; |
| 1037 | |
| 1038 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_HPX, value, |
| 1039 | sizeof(value)); |
| 1040 | if (ret >= 0) { |
| 1041 | if (!strncmp("ON", value, sizeof("ON"))) |
| 1042 | hpx_state = true; |
| 1043 | |
| 1044 | if (hpx_state == aextnmod.hpx_enabled) |
| 1045 | return; |
| 1046 | |
| 1047 | aextnmod.hpx_enabled = hpx_state; |
| 1048 | /* set HPX state on stream pp */ |
| 1049 | if (adev->offload_effects_set_hpx_state != NULL) |
| 1050 | adev->offload_effects_set_hpx_state(hpx_state); |
| 1051 | |
Dhanalakshmi Siddani | eb7d4cd | 2015-06-03 11:44:16 +0530 | [diff] [blame] | 1052 | audio_extn_dts_eagle_fade(adev, aextnmod.hpx_enabled, NULL); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 1053 | /* set HPX state on device pp */ |
| 1054 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1055 | if (ctl) |
| 1056 | mixer_ctl_set_value(ctl, 0, aextnmod.hpx_enabled); |
| 1057 | } |
| 1058 | } |
| 1059 | |
Alexy Joseph | 61300e6 | 2014-12-11 18:32:26 -0800 | [diff] [blame] | 1060 | static int audio_extn_hpx_get_parameters(struct str_parms *query, |
| 1061 | struct str_parms *reply) |
| 1062 | { |
| 1063 | int ret; |
| 1064 | char value[32]={0}; |
| 1065 | |
| 1066 | ALOGV("%s: hpx %d", __func__, aextnmod.hpx_enabled); |
| 1067 | ret = str_parms_get_str(query, AUDIO_PARAMETER_HPX, value, |
| 1068 | sizeof(value)); |
| 1069 | if (ret >= 0) { |
| 1070 | if (aextnmod.hpx_enabled) |
| 1071 | str_parms_add_str(reply, AUDIO_PARAMETER_HPX, "ON"); |
| 1072 | else |
| 1073 | str_parms_add_str(reply, AUDIO_PARAMETER_HPX, "OFF"); |
| 1074 | } |
| 1075 | return ret; |
| 1076 | } |
| 1077 | |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 1078 | void audio_extn_check_and_set_dts_hpx_state(const struct audio_device *adev) |
| 1079 | { |
| 1080 | char prop[PROPERTY_VALUE_MAX]; |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 1081 | property_get("vendor.audio.use.dts_eagle", prop, "0"); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 1082 | if (strncmp("true", prop, sizeof("true"))) |
| 1083 | return; |
| 1084 | if (adev->offload_effects_set_hpx_state) |
| 1085 | adev->offload_effects_set_hpx_state(aextnmod.hpx_enabled); |
| 1086 | } |
| 1087 | #endif |
| 1088 | |
Dhanalakshmi Siddani | 999d564 | 2019-03-22 15:27:44 +0530 | [diff] [blame] | 1089 | /* Affine AHAL thread to CPU core */ |
| 1090 | void audio_extn_set_cpu_affinity() |
| 1091 | { |
| 1092 | cpu_set_t cpuset; |
| 1093 | struct sched_param sched_param; |
| 1094 | int policy = SCHED_FIFO, rc = 0; |
| 1095 | |
| 1096 | ALOGV("%s: Set CPU affinity for read thread", __func__); |
| 1097 | CPU_ZERO(&cpuset); |
| 1098 | if (sched_setaffinity(0, sizeof(cpuset), &cpuset) != 0) |
| 1099 | ALOGE("%s: CPU Affinity allocation failed for Capture thread", |
| 1100 | __func__); |
| 1101 | |
| 1102 | sched_param.sched_priority = sched_get_priority_min(policy); |
| 1103 | rc = sched_setscheduler(0, policy, &sched_param); |
| 1104 | if (rc != 0) |
| 1105 | ALOGE("%s: Failed to set realtime priority", __func__); |
| 1106 | } |
| 1107 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1108 | // START: VBAT ============================================================= |
| 1109 | void vbat_feature_init(bool is_feature_enabled) |
Venkata Narendra Kumar Gutta | 4bd09d0 | 2016-01-29 15:31:04 +0530 | [diff] [blame] | 1110 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1111 | audio_extn_vbat_enabled = is_feature_enabled; |
| 1112 | ALOGD(":: %s: ---- Feature VBAT is %s ----", |
| 1113 | __func__, is_feature_enabled ? "ENABLED": " NOT ENABLED"); |
Venkata Narendra Kumar Gutta | 4bd09d0 | 2016-01-29 15:31:04 +0530 | [diff] [blame] | 1114 | } |
| 1115 | |
Banajit Goswami | 20cdd21 | 2015-09-11 01:11:30 -0700 | [diff] [blame] | 1116 | bool audio_extn_is_vbat_enabled(void) |
| 1117 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1118 | if (!audio_extn_vbat_enabled) |
| 1119 | return false; |
| 1120 | |
Banajit Goswami | 20cdd21 | 2015-09-11 01:11:30 -0700 | [diff] [blame] | 1121 | ALOGD("%s: status: %d", __func__, aextnmod.vbat_enabled); |
| 1122 | return (aextnmod.vbat_enabled ? true: false); |
| 1123 | } |
| 1124 | |
| 1125 | bool audio_extn_can_use_vbat(void) |
| 1126 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1127 | if (!audio_extn_vbat_enabled) |
| 1128 | return false; |
| 1129 | |
Banajit Goswami | 20cdd21 | 2015-09-11 01:11:30 -0700 | [diff] [blame] | 1130 | char prop_vbat_enabled[PROPERTY_VALUE_MAX] = "false"; |
| 1131 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 1132 | property_get("persist.vendor.audio.vbat.enabled", prop_vbat_enabled, "0"); |
Banajit Goswami | 20cdd21 | 2015-09-11 01:11:30 -0700 | [diff] [blame] | 1133 | if (!strncmp("true", prop_vbat_enabled, 4)) { |
| 1134 | aextnmod.vbat_enabled = 1; |
| 1135 | } |
| 1136 | |
| 1137 | ALOGD("%s: vbat.enabled property is set to %s", __func__, prop_vbat_enabled); |
| 1138 | return (aextnmod.vbat_enabled ? true: false); |
| 1139 | } |
Aditya Bavanari | 9b58902 | 2018-09-20 08:47:55 +0530 | [diff] [blame] | 1140 | |
| 1141 | bool audio_extn_is_bcl_enabled(void) |
| 1142 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1143 | if (!audio_extn_vbat_enabled) |
| 1144 | return false; |
| 1145 | |
Aditya Bavanari | 9b58902 | 2018-09-20 08:47:55 +0530 | [diff] [blame] | 1146 | ALOGD("%s: status: %d", __func__, aextnmod.bcl_enabled); |
| 1147 | return (aextnmod.bcl_enabled ? true: false); |
| 1148 | } |
| 1149 | |
| 1150 | bool audio_extn_can_use_bcl(void) |
| 1151 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1152 | if (!audio_extn_vbat_enabled) |
| 1153 | return false; |
| 1154 | |
Aditya Bavanari | 9b58902 | 2018-09-20 08:47:55 +0530 | [diff] [blame] | 1155 | char prop_bcl_enabled[PROPERTY_VALUE_MAX] = "false"; |
| 1156 | |
| 1157 | property_get("persist.vendor.audio.bcl.enabled", prop_bcl_enabled, "0"); |
| 1158 | if (!strncmp("true", prop_bcl_enabled, 4)) { |
| 1159 | aextnmod.bcl_enabled = 1; |
| 1160 | } |
| 1161 | |
| 1162 | ALOGD("%s: bcl.enabled property is set to %s", __func__, prop_bcl_enabled); |
| 1163 | return (aextnmod.bcl_enabled ? true: false); |
| 1164 | } |
Banajit Goswami | 20cdd21 | 2015-09-11 01:11:30 -0700 | [diff] [blame] | 1165 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1166 | // START: ANC_HEADSET ------------------------------------------------------- |
| 1167 | void anc_headset_feature_init(bool is_feature_enabled) |
Srinivas Julakanti | 1ca769a | 2017-01-04 23:18:08 -0800 | [diff] [blame] | 1168 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1169 | audio_extn_anc_headset_feature_enabled = is_feature_enabled; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 1170 | ALOGD(":: %s: ---- Feature ANC_HEADSET is %s----", __func__, |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1171 | is_feature_enabled? "ENABLED": "NOT ENABLED"); |
| 1172 | |
Srinivas Julakanti | 1ca769a | 2017-01-04 23:18:08 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1175 | bool audio_extn_get_anc_enabled(void) |
| 1176 | { |
Weiyin Jiang | d3fc3f9 | 2019-08-28 17:27:20 +0800 | [diff] [blame] | 1177 | ALOGD("%s: anc_enabled:%d", __func__, |
| 1178 | (aextnmod.anc_enabled && audio_extn_anc_headset_feature_enabled)); |
| 1179 | return (aextnmod.anc_enabled && |
| 1180 | audio_extn_anc_headset_feature_enabled); |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | bool audio_extn_should_use_handset_anc(int in_channels) |
| 1184 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1185 | if (audio_extn_anc_headset_feature_enabled) { |
| 1186 | char prop_aanc[PROPERTY_VALUE_MAX] = "false"; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1187 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1188 | property_get("persist.vendor.audio.aanc.enable", prop_aanc, "0"); |
| 1189 | if (!strncmp("true", prop_aanc, 4)) { |
| 1190 | ALOGD("%s: AANC enabled in the property", __func__); |
| 1191 | aextnmod.aanc_enabled = 1; |
| 1192 | } |
| 1193 | |
| 1194 | return (aextnmod.aanc_enabled && aextnmod.anc_enabled |
| 1195 | && (in_channels == 1)); |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1196 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1197 | return false; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | bool audio_extn_should_use_fb_anc(void) |
| 1201 | { |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1202 | char prop_anc[PROPERTY_VALUE_MAX] = "feedforward"; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1203 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1204 | if (audio_extn_anc_headset_feature_enabled) { |
| 1205 | property_get("persist.vendor.audio.headset.anc.type", prop_anc, "0"); |
| 1206 | if (!strncmp("feedback", prop_anc, sizeof("feedback"))) { |
| 1207 | ALOGD("%s: FB ANC headset type enabled\n", __func__); |
| 1208 | return true; |
| 1209 | } |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1210 | } |
| 1211 | return false; |
| 1212 | } |
| 1213 | |
Sudheer Papothi | d63caef | 2018-05-15 00:41:52 +0530 | [diff] [blame] | 1214 | void audio_extn_set_aanc_noise_level(struct audio_device *adev, |
| 1215 | struct str_parms *parms) |
| 1216 | { |
| 1217 | int ret; |
| 1218 | char value[32] = {0}; |
| 1219 | struct mixer_ctl *ctl = NULL; |
| 1220 | const char *mixer_ctl_name = "AANC Noise Level"; |
| 1221 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1222 | if(audio_extn_anc_headset_feature_enabled) { |
| 1223 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AANC_NOISE_LEVEL, value, |
Sudheer Papothi | d63caef | 2018-05-15 00:41:52 +0530 | [diff] [blame] | 1224 | sizeof(value)); |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1225 | if (ret >= 0) { |
| 1226 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1227 | if (ctl) |
| 1228 | mixer_ctl_set_value(ctl, 0, atoi(value)); |
| 1229 | else |
| 1230 | ALOGW("%s: Not able to get mixer ctl: %s", |
| 1231 | __func__, mixer_ctl_name); |
| 1232 | } |
Sudheer Papothi | d63caef | 2018-05-15 00:41:52 +0530 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
Apoorv Raghuvanshi | c053654 | 2013-11-14 16:25:59 -0800 | [diff] [blame] | 1236 | void audio_extn_set_anc_parameters(struct audio_device *adev, |
| 1237 | struct str_parms *parms) |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1238 | { |
| 1239 | int ret; |
| 1240 | char value[32] ={0}; |
Apoorv Raghuvanshi | c053654 | 2013-11-14 16:25:59 -0800 | [diff] [blame] | 1241 | struct listnode *node; |
| 1242 | struct audio_usecase *usecase; |
Dhananjay Kumar | 24a4c7b | 2015-12-04 21:33:15 +0530 | [diff] [blame] | 1243 | struct str_parms *query_44_1; |
| 1244 | struct str_parms *reply_44_1; |
| 1245 | struct str_parms *parms_disable_44_1; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1246 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1247 | if(!audio_extn_anc_headset_feature_enabled) |
| 1248 | return; |
| 1249 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1250 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_ANC, value, |
| 1251 | sizeof(value)); |
| 1252 | if (ret >= 0) { |
| 1253 | if (strcmp(value, "true") == 0) |
| 1254 | aextnmod.anc_enabled = true; |
| 1255 | else |
| 1256 | aextnmod.anc_enabled = false; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1257 | |
Dhananjay Kumar | 24a4c7b | 2015-12-04 21:33:15 +0530 | [diff] [blame] | 1258 | /* Store current 44.1 configuration and disable it temporarily before |
| 1259 | * changing ANC state. |
| 1260 | * Since 44.1 playback is not allowed with anc on. |
| 1261 | * If ANC switch is done when 44.1 is active three devices would need |
| 1262 | * sequencing 1. "headphones-44.1", 2. "headphones-anc" and |
| 1263 | * 3. "headphones". |
| 1264 | * Note: Enable/diable of anc would affect other two device's state. |
| 1265 | */ |
| 1266 | query_44_1 = str_parms_create_str(AUDIO_PARAMETER_KEY_NATIVE_AUDIO); |
| 1267 | reply_44_1 = str_parms_create(); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 1268 | if (!query_44_1 || !reply_44_1) { |
| 1269 | if (query_44_1) { |
| 1270 | str_parms_destroy(query_44_1); |
| 1271 | } |
| 1272 | if (reply_44_1) { |
| 1273 | str_parms_destroy(reply_44_1); |
| 1274 | } |
| 1275 | |
| 1276 | ALOGE("%s: param creation failed", __func__); |
| 1277 | return; |
| 1278 | } |
| 1279 | |
Dhananjay Kumar | 24a4c7b | 2015-12-04 21:33:15 +0530 | [diff] [blame] | 1280 | platform_get_parameters(adev->platform, query_44_1, reply_44_1); |
| 1281 | |
| 1282 | parms_disable_44_1 = str_parms_create(); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 1283 | if (!parms_disable_44_1) { |
| 1284 | str_parms_destroy(query_44_1); |
| 1285 | str_parms_destroy(reply_44_1); |
| 1286 | ALOGE("%s: param creation failed for parms_disable_44_1", __func__); |
| 1287 | return; |
| 1288 | } |
| 1289 | |
Dhananjay Kumar | 24a4c7b | 2015-12-04 21:33:15 +0530 | [diff] [blame] | 1290 | str_parms_add_str(parms_disable_44_1, AUDIO_PARAMETER_KEY_NATIVE_AUDIO, "false"); |
| 1291 | platform_set_parameters(adev->platform, parms_disable_44_1); |
| 1292 | str_parms_destroy(parms_disable_44_1); |
| 1293 | |
| 1294 | // Refresh device selection for anc playback |
Vimal Puthanveed | be677c3 | 2013-12-11 13:34:09 -0800 | [diff] [blame] | 1295 | list_for_each(node, &adev->usecase_list) { |
| 1296 | usecase = node_to_item(node, struct audio_usecase, list); |
Sujin Panicker | 390724d | 2019-04-26 10:43:36 +0530 | [diff] [blame] | 1297 | if (usecase->stream.out && usecase->type != PCM_CAPTURE) { |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 1298 | if (is_single_device_type_equal(&usecase->stream.out->device_list, |
| 1299 | AUDIO_DEVICE_OUT_WIRED_HEADPHONE) || |
| 1300 | is_single_device_type_equal(&usecase->stream.out->device_list, |
| 1301 | AUDIO_DEVICE_OUT_WIRED_HEADSET) || |
| 1302 | is_single_device_type_equal(&usecase->stream.out->device_list, |
| 1303 | AUDIO_DEVICE_OUT_EARPIECE)) { |
Vimal Puthanveed | be677c3 | 2013-12-11 13:34:09 -0800 | [diff] [blame] | 1304 | select_devices(adev, usecase->id); |
Dhananjay Kumar | 24a4c7b | 2015-12-04 21:33:15 +0530 | [diff] [blame] | 1305 | ALOGV("%s: switching device completed", __func__); |
Vimal Puthanveed | be677c3 | 2013-12-11 13:34:09 -0800 | [diff] [blame] | 1306 | break; |
| 1307 | } |
Apoorv Raghuvanshi | c053654 | 2013-11-14 16:25:59 -0800 | [diff] [blame] | 1308 | } |
| 1309 | } |
Dhananjay Kumar | 24a4c7b | 2015-12-04 21:33:15 +0530 | [diff] [blame] | 1310 | |
| 1311 | // Restore 44.1 configuration on top of updated anc state |
| 1312 | platform_set_parameters(adev->platform, reply_44_1); |
| 1313 | str_parms_destroy(query_44_1); |
| 1314 | str_parms_destroy(reply_44_1); |
Apoorv Raghuvanshi | c053654 | 2013-11-14 16:25:59 -0800 | [diff] [blame] | 1315 | } |
| 1316 | |
Aniket Kumar Lata | b91e4cf | 2019-02-11 18:55:23 -0800 | [diff] [blame] | 1317 | ALOGV("%s: anc_enabled:%d", __func__, aextnmod.anc_enabled); |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1318 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1319 | // END: ANC_HEADSET ------------------------------------------------------- |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1320 | |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1321 | static int32_t afe_proxy_set_channel_mapping(struct audio_device *adev, |
Sachin Mohan Gadag | 3e6e3fd | 2019-03-14 17:37:05 +0530 | [diff] [blame] | 1322 | int channel_count, |
| 1323 | snd_device_t snd_device) |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1324 | { |
Sachin Mohan Gadag | 3e6e3fd | 2019-03-14 17:37:05 +0530 | [diff] [blame] | 1325 | struct mixer_ctl *ctl = NULL, *be_ctl = NULL; |
Fred Oh | e047968 | 2015-03-25 16:30:26 -0700 | [diff] [blame] | 1326 | const char *mixer_ctl_name = "Playback Device Channel Map"; |
Sachin Mohan Gadag | 3e6e3fd | 2019-03-14 17:37:05 +0530 | [diff] [blame] | 1327 | const char *be_mixer_ctl_name = "Backend Device Channel Map"; |
| 1328 | long set_values[FCC_8] = {0}; |
| 1329 | long be_set_values[FCC_8 + 1] = {0}; |
| 1330 | int ret = -1; |
| 1331 | int be_idx = -1; |
| 1332 | |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1333 | ALOGV("%s channel_count:%d",__func__, channel_count); |
| 1334 | |
| 1335 | switch (channel_count) { |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1336 | case 2: |
| 1337 | set_values[0] = PCM_CHANNEL_FL; |
| 1338 | set_values[1] = PCM_CHANNEL_FR; |
| 1339 | break; |
Shalini Manjunatha | 43c45c4 | 2020-02-17 13:14:37 +0530 | [diff] [blame] | 1340 | case 4: |
| 1341 | set_values[0] = PCM_CHANNEL_FL; |
| 1342 | set_values[1] = PCM_CHANNEL_FR; |
| 1343 | set_values[2] = PCM_CHANNEL_LS; |
| 1344 | set_values[3] = PCM_CHANNEL_LFE; |
| 1345 | break; |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1346 | case 6: |
| 1347 | set_values[0] = PCM_CHANNEL_FL; |
| 1348 | set_values[1] = PCM_CHANNEL_FR; |
| 1349 | set_values[2] = PCM_CHANNEL_FC; |
| 1350 | set_values[3] = PCM_CHANNEL_LFE; |
| 1351 | set_values[4] = PCM_CHANNEL_LS; |
| 1352 | set_values[5] = PCM_CHANNEL_RS; |
| 1353 | break; |
| 1354 | case 8: |
| 1355 | set_values[0] = PCM_CHANNEL_FL; |
| 1356 | set_values[1] = PCM_CHANNEL_FR; |
| 1357 | set_values[2] = PCM_CHANNEL_FC; |
| 1358 | set_values[3] = PCM_CHANNEL_LFE; |
| 1359 | set_values[4] = PCM_CHANNEL_LS; |
| 1360 | set_values[5] = PCM_CHANNEL_RS; |
| 1361 | set_values[6] = PCM_CHANNEL_LB; |
| 1362 | set_values[7] = PCM_CHANNEL_RB; |
| 1363 | break; |
| 1364 | default: |
| 1365 | ALOGE("unsupported channels(%d) for setting channel map", |
| 1366 | channel_count); |
| 1367 | return -EINVAL; |
| 1368 | } |
| 1369 | |
Sachin Mohan Gadag | 3e6e3fd | 2019-03-14 17:37:05 +0530 | [diff] [blame] | 1370 | be_idx = platform_get_snd_device_backend_index(snd_device); |
| 1371 | |
| 1372 | if (be_idx >= 0) { |
| 1373 | be_ctl = mixer_get_ctl_by_name(adev->mixer, be_mixer_ctl_name); |
| 1374 | if (!be_ctl) { |
| 1375 | ALOGD("%s: Could not get ctl for mixer cmd - %s, using default control", |
| 1376 | __func__, be_mixer_ctl_name); |
| 1377 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1378 | } else |
| 1379 | ctl = be_ctl; |
| 1380 | } else |
| 1381 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1382 | |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1383 | if (!ctl) { |
| 1384 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1385 | __func__, mixer_ctl_name); |
| 1386 | return -EINVAL; |
| 1387 | } |
Sachin Mohan Gadag | 3e6e3fd | 2019-03-14 17:37:05 +0530 | [diff] [blame] | 1388 | |
Manish Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 1389 | ALOGV("AFE: set mapping(%ld %ld %ld %ld %ld %ld %ld %ld) for channel:%d", |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1390 | set_values[0], set_values[1], set_values[2], set_values[3], set_values[4], |
| 1391 | set_values[5], set_values[6], set_values[7], channel_count); |
Sachin Mohan Gadag | 3e6e3fd | 2019-03-14 17:37:05 +0530 | [diff] [blame] | 1392 | |
| 1393 | if (!be_ctl) |
| 1394 | ret = mixer_ctl_set_array(ctl, set_values, channel_count); |
| 1395 | else { |
| 1396 | be_set_values[0] = be_idx; |
| 1397 | memcpy(&be_set_values[1], set_values, sizeof(long) * channel_count); |
| 1398 | ret = mixer_ctl_set_array(ctl, be_set_values, ARRAY_SIZE(be_set_values)); |
| 1399 | } |
| 1400 | |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1401 | return ret; |
| 1402 | } |
| 1403 | |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1404 | int32_t audio_extn_set_afe_proxy_channel_mixer(struct audio_device *adev, |
Sachin Mohan Gadag | 3e6e3fd | 2019-03-14 17:37:05 +0530 | [diff] [blame] | 1405 | int channel_count, snd_device_t snd_device) |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1406 | { |
| 1407 | int32_t ret = 0; |
| 1408 | const char *channel_cnt_str = NULL; |
| 1409 | struct mixer_ctl *ctl = NULL; |
| 1410 | const char *mixer_ctl_name = "PROXY_RX Channels"; |
| 1411 | |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 1412 | if (!property_get_bool("vendor.audio.feature.afe_proxy.enable", false)) { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1413 | ALOGW("%s: AFE_PROXY is disabled", __func__); |
| 1414 | return -ENOSYS; |
| 1415 | } |
| 1416 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1417 | ALOGD("%s: entry", __func__); |
| 1418 | /* use the existing channel count set by hardware params to |
| 1419 | configure the back end for stereo as usb/a2dp would be |
| 1420 | stereo by default */ |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1421 | ALOGD("%s: channels = %d", __func__, channel_count); |
| 1422 | switch (channel_count) { |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1423 | case 8: channel_cnt_str = "Eight"; break; |
| 1424 | case 7: channel_cnt_str = "Seven"; break; |
| 1425 | case 6: channel_cnt_str = "Six"; break; |
| 1426 | case 5: channel_cnt_str = "Five"; break; |
| 1427 | case 4: channel_cnt_str = "Four"; break; |
| 1428 | case 3: channel_cnt_str = "Three"; break; |
| 1429 | default: channel_cnt_str = "Two"; break; |
| 1430 | } |
| 1431 | |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1432 | if(channel_count >= 2 && channel_count <= 8) { |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1433 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1434 | if (!ctl) { |
| 1435 | ALOGE("%s: could not get ctl for mixer cmd - %s", |
| 1436 | __func__, mixer_ctl_name); |
| 1437 | return -EINVAL; |
| 1438 | } |
| 1439 | } |
| 1440 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 1441 | |
Shalini Manjunatha | 43c45c4 | 2020-02-17 13:14:37 +0530 | [diff] [blame] | 1442 | if (channel_count == 6 || channel_count == 8 || channel_count == 2 || channel_count == 4) { |
Sachin Mohan Gadag | 3e6e3fd | 2019-03-14 17:37:05 +0530 | [diff] [blame] | 1443 | ret = afe_proxy_set_channel_mapping(adev, channel_count, snd_device); |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1444 | } else { |
| 1445 | ALOGE("%s: set unsupported channel count(%d)", __func__, channel_count); |
| 1446 | ret = -EINVAL; |
| 1447 | } |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1448 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1449 | ALOGD("%s: exit", __func__); |
| 1450 | return ret; |
| 1451 | } |
| 1452 | |
Krishnankutty Kolathappilly | 0b2de1c | 2014-02-14 14:45:49 -0800 | [diff] [blame] | 1453 | void audio_extn_set_afe_proxy_parameters(struct audio_device *adev, |
| 1454 | struct str_parms *parms) |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1455 | { |
| 1456 | int ret, val; |
| 1457 | char value[32]={0}; |
| 1458 | |
| 1459 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_WFD, value, |
| 1460 | sizeof(value)); |
| 1461 | if (ret >= 0) { |
| 1462 | val = atoi(value); |
| 1463 | aextnmod.proxy_channel_num = val; |
Krishnankutty Kolathappilly | 0b2de1c | 2014-02-14 14:45:49 -0800 | [diff] [blame] | 1464 | adev->cur_wfd_channels = val; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1465 | ALOGD("%s: channel capability set to: %d", __func__, |
| 1466 | aextnmod.proxy_channel_num); |
| 1467 | } |
| 1468 | } |
| 1469 | |
vivek mehta | 344576a | 2016-04-12 18:56:03 -0700 | [diff] [blame] | 1470 | int audio_extn_get_afe_proxy_parameters(const struct audio_device *adev, |
| 1471 | struct str_parms *query, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1472 | struct str_parms *reply) |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1473 | { |
vivek mehta | 344576a | 2016-04-12 18:56:03 -0700 | [diff] [blame] | 1474 | int ret, val = 0; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1475 | char value[32]={0}; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1476 | |
| 1477 | ret = str_parms_get_str(query, AUDIO_PARAMETER_CAN_OPEN_PROXY, value, |
| 1478 | sizeof(value)); |
| 1479 | if (ret >= 0) { |
Kuirong Wang | a9f7cee | 2016-03-07 11:21:52 -0800 | [diff] [blame] | 1480 | val = (adev->allow_afe_proxy_usage ? 1: 0); |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1481 | str_parms_add_int(reply, AUDIO_PARAMETER_CAN_OPEN_PROXY, val); |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1482 | } |
vivek mehta | 344576a | 2016-04-12 18:56:03 -0700 | [diff] [blame] | 1483 | ALOGV("%s: called ... can_use_proxy %d", __func__, val); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1484 | return 0; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1485 | } |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1486 | |
| 1487 | /* must be called with hw device mutex locked */ |
| 1488 | int32_t audio_extn_read_afe_proxy_channel_masks(struct stream_out *out) |
| 1489 | { |
| 1490 | int ret = 0; |
| 1491 | int channels = aextnmod.proxy_channel_num; |
| 1492 | |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 1493 | if (!property_get_bool("vendor.audio.feature.afe_proxy.enable", |
| 1494 | false)) { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1495 | ALOGW("%s: AFE_PROXY is disabled", __func__); |
| 1496 | return -ENOSYS; |
| 1497 | } |
| 1498 | |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 1499 | switch (channels) { |
| 1500 | /* |
| 1501 | * Do not handle stereo output in Multi-channel cases |
| 1502 | * Stereo case is handled in normal playback path |
| 1503 | */ |
| 1504 | case 6: |
| 1505 | ALOGV("%s: AFE PROXY supports 5.1", __func__); |
| 1506 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1; |
| 1507 | break; |
| 1508 | case 8: |
| 1509 | ALOGV("%s: AFE PROXY supports 5.1 and 7.1 channels", __func__); |
| 1510 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1; |
| 1511 | out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1; |
| 1512 | break; |
| 1513 | default: |
| 1514 | ALOGE("AFE PROXY does not support multi channel playback"); |
| 1515 | ret = -ENOSYS; |
| 1516 | break; |
| 1517 | } |
| 1518 | return ret; |
| 1519 | } |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1520 | |
| 1521 | int32_t audio_extn_get_afe_proxy_channel_count() |
| 1522 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1523 | |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 1524 | if (!property_get_bool("vendor.audio.feature.afe_proxy.enable", |
| 1525 | false)) { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1526 | ALOGW("%s: AFE_PROXY is disabled", __func__); |
| 1527 | return -ENOSYS; |
| 1528 | } |
| 1529 | |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1530 | return aextnmod.proxy_channel_num; |
| 1531 | } |
| 1532 | |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1533 | static int get_active_offload_usecases(const struct audio_device *adev, |
| 1534 | struct str_parms *query, |
| 1535 | struct str_parms *reply) |
| 1536 | { |
| 1537 | int ret, count = 0; |
| 1538 | char value[32]={0}; |
| 1539 | struct listnode *node; |
| 1540 | struct audio_usecase *usecase; |
| 1541 | |
| 1542 | ALOGV("%s", __func__); |
| 1543 | ret = str_parms_get_str(query, AUDIO_PARAMETER_OFFLOAD_NUM_ACTIVE, value, |
| 1544 | sizeof(value)); |
| 1545 | if (ret >= 0) { |
| 1546 | list_for_each(node, &adev->usecase_list) { |
| 1547 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1548 | if (is_offload_usecase(usecase->id)) |
| 1549 | count++; |
| 1550 | } |
| 1551 | ALOGV("%s, number of active offload usecases: %d", __func__, count); |
| 1552 | str_parms_add_int(reply, AUDIO_PARAMETER_OFFLOAD_NUM_ACTIVE, count); |
| 1553 | } |
| 1554 | return ret; |
| 1555 | } |
| 1556 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1557 | void compress_meta_data_feature_init(bool is_featuer_enabled) |
| 1558 | { |
| 1559 | is_compress_meta_data_enabled = is_featuer_enabled; |
| 1560 | } |
| 1561 | |
| 1562 | bool if_compress_meta_data_feature_enabled() |
| 1563 | { |
| 1564 | return is_compress_meta_data_enabled; |
| 1565 | } |
| 1566 | |
| 1567 | //START: USB_OFFLOAD ========================================================== |
| 1568 | // LIB is part of hal lib, so no need for dlopen and getting function pointer |
| 1569 | // rather have function declared here |
| 1570 | |
| 1571 | void usb_init(void *adev); |
| 1572 | void usb_deinit(); |
| 1573 | void usb_add_device(audio_devices_t device, int card); |
| 1574 | void usb_remove_device(audio_devices_t device, int card); |
| 1575 | bool usb_is_config_supported(unsigned int *bit_width, |
| 1576 | unsigned int *sample_rate, |
| 1577 | unsigned int *ch, |
| 1578 | bool is_playback); |
| 1579 | int usb_enable_sidetone(int device, bool enable); |
| 1580 | void usb_set_sidetone_gain(struct str_parms *parms, |
| 1581 | char *value, int len); |
| 1582 | bool usb_is_capture_supported(); |
| 1583 | int usb_get_max_channels(bool playback); |
| 1584 | int usb_get_max_bit_width(bool playback); |
| 1585 | int usb_get_sup_sample_rates(bool type, uint32_t *sr, uint32_t l); |
| 1586 | bool usb_is_tunnel_supported(); |
| 1587 | bool usb_alive(int card); |
| 1588 | bool usb_connected(struct str_parms *parms); |
Carter Hsu | 32a6236 | 2018-10-15 15:01:42 -0700 | [diff] [blame] | 1589 | char *usb_usbid(void); |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1590 | unsigned long usb_find_service_interval(bool min, bool playback); |
| 1591 | int usb_altset_for_service_interval(bool is_playback, |
| 1592 | unsigned long service_interval, |
| 1593 | uint32_t *bit_width, |
| 1594 | uint32_t *sample_rate, |
| 1595 | uint32_t *channel_count); |
| 1596 | int usb_set_service_interval(bool playback, |
| 1597 | unsigned long service_interval, |
| 1598 | bool *reconfig); |
| 1599 | int usb_get_service_interval(bool playback, |
| 1600 | unsigned long *service_interval); |
| 1601 | int usb_check_and_set_svc_int(struct audio_usecase *uc_info, |
| 1602 | bool starting_output_stream); |
| 1603 | bool usb_is_reconfig_req(); |
| 1604 | void usb_set_reconfig(bool is_required); |
| 1605 | |
| 1606 | static bool is_usb_offload_enabled = false; |
| 1607 | static bool is_usb_burst_mode_enabled = false; |
| 1608 | static bool is_usb_sidetone_vol_enabled = false; |
| 1609 | |
| 1610 | void usb_offload_feature_init(bool is_feature_enabled) |
| 1611 | { |
| 1612 | ALOGD("%s: Called with feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 1613 | is_usb_offload_enabled = is_feature_enabled; |
| 1614 | } |
| 1615 | |
| 1616 | void usb_offload_burst_mode_feature_init(bool is_feature_enabled) |
| 1617 | { |
| 1618 | ALOGD("%s: Called with feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 1619 | is_usb_burst_mode_enabled = is_feature_enabled; |
| 1620 | } |
| 1621 | |
| 1622 | void usb_offload_sidetone_volume_feature_init(bool is_feature_enabled) |
| 1623 | { |
| 1624 | ALOGD("%s: Called with feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 1625 | is_usb_sidetone_vol_enabled = is_feature_enabled; |
| 1626 | } |
| 1627 | |
| 1628 | bool audio_extn_usb_is_sidetone_volume_enabled() |
| 1629 | { |
| 1630 | return is_usb_sidetone_vol_enabled; |
| 1631 | } |
| 1632 | |
| 1633 | void audio_extn_usb_init(void *adev) |
| 1634 | { |
| 1635 | if (is_usb_offload_enabled) |
| 1636 | usb_init(adev); |
| 1637 | } |
| 1638 | |
| 1639 | |
| 1640 | void audio_extn_usb_deinit() |
| 1641 | { |
| 1642 | if (is_usb_offload_enabled) |
| 1643 | usb_deinit(); |
| 1644 | } |
| 1645 | |
| 1646 | void audio_extn_usb_add_device(audio_devices_t device, int card) |
| 1647 | { |
| 1648 | if (is_usb_offload_enabled) |
| 1649 | usb_add_device(device, card); |
| 1650 | } |
| 1651 | |
| 1652 | void audio_extn_usb_remove_device(audio_devices_t device, int card) |
| 1653 | { |
| 1654 | if (is_usb_offload_enabled) |
| 1655 | usb_remove_device(device, card); |
| 1656 | } |
| 1657 | |
| 1658 | bool audio_extn_usb_is_config_supported(unsigned int *bit_width, |
| 1659 | unsigned int *sample_rate, |
| 1660 | unsigned int *ch, |
| 1661 | bool is_playback) |
| 1662 | { |
| 1663 | bool ret_val = false; |
| 1664 | if (is_usb_offload_enabled) |
| 1665 | ret_val = usb_is_config_supported(bit_width, sample_rate, ch, is_playback); |
| 1666 | |
| 1667 | return ret_val; |
| 1668 | } |
| 1669 | |
| 1670 | int audio_extn_usb_enable_sidetone(int device, bool enable) |
| 1671 | { |
| 1672 | int ret_val = 0; |
| 1673 | if (is_usb_offload_enabled) |
| 1674 | ret_val = usb_enable_sidetone(device, enable); |
| 1675 | |
| 1676 | return ret_val; |
| 1677 | } |
| 1678 | |
| 1679 | void audio_extn_usb_set_sidetone_gain(struct str_parms *parms, |
| 1680 | char *value, int len) |
| 1681 | { |
| 1682 | if (is_usb_offload_enabled) |
| 1683 | usb_set_sidetone_gain(parms, value, len); |
| 1684 | } |
| 1685 | |
| 1686 | bool audio_extn_usb_is_capture_supported() |
| 1687 | { |
| 1688 | bool ret_val = false; |
| 1689 | if (is_usb_offload_enabled) |
| 1690 | ret_val = usb_is_capture_supported(); |
| 1691 | |
| 1692 | return ret_val; |
| 1693 | } |
| 1694 | |
| 1695 | int audio_extn_usb_get_max_channels(bool playback) |
| 1696 | { |
| 1697 | int ret_val = 0; |
| 1698 | if (is_usb_offload_enabled) |
| 1699 | ret_val = usb_get_max_channels(playback); |
| 1700 | |
| 1701 | return ret_val; |
| 1702 | } |
| 1703 | |
| 1704 | int audio_extn_usb_get_max_bit_width(bool playback) |
| 1705 | { |
| 1706 | int ret_val = 0; |
| 1707 | if (is_usb_offload_enabled) |
| 1708 | ret_val = usb_get_max_bit_width(playback); |
| 1709 | |
| 1710 | return ret_val; |
| 1711 | } |
| 1712 | |
| 1713 | |
| 1714 | int audio_extn_usb_get_sup_sample_rates(bool type, uint32_t *sr, uint32_t l) |
| 1715 | { |
| 1716 | int ret_val = 0; |
| 1717 | if (is_usb_offload_enabled) |
| 1718 | ret_val = usb_get_sup_sample_rates(type, sr, l); |
| 1719 | |
| 1720 | return ret_val; |
| 1721 | } |
| 1722 | |
| 1723 | bool audio_extn_usb_is_tunnel_supported() |
| 1724 | { |
| 1725 | bool ret_val = false; |
| 1726 | if (is_usb_offload_enabled) |
| 1727 | ret_val = usb_is_tunnel_supported(); |
| 1728 | |
| 1729 | return ret_val; |
| 1730 | } |
| 1731 | |
| 1732 | bool audio_extn_usb_alive(int card) |
| 1733 | { |
| 1734 | bool ret_val = false; |
| 1735 | if (is_usb_offload_enabled) |
| 1736 | ret_val = usb_alive(card); |
| 1737 | |
| 1738 | return ret_val; |
| 1739 | } |
| 1740 | |
| 1741 | bool audio_extn_usb_connected(struct str_parms *parms) |
| 1742 | { |
| 1743 | bool ret_val = false; |
| 1744 | if (is_usb_offload_enabled) |
| 1745 | ret_val = usb_connected(parms); |
| 1746 | |
| 1747 | return ret_val; |
| 1748 | } |
| 1749 | |
Carter Hsu | 32a6236 | 2018-10-15 15:01:42 -0700 | [diff] [blame] | 1750 | char *audio_extn_usb_usbid(void) |
| 1751 | { |
| 1752 | char *ret_val = NULL; |
| 1753 | if (is_usb_offload_enabled) |
| 1754 | ret_val = usb_usbid(); |
| 1755 | |
| 1756 | return ret_val; |
| 1757 | } |
| 1758 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1759 | unsigned long audio_extn_usb_find_service_interval(bool min, bool playback) |
| 1760 | { |
| 1761 | unsigned long ret_val = 0; |
| 1762 | if (is_usb_offload_enabled && is_usb_burst_mode_enabled) |
| 1763 | ret_val = usb_find_service_interval(min, playback); |
| 1764 | |
| 1765 | return ret_val; |
| 1766 | } |
| 1767 | |
| 1768 | int audio_extn_usb_altset_for_service_interval(bool is_playback, |
| 1769 | unsigned long service_interval, |
| 1770 | uint32_t *bit_width, |
| 1771 | uint32_t *sample_rate, |
| 1772 | uint32_t *channel_count) |
| 1773 | { |
| 1774 | int ret_val = 0; |
| 1775 | if (is_usb_offload_enabled && is_usb_burst_mode_enabled) |
| 1776 | ret_val = usb_altset_for_service_interval(is_playback, service_interval, |
| 1777 | bit_width, sample_rate, channel_count); |
| 1778 | |
| 1779 | return ret_val; |
| 1780 | } |
| 1781 | |
| 1782 | int audio_extn_usb_set_service_interval(bool playback, |
| 1783 | unsigned long service_interval, |
| 1784 | bool *reconfig) |
| 1785 | { |
| 1786 | int ret_val = 0; |
| 1787 | if (is_usb_offload_enabled && is_usb_burst_mode_enabled) |
| 1788 | ret_val = usb_set_service_interval(playback, service_interval, reconfig); |
| 1789 | |
| 1790 | return ret_val; |
| 1791 | } |
| 1792 | |
| 1793 | int audio_extn_usb_get_service_interval(bool playback, |
| 1794 | unsigned long *service_interval) |
| 1795 | { |
| 1796 | int ret_val = 0; |
| 1797 | if (is_usb_offload_enabled && is_usb_burst_mode_enabled) |
| 1798 | ret_val = usb_get_service_interval(playback, service_interval); |
| 1799 | |
| 1800 | return ret_val; |
| 1801 | } |
| 1802 | |
| 1803 | int audio_extn_usb_check_and_set_svc_int(struct audio_usecase *uc_info, |
| 1804 | bool starting_output_stream) |
| 1805 | { |
| 1806 | int ret_val = 0; |
| 1807 | if (is_usb_offload_enabled && is_usb_burst_mode_enabled) |
| 1808 | ret_val = usb_check_and_set_svc_int(uc_info, starting_output_stream); |
| 1809 | |
| 1810 | return ret_val; |
| 1811 | } |
| 1812 | |
| 1813 | bool audio_extn_usb_is_reconfig_req() |
| 1814 | { |
| 1815 | bool ret_val = 0; |
| 1816 | if (is_usb_offload_enabled && is_usb_burst_mode_enabled) |
| 1817 | ret_val = usb_is_reconfig_req(); |
| 1818 | |
| 1819 | return ret_val; |
| 1820 | } |
| 1821 | |
| 1822 | void audio_extn_usb_set_reconfig(bool is_required) |
| 1823 | { |
| 1824 | if (is_usb_offload_enabled && is_usb_burst_mode_enabled) |
| 1825 | usb_set_reconfig(is_required); |
| 1826 | } |
| 1827 | |
| 1828 | //END: USB_OFFLOAD =========================================================== |
| 1829 | |
| 1830 | //START: SPEAKER_PROTECTION ========================================================== |
| 1831 | #ifdef __LP64__ |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 1832 | #define SPKR_PROT_LIB_PATH "/vendor/lib64/libspkrprot.so" |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1833 | #define CIRRUS_SPKR_PROT_LIB_PATH "/vendor/lib64/libcirrusspkrprot.so" |
| 1834 | #else |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 1835 | #define SPKR_PROT_LIB_PATH "/vendor/lib/libspkrprot.so" |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1836 | #define CIRRUS_SPKR_PROT_LIB_PATH "/vendor/lib/libcirrusspkrprot.so" |
| 1837 | #endif |
| 1838 | |
Xu,Baochu | 235aec6 | 2022-02-14 10:20:44 +0800 | [diff] [blame] | 1839 | |
| 1840 | #define STR_CAT(path, extn) (path extn) |
| 1841 | |
| 1842 | #if LINUX_ENABLED |
| 1843 | # define SPKR_PROT_LIB_PATH STR_CAT(LE_LIBDIR, "/audio.spkr.prot.so") |
| 1844 | # define CIRRUS_SPKR_PROT_LIB_PATH STR_CAT(LE_LIBDIR, "/audio.external.spkr.prot.so") |
| 1845 | #else |
| 1846 | # ifdef __LP64__ |
| 1847 | # define SPKR_PROT_LIB_PATH "/vendor/lib64/libspkrprot.so" |
| 1848 | # define CIRRUS_SPKR_PROT_LIB_PATH "/vendor/lib64/libcirrusspkrprot.so" |
| 1849 | # else |
| 1850 | # define SPKR_PROT_LIB_PATH "/vendor/lib/libspkrprot.so" |
| 1851 | # define CIRRUS_SPKR_PROT_LIB_PATH "/vendor/lib/libcirrusspkrprot.so" |
| 1852 | # endif |
| 1853 | #endif |
| 1854 | |
| 1855 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1856 | static void *spkr_prot_lib_handle = NULL; |
| 1857 | |
| 1858 | typedef void (*spkr_prot_init_t)(void *, spkr_prot_init_config_t); |
| 1859 | static spkr_prot_init_t spkr_prot_init; |
| 1860 | |
| 1861 | typedef int (*spkr_prot_deinit_t)(); |
| 1862 | static spkr_prot_deinit_t spkr_prot_deinit; |
| 1863 | |
| 1864 | typedef int (*spkr_prot_start_processing_t)(snd_device_t); |
| 1865 | static spkr_prot_start_processing_t spkr_prot_start_processing; |
| 1866 | |
| 1867 | typedef void (*spkr_prot_stop_processing_t)(snd_device_t); |
| 1868 | static spkr_prot_stop_processing_t spkr_prot_stop_processing; |
| 1869 | |
| 1870 | typedef bool (*spkr_prot_is_enabled_t)(); |
| 1871 | static spkr_prot_is_enabled_t spkr_prot_is_enabled; |
| 1872 | |
| 1873 | typedef void (*spkr_prot_calib_cancel_t)(void *); |
| 1874 | static spkr_prot_calib_cancel_t spkr_prot_calib_cancel; |
| 1875 | |
| 1876 | typedef void (*spkr_prot_set_parameters_t)(struct str_parms *, |
| 1877 | char *, int); |
| 1878 | static spkr_prot_set_parameters_t spkr_prot_set_parameters; |
| 1879 | |
| 1880 | typedef int (*fbsp_set_parameters_t)(struct str_parms *); |
| 1881 | static fbsp_set_parameters_t fbsp_set_parameters; |
| 1882 | |
| 1883 | typedef int (*fbsp_get_parameters_t)(struct str_parms *, |
| 1884 | struct str_parms *); |
| 1885 | static fbsp_get_parameters_t fbsp_get_parameters; |
| 1886 | |
| 1887 | typedef int (*get_spkr_prot_snd_device_t)(snd_device_t); |
| 1888 | static get_spkr_prot_snd_device_t get_spkr_prot_snd_device; |
| 1889 | |
| 1890 | void spkr_prot_feature_init(bool is_feature_enabled) |
| 1891 | { |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 1892 | ALOGD("%s: Called with feature %s, vendor_enhanced_info 0x%x", __func__, |
| 1893 | is_feature_enabled ? "Enabled" : "NOT Enabled", vendor_enhanced_info); |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1894 | if (is_feature_enabled) { |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 1895 | // dlopen lib |
Xu,Baochu | 235aec6 | 2022-02-14 10:20:44 +0800 | [diff] [blame] | 1896 | #if LINUX_ENABLED |
| 1897 | spkr_prot_lib_handle = dlopen(SPKR_PROT_LIB_PATH, RTLD_NOW); |
| 1898 | #else |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 1899 | if ((vendor_enhanced_info & 0x3) == 0x0) // Pure AOSP |
Arun Mirpuri | 5dc7780 | 2019-02-26 16:32:42 -0800 | [diff] [blame] | 1900 | spkr_prot_lib_handle = dlopen(CIRRUS_SPKR_PROT_LIB_PATH, RTLD_NOW); |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 1901 | else |
| 1902 | spkr_prot_lib_handle = dlopen(SPKR_PROT_LIB_PATH, RTLD_NOW); |
Xu,Baochu | 235aec6 | 2022-02-14 10:20:44 +0800 | [diff] [blame] | 1903 | #endif |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1904 | |
| 1905 | if (spkr_prot_lib_handle == NULL) { |
| 1906 | ALOGE("%s: dlopen failed", __func__); |
| 1907 | goto feature_disabled; |
| 1908 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1909 | |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 1910 | // map each function |
| 1911 | // if mandatoy functions are not found, disble feature |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1912 | // Mandatory functions |
| 1913 | if (((spkr_prot_init = |
| 1914 | (spkr_prot_init_t)dlsym(spkr_prot_lib_handle, "spkr_prot_init")) == NULL) || |
| 1915 | ((spkr_prot_deinit = |
| 1916 | (spkr_prot_deinit_t)dlsym(spkr_prot_lib_handle, "spkr_prot_deinit")) == NULL) || |
| 1917 | ((spkr_prot_start_processing = |
| 1918 | (spkr_prot_start_processing_t)dlsym(spkr_prot_lib_handle, "spkr_prot_start_processing")) == NULL) || |
| 1919 | ((spkr_prot_stop_processing = |
| 1920 | (spkr_prot_stop_processing_t)dlsym(spkr_prot_lib_handle, "spkr_prot_stop_processing")) == NULL) || |
| 1921 | ((spkr_prot_is_enabled = |
| 1922 | (spkr_prot_is_enabled_t)dlsym(spkr_prot_lib_handle, "spkr_prot_is_enabled")) == NULL) || |
| 1923 | ((spkr_prot_calib_cancel = |
| 1924 | (spkr_prot_calib_cancel_t)dlsym(spkr_prot_lib_handle, "spkr_prot_calib_cancel")) == NULL) || |
| 1925 | ((get_spkr_prot_snd_device = |
| 1926 | (get_spkr_prot_snd_device_t)dlsym(spkr_prot_lib_handle, "get_spkr_prot_snd_device")) == NULL)) { |
| 1927 | ALOGE("%s: dlsym failed", __func__); |
| 1928 | goto feature_disabled; |
| 1929 | } |
| 1930 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 1931 | // optional functions, can be NULL |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 1932 | spkr_prot_set_parameters = NULL; |
| 1933 | fbsp_set_parameters = NULL; |
| 1934 | fbsp_get_parameters = NULL; |
| 1935 | if ((spkr_prot_set_parameters = |
| 1936 | (spkr_prot_set_parameters_t)dlsym(spkr_prot_lib_handle, "spkr_prot_set_parameters")) == NULL) { |
| 1937 | ALOGW("%s: dlsym failed for spkr_prot_set_parameters", __func__); |
| 1938 | } |
| 1939 | |
| 1940 | if ((fbsp_set_parameters = |
| 1941 | (fbsp_set_parameters_t)dlsym(spkr_prot_lib_handle, "fbsp_set_parameters")) == NULL) { |
| 1942 | ALOGW("%s: dlsym failed for fbsp_set_parameters", __func__); |
| 1943 | } |
| 1944 | |
| 1945 | if ((fbsp_get_parameters = |
| 1946 | (fbsp_get_parameters_t)dlsym(spkr_prot_lib_handle, "fbsp_get_parameters")) == NULL) { |
| 1947 | ALOGW("%s: dlsym failed for fbsp_get_parameters", __func__); |
| 1948 | } |
| 1949 | |
| 1950 | ALOGD("%s:: ---- Feature SPKR_PROT is Enabled ----", __func__); |
| 1951 | return; |
| 1952 | } |
| 1953 | |
| 1954 | feature_disabled: |
| 1955 | if (spkr_prot_lib_handle) { |
| 1956 | dlclose(spkr_prot_lib_handle); |
| 1957 | spkr_prot_lib_handle = NULL; |
| 1958 | } |
| 1959 | |
| 1960 | spkr_prot_init = NULL; |
| 1961 | spkr_prot_deinit = NULL; |
| 1962 | spkr_prot_start_processing = NULL; |
| 1963 | spkr_prot_stop_processing = NULL; |
| 1964 | spkr_prot_is_enabled = NULL; |
| 1965 | spkr_prot_calib_cancel = NULL; |
| 1966 | spkr_prot_set_parameters = NULL; |
| 1967 | fbsp_set_parameters = NULL; |
| 1968 | fbsp_get_parameters = NULL; |
| 1969 | get_spkr_prot_snd_device = NULL; |
| 1970 | |
| 1971 | ALOGW(":: %s: ---- Feature SPKR_PROT is disabled ----", __func__); |
| 1972 | return; |
| 1973 | } |
| 1974 | |
| 1975 | void audio_extn_spkr_prot_init(void *adev) { |
| 1976 | if (spkr_prot_init != NULL) { |
| 1977 | // init function pointers |
| 1978 | spkr_prot_init_config_t spkr_prot_config_val; |
| 1979 | spkr_prot_config_val.fp_read_line_from_file = read_line_from_file; |
| 1980 | spkr_prot_config_val.fp_get_usecase_from_list = get_usecase_from_list; |
| 1981 | spkr_prot_config_val.fp_disable_snd_device = disable_snd_device; |
| 1982 | spkr_prot_config_val.fp_enable_snd_device = enable_snd_device; |
| 1983 | spkr_prot_config_val.fp_disable_audio_route = disable_audio_route; |
| 1984 | spkr_prot_config_val.fp_enable_audio_route = enable_audio_route; |
| 1985 | spkr_prot_config_val.fp_platform_set_snd_device_backend = platform_set_snd_device_backend; |
| 1986 | spkr_prot_config_val.fp_platform_get_snd_device_name_extn = platform_get_snd_device_name_extn; |
| 1987 | spkr_prot_config_val.fp_platform_get_default_app_type_v2 = platform_get_default_app_type_v2; |
| 1988 | spkr_prot_config_val.fp_platform_send_audio_calibration = platform_send_audio_calibration; |
| 1989 | spkr_prot_config_val.fp_platform_get_pcm_device_id = platform_get_pcm_device_id; |
| 1990 | spkr_prot_config_val.fp_platform_get_snd_device_name = platform_get_snd_device_name; |
| 1991 | spkr_prot_config_val.fp_platform_spkr_prot_is_wsa_analog_mode = platform_spkr_prot_is_wsa_analog_mode; |
| 1992 | spkr_prot_config_val.fp_platform_get_vi_feedback_snd_device = platform_get_vi_feedback_snd_device; |
| 1993 | spkr_prot_config_val.fp_platform_get_spkr_prot_snd_device = platform_get_spkr_prot_snd_device; |
| 1994 | spkr_prot_config_val.fp_platform_check_and_set_codec_backend_cfg = platform_check_and_set_codec_backend_cfg; |
| 1995 | spkr_prot_config_val.fp_audio_extn_get_snd_card_split = audio_extn_get_snd_card_split; |
| 1996 | spkr_prot_config_val.fp_audio_extn_is_vbat_enabled = audio_extn_is_vbat_enabled; |
| 1997 | |
| 1998 | spkr_prot_init(adev, spkr_prot_config_val); |
| 1999 | } |
| 2000 | |
| 2001 | return; |
| 2002 | } |
| 2003 | |
| 2004 | int audio_extn_spkr_prot_deinit() { |
| 2005 | int ret_val = 0; |
| 2006 | |
| 2007 | if (spkr_prot_deinit != NULL) |
| 2008 | ret_val = spkr_prot_deinit(); |
| 2009 | |
| 2010 | return ret_val; |
| 2011 | } |
| 2012 | |
| 2013 | int audio_extn_spkr_prot_start_processing(snd_device_t snd_device) { |
| 2014 | int ret_val = 0; |
| 2015 | |
| 2016 | if (spkr_prot_start_processing != NULL) |
| 2017 | ret_val = spkr_prot_start_processing(snd_device); |
| 2018 | |
| 2019 | return ret_val; |
| 2020 | } |
| 2021 | |
| 2022 | void audio_extn_spkr_prot_stop_processing(snd_device_t snd_device) |
| 2023 | { |
| 2024 | if (spkr_prot_stop_processing != NULL) |
| 2025 | spkr_prot_stop_processing(snd_device); |
| 2026 | |
| 2027 | return; |
| 2028 | } |
| 2029 | |
| 2030 | bool audio_extn_spkr_prot_is_enabled() |
| 2031 | { |
| 2032 | bool ret_val = false; |
| 2033 | |
| 2034 | if (spkr_prot_is_enabled != NULL) |
| 2035 | ret_val = spkr_prot_is_enabled(); |
| 2036 | |
| 2037 | return ret_val; |
| 2038 | } |
| 2039 | |
| 2040 | void audio_extn_spkr_prot_calib_cancel(void *adev) |
| 2041 | { |
| 2042 | if (spkr_prot_calib_cancel != NULL) |
| 2043 | spkr_prot_calib_cancel(adev); |
| 2044 | |
| 2045 | return; |
| 2046 | } |
| 2047 | |
| 2048 | void audio_extn_spkr_prot_set_parameters(struct str_parms *parms, |
| 2049 | char *value, int len) |
| 2050 | { |
| 2051 | if (spkr_prot_set_parameters != NULL) |
| 2052 | spkr_prot_set_parameters(parms, value, len); |
| 2053 | |
| 2054 | return; |
| 2055 | } |
| 2056 | |
| 2057 | int audio_extn_fbsp_set_parameters(struct str_parms *parms) |
| 2058 | { |
| 2059 | int ret_val = 0; |
| 2060 | |
| 2061 | if (fbsp_set_parameters != NULL) |
| 2062 | ret_val = fbsp_set_parameters(parms); |
| 2063 | |
| 2064 | return ret_val; |
| 2065 | } |
| 2066 | |
| 2067 | int audio_extn_fbsp_get_parameters(struct str_parms *query, |
| 2068 | struct str_parms *reply) |
| 2069 | { |
| 2070 | int ret_val = 0; |
| 2071 | |
| 2072 | if (fbsp_get_parameters != NULL) |
| 2073 | ret_val = fbsp_get_parameters(query, reply); |
| 2074 | |
| 2075 | return ret_val; |
| 2076 | } |
| 2077 | |
| 2078 | int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device) |
| 2079 | { |
| 2080 | int ret_val = snd_device; |
| 2081 | |
| 2082 | if (get_spkr_prot_snd_device != NULL) |
| 2083 | ret_val = get_spkr_prot_snd_device(snd_device); |
| 2084 | |
| 2085 | return ret_val; |
| 2086 | } |
| 2087 | |
| 2088 | //END: SPEAKER_PROTECTION ========================================================== |
| 2089 | |
| 2090 | //START: EXTERNAL_QDSP ================================================================ |
| 2091 | #ifdef __LP64__ |
| 2092 | #define EXTERNAL_QDSP_LIB_PATH "/vendor/lib64/libextqdsp.so" |
| 2093 | #else |
| 2094 | #define EXTERNAL_QDSP_LIB_PATH "/vendor/lib/libextqdsp.so" |
| 2095 | #endif |
| 2096 | |
| 2097 | static void *external_qdsp_lib_handle = NULL; |
| 2098 | |
| 2099 | typedef void (*external_qdsp_init_t)(void *); |
| 2100 | static external_qdsp_init_t external_qdsp_init; |
| 2101 | |
| 2102 | typedef void (*external_qdsp_deinit_t)(void); |
| 2103 | static external_qdsp_deinit_t external_qdsp_deinit; |
| 2104 | |
| 2105 | typedef bool (*external_qdsp_set_state_t)(struct audio_device *, |
| 2106 | int , float , bool); |
| 2107 | static external_qdsp_set_state_t external_qdsp_set_state; |
| 2108 | |
| 2109 | typedef void (*external_qdsp_set_device_t)(struct audio_usecase *); |
| 2110 | static external_qdsp_set_device_t external_qdsp_set_device; |
| 2111 | |
| 2112 | typedef void (*external_qdsp_set_parameter_t)(struct audio_device *, |
| 2113 | struct str_parms *); |
| 2114 | static external_qdsp_set_parameter_t external_qdsp_set_parameter; |
| 2115 | |
| 2116 | typedef bool (*external_qdsp_supported_usb_t)(void); |
| 2117 | static external_qdsp_supported_usb_t external_qdsp_supported_usb; |
| 2118 | |
| 2119 | void external_qdsp_feature_init(bool is_feature_enabled) |
| 2120 | { |
| 2121 | ALOGD("%s: Called with feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 2122 | if (is_feature_enabled) { |
| 2123 | //dlopen lib |
| 2124 | external_qdsp_lib_handle = dlopen(EXTERNAL_QDSP_LIB_PATH, RTLD_NOW); |
| 2125 | if (external_qdsp_lib_handle == NULL) { |
| 2126 | ALOGE("%s: dlopen failed", __func__); |
| 2127 | goto feature_disabled; |
| 2128 | } |
| 2129 | //map each function |
| 2130 | //on any faliure to map any function, disble feature |
| 2131 | if (((external_qdsp_init = |
| 2132 | (external_qdsp_init_t)dlsym(external_qdsp_lib_handle, "ma_init")) == NULL) || |
| 2133 | ((external_qdsp_deinit = |
| 2134 | (external_qdsp_deinit_t)dlsym(external_qdsp_lib_handle, "ma_deinit")) == NULL) || |
| 2135 | ((external_qdsp_set_state = |
| 2136 | (external_qdsp_set_state_t)dlsym(external_qdsp_lib_handle, "set_state")) == NULL) || |
| 2137 | ((external_qdsp_set_device = |
| 2138 | (external_qdsp_set_device_t)dlsym(external_qdsp_lib_handle, "set_device")) == NULL) || |
| 2139 | ((external_qdsp_set_parameter = |
| 2140 | (external_qdsp_set_parameter_t)dlsym(external_qdsp_lib_handle, "set_parameters")) == NULL) || |
| 2141 | ((external_qdsp_supported_usb = |
| 2142 | (external_qdsp_supported_usb_t)dlsym(external_qdsp_lib_handle, "supported_usb")) == NULL)) { |
| 2143 | ALOGE("%s: dlsym failed", __func__); |
| 2144 | goto feature_disabled; |
| 2145 | } |
| 2146 | |
| 2147 | ALOGD("%s:: ---- Feature EXTERNAL_QDSP is Enabled ----", __func__); |
| 2148 | return; |
| 2149 | } |
| 2150 | |
| 2151 | feature_disabled: |
| 2152 | if (external_qdsp_lib_handle) { |
| 2153 | dlclose(external_qdsp_lib_handle); |
| 2154 | external_qdsp_lib_handle = NULL; |
| 2155 | } |
| 2156 | |
| 2157 | external_qdsp_init = NULL; |
| 2158 | external_qdsp_deinit = NULL; |
| 2159 | external_qdsp_set_state = NULL; |
| 2160 | external_qdsp_set_device = NULL; |
| 2161 | external_qdsp_set_parameter = NULL; |
| 2162 | external_qdsp_supported_usb = NULL; |
| 2163 | |
| 2164 | ALOGW(":: %s: ---- Feature EXTERNAL_QDSP is disabled ----", __func__); |
| 2165 | return; |
| 2166 | } |
| 2167 | |
| 2168 | void audio_extn_qdsp_init(void *platform) { |
| 2169 | if (external_qdsp_init != NULL) |
| 2170 | external_qdsp_init(platform); |
| 2171 | |
| 2172 | return; |
| 2173 | } |
| 2174 | |
| 2175 | void audio_extn_qdsp_deinit() { |
| 2176 | if (external_qdsp_deinit != NULL) |
| 2177 | external_qdsp_deinit(); |
| 2178 | |
| 2179 | return; |
| 2180 | } |
| 2181 | |
| 2182 | bool audio_extn_qdsp_set_state(struct audio_device *adev, int stream_type, |
| 2183 | float vol, bool active) { |
| 2184 | bool ret_val = false; |
| 2185 | |
| 2186 | if (external_qdsp_set_state != NULL) |
| 2187 | ret_val = external_qdsp_set_state(adev, stream_type, vol, active); |
| 2188 | |
| 2189 | return ret_val; |
| 2190 | } |
| 2191 | |
| 2192 | void audio_extn_qdsp_set_device(struct audio_usecase *usecase) { |
| 2193 | if (external_qdsp_set_device != NULL) |
| 2194 | external_qdsp_set_device(usecase); |
| 2195 | |
| 2196 | return; |
| 2197 | } |
| 2198 | |
| 2199 | void audio_extn_qdsp_set_parameters(struct audio_device *adev, |
| 2200 | struct str_parms *parms) { |
| 2201 | if (external_qdsp_set_parameter != NULL) |
| 2202 | external_qdsp_set_parameter(adev, parms); |
| 2203 | |
| 2204 | return; |
| 2205 | } |
| 2206 | |
| 2207 | bool audio_extn_qdsp_supported_usb() { |
| 2208 | bool ret_val = false; |
| 2209 | |
| 2210 | if (external_qdsp_supported_usb != NULL) |
| 2211 | ret_val = external_qdsp_supported_usb(); |
| 2212 | |
| 2213 | return ret_val; |
| 2214 | } |
| 2215 | |
| 2216 | |
| 2217 | //END: EXTERNAL_QDSP ================================================================ |
| 2218 | |
| 2219 | //START: EXTERNAL_SPEAKER ================================================================ |
| 2220 | #ifdef __LP64__ |
| 2221 | #define EXTERNAL_SPKR_LIB_PATH "/vendor/lib64/libextspkr.so" |
| 2222 | #else |
| 2223 | #define EXTERNAL_SPKR_LIB_PATH "/vendor/lib/libextspkr.so" |
| 2224 | #endif |
| 2225 | |
| 2226 | static void *external_speaker_lib_handle = NULL; |
| 2227 | |
| 2228 | typedef void* (*external_speaker_init_t)(struct audio_device *); |
| 2229 | static external_speaker_init_t external_speaker_init; |
| 2230 | |
| 2231 | typedef void (*external_speaker_deinit_t)(void *); |
| 2232 | static external_speaker_deinit_t external_speaker_deinit; |
| 2233 | |
| 2234 | typedef void (*external_speaker_update_t)(void *); |
| 2235 | static external_speaker_update_t external_speaker_update; |
| 2236 | |
| 2237 | typedef void (*external_speaker_set_mode_t)(void *, audio_mode_t); |
| 2238 | static external_speaker_set_mode_t external_speaker_set_mode; |
| 2239 | |
| 2240 | typedef void (*external_speaker_set_voice_vol_t)(void *, float); |
| 2241 | static external_speaker_set_voice_vol_t external_speaker_set_voice_vol; |
| 2242 | |
| 2243 | |
| 2244 | void external_speaker_feature_init(bool is_feature_enabled) |
| 2245 | { |
| 2246 | ALOGD("%s: Called with feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 2247 | if (is_feature_enabled) { |
| 2248 | //dlopen lib |
| 2249 | external_speaker_lib_handle = dlopen(EXTERNAL_SPKR_LIB_PATH, RTLD_NOW); |
| 2250 | if (external_speaker_lib_handle == NULL) { |
| 2251 | ALOGE("%s: dlopen failed", __func__); |
| 2252 | goto feature_disabled; |
| 2253 | } |
| 2254 | //map each function |
| 2255 | //on any faliure to map any function, disble feature |
| 2256 | if (((external_speaker_init = |
| 2257 | (external_speaker_init_t)dlsym(external_speaker_lib_handle, "extspk_init")) == NULL) || |
| 2258 | ((external_speaker_deinit = |
| 2259 | (external_speaker_deinit_t)dlsym(external_speaker_lib_handle, "extspk_deinit")) == NULL) || |
| 2260 | ((external_speaker_update = |
| 2261 | (external_speaker_update_t)dlsym(external_speaker_lib_handle, "extspk_update")) == NULL) || |
| 2262 | ((external_speaker_set_mode = |
| 2263 | (external_speaker_set_mode_t)dlsym(external_speaker_lib_handle, "extspk_set_mode")) == NULL) || |
| 2264 | ((external_speaker_set_voice_vol = |
| 2265 | (external_speaker_set_voice_vol_t)dlsym(external_speaker_lib_handle, "extspk_set_voice_vol")) == NULL)) { |
| 2266 | ALOGE("%s: dlsym failed", __func__); |
| 2267 | goto feature_disabled; |
| 2268 | } |
| 2269 | |
| 2270 | ALOGD("%s:: ---- Feature EXTERNAL_SPKR is Enabled ----", __func__); |
| 2271 | return; |
| 2272 | } |
| 2273 | |
| 2274 | feature_disabled: |
| 2275 | if (external_speaker_lib_handle) { |
| 2276 | dlclose(external_speaker_lib_handle); |
| 2277 | external_speaker_lib_handle = NULL; |
| 2278 | } |
| 2279 | |
| 2280 | external_speaker_init = NULL; |
| 2281 | external_speaker_deinit = NULL; |
| 2282 | external_speaker_update = NULL; |
| 2283 | external_speaker_set_mode = NULL; |
| 2284 | external_speaker_set_voice_vol = NULL; |
| 2285 | |
| 2286 | ALOGW(":: %s: ---- Feature EXTERNAL_SPKR is disabled ----", __func__); |
| 2287 | return; |
| 2288 | } |
| 2289 | |
| 2290 | void *audio_extn_extspk_init(struct audio_device *adev) { |
| 2291 | void* ret_val = NULL; |
| 2292 | |
| 2293 | if (external_speaker_init != NULL) |
| 2294 | ret_val = external_speaker_init(adev); |
| 2295 | |
| 2296 | return ret_val; |
| 2297 | } |
| 2298 | |
| 2299 | void audio_extn_extspk_deinit(void *extn) { |
| 2300 | if (external_speaker_deinit != NULL) |
| 2301 | external_speaker_deinit(extn); |
| 2302 | |
| 2303 | return; |
| 2304 | } |
| 2305 | |
| 2306 | void audio_extn_extspk_update(void* extn) { |
| 2307 | if (external_speaker_update != NULL) |
| 2308 | external_speaker_update(extn); |
| 2309 | |
| 2310 | return; |
| 2311 | } |
| 2312 | |
| 2313 | void audio_extn_extspk_set_mode(void* extn, audio_mode_t mode) { |
| 2314 | if (external_speaker_set_mode != NULL) |
| 2315 | external_speaker_set_mode(extn, mode); |
| 2316 | |
| 2317 | return; |
| 2318 | } |
| 2319 | |
| 2320 | void audio_extn_extspk_set_voice_vol(void* extn, float vol) { |
| 2321 | if (external_speaker_set_voice_vol != NULL) |
| 2322 | external_speaker_set_voice_vol(extn, vol); |
| 2323 | |
| 2324 | return; |
| 2325 | } |
| 2326 | |
| 2327 | //END: EXTERNAL_SPEAKER ================================================================ |
| 2328 | |
| 2329 | |
| 2330 | //START: EXTERNAL_SPEAKER_TFA ================================================================ |
| 2331 | #ifdef __LP64__ |
| 2332 | #define EXTERNAL_SPKR_TFA_LIB_PATH "/vendor/lib64/libextspkr_tfa.so" |
| 2333 | #else |
| 2334 | #define EXTERNAL_SPKR_TFA_LIB_PATH "/vendor/lib/libextspkr_tfa.so" |
| 2335 | #endif |
| 2336 | |
| 2337 | static void *external_speaker_tfa_lib_handle = NULL; |
| 2338 | |
| 2339 | typedef int (*external_speaker_tfa_enable_t)(void); |
| 2340 | static external_speaker_tfa_enable_t external_speaker_tfa_enable; |
| 2341 | |
| 2342 | typedef void (*external_speaker_tfa_disable_t)(snd_device_t); |
| 2343 | static external_speaker_tfa_disable_t external_speaker_tfa_disable; |
| 2344 | |
| 2345 | typedef void (*external_speaker_tfa_set_mode_t)(); |
| 2346 | static external_speaker_tfa_set_mode_t external_speaker_tfa_set_mode; |
| 2347 | |
| 2348 | typedef void (*external_speaker_tfa_set_mode_bt_t)(); |
| 2349 | static external_speaker_tfa_set_mode_bt_t external_speaker_tfa_set_mode_bt; |
| 2350 | |
| 2351 | typedef void (*external_speaker_tfa_update_t)(void); |
| 2352 | static external_speaker_tfa_update_t external_speaker_tfa_update; |
| 2353 | |
| 2354 | typedef void (*external_speaker_tfa_set_voice_vol_t)(float); |
| 2355 | static external_speaker_tfa_set_voice_vol_t external_speaker_tfa_set_voice_vol; |
| 2356 | |
| 2357 | typedef int (*external_speaker_tfa_init_t)(struct audio_device *); |
| 2358 | static external_speaker_tfa_init_t external_speaker_tfa_init; |
| 2359 | |
| 2360 | typedef void (*external_speaker_tfa_deinit_t)(void); |
| 2361 | static external_speaker_tfa_deinit_t external_speaker_tfa_deinit; |
| 2362 | |
| 2363 | typedef bool (*external_speaker_tfa_is_supported_t)(void); |
| 2364 | static external_speaker_tfa_is_supported_t external_speaker_tfa_is_supported; |
| 2365 | |
| 2366 | void external_speaker_tfa_feature_init(bool is_feature_enabled) |
| 2367 | { |
| 2368 | ALOGD("%s: Called with feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 2369 | if (is_feature_enabled) { |
| 2370 | //dlopen lib |
| 2371 | external_speaker_tfa_lib_handle = dlopen(EXTERNAL_SPKR_TFA_LIB_PATH, RTLD_NOW); |
| 2372 | if (external_speaker_tfa_lib_handle == NULL) { |
| 2373 | ALOGE("%s: dlopen failed", __func__); |
| 2374 | goto feature_disabled; |
| 2375 | } |
| 2376 | //map each function |
| 2377 | //on any faliure to map any function, disble feature |
| 2378 | if (((external_speaker_tfa_enable = |
| 2379 | (external_speaker_tfa_enable_t)dlsym(external_speaker_tfa_lib_handle, "tfa_98xx_enable_speaker")) == NULL) || |
| 2380 | ((external_speaker_tfa_disable = |
| 2381 | (external_speaker_tfa_disable_t)dlsym(external_speaker_tfa_lib_handle, "tfa_98xx_disable_speaker")) == NULL) || |
| 2382 | ((external_speaker_tfa_set_mode = |
| 2383 | (external_speaker_tfa_set_mode_t)dlsym(external_speaker_tfa_lib_handle, "tfa_98xx_set_mode")) == NULL) || |
| 2384 | ((external_speaker_tfa_set_mode_bt = |
| 2385 | (external_speaker_tfa_set_mode_bt_t)dlsym(external_speaker_tfa_lib_handle, "tfa_98xx_set_mode_bt")) == NULL) || |
| 2386 | ((external_speaker_tfa_update = |
| 2387 | (external_speaker_tfa_update_t)dlsym(external_speaker_tfa_lib_handle, "tfa_98xx_update")) == NULL) || |
| 2388 | ((external_speaker_tfa_set_voice_vol = |
| 2389 | (external_speaker_tfa_set_voice_vol_t)dlsym(external_speaker_tfa_lib_handle, "tfa_98xx_set_voice_vol")) == NULL) || |
| 2390 | ((external_speaker_tfa_init = |
| 2391 | (external_speaker_tfa_init_t)dlsym(external_speaker_tfa_lib_handle, "tfa_98xx_init")) == NULL) || |
| 2392 | ((external_speaker_tfa_deinit = |
| 2393 | (external_speaker_tfa_deinit_t)dlsym(external_speaker_tfa_lib_handle, "tfa_98xx_deinit")) == NULL) || |
| 2394 | ((external_speaker_tfa_is_supported = |
| 2395 | (external_speaker_tfa_is_supported_t)dlsym(external_speaker_tfa_lib_handle, "tfa_98xx_is_supported")) == NULL)) { |
| 2396 | ALOGE("%s: dlsym failed", __func__); |
| 2397 | goto feature_disabled; |
| 2398 | } |
| 2399 | |
| 2400 | ALOGD("%s:: ---- Feature EXTERNAL_SPKR is Enabled ----", __func__); |
| 2401 | return; |
| 2402 | } |
| 2403 | |
| 2404 | feature_disabled: |
| 2405 | if (external_speaker_tfa_lib_handle) { |
| 2406 | dlclose(external_speaker_tfa_lib_handle); |
| 2407 | external_speaker_tfa_lib_handle = NULL; |
| 2408 | } |
| 2409 | |
| 2410 | external_speaker_tfa_enable = NULL; |
| 2411 | external_speaker_tfa_disable = NULL; |
| 2412 | external_speaker_tfa_set_mode = NULL; |
| 2413 | external_speaker_tfa_update = NULL; |
| 2414 | external_speaker_tfa_set_voice_vol = NULL; |
| 2415 | external_speaker_tfa_init = NULL; |
| 2416 | external_speaker_tfa_deinit = NULL; |
| 2417 | external_speaker_tfa_is_supported = NULL; |
| 2418 | |
| 2419 | ALOGW(":: %s: ---- Feature EXTERNAL_SPKR_TFA is disabled ----", __func__); |
| 2420 | return; |
| 2421 | } |
| 2422 | |
| 2423 | int audio_extn_external_speaker_tfa_enable_speaker() { |
| 2424 | int ret_val = 0; |
| 2425 | |
| 2426 | if (external_speaker_tfa_enable != NULL) |
| 2427 | ret_val = external_speaker_tfa_enable(); |
| 2428 | |
| 2429 | return ret_val; |
| 2430 | } |
| 2431 | |
| 2432 | void audio_extn_external_speaker_tfa_disable_speaker(snd_device_t snd_device) { |
| 2433 | if (external_speaker_tfa_disable != NULL) |
| 2434 | external_speaker_tfa_disable(snd_device); |
| 2435 | |
| 2436 | return; |
| 2437 | } |
| 2438 | |
| 2439 | void audio_extn_external_speaker_tfa_set_mode(bool is_mode_bt) { |
| 2440 | if (is_mode_bt && (external_speaker_tfa_set_mode_bt != NULL)) |
| 2441 | external_speaker_tfa_set_mode_bt(); |
| 2442 | else if (external_speaker_tfa_set_mode != NULL) |
| 2443 | external_speaker_tfa_set_mode(); |
| 2444 | |
| 2445 | return; |
| 2446 | } |
| 2447 | |
| 2448 | void audio_extn_external_speaker_tfa_update() { |
| 2449 | if (external_speaker_tfa_update != NULL) |
| 2450 | external_speaker_tfa_update(); |
| 2451 | |
| 2452 | return; |
| 2453 | } |
| 2454 | |
| 2455 | void audio_extn_external_speaker_tfa_set_voice_vol(float vol) { |
| 2456 | if (external_speaker_tfa_set_voice_vol != NULL) |
| 2457 | external_speaker_tfa_set_voice_vol(vol); |
| 2458 | |
| 2459 | return; |
| 2460 | } |
| 2461 | |
| 2462 | int audio_extn_external_tfa_speaker_init(struct audio_device *adev) { |
| 2463 | int ret_val = 0; |
| 2464 | |
| 2465 | if (external_speaker_tfa_init != NULL) |
| 2466 | ret_val = external_speaker_tfa_init(adev); |
| 2467 | |
| 2468 | return ret_val; |
| 2469 | } |
| 2470 | |
| 2471 | void audio_extn_external_speaker_tfa_deinit() { |
| 2472 | if (external_speaker_tfa_deinit != NULL) |
| 2473 | external_speaker_tfa_deinit(); |
| 2474 | |
| 2475 | return; |
| 2476 | } |
| 2477 | |
| 2478 | bool audio_extn_external_speaker_tfa_is_supported() { |
| 2479 | bool ret_val = false; |
| 2480 | |
| 2481 | if (external_speaker_tfa_is_supported != NULL) |
| 2482 | ret_val = external_speaker_tfa_is_supported; |
| 2483 | |
| 2484 | return ret_val; |
| 2485 | } |
| 2486 | |
| 2487 | |
| 2488 | //END: EXTERNAL_SPEAKER_TFA ================================================================ |
| 2489 | |
| 2490 | |
| 2491 | //START: HWDEP_CAL ================================================================ |
| 2492 | #ifdef __LP64__ |
| 2493 | #define HWDEP_CAL_LIB_PATH "/vendor/lib64/libhwdepcal.so" |
| 2494 | #else |
| 2495 | #define HWDEP_CAL_LIB_PATH "/vendor/lib/libhwdepcal.so" |
| 2496 | #endif |
| 2497 | |
| 2498 | static void *hwdep_cal_lib_handle = NULL; |
| 2499 | |
| 2500 | typedef void (*hwdep_cal_send_t)(int, void*); |
| 2501 | static hwdep_cal_send_t hwdep_cal_send; |
| 2502 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 2503 | |
| 2504 | //If feature is enabled, please copy hwdep_cal.c in the audio_extn dir |
| 2505 | //Current lib doesn't have any src files |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 2506 | void hwdep_cal_feature_init(bool is_feature_enabled) |
| 2507 | { |
| 2508 | ALOGD("%s: Called with feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 2509 | if (is_feature_enabled) { |
| 2510 | //dlopen lib |
| 2511 | hwdep_cal_lib_handle = dlopen(HWDEP_CAL_LIB_PATH, RTLD_NOW); |
| 2512 | if (hwdep_cal_lib_handle == NULL) { |
| 2513 | ALOGE("%s: dlopen failed", __func__); |
| 2514 | goto feature_disabled; |
| 2515 | } |
| 2516 | //map each function |
| 2517 | //on any faliure to map any function, disble feature |
| 2518 | if ((hwdep_cal_send = |
| 2519 | (hwdep_cal_send_t)dlsym(hwdep_cal_lib_handle, "hwdep_cal_send")) == NULL) { |
| 2520 | ALOGE("%s: dlsym failed", __func__); |
| 2521 | goto feature_disabled; |
| 2522 | } |
| 2523 | |
| 2524 | ALOGD("%s:: ---- Feature HWDEP_CAL is Enabled ----", __func__); |
| 2525 | return; |
| 2526 | } |
| 2527 | |
| 2528 | feature_disabled: |
| 2529 | if (hwdep_cal_lib_handle) { |
| 2530 | dlclose(hwdep_cal_lib_handle); |
| 2531 | hwdep_cal_lib_handle = NULL; |
| 2532 | } |
| 2533 | |
| 2534 | hwdep_cal_send = NULL; |
| 2535 | |
| 2536 | ALOGW(":: %s: ---- Feature HWDEP_CAL is disabled ----", __func__); |
| 2537 | return; |
| 2538 | } |
| 2539 | |
| 2540 | void audio_extn_hwdep_cal_send(int snd_card, void *acdb_handle) |
| 2541 | { |
| 2542 | if (hwdep_cal_send != NULL) |
| 2543 | hwdep_cal_send(snd_card, acdb_handle); |
| 2544 | |
| 2545 | return; |
| 2546 | } |
| 2547 | |
| 2548 | |
| 2549 | //END: HWDEP_CAL ===================================================================== |
| 2550 | |
| 2551 | |
| 2552 | //START: DSM_FEEDBACK ================================================================ |
| 2553 | #ifdef __LP64__ |
| 2554 | #define DSM_FEEDBACK_LIB_PATH "/vendor/lib64/libdsmfeedback.so" |
| 2555 | #else |
| 2556 | #define DSM_FEEDBACK_LIB_PATH "/vendor/lib/libdsmfeedback.so" |
| 2557 | #endif |
| 2558 | |
| 2559 | static void *dsm_feedback_lib_handle = NULL; |
| 2560 | |
| 2561 | typedef void (*dsm_feedback_enable_t)(struct audio_device*, snd_device_t, bool); |
| 2562 | static dsm_feedback_enable_t dsm_feedback_enable; |
| 2563 | |
| 2564 | void dsm_feedback_feature_init (bool is_feature_enabled) |
| 2565 | { |
| 2566 | ALOGD("%s: Called with feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 2567 | if (is_feature_enabled) { |
| 2568 | //dlopen lib |
| 2569 | dsm_feedback_lib_handle = dlopen(DSM_FEEDBACK_LIB_PATH, RTLD_NOW); |
| 2570 | if (dsm_feedback_lib_handle == NULL) { |
| 2571 | ALOGE("%s: dlopen failed", __func__); |
| 2572 | goto feature_disabled; |
| 2573 | } |
| 2574 | //map each function |
| 2575 | //on any faliure to map any function, disble feature |
| 2576 | if ((dsm_feedback_enable = |
| 2577 | (dsm_feedback_enable_t)dlsym(dsm_feedback_lib_handle, "dsm_feedback_enable")) == NULL) { |
| 2578 | ALOGE("%s: dlsym failed", __func__); |
| 2579 | goto feature_disabled; |
| 2580 | } |
| 2581 | |
| 2582 | ALOGD("%s:: ---- Feature DSM_FEEDBACK is Enabled ----", __func__); |
| 2583 | return; |
| 2584 | } |
| 2585 | |
| 2586 | feature_disabled: |
| 2587 | if (dsm_feedback_lib_handle) { |
| 2588 | dlclose(dsm_feedback_lib_handle); |
| 2589 | dsm_feedback_lib_handle = NULL; |
| 2590 | } |
| 2591 | |
| 2592 | dsm_feedback_enable = NULL; |
| 2593 | |
| 2594 | ALOGW(":: %s: ---- Feature DSM_FEEDBACK is disabled ----", __func__); |
| 2595 | return; |
| 2596 | } |
| 2597 | |
| 2598 | void audio_extn_dsm_feedback_enable(struct audio_device *adev, snd_device_t snd_device, bool benable) |
| 2599 | { |
| 2600 | if (dsm_feedback_enable != NULL) |
| 2601 | dsm_feedback_enable(adev, snd_device, benable); |
| 2602 | |
| 2603 | return; |
| 2604 | } |
| 2605 | |
| 2606 | //END: DSM_FEEDBACK ================================================================ |
| 2607 | |
| 2608 | //START: SND_MONITOR_FEATURE ================================================================ |
| 2609 | #ifdef __LP64__ |
| 2610 | #define SND_MONITOR_PATH "/vendor/lib64/libsndmonitor.so" |
| 2611 | #else |
| 2612 | #define SND_MONITOR_PATH "/vendor/lib/libsndmonitor.so" |
| 2613 | #endif |
| 2614 | static void *snd_mnt_lib_handle = NULL; |
| 2615 | |
| 2616 | typedef int (*snd_mon_init_t)(); |
| 2617 | static snd_mon_init_t snd_mon_init; |
| 2618 | typedef int (*snd_mon_deinit_t)(); |
| 2619 | static snd_mon_deinit_t snd_mon_deinit; |
| 2620 | typedef int (*snd_mon_register_listener_t)(void *, snd_mon_cb); |
| 2621 | static snd_mon_register_listener_t snd_mon_register_listener; |
| 2622 | typedef int (*snd_mon_unregister_listener_t)(void *); |
| 2623 | static snd_mon_unregister_listener_t snd_mon_unregister_listener; |
| 2624 | |
| 2625 | void snd_mon_feature_init (bool is_feature_enabled) |
| 2626 | { |
| 2627 | ALOGD("%s: Called with feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 2628 | if (is_feature_enabled) { |
| 2629 | //dlopen lib |
| 2630 | snd_mnt_lib_handle = dlopen(SND_MONITOR_PATH, RTLD_NOW); |
| 2631 | if (snd_mnt_lib_handle == NULL) { |
| 2632 | ALOGE("%s: dlopen failed", __func__); |
| 2633 | goto feature_disabled; |
| 2634 | } |
| 2635 | //map each function |
| 2636 | //on any faliure to map any function, disble feature |
| 2637 | if (((snd_mon_init = (snd_mon_init_t)dlsym(snd_mnt_lib_handle,"snd_mon_init")) == NULL) || |
| 2638 | ((snd_mon_deinit = (snd_mon_deinit_t)dlsym(snd_mnt_lib_handle,"snd_mon_deinit")) == NULL) || |
| 2639 | ((snd_mon_register_listener = (snd_mon_register_listener_t)dlsym(snd_mnt_lib_handle,"snd_mon_register_listener")) == NULL) || |
| 2640 | ((snd_mon_unregister_listener = (snd_mon_unregister_listener_t)dlsym(snd_mnt_lib_handle,"snd_mon_unregister_listener")) == NULL)) { |
| 2641 | ALOGE("%s: dlsym failed", __func__); |
| 2642 | goto feature_disabled; |
| 2643 | } |
| 2644 | ALOGD("%s:: ---- Feature SND_MONITOR is Enabled ----", __func__); |
| 2645 | return; |
| 2646 | } |
| 2647 | |
| 2648 | feature_disabled: |
| 2649 | if (snd_mnt_lib_handle) { |
| 2650 | dlclose(snd_mnt_lib_handle); |
| 2651 | snd_mnt_lib_handle = NULL; |
| 2652 | } |
| 2653 | |
| 2654 | snd_mon_init = NULL; |
| 2655 | snd_mon_deinit = NULL; |
| 2656 | snd_mon_register_listener = NULL; |
| 2657 | snd_mon_unregister_listener = NULL; |
| 2658 | ALOGW(":: %s: ---- Feature SND_MONITOR is disabled ----", __func__); |
| 2659 | return; |
| 2660 | } |
| 2661 | |
| 2662 | int audio_extn_snd_mon_init() |
| 2663 | { |
| 2664 | int ret = 0; |
| 2665 | if (snd_mon_init != NULL) |
| 2666 | ret = snd_mon_init(); |
| 2667 | |
| 2668 | return ret; |
| 2669 | } |
| 2670 | |
| 2671 | int audio_extn_snd_mon_deinit() |
| 2672 | { |
| 2673 | int ret = 0; |
| 2674 | if (snd_mon_deinit != NULL) |
| 2675 | ret = snd_mon_deinit(); |
| 2676 | |
| 2677 | return ret; |
| 2678 | } |
| 2679 | |
| 2680 | int audio_extn_snd_mon_register_listener(void *stream, snd_mon_cb cb) |
| 2681 | { |
| 2682 | int ret = 0; |
| 2683 | if (snd_mon_register_listener != NULL) |
| 2684 | ret = snd_mon_register_listener(stream, cb); |
| 2685 | |
| 2686 | return ret; |
| 2687 | } |
| 2688 | |
| 2689 | int audio_extn_snd_mon_unregister_listener(void *stream) |
| 2690 | { |
| 2691 | int ret = 0; |
| 2692 | if (snd_mon_unregister_listener != NULL) |
| 2693 | ret = snd_mon_unregister_listener(stream); |
| 2694 | |
| 2695 | return ret; |
| 2696 | } |
| 2697 | |
| 2698 | //END: SND_MONITOR_FEATURE ================================================================ |
| 2699 | |
| 2700 | //START: SOURCE_TRACKING_FEATURE ============================================== |
| 2701 | int get_soundfocus_data(const struct audio_device *adev, |
| 2702 | struct sound_focus_param *payload); |
| 2703 | int get_sourcetrack_data(const struct audio_device *adev, |
| 2704 | struct source_tracking_param *payload); |
| 2705 | int set_soundfocus_data(struct audio_device *adev, |
| 2706 | struct sound_focus_param *payload); |
| 2707 | void source_track_set_parameters(struct audio_device *adev, |
| 2708 | struct str_parms *parms); |
| 2709 | void source_track_get_parameters(const struct audio_device *adev, |
| 2710 | struct str_parms *query, |
| 2711 | struct str_parms *reply); |
| 2712 | |
| 2713 | static bool is_src_trkn_enabled = false; |
| 2714 | |
| 2715 | void src_trkn_feature_init(bool is_feature_enabled) { |
| 2716 | is_src_trkn_enabled = is_feature_enabled; |
| 2717 | |
| 2718 | if (is_src_trkn_enabled) { |
| 2719 | ALOGD("%s:: ---- Feature SOURCE_TRACKING is Enabled ----", __func__); |
| 2720 | return; |
| 2721 | } |
| 2722 | |
| 2723 | ALOGW(":: %s: ---- Feature SOURCE_TRACKING is disabled ----", __func__); |
| 2724 | } |
| 2725 | |
| 2726 | int audio_extn_get_soundfocus_data(const struct audio_device *adev, |
| 2727 | struct sound_focus_param *payload) { |
| 2728 | int ret = 0; |
| 2729 | |
| 2730 | if (is_src_trkn_enabled) |
| 2731 | ret = get_soundfocus_data(adev, payload); |
| 2732 | |
| 2733 | return ret; |
| 2734 | } |
| 2735 | |
| 2736 | int audio_extn_get_sourcetrack_data(const struct audio_device *adev, |
| 2737 | struct source_tracking_param *payload) { |
| 2738 | int ret = 0; |
| 2739 | |
| 2740 | if (is_src_trkn_enabled) |
| 2741 | ret = get_sourcetrack_data(adev, payload); |
| 2742 | |
| 2743 | return ret; |
| 2744 | } |
| 2745 | |
| 2746 | int audio_extn_set_soundfocus_data(struct audio_device *adev, |
| 2747 | struct sound_focus_param *payload) { |
| 2748 | int ret = 0; |
| 2749 | |
| 2750 | if (is_src_trkn_enabled) |
| 2751 | ret = set_soundfocus_data(adev, payload); |
| 2752 | |
| 2753 | return ret; |
| 2754 | } |
| 2755 | |
| 2756 | void audio_extn_source_track_set_parameters(struct audio_device *adev, |
| 2757 | struct str_parms *parms) { |
| 2758 | if (is_src_trkn_enabled) |
| 2759 | source_track_set_parameters(adev, parms); |
| 2760 | } |
| 2761 | |
| 2762 | void audio_extn_source_track_get_parameters(const struct audio_device *adev, |
| 2763 | struct str_parms *query, |
| 2764 | struct str_parms *reply) { |
| 2765 | if (is_src_trkn_enabled) |
| 2766 | source_track_get_parameters(adev, query, reply); |
| 2767 | } |
| 2768 | //END: SOURCE_TRACKING_FEATURE ================================================ |
| 2769 | |
| 2770 | //START: SSREC_FEATURE ========================================================== |
| 2771 | #ifdef __LP64__ |
| 2772 | #define SSREC_LIB_PATH "/vendor/lib64/libssrec.so" |
| 2773 | #else |
| 2774 | #define SSREC_LIB_PATH "/vendor/lib/libssrec.so" |
| 2775 | #endif |
| 2776 | |
| 2777 | static void *ssrec_lib_handle = NULL; |
| 2778 | |
| 2779 | typedef bool (*ssr_check_usecase_t)(struct stream_in *); |
| 2780 | static ssr_check_usecase_t ssr_check_usecase; |
| 2781 | |
| 2782 | typedef int (*ssr_set_usecase_t)(struct stream_in *, |
| 2783 | struct audio_config *, |
| 2784 | bool *); |
| 2785 | static ssr_set_usecase_t ssr_set_usecase; |
| 2786 | |
| 2787 | typedef int32_t (*ssr_init_t)(struct stream_in *, |
| 2788 | int num_out_chan); |
| 2789 | static ssr_init_t ssr_init; |
| 2790 | |
| 2791 | typedef int32_t (*ssr_deinit_t)(); |
| 2792 | static ssr_deinit_t ssr_deinit; |
| 2793 | |
| 2794 | typedef void (*ssr_update_enabled_t)(); |
| 2795 | static ssr_update_enabled_t ssr_update_enabled; |
| 2796 | |
| 2797 | typedef bool (*ssr_get_enabled_t)(); |
| 2798 | static ssr_get_enabled_t ssr_get_enabled; |
| 2799 | |
| 2800 | typedef int32_t (*ssr_read_t)(struct audio_stream_in *, |
| 2801 | void *, |
| 2802 | size_t); |
| 2803 | static ssr_read_t ssr_read; |
| 2804 | |
| 2805 | typedef void (*ssr_set_parameters_t)(struct audio_device *, |
| 2806 | struct str_parms *); |
| 2807 | static ssr_set_parameters_t ssr_set_parameters; |
| 2808 | |
| 2809 | typedef void (*ssr_get_parameters_t)(const struct audio_device *, |
| 2810 | struct str_parms *, |
| 2811 | struct str_parms *); |
| 2812 | static ssr_get_parameters_t ssr_get_parameters; |
| 2813 | |
| 2814 | typedef struct stream_in *(*ssr_get_stream_t)(); |
| 2815 | static ssr_get_stream_t ssr_get_stream; |
| 2816 | |
| 2817 | void ssrec_feature_init(bool is_feature_enabled) { |
| 2818 | |
| 2819 | if (is_feature_enabled) { |
| 2820 | ssrec_lib_handle = dlopen(SSREC_LIB_PATH, RTLD_NOW); |
| 2821 | if (ssrec_lib_handle == NULL) { |
| 2822 | ALOGE("%s: dlopen failed", __func__); |
| 2823 | goto feature_disabled; |
| 2824 | } |
| 2825 | |
| 2826 | if (((ssr_check_usecase = (ssr_check_usecase_t)dlsym(ssrec_lib_handle, "ssr_check_usecase")) == NULL) || |
| 2827 | ((ssr_set_usecase = (ssr_set_usecase_t)dlsym(ssrec_lib_handle, "ssr_set_usecase")) == NULL) || |
| 2828 | ((ssr_init = (ssr_init_t)dlsym(ssrec_lib_handle, "ssr_init")) == NULL) || |
| 2829 | ((ssr_deinit = (ssr_deinit_t)dlsym(ssrec_lib_handle, "ssr_deinit")) == NULL) || |
| 2830 | ((ssr_update_enabled = (ssr_update_enabled_t)dlsym(ssrec_lib_handle, "ssr_update_enabled")) == NULL) || |
| 2831 | ((ssr_get_enabled = (ssr_get_enabled_t)dlsym(ssrec_lib_handle, "ssr_get_enabled")) == NULL) || |
| 2832 | ((ssr_read = (ssr_read_t)dlsym(ssrec_lib_handle, "ssr_read")) == NULL) || |
| 2833 | ((ssr_set_parameters = (ssr_set_parameters_t)dlsym(ssrec_lib_handle, "ssr_set_parameters")) == NULL) || |
| 2834 | ((ssr_get_parameters = (ssr_get_parameters_t)dlsym(ssrec_lib_handle, "ssr_get_parameters")) == NULL) || |
| 2835 | ((ssr_get_stream = (ssr_get_stream_t)dlsym(ssrec_lib_handle, "ssr_get_stream")) == NULL)) { |
| 2836 | ALOGE("%s: dlsym failed", __func__); |
| 2837 | goto feature_disabled; |
| 2838 | } |
| 2839 | |
| 2840 | ALOGD("%s:: ---- Feature SSREC is Enabled ----", __func__); |
| 2841 | return; |
| 2842 | } |
| 2843 | |
| 2844 | feature_disabled: |
| 2845 | if(ssrec_lib_handle) { |
| 2846 | dlclose(ssrec_lib_handle); |
| 2847 | ssrec_lib_handle = NULL; |
| 2848 | } |
| 2849 | |
| 2850 | ssr_check_usecase = NULL; |
| 2851 | ssr_set_usecase = NULL; |
| 2852 | ssr_init = NULL; |
| 2853 | ssr_deinit = NULL; |
| 2854 | ssr_update_enabled = NULL; |
| 2855 | ssr_get_enabled = NULL; |
| 2856 | ssr_read = NULL; |
| 2857 | ssr_set_parameters = NULL; |
| 2858 | ssr_get_parameters = NULL; |
| 2859 | ssr_get_stream = NULL; |
| 2860 | |
| 2861 | ALOGW(":: %s: ---- Feature SSREC is disabled ----", __func__); |
| 2862 | } |
| 2863 | |
| 2864 | bool audio_extn_ssr_check_usecase(struct stream_in *in) { |
| 2865 | bool ret = false; |
| 2866 | |
| 2867 | if (ssrec_lib_handle != NULL) |
| 2868 | ret = ssr_check_usecase(in); |
| 2869 | |
| 2870 | return ret; |
| 2871 | } |
| 2872 | |
| 2873 | int audio_extn_ssr_set_usecase(struct stream_in *in, |
| 2874 | struct audio_config *config, |
| 2875 | bool *channel_mask_updated) { |
| 2876 | int ret = 0; |
| 2877 | |
| 2878 | if (ssrec_lib_handle != NULL) |
| 2879 | ret = ssr_set_usecase(in, config, channel_mask_updated); |
| 2880 | |
| 2881 | return ret; |
| 2882 | } |
| 2883 | |
| 2884 | int32_t audio_extn_ssr_init(struct stream_in *in, |
| 2885 | int num_out_chan) { |
| 2886 | int32_t ret = 0; |
| 2887 | |
| 2888 | if (ssrec_lib_handle != NULL) |
| 2889 | ret = ssr_init(in, num_out_chan); |
| 2890 | |
| 2891 | return ret; |
| 2892 | } |
| 2893 | |
| 2894 | int32_t audio_extn_ssr_deinit() { |
| 2895 | int32_t ret = 0; |
| 2896 | |
| 2897 | if (ssrec_lib_handle != NULL) |
| 2898 | ret = ssr_deinit(); |
| 2899 | |
| 2900 | return ret; |
| 2901 | } |
| 2902 | |
| 2903 | void audio_extn_ssr_update_enabled() { |
| 2904 | |
| 2905 | if (ssrec_lib_handle) |
| 2906 | ssr_update_enabled(); |
| 2907 | } |
| 2908 | |
| 2909 | bool audio_extn_ssr_get_enabled() { |
| 2910 | bool ret = false; |
| 2911 | |
| 2912 | if (ssrec_lib_handle) |
| 2913 | ret = ssr_get_enabled(); |
| 2914 | |
| 2915 | return ret; |
| 2916 | } |
| 2917 | |
| 2918 | int32_t audio_extn_ssr_read(struct audio_stream_in *stream, |
| 2919 | void *buffer, |
| 2920 | size_t bytes) { |
| 2921 | int32_t ret = 0; |
| 2922 | |
| 2923 | if (ssrec_lib_handle) |
| 2924 | ret = ssr_read(stream, buffer, bytes); |
| 2925 | |
| 2926 | return ret; |
| 2927 | } |
| 2928 | |
| 2929 | void audio_extn_ssr_set_parameters(struct audio_device *adev, |
| 2930 | struct str_parms *parms) { |
| 2931 | |
| 2932 | if (ssrec_lib_handle) |
| 2933 | ssr_set_parameters(adev, parms); |
| 2934 | } |
| 2935 | |
| 2936 | void audio_extn_ssr_get_parameters(const struct audio_device *adev, |
| 2937 | struct str_parms *query, |
| 2938 | struct str_parms *reply) { |
| 2939 | |
| 2940 | if (ssrec_lib_handle) |
| 2941 | ssr_get_parameters(adev, query, reply); |
| 2942 | } |
| 2943 | |
| 2944 | struct stream_in *audio_extn_ssr_get_stream() { |
| 2945 | struct stream_in *ret = NULL; |
| 2946 | |
| 2947 | if (ssrec_lib_handle) |
| 2948 | ret = ssr_get_stream(); |
| 2949 | |
| 2950 | return ret; |
| 2951 | } |
| 2952 | //END: SSREC_FEATURE ============================================================ |
| 2953 | |
| 2954 | //START: COMPRESS_CAPTURE_FEATURE ================================================================ |
| 2955 | #ifdef __LP64__ |
| 2956 | #define COMPRESS_CAPTURE_PATH "/vendor/lib64/libcomprcapture.so" |
| 2957 | #else |
| 2958 | #define COMPRESS_CAPTURE_PATH "/vendor/lib/libcomprcapture.so" |
| 2959 | #endif |
| 2960 | static void *compr_cap_lib_handle = NULL; |
| 2961 | |
| 2962 | typedef void (*compr_cap_init_t)(struct stream_in*); |
| 2963 | static compr_cap_init_t compr_cap_init; |
| 2964 | |
| 2965 | typedef void (*compr_cap_deinit_t)(); |
| 2966 | static compr_cap_deinit_t compr_cap_deinit; |
| 2967 | |
| 2968 | typedef bool (*compr_cap_enabled_t)(); |
| 2969 | static compr_cap_enabled_t compr_cap_enabled; |
| 2970 | |
| 2971 | typedef bool (*compr_cap_format_supported_t)(audio_format_t); |
| 2972 | static compr_cap_format_supported_t compr_cap_format_supported; |
| 2973 | |
| 2974 | typedef bool (*compr_cap_usecase_supported_t)(audio_usecase_t); |
| 2975 | static compr_cap_usecase_supported_t compr_cap_usecase_supported; |
| 2976 | |
| 2977 | typedef size_t (*compr_cap_get_buffer_size_t)(audio_usecase_t); |
| 2978 | static compr_cap_get_buffer_size_t compr_cap_get_buffer_size; |
| 2979 | |
| 2980 | typedef int (*compr_cap_read_t)(struct stream_in*, void*, size_t); |
| 2981 | static compr_cap_read_t compr_cap_read; |
| 2982 | |
| 2983 | void compr_cap_feature_init(bool is_feature_enabled) |
| 2984 | { |
| 2985 | if(is_feature_enabled) { |
| 2986 | //dlopen lib |
| 2987 | compr_cap_lib_handle = dlopen(COMPRESS_CAPTURE_PATH, RTLD_NOW); |
| 2988 | if (compr_cap_lib_handle == NULL) { |
| 2989 | ALOGE("%s: dlopen failed", __func__); |
| 2990 | goto feature_disabled; |
| 2991 | } |
| 2992 | //map each function |
| 2993 | //on any faliure to map any function, disble feature |
| 2994 | if (((compr_cap_init = (compr_cap_init_t)dlsym(compr_cap_lib_handle,"compr_cap_init")) == NULL) || |
| 2995 | ((compr_cap_deinit = (compr_cap_deinit_t)dlsym(compr_cap_lib_handle,"compr_cap_deinit")) == NULL) || |
| 2996 | ((compr_cap_enabled = (compr_cap_enabled_t)dlsym(compr_cap_lib_handle,"compr_cap_enabled")) == NULL) || |
| 2997 | ((compr_cap_format_supported = (compr_cap_format_supported_t)dlsym(compr_cap_lib_handle,"compr_cap_format_supported")) == NULL) || |
| 2998 | ((compr_cap_usecase_supported = (compr_cap_usecase_supported_t)dlsym(compr_cap_lib_handle,"compr_cap_usecase_supported")) == NULL) || |
| 2999 | ((compr_cap_get_buffer_size = (compr_cap_get_buffer_size_t)dlsym(compr_cap_lib_handle,"compr_cap_get_buffer_size")) == NULL) || |
| 3000 | ((compr_cap_read = (compr_cap_read_t)dlsym(compr_cap_lib_handle,"compr_cap_read")) == NULL)) { |
| 3001 | ALOGE("%s: dlsym failed", __func__); |
| 3002 | goto feature_disabled; |
| 3003 | } |
| 3004 | |
| 3005 | ALOGD("%s:: ---- Feature COMPRESS_CAPTURE is Enabled ----", __func__); |
| 3006 | return; |
| 3007 | } |
| 3008 | |
| 3009 | feature_disabled: |
| 3010 | if (compr_cap_lib_handle) { |
| 3011 | dlclose(compr_cap_lib_handle); |
| 3012 | compr_cap_lib_handle = NULL; |
| 3013 | } |
| 3014 | |
| 3015 | compr_cap_init = NULL; |
| 3016 | compr_cap_deinit = NULL; |
| 3017 | compr_cap_enabled = NULL; |
| 3018 | compr_cap_format_supported = NULL; |
| 3019 | compr_cap_usecase_supported = NULL; |
| 3020 | compr_cap_get_buffer_size = NULL; |
| 3021 | compr_cap_read = NULL; |
| 3022 | |
| 3023 | ALOGW(":: %s: ---- Feature COMPRESS_CAPTURE is disabled ----", __func__); |
| 3024 | return; |
| 3025 | } |
| 3026 | |
| 3027 | void audio_extn_compr_cap_init(struct stream_in* instream) |
| 3028 | { |
| 3029 | if (compr_cap_init != NULL) |
| 3030 | compr_cap_init(instream); |
| 3031 | |
| 3032 | return; |
| 3033 | } |
| 3034 | |
| 3035 | void audio_extn_compr_cap_deinit() |
| 3036 | { |
| 3037 | if(compr_cap_deinit) |
| 3038 | compr_cap_deinit(); |
| 3039 | |
| 3040 | return; |
| 3041 | } |
| 3042 | |
| 3043 | bool audio_extn_compr_cap_enabled() |
| 3044 | { |
| 3045 | bool ret_val = false; |
| 3046 | |
| 3047 | if (compr_cap_enabled) |
| 3048 | ret_val = compr_cap_enabled(); |
| 3049 | |
| 3050 | return ret_val; |
| 3051 | } |
| 3052 | |
| 3053 | bool audio_extn_compr_cap_format_supported(audio_format_t format) |
| 3054 | { |
| 3055 | bool ret_val = false; |
| 3056 | |
| 3057 | if (compr_cap_format_supported != NULL) |
| 3058 | ret_val = compr_cap_format_supported(format); |
| 3059 | |
| 3060 | return ret_val; |
| 3061 | } |
| 3062 | |
| 3063 | bool audio_extn_compr_cap_usecase_supported(audio_usecase_t usecase) |
| 3064 | { |
| 3065 | bool ret_val = false; |
| 3066 | |
| 3067 | if (compr_cap_usecase_supported != NULL) |
| 3068 | ret_val = compr_cap_usecase_supported(usecase); |
| 3069 | |
| 3070 | return ret_val; |
| 3071 | } |
| 3072 | |
| 3073 | size_t audio_extn_compr_cap_get_buffer_size(audio_format_t format) |
| 3074 | { |
| 3075 | size_t ret_val = 0; |
| 3076 | |
| 3077 | if (compr_cap_get_buffer_size != NULL) |
| 3078 | ret_val = compr_cap_get_buffer_size(format); |
| 3079 | |
| 3080 | return ret_val; |
| 3081 | } |
| 3082 | |
| 3083 | size_t audio_extn_compr_cap_read(struct stream_in *in, |
| 3084 | void *buffer, size_t bytes) |
| 3085 | { |
| 3086 | size_t ret_val = 0; |
| 3087 | |
| 3088 | if (compr_cap_read != NULL) |
| 3089 | ret_val = compr_cap_read(in, buffer, bytes); |
| 3090 | |
| 3091 | return ret_val; |
| 3092 | } |
| 3093 | |
| 3094 | |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 3095 | void audio_extn_init(struct audio_device *adev) |
Dhanalakshmi Siddani | 0b1488e | 2016-09-06 12:58:42 +0530 | [diff] [blame] | 3096 | { |
| 3097 | aextnmod.anc_enabled = 0; |
| 3098 | aextnmod.aanc_enabled = 0; |
| 3099 | aextnmod.custom_stereo_enabled = 0; |
| 3100 | aextnmod.proxy_channel_num = 2; |
| 3101 | aextnmod.hpx_enabled = 0; |
| 3102 | aextnmod.vbat_enabled = 0; |
Aditya Bavanari | 9b58902 | 2018-09-20 08:47:55 +0530 | [diff] [blame] | 3103 | aextnmod.bcl_enabled = 0; |
Dhanalakshmi Siddani | 0b1488e | 2016-09-06 12:58:42 +0530 | [diff] [blame] | 3104 | aextnmod.hifi_audio_enabled = 0; |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 3105 | aextnmod.addr.nap = 0; |
| 3106 | aextnmod.addr.uap = 0; |
| 3107 | aextnmod.addr.lap = 0; |
Aalique Grahame | 404a15e | 2017-05-18 11:28:27 -0700 | [diff] [blame] | 3108 | aextnmod.adev = adev; |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 3109 | |
| 3110 | audio_extn_dolby_set_license(adev); |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 3111 | audio_extn_aptx_dec_set_license(adev); |
Dhanalakshmi Siddani | 0b1488e | 2016-09-06 12:58:42 +0530 | [diff] [blame] | 3112 | } |
| 3113 | |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3114 | #ifdef AUDIO_GKI_ENABLED |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3115 | static int get_wma_dec_info(struct stream_out *out, struct str_parms *parms) { |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3116 | int ret = 0; |
| 3117 | char value[32]; |
| 3118 | |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3119 | struct snd_generic_dec_wma *wma_dec = NULL; |
| 3120 | |
| 3121 | /* reserved[0] will contain the WMA decoder type */ |
| 3122 | if (out->format == AUDIO_FORMAT_WMA) { |
| 3123 | out->compr_config.codec->options.generic.reserved[0] = AUDIO_COMP_FORMAT_WMA; |
| 3124 | } else if (out->format == AUDIO_FORMAT_WMA_PRO) { |
| 3125 | out->compr_config.codec->options.generic.reserved[0] = AUDIO_COMP_FORMAT_WMA_PRO; |
| 3126 | } else { |
| 3127 | ALOGE("%s: unknown WMA format 0x%x\n", __func__, out->format); |
| 3128 | return -EINVAL; |
| 3129 | } |
| 3130 | |
| 3131 | /* reserved[1] onwards will contain the WMA decoder format info */ |
| 3132 | wma_dec = (struct snd_generic_dec_wma *) |
| 3133 | &(out->compr_config.codec->options.generic.reserved[1]); |
| 3134 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE, |
| 3135 | value, sizeof(value)); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3136 | if (ret >= 0) { |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3137 | wma_dec->avg_bit_rate = atoi(value); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3138 | out->is_compr_metadata_avail = true; |
| 3139 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3140 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_BLOCK_ALIGN, |
| 3141 | value, sizeof(value)); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3142 | if (ret >= 0) { |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3143 | wma_dec->super_block_align = atoi(value); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3144 | out->is_compr_metadata_avail = true; |
| 3145 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3146 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_BIT_PER_SAMPLE, |
| 3147 | value, sizeof(value)); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3148 | if (ret >= 0) { |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3149 | wma_dec->bits_per_sample = atoi(value); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3150 | out->is_compr_metadata_avail = true; |
| 3151 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3152 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_CHANNEL_MASK, |
| 3153 | value, sizeof(value)); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3154 | if (ret >= 0) { |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3155 | wma_dec->channelmask = atoi(value); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3156 | out->is_compr_metadata_avail = true; |
| 3157 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3158 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_ENCODE_OPTION, |
| 3159 | value, sizeof(value)); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3160 | if (ret >= 0) { |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3161 | wma_dec->encodeopt = atoi(value); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3162 | out->is_compr_metadata_avail = true; |
| 3163 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3164 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_ENCODE_OPTION1, |
| 3165 | value, sizeof(value)); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3166 | if (ret >= 0) { |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3167 | wma_dec->encodeopt1 = atoi(value); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3168 | out->is_compr_metadata_avail = true; |
| 3169 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3170 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_ENCODE_OPTION2, |
| 3171 | value, sizeof(value)); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3172 | if (ret >= 0) { |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3173 | wma_dec->encodeopt2 = atoi(value); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3174 | out->is_compr_metadata_avail = true; |
| 3175 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3176 | |
| 3177 | ALOGV("WMA params: fmt 0x%x, id 0x%x, WMA type 0x%x, bit rate 0x%x," |
| 3178 | " balgn 0x%x, sr %d, chmsk 0x%x" |
| 3179 | " encop 0x%x, op1 0x%x, op2 0x%x \n", |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3180 | out->compr_config.codec->format, |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3181 | out->compr_config.codec->id, |
| 3182 | out->compr_config.codec->options.generic.reserved[0], |
| 3183 | wma_dec->avg_bit_rate, |
| 3184 | wma_dec->super_block_align, |
| 3185 | wma_dec->bits_per_sample, |
| 3186 | wma_dec->channelmask, |
| 3187 | wma_dec->encodeopt, |
| 3188 | wma_dec->encodeopt1, |
| 3189 | wma_dec->encodeopt2); |
Meng Wang | 4c32fb4 | 2020-01-16 17:57:11 +0800 | [diff] [blame] | 3190 | |
| 3191 | return ret; |
| 3192 | } |
| 3193 | #else |
| 3194 | int get_wma_info(struct stream_out *out, struct str_parms *parms) { |
| 3195 | int ret = 0; |
| 3196 | char value[32]; |
| 3197 | |
| 3198 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE, value, sizeof(value)); |
| 3199 | if (ret >= 0) { |
| 3200 | out->compr_config.codec->options.wma.avg_bit_rate = atoi(value); |
| 3201 | out->is_compr_metadata_avail = true; |
| 3202 | } |
| 3203 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_BLOCK_ALIGN, value, sizeof(value)); |
| 3204 | if (ret >= 0) { |
| 3205 | out->compr_config.codec->options.wma.super_block_align = atoi(value); |
| 3206 | out->is_compr_metadata_avail = true; |
| 3207 | } |
| 3208 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_BIT_PER_SAMPLE, value, sizeof(value)); |
| 3209 | if (ret >= 0) { |
| 3210 | out->compr_config.codec->options.wma.bits_per_sample = atoi(value); |
| 3211 | out->is_compr_metadata_avail = true; |
| 3212 | } |
| 3213 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_CHANNEL_MASK, value, sizeof(value)); |
| 3214 | if (ret >= 0) { |
| 3215 | out->compr_config.codec->options.wma.channelmask = atoi(value); |
| 3216 | out->is_compr_metadata_avail = true; |
| 3217 | } |
| 3218 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_ENCODE_OPTION, value, sizeof(value)); |
| 3219 | if (ret >= 0) { |
| 3220 | out->compr_config.codec->options.wma.encodeopt = atoi(value); |
| 3221 | out->is_compr_metadata_avail = true; |
| 3222 | } |
| 3223 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_ENCODE_OPTION1, value, sizeof(value)); |
| 3224 | if (ret >= 0) { |
| 3225 | out->compr_config.codec->options.wma.encodeopt1 = atoi(value); |
| 3226 | out->is_compr_metadata_avail = true; |
| 3227 | } |
| 3228 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_ENCODE_OPTION2, value, sizeof(value)); |
| 3229 | if (ret >= 0) { |
| 3230 | out->compr_config.codec->options.wma.encodeopt2 = atoi(value); |
| 3231 | out->is_compr_metadata_avail = true; |
| 3232 | } |
| 3233 | ALOGV("WMA params: fmt %x, bit rate %x, balgn %x, sr %d, chmsk %x" |
| 3234 | " encop %x, op1 %x, op2 %x", |
| 3235 | out->compr_config.codec->format, |
| 3236 | out->compr_config.codec->options.wma.avg_bit_rate, |
| 3237 | out->compr_config.codec->options.wma.super_block_align, |
| 3238 | out->compr_config.codec->options.wma.bits_per_sample, |
| 3239 | out->compr_config.codec->options.wma.channelmask, |
| 3240 | out->compr_config.codec->options.wma.encodeopt, |
| 3241 | out->compr_config.codec->options.wma.encodeopt1, |
| 3242 | out->compr_config.codec->options.wma.encodeopt2); |
| 3243 | |
| 3244 | return ret; |
| 3245 | } |
| 3246 | #endif |
| 3247 | |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3248 | #ifdef AUDIO_GKI_ENABLED |
| 3249 | static int get_flac_dec_info(struct stream_out *out, struct str_parms *parms) { |
| 3250 | int ret = 0; |
| 3251 | char value[32]; |
| 3252 | struct snd_generic_dec_flac *flac_dec = NULL; |
| 3253 | |
| 3254 | /* reserved[0] will contain the FLAC decoder type */ |
| 3255 | out->compr_config.codec->options.generic.reserved[0] = |
| 3256 | AUDIO_COMP_FORMAT_FLAC; |
| 3257 | /* reserved[1] onwards will contain the FLAC decoder format info */ |
| 3258 | flac_dec = (struct snd_generic_dec_flac *) |
| 3259 | &(out->compr_config.codec->options.generic.reserved[1]); |
| 3260 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MIN_BLK_SIZE, |
| 3261 | value, sizeof(value)); |
| 3262 | if (ret >= 0) { |
| 3263 | flac_dec->min_blk_size = atoi(value); |
| 3264 | out->is_compr_metadata_avail = true; |
| 3265 | } |
| 3266 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MAX_BLK_SIZE, |
| 3267 | value, sizeof(value)); |
| 3268 | if (ret >= 0) { |
| 3269 | flac_dec->max_blk_size = atoi(value); |
| 3270 | out->is_compr_metadata_avail = true; |
| 3271 | } |
| 3272 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MIN_FRAME_SIZE, |
| 3273 | value, sizeof(value)); |
| 3274 | if (ret >= 0) { |
| 3275 | flac_dec->min_frame_size = atoi(value); |
| 3276 | out->is_compr_metadata_avail = true; |
| 3277 | } |
| 3278 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MAX_FRAME_SIZE, |
| 3279 | value, sizeof(value)); |
| 3280 | if (ret >= 0) { |
| 3281 | flac_dec->max_frame_size = atoi(value); |
| 3282 | out->is_compr_metadata_avail = true; |
| 3283 | } |
| 3284 | |
| 3285 | ALOGV("FLAC metadata: fmt 0x%x, id 0x%x, FLAC type 0x%x min_blk_size %d," |
| 3286 | " max_blk_size %d min_frame_size %d max_frame_size %d \n", |
| 3287 | out->compr_config.codec->format, |
| 3288 | out->compr_config.codec->id, |
| 3289 | out->compr_config.codec->options.generic.reserved[0], |
| 3290 | flac_dec->min_blk_size, |
| 3291 | flac_dec->max_blk_size, |
| 3292 | flac_dec->min_frame_size, |
| 3293 | flac_dec->max_frame_size); |
| 3294 | |
| 3295 | return ret; |
| 3296 | } |
| 3297 | |
| 3298 | static int get_alac_dec_info(struct stream_out *out, struct str_parms *parms) { |
| 3299 | int ret = 0; |
| 3300 | char value[32]; |
| 3301 | struct snd_generic_dec_alac *alac_dec = NULL; |
| 3302 | |
| 3303 | /* reserved[0] will contain the ALAC decoder type */ |
| 3304 | out->compr_config.codec->options.generic.reserved[0] = |
| 3305 | AUDIO_COMP_FORMAT_ALAC; |
| 3306 | /* reserved[1] onwards will contain the ALAC decoder format info */ |
| 3307 | alac_dec = (struct snd_generic_dec_alac *) |
| 3308 | &(out->compr_config.codec->options.generic.reserved[1]); |
| 3309 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_FRAME_LENGTH, |
| 3310 | value, sizeof(value)); |
| 3311 | if (ret >= 0) { |
| 3312 | alac_dec->frame_length = atoi(value); |
| 3313 | out->is_compr_metadata_avail = true; |
| 3314 | } |
| 3315 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_COMPATIBLE_VERSION, |
| 3316 | value, sizeof(value)); |
| 3317 | if (ret >= 0) { |
| 3318 | alac_dec->compatible_version = atoi(value); |
| 3319 | out->is_compr_metadata_avail = true; |
| 3320 | } |
| 3321 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_BIT_DEPTH, |
| 3322 | value, sizeof(value)); |
| 3323 | if (ret >= 0) { |
| 3324 | alac_dec->bit_depth = atoi(value); |
| 3325 | out->is_compr_metadata_avail = true; |
| 3326 | } |
| 3327 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_PB, |
| 3328 | value, sizeof(value)); |
| 3329 | if (ret >= 0) { |
| 3330 | alac_dec->pb = atoi(value); |
| 3331 | out->is_compr_metadata_avail = true; |
| 3332 | } |
| 3333 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_MB, |
| 3334 | value, sizeof(value)); |
| 3335 | if (ret >= 0) { |
| 3336 | alac_dec->mb = atoi(value); |
| 3337 | out->is_compr_metadata_avail = true; |
| 3338 | } |
| 3339 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_KB, |
| 3340 | value, sizeof(value)); |
| 3341 | if (ret >= 0) { |
| 3342 | alac_dec->kb = atoi(value); |
| 3343 | out->is_compr_metadata_avail = true; |
| 3344 | } |
| 3345 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_NUM_CHANNELS, |
| 3346 | value, sizeof(value)); |
| 3347 | if (ret >= 0) { |
| 3348 | alac_dec->num_channels = atoi(value); |
| 3349 | out->is_compr_metadata_avail = true; |
| 3350 | } |
| 3351 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_MAX_RUN, |
| 3352 | value, sizeof(value)); |
| 3353 | if (ret >= 0) { |
| 3354 | alac_dec->max_run = atoi(value); |
| 3355 | out->is_compr_metadata_avail = true; |
| 3356 | } |
| 3357 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_MAX_FRAME_BYTES, |
| 3358 | value, sizeof(value)); |
| 3359 | if (ret >= 0) { |
| 3360 | alac_dec->max_frame_bytes = atoi(value); |
| 3361 | out->is_compr_metadata_avail = true; |
| 3362 | } |
| 3363 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_AVG_BIT_RATE, |
| 3364 | value, sizeof(value)); |
| 3365 | if (ret >= 0) { |
| 3366 | alac_dec->avg_bit_rate = atoi(value); |
| 3367 | out->is_compr_metadata_avail = true; |
| 3368 | } |
| 3369 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_SAMPLING_RATE, |
| 3370 | value, sizeof(value)); |
| 3371 | if (ret >= 0) { |
| 3372 | alac_dec->sample_rate = atoi(value); |
| 3373 | out->is_compr_metadata_avail = true; |
| 3374 | } |
| 3375 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_CHANNEL_LAYOUT_TAG, |
| 3376 | value, sizeof(value)); |
| 3377 | if (ret >= 0) { |
| 3378 | alac_dec->channel_layout_tag = atoi(value); |
| 3379 | out->is_compr_metadata_avail = true; |
| 3380 | } |
| 3381 | |
| 3382 | ALOGV("ALAC CSD values: fmt 0x%x, id 0x%x, ALAC type 0x%x, frameLength %d" |
| 3383 | "bitDepth %d numChannels %d" |
| 3384 | " maxFrameBytes %d, avgBitRate %d, sampleRate %d \n", |
| 3385 | out->compr_config.codec->format, |
| 3386 | out->compr_config.codec->id, |
| 3387 | out->compr_config.codec->options.generic.reserved[0], |
| 3388 | alac_dec->frame_length, |
| 3389 | alac_dec->bit_depth, |
| 3390 | alac_dec->num_channels, |
| 3391 | alac_dec->max_frame_bytes, |
| 3392 | alac_dec->avg_bit_rate, |
| 3393 | alac_dec->sample_rate); |
| 3394 | |
| 3395 | return ret; |
| 3396 | } |
| 3397 | |
| 3398 | static int get_ape_dec_info(struct stream_out *out, struct str_parms *parms) { |
| 3399 | int ret = 0; |
| 3400 | char value[32]; |
| 3401 | struct snd_generic_dec_ape *ape_dec = NULL; |
| 3402 | |
| 3403 | /* reserved[0] will contain the APE decoder type */ |
| 3404 | out->compr_config.codec->options.generic.reserved[0] = |
| 3405 | AUDIO_COMP_FORMAT_APE; |
| 3406 | |
| 3407 | /* reserved[1] onwards will contain the APE decoder format info */ |
| 3408 | ape_dec = (struct snd_generic_dec_ape *) |
| 3409 | &(out->compr_config.codec->options.generic.reserved[1]); |
| 3410 | |
| 3411 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_COMPATIBLE_VERSION, |
| 3412 | value, sizeof(value)); |
| 3413 | if (ret >= 0) { |
| 3414 | ape_dec->compatible_version = atoi(value); |
| 3415 | out->is_compr_metadata_avail = true; |
| 3416 | } |
| 3417 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_COMPRESSION_LEVEL, |
| 3418 | value, sizeof(value)); |
| 3419 | if (ret >= 0) { |
| 3420 | ape_dec->compression_level = atoi(value); |
| 3421 | out->is_compr_metadata_avail = true; |
| 3422 | } |
| 3423 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_FORMAT_FLAGS, |
| 3424 | value, sizeof(value)); |
| 3425 | if (ret >= 0) { |
| 3426 | ape_dec->format_flags = atoi(value); |
| 3427 | out->is_compr_metadata_avail = true; |
| 3428 | } |
| 3429 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_BLOCKS_PER_FRAME, |
| 3430 | value, sizeof(value)); |
| 3431 | if (ret >= 0) { |
| 3432 | ape_dec->blocks_per_frame = atoi(value); |
| 3433 | out->is_compr_metadata_avail = true; |
| 3434 | } |
| 3435 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_FINAL_FRAME_BLOCKS, |
| 3436 | value, sizeof(value)); |
| 3437 | if (ret >= 0) { |
| 3438 | ape_dec->final_frame_blocks = atoi(value); |
| 3439 | out->is_compr_metadata_avail = true; |
| 3440 | } |
| 3441 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_TOTAL_FRAMES, value, |
| 3442 | sizeof(value)); |
| 3443 | if (ret >= 0) { |
| 3444 | ape_dec->total_frames = atoi(value); |
| 3445 | out->is_compr_metadata_avail = true; |
| 3446 | } |
| 3447 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_BITS_PER_SAMPLE, |
| 3448 | value, sizeof(value)); |
| 3449 | if (ret >= 0) { |
| 3450 | ape_dec->bits_per_sample = atoi(value); |
| 3451 | out->is_compr_metadata_avail = true; |
| 3452 | } |
| 3453 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_NUM_CHANNELS, |
| 3454 | value, sizeof(value)); |
| 3455 | if (ret >= 0) { |
| 3456 | ape_dec->num_channels = atoi(value); |
| 3457 | out->is_compr_metadata_avail = true; |
| 3458 | } |
| 3459 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_SAMPLE_RATE, |
| 3460 | value, sizeof(value)); |
| 3461 | if (ret >= 0) { |
| 3462 | ape_dec->sample_rate = atoi(value); |
| 3463 | out->is_compr_metadata_avail = true; |
| 3464 | } |
| 3465 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_SEEK_TABLE_PRESENT, |
| 3466 | value, sizeof(value)); |
| 3467 | if (ret >= 0) { |
| 3468 | ape_dec->seek_table_present = atoi(value); |
| 3469 | out->is_compr_metadata_avail = true; |
| 3470 | } |
| 3471 | |
| 3472 | ALOGV("APE CSD values: fmt 0x%x, id 0x%x, APE type 0x%x" |
| 3473 | " compatibleVersion %d compressionLevel %d" |
| 3474 | " formatFlags %d blocksPerFrame %d finalFrameBlocks %d" |
| 3475 | " totalFrames %d bitsPerSample %d numChannels %d" |
| 3476 | " sampleRate %d seekTablePresent %d", |
| 3477 | out->compr_config.codec->format, |
| 3478 | out->compr_config.codec->id, |
| 3479 | out->compr_config.codec->options.generic.reserved[0], |
| 3480 | ape_dec->compatible_version, |
| 3481 | ape_dec->compression_level, |
| 3482 | ape_dec->format_flags, |
| 3483 | ape_dec->blocks_per_frame, |
| 3484 | ape_dec->final_frame_blocks, |
| 3485 | ape_dec->total_frames, |
| 3486 | ape_dec->bits_per_sample, |
| 3487 | ape_dec->num_channels, |
| 3488 | ape_dec->sample_rate, |
| 3489 | ape_dec->seek_table_present); |
| 3490 | |
| 3491 | return ret; |
| 3492 | } |
| 3493 | |
| 3494 | static int get_vorbis_dec_info(struct stream_out *out, |
| 3495 | struct str_parms *parms) { |
| 3496 | int ret = 0; |
| 3497 | char value[32]; |
| 3498 | struct snd_generic_dec_vorbis *vorbis_dec = NULL; |
| 3499 | |
| 3500 | /* reserved[0] will contain the Vorbis decoder type */ |
| 3501 | out->compr_config.codec->options.generic.reserved[0] = |
| 3502 | AUDIO_COMP_FORMAT_VORBIS; |
| 3503 | /* reserved[1] onwards will contain the Vorbis decoder format info */ |
| 3504 | vorbis_dec = (struct snd_generic_dec_vorbis *) |
| 3505 | &(out->compr_config.codec->options.generic.reserved[1]); |
| 3506 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_VORBIS_BITSTREAM_FMT, |
| 3507 | value, sizeof(value)); |
| 3508 | if (ret >= 0) { |
| 3509 | // transcoded bitstream mode |
| 3510 | vorbis_dec->bit_stream_fmt = (atoi(value) > 0) ? 1 : 0; |
| 3511 | out->is_compr_metadata_avail = true; |
| 3512 | } |
| 3513 | |
| 3514 | ALOGV("Vorbis values: fmt 0x%x, id 0x%x, Vorbis type 0x%x" |
| 3515 | " bitStreamFmt %d\n", |
| 3516 | out->compr_config.codec->format, |
| 3517 | out->compr_config.codec->id, |
| 3518 | out->compr_config.codec->options.generic.reserved[0], |
| 3519 | vorbis_dec->bit_stream_fmt); |
| 3520 | |
| 3521 | return ret; |
| 3522 | } |
| 3523 | |
| 3524 | int audio_extn_parse_compress_metadata(struct stream_out *out, |
| 3525 | struct str_parms *parms) |
| 3526 | { |
| 3527 | int ret = 0; |
| 3528 | char value[32]; |
| 3529 | |
| 3530 | if (!if_compress_meta_data_feature_enabled()) |
| 3531 | return ret; |
| 3532 | |
| 3533 | if (out->format == AUDIO_FORMAT_FLAC) { |
| 3534 | ret = get_flac_dec_info(out, parms); |
| 3535 | } else if (out->format == AUDIO_FORMAT_ALAC) { |
| 3536 | ret = get_alac_dec_info(out, parms); |
| 3537 | } else if (out->format == AUDIO_FORMAT_APE) { |
| 3538 | ret = get_ape_dec_info(out, parms); |
| 3539 | } else if (out->format == AUDIO_FORMAT_VORBIS) { |
| 3540 | ret = get_vorbis_dec_info(out, parms); |
| 3541 | } else if (out->format == AUDIO_FORMAT_WMA || |
| 3542 | out->format == AUDIO_FORMAT_WMA_PRO) { |
| 3543 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_FORMAT_TAG, |
| 3544 | value, sizeof(value)); |
| 3545 | if (ret >= 0) { |
| 3546 | out->compr_config.codec->format = atoi(value); |
| 3547 | out->is_compr_metadata_avail = true; |
| 3548 | } |
| 3549 | |
| 3550 | ret = get_wma_dec_info(out, parms); |
| 3551 | } |
| 3552 | |
| 3553 | return ret; |
| 3554 | } |
| 3555 | |
| 3556 | #else |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3557 | int audio_extn_parse_compress_metadata(struct stream_out *out, |
| 3558 | struct str_parms *parms) |
| 3559 | { |
| 3560 | int ret = 0; |
| 3561 | char value[32]; |
| 3562 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 3563 | if (!if_compress_meta_data_feature_enabled()) { |
| 3564 | return ret; |
| 3565 | } |
| 3566 | |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3567 | if (out->format == AUDIO_FORMAT_FLAC) { |
| 3568 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MIN_BLK_SIZE, value, sizeof(value)); |
| 3569 | if (ret >= 0) { |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3570 | out->compr_config.codec->options.flac_dec.min_blk_size = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3571 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3572 | } |
| 3573 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MAX_BLK_SIZE, value, sizeof(value)); |
| 3574 | if (ret >= 0) { |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3575 | out->compr_config.codec->options.flac_dec.max_blk_size = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3576 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3577 | } |
| 3578 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MIN_FRAME_SIZE, value, sizeof(value)); |
| 3579 | if (ret >= 0) { |
| 3580 | out->compr_config.codec->options.flac_dec.min_frame_size = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3581 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3582 | } |
| 3583 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MAX_FRAME_SIZE, value, sizeof(value)); |
| 3584 | if (ret >= 0) { |
| 3585 | out->compr_config.codec->options.flac_dec.max_frame_size = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3586 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3587 | } |
| 3588 | ALOGV("FLAC metadata: min_blk_size %d, max_blk_size %d min_frame_size %d max_frame_size %d", |
| 3589 | out->compr_config.codec->options.flac_dec.min_blk_size, |
| 3590 | out->compr_config.codec->options.flac_dec.max_blk_size, |
| 3591 | out->compr_config.codec->options.flac_dec.min_frame_size, |
| 3592 | out->compr_config.codec->options.flac_dec.max_frame_size); |
| 3593 | } |
| 3594 | |
| 3595 | else if (out->format == AUDIO_FORMAT_ALAC) { |
| 3596 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_FRAME_LENGTH, value, sizeof(value)); |
| 3597 | if (ret >= 0) { |
| 3598 | out->compr_config.codec->options.alac.frame_length = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3599 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3600 | } |
| 3601 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_COMPATIBLE_VERSION, value, sizeof(value)); |
| 3602 | if (ret >= 0) { |
| 3603 | out->compr_config.codec->options.alac.compatible_version = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3604 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3605 | } |
| 3606 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_BIT_DEPTH, value, sizeof(value)); |
| 3607 | if (ret >= 0) { |
| 3608 | out->compr_config.codec->options.alac.bit_depth = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3609 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3610 | } |
| 3611 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_PB, value, sizeof(value)); |
| 3612 | if (ret >= 0) { |
| 3613 | out->compr_config.codec->options.alac.pb = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3614 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3615 | } |
| 3616 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_MB, value, sizeof(value)); |
| 3617 | if (ret >= 0) { |
| 3618 | out->compr_config.codec->options.alac.mb = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3619 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_KB, value, sizeof(value)); |
| 3623 | if (ret >= 0) { |
| 3624 | out->compr_config.codec->options.alac.kb = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3625 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3626 | } |
| 3627 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_NUM_CHANNELS, value, sizeof(value)); |
| 3628 | if (ret >= 0) { |
| 3629 | out->compr_config.codec->options.alac.num_channels = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3630 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3631 | } |
| 3632 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_MAX_RUN, value, sizeof(value)); |
| 3633 | if (ret >= 0) { |
| 3634 | out->compr_config.codec->options.alac.max_run = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3635 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3636 | } |
| 3637 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_MAX_FRAME_BYTES, value, sizeof(value)); |
| 3638 | if (ret >= 0) { |
| 3639 | out->compr_config.codec->options.alac.max_frame_bytes = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3640 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3641 | } |
| 3642 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_AVG_BIT_RATE, value, sizeof(value)); |
| 3643 | if (ret >= 0) { |
| 3644 | out->compr_config.codec->options.alac.avg_bit_rate = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3645 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3646 | } |
| 3647 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_SAMPLING_RATE, value, sizeof(value)); |
| 3648 | if (ret >= 0) { |
| 3649 | out->compr_config.codec->options.alac.sample_rate = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3650 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3651 | } |
| 3652 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_ALAC_CHANNEL_LAYOUT_TAG, value, sizeof(value)); |
| 3653 | if (ret >= 0) { |
| 3654 | out->compr_config.codec->options.alac.channel_layout_tag = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3655 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3656 | } |
| 3657 | ALOGV("ALAC CSD values: frameLength %d bitDepth %d numChannels %d" |
| 3658 | " maxFrameBytes %d, avgBitRate %d, sampleRate %d", |
| 3659 | out->compr_config.codec->options.alac.frame_length, |
| 3660 | out->compr_config.codec->options.alac.bit_depth, |
| 3661 | out->compr_config.codec->options.alac.num_channels, |
| 3662 | out->compr_config.codec->options.alac.max_frame_bytes, |
| 3663 | out->compr_config.codec->options.alac.avg_bit_rate, |
| 3664 | out->compr_config.codec->options.alac.sample_rate); |
| 3665 | } |
| 3666 | |
| 3667 | else if (out->format == AUDIO_FORMAT_APE) { |
| 3668 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_COMPATIBLE_VERSION, value, sizeof(value)); |
| 3669 | if (ret >= 0) { |
| 3670 | out->compr_config.codec->options.ape.compatible_version = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3671 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3672 | } |
| 3673 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_COMPRESSION_LEVEL, value, sizeof(value)); |
| 3674 | if (ret >= 0) { |
| 3675 | out->compr_config.codec->options.ape.compression_level = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3676 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3677 | } |
| 3678 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_FORMAT_FLAGS, value, sizeof(value)); |
| 3679 | if (ret >= 0) { |
| 3680 | out->compr_config.codec->options.ape.format_flags = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3681 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3682 | } |
| 3683 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_BLOCKS_PER_FRAME, value, sizeof(value)); |
| 3684 | if (ret >= 0) { |
| 3685 | out->compr_config.codec->options.ape.blocks_per_frame = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3686 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3687 | } |
| 3688 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_FINAL_FRAME_BLOCKS, value, sizeof(value)); |
| 3689 | if (ret >= 0) { |
| 3690 | out->compr_config.codec->options.ape.final_frame_blocks = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3691 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3692 | } |
| 3693 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_TOTAL_FRAMES, value, sizeof(value)); |
| 3694 | if (ret >= 0) { |
| 3695 | out->compr_config.codec->options.ape.total_frames = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3696 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3697 | } |
| 3698 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_BITS_PER_SAMPLE, value, sizeof(value)); |
| 3699 | if (ret >= 0) { |
| 3700 | out->compr_config.codec->options.ape.bits_per_sample = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3701 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3702 | } |
| 3703 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_NUM_CHANNELS, value, sizeof(value)); |
| 3704 | if (ret >= 0) { |
| 3705 | out->compr_config.codec->options.ape.num_channels = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3706 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3707 | } |
| 3708 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_SAMPLE_RATE, value, sizeof(value)); |
| 3709 | if (ret >= 0) { |
| 3710 | out->compr_config.codec->options.ape.sample_rate = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3711 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3712 | } |
| 3713 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_APE_SEEK_TABLE_PRESENT, value, sizeof(value)); |
| 3714 | if (ret >= 0) { |
| 3715 | out->compr_config.codec->options.ape.seek_table_present = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3716 | out->is_compr_metadata_avail = true; |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3717 | } |
| 3718 | ALOGV("APE CSD values: compatibleVersion %d compressionLevel %d" |
| 3719 | " formatFlags %d blocksPerFrame %d finalFrameBlocks %d" |
| 3720 | " totalFrames %d bitsPerSample %d numChannels %d" |
| 3721 | " sampleRate %d seekTablePresent %d", |
| 3722 | out->compr_config.codec->options.ape.compatible_version, |
| 3723 | out->compr_config.codec->options.ape.compression_level, |
| 3724 | out->compr_config.codec->options.ape.format_flags, |
| 3725 | out->compr_config.codec->options.ape.blocks_per_frame, |
| 3726 | out->compr_config.codec->options.ape.final_frame_blocks, |
| 3727 | out->compr_config.codec->options.ape.total_frames, |
| 3728 | out->compr_config.codec->options.ape.bits_per_sample, |
| 3729 | out->compr_config.codec->options.ape.num_channels, |
| 3730 | out->compr_config.codec->options.ape.sample_rate, |
| 3731 | out->compr_config.codec->options.ape.seek_table_present); |
| 3732 | } |
| 3733 | |
| 3734 | else if (out->format == AUDIO_FORMAT_VORBIS) { |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3735 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_VORBIS_BITSTREAM_FMT, value, sizeof(value)); |
| 3736 | if (ret >= 0) { |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3737 | // transcoded bitstream mode |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3738 | out->compr_config.codec->options.vorbis_dec.bit_stream_fmt = (atoi(value) > 0) ? 1 : 0; |
| 3739 | out->is_compr_metadata_avail = true; |
| 3740 | } |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | else if (out->format == AUDIO_FORMAT_WMA || out->format == AUDIO_FORMAT_WMA_PRO) { |
| 3744 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_FORMAT_TAG, value, sizeof(value)); |
| 3745 | if (ret >= 0) { |
| 3746 | out->compr_config.codec->format = atoi(value); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3747 | out->is_compr_metadata_avail = true; |
| 3748 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3749 | ret = get_wma_info(out, parms); |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | return ret; |
| 3753 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 3754 | #endif |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 3755 | |
Damir Didjusto | f1d46c7 | 2013-11-06 17:59:04 -0800 | [diff] [blame] | 3756 | #ifdef AUXPCM_BT_ENABLED |
| 3757 | int32_t audio_extn_read_xml(struct audio_device *adev, uint32_t mixer_card, |
| 3758 | const char* mixer_xml_path, |
| 3759 | const char* mixer_xml_path_auxpcm) |
| 3760 | { |
| 3761 | char bt_soc[128]; |
| 3762 | bool wifi_init_complete = false; |
| 3763 | int sleep_retry = 0; |
| 3764 | |
| 3765 | while (!wifi_init_complete && sleep_retry < MAX_SLEEP_RETRY) { |
| 3766 | property_get("qcom.bluetooth.soc", bt_soc, NULL); |
| 3767 | if (strncmp(bt_soc, "unknown", sizeof("unknown"))) { |
| 3768 | wifi_init_complete = true; |
| 3769 | } else { |
| 3770 | usleep(WIFI_INIT_WAIT_SLEEP*1000); |
| 3771 | sleep_retry++; |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | if (!strncmp(bt_soc, "ath3k", sizeof("ath3k"))) |
| 3776 | adev->audio_route = audio_route_init(mixer_card, mixer_xml_path_auxpcm); |
| 3777 | else |
| 3778 | adev->audio_route = audio_route_init(mixer_card, mixer_xml_path); |
| 3779 | |
| 3780 | return 0; |
| 3781 | } |
| 3782 | #endif /* AUXPCM_BT_ENABLED */ |
Sudheer Papothi | 390bcf3 | 2014-12-04 01:25:17 +0530 | [diff] [blame] | 3783 | |
Divya Narayanan Poojary | 45f1919 | 2016-09-30 18:52:13 +0530 | [diff] [blame] | 3784 | static int audio_extn_set_multichannel_mask(struct audio_device *adev, |
| 3785 | struct stream_in *in, |
| 3786 | struct audio_config *config, |
| 3787 | bool *channel_mask_updated) |
| 3788 | { |
| 3789 | int ret = -EINVAL; |
| 3790 | int channel_count = audio_channel_count_from_in_mask(in->channel_mask); |
| 3791 | *channel_mask_updated = false; |
| 3792 | |
| 3793 | int max_mic_count = platform_get_max_mic_count(adev->platform); |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 3794 | /* validate input params. Avoid updated channel mask if loopback device */ |
Avinash Chandra | d7296d4 | 2021-08-04 15:07:47 +0530 | [diff] [blame] | 3795 | /* validate input params. Avoid updated channel mask if HDMI or loopback device */ |
Sandhya Mutha Naga Venkata | e85bc82 | 2023-03-21 22:31:22 +0530 | [diff] [blame] | 3796 | if ((channel_count == 6) && |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 3797 | (in->format == AUDIO_FORMAT_PCM_16_BIT) && |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 3798 | (!is_loopback_input_device(get_device_types(&in->device_list)))) { |
Divya Narayanan Poojary | 45f1919 | 2016-09-30 18:52:13 +0530 | [diff] [blame] | 3799 | switch (max_mic_count) { |
| 3800 | case 4: |
| 3801 | config->channel_mask = AUDIO_CHANNEL_INDEX_MASK_4; |
| 3802 | break; |
| 3803 | case 3: |
| 3804 | config->channel_mask = AUDIO_CHANNEL_INDEX_MASK_3; |
| 3805 | break; |
| 3806 | case 2: |
| 3807 | config->channel_mask = AUDIO_CHANNEL_IN_STEREO; |
| 3808 | break; |
| 3809 | default: |
| 3810 | config->channel_mask = AUDIO_CHANNEL_IN_STEREO; |
| 3811 | break; |
| 3812 | } |
| 3813 | ret = 0; |
| 3814 | *channel_mask_updated = true; |
| 3815 | } |
| 3816 | return ret; |
| 3817 | } |
| 3818 | |
| 3819 | int audio_extn_check_and_set_multichannel_usecase(struct audio_device *adev, |
| 3820 | struct stream_in *in, |
| 3821 | struct audio_config *config, |
| 3822 | bool *update_params) |
| 3823 | { |
| 3824 | bool ssr_supported = false; |
Revathi Uddaraju | d263403 | 2017-12-07 14:42:34 +0530 | [diff] [blame] | 3825 | in->config.rate = config->sample_rate; |
Chaithanya Krishna Bacharaju | f5a1ce6 | 2018-02-02 11:34:11 +0530 | [diff] [blame] | 3826 | in->sample_rate = config->sample_rate; |
Divya Narayanan Poojary | 45f1919 | 2016-09-30 18:52:13 +0530 | [diff] [blame] | 3827 | ssr_supported = audio_extn_ssr_check_usecase(in); |
| 3828 | if (ssr_supported) { |
| 3829 | return audio_extn_ssr_set_usecase(in, config, update_params); |
Garmond Leung | e2433c3 | 2017-09-28 21:51:22 -0700 | [diff] [blame] | 3830 | } else if (audio_extn_ffv_check_usecase(in)) { |
Surendar karka | 3056979 | 2018-05-08 12:02:21 +0530 | [diff] [blame] | 3831 | char ffv_lic[LICENSE_STR_MAX_LEN + 1] = {0}; |
| 3832 | int ffv_key = 0; |
| 3833 | if(platform_get_license_by_product(adev->platform, PRODUCT_FFV, &ffv_key, ffv_lic)) |
| 3834 | { |
| 3835 | ALOGD("%s: Valid licence not availble for %s ", __func__, PRODUCT_FFV); |
| 3836 | return -EINVAL; |
| 3837 | } |
| 3838 | ALOGD("%s: KEY: %d LICENSE: %s ", __func__, ffv_key, ffv_lic); |
| 3839 | return audio_extn_ffv_set_usecase(in, ffv_key, ffv_lic); |
Divya Narayanan Poojary | 45f1919 | 2016-09-30 18:52:13 +0530 | [diff] [blame] | 3840 | } else { |
| 3841 | return audio_extn_set_multichannel_mask(adev, in, config, |
| 3842 | update_params); |
| 3843 | } |
| 3844 | } |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 3845 | |
| 3846 | #ifdef APTX_DECODER_ENABLED |
| 3847 | static void audio_extn_aptx_dec_set_license(struct audio_device *adev) |
| 3848 | { |
| 3849 | int ret, key = 0; |
| 3850 | char value[128] = {0}; |
| 3851 | struct mixer_ctl *ctl; |
| 3852 | const char *mixer_ctl_name = "APTX Dec License"; |
| 3853 | |
| 3854 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 3855 | if (!ctl) { |
| 3856 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 3857 | __func__, mixer_ctl_name); |
| 3858 | return; |
| 3859 | } |
| 3860 | key = platform_get_meta_info_key_from_list(adev->platform, "aptx"); |
| 3861 | |
| 3862 | ALOGD("%s Setting APTX License with key:0x%x",__func__, key); |
| 3863 | ret = mixer_ctl_set_value(ctl, 0, key); |
| 3864 | if (ret) |
| 3865 | ALOGE("%s: cannot set license, error:%d",__func__, ret); |
| 3866 | } |
| 3867 | |
| 3868 | static void audio_extn_set_aptx_dec_bt_addr(struct audio_device *adev, struct str_parms *parms) |
| 3869 | { |
| 3870 | int ret = 0; |
| 3871 | char value[256]; |
| 3872 | |
| 3873 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_APTX_DEC_BT_ADDR, value, |
| 3874 | sizeof(value)); |
| 3875 | if (ret >= 0) { |
| 3876 | audio_extn_parse_aptx_dec_bt_addr(value); |
| 3877 | } |
| 3878 | } |
| 3879 | |
| 3880 | int audio_extn_set_aptx_dec_params(struct aptx_dec_param *payload) |
| 3881 | { |
| 3882 | struct aptx_dec_param *aptx_cfg = payload; |
| 3883 | |
| 3884 | aextnmod.addr.nap = aptx_cfg->bt_addr.nap; |
| 3885 | aextnmod.addr.uap = aptx_cfg->bt_addr.uap; |
| 3886 | aextnmod.addr.lap = aptx_cfg->bt_addr.lap; |
| 3887 | } |
| 3888 | |
| 3889 | static void audio_extn_parse_aptx_dec_bt_addr(char *value) |
| 3890 | { |
| 3891 | int ba[6]; |
| 3892 | char *str, *tok; |
| 3893 | uint32_t addr[3]; |
| 3894 | int i = 0; |
| 3895 | |
| 3896 | ALOGV("%s: value %s", __func__, value); |
| 3897 | tok = strtok_r(value, ":", &str); |
| 3898 | while (tok != NULL) { |
| 3899 | ba[i] = strtol(tok, NULL, 16); |
| 3900 | i++; |
| 3901 | tok = strtok_r(NULL, ":", &str); |
| 3902 | } |
| 3903 | addr[0] = (ba[0] << 8) | ba[1]; |
| 3904 | addr[1] = ba[2]; |
| 3905 | addr[2] = (ba[3] << 16) | (ba[4] << 8) | ba[5]; |
| 3906 | |
| 3907 | aextnmod.addr.nap = addr[0]; |
| 3908 | aextnmod.addr.uap = addr[1]; |
| 3909 | aextnmod.addr.lap = addr[2]; |
| 3910 | } |
| 3911 | |
| 3912 | void audio_extn_send_aptx_dec_bt_addr_to_dsp(struct stream_out *out) |
| 3913 | { |
| 3914 | char mixer_ctl_name[128]; |
| 3915 | struct mixer_ctl *ctl; |
| 3916 | uint32_t addr[3]; |
| 3917 | |
| 3918 | ALOGV("%s", __func__); |
| 3919 | out->compr_config.codec->options.aptx_dec.nap = aextnmod.addr.nap; |
| 3920 | out->compr_config.codec->options.aptx_dec.uap = aextnmod.addr.uap; |
| 3921 | out->compr_config.codec->options.aptx_dec.lap = aextnmod.addr.lap; |
| 3922 | } |
| 3923 | |
| 3924 | #endif //APTX_DECODER_ENABLED |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 3925 | |
| 3926 | int audio_extn_out_set_param_data(struct stream_out *out, |
| 3927 | audio_extn_param_id param_id, |
| 3928 | audio_extn_param_payload *payload) { |
| 3929 | int ret = -EINVAL; |
| 3930 | |
| 3931 | if (!out || !payload) { |
| 3932 | ALOGE("%s:: Invalid Param",__func__); |
| 3933 | return ret; |
| 3934 | } |
| 3935 | |
| 3936 | ALOGD("%s: enter: stream (%p) usecase(%d: %s) param_id %d", __func__, |
| 3937 | out, out->usecase, use_case_table[out->usecase], param_id); |
| 3938 | |
| 3939 | switch (param_id) { |
| 3940 | case AUDIO_EXTN_PARAM_OUT_RENDER_WINDOW: |
| 3941 | ret = audio_extn_utils_compress_set_render_window(out, |
| 3942 | (struct audio_out_render_window_param *)(payload)); |
| 3943 | break; |
| 3944 | case AUDIO_EXTN_PARAM_OUT_START_DELAY: |
| 3945 | ret = audio_extn_utils_compress_set_start_delay(out, |
| 3946 | (struct audio_out_start_delay_param *)(payload)); |
| 3947 | break; |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 3948 | case AUDIO_EXTN_PARAM_OUT_ENABLE_DRIFT_CORRECTION: |
| 3949 | ret = audio_extn_utils_compress_enable_drift_correction(out, |
| 3950 | (struct audio_out_enable_drift_correction *)(payload)); |
| 3951 | break; |
| 3952 | case AUDIO_EXTN_PARAM_OUT_CORRECT_DRIFT: |
| 3953 | ret = audio_extn_utils_compress_correct_drift(out, |
| 3954 | (struct audio_out_correct_drift *)(payload)); |
| 3955 | break; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 3956 | case AUDIO_EXTN_PARAM_ADSP_STREAM_CMD: |
| 3957 | ret = audio_extn_adsp_hdlr_stream_set_param(out->adsp_hdlr_stream_handle, |
| 3958 | ADSP_HDLR_STREAM_CMD_REGISTER_EVENT, |
| 3959 | (void *)&payload->adsp_event_params); |
| 3960 | break; |
Naresh Tanniru | 29bce4e | 2017-04-27 17:54:30 +0530 | [diff] [blame] | 3961 | case AUDIO_EXTN_PARAM_OUT_CHANNEL_MAP: |
| 3962 | ret = audio_extn_utils_set_channel_map(out, |
| 3963 | (struct audio_out_channel_map_param *)(payload)); |
| 3964 | break; |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 3965 | case AUDIO_EXTN_PARAM_OUT_MIX_MATRIX_PARAMS: |
| 3966 | ret = audio_extn_utils_set_pan_scale_params(out, |
| 3967 | (struct mix_matrix_params *)(payload)); |
| 3968 | break; |
| 3969 | case AUDIO_EXTN_PARAM_CH_MIX_MATRIX_PARAMS: |
| 3970 | ret = audio_extn_utils_set_downmix_params(out, |
| 3971 | (struct mix_matrix_params *)(payload)); |
| 3972 | break; |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 3973 | default: |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 3974 | ALOGE("%s:: unsupported param_id %d", __func__, param_id); |
| 3975 | break; |
| 3976 | } |
| 3977 | return ret; |
| 3978 | } |
| 3979 | |
Trinath Thammishetty | 580f1de | 2018-09-28 12:43:24 +0530 | [diff] [blame] | 3980 | #ifdef AUDIO_HW_LOOPBACK_ENABLED |
| 3981 | int audio_extn_hw_loopback_set_param_data(audio_patch_handle_t handle, |
| 3982 | audio_extn_loopback_param_id param_id, |
| 3983 | audio_extn_loopback_param_payload *payload) { |
| 3984 | int ret = -EINVAL; |
| 3985 | |
| 3986 | if (!payload) { |
| 3987 | ALOGE("%s:: Invalid Param",__func__); |
| 3988 | return ret; |
| 3989 | } |
| 3990 | |
| 3991 | ALOGD("%d: %s: param id is %d\n", __LINE__, __func__, param_id); |
| 3992 | |
| 3993 | switch(param_id) { |
| 3994 | case AUDIO_EXTN_PARAM_LOOPBACK_RENDER_WINDOW: |
| 3995 | ret = audio_extn_hw_loopback_set_render_window(handle, payload); |
| 3996 | break; |
| 3997 | default: |
| 3998 | ALOGE("%s: unsupported param id %d", __func__, param_id); |
| 3999 | break; |
| 4000 | } |
| 4001 | |
| 4002 | return ret; |
| 4003 | } |
| 4004 | #endif |
| 4005 | |
| 4006 | |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 4007 | /* API to get playback stream specific config parameters */ |
| 4008 | int audio_extn_out_get_param_data(struct stream_out *out, |
| 4009 | audio_extn_param_id param_id, |
| 4010 | audio_extn_param_payload *payload) |
| 4011 | { |
| 4012 | int ret = -EINVAL; |
| 4013 | struct audio_usecase *uc_info; |
| 4014 | |
| 4015 | if (!out || !payload) { |
| 4016 | ALOGE("%s:: Invalid Param",__func__); |
| 4017 | return ret; |
| 4018 | } |
| 4019 | |
| 4020 | switch (param_id) { |
| 4021 | case AUDIO_EXTN_PARAM_AVT_DEVICE_DRIFT: |
| 4022 | uc_info = get_usecase_from_list(out->dev, out->usecase); |
| 4023 | if (uc_info == NULL) { |
| 4024 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 4025 | __func__, out->usecase); |
| 4026 | ret = -EINVAL; |
| 4027 | } else { |
| 4028 | ret = audio_extn_utils_get_avt_device_drift(uc_info, |
| 4029 | (struct audio_avt_device_drift_param *)payload); |
| 4030 | if(ret) |
| 4031 | ALOGE("%s:: avdrift query failed error %d", __func__, ret); |
| 4032 | } |
| 4033 | break; |
Surendar Karka | 287348c | 2019-04-10 18:31:46 +0530 | [diff] [blame] | 4034 | case AUDIO_EXTN_PARAM_OUT_PRESENTATION_POSITION: |
| 4035 | ret = audio_ext_get_presentation_position(out, |
| 4036 | (struct audio_out_presentation_position_param *)payload); |
| 4037 | if (ret < 0) |
| 4038 | ALOGE("%s:: presentation position query failed error %d", |
| 4039 | __func__, ret); |
| 4040 | break; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 4041 | default: |
| 4042 | ALOGE("%s:: unsupported param_id %d", __func__, param_id); |
| 4043 | break; |
| 4044 | } |
| 4045 | |
| 4046 | return ret; |
| 4047 | } |
Satish Babu Patakokila | c3c5d43 | 2017-07-04 22:48:59 +0530 | [diff] [blame] | 4048 | |
| 4049 | int audio_extn_set_device_cfg_params(struct audio_device *adev, |
| 4050 | struct audio_device_cfg_param *payload) |
| 4051 | { |
| 4052 | struct audio_device_cfg_param *device_cfg_params = payload; |
| 4053 | int ret = -EINVAL; |
| 4054 | struct stream_out out; |
| 4055 | uint32_t snd_device = 0, backend_idx = 0; |
Varun Balaraj | 003ee75 | 2017-08-07 17:54:55 +0530 | [diff] [blame] | 4056 | struct audio_device_config_param *adev_device_cfg_ptr; |
Satish Babu Patakokila | c3c5d43 | 2017-07-04 22:48:59 +0530 | [diff] [blame] | 4057 | |
| 4058 | ALOGV("%s", __func__); |
| 4059 | |
Varun Balaraj | 003ee75 | 2017-08-07 17:54:55 +0530 | [diff] [blame] | 4060 | if (!device_cfg_params || !adev || !adev->device_cfg_params) { |
Satish Babu Patakokila | c3c5d43 | 2017-07-04 22:48:59 +0530 | [diff] [blame] | 4061 | ALOGE("%s:: Invalid Param", __func__); |
| 4062 | return ret; |
| 4063 | } |
| 4064 | |
| 4065 | /* Config is not supported for combo devices */ |
| 4066 | if (popcount(device_cfg_params->device) != 1) { |
| 4067 | ALOGE("%s:: Invalid Device (%#x) - Config is ignored", __func__, device_cfg_params->device); |
| 4068 | return ret; |
| 4069 | } |
| 4070 | |
Varun Balaraj | 003ee75 | 2017-08-07 17:54:55 +0530 | [diff] [blame] | 4071 | adev_device_cfg_ptr = adev->device_cfg_params; |
Satish Babu Patakokila | c3c5d43 | 2017-07-04 22:48:59 +0530 | [diff] [blame] | 4072 | /* Create an out stream to get snd device from audio device */ |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 4073 | reassign_device_list(&out.device_list, device_cfg_params->device, ""); |
Satish Babu Patakokila | c3c5d43 | 2017-07-04 22:48:59 +0530 | [diff] [blame] | 4074 | out.sample_rate = device_cfg_params->sample_rate; |
Jaideep Sharma | 477917f | 2020-03-13 18:13:33 +0530 | [diff] [blame] | 4075 | snd_device = platform_get_output_snd_device(adev->platform, &out, USECASE_TYPE_MAX); |
Satish Babu Patakokila | c3c5d43 | 2017-07-04 22:48:59 +0530 | [diff] [blame] | 4076 | backend_idx = platform_get_backend_index(snd_device); |
| 4077 | |
| 4078 | ALOGV("%s:: device %d sample_rate %d snd_device %d backend_idx %d", |
Aniket Kumar Lata | 9c2fd89 | 2020-01-22 22:20:00 -0800 | [diff] [blame] | 4079 | __func__, get_device_types(&out.device_list), |
| 4080 | out.sample_rate, snd_device, backend_idx); |
Satish Babu Patakokila | c3c5d43 | 2017-07-04 22:48:59 +0530 | [diff] [blame] | 4081 | |
| 4082 | ALOGV("%s:: Device Config Params from Client samplerate %d channels %d" |
| 4083 | " bit_width %d format %d device %d channel_map[0] %d channel_map[1] %d" |
| 4084 | " channel_map[2] %d channel_map[3] %d channel_map[4] %d channel_map[5] %d" |
| 4085 | " channel_allocation %d\n", __func__, device_cfg_params->sample_rate, |
| 4086 | device_cfg_params->channels, device_cfg_params->bit_width, |
| 4087 | device_cfg_params->format, device_cfg_params->device, |
| 4088 | device_cfg_params->channel_map[0], device_cfg_params->channel_map[1], |
| 4089 | device_cfg_params->channel_map[2], device_cfg_params->channel_map[3], |
| 4090 | device_cfg_params->channel_map[4], device_cfg_params->channel_map[5], |
| 4091 | device_cfg_params->channel_allocation); |
| 4092 | |
| 4093 | /* Copy the config values into adev structure variable */ |
| 4094 | adev_device_cfg_ptr += backend_idx; |
| 4095 | adev_device_cfg_ptr->use_client_dev_cfg = true; |
| 4096 | memcpy(&adev_device_cfg_ptr->dev_cfg_params, device_cfg_params, sizeof(struct audio_device_cfg_param)); |
| 4097 | |
| 4098 | return 0; |
| 4099 | } |
Surendar Karka | f51b584 | 2018-04-26 11:28:38 +0530 | [diff] [blame] | 4100 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4101 | //START: FM_POWER_OPT_FEATURE ================================================================ |
| 4102 | void fm_feature_init(bool is_feature_enabled) |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 4103 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4104 | audio_extn_fm_power_opt_enabled = is_feature_enabled; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4105 | ALOGD("%s: ---- Feature FM_POWER_OPT is %s----", __func__, is_feature_enabled? "ENABLED": "NOT ENABLED"); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 4106 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4107 | |
| 4108 | |
| 4109 | void audio_extn_fm_get_parameters(struct str_parms *query, struct str_parms *reply) |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 4110 | { |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4111 | if(audio_extn_fm_power_opt_enabled) { |
Aniket Kumar Lata | d13758f | 2020-08-06 15:11:36 -0700 | [diff] [blame] | 4112 | ALOGV("%s: Enter", __func__); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4113 | fm_get_parameters(query, reply); |
| 4114 | } |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 4115 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4116 | |
| 4117 | void audio_extn_fm_set_parameters(struct audio_device *adev, |
| 4118 | struct str_parms *parms) |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 4119 | { |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4120 | if(audio_extn_fm_power_opt_enabled) { |
Aniket Kumar Lata | d13758f | 2020-08-06 15:11:36 -0700 | [diff] [blame] | 4121 | ALOGV("%s: Enter", __func__); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4122 | fm_set_parameters(adev, parms); |
| 4123 | } |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 4124 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4125 | //END: FM_POWER_OPT_FEATURE ================================================================ |
| 4126 | |
| 4127 | //START: HDMI_EDID ========================================================================= |
| 4128 | #ifdef __LP64__ |
| 4129 | #define HDMI_EDID_LIB_PATH "/vendor/lib64/libhdmiedid.so" |
| 4130 | #else |
| 4131 | #define HDMI_EDID_LIB_PATH "/vendor/lib/libhdmiedid.so" |
| 4132 | #endif |
| 4133 | |
| 4134 | static void *hdmi_edid_lib_handle = NULL; |
| 4135 | |
| 4136 | typedef bool (*hdmi_edid_is_supported_sr_t)(edid_audio_info*, int); |
| 4137 | static hdmi_edid_is_supported_sr_t hdmi_edid_is_supported_sr; |
| 4138 | |
| 4139 | typedef bool (*hdmi_edid_is_supported_bps_t)(edid_audio_info*, int); |
| 4140 | static hdmi_edid_is_supported_bps_t hdmi_edid_is_supported_bps; |
| 4141 | |
| 4142 | typedef int (*hdmi_edid_get_highest_supported_sr_t)(edid_audio_info*); |
| 4143 | static hdmi_edid_get_highest_supported_sr_t hdmi_edid_get_highest_supported_sr; |
| 4144 | |
| 4145 | typedef bool (*hdmi_edid_get_sink_caps_t)(edid_audio_info*, char*); |
| 4146 | static hdmi_edid_get_sink_caps_t hdmi_edid_get_sink_caps; |
| 4147 | |
| 4148 | void hdmi_edid_feature_init(bool is_feature_enabled) |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 4149 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4150 | ALOGD("%s: HDMI_EDID feature %s", __func__, is_feature_enabled?"Enabled":"NOT Enabled"); |
| 4151 | if (is_feature_enabled) { |
| 4152 | //dlopen lib |
| 4153 | hdmi_edid_lib_handle = dlopen(HDMI_EDID_LIB_PATH, RTLD_NOW); |
| 4154 | if (hdmi_edid_lib_handle == NULL) { |
| 4155 | ALOGE("%s: dlopen failed", __func__); |
| 4156 | goto feature_disabled; |
| 4157 | } |
| 4158 | //map each function |
| 4159 | //on any faliure to map any function, disble feature |
| 4160 | if (((hdmi_edid_is_supported_sr = |
| 4161 | (hdmi_edid_is_supported_sr_t)dlsym(hdmi_edid_lib_handle, |
| 4162 | "edid_is_supported_sr")) == NULL) || |
| 4163 | ((hdmi_edid_is_supported_bps = |
| 4164 | (hdmi_edid_is_supported_bps_t)dlsym(hdmi_edid_lib_handle, |
| 4165 | "edid_is_supported_bps")) == NULL) || |
| 4166 | ((hdmi_edid_get_highest_supported_sr = |
| 4167 | (hdmi_edid_get_highest_supported_sr_t)dlsym(hdmi_edid_lib_handle, |
| 4168 | "edid_get_highest_supported_sr")) == NULL) || |
| 4169 | ((hdmi_edid_get_sink_caps = |
| 4170 | (hdmi_edid_get_sink_caps_t)dlsym(hdmi_edid_lib_handle, |
| 4171 | "edid_get_sink_caps")) == NULL)) { |
| 4172 | ALOGE("%s: dlsym failed", __func__); |
| 4173 | goto feature_disabled; |
| 4174 | } |
| 4175 | |
| 4176 | ALOGD("%s:: ---- Feature HDMI_EDID is Enabled ----", __func__); |
| 4177 | return; |
| 4178 | } |
| 4179 | |
| 4180 | feature_disabled: |
| 4181 | if (hdmi_edid_lib_handle) { |
| 4182 | dlclose(hdmi_edid_lib_handle); |
| 4183 | hdmi_edid_lib_handle = NULL; |
| 4184 | } |
| 4185 | |
| 4186 | hdmi_edid_is_supported_sr = NULL; |
| 4187 | hdmi_edid_is_supported_bps = NULL; |
| 4188 | hdmi_edid_get_highest_supported_sr = NULL; |
| 4189 | hdmi_edid_get_sink_caps = NULL; |
| 4190 | ALOGW(":: %s: ---- Feature HDMI_EDID is disabled ----", __func__); |
| 4191 | return; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 4192 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4193 | |
| 4194 | bool audio_extn_edid_is_supported_sr(edid_audio_info* info, int sr) |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 4195 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4196 | bool ret = false; |
| 4197 | |
| 4198 | if(hdmi_edid_is_supported_sr != NULL) |
| 4199 | ret = hdmi_edid_is_supported_sr(info, sr); |
| 4200 | return ret; |
| 4201 | } |
| 4202 | |
| 4203 | bool audio_extn_edid_is_supported_bps(edid_audio_info* info, int bps) |
| 4204 | { |
| 4205 | bool ret = false; |
| 4206 | |
| 4207 | if(hdmi_edid_is_supported_bps != NULL) |
| 4208 | ret = hdmi_edid_is_supported_bps(info, bps); |
| 4209 | return ret; |
| 4210 | } |
| 4211 | int audio_extn_edid_get_highest_supported_sr(edid_audio_info* info) |
| 4212 | { |
| 4213 | int ret = -1; |
| 4214 | |
| 4215 | if(hdmi_edid_get_highest_supported_sr != NULL) |
| 4216 | ret = hdmi_edid_get_highest_supported_sr(info); |
| 4217 | return ret; |
| 4218 | } |
| 4219 | |
| 4220 | bool audio_extn_edid_get_sink_caps(edid_audio_info* info, char *edid_data) |
| 4221 | { |
| 4222 | bool ret = false; |
| 4223 | |
| 4224 | if(hdmi_edid_get_sink_caps != NULL) |
| 4225 | ret = hdmi_edid_get_sink_caps(info, edid_data); |
| 4226 | return ret; |
| 4227 | } |
| 4228 | |
| 4229 | //END: HDMI_EDID ========================================================================= |
| 4230 | |
| 4231 | |
| 4232 | //START: KEEP_ALIVE ========================================================================= |
| 4233 | |
| 4234 | void keep_alive_feature_init(bool is_feature_enabled) |
| 4235 | { |
| 4236 | audio_extn_keep_alive_enabled = is_feature_enabled; |
| 4237 | ALOGD(":: %s: ---- Feature KEEP_ALIVE is %s ----", __func__, is_feature_enabled? "ENABLED": " NOT ENABLED"); |
| 4238 | } |
| 4239 | |
| 4240 | void audio_extn_keep_alive_init(struct audio_device *adev) |
| 4241 | { |
| 4242 | if(audio_extn_keep_alive_enabled) |
| 4243 | keep_alive_init(adev); |
| 4244 | } |
| 4245 | |
| 4246 | void audio_extn_keep_alive_deinit() |
| 4247 | { |
| 4248 | if(audio_extn_keep_alive_enabled) |
| 4249 | keep_alive_deinit(); |
| 4250 | } |
| 4251 | |
| 4252 | void audio_extn_keep_alive_start(ka_mode_t ka_mode) |
| 4253 | { |
| 4254 | if(audio_extn_keep_alive_enabled) |
| 4255 | keep_alive_start(ka_mode); |
| 4256 | } |
| 4257 | |
| 4258 | void audio_extn_keep_alive_stop(ka_mode_t ka_mode) |
| 4259 | { |
| 4260 | if(audio_extn_keep_alive_enabled) |
| 4261 | keep_alive_stop(ka_mode); |
| 4262 | } |
| 4263 | |
| 4264 | bool audio_extn_keep_alive_is_active() |
| 4265 | { |
| 4266 | bool ret = false; |
| 4267 | return ret; |
| 4268 | } |
| 4269 | |
| 4270 | int audio_extn_keep_alive_set_parameters(struct audio_device *adev, |
| 4271 | struct str_parms *parms) |
| 4272 | { |
| 4273 | int ret = -1; |
| 4274 | if(audio_extn_keep_alive_enabled) |
| 4275 | return keep_alive_set_parameters(adev, parms); |
| 4276 | return ret; |
| 4277 | } |
| 4278 | //END: KEEP_ALIVE ========================================================================= |
| 4279 | |
| 4280 | //START: HIFI_AUDIO ========================================================================= |
| 4281 | void hifi_audio_feature_init(bool is_feature_enabled) |
| 4282 | { |
| 4283 | audio_extn_hifi_audio_enabled = is_feature_enabled; |
| 4284 | ALOGD(":: %s: ---- Feature HIFI_AUDIO is %s ----", __func__, is_feature_enabled? "ENABLED": " NOT ENABLED"); |
| 4285 | } |
| 4286 | |
| 4287 | bool audio_extn_is_hifi_audio_enabled(void) |
| 4288 | { |
| 4289 | bool ret = false; |
| 4290 | if(audio_extn_hifi_audio_enabled) |
| 4291 | { |
| 4292 | ALOGV("%s: status: %d", __func__, aextnmod.hifi_audio_enabled); |
| 4293 | return (aextnmod.hifi_audio_enabled ? true: false); |
| 4294 | } |
| 4295 | return ret; |
| 4296 | } |
| 4297 | |
| 4298 | bool audio_extn_is_hifi_audio_supported(void) |
| 4299 | { |
| 4300 | bool ret = false; |
| 4301 | |
| 4302 | if(audio_extn_hifi_audio_enabled) |
| 4303 | { |
| 4304 | /* |
| 4305 | * for internal codec, check for hifiaudio property to enable hifi audio |
| 4306 | */ |
| 4307 | if (property_get_bool("persist.vendor.audio.hifi.int_codec", false)) |
| 4308 | { |
| 4309 | ALOGD("%s: hifi audio supported on internal codec", __func__); |
| 4310 | aextnmod.hifi_audio_enabled = 1; |
| 4311 | } |
| 4312 | return (aextnmod.hifi_audio_enabled ? true: false); |
| 4313 | } |
| 4314 | return ret; |
| 4315 | } |
| 4316 | |
| 4317 | //END: HIFI_AUDIO ========================================================================= |
| 4318 | |
| 4319 | //START: RAS ============================================================================= |
| 4320 | void ras_feature_init(bool is_feature_enabled) |
| 4321 | { |
| 4322 | audio_extn_ras_feature_enabled = is_feature_enabled; |
| 4323 | ALOGD(":: %s: ---- Feature RAS_FEATURE is %s ----", __func__, is_feature_enabled? "ENABLED": " NOT ENABLED"); |
| 4324 | } |
| 4325 | |
| 4326 | bool audio_extn_is_ras_enabled(void) |
| 4327 | { |
| 4328 | bool ret = false; |
| 4329 | |
| 4330 | if(audio_extn_ras_feature_enabled) |
| 4331 | { |
| 4332 | ALOGD("%s: status: %d", __func__, aextnmod.ras_enabled); |
| 4333 | return (aextnmod.ras_enabled ? true: false); |
| 4334 | } |
| 4335 | return ret; |
| 4336 | } |
| 4337 | |
| 4338 | bool audio_extn_can_use_ras(void) |
| 4339 | { |
| 4340 | bool ret = false; |
| 4341 | |
| 4342 | if(audio_extn_ras_feature_enabled) |
| 4343 | { |
| 4344 | if (property_get_bool("persist.vendor.audio.ras.enabled", false)) |
| 4345 | aextnmod.ras_enabled = 1; |
| 4346 | ALOGD("%s: ras.enabled property is set to %d", __func__, aextnmod.ras_enabled); |
| 4347 | return (aextnmod.ras_enabled ? true: false); |
| 4348 | } |
| 4349 | return ret; |
| 4350 | } |
| 4351 | |
| 4352 | //END: RAS =============================================================================== |
| 4353 | |
| 4354 | //START: KPI_OPTIMIZE ============================================================================= |
| 4355 | void kpi_optimize_feature_init(bool is_feature_enabled) |
| 4356 | { |
| 4357 | audio_extn_kpi_optimize_feature_enabled = is_feature_enabled; |
| 4358 | ALOGD(":: %s: ---- Feature KPI_OPTIMIZE is %s ----", __func__, is_feature_enabled? "ENABLED": " NOT ENABLED"); |
| 4359 | } |
| 4360 | |
| 4361 | typedef int (*perf_lock_acquire_t)(int, int, int*, int); |
| 4362 | typedef int (*perf_lock_release_t)(int); |
| 4363 | |
| 4364 | static void *qcopt_handle; |
| 4365 | static perf_lock_acquire_t perf_lock_acq; |
| 4366 | static perf_lock_release_t perf_lock_rel; |
| 4367 | |
| 4368 | char opt_lib_path[512] = {0}; |
| 4369 | |
| 4370 | int audio_extn_perf_lock_init(void) |
| 4371 | { |
| 4372 | int ret = 0; |
| 4373 | |
| 4374 | //if feature is disabled, exit immediately |
| 4375 | if(!audio_extn_kpi_optimize_feature_enabled) |
| 4376 | goto err; |
| 4377 | |
| 4378 | if (qcopt_handle == NULL) { |
| 4379 | if (property_get("ro.vendor.extension_library", |
| 4380 | opt_lib_path, NULL) <= 0) { |
| 4381 | ALOGE("%s: Failed getting perf property \n", __func__); |
| 4382 | ret = -EINVAL; |
| 4383 | goto err; |
| 4384 | } |
| 4385 | if ((qcopt_handle = dlopen(opt_lib_path, RTLD_NOW)) == NULL) { |
| 4386 | ALOGE("%s: Failed to open perf handle \n", __func__); |
| 4387 | ret = -EINVAL; |
| 4388 | goto err; |
| 4389 | } else { |
| 4390 | perf_lock_acq = (perf_lock_acquire_t)dlsym(qcopt_handle, |
| 4391 | "perf_lock_acq"); |
| 4392 | if (perf_lock_acq == NULL) { |
| 4393 | ALOGE("%s: Perf lock Acquire NULL \n", __func__); |
| 4394 | dlclose(qcopt_handle); |
| 4395 | ret = -EINVAL; |
| 4396 | goto err; |
| 4397 | } |
| 4398 | perf_lock_rel = (perf_lock_release_t)dlsym(qcopt_handle, |
| 4399 | "perf_lock_rel"); |
| 4400 | if (perf_lock_rel == NULL) { |
| 4401 | ALOGE("%s: Perf lock Release NULL \n", __func__); |
| 4402 | dlclose(qcopt_handle); |
| 4403 | ret = -EINVAL; |
| 4404 | goto err; |
| 4405 | } |
| 4406 | ALOGE("%s: Perf lock handles Success \n", __func__); |
| 4407 | } |
| 4408 | } |
| 4409 | err: |
| 4410 | return ret; |
| 4411 | } |
| 4412 | |
| 4413 | void audio_extn_perf_lock_acquire(int *handle, int duration, |
| 4414 | int *perf_lock_opts, int size) |
| 4415 | { |
| 4416 | if (audio_extn_kpi_optimize_feature_enabled) |
| 4417 | { |
| 4418 | if (!perf_lock_opts || !size || !perf_lock_acq || !handle) { |
| 4419 | ALOGE("%s: Incorrect params, Failed to acquire perf lock, err ", |
| 4420 | __func__); |
| 4421 | return; |
| 4422 | } |
| 4423 | /* |
| 4424 | * Acquire performance lock for 1 sec during device path bringup. |
| 4425 | * Lock will be released either after 1 sec or when perf_lock_release |
| 4426 | * function is executed. |
| 4427 | */ |
| 4428 | *handle = perf_lock_acq(*handle, duration, perf_lock_opts, size); |
| 4429 | if (*handle <= 0) |
| 4430 | ALOGE("%s: Failed to acquire perf lock, err: %d\n", |
| 4431 | __func__, *handle); |
| 4432 | } |
| 4433 | } |
| 4434 | |
| 4435 | void audio_extn_perf_lock_release(int *handle) |
| 4436 | { |
| 4437 | if (audio_extn_kpi_optimize_feature_enabled) { |
| 4438 | if (perf_lock_rel && handle && (*handle > 0)) { |
| 4439 | perf_lock_rel(*handle); |
| 4440 | *handle = 0; |
| 4441 | } else |
| 4442 | ALOGE("%s: Perf lock release error \n", __func__); |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | //END: KPI_OPTIMIZE ============================================================================= |
| 4447 | |
| 4448 | //START: DISPLAY_PORT ============================================================================= |
| 4449 | void display_port_feature_init(bool is_feature_enabled) |
| 4450 | { |
| 4451 | audio_extn_display_port_feature_enabled = is_feature_enabled; |
| 4452 | ALOGD(":: %s: ---- Feature DISPLAY_PORT is %s ----", __func__, is_feature_enabled? "ENABLED": " NOT ENABLED"); |
| 4453 | } |
| 4454 | |
| 4455 | bool audio_extn_is_display_port_enabled() |
| 4456 | { |
| 4457 | return audio_extn_display_port_feature_enabled; |
| 4458 | } |
| 4459 | //END: DISPLAY_PORT =============================================================================== |
| 4460 | //START: FLUENCE ============================================================================= |
| 4461 | void fluence_feature_init(bool is_feature_enabled) |
| 4462 | { |
| 4463 | audio_extn_fluence_feature_enabled = is_feature_enabled; |
| 4464 | ALOGD(":: %s: ---- Feature FLUENCE is %s ----", __func__, is_feature_enabled? "ENABLED": " NOT ENABLED"); |
| 4465 | } |
| 4466 | |
| 4467 | bool audio_extn_is_fluence_enabled() |
| 4468 | { |
| 4469 | return audio_extn_fluence_feature_enabled; |
| 4470 | } |
| 4471 | |
| 4472 | void audio_extn_set_fluence_parameters(struct audio_device *adev, |
| 4473 | struct str_parms *parms) |
| 4474 | { |
| 4475 | int ret = 0, err; |
| 4476 | char value[32]; |
| 4477 | struct listnode *node; |
| 4478 | struct audio_usecase *usecase; |
| 4479 | |
| 4480 | if (audio_extn_is_fluence_enabled()) { |
| 4481 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE, |
| 4482 | value, sizeof(value)); |
| 4483 | ALOGV_IF(err >= 0, "%s: Set Fluence Type to %s", __func__, value); |
| 4484 | if (err >= 0) { |
| 4485 | ret = platform_set_fluence_type(adev->platform, value); |
| 4486 | if (ret != 0) { |
| 4487 | ALOGE("platform_set_fluence_type returned error: %d", ret); |
| 4488 | } else { |
| 4489 | /* |
| 4490 | *If the fluence is manually set/reset, devices |
| 4491 | *need to get updated for all the usecases |
| 4492 | *i.e. audio and voice. |
| 4493 | */ |
| 4494 | list_for_each(node, &adev->usecase_list) { |
| 4495 | usecase = node_to_item(node, struct audio_usecase, list); |
| 4496 | select_devices(adev, usecase->id); |
| 4497 | } |
| 4498 | } |
| 4499 | } |
| 4500 | |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | int audio_extn_get_fluence_parameters(const struct audio_device *adev, |
| 4505 | struct str_parms *query, struct str_parms *reply) |
| 4506 | { |
| 4507 | int ret = -1, err; |
| 4508 | char value[256] = {0}; |
| 4509 | |
| 4510 | if (audio_extn_is_fluence_enabled()) { |
| 4511 | err = str_parms_get_str(query, AUDIO_PARAMETER_KEY_FLUENCE, value, |
| 4512 | sizeof(value)); |
| 4513 | if (err >= 0) { |
| 4514 | ret = platform_get_fluence_type(adev->platform, value, sizeof(value)); |
| 4515 | if (ret >= 0) { |
| 4516 | ALOGV("%s: Fluence Type is %s", __func__, value); |
| 4517 | str_parms_add_str(reply, AUDIO_PARAMETER_KEY_FLUENCE, value); |
| 4518 | } else |
| 4519 | goto done; |
| 4520 | } |
| 4521 | } |
| 4522 | done: |
| 4523 | return ret; |
| 4524 | } |
| 4525 | //END: FLUENCE =============================================================================== |
Sujin Panicker | b904fbe | 2019-04-04 13:28:07 +0530 | [diff] [blame] | 4526 | //START: WSA ============================================================================= |
| 4527 | void wsa_feature_init(bool is_feature_enabled) |
| 4528 | { |
| 4529 | audio_extn_wsa_enabled = is_feature_enabled; |
| 4530 | } |
| 4531 | |
| 4532 | bool audio_extn_is_wsa_enabled() |
| 4533 | { |
| 4534 | return audio_extn_wsa_enabled; |
| 4535 | } |
| 4536 | //END: WSA =============================================================================== |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4537 | //START: CUSTOM_STEREO ============================================================================= |
| 4538 | void custom_stereo_feature_init(bool is_feature_enabled) |
| 4539 | { |
| 4540 | audio_extn_custom_stereo_feature_enabled = is_feature_enabled; |
| 4541 | ALOGD(":: %s: ---- Feature CUSTOM_STEREO is %s ----", __func__, is_feature_enabled? "ENABLED": " NOT ENABLED"); |
| 4542 | } |
| 4543 | |
| 4544 | bool audio_extn_is_custom_stereo_enabled() |
| 4545 | { |
| 4546 | return audio_extn_custom_stereo_feature_enabled; |
| 4547 | } |
| 4548 | |
| 4549 | void audio_extn_customstereo_set_parameters(struct audio_device *adev, |
| 4550 | struct str_parms *parms) |
| 4551 | { |
| 4552 | int ret = 0; |
| 4553 | char value[32]={0}; |
| 4554 | bool custom_stereo_state = false; |
| 4555 | const char *mixer_ctl_name = "Set Custom Stereo OnOff"; |
| 4556 | struct mixer_ctl *ctl; |
| 4557 | |
| 4558 | ALOGV("%s", __func__); |
| 4559 | |
| 4560 | if (audio_extn_custom_stereo_feature_enabled) { |
| 4561 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_CUSTOM_STEREO, value, |
| 4562 | sizeof(value)); |
| 4563 | if (ret >= 0) { |
| 4564 | if (!strncmp("true", value, sizeof("true")) || atoi(value)) |
| 4565 | custom_stereo_state = true; |
| 4566 | |
| 4567 | if (custom_stereo_state == aextnmod.custom_stereo_enabled) |
| 4568 | return; |
| 4569 | |
| 4570 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 4571 | if (!ctl) { |
| 4572 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 4573 | __func__, mixer_ctl_name); |
| 4574 | return; |
| 4575 | } |
| 4576 | if (mixer_ctl_set_value(ctl, 0, custom_stereo_state) < 0) { |
| 4577 | ALOGE("%s: Could not set custom stereo state %d", |
| 4578 | __func__, custom_stereo_state); |
| 4579 | return; |
| 4580 | } |
| 4581 | aextnmod.custom_stereo_enabled = custom_stereo_state; |
| 4582 | ALOGV("%s: Setting custom stereo state success", __func__); |
| 4583 | } |
| 4584 | } |
| 4585 | } |
| 4586 | |
| 4587 | void audio_extn_send_dual_mono_mixing_coefficients(struct stream_out *out) |
| 4588 | { |
| 4589 | struct audio_device *adev = out->dev; |
| 4590 | struct mixer_ctl *ctl; |
| 4591 | char mixer_ctl_name[128]; |
| 4592 | int cust_ch_mixer_cfg[128], len = 0; |
| 4593 | int ip_channel_cnt = audio_channel_count_from_out_mask(out->channel_mask); |
| 4594 | int pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK); |
| 4595 | int op_channel_cnt= 2; |
| 4596 | int i, j, err; |
| 4597 | |
| 4598 | ALOGV("%s", __func__); |
| 4599 | |
| 4600 | if (audio_extn_custom_stereo_feature_enabled) { |
| 4601 | if (!out->started) { |
| 4602 | out->set_dual_mono = true; |
| 4603 | goto exit; |
| 4604 | } |
| 4605 | |
| 4606 | ALOGD("%s: i/p channel count %d, o/p channel count %d, pcm id %d", __func__, |
| 4607 | ip_channel_cnt, op_channel_cnt, pcm_device_id); |
| 4608 | |
| 4609 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 4610 | "Audio Stream %d Channel Mix Cfg", pcm_device_id); |
| 4611 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 4612 | if (!ctl) { |
| 4613 | ALOGE("%s: ERROR. Could not get ctl for mixer cmd - %s", |
| 4614 | __func__, mixer_ctl_name); |
| 4615 | goto exit; |
| 4616 | } |
| 4617 | |
| 4618 | /* Output channel count corresponds to backend configuration channels. |
| 4619 | * Input channel count corresponds to ASM session channels. |
| 4620 | * Set params is called with channels that need to be selected from |
| 4621 | * input to generate output. |
| 4622 | * ex: "8,2" to downmix from 8 to 2 i.e. to downmix from 8 to 2, |
| 4623 | * |
| 4624 | * This mixer control takes values in the following sequence: |
| 4625 | * - input channel count(m) |
| 4626 | * - output channel count(n) |
| 4627 | * - weight coeff for [out ch#1, in ch#1] |
| 4628 | * .... |
| 4629 | * - weight coeff for [out ch#1, in ch#m] |
| 4630 | * |
| 4631 | * - weight coeff for [out ch#2, in ch#1] |
| 4632 | * .... |
| 4633 | * - weight coeff for [out ch#2, in ch#m] |
| 4634 | * |
| 4635 | * - weight coeff for [out ch#n, in ch#1] |
| 4636 | * .... |
| 4637 | * - weight coeff for [out ch#n, in ch#m] |
| 4638 | * |
| 4639 | * To get dualmono ouptu weightage coeff is calculated as Unity gain |
| 4640 | * divided by number of input channels. |
| 4641 | */ |
| 4642 | cust_ch_mixer_cfg[len++] = ip_channel_cnt; |
| 4643 | cust_ch_mixer_cfg[len++] = op_channel_cnt; |
| 4644 | for (i = 0; i < op_channel_cnt; i++) { |
| 4645 | for (j = 0; j < ip_channel_cnt; j++) { |
| 4646 | cust_ch_mixer_cfg[len++] = Q14_GAIN_UNITY/ip_channel_cnt; |
| 4647 | } |
| 4648 | } |
| 4649 | |
| 4650 | err = mixer_ctl_set_array(ctl, cust_ch_mixer_cfg, len); |
| 4651 | if (err) |
| 4652 | ALOGE("%s: ERROR. Mixer ctl set failed", __func__); |
| 4653 | |
| 4654 | } |
| 4655 | exit: |
| 4656 | return; |
| 4657 | } |
| 4658 | //END: CUSTOM_STEREO ============================================================================= |
| 4659 | // START: A2DP_OFFLOAD =================================================================== |
| 4660 | #ifdef __LP64__ |
| 4661 | #define A2DP_OFFLOAD_LIB_PATH "/vendor/lib64/liba2dpoffload.so" |
| 4662 | #else |
| 4663 | #define A2DP_OFFLOAD_LIB_PATH "/vendor/lib/liba2dpoffload.so" |
| 4664 | #endif |
| 4665 | |
| 4666 | static void *a2dp_lib_handle = NULL; |
| 4667 | |
Aalique Grahame | 6e76371 | 2019-01-31 16:18:17 -0800 | [diff] [blame] | 4668 | typedef void (*a2dp_init_t)(void *, a2dp_offload_init_config_t); |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4669 | static a2dp_init_t a2dp_init; |
| 4670 | |
| 4671 | typedef int (*a2dp_start_playback_t)(); |
| 4672 | static a2dp_start_playback_t a2dp_start_playback; |
| 4673 | |
| 4674 | typedef int (*a2dp_stop_playback_t)(); |
| 4675 | static a2dp_stop_playback_t a2dp_stop_playback; |
| 4676 | |
| 4677 | typedef int (*a2dp_set_parameters_t)(struct str_parms *, |
| 4678 | bool *); |
| 4679 | static a2dp_set_parameters_t a2dp_set_parameters; |
| 4680 | |
| 4681 | typedef int (*a2dp_get_parameters_t)(struct str_parms *, |
| 4682 | struct str_parms *); |
| 4683 | static a2dp_get_parameters_t a2dp_get_parameters; |
| 4684 | |
| 4685 | typedef bool (*a2dp_is_force_device_switch_t)(); |
| 4686 | static a2dp_is_force_device_switch_t a2dp_is_force_device_switch; |
| 4687 | |
| 4688 | typedef void (*a2dp_set_handoff_mode_t)(bool); |
| 4689 | static a2dp_set_handoff_mode_t a2dp_set_handoff_mode; |
| 4690 | |
| 4691 | typedef void (*a2dp_get_enc_sample_rate_t)(int *); |
| 4692 | static a2dp_get_enc_sample_rate_t a2dp_get_enc_sample_rate; |
| 4693 | |
| 4694 | typedef void (*a2dp_get_dec_sample_rate_t)(int *); |
| 4695 | static a2dp_get_dec_sample_rate_t a2dp_get_dec_sample_rate; |
| 4696 | |
| 4697 | typedef uint32_t (*a2dp_get_encoder_latency_t)(); |
| 4698 | static a2dp_get_encoder_latency_t a2dp_get_encoder_latency; |
| 4699 | |
| 4700 | typedef bool (*a2dp_sink_is_ready_t)(); |
| 4701 | static a2dp_sink_is_ready_t a2dp_sink_is_ready; |
| 4702 | |
| 4703 | typedef bool (*a2dp_source_is_ready_t)(); |
| 4704 | static a2dp_source_is_ready_t a2dp_source_is_ready; |
| 4705 | |
| 4706 | typedef bool (*a2dp_source_is_suspended_t)(); |
| 4707 | static a2dp_source_is_suspended_t a2dp_source_is_suspended; |
| 4708 | |
| 4709 | typedef int (*a2dp_start_capture_t)(); |
| 4710 | static a2dp_start_capture_t a2dp_start_capture; |
| 4711 | |
| 4712 | typedef int (*a2dp_stop_capture_t)(); |
| 4713 | static a2dp_stop_capture_t a2dp_stop_capture; |
| 4714 | |
Aniket Kumar Lata | 990de55 | 2019-07-11 14:20:23 -0700 | [diff] [blame] | 4715 | typedef bool (*a2dp_set_source_backend_cfg_t)(); |
| 4716 | static a2dp_set_source_backend_cfg_t a2dp_set_source_backend_cfg; |
| 4717 | |
Zhou Song | 12c2950 | 2019-03-16 10:37:18 +0800 | [diff] [blame] | 4718 | typedef int (*sco_start_configuration_t)(); |
| 4719 | static sco_start_configuration_t sco_start_configuration; |
| 4720 | |
| 4721 | typedef void (*sco_reset_configuration_t)(); |
| 4722 | static sco_reset_configuration_t sco_reset_configuration; |
| 4723 | |
| 4724 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4725 | int a2dp_offload_feature_init(bool is_feature_enabled) |
| 4726 | { |
| 4727 | ALOGD("%s: Called with feature %s", __func__, |
| 4728 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
| 4729 | if (is_feature_enabled) { |
| 4730 | // dlopen lib |
| 4731 | a2dp_lib_handle = dlopen(A2DP_OFFLOAD_LIB_PATH, RTLD_NOW); |
| 4732 | |
| 4733 | if (!a2dp_lib_handle) { |
| 4734 | ALOGE("%s: dlopen failed", __func__); |
| 4735 | goto feature_disabled; |
| 4736 | } |
| 4737 | |
| 4738 | if (!(a2dp_init = (a2dp_init_t)dlsym(a2dp_lib_handle, "a2dp_init")) || |
| 4739 | !(a2dp_start_playback = |
| 4740 | (a2dp_start_playback_t)dlsym(a2dp_lib_handle, "a2dp_start_playback")) || |
| 4741 | !(a2dp_stop_playback = |
| 4742 | (a2dp_stop_playback_t)dlsym(a2dp_lib_handle, "a2dp_stop_playback")) || |
| 4743 | !(a2dp_set_parameters = |
| 4744 | (a2dp_set_parameters_t)dlsym(a2dp_lib_handle, "a2dp_set_parameters")) || |
| 4745 | !(a2dp_get_parameters = |
| 4746 | (a2dp_get_parameters_t)dlsym(a2dp_lib_handle, "a2dp_get_parameters")) || |
| 4747 | !(a2dp_is_force_device_switch = |
| 4748 | (a2dp_is_force_device_switch_t)dlsym( |
| 4749 | a2dp_lib_handle, "a2dp_is_force_device_switch")) || |
| 4750 | !(a2dp_set_handoff_mode = |
| 4751 | (a2dp_set_handoff_mode_t)dlsym( |
| 4752 | a2dp_lib_handle, "a2dp_set_handoff_mode")) || |
| 4753 | !(a2dp_get_enc_sample_rate = |
| 4754 | (a2dp_get_enc_sample_rate_t)dlsym( |
| 4755 | a2dp_lib_handle, "a2dp_get_enc_sample_rate")) || |
| 4756 | !(a2dp_get_dec_sample_rate = |
| 4757 | (a2dp_get_dec_sample_rate_t)dlsym( |
| 4758 | a2dp_lib_handle, "a2dp_get_dec_sample_rate")) || |
| 4759 | !(a2dp_get_encoder_latency = |
| 4760 | (a2dp_get_encoder_latency_t)dlsym( |
| 4761 | a2dp_lib_handle, "a2dp_get_encoder_latency")) || |
| 4762 | !(a2dp_sink_is_ready = |
| 4763 | (a2dp_sink_is_ready_t)dlsym(a2dp_lib_handle, "a2dp_sink_is_ready")) || |
| 4764 | !(a2dp_source_is_ready = |
| 4765 | (a2dp_source_is_ready_t)dlsym(a2dp_lib_handle, "a2dp_source_is_ready")) || |
| 4766 | !(a2dp_source_is_suspended = |
| 4767 | (a2dp_source_is_suspended_t)dlsym( |
| 4768 | a2dp_lib_handle, "a2dp_source_is_suspended")) || |
| 4769 | !(a2dp_start_capture = |
| 4770 | (a2dp_start_capture_t)dlsym(a2dp_lib_handle, "a2dp_start_capture")) || |
| 4771 | !(a2dp_stop_capture = |
Aniket Kumar Lata | 990de55 | 2019-07-11 14:20:23 -0700 | [diff] [blame] | 4772 | (a2dp_stop_capture_t)dlsym(a2dp_lib_handle, "a2dp_stop_capture")) || |
| 4773 | !(a2dp_set_source_backend_cfg = |
| 4774 | (a2dp_set_source_backend_cfg_t)dlsym( |
| 4775 | a2dp_lib_handle, "a2dp_set_source_backend_cfg"))) { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4776 | ALOGE("%s: dlsym failed", __func__); |
| 4777 | goto feature_disabled; |
| 4778 | } |
Zhou Song | 12c2950 | 2019-03-16 10:37:18 +0800 | [diff] [blame] | 4779 | // initialize APIs for SWB extension |
| 4780 | if (!(sco_start_configuration = |
| 4781 | (sco_start_configuration_t)dlsym(a2dp_lib_handle, "sco_start_configuration")) || |
| 4782 | !(sco_reset_configuration = |
| 4783 | (sco_reset_configuration_t)dlsym(a2dp_lib_handle, "sco_reset_configuration"))) { |
| 4784 | ALOGE("%s: dlsym failed for swb APIs", __func__); |
| 4785 | sco_start_configuration = NULL; |
| 4786 | sco_reset_configuration = NULL; |
| 4787 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4788 | ALOGD("%s:: ---- Feature A2DP_OFFLOAD is Enabled ----", __func__); |
| 4789 | return 0; |
| 4790 | } |
| 4791 | |
| 4792 | feature_disabled: |
| 4793 | if (a2dp_lib_handle) { |
| 4794 | dlclose(a2dp_lib_handle); |
| 4795 | a2dp_lib_handle = NULL; |
| 4796 | } |
| 4797 | |
| 4798 | a2dp_init = NULL; |
| 4799 | a2dp_start_playback= NULL; |
| 4800 | a2dp_stop_playback = NULL; |
| 4801 | a2dp_set_parameters = NULL; |
| 4802 | a2dp_get_parameters = NULL; |
| 4803 | a2dp_is_force_device_switch = NULL; |
| 4804 | a2dp_set_handoff_mode = NULL; |
| 4805 | a2dp_get_enc_sample_rate = NULL; |
| 4806 | a2dp_get_dec_sample_rate = NULL; |
| 4807 | a2dp_get_encoder_latency = NULL; |
| 4808 | a2dp_sink_is_ready = NULL; |
| 4809 | a2dp_source_is_ready = NULL; |
| 4810 | a2dp_source_is_suspended = NULL; |
| 4811 | a2dp_start_capture = NULL; |
| 4812 | a2dp_stop_capture = NULL; |
Aniket Kumar Lata | 990de55 | 2019-07-11 14:20:23 -0700 | [diff] [blame] | 4813 | a2dp_set_source_backend_cfg = NULL; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4814 | |
| 4815 | ALOGW(":: %s: ---- Feature A2DP_OFFLOAD is disabled ----", __func__); |
| 4816 | return -ENOSYS; |
| 4817 | } |
| 4818 | |
| 4819 | void audio_extn_a2dp_init(void *adev) |
| 4820 | { |
| 4821 | if (a2dp_init) { |
Aalique Grahame | 6e76371 | 2019-01-31 16:18:17 -0800 | [diff] [blame] | 4822 | a2dp_offload_init_config_t a2dp_init_config; |
| 4823 | a2dp_init_config.fp_platform_get_pcm_device_id = platform_get_pcm_device_id; |
Weiyin Jiang | 280ea74 | 2020-09-08 20:28:22 +0800 | [diff] [blame] | 4824 | a2dp_init_config.fp_check_a2dp_restore_l = check_a2dp_restore_l; |
Gautam Manam | fbb3ebc | 2020-10-08 18:06:45 +0530 | [diff] [blame] | 4825 | a2dp_init_config.fp_platform_switch_voice_call_device_post = platform_switch_voice_call_device_post; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4826 | |
| 4827 | a2dp_init(adev, a2dp_init_config); |
| 4828 | } |
| 4829 | } |
| 4830 | |
| 4831 | int audio_extn_a2dp_start_playback() |
| 4832 | { |
| 4833 | return (a2dp_start_playback ? a2dp_start_playback() : 0); |
| 4834 | } |
| 4835 | |
| 4836 | int audio_extn_a2dp_stop_playback() |
| 4837 | { |
| 4838 | return (a2dp_stop_playback ? a2dp_stop_playback() : 0); |
| 4839 | } |
| 4840 | |
| 4841 | int audio_extn_a2dp_set_parameters(struct str_parms *parms, |
| 4842 | bool *reconfig) |
| 4843 | { |
| 4844 | return (a2dp_set_parameters ? |
| 4845 | a2dp_set_parameters(parms, reconfig) : 0); |
| 4846 | } |
| 4847 | |
| 4848 | int audio_extn_a2dp_get_parameters(struct str_parms *query, |
| 4849 | struct str_parms *reply) |
| 4850 | { |
| 4851 | return (a2dp_get_parameters ? |
| 4852 | a2dp_get_parameters(query, reply) : 0); |
| 4853 | } |
| 4854 | |
| 4855 | bool audio_extn_a2dp_is_force_device_switch() |
| 4856 | { |
| 4857 | return (a2dp_is_force_device_switch ? |
| 4858 | a2dp_is_force_device_switch() : false); |
| 4859 | } |
| 4860 | |
| 4861 | void audio_extn_a2dp_set_handoff_mode(bool is_on) |
| 4862 | { |
| 4863 | if (a2dp_set_handoff_mode) |
| 4864 | a2dp_set_handoff_mode(is_on); |
| 4865 | } |
| 4866 | |
| 4867 | void audio_extn_a2dp_get_enc_sample_rate(int *sample_rate) |
| 4868 | { |
| 4869 | if (a2dp_get_enc_sample_rate) |
| 4870 | a2dp_get_enc_sample_rate(sample_rate); |
| 4871 | } |
| 4872 | |
| 4873 | void audio_extn_a2dp_get_dec_sample_rate(int *sample_rate) |
| 4874 | { |
| 4875 | if (a2dp_get_dec_sample_rate) |
| 4876 | a2dp_get_dec_sample_rate(sample_rate); |
| 4877 | } |
| 4878 | |
| 4879 | uint32_t audio_extn_a2dp_get_encoder_latency() |
| 4880 | { |
| 4881 | return (a2dp_get_encoder_latency ? |
| 4882 | a2dp_get_encoder_latency() : 0); |
| 4883 | } |
| 4884 | |
Kakanaboina Ramanjaneyulu | 8cedb09 | 2021-03-15 15:55:29 +0530 | [diff] [blame] | 4885 | uint32_t audio_extn_a2dp_get_decoder_latency() |
| 4886 | { |
| 4887 | return (a2dp_get_encoder_latency ? |
| 4888 | a2dp_get_encoder_latency() : 0); |
| 4889 | } |
| 4890 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4891 | bool audio_extn_a2dp_sink_is_ready() |
| 4892 | { |
| 4893 | return (a2dp_sink_is_ready ? |
| 4894 | a2dp_sink_is_ready() : false); |
| 4895 | } |
| 4896 | |
| 4897 | bool audio_extn_a2dp_source_is_ready() |
| 4898 | { |
| 4899 | return (a2dp_source_is_ready ? |
| 4900 | a2dp_source_is_ready() : false); |
| 4901 | } |
| 4902 | |
| 4903 | bool audio_extn_a2dp_source_is_suspended() |
| 4904 | { |
| 4905 | return (a2dp_source_is_suspended ? |
| 4906 | a2dp_source_is_suspended() : false); |
| 4907 | } |
| 4908 | |
| 4909 | int audio_extn_a2dp_start_capture() |
| 4910 | { |
| 4911 | return (a2dp_start_capture ? a2dp_start_capture() : 0); |
| 4912 | } |
| 4913 | |
| 4914 | int audio_extn_a2dp_stop_capture() |
| 4915 | { |
| 4916 | return (a2dp_stop_capture ? a2dp_stop_capture() : 0); |
| 4917 | } |
| 4918 | |
Aniket Kumar Lata | 990de55 | 2019-07-11 14:20:23 -0700 | [diff] [blame] | 4919 | bool audio_extn_a2dp_set_source_backend_cfg() |
| 4920 | { |
| 4921 | return (a2dp_set_source_backend_cfg ? |
| 4922 | a2dp_set_source_backend_cfg() : false); |
| 4923 | } |
| 4924 | |
Zhou Song | 12c2950 | 2019-03-16 10:37:18 +0800 | [diff] [blame] | 4925 | int audio_extn_sco_start_configuration() |
| 4926 | { |
| 4927 | return (sco_start_configuration? sco_start_configuration() : 0); |
| 4928 | } |
| 4929 | |
| 4930 | void audio_extn_sco_reset_configuration() |
| 4931 | { |
| 4932 | return (sco_reset_configuration? sco_reset_configuration() : 0); |
| 4933 | } |
| 4934 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 4935 | // END: A2DP_OFFLOAD ===================================================================== |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4936 | |
| 4937 | // START: HFP ====================================================================== |
| 4938 | #ifdef __LP64__ |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 4939 | #ifdef LINUX_ENABLED |
| 4940 | #define HFP_LIB_PATH "/usr/lib64/libhfp.so" |
Shuai Zhang | 437b212 | 2022-04-25 15:30:08 +0530 | [diff] [blame] | 4941 | #define LINUX_PATH true |
| 4942 | #ifdef HAL_LIBRARY_PATH |
| 4943 | #define HFP_LIB_PATH HAL_LIBRARY_PATH |
| 4944 | #endif |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 4945 | #else |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4946 | #define HFP_LIB_PATH "/vendor/lib64/libhfp.so" |
Shuai Zhang | 437b212 | 2022-04-25 15:30:08 +0530 | [diff] [blame] | 4947 | #define LINUX_PATH false |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 4948 | #endif |
| 4949 | #else |
| 4950 | #ifdef LINUX_ENABLED |
| 4951 | #define HFP_LIB_PATH "/usr/lib/libhfp.so" |
Shuai Zhang | 437b212 | 2022-04-25 15:30:08 +0530 | [diff] [blame] | 4952 | #define LINUX_PATH true |
| 4953 | #ifdef HAL_LIBRARY_PATH |
| 4954 | #define HFP_LIB_PATH HAL_LIBRARY_PATH |
| 4955 | #endif |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4956 | #else |
| 4957 | #define HFP_LIB_PATH "/vendor/lib/libhfp.so" |
Shuai Zhang | 437b212 | 2022-04-25 15:30:08 +0530 | [diff] [blame] | 4958 | #define LINUX_PATH false |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4959 | #endif |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 4960 | #endif |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4961 | |
| 4962 | static void *hfp_lib_handle = NULL; |
| 4963 | |
| 4964 | typedef void (*hfp_init_t)(hfp_init_config_t); |
| 4965 | static hfp_init_t hfp_init; |
| 4966 | |
| 4967 | typedef bool (*hfp_is_active_t)(struct audio_device *adev); |
| 4968 | static hfp_is_active_t hfp_is_active; |
| 4969 | |
| 4970 | typedef audio_usecase_t (*hfp_get_usecase_t)(); |
| 4971 | static hfp_get_usecase_t hfp_get_usecase; |
| 4972 | |
| 4973 | typedef int (*hfp_set_mic_mute_t)(struct audio_device *dev, bool state); |
| 4974 | static hfp_set_mic_mute_t hfp_set_mic_mute; |
| 4975 | |
| 4976 | typedef void (*hfp_set_parameters_t)(struct audio_device *adev, |
| 4977 | struct str_parms *parms); |
| 4978 | static hfp_set_parameters_t hfp_set_parameters; |
| 4979 | |
| 4980 | typedef int (*hfp_set_mic_mute2_t)(struct audio_device *adev, bool state); |
| 4981 | static hfp_set_mic_mute2_t hfp_set_mic_mute2; |
| 4982 | |
| 4983 | int hfp_feature_init(bool is_feature_enabled) |
| 4984 | { |
| 4985 | ALOGD("%s: Called with feature %s", __func__, |
| 4986 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
| 4987 | if (is_feature_enabled) { |
| 4988 | // dlopen lib |
Shuai Zhang | 437b212 | 2022-04-25 15:30:08 +0530 | [diff] [blame] | 4989 | if (LINUX_PATH) { |
| 4990 | char libhfp_path[100]; |
| 4991 | snprintf(libhfp_path, sizeof(libhfp_path), "%s/libhfp.so", HFP_LIB_PATH); |
| 4992 | hfp_lib_handle = dlopen(libhfp_path, RTLD_NOW); |
| 4993 | } else |
| 4994 | hfp_lib_handle = dlopen(HFP_LIB_PATH , RTLD_NOW); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 4995 | if (!hfp_lib_handle) { |
| 4996 | ALOGE("%s: dlopen failed", __func__); |
| 4997 | goto feature_disabled; |
| 4998 | } |
| 4999 | if (!(hfp_init = (hfp_init_t)dlsym( |
| 5000 | hfp_lib_handle, "hfp_init")) || |
| 5001 | !(hfp_is_active = |
| 5002 | (hfp_is_active_t)dlsym( |
| 5003 | hfp_lib_handle, "hfp_is_active")) || |
| 5004 | !(hfp_get_usecase = |
| 5005 | (hfp_get_usecase_t)dlsym( |
| 5006 | hfp_lib_handle, "hfp_get_usecase")) || |
| 5007 | !(hfp_set_mic_mute = |
| 5008 | (hfp_set_mic_mute_t)dlsym( |
| 5009 | hfp_lib_handle, "hfp_set_mic_mute")) || |
| 5010 | !(hfp_set_mic_mute2 = |
| 5011 | (hfp_set_mic_mute2_t)dlsym( |
| 5012 | hfp_lib_handle, "hfp_set_mic_mute2")) || |
| 5013 | !(hfp_set_parameters = |
| 5014 | (hfp_set_parameters_t)dlsym( |
| 5015 | hfp_lib_handle, "hfp_set_parameters"))) { |
| 5016 | ALOGE("%s: dlsym failed", __func__); |
| 5017 | goto feature_disabled; |
| 5018 | } |
| 5019 | hfp_init_config_t init_config; |
| 5020 | init_config.fp_platform_set_mic_mute = platform_set_mic_mute; |
| 5021 | init_config.fp_platform_get_pcm_device_id = platform_get_pcm_device_id; |
| 5022 | init_config.fp_platform_set_echo_reference = platform_set_echo_reference; |
| 5023 | init_config.fp_platform_set_mic_mute = platform_set_mic_mute; |
| 5024 | init_config.fp_select_devices = select_devices; |
| 5025 | init_config.fp_audio_extn_ext_hw_plugin_usecase_start = |
| 5026 | audio_extn_ext_hw_plugin_usecase_start; |
| 5027 | init_config.fp_audio_extn_ext_hw_plugin_usecase_stop = |
| 5028 | audio_extn_ext_hw_plugin_usecase_stop; |
| 5029 | init_config.fp_get_usecase_from_list = get_usecase_from_list; |
| 5030 | init_config.fp_disable_audio_route = disable_audio_route; |
| 5031 | init_config.fp_disable_snd_device = disable_snd_device; |
| 5032 | init_config.fp_voice_get_mic_mute = voice_get_mic_mute; |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 5033 | init_config.fp_audio_extn_auto_hal_start_hfp_downlink = |
| 5034 | audio_extn_auto_hal_start_hfp_downlink; |
| 5035 | init_config.fp_audio_extn_auto_hal_stop_hfp_downlink = |
| 5036 | audio_extn_auto_hal_stop_hfp_downlink; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5037 | |
| 5038 | hfp_init(init_config); |
| 5039 | ALOGD("%s:: ---- Feature HFP is Enabled ----", __func__); |
| 5040 | return 0; |
| 5041 | } |
| 5042 | |
| 5043 | feature_disabled: |
| 5044 | if (hfp_lib_handle) { |
| 5045 | dlclose(hfp_lib_handle); |
| 5046 | hfp_lib_handle = NULL; |
| 5047 | } |
| 5048 | |
| 5049 | hfp_init = NULL; |
| 5050 | hfp_is_active = NULL; |
| 5051 | hfp_get_usecase = NULL; |
| 5052 | hfp_set_mic_mute = NULL; |
| 5053 | hfp_set_mic_mute2 = NULL; |
| 5054 | hfp_set_parameters = NULL; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5055 | ALOGW(":: %s: ---- Feature HFP is disabled ----", __func__); |
| 5056 | return -ENOSYS; |
| 5057 | } |
| 5058 | |
| 5059 | bool audio_extn_hfp_is_active(struct audio_device *adev) |
| 5060 | { |
| 5061 | return ((hfp_is_active) ? |
| 5062 | hfp_is_active(adev): false); |
| 5063 | } |
| 5064 | |
| 5065 | audio_usecase_t audio_extn_hfp_get_usecase() |
| 5066 | { |
| 5067 | return ((hfp_get_usecase) ? |
| 5068 | hfp_get_usecase(): -1); |
| 5069 | } |
| 5070 | |
| 5071 | int audio_extn_hfp_set_mic_mute(struct audio_device *adev, bool state) |
| 5072 | { |
| 5073 | return ((hfp_set_mic_mute) ? |
| 5074 | hfp_set_mic_mute(adev, state): -1); |
| 5075 | } |
| 5076 | |
| 5077 | void audio_extn_hfp_set_parameters(struct audio_device *adev, |
| 5078 | struct str_parms *parms) |
| 5079 | { |
| 5080 | ((hfp_set_parameters) ? |
| 5081 | hfp_set_parameters(adev, parms): NULL); |
| 5082 | } |
| 5083 | |
| 5084 | int audio_extn_hfp_set_mic_mute2(struct audio_device *adev, bool state) |
| 5085 | { |
| 5086 | return ((hfp_set_mic_mute2) ? |
| 5087 | hfp_set_mic_mute2(adev, state): -1); |
| 5088 | } |
| 5089 | // END: HFP ======================================================================== |
| 5090 | |
Derek Chen | a30a5f4 | 2019-12-03 11:17:09 -0500 | [diff] [blame] | 5091 | // START: ICC ====================================================================== |
| 5092 | #ifdef __LP64__ |
| 5093 | #define ICC_LIB_PATH "/vendor/lib64/libicc.so" |
| 5094 | #else |
| 5095 | #define ICC_LIB_PATH "/vendor/lib/libicc.so" |
| 5096 | #endif |
| 5097 | |
| 5098 | static void *icc_lib_handle = NULL; |
| 5099 | |
| 5100 | typedef void (*icc_init_t)(icc_init_config_t); |
| 5101 | static icc_init_t icc_init; |
| 5102 | |
| 5103 | typedef bool (*icc_is_active_t)(struct audio_device *adev); |
| 5104 | static icc_is_active_t icc_is_active; |
| 5105 | |
| 5106 | typedef audio_usecase_t (*icc_get_usecase_t)(); |
| 5107 | static icc_get_usecase_t icc_get_usecase; |
| 5108 | |
| 5109 | typedef void (*icc_set_parameters_t)(struct audio_device *adev, |
| 5110 | struct str_parms *parms); |
| 5111 | static icc_set_parameters_t icc_set_parameters; |
| 5112 | |
| 5113 | int icc_feature_init(bool is_feature_enabled) |
| 5114 | { |
| 5115 | ALOGD("%s: Called with feature %s", __func__, |
| 5116 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
| 5117 | if (is_feature_enabled) { |
| 5118 | // dlopen lib |
| 5119 | icc_lib_handle = dlopen(ICC_LIB_PATH, RTLD_NOW); |
| 5120 | |
| 5121 | if (!icc_lib_handle) { |
| 5122 | ALOGE("%s: dlopen failed", __func__); |
| 5123 | goto feature_disabled; |
| 5124 | } |
| 5125 | if (!(icc_init = (icc_init_t)dlsym( |
| 5126 | icc_lib_handle, "icc_init")) || |
| 5127 | !(icc_is_active = |
| 5128 | (icc_is_active_t)dlsym( |
| 5129 | icc_lib_handle, "icc_is_active")) || |
| 5130 | !(icc_get_usecase = |
| 5131 | (icc_get_usecase_t)dlsym( |
| 5132 | icc_lib_handle, "icc_get_usecase")) || |
| 5133 | !(icc_set_parameters = |
| 5134 | (icc_set_parameters_t)dlsym( |
| 5135 | icc_lib_handle, "icc_set_parameters"))) { |
| 5136 | ALOGE("%s: dlsym failed", __func__); |
| 5137 | goto feature_disabled; |
| 5138 | } |
| 5139 | icc_init_config_t init_config; |
| 5140 | init_config.fp_platform_get_pcm_device_id = platform_get_pcm_device_id; |
| 5141 | init_config.fp_platform_set_echo_reference = platform_set_echo_reference; |
| 5142 | init_config.fp_select_devices = select_devices; |
| 5143 | init_config.fp_audio_extn_ext_hw_plugin_usecase_start = |
| 5144 | audio_extn_ext_hw_plugin_usecase_start; |
| 5145 | init_config.fp_audio_extn_ext_hw_plugin_usecase_stop = |
| 5146 | audio_extn_ext_hw_plugin_usecase_stop; |
| 5147 | init_config.fp_get_usecase_from_list = get_usecase_from_list; |
| 5148 | init_config.fp_disable_audio_route = disable_audio_route; |
| 5149 | init_config.fp_disable_snd_device = disable_snd_device; |
| 5150 | |
| 5151 | icc_init(init_config); |
| 5152 | ALOGD("%s:: ---- Feature ICC is Enabled ----", __func__); |
| 5153 | return 0; |
| 5154 | } |
| 5155 | |
| 5156 | feature_disabled: |
| 5157 | if (icc_lib_handle) { |
| 5158 | dlclose(icc_lib_handle); |
| 5159 | icc_lib_handle = NULL; |
| 5160 | } |
| 5161 | |
| 5162 | icc_init = NULL; |
| 5163 | icc_is_active = NULL; |
| 5164 | icc_get_usecase = NULL; |
| 5165 | icc_set_parameters = NULL; |
| 5166 | |
| 5167 | ALOGW(":: %s: ---- Feature ICC is disabled ----", __func__); |
| 5168 | return -ENOSYS; |
| 5169 | } |
| 5170 | |
| 5171 | bool audio_extn_icc_is_active(struct audio_device *adev) |
| 5172 | { |
| 5173 | return ((icc_is_active) ? |
| 5174 | icc_is_active(adev): false); |
| 5175 | } |
| 5176 | |
| 5177 | audio_usecase_t audio_extn_icc_get_usecase() |
| 5178 | { |
| 5179 | return ((icc_get_usecase) ? |
| 5180 | icc_get_usecase(): -1); |
| 5181 | } |
| 5182 | |
| 5183 | void audio_extn_icc_set_parameters(struct audio_device *adev, |
| 5184 | struct str_parms *parms) |
| 5185 | { |
| 5186 | ((icc_set_parameters) ? |
| 5187 | icc_set_parameters(adev, parms): NULL); |
| 5188 | } |
| 5189 | |
| 5190 | // END: ICC ======================================================================== |
| 5191 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5192 | // START: EXT_HW_PLUGIN =================================================================== |
| 5193 | #ifdef __LP64__ |
| 5194 | #define EXT_HW_PLUGIN_LIB_PATH "/vendor/lib64/libexthwplugin.so" |
| 5195 | #else |
| 5196 | #define EXT_HW_PLUGIN_LIB_PATH "/vendor/lib/libexthwplugin.so" |
| 5197 | #endif |
| 5198 | |
| 5199 | static void *ext_hw_plugin_lib_handle = NULL; |
| 5200 | |
| 5201 | typedef void* (*ext_hw_plugin_init_t)(struct audio_device*, |
| 5202 | ext_hw_plugin_init_config_t init_config); |
| 5203 | static ext_hw_plugin_init_t ext_hw_plugin_init; |
| 5204 | |
| 5205 | typedef int (*ext_hw_plugin_deinit_t)(void*); |
| 5206 | static ext_hw_plugin_deinit_t ext_hw_plugin_deinit; |
| 5207 | |
| 5208 | typedef int(*ext_hw_plugin_usecase_start_t)(void*, struct audio_usecase*); |
| 5209 | static ext_hw_plugin_usecase_start_t ext_hw_plugin_usecase_start; |
| 5210 | |
| 5211 | typedef int(*ext_hw_plugin_usecase_stop_t)(void*, struct audio_usecase*); |
| 5212 | static ext_hw_plugin_usecase_stop_t ext_hw_plugin_usecase_stop; |
| 5213 | |
| 5214 | typedef int(*ext_hw_plugin_set_parameters_t)(void*, struct str_parms*); |
| 5215 | static ext_hw_plugin_set_parameters_t ext_hw_plugin_set_parameters; |
| 5216 | |
| 5217 | typedef int(*ext_hw_plugin_get_parameters_t)(void*, |
| 5218 | struct str_parms*, struct str_parms*); |
| 5219 | static ext_hw_plugin_get_parameters_t ext_hw_plugin_get_parameters; |
| 5220 | |
| 5221 | typedef int(*ext_hw_plugin_set_mic_mute_t)(void*, bool); |
| 5222 | static ext_hw_plugin_set_mic_mute_t ext_hw_plugin_set_mic_mute; |
| 5223 | |
| 5224 | typedef int(*ext_hw_plugin_get_mic_mute_t)(void*, bool*); |
| 5225 | static ext_hw_plugin_get_mic_mute_t ext_hw_plugin_get_mic_mute; |
| 5226 | |
| 5227 | typedef int(*ext_hw_plugin_set_audio_gain_t)(void*, struct audio_usecase*, uint32_t); |
| 5228 | static ext_hw_plugin_set_audio_gain_t ext_hw_plugin_set_audio_gain; |
| 5229 | |
| 5230 | |
| 5231 | int ext_hw_plugin_feature_init(bool is_feature_enabled) |
| 5232 | { |
| 5233 | ALOGD("%s: Called with feature %s", __func__, |
| 5234 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
| 5235 | if (is_feature_enabled) { |
| 5236 | // dlopen lib |
| 5237 | ext_hw_plugin_lib_handle = dlopen(EXT_HW_PLUGIN_LIB_PATH, RTLD_NOW); |
| 5238 | |
| 5239 | if (!ext_hw_plugin_lib_handle) { |
| 5240 | ALOGE("%s: dlopen failed", __func__); |
| 5241 | goto feature_disabled; |
| 5242 | } |
| 5243 | if (!(ext_hw_plugin_init = (ext_hw_plugin_init_t)dlsym( |
| 5244 | ext_hw_plugin_lib_handle, "ext_hw_plugin_init")) || |
| 5245 | !(ext_hw_plugin_deinit = |
| 5246 | (ext_hw_plugin_deinit_t)dlsym( |
| 5247 | ext_hw_plugin_lib_handle, "ext_hw_plugin_deinit")) || |
| 5248 | !(ext_hw_plugin_usecase_start = |
| 5249 | (ext_hw_plugin_usecase_start_t)dlsym( |
| 5250 | ext_hw_plugin_lib_handle, "ext_hw_plugin_usecase_start")) || |
| 5251 | !(ext_hw_plugin_usecase_stop = |
| 5252 | (ext_hw_plugin_usecase_stop_t)dlsym( |
| 5253 | ext_hw_plugin_lib_handle, "ext_hw_plugin_usecase_stop")) || |
| 5254 | !(ext_hw_plugin_set_parameters = |
| 5255 | (ext_hw_plugin_set_parameters_t)dlsym( |
| 5256 | ext_hw_plugin_lib_handle, "ext_hw_plugin_set_parameters")) || |
| 5257 | !(ext_hw_plugin_get_parameters = |
| 5258 | (ext_hw_plugin_get_parameters_t)dlsym( |
| 5259 | ext_hw_plugin_lib_handle, "ext_hw_plugin_get_parameters")) || |
| 5260 | !(ext_hw_plugin_set_mic_mute = |
| 5261 | (ext_hw_plugin_set_mic_mute_t)dlsym( |
| 5262 | ext_hw_plugin_lib_handle, "ext_hw_plugin_set_mic_mute")) || |
| 5263 | !(ext_hw_plugin_get_mic_mute = |
| 5264 | (ext_hw_plugin_get_mic_mute_t)dlsym( |
| 5265 | ext_hw_plugin_lib_handle, "ext_hw_plugin_get_mic_mute")) || |
| 5266 | !(ext_hw_plugin_set_audio_gain = |
| 5267 | (ext_hw_plugin_set_audio_gain_t)dlsym( |
| 5268 | ext_hw_plugin_lib_handle, "ext_hw_plugin_set_audio_gain"))) { |
| 5269 | ALOGE("%s: dlsym failed", __func__); |
| 5270 | goto feature_disabled; |
| 5271 | } |
| 5272 | ALOGD("%s:: ---- Feature EXT_HW_PLUGIN is Enabled ----", __func__); |
| 5273 | return 0; |
| 5274 | } |
| 5275 | |
| 5276 | feature_disabled: |
| 5277 | if (ext_hw_plugin_lib_handle) { |
| 5278 | dlclose(ext_hw_plugin_lib_handle); |
| 5279 | ext_hw_plugin_lib_handle = NULL; |
| 5280 | } |
| 5281 | |
| 5282 | ext_hw_plugin_init = NULL; |
| 5283 | ext_hw_plugin_deinit = NULL; |
| 5284 | ext_hw_plugin_usecase_start = NULL; |
| 5285 | ext_hw_plugin_usecase_stop = NULL; |
| 5286 | ext_hw_plugin_set_parameters = NULL; |
| 5287 | ext_hw_plugin_get_parameters = NULL; |
| 5288 | ext_hw_plugin_set_mic_mute = NULL; |
| 5289 | ext_hw_plugin_get_mic_mute = NULL; |
| 5290 | ext_hw_plugin_set_audio_gain = NULL; |
| 5291 | |
| 5292 | ALOGW(":: %s: ---- Feature EXT_HW_PLUGIN is disabled ----", __func__); |
| 5293 | return -ENOSYS; |
| 5294 | } |
| 5295 | |
| 5296 | void* audio_extn_ext_hw_plugin_init(struct audio_device *adev) |
| 5297 | { |
| 5298 | if(ext_hw_plugin_init) { |
| 5299 | ext_hw_plugin_init_config_t ext_hw_plugin_init_config; |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 5300 | ext_hw_plugin_init_config.fp_b64decode = b64decode; |
| 5301 | ext_hw_plugin_init_config.fp_b64encode = b64encode; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5302 | return ext_hw_plugin_init(adev, ext_hw_plugin_init_config); |
| 5303 | } |
| 5304 | else |
| 5305 | return NULL; |
| 5306 | } |
| 5307 | |
| 5308 | int audio_extn_ext_hw_plugin_deinit(void *plugin) |
| 5309 | { |
| 5310 | return ((ext_hw_plugin_deinit) ? |
Aalique Grahame | 6dde1a4 | 2019-06-10 14:22:46 -0700 | [diff] [blame] | 5311 | ext_hw_plugin_deinit(plugin): 0); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | int audio_extn_ext_hw_plugin_usecase_start(void *plugin, struct audio_usecase *usecase) |
| 5315 | { |
| 5316 | return ((ext_hw_plugin_usecase_start) ? |
Aalique Grahame | 6dde1a4 | 2019-06-10 14:22:46 -0700 | [diff] [blame] | 5317 | ext_hw_plugin_usecase_start(plugin, usecase): 0); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | int audio_extn_ext_hw_plugin_usecase_stop(void *plugin, struct audio_usecase *usecase) |
| 5321 | { |
| 5322 | return ((ext_hw_plugin_usecase_stop) ? |
Aalique Grahame | 6dde1a4 | 2019-06-10 14:22:46 -0700 | [diff] [blame] | 5323 | ext_hw_plugin_usecase_stop(plugin, usecase): 0); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | int audio_extn_ext_hw_plugin_set_parameters(void *plugin, |
| 5327 | struct str_parms *parms) |
| 5328 | { |
| 5329 | return ((ext_hw_plugin_set_parameters) ? |
Aalique Grahame | 6dde1a4 | 2019-06-10 14:22:46 -0700 | [diff] [blame] | 5330 | ext_hw_plugin_set_parameters(plugin, parms): 0); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | int audio_extn_ext_hw_plugin_get_parameters(void *plugin, |
| 5334 | struct str_parms *query, struct str_parms *reply) |
| 5335 | { |
| 5336 | return ((ext_hw_plugin_get_parameters) ? |
Aalique Grahame | 6dde1a4 | 2019-06-10 14:22:46 -0700 | [diff] [blame] | 5337 | ext_hw_plugin_get_parameters(plugin, query, reply): 0); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | int audio_extn_ext_hw_plugin_set_mic_mute(void *plugin, bool mute) |
| 5341 | { |
| 5342 | return ((ext_hw_plugin_set_mic_mute) ? |
Aalique Grahame | 6dde1a4 | 2019-06-10 14:22:46 -0700 | [diff] [blame] | 5343 | ext_hw_plugin_set_mic_mute(plugin, mute): 0); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5344 | } |
| 5345 | |
| 5346 | int audio_extn_ext_hw_plugin_get_mic_mute(void *plugin, bool *mute) |
| 5347 | { |
| 5348 | return ((ext_hw_plugin_get_mic_mute) ? |
Aalique Grahame | 6dde1a4 | 2019-06-10 14:22:46 -0700 | [diff] [blame] | 5349 | ext_hw_plugin_get_mic_mute(plugin, mute): 0); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | int audio_extn_ext_hw_plugin_set_audio_gain(void *plugin, |
| 5353 | struct audio_usecase *usecase, uint32_t gain) |
| 5354 | { |
| 5355 | return ((ext_hw_plugin_set_audio_gain) ? |
Aalique Grahame | 6dde1a4 | 2019-06-10 14:22:46 -0700 | [diff] [blame] | 5356 | ext_hw_plugin_set_audio_gain(plugin, usecase, gain): 0); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5357 | } |
| 5358 | // END: EXT_HW_PLUGIN =================================================================== |
| 5359 | |
| 5360 | // START: RECORD_PLAY_CONCURRENCY ======================================================= |
| 5361 | void record_play_concurency_feature_init(bool is_feature_enabled) |
| 5362 | { |
| 5363 | audio_extn_record_play_concurrency_enabled = is_feature_enabled; |
| 5364 | ALOGD("%s: ---- Feature RECORD_PLAY_CONCURRENCY is %s----", __func__, |
| 5365 | is_feature_enabled? "ENABLED": "NOT ENABLED"); |
| 5366 | } |
| 5367 | |
| 5368 | bool audio_extn_is_record_play_concurrency_enabled() |
| 5369 | { |
| 5370 | return audio_extn_record_play_concurrency_enabled; |
| 5371 | } |
| 5372 | // END: RECORD_PLAY_CONCURRENCY ========================================================= |
| 5373 | |
| 5374 | // START: HDMI_PASSTHROUGH ================================================== |
| 5375 | #ifdef __LP64__ |
| 5376 | #define HDMI_PASSTHRU_LIB_PATH "/vendor/lib64/libhdmipassthru.so" |
| 5377 | #else |
| 5378 | #define HDMI_PASSTHRU_LIB_PATH "/vendor/lib/libhdmipassthru.so" |
| 5379 | #endif |
| 5380 | |
| 5381 | static void *hdmi_passthru_lib_handle = NULL; |
| 5382 | |
| 5383 | typedef bool (*passthru_is_convert_supported_t)(struct audio_device *, |
| 5384 | struct stream_out *); |
| 5385 | static passthru_is_convert_supported_t passthru_is_convert_supported; |
| 5386 | |
| 5387 | typedef bool (*passthru_is_passt_supported_t)(struct stream_out *); |
| 5388 | static passthru_is_passt_supported_t passthru_is_passt_supported; |
| 5389 | |
| 5390 | typedef void (*passthru_update_stream_configuration_t)( |
| 5391 | struct audio_device *, struct stream_out *, const void *, size_t); |
| 5392 | static passthru_update_stream_configuration_t passthru_update_stream_configuration; |
| 5393 | |
| 5394 | typedef bool (*passthru_is_passthrough_stream_t)(struct stream_out *); |
| 5395 | static passthru_is_passthrough_stream_t passthru_is_passthrough_stream; |
| 5396 | |
| 5397 | typedef int (*passthru_get_buffer_size_t)(audio_offload_info_t*); |
| 5398 | static passthru_get_buffer_size_t passthru_get_buffer_size; |
| 5399 | |
| 5400 | typedef int (*passthru_set_volume_t)(struct stream_out *, int); |
| 5401 | static passthru_set_volume_t passthru_set_volume; |
| 5402 | |
| 5403 | typedef int (*passthru_set_latency_t)(struct stream_out *, int); |
| 5404 | static passthru_set_latency_t passthru_set_latency; |
| 5405 | |
| 5406 | typedef bool (*passthru_is_supported_format_t)(audio_format_t); |
| 5407 | static passthru_is_supported_format_t passthru_is_supported_format; |
| 5408 | |
| 5409 | typedef bool (*passthru_should_drop_data_t)(struct stream_out * out); |
| 5410 | static passthru_should_drop_data_t passthru_should_drop_data; |
| 5411 | |
| 5412 | typedef void (*passthru_on_start_t)(struct stream_out *out); |
| 5413 | static passthru_on_start_t passthru_on_start; |
| 5414 | |
| 5415 | typedef void (*passthru_on_stop_t)(struct stream_out *out); |
| 5416 | static passthru_on_stop_t passthru_on_stop; |
| 5417 | |
| 5418 | typedef void (*passthru_on_pause_t)(struct stream_out *out); |
| 5419 | static passthru_on_pause_t passthru_on_pause; |
| 5420 | |
| 5421 | typedef int (*passthru_set_parameters_t)(struct audio_device *adev, |
| 5422 | struct str_parms *parms); |
| 5423 | static passthru_set_parameters_t passthru_set_parameters; |
| 5424 | |
| 5425 | typedef bool (*passthru_is_enabled_t)(); |
| 5426 | static passthru_is_enabled_t passthru_is_enabled; |
| 5427 | |
| 5428 | typedef bool (*passthru_is_active_t)(); |
| 5429 | static passthru_is_active_t passthru_is_active; |
| 5430 | |
| 5431 | typedef void (*passthru_init_t)(passthru_init_config_t); |
| 5432 | static passthru_init_t passthru_init; |
| 5433 | |
| 5434 | typedef bool (*passthru_should_standby_t)(struct stream_out *out); |
| 5435 | static passthru_should_standby_t passthru_should_standby; |
| 5436 | |
| 5437 | typedef int (*passthru_get_channel_count_t)(struct stream_out *out); |
| 5438 | static passthru_get_channel_count_t passthru_get_channel_count; |
| 5439 | |
| 5440 | typedef int (*passthru_update_dts_stream_configuration_t)(struct stream_out *out, |
| 5441 | const void *buffer, size_t bytes); |
| 5442 | static passthru_update_dts_stream_configuration_t passthru_update_dts_stream_configuration; |
| 5443 | |
| 5444 | typedef bool (*passthru_is_direct_passthrough_t)(struct stream_out *out); |
| 5445 | static passthru_is_direct_passthrough_t passthru_is_direct_passthrough; |
| 5446 | |
| 5447 | typedef bool (*passthru_is_supported_backend_edid_cfg_t)(struct audio_device *adev, |
| 5448 | struct stream_out *out); |
| 5449 | static passthru_is_supported_backend_edid_cfg_t passthru_is_supported_backend_edid_cfg; |
| 5450 | |
| 5451 | bool audio_extn_passthru_is_convert_supported(struct audio_device *adev, |
| 5452 | struct stream_out *out) |
| 5453 | { |
| 5454 | return (passthru_is_convert_supported ? passthru_is_convert_supported(adev, out) : false); |
| 5455 | } |
| 5456 | |
| 5457 | bool audio_extn_passthru_is_passthrough_stream(struct stream_out *out) |
| 5458 | { |
| 5459 | return (passthru_is_passthrough_stream ? |
| 5460 | passthru_is_passthrough_stream(out) : false); |
| 5461 | } |
| 5462 | |
| 5463 | void audio_extn_passthru_update_stream_configuration( |
| 5464 | struct audio_device *adev, struct stream_out *out, |
| 5465 | const void *buffer, size_t bytes) |
| 5466 | { |
| 5467 | (passthru_update_stream_configuration ? |
| 5468 | passthru_update_stream_configuration(adev, out, buffer, bytes) : 0); |
| 5469 | } |
| 5470 | |
| 5471 | bool audio_extn_passthru_is_passt_supported(struct stream_out *out) |
| 5472 | { |
| 5473 | return (passthru_is_passt_supported)? passthru_is_passt_supported(out): false; |
| 5474 | } |
| 5475 | |
| 5476 | int audio_extn_passthru_get_buffer_size(audio_offload_info_t* info) |
| 5477 | { |
| 5478 | return (passthru_get_buffer_size)? passthru_get_buffer_size(info): 0; |
| 5479 | } |
| 5480 | |
| 5481 | int audio_extn_passthru_set_volume(struct stream_out *out, int mute) |
| 5482 | { |
| 5483 | return (passthru_set_volume)? passthru_set_volume(out, mute): 0; |
| 5484 | } |
| 5485 | |
| 5486 | int audio_extn_passthru_set_latency(struct stream_out *out, int latency) |
| 5487 | { |
| 5488 | return (passthru_set_latency)? passthru_set_latency(out, latency): 0; |
| 5489 | } |
| 5490 | |
| 5491 | bool audio_extn_passthru_is_supported_format(audio_format_t format) |
| 5492 | { |
| 5493 | return (passthru_is_supported_format)? passthru_is_supported_format(format): false; |
| 5494 | } |
| 5495 | |
| 5496 | bool audio_extn_passthru_should_drop_data(struct stream_out * out) |
| 5497 | { |
| 5498 | return (passthru_should_drop_data)? passthru_should_drop_data(out): false; |
| 5499 | } |
| 5500 | |
| 5501 | void audio_extn_passthru_on_start(struct stream_out *out) |
| 5502 | { |
| 5503 | (passthru_on_start)? passthru_on_start(out): 0; |
| 5504 | } |
| 5505 | |
| 5506 | void audio_extn_passthru_on_stop(struct stream_out *out) |
| 5507 | { |
| 5508 | (passthru_on_stop)? passthru_on_stop(out): 0; |
| 5509 | } |
| 5510 | |
| 5511 | void audio_extn_passthru_on_pause(struct stream_out *out) |
| 5512 | { |
| 5513 | (passthru_on_pause)? passthru_on_pause(out): 0; |
| 5514 | } |
| 5515 | |
| 5516 | int audio_extn_passthru_set_parameters(struct audio_device *adev, |
| 5517 | struct str_parms *parms) |
| 5518 | { |
| 5519 | return (passthru_set_parameters)? |
| 5520 | passthru_set_parameters(adev, parms): false; |
| 5521 | } |
| 5522 | |
| 5523 | bool audio_extn_passthru_is_enabled() |
| 5524 | { |
| 5525 | return (passthru_is_enabled)? passthru_is_enabled(): false; |
| 5526 | } |
| 5527 | |
| 5528 | bool audio_extn_passthru_is_active() |
| 5529 | { |
| 5530 | return (passthru_is_active)? passthru_is_active(): false; |
| 5531 | } |
| 5532 | |
| 5533 | bool audio_extn_passthru_should_standby(struct stream_out *out) |
| 5534 | { |
| 5535 | return (passthru_should_standby)? passthru_should_standby(out): false; |
| 5536 | } |
| 5537 | int audio_extn_passthru_get_channel_count(struct stream_out *out) |
| 5538 | { |
| 5539 | return (passthru_get_channel_count)? passthru_get_channel_count(out): 0; |
| 5540 | } |
| 5541 | |
| 5542 | int audio_extn_passthru_update_dts_stream_configuration(struct stream_out *out, |
| 5543 | const void *buffer, size_t bytes) |
| 5544 | { |
| 5545 | return (passthru_update_dts_stream_configuration)? |
| 5546 | passthru_update_dts_stream_configuration(out, buffer, bytes): 0; |
| 5547 | } |
| 5548 | |
| 5549 | bool audio_extn_passthru_is_direct_passthrough(struct stream_out *out) |
| 5550 | { |
| 5551 | return (passthru_is_direct_passthrough)? passthru_is_direct_passthrough(out): false; |
| 5552 | } |
| 5553 | |
| 5554 | bool audio_extn_passthru_is_supported_backend_edid_cfg(struct audio_device *adev, |
| 5555 | struct stream_out *out) |
| 5556 | { |
| 5557 | return (passthru_is_supported_backend_edid_cfg)? |
| 5558 | passthru_is_supported_backend_edid_cfg(adev, out): false; |
| 5559 | } |
| 5560 | bool audio_extn_is_hdmi_passthru_enabled() |
| 5561 | { |
| 5562 | return audio_extn_hdmi_passthru_enabled; |
| 5563 | } |
| 5564 | |
| 5565 | void hdmi_passthrough_feature_init(bool is_feature_enabled) |
| 5566 | { |
| 5567 | ALOGD("%s: Called with feature %s", __func__, |
| 5568 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
| 5569 | |
| 5570 | audio_extn_hdmi_passthru_enabled = is_feature_enabled; |
| 5571 | if (is_feature_enabled) { |
| 5572 | // dlopen lib |
| 5573 | hdmi_passthru_lib_handle = dlopen(HDMI_PASSTHRU_LIB_PATH, RTLD_NOW); |
| 5574 | |
| 5575 | if (!hdmi_passthru_lib_handle) { |
| 5576 | ALOGE("%s: dlopen failed", __func__); |
| 5577 | goto feature_disabled; |
| 5578 | } |
| 5579 | if (!(passthru_init = (passthru_init_t)dlsym( |
| 5580 | hdmi_passthru_lib_handle, "passthru_init")) || |
| 5581 | !(passthru_is_convert_supported = |
| 5582 | (passthru_is_convert_supported_t)dlsym( |
| 5583 | hdmi_passthru_lib_handle, "passthru_is_convert_supported")) || |
| 5584 | !(passthru_is_passthrough_stream = |
| 5585 | (passthru_is_passthrough_stream_t)dlsym( |
| 5586 | hdmi_passthru_lib_handle, "passthru_is_passthrough_stream")) || |
| 5587 | !(passthru_get_buffer_size = |
| 5588 | (passthru_get_buffer_size_t)dlsym( |
| 5589 | hdmi_passthru_lib_handle, "passthru_get_buffer_size")) || |
| 5590 | !(passthru_set_volume = |
| 5591 | (passthru_set_volume_t)dlsym( |
| 5592 | hdmi_passthru_lib_handle, "passthru_set_volume")) || |
| 5593 | !(passthru_set_latency = |
| 5594 | (passthru_set_latency_t)dlsym( |
| 5595 | hdmi_passthru_lib_handle, "passthru_set_latency")) || |
| 5596 | !(passthru_is_supported_format = |
| 5597 | (passthru_is_supported_format_t)dlsym( |
| 5598 | hdmi_passthru_lib_handle, "passthru_is_supported_format")) || |
| 5599 | !(passthru_should_drop_data = |
| 5600 | (passthru_should_drop_data_t)dlsym( |
| 5601 | hdmi_passthru_lib_handle, "passthru_should_drop_data")) || |
| 5602 | !(passthru_on_start = |
| 5603 | (passthru_on_start_t)dlsym( |
| 5604 | hdmi_passthru_lib_handle, "passthru_on_start")) || |
| 5605 | !(passthru_on_stop = |
| 5606 | (passthru_on_stop_t)dlsym( |
| 5607 | hdmi_passthru_lib_handle, "passthru_on_stop")) || |
| 5608 | !(passthru_on_pause = |
| 5609 | (passthru_on_pause_t)dlsym( |
| 5610 | hdmi_passthru_lib_handle, "passthru_on_pause")) || |
| 5611 | !(passthru_set_parameters = |
| 5612 | (passthru_set_parameters_t)dlsym( |
| 5613 | hdmi_passthru_lib_handle, "passthru_set_parameters")) || |
| 5614 | (passthru_is_enabled = |
| 5615 | (passthru_is_enabled_t)dlsym( |
| 5616 | hdmi_passthru_lib_handle, "passthru_is_enabled")) || |
| 5617 | (passthru_is_active = |
| 5618 | (passthru_is_active_t)dlsym( |
| 5619 | hdmi_passthru_lib_handle, "passthru_is_active")) || |
| 5620 | (passthru_should_standby = |
| 5621 | (passthru_should_standby_t)dlsym( |
| 5622 | hdmi_passthru_lib_handle, "passthru_should_standby")) || |
| 5623 | (passthru_get_channel_count = |
| 5624 | (passthru_get_channel_count_t)dlsym( |
| 5625 | hdmi_passthru_lib_handle, "passthru_get_channel_count")) || |
| 5626 | (passthru_update_dts_stream_configuration = |
| 5627 | (passthru_update_dts_stream_configuration_t)dlsym( |
| 5628 | hdmi_passthru_lib_handle, |
| 5629 | "passthru_update_dts_stream_configuration")) || |
| 5630 | (passthru_is_direct_passthrough = |
| 5631 | (passthru_is_direct_passthrough_t)dlsym( |
| 5632 | hdmi_passthru_lib_handle, "passthru_is_direct_passthrough")) || |
| 5633 | (passthru_is_supported_backend_edid_cfg = |
| 5634 | (passthru_is_supported_backend_edid_cfg_t)dlsym( |
| 5635 | hdmi_passthru_lib_handle, |
| 5636 | "passthru_is_supported_backend_edid_cfg"))) { |
| 5637 | ALOGE("%s: dlsym failed", __func__); |
| 5638 | goto feature_disabled; |
| 5639 | } |
| 5640 | |
| 5641 | passthru_init_config_t init_config; |
| 5642 | init_config.fp_platform_is_edid_supported_format = |
| 5643 | platform_is_edid_supported_format; |
| 5644 | init_config.fp_platform_set_device_params = platform_set_device_params; |
| 5645 | init_config.fp_platform_edid_get_max_channels = platform_edid_get_max_channels; |
| 5646 | init_config.fp_platform_get_output_snd_device = platform_get_output_snd_device; |
| 5647 | init_config.fp_platform_get_codec_backend_cfg = platform_get_codec_backend_cfg; |
| 5648 | init_config.fp_platform_get_snd_device_name = platform_get_snd_device_name; |
| 5649 | init_config.fp_platform_is_edid_supported_sample_rate = |
| 5650 | platform_is_edid_supported_sample_rate; |
| 5651 | init_config.fp_audio_extn_keep_alive_start = audio_extn_keep_alive_start; |
| 5652 | init_config.fp_audio_extn_keep_alive_stop = audio_extn_keep_alive_stop; |
| 5653 | init_config.fp_audio_extn_utils_is_dolby_format = |
| 5654 | audio_extn_utils_is_dolby_format; |
| 5655 | passthru_init(init_config); |
| 5656 | ALOGD("%s:: ---- Feature HDMI_PASSTHROUGH is Enabled ----", __func__); |
Dallas Delaney | b2d060c | 2019-06-11 16:30:35 -0700 | [diff] [blame] | 5657 | return; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | feature_disabled: |
| 5661 | if (hdmi_passthru_lib_handle) { |
| 5662 | dlclose(hdmi_passthru_lib_handle); |
| 5663 | hdmi_passthru_lib_handle = NULL; |
| 5664 | } |
| 5665 | |
| 5666 | passthru_init = NULL; |
| 5667 | passthru_is_convert_supported = NULL; |
| 5668 | passthru_is_passthrough_stream = NULL; |
| 5669 | passthru_get_buffer_size = NULL; |
| 5670 | passthru_set_volume = NULL; |
| 5671 | passthru_set_latency = NULL; |
| 5672 | passthru_is_supported_format = NULL; |
| 5673 | passthru_should_drop_data = NULL; |
| 5674 | passthru_on_start = NULL; |
| 5675 | passthru_on_stop = NULL; |
| 5676 | passthru_on_pause = NULL; |
| 5677 | passthru_set_parameters = NULL; |
| 5678 | passthru_is_enabled = NULL; |
| 5679 | passthru_is_active = NULL; |
| 5680 | passthru_should_standby = NULL; |
| 5681 | passthru_get_channel_count = NULL; |
| 5682 | passthru_update_dts_stream_configuration = NULL; |
| 5683 | passthru_is_direct_passthrough = NULL; |
| 5684 | passthru_is_supported_backend_edid_cfg = NULL; |
| 5685 | |
| 5686 | ALOGW(":: %s: ---- Feature HDMI_PASSTHROUGH is disabled ----", __func__); |
| 5687 | } |
| 5688 | // END: HDMI_PASSTHROUGH ================================================== |
| 5689 | |
| 5690 | // START: CONCURRENT_CAPTURE ================================================== |
| 5691 | bool audio_extn_is_concurrent_capture_enabled() |
| 5692 | { |
| 5693 | return audio_extn_concurrent_capture_enabled; |
| 5694 | } |
| 5695 | |
| 5696 | void concurrent_capture_feature_init(bool is_feature_enabled) |
| 5697 | { |
| 5698 | audio_extn_concurrent_capture_enabled = is_feature_enabled; |
| 5699 | ALOGD("%s: ---- Feature CONCURRENT_CAPTURE is %s----", __func__, is_feature_enabled? "ENABLED": "NOT ENABLED"); |
| 5700 | } |
| 5701 | // END: CONCURRENT_CAPTURE ==================================================== |
| 5702 | |
Krishna Kishor Jha | 0f4d848 | 2022-02-18 10:56:05 +0530 | [diff] [blame] | 5703 | // START: CONCURRENT_PCM_RECORD =============================================== |
| 5704 | bool audio_extn_is_concurrent_pcm_record_enabled() |
| 5705 | { |
| 5706 | return audio_extn_concurrent_pcm_record_enabled; |
| 5707 | } |
| 5708 | |
| 5709 | void concurrent_pcm_record_feature_init(bool is_feature_enabled) |
| 5710 | { |
| 5711 | audio_extn_concurrent_pcm_record_enabled = is_feature_enabled; |
| 5712 | ALOGD("%s: ---- Feature CONCURRENT_PCM_RECORD is %s----", __func__, is_feature_enabled? "ENABLED": "NOT ENABLED"); |
| 5713 | } |
| 5714 | // END: CONCURRENT_PCM_RECORD ================================================= |
| 5715 | |
Kogara Naveen Kumar | c575823 | 2022-11-07 20:25:40 +0530 | [diff] [blame] | 5716 | // START: CONCURRENT_LOW_LATENCY_PCM_RECORD =============================================== |
| 5717 | bool audio_extn_is_concurrent_low_latency_pcm_record_enabled() |
| 5718 | { |
| 5719 | return audio_extn_concurrent_low_latency_pcm_record_enabled; |
| 5720 | } |
| 5721 | |
| 5722 | void concurrent_low_latency_pcm_record_feature_init(bool is_feature_enabled) |
| 5723 | { |
| 5724 | audio_extn_concurrent_low_latency_pcm_record_enabled = is_feature_enabled; |
| 5725 | ALOGD("%s: ---- Feature CONCURRENT_LOW_LATENCY_PCM_RECORD is %s----", __func__, is_feature_enabled? "ENABLED": "NOT ENABLED"); |
| 5726 | } |
| 5727 | // END: CONCURRENT_LOW_LATENCY_PCM_RECORD ================================================= |
| 5728 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5729 | // START: COMPRESS_IN ================================================== |
| 5730 | void compress_in_feature_init(bool is_feature_enabled) |
| 5731 | { |
| 5732 | audio_extn_compress_in_enabled = is_feature_enabled; |
| 5733 | ALOGD("%s: ---- Feature COMPRESS_IN is %s----", __func__, is_feature_enabled? "ENABLED": "NOT ENABLED"); |
| 5734 | } |
| 5735 | |
| 5736 | bool audio_extn_cin_applicable_stream(struct stream_in *in) |
| 5737 | { |
| 5738 | return (audio_extn_compress_in_enabled? cin_applicable_stream(in): false); |
| 5739 | } |
Dhananjay Kumar | 7dbe356 | 2019-08-30 05:49:33 +0530 | [diff] [blame] | 5740 | bool audio_extn_cin_attached_usecase(struct stream_in *in) |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5741 | { |
Dhananjay Kumar | 7dbe356 | 2019-08-30 05:49:33 +0530 | [diff] [blame] | 5742 | return (audio_extn_compress_in_enabled? cin_attached_usecase(in): false); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5743 | } |
| 5744 | bool audio_extn_cin_format_supported(audio_format_t format) |
| 5745 | { |
| 5746 | return (audio_extn_compress_in_enabled? cin_format_supported(format): false); |
| 5747 | } |
Dhananjay Kumar | 7dbe356 | 2019-08-30 05:49:33 +0530 | [diff] [blame] | 5748 | int audio_extn_cin_acquire_usecase(struct stream_in *in) |
| 5749 | { |
| 5750 | return (audio_extn_compress_in_enabled? cin_acquire_usecase(in): 0); |
| 5751 | } |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5752 | size_t audio_extn_cin_get_buffer_size(struct stream_in *in) |
| 5753 | { |
| 5754 | return (audio_extn_compress_in_enabled? cin_get_buffer_size(in): 0); |
| 5755 | } |
Manish Dewangan | 46e0798 | 2018-12-13 18:18:59 +0530 | [diff] [blame] | 5756 | int audio_extn_cin_open_input_stream(struct stream_in *in) |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5757 | { |
Manish Dewangan | 46e0798 | 2018-12-13 18:18:59 +0530 | [diff] [blame] | 5758 | return (audio_extn_compress_in_enabled? cin_open_input_stream(in): -1); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5759 | } |
| 5760 | void audio_extn_cin_stop_input_stream(struct stream_in *in) |
| 5761 | { |
| 5762 | (audio_extn_compress_in_enabled? cin_stop_input_stream(in): NULL); |
| 5763 | } |
| 5764 | void audio_extn_cin_close_input_stream(struct stream_in *in) |
| 5765 | { |
| 5766 | (audio_extn_compress_in_enabled? cin_close_input_stream(in): NULL); |
| 5767 | } |
Manish Dewangan | 46e0798 | 2018-12-13 18:18:59 +0530 | [diff] [blame] | 5768 | void audio_extn_cin_free_input_stream_resources(struct stream_in *in) |
| 5769 | { |
| 5770 | return (audio_extn_compress_in_enabled? cin_free_input_stream_resources(in): NULL); |
| 5771 | } |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5772 | int audio_extn_cin_read(struct stream_in *in, void *buffer, |
| 5773 | size_t bytes, size_t *bytes_read) |
| 5774 | { |
| 5775 | return (audio_extn_compress_in_enabled? |
| 5776 | cin_read(in, buffer, bytes, bytes_read): -1); |
| 5777 | } |
Deeraj Soman | 1423092 | 2019-01-30 16:39:30 +0530 | [diff] [blame] | 5778 | int audio_extn_cin_configure_input_stream(struct stream_in *in, struct audio_config *in_config) |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5779 | { |
Deeraj Soman | 1423092 | 2019-01-30 16:39:30 +0530 | [diff] [blame] | 5780 | return (audio_extn_compress_in_enabled? cin_configure_input_stream(in, in_config): -1); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5781 | } |
| 5782 | // END: COMPRESS_IN ==================================================== |
| 5783 | |
| 5784 | // START: BATTERY_LISTENER ================================================== |
| 5785 | #ifdef __LP64__ |
| 5786 | #define BATTERY_LISTENER_LIB_PATH "/vendor/lib64/libbatterylistener.so" |
| 5787 | #else |
| 5788 | #define BATTERY_LISTENER_LIB_PATH "/vendor/lib/libbatterylistener.so" |
| 5789 | #endif |
| 5790 | |
| 5791 | static void *batt_listener_lib_handle = NULL; |
| 5792 | |
| 5793 | typedef void (*batt_listener_init_t)(battery_status_change_fn_t); |
| 5794 | static batt_listener_init_t batt_listener_init; |
| 5795 | |
Sujin Panicker | 90f923d | 2021-07-14 15:04:43 +0530 | [diff] [blame] | 5796 | typedef void (*batt_listener_deinit_t)(void); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5797 | static batt_listener_deinit_t batt_listener_deinit; |
| 5798 | |
Sujin Panicker | 90f923d | 2021-07-14 15:04:43 +0530 | [diff] [blame] | 5799 | typedef bool (*batt_prop_is_charging_t)(void); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5800 | static batt_prop_is_charging_t batt_prop_is_charging; |
| 5801 | |
| 5802 | void battery_listener_feature_init(bool is_feature_enabled) |
| 5803 | { |
| 5804 | audio_extn_battery_listener_enabled = is_feature_enabled; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5805 | if (is_feature_enabled) { |
| 5806 | // dlopen lib |
| 5807 | batt_listener_lib_handle = dlopen(BATTERY_LISTENER_LIB_PATH, RTLD_NOW); |
| 5808 | |
| 5809 | if (!batt_listener_lib_handle) { |
| 5810 | ALOGE("%s: dlopen failed", __func__); |
| 5811 | goto feature_disabled; |
| 5812 | } |
| 5813 | if (!(batt_listener_init = (batt_listener_init_t)dlsym( |
| 5814 | batt_listener_lib_handle, "battery_properties_listener_init")) || |
| 5815 | !(batt_listener_deinit = |
| 5816 | (batt_listener_deinit_t)dlsym( |
| 5817 | batt_listener_lib_handle, "battery_properties_listener_deinit")) || |
| 5818 | !(batt_prop_is_charging = |
| 5819 | (batt_prop_is_charging_t)dlsym( |
| 5820 | batt_listener_lib_handle, "battery_properties_is_charging"))) { |
| 5821 | ALOGE("%s: dlsym failed", __func__); |
| 5822 | goto feature_disabled; |
| 5823 | } |
Dallas Delaney | b2d060c | 2019-06-11 16:30:35 -0700 | [diff] [blame] | 5824 | ALOGD("%s: ---- Feature BATTERY_LISTENER is enabled ----", __func__); |
| 5825 | return; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | feature_disabled: |
| 5829 | if (batt_listener_lib_handle) { |
| 5830 | dlclose(batt_listener_lib_handle); |
| 5831 | batt_listener_lib_handle = NULL; |
| 5832 | } |
| 5833 | |
| 5834 | batt_listener_init = NULL; |
| 5835 | batt_listener_deinit = NULL; |
| 5836 | batt_prop_is_charging = NULL; |
| 5837 | ALOGW(":: %s: ---- Feature BATTERY_LISTENER is disabled ----", __func__); |
| 5838 | } |
| 5839 | |
| 5840 | void audio_extn_battery_properties_listener_init(battery_status_change_fn_t fn) |
| 5841 | { |
| 5842 | if(batt_listener_init) |
| 5843 | batt_listener_init(fn); |
| 5844 | } |
| 5845 | void audio_extn_battery_properties_listener_deinit() |
| 5846 | { |
| 5847 | if(batt_listener_deinit) |
| 5848 | batt_listener_deinit(); |
| 5849 | } |
| 5850 | bool audio_extn_battery_properties_is_charging() |
| 5851 | { |
| 5852 | return (batt_prop_is_charging)? batt_prop_is_charging(): false; |
| 5853 | } |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 5854 | // END: BATTERY_LISTENER ================================================================ |
| 5855 | |
Ramlal Karra | ab51d04 | 2019-08-08 19:02:35 +0530 | [diff] [blame] | 5856 | // START: HiFi Filter Feature ============================================================ |
| 5857 | void audio_extn_enable_hifi_filter(struct audio_device *adev, bool value) |
| 5858 | { |
| 5859 | const char *mixer_ctl_name = "HiFi Filter"; |
| 5860 | struct mixer_ctl *ctl = NULL; |
| 5861 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 5862 | if (!ctl) { |
| 5863 | ALOGE("%s: Could not get ctl for mixer cmd - %s, using default control", |
| 5864 | __func__, mixer_ctl_name); |
| 5865 | return; |
| 5866 | } else { |
| 5867 | mixer_ctl_set_value(ctl, 0, value); |
Aniket Kumar Lata | d13758f | 2020-08-06 15:11:36 -0700 | [diff] [blame] | 5868 | ALOGV("%s: mixer_value set %d", __func__, value); |
Ramlal Karra | ab51d04 | 2019-08-08 19:02:35 +0530 | [diff] [blame] | 5869 | } |
| 5870 | return; |
| 5871 | } |
| 5872 | |
| 5873 | void audio_extn_hifi_filter_set_params(struct str_parms *parms, |
| 5874 | char *value, int len) |
| 5875 | { |
| 5876 | int ret = 0; |
| 5877 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HIFI_AUDIO_FILTER, value,len); |
| 5878 | if (ret >= 0) { |
| 5879 | if (value && !strncmp(value, "true", sizeof("true"))) |
| 5880 | audio_extn_hifi_filter_enabled = true; |
| 5881 | else |
| 5882 | audio_extn_hifi_filter_enabled = false; |
| 5883 | str_parms_del(parms, AUDIO_PARAMETER_KEY_HIFI_AUDIO_FILTER); |
| 5884 | } |
| 5885 | } |
| 5886 | |
| 5887 | bool audio_extn_hifi_check_usecase_params(int sample_rate, int usecase) |
| 5888 | { |
| 5889 | if (sample_rate != 48000 && sample_rate != 44100) |
| 5890 | return false; |
| 5891 | if (usecase == USECASE_AUDIO_PLAYBACK_LOW_LATENCY || usecase == USECASE_AUDIO_PLAYBACK_ULL) |
| 5892 | return false; |
| 5893 | return true; |
| 5894 | } |
| 5895 | |
| 5896 | bool audio_extn_is_hifi_filter_enabled(struct audio_device* adev, struct stream_out *out, |
| 5897 | snd_device_t snd_device, char *codec_variant, |
| 5898 | int channels, int usecase_init) |
| 5899 | { |
| 5900 | int na_mode = platform_get_native_support(); |
| 5901 | struct audio_usecase *uc = NULL; |
| 5902 | struct listnode *node = NULL; |
| 5903 | bool hifi_active = false; |
| 5904 | |
| 5905 | if (audio_extn_hifi_filter_enabled) { |
| 5906 | /*Restricting the feature for Tavil and WCD9375 codecs only*/ |
| 5907 | if ((strstr(codec_variant, "WCD9385") || strstr(codec_variant, "WCD9375")) |
Prasad Kumpatla | 0e90ba8 | 2020-02-04 15:12:26 +0530 | [diff] [blame] | 5908 | && (na_mode == NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP || na_mode == |
| 5909 | NATIVE_AUDIO_MODE_TRUE_44_1) && channels <=2) { |
Ramlal Karra | ab51d04 | 2019-08-08 19:02:35 +0530 | [diff] [blame] | 5910 | /*Upsampling 8 time should be restricited to headphones playback only */ |
| 5911 | if (snd_device == SND_DEVICE_OUT_HEADPHONES |
| 5912 | || snd_device == SND_DEVICE_OUT_HEADPHONES_44_1 |
| 5913 | || snd_device == SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER |
| 5914 | || usecase_init) { |
| 5915 | if (audio_extn_hifi_check_usecase_params(out->sample_rate, |
| 5916 | out->usecase) && !usecase_init) |
| 5917 | return true; |
| 5918 | |
| 5919 | list_for_each(node, &adev->usecase_list) { |
| 5920 | /* checking if hifi_filter is already active to set */ |
| 5921 | /* concurrent playback sessions with hifi_filter enabled*/ |
| 5922 | uc = node_to_item(node, struct audio_usecase, list); |
| 5923 | struct stream_out *curr_out = (struct stream_out*) uc->stream.out; |
| 5924 | if (uc->type == PCM_PLAYBACK && curr_out |
| 5925 | && audio_extn_hifi_check_usecase_params( |
| 5926 | curr_out->sample_rate, curr_out->usecase) && |
| 5927 | (curr_out->channel_mask == AUDIO_CHANNEL_OUT_STEREO || |
| 5928 | curr_out->channel_mask == AUDIO_CHANNEL_OUT_MONO)) |
| 5929 | hifi_active = true; |
| 5930 | } |
| 5931 | } |
| 5932 | } |
| 5933 | } |
| 5934 | return hifi_active; |
| 5935 | } |
| 5936 | // END: HiFi Filter Feature ============================================================== |
| 5937 | |
vivek mehta | ba5ed15 | 2019-05-03 17:28:25 -0700 | [diff] [blame] | 5938 | // START: AUDIOZOOM_FEATURE ===================================================================== |
| 5939 | #ifdef __LP64__ |
| 5940 | #define AUDIOZOOM_LIB_PATH "/vendor/lib64/libaudiozoom.so" |
| 5941 | #else |
| 5942 | #define AUDIOZOOM_LIB_PATH "/vendor/lib/libaudiozoom.so" |
| 5943 | #endif |
| 5944 | |
| 5945 | static void *audiozoom_lib_handle = NULL; |
| 5946 | |
| 5947 | typedef int (*audiozoom_init_t)(audiozoom_init_config_t); |
| 5948 | static audiozoom_init_t audiozoom_init; |
| 5949 | |
| 5950 | typedef int (*audiozoom_set_microphone_direction_t)(struct stream_in *, |
| 5951 | audio_microphone_direction_t); |
| 5952 | static audiozoom_set_microphone_direction_t audiozoom_set_microphone_direction; |
| 5953 | |
| 5954 | typedef int (*audiozoom_set_microphone_field_dimension_t)(struct stream_in *, float); |
| 5955 | static audiozoom_set_microphone_field_dimension_t audiozoom_set_microphone_field_dimension; |
| 5956 | |
| 5957 | int audiozoom_feature_init(bool is_feature_enabled) |
| 5958 | { |
| 5959 | audio_extn_audiozoom_enabled = is_feature_enabled; |
| 5960 | ALOGD("%s: Called with feature %s", __func__, |
| 5961 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
| 5962 | if (is_feature_enabled) { |
| 5963 | // dlopen lib |
| 5964 | audiozoom_lib_handle = dlopen(AUDIOZOOM_LIB_PATH, RTLD_NOW); |
| 5965 | |
| 5966 | if (!audiozoom_lib_handle) { |
| 5967 | ALOGE("%s: dlopen failed", __func__); |
| 5968 | goto feature_disabled; |
| 5969 | } |
| 5970 | |
| 5971 | if (!(audiozoom_init = |
| 5972 | (audiozoom_init_t)dlsym(audiozoom_lib_handle, "audiozoom_init")) || |
| 5973 | !(audiozoom_set_microphone_direction = |
| 5974 | (audiozoom_set_microphone_direction_t)dlsym(audiozoom_lib_handle, |
| 5975 | "audiozoom_set_microphone_direction")) || |
| 5976 | !(audiozoom_set_microphone_field_dimension = |
| 5977 | (audiozoom_set_microphone_field_dimension_t)dlsym(audiozoom_lib_handle, |
| 5978 | "audiozoom_set_microphone_field_dimension"))) { |
| 5979 | ALOGE("%s: dlsym failed", __func__); |
| 5980 | goto feature_disabled; |
| 5981 | } |
| 5982 | |
| 5983 | ALOGD("%s:: ---- Feature AUDIOZOOM is Enabled ----", __func__); |
| 5984 | return 0; |
| 5985 | } |
| 5986 | feature_disabled: |
| 5987 | if (audiozoom_lib_handle) { |
| 5988 | dlclose(audiozoom_lib_handle); |
| 5989 | audiozoom_lib_handle = NULL; |
| 5990 | } |
| 5991 | |
| 5992 | audiozoom_init = NULL; |
| 5993 | audiozoom_set_microphone_direction = NULL; |
| 5994 | audiozoom_set_microphone_field_dimension = NULL; |
| 5995 | ALOGW(":: %s: ---- Feature AUDIOZOOM is disabled ----", __func__); |
| 5996 | return -ENOSYS; |
| 5997 | } |
| 5998 | |
| 5999 | bool audio_extn_is_audiozoom_enabled() |
| 6000 | { |
| 6001 | return audio_extn_audiozoom_enabled; |
| 6002 | } |
| 6003 | |
| 6004 | int audio_extn_audiozoom_init() |
| 6005 | { |
| 6006 | int ret_val = 0; |
| 6007 | if (audiozoom_init) { |
| 6008 | audiozoom_init_config_t init_config; |
| 6009 | init_config.fp_platform_set_parameters = platform_set_parameters; |
| 6010 | ret_val = audiozoom_init(init_config); |
| 6011 | } |
| 6012 | |
| 6013 | return ret_val; |
| 6014 | } |
| 6015 | |
| 6016 | int audio_extn_audiozoom_set_microphone_direction(struct stream_in *stream, |
| 6017 | audio_microphone_direction_t dir) |
| 6018 | { |
| 6019 | int ret_val = -ENOSYS; |
| 6020 | if (audiozoom_set_microphone_direction) |
| 6021 | ret_val = audiozoom_set_microphone_direction(stream, dir); |
| 6022 | |
| 6023 | return ret_val; |
| 6024 | } |
| 6025 | |
| 6026 | int audio_extn_audiozoom_set_microphone_field_dimension(struct stream_in *stream, |
| 6027 | float zoom) |
| 6028 | { |
| 6029 | int ret_val = -ENOSYS; |
| 6030 | if (audiozoom_set_microphone_field_dimension) |
| 6031 | ret_val = audiozoom_set_microphone_field_dimension(stream, zoom); |
| 6032 | |
| 6033 | return ret_val; |
| 6034 | } |
| 6035 | // END: AUDIOZOOM_FEATURE ===================================================================== |
| 6036 | |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 6037 | // START: MAXX_AUDIO ===================================================================== |
| 6038 | #ifdef __LP64__ |
| 6039 | #define MAXX_AUDIO_LIB_PATH "/vendor/lib64/libmaxxaudio.so" |
| 6040 | #else |
| 6041 | #define MAXX_AUDIO_LIB_PATH "/vendor/lib/libmaxxaudio.so" |
| 6042 | #endif |
| 6043 | |
| 6044 | static void *maxxaudio_lib_handle = NULL; |
| 6045 | |
| 6046 | typedef void (*maxxaudio_init_t)(void *, maxx_audio_init_config_t); |
| 6047 | static maxxaudio_init_t maxxaudio_init; |
| 6048 | |
| 6049 | typedef void (*maxxaudio_deinit_t)(); |
| 6050 | static maxxaudio_deinit_t maxxaudio_deinit; |
| 6051 | |
| 6052 | typedef bool (*maxxaudio_set_state_t)(struct audio_device*, int, |
| 6053 | float, bool); |
| 6054 | static maxxaudio_set_state_t maxxaudio_set_state; |
| 6055 | |
| 6056 | typedef void (*maxxaudio_set_device_t)(struct audio_usecase *); |
| 6057 | static maxxaudio_set_device_t maxxaudio_set_device; |
| 6058 | |
| 6059 | typedef void (*maxxaudio_set_parameters_t)(struct audio_device *, |
| 6060 | struct str_parms *); |
| 6061 | static maxxaudio_set_parameters_t maxxaudio_set_parameters; |
| 6062 | |
justinweng | d539515 | 2019-11-04 12:23:09 +0800 | [diff] [blame] | 6063 | typedef void (*maxxaudio_get_parameters_t)(struct audio_device *, |
| 6064 | struct str_parms *, |
| 6065 | struct str_parms *); |
| 6066 | static maxxaudio_get_parameters_t maxxaudio_get_parameters; |
| 6067 | |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 6068 | typedef bool (*maxxaudio_supported_usb_t)(); |
| 6069 | static maxxaudio_supported_usb_t maxxaudio_supported_usb; |
| 6070 | |
| 6071 | int maxx_audio_feature_init(bool is_feature_enabled) |
| 6072 | { |
| 6073 | audio_extn_maxx_audio_enabled = is_feature_enabled; |
| 6074 | ALOGD("%s: Called with feature %s", __func__, |
| 6075 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
| 6076 | if (is_feature_enabled) { |
| 6077 | // dlopen lib |
| 6078 | maxxaudio_lib_handle = dlopen(MAXX_AUDIO_LIB_PATH, RTLD_NOW); |
| 6079 | |
| 6080 | if (!maxxaudio_lib_handle) { |
| 6081 | ALOGE("%s: dlopen failed", __func__); |
| 6082 | goto feature_disabled; |
| 6083 | } |
| 6084 | |
| 6085 | if (!(maxxaudio_init = |
| 6086 | (maxxaudio_init_t)dlsym(maxxaudio_lib_handle, "ma_init")) || |
| 6087 | !(maxxaudio_deinit = |
| 6088 | (maxxaudio_deinit_t)dlsym(maxxaudio_lib_handle, "ma_deinit")) || |
| 6089 | !(maxxaudio_set_state = |
| 6090 | (maxxaudio_set_state_t)dlsym(maxxaudio_lib_handle, "ma_set_state")) || |
| 6091 | !(maxxaudio_set_device = |
| 6092 | (maxxaudio_set_device_t)dlsym(maxxaudio_lib_handle, "ma_set_device")) || |
| 6093 | !(maxxaudio_set_parameters = |
| 6094 | (maxxaudio_set_parameters_t)dlsym(maxxaudio_lib_handle, "ma_set_parameters")) || |
justinweng | d539515 | 2019-11-04 12:23:09 +0800 | [diff] [blame] | 6095 | !(maxxaudio_get_parameters = |
| 6096 | (maxxaudio_get_parameters_t)dlsym(maxxaudio_lib_handle, "ma_get_parameters")) || |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 6097 | !(maxxaudio_supported_usb = |
| 6098 | (maxxaudio_supported_usb_t)dlsym( |
| 6099 | maxxaudio_lib_handle, "ma_supported_usb"))) { |
| 6100 | ALOGE("%s: dlsym failed", __func__); |
| 6101 | goto feature_disabled; |
| 6102 | } |
| 6103 | ALOGD("%s:: ---- Feature MAXX_AUDIO is Enabled ----", __func__); |
| 6104 | return 0; |
| 6105 | } |
| 6106 | |
| 6107 | feature_disabled: |
| 6108 | if (maxxaudio_lib_handle) { |
| 6109 | dlclose(maxxaudio_lib_handle); |
| 6110 | maxxaudio_lib_handle = NULL; |
| 6111 | } |
| 6112 | |
| 6113 | maxxaudio_init = NULL; |
| 6114 | maxxaudio_deinit = NULL; |
| 6115 | maxxaudio_set_state = NULL; |
| 6116 | maxxaudio_set_device = NULL; |
| 6117 | maxxaudio_set_parameters = NULL; |
justinweng | d539515 | 2019-11-04 12:23:09 +0800 | [diff] [blame] | 6118 | maxxaudio_get_parameters = NULL; |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 6119 | maxxaudio_supported_usb = NULL; |
| 6120 | ALOGW(":: %s: ---- Feature MAXX_AUDIO is disabled ----", __func__); |
| 6121 | return -ENOSYS; |
| 6122 | } |
| 6123 | |
| 6124 | bool audio_extn_is_maxx_audio_enabled() |
| 6125 | { |
| 6126 | return audio_extn_maxx_audio_enabled; |
| 6127 | } |
| 6128 | |
| 6129 | void audio_extn_ma_init(void *platform) |
| 6130 | { |
| 6131 | |
| 6132 | if (maxxaudio_init) { |
| 6133 | maxx_audio_init_config_t init_config; |
| 6134 | init_config.fp_platform_set_parameters = platform_set_parameters; |
| 6135 | init_config.fp_audio_extn_get_snd_card_split = audio_extn_get_snd_card_split; |
| 6136 | maxxaudio_init(platform, init_config); |
| 6137 | } |
| 6138 | } |
| 6139 | |
| 6140 | void audio_extn_ma_deinit() |
| 6141 | { |
| 6142 | if (maxxaudio_deinit) |
| 6143 | maxxaudio_deinit(); |
| 6144 | } |
| 6145 | |
| 6146 | bool audio_extn_ma_set_state(struct audio_device *adev, int stream_type, |
| 6147 | float vol, bool active) |
| 6148 | { |
| 6149 | return (maxxaudio_set_state ? |
| 6150 | maxxaudio_set_state(adev, stream_type, vol, active): false); |
| 6151 | } |
| 6152 | |
| 6153 | void audio_extn_ma_set_device(struct audio_usecase *usecase) |
| 6154 | { |
| 6155 | if (maxxaudio_set_device) |
| 6156 | maxxaudio_set_device(usecase); |
| 6157 | } |
| 6158 | |
| 6159 | void audio_extn_ma_set_parameters(struct audio_device *adev, |
| 6160 | struct str_parms *parms) |
| 6161 | { |
| 6162 | if (maxxaudio_set_parameters) |
| 6163 | maxxaudio_set_parameters(adev, parms); |
| 6164 | } |
| 6165 | |
justinweng | d539515 | 2019-11-04 12:23:09 +0800 | [diff] [blame] | 6166 | void audio_extn_ma_get_parameters(struct audio_device *adev, |
| 6167 | struct str_parms *query, |
| 6168 | struct str_parms *reply) |
| 6169 | { |
| 6170 | if (maxxaudio_get_parameters) |
| 6171 | maxxaudio_get_parameters(adev, query, reply); |
| 6172 | } |
| 6173 | |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 6174 | bool audio_extn_ma_supported_usb() |
| 6175 | { |
| 6176 | return (maxxaudio_supported_usb ? maxxaudio_supported_usb(): false); |
| 6177 | } |
| 6178 | // END: MAXX_AUDIO ===================================================================== |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 6179 | |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6180 | // START: AUTO_HAL =================================================================== |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 6181 | #ifdef LINUX_ENABLED |
| 6182 | #ifdef __LP64__ |
| 6183 | #define AUTO_HAL_LIB_PATH "/usr/lib64/libautohal.so" |
| 6184 | #else |
| 6185 | #define AUTO_HAL_LIB_PATH "/usr/lib/libautohal.so" |
| 6186 | #endif |
| 6187 | #else |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6188 | #ifdef __LP64__ |
| 6189 | #define AUTO_HAL_LIB_PATH "/vendor/lib64/libautohal.so" |
| 6190 | #else |
| 6191 | #define AUTO_HAL_LIB_PATH "/vendor/lib/libautohal.so" |
| 6192 | #endif |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 6193 | #endif |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6194 | |
| 6195 | static void *auto_hal_lib_handle = NULL; |
| 6196 | |
| 6197 | typedef int (*auto_hal_init_t)(struct audio_device*, |
| 6198 | auto_hal_init_config_t); |
| 6199 | static auto_hal_init_t auto_hal_init; |
| 6200 | |
| 6201 | typedef void (*auto_hal_deinit_t)(); |
| 6202 | static auto_hal_deinit_t auto_hal_deinit; |
| 6203 | |
| 6204 | typedef int (*auto_hal_create_audio_patch_t)(struct audio_hw_device*, |
| 6205 | unsigned int, |
| 6206 | const struct audio_port_config*, |
| 6207 | unsigned int, |
| 6208 | const struct audio_port_config*, |
| 6209 | audio_patch_handle_t*); |
| 6210 | static auto_hal_create_audio_patch_t auto_hal_create_audio_patch; |
| 6211 | |
| 6212 | typedef int (*auto_hal_release_audio_patch_t)(struct audio_hw_device*, |
| 6213 | audio_patch_handle_t); |
| 6214 | static auto_hal_release_audio_patch_t auto_hal_release_audio_patch; |
| 6215 | |
| 6216 | typedef int (*auto_hal_get_car_audio_stream_from_address_t)(const char*); |
| 6217 | static auto_hal_get_car_audio_stream_from_address_t auto_hal_get_car_audio_stream_from_address; |
| 6218 | |
| 6219 | typedef int (*auto_hal_open_output_stream_t)(struct stream_out*); |
| 6220 | static auto_hal_open_output_stream_t auto_hal_open_output_stream; |
| 6221 | |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 6222 | typedef int (*auto_hal_open_input_stream_t)(struct stream_in*); |
| 6223 | static auto_hal_open_input_stream_t auto_hal_open_input_stream; |
| 6224 | |
Susan Wang | e395956 | 2021-03-11 11:50:26 -0500 | [diff] [blame] | 6225 | typedef int (*auto_hal_open_echo_reference_stream_t)(struct stream_in*); |
| 6226 | static auto_hal_open_echo_reference_stream_t auto_hal_open_echo_reference_stream; |
| 6227 | |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6228 | typedef bool (*auto_hal_is_bus_device_usecase_t)(audio_usecase_t); |
| 6229 | static auto_hal_is_bus_device_usecase_t auto_hal_is_bus_device_usecase; |
| 6230 | |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6231 | typedef int (*auto_hal_get_audio_port_t)(struct audio_hw_device*, |
| 6232 | struct audio_port*); |
| 6233 | static auto_hal_get_audio_port_t auto_hal_get_audio_port; |
| 6234 | |
| 6235 | typedef int (*auto_hal_set_audio_port_config_t)(struct audio_hw_device*, |
| 6236 | const struct audio_port_config*); |
| 6237 | static auto_hal_set_audio_port_config_t auto_hal_set_audio_port_config; |
| 6238 | |
| 6239 | typedef void (*auto_hal_set_parameters_t)(struct audio_device*, |
| 6240 | struct str_parms*); |
| 6241 | static auto_hal_set_parameters_t auto_hal_set_parameters; |
| 6242 | |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 6243 | typedef int (*auto_hal_start_hfp_downlink_t)(struct audio_device*, |
| 6244 | struct audio_usecase*); |
| 6245 | static auto_hal_start_hfp_downlink_t auto_hal_start_hfp_downlink; |
| 6246 | |
| 6247 | typedef int (*auto_hal_stop_hfp_downlink_t)(struct audio_device*, |
| 6248 | struct audio_usecase*); |
| 6249 | static auto_hal_stop_hfp_downlink_t auto_hal_stop_hfp_downlink; |
| 6250 | |
Guodong Hu | 267bdf8 | 2019-08-12 19:22:32 +0800 | [diff] [blame] | 6251 | typedef snd_device_t (*auto_hal_get_input_snd_device_t)(struct audio_device*, |
| 6252 | audio_usecase_t); |
| 6253 | static auto_hal_get_input_snd_device_t auto_hal_get_input_snd_device; |
| 6254 | |
| 6255 | typedef snd_device_t (*auto_hal_get_output_snd_device_t)(struct audio_device*, |
| 6256 | audio_usecase_t); |
| 6257 | static auto_hal_get_output_snd_device_t auto_hal_get_output_snd_device; |
| 6258 | |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 6259 | typedef snd_device_t (*auto_hal_get_snd_device_for_car_audio_stream_t)(int |
| 6260 | car_audio_stream); |
| 6261 | static auto_hal_get_snd_device_for_car_audio_stream_t auto_hal_get_snd_device_for_car_audio_stream; |
| 6262 | |
Susan Wang | 727dd6b | 2021-03-26 11:28:59 -0400 | [diff] [blame] | 6263 | typedef bool (*auto_hal_overwrite_priority_for_auto_t)(struct stream_in*); |
| 6264 | static auto_hal_overwrite_priority_for_auto_t auto_hal_overwrite_priority_for_auto; |
| 6265 | |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6266 | int auto_hal_feature_init(bool is_feature_enabled) |
| 6267 | { |
| 6268 | ALOGD("%s: Called with feature %s", __func__, |
| 6269 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 6270 | |
| 6271 | #ifdef LINUX_ENABLED |
| 6272 | is_feature_enabled = true; |
| 6273 | #endif |
| 6274 | |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6275 | if (is_feature_enabled) { |
| 6276 | // dlopen lib |
| 6277 | auto_hal_lib_handle = dlopen(AUTO_HAL_LIB_PATH, RTLD_NOW); |
| 6278 | |
| 6279 | if (!auto_hal_lib_handle) { |
| 6280 | ALOGE("%s: dlopen failed", __func__); |
| 6281 | goto feature_disabled; |
| 6282 | } |
| 6283 | if (!(auto_hal_init = (auto_hal_init_t)dlsym( |
| 6284 | auto_hal_lib_handle, "auto_hal_init")) || |
| 6285 | !(auto_hal_deinit = |
| 6286 | (auto_hal_deinit_t)dlsym( |
| 6287 | auto_hal_lib_handle, "auto_hal_deinit")) || |
| 6288 | !(auto_hal_create_audio_patch = |
| 6289 | (auto_hal_create_audio_patch_t)dlsym( |
| 6290 | auto_hal_lib_handle, "auto_hal_create_audio_patch")) || |
| 6291 | !(auto_hal_release_audio_patch = |
| 6292 | (auto_hal_release_audio_patch_t)dlsym( |
| 6293 | auto_hal_lib_handle, "auto_hal_release_audio_patch")) || |
| 6294 | !(auto_hal_get_car_audio_stream_from_address = |
| 6295 | (auto_hal_get_car_audio_stream_from_address_t)dlsym( |
| 6296 | auto_hal_lib_handle, "auto_hal_get_car_audio_stream_from_address")) || |
| 6297 | !(auto_hal_open_output_stream = |
| 6298 | (auto_hal_open_output_stream_t)dlsym( |
| 6299 | auto_hal_lib_handle, "auto_hal_open_output_stream")) || |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 6300 | !(auto_hal_open_input_stream = |
| 6301 | (auto_hal_open_input_stream_t)dlsym( |
| 6302 | auto_hal_lib_handle, "auto_hal_open_input_stream")) || |
Susan Wang | e395956 | 2021-03-11 11:50:26 -0500 | [diff] [blame] | 6303 | !(auto_hal_open_echo_reference_stream = |
| 6304 | (auto_hal_open_echo_reference_stream_t)dlsym( |
| 6305 | auto_hal_lib_handle, "auto_hal_open_echo_reference_stream")) || |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6306 | !(auto_hal_is_bus_device_usecase = |
| 6307 | (auto_hal_is_bus_device_usecase_t)dlsym( |
| 6308 | auto_hal_lib_handle, "auto_hal_is_bus_device_usecase")) || |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6309 | !(auto_hal_get_audio_port = |
| 6310 | (auto_hal_get_audio_port_t)dlsym( |
| 6311 | auto_hal_lib_handle, "auto_hal_get_audio_port")) || |
| 6312 | !(auto_hal_set_audio_port_config = |
| 6313 | (auto_hal_set_audio_port_config_t)dlsym( |
| 6314 | auto_hal_lib_handle, "auto_hal_set_audio_port_config")) || |
| 6315 | !(auto_hal_set_parameters = |
| 6316 | (auto_hal_set_parameters_t)dlsym( |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 6317 | auto_hal_lib_handle, "auto_hal_set_parameters")) || |
| 6318 | !(auto_hal_start_hfp_downlink = |
| 6319 | (auto_hal_start_hfp_downlink_t)dlsym( |
| 6320 | auto_hal_lib_handle, "auto_hal_start_hfp_downlink")) || |
| 6321 | !(auto_hal_stop_hfp_downlink = |
| 6322 | (auto_hal_stop_hfp_downlink_t)dlsym( |
Guodong Hu | 267bdf8 | 2019-08-12 19:22:32 +0800 | [diff] [blame] | 6323 | auto_hal_lib_handle, "auto_hal_stop_hfp_downlink")) || |
| 6324 | !(auto_hal_get_input_snd_device = |
| 6325 | (auto_hal_get_input_snd_device_t)dlsym( |
| 6326 | auto_hal_lib_handle, "auto_hal_get_input_snd_device")) || |
| 6327 | !(auto_hal_get_output_snd_device = |
| 6328 | (auto_hal_get_output_snd_device_t)dlsym( |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 6329 | auto_hal_lib_handle, "auto_hal_get_output_snd_device")) || |
| 6330 | !(auto_hal_get_snd_device_for_car_audio_stream = |
| 6331 | (auto_hal_get_snd_device_for_car_audio_stream_t)dlsym( |
Susan Wang | 727dd6b | 2021-03-26 11:28:59 -0400 | [diff] [blame] | 6332 | auto_hal_lib_handle, "auto_hal_get_snd_device_for_car_audio_stream")) || |
| 6333 | !(auto_hal_overwrite_priority_for_auto = |
| 6334 | (auto_hal_overwrite_priority_for_auto_t)dlsym( |
| 6335 | auto_hal_lib_handle, "auto_hal_overwrite_priority_for_auto"))) { |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6336 | ALOGE("%s: dlsym failed", __func__); |
| 6337 | goto feature_disabled; |
| 6338 | } |
| 6339 | ALOGD("%s:: ---- Feature AUTO_HAL is Enabled ----", __func__); |
| 6340 | return 0; |
| 6341 | } |
| 6342 | |
| 6343 | feature_disabled: |
| 6344 | if (auto_hal_lib_handle) { |
| 6345 | dlclose(auto_hal_lib_handle); |
| 6346 | auto_hal_lib_handle = NULL; |
| 6347 | } |
| 6348 | |
| 6349 | auto_hal_init = NULL; |
| 6350 | auto_hal_deinit = NULL; |
| 6351 | auto_hal_create_audio_patch = NULL; |
| 6352 | auto_hal_release_audio_patch = NULL; |
| 6353 | auto_hal_get_car_audio_stream_from_address = NULL; |
| 6354 | auto_hal_open_output_stream = NULL; |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 6355 | auto_hal_open_input_stream = NULL; |
Susan Wang | e395956 | 2021-03-11 11:50:26 -0500 | [diff] [blame] | 6356 | auto_hal_open_echo_reference_stream = NULL; |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6357 | auto_hal_is_bus_device_usecase = NULL; |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6358 | auto_hal_get_audio_port = NULL; |
| 6359 | auto_hal_set_audio_port_config = NULL; |
| 6360 | auto_hal_set_parameters = NULL; |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 6361 | auto_hal_start_hfp_downlink = NULL; |
| 6362 | auto_hal_stop_hfp_downlink = NULL; |
Guodong Hu | 267bdf8 | 2019-08-12 19:22:32 +0800 | [diff] [blame] | 6363 | auto_hal_get_input_snd_device = NULL; |
| 6364 | auto_hal_get_output_snd_device = NULL; |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 6365 | auto_hal_get_snd_device_for_car_audio_stream = NULL; |
Susan Wang | 727dd6b | 2021-03-26 11:28:59 -0400 | [diff] [blame] | 6366 | auto_hal_overwrite_priority_for_auto = NULL; |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6367 | |
| 6368 | ALOGW(":: %s: ---- Feature AUTO_HAL is disabled ----", __func__); |
| 6369 | return -ENOSYS; |
| 6370 | } |
| 6371 | |
| 6372 | int audio_extn_auto_hal_init(struct audio_device *adev) |
| 6373 | { |
| 6374 | if(auto_hal_init) { |
| 6375 | auto_hal_init_config_t auto_hal_init_config; |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6376 | auto_hal_init_config.fp_audio_extn_ext_hw_plugin_usecase_start = audio_extn_ext_hw_plugin_usecase_start; |
| 6377 | auto_hal_init_config.fp_audio_extn_ext_hw_plugin_usecase_stop = audio_extn_ext_hw_plugin_usecase_stop; |
| 6378 | auto_hal_init_config.fp_get_usecase_from_list = get_usecase_from_list; |
| 6379 | auto_hal_init_config.fp_get_output_period_size = get_output_period_size; |
| 6380 | auto_hal_init_config.fp_audio_extn_ext_hw_plugin_set_audio_gain = audio_extn_ext_hw_plugin_set_audio_gain; |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 6381 | auto_hal_init_config.fp_select_devices = select_devices; |
| 6382 | auto_hal_init_config.fp_disable_audio_route = disable_audio_route; |
| 6383 | auto_hal_init_config.fp_disable_snd_device = disable_snd_device; |
Guodong Hu | 267bdf8 | 2019-08-12 19:22:32 +0800 | [diff] [blame] | 6384 | auto_hal_init_config.fp_adev_get_active_input = adev_get_active_input; |
| 6385 | auto_hal_init_config.fp_platform_set_echo_reference = platform_set_echo_reference; |
Guodong Hu | f5e614d | 2019-06-24 18:42:03 +0800 | [diff] [blame] | 6386 | auto_hal_init_config.fp_platform_get_eccarstate = platform_get_eccarstate; |
Derek Chen | 6c0f3de | 2020-02-26 00:30:42 -0800 | [diff] [blame] | 6387 | auto_hal_init_config.fp_generate_patch_handle = generate_patch_handle; |
Tahir Dawson | 7fabad4 | 2022-06-21 12:37:55 -0400 | [diff] [blame] | 6388 | auto_hal_init_config.fp_platform_get_pcm_device_id = platform_get_pcm_device_id; |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6389 | return auto_hal_init(adev, auto_hal_init_config); |
| 6390 | } |
| 6391 | else |
| 6392 | return 0; |
| 6393 | } |
| 6394 | |
| 6395 | void audio_extn_auto_hal_deinit() |
| 6396 | { |
| 6397 | if (auto_hal_deinit) |
| 6398 | auto_hal_deinit(); |
| 6399 | } |
| 6400 | |
| 6401 | int audio_extn_auto_hal_create_audio_patch(struct audio_hw_device *dev, |
| 6402 | unsigned int num_sources, |
| 6403 | const struct audio_port_config *sources, |
| 6404 | unsigned int num_sinks, |
| 6405 | const struct audio_port_config *sinks, |
| 6406 | audio_patch_handle_t *handle) |
| 6407 | { |
| 6408 | return ((auto_hal_create_audio_patch) ? |
| 6409 | auto_hal_create_audio_patch(dev, |
| 6410 | num_sources, |
| 6411 | sources, |
| 6412 | num_sinks, |
| 6413 | sinks, |
| 6414 | handle): 0); |
| 6415 | } |
| 6416 | |
| 6417 | int audio_extn_auto_hal_release_audio_patch(struct audio_hw_device *dev, |
| 6418 | audio_patch_handle_t handle) |
| 6419 | { |
| 6420 | return ((auto_hal_release_audio_patch) ? |
| 6421 | auto_hal_release_audio_patch(dev, handle): 0); |
| 6422 | } |
| 6423 | |
| 6424 | int audio_extn_auto_hal_get_car_audio_stream_from_address(const char *address) |
| 6425 | { |
| 6426 | return ((auto_hal_get_car_audio_stream_from_address) ? |
Guodong Hu | 267bdf8 | 2019-08-12 19:22:32 +0800 | [diff] [blame] | 6427 | auto_hal_get_car_audio_stream_from_address(address): -ENOSYS); |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | int audio_extn_auto_hal_open_output_stream(struct stream_out *out) |
| 6431 | { |
| 6432 | return ((auto_hal_open_output_stream) ? |
Guodong Hu | 267bdf8 | 2019-08-12 19:22:32 +0800 | [diff] [blame] | 6433 | auto_hal_open_output_stream(out): -ENOSYS); |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6434 | } |
| 6435 | |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 6436 | int audio_extn_auto_hal_open_input_stream(struct stream_in *in) |
| 6437 | { |
| 6438 | return ((auto_hal_open_input_stream) ? |
| 6439 | auto_hal_open_input_stream(in): -ENOSYS); |
| 6440 | } |
| 6441 | |
Susan Wang | e395956 | 2021-03-11 11:50:26 -0500 | [diff] [blame] | 6442 | int audio_extn_auto_hal_open_echo_reference_stream(struct stream_in *in) |
| 6443 | { |
| 6444 | return ((auto_hal_open_echo_reference_stream) ? |
| 6445 | auto_hal_open_echo_reference_stream(in): 0); |
| 6446 | } |
| 6447 | |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6448 | bool audio_extn_auto_hal_is_bus_device_usecase(audio_usecase_t uc_id) |
| 6449 | { |
| 6450 | return ((auto_hal_is_bus_device_usecase) ? |
Guodong Hu | 267bdf8 | 2019-08-12 19:22:32 +0800 | [diff] [blame] | 6451 | auto_hal_is_bus_device_usecase(uc_id): false); |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6452 | } |
| 6453 | |
| 6454 | int audio_extn_auto_hal_get_audio_port(struct audio_hw_device *dev, |
| 6455 | struct audio_port *config) |
| 6456 | { |
| 6457 | return ((auto_hal_get_audio_port) ? |
| 6458 | auto_hal_get_audio_port(dev, config): 0); |
| 6459 | } |
| 6460 | |
| 6461 | int audio_extn_auto_hal_set_audio_port_config(struct audio_hw_device *dev, |
| 6462 | const struct audio_port_config *config) |
| 6463 | { |
| 6464 | return ((auto_hal_set_audio_port_config) ? |
| 6465 | auto_hal_set_audio_port_config(dev, config): 0); |
| 6466 | } |
| 6467 | |
| 6468 | void audio_extn_auto_hal_set_parameters(struct audio_device *adev, |
| 6469 | struct str_parms *parms) |
| 6470 | { |
| 6471 | if (auto_hal_set_parameters) |
| 6472 | auto_hal_set_parameters(adev, parms); |
| 6473 | } |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 6474 | |
| 6475 | int audio_extn_auto_hal_start_hfp_downlink(struct audio_device *adev, |
| 6476 | struct audio_usecase *uc_info) |
| 6477 | { |
| 6478 | return ((auto_hal_start_hfp_downlink) ? |
| 6479 | auto_hal_start_hfp_downlink(adev, uc_info): 0); |
| 6480 | } |
| 6481 | |
| 6482 | int audio_extn_auto_hal_stop_hfp_downlink(struct audio_device *adev, |
| 6483 | struct audio_usecase *uc_info) |
| 6484 | { |
| 6485 | return ((auto_hal_stop_hfp_downlink) ? |
| 6486 | auto_hal_stop_hfp_downlink(adev, uc_info): 0); |
| 6487 | } |
Guodong Hu | 267bdf8 | 2019-08-12 19:22:32 +0800 | [diff] [blame] | 6488 | |
| 6489 | snd_device_t audio_extn_auto_hal_get_input_snd_device(struct audio_device *adev, |
| 6490 | audio_usecase_t uc_id) |
| 6491 | { |
| 6492 | return ((auto_hal_get_input_snd_device) ? |
| 6493 | auto_hal_get_input_snd_device(adev, uc_id): SND_DEVICE_NONE); |
| 6494 | } |
| 6495 | |
| 6496 | snd_device_t audio_extn_auto_hal_get_output_snd_device(struct audio_device *adev, |
| 6497 | audio_usecase_t uc_id) |
| 6498 | { |
| 6499 | return ((auto_hal_get_output_snd_device) ? |
| 6500 | auto_hal_get_output_snd_device(adev, uc_id): SND_DEVICE_NONE); |
| 6501 | } |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 6502 | |
| 6503 | snd_device_t audio_extn_auto_hal_get_snd_device_for_car_audio_stream(int car_audio_stream) |
| 6504 | { |
| 6505 | return ((auto_hal_get_snd_device_for_car_audio_stream) ? |
| 6506 | auto_hal_get_snd_device_for_car_audio_stream(car_audio_stream): SND_DEVICE_NONE); |
| 6507 | } |
Susan Wang | 727dd6b | 2021-03-26 11:28:59 -0400 | [diff] [blame] | 6508 | |
| 6509 | bool audio_extn_auto_hal_overwrite_priority_for_auto(struct stream_in *in) |
| 6510 | { |
| 6511 | return ((auto_hal_overwrite_priority_for_auto) ? |
| 6512 | auto_hal_overwrite_priority_for_auto(in): false); |
| 6513 | } |
| 6514 | |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6515 | // END: AUTO_HAL =================================================================== |
| 6516 | |
Fei Tong | affdf73 | 2020-02-20 20:39:05 +0800 | [diff] [blame] | 6517 | // START: Synth ====================================================================== |
| 6518 | #ifdef __LP64__ |
| 6519 | #define SYNTH_LIB_PATH "/vendor/lib64/libsynth.so" |
| 6520 | #else |
| 6521 | #define SYNTH_LIB_PATH "/vendor/lib/libsynth.so" |
| 6522 | #endif |
| 6523 | |
| 6524 | static void *synth_lib_handle = NULL; |
| 6525 | |
| 6526 | typedef void (*synth_init_t)(synth_init_config_t); |
| 6527 | static synth_init_t synth_init; |
| 6528 | |
| 6529 | typedef bool (*synth_is_active_t)(struct audio_device *adev); |
| 6530 | static synth_is_active_t synth_is_active; |
| 6531 | |
| 6532 | typedef void (*synth_set_parameters_t)(struct audio_device *adev, |
| 6533 | struct str_parms *parms); |
| 6534 | static synth_set_parameters_t synth_set_parameters; |
| 6535 | |
| 6536 | int synth_feature_init(bool is_feature_enabled) |
| 6537 | { |
| 6538 | ALOGD("%s: Called with feature %s", __func__, |
| 6539 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
| 6540 | if (is_feature_enabled) { |
| 6541 | // dlopen lib |
| 6542 | synth_lib_handle = dlopen(SYNTH_LIB_PATH, RTLD_NOW); |
| 6543 | |
| 6544 | if (!synth_lib_handle) { |
| 6545 | ALOGE("%s: dlopen failed", __func__); |
| 6546 | goto feature_disabled; |
| 6547 | } |
| 6548 | if (!(synth_init = (synth_init_t)dlsym( |
| 6549 | synth_lib_handle, "synth_init")) || |
| 6550 | !(synth_is_active = |
| 6551 | (synth_is_active_t)dlsym( |
| 6552 | synth_lib_handle, "synth_is_active")) || |
| 6553 | !(synth_set_parameters = |
| 6554 | (synth_set_parameters_t)dlsym( |
| 6555 | synth_lib_handle, "synth_set_parameters"))) { |
| 6556 | ALOGE("%s: dlsym failed", __func__); |
| 6557 | goto feature_disabled; |
| 6558 | } |
| 6559 | synth_init_config_t init_config; |
| 6560 | init_config.fp_platform_get_pcm_device_id = platform_get_pcm_device_id; |
| 6561 | init_config.fp_get_usecase_from_list = get_usecase_from_list; |
| 6562 | init_config.fp_select_devices = select_devices; |
| 6563 | init_config.fp_disable_audio_route = disable_audio_route; |
| 6564 | init_config.fp_disable_snd_device = disable_snd_device; |
| 6565 | |
| 6566 | synth_init(init_config); |
| 6567 | ALOGD("%s:: ---- Feature Synth is Enabled ----", __func__); |
| 6568 | return 0; |
| 6569 | } |
| 6570 | |
| 6571 | feature_disabled: |
| 6572 | if (synth_lib_handle) { |
| 6573 | dlclose(synth_lib_handle); |
| 6574 | synth_lib_handle = NULL; |
| 6575 | } |
| 6576 | |
| 6577 | synth_init = NULL; |
| 6578 | synth_is_active = NULL; |
| 6579 | synth_set_parameters = NULL; |
| 6580 | |
| 6581 | ALOGW(":: %s: ---- Feature Synth is disabled ----", __func__); |
| 6582 | return -ENOSYS; |
| 6583 | } |
| 6584 | |
| 6585 | bool audio_extn_synth_is_active(struct audio_device *adev) |
| 6586 | { |
| 6587 | return ((synth_is_active) ? |
| 6588 | synth_is_active(adev): false); |
| 6589 | } |
| 6590 | |
| 6591 | void audio_extn_synth_set_parameters(struct audio_device *adev, |
| 6592 | struct str_parms *parms) |
| 6593 | { |
| 6594 | ((synth_set_parameters) ? |
| 6595 | synth_set_parameters(adev, parms): NULL); |
| 6596 | } |
| 6597 | |
| 6598 | // END: Synth ======================================================================== |
| 6599 | |
Tahir Dawson | caaf099 | 2021-03-11 13:31:23 -0500 | [diff] [blame] | 6600 | // START: Power Policy Client ====================================================================== |
| 6601 | #ifdef __LP64__ |
| 6602 | #define POWER_POLICY_LIB_PATH "/vendor/lib64/libaudiopowerpolicy.so" |
| 6603 | #else |
| 6604 | #define POWER_POLICY_LIB_PATH "/vendor/lib/libaudiopowerpolicy.so" |
| 6605 | #endif |
Fei Tong | affdf73 | 2020-02-20 20:39:05 +0800 | [diff] [blame] | 6606 | |
Tahir Dawson | caaf099 | 2021-03-11 13:31:23 -0500 | [diff] [blame] | 6607 | static void* power_policy_lib_handle; |
Subhadra Jagadeesan | 63a1e83 | 2023-01-13 11:26:38 +0530 | [diff] [blame] | 6608 | typedef int (*launch_power_policy_t) (power_policy_init_config_t); |
Tahir Dawson | caaf099 | 2021-03-11 13:31:23 -0500 | [diff] [blame] | 6609 | static launch_power_policy_t launch_power_policy; |
| 6610 | |
| 6611 | static void* power_policy_thread_func(void* arg __unused) { |
| 6612 | if (launch_power_policy == NULL) { |
| 6613 | ALOGE("%s: Power Policy launcher is NULL", __func__); |
| 6614 | goto exit; |
| 6615 | } |
| 6616 | ALOGD("%s: Launching Power Policy Client", __func__); |
Shubhasini Sugumaran | 3fde658 | 2022-01-19 15:54:50 -0500 | [diff] [blame] | 6617 | power_policy_init_config_t init_config; |
| 6618 | init_config.fp_in_set_power_policy = in_set_power_policy; |
| 6619 | init_config.fp_out_set_power_policy = out_set_power_policy; |
| 6620 | launch_power_policy(init_config); |
Tahir Dawson | caaf099 | 2021-03-11 13:31:23 -0500 | [diff] [blame] | 6621 | |
| 6622 | exit: |
Shubhasini Sugumaran | 3fde658 | 2022-01-19 15:54:50 -0500 | [diff] [blame] | 6623 | return NULL; |
Tahir Dawson | caaf099 | 2021-03-11 13:31:23 -0500 | [diff] [blame] | 6624 | } |
| 6625 | |
| 6626 | static int power_policy_feature_init(bool is_feature_enabled) |
| 6627 | { |
| 6628 | pthread_t tid; |
| 6629 | pthread_attr_t attr; |
| 6630 | |
| 6631 | ALOGD("%s: Called with feature %s", __func__, |
| 6632 | is_feature_enabled ? "Enabled" : "NOT Enabled"); |
| 6633 | if (is_feature_enabled) { |
| 6634 | // dlopen lib |
| 6635 | power_policy_lib_handle = dlopen(POWER_POLICY_LIB_PATH, RTLD_NOW); |
| 6636 | |
| 6637 | if (!power_policy_lib_handle) { |
| 6638 | ALOGE("%s: dlopen failed", __func__); |
| 6639 | goto feature_disabled; |
| 6640 | } |
| 6641 | if (!(launch_power_policy = (launch_power_policy_t)dlsym( |
| 6642 | power_policy_lib_handle, "launchPowerPolicyClient"))) |
| 6643 | { |
| 6644 | ALOGE("%s: dlsym failed", __func__); |
| 6645 | goto feature_disabled; |
| 6646 | } |
| 6647 | |
| 6648 | pthread_attr_init(&attr); |
| 6649 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 6650 | if (pthread_create(&tid, &attr, power_policy_thread_func, NULL)) |
| 6651 | { |
| 6652 | ALOGE("%s: Failed to create power policy thread", __func__); |
| 6653 | goto feature_disabled; |
| 6654 | } |
| 6655 | ALOGD("%s:: ---- Feature Power Policy Client is Enabled ----", __func__); |
| 6656 | return 0; |
| 6657 | } |
| 6658 | |
| 6659 | feature_disabled: |
| 6660 | if (power_policy_lib_handle) { |
| 6661 | dlclose(power_policy_lib_handle); |
| 6662 | power_policy_lib_handle = NULL; |
| 6663 | } |
| 6664 | |
| 6665 | launch_power_policy = NULL; |
| 6666 | |
| 6667 | ALOGW(":: %s: ---- Feature Power Policy Client is disabled ----", __func__); |
| 6668 | return -ENOSYS; |
| 6669 | |
| 6670 | // END: Power Policy Client ====================================================================== |
| 6671 | } |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6672 | void audio_extn_feature_init() |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 6673 | { |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 6674 | vendor_enhanced_info = audio_extn_utils_get_vendor_enhanced_info(); |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6675 | // register feature init functions here |
| 6676 | // each feature needs a vendor property |
| 6677 | // default value added is for GSI (non vendor modified images) |
| 6678 | snd_mon_feature_init( |
| 6679 | property_get_bool("vendor.audio.feature.snd_mon.enable", |
vivek mehta | f6e6b96 | 2019-06-21 15:08:51 -0700 | [diff] [blame] | 6680 | false)); |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6681 | compr_cap_feature_init( |
| 6682 | property_get_bool("vendor.audio.feature.compr_cap.enable", |
| 6683 | false)); |
| 6684 | dsm_feedback_feature_init( |
| 6685 | property_get_bool("vendor.audio.feature.dsm_feedback.enable", |
| 6686 | false)); |
| 6687 | ssrec_feature_init( |
| 6688 | property_get_bool("vendor.audio.feature.ssrec.enable", |
| 6689 | false)); |
| 6690 | src_trkn_feature_init( |
| 6691 | property_get_bool("vendor.audio.feature.src_trkn.enable", |
| 6692 | false)); |
| 6693 | hdmi_edid_feature_init( |
| 6694 | property_get_bool("vendor.audio.feature.hdmi_edid.enable", |
| 6695 | false)); |
| 6696 | keep_alive_feature_init( |
| 6697 | property_get_bool("vendor.audio.feature.keep_alive.enable", |
| 6698 | false)); |
| 6699 | hifi_audio_feature_init( |
| 6700 | property_get_bool("vendor.audio.feature.hifi_audio.enable", |
| 6701 | false)); |
| 6702 | ras_feature_init( |
| 6703 | property_get_bool("vendor.audio.feature.ras.enable", |
| 6704 | false)); |
| 6705 | kpi_optimize_feature_init( |
| 6706 | property_get_bool("vendor.audio.feature.kpi_optimize.enable", |
| 6707 | false)); |
| 6708 | usb_offload_feature_init( |
| 6709 | property_get_bool("vendor.audio.feature.usb_offload.enable", |
vivek mehta | f6e6b96 | 2019-06-21 15:08:51 -0700 | [diff] [blame] | 6710 | false)); |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6711 | usb_offload_burst_mode_feature_init( |
| 6712 | property_get_bool("vendor.audio.feature.usb_offload_burst_mode.enable", |
| 6713 | false)); |
| 6714 | usb_offload_sidetone_volume_feature_init( |
| 6715 | property_get_bool("vendor.audio.feature.usb_offload_sidetone_volume.enable", |
| 6716 | false)); |
| 6717 | a2dp_offload_feature_init( |
| 6718 | property_get_bool("vendor.audio.feature.a2dp_offload.enable", |
| 6719 | false)); |
| 6720 | wsa_feature_init( |
| 6721 | property_get_bool("vendor.audio.feature.wsa.enable", |
| 6722 | false)); |
| 6723 | compress_meta_data_feature_init( |
| 6724 | property_get_bool("vendor.audio.feature.compress_meta_data.enable", |
| 6725 | false)); |
| 6726 | vbat_feature_init( |
| 6727 | property_get_bool("vendor.audio.feature.vbat.enable", |
| 6728 | false)); |
| 6729 | display_port_feature_init( |
| 6730 | property_get_bool("vendor.audio.feature.display_port.enable", |
| 6731 | false)); |
| 6732 | fluence_feature_init( |
| 6733 | property_get_bool("vendor.audio.feature.fluence.enable", |
| 6734 | false)); |
| 6735 | custom_stereo_feature_init( |
| 6736 | property_get_bool("vendor.audio.feature.custom_stereo.enable", |
| 6737 | false)); |
| 6738 | anc_headset_feature_init( |
| 6739 | property_get_bool("vendor.audio.feature.anc_headset.enable", |
| 6740 | false)); |
| 6741 | spkr_prot_feature_init( |
| 6742 | property_get_bool("vendor.audio.feature.spkr_prot.enable", |
vivek mehta | f6e6b96 | 2019-06-21 15:08:51 -0700 | [diff] [blame] | 6743 | false)); |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6744 | fm_feature_init( |
| 6745 | property_get_bool("vendor.audio.feature.fm.enable", |
| 6746 | false)); |
| 6747 | external_qdsp_feature_init( |
| 6748 | property_get_bool("vendor.audio.feature.external_dsp.enable", |
vivek mehta | f6e6b96 | 2019-06-21 15:08:51 -0700 | [diff] [blame] | 6749 | false)); |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6750 | external_speaker_feature_init( |
| 6751 | property_get_bool("vendor.audio.feature.external_speaker.enable", |
vivek mehta | f6e6b96 | 2019-06-21 15:08:51 -0700 | [diff] [blame] | 6752 | false)); |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6753 | external_speaker_tfa_feature_init( |
| 6754 | property_get_bool("vendor.audio.feature.external_speaker_tfa.enable", |
| 6755 | false)); |
| 6756 | hwdep_cal_feature_init( |
| 6757 | property_get_bool("vendor.audio.feature.hwdep_cal.enable", |
vivek mehta | f6e6b96 | 2019-06-21 15:08:51 -0700 | [diff] [blame] | 6758 | false)); |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 6759 | #ifdef LINUX_ENABLED |
| 6760 | #ifdef HFP_ENABLED |
| 6761 | hfp_feature_init(true); |
| 6762 | #else |
| 6763 | hfp_feature_init(false); |
| 6764 | #endif |
| 6765 | #else |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6766 | hfp_feature_init( |
| 6767 | property_get_bool("vendor.audio.feature.hfp.enable", |
Fei Tong | c20ce93 | 2021-06-21 16:42:38 +0800 | [diff] [blame] | 6768 | false)); |
| 6769 | #endif |
Derek Chen | a30a5f4 | 2019-12-03 11:17:09 -0500 | [diff] [blame] | 6770 | icc_feature_init( |
| 6771 | property_get_bool("vendor.audio.feature.icc.enable", |
| 6772 | false)); |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6773 | ext_hw_plugin_feature_init( |
| 6774 | property_get_bool("vendor.audio.feature.ext_hw_plugin.enable", |
| 6775 | false)); |
| 6776 | record_play_concurency_feature_init( |
| 6777 | property_get_bool("vendor.audio.feature.record_play_concurency.enable", |
| 6778 | false)); |
| 6779 | hdmi_passthrough_feature_init( |
| 6780 | property_get_bool("vendor.audio.feature.hdmi_passthrough.enable", |
| 6781 | false)); |
| 6782 | concurrent_capture_feature_init( |
| 6783 | property_get_bool("vendor.audio.feature.concurrent_capture.enable", |
vivek mehta | f6e6b96 | 2019-06-21 15:08:51 -0700 | [diff] [blame] | 6784 | false)); |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6785 | compress_in_feature_init( |
| 6786 | property_get_bool("vendor.audio.feature.compress_in.enable", |
| 6787 | false)); |
| 6788 | battery_listener_feature_init( |
| 6789 | property_get_bool("vendor.audio.feature.battery_listener.enable", |
| 6790 | false)); |
| 6791 | maxx_audio_feature_init( |
| 6792 | property_get_bool("vendor.audio.feature.maxx_audio.enable", |
vivek mehta | f6e6b96 | 2019-06-21 15:08:51 -0700 | [diff] [blame] | 6793 | false)); |
vivek mehta | ae1018c | 2019-05-09 12:19:57 -0700 | [diff] [blame] | 6794 | audiozoom_feature_init( |
| 6795 | property_get_bool("vendor.audio.feature.audiozoom.enable", |
vivek mehta | f6e6b96 | 2019-06-21 15:08:51 -0700 | [diff] [blame] | 6796 | false)); |
Derek Chen | f082fdb | 2019-07-24 13:27:20 -0700 | [diff] [blame] | 6797 | auto_hal_feature_init( |
| 6798 | property_get_bool("vendor.audio.feature.auto_hal.enable", |
| 6799 | false)); |
Fei Tong | affdf73 | 2020-02-20 20:39:05 +0800 | [diff] [blame] | 6800 | synth_feature_init( |
| 6801 | property_get_bool("vendor.audio.feature.synth.enable", |
| 6802 | false)); |
Tahir Dawson | caaf099 | 2021-03-11 13:31:23 -0500 | [diff] [blame] | 6803 | power_policy_feature_init( |
| 6804 | property_get_bool("vendor.audio.feature.powerpolicy.enable", |
| 6805 | false)); |
Krishna Kishor Jha | 0f4d848 | 2022-02-18 10:56:05 +0530 | [diff] [blame] | 6806 | concurrent_pcm_record_feature_init( |
| 6807 | property_get_bool("vendor.audio.feature.concurrent_pcm_record.enable", |
| 6808 | false)); |
Kogara Naveen Kumar | c575823 | 2022-11-07 20:25:40 +0530 | [diff] [blame] | 6809 | concurrent_low_latency_pcm_record_feature_init( |
| 6810 | property_get_bool("vendor.audio.feature.concurrent_low_latency_pcm_record.enable", |
| 6811 | false)); |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 6812 | } |
| 6813 | |
| 6814 | void audio_extn_set_parameters(struct audio_device *adev, |
| 6815 | struct str_parms *parms) |
| 6816 | { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 6817 | audio_extn_set_aanc_noise_level(adev, parms); |
| 6818 | audio_extn_set_anc_parameters(adev, parms); |
| 6819 | audio_extn_set_fluence_parameters(adev, parms); |
| 6820 | audio_extn_set_afe_proxy_parameters(adev, parms); |
| 6821 | audio_extn_fm_set_parameters(adev, parms); |
| 6822 | audio_extn_sound_trigger_set_parameters(adev, parms); |
| 6823 | audio_extn_listen_set_parameters(adev, parms); |
| 6824 | audio_extn_ssr_set_parameters(adev, parms); |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 6825 | audio_extn_dts_eagle_set_parameters(adev, parms); |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 6826 | audio_extn_ddp_set_parameters(adev, parms); |
| 6827 | audio_extn_ds2_set_parameters(adev, parms); |
| 6828 | audio_extn_customstereo_set_parameters(adev, parms); |
| 6829 | audio_extn_hpx_set_parameters(adev, parms); |
| 6830 | audio_extn_pm_set_parameters(parms); |
| 6831 | audio_extn_source_track_set_parameters(adev, parms); |
| 6832 | audio_extn_fbsp_set_parameters(parms); |
| 6833 | audio_extn_keep_alive_set_parameters(adev, parms); |
| 6834 | audio_extn_passthru_set_parameters(adev, parms); |
| 6835 | audio_extn_ext_disp_set_parameters(adev, parms); |
| 6836 | audio_extn_qaf_set_parameters(adev, parms); |
Sidipotu Ashok | d2f10ba | 2019-05-06 15:41:56 +0530 | [diff] [blame] | 6837 | if (audio_extn_qap_is_enabled()) |
| 6838 | audio_extn_qap_set_parameters(adev, parms); |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 6839 | if (adev->offload_effects_set_parameters != NULL) |
| 6840 | adev->offload_effects_set_parameters(parms); |
| 6841 | audio_extn_set_aptx_dec_bt_addr(adev, parms); |
| 6842 | audio_extn_ffv_set_parameters(adev, parms); |
| 6843 | audio_extn_ext_hw_plugin_set_parameters(adev->ext_hw_plugin, parms); |
Derek Chen | a30a5f4 | 2019-12-03 11:17:09 -0500 | [diff] [blame] | 6844 | audio_extn_icc_set_parameters(adev, parms); |
Fei Tong | affdf73 | 2020-02-20 20:39:05 +0800 | [diff] [blame] | 6845 | audio_extn_synth_set_parameters(adev, parms); |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 6846 | } |
| 6847 | |
| 6848 | void audio_extn_get_parameters(const struct audio_device *adev, |
| 6849 | struct str_parms *query, |
| 6850 | struct str_parms *reply) |
| 6851 | { |
| 6852 | char *kv_pairs = NULL; |
| 6853 | audio_extn_get_afe_proxy_parameters(adev, query, reply); |
| 6854 | audio_extn_get_fluence_parameters(adev, query, reply); |
| 6855 | audio_extn_ssr_get_parameters(adev, query, reply); |
| 6856 | get_active_offload_usecases(adev, query, reply); |
| 6857 | audio_extn_dts_eagle_get_parameters(adev, query, reply); |
| 6858 | audio_extn_hpx_get_parameters(query, reply); |
| 6859 | audio_extn_source_track_get_parameters(adev, query, reply); |
| 6860 | audio_extn_fbsp_get_parameters(query, reply); |
| 6861 | audio_extn_sound_trigger_get_parameters(adev, query, reply); |
| 6862 | audio_extn_fm_get_parameters(query, reply); |
| 6863 | if (adev->offload_effects_get_parameters != NULL) |
| 6864 | adev->offload_effects_get_parameters(query, reply); |
| 6865 | audio_extn_ext_hw_plugin_get_parameters(adev->ext_hw_plugin, query, reply); |
| 6866 | |
| 6867 | kv_pairs = str_parms_to_str(reply); |
| 6868 | ALOGD_IF(kv_pairs != NULL, "%s: returns %s", __func__, kv_pairs); |
| 6869 | free(kv_pairs); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 6870 | } |
Surendar Karka | 287348c | 2019-04-10 18:31:46 +0530 | [diff] [blame] | 6871 | |
| 6872 | int audio_ext_get_presentation_position(struct stream_out *out, |
| 6873 | struct audio_out_presentation_position_param *pos_param) |
| 6874 | { |
| 6875 | int ret = -ENODATA; |
| 6876 | |
| 6877 | if (!out) { |
| 6878 | ALOGE("%s:: Invalid stream",__func__); |
| 6879 | return ret; |
| 6880 | } |
| 6881 | |
| 6882 | if (is_offload_usecase(out->usecase)) { |
| 6883 | if (out->compr != NULL) |
| 6884 | ret = audio_extn_utils_compress_get_dsp_presentation_pos(out, |
| 6885 | &pos_param->frames, &pos_param->timestamp, pos_param->clock_id); |
| 6886 | } else { |
| 6887 | if (out->pcm) |
| 6888 | ret = audio_extn_utils_pcm_get_dsp_presentation_pos(out, |
| 6889 | &pos_param->frames, &pos_param->timestamp, pos_param->clock_id); |
| 6890 | } |
| 6891 | |
| 6892 | ALOGV("%s frames %lld timestamp %lld", __func__, (long long int)pos_param->frames, |
| 6893 | pos_param->timestamp.tv_sec*1000000000LL + pos_param->timestamp.tv_nsec); |
| 6894 | |
| 6895 | return ret; |
| 6896 | } |