blob: 9b64c791a5aa3b31167f1b4ac3be87eba6c32c97 [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"
42#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070043#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080044
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053045#ifdef DYNAMIC_LOG_ENABLED
46#include <log_xml_parser.h>
47#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
48#include <log_utils.h>
49#endif
50
Ben Romberger55886882014-01-10 13:49:02 -080051#define BUF_SIZE 1024
52
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070053typedef enum {
54 ROOT,
55 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070056 MODULE,
57 AEC,
58 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070059 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070060 PCM_ID,
61 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080062 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070063 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080064 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070065 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080066 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053067 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053068 MICROPHONE_CHARACTERISTIC,
69 SND_DEVICES,
70 INPUT_SND_DEVICE,
71 INPUT_SND_DEVICE_TO_MIC_MAPPING,
72 SND_DEV,
73 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053074 CUSTOM_MTMX_PARAMS,
75 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070076 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053077 CUSTOM_MTMX_IN_PARAMS,
78 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +080079 MMSECNS,
Robert Lee58215542019-07-15 20:55:12 +080080 SND_DEV_DELAY,
Juyu Chen918e1e12019-08-08 15:28:18 -070081 AUDIO_SOURCE_DELAY,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070082} section_t;
83
84typedef void (* section_process_fn)(const XML_Char **attr);
85
86static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070087static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
88static void process_effect_aec(const XML_Char **attr);
89static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070090static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070091static void process_pcm_id(const XML_Char **attr);
92static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080093static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070094static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070095static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080096static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070097static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080098static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053099static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530100static void process_microphone_characteristic(const XML_Char **attr);
101static void process_snd_dev(const XML_Char **attr);
102static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530103static void process_custom_mtmx_params(const XML_Char **attr);
104static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700105static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530106static void process_custom_mtmx_in_params(const XML_Char **attr);
107static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Guodong Hu1d46f342019-06-28 16:57:30 +0800108static void process_fluence_mmsecns(const XML_Char **attr);
Robert Lee58215542019-07-15 20:55:12 +0800109static void process_snd_device_delay(const XML_Char **attr);
Juyu Chen918e1e12019-08-08 15:28:18 -0700110static void process_audio_source_delay(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700111
112static section_process_fn section_table[] = {
113 [ROOT] = process_root,
114 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700115 [AEC] = process_effect_aec,
116 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700117 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700118 [PCM_ID] = process_pcm_id,
119 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800120 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700121 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800122 [OPERATOR_SPECIFIC] = process_operator_specific,
123 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700124 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530125 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530126 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
127 [SND_DEV] = process_snd_dev,
128 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530129 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
130 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700131 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530132 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
133 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800134 [MMSECNS] = process_fluence_mmsecns,
Robert Lee58215542019-07-15 20:55:12 +0800135 [SND_DEV_DELAY] = process_snd_device_delay,
Juyu Chen918e1e12019-08-08 15:28:18 -0700136 [AUDIO_SOURCE_DELAY] = process_audio_source_delay,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700137};
138
139static section_t section;
140
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700141struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700142 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700143 void *platform;
144 struct str_parms *kvpairs;
145};
146
147static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800148static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700149
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530150
151struct audio_string_to_enum {
152 const char* name;
153 unsigned int value;
154};
155
156static snd_device_t in_snd_device;
157
158static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
163};
164
165static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
167 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
172};
173
174static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
178};
179
180static const struct audio_string_to_enum device_in_types[] = {
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
199 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
200 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
201 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
202 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
203 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
204 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
205 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
206 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
207 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
208};
209
210enum {
211 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
212 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
213 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
214 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
215 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
216 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
217 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
218 | ORIENTATION) | GEOMETRIC_LOCATION) */
219};
220
221static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
222 int32_t len, unsigned int *value)
223{
224 if (table == NULL) {
225 ALOGE("%s: table is NULL", __func__);
226 return false;
227 }
228
229 if (name == NULL) {
230 ALOGE("null key");
231 return false;
232 }
233
234 for (int i = 0; i < len; i++) {
235 if (!strcmp(table[i].name, name)) {
236 *value = table[i].value;
237 return true;
238 }
239 }
240 return false;
241}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530242
243static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530244static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530245
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700246/*
247 * <audio_platform_info>
248 * <acdb_ids>
249 * <device name="???" acdb_id="???"/>
250 * ...
251 * ...
252 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700253 * <module_ids>
254 * <device name="???" module_id="???"/>
255 * ...
256 * ...
257 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700258 * <backend_names>
259 * <device name="???" backend="???"/>
260 * ...
261 * ...
262 * </backend_names>
263 * <pcm_ids>
264 * <usecase name="???" type="in/out" id="???"/>
265 * ...
266 * ...
267 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800268 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530269 * <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 -0800270 * ...
271 * ...
272 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700273 * <config_params>
274 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800275 * <param key="operator_info" value="tmus;aa;bb;cc"/>
276 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700277 * ...
278 * ...
279 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800280 *
281 * <operator_specific>
282 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
283 * ...
284 * ...
285 * </operator_specific>
286 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700287 * </audio_platform_info>
288 */
289
290static void process_root(const XML_Char **attr __unused)
291{
292}
293
294/* mapping from usecase to pcm dev id */
295static void process_pcm_id(const XML_Char **attr)
296{
297 int index;
298
299 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700300 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700301 goto done;
302 }
303
304 index = platform_get_usecase_index((char *)attr[1]);
305 if (index < 0) {
306 ALOGE("%s: usecase %s not found!",
307 __func__, attr[1]);
308 goto done;
309 }
310
311 if (strcmp(attr[2], "type") != 0) {
312 ALOGE("%s: usecase type not mentioned", __func__);
313 goto done;
314 }
315
316 int type = -1;
317
318 if (!strcasecmp((char *)attr[3], "in")) {
319 type = 1;
320 } else if (!strcasecmp((char *)attr[3], "out")) {
321 type = 0;
322 } else {
323 ALOGE("%s: type must be IN or OUT", __func__);
324 goto done;
325 }
326
327 if (strcmp(attr[4], "id") != 0) {
328 ALOGE("%s: usecase id not mentioned", __func__);
329 goto done;
330 }
331
332 int id = atoi((char *)attr[5]);
333
334 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
335 ALOGE("%s: usecase %s type %d id %d was not set!",
336 __func__, attr[1], type, id);
337 goto done;
338 }
339
340done:
341 return;
342}
343
344/* backend to be used for a device */
345static void process_backend_name(const XML_Char **attr)
346{
347 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530348 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530349 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700350
351 if (strcmp(attr[0], "name") != 0) {
352 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
353 goto done;
354 }
355
356 index = platform_get_snd_device_index((char *)attr[1]);
357 if (index < 0) {
358 ALOGE("%s: Device %s not found, no ACDB ID set!",
359 __func__, attr[1]);
360 goto done;
361 }
362
363 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530364 if (strcmp(attr[2], "interface") == 0)
365 hw_interface = (char *)attr[3];
366 } else {
367 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700368 }
369
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530370 if (attr[4] != NULL) {
371 if (strcmp(attr[4], "interface") != 0) {
372 hw_interface = NULL;
373 } else {
374 hw_interface = (char *)attr[5];
375 }
376 }
377
Ashish Jaind150d4c2017-02-03 18:44:34 +0530378 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700379 ALOGE("%s: Device %s backend %s was not set!",
380 __func__, attr[1], attr[3]);
381 goto done;
382 }
383
384done:
385 return;
386}
387
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700388static void process_gain_db_to_level_map(const XML_Char **attr)
389{
390 struct amp_db_and_gain_table tbl_entry;
391
392 if ((strcmp(attr[0], "db") != 0) ||
393 (strcmp(attr[2], "level") != 0)) {
394 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
395 __func__, attr[0], attr[2]);
396 goto done;
397 }
398
399 tbl_entry.db = atof(attr[1]);
400 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
401 tbl_entry.level = atoi(attr[3]);
402
Aalique Grahame22e49102018-12-18 14:23:57 -0800403 //custome level should be > 0. Level 0 is fixed for default
404 CHECK(tbl_entry.level > 0);
405
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700406 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
407 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
408 platform_add_gain_level_mapping(&tbl_entry);
409
410done:
411 return;
412}
413
414
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700415static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800416{
Ben Romberger61764e32014-01-10 13:49:02 -0800417 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800418
Ben Romberger61764e32014-01-10 13:49:02 -0800419 if (strcmp(attr[0], "name") != 0) {
420 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800421 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800422 }
Ben Romberger55886882014-01-10 13:49:02 -0800423
Ben Romberger61764e32014-01-10 13:49:02 -0800424 index = platform_get_snd_device_index((char *)attr[1]);
425 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800426 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
427 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800428 goto done;
429 }
430
431 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800432 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
433 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800434 goto done;
435 }
436
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700437 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
438 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800439 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800440 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800441 }
Ben Romberger55886882014-01-10 13:49:02 -0800442
Ben Romberger55886882014-01-10 13:49:02 -0800443done:
444 return;
445}
446
Aalique Grahame22e49102018-12-18 14:23:57 -0800447static void process_operator_specific(const XML_Char **attr)
448{
449 snd_device_t snd_device = SND_DEVICE_NONE;
450
451 if (strcmp(attr[0], "name") != 0) {
452 ALOGE("%s: 'name' not found", __func__);
453 goto done;
454 }
455
456 snd_device = platform_get_snd_device_index((char *)attr[1]);
457 if (snd_device < 0) {
458 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
459 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
460 goto done;
461 }
462
463 if (strcmp(attr[2], "operator") != 0) {
464 ALOGE("%s: 'operator' not found", __func__);
465 goto done;
466 }
467
468 if (strcmp(attr[4], "mixer_path") != 0) {
469 ALOGE("%s: 'mixer_path' not found", __func__);
470 goto done;
471 }
472
473 if (strcmp(attr[6], "acdb_id") != 0) {
474 ALOGE("%s: 'acdb_id' not found", __func__);
475 goto done;
476 }
477
478 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
479
480done:
481 return;
482}
483
Carter Hsu32a62362018-10-15 15:01:42 -0700484static void process_external_dev(const XML_Char **attr)
485{
486 snd_device_t snd_device = SND_DEVICE_NONE;
487
488 if (strcmp(attr[0], "name") != 0) {
489 ALOGE("%s: 'name' not found", __func__);
490 goto done;
491 }
492
493 snd_device = platform_get_snd_device_index((char *)attr[1]);
494 if (snd_device < 0) {
495 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
496 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
497 goto done;
498 }
499
500 if (strcmp(attr[2], "usbid") != 0) {
501 ALOGE("%s: 'usbid' not found", __func__);
502 goto done;
503 }
504
505 if (strcmp(attr[4], "acdb_id") != 0) {
506 ALOGE("%s: 'acdb_id' not found", __func__);
507 goto done;
508 }
509
510 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
511
512done:
513 return;
514}
515
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700516static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
517{
518 int index;
519 struct audio_effect_config effect_config;
520
521 if (strcmp(attr[0], "name") != 0) {
522 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
523 goto done;
524 }
525
526 index = platform_get_snd_device_index((char *)attr[1]);
527 if (index < 0) {
528 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
529 __func__, attr[1]);
530 goto done;
531 }
532
533 if (strcmp(attr[2], "module_id") != 0) {
534 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
535 __func__, attr[2]);
536 goto done;
537 }
538
539 if (strcmp(attr[4], "instance_id") != 0) {
540 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
541 __func__, attr[4]);
542 goto done;
543 }
544
545 if (strcmp(attr[6], "param_id") != 0) {
546 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
547 __func__, attr[6]);
548 goto done;
549 }
550
551 if (strcmp(attr[8], "param_value") != 0) {
552 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
553 __func__, attr[8]);
554 goto done;
555 }
556
557 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
558 strtol((char *)attr[5], NULL, 0),
559 strtol((char *)attr[7], NULL, 0),
560 strtol((char *)attr[9], NULL, 0)};
561
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700562 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
563 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
564 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
565 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
566 strtol((char *)attr[9], NULL, 0));
567 goto done;
568 }
569
570done:
571 return;
572}
573
574static void process_effect_aec(const XML_Char **attr)
575{
576 process_audio_effect(attr, EFFECT_AEC);
577 return;
578}
579
580static void process_effect_ns(const XML_Char **attr)
581{
582 process_audio_effect(attr, EFFECT_NS);
583 return;
584}
585
Guodong Hu1d46f342019-06-28 16:57:30 +0800586static void process_fluence_mmsecns(const XML_Char **attr)
587{
588 int index;
589 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
590
591 if (strcmp(attr[0], "name") != 0) {
592 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
593 goto done;
594 }
595
596 index = platform_get_snd_device_index((char *)attr[1]);
597 if (index < 0) {
598 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
599 __func__, attr[1]);
600 goto done;
601 }
602
603 if (strcmp(attr[2], "topology_id") != 0) {
604 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
605 __func__, attr[2]);
606 goto done;
607 }
608
609 if (strcmp(attr[4], "module_id") != 0) {
610 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
611 __func__, attr[4]);
612 goto done;
613 }
614
615 if (strcmp(attr[6], "instance_id") != 0) {
616 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
617 __func__, attr[6]);
618 goto done;
619 }
620
621 if (strcmp(attr[8], "param_id") != 0) {
622 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
623 __func__, attr[8]);
624 goto done;
625 }
626
627 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
628 strtol((char *)attr[5], NULL, 0),
629 strtol((char *)attr[7], NULL, 0),
630 strtol((char *)attr[9], NULL, 0)};
631
632
633 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
634 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
635 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
636 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
637 goto done;
638 }
639
640done:
641 return;
642}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700643static void process_bit_width(const XML_Char **attr)
644{
645 int index;
646
647 if (strcmp(attr[0], "name") != 0) {
648 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
649 goto done;
650 }
651
652 index = platform_get_snd_device_index((char *)attr[1]);
653 if (index < 0) {
654 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
655 __func__, attr[1]);
656 goto done;
657 }
658
659 if (strcmp(attr[2], "bit_width") != 0) {
660 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
661 __func__, attr[1]);
662 goto done;
663 }
664
665 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
666 ALOGE("%s: Device %s, ACDB ID %d was not set!",
667 __func__, attr[1], atoi((char *)attr[3]));
668 goto done;
669 }
670
671done:
672 return;
673}
674
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800675static void process_interface_name(const XML_Char **attr)
676{
677 int ret;
678
679 if (strcmp(attr[0], "name") != 0) {
680 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
681
682 goto done;
683 }
684
685 if (strcmp(attr[2], "interface") != 0) {
686 ALOGE("%s: Device %s has no Audio Interface set!",
687 __func__, attr[1]);
688
689 goto done;
690 }
691
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530692 if (strcmp(attr[4], "codec_type") != 0) {
693 ALOGE("%s: Device %s has no codec type set!",
694 __func__, attr[1]);
695
696 goto done;
697 }
698
699 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
700 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800701 if (ret < 0) {
702 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800703 goto done;
704 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800705
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800706done:
707 return;
708}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530709
Robert Lee58215542019-07-15 20:55:12 +0800710static void process_snd_device_delay(const XML_Char **attr)
711{
712 snd_device_t snd_device = SND_DEVICE_NONE;
713
714 if (strcmp(attr[0], "name") != 0) {
715 ALOGE("%s: 'name' not found", __func__);
716 goto done;
717 }
718
719 snd_device = platform_get_snd_device_index((char *)attr[1]);
720 if (snd_device < 0) {
721 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
722 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
723 goto done;
724 }
725
726 if (strcmp(attr[2], "delay") != 0) {
727 ALOGE("%s: 'delay' not found", __func__);
728 goto done;
729 }
730
731 platform_set_snd_device_delay(snd_device, atoi((char *)attr[3]));
732
733done:
734 return;
735}
736
Juyu Chen918e1e12019-08-08 15:28:18 -0700737static void process_audio_source_delay(const XML_Char **attr)
738{
739 audio_source_t audio_source = -1;
740
741 if (strcmp(attr[0], "name") != 0) {
742 ALOGE("%s: 'name' not found", __func__);
743 goto done;
744 }
745 audio_source = platform_get_audio_source_index((const char *)attr[1]);
746
747 if (audio_source < 0) {
748 ALOGE("%s: audio_source %s is not defined",
749 __func__, (char *)attr[1]);
750 goto done;
751 }
752
753 if (strcmp(attr[2], "delay") != 0) {
754 ALOGE("%s: 'delay' not found", __func__);
755 goto done;
756 }
757
758 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
759
760done:
761 return;
762}
763
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700764static void process_config_params(const XML_Char **attr)
765{
766 if (strcmp(attr[0], "key") != 0) {
767 ALOGE("%s: 'key' not found", __func__);
768 goto done;
769 }
770
771 if (strcmp(attr[2], "value") != 0) {
772 ALOGE("%s: 'value' not found", __func__);
773 goto done;
774 }
775
776 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700777 if (my_data.caller == PLATFORM)
778 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700779done:
780 return;
781}
782
Aalique Grahame22e49102018-12-18 14:23:57 -0800783static void process_app_type(const XML_Char **attr)
784{
785 if (strcmp(attr[0], "uc_type")) {
786 ALOGE("%s: uc_type not found", __func__);
787 goto done;
788 }
789
790 if (strcmp(attr[2], "mode")) {
791 ALOGE("%s: mode not found", __func__);
792 goto done;
793 }
794
795 if (strcmp(attr[4], "bit_width")) {
796 ALOGE("%s: bit_width not found", __func__);
797 goto done;
798 }
799
800 if (strcmp(attr[6], "id")) {
801 ALOGE("%s: id not found", __func__);
802 goto done;
803 }
804
805 if (strcmp(attr[8], "max_rate")) {
806 ALOGE("%s: max rate not found", __func__);
807 goto done;
808 }
809
810 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
811 atoi(attr[9]));
812done:
813 return;
814}
815
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530816static void process_microphone_characteristic(const XML_Char **attr) {
817 struct audio_microphone_characteristic_t microphone;
818 uint32_t curIdx = 0;
819
820 if (strcmp(attr[curIdx++], "valid_mask")) {
821 ALOGE("%s: valid_mask not found", __func__);
822 goto done;
823 }
824 uint32_t valid_mask = atoi(attr[curIdx++]);
825
826 if (strcmp(attr[curIdx++], "device_id")) {
827 ALOGE("%s: device_id not found", __func__);
828 goto done;
829 }
830 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
831 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
832 goto done;
833 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530834 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530835
836 if (strcmp(attr[curIdx++], "type")) {
837 ALOGE("%s: device not found", __func__);
838 goto done;
839 }
840 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
841 ARRAY_SIZE(device_in_types), &microphone.device)) {
842 ALOGE("%s: type %s in %s not found!",
843 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
844 goto done;
845 }
846
847 if (strcmp(attr[curIdx++], "address")) {
848 ALOGE("%s: address not found", __func__);
849 goto done;
850 }
851 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
852 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
853 goto done;
854 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530855 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530856 if (strlen(microphone.address) == 0) {
857 // If the address is empty, populate the address according to device type.
858 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530859 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530860 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530861 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530862 }
863 }
864
865 if (strcmp(attr[curIdx++], "location")) {
866 ALOGE("%s: location not found", __func__);
867 goto done;
868 }
869 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
870 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
871 ALOGE("%s: location %s in %s not found!",
872 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
873 goto done;
874 }
875
876 if (strcmp(attr[curIdx++], "group")) {
877 ALOGE("%s: group not found", __func__);
878 goto done;
879 }
880 microphone.group = atoi(attr[curIdx++]);
881
882 if (strcmp(attr[curIdx++], "index_in_the_group")) {
883 ALOGE("%s: index_in_the_group not found", __func__);
884 goto done;
885 }
886 microphone.index_in_the_group = atoi(attr[curIdx++]);
887
888 if (strcmp(attr[curIdx++], "directionality")) {
889 ALOGE("%s: directionality not found", __func__);
890 goto done;
891 }
892 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
893 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
894 ALOGE("%s: directionality %s in %s not found!",
895 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
896 goto done;
897 }
898
899 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
900 ALOGE("%s: num_frequency_responses not found", __func__);
901 goto done;
902 }
903 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530904 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530905 ALOGE("%s: num_frequency_responses is too large", __func__);
906 goto done;
907 }
908 if (microphone.num_frequency_responses > 0) {
909 if (strcmp(attr[curIdx++], "frequencies")) {
910 ALOGE("%s: frequencies not found", __func__);
911 goto done;
912 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530913 char *context = NULL;
914 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530915 uint32_t num_frequencies = 0;
916 while (token) {
917 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800918 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530919 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530920 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530921 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530922 }
923
924 if (strcmp(attr[curIdx++], "responses")) {
925 ALOGE("%s: responses not found", __func__);
926 goto done;
927 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530928 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530929 uint32_t num_responses = 0;
930 while (token) {
931 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800932 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530933 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530934 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530935 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530936 }
937
938 if (num_frequencies != num_responses
939 || num_frequencies != microphone.num_frequency_responses) {
940 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
941 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
942 goto done;
943 }
944 }
945
946 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
947 if (strcmp(attr[curIdx++], "sensitivity")) {
948 ALOGE("%s: sensitivity not found", __func__);
949 goto done;
950 }
951 microphone.sensitivity = atof(attr[curIdx++]);
952 } else {
953 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
954 }
955
956 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
957 if (strcmp(attr[curIdx++], "max_spl")) {
958 ALOGE("%s: max_spl not found", __func__);
959 goto done;
960 }
961 microphone.max_spl = atof(attr[curIdx++]);
962 } else {
963 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
964 }
965
966 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
967 if (strcmp(attr[curIdx++], "min_spl")) {
968 ALOGE("%s: min_spl not found", __func__);
969 goto done;
970 }
971 microphone.min_spl = atof(attr[curIdx++]);
972 } else {
973 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
974 }
975
976 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
977 if (strcmp(attr[curIdx++], "orientation")) {
978 ALOGE("%s: orientation not found", __func__);
979 goto done;
980 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530981 char *context = NULL;
982 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530983 float orientation[3];
984 uint32_t idx = 0;
985 while (token) {
986 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800987 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530988 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530989 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530990 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530991 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530992 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530993 ALOGE("%s: orientation invalid", __func__);
994 goto done;
995 }
996 microphone.orientation.x = orientation[0];
997 microphone.orientation.y = orientation[1];
998 microphone.orientation.z = orientation[2];
999 } else {
1000 microphone.orientation.x = 0.0f;
1001 microphone.orientation.y = 0.0f;
1002 microphone.orientation.z = 0.0f;
1003 }
1004
1005 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
1006 if (strcmp(attr[curIdx++], "geometric_location")) {
1007 ALOGE("%s: geometric_location not found", __func__);
1008 goto done;
1009 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301010 char *context = NULL;
1011 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301012 float geometric_location[3];
1013 uint32_t idx = 0;
1014 while (token) {
1015 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001016 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301017 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301018 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301019 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301020 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301021 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301022 ALOGE("%s: geometric_location invalid", __func__);
1023 goto done;
1024 }
1025 microphone.geometric_location.x = geometric_location[0];
1026 microphone.geometric_location.y = geometric_location[1];
1027 microphone.geometric_location.z = geometric_location[2];
1028 } else {
1029 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1030 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1031 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1032 }
1033
1034 platform_set_microphone_characteristic(my_data.platform, microphone);
1035done:
1036 return;
1037}
1038
1039static void process_snd_dev(const XML_Char **attr)
1040{
1041 uint32_t curIdx = 0;
1042 in_snd_device = SND_DEVICE_NONE;
1043
1044 if (strcmp(attr[curIdx++], "in_snd_device")) {
1045 ALOGE("%s: snd_device not found", __func__);
1046 return;
1047 }
1048 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1049 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1050 in_snd_device >= SND_DEVICE_IN_END) {
1051 ALOGE("%s: Sound device not valid", __func__);
1052 in_snd_device = SND_DEVICE_NONE;
1053 }
1054
1055 return;
1056}
1057
1058static void process_mic_info(const XML_Char **attr)
1059{
1060 uint32_t curIdx = 0;
1061 struct mic_info microphone;
1062
1063 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1064 sizeof(microphone.channel_mapping));
1065
1066 if (strcmp(attr[curIdx++], "mic_device_id")) {
1067 ALOGE("%s: mic_device_id not found", __func__);
1068 goto on_error;
1069 }
1070 strlcpy(microphone.device_id,
1071 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1072
1073 if (strcmp(attr[curIdx++], "channel_mapping")) {
1074 ALOGE("%s: channel_mapping not found", __func__);
1075 goto on_error;
1076 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301077 char *context = NULL;
1078 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301079 uint32_t idx = 0;
1080 while (token) {
1081 if (!find_enum_by_string(mic_channel_mapping, token,
1082 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1083 &microphone.channel_mapping[idx++])) {
1084 ALOGE("%s: channel_mapping %s in %s not found!",
1085 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
1086 goto on_error;
1087 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301088 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301089 }
1090 microphone.channel_count = idx;
1091
1092 platform_set_microphone_map(my_data.platform, in_snd_device,
1093 &microphone);
1094 return;
1095on_error:
1096 in_snd_device = SND_DEVICE_NONE;
1097 return;
1098}
1099
1100
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301101/* process acdb meta info key value */
1102static void process_acdb_metainfo_key(const XML_Char **attr)
1103{
1104 if (strcmp(attr[0], "name") != 0) {
1105 ALOGE("%s: 'name' not found", __func__);
1106 goto done;
1107 }
1108
1109 if (strcmp(attr[2], "value") != 0) {
1110 ALOGE("%s: 'value' not found", __func__);
1111 goto done;
1112 }
1113
1114 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001115 switch(my_data.caller) {
1116 case ACDB_EXTN:
1117 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1118 ALOGE("%s: key %d was not set!", __func__, key);
1119 goto done;
1120 }
1121 break;
1122 case PLATFORM:
1123 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1124 ALOGE("%s: key %d was not set!", __func__, key);
1125 goto done;
1126 }
1127 break;
1128 default:
1129 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301130 }
1131
1132done:
1133 return;
1134}
1135
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301136static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1137{
1138 uint32_t attr_idx = 0;
1139 int32_t in_ch_idx = -1;
1140 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1141
1142 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1143 &mtmx_in_params_info);
1144 if (mtmx_in_params == NULL) {
1145 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1146 return;
1147 }
1148
1149 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1150 ALOGE("%s: 'in_channel_index' not found", __func__);
1151 return;
1152 }
1153
1154 in_ch_idx = atoi((char *)attr[attr_idx++]);
1155 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1156 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1157 return;
1158 }
1159
1160 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1161 ALOGE("%s: 'channel_count' not found", __func__);
1162 return;
1163 }
1164 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1165
1166 if (strcmp(attr[attr_idx++], "device") != 0) {
1167 ALOGE("%s: 'device' not found", __func__);
1168 return;
1169 }
1170 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1171 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1172
1173 if (strcmp(attr[attr_idx++], "interface") != 0) {
1174 ALOGE("%s: 'interface' not found", __func__);
1175 return;
1176 }
1177 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1178 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1179
1180 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1181 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1182 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1183 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1184 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1185 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1186 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1187 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1188
1189 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1190}
1191
1192static void process_custom_mtmx_in_params(const XML_Char **attr)
1193{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301194 int attr_idx = 0, i = 0;
1195 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301196
1197 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1198 ALOGE("%s: 'usecase' not found", __func__);
1199 return;
1200 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301201 /* Check if multi usecases are supported for this custom mtrx params */
1202 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1203 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1204 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1205 value = strtok_r(NULL, ",", &context);
1206 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301207
1208 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1209 ALOGE("%s: 'out_channel_count' not found", __func__);
1210 return;
1211 }
1212 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1213
1214 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1215
1216}
1217
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301218static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1219{
1220 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301221 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301222 char *context = NULL, *ch_coeff_value = NULL;
1223 struct audio_custom_mtmx_params *mtmx_params = NULL;
1224
1225 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1226 ALOGE("%s: 'out_channel_index' not found", __func__);
1227 return;
1228 }
1229 out_ch_idx = atoi((char *)attr[attr_idx++]);
1230
1231 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1232 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1233 return;
1234 }
1235
1236 if (strcmp(attr[attr_idx++], "values") != 0) {
1237 ALOGE("%s: 'values' not found", __func__);
1238 return;
1239 }
1240 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301241 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301242 if (mtmx_params == NULL) {
1243 ALOGE("%s: mtmx params with given param info, not found", __func__);
1244 return;
1245 }
1246 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1247 ip_channels = mtmx_params->info.ip_channels;
1248 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301249 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301250 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1251 = atoi(ch_coeff_value);
1252 ch_coeff_value = strtok_r(NULL, " ", &context);
1253 }
1254 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1255 ch_coeff_value != NULL)
1256 ALOGE("%s: invalid/malformed coefficient values", __func__);
1257}
1258
1259static void process_custom_mtmx_params(const XML_Char **attr)
1260{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301261 int attr_idx = 0, i = 0;
1262 char *context = NULL, *value = NULL;
1263
1264 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301265
1266 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1267 ALOGE("%s: 'param_id' not found", __func__);
1268 return;
1269 }
1270 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1271
1272 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1273 ALOGE("%s: 'in_channel_count' not found", __func__);
1274 return;
1275 }
1276 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1277
1278 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1279 ALOGE("%s: 'out_channel_count' not found", __func__);
1280 return;
1281 }
1282 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1283
1284 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1285 ALOGE("%s: 'usecase' not found", __func__);
1286 return;
1287 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301288
1289 /* check if multi usecases are supported for this custom mtrx params */
1290 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1291 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1292 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1293 value = strtok_r(NULL, ",", &context);
1294 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301295
1296 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1297 ALOGE("%s: 'snd_device' not found", __func__);
1298 return;
1299 }
1300 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301301
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301302 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1303 i = 0;
1304 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1305 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1306 mtmx_params_info.fe_id[i++] = atoi(value);
1307 value = strtok_r(NULL, ",", &context);
1308 }
1309
1310 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301311 }
1312
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301313 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1314
1315}
1316
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001317static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001318 const XML_Char **attr)
1319{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001320 if (my_data.caller == ACDB_EXTN) {
1321 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1322 section = ACDB_METAINFO_KEY;
1323 } else if (strcmp(tag_name, "param") == 0) {
1324 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1325 ALOGE("param tag only supported with CONFIG_PARAMS section");
1326 return;
1327 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001328
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001329 section_process_fn fn = section_table[section];
1330 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001331 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001332 } else if(my_data.caller == PLATFORM) {
1333 if (strcmp(tag_name, "bit_width_configs") == 0) {
1334 section = BITWIDTH;
1335 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1336 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001337 } else if (strcmp(tag_name, "module_ids") == 0) {
1338 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001339 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1340 section = PCM_ID;
1341 } else if (strcmp(tag_name, "backend_names") == 0) {
1342 section = BACKEND_NAME;
1343 } else if (strcmp(tag_name, "config_params") == 0) {
1344 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001345 } else if (strcmp(tag_name, "operator_specific") == 0) {
1346 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001347 } else if (strcmp(tag_name, "interface_names") == 0) {
1348 section = INTERFACE_NAME;
1349 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1350 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001351 } else if (strcmp(tag_name, "app_types") == 0) {
1352 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001353 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1354 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301355 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1356 section = MICROPHONE_CHARACTERISTIC;
1357 } else if (strcmp(tag_name, "snd_devices") == 0) {
1358 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001359 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001360 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001361 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001362 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001363 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1364 return;
1365 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001366
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001367 /* call into process function for the current section */
1368 section_process_fn fn = section_table[section];
1369 fn(attr);
1370 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1371 if (section != GAIN_LEVEL_MAPPING) {
1372 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1373 return;
1374 }
1375
1376 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1377 fn(attr);
1378 } else if (strcmp(tag_name, "usecase") == 0) {
1379 if (section != PCM_ID) {
1380 ALOGE("usecase tag only supported with PCM_ID section");
1381 return;
1382 }
1383
1384 section_process_fn fn = section_table[PCM_ID];
1385 fn(attr);
1386 } else if (strcmp(tag_name, "param") == 0) {
1387 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1388 ALOGE("param tag only supported with CONFIG_PARAMS section");
1389 return;
1390 }
1391
1392 section_process_fn fn = section_table[section];
1393 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301394 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001395 if (section != MODULE) {
1396 ALOGE("aec tag only supported with MODULE section");
1397 return;
1398 }
1399 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301400 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001401 if (section != MODULE) {
1402 ALOGE("ns tag only supported with MODULE section");
1403 return;
1404 }
1405 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001406 } else if (strcmp(tag_name, "mmsecns") == 0) {
1407 if (section != MODULE) {
1408 ALOGE("mmsecns tag only supported with MODULE section");
1409 return;
1410 }
1411 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001412 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1413 if (section != GAIN_LEVEL_MAPPING) {
1414 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1415 return;
1416 }
1417
1418 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1419 fn(attr);
1420 } else if (!strcmp(tag_name, "app")) {
1421 if (section != APP_TYPE) {
1422 ALOGE("app tag only valid in section APP_TYPE");
1423 return;
1424 }
1425
1426 section_process_fn fn = section_table[APP_TYPE];
1427 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301428 } else if (strcmp(tag_name, "microphone") == 0) {
1429 if (section != MICROPHONE_CHARACTERISTIC) {
1430 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1431 return;
1432 }
1433 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1434 fn(attr);
1435 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1436 if (section != SND_DEVICES) {
1437 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1438 return;
1439 }
1440 section = INPUT_SND_DEVICE;
1441 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1442 if (section != INPUT_SND_DEVICE) {
1443 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1444 return;
1445 }
1446 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1447 } else if (strcmp(tag_name, "snd_dev") == 0) {
1448 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1449 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1450 return;
1451 }
1452 section_process_fn fn = section_table[SND_DEV];
1453 fn(attr);
1454 } else if (strcmp(tag_name, "mic_info") == 0) {
1455 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1456 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1457 return;
1458 }
1459 if (in_snd_device == SND_DEVICE_NONE) {
1460 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1461 return;
1462 }
1463 section_process_fn fn = section_table[MIC_INFO];
1464 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301465 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1466 if (section != ROOT) {
1467 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1468 return;
1469 }
1470 section = CUSTOM_MTMX_PARAMS;
1471 section_process_fn fn = section_table[section];
1472 fn(attr);
1473 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1474 if (section != CUSTOM_MTMX_PARAMS) {
1475 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1476 return;
1477 }
1478 section = CUSTOM_MTMX_PARAM_COEFFS;
1479 section_process_fn fn = section_table[section];
1480 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001481 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1482 section = EXTERNAL_DEVICE_SPECIFIC;
1483 } else if (strcmp(tag_name, "ext_device") == 0) {
1484 section_process_fn fn = section_table[section];
1485 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301486 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1487 if (section != ROOT) {
1488 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1489 return;
1490 }
1491 section = CUSTOM_MTMX_IN_PARAMS;
1492 section_process_fn fn = section_table[section];
1493 fn(attr);
1494 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1495 if (section != CUSTOM_MTMX_IN_PARAMS) {
1496 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1497 return;
1498 }
1499 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Robert Lee58215542019-07-15 20:55:12 +08001500 } else if (strcmp(tag_name, "snd_device_delay") == 0) {
1501 section = SND_DEV_DELAY;
1502 } else if (strcmp(tag_name, "device_delay") == 0) {
Juyu Chen918e1e12019-08-08 15:28:18 -07001503 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1504 section = AUDIO_SOURCE_DELAY;
1505 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301506 section_process_fn fn = section_table[section];
1507 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301508 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001509 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001510 if(strcmp(tag_name, "config_params") == 0) {
1511 section = CONFIG_PARAMS;
1512 } else if (strcmp(tag_name, "param") == 0) {
1513 if (section != CONFIG_PARAMS) {
1514 ALOGE("param tag only supported with CONFIG_PARAMS section");
1515 return;
1516 }
1517
1518 section_process_fn fn = section_table[section];
1519 fn(attr);
1520 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001521 }
Ben Romberger55886882014-01-10 13:49:02 -08001522 return;
1523}
1524
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001525static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001526{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001527 if (strcmp(tag_name, "bit_width_configs") == 0) {
1528 section = ROOT;
1529 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001530 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001531 } else if (strcmp(tag_name, "module_ids") == 0) {
1532 section = ROOT;
1533 } else if (strcmp(tag_name, "aec") == 0) {
1534 section = MODULE;
1535 } else if (strcmp(tag_name, "ns") == 0) {
1536 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001537 } else if (strcmp(tag_name, "mmsecns") == 0) {
1538 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001539 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1540 section = ROOT;
1541 } else if (strcmp(tag_name, "backend_names") == 0) {
1542 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001543 } else if (strcmp(tag_name, "config_params") == 0) {
1544 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001545 } else if (strcmp(tag_name, "operator_specific") == 0) {
1546 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001547 } else if (strcmp(tag_name, "interface_names") == 0) {
1548 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001549 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1550 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001551 } else if (strcmp(tag_name, "app_types") == 0) {
1552 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301553 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1554 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301555 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1556 section = ROOT;
1557 } else if (strcmp(tag_name, "snd_devices") == 0) {
1558 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001559 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1560 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301561 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1562 section = SND_DEVICES;
1563 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1564 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301565 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1566 section = ROOT;
1567 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1568 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301569 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1570 section = ROOT;
1571 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1572 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001573 }
Ben Romberger55886882014-01-10 13:49:02 -08001574}
1575
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001576int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001577{
1578 XML_Parser parser;
1579 FILE *file;
1580 int ret = 0;
1581 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001582 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001583 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001584
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001585 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001586 if (filename == NULL)
1587 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1588 MIXER_PATH_MAX_LENGTH);
1589 else
1590 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1591
1592 ALOGV("%s: platform info file name is %s", __func__,
1593 platform_info_file_name);
1594
1595 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001596 section = ROOT;
1597
Ben Romberger55886882014-01-10 13:49:02 -08001598 if (!file) {
1599 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001600 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001601 ret = -ENODEV;
1602 goto done;
1603 }
1604
1605 parser = XML_ParserCreate(NULL);
1606 if (!parser) {
1607 ALOGE("%s: Failed to create XML parser!", __func__);
1608 ret = -ENODEV;
1609 goto err_close_file;
1610 }
1611
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001612 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001613 my_data.platform = platform;
1614 my_data.kvpairs = str_parms_create();
1615
Ben Romberger55886882014-01-10 13:49:02 -08001616 XML_SetElementHandler(parser, start_tag, end_tag);
1617
1618 while (1) {
1619 buf = XML_GetBuffer(parser, BUF_SIZE);
1620 if (buf == NULL) {
1621 ALOGE("%s: XML_GetBuffer failed", __func__);
1622 ret = -ENOMEM;
1623 goto err_free_parser;
1624 }
1625
1626 bytes_read = fread(buf, 1, BUF_SIZE, file);
1627 if (bytes_read < 0) {
1628 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1629 ret = bytes_read;
1630 goto err_free_parser;
1631 }
1632
1633 if (XML_ParseBuffer(parser, bytes_read,
1634 bytes_read == 0) == XML_STATUS_ERROR) {
1635 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001636 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001637 ret = -EINVAL;
1638 goto err_free_parser;
1639 }
1640
1641 if (bytes_read == 0)
1642 break;
1643 }
1644
Ben Romberger55886882014-01-10 13:49:02 -08001645err_free_parser:
1646 XML_ParserFree(parser);
1647err_close_file:
1648 fclose(file);
1649done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001650 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001651 return ret;
1652}