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