blob: 76239acedbc3c3eee682758f629744c79797932a [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.
28 */
29
Ben Romberger61764e32014-01-10 13:49:02 -080030#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080031#define LOG_NDDEBUG 0
32
33#include <errno.h>
34#include <stdio.h>
35#include <expat.h>
Jiangen Jiao334224b2019-09-12 15:47:46 +080036#include <pthread.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080037#include <log/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070038#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080039#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070040#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080041#include "platform_api.h"
Saurav Kumardba3caf2020-05-29 20:53:55 +053042#include "audio_extn.h"
Ben Romberger61764e32014-01-10 13:49:02 -080043#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070044#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080045
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053046#ifdef DYNAMIC_LOG_ENABLED
47#include <log_xml_parser.h>
48#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
49#include <log_utils.h>
50#endif
51
Ben Romberger55886882014-01-10 13:49:02 -080052#define BUF_SIZE 1024
Saurav Kumardba3caf2020-05-29 20:53:55 +053053char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH];
54char platform_info_xml_path_file[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -080055
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070056typedef enum {
57 ROOT,
58 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070059 MODULE,
60 AEC,
61 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070062 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070063 PCM_ID,
64 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080065 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070066 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080067 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070068 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080069 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053070 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053071 MICROPHONE_CHARACTERISTIC,
72 SND_DEVICES,
73 INPUT_SND_DEVICE,
74 INPUT_SND_DEVICE_TO_MIC_MAPPING,
75 SND_DEV,
76 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053077 CUSTOM_MTMX_PARAMS,
78 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070079 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053080 CUSTOM_MTMX_IN_PARAMS,
81 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +080082 MMSECNS,
Robert Lee58215542019-07-15 20:55:12 +080083 SND_DEV_DELAY,
Juyu Chen918e1e12019-08-08 15:28:18 -070084 AUDIO_SOURCE_DELAY,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070085} section_t;
86
87typedef void (* section_process_fn)(const XML_Char **attr);
88
Saurav Kumardba3caf2020-05-29 20:53:55 +053089const char* get_platform_xml_path()
90{
91 audio_get_vendor_config_path(vendor_config_path, sizeof(vendor_config_path));
92 /* Get path for platorm_info_xml_path_name in vendor */
93 snprintf(platform_info_xml_path_file, sizeof(platform_info_xml_path_file),
94 "%s/%s", vendor_config_path, PLATFORM_INFO_XML_PATH_NAME);
95 return platform_info_xml_path_file;
96}
97
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070098static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070099static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
100static void process_effect_aec(const XML_Char **attr);
101static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -0700102static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700103static void process_pcm_id(const XML_Char **attr);
104static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800105static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700106static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700107static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800108static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700109static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800110static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530111static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530112static void process_microphone_characteristic(const XML_Char **attr);
113static void process_snd_dev(const XML_Char **attr);
114static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530115static void process_custom_mtmx_params(const XML_Char **attr);
116static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700117static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530118static void process_custom_mtmx_in_params(const XML_Char **attr);
119static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Guodong Hu1d46f342019-06-28 16:57:30 +0800120static void process_fluence_mmsecns(const XML_Char **attr);
Robert Lee58215542019-07-15 20:55:12 +0800121static void process_snd_device_delay(const XML_Char **attr);
Juyu Chen918e1e12019-08-08 15:28:18 -0700122static void process_audio_source_delay(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700123
124static section_process_fn section_table[] = {
125 [ROOT] = process_root,
126 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700127 [AEC] = process_effect_aec,
128 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700129 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700130 [PCM_ID] = process_pcm_id,
131 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800132 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700133 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800134 [OPERATOR_SPECIFIC] = process_operator_specific,
135 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700136 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530137 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530138 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
139 [SND_DEV] = process_snd_dev,
140 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530141 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
142 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700143 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530144 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
145 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800146 [MMSECNS] = process_fluence_mmsecns,
Robert Lee58215542019-07-15 20:55:12 +0800147 [SND_DEV_DELAY] = process_snd_device_delay,
Juyu Chen918e1e12019-08-08 15:28:18 -0700148 [AUDIO_SOURCE_DELAY] = process_audio_source_delay,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700149};
150
151static section_t section;
152
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700153struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700154 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700155 void *platform;
156 struct str_parms *kvpairs;
157};
158
159static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800160static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700161
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530162
163struct audio_string_to_enum {
164 const char* name;
165 unsigned int value;
166};
167
168static snd_device_t in_snd_device;
169
170static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
175};
176
177static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
184};
185
186static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
190};
191
192static const struct audio_string_to_enum device_in_types[] = {
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
199 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
200 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
201 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
202 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
203 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
204 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
205 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
206 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
207 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
208 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
209 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
210 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
211 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
212 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
213 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
214 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
215 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
216 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
217 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
218 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
219 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
220};
221
222enum {
223 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
224 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
225 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
226 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
227 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
228 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
229 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
230 | ORIENTATION) | GEOMETRIC_LOCATION) */
231};
232
233static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
234 int32_t len, unsigned int *value)
235{
236 if (table == NULL) {
237 ALOGE("%s: table is NULL", __func__);
238 return false;
239 }
240
241 if (name == NULL) {
242 ALOGE("null key");
243 return false;
244 }
245
246 for (int i = 0; i < len; i++) {
247 if (!strcmp(table[i].name, name)) {
248 *value = table[i].value;
249 return true;
250 }
251 }
252 return false;
253}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530254
255static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530256static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530257
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700258/*
259 * <audio_platform_info>
260 * <acdb_ids>
261 * <device name="???" acdb_id="???"/>
262 * ...
263 * ...
264 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700265 * <module_ids>
266 * <device name="???" module_id="???"/>
267 * ...
268 * ...
269 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700270 * <backend_names>
271 * <device name="???" backend="???"/>
272 * ...
273 * ...
274 * </backend_names>
275 * <pcm_ids>
276 * <usecase name="???" type="in/out" id="???"/>
277 * ...
278 * ...
279 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800280 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530281 * <device name="Use audio device name here, not sound device name" interface="PRIMARY_I2S" codec_type="external/internal"/>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800282 * ...
283 * ...
284 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700285 * <config_params>
286 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800287 * <param key="operator_info" value="tmus;aa;bb;cc"/>
288 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700289 * ...
290 * ...
291 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800292 *
293 * <operator_specific>
294 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
295 * ...
296 * ...
297 * </operator_specific>
298 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700299 * </audio_platform_info>
300 */
301
302static void process_root(const XML_Char **attr __unused)
303{
304}
305
306/* mapping from usecase to pcm dev id */
307static void process_pcm_id(const XML_Char **attr)
308{
309 int index;
310
311 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700312 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700313 goto done;
314 }
315
316 index = platform_get_usecase_index((char *)attr[1]);
317 if (index < 0) {
318 ALOGE("%s: usecase %s not found!",
319 __func__, attr[1]);
320 goto done;
321 }
322
323 if (strcmp(attr[2], "type") != 0) {
324 ALOGE("%s: usecase type not mentioned", __func__);
325 goto done;
326 }
327
328 int type = -1;
329
330 if (!strcasecmp((char *)attr[3], "in")) {
331 type = 1;
332 } else if (!strcasecmp((char *)attr[3], "out")) {
333 type = 0;
334 } else {
335 ALOGE("%s: type must be IN or OUT", __func__);
336 goto done;
337 }
338
339 if (strcmp(attr[4], "id") != 0) {
340 ALOGE("%s: usecase id not mentioned", __func__);
341 goto done;
342 }
343
344 int id = atoi((char *)attr[5]);
345
346 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
347 ALOGE("%s: usecase %s type %d id %d was not set!",
348 __func__, attr[1], type, id);
349 goto done;
350 }
351
352done:
353 return;
354}
355
356/* backend to be used for a device */
357static void process_backend_name(const XML_Char **attr)
358{
359 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530360 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530361 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700362
363 if (strcmp(attr[0], "name") != 0) {
364 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
365 goto done;
366 }
367
368 index = platform_get_snd_device_index((char *)attr[1]);
369 if (index < 0) {
370 ALOGE("%s: Device %s not found, no ACDB ID set!",
371 __func__, attr[1]);
372 goto done;
373 }
374
375 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530376 if (strcmp(attr[2], "interface") == 0)
377 hw_interface = (char *)attr[3];
378 } else {
379 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700380 }
381
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530382 if (attr[4] != NULL) {
383 if (strcmp(attr[4], "interface") != 0) {
384 hw_interface = NULL;
385 } else {
386 hw_interface = (char *)attr[5];
387 }
388 }
389
Ashish Jaind150d4c2017-02-03 18:44:34 +0530390 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700391 ALOGE("%s: Device %s backend %s was not set!",
392 __func__, attr[1], attr[3]);
393 goto done;
394 }
395
396done:
397 return;
398}
399
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700400static void process_gain_db_to_level_map(const XML_Char **attr)
401{
402 struct amp_db_and_gain_table tbl_entry;
403
404 if ((strcmp(attr[0], "db") != 0) ||
405 (strcmp(attr[2], "level") != 0)) {
406 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
407 __func__, attr[0], attr[2]);
408 goto done;
409 }
410
411 tbl_entry.db = atof(attr[1]);
412 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
413 tbl_entry.level = atoi(attr[3]);
414
Aalique Grahame22e49102018-12-18 14:23:57 -0800415 //custome level should be > 0. Level 0 is fixed for default
416 CHECK(tbl_entry.level > 0);
417
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700418 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
419 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
420 platform_add_gain_level_mapping(&tbl_entry);
421
422done:
423 return;
424}
425
426
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700427static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800428{
Ben Romberger61764e32014-01-10 13:49:02 -0800429 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800430
Ben Romberger61764e32014-01-10 13:49:02 -0800431 if (strcmp(attr[0], "name") != 0) {
432 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800433 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800434 }
Ben Romberger55886882014-01-10 13:49:02 -0800435
Ben Romberger61764e32014-01-10 13:49:02 -0800436 index = platform_get_snd_device_index((char *)attr[1]);
437 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800438 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
439 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800440 goto done;
441 }
442
443 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800444 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
445 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800446 goto done;
447 }
448
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700449 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
450 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800451 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800452 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800453 }
Ben Romberger55886882014-01-10 13:49:02 -0800454
Ben Romberger55886882014-01-10 13:49:02 -0800455done:
456 return;
457}
458
Aalique Grahame22e49102018-12-18 14:23:57 -0800459static void process_operator_specific(const XML_Char **attr)
460{
461 snd_device_t snd_device = SND_DEVICE_NONE;
462
463 if (strcmp(attr[0], "name") != 0) {
464 ALOGE("%s: 'name' not found", __func__);
465 goto done;
466 }
467
468 snd_device = platform_get_snd_device_index((char *)attr[1]);
469 if (snd_device < 0) {
470 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530471 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800472 goto done;
473 }
474
475 if (strcmp(attr[2], "operator") != 0) {
476 ALOGE("%s: 'operator' not found", __func__);
477 goto done;
478 }
479
480 if (strcmp(attr[4], "mixer_path") != 0) {
481 ALOGE("%s: 'mixer_path' not found", __func__);
482 goto done;
483 }
484
485 if (strcmp(attr[6], "acdb_id") != 0) {
486 ALOGE("%s: 'acdb_id' not found", __func__);
487 goto done;
488 }
489
490 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
491
492done:
493 return;
494}
495
Carter Hsu32a62362018-10-15 15:01:42 -0700496static void process_external_dev(const XML_Char **attr)
497{
498 snd_device_t snd_device = SND_DEVICE_NONE;
499
500 if (strcmp(attr[0], "name") != 0) {
501 ALOGE("%s: 'name' not found", __func__);
502 goto done;
503 }
504
505 snd_device = platform_get_snd_device_index((char *)attr[1]);
506 if (snd_device < 0) {
507 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530508 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700509 goto done;
510 }
511
512 if (strcmp(attr[2], "usbid") != 0) {
513 ALOGE("%s: 'usbid' not found", __func__);
514 goto done;
515 }
516
517 if (strcmp(attr[4], "acdb_id") != 0) {
518 ALOGE("%s: 'acdb_id' not found", __func__);
519 goto done;
520 }
521
522 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
523
524done:
525 return;
526}
527
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700528static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
529{
530 int index;
531 struct audio_effect_config effect_config;
532
533 if (strcmp(attr[0], "name") != 0) {
534 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
535 goto done;
536 }
537
538 index = platform_get_snd_device_index((char *)attr[1]);
539 if (index < 0) {
540 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
541 __func__, attr[1]);
542 goto done;
543 }
544
545 if (strcmp(attr[2], "module_id") != 0) {
546 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
547 __func__, attr[2]);
548 goto done;
549 }
550
551 if (strcmp(attr[4], "instance_id") != 0) {
552 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
553 __func__, attr[4]);
554 goto done;
555 }
556
557 if (strcmp(attr[6], "param_id") != 0) {
558 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
559 __func__, attr[6]);
560 goto done;
561 }
562
563 if (strcmp(attr[8], "param_value") != 0) {
564 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
565 __func__, attr[8]);
566 goto done;
567 }
568
569 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
570 strtol((char *)attr[5], NULL, 0),
571 strtol((char *)attr[7], NULL, 0),
572 strtol((char *)attr[9], NULL, 0)};
573
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700574 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
575 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
576 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
577 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
578 strtol((char *)attr[9], NULL, 0));
579 goto done;
580 }
581
582done:
583 return;
584}
585
586static void process_effect_aec(const XML_Char **attr)
587{
588 process_audio_effect(attr, EFFECT_AEC);
589 return;
590}
591
592static void process_effect_ns(const XML_Char **attr)
593{
594 process_audio_effect(attr, EFFECT_NS);
595 return;
596}
597
Guodong Hu1d46f342019-06-28 16:57:30 +0800598static void process_fluence_mmsecns(const XML_Char **attr)
599{
600 int index;
601 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
602
603 if (strcmp(attr[0], "name") != 0) {
604 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
605 goto done;
606 }
607
608 index = platform_get_snd_device_index((char *)attr[1]);
609 if (index < 0) {
610 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
611 __func__, attr[1]);
612 goto done;
613 }
614
615 if (strcmp(attr[2], "topology_id") != 0) {
616 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
617 __func__, attr[2]);
618 goto done;
619 }
620
621 if (strcmp(attr[4], "module_id") != 0) {
622 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
623 __func__, attr[4]);
624 goto done;
625 }
626
627 if (strcmp(attr[6], "instance_id") != 0) {
628 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
629 __func__, attr[6]);
630 goto done;
631 }
632
633 if (strcmp(attr[8], "param_id") != 0) {
634 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
635 __func__, attr[8]);
636 goto done;
637 }
638
639 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
640 strtol((char *)attr[5], NULL, 0),
641 strtol((char *)attr[7], NULL, 0),
642 strtol((char *)attr[9], NULL, 0)};
643
644
645 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
646 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
647 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
648 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
649 goto done;
650 }
651
652done:
653 return;
654}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700655static void process_bit_width(const XML_Char **attr)
656{
657 int index;
658
659 if (strcmp(attr[0], "name") != 0) {
660 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
661 goto done;
662 }
663
664 index = platform_get_snd_device_index((char *)attr[1]);
665 if (index < 0) {
666 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
667 __func__, attr[1]);
668 goto done;
669 }
670
671 if (strcmp(attr[2], "bit_width") != 0) {
672 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
673 __func__, attr[1]);
674 goto done;
675 }
676
677 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
678 ALOGE("%s: Device %s, ACDB ID %d was not set!",
679 __func__, attr[1], atoi((char *)attr[3]));
680 goto done;
681 }
682
683done:
684 return;
685}
686
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800687static void process_interface_name(const XML_Char **attr)
688{
689 int ret;
690
691 if (strcmp(attr[0], "name") != 0) {
692 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
693
694 goto done;
695 }
696
697 if (strcmp(attr[2], "interface") != 0) {
698 ALOGE("%s: Device %s has no Audio Interface set!",
699 __func__, attr[1]);
700
701 goto done;
702 }
703
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530704 if (strcmp(attr[4], "codec_type") != 0) {
705 ALOGE("%s: Device %s has no codec type set!",
706 __func__, attr[1]);
707
708 goto done;
709 }
710
711 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
712 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800713 if (ret < 0) {
714 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800715 goto done;
716 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800717
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800718done:
719 return;
720}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530721
Robert Lee58215542019-07-15 20:55:12 +0800722static void process_snd_device_delay(const XML_Char **attr)
723{
724 snd_device_t snd_device = SND_DEVICE_NONE;
725
726 if (strcmp(attr[0], "name") != 0) {
727 ALOGE("%s: 'name' not found", __func__);
728 goto done;
729 }
730
731 snd_device = platform_get_snd_device_index((char *)attr[1]);
732 if (snd_device < 0) {
733 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530734 __func__, (char *)attr[3], get_platform_xml_path());
Robert Lee58215542019-07-15 20:55:12 +0800735 goto done;
736 }
737
738 if (strcmp(attr[2], "delay") != 0) {
739 ALOGE("%s: 'delay' not found", __func__);
740 goto done;
741 }
742
743 platform_set_snd_device_delay(snd_device, atoi((char *)attr[3]));
744
745done:
746 return;
747}
748
Juyu Chen918e1e12019-08-08 15:28:18 -0700749static void process_audio_source_delay(const XML_Char **attr)
750{
751 audio_source_t audio_source = -1;
752
753 if (strcmp(attr[0], "name") != 0) {
754 ALOGE("%s: 'name' not found", __func__);
755 goto done;
756 }
757 audio_source = platform_get_audio_source_index((const char *)attr[1]);
758
759 if (audio_source < 0) {
760 ALOGE("%s: audio_source %s is not defined",
761 __func__, (char *)attr[1]);
762 goto done;
763 }
764
765 if (strcmp(attr[2], "delay") != 0) {
766 ALOGE("%s: 'delay' not found", __func__);
767 goto done;
768 }
769
770 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
771
772done:
773 return;
774}
775
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700776static void process_config_params(const XML_Char **attr)
777{
778 if (strcmp(attr[0], "key") != 0) {
779 ALOGE("%s: 'key' not found", __func__);
780 goto done;
781 }
782
783 if (strcmp(attr[2], "value") != 0) {
784 ALOGE("%s: 'value' not found", __func__);
785 goto done;
786 }
787
788 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700789 if (my_data.caller == PLATFORM)
790 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700791done:
792 return;
793}
794
Aalique Grahame22e49102018-12-18 14:23:57 -0800795static void process_app_type(const XML_Char **attr)
796{
797 if (strcmp(attr[0], "uc_type")) {
798 ALOGE("%s: uc_type not found", __func__);
799 goto done;
800 }
801
802 if (strcmp(attr[2], "mode")) {
803 ALOGE("%s: mode not found", __func__);
804 goto done;
805 }
806
807 if (strcmp(attr[4], "bit_width")) {
808 ALOGE("%s: bit_width not found", __func__);
809 goto done;
810 }
811
812 if (strcmp(attr[6], "id")) {
813 ALOGE("%s: id not found", __func__);
814 goto done;
815 }
816
817 if (strcmp(attr[8], "max_rate")) {
818 ALOGE("%s: max rate not found", __func__);
819 goto done;
820 }
821
822 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
823 atoi(attr[9]));
824done:
825 return;
826}
827
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530828static void process_microphone_characteristic(const XML_Char **attr) {
829 struct audio_microphone_characteristic_t microphone;
830 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530831 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530832
Saurav Kumardba3caf2020-05-29 20:53:55 +0530833 strlcpy(platform_info_xml_path, get_platform_xml_path(),
834 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530835 if (strcmp(attr[curIdx++], "valid_mask")) {
836 ALOGE("%s: valid_mask not found", __func__);
837 goto done;
838 }
839 uint32_t valid_mask = atoi(attr[curIdx++]);
840
841 if (strcmp(attr[curIdx++], "device_id")) {
842 ALOGE("%s: device_id not found", __func__);
843 goto done;
844 }
845 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
846 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
847 goto done;
848 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530849 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530850
851 if (strcmp(attr[curIdx++], "type")) {
852 ALOGE("%s: device not found", __func__);
853 goto done;
854 }
855 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
856 ARRAY_SIZE(device_in_types), &microphone.device)) {
857 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530858 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530859 goto done;
860 }
861
862 if (strcmp(attr[curIdx++], "address")) {
863 ALOGE("%s: address not found", __func__);
864 goto done;
865 }
866 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
867 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
868 goto done;
869 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530870 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530871 if (strlen(microphone.address) == 0) {
872 // If the address is empty, populate the address according to device type.
873 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530874 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530875 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530876 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530877 }
878 }
879
880 if (strcmp(attr[curIdx++], "location")) {
881 ALOGE("%s: location not found", __func__);
882 goto done;
883 }
884 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
885 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
886 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530887 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530888 goto done;
889 }
890
891 if (strcmp(attr[curIdx++], "group")) {
892 ALOGE("%s: group not found", __func__);
893 goto done;
894 }
895 microphone.group = atoi(attr[curIdx++]);
896
897 if (strcmp(attr[curIdx++], "index_in_the_group")) {
898 ALOGE("%s: index_in_the_group not found", __func__);
899 goto done;
900 }
901 microphone.index_in_the_group = atoi(attr[curIdx++]);
902
903 if (strcmp(attr[curIdx++], "directionality")) {
904 ALOGE("%s: directionality not found", __func__);
905 goto done;
906 }
907 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
908 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
909 ALOGE("%s: directionality %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++], "num_frequency_responses")) {
915 ALOGE("%s: num_frequency_responses not found", __func__);
916 goto done;
917 }
918 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530919 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530920 ALOGE("%s: num_frequency_responses is too large", __func__);
921 goto done;
922 }
923 if (microphone.num_frequency_responses > 0) {
924 if (strcmp(attr[curIdx++], "frequencies")) {
925 ALOGE("%s: frequencies not found", __func__);
926 goto done;
927 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530928 char *context = NULL;
929 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530930 uint32_t num_frequencies = 0;
931 while (token) {
932 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800933 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530934 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530935 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530936 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530937 }
938
939 if (strcmp(attr[curIdx++], "responses")) {
940 ALOGE("%s: responses not found", __func__);
941 goto done;
942 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530943 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530944 uint32_t num_responses = 0;
945 while (token) {
946 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800947 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530948 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530949 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530950 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530951 }
952
953 if (num_frequencies != num_responses
954 || num_frequencies != microphone.num_frequency_responses) {
955 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
956 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
957 goto done;
958 }
959 }
960
961 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
962 if (strcmp(attr[curIdx++], "sensitivity")) {
963 ALOGE("%s: sensitivity not found", __func__);
964 goto done;
965 }
966 microphone.sensitivity = atof(attr[curIdx++]);
967 } else {
968 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
969 }
970
971 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
972 if (strcmp(attr[curIdx++], "max_spl")) {
973 ALOGE("%s: max_spl not found", __func__);
974 goto done;
975 }
976 microphone.max_spl = atof(attr[curIdx++]);
977 } else {
978 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
979 }
980
981 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
982 if (strcmp(attr[curIdx++], "min_spl")) {
983 ALOGE("%s: min_spl not found", __func__);
984 goto done;
985 }
986 microphone.min_spl = atof(attr[curIdx++]);
987 } else {
988 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
989 }
990
991 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
992 if (strcmp(attr[curIdx++], "orientation")) {
993 ALOGE("%s: orientation not found", __func__);
994 goto done;
995 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530996 char *context = NULL;
997 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530998 float orientation[3];
999 uint32_t idx = 0;
1000 while (token) {
1001 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001002 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301003 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301004 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301005 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301006 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301007 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301008 ALOGE("%s: orientation invalid", __func__);
1009 goto done;
1010 }
1011 microphone.orientation.x = orientation[0];
1012 microphone.orientation.y = orientation[1];
1013 microphone.orientation.z = orientation[2];
1014 } else {
1015 microphone.orientation.x = 0.0f;
1016 microphone.orientation.y = 0.0f;
1017 microphone.orientation.z = 0.0f;
1018 }
1019
1020 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
1021 if (strcmp(attr[curIdx++], "geometric_location")) {
1022 ALOGE("%s: geometric_location not found", __func__);
1023 goto done;
1024 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301025 char *context = NULL;
1026 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301027 float geometric_location[3];
1028 uint32_t idx = 0;
1029 while (token) {
1030 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001031 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301032 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301033 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301034 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301035 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301036 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301037 ALOGE("%s: geometric_location invalid", __func__);
1038 goto done;
1039 }
1040 microphone.geometric_location.x = geometric_location[0];
1041 microphone.geometric_location.y = geometric_location[1];
1042 microphone.geometric_location.z = geometric_location[2];
1043 } else {
1044 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1045 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1046 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1047 }
1048
1049 platform_set_microphone_characteristic(my_data.platform, microphone);
1050done:
1051 return;
1052}
1053
1054static void process_snd_dev(const XML_Char **attr)
1055{
1056 uint32_t curIdx = 0;
1057 in_snd_device = SND_DEVICE_NONE;
1058
1059 if (strcmp(attr[curIdx++], "in_snd_device")) {
1060 ALOGE("%s: snd_device not found", __func__);
1061 return;
1062 }
1063 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1064 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1065 in_snd_device >= SND_DEVICE_IN_END) {
1066 ALOGE("%s: Sound device not valid", __func__);
1067 in_snd_device = SND_DEVICE_NONE;
1068 }
1069
1070 return;
1071}
1072
1073static void process_mic_info(const XML_Char **attr)
1074{
1075 uint32_t curIdx = 0;
1076 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301077 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301078
Saurav Kumardba3caf2020-05-29 20:53:55 +05301079 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1080 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301081 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1082 sizeof(microphone.channel_mapping));
1083
1084 if (strcmp(attr[curIdx++], "mic_device_id")) {
1085 ALOGE("%s: mic_device_id not found", __func__);
1086 goto on_error;
1087 }
1088 strlcpy(microphone.device_id,
1089 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1090
1091 if (strcmp(attr[curIdx++], "channel_mapping")) {
1092 ALOGE("%s: channel_mapping not found", __func__);
1093 goto on_error;
1094 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301095 char *context = NULL;
1096 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301097 uint32_t idx = 0;
1098 while (token) {
1099 if (!find_enum_by_string(mic_channel_mapping, token,
1100 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1101 &microphone.channel_mapping[idx++])) {
1102 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301103 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301104 goto on_error;
1105 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301106 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301107 }
1108 microphone.channel_count = idx;
1109
1110 platform_set_microphone_map(my_data.platform, in_snd_device,
1111 &microphone);
1112 return;
1113on_error:
1114 in_snd_device = SND_DEVICE_NONE;
1115 return;
1116}
1117
1118
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301119/* process acdb meta info key value */
1120static void process_acdb_metainfo_key(const XML_Char **attr)
1121{
1122 if (strcmp(attr[0], "name") != 0) {
1123 ALOGE("%s: 'name' not found", __func__);
1124 goto done;
1125 }
1126
1127 if (strcmp(attr[2], "value") != 0) {
1128 ALOGE("%s: 'value' not found", __func__);
1129 goto done;
1130 }
1131
1132 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001133 switch(my_data.caller) {
1134 case ACDB_EXTN:
1135 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1136 ALOGE("%s: key %d was not set!", __func__, key);
1137 goto done;
1138 }
1139 break;
1140 case PLATFORM:
1141 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1142 ALOGE("%s: key %d was not set!", __func__, key);
1143 goto done;
1144 }
1145 break;
1146 default:
1147 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301148 }
1149
1150done:
1151 return;
1152}
1153
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301154static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1155{
1156 uint32_t attr_idx = 0;
1157 int32_t in_ch_idx = -1;
1158 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1159
1160 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1161 &mtmx_in_params_info);
1162 if (mtmx_in_params == NULL) {
1163 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1164 return;
1165 }
1166
1167 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1168 ALOGE("%s: 'in_channel_index' not found", __func__);
1169 return;
1170 }
1171
1172 in_ch_idx = atoi((char *)attr[attr_idx++]);
1173 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1174 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1175 return;
1176 }
1177
1178 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1179 ALOGE("%s: 'channel_count' not found", __func__);
1180 return;
1181 }
1182 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1183
1184 if (strcmp(attr[attr_idx++], "device") != 0) {
1185 ALOGE("%s: 'device' not found", __func__);
1186 return;
1187 }
1188 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1189 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1190
1191 if (strcmp(attr[attr_idx++], "interface") != 0) {
1192 ALOGE("%s: 'interface' not found", __func__);
1193 return;
1194 }
1195 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1196 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1197
1198 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1199 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1200 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1201 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1202 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1203 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1204 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1205 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1206
1207 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1208}
1209
1210static void process_custom_mtmx_in_params(const XML_Char **attr)
1211{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301212 int attr_idx = 0, i = 0;
1213 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301214
1215 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1216 ALOGE("%s: 'usecase' not found", __func__);
1217 return;
1218 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301219 /* Check if multi usecases are supported for this custom mtrx params */
1220 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1221 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1222 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1223 value = strtok_r(NULL, ",", &context);
1224 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301225
1226 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1227 ALOGE("%s: 'out_channel_count' not found", __func__);
1228 return;
1229 }
1230 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1231
1232 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1233
1234}
1235
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301236static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1237{
1238 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301239 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301240 char *context = NULL, *ch_coeff_value = NULL;
1241 struct audio_custom_mtmx_params *mtmx_params = NULL;
1242
1243 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1244 ALOGE("%s: 'out_channel_index' not found", __func__);
1245 return;
1246 }
1247 out_ch_idx = atoi((char *)attr[attr_idx++]);
1248
1249 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1250 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1251 return;
1252 }
1253
1254 if (strcmp(attr[attr_idx++], "values") != 0) {
1255 ALOGE("%s: 'values' not found", __func__);
1256 return;
1257 }
1258 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301259 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301260 if (mtmx_params == NULL) {
1261 ALOGE("%s: mtmx params with given param info, not found", __func__);
1262 return;
1263 }
1264 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1265 ip_channels = mtmx_params->info.ip_channels;
1266 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301267 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301268 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1269 = atoi(ch_coeff_value);
1270 ch_coeff_value = strtok_r(NULL, " ", &context);
1271 }
1272 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1273 ch_coeff_value != NULL)
1274 ALOGE("%s: invalid/malformed coefficient values", __func__);
1275}
1276
1277static void process_custom_mtmx_params(const XML_Char **attr)
1278{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301279 int attr_idx = 0, i = 0;
1280 char *context = NULL, *value = NULL;
1281
1282 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301283
1284 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1285 ALOGE("%s: 'param_id' not found", __func__);
1286 return;
1287 }
1288 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1289
1290 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1291 ALOGE("%s: 'in_channel_count' not found", __func__);
1292 return;
1293 }
1294 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1295
1296 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1297 ALOGE("%s: 'out_channel_count' not found", __func__);
1298 return;
1299 }
1300 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1301
1302 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1303 ALOGE("%s: 'usecase' not found", __func__);
1304 return;
1305 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301306
1307 /* check if multi usecases are supported for this custom mtrx params */
1308 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1309 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1310 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1311 value = strtok_r(NULL, ",", &context);
1312 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301313
1314 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1315 ALOGE("%s: 'snd_device' not found", __func__);
1316 return;
1317 }
1318 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301319
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301320 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1321 i = 0;
1322 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1323 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1324 mtmx_params_info.fe_id[i++] = atoi(value);
1325 value = strtok_r(NULL, ",", &context);
1326 }
1327
1328 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301329 }
1330
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301331 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1332
1333}
1334
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001335static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001336 const XML_Char **attr)
1337{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001338 if (my_data.caller == ACDB_EXTN) {
1339 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1340 section = ACDB_METAINFO_KEY;
1341 } else if (strcmp(tag_name, "param") == 0) {
1342 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1343 ALOGE("param tag only supported with CONFIG_PARAMS section");
1344 return;
1345 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001346
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001347 section_process_fn fn = section_table[section];
1348 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001349 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001350 } else if(my_data.caller == PLATFORM) {
1351 if (strcmp(tag_name, "bit_width_configs") == 0) {
1352 section = BITWIDTH;
1353 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1354 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001355 } else if (strcmp(tag_name, "module_ids") == 0) {
1356 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001357 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1358 section = PCM_ID;
1359 } else if (strcmp(tag_name, "backend_names") == 0) {
1360 section = BACKEND_NAME;
1361 } else if (strcmp(tag_name, "config_params") == 0) {
1362 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001363 } else if (strcmp(tag_name, "operator_specific") == 0) {
1364 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001365 } else if (strcmp(tag_name, "interface_names") == 0) {
1366 section = INTERFACE_NAME;
1367 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1368 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001369 } else if (strcmp(tag_name, "app_types") == 0) {
1370 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001371 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1372 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301373 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1374 section = MICROPHONE_CHARACTERISTIC;
1375 } else if (strcmp(tag_name, "snd_devices") == 0) {
1376 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001377 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001378 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001379 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001380 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001381 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1382 return;
1383 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001384
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001385 /* call into process function for the current section */
1386 section_process_fn fn = section_table[section];
1387 fn(attr);
1388 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1389 if (section != GAIN_LEVEL_MAPPING) {
1390 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1391 return;
1392 }
1393
1394 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1395 fn(attr);
1396 } else if (strcmp(tag_name, "usecase") == 0) {
1397 if (section != PCM_ID) {
1398 ALOGE("usecase tag only supported with PCM_ID section");
1399 return;
1400 }
1401
1402 section_process_fn fn = section_table[PCM_ID];
1403 fn(attr);
1404 } else if (strcmp(tag_name, "param") == 0) {
1405 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1406 ALOGE("param tag only supported with CONFIG_PARAMS section");
1407 return;
1408 }
1409
1410 section_process_fn fn = section_table[section];
1411 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301412 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001413 if (section != MODULE) {
1414 ALOGE("aec tag only supported with MODULE section");
1415 return;
1416 }
1417 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301418 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001419 if (section != MODULE) {
1420 ALOGE("ns tag only supported with MODULE section");
1421 return;
1422 }
1423 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001424 } else if (strcmp(tag_name, "mmsecns") == 0) {
1425 if (section != MODULE) {
1426 ALOGE("mmsecns tag only supported with MODULE section");
1427 return;
1428 }
1429 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001430 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1431 if (section != GAIN_LEVEL_MAPPING) {
1432 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1433 return;
1434 }
1435
1436 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1437 fn(attr);
1438 } else if (!strcmp(tag_name, "app")) {
1439 if (section != APP_TYPE) {
1440 ALOGE("app tag only valid in section APP_TYPE");
1441 return;
1442 }
1443
1444 section_process_fn fn = section_table[APP_TYPE];
1445 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301446 } else if (strcmp(tag_name, "microphone") == 0) {
1447 if (section != MICROPHONE_CHARACTERISTIC) {
1448 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1449 return;
1450 }
1451 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1452 fn(attr);
1453 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1454 if (section != SND_DEVICES) {
1455 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1456 return;
1457 }
1458 section = INPUT_SND_DEVICE;
1459 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1460 if (section != INPUT_SND_DEVICE) {
1461 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1462 return;
1463 }
1464 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1465 } else if (strcmp(tag_name, "snd_dev") == 0) {
1466 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1467 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1468 return;
1469 }
1470 section_process_fn fn = section_table[SND_DEV];
1471 fn(attr);
1472 } else if (strcmp(tag_name, "mic_info") == 0) {
1473 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1474 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1475 return;
1476 }
1477 if (in_snd_device == SND_DEVICE_NONE) {
1478 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1479 return;
1480 }
1481 section_process_fn fn = section_table[MIC_INFO];
1482 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301483 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1484 if (section != ROOT) {
1485 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1486 return;
1487 }
1488 section = CUSTOM_MTMX_PARAMS;
1489 section_process_fn fn = section_table[section];
1490 fn(attr);
1491 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1492 if (section != CUSTOM_MTMX_PARAMS) {
1493 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1494 return;
1495 }
1496 section = CUSTOM_MTMX_PARAM_COEFFS;
1497 section_process_fn fn = section_table[section];
1498 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001499 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1500 section = EXTERNAL_DEVICE_SPECIFIC;
1501 } else if (strcmp(tag_name, "ext_device") == 0) {
1502 section_process_fn fn = section_table[section];
1503 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301504 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1505 if (section != ROOT) {
1506 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1507 return;
1508 }
1509 section = CUSTOM_MTMX_IN_PARAMS;
1510 section_process_fn fn = section_table[section];
1511 fn(attr);
1512 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1513 if (section != CUSTOM_MTMX_IN_PARAMS) {
1514 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1515 return;
1516 }
1517 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Robert Lee58215542019-07-15 20:55:12 +08001518 } else if (strcmp(tag_name, "snd_device_delay") == 0) {
1519 section = SND_DEV_DELAY;
1520 } else if (strcmp(tag_name, "device_delay") == 0) {
Juyu Chen918e1e12019-08-08 15:28:18 -07001521 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1522 section = AUDIO_SOURCE_DELAY;
1523 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301524 section_process_fn fn = section_table[section];
1525 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301526 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001527 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001528 if(strcmp(tag_name, "config_params") == 0) {
1529 section = CONFIG_PARAMS;
1530 } else if (strcmp(tag_name, "param") == 0) {
1531 if (section != CONFIG_PARAMS) {
1532 ALOGE("param tag only supported with CONFIG_PARAMS section");
1533 return;
1534 }
1535
1536 section_process_fn fn = section_table[section];
1537 fn(attr);
1538 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001539 }
Ben Romberger55886882014-01-10 13:49:02 -08001540 return;
1541}
1542
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001543static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001544{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001545 if (strcmp(tag_name, "bit_width_configs") == 0) {
1546 section = ROOT;
1547 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001548 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001549 } else if (strcmp(tag_name, "module_ids") == 0) {
1550 section = ROOT;
1551 } else if (strcmp(tag_name, "aec") == 0) {
1552 section = MODULE;
1553 } else if (strcmp(tag_name, "ns") == 0) {
1554 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001555 } else if (strcmp(tag_name, "mmsecns") == 0) {
1556 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001557 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1558 section = ROOT;
1559 } else if (strcmp(tag_name, "backend_names") == 0) {
1560 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001561 } else if (strcmp(tag_name, "config_params") == 0) {
1562 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001563 } else if (strcmp(tag_name, "operator_specific") == 0) {
1564 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001565 } else if (strcmp(tag_name, "interface_names") == 0) {
1566 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001567 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1568 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001569 } else if (strcmp(tag_name, "app_types") == 0) {
1570 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301571 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1572 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301573 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1574 section = ROOT;
1575 } else if (strcmp(tag_name, "snd_devices") == 0) {
1576 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001577 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1578 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301579 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1580 section = SND_DEVICES;
1581 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1582 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301583 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1584 section = ROOT;
1585 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1586 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301587 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1588 section = ROOT;
1589 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1590 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001591 }
Ben Romberger55886882014-01-10 13:49:02 -08001592}
1593
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001594int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001595{
1596 XML_Parser parser;
1597 FILE *file;
1598 int ret = 0;
1599 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001600 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001601 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301602 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001603
Saurav Kumardba3caf2020-05-29 20:53:55 +05301604 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1605 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001606 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001607 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301608 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001609 MIXER_PATH_MAX_LENGTH);
1610 else
1611 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1612
1613 ALOGV("%s: platform info file name is %s", __func__,
1614 platform_info_file_name);
1615
1616 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001617 section = ROOT;
1618
Ben Romberger55886882014-01-10 13:49:02 -08001619 if (!file) {
1620 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001621 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001622 ret = -ENODEV;
1623 goto done;
1624 }
1625
1626 parser = XML_ParserCreate(NULL);
1627 if (!parser) {
1628 ALOGE("%s: Failed to create XML parser!", __func__);
1629 ret = -ENODEV;
1630 goto err_close_file;
1631 }
1632
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001633 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001634 my_data.platform = platform;
1635 my_data.kvpairs = str_parms_create();
1636
Ben Romberger55886882014-01-10 13:49:02 -08001637 XML_SetElementHandler(parser, start_tag, end_tag);
1638
1639 while (1) {
1640 buf = XML_GetBuffer(parser, BUF_SIZE);
1641 if (buf == NULL) {
1642 ALOGE("%s: XML_GetBuffer failed", __func__);
1643 ret = -ENOMEM;
1644 goto err_free_parser;
1645 }
1646
1647 bytes_read = fread(buf, 1, BUF_SIZE, file);
1648 if (bytes_read < 0) {
1649 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1650 ret = bytes_read;
1651 goto err_free_parser;
1652 }
1653
1654 if (XML_ParseBuffer(parser, bytes_read,
1655 bytes_read == 0) == XML_STATUS_ERROR) {
1656 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001657 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001658 ret = -EINVAL;
1659 goto err_free_parser;
1660 }
1661
1662 if (bytes_read == 0)
1663 break;
1664 }
1665
Ben Romberger55886882014-01-10 13:49:02 -08001666err_free_parser:
1667 XML_ParserFree(parser);
1668err_close_file:
1669 fclose(file);
1670done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001671 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001672 return ret;
1673}