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