blob: 84f56a10b73531361ab928dbbfb56657ff60c642 [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>
Atmanaecabe12019-07-04 17:36:59 +000044#include <pthread.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070045#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080046
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053047#ifdef DYNAMIC_LOG_ENABLED
48#include <log_xml_parser.h>
49#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
50#include <log_utils.h>
51#endif
52
Ben Romberger55886882014-01-10 13:49:02 -080053#define BUF_SIZE 1024
Saurav Kumardba3caf2020-05-29 20:53:55 +053054char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH];
55char platform_info_xml_path_file[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -080056
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070057typedef enum {
58 ROOT,
59 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070060 MODULE,
61 AEC,
62 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070063 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070064 PCM_ID,
65 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080066 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070067 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080068 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070069 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080070 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053071 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053072 MICROPHONE_CHARACTERISTIC,
73 SND_DEVICES,
74 INPUT_SND_DEVICE,
75 INPUT_SND_DEVICE_TO_MIC_MAPPING,
76 SND_DEV,
77 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053078 CUSTOM_MTMX_PARAMS,
79 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070080 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053081 CUSTOM_MTMX_IN_PARAMS,
82 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +080083 MMSECNS,
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);
Juyu Chen918e1e12019-08-08 15:28:18 -0700121static void process_audio_source_delay(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700122
123static section_process_fn section_table[] = {
124 [ROOT] = process_root,
125 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700126 [AEC] = process_effect_aec,
127 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700128 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700129 [PCM_ID] = process_pcm_id,
130 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800131 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700132 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800133 [OPERATOR_SPECIFIC] = process_operator_specific,
134 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700135 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530136 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530137 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
138 [SND_DEV] = process_snd_dev,
139 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530140 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
141 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700142 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530143 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
144 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800145 [MMSECNS] = process_fluence_mmsecns,
Juyu Chen918e1e12019-08-08 15:28:18 -0700146 [AUDIO_SOURCE_DELAY] = process_audio_source_delay,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700147};
148
149static section_t section;
150
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700151struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700152 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700153 void *platform;
154 struct str_parms *kvpairs;
155};
156
157static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800158static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700159
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530160
161struct audio_string_to_enum {
162 const char* name;
163 unsigned int value;
164};
165
166static snd_device_t in_snd_device;
167
168static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
173};
174
175static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
182};
183
184static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
188};
189
190static const struct audio_string_to_enum device_in_types[] = {
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
199 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
200 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
201 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
202 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
203 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
204 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
205 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
206 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
207 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
208 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
209 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
210 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
211 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
212 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
213 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
214 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
215 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
216 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
217 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
218};
219
220enum {
221 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
222 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
223 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
224 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
225 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
226 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
227 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
228 | ORIENTATION) | GEOMETRIC_LOCATION) */
229};
230
231static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
232 int32_t len, unsigned int *value)
233{
234 if (table == NULL) {
235 ALOGE("%s: table is NULL", __func__);
236 return false;
237 }
238
239 if (name == NULL) {
240 ALOGE("null key");
241 return false;
242 }
243
244 for (int i = 0; i < len; i++) {
245 if (!strcmp(table[i].name, name)) {
246 *value = table[i].value;
247 return true;
248 }
249 }
250 return false;
251}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530252
253static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530254static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530255
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700256/*
257 * <audio_platform_info>
258 * <acdb_ids>
259 * <device name="???" acdb_id="???"/>
260 * ...
261 * ...
262 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700263 * <module_ids>
264 * <device name="???" module_id="???"/>
265 * ...
266 * ...
267 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700268 * <backend_names>
269 * <device name="???" backend="???"/>
270 * ...
271 * ...
272 * </backend_names>
273 * <pcm_ids>
274 * <usecase name="???" type="in/out" id="???"/>
275 * ...
276 * ...
277 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800278 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530279 * <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 -0800280 * ...
281 * ...
282 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700283 * <config_params>
284 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800285 * <param key="operator_info" value="tmus;aa;bb;cc"/>
286 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700287 * ...
288 * ...
289 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800290 *
291 * <operator_specific>
292 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
293 * ...
294 * ...
295 * </operator_specific>
296 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700297 * </audio_platform_info>
298 */
299
300static void process_root(const XML_Char **attr __unused)
301{
302}
303
304/* mapping from usecase to pcm dev id */
305static void process_pcm_id(const XML_Char **attr)
306{
307 int index;
308
309 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700310 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700311 goto done;
312 }
313
314 index = platform_get_usecase_index((char *)attr[1]);
315 if (index < 0) {
316 ALOGE("%s: usecase %s not found!",
317 __func__, attr[1]);
318 goto done;
319 }
320
321 if (strcmp(attr[2], "type") != 0) {
322 ALOGE("%s: usecase type not mentioned", __func__);
323 goto done;
324 }
325
326 int type = -1;
327
328 if (!strcasecmp((char *)attr[3], "in")) {
329 type = 1;
330 } else if (!strcasecmp((char *)attr[3], "out")) {
331 type = 0;
332 } else {
333 ALOGE("%s: type must be IN or OUT", __func__);
334 goto done;
335 }
336
337 if (strcmp(attr[4], "id") != 0) {
338 ALOGE("%s: usecase id not mentioned", __func__);
339 goto done;
340 }
341
342 int id = atoi((char *)attr[5]);
343
344 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
345 ALOGE("%s: usecase %s type %d id %d was not set!",
346 __func__, attr[1], type, id);
347 goto done;
348 }
349
350done:
351 return;
352}
353
354/* backend to be used for a device */
355static void process_backend_name(const XML_Char **attr)
356{
357 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530358 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530359 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700360
361 if (strcmp(attr[0], "name") != 0) {
362 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
363 goto done;
364 }
365
366 index = platform_get_snd_device_index((char *)attr[1]);
367 if (index < 0) {
368 ALOGE("%s: Device %s not found, no ACDB ID set!",
369 __func__, attr[1]);
370 goto done;
371 }
372
373 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530374 if (strcmp(attr[2], "interface") == 0)
375 hw_interface = (char *)attr[3];
376 } else {
377 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700378 }
379
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530380 if (attr[4] != NULL) {
381 if (strcmp(attr[4], "interface") != 0) {
382 hw_interface = NULL;
383 } else {
384 hw_interface = (char *)attr[5];
385 }
386 }
387
Ashish Jaind150d4c2017-02-03 18:44:34 +0530388 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700389 ALOGE("%s: Device %s backend %s was not set!",
390 __func__, attr[1], attr[3]);
391 goto done;
392 }
393
394done:
395 return;
396}
397
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700398static void process_gain_db_to_level_map(const XML_Char **attr)
399{
400 struct amp_db_and_gain_table tbl_entry;
401
402 if ((strcmp(attr[0], "db") != 0) ||
403 (strcmp(attr[2], "level") != 0)) {
404 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
405 __func__, attr[0], attr[2]);
406 goto done;
407 }
408
409 tbl_entry.db = atof(attr[1]);
410 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
411 tbl_entry.level = atoi(attr[3]);
412
Aalique Grahame22e49102018-12-18 14:23:57 -0800413 //custome level should be > 0. Level 0 is fixed for default
414 CHECK(tbl_entry.level > 0);
415
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700416 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
417 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
418 platform_add_gain_level_mapping(&tbl_entry);
419
420done:
421 return;
422}
423
424
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700425static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800426{
Ben Romberger61764e32014-01-10 13:49:02 -0800427 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800428
Ben Romberger61764e32014-01-10 13:49:02 -0800429 if (strcmp(attr[0], "name") != 0) {
430 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800431 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800432 }
Ben Romberger55886882014-01-10 13:49:02 -0800433
Ben Romberger61764e32014-01-10 13:49:02 -0800434 index = platform_get_snd_device_index((char *)attr[1]);
435 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800436 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
437 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800438 goto done;
439 }
440
441 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800442 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
443 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800444 goto done;
445 }
446
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700447 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
448 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800449 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800450 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800451 }
Ben Romberger55886882014-01-10 13:49:02 -0800452
Ben Romberger55886882014-01-10 13:49:02 -0800453done:
454 return;
455}
456
Aalique Grahame22e49102018-12-18 14:23:57 -0800457static void process_operator_specific(const XML_Char **attr)
458{
459 snd_device_t snd_device = SND_DEVICE_NONE;
460
461 if (strcmp(attr[0], "name") != 0) {
462 ALOGE("%s: 'name' not found", __func__);
463 goto done;
464 }
465
466 snd_device = platform_get_snd_device_index((char *)attr[1]);
467 if (snd_device < 0) {
468 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530469 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800470 goto done;
471 }
472
473 if (strcmp(attr[2], "operator") != 0) {
474 ALOGE("%s: 'operator' not found", __func__);
475 goto done;
476 }
477
478 if (strcmp(attr[4], "mixer_path") != 0) {
479 ALOGE("%s: 'mixer_path' not found", __func__);
480 goto done;
481 }
482
483 if (strcmp(attr[6], "acdb_id") != 0) {
484 ALOGE("%s: 'acdb_id' not found", __func__);
485 goto done;
486 }
487
488 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
489
490done:
491 return;
492}
493
Carter Hsu32a62362018-10-15 15:01:42 -0700494static void process_external_dev(const XML_Char **attr)
495{
496 snd_device_t snd_device = SND_DEVICE_NONE;
497
498 if (strcmp(attr[0], "name") != 0) {
499 ALOGE("%s: 'name' not found", __func__);
500 goto done;
501 }
502
503 snd_device = platform_get_snd_device_index((char *)attr[1]);
504 if (snd_device < 0) {
505 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530506 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700507 goto done;
508 }
509
510 if (strcmp(attr[2], "usbid") != 0) {
511 ALOGE("%s: 'usbid' not found", __func__);
512 goto done;
513 }
514
515 if (strcmp(attr[4], "acdb_id") != 0) {
516 ALOGE("%s: 'acdb_id' not found", __func__);
517 goto done;
518 }
519
520 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
521
522done:
523 return;
524}
525
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700526static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
527{
528 int index;
529 struct audio_effect_config effect_config;
530
531 if (strcmp(attr[0], "name") != 0) {
532 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
533 goto done;
534 }
535
536 index = platform_get_snd_device_index((char *)attr[1]);
537 if (index < 0) {
538 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
539 __func__, attr[1]);
540 goto done;
541 }
542
543 if (strcmp(attr[2], "module_id") != 0) {
544 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
545 __func__, attr[2]);
546 goto done;
547 }
548
549 if (strcmp(attr[4], "instance_id") != 0) {
550 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
551 __func__, attr[4]);
552 goto done;
553 }
554
555 if (strcmp(attr[6], "param_id") != 0) {
556 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
557 __func__, attr[6]);
558 goto done;
559 }
560
561 if (strcmp(attr[8], "param_value") != 0) {
562 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
563 __func__, attr[8]);
564 goto done;
565 }
566
567 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
568 strtol((char *)attr[5], NULL, 0),
569 strtol((char *)attr[7], NULL, 0),
570 strtol((char *)attr[9], NULL, 0)};
571
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700572 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
573 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
574 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
575 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
576 strtol((char *)attr[9], NULL, 0));
577 goto done;
578 }
579
580done:
581 return;
582}
583
584static void process_effect_aec(const XML_Char **attr)
585{
586 process_audio_effect(attr, EFFECT_AEC);
587 return;
588}
589
590static void process_effect_ns(const XML_Char **attr)
591{
592 process_audio_effect(attr, EFFECT_NS);
593 return;
594}
595
Guodong Hu1d46f342019-06-28 16:57:30 +0800596static void process_fluence_mmsecns(const XML_Char **attr)
597{
598 int index;
599 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
600
601 if (strcmp(attr[0], "name") != 0) {
602 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
603 goto done;
604 }
605
606 index = platform_get_snd_device_index((char *)attr[1]);
607 if (index < 0) {
608 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
609 __func__, attr[1]);
610 goto done;
611 }
612
613 if (strcmp(attr[2], "topology_id") != 0) {
614 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
615 __func__, attr[2]);
616 goto done;
617 }
618
619 if (strcmp(attr[4], "module_id") != 0) {
620 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
621 __func__, attr[4]);
622 goto done;
623 }
624
625 if (strcmp(attr[6], "instance_id") != 0) {
626 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
627 __func__, attr[6]);
628 goto done;
629 }
630
631 if (strcmp(attr[8], "param_id") != 0) {
632 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
633 __func__, attr[8]);
634 goto done;
635 }
636
637 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
638 strtol((char *)attr[5], NULL, 0),
639 strtol((char *)attr[7], NULL, 0),
640 strtol((char *)attr[9], NULL, 0)};
641
642
643 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
644 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
645 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
646 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
647 goto done;
648 }
649
650done:
651 return;
652}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700653static void process_bit_width(const XML_Char **attr)
654{
655 int index;
656
657 if (strcmp(attr[0], "name") != 0) {
658 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
659 goto done;
660 }
661
662 index = platform_get_snd_device_index((char *)attr[1]);
663 if (index < 0) {
664 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
665 __func__, attr[1]);
666 goto done;
667 }
668
669 if (strcmp(attr[2], "bit_width") != 0) {
670 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
671 __func__, attr[1]);
672 goto done;
673 }
674
675 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
676 ALOGE("%s: Device %s, ACDB ID %d was not set!",
677 __func__, attr[1], atoi((char *)attr[3]));
678 goto done;
679 }
680
681done:
682 return;
683}
684
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800685static void process_interface_name(const XML_Char **attr)
686{
687 int ret;
688
689 if (strcmp(attr[0], "name") != 0) {
690 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
691
692 goto done;
693 }
694
695 if (strcmp(attr[2], "interface") != 0) {
696 ALOGE("%s: Device %s has no Audio Interface set!",
697 __func__, attr[1]);
698
699 goto done;
700 }
701
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530702 if (strcmp(attr[4], "codec_type") != 0) {
703 ALOGE("%s: Device %s has no codec type set!",
704 __func__, attr[1]);
705
706 goto done;
707 }
708
709 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
710 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800711 if (ret < 0) {
712 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800713 goto done;
714 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800715
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800716done:
717 return;
718}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530719
Juyu Chen918e1e12019-08-08 15:28:18 -0700720static void process_audio_source_delay(const XML_Char **attr)
721{
722 audio_source_t audio_source = -1;
723
724 if (strcmp(attr[0], "name") != 0) {
725 ALOGE("%s: 'name' not found", __func__);
726 goto done;
727 }
George Gao9ba8a142020-07-23 14:30:03 -0700728
Juyu Chen918e1e12019-08-08 15:28:18 -0700729 audio_source = platform_get_audio_source_index((const char *)attr[1]);
730
731 if (audio_source < 0) {
732 ALOGE("%s: audio_source %s is not defined",
733 __func__, (char *)attr[1]);
734 goto done;
735 }
736
737 if (strcmp(attr[2], "delay") != 0) {
738 ALOGE("%s: 'delay' not found", __func__);
739 goto done;
740 }
741
742 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
743
744done:
745 return;
746}
747
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700748static void process_config_params(const XML_Char **attr)
749{
750 if (strcmp(attr[0], "key") != 0) {
751 ALOGE("%s: 'key' not found", __func__);
752 goto done;
753 }
754
755 if (strcmp(attr[2], "value") != 0) {
756 ALOGE("%s: 'value' not found", __func__);
757 goto done;
758 }
759
760 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700761 if (my_data.caller == PLATFORM)
762 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700763done:
764 return;
765}
766
Aalique Grahame22e49102018-12-18 14:23:57 -0800767static void process_app_type(const XML_Char **attr)
768{
769 if (strcmp(attr[0], "uc_type")) {
770 ALOGE("%s: uc_type not found", __func__);
771 goto done;
772 }
773
774 if (strcmp(attr[2], "mode")) {
775 ALOGE("%s: mode not found", __func__);
776 goto done;
777 }
778
779 if (strcmp(attr[4], "bit_width")) {
780 ALOGE("%s: bit_width not found", __func__);
781 goto done;
782 }
783
784 if (strcmp(attr[6], "id")) {
785 ALOGE("%s: id not found", __func__);
786 goto done;
787 }
788
789 if (strcmp(attr[8], "max_rate")) {
790 ALOGE("%s: max rate not found", __func__);
791 goto done;
792 }
793
794 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
795 atoi(attr[9]));
796done:
797 return;
798}
799
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530800static void process_microphone_characteristic(const XML_Char **attr) {
801 struct audio_microphone_characteristic_t microphone;
802 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530803 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530804
Saurav Kumardba3caf2020-05-29 20:53:55 +0530805 strlcpy(platform_info_xml_path, get_platform_xml_path(),
806 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530807 if (strcmp(attr[curIdx++], "valid_mask")) {
808 ALOGE("%s: valid_mask not found", __func__);
809 goto done;
810 }
811 uint32_t valid_mask = atoi(attr[curIdx++]);
812
813 if (strcmp(attr[curIdx++], "device_id")) {
814 ALOGE("%s: device_id not found", __func__);
815 goto done;
816 }
817 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
818 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
819 goto done;
820 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530821 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530822
823 if (strcmp(attr[curIdx++], "type")) {
824 ALOGE("%s: device not found", __func__);
825 goto done;
826 }
827 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
828 ARRAY_SIZE(device_in_types), &microphone.device)) {
829 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530830 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530831 goto done;
832 }
833
834 if (strcmp(attr[curIdx++], "address")) {
835 ALOGE("%s: address not found", __func__);
836 goto done;
837 }
838 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
839 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
840 goto done;
841 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530842 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530843 if (strlen(microphone.address) == 0) {
844 // If the address is empty, populate the address according to device type.
845 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530846 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530847 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530848 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530849 }
850 }
851
852 if (strcmp(attr[curIdx++], "location")) {
853 ALOGE("%s: location not found", __func__);
854 goto done;
855 }
856 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
857 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
858 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530859 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530860 goto done;
861 }
862
863 if (strcmp(attr[curIdx++], "group")) {
864 ALOGE("%s: group not found", __func__);
865 goto done;
866 }
867 microphone.group = atoi(attr[curIdx++]);
868
869 if (strcmp(attr[curIdx++], "index_in_the_group")) {
870 ALOGE("%s: index_in_the_group not found", __func__);
871 goto done;
872 }
873 microphone.index_in_the_group = atoi(attr[curIdx++]);
874
875 if (strcmp(attr[curIdx++], "directionality")) {
876 ALOGE("%s: directionality not found", __func__);
877 goto done;
878 }
879 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
880 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
881 ALOGE("%s: directionality %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530882 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530883 goto done;
884 }
885
886 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
887 ALOGE("%s: num_frequency_responses not found", __func__);
888 goto done;
889 }
890 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530891 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530892 ALOGE("%s: num_frequency_responses is too large", __func__);
893 goto done;
894 }
895 if (microphone.num_frequency_responses > 0) {
896 if (strcmp(attr[curIdx++], "frequencies")) {
897 ALOGE("%s: frequencies not found", __func__);
898 goto done;
899 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530900 char *context = NULL;
901 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530902 uint32_t num_frequencies = 0;
903 while (token) {
904 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800905 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530906 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530907 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530908 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530909 }
910
911 if (strcmp(attr[curIdx++], "responses")) {
912 ALOGE("%s: responses not found", __func__);
913 goto done;
914 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530915 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530916 uint32_t num_responses = 0;
917 while (token) {
918 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800919 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530920 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530921 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530922 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530923 }
924
925 if (num_frequencies != num_responses
926 || num_frequencies != microphone.num_frequency_responses) {
927 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
928 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
929 goto done;
930 }
931 }
932
933 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
934 if (strcmp(attr[curIdx++], "sensitivity")) {
935 ALOGE("%s: sensitivity not found", __func__);
936 goto done;
937 }
938 microphone.sensitivity = atof(attr[curIdx++]);
939 } else {
940 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
941 }
942
943 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
944 if (strcmp(attr[curIdx++], "max_spl")) {
945 ALOGE("%s: max_spl not found", __func__);
946 goto done;
947 }
948 microphone.max_spl = atof(attr[curIdx++]);
949 } else {
950 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
951 }
952
953 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
954 if (strcmp(attr[curIdx++], "min_spl")) {
955 ALOGE("%s: min_spl not found", __func__);
956 goto done;
957 }
958 microphone.min_spl = atof(attr[curIdx++]);
959 } else {
960 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
961 }
962
963 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
964 if (strcmp(attr[curIdx++], "orientation")) {
965 ALOGE("%s: orientation not found", __func__);
966 goto done;
967 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530968 char *context = NULL;
969 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530970 float orientation[3];
971 uint32_t idx = 0;
972 while (token) {
973 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800974 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530975 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530976 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530977 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530978 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530979 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530980 ALOGE("%s: orientation invalid", __func__);
981 goto done;
982 }
983 microphone.orientation.x = orientation[0];
984 microphone.orientation.y = orientation[1];
985 microphone.orientation.z = orientation[2];
986 } else {
987 microphone.orientation.x = 0.0f;
988 microphone.orientation.y = 0.0f;
989 microphone.orientation.z = 0.0f;
990 }
991
992 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
993 if (strcmp(attr[curIdx++], "geometric_location")) {
994 ALOGE("%s: geometric_location not found", __func__);
995 goto done;
996 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530997 char *context = NULL;
998 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530999 float geometric_location[3];
1000 uint32_t idx = 0;
1001 while (token) {
1002 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001003 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301004 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301005 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301006 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301007 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301008 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301009 ALOGE("%s: geometric_location invalid", __func__);
1010 goto done;
1011 }
1012 microphone.geometric_location.x = geometric_location[0];
1013 microphone.geometric_location.y = geometric_location[1];
1014 microphone.geometric_location.z = geometric_location[2];
1015 } else {
1016 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1017 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1018 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1019 }
1020
1021 platform_set_microphone_characteristic(my_data.platform, microphone);
1022done:
1023 return;
1024}
1025
1026static void process_snd_dev(const XML_Char **attr)
1027{
1028 uint32_t curIdx = 0;
1029 in_snd_device = SND_DEVICE_NONE;
1030
1031 if (strcmp(attr[curIdx++], "in_snd_device")) {
1032 ALOGE("%s: snd_device not found", __func__);
1033 return;
1034 }
1035 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1036 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1037 in_snd_device >= SND_DEVICE_IN_END) {
1038 ALOGE("%s: Sound device not valid", __func__);
1039 in_snd_device = SND_DEVICE_NONE;
1040 }
1041
1042 return;
1043}
1044
1045static void process_mic_info(const XML_Char **attr)
1046{
1047 uint32_t curIdx = 0;
1048 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301049 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301050
Saurav Kumardba3caf2020-05-29 20:53:55 +05301051 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1052 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301053 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1054 sizeof(microphone.channel_mapping));
1055
1056 if (strcmp(attr[curIdx++], "mic_device_id")) {
1057 ALOGE("%s: mic_device_id not found", __func__);
1058 goto on_error;
1059 }
1060 strlcpy(microphone.device_id,
1061 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1062
1063 if (strcmp(attr[curIdx++], "channel_mapping")) {
1064 ALOGE("%s: channel_mapping not found", __func__);
1065 goto on_error;
1066 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301067 char *context = NULL;
1068 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301069 uint32_t idx = 0;
1070 while (token) {
1071 if (!find_enum_by_string(mic_channel_mapping, token,
1072 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1073 &microphone.channel_mapping[idx++])) {
1074 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301075 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301076 goto on_error;
1077 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301078 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301079 }
1080 microphone.channel_count = idx;
1081
1082 platform_set_microphone_map(my_data.platform, in_snd_device,
1083 &microphone);
1084 return;
1085on_error:
1086 in_snd_device = SND_DEVICE_NONE;
1087 return;
1088}
1089
1090
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301091/* process acdb meta info key value */
1092static void process_acdb_metainfo_key(const XML_Char **attr)
1093{
1094 if (strcmp(attr[0], "name") != 0) {
1095 ALOGE("%s: 'name' not found", __func__);
1096 goto done;
1097 }
1098
1099 if (strcmp(attr[2], "value") != 0) {
1100 ALOGE("%s: 'value' not found", __func__);
1101 goto done;
1102 }
1103
1104 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001105 switch(my_data.caller) {
1106 case ACDB_EXTN:
1107 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1108 ALOGE("%s: key %d was not set!", __func__, key);
1109 goto done;
1110 }
1111 break;
1112 case PLATFORM:
1113 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1114 ALOGE("%s: key %d was not set!", __func__, key);
1115 goto done;
1116 }
1117 break;
1118 default:
1119 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301120 }
1121
1122done:
1123 return;
1124}
1125
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301126static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1127{
1128 uint32_t attr_idx = 0;
1129 int32_t in_ch_idx = -1;
1130 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1131
1132 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1133 &mtmx_in_params_info);
1134 if (mtmx_in_params == NULL) {
1135 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1136 return;
1137 }
1138
1139 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1140 ALOGE("%s: 'in_channel_index' not found", __func__);
1141 return;
1142 }
1143
1144 in_ch_idx = atoi((char *)attr[attr_idx++]);
1145 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1146 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1147 return;
1148 }
1149
1150 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1151 ALOGE("%s: 'channel_count' not found", __func__);
1152 return;
1153 }
1154 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1155
1156 if (strcmp(attr[attr_idx++], "device") != 0) {
1157 ALOGE("%s: 'device' not found", __func__);
1158 return;
1159 }
1160 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1161 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1162
1163 if (strcmp(attr[attr_idx++], "interface") != 0) {
1164 ALOGE("%s: 'interface' not found", __func__);
1165 return;
1166 }
1167 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1168 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1169
1170 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1171 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1172 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1173 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1174 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1175 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1176 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1177 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1178
1179 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1180}
1181
1182static void process_custom_mtmx_in_params(const XML_Char **attr)
1183{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301184 int attr_idx = 0, i = 0;
1185 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301186
1187 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1188 ALOGE("%s: 'usecase' not found", __func__);
1189 return;
1190 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301191 /* Check if multi usecases are supported for this custom mtrx params */
1192 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1193 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1194 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1195 value = strtok_r(NULL, ",", &context);
1196 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301197
1198 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1199 ALOGE("%s: 'out_channel_count' not found", __func__);
1200 return;
1201 }
1202 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1203
1204 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1205
1206}
1207
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301208static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1209{
1210 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301211 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301212 char *context = NULL, *ch_coeff_value = NULL;
1213 struct audio_custom_mtmx_params *mtmx_params = NULL;
1214
1215 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1216 ALOGE("%s: 'out_channel_index' not found", __func__);
1217 return;
1218 }
1219 out_ch_idx = atoi((char *)attr[attr_idx++]);
1220
1221 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1222 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1223 return;
1224 }
1225
1226 if (strcmp(attr[attr_idx++], "values") != 0) {
1227 ALOGE("%s: 'values' not found", __func__);
1228 return;
1229 }
1230 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301231 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301232 if (mtmx_params == NULL) {
1233 ALOGE("%s: mtmx params with given param info, not found", __func__);
1234 return;
1235 }
1236 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1237 ip_channels = mtmx_params->info.ip_channels;
1238 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301239 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301240 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1241 = atoi(ch_coeff_value);
1242 ch_coeff_value = strtok_r(NULL, " ", &context);
1243 }
1244 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1245 ch_coeff_value != NULL)
1246 ALOGE("%s: invalid/malformed coefficient values", __func__);
1247}
1248
1249static void process_custom_mtmx_params(const XML_Char **attr)
1250{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301251 int attr_idx = 0, i = 0;
1252 char *context = NULL, *value = NULL;
1253
1254 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301255
1256 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1257 ALOGE("%s: 'param_id' not found", __func__);
1258 return;
1259 }
1260 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1261
1262 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1263 ALOGE("%s: 'in_channel_count' not found", __func__);
1264 return;
1265 }
1266 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1267
1268 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1269 ALOGE("%s: 'out_channel_count' not found", __func__);
1270 return;
1271 }
1272 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1273
1274 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1275 ALOGE("%s: 'usecase' not found", __func__);
1276 return;
1277 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301278
1279 /* check if multi usecases are supported for this custom mtrx params */
1280 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1281 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1282 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1283 value = strtok_r(NULL, ",", &context);
1284 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301285
1286 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1287 ALOGE("%s: 'snd_device' not found", __func__);
1288 return;
1289 }
1290 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301291
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301292 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1293 i = 0;
1294 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1295 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1296 mtmx_params_info.fe_id[i++] = atoi(value);
1297 value = strtok_r(NULL, ",", &context);
1298 }
1299
1300 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301301 }
1302
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301303 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1304
1305}
1306
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001307static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001308 const XML_Char **attr)
1309{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001310 if (my_data.caller == ACDB_EXTN) {
1311 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1312 section = ACDB_METAINFO_KEY;
1313 } else if (strcmp(tag_name, "param") == 0) {
1314 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1315 ALOGE("param tag only supported with CONFIG_PARAMS section");
1316 return;
1317 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001318
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001319 section_process_fn fn = section_table[section];
1320 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001321 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001322 } else if(my_data.caller == PLATFORM) {
1323 if (strcmp(tag_name, "bit_width_configs") == 0) {
1324 section = BITWIDTH;
1325 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1326 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001327 } else if (strcmp(tag_name, "module_ids") == 0) {
1328 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001329 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1330 section = PCM_ID;
1331 } else if (strcmp(tag_name, "backend_names") == 0) {
1332 section = BACKEND_NAME;
1333 } else if (strcmp(tag_name, "config_params") == 0) {
1334 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001335 } else if (strcmp(tag_name, "operator_specific") == 0) {
1336 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001337 } else if (strcmp(tag_name, "interface_names") == 0) {
1338 section = INTERFACE_NAME;
1339 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1340 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001341 } else if (strcmp(tag_name, "app_types") == 0) {
1342 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001343 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1344 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301345 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1346 section = MICROPHONE_CHARACTERISTIC;
1347 } else if (strcmp(tag_name, "snd_devices") == 0) {
1348 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001349 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001350 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001351 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001352 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001353 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1354 return;
1355 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001356
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001357 /* call into process function for the current section */
1358 section_process_fn fn = section_table[section];
1359 fn(attr);
1360 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1361 if (section != GAIN_LEVEL_MAPPING) {
1362 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1363 return;
1364 }
1365
1366 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1367 fn(attr);
1368 } else if (strcmp(tag_name, "usecase") == 0) {
1369 if (section != PCM_ID) {
1370 ALOGE("usecase tag only supported with PCM_ID section");
1371 return;
1372 }
1373
1374 section_process_fn fn = section_table[PCM_ID];
1375 fn(attr);
1376 } else if (strcmp(tag_name, "param") == 0) {
1377 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1378 ALOGE("param tag only supported with CONFIG_PARAMS section");
1379 return;
1380 }
1381
1382 section_process_fn fn = section_table[section];
1383 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301384 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001385 if (section != MODULE) {
1386 ALOGE("aec tag only supported with MODULE section");
1387 return;
1388 }
1389 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301390 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001391 if (section != MODULE) {
1392 ALOGE("ns tag only supported with MODULE section");
1393 return;
1394 }
1395 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001396 } else if (strcmp(tag_name, "mmsecns") == 0) {
1397 if (section != MODULE) {
1398 ALOGE("mmsecns tag only supported with MODULE section");
1399 return;
1400 }
1401 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001402 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1403 if (section != GAIN_LEVEL_MAPPING) {
1404 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1405 return;
1406 }
1407
1408 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1409 fn(attr);
1410 } else if (!strcmp(tag_name, "app")) {
1411 if (section != APP_TYPE) {
1412 ALOGE("app tag only valid in section APP_TYPE");
1413 return;
1414 }
1415
1416 section_process_fn fn = section_table[APP_TYPE];
1417 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301418 } else if (strcmp(tag_name, "microphone") == 0) {
1419 if (section != MICROPHONE_CHARACTERISTIC) {
1420 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1421 return;
1422 }
1423 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1424 fn(attr);
1425 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1426 if (section != SND_DEVICES) {
1427 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1428 return;
1429 }
1430 section = INPUT_SND_DEVICE;
1431 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1432 if (section != INPUT_SND_DEVICE) {
1433 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1434 return;
1435 }
1436 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1437 } else if (strcmp(tag_name, "snd_dev") == 0) {
1438 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1439 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1440 return;
1441 }
1442 section_process_fn fn = section_table[SND_DEV];
1443 fn(attr);
1444 } else if (strcmp(tag_name, "mic_info") == 0) {
1445 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1446 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1447 return;
1448 }
1449 if (in_snd_device == SND_DEVICE_NONE) {
1450 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1451 return;
1452 }
1453 section_process_fn fn = section_table[MIC_INFO];
1454 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301455 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1456 if (section != ROOT) {
1457 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1458 return;
1459 }
1460 section = CUSTOM_MTMX_PARAMS;
1461 section_process_fn fn = section_table[section];
1462 fn(attr);
1463 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1464 if (section != CUSTOM_MTMX_PARAMS) {
1465 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1466 return;
1467 }
1468 section = CUSTOM_MTMX_PARAM_COEFFS;
1469 section_process_fn fn = section_table[section];
1470 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001471 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1472 section = EXTERNAL_DEVICE_SPECIFIC;
1473 } else if (strcmp(tag_name, "ext_device") == 0) {
1474 section_process_fn fn = section_table[section];
1475 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301476 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1477 if (section != ROOT) {
1478 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1479 return;
1480 }
1481 section = CUSTOM_MTMX_IN_PARAMS;
1482 section_process_fn fn = section_table[section];
1483 fn(attr);
1484 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1485 if (section != CUSTOM_MTMX_IN_PARAMS) {
1486 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1487 return;
1488 }
1489 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Juyu Chen918e1e12019-08-08 15:28:18 -07001490 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1491 section = AUDIO_SOURCE_DELAY;
1492 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301493 section_process_fn fn = section_table[section];
1494 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301495 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001496 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001497 if(strcmp(tag_name, "config_params") == 0) {
1498 section = CONFIG_PARAMS;
1499 } else if (strcmp(tag_name, "param") == 0) {
1500 if (section != CONFIG_PARAMS) {
1501 ALOGE("param tag only supported with CONFIG_PARAMS section");
1502 return;
1503 }
1504
1505 section_process_fn fn = section_table[section];
1506 fn(attr);
1507 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001508 }
Ben Romberger55886882014-01-10 13:49:02 -08001509 return;
1510}
1511
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001512static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001513{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001514 if (strcmp(tag_name, "bit_width_configs") == 0) {
1515 section = ROOT;
1516 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001517 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001518 } else if (strcmp(tag_name, "module_ids") == 0) {
1519 section = ROOT;
1520 } else if (strcmp(tag_name, "aec") == 0) {
1521 section = MODULE;
1522 } else if (strcmp(tag_name, "ns") == 0) {
1523 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001524 } else if (strcmp(tag_name, "mmsecns") == 0) {
1525 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001526 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1527 section = ROOT;
1528 } else if (strcmp(tag_name, "backend_names") == 0) {
1529 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001530 } else if (strcmp(tag_name, "config_params") == 0) {
1531 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001532 } else if (strcmp(tag_name, "operator_specific") == 0) {
1533 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001534 } else if (strcmp(tag_name, "interface_names") == 0) {
1535 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001536 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1537 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001538 } else if (strcmp(tag_name, "app_types") == 0) {
1539 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301540 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1541 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301542 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1543 section = ROOT;
1544 } else if (strcmp(tag_name, "snd_devices") == 0) {
1545 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001546 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1547 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301548 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1549 section = SND_DEVICES;
1550 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1551 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301552 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1553 section = ROOT;
1554 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1555 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301556 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1557 section = ROOT;
1558 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1559 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001560 }
Ben Romberger55886882014-01-10 13:49:02 -08001561}
1562
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001563int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001564{
1565 XML_Parser parser;
1566 FILE *file;
1567 int ret = 0;
1568 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001569 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001570 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301571 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001572
Saurav Kumardba3caf2020-05-29 20:53:55 +05301573 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1574 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001575 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001576 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301577 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001578 MIXER_PATH_MAX_LENGTH);
1579 else
1580 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1581
1582 ALOGV("%s: platform info file name is %s", __func__,
1583 platform_info_file_name);
1584
1585 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001586 section = ROOT;
1587
Ben Romberger55886882014-01-10 13:49:02 -08001588 if (!file) {
1589 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001590 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001591 ret = -ENODEV;
1592 goto done;
1593 }
1594
1595 parser = XML_ParserCreate(NULL);
1596 if (!parser) {
1597 ALOGE("%s: Failed to create XML parser!", __func__);
1598 ret = -ENODEV;
1599 goto err_close_file;
1600 }
1601
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001602 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001603 my_data.platform = platform;
1604 my_data.kvpairs = str_parms_create();
1605
Ben Romberger55886882014-01-10 13:49:02 -08001606 XML_SetElementHandler(parser, start_tag, end_tag);
1607
1608 while (1) {
1609 buf = XML_GetBuffer(parser, BUF_SIZE);
1610 if (buf == NULL) {
1611 ALOGE("%s: XML_GetBuffer failed", __func__);
1612 ret = -ENOMEM;
1613 goto err_free_parser;
1614 }
1615
1616 bytes_read = fread(buf, 1, BUF_SIZE, file);
1617 if (bytes_read < 0) {
1618 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1619 ret = bytes_read;
1620 goto err_free_parser;
1621 }
1622
1623 if (XML_ParseBuffer(parser, bytes_read,
1624 bytes_read == 0) == XML_STATUS_ERROR) {
1625 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001626 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001627 ret = -EINVAL;
1628 goto err_free_parser;
1629 }
1630
1631 if (bytes_read == 0)
1632 break;
1633 }
1634
Ben Romberger55886882014-01-10 13:49:02 -08001635err_free_parser:
1636 XML_ParserFree(parser);
1637err_close_file:
1638 fclose(file);
1639done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001640 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001641 return ret;
1642}