blob: 4c019cb3bda652f2c6d76fcf7f80671760d508ad [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
393 int id = atoi((char *)attr[5]);
394
395 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
396 ALOGE("%s: usecase %s type %d id %d was not set!",
397 __func__, attr[1], type, id);
398 goto done;
399 }
400
401done:
402 return;
403}
404
405/* backend to be used for a device */
406static void process_backend_name(const XML_Char **attr)
407{
408 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530409 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530410 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700411
412 if (strcmp(attr[0], "name") != 0) {
413 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
414 goto done;
415 }
416
417 index = platform_get_snd_device_index((char *)attr[1]);
418 if (index < 0) {
419 ALOGE("%s: Device %s not found, no ACDB ID set!",
420 __func__, attr[1]);
421 goto done;
422 }
423
424 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530425 if (strcmp(attr[2], "interface") == 0)
426 hw_interface = (char *)attr[3];
427 } else {
428 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700429 }
430
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530431 if (attr[4] != NULL) {
432 if (strcmp(attr[4], "interface") != 0) {
433 hw_interface = NULL;
434 } else {
435 hw_interface = (char *)attr[5];
436 }
437 }
438
Ashish Jaind150d4c2017-02-03 18:44:34 +0530439 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700440 ALOGE("%s: Device %s backend %s was not set!",
441 __func__, attr[1], attr[3]);
442 goto done;
443 }
444
445done:
446 return;
447}
448
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700449static void process_gain_db_to_level_map(const XML_Char **attr)
450{
451 struct amp_db_and_gain_table tbl_entry;
452
453 if ((strcmp(attr[0], "db") != 0) ||
454 (strcmp(attr[2], "level") != 0)) {
455 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
456 __func__, attr[0], attr[2]);
457 goto done;
458 }
459
460 tbl_entry.db = atof(attr[1]);
461 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
462 tbl_entry.level = atoi(attr[3]);
463
Aalique Grahame22e49102018-12-18 14:23:57 -0800464 //custome level should be > 0. Level 0 is fixed for default
465 CHECK(tbl_entry.level > 0);
466
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700467 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
468 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
469 platform_add_gain_level_mapping(&tbl_entry);
470
471done:
472 return;
473}
474
475
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700476static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800477{
Ben Romberger61764e32014-01-10 13:49:02 -0800478 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800479
Ben Romberger61764e32014-01-10 13:49:02 -0800480 if (strcmp(attr[0], "name") != 0) {
481 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800482 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800483 }
Ben Romberger55886882014-01-10 13:49:02 -0800484
Ben Romberger61764e32014-01-10 13:49:02 -0800485 index = platform_get_snd_device_index((char *)attr[1]);
486 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800487 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
488 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800489 goto done;
490 }
491
492 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800493 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
494 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800495 goto done;
496 }
497
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700498 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
499 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800500 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800501 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800502 }
Ben Romberger55886882014-01-10 13:49:02 -0800503
Ben Romberger55886882014-01-10 13:49:02 -0800504done:
505 return;
506}
507
Aalique Grahame22e49102018-12-18 14:23:57 -0800508static void process_operator_specific(const XML_Char **attr)
509{
510 snd_device_t snd_device = SND_DEVICE_NONE;
511
512 if (strcmp(attr[0], "name") != 0) {
513 ALOGE("%s: 'name' not found", __func__);
514 goto done;
515 }
516
517 snd_device = platform_get_snd_device_index((char *)attr[1]);
518 if (snd_device < 0) {
519 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530520 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800521 goto done;
522 }
523
524 if (strcmp(attr[2], "operator") != 0) {
525 ALOGE("%s: 'operator' not found", __func__);
526 goto done;
527 }
528
529 if (strcmp(attr[4], "mixer_path") != 0) {
530 ALOGE("%s: 'mixer_path' not found", __func__);
531 goto done;
532 }
533
534 if (strcmp(attr[6], "acdb_id") != 0) {
535 ALOGE("%s: 'acdb_id' not found", __func__);
536 goto done;
537 }
538
539 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
540
541done:
542 return;
543}
544
Carter Hsu32a62362018-10-15 15:01:42 -0700545static void process_external_dev(const XML_Char **attr)
546{
547 snd_device_t snd_device = SND_DEVICE_NONE;
548
549 if (strcmp(attr[0], "name") != 0) {
550 ALOGE("%s: 'name' not found", __func__);
551 goto done;
552 }
553
554 snd_device = platform_get_snd_device_index((char *)attr[1]);
555 if (snd_device < 0) {
556 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530557 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700558 goto done;
559 }
560
561 if (strcmp(attr[2], "usbid") != 0) {
562 ALOGE("%s: 'usbid' not found", __func__);
563 goto done;
564 }
565
566 if (strcmp(attr[4], "acdb_id") != 0) {
567 ALOGE("%s: 'acdb_id' not found", __func__);
568 goto done;
569 }
570
571 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
572
573done:
574 return;
575}
576
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700577static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
578{
579 int index;
580 struct audio_effect_config effect_config;
581
582 if (strcmp(attr[0], "name") != 0) {
583 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
584 goto done;
585 }
586
587 index = platform_get_snd_device_index((char *)attr[1]);
588 if (index < 0) {
589 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
590 __func__, attr[1]);
591 goto done;
592 }
593
594 if (strcmp(attr[2], "module_id") != 0) {
595 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
596 __func__, attr[2]);
597 goto done;
598 }
599
600 if (strcmp(attr[4], "instance_id") != 0) {
601 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
602 __func__, attr[4]);
603 goto done;
604 }
605
606 if (strcmp(attr[6], "param_id") != 0) {
607 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
608 __func__, attr[6]);
609 goto done;
610 }
611
612 if (strcmp(attr[8], "param_value") != 0) {
613 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
614 __func__, attr[8]);
615 goto done;
616 }
617
618 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
619 strtol((char *)attr[5], NULL, 0),
620 strtol((char *)attr[7], NULL, 0),
621 strtol((char *)attr[9], NULL, 0)};
622
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700623 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
624 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
625 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
626 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
627 strtol((char *)attr[9], NULL, 0));
628 goto done;
629 }
630
631done:
632 return;
633}
634
635static void process_effect_aec(const XML_Char **attr)
636{
637 process_audio_effect(attr, EFFECT_AEC);
638 return;
639}
640
641static void process_effect_ns(const XML_Char **attr)
642{
643 process_audio_effect(attr, EFFECT_NS);
644 return;
645}
646
Guodong Hu1d46f342019-06-28 16:57:30 +0800647static void process_fluence_mmsecns(const XML_Char **attr)
648{
649 int index;
650 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
651
652 if (strcmp(attr[0], "name") != 0) {
653 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
654 goto done;
655 }
656
657 index = platform_get_snd_device_index((char *)attr[1]);
658 if (index < 0) {
659 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
660 __func__, attr[1]);
661 goto done;
662 }
663
664 if (strcmp(attr[2], "topology_id") != 0) {
665 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
666 __func__, attr[2]);
667 goto done;
668 }
669
670 if (strcmp(attr[4], "module_id") != 0) {
671 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
672 __func__, attr[4]);
673 goto done;
674 }
675
676 if (strcmp(attr[6], "instance_id") != 0) {
677 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
678 __func__, attr[6]);
679 goto done;
680 }
681
682 if (strcmp(attr[8], "param_id") != 0) {
683 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
684 __func__, attr[8]);
685 goto done;
686 }
687
688 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
689 strtol((char *)attr[5], NULL, 0),
690 strtol((char *)attr[7], NULL, 0),
691 strtol((char *)attr[9], NULL, 0)};
692
693
694 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
695 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
696 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
697 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
698 goto done;
699 }
700
701done:
702 return;
703}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700704static void process_bit_width(const XML_Char **attr)
705{
706 int index;
707
708 if (strcmp(attr[0], "name") != 0) {
709 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
710 goto done;
711 }
712
713 index = platform_get_snd_device_index((char *)attr[1]);
714 if (index < 0) {
715 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
716 __func__, attr[1]);
717 goto done;
718 }
719
720 if (strcmp(attr[2], "bit_width") != 0) {
721 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
722 __func__, attr[1]);
723 goto done;
724 }
725
726 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
727 ALOGE("%s: Device %s, ACDB ID %d was not set!",
728 __func__, attr[1], atoi((char *)attr[3]));
729 goto done;
730 }
731
732done:
733 return;
734}
735
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800736static void process_interface_name(const XML_Char **attr)
737{
738 int ret;
739
740 if (strcmp(attr[0], "name") != 0) {
741 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
742
743 goto done;
744 }
745
746 if (strcmp(attr[2], "interface") != 0) {
747 ALOGE("%s: Device %s has no Audio Interface set!",
748 __func__, attr[1]);
749
750 goto done;
751 }
752
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530753 if (strcmp(attr[4], "codec_type") != 0) {
754 ALOGE("%s: Device %s has no codec type set!",
755 __func__, attr[1]);
756
757 goto done;
758 }
759
760 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
761 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800762 if (ret < 0) {
763 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800764 goto done;
765 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800766
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800767done:
768 return;
769}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530770
Juyu Chen918e1e12019-08-08 15:28:18 -0700771static void process_audio_source_delay(const XML_Char **attr)
772{
773 audio_source_t audio_source = -1;
774
775 if (strcmp(attr[0], "name") != 0) {
776 ALOGE("%s: 'name' not found", __func__);
777 goto done;
778 }
George Gao9ba8a142020-07-23 14:30:03 -0700779
Juyu Chen918e1e12019-08-08 15:28:18 -0700780 audio_source = platform_get_audio_source_index((const char *)attr[1]);
781
782 if (audio_source < 0) {
783 ALOGE("%s: audio_source %s is not defined",
784 __func__, (char *)attr[1]);
785 goto done;
786 }
787
788 if (strcmp(attr[2], "delay") != 0) {
789 ALOGE("%s: 'delay' not found", __func__);
790 goto done;
791 }
792
793 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
794
795done:
796 return;
797}
798
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700799static void process_config_params(const XML_Char **attr)
800{
801 if (strcmp(attr[0], "key") != 0) {
802 ALOGE("%s: 'key' not found", __func__);
803 goto done;
804 }
805
806 if (strcmp(attr[2], "value") != 0) {
807 ALOGE("%s: 'value' not found", __func__);
808 goto done;
809 }
810
811 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700812 if (my_data.caller == PLATFORM)
813 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700814done:
815 return;
816}
817
Aalique Grahame22e49102018-12-18 14:23:57 -0800818static void process_app_type(const XML_Char **attr)
819{
820 if (strcmp(attr[0], "uc_type")) {
821 ALOGE("%s: uc_type not found", __func__);
822 goto done;
823 }
824
825 if (strcmp(attr[2], "mode")) {
826 ALOGE("%s: mode not found", __func__);
827 goto done;
828 }
829
830 if (strcmp(attr[4], "bit_width")) {
831 ALOGE("%s: bit_width not found", __func__);
832 goto done;
833 }
834
835 if (strcmp(attr[6], "id")) {
836 ALOGE("%s: id not found", __func__);
837 goto done;
838 }
839
840 if (strcmp(attr[8], "max_rate")) {
841 ALOGE("%s: max rate not found", __func__);
842 goto done;
843 }
844
845 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
846 atoi(attr[9]));
847done:
848 return;
849}
850
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530851static void process_microphone_characteristic(const XML_Char **attr) {
852 struct audio_microphone_characteristic_t microphone;
853 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530854 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530855
Saurav Kumardba3caf2020-05-29 20:53:55 +0530856 strlcpy(platform_info_xml_path, get_platform_xml_path(),
857 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530858 if (strcmp(attr[curIdx++], "valid_mask")) {
859 ALOGE("%s: valid_mask not found", __func__);
860 goto done;
861 }
862 uint32_t valid_mask = atoi(attr[curIdx++]);
863
864 if (strcmp(attr[curIdx++], "device_id")) {
865 ALOGE("%s: device_id not found", __func__);
866 goto done;
867 }
868 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
869 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
870 goto done;
871 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530872 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530873
874 if (strcmp(attr[curIdx++], "type")) {
875 ALOGE("%s: device not found", __func__);
876 goto done;
877 }
878 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
879 ARRAY_SIZE(device_in_types), &microphone.device)) {
880 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530881 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530882 goto done;
883 }
884
885 if (strcmp(attr[curIdx++], "address")) {
886 ALOGE("%s: address not found", __func__);
887 goto done;
888 }
889 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
890 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
891 goto done;
892 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530893 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530894 if (strlen(microphone.address) == 0) {
895 // If the address is empty, populate the address according to device type.
896 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530897 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530898 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530899 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530900 }
901 }
902
903 if (strcmp(attr[curIdx++], "location")) {
904 ALOGE("%s: location not found", __func__);
905 goto done;
906 }
907 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
908 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
909 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530910 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530911 goto done;
912 }
913
914 if (strcmp(attr[curIdx++], "group")) {
915 ALOGE("%s: group not found", __func__);
916 goto done;
917 }
918 microphone.group = atoi(attr[curIdx++]);
919
920 if (strcmp(attr[curIdx++], "index_in_the_group")) {
921 ALOGE("%s: index_in_the_group not found", __func__);
922 goto done;
923 }
924 microphone.index_in_the_group = atoi(attr[curIdx++]);
925
926 if (strcmp(attr[curIdx++], "directionality")) {
927 ALOGE("%s: directionality not found", __func__);
928 goto done;
929 }
930 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
931 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
932 ALOGE("%s: directionality %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530933 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530934 goto done;
935 }
936
937 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
938 ALOGE("%s: num_frequency_responses not found", __func__);
939 goto done;
940 }
941 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530942 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530943 ALOGE("%s: num_frequency_responses is too large", __func__);
944 goto done;
945 }
946 if (microphone.num_frequency_responses > 0) {
947 if (strcmp(attr[curIdx++], "frequencies")) {
948 ALOGE("%s: frequencies not found", __func__);
949 goto done;
950 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530951 char *context = NULL;
952 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530953 uint32_t num_frequencies = 0;
954 while (token) {
955 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800956 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530957 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530958 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530959 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530960 }
961
962 if (strcmp(attr[curIdx++], "responses")) {
963 ALOGE("%s: responses not found", __func__);
964 goto done;
965 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530966 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530967 uint32_t num_responses = 0;
968 while (token) {
969 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800970 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530971 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530972 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530973 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530974 }
975
976 if (num_frequencies != num_responses
977 || num_frequencies != microphone.num_frequency_responses) {
978 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
979 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
980 goto done;
981 }
982 }
983
984 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
985 if (strcmp(attr[curIdx++], "sensitivity")) {
986 ALOGE("%s: sensitivity not found", __func__);
987 goto done;
988 }
989 microphone.sensitivity = atof(attr[curIdx++]);
990 } else {
991 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
992 }
993
994 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
995 if (strcmp(attr[curIdx++], "max_spl")) {
996 ALOGE("%s: max_spl not found", __func__);
997 goto done;
998 }
999 microphone.max_spl = atof(attr[curIdx++]);
1000 } else {
1001 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1002 }
1003
1004 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
1005 if (strcmp(attr[curIdx++], "min_spl")) {
1006 ALOGE("%s: min_spl not found", __func__);
1007 goto done;
1008 }
1009 microphone.min_spl = atof(attr[curIdx++]);
1010 } else {
1011 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
1012 }
1013
1014 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
1015 if (strcmp(attr[curIdx++], "orientation")) {
1016 ALOGE("%s: orientation not found", __func__);
1017 goto done;
1018 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301019 char *context = NULL;
1020 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301021 float orientation[3];
1022 uint32_t idx = 0;
1023 while (token) {
1024 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001025 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301026 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301027 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301028 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301029 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301030 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301031 ALOGE("%s: orientation invalid", __func__);
1032 goto done;
1033 }
1034 microphone.orientation.x = orientation[0];
1035 microphone.orientation.y = orientation[1];
1036 microphone.orientation.z = orientation[2];
1037 } else {
1038 microphone.orientation.x = 0.0f;
1039 microphone.orientation.y = 0.0f;
1040 microphone.orientation.z = 0.0f;
1041 }
1042
1043 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
1044 if (strcmp(attr[curIdx++], "geometric_location")) {
1045 ALOGE("%s: geometric_location not found", __func__);
1046 goto done;
1047 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301048 char *context = NULL;
1049 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301050 float geometric_location[3];
1051 uint32_t idx = 0;
1052 while (token) {
1053 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001054 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301055 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301056 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301057 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301058 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301059 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301060 ALOGE("%s: geometric_location invalid", __func__);
1061 goto done;
1062 }
1063 microphone.geometric_location.x = geometric_location[0];
1064 microphone.geometric_location.y = geometric_location[1];
1065 microphone.geometric_location.z = geometric_location[2];
1066 } else {
1067 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1068 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1069 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1070 }
1071
1072 platform_set_microphone_characteristic(my_data.platform, microphone);
1073done:
1074 return;
1075}
1076
1077static void process_snd_dev(const XML_Char **attr)
1078{
1079 uint32_t curIdx = 0;
1080 in_snd_device = SND_DEVICE_NONE;
1081
1082 if (strcmp(attr[curIdx++], "in_snd_device")) {
1083 ALOGE("%s: snd_device not found", __func__);
1084 return;
1085 }
1086 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1087 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1088 in_snd_device >= SND_DEVICE_IN_END) {
1089 ALOGE("%s: Sound device not valid", __func__);
1090 in_snd_device = SND_DEVICE_NONE;
1091 }
1092
1093 return;
1094}
1095
1096static void process_mic_info(const XML_Char **attr)
1097{
1098 uint32_t curIdx = 0;
1099 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301100 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301101
Saurav Kumardba3caf2020-05-29 20:53:55 +05301102 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1103 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301104 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1105 sizeof(microphone.channel_mapping));
1106
1107 if (strcmp(attr[curIdx++], "mic_device_id")) {
1108 ALOGE("%s: mic_device_id not found", __func__);
1109 goto on_error;
1110 }
1111 strlcpy(microphone.device_id,
1112 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1113
1114 if (strcmp(attr[curIdx++], "channel_mapping")) {
1115 ALOGE("%s: channel_mapping not found", __func__);
1116 goto on_error;
1117 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301118 char *context = NULL;
1119 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301120 uint32_t idx = 0;
1121 while (token) {
1122 if (!find_enum_by_string(mic_channel_mapping, token,
1123 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1124 &microphone.channel_mapping[idx++])) {
1125 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301126 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301127 goto on_error;
1128 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301129 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301130 }
1131 microphone.channel_count = idx;
1132
1133 platform_set_microphone_map(my_data.platform, in_snd_device,
1134 &microphone);
1135 return;
1136on_error:
1137 in_snd_device = SND_DEVICE_NONE;
1138 return;
1139}
1140
1141
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301142/* process acdb meta info key value */
1143static void process_acdb_metainfo_key(const XML_Char **attr)
1144{
1145 if (strcmp(attr[0], "name") != 0) {
1146 ALOGE("%s: 'name' not found", __func__);
1147 goto done;
1148 }
1149
1150 if (strcmp(attr[2], "value") != 0) {
1151 ALOGE("%s: 'value' not found", __func__);
1152 goto done;
1153 }
1154
1155 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001156 switch(my_data.caller) {
1157 case ACDB_EXTN:
1158 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1159 ALOGE("%s: key %d was not set!", __func__, key);
1160 goto done;
1161 }
1162 break;
1163 case PLATFORM:
1164 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1165 ALOGE("%s: key %d was not set!", __func__, key);
1166 goto done;
1167 }
1168 break;
1169 default:
1170 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301171 }
1172
1173done:
1174 return;
1175}
1176
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301177static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1178{
1179 uint32_t attr_idx = 0;
1180 int32_t in_ch_idx = -1;
1181 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1182
1183 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1184 &mtmx_in_params_info);
1185 if (mtmx_in_params == NULL) {
1186 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1187 return;
1188 }
1189
1190 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1191 ALOGE("%s: 'in_channel_index' not found", __func__);
1192 return;
1193 }
1194
1195 in_ch_idx = atoi((char *)attr[attr_idx++]);
1196 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1197 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1198 return;
1199 }
1200
1201 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1202 ALOGE("%s: 'channel_count' not found", __func__);
1203 return;
1204 }
1205 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1206
1207 if (strcmp(attr[attr_idx++], "device") != 0) {
1208 ALOGE("%s: 'device' not found", __func__);
1209 return;
1210 }
1211 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1212 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1213
1214 if (strcmp(attr[attr_idx++], "interface") != 0) {
1215 ALOGE("%s: 'interface' not found", __func__);
1216 return;
1217 }
1218 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1219 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1220
1221 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1222 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1223 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1224 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1225 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1226 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1227 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1228 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301229 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1230 ENUM_TO_STRING(AUDIO_DEVICE_IN_SPEAKER_MIC2),
1231 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1232 mtmx_in_params->i2s_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301233
1234 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1235}
1236
1237static void process_custom_mtmx_in_params(const XML_Char **attr)
1238{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301239 int attr_idx = 0, i = 0;
1240 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301241
1242 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1243 ALOGE("%s: 'usecase' not found", __func__);
1244 return;
1245 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301246 /* Check if multi usecases are supported for this custom mtrx params */
1247 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1248 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1249 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1250 value = strtok_r(NULL, ",", &context);
1251 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301252
1253 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1254 ALOGE("%s: 'out_channel_count' not found", __func__);
1255 return;
1256 }
1257 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1258
1259 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1260
1261}
1262
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301263static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1264{
1265 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301266 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301267 char *context = NULL, *ch_coeff_value = NULL;
1268 struct audio_custom_mtmx_params *mtmx_params = NULL;
1269
1270 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1271 ALOGE("%s: 'out_channel_index' not found", __func__);
1272 return;
1273 }
1274 out_ch_idx = atoi((char *)attr[attr_idx++]);
1275
1276 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1277 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1278 return;
1279 }
1280
1281 if (strcmp(attr[attr_idx++], "values") != 0) {
1282 ALOGE("%s: 'values' not found", __func__);
1283 return;
1284 }
1285 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301286 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301287 if (mtmx_params == NULL) {
1288 ALOGE("%s: mtmx params with given param info, not found", __func__);
1289 return;
1290 }
1291 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1292 ip_channels = mtmx_params->info.ip_channels;
1293 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301294 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301295 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1296 = atoi(ch_coeff_value);
1297 ch_coeff_value = strtok_r(NULL, " ", &context);
1298 }
1299 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1300 ch_coeff_value != NULL)
1301 ALOGE("%s: invalid/malformed coefficient values", __func__);
1302}
1303
1304static void process_custom_mtmx_params(const XML_Char **attr)
1305{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301306 int attr_idx = 0, i = 0;
1307 char *context = NULL, *value = NULL;
1308
1309 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301310
1311 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1312 ALOGE("%s: 'param_id' not found", __func__);
1313 return;
1314 }
1315 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1316
1317 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1318 ALOGE("%s: 'in_channel_count' not found", __func__);
1319 return;
1320 }
1321 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1322
1323 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1324 ALOGE("%s: 'out_channel_count' not found", __func__);
1325 return;
1326 }
1327 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1328
1329 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1330 ALOGE("%s: 'usecase' not found", __func__);
1331 return;
1332 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301333
1334 /* check if multi usecases are supported for this custom mtrx params */
1335 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1336 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1337 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1338 value = strtok_r(NULL, ",", &context);
1339 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301340
1341 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1342 ALOGE("%s: 'snd_device' not found", __func__);
1343 return;
1344 }
1345 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301346
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301347 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1348 i = 0;
1349 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1350 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1351 mtmx_params_info.fe_id[i++] = atoi(value);
1352 value = strtok_r(NULL, ",", &context);
1353 }
1354
1355 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301356 }
1357
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301358 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1359
1360}
1361
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001362static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001363 const XML_Char **attr)
1364{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001365 if (my_data.caller == ACDB_EXTN) {
1366 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1367 section = ACDB_METAINFO_KEY;
1368 } else if (strcmp(tag_name, "param") == 0) {
1369 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1370 ALOGE("param tag only supported with CONFIG_PARAMS section");
1371 return;
1372 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001373
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001374 section_process_fn fn = section_table[section];
1375 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001376 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001377 } else if(my_data.caller == PLATFORM) {
1378 if (strcmp(tag_name, "bit_width_configs") == 0) {
1379 section = BITWIDTH;
1380 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1381 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001382 } else if (strcmp(tag_name, "module_ids") == 0) {
1383 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001384 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1385 section = PCM_ID;
1386 } else if (strcmp(tag_name, "backend_names") == 0) {
1387 section = BACKEND_NAME;
1388 } else if (strcmp(tag_name, "config_params") == 0) {
1389 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001390 } else if (strcmp(tag_name, "operator_specific") == 0) {
1391 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001392 } else if (strcmp(tag_name, "interface_names") == 0) {
1393 section = INTERFACE_NAME;
1394 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1395 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001396 } else if (strcmp(tag_name, "app_types") == 0) {
1397 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001398 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1399 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301400 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1401 section = MICROPHONE_CHARACTERISTIC;
1402 } else if (strcmp(tag_name, "snd_devices") == 0) {
1403 section = SND_DEVICES;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301404#ifdef SOFT_VOLUME
1405 } else if (strcmp(tag_name, "soft_vol_params") == 0) {
1406 section = SOFT_VOLUME_PARAMS;
1407#endif
1408 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001409 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001410 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001411 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001412 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1413 return;
1414 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001415
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001416 /* call into process function for the current section */
1417 section_process_fn fn = section_table[section];
1418 fn(attr);
1419 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1420 if (section != GAIN_LEVEL_MAPPING) {
1421 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1422 return;
1423 }
1424
1425 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1426 fn(attr);
1427 } else if (strcmp(tag_name, "usecase") == 0) {
1428 if (section != PCM_ID) {
1429 ALOGE("usecase tag only supported with PCM_ID section");
1430 return;
1431 }
1432
1433 section_process_fn fn = section_table[PCM_ID];
1434 fn(attr);
1435 } else if (strcmp(tag_name, "param") == 0) {
1436 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1437 ALOGE("param tag only supported with CONFIG_PARAMS section");
1438 return;
1439 }
1440
1441 section_process_fn fn = section_table[section];
1442 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301443 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001444 if (section != MODULE) {
1445 ALOGE("aec tag only supported with MODULE section");
1446 return;
1447 }
1448 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301449 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001450 if (section != MODULE) {
1451 ALOGE("ns tag only supported with MODULE section");
1452 return;
1453 }
1454 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001455 } else if (strcmp(tag_name, "mmsecns") == 0) {
1456 if (section != MODULE) {
1457 ALOGE("mmsecns tag only supported with MODULE section");
1458 return;
1459 }
1460 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001461 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1462 if (section != GAIN_LEVEL_MAPPING) {
1463 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1464 return;
1465 }
1466
1467 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1468 fn(attr);
1469 } else if (!strcmp(tag_name, "app")) {
1470 if (section != APP_TYPE) {
1471 ALOGE("app tag only valid in section APP_TYPE");
1472 return;
1473 }
1474
1475 section_process_fn fn = section_table[APP_TYPE];
1476 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301477 } else if (strcmp(tag_name, "microphone") == 0) {
1478 if (section != MICROPHONE_CHARACTERISTIC) {
1479 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1480 return;
1481 }
1482 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1483 fn(attr);
1484 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1485 if (section != SND_DEVICES) {
1486 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1487 return;
1488 }
1489 section = INPUT_SND_DEVICE;
1490 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1491 if (section != INPUT_SND_DEVICE) {
1492 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1493 return;
1494 }
1495 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1496 } else if (strcmp(tag_name, "snd_dev") == 0) {
1497 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1498 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1499 return;
1500 }
1501 section_process_fn fn = section_table[SND_DEV];
1502 fn(attr);
1503 } else if (strcmp(tag_name, "mic_info") == 0) {
1504 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1505 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1506 return;
1507 }
1508 if (in_snd_device == SND_DEVICE_NONE) {
1509 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1510 return;
1511 }
1512 section_process_fn fn = section_table[MIC_INFO];
1513 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301514 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1515 if (section != ROOT) {
1516 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1517 return;
1518 }
1519 section = CUSTOM_MTMX_PARAMS;
1520 section_process_fn fn = section_table[section];
1521 fn(attr);
1522 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1523 if (section != CUSTOM_MTMX_PARAMS) {
1524 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1525 return;
1526 }
1527 section = CUSTOM_MTMX_PARAM_COEFFS;
1528 section_process_fn fn = section_table[section];
1529 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001530 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1531 section = EXTERNAL_DEVICE_SPECIFIC;
1532 } else if (strcmp(tag_name, "ext_device") == 0) {
1533 section_process_fn fn = section_table[section];
1534 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301535 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1536 if (section != ROOT) {
1537 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1538 return;
1539 }
1540 section = CUSTOM_MTMX_IN_PARAMS;
1541 section_process_fn fn = section_table[section];
1542 fn(attr);
1543 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1544 if (section != CUSTOM_MTMX_IN_PARAMS) {
1545 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1546 return;
1547 }
1548 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Avinash Chandrad7296d42021-08-04 15:07:47 +05301549 section_process_fn fn = section_table[section];
1550 fn(attr);
Juyu Chen918e1e12019-08-08 15:28:18 -07001551 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1552 section = AUDIO_SOURCE_DELAY;
1553 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301554 section_process_fn fn = section_table[section];
1555 fn(attr);
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301556#ifdef SOFT_VOLUME
1557 } else if (strcmp(tag_name, "vol_params") == 0) {
1558 section = SOFT_VOLUME_PARAMS;
1559 section_process_fn fn = section_table[section];
1560 fn(attr);
1561#endif
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301562 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001563 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001564 if(strcmp(tag_name, "config_params") == 0) {
1565 section = CONFIG_PARAMS;
1566 } else if (strcmp(tag_name, "param") == 0) {
1567 if (section != CONFIG_PARAMS) {
1568 ALOGE("param tag only supported with CONFIG_PARAMS section");
1569 return;
1570 }
1571
1572 section_process_fn fn = section_table[section];
1573 fn(attr);
1574 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001575 }
Ben Romberger55886882014-01-10 13:49:02 -08001576 return;
1577}
1578
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001579static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001580{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001581 if (strcmp(tag_name, "bit_width_configs") == 0) {
1582 section = ROOT;
1583 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001584 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001585 } else if (strcmp(tag_name, "module_ids") == 0) {
1586 section = ROOT;
1587 } else if (strcmp(tag_name, "aec") == 0) {
1588 section = MODULE;
1589 } else if (strcmp(tag_name, "ns") == 0) {
1590 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001591 } else if (strcmp(tag_name, "mmsecns") == 0) {
1592 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001593 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1594 section = ROOT;
Krishna Kishor Jha10ad39f2022-02-21 17:02:47 +05301595#ifdef SOFT_VOLUME
1596 } else if (strcmp(tag_name, "soft_volume_params") == 0) {
1597 section = ROOT;
1598#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001599 } else if (strcmp(tag_name, "backend_names") == 0) {
1600 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001601 } else if (strcmp(tag_name, "config_params") == 0) {
1602 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001603 } else if (strcmp(tag_name, "operator_specific") == 0) {
1604 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001605 } else if (strcmp(tag_name, "interface_names") == 0) {
1606 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001607 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1608 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001609 } else if (strcmp(tag_name, "app_types") == 0) {
1610 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301611 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1612 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301613 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1614 section = ROOT;
1615 } else if (strcmp(tag_name, "snd_devices") == 0) {
1616 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001617 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1618 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301619 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1620 section = SND_DEVICES;
1621 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1622 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301623 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1624 section = ROOT;
1625 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1626 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301627 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1628 section = ROOT;
1629 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1630 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001631 }
Ben Romberger55886882014-01-10 13:49:02 -08001632}
1633
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001634int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001635{
1636 XML_Parser parser;
1637 FILE *file;
1638 int ret = 0;
1639 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001640 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001641 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301642 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001643
Saurav Kumardba3caf2020-05-29 20:53:55 +05301644 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1645 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001646 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001647 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301648 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001649 MIXER_PATH_MAX_LENGTH);
1650 else
1651 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1652
1653 ALOGV("%s: platform info file name is %s", __func__,
1654 platform_info_file_name);
1655
1656 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001657 section = ROOT;
1658
Ben Romberger55886882014-01-10 13:49:02 -08001659 if (!file) {
1660 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001661 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001662 ret = -ENODEV;
1663 goto done;
1664 }
1665
1666 parser = XML_ParserCreate(NULL);
1667 if (!parser) {
1668 ALOGE("%s: Failed to create XML parser!", __func__);
1669 ret = -ENODEV;
1670 goto err_close_file;
1671 }
1672
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001673 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001674 my_data.platform = platform;
1675 my_data.kvpairs = str_parms_create();
1676
Ben Romberger55886882014-01-10 13:49:02 -08001677 XML_SetElementHandler(parser, start_tag, end_tag);
1678
1679 while (1) {
1680 buf = XML_GetBuffer(parser, BUF_SIZE);
1681 if (buf == NULL) {
1682 ALOGE("%s: XML_GetBuffer failed", __func__);
1683 ret = -ENOMEM;
1684 goto err_free_parser;
1685 }
1686
1687 bytes_read = fread(buf, 1, BUF_SIZE, file);
1688 if (bytes_read < 0) {
1689 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1690 ret = bytes_read;
1691 goto err_free_parser;
1692 }
1693
1694 if (XML_ParseBuffer(parser, bytes_read,
1695 bytes_read == 0) == XML_STATUS_ERROR) {
1696 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001697 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001698 ret = -EINVAL;
1699 goto err_free_parser;
1700 }
1701
1702 if (bytes_read == 0)
1703 break;
1704 }
1705
Ben Romberger55886882014-01-10 13:49:02 -08001706err_free_parser:
1707 XML_ParserFree(parser);
1708err_close_file:
1709 fclose(file);
1710done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001711 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001712 return ret;
1713}