Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1 | /* |
Robert Lee | 5821554 | 2019-07-15 20:55:12 +0800 | [diff] [blame] | 2 | * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved. |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 30 | #define LOG_TAG "platform_info" |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 31 | #define LOG_NDDEBUG 0 |
| 32 | |
| 33 | #include <errno.h> |
| 34 | #include <stdio.h> |
| 35 | #include <expat.h> |
Jiangen Jiao | 334224b | 2019-09-12 15:47:46 +0800 | [diff] [blame] | 36 | #include <pthread.h> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 37 | #include <log/log.h> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 38 | #include <cutils/str_parms.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 39 | #include <audio_hw.h> |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 40 | #include "acdb.h" |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 41 | #include "platform_api.h" |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 42 | #include "audio_extn.h" |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 43 | #include <platform.h> |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 44 | #include <math.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 45 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 46 | #ifdef DYNAMIC_LOG_ENABLED |
| 47 | #include <log_xml_parser.h> |
| 48 | #define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO |
| 49 | #include <log_utils.h> |
| 50 | #endif |
| 51 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 52 | #define BUF_SIZE 1024 |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 53 | char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH]; |
| 54 | char platform_info_xml_path_file[VENDOR_CONFIG_FILE_MAX_LENGTH]; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 55 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 56 | typedef enum { |
| 57 | ROOT, |
| 58 | ACDB, |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 59 | MODULE, |
| 60 | AEC, |
| 61 | NS, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 62 | BITWIDTH, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 63 | PCM_ID, |
| 64 | BACKEND_NAME, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 65 | INTERFACE_NAME, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 66 | CONFIG_PARAMS, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 67 | OPERATOR_SPECIFIC, |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 68 | GAIN_LEVEL_MAPPING, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 69 | APP_TYPE, |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 70 | ACDB_METAINFO_KEY, |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 71 | MICROPHONE_CHARACTERISTIC, |
| 72 | SND_DEVICES, |
| 73 | INPUT_SND_DEVICE, |
| 74 | INPUT_SND_DEVICE_TO_MIC_MAPPING, |
| 75 | SND_DEV, |
| 76 | MIC_INFO, |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 77 | CUSTOM_MTMX_PARAMS, |
| 78 | CUSTOM_MTMX_PARAM_COEFFS, |
Carter Hsu | 32a6236 | 2018-10-15 15:01:42 -0700 | [diff] [blame] | 79 | EXTERNAL_DEVICE_SPECIFIC, |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 80 | CUSTOM_MTMX_IN_PARAMS, |
| 81 | CUSTOM_MTMX_PARAM_IN_CH_INFO, |
Guodong Hu | 1d46f34 | 2019-06-28 16:57:30 +0800 | [diff] [blame] | 82 | MMSECNS, |
Juyu Chen | 918e1e1 | 2019-08-08 15:28:18 -0700 | [diff] [blame] | 83 | AUDIO_SOURCE_DELAY, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 84 | } section_t; |
| 85 | |
| 86 | typedef void (* section_process_fn)(const XML_Char **attr); |
| 87 | |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 88 | const char* get_platform_xml_path() |
| 89 | { |
| 90 | audio_get_vendor_config_path(vendor_config_path, sizeof(vendor_config_path)); |
| 91 | /* Get path for platorm_info_xml_path_name in vendor */ |
| 92 | snprintf(platform_info_xml_path_file, sizeof(platform_info_xml_path_file), |
| 93 | "%s/%s", vendor_config_path, PLATFORM_INFO_XML_PATH_NAME); |
| 94 | return platform_info_xml_path_file; |
| 95 | } |
| 96 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 97 | static void process_acdb_id(const XML_Char **attr); |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 98 | static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type); |
| 99 | static void process_effect_aec(const XML_Char **attr); |
| 100 | static void process_effect_ns(const XML_Char **attr); |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 101 | static void process_bit_width(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 102 | static void process_pcm_id(const XML_Char **attr); |
| 103 | static void process_backend_name(const XML_Char **attr); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 104 | static void process_interface_name(const XML_Char **attr); |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 105 | static void process_config_params(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 106 | static void process_root(const XML_Char **attr); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 107 | static void process_operator_specific(const XML_Char **attr); |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 108 | static void process_gain_db_to_level_map(const XML_Char **attr); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 109 | static void process_app_type(const XML_Char **attr); |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 110 | static void process_acdb_metainfo_key(const XML_Char **attr); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 111 | static void process_microphone_characteristic(const XML_Char **attr); |
| 112 | static void process_snd_dev(const XML_Char **attr); |
| 113 | static void process_mic_info(const XML_Char **attr); |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 114 | static void process_custom_mtmx_params(const XML_Char **attr); |
| 115 | static void process_custom_mtmx_param_coeffs(const XML_Char **attr); |
Carter Hsu | 32a6236 | 2018-10-15 15:01:42 -0700 | [diff] [blame] | 116 | static void process_external_dev(const XML_Char **attr); |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 117 | static void process_custom_mtmx_in_params(const XML_Char **attr); |
| 118 | static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr); |
Guodong Hu | 1d46f34 | 2019-06-28 16:57:30 +0800 | [diff] [blame] | 119 | static void process_fluence_mmsecns(const XML_Char **attr); |
Juyu Chen | 918e1e1 | 2019-08-08 15:28:18 -0700 | [diff] [blame] | 120 | static void process_audio_source_delay(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 121 | |
| 122 | static section_process_fn section_table[] = { |
| 123 | [ROOT] = process_root, |
| 124 | [ACDB] = process_acdb_id, |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 125 | [AEC] = process_effect_aec, |
| 126 | [NS] = process_effect_ns, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 127 | [BITWIDTH] = process_bit_width, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 128 | [PCM_ID] = process_pcm_id, |
| 129 | [BACKEND_NAME] = process_backend_name, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 130 | [INTERFACE_NAME] = process_interface_name, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 131 | [CONFIG_PARAMS] = process_config_params, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 132 | [OPERATOR_SPECIFIC] = process_operator_specific, |
| 133 | [APP_TYPE] = process_app_type, |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 134 | [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map, |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 135 | [ACDB_METAINFO_KEY] = process_acdb_metainfo_key, |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 136 | [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic, |
| 137 | [SND_DEV] = process_snd_dev, |
| 138 | [MIC_INFO] = process_mic_info, |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 139 | [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params, |
| 140 | [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs, |
Carter Hsu | 32a6236 | 2018-10-15 15:01:42 -0700 | [diff] [blame] | 141 | [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev, |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 142 | [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params, |
| 143 | [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info, |
Guodong Hu | 1d46f34 | 2019-06-28 16:57:30 +0800 | [diff] [blame] | 144 | [MMSECNS] = process_fluence_mmsecns, |
Juyu Chen | 918e1e1 | 2019-08-08 15:28:18 -0700 | [diff] [blame] | 145 | [AUDIO_SOURCE_DELAY] = process_audio_source_delay, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | static section_t section; |
| 149 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 150 | struct platform_info { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 151 | caller_t caller; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 152 | void *platform; |
| 153 | struct str_parms *kvpairs; |
| 154 | }; |
| 155 | |
| 156 | static struct platform_info my_data; |
Weiyin Jiang | 13bcdde | 2019-09-06 16:59:32 +0800 | [diff] [blame] | 157 | static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 158 | |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 159 | |
| 160 | struct audio_string_to_enum { |
| 161 | const char* name; |
| 162 | unsigned int value; |
| 163 | }; |
| 164 | |
| 165 | static snd_device_t in_snd_device; |
| 166 | |
| 167 | static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = { |
| 168 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN), |
| 169 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY), |
| 170 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE), |
| 171 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL), |
| 172 | }; |
| 173 | |
| 174 | static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = { |
| 175 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI), |
| 176 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL), |
| 177 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN), |
| 178 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID), |
| 179 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID), |
| 180 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID), |
| 181 | }; |
| 182 | |
| 183 | static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = { |
| 184 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED), |
| 185 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT), |
| 186 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED), |
| 187 | }; |
| 188 | |
| 189 | static const struct audio_string_to_enum device_in_types[] = { |
| 190 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT), |
| 191 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION), |
| 192 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC), |
| 193 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET), |
| 194 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET), |
| 195 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL), |
| 196 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI), |
| 197 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL), |
| 198 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX), |
| 199 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC), |
| 200 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX), |
| 201 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET), |
| 202 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET), |
| 203 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY), |
| 204 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE), |
| 205 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER), |
| 206 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER), |
| 207 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE), |
| 208 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF), |
| 209 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP), |
| 210 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK), |
| 211 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP), |
| 212 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS), |
| 213 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY), |
| 214 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET), |
| 215 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE), |
| 216 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT), |
| 217 | }; |
| 218 | |
| 219 | enum { |
| 220 | AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0 |
| 221 | AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1 |
| 222 | AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2 |
| 223 | AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4 |
| 224 | AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8 |
| 225 | AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10 |
| 226 | AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL) |
| 227 | | ORIENTATION) | GEOMETRIC_LOCATION) */ |
| 228 | }; |
| 229 | |
| 230 | static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name, |
| 231 | int32_t len, unsigned int *value) |
| 232 | { |
| 233 | if (table == NULL) { |
| 234 | ALOGE("%s: table is NULL", __func__); |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | if (name == NULL) { |
| 239 | ALOGE("null key"); |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | for (int i = 0; i < len; i++) { |
| 244 | if (!strcmp(table[i].name, name)) { |
| 245 | *value = table[i].value; |
| 246 | return true; |
| 247 | } |
| 248 | } |
| 249 | return false; |
| 250 | } |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 251 | |
| 252 | static struct audio_custom_mtmx_params_info mtmx_params_info; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 253 | static struct audio_custom_mtmx_in_params_info mtmx_in_params_info; |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 254 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 255 | /* |
| 256 | * <audio_platform_info> |
| 257 | * <acdb_ids> |
| 258 | * <device name="???" acdb_id="???"/> |
| 259 | * ... |
| 260 | * ... |
| 261 | * </acdb_ids> |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 262 | * <module_ids> |
| 263 | * <device name="???" module_id="???"/> |
| 264 | * ... |
| 265 | * ... |
| 266 | * </module_ids> |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 267 | * <backend_names> |
| 268 | * <device name="???" backend="???"/> |
| 269 | * ... |
| 270 | * ... |
| 271 | * </backend_names> |
| 272 | * <pcm_ids> |
| 273 | * <usecase name="???" type="in/out" id="???"/> |
| 274 | * ... |
| 275 | * ... |
| 276 | * </pcm_ids> |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 277 | * <interface_names> |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 278 | * <device name="Use audio device name here, not sound device name" interface="PRIMARY_I2S" codec_type="external/internal"/> |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 279 | * ... |
| 280 | * ... |
| 281 | * </interface_names> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 282 | * <config_params> |
| 283 | * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 284 | * <param key="operator_info" value="tmus;aa;bb;cc"/> |
| 285 | * <param key="operator_info" value="sprint;xx;yy;zz"/> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 286 | * ... |
| 287 | * ... |
| 288 | * </config_params> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 289 | * |
| 290 | * <operator_specific> |
| 291 | * <device name="???" operator="???" mixer_path="???" acdb_id="???"/> |
| 292 | * ... |
| 293 | * ... |
| 294 | * </operator_specific> |
| 295 | * |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 296 | * </audio_platform_info> |
| 297 | */ |
| 298 | |
| 299 | static void process_root(const XML_Char **attr __unused) |
| 300 | { |
| 301 | } |
| 302 | |
| 303 | /* mapping from usecase to pcm dev id */ |
| 304 | static void process_pcm_id(const XML_Char **attr) |
| 305 | { |
| 306 | int index; |
| 307 | |
| 308 | if (strcmp(attr[0], "name") != 0) { |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 309 | ALOGE("%s: 'name' not found, no pcm_id set!", __func__); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 310 | goto done; |
| 311 | } |
| 312 | |
| 313 | index = platform_get_usecase_index((char *)attr[1]); |
| 314 | if (index < 0) { |
| 315 | ALOGE("%s: usecase %s not found!", |
| 316 | __func__, attr[1]); |
| 317 | goto done; |
| 318 | } |
| 319 | |
| 320 | if (strcmp(attr[2], "type") != 0) { |
| 321 | ALOGE("%s: usecase type not mentioned", __func__); |
| 322 | goto done; |
| 323 | } |
| 324 | |
| 325 | int type = -1; |
| 326 | |
| 327 | if (!strcasecmp((char *)attr[3], "in")) { |
| 328 | type = 1; |
| 329 | } else if (!strcasecmp((char *)attr[3], "out")) { |
| 330 | type = 0; |
| 331 | } else { |
| 332 | ALOGE("%s: type must be IN or OUT", __func__); |
| 333 | goto done; |
| 334 | } |
| 335 | |
| 336 | if (strcmp(attr[4], "id") != 0) { |
| 337 | ALOGE("%s: usecase id not mentioned", __func__); |
| 338 | goto done; |
| 339 | } |
| 340 | |
| 341 | int id = atoi((char *)attr[5]); |
| 342 | |
| 343 | if (platform_set_usecase_pcm_id(index, type, id) < 0) { |
| 344 | ALOGE("%s: usecase %s type %d id %d was not set!", |
| 345 | __func__, attr[1], type, id); |
| 346 | goto done; |
| 347 | } |
| 348 | |
| 349 | done: |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | /* backend to be used for a device */ |
| 354 | static void process_backend_name(const XML_Char **attr) |
| 355 | { |
| 356 | int index; |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 357 | char *hw_interface = NULL; |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 358 | char *backend = NULL; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 359 | |
| 360 | if (strcmp(attr[0], "name") != 0) { |
| 361 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 362 | goto done; |
| 363 | } |
| 364 | |
| 365 | index = platform_get_snd_device_index((char *)attr[1]); |
| 366 | if (index < 0) { |
| 367 | ALOGE("%s: Device %s not found, no ACDB ID set!", |
| 368 | __func__, attr[1]); |
| 369 | goto done; |
| 370 | } |
| 371 | |
| 372 | if (strcmp(attr[2], "backend") != 0) { |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 373 | if (strcmp(attr[2], "interface") == 0) |
| 374 | hw_interface = (char *)attr[3]; |
| 375 | } else { |
| 376 | backend = (char *)attr[3]; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 379 | if (attr[4] != NULL) { |
| 380 | if (strcmp(attr[4], "interface") != 0) { |
| 381 | hw_interface = NULL; |
| 382 | } else { |
| 383 | hw_interface = (char *)attr[5]; |
| 384 | } |
| 385 | } |
| 386 | |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 387 | if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 388 | ALOGE("%s: Device %s backend %s was not set!", |
| 389 | __func__, attr[1], attr[3]); |
| 390 | goto done; |
| 391 | } |
| 392 | |
| 393 | done: |
| 394 | return; |
| 395 | } |
| 396 | |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 397 | static void process_gain_db_to_level_map(const XML_Char **attr) |
| 398 | { |
| 399 | struct amp_db_and_gain_table tbl_entry; |
| 400 | |
| 401 | if ((strcmp(attr[0], "db") != 0) || |
| 402 | (strcmp(attr[2], "level") != 0)) { |
| 403 | ALOGE("%s: invalid attribute passed %s %sexpected amp db level", |
| 404 | __func__, attr[0], attr[2]); |
| 405 | goto done; |
| 406 | } |
| 407 | |
| 408 | tbl_entry.db = atof(attr[1]); |
| 409 | tbl_entry.amp = exp(tbl_entry.db * 0.115129f); |
| 410 | tbl_entry.level = atoi(attr[3]); |
| 411 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 412 | //custome level should be > 0. Level 0 is fixed for default |
| 413 | CHECK(tbl_entry.level > 0); |
| 414 | |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 415 | ALOGV("%s: amp [%f] db [%f] level [%d]", __func__, |
| 416 | tbl_entry.amp, tbl_entry.db, tbl_entry.level); |
| 417 | platform_add_gain_level_mapping(&tbl_entry); |
| 418 | |
| 419 | done: |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 424 | static void process_acdb_id(const XML_Char **attr) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 425 | { |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 426 | int index; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 427 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 428 | if (strcmp(attr[0], "name") != 0) { |
| 429 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 430 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 431 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 432 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 433 | index = platform_get_snd_device_index((char *)attr[1]); |
| 434 | if (index < 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 435 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 436 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 437 | goto done; |
| 438 | } |
| 439 | |
| 440 | if (strcmp(attr[2], "acdb_id") != 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 441 | ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!", |
| 442 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 443 | goto done; |
| 444 | } |
| 445 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 446 | if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) { |
| 447 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 448 | __func__, attr[1], atoi((char *)attr[3])); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 449 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 450 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 451 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 452 | done: |
| 453 | return; |
| 454 | } |
| 455 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 456 | static void process_operator_specific(const XML_Char **attr) |
| 457 | { |
| 458 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 459 | |
| 460 | if (strcmp(attr[0], "name") != 0) { |
| 461 | ALOGE("%s: 'name' not found", __func__); |
| 462 | goto done; |
| 463 | } |
| 464 | |
| 465 | snd_device = platform_get_snd_device_index((char *)attr[1]); |
| 466 | if (snd_device < 0) { |
| 467 | ALOGE("%s: Device %s in %s not found, no ACDB ID set!", |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 468 | __func__, (char *)attr[3], get_platform_xml_path()); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 469 | goto done; |
| 470 | } |
| 471 | |
| 472 | if (strcmp(attr[2], "operator") != 0) { |
| 473 | ALOGE("%s: 'operator' not found", __func__); |
| 474 | goto done; |
| 475 | } |
| 476 | |
| 477 | if (strcmp(attr[4], "mixer_path") != 0) { |
| 478 | ALOGE("%s: 'mixer_path' not found", __func__); |
| 479 | goto done; |
| 480 | } |
| 481 | |
| 482 | if (strcmp(attr[6], "acdb_id") != 0) { |
| 483 | ALOGE("%s: 'acdb_id' not found", __func__); |
| 484 | goto done; |
| 485 | } |
| 486 | |
| 487 | platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7])); |
| 488 | |
| 489 | done: |
| 490 | return; |
| 491 | } |
| 492 | |
Carter Hsu | 32a6236 | 2018-10-15 15:01:42 -0700 | [diff] [blame] | 493 | static void process_external_dev(const XML_Char **attr) |
| 494 | { |
| 495 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 496 | |
| 497 | if (strcmp(attr[0], "name") != 0) { |
| 498 | ALOGE("%s: 'name' not found", __func__); |
| 499 | goto done; |
| 500 | } |
| 501 | |
| 502 | snd_device = platform_get_snd_device_index((char *)attr[1]); |
| 503 | if (snd_device < 0) { |
| 504 | ALOGE("%s: Device %s in %s not found, no ACDB ID set!", |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 505 | __func__, (char *)attr[3], get_platform_xml_path()); |
Carter Hsu | 32a6236 | 2018-10-15 15:01:42 -0700 | [diff] [blame] | 506 | goto done; |
| 507 | } |
| 508 | |
| 509 | if (strcmp(attr[2], "usbid") != 0) { |
| 510 | ALOGE("%s: 'usbid' not found", __func__); |
| 511 | goto done; |
| 512 | } |
| 513 | |
| 514 | if (strcmp(attr[4], "acdb_id") != 0) { |
| 515 | ALOGE("%s: 'acdb_id' not found", __func__); |
| 516 | goto done; |
| 517 | } |
| 518 | |
| 519 | platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5])); |
| 520 | |
| 521 | done: |
| 522 | return; |
| 523 | } |
| 524 | |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 525 | static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type) |
| 526 | { |
| 527 | int index; |
| 528 | struct audio_effect_config effect_config; |
| 529 | |
| 530 | if (strcmp(attr[0], "name") != 0) { |
| 531 | ALOGE("%s: 'name' not found, no MODULE ID set!", __func__); |
| 532 | goto done; |
| 533 | } |
| 534 | |
| 535 | index = platform_get_snd_device_index((char *)attr[1]); |
| 536 | if (index < 0) { |
| 537 | ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!", |
| 538 | __func__, attr[1]); |
| 539 | goto done; |
| 540 | } |
| 541 | |
| 542 | if (strcmp(attr[2], "module_id") != 0) { |
| 543 | ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!", |
| 544 | __func__, attr[2]); |
| 545 | goto done; |
| 546 | } |
| 547 | |
| 548 | if (strcmp(attr[4], "instance_id") != 0) { |
| 549 | ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!", |
| 550 | __func__, attr[4]); |
| 551 | goto done; |
| 552 | } |
| 553 | |
| 554 | if (strcmp(attr[6], "param_id") != 0) { |
| 555 | ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!", |
| 556 | __func__, attr[6]); |
| 557 | goto done; |
| 558 | } |
| 559 | |
| 560 | if (strcmp(attr[8], "param_value") != 0) { |
| 561 | ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!", |
| 562 | __func__, attr[8]); |
| 563 | goto done; |
| 564 | } |
| 565 | |
| 566 | effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0), |
| 567 | strtol((char *)attr[5], NULL, 0), |
| 568 | strtol((char *)attr[7], NULL, 0), |
| 569 | strtol((char *)attr[9], NULL, 0)}; |
| 570 | |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 571 | if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) { |
| 572 | ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!", |
| 573 | __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0), |
| 574 | strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0), |
| 575 | strtol((char *)attr[9], NULL, 0)); |
| 576 | goto done; |
| 577 | } |
| 578 | |
| 579 | done: |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | static void process_effect_aec(const XML_Char **attr) |
| 584 | { |
| 585 | process_audio_effect(attr, EFFECT_AEC); |
| 586 | return; |
| 587 | } |
| 588 | |
| 589 | static void process_effect_ns(const XML_Char **attr) |
| 590 | { |
| 591 | process_audio_effect(attr, EFFECT_NS); |
| 592 | return; |
| 593 | } |
| 594 | |
Guodong Hu | 1d46f34 | 2019-06-28 16:57:30 +0800 | [diff] [blame] | 595 | static void process_fluence_mmsecns(const XML_Char **attr) |
| 596 | { |
| 597 | int index; |
| 598 | struct audio_fluence_mmsecns_config fluence_mmsecns_config; |
| 599 | |
| 600 | if (strcmp(attr[0], "name") != 0) { |
| 601 | ALOGE("%s: 'name' not found, no MODULE ID set!", __func__); |
| 602 | goto done; |
| 603 | } |
| 604 | |
| 605 | index = platform_get_snd_device_index((char *)attr[1]); |
| 606 | if (index < 0) { |
| 607 | ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!", |
| 608 | __func__, attr[1]); |
| 609 | goto done; |
| 610 | } |
| 611 | |
| 612 | if (strcmp(attr[2], "topology_id") != 0) { |
| 613 | ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!", |
| 614 | __func__, attr[2]); |
| 615 | goto done; |
| 616 | } |
| 617 | |
| 618 | if (strcmp(attr[4], "module_id") != 0) { |
| 619 | ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!", |
| 620 | __func__, attr[4]); |
| 621 | goto done; |
| 622 | } |
| 623 | |
| 624 | if (strcmp(attr[6], "instance_id") != 0) { |
| 625 | ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!", |
| 626 | __func__, attr[6]); |
| 627 | goto done; |
| 628 | } |
| 629 | |
| 630 | if (strcmp(attr[8], "param_id") != 0) { |
| 631 | ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!", |
| 632 | __func__, attr[8]); |
| 633 | goto done; |
| 634 | } |
| 635 | |
| 636 | fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0), |
| 637 | strtol((char *)attr[5], NULL, 0), |
| 638 | strtol((char *)attr[7], NULL, 0), |
| 639 | strtol((char *)attr[9], NULL, 0)}; |
| 640 | |
| 641 | |
| 642 | if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) { |
| 643 | ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!", |
| 644 | __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0), |
| 645 | strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0)); |
| 646 | goto done; |
| 647 | } |
| 648 | |
| 649 | done: |
| 650 | return; |
| 651 | } |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 652 | static void process_bit_width(const XML_Char **attr) |
| 653 | { |
| 654 | int index; |
| 655 | |
| 656 | if (strcmp(attr[0], "name") != 0) { |
| 657 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 658 | goto done; |
| 659 | } |
| 660 | |
| 661 | index = platform_get_snd_device_index((char *)attr[1]); |
| 662 | if (index < 0) { |
| 663 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 664 | __func__, attr[1]); |
| 665 | goto done; |
| 666 | } |
| 667 | |
| 668 | if (strcmp(attr[2], "bit_width") != 0) { |
| 669 | ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!", |
| 670 | __func__, attr[1]); |
| 671 | goto done; |
| 672 | } |
| 673 | |
| 674 | if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) { |
| 675 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
| 676 | __func__, attr[1], atoi((char *)attr[3])); |
| 677 | goto done; |
| 678 | } |
| 679 | |
| 680 | done: |
| 681 | return; |
| 682 | } |
| 683 | |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 684 | static void process_interface_name(const XML_Char **attr) |
| 685 | { |
| 686 | int ret; |
| 687 | |
| 688 | if (strcmp(attr[0], "name") != 0) { |
| 689 | ALOGE("%s: 'name' not found, no Audio Interface set!", __func__); |
| 690 | |
| 691 | goto done; |
| 692 | } |
| 693 | |
| 694 | if (strcmp(attr[2], "interface") != 0) { |
| 695 | ALOGE("%s: Device %s has no Audio Interface set!", |
| 696 | __func__, attr[1]); |
| 697 | |
| 698 | goto done; |
| 699 | } |
| 700 | |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 701 | if (strcmp(attr[4], "codec_type") != 0) { |
| 702 | ALOGE("%s: Device %s has no codec type set!", |
| 703 | __func__, attr[1]); |
| 704 | |
| 705 | goto done; |
| 706 | } |
| 707 | |
| 708 | ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3], |
| 709 | (char *)attr[5]); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 710 | if (ret < 0) { |
| 711 | ALOGE("%s: Audio Interface not set!", __func__); |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 712 | goto done; |
| 713 | } |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 714 | |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 715 | done: |
| 716 | return; |
| 717 | } |
Laxminath Kasam | 44f4940 | 2015-05-29 18:37:11 +0530 | [diff] [blame] | 718 | |
Juyu Chen | 918e1e1 | 2019-08-08 15:28:18 -0700 | [diff] [blame] | 719 | static void process_audio_source_delay(const XML_Char **attr) |
| 720 | { |
| 721 | audio_source_t audio_source = -1; |
| 722 | |
| 723 | if (strcmp(attr[0], "name") != 0) { |
| 724 | ALOGE("%s: 'name' not found", __func__); |
| 725 | goto done; |
| 726 | } |
George Gao | 9ba8a14 | 2020-07-23 14:30:03 -0700 | [diff] [blame] | 727 | |
Juyu Chen | 918e1e1 | 2019-08-08 15:28:18 -0700 | [diff] [blame] | 728 | audio_source = platform_get_audio_source_index((const char *)attr[1]); |
| 729 | |
| 730 | if (audio_source < 0) { |
| 731 | ALOGE("%s: audio_source %s is not defined", |
| 732 | __func__, (char *)attr[1]); |
| 733 | goto done; |
| 734 | } |
| 735 | |
| 736 | if (strcmp(attr[2], "delay") != 0) { |
| 737 | ALOGE("%s: 'delay' not found", __func__); |
| 738 | goto done; |
| 739 | } |
| 740 | |
| 741 | platform_set_audio_source_delay(audio_source, atoi((char *)attr[3])); |
| 742 | |
| 743 | done: |
| 744 | return; |
| 745 | } |
| 746 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 747 | static void process_config_params(const XML_Char **attr) |
| 748 | { |
| 749 | if (strcmp(attr[0], "key") != 0) { |
| 750 | ALOGE("%s: 'key' not found", __func__); |
| 751 | goto done; |
| 752 | } |
| 753 | |
| 754 | if (strcmp(attr[2], "value") != 0) { |
| 755 | ALOGE("%s: 'value' not found", __func__); |
| 756 | goto done; |
| 757 | } |
| 758 | |
| 759 | str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]); |
Aniket Kumar Lata | d64bfbd | 2019-07-09 12:01:16 -0700 | [diff] [blame] | 760 | if (my_data.caller == PLATFORM) |
| 761 | platform_set_parameters(my_data.platform, my_data.kvpairs); |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 762 | done: |
| 763 | return; |
| 764 | } |
| 765 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 766 | static void process_app_type(const XML_Char **attr) |
| 767 | { |
| 768 | if (strcmp(attr[0], "uc_type")) { |
| 769 | ALOGE("%s: uc_type not found", __func__); |
| 770 | goto done; |
| 771 | } |
| 772 | |
| 773 | if (strcmp(attr[2], "mode")) { |
| 774 | ALOGE("%s: mode not found", __func__); |
| 775 | goto done; |
| 776 | } |
| 777 | |
| 778 | if (strcmp(attr[4], "bit_width")) { |
| 779 | ALOGE("%s: bit_width not found", __func__); |
| 780 | goto done; |
| 781 | } |
| 782 | |
| 783 | if (strcmp(attr[6], "id")) { |
| 784 | ALOGE("%s: id not found", __func__); |
| 785 | goto done; |
| 786 | } |
| 787 | |
| 788 | if (strcmp(attr[8], "max_rate")) { |
| 789 | ALOGE("%s: max rate not found", __func__); |
| 790 | goto done; |
| 791 | } |
| 792 | |
| 793 | platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]), |
| 794 | atoi(attr[9])); |
| 795 | done: |
| 796 | return; |
| 797 | } |
| 798 | |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 799 | static void process_microphone_characteristic(const XML_Char **attr) { |
| 800 | struct audio_microphone_characteristic_t microphone; |
| 801 | uint32_t curIdx = 0; |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 802 | char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH]; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 803 | |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 804 | strlcpy(platform_info_xml_path, get_platform_xml_path(), |
| 805 | sizeof(platform_info_xml_path)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 806 | if (strcmp(attr[curIdx++], "valid_mask")) { |
| 807 | ALOGE("%s: valid_mask not found", __func__); |
| 808 | goto done; |
| 809 | } |
| 810 | uint32_t valid_mask = atoi(attr[curIdx++]); |
| 811 | |
| 812 | if (strcmp(attr[curIdx++], "device_id")) { |
| 813 | ALOGE("%s: device_id not found", __func__); |
| 814 | goto done; |
| 815 | } |
| 816 | if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) { |
| 817 | ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]); |
| 818 | goto done; |
| 819 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 820 | strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 821 | |
| 822 | if (strcmp(attr[curIdx++], "type")) { |
| 823 | ALOGE("%s: device not found", __func__); |
| 824 | goto done; |
| 825 | } |
| 826 | if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++], |
| 827 | ARRAY_SIZE(device_in_types), µphone.device)) { |
| 828 | ALOGE("%s: type %s in %s not found!", |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 829 | __func__, attr[--curIdx], platform_info_xml_path); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 830 | goto done; |
| 831 | } |
| 832 | |
| 833 | if (strcmp(attr[curIdx++], "address")) { |
| 834 | ALOGE("%s: address not found", __func__); |
| 835 | goto done; |
| 836 | } |
| 837 | if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) { |
| 838 | ALOGE("%s, address %s is too long", __func__, attr[curIdx]); |
| 839 | goto done; |
| 840 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 841 | strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 842 | if (strlen(microphone.address) == 0) { |
| 843 | // If the address is empty, populate the address according to device type. |
| 844 | if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 845 | strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 846 | } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) { |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 847 | strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | |
| 851 | if (strcmp(attr[curIdx++], "location")) { |
| 852 | ALOGE("%s: location not found", __func__); |
| 853 | goto done; |
| 854 | } |
| 855 | if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++], |
| 856 | AUDIO_MICROPHONE_LOCATION_CNT, µphone.location)) { |
| 857 | ALOGE("%s: location %s in %s not found!", |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 858 | __func__, attr[--curIdx], platform_info_xml_path); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 859 | goto done; |
| 860 | } |
| 861 | |
| 862 | if (strcmp(attr[curIdx++], "group")) { |
| 863 | ALOGE("%s: group not found", __func__); |
| 864 | goto done; |
| 865 | } |
| 866 | microphone.group = atoi(attr[curIdx++]); |
| 867 | |
| 868 | if (strcmp(attr[curIdx++], "index_in_the_group")) { |
| 869 | ALOGE("%s: index_in_the_group not found", __func__); |
| 870 | goto done; |
| 871 | } |
| 872 | microphone.index_in_the_group = atoi(attr[curIdx++]); |
| 873 | |
| 874 | if (strcmp(attr[curIdx++], "directionality")) { |
| 875 | ALOGE("%s: directionality not found", __func__); |
| 876 | goto done; |
| 877 | } |
| 878 | if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++], |
| 879 | AUDIO_MICROPHONE_DIRECTIONALITY_CNT, µphone.directionality)) { |
| 880 | ALOGE("%s: directionality %s in %s not found!", |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 881 | __func__, attr[--curIdx], platform_info_xml_path); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 882 | goto done; |
| 883 | } |
| 884 | |
| 885 | if (strcmp(attr[curIdx++], "num_frequency_responses")) { |
| 886 | ALOGE("%s: num_frequency_responses not found", __func__); |
| 887 | goto done; |
| 888 | } |
| 889 | microphone.num_frequency_responses = atoi(attr[curIdx++]); |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 890 | if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) { |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 891 | ALOGE("%s: num_frequency_responses is too large", __func__); |
| 892 | goto done; |
| 893 | } |
| 894 | if (microphone.num_frequency_responses > 0) { |
| 895 | if (strcmp(attr[curIdx++], "frequencies")) { |
| 896 | ALOGE("%s: frequencies not found", __func__); |
| 897 | goto done; |
| 898 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 899 | char *context = NULL; |
| 900 | char *token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 901 | uint32_t num_frequencies = 0; |
| 902 | while (token) { |
| 903 | microphone.frequency_responses[0][num_frequencies++] = atof(token); |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 904 | if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) { |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 905 | break; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 906 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 907 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | if (strcmp(attr[curIdx++], "responses")) { |
| 911 | ALOGE("%s: responses not found", __func__); |
| 912 | goto done; |
| 913 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 914 | token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 915 | uint32_t num_responses = 0; |
| 916 | while (token) { |
| 917 | microphone.frequency_responses[1][num_responses++] = atof(token); |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 918 | if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) { |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 919 | break; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 920 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 921 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | if (num_frequencies != num_responses |
| 925 | || num_frequencies != microphone.num_frequency_responses) { |
| 926 | ALOGE("%s: num of frequency and response not match: %u, %u, %u", |
| 927 | __func__, num_frequencies, num_responses, microphone.num_frequency_responses); |
| 928 | goto done; |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) { |
| 933 | if (strcmp(attr[curIdx++], "sensitivity")) { |
| 934 | ALOGE("%s: sensitivity not found", __func__); |
| 935 | goto done; |
| 936 | } |
| 937 | microphone.sensitivity = atof(attr[curIdx++]); |
| 938 | } else { |
| 939 | microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN; |
| 940 | } |
| 941 | |
| 942 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) { |
| 943 | if (strcmp(attr[curIdx++], "max_spl")) { |
| 944 | ALOGE("%s: max_spl not found", __func__); |
| 945 | goto done; |
| 946 | } |
| 947 | microphone.max_spl = atof(attr[curIdx++]); |
| 948 | } else { |
| 949 | microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN; |
| 950 | } |
| 951 | |
| 952 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) { |
| 953 | if (strcmp(attr[curIdx++], "min_spl")) { |
| 954 | ALOGE("%s: min_spl not found", __func__); |
| 955 | goto done; |
| 956 | } |
| 957 | microphone.min_spl = atof(attr[curIdx++]); |
| 958 | } else { |
| 959 | microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN; |
| 960 | } |
| 961 | |
| 962 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) { |
| 963 | if (strcmp(attr[curIdx++], "orientation")) { |
| 964 | ALOGE("%s: orientation not found", __func__); |
| 965 | goto done; |
| 966 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 967 | char *context = NULL; |
| 968 | char *token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 969 | float orientation[3]; |
| 970 | uint32_t idx = 0; |
| 971 | while (token) { |
| 972 | orientation[idx++] = atof(token); |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 973 | if (idx >= 3) { |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 974 | break; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 975 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 976 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 977 | } |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 978 | if (idx != 3) { |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 979 | ALOGE("%s: orientation invalid", __func__); |
| 980 | goto done; |
| 981 | } |
| 982 | microphone.orientation.x = orientation[0]; |
| 983 | microphone.orientation.y = orientation[1]; |
| 984 | microphone.orientation.z = orientation[2]; |
| 985 | } else { |
| 986 | microphone.orientation.x = 0.0f; |
| 987 | microphone.orientation.y = 0.0f; |
| 988 | microphone.orientation.z = 0.0f; |
| 989 | } |
| 990 | |
| 991 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) { |
| 992 | if (strcmp(attr[curIdx++], "geometric_location")) { |
| 993 | ALOGE("%s: geometric_location not found", __func__); |
| 994 | goto done; |
| 995 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 996 | char *context = NULL; |
| 997 | char *token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 998 | float geometric_location[3]; |
| 999 | uint32_t idx = 0; |
| 1000 | while (token) { |
| 1001 | geometric_location[idx++] = atof(token); |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 1002 | if (idx >= 3) { |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 1003 | break; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1004 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 1005 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1006 | } |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 1007 | if (idx != 3) { |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1008 | ALOGE("%s: geometric_location invalid", __func__); |
| 1009 | goto done; |
| 1010 | } |
| 1011 | microphone.geometric_location.x = geometric_location[0]; |
| 1012 | microphone.geometric_location.y = geometric_location[1]; |
| 1013 | microphone.geometric_location.z = geometric_location[2]; |
| 1014 | } else { |
| 1015 | microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; |
| 1016 | microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; |
| 1017 | microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; |
| 1018 | } |
| 1019 | |
| 1020 | platform_set_microphone_characteristic(my_data.platform, microphone); |
| 1021 | done: |
| 1022 | return; |
| 1023 | } |
| 1024 | |
| 1025 | static void process_snd_dev(const XML_Char **attr) |
| 1026 | { |
| 1027 | uint32_t curIdx = 0; |
| 1028 | in_snd_device = SND_DEVICE_NONE; |
| 1029 | |
| 1030 | if (strcmp(attr[curIdx++], "in_snd_device")) { |
| 1031 | ALOGE("%s: snd_device not found", __func__); |
| 1032 | return; |
| 1033 | } |
| 1034 | in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]); |
| 1035 | if (in_snd_device < SND_DEVICE_IN_BEGIN || |
| 1036 | in_snd_device >= SND_DEVICE_IN_END) { |
| 1037 | ALOGE("%s: Sound device not valid", __func__); |
| 1038 | in_snd_device = SND_DEVICE_NONE; |
| 1039 | } |
| 1040 | |
| 1041 | return; |
| 1042 | } |
| 1043 | |
| 1044 | static void process_mic_info(const XML_Char **attr) |
| 1045 | { |
| 1046 | uint32_t curIdx = 0; |
| 1047 | struct mic_info microphone; |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 1048 | char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH]; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1049 | |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 1050 | strlcpy(platform_info_xml_path, get_platform_xml_path(), |
| 1051 | sizeof(platform_info_xml_path)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1052 | memset(µphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED, |
| 1053 | sizeof(microphone.channel_mapping)); |
| 1054 | |
| 1055 | if (strcmp(attr[curIdx++], "mic_device_id")) { |
| 1056 | ALOGE("%s: mic_device_id not found", __func__); |
| 1057 | goto on_error; |
| 1058 | } |
| 1059 | strlcpy(microphone.device_id, |
| 1060 | (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN); |
| 1061 | |
| 1062 | if (strcmp(attr[curIdx++], "channel_mapping")) { |
| 1063 | ALOGE("%s: channel_mapping not found", __func__); |
| 1064 | goto on_error; |
| 1065 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 1066 | char *context = NULL; |
| 1067 | const char *token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1068 | uint32_t idx = 0; |
| 1069 | while (token) { |
| 1070 | if (!find_enum_by_string(mic_channel_mapping, token, |
| 1071 | AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT, |
| 1072 | µphone.channel_mapping[idx++])) { |
| 1073 | ALOGE("%s: channel_mapping %s in %s not found!", |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 1074 | __func__, attr[--curIdx], platform_info_xml_path); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1075 | goto on_error; |
| 1076 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 1077 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1078 | } |
| 1079 | microphone.channel_count = idx; |
| 1080 | |
| 1081 | platform_set_microphone_map(my_data.platform, in_snd_device, |
| 1082 | µphone); |
| 1083 | return; |
| 1084 | on_error: |
| 1085 | in_snd_device = SND_DEVICE_NONE; |
| 1086 | return; |
| 1087 | } |
| 1088 | |
| 1089 | |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 1090 | /* process acdb meta info key value */ |
| 1091 | static void process_acdb_metainfo_key(const XML_Char **attr) |
| 1092 | { |
| 1093 | if (strcmp(attr[0], "name") != 0) { |
| 1094 | ALOGE("%s: 'name' not found", __func__); |
| 1095 | goto done; |
| 1096 | } |
| 1097 | |
| 1098 | if (strcmp(attr[2], "value") != 0) { |
| 1099 | ALOGE("%s: 'value' not found", __func__); |
| 1100 | goto done; |
| 1101 | } |
| 1102 | |
| 1103 | int key = atoi((char *)attr[3]); |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1104 | switch(my_data.caller) { |
| 1105 | case ACDB_EXTN: |
| 1106 | if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) { |
| 1107 | ALOGE("%s: key %d was not set!", __func__, key); |
| 1108 | goto done; |
| 1109 | } |
| 1110 | break; |
| 1111 | case PLATFORM: |
| 1112 | if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) { |
| 1113 | ALOGE("%s: key %d was not set!", __func__, key); |
| 1114 | goto done; |
| 1115 | } |
| 1116 | break; |
| 1117 | default: |
| 1118 | ALOGE("%s: unknown caller!", __func__); |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | done: |
| 1122 | return; |
| 1123 | } |
| 1124 | |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 1125 | static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr) |
| 1126 | { |
| 1127 | uint32_t attr_idx = 0; |
| 1128 | int32_t in_ch_idx = -1; |
| 1129 | struct audio_custom_mtmx_in_params *mtmx_in_params = NULL; |
| 1130 | |
| 1131 | mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform, |
| 1132 | &mtmx_in_params_info); |
| 1133 | if (mtmx_in_params == NULL) { |
| 1134 | ALOGE("%s: mtmx in params with given param info, not found", __func__); |
| 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | if (strcmp(attr[attr_idx++], "in_channel_index") != 0) { |
| 1139 | ALOGE("%s: 'in_channel_index' not found", __func__); |
| 1140 | return; |
| 1141 | } |
| 1142 | |
| 1143 | in_ch_idx = atoi((char *)attr[attr_idx++]); |
| 1144 | if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) { |
| 1145 | ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx); |
| 1146 | return; |
| 1147 | } |
| 1148 | |
| 1149 | if (strcmp(attr[attr_idx++], "channel_count") != 0) { |
| 1150 | ALOGE("%s: 'channel_count' not found", __func__); |
| 1151 | return; |
| 1152 | } |
| 1153 | mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]); |
| 1154 | |
| 1155 | if (strcmp(attr[attr_idx++], "device") != 0) { |
| 1156 | ALOGE("%s: 'device' not found", __func__); |
| 1157 | return; |
| 1158 | } |
| 1159 | strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++], |
| 1160 | sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)); |
| 1161 | |
| 1162 | if (strcmp(attr[attr_idx++], "interface") != 0) { |
| 1163 | ALOGE("%s: 'interface' not found", __func__); |
| 1164 | return; |
| 1165 | } |
| 1166 | strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++], |
| 1167 | sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface)); |
| 1168 | |
| 1169 | if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device, |
| 1170 | ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), |
| 1171 | sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device))) |
| 1172 | mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count; |
| 1173 | else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device, |
| 1174 | ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK), |
| 1175 | sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device))) |
| 1176 | mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count; |
| 1177 | |
| 1178 | mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count; |
| 1179 | } |
| 1180 | |
| 1181 | static void process_custom_mtmx_in_params(const XML_Char **attr) |
| 1182 | { |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 1183 | int attr_idx = 0, i = 0; |
| 1184 | char *context = NULL, *value = NULL; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 1185 | |
| 1186 | if (strcmp(attr[attr_idx++], "usecase") != 0) { |
| 1187 | ALOGE("%s: 'usecase' not found", __func__); |
| 1188 | return; |
| 1189 | } |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 1190 | /* Check if multi usecases are supported for this custom mtrx params */ |
| 1191 | value = strtok_r((char *)attr[attr_idx++], ",", &context); |
| 1192 | while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) { |
| 1193 | mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value); |
| 1194 | value = strtok_r(NULL, ",", &context); |
| 1195 | } |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 1196 | |
| 1197 | if (strcmp(attr[attr_idx++], "out_channel_count") != 0) { |
| 1198 | ALOGE("%s: 'out_channel_count' not found", __func__); |
| 1199 | return; |
| 1200 | } |
| 1201 | mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]); |
| 1202 | |
| 1203 | platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info); |
| 1204 | |
| 1205 | } |
| 1206 | |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1207 | static void process_custom_mtmx_param_coeffs(const XML_Char **attr) |
| 1208 | { |
| 1209 | uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0; |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 1210 | uint32_t ip_channels = 0, op_channels = 0, idx = 0; |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1211 | char *context = NULL, *ch_coeff_value = NULL; |
| 1212 | struct audio_custom_mtmx_params *mtmx_params = NULL; |
| 1213 | |
| 1214 | if (strcmp(attr[attr_idx++], "out_channel_index") != 0) { |
| 1215 | ALOGE("%s: 'out_channel_index' not found", __func__); |
| 1216 | return; |
| 1217 | } |
| 1218 | out_ch_idx = atoi((char *)attr[attr_idx++]); |
| 1219 | |
| 1220 | if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) { |
| 1221 | ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx); |
| 1222 | return; |
| 1223 | } |
| 1224 | |
| 1225 | if (strcmp(attr[attr_idx++], "values") != 0) { |
| 1226 | ALOGE("%s: 'values' not found", __func__); |
| 1227 | return; |
| 1228 | } |
| 1229 | mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform, |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 1230 | &mtmx_params_info, &idx); |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1231 | if (mtmx_params == NULL) { |
| 1232 | ALOGE("%s: mtmx params with given param info, not found", __func__); |
| 1233 | return; |
| 1234 | } |
| 1235 | ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context); |
| 1236 | ip_channels = mtmx_params->info.ip_channels; |
| 1237 | op_channels = mtmx_params->info.op_channels; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 1238 | while(ch_coeff_value && ch_coeff_count < ip_channels) { |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1239 | mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++] |
| 1240 | = atoi(ch_coeff_value); |
| 1241 | ch_coeff_value = strtok_r(NULL, " ", &context); |
| 1242 | } |
| 1243 | if (ch_coeff_count != mtmx_params->info.ip_channels || |
| 1244 | ch_coeff_value != NULL) |
| 1245 | ALOGE("%s: invalid/malformed coefficient values", __func__); |
| 1246 | } |
| 1247 | |
| 1248 | static void process_custom_mtmx_params(const XML_Char **attr) |
| 1249 | { |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 1250 | int attr_idx = 0, i = 0; |
| 1251 | char *context = NULL, *value = NULL; |
| 1252 | |
| 1253 | memset(&mtmx_params_info, 0, sizeof(mtmx_params_info)); |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1254 | |
| 1255 | if (strcmp(attr[attr_idx++], "param_id") != 0) { |
| 1256 | ALOGE("%s: 'param_id' not found", __func__); |
| 1257 | return; |
| 1258 | } |
| 1259 | mtmx_params_info.id = atoi((char *)attr[attr_idx++]); |
| 1260 | |
| 1261 | if (strcmp(attr[attr_idx++], "in_channel_count") != 0) { |
| 1262 | ALOGE("%s: 'in_channel_count' not found", __func__); |
| 1263 | return; |
| 1264 | } |
| 1265 | mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]); |
| 1266 | |
| 1267 | if (strcmp(attr[attr_idx++], "out_channel_count") != 0) { |
| 1268 | ALOGE("%s: 'out_channel_count' not found", __func__); |
| 1269 | return; |
| 1270 | } |
| 1271 | mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]); |
| 1272 | |
| 1273 | if (strcmp(attr[attr_idx++], "usecase") != 0) { |
| 1274 | ALOGE("%s: 'usecase' not found", __func__); |
| 1275 | return; |
| 1276 | } |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 1277 | |
| 1278 | /* check if multi usecases are supported for this custom mtrx params */ |
| 1279 | value = strtok_r((char *)attr[attr_idx++], ",", &context); |
| 1280 | while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) { |
| 1281 | mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value); |
| 1282 | value = strtok_r(NULL, ",", &context); |
| 1283 | } |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1284 | |
| 1285 | if (strcmp(attr[attr_idx++], "snd_device") != 0) { |
| 1286 | ALOGE("%s: 'snd_device' not found", __func__); |
| 1287 | return; |
| 1288 | } |
| 1289 | mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]); |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 1290 | |
Chaithanya Krishna Bacharaju | 3e94c91 | 2019-05-27 11:25:44 +0530 | [diff] [blame] | 1291 | if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) { |
| 1292 | i = 0; |
| 1293 | value = strtok_r((char *)attr[attr_idx++], ",", &context); |
| 1294 | while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) { |
| 1295 | mtmx_params_info.fe_id[i++] = atoi(value); |
| 1296 | value = strtok_r(NULL, ",", &context); |
| 1297 | } |
| 1298 | |
| 1299 | attr_idx++; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 1300 | } |
| 1301 | |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1302 | platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info); |
| 1303 | |
| 1304 | } |
| 1305 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1306 | static void start_tag(void *userdata __unused, const XML_Char *tag_name, |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1307 | const XML_Char **attr) |
| 1308 | { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1309 | if (my_data.caller == ACDB_EXTN) { |
| 1310 | if(strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 1311 | section = ACDB_METAINFO_KEY; |
| 1312 | } else if (strcmp(tag_name, "param") == 0) { |
| 1313 | if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) { |
| 1314 | ALOGE("param tag only supported with CONFIG_PARAMS section"); |
| 1315 | return; |
| 1316 | } |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1317 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1318 | section_process_fn fn = section_table[section]; |
| 1319 | fn(attr); |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 1320 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1321 | } else if(my_data.caller == PLATFORM) { |
| 1322 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 1323 | section = BITWIDTH; |
| 1324 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
| 1325 | section = ACDB; |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 1326 | } else if (strcmp(tag_name, "module_ids") == 0) { |
| 1327 | section = MODULE; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1328 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 1329 | section = PCM_ID; |
| 1330 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 1331 | section = BACKEND_NAME; |
| 1332 | } else if (strcmp(tag_name, "config_params") == 0) { |
| 1333 | section = CONFIG_PARAMS; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1334 | } else if (strcmp(tag_name, "operator_specific") == 0) { |
| 1335 | section = OPERATOR_SPECIFIC; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1336 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 1337 | section = INTERFACE_NAME; |
| 1338 | } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) { |
| 1339 | section = GAIN_LEVEL_MAPPING; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1340 | } else if (strcmp(tag_name, "app_types") == 0) { |
| 1341 | section = APP_TYPE; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1342 | } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 1343 | section = ACDB_METAINFO_KEY; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1344 | } else if (strcmp(tag_name, "microphone_characteristics") == 0) { |
| 1345 | section = MICROPHONE_CHARACTERISTIC; |
| 1346 | } else if (strcmp(tag_name, "snd_devices") == 0) { |
| 1347 | section = SND_DEVICES; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1348 | } else if (strcmp(tag_name, "device") == 0) { |
Guodong Hu | 1d46f34 | 2019-06-28 16:57:30 +0800 | [diff] [blame] | 1349 | if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) && |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 1350 | (section != BACKEND_NAME) && (section != BITWIDTH) && |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1351 | (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1352 | ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names"); |
| 1353 | return; |
| 1354 | } |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 1355 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1356 | /* call into process function for the current section */ |
| 1357 | section_process_fn fn = section_table[section]; |
| 1358 | fn(attr); |
| 1359 | } else if (strcmp(tag_name, "gain_level_map") == 0) { |
| 1360 | if (section != GAIN_LEVEL_MAPPING) { |
| 1361 | ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section"); |
| 1362 | return; |
| 1363 | } |
| 1364 | |
| 1365 | section_process_fn fn = section_table[GAIN_LEVEL_MAPPING]; |
| 1366 | fn(attr); |
| 1367 | } else if (strcmp(tag_name, "usecase") == 0) { |
| 1368 | if (section != PCM_ID) { |
| 1369 | ALOGE("usecase tag only supported with PCM_ID section"); |
| 1370 | return; |
| 1371 | } |
| 1372 | |
| 1373 | section_process_fn fn = section_table[PCM_ID]; |
| 1374 | fn(attr); |
| 1375 | } else if (strcmp(tag_name, "param") == 0) { |
| 1376 | if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) { |
| 1377 | ALOGE("param tag only supported with CONFIG_PARAMS section"); |
| 1378 | return; |
| 1379 | } |
| 1380 | |
| 1381 | section_process_fn fn = section_table[section]; |
| 1382 | fn(attr); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1383 | } else if (strcmp(tag_name, "aec") == 0) { |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 1384 | if (section != MODULE) { |
| 1385 | ALOGE("aec tag only supported with MODULE section"); |
| 1386 | return; |
| 1387 | } |
| 1388 | section = AEC; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1389 | } else if (strcmp(tag_name, "ns") == 0) { |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 1390 | if (section != MODULE) { |
| 1391 | ALOGE("ns tag only supported with MODULE section"); |
| 1392 | return; |
| 1393 | } |
| 1394 | section = NS; |
Guodong Hu | 1d46f34 | 2019-06-28 16:57:30 +0800 | [diff] [blame] | 1395 | } else if (strcmp(tag_name, "mmsecns") == 0) { |
| 1396 | if (section != MODULE) { |
| 1397 | ALOGE("mmsecns tag only supported with MODULE section"); |
| 1398 | return; |
| 1399 | } |
| 1400 | section = MMSECNS; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1401 | } else if (strcmp(tag_name, "gain_level_map") == 0) { |
| 1402 | if (section != GAIN_LEVEL_MAPPING) { |
| 1403 | ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section"); |
| 1404 | return; |
| 1405 | } |
| 1406 | |
| 1407 | section_process_fn fn = section_table[GAIN_LEVEL_MAPPING]; |
| 1408 | fn(attr); |
| 1409 | } else if (!strcmp(tag_name, "app")) { |
| 1410 | if (section != APP_TYPE) { |
| 1411 | ALOGE("app tag only valid in section APP_TYPE"); |
| 1412 | return; |
| 1413 | } |
| 1414 | |
| 1415 | section_process_fn fn = section_table[APP_TYPE]; |
| 1416 | fn(attr); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1417 | } else if (strcmp(tag_name, "microphone") == 0) { |
| 1418 | if (section != MICROPHONE_CHARACTERISTIC) { |
| 1419 | ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section"); |
| 1420 | return; |
| 1421 | } |
| 1422 | section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC]; |
| 1423 | fn(attr); |
| 1424 | } else if (strcmp(tag_name, "input_snd_device") == 0) { |
| 1425 | if (section != SND_DEVICES) { |
| 1426 | ALOGE("input_snd_device tag only supported with SND_DEVICES section"); |
| 1427 | return; |
| 1428 | } |
| 1429 | section = INPUT_SND_DEVICE; |
| 1430 | } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) { |
| 1431 | if (section != INPUT_SND_DEVICE) { |
| 1432 | ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section"); |
| 1433 | return; |
| 1434 | } |
| 1435 | section = INPUT_SND_DEVICE_TO_MIC_MAPPING; |
| 1436 | } else if (strcmp(tag_name, "snd_dev") == 0) { |
| 1437 | if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) { |
| 1438 | ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section"); |
| 1439 | return; |
| 1440 | } |
| 1441 | section_process_fn fn = section_table[SND_DEV]; |
| 1442 | fn(attr); |
| 1443 | } else if (strcmp(tag_name, "mic_info") == 0) { |
| 1444 | if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) { |
| 1445 | ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section"); |
| 1446 | return; |
| 1447 | } |
| 1448 | if (in_snd_device == SND_DEVICE_NONE) { |
| 1449 | ALOGE("%s: Error in previous tags, do not process mic info", __func__); |
| 1450 | return; |
| 1451 | } |
| 1452 | section_process_fn fn = section_table[MIC_INFO]; |
| 1453 | fn(attr); |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1454 | } else if (strcmp(tag_name, "custom_mtmx_params") == 0) { |
| 1455 | if (section != ROOT) { |
| 1456 | ALOGE("custom_mtmx_params tag supported only in ROOT section"); |
| 1457 | return; |
| 1458 | } |
| 1459 | section = CUSTOM_MTMX_PARAMS; |
| 1460 | section_process_fn fn = section_table[section]; |
| 1461 | fn(attr); |
| 1462 | } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) { |
| 1463 | if (section != CUSTOM_MTMX_PARAMS) { |
| 1464 | ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section"); |
| 1465 | return; |
| 1466 | } |
| 1467 | section = CUSTOM_MTMX_PARAM_COEFFS; |
| 1468 | section_process_fn fn = section_table[section]; |
| 1469 | fn(attr); |
Carter Hsu | 32a6236 | 2018-10-15 15:01:42 -0700 | [diff] [blame] | 1470 | } else if (strcmp(tag_name, "external_specific_dev") == 0) { |
| 1471 | section = EXTERNAL_DEVICE_SPECIFIC; |
| 1472 | } else if (strcmp(tag_name, "ext_device") == 0) { |
| 1473 | section_process_fn fn = section_table[section]; |
| 1474 | fn(attr); |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 1475 | } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) { |
| 1476 | if (section != ROOT) { |
| 1477 | ALOGE("custom_mtmx_in_params tag supported only in ROOT section"); |
| 1478 | return; |
| 1479 | } |
| 1480 | section = CUSTOM_MTMX_IN_PARAMS; |
| 1481 | section_process_fn fn = section_table[section]; |
| 1482 | fn(attr); |
| 1483 | } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) { |
| 1484 | if (section != CUSTOM_MTMX_IN_PARAMS) { |
| 1485 | ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section"); |
| 1486 | return; |
| 1487 | } |
| 1488 | section = CUSTOM_MTMX_PARAM_IN_CH_INFO; |
Juyu Chen | 918e1e1 | 2019-08-08 15:28:18 -0700 | [diff] [blame] | 1489 | } else if (strcmp(tag_name, "audio_input_source_delay") == 0) { |
| 1490 | section = AUDIO_SOURCE_DELAY; |
| 1491 | } else if (strcmp(tag_name, "audio_source_delay") == 0) { |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 1492 | section_process_fn fn = section_table[section]; |
| 1493 | fn(attr); |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1494 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1495 | } else { |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1496 | if(strcmp(tag_name, "config_params") == 0) { |
| 1497 | section = CONFIG_PARAMS; |
| 1498 | } else if (strcmp(tag_name, "param") == 0) { |
| 1499 | if (section != CONFIG_PARAMS) { |
| 1500 | ALOGE("param tag only supported with CONFIG_PARAMS section"); |
| 1501 | return; |
| 1502 | } |
| 1503 | |
| 1504 | section_process_fn fn = section_table[section]; |
| 1505 | fn(attr); |
| 1506 | } |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1507 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1508 | return; |
| 1509 | } |
| 1510 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1511 | static void end_tag(void *userdata __unused, const XML_Char *tag_name) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1512 | { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 1513 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 1514 | section = ROOT; |
| 1515 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1516 | section = ROOT; |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 1517 | } else if (strcmp(tag_name, "module_ids") == 0) { |
| 1518 | section = ROOT; |
| 1519 | } else if (strcmp(tag_name, "aec") == 0) { |
| 1520 | section = MODULE; |
| 1521 | } else if (strcmp(tag_name, "ns") == 0) { |
| 1522 | section = MODULE; |
Guodong Hu | 1d46f34 | 2019-06-28 16:57:30 +0800 | [diff] [blame] | 1523 | } else if (strcmp(tag_name, "mmsecns") == 0) { |
| 1524 | section = MODULE; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1525 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 1526 | section = ROOT; |
| 1527 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 1528 | section = ROOT; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 1529 | } else if (strcmp(tag_name, "config_params") == 0) { |
| 1530 | section = ROOT; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1531 | } else if (strcmp(tag_name, "operator_specific") == 0) { |
| 1532 | section = ROOT; |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 1533 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 1534 | section = ROOT; |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 1535 | } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) { |
| 1536 | section = ROOT; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1537 | } else if (strcmp(tag_name, "app_types") == 0) { |
| 1538 | section = ROOT; |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 1539 | } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 1540 | section = ROOT; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1541 | } else if (strcmp(tag_name, "microphone_characteristics") == 0) { |
| 1542 | section = ROOT; |
| 1543 | } else if (strcmp(tag_name, "snd_devices") == 0) { |
| 1544 | section = ROOT; |
Carter Hsu | 32a6236 | 2018-10-15 15:01:42 -0700 | [diff] [blame] | 1545 | } else if (strcmp(tag_name, "external_specific_dev") == 0) { |
| 1546 | section = ROOT; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1547 | } else if (strcmp(tag_name, "input_snd_device") == 0) { |
| 1548 | section = SND_DEVICES; |
| 1549 | } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) { |
| 1550 | section = INPUT_SND_DEVICE; |
Dhananjay Kumar | 429eb45 | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1551 | } else if (strcmp(tag_name, "custom_mtmx_params") == 0) { |
| 1552 | section = ROOT; |
| 1553 | } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) { |
| 1554 | section = CUSTOM_MTMX_PARAMS; |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 1555 | } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) { |
| 1556 | section = ROOT; |
| 1557 | } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) { |
| 1558 | section = CUSTOM_MTMX_IN_PARAMS; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1559 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1560 | } |
| 1561 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1562 | int platform_info_init(const char *filename, void *platform, caller_t caller_type) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1563 | { |
| 1564 | XML_Parser parser; |
| 1565 | FILE *file; |
| 1566 | int ret = 0; |
| 1567 | int bytes_read; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1568 | void *buf; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1569 | char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0}; |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 1570 | char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH]; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1571 | |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 1572 | strlcpy(platform_info_xml_path, get_platform_xml_path(), |
| 1573 | sizeof(platform_info_xml_path)); |
Weiyin Jiang | 13bcdde | 2019-09-06 16:59:32 +0800 | [diff] [blame] | 1574 | pthread_mutex_lock(&parser_lock); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1575 | if (filename == NULL) |
Saurav Kumar | dba3caf | 2020-05-29 20:53:55 +0530 | [diff] [blame] | 1576 | strlcpy(platform_info_file_name, platform_info_xml_path, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1577 | MIXER_PATH_MAX_LENGTH); |
| 1578 | else |
| 1579 | strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH); |
| 1580 | |
| 1581 | ALOGV("%s: platform info file name is %s", __func__, |
| 1582 | platform_info_file_name); |
| 1583 | |
| 1584 | file = fopen(platform_info_file_name, "r"); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1585 | section = ROOT; |
| 1586 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1587 | if (!file) { |
| 1588 | ALOGD("%s: Failed to open %s, using defaults.", |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1589 | __func__, platform_info_file_name); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1590 | ret = -ENODEV; |
| 1591 | goto done; |
| 1592 | } |
| 1593 | |
| 1594 | parser = XML_ParserCreate(NULL); |
| 1595 | if (!parser) { |
| 1596 | ALOGE("%s: Failed to create XML parser!", __func__); |
| 1597 | ret = -ENODEV; |
| 1598 | goto err_close_file; |
| 1599 | } |
| 1600 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1601 | my_data.caller = caller_type; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 1602 | my_data.platform = platform; |
| 1603 | my_data.kvpairs = str_parms_create(); |
| 1604 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1605 | XML_SetElementHandler(parser, start_tag, end_tag); |
| 1606 | |
| 1607 | while (1) { |
| 1608 | buf = XML_GetBuffer(parser, BUF_SIZE); |
| 1609 | if (buf == NULL) { |
| 1610 | ALOGE("%s: XML_GetBuffer failed", __func__); |
| 1611 | ret = -ENOMEM; |
| 1612 | goto err_free_parser; |
| 1613 | } |
| 1614 | |
| 1615 | bytes_read = fread(buf, 1, BUF_SIZE, file); |
| 1616 | if (bytes_read < 0) { |
| 1617 | ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read); |
| 1618 | ret = bytes_read; |
| 1619 | goto err_free_parser; |
| 1620 | } |
| 1621 | |
| 1622 | if (XML_ParseBuffer(parser, bytes_read, |
| 1623 | bytes_read == 0) == XML_STATUS_ERROR) { |
| 1624 | ALOGE("%s: XML_ParseBuffer failed, for %s", |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1625 | __func__, platform_info_file_name); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1626 | ret = -EINVAL; |
| 1627 | goto err_free_parser; |
| 1628 | } |
| 1629 | |
| 1630 | if (bytes_read == 0) |
| 1631 | break; |
| 1632 | } |
| 1633 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1634 | err_free_parser: |
| 1635 | XML_ParserFree(parser); |
| 1636 | err_close_file: |
| 1637 | fclose(file); |
| 1638 | done: |
Weiyin Jiang | 13bcdde | 2019-09-06 16:59:32 +0800 | [diff] [blame] | 1639 | pthread_mutex_unlock(&parser_lock); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1640 | return ret; |
| 1641 | } |