blob: de7f187225c5f6923a9fc01abb7f61edf018192b [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.
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +053028
29 * Changes from Qualcomm Innovation Center are provided under the following license:
30
31 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
32
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted (subject to the limitations in the
35 * disclaimer below) provided that the following conditions are met:
36
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39
40 * * Redistributions in binary form must reproduce the above
41 * copyright notice, this list of conditions and the following
42 * disclaimer in the documentation and/or other materials provided
43 * with the distribution.
44
45 * * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
48
49 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
50 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
51 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
52 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
55 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
57 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
58 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
59 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
61 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Ben Romberger55886882014-01-10 13:49:02 -080062 */
63
Ben Romberger61764e32014-01-10 13:49:02 -080064#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080065#define LOG_NDDEBUG 0
66
67#include <errno.h>
68#include <stdio.h>
69#include <expat.h>
Jiangen Jiao334224b2019-09-12 15:47:46 +080070#include <pthread.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080071#include <log/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070072#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080073#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070074#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080075#include "platform_api.h"
Saurav Kumardba3caf2020-05-29 20:53:55 +053076#include "audio_extn.h"
Ben Romberger61764e32014-01-10 13:49:02 -080077#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070078#include <math.h>
Fei Tongc20ce932021-06-21 16:42:38 +080079#ifdef LINUX_ENABLED
80#include <float.h>
81#endif
Ben Romberger55886882014-01-10 13:49:02 -080082
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053083#ifdef DYNAMIC_LOG_ENABLED
84#include <log_xml_parser.h>
85#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
86#include <log_utils.h>
87#endif
88
Ben Romberger55886882014-01-10 13:49:02 -080089#define BUF_SIZE 1024
Saurav Kumardba3caf2020-05-29 20:53:55 +053090char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH];
91char platform_info_xml_path_file[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -080092
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070093typedef enum {
94 ROOT,
95 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070096 MODULE,
97 AEC,
98 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070099 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700100 PCM_ID,
101 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800102 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700103 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -0800104 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700105 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -0800106 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530107 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530108 MICROPHONE_CHARACTERISTIC,
109 SND_DEVICES,
110 INPUT_SND_DEVICE,
111 INPUT_SND_DEVICE_TO_MIC_MAPPING,
112 SND_DEV,
113 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530114 CUSTOM_MTMX_PARAMS,
115 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -0700116 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530117 CUSTOM_MTMX_IN_PARAMS,
118 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +0800119 MMSECNS,
Juyu Chen918e1e12019-08-08 15:28:18 -0700120 AUDIO_SOURCE_DELAY,
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +0530121#ifdef SOFT_VOLUME
122 SOFT_VOLUME_PARAMS,
123#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700124} section_t;
125
126typedef void (* section_process_fn)(const XML_Char **attr);
127
Saurav Kumardba3caf2020-05-29 20:53:55 +0530128const char* get_platform_xml_path()
129{
130 audio_get_vendor_config_path(vendor_config_path, sizeof(vendor_config_path));
131 /* Get path for platorm_info_xml_path_name in vendor */
132 snprintf(platform_info_xml_path_file, sizeof(platform_info_xml_path_file),
133 "%s/%s", vendor_config_path, PLATFORM_INFO_XML_PATH_NAME);
134 return platform_info_xml_path_file;
135}
136
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700137static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700138static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
139static void process_effect_aec(const XML_Char **attr);
140static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -0700141static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700142static void process_pcm_id(const XML_Char **attr);
143static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800144static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700145static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700146static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800147static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700148static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800149static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530150static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530151static void process_microphone_characteristic(const XML_Char **attr);
152static void process_snd_dev(const XML_Char **attr);
153static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530154static void process_custom_mtmx_params(const XML_Char **attr);
155static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700156static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530157static void process_custom_mtmx_in_params(const XML_Char **attr);
158static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Guodong Hu1d46f342019-06-28 16:57:30 +0800159static void process_fluence_mmsecns(const XML_Char **attr);
Juyu Chen918e1e12019-08-08 15:28:18 -0700160static void process_audio_source_delay(const XML_Char **attr);
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +0530161#ifdef SOFT_VOLUME
162static void process_soft_volume_params(const XML_Char **attr);
163#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700164
165static section_process_fn section_table[] = {
166 [ROOT] = process_root,
167 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700168 [AEC] = process_effect_aec,
169 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700170 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700171 [PCM_ID] = process_pcm_id,
172 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800173 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700174 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800175 [OPERATOR_SPECIFIC] = process_operator_specific,
176 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700177 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530178 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530179 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
180 [SND_DEV] = process_snd_dev,
181 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530182 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
183 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700184 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530185 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
186 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800187 [MMSECNS] = process_fluence_mmsecns,
Juyu Chen918e1e12019-08-08 15:28:18 -0700188 [AUDIO_SOURCE_DELAY] = process_audio_source_delay,
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +0530189#ifdef SOFT_VOLUME
190 [SOFT_VOLUME_PARAMS] = process_soft_volume_params,
191#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700192};
193
194static section_t section;
195
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700196struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700197 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700198 void *platform;
199 struct str_parms *kvpairs;
200};
201
202static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800203static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700204
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530205
206struct audio_string_to_enum {
207 const char* name;
208 unsigned int value;
209};
210
211static snd_device_t in_snd_device;
212
213static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
214 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
215 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
216 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
217 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
218};
219
220static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
221 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
222 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
223 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
224 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
225 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
226 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
227};
228
229static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
230 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
231 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
232 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
233};
234
235static const struct audio_string_to_enum device_in_types[] = {
236 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
237 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
238 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
239 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
240 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
241 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
242 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
243 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
244 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
245 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
246 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
247 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
248 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
249 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
250 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
251 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
252 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
253 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
254 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
255 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
256 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
257 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
258 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
259 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
260 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
261 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
262 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
263};
264
265enum {
266 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
267 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
268 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
269 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
270 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
271 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
272 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
273 | ORIENTATION) | GEOMETRIC_LOCATION) */
274};
275
276static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
277 int32_t len, unsigned int *value)
278{
279 if (table == NULL) {
280 ALOGE("%s: table is NULL", __func__);
281 return false;
282 }
283
284 if (name == NULL) {
285 ALOGE("null key");
286 return false;
287 }
288
289 for (int i = 0; i < len; i++) {
290 if (!strcmp(table[i].name, name)) {
291 *value = table[i].value;
292 return true;
293 }
294 }
295 return false;
296}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530297
298static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530299static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530300
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700301static void process_root(const XML_Char **attr __unused)
302{
303}
304
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +0530305#ifdef SOFT_VOLUME
306/**mapping usecase and soft volume params **/
307static void process_soft_volume_params(const XML_Char **attr)
308{
309 int index;
310
311 if (strcmp(attr[0], "name") != 0) {
312 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
313 goto done;
314 }
315
316 index = platform_get_usecase_index((char *)attr[1]);
317 if (index < 0) {
318 ALOGE("%s: usecase %s not found!",
319 __func__, attr[1]);
320 goto done;
321 }
322
323 if (strcmp(attr[2], "period") != 0) {
324 ALOGE("%s: ramp period not mentioned", __func__);
325 goto done;
326 }
327
328 int period = atoi((char *)attr[3]);
329
330 if (strcmp(attr[4], "step") != 0) {
331 ALOGE("%s: ramp period not mentioned", __func__);
332 goto done;
333 }
334 int step = atoi((char *)attr[5]);
335
336 if (strcmp(attr[6], "curve") != 0) {
337 ALOGE("%s: usecase id not mentioned", __func__);
338 goto done;
339 }
340
341 int curve = atoi((char *)attr[7]);
342
343 if (platform_set_soft_step_volume_params(index, period, step, curve) < 0) {
344 ALOGE("%s: usecase %s period %d step %d curve %d ",
345 __func__, attr[1], period, step, curve);
346 goto done;
347 }
348
349done:
350 return;
351}
352#endif
353
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700354/* mapping from usecase to pcm dev id */
355static void process_pcm_id(const XML_Char **attr)
356{
357 int index;
358
359 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700360 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700361 goto done;
362 }
363
364 index = platform_get_usecase_index((char *)attr[1]);
365 if (index < 0) {
366 ALOGE("%s: usecase %s not found!",
367 __func__, attr[1]);
368 goto done;
369 }
370
371 if (strcmp(attr[2], "type") != 0) {
372 ALOGE("%s: usecase type not mentioned", __func__);
373 goto done;
374 }
375
376 int type = -1;
377
378 if (!strcasecmp((char *)attr[3], "in")) {
379 type = 1;
380 } else if (!strcasecmp((char *)attr[3], "out")) {
381 type = 0;
382 } else {
383 ALOGE("%s: type must be IN or OUT", __func__);
384 goto done;
385 }
386
387 if (strcmp(attr[4], "id") != 0) {
388 ALOGE("%s: usecase id not mentioned", __func__);
389 goto done;
390 }
391
392 int id = atoi((char *)attr[5]);
393
394 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
395 ALOGE("%s: usecase %s type %d id %d was not set!",
396 __func__, attr[1], type, id);
397 goto done;
398 }
399
400done:
401 return;
402}
403
404/* backend to be used for a device */
405static void process_backend_name(const XML_Char **attr)
406{
407 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530408 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530409 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700410
411 if (strcmp(attr[0], "name") != 0) {
412 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
413 goto done;
414 }
415
416 index = platform_get_snd_device_index((char *)attr[1]);
417 if (index < 0) {
418 ALOGE("%s: Device %s not found, no ACDB ID set!",
419 __func__, attr[1]);
420 goto done;
421 }
422
423 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530424 if (strcmp(attr[2], "interface") == 0)
425 hw_interface = (char *)attr[3];
426 } else {
427 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700428 }
429
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530430 if (attr[4] != NULL) {
431 if (strcmp(attr[4], "interface") != 0) {
432 hw_interface = NULL;
433 } else {
434 hw_interface = (char *)attr[5];
435 }
436 }
437
Ashish Jaind150d4c2017-02-03 18:44:34 +0530438 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700439 ALOGE("%s: Device %s backend %s was not set!",
440 __func__, attr[1], attr[3]);
441 goto done;
442 }
443
444done:
445 return;
446}
447
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700448static void process_gain_db_to_level_map(const XML_Char **attr)
449{
450 struct amp_db_and_gain_table tbl_entry;
451
452 if ((strcmp(attr[0], "db") != 0) ||
453 (strcmp(attr[2], "level") != 0)) {
454 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
455 __func__, attr[0], attr[2]);
456 goto done;
457 }
458
459 tbl_entry.db = atof(attr[1]);
460 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
461 tbl_entry.level = atoi(attr[3]);
462
Aalique Grahame22e49102018-12-18 14:23:57 -0800463 //custome level should be > 0. Level 0 is fixed for default
464 CHECK(tbl_entry.level > 0);
465
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700466 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
467 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
468 platform_add_gain_level_mapping(&tbl_entry);
469
470done:
471 return;
472}
473
474
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700475static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800476{
Ben Romberger61764e32014-01-10 13:49:02 -0800477 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800478
Ben Romberger61764e32014-01-10 13:49:02 -0800479 if (strcmp(attr[0], "name") != 0) {
480 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800481 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800482 }
Ben Romberger55886882014-01-10 13:49:02 -0800483
Ben Romberger61764e32014-01-10 13:49:02 -0800484 index = platform_get_snd_device_index((char *)attr[1]);
485 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800486 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
487 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800488 goto done;
489 }
490
491 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800492 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
493 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800494 goto done;
495 }
496
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700497 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
498 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800499 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800500 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800501 }
Ben Romberger55886882014-01-10 13:49:02 -0800502
Ben Romberger55886882014-01-10 13:49:02 -0800503done:
504 return;
505}
506
Aalique Grahame22e49102018-12-18 14:23:57 -0800507static void process_operator_specific(const XML_Char **attr)
508{
509 snd_device_t snd_device = SND_DEVICE_NONE;
510
511 if (strcmp(attr[0], "name") != 0) {
512 ALOGE("%s: 'name' not found", __func__);
513 goto done;
514 }
515
516 snd_device = platform_get_snd_device_index((char *)attr[1]);
517 if (snd_device < 0) {
518 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530519 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800520 goto done;
521 }
522
523 if (strcmp(attr[2], "operator") != 0) {
524 ALOGE("%s: 'operator' not found", __func__);
525 goto done;
526 }
527
528 if (strcmp(attr[4], "mixer_path") != 0) {
529 ALOGE("%s: 'mixer_path' not found", __func__);
530 goto done;
531 }
532
533 if (strcmp(attr[6], "acdb_id") != 0) {
534 ALOGE("%s: 'acdb_id' not found", __func__);
535 goto done;
536 }
537
538 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
539
540done:
541 return;
542}
543
Carter Hsu32a62362018-10-15 15:01:42 -0700544static void process_external_dev(const XML_Char **attr)
545{
546 snd_device_t snd_device = SND_DEVICE_NONE;
547
548 if (strcmp(attr[0], "name") != 0) {
549 ALOGE("%s: 'name' not found", __func__);
550 goto done;
551 }
552
553 snd_device = platform_get_snd_device_index((char *)attr[1]);
554 if (snd_device < 0) {
555 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530556 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700557 goto done;
558 }
559
560 if (strcmp(attr[2], "usbid") != 0) {
561 ALOGE("%s: 'usbid' not found", __func__);
562 goto done;
563 }
564
565 if (strcmp(attr[4], "acdb_id") != 0) {
566 ALOGE("%s: 'acdb_id' not found", __func__);
567 goto done;
568 }
569
570 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
571
572done:
573 return;
574}
575
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700576static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
577{
578 int index;
579 struct audio_effect_config effect_config;
580
581 if (strcmp(attr[0], "name") != 0) {
582 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
583 goto done;
584 }
585
586 index = platform_get_snd_device_index((char *)attr[1]);
587 if (index < 0) {
588 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
589 __func__, attr[1]);
590 goto done;
591 }
592
593 if (strcmp(attr[2], "module_id") != 0) {
594 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
595 __func__, attr[2]);
596 goto done;
597 }
598
599 if (strcmp(attr[4], "instance_id") != 0) {
600 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
601 __func__, attr[4]);
602 goto done;
603 }
604
605 if (strcmp(attr[6], "param_id") != 0) {
606 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
607 __func__, attr[6]);
608 goto done;
609 }
610
611 if (strcmp(attr[8], "param_value") != 0) {
612 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
613 __func__, attr[8]);
614 goto done;
615 }
616
617 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
618 strtol((char *)attr[5], NULL, 0),
619 strtol((char *)attr[7], NULL, 0),
620 strtol((char *)attr[9], NULL, 0)};
621
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700622 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
623 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
624 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
625 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
626 strtol((char *)attr[9], NULL, 0));
627 goto done;
628 }
629
630done:
631 return;
632}
633
634static void process_effect_aec(const XML_Char **attr)
635{
636 process_audio_effect(attr, EFFECT_AEC);
637 return;
638}
639
640static void process_effect_ns(const XML_Char **attr)
641{
642 process_audio_effect(attr, EFFECT_NS);
643 return;
644}
645
Guodong Hu1d46f342019-06-28 16:57:30 +0800646static void process_fluence_mmsecns(const XML_Char **attr)
647{
648 int index;
649 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
650
651 if (strcmp(attr[0], "name") != 0) {
652 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
653 goto done;
654 }
655
656 index = platform_get_snd_device_index((char *)attr[1]);
657 if (index < 0) {
658 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
659 __func__, attr[1]);
660 goto done;
661 }
662
663 if (strcmp(attr[2], "topology_id") != 0) {
664 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
665 __func__, attr[2]);
666 goto done;
667 }
668
669 if (strcmp(attr[4], "module_id") != 0) {
670 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
671 __func__, attr[4]);
672 goto done;
673 }
674
675 if (strcmp(attr[6], "instance_id") != 0) {
676 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
677 __func__, attr[6]);
678 goto done;
679 }
680
681 if (strcmp(attr[8], "param_id") != 0) {
682 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
683 __func__, attr[8]);
684 goto done;
685 }
686
687 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
688 strtol((char *)attr[5], NULL, 0),
689 strtol((char *)attr[7], NULL, 0),
690 strtol((char *)attr[9], NULL, 0)};
691
692
693 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
694 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
695 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
696 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
697 goto done;
698 }
699
700done:
701 return;
702}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700703static void process_bit_width(const XML_Char **attr)
704{
705 int index;
706
707 if (strcmp(attr[0], "name") != 0) {
708 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
709 goto done;
710 }
711
712 index = platform_get_snd_device_index((char *)attr[1]);
713 if (index < 0) {
714 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
715 __func__, attr[1]);
716 goto done;
717 }
718
719 if (strcmp(attr[2], "bit_width") != 0) {
720 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
721 __func__, attr[1]);
722 goto done;
723 }
724
725 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
726 ALOGE("%s: Device %s, ACDB ID %d was not set!",
727 __func__, attr[1], atoi((char *)attr[3]));
728 goto done;
729 }
730
731done:
732 return;
733}
734
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800735static void process_interface_name(const XML_Char **attr)
736{
737 int ret;
738
739 if (strcmp(attr[0], "name") != 0) {
740 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
741
742 goto done;
743 }
744
745 if (strcmp(attr[2], "interface") != 0) {
746 ALOGE("%s: Device %s has no Audio Interface set!",
747 __func__, attr[1]);
748
749 goto done;
750 }
751
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530752 if (strcmp(attr[4], "codec_type") != 0) {
753 ALOGE("%s: Device %s has no codec type set!",
754 __func__, attr[1]);
755
756 goto done;
757 }
758
759 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
760 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800761 if (ret < 0) {
762 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800763 goto done;
764 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800765
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800766done:
767 return;
768}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530769
Juyu Chen918e1e12019-08-08 15:28:18 -0700770static void process_audio_source_delay(const XML_Char **attr)
771{
772 audio_source_t audio_source = -1;
773
774 if (strcmp(attr[0], "name") != 0) {
775 ALOGE("%s: 'name' not found", __func__);
776 goto done;
777 }
George Gao9ba8a142020-07-23 14:30:03 -0700778
Juyu Chen918e1e12019-08-08 15:28:18 -0700779 audio_source = platform_get_audio_source_index((const char *)attr[1]);
780
781 if (audio_source < 0) {
782 ALOGE("%s: audio_source %s is not defined",
783 __func__, (char *)attr[1]);
784 goto done;
785 }
786
787 if (strcmp(attr[2], "delay") != 0) {
788 ALOGE("%s: 'delay' not found", __func__);
789 goto done;
790 }
791
792 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
793
794done:
795 return;
796}
797
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700798static void process_config_params(const XML_Char **attr)
799{
800 if (strcmp(attr[0], "key") != 0) {
801 ALOGE("%s: 'key' not found", __func__);
802 goto done;
803 }
804
805 if (strcmp(attr[2], "value") != 0) {
806 ALOGE("%s: 'value' not found", __func__);
807 goto done;
808 }
809
810 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700811 if (my_data.caller == PLATFORM)
812 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700813done:
814 return;
815}
816
Aalique Grahame22e49102018-12-18 14:23:57 -0800817static void process_app_type(const XML_Char **attr)
818{
819 if (strcmp(attr[0], "uc_type")) {
820 ALOGE("%s: uc_type not found", __func__);
821 goto done;
822 }
823
824 if (strcmp(attr[2], "mode")) {
825 ALOGE("%s: mode not found", __func__);
826 goto done;
827 }
828
829 if (strcmp(attr[4], "bit_width")) {
830 ALOGE("%s: bit_width not found", __func__);
831 goto done;
832 }
833
834 if (strcmp(attr[6], "id")) {
835 ALOGE("%s: id not found", __func__);
836 goto done;
837 }
838
839 if (strcmp(attr[8], "max_rate")) {
840 ALOGE("%s: max rate not found", __func__);
841 goto done;
842 }
843
844 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
845 atoi(attr[9]));
846done:
847 return;
848}
849
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530850static void process_microphone_characteristic(const XML_Char **attr) {
851 struct audio_microphone_characteristic_t microphone;
852 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530853 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530854
Saurav Kumardba3caf2020-05-29 20:53:55 +0530855 strlcpy(platform_info_xml_path, get_platform_xml_path(),
856 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530857 if (strcmp(attr[curIdx++], "valid_mask")) {
858 ALOGE("%s: valid_mask not found", __func__);
859 goto done;
860 }
861 uint32_t valid_mask = atoi(attr[curIdx++]);
862
863 if (strcmp(attr[curIdx++], "device_id")) {
864 ALOGE("%s: device_id not found", __func__);
865 goto done;
866 }
867 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
868 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
869 goto done;
870 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530871 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530872
873 if (strcmp(attr[curIdx++], "type")) {
874 ALOGE("%s: device not found", __func__);
875 goto done;
876 }
877 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
878 ARRAY_SIZE(device_in_types), &microphone.device)) {
879 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530880 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530881 goto done;
882 }
883
884 if (strcmp(attr[curIdx++], "address")) {
885 ALOGE("%s: address not found", __func__);
886 goto done;
887 }
888 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
889 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
890 goto done;
891 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530892 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530893 if (strlen(microphone.address) == 0) {
894 // If the address is empty, populate the address according to device type.
895 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530896 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530897 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530898 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530899 }
900 }
901
902 if (strcmp(attr[curIdx++], "location")) {
903 ALOGE("%s: location not found", __func__);
904 goto done;
905 }
906 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
907 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
908 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530909 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530910 goto done;
911 }
912
913 if (strcmp(attr[curIdx++], "group")) {
914 ALOGE("%s: group not found", __func__);
915 goto done;
916 }
917 microphone.group = atoi(attr[curIdx++]);
918
919 if (strcmp(attr[curIdx++], "index_in_the_group")) {
920 ALOGE("%s: index_in_the_group not found", __func__);
921 goto done;
922 }
923 microphone.index_in_the_group = atoi(attr[curIdx++]);
924
925 if (strcmp(attr[curIdx++], "directionality")) {
926 ALOGE("%s: directionality not found", __func__);
927 goto done;
928 }
929 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
930 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
931 ALOGE("%s: directionality %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530932 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530933 goto done;
934 }
935
936 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
937 ALOGE("%s: num_frequency_responses not found", __func__);
938 goto done;
939 }
940 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530941 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530942 ALOGE("%s: num_frequency_responses is too large", __func__);
943 goto done;
944 }
945 if (microphone.num_frequency_responses > 0) {
946 if (strcmp(attr[curIdx++], "frequencies")) {
947 ALOGE("%s: frequencies not found", __func__);
948 goto done;
949 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530950 char *context = NULL;
951 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530952 uint32_t num_frequencies = 0;
953 while (token) {
954 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800955 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530956 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530957 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530958 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530959 }
960
961 if (strcmp(attr[curIdx++], "responses")) {
962 ALOGE("%s: responses not found", __func__);
963 goto done;
964 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530965 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530966 uint32_t num_responses = 0;
967 while (token) {
968 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800969 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530970 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530971 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530972 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530973 }
974
975 if (num_frequencies != num_responses
976 || num_frequencies != microphone.num_frequency_responses) {
977 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
978 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
979 goto done;
980 }
981 }
982
983 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
984 if (strcmp(attr[curIdx++], "sensitivity")) {
985 ALOGE("%s: sensitivity not found", __func__);
986 goto done;
987 }
988 microphone.sensitivity = atof(attr[curIdx++]);
989 } else {
990 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
991 }
992
993 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
994 if (strcmp(attr[curIdx++], "max_spl")) {
995 ALOGE("%s: max_spl not found", __func__);
996 goto done;
997 }
998 microphone.max_spl = atof(attr[curIdx++]);
999 } else {
1000 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1001 }
1002
1003 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
1004 if (strcmp(attr[curIdx++], "min_spl")) {
1005 ALOGE("%s: min_spl not found", __func__);
1006 goto done;
1007 }
1008 microphone.min_spl = atof(attr[curIdx++]);
1009 } else {
1010 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1011 }
1012
1013 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
1014 if (strcmp(attr[curIdx++], "orientation")) {
1015 ALOGE("%s: orientation not found", __func__);
1016 goto done;
1017 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301018 char *context = NULL;
1019 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301020 float orientation[3];
1021 uint32_t idx = 0;
1022 while (token) {
1023 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001024 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301025 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301026 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301027 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301028 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301029 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301030 ALOGE("%s: orientation invalid", __func__);
1031 goto done;
1032 }
1033 microphone.orientation.x = orientation[0];
1034 microphone.orientation.y = orientation[1];
1035 microphone.orientation.z = orientation[2];
1036 } else {
1037 microphone.orientation.x = 0.0f;
1038 microphone.orientation.y = 0.0f;
1039 microphone.orientation.z = 0.0f;
1040 }
1041
1042 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
1043 if (strcmp(attr[curIdx++], "geometric_location")) {
1044 ALOGE("%s: geometric_location not found", __func__);
1045 goto done;
1046 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301047 char *context = NULL;
1048 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301049 float geometric_location[3];
1050 uint32_t idx = 0;
1051 while (token) {
1052 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001053 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301054 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301055 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301056 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301057 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301058 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301059 ALOGE("%s: geometric_location invalid", __func__);
1060 goto done;
1061 }
1062 microphone.geometric_location.x = geometric_location[0];
1063 microphone.geometric_location.y = geometric_location[1];
1064 microphone.geometric_location.z = geometric_location[2];
1065 } else {
1066 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1067 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1068 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1069 }
1070
1071 platform_set_microphone_characteristic(my_data.platform, microphone);
1072done:
1073 return;
1074}
1075
1076static void process_snd_dev(const XML_Char **attr)
1077{
1078 uint32_t curIdx = 0;
1079 in_snd_device = SND_DEVICE_NONE;
1080
1081 if (strcmp(attr[curIdx++], "in_snd_device")) {
1082 ALOGE("%s: snd_device not found", __func__);
1083 return;
1084 }
1085 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1086 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1087 in_snd_device >= SND_DEVICE_IN_END) {
1088 ALOGE("%s: Sound device not valid", __func__);
1089 in_snd_device = SND_DEVICE_NONE;
1090 }
1091
1092 return;
1093}
1094
1095static void process_mic_info(const XML_Char **attr)
1096{
1097 uint32_t curIdx = 0;
1098 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301099 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301100
Saurav Kumardba3caf2020-05-29 20:53:55 +05301101 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1102 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301103 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1104 sizeof(microphone.channel_mapping));
1105
1106 if (strcmp(attr[curIdx++], "mic_device_id")) {
1107 ALOGE("%s: mic_device_id not found", __func__);
1108 goto on_error;
1109 }
1110 strlcpy(microphone.device_id,
1111 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1112
1113 if (strcmp(attr[curIdx++], "channel_mapping")) {
1114 ALOGE("%s: channel_mapping not found", __func__);
1115 goto on_error;
1116 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301117 char *context = NULL;
1118 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301119 uint32_t idx = 0;
1120 while (token) {
1121 if (!find_enum_by_string(mic_channel_mapping, token,
1122 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1123 &microphone.channel_mapping[idx++])) {
1124 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301125 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301126 goto on_error;
1127 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301128 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301129 }
1130 microphone.channel_count = idx;
1131
1132 platform_set_microphone_map(my_data.platform, in_snd_device,
1133 &microphone);
1134 return;
1135on_error:
1136 in_snd_device = SND_DEVICE_NONE;
1137 return;
1138}
1139
1140
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301141/* process acdb meta info key value */
1142static void process_acdb_metainfo_key(const XML_Char **attr)
1143{
1144 if (strcmp(attr[0], "name") != 0) {
1145 ALOGE("%s: 'name' not found", __func__);
1146 goto done;
1147 }
1148
1149 if (strcmp(attr[2], "value") != 0) {
1150 ALOGE("%s: 'value' not found", __func__);
1151 goto done;
1152 }
1153
1154 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001155 switch(my_data.caller) {
1156 case ACDB_EXTN:
1157 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1158 ALOGE("%s: key %d was not set!", __func__, key);
1159 goto done;
1160 }
1161 break;
1162 case PLATFORM:
1163 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1164 ALOGE("%s: key %d was not set!", __func__, key);
1165 goto done;
1166 }
1167 break;
1168 default:
1169 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301170 }
1171
1172done:
1173 return;
1174}
1175
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301176static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1177{
1178 uint32_t attr_idx = 0;
1179 int32_t in_ch_idx = -1;
1180 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1181
1182 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1183 &mtmx_in_params_info);
1184 if (mtmx_in_params == NULL) {
1185 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1186 return;
1187 }
1188
1189 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1190 ALOGE("%s: 'in_channel_index' not found", __func__);
1191 return;
1192 }
1193
1194 in_ch_idx = atoi((char *)attr[attr_idx++]);
1195 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1196 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1197 return;
1198 }
1199
1200 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1201 ALOGE("%s: 'channel_count' not found", __func__);
1202 return;
1203 }
1204 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1205
1206 if (strcmp(attr[attr_idx++], "device") != 0) {
1207 ALOGE("%s: 'device' not found", __func__);
1208 return;
1209 }
1210 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1211 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1212
1213 if (strcmp(attr[attr_idx++], "interface") != 0) {
1214 ALOGE("%s: 'interface' not found", __func__);
1215 return;
1216 }
1217 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1218 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1219
1220 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1221 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1222 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1223 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1224 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1225 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1226 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1227 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301228 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1229 ENUM_TO_STRING(AUDIO_DEVICE_IN_SPEAKER_MIC2),
1230 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1231 mtmx_in_params->i2s_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301232
1233 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1234}
1235
1236static void process_custom_mtmx_in_params(const XML_Char **attr)
1237{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301238 int attr_idx = 0, i = 0;
1239 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301240
1241 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1242 ALOGE("%s: 'usecase' not found", __func__);
1243 return;
1244 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301245 /* Check if multi usecases are supported for this custom mtrx params */
1246 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1247 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1248 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1249 value = strtok_r(NULL, ",", &context);
1250 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301251
1252 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1253 ALOGE("%s: 'out_channel_count' not found", __func__);
1254 return;
1255 }
1256 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1257
1258 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1259
1260}
1261
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301262static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1263{
1264 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301265 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301266 char *context = NULL, *ch_coeff_value = NULL;
1267 struct audio_custom_mtmx_params *mtmx_params = NULL;
1268
1269 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1270 ALOGE("%s: 'out_channel_index' not found", __func__);
1271 return;
1272 }
1273 out_ch_idx = atoi((char *)attr[attr_idx++]);
1274
1275 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1276 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1277 return;
1278 }
1279
1280 if (strcmp(attr[attr_idx++], "values") != 0) {
1281 ALOGE("%s: 'values' not found", __func__);
1282 return;
1283 }
1284 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301285 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301286 if (mtmx_params == NULL) {
1287 ALOGE("%s: mtmx params with given param info, not found", __func__);
1288 return;
1289 }
1290 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1291 ip_channels = mtmx_params->info.ip_channels;
1292 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301293 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301294 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1295 = atoi(ch_coeff_value);
1296 ch_coeff_value = strtok_r(NULL, " ", &context);
1297 }
1298 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1299 ch_coeff_value != NULL)
1300 ALOGE("%s: invalid/malformed coefficient values", __func__);
1301}
1302
1303static void process_custom_mtmx_params(const XML_Char **attr)
1304{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301305 int attr_idx = 0, i = 0;
1306 char *context = NULL, *value = NULL;
1307
1308 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301309
1310 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1311 ALOGE("%s: 'param_id' not found", __func__);
1312 return;
1313 }
1314 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1315
1316 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1317 ALOGE("%s: 'in_channel_count' not found", __func__);
1318 return;
1319 }
1320 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1321
1322 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1323 ALOGE("%s: 'out_channel_count' not found", __func__);
1324 return;
1325 }
1326 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1327
1328 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1329 ALOGE("%s: 'usecase' not found", __func__);
1330 return;
1331 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301332
1333 /* check if multi usecases are supported for this custom mtrx params */
1334 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1335 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1336 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1337 value = strtok_r(NULL, ",", &context);
1338 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301339
1340 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1341 ALOGE("%s: 'snd_device' not found", __func__);
1342 return;
1343 }
1344 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301345
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301346 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1347 i = 0;
1348 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1349 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1350 mtmx_params_info.fe_id[i++] = atoi(value);
1351 value = strtok_r(NULL, ",", &context);
1352 }
1353
1354 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301355 }
1356
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301357 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1358
1359}
1360
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001361static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001362 const XML_Char **attr)
1363{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001364 if (my_data.caller == ACDB_EXTN) {
1365 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1366 section = ACDB_METAINFO_KEY;
1367 } else if (strcmp(tag_name, "param") == 0) {
1368 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1369 ALOGE("param tag only supported with CONFIG_PARAMS section");
1370 return;
1371 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001372
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001373 section_process_fn fn = section_table[section];
1374 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001375 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001376 } else if(my_data.caller == PLATFORM) {
1377 if (strcmp(tag_name, "bit_width_configs") == 0) {
1378 section = BITWIDTH;
1379 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1380 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001381 } else if (strcmp(tag_name, "module_ids") == 0) {
1382 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001383 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1384 section = PCM_ID;
1385 } else if (strcmp(tag_name, "backend_names") == 0) {
1386 section = BACKEND_NAME;
1387 } else if (strcmp(tag_name, "config_params") == 0) {
1388 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001389 } else if (strcmp(tag_name, "operator_specific") == 0) {
1390 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001391 } else if (strcmp(tag_name, "interface_names") == 0) {
1392 section = INTERFACE_NAME;
1393 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1394 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001395 } else if (strcmp(tag_name, "app_types") == 0) {
1396 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001397 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1398 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301399 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1400 section = MICROPHONE_CHARACTERISTIC;
1401 } else if (strcmp(tag_name, "snd_devices") == 0) {
1402 section = SND_DEVICES;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301403#ifdef SOFT_VOLUME
1404 } else if (strcmp(tag_name, "soft_vol_params") == 0) {
1405 section = SOFT_VOLUME_PARAMS;
1406#endif
1407 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001408 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001409 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001410 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001411 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1412 return;
1413 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001414
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001415 /* call into process function for the current section */
1416 section_process_fn fn = section_table[section];
1417 fn(attr);
1418 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1419 if (section != GAIN_LEVEL_MAPPING) {
1420 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1421 return;
1422 }
1423
1424 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1425 fn(attr);
1426 } else if (strcmp(tag_name, "usecase") == 0) {
1427 if (section != PCM_ID) {
1428 ALOGE("usecase tag only supported with PCM_ID section");
1429 return;
1430 }
1431
1432 section_process_fn fn = section_table[PCM_ID];
1433 fn(attr);
1434 } else if (strcmp(tag_name, "param") == 0) {
1435 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1436 ALOGE("param tag only supported with CONFIG_PARAMS section");
1437 return;
1438 }
1439
1440 section_process_fn fn = section_table[section];
1441 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301442 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001443 if (section != MODULE) {
1444 ALOGE("aec tag only supported with MODULE section");
1445 return;
1446 }
1447 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301448 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001449 if (section != MODULE) {
1450 ALOGE("ns tag only supported with MODULE section");
1451 return;
1452 }
1453 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001454 } else if (strcmp(tag_name, "mmsecns") == 0) {
1455 if (section != MODULE) {
1456 ALOGE("mmsecns tag only supported with MODULE section");
1457 return;
1458 }
1459 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001460 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1461 if (section != GAIN_LEVEL_MAPPING) {
1462 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1463 return;
1464 }
1465
1466 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1467 fn(attr);
1468 } else if (!strcmp(tag_name, "app")) {
1469 if (section != APP_TYPE) {
1470 ALOGE("app tag only valid in section APP_TYPE");
1471 return;
1472 }
1473
1474 section_process_fn fn = section_table[APP_TYPE];
1475 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301476 } else if (strcmp(tag_name, "microphone") == 0) {
1477 if (section != MICROPHONE_CHARACTERISTIC) {
1478 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1479 return;
1480 }
1481 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1482 fn(attr);
1483 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1484 if (section != SND_DEVICES) {
1485 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1486 return;
1487 }
1488 section = INPUT_SND_DEVICE;
1489 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1490 if (section != INPUT_SND_DEVICE) {
1491 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1492 return;
1493 }
1494 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1495 } else if (strcmp(tag_name, "snd_dev") == 0) {
1496 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1497 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1498 return;
1499 }
1500 section_process_fn fn = section_table[SND_DEV];
1501 fn(attr);
1502 } else if (strcmp(tag_name, "mic_info") == 0) {
1503 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1504 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1505 return;
1506 }
1507 if (in_snd_device == SND_DEVICE_NONE) {
1508 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1509 return;
1510 }
1511 section_process_fn fn = section_table[MIC_INFO];
1512 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301513 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1514 if (section != ROOT) {
1515 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1516 return;
1517 }
1518 section = CUSTOM_MTMX_PARAMS;
1519 section_process_fn fn = section_table[section];
1520 fn(attr);
1521 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1522 if (section != CUSTOM_MTMX_PARAMS) {
1523 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1524 return;
1525 }
1526 section = CUSTOM_MTMX_PARAM_COEFFS;
1527 section_process_fn fn = section_table[section];
1528 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001529 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1530 section = EXTERNAL_DEVICE_SPECIFIC;
1531 } else if (strcmp(tag_name, "ext_device") == 0) {
1532 section_process_fn fn = section_table[section];
1533 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301534 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1535 if (section != ROOT) {
1536 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1537 return;
1538 }
1539 section = CUSTOM_MTMX_IN_PARAMS;
1540 section_process_fn fn = section_table[section];
1541 fn(attr);
1542 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1543 if (section != CUSTOM_MTMX_IN_PARAMS) {
1544 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1545 return;
1546 }
1547 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301548 section_process_fn fn = section_table[section];
1549 fn(attr);
Juyu Chen918e1e12019-08-08 15:28:18 -07001550 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1551 section = AUDIO_SOURCE_DELAY;
1552 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301553 section_process_fn fn = section_table[section];
1554 fn(attr);
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301555#ifdef SOFT_VOLUME
1556 } else if (strcmp(tag_name, "vol_params") == 0) {
1557 section = SOFT_VOLUME_PARAMS;
1558 section_process_fn fn = section_table[section];
1559 fn(attr);
1560#endif
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301561 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001562 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001563 if(strcmp(tag_name, "config_params") == 0) {
1564 section = CONFIG_PARAMS;
1565 } else if (strcmp(tag_name, "param") == 0) {
1566 if (section != CONFIG_PARAMS) {
1567 ALOGE("param tag only supported with CONFIG_PARAMS section");
1568 return;
1569 }
1570
1571 section_process_fn fn = section_table[section];
1572 fn(attr);
1573 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001574 }
Ben Romberger55886882014-01-10 13:49:02 -08001575 return;
1576}
1577
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001578static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001579{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001580 if (strcmp(tag_name, "bit_width_configs") == 0) {
1581 section = ROOT;
1582 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001583 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001584 } else if (strcmp(tag_name, "module_ids") == 0) {
1585 section = ROOT;
1586 } else if (strcmp(tag_name, "aec") == 0) {
1587 section = MODULE;
1588 } else if (strcmp(tag_name, "ns") == 0) {
1589 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001590 } else if (strcmp(tag_name, "mmsecns") == 0) {
1591 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001592 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1593 section = ROOT;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301594#ifdef SOFT_VOLUME
1595 } else if (strcmp(tag_name, "soft_volume_params") == 0) {
1596 section = ROOT;
1597#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001598 } else if (strcmp(tag_name, "backend_names") == 0) {
1599 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001600 } else if (strcmp(tag_name, "config_params") == 0) {
1601 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001602 } else if (strcmp(tag_name, "operator_specific") == 0) {
1603 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001604 } else if (strcmp(tag_name, "interface_names") == 0) {
1605 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001606 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1607 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001608 } else if (strcmp(tag_name, "app_types") == 0) {
1609 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301610 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1611 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301612 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1613 section = ROOT;
1614 } else if (strcmp(tag_name, "snd_devices") == 0) {
1615 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001616 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1617 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301618 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1619 section = SND_DEVICES;
1620 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1621 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301622 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1623 section = ROOT;
1624 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1625 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301626 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1627 section = ROOT;
1628 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1629 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001630 }
Ben Romberger55886882014-01-10 13:49:02 -08001631}
1632
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001633int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001634{
1635 XML_Parser parser;
1636 FILE *file;
1637 int ret = 0;
1638 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001639 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001640 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301641 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001642
Saurav Kumardba3caf2020-05-29 20:53:55 +05301643 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1644 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001645 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001646 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301647 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001648 MIXER_PATH_MAX_LENGTH);
1649 else
1650 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1651
1652 ALOGV("%s: platform info file name is %s", __func__,
1653 platform_info_file_name);
1654
1655 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001656 section = ROOT;
1657
Ben Romberger55886882014-01-10 13:49:02 -08001658 if (!file) {
1659 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001660 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001661 ret = -ENODEV;
1662 goto done;
1663 }
1664
1665 parser = XML_ParserCreate(NULL);
1666 if (!parser) {
1667 ALOGE("%s: Failed to create XML parser!", __func__);
1668 ret = -ENODEV;
1669 goto err_close_file;
1670 }
1671
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001672 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001673 my_data.platform = platform;
1674 my_data.kvpairs = str_parms_create();
1675
Ben Romberger55886882014-01-10 13:49:02 -08001676 XML_SetElementHandler(parser, start_tag, end_tag);
1677
1678 while (1) {
1679 buf = XML_GetBuffer(parser, BUF_SIZE);
1680 if (buf == NULL) {
1681 ALOGE("%s: XML_GetBuffer failed", __func__);
1682 ret = -ENOMEM;
1683 goto err_free_parser;
1684 }
1685
1686 bytes_read = fread(buf, 1, BUF_SIZE, file);
1687 if (bytes_read < 0) {
1688 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1689 ret = bytes_read;
1690 goto err_free_parser;
1691 }
1692
1693 if (XML_ParseBuffer(parser, bytes_read,
1694 bytes_read == 0) == XML_STATUS_ERROR) {
1695 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001696 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001697 ret = -EINVAL;
1698 goto err_free_parser;
1699 }
1700
1701 if (bytes_read == 0)
1702 break;
1703 }
1704
Ben Romberger55886882014-01-10 13:49:02 -08001705err_free_parser:
1706 XML_ParserFree(parser);
1707err_close_file:
1708 fclose(file);
1709done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001710 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001711 return ret;
1712}