blob: 80b6e0d787b1aa95b5417e443b3c00f510428433 [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 D569498a2022-10-19 14:38:19 +0530394#ifdef PLATFORM_AUTO
Manoj Kumar N D7951b252022-08-23 13:18:00 +0530395 if (strcmp(attr[6], "fe") != 0) {
396 ALOGE("%s: fe id not mentioned", __func__);
397 goto done;
398 }
399
400 int fe_id = atoi((char *)attr[7]);
401
402 if (platform_set_usecase_pcm_id(index, type, pcm_id, fe_id) < 0) {
403 ALOGE("%s: usecase %s type %d pcm_id %d fe_id %d was not set!",
404 __func__, attr[1], type, pcm_id, fe_id);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700405 goto done;
406 }
Manoj Kumar N D569498a2022-10-19 14:38:19 +0530407#else
408 int fe_id = -1;
409
410 if (platform_set_usecase_pcm_id(index, type, pcm_id, fe_id) < 0) {
411 ALOGE("%s: usecase %s type %d pcm_id %d fe_id %d was not set!",
412 __func__, attr[1], type, pcm_id, fe_id);
413 goto done;
414 }
415#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700416
417done:
418 return;
419}
420
421/* backend to be used for a device */
422static void process_backend_name(const XML_Char **attr)
423{
424 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530425 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530426 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700427
428 if (strcmp(attr[0], "name") != 0) {
429 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
430 goto done;
431 }
432
433 index = platform_get_snd_device_index((char *)attr[1]);
434 if (index < 0) {
435 ALOGE("%s: Device %s not found, no ACDB ID set!",
436 __func__, attr[1]);
437 goto done;
438 }
439
440 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530441 if (strcmp(attr[2], "interface") == 0)
442 hw_interface = (char *)attr[3];
443 } else {
444 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700445 }
446
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530447 if (attr[4] != NULL) {
448 if (strcmp(attr[4], "interface") != 0) {
449 hw_interface = NULL;
450 } else {
451 hw_interface = (char *)attr[5];
452 }
453 }
454
Ashish Jaind150d4c2017-02-03 18:44:34 +0530455 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700456 ALOGE("%s: Device %s backend %s was not set!",
457 __func__, attr[1], attr[3]);
458 goto done;
459 }
460
461done:
462 return;
463}
464
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700465static void process_gain_db_to_level_map(const XML_Char **attr)
466{
467 struct amp_db_and_gain_table tbl_entry;
468
469 if ((strcmp(attr[0], "db") != 0) ||
470 (strcmp(attr[2], "level") != 0)) {
471 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
472 __func__, attr[0], attr[2]);
473 goto done;
474 }
475
476 tbl_entry.db = atof(attr[1]);
477 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
478 tbl_entry.level = atoi(attr[3]);
479
Aalique Grahame22e49102018-12-18 14:23:57 -0800480 //custome level should be > 0. Level 0 is fixed for default
481 CHECK(tbl_entry.level > 0);
482
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700483 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
484 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
485 platform_add_gain_level_mapping(&tbl_entry);
486
487done:
488 return;
489}
490
491
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700492static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800493{
Ben Romberger61764e32014-01-10 13:49:02 -0800494 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800495
Ben Romberger61764e32014-01-10 13:49:02 -0800496 if (strcmp(attr[0], "name") != 0) {
497 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800498 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800499 }
Ben Romberger55886882014-01-10 13:49:02 -0800500
Ben Romberger61764e32014-01-10 13:49:02 -0800501 index = platform_get_snd_device_index((char *)attr[1]);
502 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800503 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
504 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800505 goto done;
506 }
507
508 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800509 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
510 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800511 goto done;
512 }
513
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700514 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
515 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800516 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800517 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800518 }
Ben Romberger55886882014-01-10 13:49:02 -0800519
Ben Romberger55886882014-01-10 13:49:02 -0800520done:
521 return;
522}
523
Aalique Grahame22e49102018-12-18 14:23:57 -0800524static void process_operator_specific(const XML_Char **attr)
525{
526 snd_device_t snd_device = SND_DEVICE_NONE;
527
528 if (strcmp(attr[0], "name") != 0) {
529 ALOGE("%s: 'name' not found", __func__);
530 goto done;
531 }
532
533 snd_device = platform_get_snd_device_index((char *)attr[1]);
534 if (snd_device < 0) {
535 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530536 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800537 goto done;
538 }
539
540 if (strcmp(attr[2], "operator") != 0) {
541 ALOGE("%s: 'operator' not found", __func__);
542 goto done;
543 }
544
545 if (strcmp(attr[4], "mixer_path") != 0) {
546 ALOGE("%s: 'mixer_path' not found", __func__);
547 goto done;
548 }
549
550 if (strcmp(attr[6], "acdb_id") != 0) {
551 ALOGE("%s: 'acdb_id' not found", __func__);
552 goto done;
553 }
554
555 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
556
557done:
558 return;
559}
560
Carter Hsu32a62362018-10-15 15:01:42 -0700561static void process_external_dev(const XML_Char **attr)
562{
563 snd_device_t snd_device = SND_DEVICE_NONE;
564
565 if (strcmp(attr[0], "name") != 0) {
566 ALOGE("%s: 'name' not found", __func__);
567 goto done;
568 }
569
570 snd_device = platform_get_snd_device_index((char *)attr[1]);
571 if (snd_device < 0) {
572 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530573 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700574 goto done;
575 }
576
577 if (strcmp(attr[2], "usbid") != 0) {
578 ALOGE("%s: 'usbid' not found", __func__);
579 goto done;
580 }
581
582 if (strcmp(attr[4], "acdb_id") != 0) {
583 ALOGE("%s: 'acdb_id' not found", __func__);
584 goto done;
585 }
586
587 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
588
589done:
590 return;
591}
592
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700593static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
594{
595 int index;
596 struct audio_effect_config effect_config;
597
598 if (strcmp(attr[0], "name") != 0) {
599 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
600 goto done;
601 }
602
603 index = platform_get_snd_device_index((char *)attr[1]);
604 if (index < 0) {
605 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
606 __func__, attr[1]);
607 goto done;
608 }
609
610 if (strcmp(attr[2], "module_id") != 0) {
611 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
612 __func__, attr[2]);
613 goto done;
614 }
615
616 if (strcmp(attr[4], "instance_id") != 0) {
617 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
618 __func__, attr[4]);
619 goto done;
620 }
621
622 if (strcmp(attr[6], "param_id") != 0) {
623 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
624 __func__, attr[6]);
625 goto done;
626 }
627
628 if (strcmp(attr[8], "param_value") != 0) {
629 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
630 __func__, attr[8]);
631 goto done;
632 }
633
634 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
635 strtol((char *)attr[5], NULL, 0),
636 strtol((char *)attr[7], NULL, 0),
637 strtol((char *)attr[9], NULL, 0)};
638
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700639 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
640 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
641 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
642 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
643 strtol((char *)attr[9], NULL, 0));
644 goto done;
645 }
646
647done:
648 return;
649}
650
651static void process_effect_aec(const XML_Char **attr)
652{
653 process_audio_effect(attr, EFFECT_AEC);
654 return;
655}
656
657static void process_effect_ns(const XML_Char **attr)
658{
659 process_audio_effect(attr, EFFECT_NS);
660 return;
661}
662
Guodong Hu1d46f342019-06-28 16:57:30 +0800663static void process_fluence_mmsecns(const XML_Char **attr)
664{
665 int index;
666 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
667
668 if (strcmp(attr[0], "name") != 0) {
669 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
670 goto done;
671 }
672
673 index = platform_get_snd_device_index((char *)attr[1]);
674 if (index < 0) {
675 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
676 __func__, attr[1]);
677 goto done;
678 }
679
680 if (strcmp(attr[2], "topology_id") != 0) {
681 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
682 __func__, attr[2]);
683 goto done;
684 }
685
686 if (strcmp(attr[4], "module_id") != 0) {
687 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
688 __func__, attr[4]);
689 goto done;
690 }
691
692 if (strcmp(attr[6], "instance_id") != 0) {
693 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
694 __func__, attr[6]);
695 goto done;
696 }
697
698 if (strcmp(attr[8], "param_id") != 0) {
699 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
700 __func__, attr[8]);
701 goto done;
702 }
703
704 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
705 strtol((char *)attr[5], NULL, 0),
706 strtol((char *)attr[7], NULL, 0),
707 strtol((char *)attr[9], NULL, 0)};
708
709
710 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
711 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
712 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
713 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
714 goto done;
715 }
716
717done:
718 return;
719}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700720static void process_bit_width(const XML_Char **attr)
721{
722 int index;
723
724 if (strcmp(attr[0], "name") != 0) {
725 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
726 goto done;
727 }
728
729 index = platform_get_snd_device_index((char *)attr[1]);
730 if (index < 0) {
731 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
732 __func__, attr[1]);
733 goto done;
734 }
735
736 if (strcmp(attr[2], "bit_width") != 0) {
737 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
738 __func__, attr[1]);
739 goto done;
740 }
741
742 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
743 ALOGE("%s: Device %s, ACDB ID %d was not set!",
744 __func__, attr[1], atoi((char *)attr[3]));
745 goto done;
746 }
747
748done:
749 return;
750}
751
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800752static void process_interface_name(const XML_Char **attr)
753{
754 int ret;
755
756 if (strcmp(attr[0], "name") != 0) {
757 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
758
759 goto done;
760 }
761
762 if (strcmp(attr[2], "interface") != 0) {
763 ALOGE("%s: Device %s has no Audio Interface set!",
764 __func__, attr[1]);
765
766 goto done;
767 }
768
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530769 if (strcmp(attr[4], "codec_type") != 0) {
770 ALOGE("%s: Device %s has no codec type set!",
771 __func__, attr[1]);
772
773 goto done;
774 }
775
776 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
777 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800778 if (ret < 0) {
779 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800780 goto done;
781 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800782
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800783done:
784 return;
785}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530786
Juyu Chen918e1e12019-08-08 15:28:18 -0700787static void process_audio_source_delay(const XML_Char **attr)
788{
789 audio_source_t audio_source = -1;
790
791 if (strcmp(attr[0], "name") != 0) {
792 ALOGE("%s: 'name' not found", __func__);
793 goto done;
794 }
George Gao9ba8a142020-07-23 14:30:03 -0700795
Juyu Chen918e1e12019-08-08 15:28:18 -0700796 audio_source = platform_get_audio_source_index((const char *)attr[1]);
797
798 if (audio_source < 0) {
799 ALOGE("%s: audio_source %s is not defined",
800 __func__, (char *)attr[1]);
801 goto done;
802 }
803
804 if (strcmp(attr[2], "delay") != 0) {
805 ALOGE("%s: 'delay' not found", __func__);
806 goto done;
807 }
808
809 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
810
811done:
812 return;
813}
814
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700815static void process_config_params(const XML_Char **attr)
816{
817 if (strcmp(attr[0], "key") != 0) {
818 ALOGE("%s: 'key' not found", __func__);
819 goto done;
820 }
821
822 if (strcmp(attr[2], "value") != 0) {
823 ALOGE("%s: 'value' not found", __func__);
824 goto done;
825 }
826
827 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700828 if (my_data.caller == PLATFORM)
829 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700830done:
831 return;
832}
833
Aalique Grahame22e49102018-12-18 14:23:57 -0800834static void process_app_type(const XML_Char **attr)
835{
836 if (strcmp(attr[0], "uc_type")) {
837 ALOGE("%s: uc_type not found", __func__);
838 goto done;
839 }
840
841 if (strcmp(attr[2], "mode")) {
842 ALOGE("%s: mode not found", __func__);
843 goto done;
844 }
845
846 if (strcmp(attr[4], "bit_width")) {
847 ALOGE("%s: bit_width not found", __func__);
848 goto done;
849 }
850
851 if (strcmp(attr[6], "id")) {
852 ALOGE("%s: id not found", __func__);
853 goto done;
854 }
855
856 if (strcmp(attr[8], "max_rate")) {
857 ALOGE("%s: max rate not found", __func__);
858 goto done;
859 }
860
861 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
862 atoi(attr[9]));
863done:
864 return;
865}
866
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530867static void process_microphone_characteristic(const XML_Char **attr) {
868 struct audio_microphone_characteristic_t microphone;
869 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530870 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530871
Saurav Kumardba3caf2020-05-29 20:53:55 +0530872 strlcpy(platform_info_xml_path, get_platform_xml_path(),
873 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530874 if (strcmp(attr[curIdx++], "valid_mask")) {
875 ALOGE("%s: valid_mask not found", __func__);
876 goto done;
877 }
878 uint32_t valid_mask = atoi(attr[curIdx++]);
879
880 if (strcmp(attr[curIdx++], "device_id")) {
881 ALOGE("%s: device_id not found", __func__);
882 goto done;
883 }
884 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
885 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
886 goto done;
887 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530888 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530889
890 if (strcmp(attr[curIdx++], "type")) {
891 ALOGE("%s: device not found", __func__);
892 goto done;
893 }
894 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
895 ARRAY_SIZE(device_in_types), &microphone.device)) {
896 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530897 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530898 goto done;
899 }
900
901 if (strcmp(attr[curIdx++], "address")) {
902 ALOGE("%s: address not found", __func__);
903 goto done;
904 }
905 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
906 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
907 goto done;
908 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530909 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530910 if (strlen(microphone.address) == 0) {
911 // If the address is empty, populate the address according to device type.
912 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530913 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530914 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530915 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530916 }
917 }
918
919 if (strcmp(attr[curIdx++], "location")) {
920 ALOGE("%s: location not found", __func__);
921 goto done;
922 }
923 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
924 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
925 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530926 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530927 goto done;
928 }
929
930 if (strcmp(attr[curIdx++], "group")) {
931 ALOGE("%s: group not found", __func__);
932 goto done;
933 }
934 microphone.group = atoi(attr[curIdx++]);
935
936 if (strcmp(attr[curIdx++], "index_in_the_group")) {
937 ALOGE("%s: index_in_the_group not found", __func__);
938 goto done;
939 }
940 microphone.index_in_the_group = atoi(attr[curIdx++]);
941
942 if (strcmp(attr[curIdx++], "directionality")) {
943 ALOGE("%s: directionality not found", __func__);
944 goto done;
945 }
946 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
947 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
948 ALOGE("%s: directionality %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530949 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530950 goto done;
951 }
952
953 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
954 ALOGE("%s: num_frequency_responses not found", __func__);
955 goto done;
956 }
957 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530958 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530959 ALOGE("%s: num_frequency_responses is too large", __func__);
960 goto done;
961 }
962 if (microphone.num_frequency_responses > 0) {
963 if (strcmp(attr[curIdx++], "frequencies")) {
964 ALOGE("%s: frequencies not found", __func__);
965 goto done;
966 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530967 char *context = NULL;
968 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530969 uint32_t num_frequencies = 0;
970 while (token) {
971 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800972 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530973 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530974 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530975 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530976 }
977
978 if (strcmp(attr[curIdx++], "responses")) {
979 ALOGE("%s: responses not found", __func__);
980 goto done;
981 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530982 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530983 uint32_t num_responses = 0;
984 while (token) {
985 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800986 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530987 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530988 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530989 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530990 }
991
992 if (num_frequencies != num_responses
993 || num_frequencies != microphone.num_frequency_responses) {
994 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
995 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
996 goto done;
997 }
998 }
999
1000 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
1001 if (strcmp(attr[curIdx++], "sensitivity")) {
1002 ALOGE("%s: sensitivity not found", __func__);
1003 goto done;
1004 }
1005 microphone.sensitivity = atof(attr[curIdx++]);
1006 } else {
1007 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
1008 }
1009
1010 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
1011 if (strcmp(attr[curIdx++], "max_spl")) {
1012 ALOGE("%s: max_spl not found", __func__);
1013 goto done;
1014 }
1015 microphone.max_spl = atof(attr[curIdx++]);
1016 } else {
1017 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1018 }
1019
1020 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
1021 if (strcmp(attr[curIdx++], "min_spl")) {
1022 ALOGE("%s: min_spl not found", __func__);
1023 goto done;
1024 }
1025 microphone.min_spl = atof(attr[curIdx++]);
1026 } else {
1027 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1028 }
1029
1030 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
1031 if (strcmp(attr[curIdx++], "orientation")) {
1032 ALOGE("%s: orientation not found", __func__);
1033 goto done;
1034 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301035 char *context = NULL;
1036 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301037 float orientation[3];
1038 uint32_t idx = 0;
1039 while (token) {
1040 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001041 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301042 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301043 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301044 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301045 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301046 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301047 ALOGE("%s: orientation invalid", __func__);
1048 goto done;
1049 }
1050 microphone.orientation.x = orientation[0];
1051 microphone.orientation.y = orientation[1];
1052 microphone.orientation.z = orientation[2];
1053 } else {
1054 microphone.orientation.x = 0.0f;
1055 microphone.orientation.y = 0.0f;
1056 microphone.orientation.z = 0.0f;
1057 }
1058
1059 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
1060 if (strcmp(attr[curIdx++], "geometric_location")) {
1061 ALOGE("%s: geometric_location not found", __func__);
1062 goto done;
1063 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301064 char *context = NULL;
1065 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301066 float geometric_location[3];
1067 uint32_t idx = 0;
1068 while (token) {
1069 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001070 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301071 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301072 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301073 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301074 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301075 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301076 ALOGE("%s: geometric_location invalid", __func__);
1077 goto done;
1078 }
1079 microphone.geometric_location.x = geometric_location[0];
1080 microphone.geometric_location.y = geometric_location[1];
1081 microphone.geometric_location.z = geometric_location[2];
1082 } else {
1083 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1084 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1085 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1086 }
1087
1088 platform_set_microphone_characteristic(my_data.platform, microphone);
1089done:
1090 return;
1091}
1092
1093static void process_snd_dev(const XML_Char **attr)
1094{
1095 uint32_t curIdx = 0;
1096 in_snd_device = SND_DEVICE_NONE;
1097
1098 if (strcmp(attr[curIdx++], "in_snd_device")) {
1099 ALOGE("%s: snd_device not found", __func__);
1100 return;
1101 }
1102 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1103 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1104 in_snd_device >= SND_DEVICE_IN_END) {
1105 ALOGE("%s: Sound device not valid", __func__);
1106 in_snd_device = SND_DEVICE_NONE;
1107 }
1108
1109 return;
1110}
1111
1112static void process_mic_info(const XML_Char **attr)
1113{
1114 uint32_t curIdx = 0;
1115 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301116 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301117
Saurav Kumardba3caf2020-05-29 20:53:55 +05301118 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1119 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301120 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1121 sizeof(microphone.channel_mapping));
1122
1123 if (strcmp(attr[curIdx++], "mic_device_id")) {
1124 ALOGE("%s: mic_device_id not found", __func__);
1125 goto on_error;
1126 }
1127 strlcpy(microphone.device_id,
1128 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1129
1130 if (strcmp(attr[curIdx++], "channel_mapping")) {
1131 ALOGE("%s: channel_mapping not found", __func__);
1132 goto on_error;
1133 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301134 char *context = NULL;
1135 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301136 uint32_t idx = 0;
1137 while (token) {
1138 if (!find_enum_by_string(mic_channel_mapping, token,
1139 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1140 &microphone.channel_mapping[idx++])) {
1141 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301142 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301143 goto on_error;
1144 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301145 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301146 }
1147 microphone.channel_count = idx;
1148
1149 platform_set_microphone_map(my_data.platform, in_snd_device,
1150 &microphone);
1151 return;
1152on_error:
1153 in_snd_device = SND_DEVICE_NONE;
1154 return;
1155}
1156
1157
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301158/* process acdb meta info key value */
1159static void process_acdb_metainfo_key(const XML_Char **attr)
1160{
1161 if (strcmp(attr[0], "name") != 0) {
1162 ALOGE("%s: 'name' not found", __func__);
1163 goto done;
1164 }
1165
1166 if (strcmp(attr[2], "value") != 0) {
1167 ALOGE("%s: 'value' not found", __func__);
1168 goto done;
1169 }
1170
1171 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001172 switch(my_data.caller) {
1173 case ACDB_EXTN:
1174 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1175 ALOGE("%s: key %d was not set!", __func__, key);
1176 goto done;
1177 }
1178 break;
1179 case PLATFORM:
1180 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1181 ALOGE("%s: key %d was not set!", __func__, key);
1182 goto done;
1183 }
1184 break;
1185 default:
1186 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301187 }
1188
1189done:
1190 return;
1191}
1192
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301193static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1194{
1195 uint32_t attr_idx = 0;
1196 int32_t in_ch_idx = -1;
1197 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1198
1199 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1200 &mtmx_in_params_info);
1201 if (mtmx_in_params == NULL) {
1202 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1203 return;
1204 }
1205
1206 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1207 ALOGE("%s: 'in_channel_index' not found", __func__);
1208 return;
1209 }
1210
1211 in_ch_idx = atoi((char *)attr[attr_idx++]);
1212 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1213 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1214 return;
1215 }
1216
1217 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1218 ALOGE("%s: 'channel_count' not found", __func__);
1219 return;
1220 }
1221 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1222
1223 if (strcmp(attr[attr_idx++], "device") != 0) {
1224 ALOGE("%s: 'device' not found", __func__);
1225 return;
1226 }
1227 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1228 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1229
1230 if (strcmp(attr[attr_idx++], "interface") != 0) {
1231 ALOGE("%s: 'interface' not found", __func__);
1232 return;
1233 }
1234 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1235 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1236
1237 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1238 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1239 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1240 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1241 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1242 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1243 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1244 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301245 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1246 ENUM_TO_STRING(AUDIO_DEVICE_IN_SPEAKER_MIC2),
1247 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1248 mtmx_in_params->i2s_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301249
1250 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1251}
1252
1253static void process_custom_mtmx_in_params(const XML_Char **attr)
1254{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301255 int attr_idx = 0, i = 0;
1256 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301257
1258 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1259 ALOGE("%s: 'usecase' not found", __func__);
1260 return;
1261 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301262 /* Check if multi usecases are supported for this custom mtrx params */
1263 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1264 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1265 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1266 value = strtok_r(NULL, ",", &context);
1267 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301268
1269 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1270 ALOGE("%s: 'out_channel_count' not found", __func__);
1271 return;
1272 }
1273 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1274
1275 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1276
1277}
1278
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301279static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1280{
1281 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301282 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301283 char *context = NULL, *ch_coeff_value = NULL;
1284 struct audio_custom_mtmx_params *mtmx_params = NULL;
1285
1286 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1287 ALOGE("%s: 'out_channel_index' not found", __func__);
1288 return;
1289 }
1290 out_ch_idx = atoi((char *)attr[attr_idx++]);
1291
1292 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1293 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1294 return;
1295 }
1296
1297 if (strcmp(attr[attr_idx++], "values") != 0) {
1298 ALOGE("%s: 'values' not found", __func__);
1299 return;
1300 }
1301 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301302 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301303 if (mtmx_params == NULL) {
1304 ALOGE("%s: mtmx params with given param info, not found", __func__);
1305 return;
1306 }
1307 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1308 ip_channels = mtmx_params->info.ip_channels;
1309 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301310 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301311 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1312 = atoi(ch_coeff_value);
1313 ch_coeff_value = strtok_r(NULL, " ", &context);
1314 }
1315 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1316 ch_coeff_value != NULL)
1317 ALOGE("%s: invalid/malformed coefficient values", __func__);
1318}
1319
1320static void process_custom_mtmx_params(const XML_Char **attr)
1321{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301322 int attr_idx = 0, i = 0;
1323 char *context = NULL, *value = NULL;
1324
1325 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301326
1327 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1328 ALOGE("%s: 'param_id' not found", __func__);
1329 return;
1330 }
1331 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1332
1333 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1334 ALOGE("%s: 'in_channel_count' not found", __func__);
1335 return;
1336 }
1337 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1338
1339 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1340 ALOGE("%s: 'out_channel_count' not found", __func__);
1341 return;
1342 }
1343 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1344
1345 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1346 ALOGE("%s: 'usecase' not found", __func__);
1347 return;
1348 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301349
1350 /* check if multi usecases are supported for this custom mtrx params */
1351 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1352 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1353 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1354 value = strtok_r(NULL, ",", &context);
1355 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301356
1357 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1358 ALOGE("%s: 'snd_device' not found", __func__);
1359 return;
1360 }
1361 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301362
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301363 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1364 i = 0;
1365 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1366 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1367 mtmx_params_info.fe_id[i++] = atoi(value);
1368 value = strtok_r(NULL, ",", &context);
1369 }
1370
1371 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301372 }
1373
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301374 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1375
1376}
1377
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001378static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001379 const XML_Char **attr)
1380{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001381 if (my_data.caller == ACDB_EXTN) {
1382 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1383 section = ACDB_METAINFO_KEY;
1384 } else if (strcmp(tag_name, "param") == 0) {
1385 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1386 ALOGE("param tag only supported with CONFIG_PARAMS section");
1387 return;
1388 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001389
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001390 section_process_fn fn = section_table[section];
1391 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001392 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001393 } else if(my_data.caller == PLATFORM) {
1394 if (strcmp(tag_name, "bit_width_configs") == 0) {
1395 section = BITWIDTH;
1396 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1397 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001398 } else if (strcmp(tag_name, "module_ids") == 0) {
1399 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001400 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1401 section = PCM_ID;
1402 } else if (strcmp(tag_name, "backend_names") == 0) {
1403 section = BACKEND_NAME;
1404 } else if (strcmp(tag_name, "config_params") == 0) {
1405 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001406 } else if (strcmp(tag_name, "operator_specific") == 0) {
1407 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001408 } else if (strcmp(tag_name, "interface_names") == 0) {
1409 section = INTERFACE_NAME;
1410 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1411 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001412 } else if (strcmp(tag_name, "app_types") == 0) {
1413 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001414 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1415 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301416 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1417 section = MICROPHONE_CHARACTERISTIC;
1418 } else if (strcmp(tag_name, "snd_devices") == 0) {
1419 section = SND_DEVICES;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301420#ifdef SOFT_VOLUME
1421 } else if (strcmp(tag_name, "soft_vol_params") == 0) {
1422 section = SOFT_VOLUME_PARAMS;
1423#endif
1424 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001425 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001426 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001427 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001428 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1429 return;
1430 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001431
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001432 /* call into process function for the current section */
1433 section_process_fn fn = section_table[section];
1434 fn(attr);
1435 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1436 if (section != GAIN_LEVEL_MAPPING) {
1437 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1438 return;
1439 }
1440
1441 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1442 fn(attr);
1443 } else if (strcmp(tag_name, "usecase") == 0) {
1444 if (section != PCM_ID) {
1445 ALOGE("usecase tag only supported with PCM_ID section");
1446 return;
1447 }
1448
1449 section_process_fn fn = section_table[PCM_ID];
1450 fn(attr);
1451 } else if (strcmp(tag_name, "param") == 0) {
1452 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1453 ALOGE("param tag only supported with CONFIG_PARAMS section");
1454 return;
1455 }
1456
1457 section_process_fn fn = section_table[section];
1458 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301459 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001460 if (section != MODULE) {
1461 ALOGE("aec tag only supported with MODULE section");
1462 return;
1463 }
1464 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301465 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001466 if (section != MODULE) {
1467 ALOGE("ns tag only supported with MODULE section");
1468 return;
1469 }
1470 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001471 } else if (strcmp(tag_name, "mmsecns") == 0) {
1472 if (section != MODULE) {
1473 ALOGE("mmsecns tag only supported with MODULE section");
1474 return;
1475 }
1476 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001477 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1478 if (section != GAIN_LEVEL_MAPPING) {
1479 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1480 return;
1481 }
1482
1483 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1484 fn(attr);
1485 } else if (!strcmp(tag_name, "app")) {
1486 if (section != APP_TYPE) {
1487 ALOGE("app tag only valid in section APP_TYPE");
1488 return;
1489 }
1490
1491 section_process_fn fn = section_table[APP_TYPE];
1492 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301493 } else if (strcmp(tag_name, "microphone") == 0) {
1494 if (section != MICROPHONE_CHARACTERISTIC) {
1495 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1496 return;
1497 }
1498 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1499 fn(attr);
1500 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1501 if (section != SND_DEVICES) {
1502 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1503 return;
1504 }
1505 section = INPUT_SND_DEVICE;
1506 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1507 if (section != INPUT_SND_DEVICE) {
1508 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1509 return;
1510 }
1511 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1512 } else if (strcmp(tag_name, "snd_dev") == 0) {
1513 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1514 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1515 return;
1516 }
1517 section_process_fn fn = section_table[SND_DEV];
1518 fn(attr);
1519 } else if (strcmp(tag_name, "mic_info") == 0) {
1520 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1521 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1522 return;
1523 }
1524 if (in_snd_device == SND_DEVICE_NONE) {
1525 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1526 return;
1527 }
1528 section_process_fn fn = section_table[MIC_INFO];
1529 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301530 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1531 if (section != ROOT) {
1532 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1533 return;
1534 }
1535 section = CUSTOM_MTMX_PARAMS;
1536 section_process_fn fn = section_table[section];
1537 fn(attr);
1538 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1539 if (section != CUSTOM_MTMX_PARAMS) {
1540 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1541 return;
1542 }
1543 section = CUSTOM_MTMX_PARAM_COEFFS;
1544 section_process_fn fn = section_table[section];
1545 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001546 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1547 section = EXTERNAL_DEVICE_SPECIFIC;
1548 } else if (strcmp(tag_name, "ext_device") == 0) {
1549 section_process_fn fn = section_table[section];
1550 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301551 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1552 if (section != ROOT) {
1553 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1554 return;
1555 }
1556 section = CUSTOM_MTMX_IN_PARAMS;
1557 section_process_fn fn = section_table[section];
1558 fn(attr);
1559 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1560 if (section != CUSTOM_MTMX_IN_PARAMS) {
1561 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1562 return;
1563 }
1564 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301565 section_process_fn fn = section_table[section];
1566 fn(attr);
Juyu Chen918e1e12019-08-08 15:28:18 -07001567 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1568 section = AUDIO_SOURCE_DELAY;
1569 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301570 section_process_fn fn = section_table[section];
1571 fn(attr);
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301572#ifdef SOFT_VOLUME
1573 } else if (strcmp(tag_name, "vol_params") == 0) {
1574 section = SOFT_VOLUME_PARAMS;
1575 section_process_fn fn = section_table[section];
1576 fn(attr);
1577#endif
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301578 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001579 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001580 if(strcmp(tag_name, "config_params") == 0) {
1581 section = CONFIG_PARAMS;
1582 } else if (strcmp(tag_name, "param") == 0) {
1583 if (section != CONFIG_PARAMS) {
1584 ALOGE("param tag only supported with CONFIG_PARAMS section");
1585 return;
1586 }
1587
1588 section_process_fn fn = section_table[section];
1589 fn(attr);
1590 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001591 }
Ben Romberger55886882014-01-10 13:49:02 -08001592 return;
1593}
1594
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001595static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001596{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001597 if (strcmp(tag_name, "bit_width_configs") == 0) {
1598 section = ROOT;
1599 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001600 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001601 } else if (strcmp(tag_name, "module_ids") == 0) {
1602 section = ROOT;
1603 } else if (strcmp(tag_name, "aec") == 0) {
1604 section = MODULE;
1605 } else if (strcmp(tag_name, "ns") == 0) {
1606 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001607 } else if (strcmp(tag_name, "mmsecns") == 0) {
1608 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001609 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1610 section = ROOT;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301611#ifdef SOFT_VOLUME
1612 } else if (strcmp(tag_name, "soft_volume_params") == 0) {
1613 section = ROOT;
1614#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001615 } else if (strcmp(tag_name, "backend_names") == 0) {
1616 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001617 } else if (strcmp(tag_name, "config_params") == 0) {
1618 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001619 } else if (strcmp(tag_name, "operator_specific") == 0) {
1620 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001621 } else if (strcmp(tag_name, "interface_names") == 0) {
1622 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001623 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1624 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001625 } else if (strcmp(tag_name, "app_types") == 0) {
1626 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301627 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1628 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301629 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1630 section = ROOT;
1631 } else if (strcmp(tag_name, "snd_devices") == 0) {
1632 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001633 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1634 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301635 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1636 section = SND_DEVICES;
1637 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1638 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301639 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1640 section = ROOT;
1641 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1642 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301643 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1644 section = ROOT;
1645 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1646 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001647 }
Ben Romberger55886882014-01-10 13:49:02 -08001648}
1649
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001650int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001651{
1652 XML_Parser parser;
1653 FILE *file;
1654 int ret = 0;
1655 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001656 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001657 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301658 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001659
Saurav Kumardba3caf2020-05-29 20:53:55 +05301660 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1661 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001662 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001663 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301664 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001665 MIXER_PATH_MAX_LENGTH);
1666 else
1667 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1668
1669 ALOGV("%s: platform info file name is %s", __func__,
1670 platform_info_file_name);
1671
1672 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001673 section = ROOT;
1674
Ben Romberger55886882014-01-10 13:49:02 -08001675 if (!file) {
1676 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001677 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001678 ret = -ENODEV;
1679 goto done;
1680 }
1681
1682 parser = XML_ParserCreate(NULL);
1683 if (!parser) {
1684 ALOGE("%s: Failed to create XML parser!", __func__);
1685 ret = -ENODEV;
1686 goto err_close_file;
1687 }
1688
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001689 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001690 my_data.platform = platform;
Sandhya Mutha Naga Venkata4c6fc9f2022-10-14 19:38:02 +05301691
1692 if (!my_data.kvpairs)
1693 my_data.kvpairs = str_parms_create();
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001694
Ben Romberger55886882014-01-10 13:49:02 -08001695 XML_SetElementHandler(parser, start_tag, end_tag);
1696
1697 while (1) {
1698 buf = XML_GetBuffer(parser, BUF_SIZE);
1699 if (buf == NULL) {
1700 ALOGE("%s: XML_GetBuffer failed", __func__);
1701 ret = -ENOMEM;
1702 goto err_free_parser;
1703 }
1704
1705 bytes_read = fread(buf, 1, BUF_SIZE, file);
1706 if (bytes_read < 0) {
1707 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1708 ret = bytes_read;
1709 goto err_free_parser;
1710 }
1711
1712 if (XML_ParseBuffer(parser, bytes_read,
1713 bytes_read == 0) == XML_STATUS_ERROR) {
1714 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001715 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001716 ret = -EINVAL;
1717 goto err_free_parser;
1718 }
1719
1720 if (bytes_read == 0)
1721 break;
1722 }
1723
Ben Romberger55886882014-01-10 13:49:02 -08001724err_free_parser:
1725 XML_ParserFree(parser);
1726err_close_file:
1727 fclose(file);
1728done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001729 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001730 return ret;
1731}
Sandhya Mutha Naga Venkata4c6fc9f2022-10-14 19:38:02 +05301732
1733void platform_info_deinit()
1734{
1735 if (my_data.kvpairs)
1736 str_parms_destroy(my_data.kvpairs);
1737}