blob: 9cfd7600e7ff816a48da30274b94f13bf09534e2 [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>
LuK1337b1403752021-05-28 08:01:40 +020044#include <pthread.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070045#include <math.h>
Fei Tongc20ce932021-06-21 16:42:38 +080046#ifdef LINUX_ENABLED
47#include <float.h>
48#endif
Ben Romberger55886882014-01-10 13:49:02 -080049
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053050#ifdef DYNAMIC_LOG_ENABLED
51#include <log_xml_parser.h>
52#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
53#include <log_utils.h>
54#endif
55
Ben Romberger55886882014-01-10 13:49:02 -080056#define BUF_SIZE 1024
Saurav Kumardba3caf2020-05-29 20:53:55 +053057char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH];
58char platform_info_xml_path_file[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -080059
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070060typedef enum {
61 ROOT,
62 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070063 MODULE,
64 AEC,
65 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070066 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070067 PCM_ID,
68 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080069 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070070 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080071 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070072 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080073 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053074 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053075 MICROPHONE_CHARACTERISTIC,
76 SND_DEVICES,
77 INPUT_SND_DEVICE,
78 INPUT_SND_DEVICE_TO_MIC_MAPPING,
79 SND_DEV,
80 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053081 CUSTOM_MTMX_PARAMS,
82 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070083 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053084 CUSTOM_MTMX_IN_PARAMS,
85 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +080086 MMSECNS,
Juyu Chen918e1e12019-08-08 15:28:18 -070087 AUDIO_SOURCE_DELAY,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070088} section_t;
89
90typedef void (* section_process_fn)(const XML_Char **attr);
91
Saurav Kumardba3caf2020-05-29 20:53:55 +053092const char* get_platform_xml_path()
93{
94 audio_get_vendor_config_path(vendor_config_path, sizeof(vendor_config_path));
95 /* Get path for platorm_info_xml_path_name in vendor */
96 snprintf(platform_info_xml_path_file, sizeof(platform_info_xml_path_file),
97 "%s/%s", vendor_config_path, PLATFORM_INFO_XML_PATH_NAME);
98 return platform_info_xml_path_file;
99}
100
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700101static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700102static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
103static void process_effect_aec(const XML_Char **attr);
104static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -0700105static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700106static void process_pcm_id(const XML_Char **attr);
107static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800108static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700109static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700110static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800111static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700112static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -0800113static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530114static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530115static void process_microphone_characteristic(const XML_Char **attr);
116static void process_snd_dev(const XML_Char **attr);
117static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530118static void process_custom_mtmx_params(const XML_Char **attr);
119static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700120static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530121static void process_custom_mtmx_in_params(const XML_Char **attr);
122static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Guodong Hu1d46f342019-06-28 16:57:30 +0800123static void process_fluence_mmsecns(const XML_Char **attr);
Juyu Chen918e1e12019-08-08 15:28:18 -0700124static void process_audio_source_delay(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700125
126static section_process_fn section_table[] = {
127 [ROOT] = process_root,
128 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700129 [AEC] = process_effect_aec,
130 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700131 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700132 [PCM_ID] = process_pcm_id,
133 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800134 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700135 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800136 [OPERATOR_SPECIFIC] = process_operator_specific,
137 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700138 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530139 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530140 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
141 [SND_DEV] = process_snd_dev,
142 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530143 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
144 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700145 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530146 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
147 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800148 [MMSECNS] = process_fluence_mmsecns,
Juyu Chen918e1e12019-08-08 15:28:18 -0700149 [AUDIO_SOURCE_DELAY] = process_audio_source_delay,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700150};
151
152static section_t section;
153
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700154struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700155 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700156 void *platform;
157 struct str_parms *kvpairs;
158};
159
160static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800161static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700162
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530163
164struct audio_string_to_enum {
165 const char* name;
166 unsigned int value;
167};
168
169static snd_device_t in_snd_device;
170
171static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
176};
177
178static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
185};
186
187static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
191};
192
193static const struct audio_string_to_enum device_in_types[] = {
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
199 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
200 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
201 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
202 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
203 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
204 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
205 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
206 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
207 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
208 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
209 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
210 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
211 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
212 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
213 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
214 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
215 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
216 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
217 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
218 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
219 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
220 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
221};
222
223enum {
224 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
225 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
226 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
227 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
228 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
229 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
230 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
231 | ORIENTATION) | GEOMETRIC_LOCATION) */
232};
233
234static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
235 int32_t len, unsigned int *value)
236{
237 if (table == NULL) {
238 ALOGE("%s: table is NULL", __func__);
239 return false;
240 }
241
242 if (name == NULL) {
243 ALOGE("null key");
244 return false;
245 }
246
247 for (int i = 0; i < len; i++) {
248 if (!strcmp(table[i].name, name)) {
249 *value = table[i].value;
250 return true;
251 }
252 }
253 return false;
254}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530255
256static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530257static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530258
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700259/*
260 * <audio_platform_info>
261 * <acdb_ids>
262 * <device name="???" acdb_id="???"/>
263 * ...
264 * ...
265 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700266 * <module_ids>
267 * <device name="???" module_id="???"/>
268 * ...
269 * ...
270 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700271 * <backend_names>
272 * <device name="???" backend="???"/>
273 * ...
274 * ...
275 * </backend_names>
276 * <pcm_ids>
277 * <usecase name="???" type="in/out" id="???"/>
278 * ...
279 * ...
280 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800281 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530282 * <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 -0800283 * ...
284 * ...
285 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700286 * <config_params>
287 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800288 * <param key="operator_info" value="tmus;aa;bb;cc"/>
289 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700290 * ...
291 * ...
292 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800293 *
294 * <operator_specific>
295 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
296 * ...
297 * ...
298 * </operator_specific>
299 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700300 * </audio_platform_info>
301 */
302
303static void process_root(const XML_Char **attr __unused)
304{
305}
306
307/* mapping from usecase to pcm dev id */
308static void process_pcm_id(const XML_Char **attr)
309{
310 int index;
311
312 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700313 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700314 goto done;
315 }
316
317 index = platform_get_usecase_index((char *)attr[1]);
318 if (index < 0) {
319 ALOGE("%s: usecase %s not found!",
320 __func__, attr[1]);
321 goto done;
322 }
323
324 if (strcmp(attr[2], "type") != 0) {
325 ALOGE("%s: usecase type not mentioned", __func__);
326 goto done;
327 }
328
329 int type = -1;
330
331 if (!strcasecmp((char *)attr[3], "in")) {
332 type = 1;
333 } else if (!strcasecmp((char *)attr[3], "out")) {
334 type = 0;
335 } else {
336 ALOGE("%s: type must be IN or OUT", __func__);
337 goto done;
338 }
339
340 if (strcmp(attr[4], "id") != 0) {
341 ALOGE("%s: usecase id not mentioned", __func__);
342 goto done;
343 }
344
345 int id = atoi((char *)attr[5]);
346
347 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
348 ALOGE("%s: usecase %s type %d id %d was not set!",
349 __func__, attr[1], type, id);
350 goto done;
351 }
352
353done:
354 return;
355}
356
357/* backend to be used for a device */
358static void process_backend_name(const XML_Char **attr)
359{
360 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530361 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530362 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700363
364 if (strcmp(attr[0], "name") != 0) {
365 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
366 goto done;
367 }
368
369 index = platform_get_snd_device_index((char *)attr[1]);
370 if (index < 0) {
371 ALOGE("%s: Device %s not found, no ACDB ID set!",
372 __func__, attr[1]);
373 goto done;
374 }
375
376 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530377 if (strcmp(attr[2], "interface") == 0)
378 hw_interface = (char *)attr[3];
379 } else {
380 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700381 }
382
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530383 if (attr[4] != NULL) {
384 if (strcmp(attr[4], "interface") != 0) {
385 hw_interface = NULL;
386 } else {
387 hw_interface = (char *)attr[5];
388 }
389 }
390
Ashish Jaind150d4c2017-02-03 18:44:34 +0530391 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700392 ALOGE("%s: Device %s backend %s was not set!",
393 __func__, attr[1], attr[3]);
394 goto done;
395 }
396
397done:
398 return;
399}
400
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700401static void process_gain_db_to_level_map(const XML_Char **attr)
402{
403 struct amp_db_and_gain_table tbl_entry;
404
405 if ((strcmp(attr[0], "db") != 0) ||
406 (strcmp(attr[2], "level") != 0)) {
407 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
408 __func__, attr[0], attr[2]);
409 goto done;
410 }
411
412 tbl_entry.db = atof(attr[1]);
413 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
414 tbl_entry.level = atoi(attr[3]);
415
Aalique Grahame22e49102018-12-18 14:23:57 -0800416 //custome level should be > 0. Level 0 is fixed for default
417 CHECK(tbl_entry.level > 0);
418
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700419 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
420 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
421 platform_add_gain_level_mapping(&tbl_entry);
422
423done:
424 return;
425}
426
427
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700428static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800429{
Ben Romberger61764e32014-01-10 13:49:02 -0800430 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800431
Ben Romberger61764e32014-01-10 13:49:02 -0800432 if (strcmp(attr[0], "name") != 0) {
433 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800434 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800435 }
Ben Romberger55886882014-01-10 13:49:02 -0800436
Ben Romberger61764e32014-01-10 13:49:02 -0800437 index = platform_get_snd_device_index((char *)attr[1]);
438 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800439 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
440 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800441 goto done;
442 }
443
444 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800445 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
446 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800447 goto done;
448 }
449
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700450 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
451 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800452 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800453 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800454 }
Ben Romberger55886882014-01-10 13:49:02 -0800455
Ben Romberger55886882014-01-10 13:49:02 -0800456done:
457 return;
458}
459
Aalique Grahame22e49102018-12-18 14:23:57 -0800460static void process_operator_specific(const XML_Char **attr)
461{
462 snd_device_t snd_device = SND_DEVICE_NONE;
463
464 if (strcmp(attr[0], "name") != 0) {
465 ALOGE("%s: 'name' not found", __func__);
466 goto done;
467 }
468
469 snd_device = platform_get_snd_device_index((char *)attr[1]);
470 if (snd_device < 0) {
471 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530472 __func__, (char *)attr[3], get_platform_xml_path());
Aalique Grahame22e49102018-12-18 14:23:57 -0800473 goto done;
474 }
475
476 if (strcmp(attr[2], "operator") != 0) {
477 ALOGE("%s: 'operator' not found", __func__);
478 goto done;
479 }
480
481 if (strcmp(attr[4], "mixer_path") != 0) {
482 ALOGE("%s: 'mixer_path' not found", __func__);
483 goto done;
484 }
485
486 if (strcmp(attr[6], "acdb_id") != 0) {
487 ALOGE("%s: 'acdb_id' not found", __func__);
488 goto done;
489 }
490
491 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
492
493done:
494 return;
495}
496
Carter Hsu32a62362018-10-15 15:01:42 -0700497static void process_external_dev(const XML_Char **attr)
498{
499 snd_device_t snd_device = SND_DEVICE_NONE;
500
501 if (strcmp(attr[0], "name") != 0) {
502 ALOGE("%s: 'name' not found", __func__);
503 goto done;
504 }
505
506 snd_device = platform_get_snd_device_index((char *)attr[1]);
507 if (snd_device < 0) {
508 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530509 __func__, (char *)attr[3], get_platform_xml_path());
Carter Hsu32a62362018-10-15 15:01:42 -0700510 goto done;
511 }
512
513 if (strcmp(attr[2], "usbid") != 0) {
514 ALOGE("%s: 'usbid' not found", __func__);
515 goto done;
516 }
517
518 if (strcmp(attr[4], "acdb_id") != 0) {
519 ALOGE("%s: 'acdb_id' not found", __func__);
520 goto done;
521 }
522
523 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
524
525done:
526 return;
527}
528
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700529static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
530{
531 int index;
532 struct audio_effect_config effect_config;
533
534 if (strcmp(attr[0], "name") != 0) {
535 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
536 goto done;
537 }
538
539 index = platform_get_snd_device_index((char *)attr[1]);
540 if (index < 0) {
541 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
542 __func__, attr[1]);
543 goto done;
544 }
545
546 if (strcmp(attr[2], "module_id") != 0) {
547 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
548 __func__, attr[2]);
549 goto done;
550 }
551
552 if (strcmp(attr[4], "instance_id") != 0) {
553 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
554 __func__, attr[4]);
555 goto done;
556 }
557
558 if (strcmp(attr[6], "param_id") != 0) {
559 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
560 __func__, attr[6]);
561 goto done;
562 }
563
564 if (strcmp(attr[8], "param_value") != 0) {
565 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
566 __func__, attr[8]);
567 goto done;
568 }
569
570 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
571 strtol((char *)attr[5], NULL, 0),
572 strtol((char *)attr[7], NULL, 0),
573 strtol((char *)attr[9], NULL, 0)};
574
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700575 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
576 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
577 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
578 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
579 strtol((char *)attr[9], NULL, 0));
580 goto done;
581 }
582
583done:
584 return;
585}
586
587static void process_effect_aec(const XML_Char **attr)
588{
589 process_audio_effect(attr, EFFECT_AEC);
590 return;
591}
592
593static void process_effect_ns(const XML_Char **attr)
594{
595 process_audio_effect(attr, EFFECT_NS);
596 return;
597}
598
Guodong Hu1d46f342019-06-28 16:57:30 +0800599static void process_fluence_mmsecns(const XML_Char **attr)
600{
601 int index;
602 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
603
604 if (strcmp(attr[0], "name") != 0) {
605 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
606 goto done;
607 }
608
609 index = platform_get_snd_device_index((char *)attr[1]);
610 if (index < 0) {
611 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
612 __func__, attr[1]);
613 goto done;
614 }
615
616 if (strcmp(attr[2], "topology_id") != 0) {
617 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
618 __func__, attr[2]);
619 goto done;
620 }
621
622 if (strcmp(attr[4], "module_id") != 0) {
623 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
624 __func__, attr[4]);
625 goto done;
626 }
627
628 if (strcmp(attr[6], "instance_id") != 0) {
629 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
630 __func__, attr[6]);
631 goto done;
632 }
633
634 if (strcmp(attr[8], "param_id") != 0) {
635 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
636 __func__, attr[8]);
637 goto done;
638 }
639
640 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
641 strtol((char *)attr[5], NULL, 0),
642 strtol((char *)attr[7], NULL, 0),
643 strtol((char *)attr[9], NULL, 0)};
644
645
646 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
647 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
648 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
649 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
650 goto done;
651 }
652
653done:
654 return;
655}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700656static void process_bit_width(const XML_Char **attr)
657{
658 int index;
659
660 if (strcmp(attr[0], "name") != 0) {
661 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
662 goto done;
663 }
664
665 index = platform_get_snd_device_index((char *)attr[1]);
666 if (index < 0) {
667 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
668 __func__, attr[1]);
669 goto done;
670 }
671
672 if (strcmp(attr[2], "bit_width") != 0) {
673 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
674 __func__, attr[1]);
675 goto done;
676 }
677
678 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
679 ALOGE("%s: Device %s, ACDB ID %d was not set!",
680 __func__, attr[1], atoi((char *)attr[3]));
681 goto done;
682 }
683
684done:
685 return;
686}
687
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800688static void process_interface_name(const XML_Char **attr)
689{
690 int ret;
691
692 if (strcmp(attr[0], "name") != 0) {
693 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
694
695 goto done;
696 }
697
698 if (strcmp(attr[2], "interface") != 0) {
699 ALOGE("%s: Device %s has no Audio Interface set!",
700 __func__, attr[1]);
701
702 goto done;
703 }
704
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530705 if (strcmp(attr[4], "codec_type") != 0) {
706 ALOGE("%s: Device %s has no codec type set!",
707 __func__, attr[1]);
708
709 goto done;
710 }
711
712 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
713 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800714 if (ret < 0) {
715 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800716 goto done;
717 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800718
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800719done:
720 return;
721}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530722
Juyu Chen918e1e12019-08-08 15:28:18 -0700723static void process_audio_source_delay(const XML_Char **attr)
724{
725 audio_source_t audio_source = -1;
726
727 if (strcmp(attr[0], "name") != 0) {
728 ALOGE("%s: 'name' not found", __func__);
729 goto done;
730 }
George Gao9ba8a142020-07-23 14:30:03 -0700731
Juyu Chen918e1e12019-08-08 15:28:18 -0700732 audio_source = platform_get_audio_source_index((const char *)attr[1]);
733
734 if (audio_source < 0) {
735 ALOGE("%s: audio_source %s is not defined",
736 __func__, (char *)attr[1]);
737 goto done;
738 }
739
740 if (strcmp(attr[2], "delay") != 0) {
741 ALOGE("%s: 'delay' not found", __func__);
742 goto done;
743 }
744
745 platform_set_audio_source_delay(audio_source, atoi((char *)attr[3]));
746
747done:
748 return;
749}
750
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700751static void process_config_params(const XML_Char **attr)
752{
753 if (strcmp(attr[0], "key") != 0) {
754 ALOGE("%s: 'key' not found", __func__);
755 goto done;
756 }
757
758 if (strcmp(attr[2], "value") != 0) {
759 ALOGE("%s: 'value' not found", __func__);
760 goto done;
761 }
762
763 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700764 if (my_data.caller == PLATFORM)
765 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700766done:
767 return;
768}
769
Aalique Grahame22e49102018-12-18 14:23:57 -0800770static void process_app_type(const XML_Char **attr)
771{
772 if (strcmp(attr[0], "uc_type")) {
773 ALOGE("%s: uc_type not found", __func__);
774 goto done;
775 }
776
777 if (strcmp(attr[2], "mode")) {
778 ALOGE("%s: mode not found", __func__);
779 goto done;
780 }
781
782 if (strcmp(attr[4], "bit_width")) {
783 ALOGE("%s: bit_width not found", __func__);
784 goto done;
785 }
786
787 if (strcmp(attr[6], "id")) {
788 ALOGE("%s: id not found", __func__);
789 goto done;
790 }
791
792 if (strcmp(attr[8], "max_rate")) {
793 ALOGE("%s: max rate not found", __func__);
794 goto done;
795 }
796
797 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
798 atoi(attr[9]));
799done:
800 return;
801}
802
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530803static void process_microphone_characteristic(const XML_Char **attr) {
804 struct audio_microphone_characteristic_t microphone;
805 uint32_t curIdx = 0;
Saurav Kumardba3caf2020-05-29 20:53:55 +0530806 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530807
Saurav Kumardba3caf2020-05-29 20:53:55 +0530808 strlcpy(platform_info_xml_path, get_platform_xml_path(),
809 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530810 if (strcmp(attr[curIdx++], "valid_mask")) {
811 ALOGE("%s: valid_mask not found", __func__);
812 goto done;
813 }
814 uint32_t valid_mask = atoi(attr[curIdx++]);
815
816 if (strcmp(attr[curIdx++], "device_id")) {
817 ALOGE("%s: device_id not found", __func__);
818 goto done;
819 }
820 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
821 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
822 goto done;
823 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530824 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530825
826 if (strcmp(attr[curIdx++], "type")) {
827 ALOGE("%s: device not found", __func__);
828 goto done;
829 }
830 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
831 ARRAY_SIZE(device_in_types), &microphone.device)) {
832 ALOGE("%s: type %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530833 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530834 goto done;
835 }
836
837 if (strcmp(attr[curIdx++], "address")) {
838 ALOGE("%s: address not found", __func__);
839 goto done;
840 }
841 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
842 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
843 goto done;
844 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530845 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530846 if (strlen(microphone.address) == 0) {
847 // If the address is empty, populate the address according to device type.
848 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530849 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530850 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530851 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530852 }
853 }
854
855 if (strcmp(attr[curIdx++], "location")) {
856 ALOGE("%s: location not found", __func__);
857 goto done;
858 }
859 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
860 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
861 ALOGE("%s: location %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530862 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530863 goto done;
864 }
865
866 if (strcmp(attr[curIdx++], "group")) {
867 ALOGE("%s: group not found", __func__);
868 goto done;
869 }
870 microphone.group = atoi(attr[curIdx++]);
871
872 if (strcmp(attr[curIdx++], "index_in_the_group")) {
873 ALOGE("%s: index_in_the_group not found", __func__);
874 goto done;
875 }
876 microphone.index_in_the_group = atoi(attr[curIdx++]);
877
878 if (strcmp(attr[curIdx++], "directionality")) {
879 ALOGE("%s: directionality not found", __func__);
880 goto done;
881 }
882 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
883 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
884 ALOGE("%s: directionality %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +0530885 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530886 goto done;
887 }
888
889 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
890 ALOGE("%s: num_frequency_responses not found", __func__);
891 goto done;
892 }
893 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530894 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530895 ALOGE("%s: num_frequency_responses is too large", __func__);
896 goto done;
897 }
898 if (microphone.num_frequency_responses > 0) {
899 if (strcmp(attr[curIdx++], "frequencies")) {
900 ALOGE("%s: frequencies not found", __func__);
901 goto done;
902 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530903 char *context = NULL;
904 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530905 uint32_t num_frequencies = 0;
906 while (token) {
907 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800908 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530909 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530910 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530911 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530912 }
913
914 if (strcmp(attr[curIdx++], "responses")) {
915 ALOGE("%s: responses not found", __func__);
916 goto done;
917 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530918 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530919 uint32_t num_responses = 0;
920 while (token) {
921 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800922 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530923 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530924 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530925 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530926 }
927
928 if (num_frequencies != num_responses
929 || num_frequencies != microphone.num_frequency_responses) {
930 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
931 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
932 goto done;
933 }
934 }
935
936 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
937 if (strcmp(attr[curIdx++], "sensitivity")) {
938 ALOGE("%s: sensitivity not found", __func__);
939 goto done;
940 }
941 microphone.sensitivity = atof(attr[curIdx++]);
942 } else {
943 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
944 }
945
946 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
947 if (strcmp(attr[curIdx++], "max_spl")) {
948 ALOGE("%s: max_spl not found", __func__);
949 goto done;
950 }
951 microphone.max_spl = atof(attr[curIdx++]);
952 } else {
953 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
954 }
955
956 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
957 if (strcmp(attr[curIdx++], "min_spl")) {
958 ALOGE("%s: min_spl not found", __func__);
959 goto done;
960 }
961 microphone.min_spl = atof(attr[curIdx++]);
962 } else {
963 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
964 }
965
966 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
967 if (strcmp(attr[curIdx++], "orientation")) {
968 ALOGE("%s: orientation not found", __func__);
969 goto done;
970 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530971 char *context = NULL;
972 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530973 float orientation[3];
974 uint32_t idx = 0;
975 while (token) {
976 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800977 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530978 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530979 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530980 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530981 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530982 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530983 ALOGE("%s: orientation invalid", __func__);
984 goto done;
985 }
986 microphone.orientation.x = orientation[0];
987 microphone.orientation.y = orientation[1];
988 microphone.orientation.z = orientation[2];
989 } else {
990 microphone.orientation.x = 0.0f;
991 microphone.orientation.y = 0.0f;
992 microphone.orientation.z = 0.0f;
993 }
994
995 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
996 if (strcmp(attr[curIdx++], "geometric_location")) {
997 ALOGE("%s: geometric_location not found", __func__);
998 goto done;
999 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301000 char *context = NULL;
1001 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301002 float geometric_location[3];
1003 uint32_t idx = 0;
1004 while (token) {
1005 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +08001006 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301007 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301008 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301009 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301010 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +05301011 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301012 ALOGE("%s: geometric_location invalid", __func__);
1013 goto done;
1014 }
1015 microphone.geometric_location.x = geometric_location[0];
1016 microphone.geometric_location.y = geometric_location[1];
1017 microphone.geometric_location.z = geometric_location[2];
1018 } else {
1019 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1020 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1021 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1022 }
1023
1024 platform_set_microphone_characteristic(my_data.platform, microphone);
1025done:
1026 return;
1027}
1028
1029static void process_snd_dev(const XML_Char **attr)
1030{
1031 uint32_t curIdx = 0;
1032 in_snd_device = SND_DEVICE_NONE;
1033
1034 if (strcmp(attr[curIdx++], "in_snd_device")) {
1035 ALOGE("%s: snd_device not found", __func__);
1036 return;
1037 }
1038 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1039 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1040 in_snd_device >= SND_DEVICE_IN_END) {
1041 ALOGE("%s: Sound device not valid", __func__);
1042 in_snd_device = SND_DEVICE_NONE;
1043 }
1044
1045 return;
1046}
1047
1048static void process_mic_info(const XML_Char **attr)
1049{
1050 uint32_t curIdx = 0;
1051 struct mic_info microphone;
Saurav Kumardba3caf2020-05-29 20:53:55 +05301052 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301053
Saurav Kumardba3caf2020-05-29 20:53:55 +05301054 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1055 sizeof(platform_info_xml_path));
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301056 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1057 sizeof(microphone.channel_mapping));
1058
1059 if (strcmp(attr[curIdx++], "mic_device_id")) {
1060 ALOGE("%s: mic_device_id not found", __func__);
1061 goto on_error;
1062 }
1063 strlcpy(microphone.device_id,
1064 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1065
1066 if (strcmp(attr[curIdx++], "channel_mapping")) {
1067 ALOGE("%s: channel_mapping not found", __func__);
1068 goto on_error;
1069 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301070 char *context = NULL;
1071 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301072 uint32_t idx = 0;
1073 while (token) {
1074 if (!find_enum_by_string(mic_channel_mapping, token,
1075 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1076 &microphone.channel_mapping[idx++])) {
1077 ALOGE("%s: channel_mapping %s in %s not found!",
Saurav Kumardba3caf2020-05-29 20:53:55 +05301078 __func__, attr[--curIdx], platform_info_xml_path);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301079 goto on_error;
1080 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301081 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301082 }
1083 microphone.channel_count = idx;
1084
1085 platform_set_microphone_map(my_data.platform, in_snd_device,
1086 &microphone);
1087 return;
1088on_error:
1089 in_snd_device = SND_DEVICE_NONE;
1090 return;
1091}
1092
1093
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301094/* process acdb meta info key value */
1095static void process_acdb_metainfo_key(const XML_Char **attr)
1096{
1097 if (strcmp(attr[0], "name") != 0) {
1098 ALOGE("%s: 'name' not found", __func__);
1099 goto done;
1100 }
1101
1102 if (strcmp(attr[2], "value") != 0) {
1103 ALOGE("%s: 'value' not found", __func__);
1104 goto done;
1105 }
1106
1107 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001108 switch(my_data.caller) {
1109 case ACDB_EXTN:
1110 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1111 ALOGE("%s: key %d was not set!", __func__, key);
1112 goto done;
1113 }
1114 break;
1115 case PLATFORM:
1116 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1117 ALOGE("%s: key %d was not set!", __func__, key);
1118 goto done;
1119 }
1120 break;
1121 default:
1122 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301123 }
1124
1125done:
1126 return;
1127}
1128
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301129static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1130{
1131 uint32_t attr_idx = 0;
1132 int32_t in_ch_idx = -1;
1133 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1134
1135 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1136 &mtmx_in_params_info);
1137 if (mtmx_in_params == NULL) {
1138 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1139 return;
1140 }
1141
1142 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1143 ALOGE("%s: 'in_channel_index' not found", __func__);
1144 return;
1145 }
1146
1147 in_ch_idx = atoi((char *)attr[attr_idx++]);
1148 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1149 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1150 return;
1151 }
1152
1153 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1154 ALOGE("%s: 'channel_count' not found", __func__);
1155 return;
1156 }
1157 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1158
1159 if (strcmp(attr[attr_idx++], "device") != 0) {
1160 ALOGE("%s: 'device' not found", __func__);
1161 return;
1162 }
1163 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1164 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1165
1166 if (strcmp(attr[attr_idx++], "interface") != 0) {
1167 ALOGE("%s: 'interface' not found", __func__);
1168 return;
1169 }
1170 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1171 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1172
1173 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1174 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1175 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1176 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1177 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1178 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1179 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1180 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1181
1182 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1183}
1184
1185static void process_custom_mtmx_in_params(const XML_Char **attr)
1186{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301187 int attr_idx = 0, i = 0;
1188 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301189
1190 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1191 ALOGE("%s: 'usecase' not found", __func__);
1192 return;
1193 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301194 /* Check if multi usecases are supported for this custom mtrx params */
1195 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1196 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1197 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1198 value = strtok_r(NULL, ",", &context);
1199 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301200
1201 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1202 ALOGE("%s: 'out_channel_count' not found", __func__);
1203 return;
1204 }
1205 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1206
1207 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1208
1209}
1210
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301211static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1212{
1213 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301214 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301215 char *context = NULL, *ch_coeff_value = NULL;
1216 struct audio_custom_mtmx_params *mtmx_params = NULL;
1217
1218 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1219 ALOGE("%s: 'out_channel_index' not found", __func__);
1220 return;
1221 }
1222 out_ch_idx = atoi((char *)attr[attr_idx++]);
1223
1224 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1225 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1226 return;
1227 }
1228
1229 if (strcmp(attr[attr_idx++], "values") != 0) {
1230 ALOGE("%s: 'values' not found", __func__);
1231 return;
1232 }
1233 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301234 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301235 if (mtmx_params == NULL) {
1236 ALOGE("%s: mtmx params with given param info, not found", __func__);
1237 return;
1238 }
1239 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1240 ip_channels = mtmx_params->info.ip_channels;
1241 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301242 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301243 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1244 = atoi(ch_coeff_value);
1245 ch_coeff_value = strtok_r(NULL, " ", &context);
1246 }
1247 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1248 ch_coeff_value != NULL)
1249 ALOGE("%s: invalid/malformed coefficient values", __func__);
1250}
1251
1252static void process_custom_mtmx_params(const XML_Char **attr)
1253{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301254 int attr_idx = 0, i = 0;
1255 char *context = NULL, *value = NULL;
1256
1257 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301258
1259 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1260 ALOGE("%s: 'param_id' not found", __func__);
1261 return;
1262 }
1263 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1264
1265 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1266 ALOGE("%s: 'in_channel_count' not found", __func__);
1267 return;
1268 }
1269 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1270
1271 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1272 ALOGE("%s: 'out_channel_count' not found", __func__);
1273 return;
1274 }
1275 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1276
1277 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1278 ALOGE("%s: 'usecase' not found", __func__);
1279 return;
1280 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301281
1282 /* check if multi usecases are supported for this custom mtrx params */
1283 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1284 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1285 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1286 value = strtok_r(NULL, ",", &context);
1287 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301288
1289 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1290 ALOGE("%s: 'snd_device' not found", __func__);
1291 return;
1292 }
1293 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301294
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301295 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1296 i = 0;
1297 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1298 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1299 mtmx_params_info.fe_id[i++] = atoi(value);
1300 value = strtok_r(NULL, ",", &context);
1301 }
1302
1303 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301304 }
1305
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301306 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1307
1308}
1309
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001310static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001311 const XML_Char **attr)
1312{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001313 if (my_data.caller == ACDB_EXTN) {
1314 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1315 section = ACDB_METAINFO_KEY;
1316 } else if (strcmp(tag_name, "param") == 0) {
1317 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1318 ALOGE("param tag only supported with CONFIG_PARAMS section");
1319 return;
1320 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001321
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001322 section_process_fn fn = section_table[section];
1323 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001324 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001325 } else if(my_data.caller == PLATFORM) {
1326 if (strcmp(tag_name, "bit_width_configs") == 0) {
1327 section = BITWIDTH;
1328 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1329 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001330 } else if (strcmp(tag_name, "module_ids") == 0) {
1331 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001332 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1333 section = PCM_ID;
1334 } else if (strcmp(tag_name, "backend_names") == 0) {
1335 section = BACKEND_NAME;
1336 } else if (strcmp(tag_name, "config_params") == 0) {
1337 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001338 } else if (strcmp(tag_name, "operator_specific") == 0) {
1339 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001340 } else if (strcmp(tag_name, "interface_names") == 0) {
1341 section = INTERFACE_NAME;
1342 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1343 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001344 } else if (strcmp(tag_name, "app_types") == 0) {
1345 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001346 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1347 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301348 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1349 section = MICROPHONE_CHARACTERISTIC;
1350 } else if (strcmp(tag_name, "snd_devices") == 0) {
1351 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001352 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001353 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001354 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001355 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001356 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1357 return;
1358 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001359
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001360 /* call into process function for the current section */
1361 section_process_fn fn = section_table[section];
1362 fn(attr);
1363 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1364 if (section != GAIN_LEVEL_MAPPING) {
1365 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1366 return;
1367 }
1368
1369 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1370 fn(attr);
1371 } else if (strcmp(tag_name, "usecase") == 0) {
1372 if (section != PCM_ID) {
1373 ALOGE("usecase tag only supported with PCM_ID section");
1374 return;
1375 }
1376
1377 section_process_fn fn = section_table[PCM_ID];
1378 fn(attr);
1379 } else if (strcmp(tag_name, "param") == 0) {
1380 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1381 ALOGE("param tag only supported with CONFIG_PARAMS section");
1382 return;
1383 }
1384
1385 section_process_fn fn = section_table[section];
1386 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301387 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001388 if (section != MODULE) {
1389 ALOGE("aec tag only supported with MODULE section");
1390 return;
1391 }
1392 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301393 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001394 if (section != MODULE) {
1395 ALOGE("ns tag only supported with MODULE section");
1396 return;
1397 }
1398 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001399 } else if (strcmp(tag_name, "mmsecns") == 0) {
1400 if (section != MODULE) {
1401 ALOGE("mmsecns tag only supported with MODULE section");
1402 return;
1403 }
1404 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001405 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1406 if (section != GAIN_LEVEL_MAPPING) {
1407 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1408 return;
1409 }
1410
1411 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1412 fn(attr);
1413 } else if (!strcmp(tag_name, "app")) {
1414 if (section != APP_TYPE) {
1415 ALOGE("app tag only valid in section APP_TYPE");
1416 return;
1417 }
1418
1419 section_process_fn fn = section_table[APP_TYPE];
1420 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301421 } else if (strcmp(tag_name, "microphone") == 0) {
1422 if (section != MICROPHONE_CHARACTERISTIC) {
1423 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1424 return;
1425 }
1426 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1427 fn(attr);
1428 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1429 if (section != SND_DEVICES) {
1430 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1431 return;
1432 }
1433 section = INPUT_SND_DEVICE;
1434 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1435 if (section != INPUT_SND_DEVICE) {
1436 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1437 return;
1438 }
1439 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1440 } else if (strcmp(tag_name, "snd_dev") == 0) {
1441 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1442 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1443 return;
1444 }
1445 section_process_fn fn = section_table[SND_DEV];
1446 fn(attr);
1447 } else if (strcmp(tag_name, "mic_info") == 0) {
1448 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1449 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1450 return;
1451 }
1452 if (in_snd_device == SND_DEVICE_NONE) {
1453 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1454 return;
1455 }
1456 section_process_fn fn = section_table[MIC_INFO];
1457 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301458 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1459 if (section != ROOT) {
1460 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1461 return;
1462 }
1463 section = CUSTOM_MTMX_PARAMS;
1464 section_process_fn fn = section_table[section];
1465 fn(attr);
1466 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1467 if (section != CUSTOM_MTMX_PARAMS) {
1468 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1469 return;
1470 }
1471 section = CUSTOM_MTMX_PARAM_COEFFS;
1472 section_process_fn fn = section_table[section];
1473 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001474 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1475 section = EXTERNAL_DEVICE_SPECIFIC;
1476 } else if (strcmp(tag_name, "ext_device") == 0) {
1477 section_process_fn fn = section_table[section];
1478 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301479 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1480 if (section != ROOT) {
1481 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1482 return;
1483 }
1484 section = CUSTOM_MTMX_IN_PARAMS;
1485 section_process_fn fn = section_table[section];
1486 fn(attr);
1487 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1488 if (section != CUSTOM_MTMX_IN_PARAMS) {
1489 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1490 return;
1491 }
1492 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Juyu Chen918e1e12019-08-08 15:28:18 -07001493 } else if (strcmp(tag_name, "audio_input_source_delay") == 0) {
1494 section = AUDIO_SOURCE_DELAY;
1495 } else if (strcmp(tag_name, "audio_source_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301496 section_process_fn fn = section_table[section];
1497 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301498 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001499 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001500 if(strcmp(tag_name, "config_params") == 0) {
1501 section = CONFIG_PARAMS;
1502 } else if (strcmp(tag_name, "param") == 0) {
1503 if (section != CONFIG_PARAMS) {
1504 ALOGE("param tag only supported with CONFIG_PARAMS section");
1505 return;
1506 }
1507
1508 section_process_fn fn = section_table[section];
1509 fn(attr);
1510 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001511 }
Ben Romberger55886882014-01-10 13:49:02 -08001512 return;
1513}
1514
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001515static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001516{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001517 if (strcmp(tag_name, "bit_width_configs") == 0) {
1518 section = ROOT;
1519 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001520 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001521 } else if (strcmp(tag_name, "module_ids") == 0) {
1522 section = ROOT;
1523 } else if (strcmp(tag_name, "aec") == 0) {
1524 section = MODULE;
1525 } else if (strcmp(tag_name, "ns") == 0) {
1526 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001527 } else if (strcmp(tag_name, "mmsecns") == 0) {
1528 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001529 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1530 section = ROOT;
1531 } else if (strcmp(tag_name, "backend_names") == 0) {
1532 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001533 } else if (strcmp(tag_name, "config_params") == 0) {
1534 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001535 } else if (strcmp(tag_name, "operator_specific") == 0) {
1536 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001537 } else if (strcmp(tag_name, "interface_names") == 0) {
1538 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001539 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1540 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001541 } else if (strcmp(tag_name, "app_types") == 0) {
1542 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301543 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1544 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301545 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1546 section = ROOT;
1547 } else if (strcmp(tag_name, "snd_devices") == 0) {
1548 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001549 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1550 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301551 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1552 section = SND_DEVICES;
1553 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1554 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301555 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1556 section = ROOT;
1557 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1558 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301559 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1560 section = ROOT;
1561 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1562 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001563 }
Ben Romberger55886882014-01-10 13:49:02 -08001564}
1565
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001566int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001567{
1568 XML_Parser parser;
1569 FILE *file;
1570 int ret = 0;
1571 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001572 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001573 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Saurav Kumardba3caf2020-05-29 20:53:55 +05301574 char platform_info_xml_path[VENDOR_CONFIG_FILE_MAX_LENGTH];
Ben Romberger55886882014-01-10 13:49:02 -08001575
Saurav Kumardba3caf2020-05-29 20:53:55 +05301576 strlcpy(platform_info_xml_path, get_platform_xml_path(),
1577 sizeof(platform_info_xml_path));
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001578 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001579 if (filename == NULL)
Saurav Kumardba3caf2020-05-29 20:53:55 +05301580 strlcpy(platform_info_file_name, platform_info_xml_path,
Aalique Grahame22e49102018-12-18 14:23:57 -08001581 MIXER_PATH_MAX_LENGTH);
1582 else
1583 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1584
1585 ALOGV("%s: platform info file name is %s", __func__,
1586 platform_info_file_name);
1587
1588 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001589 section = ROOT;
1590
Ben Romberger55886882014-01-10 13:49:02 -08001591 if (!file) {
1592 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001593 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001594 ret = -ENODEV;
1595 goto done;
1596 }
1597
1598 parser = XML_ParserCreate(NULL);
1599 if (!parser) {
1600 ALOGE("%s: Failed to create XML parser!", __func__);
1601 ret = -ENODEV;
1602 goto err_close_file;
1603 }
1604
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001605 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001606 my_data.platform = platform;
1607 my_data.kvpairs = str_parms_create();
1608
Ben Romberger55886882014-01-10 13:49:02 -08001609 XML_SetElementHandler(parser, start_tag, end_tag);
1610
1611 while (1) {
1612 buf = XML_GetBuffer(parser, BUF_SIZE);
1613 if (buf == NULL) {
1614 ALOGE("%s: XML_GetBuffer failed", __func__);
1615 ret = -ENOMEM;
1616 goto err_free_parser;
1617 }
1618
1619 bytes_read = fread(buf, 1, BUF_SIZE, file);
1620 if (bytes_read < 0) {
1621 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1622 ret = bytes_read;
1623 goto err_free_parser;
1624 }
1625
1626 if (XML_ParseBuffer(parser, bytes_read,
1627 bytes_read == 0) == XML_STATUS_ERROR) {
1628 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001629 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001630 ret = -EINVAL;
1631 goto err_free_parser;
1632 }
1633
1634 if (bytes_read == 0)
1635 break;
1636 }
1637
Ben Romberger55886882014-01-10 13:49:02 -08001638err_free_parser:
1639 XML_ParserFree(parser);
1640err_close_file:
1641 fclose(file);
1642done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001643 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001644 return ret;
1645}