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