blob: e55b91d2d8a737c277dac02beaeac7e761146e4e [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>
Fei Tongc20ce932021-06-21 16:42:38 +080045#ifdef LINUX_ENABLED
46#include <float.h>
47#endif
Ben Romberger55886882014-01-10 13:49:02 -080048
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053049#ifdef DYNAMIC_LOG_ENABLED
50#include <log_xml_parser.h>
51#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
52#include <log_utils.h>
53#endif
54
Ben Romberger55886882014-01-10 13:49:02 -080055#define BUF_SIZE 1024
Saurav Kumardba3caf2020-05-29 20:53:55 +053056char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH];
57char platform_info_xml_path_file[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -080058
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070059typedef enum {
60 ROOT,
61 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070062 MODULE,
63 AEC,
64 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070065 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070066 PCM_ID,
67 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080068 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070069 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080070 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070071 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080072 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053073 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053074 MICROPHONE_CHARACTERISTIC,
75 SND_DEVICES,
76 INPUT_SND_DEVICE,
77 INPUT_SND_DEVICE_TO_MIC_MAPPING,
78 SND_DEV,
79 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053080 CUSTOM_MTMX_PARAMS,
81 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070082 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053083 CUSTOM_MTMX_IN_PARAMS,
84 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +080085 MMSECNS,
Juyu Chen918e1e12019-08-08 15:28:18 -070086 AUDIO_SOURCE_DELAY,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070087} section_t;
88
89typedef void (* section_process_fn)(const XML_Char **attr);
90
Saurav Kumardba3caf2020-05-29 20:53:55 +053091const char* get_platform_xml_path()
92{
93 audio_get_vendor_config_path(vendor_config_path, sizeof(vendor_config_path));
94 /* Get path for platorm_info_xml_path_name in vendor */
95 snprintf(platform_info_xml_path_file, sizeof(platform_info_xml_path_file),
96 "%s/%s", vendor_config_path, PLATFORM_INFO_XML_PATH_NAME);
97 return platform_info_xml_path_file;
98}
99
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700100static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700101static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
102static void process_effect_aec(const XML_Char **attr);
103static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -0700104static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700105static void process_pcm_id(const XML_Char **attr);
106static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800107static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700108static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700109static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800110static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700111static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800112static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530113static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530114static void process_microphone_characteristic(const XML_Char **attr);
115static void process_snd_dev(const XML_Char **attr);
116static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530117static void process_custom_mtmx_params(const XML_Char **attr);
118static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700119static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530120static void process_custom_mtmx_in_params(const XML_Char **attr);
121static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Guodong Hu1d46f342019-06-28 16:57:30 +0800122static void process_fluence_mmsecns(const XML_Char **attr);
Juyu Chen918e1e12019-08-08 15:28:18 -0700123static void process_audio_source_delay(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700124
125static section_process_fn section_table[] = {
126 [ROOT] = process_root,
127 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700128 [AEC] = process_effect_aec,
129 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700130 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700131 [PCM_ID] = process_pcm_id,
132 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800133 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700134 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800135 [OPERATOR_SPECIFIC] = process_operator_specific,
136 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700137 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530138 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530139 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
140 [SND_DEV] = process_snd_dev,
141 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530142 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
143 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700144 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530145 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
146 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800147 [MMSECNS] = process_fluence_mmsecns,
Juyu Chen918e1e12019-08-08 15:28:18 -0700148 [AUDIO_SOURCE_DELAY] = process_audio_source_delay,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700149};
150
151static section_t section;
152
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700153struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700154 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700155 void *platform;
156 struct str_parms *kvpairs;
157};
158
159static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800160static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700161
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530162
163struct audio_string_to_enum {
164 const char* name;
165 unsigned int value;
166};
167
168static snd_device_t in_snd_device;
169
170static 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
177static 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
186static 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
192static 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
222enum {
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
233static 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 Kumar429eb452018-12-10 22:26:53 +0530254
255static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530256static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530257
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700258/*
259 * <audio_platform_info>
260 * <acdb_ids>
261 * <device name="???" acdb_id="???"/>
262 * ...
263 * ...
264 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700265 * <module_ids>
266 * <device name="???" module_id="???"/>
267 * ...
268 * ...
269 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700270 * <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 Chellaf928a982015-03-06 14:57:35 -0800280 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530281 * <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 -0800282 * ...
283 * ...
284 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700285 * <config_params>
286 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800287 * <param key="operator_info" value="tmus;aa;bb;cc"/>
288 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700289 * ...
290 * ...
291 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800292 *
293 * <operator_specific>
294 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
295 * ...
296 * ...
297 * </operator_specific>
298 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700299 * </audio_platform_info>
300 */
301
302static void process_root(const XML_Char **attr __unused)
303{
304}
305
306/* mapping from usecase to pcm dev id */
307static void process_pcm_id(const XML_Char **attr)
308{
309 int index;
310
311 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700312 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700313 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
352done:
353 return;
354}
355
356/* backend to be used for a device */
357static void process_backend_name(const XML_Char **attr)
358{
359 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530360 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530361 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700362
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 Jaind150d4c2017-02-03 18:44:34 +0530376 if (strcmp(attr[2], "interface") == 0)
377 hw_interface = (char *)attr[3];
378 } else {
379 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700380 }
381
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530382 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 Jaind150d4c2017-02-03 18:44:34 +0530390 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700391 ALOGE("%s: Device %s backend %s was not set!",
392 __func__, attr[1], attr[3]);
393 goto done;
394 }
395
396done:
397 return;
398}
399
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700400static 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 Grahame22e49102018-12-18 14:23:57 -0800415 //custome level should be > 0. Level 0 is fixed for default
416 CHECK(tbl_entry.level > 0);
417
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700418 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
422done:
423 return;
424}
425
426
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700427static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800428{
Ben Romberger61764e32014-01-10 13:49:02 -0800429 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800430
Ben Romberger61764e32014-01-10 13:49:02 -0800431 if (strcmp(attr[0], "name") != 0) {
432 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800433 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800434 }
Ben Romberger55886882014-01-10 13:49:02 -0800435
Ben Romberger61764e32014-01-10 13:49:02 -0800436 index = platform_get_snd_device_index((char *)attr[1]);
437 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800438 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
439 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800440 goto done;
441 }
442
443 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800444 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
445 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800446 goto done;
447 }
448
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700449 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 Zeng6a16ad72014-02-23 22:04:44 -0800451 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800452 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800453 }
Ben Romberger55886882014-01-10 13:49:02 -0800454
Ben Romberger55886882014-01-10 13:49:02 -0800455done:
456 return;
457}
458
Aalique Grahame22e49102018-12-18 14:23:57 -0800459static 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 Kumardba3caf2020-05-29 20:53:55 +0530471 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800472 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
492done:
493 return;
494}
495
Carter Hsu32a62362018-10-15 15:01:42 -0700496static 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 Kumardba3caf2020-05-29 20:53:55 +0530508 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700509 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
524done:
525 return;
526}
527
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700528static 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 Pandurangadf59cae2017-08-03 18:04:55 -0700574 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
582done:
583 return;
584}
585
586static void process_effect_aec(const XML_Char **attr)
587{
588 process_audio_effect(attr, EFFECT_AEC);
589 return;
590}
591
592static void process_effect_ns(const XML_Char **attr)
593{
594 process_audio_effect(attr, EFFECT_NS);
595 return;
596}
597
Guodong Hu1d46f342019-06-28 16:57:30 +0800598static 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
652done:
653 return;
654}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700655static 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
683done:
684 return;
685}
686
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800687static 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 Katta508eca42015-05-11 13:43:18 +0530704 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 Chellaf928a982015-03-06 14:57:35 -0800713 if (ret < 0) {
714 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800715 goto done;
716 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800717
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800718done:
719 return;
720}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530721
Juyu Chen918e1e12019-08-08 15:28:18 -0700722static void process_audio_source_delay(const XML_Char **attr)
723{
724 audio_source_t audio_source = -1;
725
726 if (strcmp(attr[0], "name") != 0) {
727 ALOGE("%s: 'name' not found", __func__);
728 goto done;
729 }
George Gao9ba8a142020-07-23 14:30:03 -0700730
Juyu Chen918e1e12019-08-08 15:28:18 -0700731 audio_source = platform_get_audio_source_index((const char *)attr[1]);
732
733 if (audio_source < 0) {
734 ALOGE("%s: audio_source %s is not defined",
735 __func__, (char *)attr[1]);
736 goto done;
737 }
738
739 if (strcmp(attr[2], "delay") != 0) {
740 ALOGE("%s: 'delay' not found", __func__);
741 goto done;
742 }
743
744 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
745
746done:
747 return;
748}
749
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700750static void process_config_params(const XML_Char **attr)
751{
752 if (strcmp(attr[0], "key") != 0) {
753 ALOGE("%s: 'key' not found", __func__);
754 goto done;
755 }
756
757 if (strcmp(attr[2], "value") != 0) {
758 ALOGE("%s: 'value' not found", __func__);
759 goto done;
760 }
761
762 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700763 if (my_data.caller == PLATFORM)
764 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700765done:
766 return;
767}
768
Aalique Grahame22e49102018-12-18 14:23:57 -0800769static void process_app_type(const XML_Char **attr)
770{
771 if (strcmp(attr[0], "uc_type")) {
772 ALOGE("%s: uc_type not found", __func__);
773 goto done;
774 }
775
776 if (strcmp(attr[2], "mode")) {
777 ALOGE("%s: mode not found", __func__);
778 goto done;
779 }
780
781 if (strcmp(attr[4], "bit_width")) {
782 ALOGE("%s: bit_width not found", __func__);
783 goto done;
784 }
785
786 if (strcmp(attr[6], "id")) {
787 ALOGE("%s: id not found", __func__);
788 goto done;
789 }
790
791 if (strcmp(attr[8], "max_rate")) {
792 ALOGE("%s: max rate not found", __func__);
793 goto done;
794 }
795
796 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
797 atoi(attr[9]));
798done:
799 return;
800}
801
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530802static void process_microphone_characteristic(const XML_Char **attr) {
803 struct audio_microphone_characteristic_t microphone;
804 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530805 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530806
Saurav Kumardba3caf2020-05-29 20:53:55 +0530807 strlcpy(platform_info_xml_path, get_platform_xml_path(),
808 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530809 if (strcmp(attr[curIdx++], "valid_mask")) {
810 ALOGE("%s: valid_mask not found", __func__);
811 goto done;
812 }
813 uint32_t valid_mask = atoi(attr[curIdx++]);
814
815 if (strcmp(attr[curIdx++], "device_id")) {
816 ALOGE("%s: device_id not found", __func__);
817 goto done;
818 }
819 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
820 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
821 goto done;
822 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530823 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530824
825 if (strcmp(attr[curIdx++], "type")) {
826 ALOGE("%s: device not found", __func__);
827 goto done;
828 }
829 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
830 ARRAY_SIZE(device_in_types), &microphone.device)) {
831 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530832 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530833 goto done;
834 }
835
836 if (strcmp(attr[curIdx++], "address")) {
837 ALOGE("%s: address not found", __func__);
838 goto done;
839 }
840 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
841 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
842 goto done;
843 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530844 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530845 if (strlen(microphone.address) == 0) {
846 // If the address is empty, populate the address according to device type.
847 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530848 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530849 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530850 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530851 }
852 }
853
854 if (strcmp(attr[curIdx++], "location")) {
855 ALOGE("%s: location not found", __func__);
856 goto done;
857 }
858 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
859 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
860 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530861 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530862 goto done;
863 }
864
865 if (strcmp(attr[curIdx++], "group")) {
866 ALOGE("%s: group not found", __func__);
867 goto done;
868 }
869 microphone.group = atoi(attr[curIdx++]);
870
871 if (strcmp(attr[curIdx++], "index_in_the_group")) {
872 ALOGE("%s: index_in_the_group not found", __func__);
873 goto done;
874 }
875 microphone.index_in_the_group = atoi(attr[curIdx++]);
876
877 if (strcmp(attr[curIdx++], "directionality")) {
878 ALOGE("%s: directionality not found", __func__);
879 goto done;
880 }
881 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
882 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
883 ALOGE("%s: directionality %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530884 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530885 goto done;
886 }
887
888 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
889 ALOGE("%s: num_frequency_responses not found", __func__);
890 goto done;
891 }
892 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530893 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530894 ALOGE("%s: num_frequency_responses is too large", __func__);
895 goto done;
896 }
897 if (microphone.num_frequency_responses > 0) {
898 if (strcmp(attr[curIdx++], "frequencies")) {
899 ALOGE("%s: frequencies not found", __func__);
900 goto done;
901 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530902 char *context = NULL;
903 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530904 uint32_t num_frequencies = 0;
905 while (token) {
906 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800907 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530908 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530909 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530910 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530911 }
912
913 if (strcmp(attr[curIdx++], "responses")) {
914 ALOGE("%s: responses not found", __func__);
915 goto done;
916 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530917 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530918 uint32_t num_responses = 0;
919 while (token) {
920 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800921 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530922 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530923 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530924 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530925 }
926
927 if (num_frequencies != num_responses
928 || num_frequencies != microphone.num_frequency_responses) {
929 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
930 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
931 goto done;
932 }
933 }
934
935 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
936 if (strcmp(attr[curIdx++], "sensitivity")) {
937 ALOGE("%s: sensitivity not found", __func__);
938 goto done;
939 }
940 microphone.sensitivity = atof(attr[curIdx++]);
941 } else {
942 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
943 }
944
945 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
946 if (strcmp(attr[curIdx++], "max_spl")) {
947 ALOGE("%s: max_spl not found", __func__);
948 goto done;
949 }
950 microphone.max_spl = atof(attr[curIdx++]);
951 } else {
952 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
953 }
954
955 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
956 if (strcmp(attr[curIdx++], "min_spl")) {
957 ALOGE("%s: min_spl not found", __func__);
958 goto done;
959 }
960 microphone.min_spl = atof(attr[curIdx++]);
961 } else {
962 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
963 }
964
965 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
966 if (strcmp(attr[curIdx++], "orientation")) {
967 ALOGE("%s: orientation not found", __func__);
968 goto done;
969 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530970 char *context = NULL;
971 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530972 float orientation[3];
973 uint32_t idx = 0;
974 while (token) {
975 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800976 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530977 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530978 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530979 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530980 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530981 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530982 ALOGE("%s: orientation invalid", __func__);
983 goto done;
984 }
985 microphone.orientation.x = orientation[0];
986 microphone.orientation.y = orientation[1];
987 microphone.orientation.z = orientation[2];
988 } else {
989 microphone.orientation.x = 0.0f;
990 microphone.orientation.y = 0.0f;
991 microphone.orientation.z = 0.0f;
992 }
993
994 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
995 if (strcmp(attr[curIdx++], "geometric_location")) {
996 ALOGE("%s: geometric_location not found", __func__);
997 goto done;
998 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530999 char *context = NULL;
1000 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301001 float geometric_location[3];
1002 uint32_t idx = 0;
1003 while (token) {
1004 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001005 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301006 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301007 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301008 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301009 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301010 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301011 ALOGE("%s: geometric_location invalid", __func__);
1012 goto done;
1013 }
1014 microphone.geometric_location.x = geometric_location[0];
1015 microphone.geometric_location.y = geometric_location[1];
1016 microphone.geometric_location.z = geometric_location[2];
1017 } else {
1018 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1019 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1020 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1021 }
1022
1023 platform_set_microphone_characteristic(my_data.platform, microphone);
1024done:
1025 return;
1026}
1027
1028static void process_snd_dev(const XML_Char **attr)
1029{
1030 uint32_t curIdx = 0;
1031 in_snd_device = SND_DEVICE_NONE;
1032
1033 if (strcmp(attr[curIdx++], "in_snd_device")) {
1034 ALOGE("%s: snd_device not found", __func__);
1035 return;
1036 }
1037 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1038 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1039 in_snd_device >= SND_DEVICE_IN_END) {
1040 ALOGE("%s: Sound device not valid", __func__);
1041 in_snd_device = SND_DEVICE_NONE;
1042 }
1043
1044 return;
1045}
1046
1047static void process_mic_info(const XML_Char **attr)
1048{
1049 uint32_t curIdx = 0;
1050 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301051 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301052
Saurav Kumardba3caf2020-05-29 20:53:55 +05301053 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1054 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301055 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1056 sizeof(microphone.channel_mapping));
1057
1058 if (strcmp(attr[curIdx++], "mic_device_id")) {
1059 ALOGE("%s: mic_device_id not found", __func__);
1060 goto on_error;
1061 }
1062 strlcpy(microphone.device_id,
1063 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1064
1065 if (strcmp(attr[curIdx++], "channel_mapping")) {
1066 ALOGE("%s: channel_mapping not found", __func__);
1067 goto on_error;
1068 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301069 char *context = NULL;
1070 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301071 uint32_t idx = 0;
1072 while (token) {
1073 if (!find_enum_by_string(mic_channel_mapping, token,
1074 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1075 &microphone.channel_mapping[idx++])) {
1076 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301077 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301078 goto on_error;
1079 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301080 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301081 }
1082 microphone.channel_count = idx;
1083
1084 platform_set_microphone_map(my_data.platform, in_snd_device,
1085 &microphone);
1086 return;
1087on_error:
1088 in_snd_device = SND_DEVICE_NONE;
1089 return;
1090}
1091
1092
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301093/* process acdb meta info key value */
1094static void process_acdb_metainfo_key(const XML_Char **attr)
1095{
1096 if (strcmp(attr[0], "name") != 0) {
1097 ALOGE("%s: 'name' not found", __func__);
1098 goto done;
1099 }
1100
1101 if (strcmp(attr[2], "value") != 0) {
1102 ALOGE("%s: 'value' not found", __func__);
1103 goto done;
1104 }
1105
1106 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001107 switch(my_data.caller) {
1108 case ACDB_EXTN:
1109 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1110 ALOGE("%s: key %d was not set!", __func__, key);
1111 goto done;
1112 }
1113 break;
1114 case PLATFORM:
1115 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1116 ALOGE("%s: key %d was not set!", __func__, key);
1117 goto done;
1118 }
1119 break;
1120 default:
1121 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301122 }
1123
1124done:
1125 return;
1126}
1127
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301128static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1129{
1130 uint32_t attr_idx = 0;
1131 int32_t in_ch_idx = -1;
1132 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1133
1134 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1135 &mtmx_in_params_info);
1136 if (mtmx_in_params == NULL) {
1137 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1138 return;
1139 }
1140
1141 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1142 ALOGE("%s: 'in_channel_index' not found", __func__);
1143 return;
1144 }
1145
1146 in_ch_idx = atoi((char *)attr[attr_idx++]);
1147 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1148 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1149 return;
1150 }
1151
1152 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1153 ALOGE("%s: 'channel_count' not found", __func__);
1154 return;
1155 }
1156 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1157
1158 if (strcmp(attr[attr_idx++], "device") != 0) {
1159 ALOGE("%s: 'device' not found", __func__);
1160 return;
1161 }
1162 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1163 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1164
1165 if (strcmp(attr[attr_idx++], "interface") != 0) {
1166 ALOGE("%s: 'interface' not found", __func__);
1167 return;
1168 }
1169 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1170 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1171
1172 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1173 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1174 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1175 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1176 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1177 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1178 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1179 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1180
1181 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1182}
1183
1184static void process_custom_mtmx_in_params(const XML_Char **attr)
1185{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301186 int attr_idx = 0, i = 0;
1187 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301188
1189 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1190 ALOGE("%s: 'usecase' not found", __func__);
1191 return;
1192 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301193 /* Check if multi usecases are supported for this custom mtrx params */
1194 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1195 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1196 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1197 value = strtok_r(NULL, ",", &context);
1198 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301199
1200 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1201 ALOGE("%s: 'out_channel_count' not found", __func__);
1202 return;
1203 }
1204 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1205
1206 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1207
1208}
1209
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301210static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1211{
1212 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301213 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301214 char *context = NULL, *ch_coeff_value = NULL;
1215 struct audio_custom_mtmx_params *mtmx_params = NULL;
1216
1217 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1218 ALOGE("%s: 'out_channel_index' not found", __func__);
1219 return;
1220 }
1221 out_ch_idx = atoi((char *)attr[attr_idx++]);
1222
1223 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1224 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1225 return;
1226 }
1227
1228 if (strcmp(attr[attr_idx++], "values") != 0) {
1229 ALOGE("%s: 'values' not found", __func__);
1230 return;
1231 }
1232 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301233 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301234 if (mtmx_params == NULL) {
1235 ALOGE("%s: mtmx params with given param info, not found", __func__);
1236 return;
1237 }
1238 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1239 ip_channels = mtmx_params->info.ip_channels;
1240 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301241 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301242 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1243 = atoi(ch_coeff_value);
1244 ch_coeff_value = strtok_r(NULL, " ", &context);
1245 }
1246 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1247 ch_coeff_value != NULL)
1248 ALOGE("%s: invalid/malformed coefficient values", __func__);
1249}
1250
1251static void process_custom_mtmx_params(const XML_Char **attr)
1252{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301253 int attr_idx = 0, i = 0;
1254 char *context = NULL, *value = NULL;
1255
1256 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301257
1258 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1259 ALOGE("%s: 'param_id' not found", __func__);
1260 return;
1261 }
1262 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1263
1264 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1265 ALOGE("%s: 'in_channel_count' not found", __func__);
1266 return;
1267 }
1268 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1269
1270 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1271 ALOGE("%s: 'out_channel_count' not found", __func__);
1272 return;
1273 }
1274 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1275
1276 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1277 ALOGE("%s: 'usecase' not found", __func__);
1278 return;
1279 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301280
1281 /* check if multi usecases are supported for this custom mtrx params */
1282 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1283 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1284 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1285 value = strtok_r(NULL, ",", &context);
1286 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301287
1288 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1289 ALOGE("%s: 'snd_device' not found", __func__);
1290 return;
1291 }
1292 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301293
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301294 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1295 i = 0;
1296 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1297 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1298 mtmx_params_info.fe_id[i++] = atoi(value);
1299 value = strtok_r(NULL, ",", &context);
1300 }
1301
1302 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301303 }
1304
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301305 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1306
1307}
1308
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001309static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001310 const XML_Char **attr)
1311{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001312 if (my_data.caller == ACDB_EXTN) {
1313 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1314 section = ACDB_METAINFO_KEY;
1315 } else if (strcmp(tag_name, "param") == 0) {
1316 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1317 ALOGE("param tag only supported with CONFIG_PARAMS section");
1318 return;
1319 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001320
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001321 section_process_fn fn = section_table[section];
1322 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001323 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001324 } else if(my_data.caller == PLATFORM) {
1325 if (strcmp(tag_name, "bit_width_configs") == 0) {
1326 section = BITWIDTH;
1327 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1328 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001329 } else if (strcmp(tag_name, "module_ids") == 0) {
1330 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001331 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1332 section = PCM_ID;
1333 } else if (strcmp(tag_name, "backend_names") == 0) {
1334 section = BACKEND_NAME;
1335 } else if (strcmp(tag_name, "config_params") == 0) {
1336 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001337 } else if (strcmp(tag_name, "operator_specific") == 0) {
1338 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001339 } else if (strcmp(tag_name, "interface_names") == 0) {
1340 section = INTERFACE_NAME;
1341 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1342 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001343 } else if (strcmp(tag_name, "app_types") == 0) {
1344 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001345 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1346 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301347 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1348 section = MICROPHONE_CHARACTERISTIC;
1349 } else if (strcmp(tag_name, "snd_devices") == 0) {
1350 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001351 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001352 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001353 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001354 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001355 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1356 return;
1357 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001358
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001359 /* call into process function for the current section */
1360 section_process_fn fn = section_table[section];
1361 fn(attr);
1362 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1363 if (section != GAIN_LEVEL_MAPPING) {
1364 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1365 return;
1366 }
1367
1368 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1369 fn(attr);
1370 } else if (strcmp(tag_name, "usecase") == 0) {
1371 if (section != PCM_ID) {
1372 ALOGE("usecase tag only supported with PCM_ID section");
1373 return;
1374 }
1375
1376 section_process_fn fn = section_table[PCM_ID];
1377 fn(attr);
1378 } else if (strcmp(tag_name, "param") == 0) {
1379 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1380 ALOGE("param tag only supported with CONFIG_PARAMS section");
1381 return;
1382 }
1383
1384 section_process_fn fn = section_table[section];
1385 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301386 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001387 if (section != MODULE) {
1388 ALOGE("aec tag only supported with MODULE section");
1389 return;
1390 }
1391 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301392 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001393 if (section != MODULE) {
1394 ALOGE("ns tag only supported with MODULE section");
1395 return;
1396 }
1397 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001398 } else if (strcmp(tag_name, "mmsecns") == 0) {
1399 if (section != MODULE) {
1400 ALOGE("mmsecns tag only supported with MODULE section");
1401 return;
1402 }
1403 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001404 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1405 if (section != GAIN_LEVEL_MAPPING) {
1406 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1407 return;
1408 }
1409
1410 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1411 fn(attr);
1412 } else if (!strcmp(tag_name, "app")) {
1413 if (section != APP_TYPE) {
1414 ALOGE("app tag only valid in section APP_TYPE");
1415 return;
1416 }
1417
1418 section_process_fn fn = section_table[APP_TYPE];
1419 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301420 } else if (strcmp(tag_name, "microphone") == 0) {
1421 if (section != MICROPHONE_CHARACTERISTIC) {
1422 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1423 return;
1424 }
1425 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1426 fn(attr);
1427 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1428 if (section != SND_DEVICES) {
1429 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1430 return;
1431 }
1432 section = INPUT_SND_DEVICE;
1433 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1434 if (section != INPUT_SND_DEVICE) {
1435 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1436 return;
1437 }
1438 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1439 } else if (strcmp(tag_name, "snd_dev") == 0) {
1440 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1441 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1442 return;
1443 }
1444 section_process_fn fn = section_table[SND_DEV];
1445 fn(attr);
1446 } else if (strcmp(tag_name, "mic_info") == 0) {
1447 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1448 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1449 return;
1450 }
1451 if (in_snd_device == SND_DEVICE_NONE) {
1452 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1453 return;
1454 }
1455 section_process_fn fn = section_table[MIC_INFO];
1456 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301457 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1458 if (section != ROOT) {
1459 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1460 return;
1461 }
1462 section = CUSTOM_MTMX_PARAMS;
1463 section_process_fn fn = section_table[section];
1464 fn(attr);
1465 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1466 if (section != CUSTOM_MTMX_PARAMS) {
1467 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1468 return;
1469 }
1470 section = CUSTOM_MTMX_PARAM_COEFFS;
1471 section_process_fn fn = section_table[section];
1472 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001473 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1474 section = EXTERNAL_DEVICE_SPECIFIC;
1475 } else if (strcmp(tag_name, "ext_device") == 0) {
1476 section_process_fn fn = section_table[section];
1477 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301478 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1479 if (section != ROOT) {
1480 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1481 return;
1482 }
1483 section = CUSTOM_MTMX_IN_PARAMS;
1484 section_process_fn fn = section_table[section];
1485 fn(attr);
1486 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1487 if (section != CUSTOM_MTMX_IN_PARAMS) {
1488 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1489 return;
1490 }
1491 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Juyu Chen918e1e12019-08-08 15:28:18 -07001492 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1493 section = AUDIO_SOURCE_DELAY;
1494 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301495 section_process_fn fn = section_table[section];
1496 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301497 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001498 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001499 if(strcmp(tag_name, "config_params") == 0) {
1500 section = CONFIG_PARAMS;
1501 } else if (strcmp(tag_name, "param") == 0) {
1502 if (section != CONFIG_PARAMS) {
1503 ALOGE("param tag only supported with CONFIG_PARAMS section");
1504 return;
1505 }
1506
1507 section_process_fn fn = section_table[section];
1508 fn(attr);
1509 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001510 }
Ben Romberger55886882014-01-10 13:49:02 -08001511 return;
1512}
1513
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001514static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001515{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001516 if (strcmp(tag_name, "bit_width_configs") == 0) {
1517 section = ROOT;
1518 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001519 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001520 } else if (strcmp(tag_name, "module_ids") == 0) {
1521 section = ROOT;
1522 } else if (strcmp(tag_name, "aec") == 0) {
1523 section = MODULE;
1524 } else if (strcmp(tag_name, "ns") == 0) {
1525 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001526 } else if (strcmp(tag_name, "mmsecns") == 0) {
1527 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001528 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1529 section = ROOT;
1530 } else if (strcmp(tag_name, "backend_names") == 0) {
1531 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001532 } else if (strcmp(tag_name, "config_params") == 0) {
1533 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001534 } else if (strcmp(tag_name, "operator_specific") == 0) {
1535 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001536 } else if (strcmp(tag_name, "interface_names") == 0) {
1537 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001538 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1539 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001540 } else if (strcmp(tag_name, "app_types") == 0) {
1541 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301542 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1543 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301544 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1545 section = ROOT;
1546 } else if (strcmp(tag_name, "snd_devices") == 0) {
1547 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001548 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1549 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301550 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1551 section = SND_DEVICES;
1552 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1553 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301554 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1555 section = ROOT;
1556 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1557 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301558 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1559 section = ROOT;
1560 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1561 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001562 }
Ben Romberger55886882014-01-10 13:49:02 -08001563}
1564
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001565int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001566{
1567 XML_Parser parser;
1568 FILE *file;
1569 int ret = 0;
1570 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001571 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001572 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301573 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001574
Saurav Kumardba3caf2020-05-29 20:53:55 +05301575 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1576 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001577 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001578 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301579 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001580 MIXER_PATH_MAX_LENGTH);
1581 else
1582 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1583
1584 ALOGV("%s: platform info file name is %s", __func__,
1585 platform_info_file_name);
1586
1587 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001588 section = ROOT;
1589
Ben Romberger55886882014-01-10 13:49:02 -08001590 if (!file) {
1591 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001592 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001593 ret = -ENODEV;
1594 goto done;
1595 }
1596
1597 parser = XML_ParserCreate(NULL);
1598 if (!parser) {
1599 ALOGE("%s: Failed to create XML parser!", __func__);
1600 ret = -ENODEV;
1601 goto err_close_file;
1602 }
1603
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001604 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001605 my_data.platform = platform;
1606 my_data.kvpairs = str_parms_create();
1607
Ben Romberger55886882014-01-10 13:49:02 -08001608 XML_SetElementHandler(parser, start_tag, end_tag);
1609
1610 while (1) {
1611 buf = XML_GetBuffer(parser, BUF_SIZE);
1612 if (buf == NULL) {
1613 ALOGE("%s: XML_GetBuffer failed", __func__);
1614 ret = -ENOMEM;
1615 goto err_free_parser;
1616 }
1617
1618 bytes_read = fread(buf, 1, BUF_SIZE, file);
1619 if (bytes_read < 0) {
1620 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1621 ret = bytes_read;
1622 goto err_free_parser;
1623 }
1624
1625 if (XML_ParseBuffer(parser, bytes_read,
1626 bytes_read == 0) == XML_STATUS_ERROR) {
1627 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001628 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001629 ret = -EINVAL;
1630 goto err_free_parser;
1631 }
1632
1633 if (bytes_read == 0)
1634 break;
1635 }
1636
Ben Romberger55886882014-01-10 13:49:02 -08001637err_free_parser:
1638 XML_ParserFree(parser);
1639err_close_file:
1640 fclose(file);
1641done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001642 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001643 return ret;
1644}