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