blob: d10189a6b0d062cdb62d0829969c51010d653728 [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>
LuK1337994b0762021-05-28 08:01:40 +020078#include <pthread.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070079#include <math.h>
Fei Tongc20ce932021-06-21 16:42:38 +080080#ifdef LINUX_ENABLED
81#include <float.h>
82#endif
Ben Romberger55886882014-01-10 13:49:02 -080083
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053084#ifdef DYNAMIC_LOG_ENABLED
85#include <log_xml_parser.h>
86#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
87#include <log_utils.h>
88#endif
89
Ben Romberger55886882014-01-10 13:49:02 -080090#define BUF_SIZE 1024
Saurav Kumardba3caf2020-05-29 20:53:55 +053091char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH];
92char platform_info_xml_path_file[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -080093
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070094typedef enum {
95 ROOT,
96 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070097 MODULE,
98 AEC,
99 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700100 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700101 PCM_ID,
102 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800103 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700104 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -0800105 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700106 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -0800107 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530108 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530109 MICROPHONE_CHARACTERISTIC,
110 SND_DEVICES,
111 INPUT_SND_DEVICE,
112 INPUT_SND_DEVICE_TO_MIC_MAPPING,
113 SND_DEV,
114 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530115 CUSTOM_MTMX_PARAMS,
116 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -0700117 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530118 CUSTOM_MTMX_IN_PARAMS,
119 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +0800120 MMSECNS,
Juyu Chen918e1e12019-08-08 15:28:18 -0700121 AUDIO_SOURCE_DELAY,
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +0530122#ifdef SOFT_VOLUME
123 SOFT_VOLUME_PARAMS,
124#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700125} section_t;
126
127typedef void (* section_process_fn)(const XML_Char **attr);
128
Saurav Kumardba3caf2020-05-29 20:53:55 +0530129const char* get_platform_xml_path()
130{
131 audio_get_vendor_config_path(vendor_config_path, sizeof(vendor_config_path));
132 /* Get path for platorm_info_xml_path_name in vendor */
133 snprintf(platform_info_xml_path_file, sizeof(platform_info_xml_path_file),
134 "%s/%s", vendor_config_path, PLATFORM_INFO_XML_PATH_NAME);
135 return platform_info_xml_path_file;
136}
137
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700138static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700139static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
140static void process_effect_aec(const XML_Char **attr);
141static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -0700142static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700143static void process_pcm_id(const XML_Char **attr);
144static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800145static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700146static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700147static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800148static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700149static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800150static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530151static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530152static void process_microphone_characteristic(const XML_Char **attr);
153static void process_snd_dev(const XML_Char **attr);
154static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530155static void process_custom_mtmx_params(const XML_Char **attr);
156static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700157static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530158static void process_custom_mtmx_in_params(const XML_Char **attr);
159static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Guodong Hu1d46f342019-06-28 16:57:30 +0800160static void process_fluence_mmsecns(const XML_Char **attr);
Juyu Chen918e1e12019-08-08 15:28:18 -0700161static void process_audio_source_delay(const XML_Char **attr);
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +0530162#ifdef SOFT_VOLUME
163static void process_soft_volume_params(const XML_Char **attr);
164#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700165
166static section_process_fn section_table[] = {
167 [ROOT] = process_root,
168 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700169 [AEC] = process_effect_aec,
170 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700171 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700172 [PCM_ID] = process_pcm_id,
173 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800174 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700175 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800176 [OPERATOR_SPECIFIC] = process_operator_specific,
177 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700178 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530179 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530180 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
181 [SND_DEV] = process_snd_dev,
182 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530183 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
184 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700185 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530186 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
187 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800188 [MMSECNS] = process_fluence_mmsecns,
Juyu Chen918e1e12019-08-08 15:28:18 -0700189 [AUDIO_SOURCE_DELAY] = process_audio_source_delay,
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +0530190#ifdef SOFT_VOLUME
191 [SOFT_VOLUME_PARAMS] = process_soft_volume_params,
192#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700193};
194
195static section_t section;
196
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700197struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700198 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700199 void *platform;
200 struct str_parms *kvpairs;
201};
202
203static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800204static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700205
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530206
207struct audio_string_to_enum {
208 const char* name;
209 unsigned int value;
210};
211
212static snd_device_t in_snd_device;
213
214static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
215 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
216 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
217 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
218 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
219};
220
221static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
222 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
223 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
224 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
225 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
226 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
227 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
228};
229
230static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
231 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
232 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
233 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
234};
235
236static const struct audio_string_to_enum device_in_types[] = {
237 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
238 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
239 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
240 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
241 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
242 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
243 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
244 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
245 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
246 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
247 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
248 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
249 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
250 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
251 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
252 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
253 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
254 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
255 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
256 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
257 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
258 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
259 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
260 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
261 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
262 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
263 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
264};
265
266enum {
267 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
268 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
269 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
270 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
271 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
272 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
273 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
274 | ORIENTATION) | GEOMETRIC_LOCATION) */
275};
276
277static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
278 int32_t len, unsigned int *value)
279{
280 if (table == NULL) {
281 ALOGE("%s: table is NULL", __func__);
282 return false;
283 }
284
285 if (name == NULL) {
286 ALOGE("null key");
287 return false;
288 }
289
290 for (int i = 0; i < len; i++) {
291 if (!strcmp(table[i].name, name)) {
292 *value = table[i].value;
293 return true;
294 }
295 }
296 return false;
297}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530298
299static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530300static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530301
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700302static void process_root(const XML_Char **attr __unused)
303{
304}
305
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +0530306#ifdef SOFT_VOLUME
307/**mapping usecase and soft volume params **/
308static void process_soft_volume_params(const XML_Char **attr)
309{
310 int index;
311
312 if (strcmp(attr[0], "name") != 0) {
313 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
314 goto done;
315 }
316
317 index = platform_get_usecase_index((char *)attr[1]);
318 if (index < 0) {
319 ALOGE("%s: usecase %s not found!",
320 __func__, attr[1]);
321 goto done;
322 }
323
324 if (strcmp(attr[2], "period") != 0) {
325 ALOGE("%s: ramp period not mentioned", __func__);
326 goto done;
327 }
328
329 int period = atoi((char *)attr[3]);
330
331 if (strcmp(attr[4], "step") != 0) {
332 ALOGE("%s: ramp period not mentioned", __func__);
333 goto done;
334 }
335 int step = atoi((char *)attr[5]);
336
337 if (strcmp(attr[6], "curve") != 0) {
338 ALOGE("%s: usecase id not mentioned", __func__);
339 goto done;
340 }
341
342 int curve = atoi((char *)attr[7]);
343
344 if (platform_set_soft_step_volume_params(index, period, step, curve) < 0) {
345 ALOGE("%s: usecase %s period %d step %d curve %d ",
346 __func__, attr[1], period, step, curve);
347 goto done;
348 }
349
350done:
351 return;
352}
353#endif
354
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700355/* mapping from usecase to pcm dev id */
356static void process_pcm_id(const XML_Char **attr)
357{
358 int index;
359
360 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700361 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700362 goto done;
363 }
364
365 index = platform_get_usecase_index((char *)attr[1]);
366 if (index < 0) {
367 ALOGE("%s: usecase %s not found!",
368 __func__, attr[1]);
369 goto done;
370 }
371
372 if (strcmp(attr[2], "type") != 0) {
373 ALOGE("%s: usecase type not mentioned", __func__);
374 goto done;
375 }
376
377 int type = -1;
378
379 if (!strcasecmp((char *)attr[3], "in")) {
380 type = 1;
381 } else if (!strcasecmp((char *)attr[3], "out")) {
382 type = 0;
383 } else {
384 ALOGE("%s: type must be IN or OUT", __func__);
385 goto done;
386 }
387
388 if (strcmp(attr[4], "id") != 0) {
389 ALOGE("%s: usecase id not mentioned", __func__);
390 goto done;
391 }
392
Manoj Kumar N D7951b252022-08-23 13:18:00 +0530393 int pcm_id = atoi((char *)attr[5]);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700394
Manoj Kumar N D569498a2022-10-19 14:38:19 +0530395#ifdef PLATFORM_AUTO
Manoj Kumar N D7951b252022-08-23 13:18:00 +0530396 if (strcmp(attr[6], "fe") != 0) {
397 ALOGE("%s: fe id not mentioned", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700398 goto done;
399 }
400
Manoj Kumar N D7951b252022-08-23 13:18:00 +0530401 int fe_id = atoi((char *)attr[7]);
402
403 if (platform_set_usecase_pcm_id(index, type, pcm_id, fe_id) < 0) {
404 ALOGE("%s: usecase %s type %d pcm_id %d fe_id %d was not set!",
405 __func__, attr[1], type, pcm_id, fe_id);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700406 goto done;
407 }
Manoj Kumar N D569498a2022-10-19 14:38:19 +0530408#else
409 int fe_id = -1;
410
411 if (platform_set_usecase_pcm_id(index, type, pcm_id, fe_id) < 0) {
412 ALOGE("%s: usecase %s type %d pcm_id %d fe_id %d was not set!",
413 __func__, attr[1], type, pcm_id, fe_id);
414 goto done;
415 }
416#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700417
418done:
419 return;
420}
421
422/* backend to be used for a device */
423static void process_backend_name(const XML_Char **attr)
424{
425 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530426 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530427 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700428
429 if (strcmp(attr[0], "name") != 0) {
430 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
431 goto done;
432 }
433
434 index = platform_get_snd_device_index((char *)attr[1]);
435 if (index < 0) {
436 ALOGE("%s: Device %s not found, no ACDB ID set!",
437 __func__, attr[1]);
438 goto done;
439 }
440
441 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530442 if (strcmp(attr[2], "interface") == 0)
443 hw_interface = (char *)attr[3];
444 } else {
445 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700446 }
447
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530448 if (attr[4] != NULL) {
449 if (strcmp(attr[4], "interface") != 0) {
450 hw_interface = NULL;
451 } else {
452 hw_interface = (char *)attr[5];
453 }
454 }
455
Ashish Jaind150d4c2017-02-03 18:44:34 +0530456 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700457 ALOGE("%s: Device %s backend %s was not set!",
458 __func__, attr[1], attr[3]);
459 goto done;
460 }
461
462done:
463 return;
464}
465
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700466static void process_gain_db_to_level_map(const XML_Char **attr)
467{
468 struct amp_db_and_gain_table tbl_entry;
469
470 if ((strcmp(attr[0], "db") != 0) ||
471 (strcmp(attr[2], "level") != 0)) {
472 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
473 __func__, attr[0], attr[2]);
474 goto done;
475 }
476
477 tbl_entry.db = atof(attr[1]);
478 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
479 tbl_entry.level = atoi(attr[3]);
480
Aalique Grahame22e49102018-12-18 14:23:57 -0800481 //custome level should be > 0. Level 0 is fixed for default
482 CHECK(tbl_entry.level > 0);
483
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700484 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
485 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
486 platform_add_gain_level_mapping(&tbl_entry);
487
488done:
489 return;
490}
491
492
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700493static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800494{
Ben Romberger61764e32014-01-10 13:49:02 -0800495 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800496
Ben Romberger61764e32014-01-10 13:49:02 -0800497 if (strcmp(attr[0], "name") != 0) {
498 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800499 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800500 }
Ben Romberger55886882014-01-10 13:49:02 -0800501
Ben Romberger61764e32014-01-10 13:49:02 -0800502 index = platform_get_snd_device_index((char *)attr[1]);
503 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800504 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
505 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800506 goto done;
507 }
508
509 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800510 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
511 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800512 goto done;
513 }
514
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700515 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
516 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800517 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800518 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800519 }
Ben Romberger55886882014-01-10 13:49:02 -0800520
Ben Romberger55886882014-01-10 13:49:02 -0800521done:
522 return;
523}
524
Aalique Grahame22e49102018-12-18 14:23:57 -0800525static void process_operator_specific(const XML_Char **attr)
526{
527 snd_device_t snd_device = SND_DEVICE_NONE;
528
529 if (strcmp(attr[0], "name") != 0) {
530 ALOGE("%s: 'name' not found", __func__);
531 goto done;
532 }
533
534 snd_device = platform_get_snd_device_index((char *)attr[1]);
535 if (snd_device < 0) {
536 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530537 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800538 goto done;
539 }
540
541 if (strcmp(attr[2], "operator") != 0) {
542 ALOGE("%s: 'operator' not found", __func__);
543 goto done;
544 }
545
546 if (strcmp(attr[4], "mixer_path") != 0) {
547 ALOGE("%s: 'mixer_path' not found", __func__);
548 goto done;
549 }
550
551 if (strcmp(attr[6], "acdb_id") != 0) {
552 ALOGE("%s: 'acdb_id' not found", __func__);
553 goto done;
554 }
555
556 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
557
558done:
559 return;
560}
561
Carter Hsu32a62362018-10-15 15:01:42 -0700562static void process_external_dev(const XML_Char **attr)
563{
564 snd_device_t snd_device = SND_DEVICE_NONE;
565
566 if (strcmp(attr[0], "name") != 0) {
567 ALOGE("%s: 'name' not found", __func__);
568 goto done;
569 }
570
571 snd_device = platform_get_snd_device_index((char *)attr[1]);
572 if (snd_device < 0) {
573 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530574 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700575 goto done;
576 }
577
578 if (strcmp(attr[2], "usbid") != 0) {
579 ALOGE("%s: 'usbid' not found", __func__);
580 goto done;
581 }
582
583 if (strcmp(attr[4], "acdb_id") != 0) {
584 ALOGE("%s: 'acdb_id' not found", __func__);
585 goto done;
586 }
587
588 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
589
590done:
591 return;
592}
593
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700594static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
595{
596 int index;
597 struct audio_effect_config effect_config;
598
599 if (strcmp(attr[0], "name") != 0) {
600 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
601 goto done;
602 }
603
604 index = platform_get_snd_device_index((char *)attr[1]);
605 if (index < 0) {
606 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
607 __func__, attr[1]);
608 goto done;
609 }
610
611 if (strcmp(attr[2], "module_id") != 0) {
612 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
613 __func__, attr[2]);
614 goto done;
615 }
616
617 if (strcmp(attr[4], "instance_id") != 0) {
618 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
619 __func__, attr[4]);
620 goto done;
621 }
622
623 if (strcmp(attr[6], "param_id") != 0) {
624 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
625 __func__, attr[6]);
626 goto done;
627 }
628
629 if (strcmp(attr[8], "param_value") != 0) {
630 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
631 __func__, attr[8]);
632 goto done;
633 }
634
635 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
636 strtol((char *)attr[5], NULL, 0),
637 strtol((char *)attr[7], NULL, 0),
638 strtol((char *)attr[9], NULL, 0)};
639
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700640 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
641 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
642 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
643 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
644 strtol((char *)attr[9], NULL, 0));
645 goto done;
646 }
647
648done:
649 return;
650}
651
652static void process_effect_aec(const XML_Char **attr)
653{
654 process_audio_effect(attr, EFFECT_AEC);
655 return;
656}
657
658static void process_effect_ns(const XML_Char **attr)
659{
660 process_audio_effect(attr, EFFECT_NS);
661 return;
662}
663
Guodong Hu1d46f342019-06-28 16:57:30 +0800664static void process_fluence_mmsecns(const XML_Char **attr)
665{
666 int index;
667 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
668
669 if (strcmp(attr[0], "name") != 0) {
670 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
671 goto done;
672 }
673
674 index = platform_get_snd_device_index((char *)attr[1]);
675 if (index < 0) {
676 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
677 __func__, attr[1]);
678 goto done;
679 }
680
681 if (strcmp(attr[2], "topology_id") != 0) {
682 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
683 __func__, attr[2]);
684 goto done;
685 }
686
687 if (strcmp(attr[4], "module_id") != 0) {
688 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
689 __func__, attr[4]);
690 goto done;
691 }
692
693 if (strcmp(attr[6], "instance_id") != 0) {
694 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
695 __func__, attr[6]);
696 goto done;
697 }
698
699 if (strcmp(attr[8], "param_id") != 0) {
700 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
701 __func__, attr[8]);
702 goto done;
703 }
704
705 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
706 strtol((char *)attr[5], NULL, 0),
707 strtol((char *)attr[7], NULL, 0),
708 strtol((char *)attr[9], NULL, 0)};
709
710
711 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
712 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
713 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
714 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
715 goto done;
716 }
717
718done:
719 return;
720}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700721static void process_bit_width(const XML_Char **attr)
722{
723 int index;
724
725 if (strcmp(attr[0], "name") != 0) {
726 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
727 goto done;
728 }
729
730 index = platform_get_snd_device_index((char *)attr[1]);
731 if (index < 0) {
732 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
733 __func__, attr[1]);
734 goto done;
735 }
736
737 if (strcmp(attr[2], "bit_width") != 0) {
738 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
739 __func__, attr[1]);
740 goto done;
741 }
742
743 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
744 ALOGE("%s: Device %s, ACDB ID %d was not set!",
745 __func__, attr[1], atoi((char *)attr[3]));
746 goto done;
747 }
748
749done:
750 return;
751}
752
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800753static void process_interface_name(const XML_Char **attr)
754{
755 int ret;
756
757 if (strcmp(attr[0], "name") != 0) {
758 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
759
760 goto done;
761 }
762
763 if (strcmp(attr[2], "interface") != 0) {
764 ALOGE("%s: Device %s has no Audio Interface set!",
765 __func__, attr[1]);
766
767 goto done;
768 }
769
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530770 if (strcmp(attr[4], "codec_type") != 0) {
771 ALOGE("%s: Device %s has no codec type set!",
772 __func__, attr[1]);
773
774 goto done;
775 }
776
777 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
778 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800779 if (ret < 0) {
780 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800781 goto done;
782 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800783
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800784done:
785 return;
786}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530787
Juyu Chen918e1e12019-08-08 15:28:18 -0700788static void process_audio_source_delay(const XML_Char **attr)
789{
790 audio_source_t audio_source = -1;
791
792 if (strcmp(attr[0], "name") != 0) {
793 ALOGE("%s: 'name' not found", __func__);
794 goto done;
795 }
George Gao9ba8a142020-07-23 14:30:03 -0700796
Juyu Chen918e1e12019-08-08 15:28:18 -0700797 audio_source = platform_get_audio_source_index((const char *)attr[1]);
798
799 if (audio_source < 0) {
800 ALOGE("%s: audio_source %s is not defined",
801 __func__, (char *)attr[1]);
802 goto done;
803 }
804
805 if (strcmp(attr[2], "delay") != 0) {
806 ALOGE("%s: 'delay' not found", __func__);
807 goto done;
808 }
809
810 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
811
812done:
813 return;
814}
815
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700816static void process_config_params(const XML_Char **attr)
817{
818 if (strcmp(attr[0], "key") != 0) {
819 ALOGE("%s: 'key' not found", __func__);
820 goto done;
821 }
822
823 if (strcmp(attr[2], "value") != 0) {
824 ALOGE("%s: 'value' not found", __func__);
825 goto done;
826 }
827
828 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700829 if (my_data.caller == PLATFORM)
830 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700831done:
832 return;
833}
834
Aalique Grahame22e49102018-12-18 14:23:57 -0800835static void process_app_type(const XML_Char **attr)
836{
837 if (strcmp(attr[0], "uc_type")) {
838 ALOGE("%s: uc_type not found", __func__);
839 goto done;
840 }
841
842 if (strcmp(attr[2], "mode")) {
843 ALOGE("%s: mode not found", __func__);
844 goto done;
845 }
846
847 if (strcmp(attr[4], "bit_width")) {
848 ALOGE("%s: bit_width not found", __func__);
849 goto done;
850 }
851
852 if (strcmp(attr[6], "id")) {
853 ALOGE("%s: id not found", __func__);
854 goto done;
855 }
856
857 if (strcmp(attr[8], "max_rate")) {
858 ALOGE("%s: max rate not found", __func__);
859 goto done;
860 }
861
862 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
863 atoi(attr[9]));
864done:
865 return;
866}
867
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530868static void process_microphone_characteristic(const XML_Char **attr) {
869 struct audio_microphone_characteristic_t microphone;
870 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530871 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530872
Saurav Kumardba3caf2020-05-29 20:53:55 +0530873 strlcpy(platform_info_xml_path, get_platform_xml_path(),
874 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530875 if (strcmp(attr[curIdx++], "valid_mask")) {
876 ALOGE("%s: valid_mask not found", __func__);
877 goto done;
878 }
879 uint32_t valid_mask = atoi(attr[curIdx++]);
880
881 if (strcmp(attr[curIdx++], "device_id")) {
882 ALOGE("%s: device_id not found", __func__);
883 goto done;
884 }
885 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
886 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
887 goto done;
888 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530889 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530890
891 if (strcmp(attr[curIdx++], "type")) {
892 ALOGE("%s: device not found", __func__);
893 goto done;
894 }
895 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
896 ARRAY_SIZE(device_in_types), &microphone.device)) {
897 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530898 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530899 goto done;
900 }
901
902 if (strcmp(attr[curIdx++], "address")) {
903 ALOGE("%s: address not found", __func__);
904 goto done;
905 }
906 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
907 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
908 goto done;
909 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530910 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530911 if (strlen(microphone.address) == 0) {
912 // If the address is empty, populate the address according to device type.
913 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530914 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530915 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530916 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530917 }
918 }
919
920 if (strcmp(attr[curIdx++], "location")) {
921 ALOGE("%s: location not found", __func__);
922 goto done;
923 }
924 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
925 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
926 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530927 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530928 goto done;
929 }
930
931 if (strcmp(attr[curIdx++], "group")) {
932 ALOGE("%s: group not found", __func__);
933 goto done;
934 }
935 microphone.group = atoi(attr[curIdx++]);
936
937 if (strcmp(attr[curIdx++], "index_in_the_group")) {
938 ALOGE("%s: index_in_the_group not found", __func__);
939 goto done;
940 }
941 microphone.index_in_the_group = atoi(attr[curIdx++]);
942
943 if (strcmp(attr[curIdx++], "directionality")) {
944 ALOGE("%s: directionality not found", __func__);
945 goto done;
946 }
947 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
948 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
949 ALOGE("%s: directionality %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530950 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530951 goto done;
952 }
953
954 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
955 ALOGE("%s: num_frequency_responses not found", __func__);
956 goto done;
957 }
958 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530959 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530960 ALOGE("%s: num_frequency_responses is too large", __func__);
961 goto done;
962 }
963 if (microphone.num_frequency_responses > 0) {
964 if (strcmp(attr[curIdx++], "frequencies")) {
965 ALOGE("%s: frequencies not found", __func__);
966 goto done;
967 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530968 char *context = NULL;
969 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530970 uint32_t num_frequencies = 0;
971 while (token) {
972 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800973 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530974 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530975 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530976 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530977 }
978
979 if (strcmp(attr[curIdx++], "responses")) {
980 ALOGE("%s: responses not found", __func__);
981 goto done;
982 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530983 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530984 uint32_t num_responses = 0;
985 while (token) {
986 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800987 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530988 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530989 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530990 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530991 }
992
993 if (num_frequencies != num_responses
994 || num_frequencies != microphone.num_frequency_responses) {
995 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
996 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
997 goto done;
998 }
999 }
1000
1001 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
1002 if (strcmp(attr[curIdx++], "sensitivity")) {
1003 ALOGE("%s: sensitivity not found", __func__);
1004 goto done;
1005 }
1006 microphone.sensitivity = atof(attr[curIdx++]);
1007 } else {
1008 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
1009 }
1010
1011 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
1012 if (strcmp(attr[curIdx++], "max_spl")) {
1013 ALOGE("%s: max_spl not found", __func__);
1014 goto done;
1015 }
1016 microphone.max_spl = atof(attr[curIdx++]);
1017 } else {
1018 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1019 }
1020
1021 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
1022 if (strcmp(attr[curIdx++], "min_spl")) {
1023 ALOGE("%s: min_spl not found", __func__);
1024 goto done;
1025 }
1026 microphone.min_spl = atof(attr[curIdx++]);
1027 } else {
1028 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1029 }
1030
1031 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
1032 if (strcmp(attr[curIdx++], "orientation")) {
1033 ALOGE("%s: orientation not found", __func__);
1034 goto done;
1035 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301036 char *context = NULL;
1037 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301038 float orientation[3];
1039 uint32_t idx = 0;
1040 while (token) {
1041 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001042 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301043 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301044 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301045 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301046 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301047 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301048 ALOGE("%s: orientation invalid", __func__);
1049 goto done;
1050 }
1051 microphone.orientation.x = orientation[0];
1052 microphone.orientation.y = orientation[1];
1053 microphone.orientation.z = orientation[2];
1054 } else {
1055 microphone.orientation.x = 0.0f;
1056 microphone.orientation.y = 0.0f;
1057 microphone.orientation.z = 0.0f;
1058 }
1059
1060 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
1061 if (strcmp(attr[curIdx++], "geometric_location")) {
1062 ALOGE("%s: geometric_location not found", __func__);
1063 goto done;
1064 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301065 char *context = NULL;
1066 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301067 float geometric_location[3];
1068 uint32_t idx = 0;
1069 while (token) {
1070 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001071 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301072 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301073 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301074 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301075 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301076 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301077 ALOGE("%s: geometric_location invalid", __func__);
1078 goto done;
1079 }
1080 microphone.geometric_location.x = geometric_location[0];
1081 microphone.geometric_location.y = geometric_location[1];
1082 microphone.geometric_location.z = geometric_location[2];
1083 } else {
1084 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1085 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1086 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1087 }
1088
1089 platform_set_microphone_characteristic(my_data.platform, microphone);
1090done:
1091 return;
1092}
1093
1094static void process_snd_dev(const XML_Char **attr)
1095{
1096 uint32_t curIdx = 0;
1097 in_snd_device = SND_DEVICE_NONE;
1098
1099 if (strcmp(attr[curIdx++], "in_snd_device")) {
1100 ALOGE("%s: snd_device not found", __func__);
1101 return;
1102 }
1103 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1104 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1105 in_snd_device >= SND_DEVICE_IN_END) {
1106 ALOGE("%s: Sound device not valid", __func__);
1107 in_snd_device = SND_DEVICE_NONE;
1108 }
1109
1110 return;
1111}
1112
1113static void process_mic_info(const XML_Char **attr)
1114{
1115 uint32_t curIdx = 0;
1116 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301117 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301118
Saurav Kumardba3caf2020-05-29 20:53:55 +05301119 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1120 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301121 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1122 sizeof(microphone.channel_mapping));
1123
1124 if (strcmp(attr[curIdx++], "mic_device_id")) {
1125 ALOGE("%s: mic_device_id not found", __func__);
1126 goto on_error;
1127 }
1128 strlcpy(microphone.device_id,
1129 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1130
1131 if (strcmp(attr[curIdx++], "channel_mapping")) {
1132 ALOGE("%s: channel_mapping not found", __func__);
1133 goto on_error;
1134 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301135 char *context = NULL;
1136 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301137 uint32_t idx = 0;
1138 while (token) {
1139 if (!find_enum_by_string(mic_channel_mapping, token,
1140 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1141 &microphone.channel_mapping[idx++])) {
1142 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301143 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301144 goto on_error;
1145 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301146 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301147 }
1148 microphone.channel_count = idx;
1149
1150 platform_set_microphone_map(my_data.platform, in_snd_device,
1151 &microphone);
1152 return;
1153on_error:
1154 in_snd_device = SND_DEVICE_NONE;
1155 return;
1156}
1157
1158
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301159/* process acdb meta info key value */
1160static void process_acdb_metainfo_key(const XML_Char **attr)
1161{
1162 if (strcmp(attr[0], "name") != 0) {
1163 ALOGE("%s: 'name' not found", __func__);
1164 goto done;
1165 }
1166
1167 if (strcmp(attr[2], "value") != 0) {
1168 ALOGE("%s: 'value' not found", __func__);
1169 goto done;
1170 }
1171
1172 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001173 switch(my_data.caller) {
1174 case ACDB_EXTN:
1175 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1176 ALOGE("%s: key %d was not set!", __func__, key);
1177 goto done;
1178 }
1179 break;
1180 case PLATFORM:
1181 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1182 ALOGE("%s: key %d was not set!", __func__, key);
1183 goto done;
1184 }
1185 break;
1186 default:
1187 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301188 }
1189
1190done:
1191 return;
1192}
1193
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301194static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1195{
1196 uint32_t attr_idx = 0;
1197 int32_t in_ch_idx = -1;
1198 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1199
1200 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1201 &mtmx_in_params_info);
1202 if (mtmx_in_params == NULL) {
1203 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1204 return;
1205 }
1206
1207 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1208 ALOGE("%s: 'in_channel_index' not found", __func__);
1209 return;
1210 }
1211
1212 in_ch_idx = atoi((char *)attr[attr_idx++]);
1213 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1214 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1215 return;
1216 }
1217
1218 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1219 ALOGE("%s: 'channel_count' not found", __func__);
1220 return;
1221 }
1222 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1223
1224 if (strcmp(attr[attr_idx++], "device") != 0) {
1225 ALOGE("%s: 'device' not found", __func__);
1226 return;
1227 }
1228 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1229 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1230
1231 if (strcmp(attr[attr_idx++], "interface") != 0) {
1232 ALOGE("%s: 'interface' not found", __func__);
1233 return;
1234 }
1235 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1236 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1237
1238 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1239 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1240 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1241 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1242 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1243 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1244 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1245 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301246 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1247 ENUM_TO_STRING(AUDIO_DEVICE_IN_SPEAKER_MIC2),
1248 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1249 mtmx_in_params->i2s_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301250
1251 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1252}
1253
1254static void process_custom_mtmx_in_params(const XML_Char **attr)
1255{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301256 int attr_idx = 0, i = 0;
1257 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301258
1259 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1260 ALOGE("%s: 'usecase' not found", __func__);
1261 return;
1262 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301263 /* Check if multi usecases are supported for this custom mtrx params */
1264 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1265 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1266 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1267 value = strtok_r(NULL, ",", &context);
1268 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301269
1270 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1271 ALOGE("%s: 'out_channel_count' not found", __func__);
1272 return;
1273 }
1274 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1275
1276 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1277
1278}
1279
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301280static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1281{
1282 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301283 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301284 char *context = NULL, *ch_coeff_value = NULL;
1285 struct audio_custom_mtmx_params *mtmx_params = NULL;
1286
1287 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1288 ALOGE("%s: 'out_channel_index' not found", __func__);
1289 return;
1290 }
1291 out_ch_idx = atoi((char *)attr[attr_idx++]);
1292
1293 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1294 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1295 return;
1296 }
1297
1298 if (strcmp(attr[attr_idx++], "values") != 0) {
1299 ALOGE("%s: 'values' not found", __func__);
1300 return;
1301 }
1302 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301303 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301304 if (mtmx_params == NULL) {
1305 ALOGE("%s: mtmx params with given param info, not found", __func__);
1306 return;
1307 }
1308 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1309 ip_channels = mtmx_params->info.ip_channels;
1310 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301311 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301312 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1313 = atoi(ch_coeff_value);
1314 ch_coeff_value = strtok_r(NULL, " ", &context);
1315 }
1316 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1317 ch_coeff_value != NULL)
1318 ALOGE("%s: invalid/malformed coefficient values", __func__);
1319}
1320
1321static void process_custom_mtmx_params(const XML_Char **attr)
1322{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301323 int attr_idx = 0, i = 0;
1324 char *context = NULL, *value = NULL;
1325
1326 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301327
1328 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1329 ALOGE("%s: 'param_id' not found", __func__);
1330 return;
1331 }
1332 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1333
1334 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1335 ALOGE("%s: 'in_channel_count' not found", __func__);
1336 return;
1337 }
1338 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1339
1340 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1341 ALOGE("%s: 'out_channel_count' not found", __func__);
1342 return;
1343 }
1344 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1345
1346 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1347 ALOGE("%s: 'usecase' not found", __func__);
1348 return;
1349 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301350
1351 /* check if multi usecases are supported for this custom mtrx params */
1352 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1353 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1354 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1355 value = strtok_r(NULL, ",", &context);
1356 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301357
1358 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1359 ALOGE("%s: 'snd_device' not found", __func__);
1360 return;
1361 }
1362 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301363
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301364 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1365 i = 0;
1366 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1367 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1368 mtmx_params_info.fe_id[i++] = atoi(value);
1369 value = strtok_r(NULL, ",", &context);
1370 }
1371
1372 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301373 }
1374
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301375 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1376
1377}
1378
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001379static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001380 const XML_Char **attr)
1381{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001382 if (my_data.caller == ACDB_EXTN) {
1383 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1384 section = ACDB_METAINFO_KEY;
1385 } else if (strcmp(tag_name, "param") == 0) {
1386 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1387 ALOGE("param tag only supported with CONFIG_PARAMS section");
1388 return;
1389 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001390
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001391 section_process_fn fn = section_table[section];
1392 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001393 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001394 } else if(my_data.caller == PLATFORM) {
1395 if (strcmp(tag_name, "bit_width_configs") == 0) {
1396 section = BITWIDTH;
1397 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1398 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001399 } else if (strcmp(tag_name, "module_ids") == 0) {
1400 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001401 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1402 section = PCM_ID;
1403 } else if (strcmp(tag_name, "backend_names") == 0) {
1404 section = BACKEND_NAME;
1405 } else if (strcmp(tag_name, "config_params") == 0) {
1406 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001407 } else if (strcmp(tag_name, "operator_specific") == 0) {
1408 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001409 } else if (strcmp(tag_name, "interface_names") == 0) {
1410 section = INTERFACE_NAME;
1411 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1412 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001413 } else if (strcmp(tag_name, "app_types") == 0) {
1414 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001415 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1416 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301417 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1418 section = MICROPHONE_CHARACTERISTIC;
1419 } else if (strcmp(tag_name, "snd_devices") == 0) {
1420 section = SND_DEVICES;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301421#ifdef SOFT_VOLUME
1422 } else if (strcmp(tag_name, "soft_vol_params") == 0) {
1423 section = SOFT_VOLUME_PARAMS;
1424#endif
1425 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001426 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001427 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001428 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001429 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1430 return;
1431 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001432
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001433 /* call into process function for the current section */
1434 section_process_fn fn = section_table[section];
1435 fn(attr);
1436 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1437 if (section != GAIN_LEVEL_MAPPING) {
1438 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1439 return;
1440 }
1441
1442 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1443 fn(attr);
1444 } else if (strcmp(tag_name, "usecase") == 0) {
1445 if (section != PCM_ID) {
1446 ALOGE("usecase tag only supported with PCM_ID section");
1447 return;
1448 }
1449
1450 section_process_fn fn = section_table[PCM_ID];
1451 fn(attr);
1452 } else if (strcmp(tag_name, "param") == 0) {
1453 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1454 ALOGE("param tag only supported with CONFIG_PARAMS section");
1455 return;
1456 }
1457
1458 section_process_fn fn = section_table[section];
1459 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301460 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001461 if (section != MODULE) {
1462 ALOGE("aec tag only supported with MODULE section");
1463 return;
1464 }
1465 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301466 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001467 if (section != MODULE) {
1468 ALOGE("ns tag only supported with MODULE section");
1469 return;
1470 }
1471 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001472 } else if (strcmp(tag_name, "mmsecns") == 0) {
1473 if (section != MODULE) {
1474 ALOGE("mmsecns tag only supported with MODULE section");
1475 return;
1476 }
1477 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001478 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1479 if (section != GAIN_LEVEL_MAPPING) {
1480 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1481 return;
1482 }
1483
1484 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1485 fn(attr);
1486 } else if (!strcmp(tag_name, "app")) {
1487 if (section != APP_TYPE) {
1488 ALOGE("app tag only valid in section APP_TYPE");
1489 return;
1490 }
1491
1492 section_process_fn fn = section_table[APP_TYPE];
1493 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301494 } else if (strcmp(tag_name, "microphone") == 0) {
1495 if (section != MICROPHONE_CHARACTERISTIC) {
1496 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1497 return;
1498 }
1499 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1500 fn(attr);
1501 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1502 if (section != SND_DEVICES) {
1503 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1504 return;
1505 }
1506 section = INPUT_SND_DEVICE;
1507 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1508 if (section != INPUT_SND_DEVICE) {
1509 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1510 return;
1511 }
1512 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1513 } else if (strcmp(tag_name, "snd_dev") == 0) {
1514 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1515 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1516 return;
1517 }
1518 section_process_fn fn = section_table[SND_DEV];
1519 fn(attr);
1520 } else if (strcmp(tag_name, "mic_info") == 0) {
1521 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1522 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1523 return;
1524 }
1525 if (in_snd_device == SND_DEVICE_NONE) {
1526 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1527 return;
1528 }
1529 section_process_fn fn = section_table[MIC_INFO];
1530 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301531 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1532 if (section != ROOT) {
1533 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1534 return;
1535 }
1536 section = CUSTOM_MTMX_PARAMS;
1537 section_process_fn fn = section_table[section];
1538 fn(attr);
1539 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1540 if (section != CUSTOM_MTMX_PARAMS) {
1541 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1542 return;
1543 }
1544 section = CUSTOM_MTMX_PARAM_COEFFS;
1545 section_process_fn fn = section_table[section];
1546 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001547 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1548 section = EXTERNAL_DEVICE_SPECIFIC;
1549 } else if (strcmp(tag_name, "ext_device") == 0) {
1550 section_process_fn fn = section_table[section];
1551 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301552 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1553 if (section != ROOT) {
1554 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1555 return;
1556 }
1557 section = CUSTOM_MTMX_IN_PARAMS;
1558 section_process_fn fn = section_table[section];
1559 fn(attr);
1560 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1561 if (section != CUSTOM_MTMX_IN_PARAMS) {
1562 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1563 return;
1564 }
1565 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301566 section_process_fn fn = section_table[section];
1567 fn(attr);
Juyu Chen918e1e12019-08-08 15:28:18 -07001568 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1569 section = AUDIO_SOURCE_DELAY;
1570 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301571 section_process_fn fn = section_table[section];
1572 fn(attr);
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301573#ifdef SOFT_VOLUME
1574 } else if (strcmp(tag_name, "vol_params") == 0) {
1575 section = SOFT_VOLUME_PARAMS;
1576 section_process_fn fn = section_table[section];
1577 fn(attr);
1578#endif
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301579 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001580 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001581 if(strcmp(tag_name, "config_params") == 0) {
1582 section = CONFIG_PARAMS;
1583 } else if (strcmp(tag_name, "param") == 0) {
1584 if (section != CONFIG_PARAMS) {
1585 ALOGE("param tag only supported with CONFIG_PARAMS section");
1586 return;
1587 }
1588
1589 section_process_fn fn = section_table[section];
1590 fn(attr);
1591 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001592 }
Ben Romberger55886882014-01-10 13:49:02 -08001593 return;
1594}
1595
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001596static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001597{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001598 if (strcmp(tag_name, "bit_width_configs") == 0) {
1599 section = ROOT;
1600 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001601 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001602 } else if (strcmp(tag_name, "module_ids") == 0) {
1603 section = ROOT;
1604 } else if (strcmp(tag_name, "aec") == 0) {
1605 section = MODULE;
1606 } else if (strcmp(tag_name, "ns") == 0) {
1607 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001608 } else if (strcmp(tag_name, "mmsecns") == 0) {
1609 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001610 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1611 section = ROOT;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301612#ifdef SOFT_VOLUME
1613 } else if (strcmp(tag_name, "soft_volume_params") == 0) {
1614 section = ROOT;
1615#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001616 } else if (strcmp(tag_name, "backend_names") == 0) {
1617 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001618 } else if (strcmp(tag_name, "config_params") == 0) {
1619 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001620 } else if (strcmp(tag_name, "operator_specific") == 0) {
1621 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001622 } else if (strcmp(tag_name, "interface_names") == 0) {
1623 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001624 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1625 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001626 } else if (strcmp(tag_name, "app_types") == 0) {
1627 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301628 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1629 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301630 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1631 section = ROOT;
1632 } else if (strcmp(tag_name, "snd_devices") == 0) {
1633 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001634 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1635 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301636 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1637 section = SND_DEVICES;
1638 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1639 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301640 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1641 section = ROOT;
1642 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1643 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301644 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1645 section = ROOT;
1646 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1647 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001648 }
Ben Romberger55886882014-01-10 13:49:02 -08001649}
1650
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001651int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001652{
1653 XML_Parser parser;
1654 FILE *file;
1655 int ret = 0;
1656 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001657 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001658 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301659 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001660
Saurav Kumardba3caf2020-05-29 20:53:55 +05301661 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1662 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001663 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001664 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301665 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001666 MIXER_PATH_MAX_LENGTH);
1667 else
1668 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1669
1670 ALOGV("%s: platform info file name is %s", __func__,
1671 platform_info_file_name);
1672
1673 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001674 section = ROOT;
1675
Ben Romberger55886882014-01-10 13:49:02 -08001676 if (!file) {
1677 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001678 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001679 ret = -ENODEV;
1680 goto done;
1681 }
1682
1683 parser = XML_ParserCreate(NULL);
1684 if (!parser) {
1685 ALOGE("%s: Failed to create XML parser!", __func__);
1686 ret = -ENODEV;
1687 goto err_close_file;
1688 }
1689
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001690 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001691 my_data.platform = platform;
Sandhya Mutha Naga Venkata4c6fc9f2022-10-14 19:38:02 +05301692
1693 if (!my_data.kvpairs)
1694 my_data.kvpairs = str_parms_create();
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001695
Ben Romberger55886882014-01-10 13:49:02 -08001696 XML_SetElementHandler(parser, start_tag, end_tag);
1697
1698 while (1) {
1699 buf = XML_GetBuffer(parser, BUF_SIZE);
1700 if (buf == NULL) {
1701 ALOGE("%s: XML_GetBuffer failed", __func__);
1702 ret = -ENOMEM;
1703 goto err_free_parser;
1704 }
1705
1706 bytes_read = fread(buf, 1, BUF_SIZE, file);
1707 if (bytes_read < 0) {
1708 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1709 ret = bytes_read;
1710 goto err_free_parser;
1711 }
1712
1713 if (XML_ParseBuffer(parser, bytes_read,
1714 bytes_read == 0) == XML_STATUS_ERROR) {
1715 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001716 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001717 ret = -EINVAL;
1718 goto err_free_parser;
1719 }
1720
1721 if (bytes_read == 0)
1722 break;
1723 }
1724
Ben Romberger55886882014-01-10 13:49:02 -08001725err_free_parser:
1726 XML_ParserFree(parser);
1727err_close_file:
1728 fclose(file);
1729done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001730 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001731 return ret;
1732}
Sandhya Mutha Naga Venkata4c6fc9f2022-10-14 19:38:02 +05301733
1734void platform_info_deinit()
1735{
1736 if (my_data.kvpairs)
1737 str_parms_destroy(my_data.kvpairs);
1738}