Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1 | /* |
Dhananjay Kumar | 2a7f75b | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2019, 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> |
| 36 | #include <cutils/log.h> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 37 | #include <cutils/str_parms.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 38 | #include <audio_hw.h> |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 39 | #include "acdb.h" |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 40 | #include "platform_api.h" |
| 41 | #include <platform.h> |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 42 | #include <math.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 43 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 44 | #ifdef DYNAMIC_LOG_ENABLED |
| 45 | #include <log_xml_parser.h> |
| 46 | #define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO |
| 47 | #include <log_utils.h> |
| 48 | #endif |
| 49 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 50 | #define BUF_SIZE 1024 |
| 51 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 52 | typedef enum { |
| 53 | ROOT, |
| 54 | ACDB, |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 55 | MODULE, |
| 56 | AEC, |
| 57 | NS, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 58 | BITWIDTH, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 59 | PCM_ID, |
| 60 | BACKEND_NAME, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 61 | INTERFACE_NAME, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 62 | CONFIG_PARAMS, |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 63 | GAIN_LEVEL_MAPPING, |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 64 | ACDB_METAINFO_KEY, |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 65 | MICROPHONE_CHARACTERISTIC, |
| 66 | SND_DEVICES, |
| 67 | INPUT_SND_DEVICE, |
| 68 | INPUT_SND_DEVICE_TO_MIC_MAPPING, |
| 69 | SND_DEV, |
| 70 | MIC_INFO, |
Dhananjay Kumar | 2a7f75b | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 71 | CUSTOM_MTMX_PARAMS, |
| 72 | CUSTOM_MTMX_PARAM_COEFFS, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 73 | } section_t; |
| 74 | |
| 75 | typedef void (* section_process_fn)(const XML_Char **attr); |
| 76 | |
| 77 | static void process_acdb_id(const XML_Char **attr); |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 78 | static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type); |
| 79 | static void process_effect_aec(const XML_Char **attr); |
| 80 | static void process_effect_ns(const XML_Char **attr); |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 81 | static void process_bit_width(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 82 | static void process_pcm_id(const XML_Char **attr); |
| 83 | static void process_backend_name(const XML_Char **attr); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 84 | static void process_interface_name(const XML_Char **attr); |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 85 | static void process_config_params(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 86 | static void process_root(const XML_Char **attr); |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 87 | static void process_gain_db_to_level_map(const XML_Char **attr); |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 88 | static void process_acdb_metainfo_key(const XML_Char **attr); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 89 | static void process_microphone_characteristic(const XML_Char **attr); |
| 90 | static void process_snd_dev(const XML_Char **attr); |
| 91 | static void process_mic_info(const XML_Char **attr); |
Dhananjay Kumar | 2a7f75b | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 92 | static void process_custom_mtmx_params(const XML_Char **attr); |
| 93 | static void process_custom_mtmx_param_coeffs(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 94 | |
| 95 | static section_process_fn section_table[] = { |
| 96 | [ROOT] = process_root, |
| 97 | [ACDB] = process_acdb_id, |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 98 | [AEC] = process_effect_aec, |
| 99 | [NS] = process_effect_ns, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 100 | [BITWIDTH] = process_bit_width, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 101 | [PCM_ID] = process_pcm_id, |
| 102 | [BACKEND_NAME] = process_backend_name, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 103 | [INTERFACE_NAME] = process_interface_name, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 104 | [CONFIG_PARAMS] = process_config_params, |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 105 | [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map, |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 106 | [ACDB_METAINFO_KEY] = process_acdb_metainfo_key, |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 107 | [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic, |
| 108 | [SND_DEV] = process_snd_dev, |
| 109 | [MIC_INFO] = process_mic_info, |
Dhananjay Kumar | 2a7f75b | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 110 | [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params, |
| 111 | [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | static section_t section; |
| 115 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 116 | struct platform_info { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 117 | caller_t caller; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 118 | void *platform; |
| 119 | struct str_parms *kvpairs; |
| 120 | }; |
| 121 | |
| 122 | static struct platform_info my_data; |
| 123 | |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 124 | |
| 125 | struct audio_string_to_enum { |
| 126 | const char* name; |
| 127 | unsigned int value; |
| 128 | }; |
| 129 | |
| 130 | static snd_device_t in_snd_device; |
| 131 | |
| 132 | static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = { |
| 133 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN), |
| 134 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY), |
| 135 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE), |
| 136 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL), |
| 137 | }; |
| 138 | |
| 139 | static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = { |
| 140 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI), |
| 141 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL), |
| 142 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN), |
| 143 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID), |
| 144 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID), |
| 145 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID), |
| 146 | }; |
| 147 | |
| 148 | static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = { |
| 149 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED), |
| 150 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT), |
| 151 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED), |
| 152 | }; |
| 153 | |
| 154 | static const struct audio_string_to_enum device_in_types[] = { |
| 155 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT), |
| 156 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION), |
| 157 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC), |
| 158 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET), |
| 159 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET), |
| 160 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL), |
| 161 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI), |
| 162 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL), |
| 163 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX), |
| 164 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC), |
| 165 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX), |
| 166 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET), |
| 167 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET), |
| 168 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY), |
| 169 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE), |
| 170 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER), |
| 171 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER), |
| 172 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE), |
| 173 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF), |
| 174 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP), |
| 175 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK), |
| 176 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP), |
| 177 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS), |
| 178 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY), |
| 179 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET), |
| 180 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE), |
| 181 | AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT), |
| 182 | }; |
| 183 | |
| 184 | enum { |
| 185 | AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0 |
| 186 | AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1 |
| 187 | AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2 |
| 188 | AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4 |
| 189 | AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8 |
| 190 | AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10 |
| 191 | AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL) |
| 192 | | ORIENTATION) | GEOMETRIC_LOCATION) */ |
| 193 | }; |
| 194 | |
| 195 | static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name, |
| 196 | int32_t len, unsigned int *value) |
| 197 | { |
| 198 | if (table == NULL) { |
| 199 | ALOGE("%s: table is NULL", __func__); |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | if (name == NULL) { |
| 204 | ALOGE("null key"); |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | for (int i = 0; i < len; i++) { |
| 209 | if (!strcmp(table[i].name, name)) { |
| 210 | *value = table[i].value; |
| 211 | return true; |
| 212 | } |
| 213 | } |
| 214 | return false; |
| 215 | } |
Dhananjay Kumar | 2a7f75b | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 216 | |
| 217 | static struct audio_custom_mtmx_params_info mtmx_params_info; |
| 218 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 219 | /* |
| 220 | * <audio_platform_info> |
| 221 | * <acdb_ids> |
| 222 | * <device name="???" acdb_id="???"/> |
| 223 | * ... |
| 224 | * ... |
| 225 | * </acdb_ids> |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 226 | * <module_ids> |
| 227 | * <device name="???" module_id="???"/> |
| 228 | * ... |
| 229 | * ... |
| 230 | * </module_ids> |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 231 | * <backend_names> |
| 232 | * <device name="???" backend="???"/> |
| 233 | * ... |
| 234 | * ... |
| 235 | * </backend_names> |
| 236 | * <pcm_ids> |
| 237 | * <usecase name="???" type="in/out" id="???"/> |
| 238 | * ... |
| 239 | * ... |
| 240 | * </pcm_ids> |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 241 | * <interface_names> |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 242 | * <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] | 243 | * ... |
| 244 | * ... |
| 245 | * </interface_names> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 246 | * <config_params> |
| 247 | * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/> |
| 248 | * ... |
| 249 | * ... |
| 250 | * </config_params> |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 251 | * </audio_platform_info> |
| 252 | */ |
| 253 | |
| 254 | static void process_root(const XML_Char **attr __unused) |
| 255 | { |
| 256 | } |
| 257 | |
| 258 | /* mapping from usecase to pcm dev id */ |
| 259 | static void process_pcm_id(const XML_Char **attr) |
| 260 | { |
| 261 | int index; |
| 262 | |
| 263 | if (strcmp(attr[0], "name") != 0) { |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 264 | ALOGE("%s: 'name' not found, no pcm_id set!", __func__); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 265 | goto done; |
| 266 | } |
| 267 | |
| 268 | index = platform_get_usecase_index((char *)attr[1]); |
| 269 | if (index < 0) { |
| 270 | ALOGE("%s: usecase %s not found!", |
| 271 | __func__, attr[1]); |
| 272 | goto done; |
| 273 | } |
| 274 | |
| 275 | if (strcmp(attr[2], "type") != 0) { |
| 276 | ALOGE("%s: usecase type not mentioned", __func__); |
| 277 | goto done; |
| 278 | } |
| 279 | |
| 280 | int type = -1; |
| 281 | |
| 282 | if (!strcasecmp((char *)attr[3], "in")) { |
| 283 | type = 1; |
| 284 | } else if (!strcasecmp((char *)attr[3], "out")) { |
| 285 | type = 0; |
| 286 | } else { |
| 287 | ALOGE("%s: type must be IN or OUT", __func__); |
| 288 | goto done; |
| 289 | } |
| 290 | |
| 291 | if (strcmp(attr[4], "id") != 0) { |
| 292 | ALOGE("%s: usecase id not mentioned", __func__); |
| 293 | goto done; |
| 294 | } |
| 295 | |
| 296 | int id = atoi((char *)attr[5]); |
| 297 | |
| 298 | if (platform_set_usecase_pcm_id(index, type, id) < 0) { |
| 299 | ALOGE("%s: usecase %s type %d id %d was not set!", |
| 300 | __func__, attr[1], type, id); |
| 301 | goto done; |
| 302 | } |
| 303 | |
| 304 | done: |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | /* backend to be used for a device */ |
| 309 | static void process_backend_name(const XML_Char **attr) |
| 310 | { |
| 311 | int index; |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 312 | char *hw_interface = NULL; |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 313 | char *backend = NULL; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 314 | |
| 315 | if (strcmp(attr[0], "name") != 0) { |
| 316 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 317 | goto done; |
| 318 | } |
| 319 | |
| 320 | index = platform_get_snd_device_index((char *)attr[1]); |
| 321 | if (index < 0) { |
| 322 | ALOGE("%s: Device %s not found, no ACDB ID set!", |
| 323 | __func__, attr[1]); |
| 324 | goto done; |
| 325 | } |
| 326 | |
| 327 | if (strcmp(attr[2], "backend") != 0) { |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 328 | if (strcmp(attr[2], "interface") == 0) |
| 329 | hw_interface = (char *)attr[3]; |
| 330 | } else { |
| 331 | backend = (char *)attr[3]; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 334 | if (attr[4] != NULL) { |
| 335 | if (strcmp(attr[4], "interface") != 0) { |
| 336 | hw_interface = NULL; |
| 337 | } else { |
| 338 | hw_interface = (char *)attr[5]; |
| 339 | } |
| 340 | } |
| 341 | |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 342 | if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 343 | ALOGE("%s: Device %s backend %s was not set!", |
| 344 | __func__, attr[1], attr[3]); |
| 345 | goto done; |
| 346 | } |
| 347 | |
| 348 | done: |
| 349 | return; |
| 350 | } |
| 351 | |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 352 | static void process_gain_db_to_level_map(const XML_Char **attr) |
| 353 | { |
| 354 | struct amp_db_and_gain_table tbl_entry; |
| 355 | |
| 356 | if ((strcmp(attr[0], "db") != 0) || |
| 357 | (strcmp(attr[2], "level") != 0)) { |
| 358 | ALOGE("%s: invalid attribute passed %s %sexpected amp db level", |
| 359 | __func__, attr[0], attr[2]); |
| 360 | goto done; |
| 361 | } |
| 362 | |
| 363 | tbl_entry.db = atof(attr[1]); |
| 364 | tbl_entry.amp = exp(tbl_entry.db * 0.115129f); |
| 365 | tbl_entry.level = atoi(attr[3]); |
| 366 | |
| 367 | ALOGV("%s: amp [%f] db [%f] level [%d]", __func__, |
| 368 | tbl_entry.amp, tbl_entry.db, tbl_entry.level); |
| 369 | platform_add_gain_level_mapping(&tbl_entry); |
| 370 | |
| 371 | done: |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 376 | static void process_acdb_id(const XML_Char **attr) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 377 | { |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 378 | int index; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 379 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 380 | if (strcmp(attr[0], "name") != 0) { |
| 381 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 382 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 383 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 384 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 385 | index = platform_get_snd_device_index((char *)attr[1]); |
| 386 | if (index < 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 387 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 388 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 389 | goto done; |
| 390 | } |
| 391 | |
| 392 | if (strcmp(attr[2], "acdb_id") != 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 393 | ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!", |
| 394 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 395 | goto done; |
| 396 | } |
| 397 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 398 | if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) { |
| 399 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 400 | __func__, attr[1], atoi((char *)attr[3])); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 401 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 402 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 403 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 404 | done: |
| 405 | return; |
| 406 | } |
| 407 | |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 408 | static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type) |
| 409 | { |
| 410 | int index; |
| 411 | struct audio_effect_config effect_config; |
| 412 | |
| 413 | if (strcmp(attr[0], "name") != 0) { |
| 414 | ALOGE("%s: 'name' not found, no MODULE ID set!", __func__); |
| 415 | goto done; |
| 416 | } |
| 417 | |
| 418 | index = platform_get_snd_device_index((char *)attr[1]); |
| 419 | if (index < 0) { |
| 420 | ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!", |
| 421 | __func__, attr[1]); |
| 422 | goto done; |
| 423 | } |
| 424 | |
| 425 | if (strcmp(attr[2], "module_id") != 0) { |
| 426 | ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!", |
| 427 | __func__, attr[2]); |
| 428 | goto done; |
| 429 | } |
| 430 | |
| 431 | if (strcmp(attr[4], "instance_id") != 0) { |
| 432 | ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!", |
| 433 | __func__, attr[4]); |
| 434 | goto done; |
| 435 | } |
| 436 | |
| 437 | if (strcmp(attr[6], "param_id") != 0) { |
| 438 | ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!", |
| 439 | __func__, attr[6]); |
| 440 | goto done; |
| 441 | } |
| 442 | |
| 443 | if (strcmp(attr[8], "param_value") != 0) { |
| 444 | ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!", |
| 445 | __func__, attr[8]); |
| 446 | goto done; |
| 447 | } |
| 448 | |
| 449 | effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0), |
| 450 | strtol((char *)attr[5], NULL, 0), |
| 451 | strtol((char *)attr[7], NULL, 0), |
| 452 | strtol((char *)attr[9], NULL, 0)}; |
| 453 | |
| 454 | |
| 455 | if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) { |
| 456 | ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!", |
| 457 | __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0), |
| 458 | strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0), |
| 459 | strtol((char *)attr[9], NULL, 0)); |
| 460 | goto done; |
| 461 | } |
| 462 | |
| 463 | done: |
| 464 | return; |
| 465 | } |
| 466 | |
| 467 | static void process_effect_aec(const XML_Char **attr) |
| 468 | { |
| 469 | process_audio_effect(attr, EFFECT_AEC); |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | static void process_effect_ns(const XML_Char **attr) |
| 474 | { |
| 475 | process_audio_effect(attr, EFFECT_NS); |
| 476 | return; |
| 477 | } |
| 478 | |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 479 | static void process_bit_width(const XML_Char **attr) |
| 480 | { |
| 481 | int index; |
| 482 | |
| 483 | if (strcmp(attr[0], "name") != 0) { |
| 484 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 485 | goto done; |
| 486 | } |
| 487 | |
| 488 | index = platform_get_snd_device_index((char *)attr[1]); |
| 489 | if (index < 0) { |
| 490 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 491 | __func__, attr[1]); |
| 492 | goto done; |
| 493 | } |
| 494 | |
| 495 | if (strcmp(attr[2], "bit_width") != 0) { |
| 496 | ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!", |
| 497 | __func__, attr[1]); |
| 498 | goto done; |
| 499 | } |
| 500 | |
| 501 | if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) { |
| 502 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
| 503 | __func__, attr[1], atoi((char *)attr[3])); |
| 504 | goto done; |
| 505 | } |
| 506 | |
| 507 | done: |
| 508 | return; |
| 509 | } |
| 510 | |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 511 | static void process_interface_name(const XML_Char **attr) |
| 512 | { |
| 513 | int ret; |
| 514 | |
| 515 | if (strcmp(attr[0], "name") != 0) { |
| 516 | ALOGE("%s: 'name' not found, no Audio Interface set!", __func__); |
| 517 | |
| 518 | goto done; |
| 519 | } |
| 520 | |
| 521 | if (strcmp(attr[2], "interface") != 0) { |
| 522 | ALOGE("%s: Device %s has no Audio Interface set!", |
| 523 | __func__, attr[1]); |
| 524 | |
| 525 | goto done; |
| 526 | } |
| 527 | |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 528 | if (strcmp(attr[4], "codec_type") != 0) { |
| 529 | ALOGE("%s: Device %s has no codec type set!", |
| 530 | __func__, attr[1]); |
| 531 | |
| 532 | goto done; |
| 533 | } |
| 534 | |
| 535 | ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3], |
| 536 | (char *)attr[5]); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 537 | if (ret < 0) { |
| 538 | ALOGE("%s: Audio Interface not set!", __func__); |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 539 | goto done; |
| 540 | } |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 541 | |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 542 | done: |
| 543 | return; |
| 544 | } |
Laxminath Kasam | 44f4940 | 2015-05-29 18:37:11 +0530 | [diff] [blame] | 545 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 546 | static void process_config_params(const XML_Char **attr) |
| 547 | { |
| 548 | if (strcmp(attr[0], "key") != 0) { |
| 549 | ALOGE("%s: 'key' not found", __func__); |
| 550 | goto done; |
| 551 | } |
| 552 | |
| 553 | if (strcmp(attr[2], "value") != 0) { |
| 554 | ALOGE("%s: 'value' not found", __func__); |
| 555 | goto done; |
| 556 | } |
| 557 | |
| 558 | str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]); |
| 559 | done: |
| 560 | return; |
| 561 | } |
| 562 | |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 563 | static void process_microphone_characteristic(const XML_Char **attr) { |
| 564 | struct audio_microphone_characteristic_t microphone; |
| 565 | uint32_t curIdx = 0; |
| 566 | |
| 567 | if (strcmp(attr[curIdx++], "valid_mask")) { |
| 568 | ALOGE("%s: valid_mask not found", __func__); |
| 569 | goto done; |
| 570 | } |
| 571 | uint32_t valid_mask = atoi(attr[curIdx++]); |
| 572 | |
| 573 | if (strcmp(attr[curIdx++], "device_id")) { |
| 574 | ALOGE("%s: device_id not found", __func__); |
| 575 | goto done; |
| 576 | } |
| 577 | if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) { |
| 578 | ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]); |
| 579 | goto done; |
| 580 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 581 | strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 582 | |
| 583 | if (strcmp(attr[curIdx++], "type")) { |
| 584 | ALOGE("%s: device not found", __func__); |
| 585 | goto done; |
| 586 | } |
| 587 | if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++], |
| 588 | ARRAY_SIZE(device_in_types), µphone.device)) { |
| 589 | ALOGE("%s: type %s in %s not found!", |
| 590 | __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH); |
| 591 | goto done; |
| 592 | } |
| 593 | |
| 594 | if (strcmp(attr[curIdx++], "address")) { |
| 595 | ALOGE("%s: address not found", __func__); |
| 596 | goto done; |
| 597 | } |
| 598 | if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) { |
| 599 | ALOGE("%s, address %s is too long", __func__, attr[curIdx]); |
| 600 | goto done; |
| 601 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 602 | strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 603 | if (strlen(microphone.address) == 0) { |
| 604 | // If the address is empty, populate the address according to device type. |
| 605 | if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 606 | strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 607 | } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) { |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 608 | strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address)); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
| 612 | if (strcmp(attr[curIdx++], "location")) { |
| 613 | ALOGE("%s: location not found", __func__); |
| 614 | goto done; |
| 615 | } |
| 616 | if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++], |
| 617 | AUDIO_MICROPHONE_LOCATION_CNT, µphone.location)) { |
| 618 | ALOGE("%s: location %s in %s not found!", |
| 619 | __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH); |
| 620 | goto done; |
| 621 | } |
| 622 | |
| 623 | if (strcmp(attr[curIdx++], "group")) { |
| 624 | ALOGE("%s: group not found", __func__); |
| 625 | goto done; |
| 626 | } |
| 627 | microphone.group = atoi(attr[curIdx++]); |
| 628 | |
| 629 | if (strcmp(attr[curIdx++], "index_in_the_group")) { |
| 630 | ALOGE("%s: index_in_the_group not found", __func__); |
| 631 | goto done; |
| 632 | } |
| 633 | microphone.index_in_the_group = atoi(attr[curIdx++]); |
| 634 | |
| 635 | if (strcmp(attr[curIdx++], "directionality")) { |
| 636 | ALOGE("%s: directionality not found", __func__); |
| 637 | goto done; |
| 638 | } |
| 639 | if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++], |
| 640 | AUDIO_MICROPHONE_DIRECTIONALITY_CNT, µphone.directionality)) { |
| 641 | ALOGE("%s: directionality %s in %s not found!", |
| 642 | __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH); |
| 643 | goto done; |
| 644 | } |
| 645 | |
| 646 | if (strcmp(attr[curIdx++], "num_frequency_responses")) { |
| 647 | ALOGE("%s: num_frequency_responses not found", __func__); |
| 648 | goto done; |
| 649 | } |
| 650 | microphone.num_frequency_responses = atoi(attr[curIdx++]); |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 651 | if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) { |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 652 | ALOGE("%s: num_frequency_responses is too large", __func__); |
| 653 | goto done; |
| 654 | } |
| 655 | if (microphone.num_frequency_responses > 0) { |
| 656 | if (strcmp(attr[curIdx++], "frequencies")) { |
| 657 | ALOGE("%s: frequencies not found", __func__); |
| 658 | goto done; |
| 659 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 660 | char *context = NULL; |
| 661 | char *token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 662 | uint32_t num_frequencies = 0; |
| 663 | while (token) { |
| 664 | microphone.frequency_responses[0][num_frequencies++] = atof(token); |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 665 | if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) { |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 666 | break; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 667 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 668 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | if (strcmp(attr[curIdx++], "responses")) { |
| 672 | ALOGE("%s: responses not found", __func__); |
| 673 | goto done; |
| 674 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 675 | token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 676 | uint32_t num_responses = 0; |
| 677 | while (token) { |
| 678 | microphone.frequency_responses[1][num_responses++] = atof(token); |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 679 | if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) { |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 680 | break; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 681 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 682 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | if (num_frequencies != num_responses |
| 686 | || num_frequencies != microphone.num_frequency_responses) { |
| 687 | ALOGE("%s: num of frequency and response not match: %u, %u, %u", |
| 688 | __func__, num_frequencies, num_responses, microphone.num_frequency_responses); |
| 689 | goto done; |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) { |
| 694 | if (strcmp(attr[curIdx++], "sensitivity")) { |
| 695 | ALOGE("%s: sensitivity not found", __func__); |
| 696 | goto done; |
| 697 | } |
| 698 | microphone.sensitivity = atof(attr[curIdx++]); |
| 699 | } else { |
| 700 | microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN; |
| 701 | } |
| 702 | |
| 703 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) { |
| 704 | if (strcmp(attr[curIdx++], "max_spl")) { |
| 705 | ALOGE("%s: max_spl not found", __func__); |
| 706 | goto done; |
| 707 | } |
| 708 | microphone.max_spl = atof(attr[curIdx++]); |
| 709 | } else { |
| 710 | microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN; |
| 711 | } |
| 712 | |
| 713 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) { |
| 714 | if (strcmp(attr[curIdx++], "min_spl")) { |
| 715 | ALOGE("%s: min_spl not found", __func__); |
| 716 | goto done; |
| 717 | } |
| 718 | microphone.min_spl = atof(attr[curIdx++]); |
| 719 | } else { |
| 720 | microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN; |
| 721 | } |
| 722 | |
| 723 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) { |
| 724 | if (strcmp(attr[curIdx++], "orientation")) { |
| 725 | ALOGE("%s: orientation not found", __func__); |
| 726 | goto done; |
| 727 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 728 | char *context = NULL; |
| 729 | char *token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 730 | float orientation[3]; |
| 731 | uint32_t idx = 0; |
| 732 | while (token) { |
| 733 | orientation[idx++] = atof(token); |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 734 | if (idx >= 3) { |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 735 | break; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 736 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 737 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 738 | } |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 739 | if (idx != 3) { |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 740 | ALOGE("%s: orientation invalid", __func__); |
| 741 | goto done; |
| 742 | } |
| 743 | microphone.orientation.x = orientation[0]; |
| 744 | microphone.orientation.y = orientation[1]; |
| 745 | microphone.orientation.z = orientation[2]; |
| 746 | } else { |
| 747 | microphone.orientation.x = 0.0f; |
| 748 | microphone.orientation.y = 0.0f; |
| 749 | microphone.orientation.z = 0.0f; |
| 750 | } |
| 751 | |
| 752 | if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) { |
| 753 | if (strcmp(attr[curIdx++], "geometric_location")) { |
| 754 | ALOGE("%s: geometric_location not found", __func__); |
| 755 | goto done; |
| 756 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 757 | char *context = NULL; |
| 758 | char *token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 759 | float geometric_location[3]; |
| 760 | uint32_t idx = 0; |
| 761 | while (token) { |
| 762 | geometric_location[idx++] = atof(token); |
Weiyin Jiang | 20d3fa6 | 2018-08-01 18:06:27 +0800 | [diff] [blame] | 763 | if (idx >= 3) { |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 764 | break; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 765 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 766 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 767 | } |
Ramjee Singh | f57ff2a | 2018-08-27 16:22:16 +0530 | [diff] [blame] | 768 | if (idx != 3) { |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 769 | ALOGE("%s: geometric_location invalid", __func__); |
| 770 | goto done; |
| 771 | } |
| 772 | microphone.geometric_location.x = geometric_location[0]; |
| 773 | microphone.geometric_location.y = geometric_location[1]; |
| 774 | microphone.geometric_location.z = geometric_location[2]; |
| 775 | } else { |
| 776 | microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; |
| 777 | microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; |
| 778 | microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; |
| 779 | } |
| 780 | |
| 781 | platform_set_microphone_characteristic(my_data.platform, microphone); |
| 782 | done: |
| 783 | return; |
| 784 | } |
| 785 | |
| 786 | static void process_snd_dev(const XML_Char **attr) |
| 787 | { |
| 788 | uint32_t curIdx = 0; |
| 789 | in_snd_device = SND_DEVICE_NONE; |
| 790 | |
| 791 | if (strcmp(attr[curIdx++], "in_snd_device")) { |
| 792 | ALOGE("%s: snd_device not found", __func__); |
| 793 | return; |
| 794 | } |
| 795 | in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]); |
| 796 | if (in_snd_device < SND_DEVICE_IN_BEGIN || |
| 797 | in_snd_device >= SND_DEVICE_IN_END) { |
| 798 | ALOGE("%s: Sound device not valid", __func__); |
| 799 | in_snd_device = SND_DEVICE_NONE; |
| 800 | } |
| 801 | |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | static void process_mic_info(const XML_Char **attr) |
| 806 | { |
| 807 | uint32_t curIdx = 0; |
| 808 | struct mic_info microphone; |
| 809 | |
| 810 | memset(µphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED, |
| 811 | sizeof(microphone.channel_mapping)); |
| 812 | |
| 813 | if (strcmp(attr[curIdx++], "mic_device_id")) { |
| 814 | ALOGE("%s: mic_device_id not found", __func__); |
| 815 | goto on_error; |
| 816 | } |
| 817 | strlcpy(microphone.device_id, |
| 818 | (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN); |
| 819 | |
| 820 | if (strcmp(attr[curIdx++], "channel_mapping")) { |
| 821 | ALOGE("%s: channel_mapping not found", __func__); |
| 822 | goto on_error; |
| 823 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 824 | char *context = NULL; |
| 825 | const char *token = strtok_r((char *)attr[curIdx++], " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 826 | uint32_t idx = 0; |
| 827 | while (token) { |
| 828 | if (!find_enum_by_string(mic_channel_mapping, token, |
| 829 | AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT, |
| 830 | µphone.channel_mapping[idx++])) { |
| 831 | ALOGE("%s: channel_mapping %s in %s not found!", |
| 832 | __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH); |
| 833 | goto on_error; |
| 834 | } |
Ramjee Singh | 83e1eb1 | 2018-07-11 16:22:46 +0530 | [diff] [blame] | 835 | token = strtok_r(NULL, " ", &context); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 836 | } |
| 837 | microphone.channel_count = idx; |
| 838 | |
| 839 | platform_set_microphone_map(my_data.platform, in_snd_device, |
| 840 | µphone); |
| 841 | return; |
| 842 | on_error: |
| 843 | in_snd_device = SND_DEVICE_NONE; |
| 844 | return; |
| 845 | } |
| 846 | |
| 847 | |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 848 | /* process acdb meta info key value */ |
| 849 | static void process_acdb_metainfo_key(const XML_Char **attr) |
| 850 | { |
| 851 | if (strcmp(attr[0], "name") != 0) { |
| 852 | ALOGE("%s: 'name' not found", __func__); |
| 853 | goto done; |
| 854 | } |
| 855 | |
| 856 | if (strcmp(attr[2], "value") != 0) { |
| 857 | ALOGE("%s: 'value' not found", __func__); |
| 858 | goto done; |
| 859 | } |
| 860 | |
| 861 | int key = atoi((char *)attr[3]); |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 862 | switch(my_data.caller) { |
| 863 | case ACDB_EXTN: |
| 864 | if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) { |
| 865 | ALOGE("%s: key %d was not set!", __func__, key); |
| 866 | goto done; |
| 867 | } |
| 868 | break; |
| 869 | case PLATFORM: |
| 870 | if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) { |
| 871 | ALOGE("%s: key %d was not set!", __func__, key); |
| 872 | goto done; |
| 873 | } |
| 874 | break; |
| 875 | default: |
| 876 | ALOGE("%s: unknown caller!", __func__); |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | done: |
| 880 | return; |
| 881 | } |
| 882 | |
Dhananjay Kumar | 2a7f75b | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 883 | static void process_custom_mtmx_param_coeffs(const XML_Char **attr) |
| 884 | { |
| 885 | uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0; |
| 886 | uint32_t ip_channels = 0, op_channels = 0; |
| 887 | char *context = NULL, *ch_coeff_value = NULL; |
| 888 | struct audio_custom_mtmx_params *mtmx_params = NULL; |
| 889 | |
| 890 | if (strcmp(attr[attr_idx++], "out_channel_index") != 0) { |
| 891 | ALOGE("%s: 'out_channel_index' not found", __func__); |
| 892 | return; |
| 893 | } |
| 894 | out_ch_idx = atoi((char *)attr[attr_idx++]); |
| 895 | |
| 896 | if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) { |
| 897 | ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx); |
| 898 | return; |
| 899 | } |
| 900 | |
| 901 | if (strcmp(attr[attr_idx++], "values") != 0) { |
| 902 | ALOGE("%s: 'values' not found", __func__); |
| 903 | return; |
| 904 | } |
| 905 | mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform, |
| 906 | &mtmx_params_info); |
| 907 | if (mtmx_params == NULL) { |
| 908 | ALOGE("%s: mtmx params with given param info, not found", __func__); |
| 909 | return; |
| 910 | } |
| 911 | ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context); |
| 912 | ip_channels = mtmx_params->info.ip_channels; |
| 913 | op_channels = mtmx_params->info.op_channels; |
| 914 | while(ch_coeff_value && ch_coeff_count < op_channels) { |
| 915 | mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++] |
| 916 | = atoi(ch_coeff_value); |
| 917 | ch_coeff_value = strtok_r(NULL, " ", &context); |
| 918 | } |
| 919 | if (ch_coeff_count != mtmx_params->info.ip_channels || |
| 920 | ch_coeff_value != NULL) |
| 921 | ALOGE("%s: invalid/malformed coefficient values", __func__); |
| 922 | } |
| 923 | |
| 924 | static void process_custom_mtmx_params(const XML_Char **attr) |
| 925 | { |
| 926 | int attr_idx = 0; |
| 927 | |
| 928 | if (strcmp(attr[attr_idx++], "param_id") != 0) { |
| 929 | ALOGE("%s: 'param_id' not found", __func__); |
| 930 | return; |
| 931 | } |
| 932 | mtmx_params_info.id = atoi((char *)attr[attr_idx++]); |
| 933 | |
| 934 | if (strcmp(attr[attr_idx++], "in_channel_count") != 0) { |
| 935 | ALOGE("%s: 'in_channel_count' not found", __func__); |
| 936 | return; |
| 937 | } |
| 938 | mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]); |
| 939 | |
| 940 | if (strcmp(attr[attr_idx++], "out_channel_count") != 0) { |
| 941 | ALOGE("%s: 'out_channel_count' not found", __func__); |
| 942 | return; |
| 943 | } |
| 944 | mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]); |
| 945 | |
| 946 | if (strcmp(attr[attr_idx++], "usecase") != 0) { |
| 947 | ALOGE("%s: 'usecase' not found", __func__); |
| 948 | return; |
| 949 | } |
| 950 | mtmx_params_info.usecase_id = platform_get_usecase_index((char *)attr[attr_idx++]); |
| 951 | |
| 952 | if (strcmp(attr[attr_idx++], "snd_device") != 0) { |
| 953 | ALOGE("%s: 'snd_device' not found", __func__); |
| 954 | return; |
| 955 | } |
| 956 | mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]); |
| 957 | platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info); |
| 958 | |
| 959 | } |
| 960 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 961 | static void start_tag(void *userdata __unused, const XML_Char *tag_name, |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 962 | const XML_Char **attr) |
| 963 | { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 964 | if (my_data.caller == ACDB_EXTN) { |
| 965 | if(strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 966 | section = ACDB_METAINFO_KEY; |
| 967 | } else if (strcmp(tag_name, "param") == 0) { |
| 968 | if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) { |
| 969 | ALOGE("param tag only supported with CONFIG_PARAMS section"); |
| 970 | return; |
| 971 | } |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 972 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 973 | section_process_fn fn = section_table[section]; |
| 974 | fn(attr); |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 975 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 976 | } else if(my_data.caller == PLATFORM) { |
| 977 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 978 | section = BITWIDTH; |
| 979 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
| 980 | section = ACDB; |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 981 | } else if (strcmp(tag_name, "module_ids") == 0) { |
| 982 | section = MODULE; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 983 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 984 | section = PCM_ID; |
| 985 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 986 | section = BACKEND_NAME; |
| 987 | } else if (strcmp(tag_name, "config_params") == 0) { |
| 988 | section = CONFIG_PARAMS; |
| 989 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 990 | section = INTERFACE_NAME; |
| 991 | } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) { |
| 992 | section = GAIN_LEVEL_MAPPING; |
| 993 | } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 994 | section = ACDB_METAINFO_KEY; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 995 | } else if (strcmp(tag_name, "microphone_characteristics") == 0) { |
| 996 | section = MICROPHONE_CHARACTERISTIC; |
| 997 | } else if (strcmp(tag_name, "snd_devices") == 0) { |
| 998 | section = SND_DEVICES; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 999 | } else if (strcmp(tag_name, "device") == 0) { |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 1000 | if ((section != ACDB) && (section != AEC) && (section != NS) && |
| 1001 | (section != BACKEND_NAME) && (section != BITWIDTH) && |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1002 | (section != INTERFACE_NAME)) { |
| 1003 | ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names"); |
| 1004 | return; |
| 1005 | } |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 1006 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1007 | /* call into process function for the current section */ |
| 1008 | section_process_fn fn = section_table[section]; |
| 1009 | fn(attr); |
| 1010 | } else if (strcmp(tag_name, "gain_level_map") == 0) { |
| 1011 | if (section != GAIN_LEVEL_MAPPING) { |
| 1012 | ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section"); |
| 1013 | return; |
| 1014 | } |
| 1015 | |
| 1016 | section_process_fn fn = section_table[GAIN_LEVEL_MAPPING]; |
| 1017 | fn(attr); |
| 1018 | } else if (strcmp(tag_name, "usecase") == 0) { |
| 1019 | if (section != PCM_ID) { |
| 1020 | ALOGE("usecase tag only supported with PCM_ID section"); |
| 1021 | return; |
| 1022 | } |
| 1023 | |
| 1024 | section_process_fn fn = section_table[PCM_ID]; |
| 1025 | fn(attr); |
| 1026 | } else if (strcmp(tag_name, "param") == 0) { |
| 1027 | if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) { |
| 1028 | ALOGE("param tag only supported with CONFIG_PARAMS section"); |
| 1029 | return; |
| 1030 | } |
| 1031 | |
| 1032 | section_process_fn fn = section_table[section]; |
| 1033 | fn(attr); |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1034 | } else if (strcmp(tag_name, "aec") == 0) { |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 1035 | if (section != MODULE) { |
| 1036 | ALOGE("aec tag only supported with MODULE section"); |
| 1037 | return; |
| 1038 | } |
| 1039 | section = AEC; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1040 | } else if (strcmp(tag_name, "ns") == 0) { |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 1041 | if (section != MODULE) { |
| 1042 | ALOGE("ns tag only supported with MODULE section"); |
| 1043 | return; |
| 1044 | } |
| 1045 | section = NS; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1046 | } else if (strcmp(tag_name, "microphone") == 0) { |
| 1047 | if (section != MICROPHONE_CHARACTERISTIC) { |
| 1048 | ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section"); |
| 1049 | return; |
| 1050 | } |
| 1051 | section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC]; |
| 1052 | fn(attr); |
| 1053 | } else if (strcmp(tag_name, "input_snd_device") == 0) { |
| 1054 | if (section != SND_DEVICES) { |
| 1055 | ALOGE("input_snd_device tag only supported with SND_DEVICES section"); |
| 1056 | return; |
| 1057 | } |
| 1058 | section = INPUT_SND_DEVICE; |
| 1059 | } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) { |
| 1060 | if (section != INPUT_SND_DEVICE) { |
| 1061 | ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section"); |
| 1062 | return; |
| 1063 | } |
| 1064 | section = INPUT_SND_DEVICE_TO_MIC_MAPPING; |
| 1065 | } else if (strcmp(tag_name, "snd_dev") == 0) { |
| 1066 | if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) { |
| 1067 | ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section"); |
| 1068 | return; |
| 1069 | } |
| 1070 | section_process_fn fn = section_table[SND_DEV]; |
| 1071 | fn(attr); |
| 1072 | } else if (strcmp(tag_name, "mic_info") == 0) { |
| 1073 | if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) { |
| 1074 | ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section"); |
| 1075 | return; |
| 1076 | } |
| 1077 | if (in_snd_device == SND_DEVICE_NONE) { |
| 1078 | ALOGE("%s: Error in previous tags, do not process mic info", __func__); |
| 1079 | return; |
| 1080 | } |
| 1081 | section_process_fn fn = section_table[MIC_INFO]; |
| 1082 | fn(attr); |
Dhananjay Kumar | 2a7f75b | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1083 | } else if (strcmp(tag_name, "custom_mtmx_params") == 0) { |
| 1084 | if (section != ROOT) { |
| 1085 | ALOGE("custom_mtmx_params tag supported only in ROOT section"); |
| 1086 | return; |
| 1087 | } |
| 1088 | section = CUSTOM_MTMX_PARAMS; |
| 1089 | section_process_fn fn = section_table[section]; |
| 1090 | fn(attr); |
| 1091 | } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) { |
| 1092 | if (section != CUSTOM_MTMX_PARAMS) { |
| 1093 | ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section"); |
| 1094 | return; |
| 1095 | } |
| 1096 | section = CUSTOM_MTMX_PARAM_COEFFS; |
| 1097 | section_process_fn fn = section_table[section]; |
| 1098 | fn(attr); |
| 1099 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1100 | } else { |
| 1101 | ALOGE("%s: unknown caller!", __func__); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1102 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1103 | return; |
| 1104 | } |
| 1105 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1106 | static void end_tag(void *userdata __unused, const XML_Char *tag_name) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1107 | { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 1108 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 1109 | section = ROOT; |
| 1110 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1111 | section = ROOT; |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 1112 | } else if (strcmp(tag_name, "module_ids") == 0) { |
| 1113 | section = ROOT; |
| 1114 | } else if (strcmp(tag_name, "aec") == 0) { |
| 1115 | section = MODULE; |
| 1116 | } else if (strcmp(tag_name, "ns") == 0) { |
| 1117 | section = MODULE; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1118 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 1119 | section = ROOT; |
| 1120 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 1121 | section = ROOT; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 1122 | } else if (strcmp(tag_name, "config_params") == 0) { |
| 1123 | section = ROOT; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1124 | if (my_data.caller == PLATFORM) { |
| 1125 | platform_set_parameters(my_data.platform, my_data.kvpairs); |
| 1126 | } |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 1127 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 1128 | section = ROOT; |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 1129 | } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) { |
| 1130 | section = ROOT; |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 1131 | } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 1132 | section = ROOT; |
Naresh Tanniru | dcb47c5 | 2018-06-25 16:23:32 +0530 | [diff] [blame] | 1133 | } else if (strcmp(tag_name, "microphone_characteristics") == 0) { |
| 1134 | section = ROOT; |
| 1135 | } else if (strcmp(tag_name, "snd_devices") == 0) { |
| 1136 | section = ROOT; |
| 1137 | } else if (strcmp(tag_name, "input_snd_device") == 0) { |
| 1138 | section = SND_DEVICES; |
| 1139 | } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) { |
| 1140 | section = INPUT_SND_DEVICE; |
Dhananjay Kumar | 2a7f75b | 2018-12-10 22:26:53 +0530 | [diff] [blame] | 1141 | } else if (strcmp(tag_name, "custom_mtmx_params") == 0) { |
| 1142 | section = ROOT; |
| 1143 | } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) { |
| 1144 | section = CUSTOM_MTMX_PARAMS; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1145 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1146 | } |
| 1147 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1148 | 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] | 1149 | { |
| 1150 | XML_Parser parser; |
| 1151 | FILE *file; |
| 1152 | int ret = 0; |
| 1153 | int bytes_read; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1154 | void *buf; |
| 1155 | |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 1156 | file = fopen(filename, "r"); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1157 | section = ROOT; |
| 1158 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1159 | if (!file) { |
| 1160 | ALOGD("%s: Failed to open %s, using defaults.", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 1161 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1162 | ret = -ENODEV; |
| 1163 | goto done; |
| 1164 | } |
| 1165 | |
| 1166 | parser = XML_ParserCreate(NULL); |
| 1167 | if (!parser) { |
| 1168 | ALOGE("%s: Failed to create XML parser!", __func__); |
| 1169 | ret = -ENODEV; |
| 1170 | goto err_close_file; |
| 1171 | } |
| 1172 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 1173 | my_data.caller = caller_type; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 1174 | my_data.platform = platform; |
| 1175 | my_data.kvpairs = str_parms_create(); |
| 1176 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1177 | XML_SetElementHandler(parser, start_tag, end_tag); |
| 1178 | |
| 1179 | while (1) { |
| 1180 | buf = XML_GetBuffer(parser, BUF_SIZE); |
| 1181 | if (buf == NULL) { |
| 1182 | ALOGE("%s: XML_GetBuffer failed", __func__); |
| 1183 | ret = -ENOMEM; |
| 1184 | goto err_free_parser; |
| 1185 | } |
| 1186 | |
| 1187 | bytes_read = fread(buf, 1, BUF_SIZE, file); |
| 1188 | if (bytes_read < 0) { |
| 1189 | ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read); |
| 1190 | ret = bytes_read; |
| 1191 | goto err_free_parser; |
| 1192 | } |
| 1193 | |
| 1194 | if (XML_ParseBuffer(parser, bytes_read, |
| 1195 | bytes_read == 0) == XML_STATUS_ERROR) { |
| 1196 | ALOGE("%s: XML_ParseBuffer failed, for %s", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 1197 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1198 | ret = -EINVAL; |
| 1199 | goto err_free_parser; |
| 1200 | } |
| 1201 | |
| 1202 | if (bytes_read == 0) |
| 1203 | break; |
| 1204 | } |
| 1205 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1206 | err_free_parser: |
| 1207 | XML_ParserFree(parser); |
| 1208 | err_close_file: |
| 1209 | fclose(file); |
| 1210 | done: |
| 1211 | return ret; |
| 1212 | } |