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