blob: d9aabbfd0e3a21a3a8643c3cbdb25cf683e25c0e [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
Manoj Kumar N D7951b252022-08-23 13:18:00 +0530392 int pcm_id = atoi((char *)attr[5]);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700393
Manoj Kumar N D7951b252022-08-23 13:18:00 +0530394 if (strcmp(attr[6], "fe") != 0) {
395 ALOGE("%s: fe id not mentioned", __func__);
396 goto done;
397 }
398
399 int fe_id = atoi((char *)attr[7]);
400
401 if (platform_set_usecase_pcm_id(index, type, pcm_id, fe_id) < 0) {
402 ALOGE("%s: usecase %s type %d pcm_id %d fe_id %d was not set!",
403 __func__, attr[1], type, pcm_id, fe_id);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700404 goto done;
405 }
406
407done:
408 return;
409}
410
411/* backend to be used for a device */
412static void process_backend_name(const XML_Char **attr)
413{
414 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530415 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530416 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700417
418 if (strcmp(attr[0], "name") != 0) {
419 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
420 goto done;
421 }
422
423 index = platform_get_snd_device_index((char *)attr[1]);
424 if (index < 0) {
425 ALOGE("%s: Device %s not found, no ACDB ID set!",
426 __func__, attr[1]);
427 goto done;
428 }
429
430 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530431 if (strcmp(attr[2], "interface") == 0)
432 hw_interface = (char *)attr[3];
433 } else {
434 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700435 }
436
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530437 if (attr[4] != NULL) {
438 if (strcmp(attr[4], "interface") != 0) {
439 hw_interface = NULL;
440 } else {
441 hw_interface = (char *)attr[5];
442 }
443 }
444
Ashish Jaind150d4c2017-02-03 18:44:34 +0530445 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700446 ALOGE("%s: Device %s backend %s was not set!",
447 __func__, attr[1], attr[3]);
448 goto done;
449 }
450
451done:
452 return;
453}
454
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700455static void process_gain_db_to_level_map(const XML_Char **attr)
456{
457 struct amp_db_and_gain_table tbl_entry;
458
459 if ((strcmp(attr[0], "db") != 0) ||
460 (strcmp(attr[2], "level") != 0)) {
461 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
462 __func__, attr[0], attr[2]);
463 goto done;
464 }
465
466 tbl_entry.db = atof(attr[1]);
467 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
468 tbl_entry.level = atoi(attr[3]);
469
Aalique Grahame22e49102018-12-18 14:23:57 -0800470 //custome level should be > 0. Level 0 is fixed for default
471 CHECK(tbl_entry.level > 0);
472
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700473 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
474 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
475 platform_add_gain_level_mapping(&tbl_entry);
476
477done:
478 return;
479}
480
481
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700482static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800483{
Ben Romberger61764e32014-01-10 13:49:02 -0800484 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800485
Ben Romberger61764e32014-01-10 13:49:02 -0800486 if (strcmp(attr[0], "name") != 0) {
487 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800488 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800489 }
Ben Romberger55886882014-01-10 13:49:02 -0800490
Ben Romberger61764e32014-01-10 13:49:02 -0800491 index = platform_get_snd_device_index((char *)attr[1]);
492 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800493 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
494 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800495 goto done;
496 }
497
498 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800499 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
500 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800501 goto done;
502 }
503
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700504 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
505 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800506 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800507 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800508 }
Ben Romberger55886882014-01-10 13:49:02 -0800509
Ben Romberger55886882014-01-10 13:49:02 -0800510done:
511 return;
512}
513
Aalique Grahame22e49102018-12-18 14:23:57 -0800514static void process_operator_specific(const XML_Char **attr)
515{
516 snd_device_t snd_device = SND_DEVICE_NONE;
517
518 if (strcmp(attr[0], "name") != 0) {
519 ALOGE("%s: 'name' not found", __func__);
520 goto done;
521 }
522
523 snd_device = platform_get_snd_device_index((char *)attr[1]);
524 if (snd_device < 0) {
525 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530526 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800527 goto done;
528 }
529
530 if (strcmp(attr[2], "operator") != 0) {
531 ALOGE("%s: 'operator' not found", __func__);
532 goto done;
533 }
534
535 if (strcmp(attr[4], "mixer_path") != 0) {
536 ALOGE("%s: 'mixer_path' not found", __func__);
537 goto done;
538 }
539
540 if (strcmp(attr[6], "acdb_id") != 0) {
541 ALOGE("%s: 'acdb_id' not found", __func__);
542 goto done;
543 }
544
545 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
546
547done:
548 return;
549}
550
Carter Hsu32a62362018-10-15 15:01:42 -0700551static void process_external_dev(const XML_Char **attr)
552{
553 snd_device_t snd_device = SND_DEVICE_NONE;
554
555 if (strcmp(attr[0], "name") != 0) {
556 ALOGE("%s: 'name' not found", __func__);
557 goto done;
558 }
559
560 snd_device = platform_get_snd_device_index((char *)attr[1]);
561 if (snd_device < 0) {
562 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530563 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700564 goto done;
565 }
566
567 if (strcmp(attr[2], "usbid") != 0) {
568 ALOGE("%s: 'usbid' not found", __func__);
569 goto done;
570 }
571
572 if (strcmp(attr[4], "acdb_id") != 0) {
573 ALOGE("%s: 'acdb_id' not found", __func__);
574 goto done;
575 }
576
577 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
578
579done:
580 return;
581}
582
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700583static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
584{
585 int index;
586 struct audio_effect_config effect_config;
587
588 if (strcmp(attr[0], "name") != 0) {
589 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
590 goto done;
591 }
592
593 index = platform_get_snd_device_index((char *)attr[1]);
594 if (index < 0) {
595 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
596 __func__, attr[1]);
597 goto done;
598 }
599
600 if (strcmp(attr[2], "module_id") != 0) {
601 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
602 __func__, attr[2]);
603 goto done;
604 }
605
606 if (strcmp(attr[4], "instance_id") != 0) {
607 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
608 __func__, attr[4]);
609 goto done;
610 }
611
612 if (strcmp(attr[6], "param_id") != 0) {
613 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
614 __func__, attr[6]);
615 goto done;
616 }
617
618 if (strcmp(attr[8], "param_value") != 0) {
619 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
620 __func__, attr[8]);
621 goto done;
622 }
623
624 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
625 strtol((char *)attr[5], NULL, 0),
626 strtol((char *)attr[7], NULL, 0),
627 strtol((char *)attr[9], NULL, 0)};
628
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700629 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
630 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
631 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
632 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
633 strtol((char *)attr[9], NULL, 0));
634 goto done;
635 }
636
637done:
638 return;
639}
640
641static void process_effect_aec(const XML_Char **attr)
642{
643 process_audio_effect(attr, EFFECT_AEC);
644 return;
645}
646
647static void process_effect_ns(const XML_Char **attr)
648{
649 process_audio_effect(attr, EFFECT_NS);
650 return;
651}
652
Guodong Hu1d46f342019-06-28 16:57:30 +0800653static void process_fluence_mmsecns(const XML_Char **attr)
654{
655 int index;
656 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
657
658 if (strcmp(attr[0], "name") != 0) {
659 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
660 goto done;
661 }
662
663 index = platform_get_snd_device_index((char *)attr[1]);
664 if (index < 0) {
665 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
666 __func__, attr[1]);
667 goto done;
668 }
669
670 if (strcmp(attr[2], "topology_id") != 0) {
671 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
672 __func__, attr[2]);
673 goto done;
674 }
675
676 if (strcmp(attr[4], "module_id") != 0) {
677 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
678 __func__, attr[4]);
679 goto done;
680 }
681
682 if (strcmp(attr[6], "instance_id") != 0) {
683 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
684 __func__, attr[6]);
685 goto done;
686 }
687
688 if (strcmp(attr[8], "param_id") != 0) {
689 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
690 __func__, attr[8]);
691 goto done;
692 }
693
694 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
695 strtol((char *)attr[5], NULL, 0),
696 strtol((char *)attr[7], NULL, 0),
697 strtol((char *)attr[9], NULL, 0)};
698
699
700 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
701 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
702 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
703 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
704 goto done;
705 }
706
707done:
708 return;
709}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700710static void process_bit_width(const XML_Char **attr)
711{
712 int index;
713
714 if (strcmp(attr[0], "name") != 0) {
715 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
716 goto done;
717 }
718
719 index = platform_get_snd_device_index((char *)attr[1]);
720 if (index < 0) {
721 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
722 __func__, attr[1]);
723 goto done;
724 }
725
726 if (strcmp(attr[2], "bit_width") != 0) {
727 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
728 __func__, attr[1]);
729 goto done;
730 }
731
732 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
733 ALOGE("%s: Device %s, ACDB ID %d was not set!",
734 __func__, attr[1], atoi((char *)attr[3]));
735 goto done;
736 }
737
738done:
739 return;
740}
741
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800742static void process_interface_name(const XML_Char **attr)
743{
744 int ret;
745
746 if (strcmp(attr[0], "name") != 0) {
747 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
748
749 goto done;
750 }
751
752 if (strcmp(attr[2], "interface") != 0) {
753 ALOGE("%s: Device %s has no Audio Interface set!",
754 __func__, attr[1]);
755
756 goto done;
757 }
758
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530759 if (strcmp(attr[4], "codec_type") != 0) {
760 ALOGE("%s: Device %s has no codec type set!",
761 __func__, attr[1]);
762
763 goto done;
764 }
765
766 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
767 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800768 if (ret < 0) {
769 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800770 goto done;
771 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800772
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800773done:
774 return;
775}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530776
Juyu Chen918e1e12019-08-08 15:28:18 -0700777static void process_audio_source_delay(const XML_Char **attr)
778{
779 audio_source_t audio_source = -1;
780
781 if (strcmp(attr[0], "name") != 0) {
782 ALOGE("%s: 'name' not found", __func__);
783 goto done;
784 }
George Gao9ba8a142020-07-23 14:30:03 -0700785
Juyu Chen918e1e12019-08-08 15:28:18 -0700786 audio_source = platform_get_audio_source_index((const char *)attr[1]);
787
788 if (audio_source < 0) {
789 ALOGE("%s: audio_source %s is not defined",
790 __func__, (char *)attr[1]);
791 goto done;
792 }
793
794 if (strcmp(attr[2], "delay") != 0) {
795 ALOGE("%s: 'delay' not found", __func__);
796 goto done;
797 }
798
799 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
800
801done:
802 return;
803}
804
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700805static void process_config_params(const XML_Char **attr)
806{
807 if (strcmp(attr[0], "key") != 0) {
808 ALOGE("%s: 'key' not found", __func__);
809 goto done;
810 }
811
812 if (strcmp(attr[2], "value") != 0) {
813 ALOGE("%s: 'value' not found", __func__);
814 goto done;
815 }
816
817 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700818 if (my_data.caller == PLATFORM)
819 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700820done:
821 return;
822}
823
Aalique Grahame22e49102018-12-18 14:23:57 -0800824static void process_app_type(const XML_Char **attr)
825{
826 if (strcmp(attr[0], "uc_type")) {
827 ALOGE("%s: uc_type not found", __func__);
828 goto done;
829 }
830
831 if (strcmp(attr[2], "mode")) {
832 ALOGE("%s: mode not found", __func__);
833 goto done;
834 }
835
836 if (strcmp(attr[4], "bit_width")) {
837 ALOGE("%s: bit_width not found", __func__);
838 goto done;
839 }
840
841 if (strcmp(attr[6], "id")) {
842 ALOGE("%s: id not found", __func__);
843 goto done;
844 }
845
846 if (strcmp(attr[8], "max_rate")) {
847 ALOGE("%s: max rate not found", __func__);
848 goto done;
849 }
850
851 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
852 atoi(attr[9]));
853done:
854 return;
855}
856
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530857static void process_microphone_characteristic(const XML_Char **attr) {
858 struct audio_microphone_characteristic_t microphone;
859 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530860 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530861
Saurav Kumardba3caf2020-05-29 20:53:55 +0530862 strlcpy(platform_info_xml_path, get_platform_xml_path(),
863 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530864 if (strcmp(attr[curIdx++], "valid_mask")) {
865 ALOGE("%s: valid_mask not found", __func__);
866 goto done;
867 }
868 uint32_t valid_mask = atoi(attr[curIdx++]);
869
870 if (strcmp(attr[curIdx++], "device_id")) {
871 ALOGE("%s: device_id not found", __func__);
872 goto done;
873 }
874 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
875 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
876 goto done;
877 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530878 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530879
880 if (strcmp(attr[curIdx++], "type")) {
881 ALOGE("%s: device not found", __func__);
882 goto done;
883 }
884 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
885 ARRAY_SIZE(device_in_types), &microphone.device)) {
886 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530887 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530888 goto done;
889 }
890
891 if (strcmp(attr[curIdx++], "address")) {
892 ALOGE("%s: address not found", __func__);
893 goto done;
894 }
895 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
896 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
897 goto done;
898 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530899 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530900 if (strlen(microphone.address) == 0) {
901 // If the address is empty, populate the address according to device type.
902 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530903 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530904 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530905 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530906 }
907 }
908
909 if (strcmp(attr[curIdx++], "location")) {
910 ALOGE("%s: location not found", __func__);
911 goto done;
912 }
913 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
914 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
915 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530916 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530917 goto done;
918 }
919
920 if (strcmp(attr[curIdx++], "group")) {
921 ALOGE("%s: group not found", __func__);
922 goto done;
923 }
924 microphone.group = atoi(attr[curIdx++]);
925
926 if (strcmp(attr[curIdx++], "index_in_the_group")) {
927 ALOGE("%s: index_in_the_group not found", __func__);
928 goto done;
929 }
930 microphone.index_in_the_group = atoi(attr[curIdx++]);
931
932 if (strcmp(attr[curIdx++], "directionality")) {
933 ALOGE("%s: directionality not found", __func__);
934 goto done;
935 }
936 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
937 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
938 ALOGE("%s: directionality %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530939 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530940 goto done;
941 }
942
943 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
944 ALOGE("%s: num_frequency_responses not found", __func__);
945 goto done;
946 }
947 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530948 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530949 ALOGE("%s: num_frequency_responses is too large", __func__);
950 goto done;
951 }
952 if (microphone.num_frequency_responses > 0) {
953 if (strcmp(attr[curIdx++], "frequencies")) {
954 ALOGE("%s: frequencies not found", __func__);
955 goto done;
956 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530957 char *context = NULL;
958 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530959 uint32_t num_frequencies = 0;
960 while (token) {
961 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800962 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530963 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530964 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530965 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530966 }
967
968 if (strcmp(attr[curIdx++], "responses")) {
969 ALOGE("%s: responses not found", __func__);
970 goto done;
971 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530972 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530973 uint32_t num_responses = 0;
974 while (token) {
975 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800976 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
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 }
981
982 if (num_frequencies != num_responses
983 || num_frequencies != microphone.num_frequency_responses) {
984 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
985 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
986 goto done;
987 }
988 }
989
990 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
991 if (strcmp(attr[curIdx++], "sensitivity")) {
992 ALOGE("%s: sensitivity not found", __func__);
993 goto done;
994 }
995 microphone.sensitivity = atof(attr[curIdx++]);
996 } else {
997 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
998 }
999
1000 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
1001 if (strcmp(attr[curIdx++], "max_spl")) {
1002 ALOGE("%s: max_spl not found", __func__);
1003 goto done;
1004 }
1005 microphone.max_spl = atof(attr[curIdx++]);
1006 } else {
1007 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1008 }
1009
1010 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
1011 if (strcmp(attr[curIdx++], "min_spl")) {
1012 ALOGE("%s: min_spl not found", __func__);
1013 goto done;
1014 }
1015 microphone.min_spl = atof(attr[curIdx++]);
1016 } else {
1017 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1018 }
1019
1020 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
1021 if (strcmp(attr[curIdx++], "orientation")) {
1022 ALOGE("%s: orientation not found", __func__);
1023 goto done;
1024 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301025 char *context = NULL;
1026 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301027 float orientation[3];
1028 uint32_t idx = 0;
1029 while (token) {
1030 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001031 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301032 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301033 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301034 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301035 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301036 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301037 ALOGE("%s: orientation invalid", __func__);
1038 goto done;
1039 }
1040 microphone.orientation.x = orientation[0];
1041 microphone.orientation.y = orientation[1];
1042 microphone.orientation.z = orientation[2];
1043 } else {
1044 microphone.orientation.x = 0.0f;
1045 microphone.orientation.y = 0.0f;
1046 microphone.orientation.z = 0.0f;
1047 }
1048
1049 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
1050 if (strcmp(attr[curIdx++], "geometric_location")) {
1051 ALOGE("%s: geometric_location not found", __func__);
1052 goto done;
1053 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301054 char *context = NULL;
1055 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301056 float geometric_location[3];
1057 uint32_t idx = 0;
1058 while (token) {
1059 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001060 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301061 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301062 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301063 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301064 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301065 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301066 ALOGE("%s: geometric_location invalid", __func__);
1067 goto done;
1068 }
1069 microphone.geometric_location.x = geometric_location[0];
1070 microphone.geometric_location.y = geometric_location[1];
1071 microphone.geometric_location.z = geometric_location[2];
1072 } else {
1073 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1074 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1075 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1076 }
1077
1078 platform_set_microphone_characteristic(my_data.platform, microphone);
1079done:
1080 return;
1081}
1082
1083static void process_snd_dev(const XML_Char **attr)
1084{
1085 uint32_t curIdx = 0;
1086 in_snd_device = SND_DEVICE_NONE;
1087
1088 if (strcmp(attr[curIdx++], "in_snd_device")) {
1089 ALOGE("%s: snd_device not found", __func__);
1090 return;
1091 }
1092 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1093 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1094 in_snd_device >= SND_DEVICE_IN_END) {
1095 ALOGE("%s: Sound device not valid", __func__);
1096 in_snd_device = SND_DEVICE_NONE;
1097 }
1098
1099 return;
1100}
1101
1102static void process_mic_info(const XML_Char **attr)
1103{
1104 uint32_t curIdx = 0;
1105 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301106 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301107
Saurav Kumardba3caf2020-05-29 20:53:55 +05301108 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1109 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301110 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1111 sizeof(microphone.channel_mapping));
1112
1113 if (strcmp(attr[curIdx++], "mic_device_id")) {
1114 ALOGE("%s: mic_device_id not found", __func__);
1115 goto on_error;
1116 }
1117 strlcpy(microphone.device_id,
1118 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1119
1120 if (strcmp(attr[curIdx++], "channel_mapping")) {
1121 ALOGE("%s: channel_mapping not found", __func__);
1122 goto on_error;
1123 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301124 char *context = NULL;
1125 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301126 uint32_t idx = 0;
1127 while (token) {
1128 if (!find_enum_by_string(mic_channel_mapping, token,
1129 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1130 &microphone.channel_mapping[idx++])) {
1131 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301132 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301133 goto on_error;
1134 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301135 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301136 }
1137 microphone.channel_count = idx;
1138
1139 platform_set_microphone_map(my_data.platform, in_snd_device,
1140 &microphone);
1141 return;
1142on_error:
1143 in_snd_device = SND_DEVICE_NONE;
1144 return;
1145}
1146
1147
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301148/* process acdb meta info key value */
1149static void process_acdb_metainfo_key(const XML_Char **attr)
1150{
1151 if (strcmp(attr[0], "name") != 0) {
1152 ALOGE("%s: 'name' not found", __func__);
1153 goto done;
1154 }
1155
1156 if (strcmp(attr[2], "value") != 0) {
1157 ALOGE("%s: 'value' not found", __func__);
1158 goto done;
1159 }
1160
1161 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001162 switch(my_data.caller) {
1163 case ACDB_EXTN:
1164 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1165 ALOGE("%s: key %d was not set!", __func__, key);
1166 goto done;
1167 }
1168 break;
1169 case PLATFORM:
1170 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1171 ALOGE("%s: key %d was not set!", __func__, key);
1172 goto done;
1173 }
1174 break;
1175 default:
1176 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301177 }
1178
1179done:
1180 return;
1181}
1182
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301183static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1184{
1185 uint32_t attr_idx = 0;
1186 int32_t in_ch_idx = -1;
1187 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1188
1189 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1190 &mtmx_in_params_info);
1191 if (mtmx_in_params == NULL) {
1192 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1193 return;
1194 }
1195
1196 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1197 ALOGE("%s: 'in_channel_index' not found", __func__);
1198 return;
1199 }
1200
1201 in_ch_idx = atoi((char *)attr[attr_idx++]);
1202 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1203 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1204 return;
1205 }
1206
1207 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1208 ALOGE("%s: 'channel_count' not found", __func__);
1209 return;
1210 }
1211 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1212
1213 if (strcmp(attr[attr_idx++], "device") != 0) {
1214 ALOGE("%s: 'device' not found", __func__);
1215 return;
1216 }
1217 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1218 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1219
1220 if (strcmp(attr[attr_idx++], "interface") != 0) {
1221 ALOGE("%s: 'interface' not found", __func__);
1222 return;
1223 }
1224 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1225 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1226
1227 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1228 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1229 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1230 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1231 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1232 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1233 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1234 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301235 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1236 ENUM_TO_STRING(AUDIO_DEVICE_IN_SPEAKER_MIC2),
1237 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1238 mtmx_in_params->i2s_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301239
1240 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1241}
1242
1243static void process_custom_mtmx_in_params(const XML_Char **attr)
1244{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301245 int attr_idx = 0, i = 0;
1246 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301247
1248 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1249 ALOGE("%s: 'usecase' not found", __func__);
1250 return;
1251 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301252 /* Check if multi usecases are supported for this custom mtrx params */
1253 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1254 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1255 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1256 value = strtok_r(NULL, ",", &context);
1257 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301258
1259 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1260 ALOGE("%s: 'out_channel_count' not found", __func__);
1261 return;
1262 }
1263 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1264
1265 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1266
1267}
1268
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301269static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1270{
1271 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301272 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301273 char *context = NULL, *ch_coeff_value = NULL;
1274 struct audio_custom_mtmx_params *mtmx_params = NULL;
1275
1276 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1277 ALOGE("%s: 'out_channel_index' not found", __func__);
1278 return;
1279 }
1280 out_ch_idx = atoi((char *)attr[attr_idx++]);
1281
1282 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1283 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1284 return;
1285 }
1286
1287 if (strcmp(attr[attr_idx++], "values") != 0) {
1288 ALOGE("%s: 'values' not found", __func__);
1289 return;
1290 }
1291 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301292 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301293 if (mtmx_params == NULL) {
1294 ALOGE("%s: mtmx params with given param info, not found", __func__);
1295 return;
1296 }
1297 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1298 ip_channels = mtmx_params->info.ip_channels;
1299 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301300 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301301 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1302 = atoi(ch_coeff_value);
1303 ch_coeff_value = strtok_r(NULL, " ", &context);
1304 }
1305 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1306 ch_coeff_value != NULL)
1307 ALOGE("%s: invalid/malformed coefficient values", __func__);
1308}
1309
1310static void process_custom_mtmx_params(const XML_Char **attr)
1311{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301312 int attr_idx = 0, i = 0;
1313 char *context = NULL, *value = NULL;
1314
1315 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301316
1317 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1318 ALOGE("%s: 'param_id' not found", __func__);
1319 return;
1320 }
1321 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1322
1323 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1324 ALOGE("%s: 'in_channel_count' not found", __func__);
1325 return;
1326 }
1327 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1328
1329 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1330 ALOGE("%s: 'out_channel_count' not found", __func__);
1331 return;
1332 }
1333 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1334
1335 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1336 ALOGE("%s: 'usecase' not found", __func__);
1337 return;
1338 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301339
1340 /* check if multi usecases are supported for this custom mtrx params */
1341 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1342 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1343 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1344 value = strtok_r(NULL, ",", &context);
1345 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301346
1347 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1348 ALOGE("%s: 'snd_device' not found", __func__);
1349 return;
1350 }
1351 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301352
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301353 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1354 i = 0;
1355 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1356 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1357 mtmx_params_info.fe_id[i++] = atoi(value);
1358 value = strtok_r(NULL, ",", &context);
1359 }
1360
1361 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301362 }
1363
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301364 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1365
1366}
1367
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001368static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001369 const XML_Char **attr)
1370{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001371 if (my_data.caller == ACDB_EXTN) {
1372 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1373 section = ACDB_METAINFO_KEY;
1374 } else if (strcmp(tag_name, "param") == 0) {
1375 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1376 ALOGE("param tag only supported with CONFIG_PARAMS section");
1377 return;
1378 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001379
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001380 section_process_fn fn = section_table[section];
1381 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001382 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001383 } else if(my_data.caller == PLATFORM) {
1384 if (strcmp(tag_name, "bit_width_configs") == 0) {
1385 section = BITWIDTH;
1386 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1387 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001388 } else if (strcmp(tag_name, "module_ids") == 0) {
1389 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001390 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1391 section = PCM_ID;
1392 } else if (strcmp(tag_name, "backend_names") == 0) {
1393 section = BACKEND_NAME;
1394 } else if (strcmp(tag_name, "config_params") == 0) {
1395 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001396 } else if (strcmp(tag_name, "operator_specific") == 0) {
1397 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001398 } else if (strcmp(tag_name, "interface_names") == 0) {
1399 section = INTERFACE_NAME;
1400 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1401 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001402 } else if (strcmp(tag_name, "app_types") == 0) {
1403 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001404 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1405 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301406 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1407 section = MICROPHONE_CHARACTERISTIC;
1408 } else if (strcmp(tag_name, "snd_devices") == 0) {
1409 section = SND_DEVICES;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301410#ifdef SOFT_VOLUME
1411 } else if (strcmp(tag_name, "soft_vol_params") == 0) {
1412 section = SOFT_VOLUME_PARAMS;
1413#endif
1414 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001415 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001416 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001417 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001418 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1419 return;
1420 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001421
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001422 /* call into process function for the current section */
1423 section_process_fn fn = section_table[section];
1424 fn(attr);
1425 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1426 if (section != GAIN_LEVEL_MAPPING) {
1427 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1428 return;
1429 }
1430
1431 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1432 fn(attr);
1433 } else if (strcmp(tag_name, "usecase") == 0) {
1434 if (section != PCM_ID) {
1435 ALOGE("usecase tag only supported with PCM_ID section");
1436 return;
1437 }
1438
1439 section_process_fn fn = section_table[PCM_ID];
1440 fn(attr);
1441 } else if (strcmp(tag_name, "param") == 0) {
1442 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1443 ALOGE("param tag only supported with CONFIG_PARAMS section");
1444 return;
1445 }
1446
1447 section_process_fn fn = section_table[section];
1448 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301449 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001450 if (section != MODULE) {
1451 ALOGE("aec tag only supported with MODULE section");
1452 return;
1453 }
1454 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301455 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001456 if (section != MODULE) {
1457 ALOGE("ns tag only supported with MODULE section");
1458 return;
1459 }
1460 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001461 } else if (strcmp(tag_name, "mmsecns") == 0) {
1462 if (section != MODULE) {
1463 ALOGE("mmsecns tag only supported with MODULE section");
1464 return;
1465 }
1466 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001467 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1468 if (section != GAIN_LEVEL_MAPPING) {
1469 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1470 return;
1471 }
1472
1473 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1474 fn(attr);
1475 } else if (!strcmp(tag_name, "app")) {
1476 if (section != APP_TYPE) {
1477 ALOGE("app tag only valid in section APP_TYPE");
1478 return;
1479 }
1480
1481 section_process_fn fn = section_table[APP_TYPE];
1482 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301483 } else if (strcmp(tag_name, "microphone") == 0) {
1484 if (section != MICROPHONE_CHARACTERISTIC) {
1485 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1486 return;
1487 }
1488 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1489 fn(attr);
1490 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1491 if (section != SND_DEVICES) {
1492 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1493 return;
1494 }
1495 section = INPUT_SND_DEVICE;
1496 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1497 if (section != INPUT_SND_DEVICE) {
1498 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1499 return;
1500 }
1501 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1502 } else if (strcmp(tag_name, "snd_dev") == 0) {
1503 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1504 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1505 return;
1506 }
1507 section_process_fn fn = section_table[SND_DEV];
1508 fn(attr);
1509 } else if (strcmp(tag_name, "mic_info") == 0) {
1510 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1511 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1512 return;
1513 }
1514 if (in_snd_device == SND_DEVICE_NONE) {
1515 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1516 return;
1517 }
1518 section_process_fn fn = section_table[MIC_INFO];
1519 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301520 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1521 if (section != ROOT) {
1522 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1523 return;
1524 }
1525 section = CUSTOM_MTMX_PARAMS;
1526 section_process_fn fn = section_table[section];
1527 fn(attr);
1528 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1529 if (section != CUSTOM_MTMX_PARAMS) {
1530 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1531 return;
1532 }
1533 section = CUSTOM_MTMX_PARAM_COEFFS;
1534 section_process_fn fn = section_table[section];
1535 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001536 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1537 section = EXTERNAL_DEVICE_SPECIFIC;
1538 } else if (strcmp(tag_name, "ext_device") == 0) {
1539 section_process_fn fn = section_table[section];
1540 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301541 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1542 if (section != ROOT) {
1543 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1544 return;
1545 }
1546 section = CUSTOM_MTMX_IN_PARAMS;
1547 section_process_fn fn = section_table[section];
1548 fn(attr);
1549 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1550 if (section != CUSTOM_MTMX_IN_PARAMS) {
1551 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1552 return;
1553 }
1554 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301555 section_process_fn fn = section_table[section];
1556 fn(attr);
Juyu Chen918e1e12019-08-08 15:28:18 -07001557 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1558 section = AUDIO_SOURCE_DELAY;
1559 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301560 section_process_fn fn = section_table[section];
1561 fn(attr);
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301562#ifdef SOFT_VOLUME
1563 } else if (strcmp(tag_name, "vol_params") == 0) {
1564 section = SOFT_VOLUME_PARAMS;
1565 section_process_fn fn = section_table[section];
1566 fn(attr);
1567#endif
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301568 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001569 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001570 if(strcmp(tag_name, "config_params") == 0) {
1571 section = CONFIG_PARAMS;
1572 } else if (strcmp(tag_name, "param") == 0) {
1573 if (section != CONFIG_PARAMS) {
1574 ALOGE("param tag only supported with CONFIG_PARAMS section");
1575 return;
1576 }
1577
1578 section_process_fn fn = section_table[section];
1579 fn(attr);
1580 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001581 }
Ben Romberger55886882014-01-10 13:49:02 -08001582 return;
1583}
1584
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001585static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001586{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001587 if (strcmp(tag_name, "bit_width_configs") == 0) {
1588 section = ROOT;
1589 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001590 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001591 } else if (strcmp(tag_name, "module_ids") == 0) {
1592 section = ROOT;
1593 } else if (strcmp(tag_name, "aec") == 0) {
1594 section = MODULE;
1595 } else if (strcmp(tag_name, "ns") == 0) {
1596 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001597 } else if (strcmp(tag_name, "mmsecns") == 0) {
1598 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001599 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1600 section = ROOT;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301601#ifdef SOFT_VOLUME
1602 } else if (strcmp(tag_name, "soft_volume_params") == 0) {
1603 section = ROOT;
1604#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001605 } else if (strcmp(tag_name, "backend_names") == 0) {
1606 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001607 } else if (strcmp(tag_name, "config_params") == 0) {
1608 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001609 } else if (strcmp(tag_name, "operator_specific") == 0) {
1610 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001611 } else if (strcmp(tag_name, "interface_names") == 0) {
1612 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001613 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1614 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001615 } else if (strcmp(tag_name, "app_types") == 0) {
1616 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301617 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1618 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301619 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1620 section = ROOT;
1621 } else if (strcmp(tag_name, "snd_devices") == 0) {
1622 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001623 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1624 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301625 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1626 section = SND_DEVICES;
1627 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1628 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301629 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1630 section = ROOT;
1631 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1632 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301633 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1634 section = ROOT;
1635 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1636 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001637 }
Ben Romberger55886882014-01-10 13:49:02 -08001638}
1639
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001640int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001641{
1642 XML_Parser parser;
1643 FILE *file;
1644 int ret = 0;
1645 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001646 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001647 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301648 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001649
Saurav Kumardba3caf2020-05-29 20:53:55 +05301650 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1651 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001652 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001653 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301654 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001655 MIXER_PATH_MAX_LENGTH);
1656 else
1657 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1658
1659 ALOGV("%s: platform info file name is %s", __func__,
1660 platform_info_file_name);
1661
1662 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001663 section = ROOT;
1664
Ben Romberger55886882014-01-10 13:49:02 -08001665 if (!file) {
1666 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001667 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001668 ret = -ENODEV;
1669 goto done;
1670 }
1671
1672 parser = XML_ParserCreate(NULL);
1673 if (!parser) {
1674 ALOGE("%s: Failed to create XML parser!", __func__);
1675 ret = -ENODEV;
1676 goto err_close_file;
1677 }
1678
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001679 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001680 my_data.platform = platform;
1681 my_data.kvpairs = str_parms_create();
1682
Ben Romberger55886882014-01-10 13:49:02 -08001683 XML_SetElementHandler(parser, start_tag, end_tag);
1684
1685 while (1) {
1686 buf = XML_GetBuffer(parser, BUF_SIZE);
1687 if (buf == NULL) {
1688 ALOGE("%s: XML_GetBuffer failed", __func__);
1689 ret = -ENOMEM;
1690 goto err_free_parser;
1691 }
1692
1693 bytes_read = fread(buf, 1, BUF_SIZE, file);
1694 if (bytes_read < 0) {
1695 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1696 ret = bytes_read;
1697 goto err_free_parser;
1698 }
1699
1700 if (XML_ParseBuffer(parser, bytes_read,
1701 bytes_read == 0) == XML_STATUS_ERROR) {
1702 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001703 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001704 ret = -EINVAL;
1705 goto err_free_parser;
1706 }
1707
1708 if (bytes_read == 0)
1709 break;
1710 }
1711
Ben Romberger55886882014-01-10 13:49:02 -08001712err_free_parser:
1713 XML_ParserFree(parser);
1714err_close_file:
1715 fclose(file);
1716done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001717 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001718 return ret;
1719}