blob: 4ad5a5cc37d8b877a1b67778f5c1020ecc08511a [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Robert Lee58215542019-07-15 20:55:12 +08002 * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved.
Ben Romberger55886882014-01-10 13:49:02 -08003 *
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 Romberger61764e32014-01-10 13:49:02 -080030#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080031#define LOG_NDDEBUG 0
32
33#include <errno.h>
34#include <stdio.h>
35#include <expat.h>
Jiangen Jiao334224b2019-09-12 15:47:46 +080036#include <pthread.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080037#include <log/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070038#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080039#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070040#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080041#include "platform_api.h"
Saurav Kumardba3caf2020-05-29 20:53:55 +053042#include "audio_extn.h"
Ben Romberger61764e32014-01-10 13:49:02 -080043#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070044#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080045
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053046#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 Romberger55886882014-01-10 13:49:02 -080052#define BUF_SIZE 1024
Saurav Kumardba3caf2020-05-29 20:53:55 +053053char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH];
54char platform_info_xml_path_file[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -080055
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070056typedef enum {
57 ROOT,
58 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070059 MODULE,
60 AEC,
61 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070062 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070063 PCM_ID,
64 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080065 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070066 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080067 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070068 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080069 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053070 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053071 MICROPHONE_CHARACTERISTIC,
72 SND_DEVICES,
73 INPUT_SND_DEVICE,
74 INPUT_SND_DEVICE_TO_MIC_MAPPING,
75 SND_DEV,
76 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053077 CUSTOM_MTMX_PARAMS,
78 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070079 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053080 CUSTOM_MTMX_IN_PARAMS,
81 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +080082 MMSECNS,
Juyu Chen918e1e12019-08-08 15:28:18 -070083 AUDIO_SOURCE_DELAY,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070084} section_t;
85
86typedef void (* section_process_fn)(const XML_Char **attr);
87
Saurav Kumardba3caf2020-05-29 20:53:55 +053088const char* get_platform_xml_path()
89{
90 audio_get_vendor_config_path(vendor_config_path, sizeof(vendor_config_path));
91 /* Get path for platorm_info_xml_path_name in vendor */
92 snprintf(platform_info_xml_path_file, sizeof(platform_info_xml_path_file),
93 "%s/%s", vendor_config_path, PLATFORM_INFO_XML_PATH_NAME);
94 return platform_info_xml_path_file;
95}
96
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070097static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070098static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
99static void process_effect_aec(const XML_Char **attr);
100static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -0700101static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700102static void process_pcm_id(const XML_Char **attr);
103static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800104static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700105static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700106static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800107static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700108static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800109static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530110static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530111static void process_microphone_characteristic(const XML_Char **attr);
112static void process_snd_dev(const XML_Char **attr);
113static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530114static void process_custom_mtmx_params(const XML_Char **attr);
115static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700116static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530117static void process_custom_mtmx_in_params(const XML_Char **attr);
118static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Guodong Hu1d46f342019-06-28 16:57:30 +0800119static void process_fluence_mmsecns(const XML_Char **attr);
Juyu Chen918e1e12019-08-08 15:28:18 -0700120static void process_audio_source_delay(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700121
122static section_process_fn section_table[] = {
123 [ROOT] = process_root,
124 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700125 [AEC] = process_effect_aec,
126 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700127 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700128 [PCM_ID] = process_pcm_id,
129 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800130 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700131 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800132 [OPERATOR_SPECIFIC] = process_operator_specific,
133 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700134 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530135 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530136 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
137 [SND_DEV] = process_snd_dev,
138 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530139 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
140 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700141 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530142 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
143 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800144 [MMSECNS] = process_fluence_mmsecns,
Juyu Chen918e1e12019-08-08 15:28:18 -0700145 [AUDIO_SOURCE_DELAY] = process_audio_source_delay,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700146};
147
148static section_t section;
149
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700150struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700151 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700152 void *platform;
153 struct str_parms *kvpairs;
154};
155
156static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800157static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700158
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530159
160struct audio_string_to_enum {
161 const char* name;
162 unsigned int value;
163};
164
165static snd_device_t in_snd_device;
166
167static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
172};
173
174static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
181};
182
183static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
187};
188
189static const struct audio_string_to_enum device_in_types[] = {
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
199 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
200 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
201 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
202 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
203 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
204 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
205 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
206 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
207 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
208 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
209 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
210 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
211 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
212 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
213 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
214 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
215 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
216 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
217};
218
219enum {
220 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
221 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
222 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
223 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
224 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
225 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
226 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
227 | ORIENTATION) | GEOMETRIC_LOCATION) */
228};
229
230static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
231 int32_t len, unsigned int *value)
232{
233 if (table == NULL) {
234 ALOGE("%s: table is NULL", __func__);
235 return false;
236 }
237
238 if (name == NULL) {
239 ALOGE("null key");
240 return false;
241 }
242
243 for (int i = 0; i < len; i++) {
244 if (!strcmp(table[i].name, name)) {
245 *value = table[i].value;
246 return true;
247 }
248 }
249 return false;
250}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530251
252static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530253static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530254
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700255/*
256 * <audio_platform_info>
257 * <acdb_ids>
258 * <device name="???" acdb_id="???"/>
259 * ...
260 * ...
261 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700262 * <module_ids>
263 * <device name="???" module_id="???"/>
264 * ...
265 * ...
266 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700267 * <backend_names>
268 * <device name="???" backend="???"/>
269 * ...
270 * ...
271 * </backend_names>
272 * <pcm_ids>
273 * <usecase name="???" type="in/out" id="???"/>
274 * ...
275 * ...
276 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800277 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530278 * <device name="Use audio device name here, not sound device name" interface="PRIMARY_I2S" codec_type="external/internal"/>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800279 * ...
280 * ...
281 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700282 * <config_params>
283 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800284 * <param key="operator_info" value="tmus;aa;bb;cc"/>
285 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700286 * ...
287 * ...
288 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800289 *
290 * <operator_specific>
291 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
292 * ...
293 * ...
294 * </operator_specific>
295 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700296 * </audio_platform_info>
297 */
298
299static void process_root(const XML_Char **attr __unused)
300{
301}
302
303/* mapping from usecase to pcm dev id */
304static void process_pcm_id(const XML_Char **attr)
305{
306 int index;
307
308 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700309 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700310 goto done;
311 }
312
313 index = platform_get_usecase_index((char *)attr[1]);
314 if (index < 0) {
315 ALOGE("%s: usecase %s not found!",
316 __func__, attr[1]);
317 goto done;
318 }
319
320 if (strcmp(attr[2], "type") != 0) {
321 ALOGE("%s: usecase type not mentioned", __func__);
322 goto done;
323 }
324
325 int type = -1;
326
327 if (!strcasecmp((char *)attr[3], "in")) {
328 type = 1;
329 } else if (!strcasecmp((char *)attr[3], "out")) {
330 type = 0;
331 } else {
332 ALOGE("%s: type must be IN or OUT", __func__);
333 goto done;
334 }
335
336 if (strcmp(attr[4], "id") != 0) {
337 ALOGE("%s: usecase id not mentioned", __func__);
338 goto done;
339 }
340
341 int id = atoi((char *)attr[5]);
342
343 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
344 ALOGE("%s: usecase %s type %d id %d was not set!",
345 __func__, attr[1], type, id);
346 goto done;
347 }
348
349done:
350 return;
351}
352
353/* backend to be used for a device */
354static void process_backend_name(const XML_Char **attr)
355{
356 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530357 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530358 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700359
360 if (strcmp(attr[0], "name") != 0) {
361 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
362 goto done;
363 }
364
365 index = platform_get_snd_device_index((char *)attr[1]);
366 if (index < 0) {
367 ALOGE("%s: Device %s not found, no ACDB ID set!",
368 __func__, attr[1]);
369 goto done;
370 }
371
372 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530373 if (strcmp(attr[2], "interface") == 0)
374 hw_interface = (char *)attr[3];
375 } else {
376 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700377 }
378
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530379 if (attr[4] != NULL) {
380 if (strcmp(attr[4], "interface") != 0) {
381 hw_interface = NULL;
382 } else {
383 hw_interface = (char *)attr[5];
384 }
385 }
386
Ashish Jaind150d4c2017-02-03 18:44:34 +0530387 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700388 ALOGE("%s: Device %s backend %s was not set!",
389 __func__, attr[1], attr[3]);
390 goto done;
391 }
392
393done:
394 return;
395}
396
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700397static void process_gain_db_to_level_map(const XML_Char **attr)
398{
399 struct amp_db_and_gain_table tbl_entry;
400
401 if ((strcmp(attr[0], "db") != 0) ||
402 (strcmp(attr[2], "level") != 0)) {
403 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
404 __func__, attr[0], attr[2]);
405 goto done;
406 }
407
408 tbl_entry.db = atof(attr[1]);
409 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
410 tbl_entry.level = atoi(attr[3]);
411
Aalique Grahame22e49102018-12-18 14:23:57 -0800412 //custome level should be > 0. Level 0 is fixed for default
413 CHECK(tbl_entry.level > 0);
414
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700415 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
416 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
417 platform_add_gain_level_mapping(&tbl_entry);
418
419done:
420 return;
421}
422
423
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700424static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800425{
Ben Romberger61764e32014-01-10 13:49:02 -0800426 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800427
Ben Romberger61764e32014-01-10 13:49:02 -0800428 if (strcmp(attr[0], "name") != 0) {
429 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800430 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800431 }
Ben Romberger55886882014-01-10 13:49:02 -0800432
Ben Romberger61764e32014-01-10 13:49:02 -0800433 index = platform_get_snd_device_index((char *)attr[1]);
434 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800435 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
436 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800437 goto done;
438 }
439
440 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800441 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
442 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800443 goto done;
444 }
445
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700446 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
447 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800448 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800449 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800450 }
Ben Romberger55886882014-01-10 13:49:02 -0800451
Ben Romberger55886882014-01-10 13:49:02 -0800452done:
453 return;
454}
455
Aalique Grahame22e49102018-12-18 14:23:57 -0800456static void process_operator_specific(const XML_Char **attr)
457{
458 snd_device_t snd_device = SND_DEVICE_NONE;
459
460 if (strcmp(attr[0], "name") != 0) {
461 ALOGE("%s: 'name' not found", __func__);
462 goto done;
463 }
464
465 snd_device = platform_get_snd_device_index((char *)attr[1]);
466 if (snd_device < 0) {
467 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530468 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800469 goto done;
470 }
471
472 if (strcmp(attr[2], "operator") != 0) {
473 ALOGE("%s: 'operator' not found", __func__);
474 goto done;
475 }
476
477 if (strcmp(attr[4], "mixer_path") != 0) {
478 ALOGE("%s: 'mixer_path' not found", __func__);
479 goto done;
480 }
481
482 if (strcmp(attr[6], "acdb_id") != 0) {
483 ALOGE("%s: 'acdb_id' not found", __func__);
484 goto done;
485 }
486
487 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
488
489done:
490 return;
491}
492
Carter Hsu32a62362018-10-15 15:01:42 -0700493static void process_external_dev(const XML_Char **attr)
494{
495 snd_device_t snd_device = SND_DEVICE_NONE;
496
497 if (strcmp(attr[0], "name") != 0) {
498 ALOGE("%s: 'name' not found", __func__);
499 goto done;
500 }
501
502 snd_device = platform_get_snd_device_index((char *)attr[1]);
503 if (snd_device < 0) {
504 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530505 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700506 goto done;
507 }
508
509 if (strcmp(attr[2], "usbid") != 0) {
510 ALOGE("%s: 'usbid' not found", __func__);
511 goto done;
512 }
513
514 if (strcmp(attr[4], "acdb_id") != 0) {
515 ALOGE("%s: 'acdb_id' not found", __func__);
516 goto done;
517 }
518
519 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
520
521done:
522 return;
523}
524
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700525static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
526{
527 int index;
528 struct audio_effect_config effect_config;
529
530 if (strcmp(attr[0], "name") != 0) {
531 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
532 goto done;
533 }
534
535 index = platform_get_snd_device_index((char *)attr[1]);
536 if (index < 0) {
537 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
538 __func__, attr[1]);
539 goto done;
540 }
541
542 if (strcmp(attr[2], "module_id") != 0) {
543 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
544 __func__, attr[2]);
545 goto done;
546 }
547
548 if (strcmp(attr[4], "instance_id") != 0) {
549 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
550 __func__, attr[4]);
551 goto done;
552 }
553
554 if (strcmp(attr[6], "param_id") != 0) {
555 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
556 __func__, attr[6]);
557 goto done;
558 }
559
560 if (strcmp(attr[8], "param_value") != 0) {
561 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
562 __func__, attr[8]);
563 goto done;
564 }
565
566 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
567 strtol((char *)attr[5], NULL, 0),
568 strtol((char *)attr[7], NULL, 0),
569 strtol((char *)attr[9], NULL, 0)};
570
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700571 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
572 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
573 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
574 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
575 strtol((char *)attr[9], NULL, 0));
576 goto done;
577 }
578
579done:
580 return;
581}
582
583static void process_effect_aec(const XML_Char **attr)
584{
585 process_audio_effect(attr, EFFECT_AEC);
586 return;
587}
588
589static void process_effect_ns(const XML_Char **attr)
590{
591 process_audio_effect(attr, EFFECT_NS);
592 return;
593}
594
Guodong Hu1d46f342019-06-28 16:57:30 +0800595static void process_fluence_mmsecns(const XML_Char **attr)
596{
597 int index;
598 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
599
600 if (strcmp(attr[0], "name") != 0) {
601 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
602 goto done;
603 }
604
605 index = platform_get_snd_device_index((char *)attr[1]);
606 if (index < 0) {
607 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
608 __func__, attr[1]);
609 goto done;
610 }
611
612 if (strcmp(attr[2], "topology_id") != 0) {
613 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
614 __func__, attr[2]);
615 goto done;
616 }
617
618 if (strcmp(attr[4], "module_id") != 0) {
619 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
620 __func__, attr[4]);
621 goto done;
622 }
623
624 if (strcmp(attr[6], "instance_id") != 0) {
625 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
626 __func__, attr[6]);
627 goto done;
628 }
629
630 if (strcmp(attr[8], "param_id") != 0) {
631 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
632 __func__, attr[8]);
633 goto done;
634 }
635
636 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
637 strtol((char *)attr[5], NULL, 0),
638 strtol((char *)attr[7], NULL, 0),
639 strtol((char *)attr[9], NULL, 0)};
640
641
642 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
643 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
644 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
645 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
646 goto done;
647 }
648
649done:
650 return;
651}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700652static void process_bit_width(const XML_Char **attr)
653{
654 int index;
655
656 if (strcmp(attr[0], "name") != 0) {
657 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
658 goto done;
659 }
660
661 index = platform_get_snd_device_index((char *)attr[1]);
662 if (index < 0) {
663 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
664 __func__, attr[1]);
665 goto done;
666 }
667
668 if (strcmp(attr[2], "bit_width") != 0) {
669 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
670 __func__, attr[1]);
671 goto done;
672 }
673
674 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
675 ALOGE("%s: Device %s, ACDB ID %d was not set!",
676 __func__, attr[1], atoi((char *)attr[3]));
677 goto done;
678 }
679
680done:
681 return;
682}
683
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800684static void process_interface_name(const XML_Char **attr)
685{
686 int ret;
687
688 if (strcmp(attr[0], "name") != 0) {
689 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
690
691 goto done;
692 }
693
694 if (strcmp(attr[2], "interface") != 0) {
695 ALOGE("%s: Device %s has no Audio Interface set!",
696 __func__, attr[1]);
697
698 goto done;
699 }
700
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530701 if (strcmp(attr[4], "codec_type") != 0) {
702 ALOGE("%s: Device %s has no codec type set!",
703 __func__, attr[1]);
704
705 goto done;
706 }
707
708 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
709 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800710 if (ret < 0) {
711 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800712 goto done;
713 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800714
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800715done:
716 return;
717}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530718
Juyu Chen918e1e12019-08-08 15:28:18 -0700719static void process_audio_source_delay(const XML_Char **attr)
720{
721 audio_source_t audio_source = -1;
722
723 if (strcmp(attr[0], "name") != 0) {
724 ALOGE("%s: 'name' not found", __func__);
725 goto done;
726 }
George Gao9ba8a142020-07-23 14:30:03 -0700727
Juyu Chen918e1e12019-08-08 15:28:18 -0700728 audio_source = platform_get_audio_source_index((const char *)attr[1]);
729
730 if (audio_source < 0) {
731 ALOGE("%s: audio_source %s is not defined",
732 __func__, (char *)attr[1]);
733 goto done;
734 }
735
736 if (strcmp(attr[2], "delay") != 0) {
737 ALOGE("%s: 'delay' not found", __func__);
738 goto done;
739 }
740
741 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
742
743done:
744 return;
745}
746
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700747static void process_config_params(const XML_Char **attr)
748{
749 if (strcmp(attr[0], "key") != 0) {
750 ALOGE("%s: 'key' not found", __func__);
751 goto done;
752 }
753
754 if (strcmp(attr[2], "value") != 0) {
755 ALOGE("%s: 'value' not found", __func__);
756 goto done;
757 }
758
759 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700760 if (my_data.caller == PLATFORM)
761 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700762done:
763 return;
764}
765
Aalique Grahame22e49102018-12-18 14:23:57 -0800766static void process_app_type(const XML_Char **attr)
767{
768 if (strcmp(attr[0], "uc_type")) {
769 ALOGE("%s: uc_type not found", __func__);
770 goto done;
771 }
772
773 if (strcmp(attr[2], "mode")) {
774 ALOGE("%s: mode not found", __func__);
775 goto done;
776 }
777
778 if (strcmp(attr[4], "bit_width")) {
779 ALOGE("%s: bit_width not found", __func__);
780 goto done;
781 }
782
783 if (strcmp(attr[6], "id")) {
784 ALOGE("%s: id not found", __func__);
785 goto done;
786 }
787
788 if (strcmp(attr[8], "max_rate")) {
789 ALOGE("%s: max rate not found", __func__);
790 goto done;
791 }
792
793 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
794 atoi(attr[9]));
795done:
796 return;
797}
798
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530799static void process_microphone_characteristic(const XML_Char **attr) {
800 struct audio_microphone_characteristic_t microphone;
801 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530802 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530803
Saurav Kumardba3caf2020-05-29 20:53:55 +0530804 strlcpy(platform_info_xml_path, get_platform_xml_path(),
805 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530806 if (strcmp(attr[curIdx++], "valid_mask")) {
807 ALOGE("%s: valid_mask not found", __func__);
808 goto done;
809 }
810 uint32_t valid_mask = atoi(attr[curIdx++]);
811
812 if (strcmp(attr[curIdx++], "device_id")) {
813 ALOGE("%s: device_id not found", __func__);
814 goto done;
815 }
816 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
817 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
818 goto done;
819 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530820 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530821
822 if (strcmp(attr[curIdx++], "type")) {
823 ALOGE("%s: device not found", __func__);
824 goto done;
825 }
826 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
827 ARRAY_SIZE(device_in_types), &microphone.device)) {
828 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530829 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530830 goto done;
831 }
832
833 if (strcmp(attr[curIdx++], "address")) {
834 ALOGE("%s: address not found", __func__);
835 goto done;
836 }
837 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
838 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
839 goto done;
840 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530841 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530842 if (strlen(microphone.address) == 0) {
843 // If the address is empty, populate the address according to device type.
844 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530845 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530846 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530847 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530848 }
849 }
850
851 if (strcmp(attr[curIdx++], "location")) {
852 ALOGE("%s: location not found", __func__);
853 goto done;
854 }
855 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
856 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
857 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530858 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530859 goto done;
860 }
861
862 if (strcmp(attr[curIdx++], "group")) {
863 ALOGE("%s: group not found", __func__);
864 goto done;
865 }
866 microphone.group = atoi(attr[curIdx++]);
867
868 if (strcmp(attr[curIdx++], "index_in_the_group")) {
869 ALOGE("%s: index_in_the_group not found", __func__);
870 goto done;
871 }
872 microphone.index_in_the_group = atoi(attr[curIdx++]);
873
874 if (strcmp(attr[curIdx++], "directionality")) {
875 ALOGE("%s: directionality not found", __func__);
876 goto done;
877 }
878 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
879 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
880 ALOGE("%s: directionality %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530881 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530882 goto done;
883 }
884
885 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
886 ALOGE("%s: num_frequency_responses not found", __func__);
887 goto done;
888 }
889 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530890 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530891 ALOGE("%s: num_frequency_responses is too large", __func__);
892 goto done;
893 }
894 if (microphone.num_frequency_responses > 0) {
895 if (strcmp(attr[curIdx++], "frequencies")) {
896 ALOGE("%s: frequencies not found", __func__);
897 goto done;
898 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530899 char *context = NULL;
900 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530901 uint32_t num_frequencies = 0;
902 while (token) {
903 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800904 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530905 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530906 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530907 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530908 }
909
910 if (strcmp(attr[curIdx++], "responses")) {
911 ALOGE("%s: responses not found", __func__);
912 goto done;
913 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530914 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530915 uint32_t num_responses = 0;
916 while (token) {
917 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800918 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530919 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530920 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530921 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530922 }
923
924 if (num_frequencies != num_responses
925 || num_frequencies != microphone.num_frequency_responses) {
926 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
927 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
928 goto done;
929 }
930 }
931
932 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
933 if (strcmp(attr[curIdx++], "sensitivity")) {
934 ALOGE("%s: sensitivity not found", __func__);
935 goto done;
936 }
937 microphone.sensitivity = atof(attr[curIdx++]);
938 } else {
939 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
940 }
941
942 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
943 if (strcmp(attr[curIdx++], "max_spl")) {
944 ALOGE("%s: max_spl not found", __func__);
945 goto done;
946 }
947 microphone.max_spl = atof(attr[curIdx++]);
948 } else {
949 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
950 }
951
952 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
953 if (strcmp(attr[curIdx++], "min_spl")) {
954 ALOGE("%s: min_spl not found", __func__);
955 goto done;
956 }
957 microphone.min_spl = atof(attr[curIdx++]);
958 } else {
959 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
960 }
961
962 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
963 if (strcmp(attr[curIdx++], "orientation")) {
964 ALOGE("%s: orientation not found", __func__);
965 goto done;
966 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530967 char *context = NULL;
968 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530969 float orientation[3];
970 uint32_t idx = 0;
971 while (token) {
972 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800973 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530974 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530975 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530976 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530977 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530978 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530979 ALOGE("%s: orientation invalid", __func__);
980 goto done;
981 }
982 microphone.orientation.x = orientation[0];
983 microphone.orientation.y = orientation[1];
984 microphone.orientation.z = orientation[2];
985 } else {
986 microphone.orientation.x = 0.0f;
987 microphone.orientation.y = 0.0f;
988 microphone.orientation.z = 0.0f;
989 }
990
991 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
992 if (strcmp(attr[curIdx++], "geometric_location")) {
993 ALOGE("%s: geometric_location not found", __func__);
994 goto done;
995 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530996 char *context = NULL;
997 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530998 float geometric_location[3];
999 uint32_t idx = 0;
1000 while (token) {
1001 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001002 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301003 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301004 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301005 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301006 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301007 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301008 ALOGE("%s: geometric_location invalid", __func__);
1009 goto done;
1010 }
1011 microphone.geometric_location.x = geometric_location[0];
1012 microphone.geometric_location.y = geometric_location[1];
1013 microphone.geometric_location.z = geometric_location[2];
1014 } else {
1015 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1016 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1017 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1018 }
1019
1020 platform_set_microphone_characteristic(my_data.platform, microphone);
1021done:
1022 return;
1023}
1024
1025static void process_snd_dev(const XML_Char **attr)
1026{
1027 uint32_t curIdx = 0;
1028 in_snd_device = SND_DEVICE_NONE;
1029
1030 if (strcmp(attr[curIdx++], "in_snd_device")) {
1031 ALOGE("%s: snd_device not found", __func__);
1032 return;
1033 }
1034 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1035 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1036 in_snd_device >= SND_DEVICE_IN_END) {
1037 ALOGE("%s: Sound device not valid", __func__);
1038 in_snd_device = SND_DEVICE_NONE;
1039 }
1040
1041 return;
1042}
1043
1044static void process_mic_info(const XML_Char **attr)
1045{
1046 uint32_t curIdx = 0;
1047 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301048 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301049
Saurav Kumardba3caf2020-05-29 20:53:55 +05301050 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1051 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301052 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1053 sizeof(microphone.channel_mapping));
1054
1055 if (strcmp(attr[curIdx++], "mic_device_id")) {
1056 ALOGE("%s: mic_device_id not found", __func__);
1057 goto on_error;
1058 }
1059 strlcpy(microphone.device_id,
1060 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1061
1062 if (strcmp(attr[curIdx++], "channel_mapping")) {
1063 ALOGE("%s: channel_mapping not found", __func__);
1064 goto on_error;
1065 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301066 char *context = NULL;
1067 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301068 uint32_t idx = 0;
1069 while (token) {
1070 if (!find_enum_by_string(mic_channel_mapping, token,
1071 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1072 &microphone.channel_mapping[idx++])) {
1073 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301074 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301075 goto on_error;
1076 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301077 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301078 }
1079 microphone.channel_count = idx;
1080
1081 platform_set_microphone_map(my_data.platform, in_snd_device,
1082 &microphone);
1083 return;
1084on_error:
1085 in_snd_device = SND_DEVICE_NONE;
1086 return;
1087}
1088
1089
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301090/* process acdb meta info key value */
1091static void process_acdb_metainfo_key(const XML_Char **attr)
1092{
1093 if (strcmp(attr[0], "name") != 0) {
1094 ALOGE("%s: 'name' not found", __func__);
1095 goto done;
1096 }
1097
1098 if (strcmp(attr[2], "value") != 0) {
1099 ALOGE("%s: 'value' not found", __func__);
1100 goto done;
1101 }
1102
1103 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001104 switch(my_data.caller) {
1105 case ACDB_EXTN:
1106 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1107 ALOGE("%s: key %d was not set!", __func__, key);
1108 goto done;
1109 }
1110 break;
1111 case PLATFORM:
1112 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1113 ALOGE("%s: key %d was not set!", __func__, key);
1114 goto done;
1115 }
1116 break;
1117 default:
1118 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301119 }
1120
1121done:
1122 return;
1123}
1124
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301125static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1126{
1127 uint32_t attr_idx = 0;
1128 int32_t in_ch_idx = -1;
1129 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1130
1131 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1132 &mtmx_in_params_info);
1133 if (mtmx_in_params == NULL) {
1134 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1135 return;
1136 }
1137
1138 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1139 ALOGE("%s: 'in_channel_index' not found", __func__);
1140 return;
1141 }
1142
1143 in_ch_idx = atoi((char *)attr[attr_idx++]);
1144 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1145 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1146 return;
1147 }
1148
1149 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1150 ALOGE("%s: 'channel_count' not found", __func__);
1151 return;
1152 }
1153 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1154
1155 if (strcmp(attr[attr_idx++], "device") != 0) {
1156 ALOGE("%s: 'device' not found", __func__);
1157 return;
1158 }
1159 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1160 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1161
1162 if (strcmp(attr[attr_idx++], "interface") != 0) {
1163 ALOGE("%s: 'interface' not found", __func__);
1164 return;
1165 }
1166 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1167 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1168
1169 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1170 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1171 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1172 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1173 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1174 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1175 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1176 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1177
1178 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1179}
1180
1181static void process_custom_mtmx_in_params(const XML_Char **attr)
1182{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301183 int attr_idx = 0, i = 0;
1184 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301185
1186 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1187 ALOGE("%s: 'usecase' not found", __func__);
1188 return;
1189 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301190 /* Check if multi usecases are supported for this custom mtrx params */
1191 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1192 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1193 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1194 value = strtok_r(NULL, ",", &context);
1195 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301196
1197 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1198 ALOGE("%s: 'out_channel_count' not found", __func__);
1199 return;
1200 }
1201 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1202
1203 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1204
1205}
1206
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301207static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1208{
1209 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301210 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301211 char *context = NULL, *ch_coeff_value = NULL;
1212 struct audio_custom_mtmx_params *mtmx_params = NULL;
1213
1214 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1215 ALOGE("%s: 'out_channel_index' not found", __func__);
1216 return;
1217 }
1218 out_ch_idx = atoi((char *)attr[attr_idx++]);
1219
1220 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1221 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1222 return;
1223 }
1224
1225 if (strcmp(attr[attr_idx++], "values") != 0) {
1226 ALOGE("%s: 'values' not found", __func__);
1227 return;
1228 }
1229 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301230 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301231 if (mtmx_params == NULL) {
1232 ALOGE("%s: mtmx params with given param info, not found", __func__);
1233 return;
1234 }
1235 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1236 ip_channels = mtmx_params->info.ip_channels;
1237 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301238 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301239 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1240 = atoi(ch_coeff_value);
1241 ch_coeff_value = strtok_r(NULL, " ", &context);
1242 }
1243 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1244 ch_coeff_value != NULL)
1245 ALOGE("%s: invalid/malformed coefficient values", __func__);
1246}
1247
1248static void process_custom_mtmx_params(const XML_Char **attr)
1249{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301250 int attr_idx = 0, i = 0;
1251 char *context = NULL, *value = NULL;
1252
1253 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301254
1255 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1256 ALOGE("%s: 'param_id' not found", __func__);
1257 return;
1258 }
1259 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1260
1261 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1262 ALOGE("%s: 'in_channel_count' not found", __func__);
1263 return;
1264 }
1265 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1266
1267 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1268 ALOGE("%s: 'out_channel_count' not found", __func__);
1269 return;
1270 }
1271 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1272
1273 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1274 ALOGE("%s: 'usecase' not found", __func__);
1275 return;
1276 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301277
1278 /* check if multi usecases are supported for this custom mtrx params */
1279 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1280 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1281 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1282 value = strtok_r(NULL, ",", &context);
1283 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301284
1285 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1286 ALOGE("%s: 'snd_device' not found", __func__);
1287 return;
1288 }
1289 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301290
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301291 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1292 i = 0;
1293 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1294 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1295 mtmx_params_info.fe_id[i++] = atoi(value);
1296 value = strtok_r(NULL, ",", &context);
1297 }
1298
1299 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301300 }
1301
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301302 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1303
1304}
1305
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001306static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001307 const XML_Char **attr)
1308{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001309 if (my_data.caller == ACDB_EXTN) {
1310 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1311 section = ACDB_METAINFO_KEY;
1312 } else if (strcmp(tag_name, "param") == 0) {
1313 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1314 ALOGE("param tag only supported with CONFIG_PARAMS section");
1315 return;
1316 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001317
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001318 section_process_fn fn = section_table[section];
1319 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001320 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001321 } else if(my_data.caller == PLATFORM) {
1322 if (strcmp(tag_name, "bit_width_configs") == 0) {
1323 section = BITWIDTH;
1324 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1325 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001326 } else if (strcmp(tag_name, "module_ids") == 0) {
1327 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001328 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1329 section = PCM_ID;
1330 } else if (strcmp(tag_name, "backend_names") == 0) {
1331 section = BACKEND_NAME;
1332 } else if (strcmp(tag_name, "config_params") == 0) {
1333 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001334 } else if (strcmp(tag_name, "operator_specific") == 0) {
1335 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001336 } else if (strcmp(tag_name, "interface_names") == 0) {
1337 section = INTERFACE_NAME;
1338 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1339 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001340 } else if (strcmp(tag_name, "app_types") == 0) {
1341 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001342 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1343 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301344 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1345 section = MICROPHONE_CHARACTERISTIC;
1346 } else if (strcmp(tag_name, "snd_devices") == 0) {
1347 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001348 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001349 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001350 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001351 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001352 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1353 return;
1354 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001355
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001356 /* call into process function for the current section */
1357 section_process_fn fn = section_table[section];
1358 fn(attr);
1359 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1360 if (section != GAIN_LEVEL_MAPPING) {
1361 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1362 return;
1363 }
1364
1365 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1366 fn(attr);
1367 } else if (strcmp(tag_name, "usecase") == 0) {
1368 if (section != PCM_ID) {
1369 ALOGE("usecase tag only supported with PCM_ID section");
1370 return;
1371 }
1372
1373 section_process_fn fn = section_table[PCM_ID];
1374 fn(attr);
1375 } else if (strcmp(tag_name, "param") == 0) {
1376 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1377 ALOGE("param tag only supported with CONFIG_PARAMS section");
1378 return;
1379 }
1380
1381 section_process_fn fn = section_table[section];
1382 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301383 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001384 if (section != MODULE) {
1385 ALOGE("aec tag only supported with MODULE section");
1386 return;
1387 }
1388 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301389 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001390 if (section != MODULE) {
1391 ALOGE("ns tag only supported with MODULE section");
1392 return;
1393 }
1394 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001395 } else if (strcmp(tag_name, "mmsecns") == 0) {
1396 if (section != MODULE) {
1397 ALOGE("mmsecns tag only supported with MODULE section");
1398 return;
1399 }
1400 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001401 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1402 if (section != GAIN_LEVEL_MAPPING) {
1403 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1404 return;
1405 }
1406
1407 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1408 fn(attr);
1409 } else if (!strcmp(tag_name, "app")) {
1410 if (section != APP_TYPE) {
1411 ALOGE("app tag only valid in section APP_TYPE");
1412 return;
1413 }
1414
1415 section_process_fn fn = section_table[APP_TYPE];
1416 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301417 } else if (strcmp(tag_name, "microphone") == 0) {
1418 if (section != MICROPHONE_CHARACTERISTIC) {
1419 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1420 return;
1421 }
1422 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1423 fn(attr);
1424 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1425 if (section != SND_DEVICES) {
1426 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1427 return;
1428 }
1429 section = INPUT_SND_DEVICE;
1430 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1431 if (section != INPUT_SND_DEVICE) {
1432 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1433 return;
1434 }
1435 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1436 } else if (strcmp(tag_name, "snd_dev") == 0) {
1437 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1438 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1439 return;
1440 }
1441 section_process_fn fn = section_table[SND_DEV];
1442 fn(attr);
1443 } else if (strcmp(tag_name, "mic_info") == 0) {
1444 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1445 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1446 return;
1447 }
1448 if (in_snd_device == SND_DEVICE_NONE) {
1449 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1450 return;
1451 }
1452 section_process_fn fn = section_table[MIC_INFO];
1453 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301454 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1455 if (section != ROOT) {
1456 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1457 return;
1458 }
1459 section = CUSTOM_MTMX_PARAMS;
1460 section_process_fn fn = section_table[section];
1461 fn(attr);
1462 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1463 if (section != CUSTOM_MTMX_PARAMS) {
1464 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1465 return;
1466 }
1467 section = CUSTOM_MTMX_PARAM_COEFFS;
1468 section_process_fn fn = section_table[section];
1469 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001470 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1471 section = EXTERNAL_DEVICE_SPECIFIC;
1472 } else if (strcmp(tag_name, "ext_device") == 0) {
1473 section_process_fn fn = section_table[section];
1474 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301475 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1476 if (section != ROOT) {
1477 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1478 return;
1479 }
1480 section = CUSTOM_MTMX_IN_PARAMS;
1481 section_process_fn fn = section_table[section];
1482 fn(attr);
1483 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1484 if (section != CUSTOM_MTMX_IN_PARAMS) {
1485 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1486 return;
1487 }
1488 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Juyu Chen918e1e12019-08-08 15:28:18 -07001489 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1490 section = AUDIO_SOURCE_DELAY;
1491 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301492 section_process_fn fn = section_table[section];
1493 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301494 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001495 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001496 if(strcmp(tag_name, "config_params") == 0) {
1497 section = CONFIG_PARAMS;
1498 } else if (strcmp(tag_name, "param") == 0) {
1499 if (section != CONFIG_PARAMS) {
1500 ALOGE("param tag only supported with CONFIG_PARAMS section");
1501 return;
1502 }
1503
1504 section_process_fn fn = section_table[section];
1505 fn(attr);
1506 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001507 }
Ben Romberger55886882014-01-10 13:49:02 -08001508 return;
1509}
1510
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001511static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001512{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001513 if (strcmp(tag_name, "bit_width_configs") == 0) {
1514 section = ROOT;
1515 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001516 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001517 } else if (strcmp(tag_name, "module_ids") == 0) {
1518 section = ROOT;
1519 } else if (strcmp(tag_name, "aec") == 0) {
1520 section = MODULE;
1521 } else if (strcmp(tag_name, "ns") == 0) {
1522 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001523 } else if (strcmp(tag_name, "mmsecns") == 0) {
1524 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001525 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1526 section = ROOT;
1527 } else if (strcmp(tag_name, "backend_names") == 0) {
1528 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001529 } else if (strcmp(tag_name, "config_params") == 0) {
1530 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001531 } else if (strcmp(tag_name, "operator_specific") == 0) {
1532 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001533 } else if (strcmp(tag_name, "interface_names") == 0) {
1534 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001535 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1536 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001537 } else if (strcmp(tag_name, "app_types") == 0) {
1538 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301539 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1540 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301541 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1542 section = ROOT;
1543 } else if (strcmp(tag_name, "snd_devices") == 0) {
1544 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001545 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1546 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301547 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1548 section = SND_DEVICES;
1549 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1550 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301551 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1552 section = ROOT;
1553 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1554 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301555 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1556 section = ROOT;
1557 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1558 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001559 }
Ben Romberger55886882014-01-10 13:49:02 -08001560}
1561
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001562int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001563{
1564 XML_Parser parser;
1565 FILE *file;
1566 int ret = 0;
1567 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001568 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001569 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301570 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001571
Saurav Kumardba3caf2020-05-29 20:53:55 +05301572 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1573 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001574 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001575 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301576 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001577 MIXER_PATH_MAX_LENGTH);
1578 else
1579 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1580
1581 ALOGV("%s: platform info file name is %s", __func__,
1582 platform_info_file_name);
1583
1584 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001585 section = ROOT;
1586
Ben Romberger55886882014-01-10 13:49:02 -08001587 if (!file) {
1588 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001589 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001590 ret = -ENODEV;
1591 goto done;
1592 }
1593
1594 parser = XML_ParserCreate(NULL);
1595 if (!parser) {
1596 ALOGE("%s: Failed to create XML parser!", __func__);
1597 ret = -ENODEV;
1598 goto err_close_file;
1599 }
1600
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001601 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001602 my_data.platform = platform;
1603 my_data.kvpairs = str_parms_create();
1604
Ben Romberger55886882014-01-10 13:49:02 -08001605 XML_SetElementHandler(parser, start_tag, end_tag);
1606
1607 while (1) {
1608 buf = XML_GetBuffer(parser, BUF_SIZE);
1609 if (buf == NULL) {
1610 ALOGE("%s: XML_GetBuffer failed", __func__);
1611 ret = -ENOMEM;
1612 goto err_free_parser;
1613 }
1614
1615 bytes_read = fread(buf, 1, BUF_SIZE, file);
1616 if (bytes_read < 0) {
1617 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1618 ret = bytes_read;
1619 goto err_free_parser;
1620 }
1621
1622 if (XML_ParseBuffer(parser, bytes_read,
1623 bytes_read == 0) == XML_STATUS_ERROR) {
1624 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001625 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001626 ret = -EINVAL;
1627 goto err_free_parser;
1628 }
1629
1630 if (bytes_read == 0)
1631 break;
1632 }
1633
Ben Romberger55886882014-01-10 13:49:02 -08001634err_free_parser:
1635 XML_ParserFree(parser);
1636err_close_file:
1637 fclose(file);
1638done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001639 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001640 return ret;
1641}