blob: 5e25533f9aff36d075de8b0211d0c87bdc5689d8 [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Aalique Grahame22e49102018-12-18 14:23:57 -08002 * Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
Ben Romberger55886882014-01-10 13:49:02 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Ben Romberger61764e32014-01-10 13:49:02 -080030#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080031#define LOG_NDDEBUG 0
32
33#include <errno.h>
34#include <stdio.h>
35#include <expat.h>
Jiangen Jiao334224b2019-09-12 15:47:46 +080036#include <pthread.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080037#include <log/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070038#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080039#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070040#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080041#include "platform_api.h"
42#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070043#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080044
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053045#ifdef DYNAMIC_LOG_ENABLED
46#include <log_xml_parser.h>
47#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
48#include <log_utils.h>
49#endif
50
Ben Romberger55886882014-01-10 13:49:02 -080051#define BUF_SIZE 1024
52
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070053typedef enum {
54 ROOT,
55 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070056 MODULE,
57 AEC,
58 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070059 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070060 PCM_ID,
61 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080062 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070063 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080064 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070065 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080066 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053067 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053068 MICROPHONE_CHARACTERISTIC,
69 SND_DEVICES,
70 INPUT_SND_DEVICE,
71 INPUT_SND_DEVICE_TO_MIC_MAPPING,
72 SND_DEV,
73 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053074 CUSTOM_MTMX_PARAMS,
75 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070076 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053077 CUSTOM_MTMX_IN_PARAMS,
78 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +080079 MMSECNS,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070080} section_t;
81
82typedef void (* section_process_fn)(const XML_Char **attr);
83
84static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070085static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
86static void process_effect_aec(const XML_Char **attr);
87static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070088static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070089static void process_pcm_id(const XML_Char **attr);
90static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080091static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070092static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070093static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080094static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070095static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080096static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053097static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053098static void process_microphone_characteristic(const XML_Char **attr);
99static void process_snd_dev(const XML_Char **attr);
100static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530101static void process_custom_mtmx_params(const XML_Char **attr);
102static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700103static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530104static void process_custom_mtmx_in_params(const XML_Char **attr);
105static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Guodong Hu1d46f342019-06-28 16:57:30 +0800106static void process_fluence_mmsecns(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700107
108static section_process_fn section_table[] = {
109 [ROOT] = process_root,
110 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700111 [AEC] = process_effect_aec,
112 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700113 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700114 [PCM_ID] = process_pcm_id,
115 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800116 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700117 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800118 [OPERATOR_SPECIFIC] = process_operator_specific,
119 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700120 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530121 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530122 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
123 [SND_DEV] = process_snd_dev,
124 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530125 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
126 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700127 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530128 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
129 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800130 [MMSECNS] = process_fluence_mmsecns,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700131};
132
133static section_t section;
134
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700135struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700136 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700137 void *platform;
138 struct str_parms *kvpairs;
139};
140
141static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800142static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700143
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530144
145struct audio_string_to_enum {
146 const char* name;
147 unsigned int value;
148};
149
150static snd_device_t in_snd_device;
151
152static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
153 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
154 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
155 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
157};
158
159static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
163 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
166};
167
168static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
172};
173
174static const struct audio_string_to_enum device_in_types[] = {
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
199 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
200 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
201 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
202};
203
204enum {
205 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
206 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
207 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
208 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
209 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
210 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
211 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
212 | ORIENTATION) | GEOMETRIC_LOCATION) */
213};
214
215static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
216 int32_t len, unsigned int *value)
217{
218 if (table == NULL) {
219 ALOGE("%s: table is NULL", __func__);
220 return false;
221 }
222
223 if (name == NULL) {
224 ALOGE("null key");
225 return false;
226 }
227
228 for (int i = 0; i < len; i++) {
229 if (!strcmp(table[i].name, name)) {
230 *value = table[i].value;
231 return true;
232 }
233 }
234 return false;
235}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530236
237static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530238static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530239
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700240/*
241 * <audio_platform_info>
242 * <acdb_ids>
243 * <device name="???" acdb_id="???"/>
244 * ...
245 * ...
246 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700247 * <module_ids>
248 * <device name="???" module_id="???"/>
249 * ...
250 * ...
251 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700252 * <backend_names>
253 * <device name="???" backend="???"/>
254 * ...
255 * ...
256 * </backend_names>
257 * <pcm_ids>
258 * <usecase name="???" type="in/out" id="???"/>
259 * ...
260 * ...
261 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800262 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530263 * <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 -0800264 * ...
265 * ...
266 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700267 * <config_params>
268 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800269 * <param key="operator_info" value="tmus;aa;bb;cc"/>
270 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700271 * ...
272 * ...
273 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800274 *
275 * <operator_specific>
276 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
277 * ...
278 * ...
279 * </operator_specific>
280 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700281 * </audio_platform_info>
282 */
283
284static void process_root(const XML_Char **attr __unused)
285{
286}
287
288/* mapping from usecase to pcm dev id */
289static void process_pcm_id(const XML_Char **attr)
290{
291 int index;
292
293 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700294 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700295 goto done;
296 }
297
298 index = platform_get_usecase_index((char *)attr[1]);
299 if (index < 0) {
300 ALOGE("%s: usecase %s not found!",
301 __func__, attr[1]);
302 goto done;
303 }
304
305 if (strcmp(attr[2], "type") != 0) {
306 ALOGE("%s: usecase type not mentioned", __func__);
307 goto done;
308 }
309
310 int type = -1;
311
312 if (!strcasecmp((char *)attr[3], "in")) {
313 type = 1;
314 } else if (!strcasecmp((char *)attr[3], "out")) {
315 type = 0;
316 } else {
317 ALOGE("%s: type must be IN or OUT", __func__);
318 goto done;
319 }
320
321 if (strcmp(attr[4], "id") != 0) {
322 ALOGE("%s: usecase id not mentioned", __func__);
323 goto done;
324 }
325
326 int id = atoi((char *)attr[5]);
327
328 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
329 ALOGE("%s: usecase %s type %d id %d was not set!",
330 __func__, attr[1], type, id);
331 goto done;
332 }
333
334done:
335 return;
336}
337
338/* backend to be used for a device */
339static void process_backend_name(const XML_Char **attr)
340{
341 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530342 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530343 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700344
345 if (strcmp(attr[0], "name") != 0) {
346 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
347 goto done;
348 }
349
350 index = platform_get_snd_device_index((char *)attr[1]);
351 if (index < 0) {
352 ALOGE("%s: Device %s not found, no ACDB ID set!",
353 __func__, attr[1]);
354 goto done;
355 }
356
357 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530358 if (strcmp(attr[2], "interface") == 0)
359 hw_interface = (char *)attr[3];
360 } else {
361 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700362 }
363
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530364 if (attr[4] != NULL) {
365 if (strcmp(attr[4], "interface") != 0) {
366 hw_interface = NULL;
367 } else {
368 hw_interface = (char *)attr[5];
369 }
370 }
371
Ashish Jaind150d4c2017-02-03 18:44:34 +0530372 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700373 ALOGE("%s: Device %s backend %s was not set!",
374 __func__, attr[1], attr[3]);
375 goto done;
376 }
377
378done:
379 return;
380}
381
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700382static void process_gain_db_to_level_map(const XML_Char **attr)
383{
384 struct amp_db_and_gain_table tbl_entry;
385
386 if ((strcmp(attr[0], "db") != 0) ||
387 (strcmp(attr[2], "level") != 0)) {
388 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
389 __func__, attr[0], attr[2]);
390 goto done;
391 }
392
393 tbl_entry.db = atof(attr[1]);
394 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
395 tbl_entry.level = atoi(attr[3]);
396
Aalique Grahame22e49102018-12-18 14:23:57 -0800397 //custome level should be > 0. Level 0 is fixed for default
398 CHECK(tbl_entry.level > 0);
399
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700400 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
401 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
402 platform_add_gain_level_mapping(&tbl_entry);
403
404done:
405 return;
406}
407
408
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700409static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800410{
Ben Romberger61764e32014-01-10 13:49:02 -0800411 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800412
Ben Romberger61764e32014-01-10 13:49:02 -0800413 if (strcmp(attr[0], "name") != 0) {
414 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800415 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800416 }
Ben Romberger55886882014-01-10 13:49:02 -0800417
Ben Romberger61764e32014-01-10 13:49:02 -0800418 index = platform_get_snd_device_index((char *)attr[1]);
419 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800420 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
421 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800422 goto done;
423 }
424
425 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800426 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
427 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800428 goto done;
429 }
430
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700431 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
432 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800433 __func__, attr[1], atoi((char *)attr[3]));
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 Romberger55886882014-01-10 13:49:02 -0800437done:
438 return;
439}
440
Aalique Grahame22e49102018-12-18 14:23:57 -0800441static void process_operator_specific(const XML_Char **attr)
442{
443 snd_device_t snd_device = SND_DEVICE_NONE;
444
445 if (strcmp(attr[0], "name") != 0) {
446 ALOGE("%s: 'name' not found", __func__);
447 goto done;
448 }
449
450 snd_device = platform_get_snd_device_index((char *)attr[1]);
451 if (snd_device < 0) {
452 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
453 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
454 goto done;
455 }
456
457 if (strcmp(attr[2], "operator") != 0) {
458 ALOGE("%s: 'operator' not found", __func__);
459 goto done;
460 }
461
462 if (strcmp(attr[4], "mixer_path") != 0) {
463 ALOGE("%s: 'mixer_path' not found", __func__);
464 goto done;
465 }
466
467 if (strcmp(attr[6], "acdb_id") != 0) {
468 ALOGE("%s: 'acdb_id' not found", __func__);
469 goto done;
470 }
471
472 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
473
474done:
475 return;
476}
477
Carter Hsu32a62362018-10-15 15:01:42 -0700478static void process_external_dev(const XML_Char **attr)
479{
480 snd_device_t snd_device = SND_DEVICE_NONE;
481
482 if (strcmp(attr[0], "name") != 0) {
483 ALOGE("%s: 'name' not found", __func__);
484 goto done;
485 }
486
487 snd_device = platform_get_snd_device_index((char *)attr[1]);
488 if (snd_device < 0) {
489 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
490 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
491 goto done;
492 }
493
494 if (strcmp(attr[2], "usbid") != 0) {
495 ALOGE("%s: 'usbid' not found", __func__);
496 goto done;
497 }
498
499 if (strcmp(attr[4], "acdb_id") != 0) {
500 ALOGE("%s: 'acdb_id' not found", __func__);
501 goto done;
502 }
503
504 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
505
506done:
507 return;
508}
509
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700510static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
511{
512 int index;
513 struct audio_effect_config effect_config;
514
515 if (strcmp(attr[0], "name") != 0) {
516 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
517 goto done;
518 }
519
520 index = platform_get_snd_device_index((char *)attr[1]);
521 if (index < 0) {
522 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
523 __func__, attr[1]);
524 goto done;
525 }
526
527 if (strcmp(attr[2], "module_id") != 0) {
528 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
529 __func__, attr[2]);
530 goto done;
531 }
532
533 if (strcmp(attr[4], "instance_id") != 0) {
534 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
535 __func__, attr[4]);
536 goto done;
537 }
538
539 if (strcmp(attr[6], "param_id") != 0) {
540 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
541 __func__, attr[6]);
542 goto done;
543 }
544
545 if (strcmp(attr[8], "param_value") != 0) {
546 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
547 __func__, attr[8]);
548 goto done;
549 }
550
551 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
552 strtol((char *)attr[5], NULL, 0),
553 strtol((char *)attr[7], NULL, 0),
554 strtol((char *)attr[9], NULL, 0)};
555
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700556 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
557 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
558 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
559 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
560 strtol((char *)attr[9], NULL, 0));
561 goto done;
562 }
563
564done:
565 return;
566}
567
568static void process_effect_aec(const XML_Char **attr)
569{
570 process_audio_effect(attr, EFFECT_AEC);
571 return;
572}
573
574static void process_effect_ns(const XML_Char **attr)
575{
576 process_audio_effect(attr, EFFECT_NS);
577 return;
578}
579
Guodong Hu1d46f342019-06-28 16:57:30 +0800580static void process_fluence_mmsecns(const XML_Char **attr)
581{
582 int index;
583 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
584
585 if (strcmp(attr[0], "name") != 0) {
586 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
587 goto done;
588 }
589
590 index = platform_get_snd_device_index((char *)attr[1]);
591 if (index < 0) {
592 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
593 __func__, attr[1]);
594 goto done;
595 }
596
597 if (strcmp(attr[2], "topology_id") != 0) {
598 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
599 __func__, attr[2]);
600 goto done;
601 }
602
603 if (strcmp(attr[4], "module_id") != 0) {
604 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
605 __func__, attr[4]);
606 goto done;
607 }
608
609 if (strcmp(attr[6], "instance_id") != 0) {
610 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
611 __func__, attr[6]);
612 goto done;
613 }
614
615 if (strcmp(attr[8], "param_id") != 0) {
616 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
617 __func__, attr[8]);
618 goto done;
619 }
620
621 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
622 strtol((char *)attr[5], NULL, 0),
623 strtol((char *)attr[7], NULL, 0),
624 strtol((char *)attr[9], NULL, 0)};
625
626
627 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
628 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
629 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
630 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
631 goto done;
632 }
633
634done:
635 return;
636}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700637static void process_bit_width(const XML_Char **attr)
638{
639 int index;
640
641 if (strcmp(attr[0], "name") != 0) {
642 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
643 goto done;
644 }
645
646 index = platform_get_snd_device_index((char *)attr[1]);
647 if (index < 0) {
648 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
649 __func__, attr[1]);
650 goto done;
651 }
652
653 if (strcmp(attr[2], "bit_width") != 0) {
654 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
655 __func__, attr[1]);
656 goto done;
657 }
658
659 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
660 ALOGE("%s: Device %s, ACDB ID %d was not set!",
661 __func__, attr[1], atoi((char *)attr[3]));
662 goto done;
663 }
664
665done:
666 return;
667}
668
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800669static void process_interface_name(const XML_Char **attr)
670{
671 int ret;
672
673 if (strcmp(attr[0], "name") != 0) {
674 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
675
676 goto done;
677 }
678
679 if (strcmp(attr[2], "interface") != 0) {
680 ALOGE("%s: Device %s has no Audio Interface set!",
681 __func__, attr[1]);
682
683 goto done;
684 }
685
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530686 if (strcmp(attr[4], "codec_type") != 0) {
687 ALOGE("%s: Device %s has no codec type set!",
688 __func__, attr[1]);
689
690 goto done;
691 }
692
693 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
694 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800695 if (ret < 0) {
696 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800697 goto done;
698 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800699
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800700done:
701 return;
702}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530703
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700704static void process_config_params(const XML_Char **attr)
705{
706 if (strcmp(attr[0], "key") != 0) {
707 ALOGE("%s: 'key' not found", __func__);
708 goto done;
709 }
710
711 if (strcmp(attr[2], "value") != 0) {
712 ALOGE("%s: 'value' not found", __func__);
713 goto done;
714 }
715
716 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700717 if (my_data.caller == PLATFORM)
718 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700719done:
720 return;
721}
722
Aalique Grahame22e49102018-12-18 14:23:57 -0800723static void process_app_type(const XML_Char **attr)
724{
725 if (strcmp(attr[0], "uc_type")) {
726 ALOGE("%s: uc_type not found", __func__);
727 goto done;
728 }
729
730 if (strcmp(attr[2], "mode")) {
731 ALOGE("%s: mode not found", __func__);
732 goto done;
733 }
734
735 if (strcmp(attr[4], "bit_width")) {
736 ALOGE("%s: bit_width not found", __func__);
737 goto done;
738 }
739
740 if (strcmp(attr[6], "id")) {
741 ALOGE("%s: id not found", __func__);
742 goto done;
743 }
744
745 if (strcmp(attr[8], "max_rate")) {
746 ALOGE("%s: max rate not found", __func__);
747 goto done;
748 }
749
750 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
751 atoi(attr[9]));
752done:
753 return;
754}
755
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530756static void process_microphone_characteristic(const XML_Char **attr) {
757 struct audio_microphone_characteristic_t microphone;
758 uint32_t curIdx = 0;
759
760 if (strcmp(attr[curIdx++], "valid_mask")) {
761 ALOGE("%s: valid_mask not found", __func__);
762 goto done;
763 }
764 uint32_t valid_mask = atoi(attr[curIdx++]);
765
766 if (strcmp(attr[curIdx++], "device_id")) {
767 ALOGE("%s: device_id not found", __func__);
768 goto done;
769 }
770 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
771 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
772 goto done;
773 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530774 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530775
776 if (strcmp(attr[curIdx++], "type")) {
777 ALOGE("%s: device not found", __func__);
778 goto done;
779 }
780 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
781 ARRAY_SIZE(device_in_types), &microphone.device)) {
782 ALOGE("%s: type %s in %s not found!",
783 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
784 goto done;
785 }
786
787 if (strcmp(attr[curIdx++], "address")) {
788 ALOGE("%s: address not found", __func__);
789 goto done;
790 }
791 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
792 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
793 goto done;
794 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530795 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530796 if (strlen(microphone.address) == 0) {
797 // If the address is empty, populate the address according to device type.
798 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530799 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530800 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530801 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530802 }
803 }
804
805 if (strcmp(attr[curIdx++], "location")) {
806 ALOGE("%s: location not found", __func__);
807 goto done;
808 }
809 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
810 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
811 ALOGE("%s: location %s in %s not found!",
812 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
813 goto done;
814 }
815
816 if (strcmp(attr[curIdx++], "group")) {
817 ALOGE("%s: group not found", __func__);
818 goto done;
819 }
820 microphone.group = atoi(attr[curIdx++]);
821
822 if (strcmp(attr[curIdx++], "index_in_the_group")) {
823 ALOGE("%s: index_in_the_group not found", __func__);
824 goto done;
825 }
826 microphone.index_in_the_group = atoi(attr[curIdx++]);
827
828 if (strcmp(attr[curIdx++], "directionality")) {
829 ALOGE("%s: directionality not found", __func__);
830 goto done;
831 }
832 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
833 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
834 ALOGE("%s: directionality %s in %s not found!",
835 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
836 goto done;
837 }
838
839 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
840 ALOGE("%s: num_frequency_responses not found", __func__);
841 goto done;
842 }
843 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530844 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530845 ALOGE("%s: num_frequency_responses is too large", __func__);
846 goto done;
847 }
848 if (microphone.num_frequency_responses > 0) {
849 if (strcmp(attr[curIdx++], "frequencies")) {
850 ALOGE("%s: frequencies not found", __func__);
851 goto done;
852 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530853 char *context = NULL;
854 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530855 uint32_t num_frequencies = 0;
856 while (token) {
857 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800858 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530859 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530860 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530861 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530862 }
863
864 if (strcmp(attr[curIdx++], "responses")) {
865 ALOGE("%s: responses not found", __func__);
866 goto done;
867 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530868 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530869 uint32_t num_responses = 0;
870 while (token) {
871 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800872 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530873 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530874 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530875 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530876 }
877
878 if (num_frequencies != num_responses
879 || num_frequencies != microphone.num_frequency_responses) {
880 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
881 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
882 goto done;
883 }
884 }
885
886 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
887 if (strcmp(attr[curIdx++], "sensitivity")) {
888 ALOGE("%s: sensitivity not found", __func__);
889 goto done;
890 }
891 microphone.sensitivity = atof(attr[curIdx++]);
892 } else {
893 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
894 }
895
896 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
897 if (strcmp(attr[curIdx++], "max_spl")) {
898 ALOGE("%s: max_spl not found", __func__);
899 goto done;
900 }
901 microphone.max_spl = atof(attr[curIdx++]);
902 } else {
903 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
904 }
905
906 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
907 if (strcmp(attr[curIdx++], "min_spl")) {
908 ALOGE("%s: min_spl not found", __func__);
909 goto done;
910 }
911 microphone.min_spl = atof(attr[curIdx++]);
912 } else {
913 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
914 }
915
916 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
917 if (strcmp(attr[curIdx++], "orientation")) {
918 ALOGE("%s: orientation not found", __func__);
919 goto done;
920 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530921 char *context = NULL;
922 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530923 float orientation[3];
924 uint32_t idx = 0;
925 while (token) {
926 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800927 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530928 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530929 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530930 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530931 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530932 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530933 ALOGE("%s: orientation invalid", __func__);
934 goto done;
935 }
936 microphone.orientation.x = orientation[0];
937 microphone.orientation.y = orientation[1];
938 microphone.orientation.z = orientation[2];
939 } else {
940 microphone.orientation.x = 0.0f;
941 microphone.orientation.y = 0.0f;
942 microphone.orientation.z = 0.0f;
943 }
944
945 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
946 if (strcmp(attr[curIdx++], "geometric_location")) {
947 ALOGE("%s: geometric_location not found", __func__);
948 goto done;
949 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530950 char *context = NULL;
951 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530952 float geometric_location[3];
953 uint32_t idx = 0;
954 while (token) {
955 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800956 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530957 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530958 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530959 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530960 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530961 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530962 ALOGE("%s: geometric_location invalid", __func__);
963 goto done;
964 }
965 microphone.geometric_location.x = geometric_location[0];
966 microphone.geometric_location.y = geometric_location[1];
967 microphone.geometric_location.z = geometric_location[2];
968 } else {
969 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
970 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
971 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
972 }
973
974 platform_set_microphone_characteristic(my_data.platform, microphone);
975done:
976 return;
977}
978
979static void process_snd_dev(const XML_Char **attr)
980{
981 uint32_t curIdx = 0;
982 in_snd_device = SND_DEVICE_NONE;
983
984 if (strcmp(attr[curIdx++], "in_snd_device")) {
985 ALOGE("%s: snd_device not found", __func__);
986 return;
987 }
988 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
989 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
990 in_snd_device >= SND_DEVICE_IN_END) {
991 ALOGE("%s: Sound device not valid", __func__);
992 in_snd_device = SND_DEVICE_NONE;
993 }
994
995 return;
996}
997
998static void process_mic_info(const XML_Char **attr)
999{
1000 uint32_t curIdx = 0;
1001 struct mic_info microphone;
1002
1003 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1004 sizeof(microphone.channel_mapping));
1005
1006 if (strcmp(attr[curIdx++], "mic_device_id")) {
1007 ALOGE("%s: mic_device_id not found", __func__);
1008 goto on_error;
1009 }
1010 strlcpy(microphone.device_id,
1011 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1012
1013 if (strcmp(attr[curIdx++], "channel_mapping")) {
1014 ALOGE("%s: channel_mapping not found", __func__);
1015 goto on_error;
1016 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301017 char *context = NULL;
1018 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301019 uint32_t idx = 0;
1020 while (token) {
1021 if (!find_enum_by_string(mic_channel_mapping, token,
1022 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1023 &microphone.channel_mapping[idx++])) {
1024 ALOGE("%s: channel_mapping %s in %s not found!",
1025 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
1026 goto on_error;
1027 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301028 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301029 }
1030 microphone.channel_count = idx;
1031
1032 platform_set_microphone_map(my_data.platform, in_snd_device,
1033 &microphone);
1034 return;
1035on_error:
1036 in_snd_device = SND_DEVICE_NONE;
1037 return;
1038}
1039
1040
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301041/* process acdb meta info key value */
1042static void process_acdb_metainfo_key(const XML_Char **attr)
1043{
1044 if (strcmp(attr[0], "name") != 0) {
1045 ALOGE("%s: 'name' not found", __func__);
1046 goto done;
1047 }
1048
1049 if (strcmp(attr[2], "value") != 0) {
1050 ALOGE("%s: 'value' not found", __func__);
1051 goto done;
1052 }
1053
1054 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001055 switch(my_data.caller) {
1056 case ACDB_EXTN:
1057 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1058 ALOGE("%s: key %d was not set!", __func__, key);
1059 goto done;
1060 }
1061 break;
1062 case PLATFORM:
1063 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1064 ALOGE("%s: key %d was not set!", __func__, key);
1065 goto done;
1066 }
1067 break;
1068 default:
1069 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301070 }
1071
1072done:
1073 return;
1074}
1075
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301076static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1077{
1078 uint32_t attr_idx = 0;
1079 int32_t in_ch_idx = -1;
1080 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1081
1082 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1083 &mtmx_in_params_info);
1084 if (mtmx_in_params == NULL) {
1085 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1086 return;
1087 }
1088
1089 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1090 ALOGE("%s: 'in_channel_index' not found", __func__);
1091 return;
1092 }
1093
1094 in_ch_idx = atoi((char *)attr[attr_idx++]);
1095 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1096 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1097 return;
1098 }
1099
1100 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1101 ALOGE("%s: 'channel_count' not found", __func__);
1102 return;
1103 }
1104 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1105
1106 if (strcmp(attr[attr_idx++], "device") != 0) {
1107 ALOGE("%s: 'device' not found", __func__);
1108 return;
1109 }
1110 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1111 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1112
1113 if (strcmp(attr[attr_idx++], "interface") != 0) {
1114 ALOGE("%s: 'interface' not found", __func__);
1115 return;
1116 }
1117 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1118 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1119
1120 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1121 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1122 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1123 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1124 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1125 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1126 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1127 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1128
1129 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1130}
1131
1132static void process_custom_mtmx_in_params(const XML_Char **attr)
1133{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301134 int attr_idx = 0, i = 0;
1135 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301136
1137 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1138 ALOGE("%s: 'usecase' not found", __func__);
1139 return;
1140 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301141 /* Check if multi usecases are supported for this custom mtrx params */
1142 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1143 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1144 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1145 value = strtok_r(NULL, ",", &context);
1146 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301147
1148 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1149 ALOGE("%s: 'out_channel_count' not found", __func__);
1150 return;
1151 }
1152 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1153
1154 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1155
1156}
1157
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301158static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1159{
1160 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301161 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301162 char *context = NULL, *ch_coeff_value = NULL;
1163 struct audio_custom_mtmx_params *mtmx_params = NULL;
1164
1165 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1166 ALOGE("%s: 'out_channel_index' not found", __func__);
1167 return;
1168 }
1169 out_ch_idx = atoi((char *)attr[attr_idx++]);
1170
1171 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1172 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1173 return;
1174 }
1175
1176 if (strcmp(attr[attr_idx++], "values") != 0) {
1177 ALOGE("%s: 'values' not found", __func__);
1178 return;
1179 }
1180 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301181 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301182 if (mtmx_params == NULL) {
1183 ALOGE("%s: mtmx params with given param info, not found", __func__);
1184 return;
1185 }
1186 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1187 ip_channels = mtmx_params->info.ip_channels;
1188 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301189 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301190 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1191 = atoi(ch_coeff_value);
1192 ch_coeff_value = strtok_r(NULL, " ", &context);
1193 }
1194 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1195 ch_coeff_value != NULL)
1196 ALOGE("%s: invalid/malformed coefficient values", __func__);
1197}
1198
1199static void process_custom_mtmx_params(const XML_Char **attr)
1200{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301201 int attr_idx = 0, i = 0;
1202 char *context = NULL, *value = NULL;
1203
1204 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301205
1206 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1207 ALOGE("%s: 'param_id' not found", __func__);
1208 return;
1209 }
1210 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1211
1212 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1213 ALOGE("%s: 'in_channel_count' not found", __func__);
1214 return;
1215 }
1216 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1217
1218 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1219 ALOGE("%s: 'out_channel_count' not found", __func__);
1220 return;
1221 }
1222 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1223
1224 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1225 ALOGE("%s: 'usecase' not found", __func__);
1226 return;
1227 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301228
1229 /* check if multi usecases are supported for this custom mtrx params */
1230 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1231 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1232 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1233 value = strtok_r(NULL, ",", &context);
1234 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301235
1236 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1237 ALOGE("%s: 'snd_device' not found", __func__);
1238 return;
1239 }
1240 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301241
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301242 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1243 i = 0;
1244 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1245 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1246 mtmx_params_info.fe_id[i++] = atoi(value);
1247 value = strtok_r(NULL, ",", &context);
1248 }
1249
1250 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301251 }
1252
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301253 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1254
1255}
1256
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001257static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001258 const XML_Char **attr)
1259{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001260 if (my_data.caller == ACDB_EXTN) {
1261 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1262 section = ACDB_METAINFO_KEY;
1263 } else if (strcmp(tag_name, "param") == 0) {
1264 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1265 ALOGE("param tag only supported with CONFIG_PARAMS section");
1266 return;
1267 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001268
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001269 section_process_fn fn = section_table[section];
1270 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001271 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001272 } else if(my_data.caller == PLATFORM) {
1273 if (strcmp(tag_name, "bit_width_configs") == 0) {
1274 section = BITWIDTH;
1275 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1276 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001277 } else if (strcmp(tag_name, "module_ids") == 0) {
1278 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001279 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1280 section = PCM_ID;
1281 } else if (strcmp(tag_name, "backend_names") == 0) {
1282 section = BACKEND_NAME;
1283 } else if (strcmp(tag_name, "config_params") == 0) {
1284 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001285 } else if (strcmp(tag_name, "operator_specific") == 0) {
1286 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001287 } else if (strcmp(tag_name, "interface_names") == 0) {
1288 section = INTERFACE_NAME;
1289 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1290 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001291 } else if (strcmp(tag_name, "app_types") == 0) {
1292 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001293 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1294 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301295 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1296 section = MICROPHONE_CHARACTERISTIC;
1297 } else if (strcmp(tag_name, "snd_devices") == 0) {
1298 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001299 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001300 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001301 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001302 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001303 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1304 return;
1305 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001306
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001307 /* call into process function for the current section */
1308 section_process_fn fn = section_table[section];
1309 fn(attr);
1310 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1311 if (section != GAIN_LEVEL_MAPPING) {
1312 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1313 return;
1314 }
1315
1316 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1317 fn(attr);
1318 } else if (strcmp(tag_name, "usecase") == 0) {
1319 if (section != PCM_ID) {
1320 ALOGE("usecase tag only supported with PCM_ID section");
1321 return;
1322 }
1323
1324 section_process_fn fn = section_table[PCM_ID];
1325 fn(attr);
1326 } else if (strcmp(tag_name, "param") == 0) {
1327 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1328 ALOGE("param tag only supported with CONFIG_PARAMS section");
1329 return;
1330 }
1331
1332 section_process_fn fn = section_table[section];
1333 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301334 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001335 if (section != MODULE) {
1336 ALOGE("aec tag only supported with MODULE section");
1337 return;
1338 }
1339 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301340 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001341 if (section != MODULE) {
1342 ALOGE("ns tag only supported with MODULE section");
1343 return;
1344 }
1345 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001346 } else if (strcmp(tag_name, "mmsecns") == 0) {
1347 if (section != MODULE) {
1348 ALOGE("mmsecns tag only supported with MODULE section");
1349 return;
1350 }
1351 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001352 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1353 if (section != GAIN_LEVEL_MAPPING) {
1354 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1355 return;
1356 }
1357
1358 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1359 fn(attr);
1360 } else if (!strcmp(tag_name, "app")) {
1361 if (section != APP_TYPE) {
1362 ALOGE("app tag only valid in section APP_TYPE");
1363 return;
1364 }
1365
1366 section_process_fn fn = section_table[APP_TYPE];
1367 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301368 } else if (strcmp(tag_name, "microphone") == 0) {
1369 if (section != MICROPHONE_CHARACTERISTIC) {
1370 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1371 return;
1372 }
1373 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1374 fn(attr);
1375 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1376 if (section != SND_DEVICES) {
1377 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1378 return;
1379 }
1380 section = INPUT_SND_DEVICE;
1381 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1382 if (section != INPUT_SND_DEVICE) {
1383 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1384 return;
1385 }
1386 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1387 } else if (strcmp(tag_name, "snd_dev") == 0) {
1388 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1389 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1390 return;
1391 }
1392 section_process_fn fn = section_table[SND_DEV];
1393 fn(attr);
1394 } else if (strcmp(tag_name, "mic_info") == 0) {
1395 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1396 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1397 return;
1398 }
1399 if (in_snd_device == SND_DEVICE_NONE) {
1400 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1401 return;
1402 }
1403 section_process_fn fn = section_table[MIC_INFO];
1404 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301405 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1406 if (section != ROOT) {
1407 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1408 return;
1409 }
1410 section = CUSTOM_MTMX_PARAMS;
1411 section_process_fn fn = section_table[section];
1412 fn(attr);
1413 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1414 if (section != CUSTOM_MTMX_PARAMS) {
1415 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1416 return;
1417 }
1418 section = CUSTOM_MTMX_PARAM_COEFFS;
1419 section_process_fn fn = section_table[section];
1420 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001421 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1422 section = EXTERNAL_DEVICE_SPECIFIC;
1423 } else if (strcmp(tag_name, "ext_device") == 0) {
1424 section_process_fn fn = section_table[section];
1425 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301426 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1427 if (section != ROOT) {
1428 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1429 return;
1430 }
1431 section = CUSTOM_MTMX_IN_PARAMS;
1432 section_process_fn fn = section_table[section];
1433 fn(attr);
1434 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1435 if (section != CUSTOM_MTMX_IN_PARAMS) {
1436 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1437 return;
1438 }
1439 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
1440 section_process_fn fn = section_table[section];
1441 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301442 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001443 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001444 if(strcmp(tag_name, "config_params") == 0) {
1445 section = CONFIG_PARAMS;
1446 } else if (strcmp(tag_name, "param") == 0) {
1447 if (section != CONFIG_PARAMS) {
1448 ALOGE("param tag only supported with CONFIG_PARAMS section");
1449 return;
1450 }
1451
1452 section_process_fn fn = section_table[section];
1453 fn(attr);
1454 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001455 }
Ben Romberger55886882014-01-10 13:49:02 -08001456 return;
1457}
1458
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001459static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001460{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001461 if (strcmp(tag_name, "bit_width_configs") == 0) {
1462 section = ROOT;
1463 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001464 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001465 } else if (strcmp(tag_name, "module_ids") == 0) {
1466 section = ROOT;
1467 } else if (strcmp(tag_name, "aec") == 0) {
1468 section = MODULE;
1469 } else if (strcmp(tag_name, "ns") == 0) {
1470 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001471 } else if (strcmp(tag_name, "mmsecns") == 0) {
1472 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001473 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1474 section = ROOT;
1475 } else if (strcmp(tag_name, "backend_names") == 0) {
1476 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001477 } else if (strcmp(tag_name, "config_params") == 0) {
1478 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001479 } else if (strcmp(tag_name, "operator_specific") == 0) {
1480 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001481 } else if (strcmp(tag_name, "interface_names") == 0) {
1482 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001483 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1484 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001485 } else if (strcmp(tag_name, "app_types") == 0) {
1486 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301487 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1488 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301489 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1490 section = ROOT;
1491 } else if (strcmp(tag_name, "snd_devices") == 0) {
1492 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001493 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1494 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301495 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1496 section = SND_DEVICES;
1497 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1498 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301499 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1500 section = ROOT;
1501 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1502 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301503 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1504 section = ROOT;
1505 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1506 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001507 }
Ben Romberger55886882014-01-10 13:49:02 -08001508}
1509
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001510int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001511{
1512 XML_Parser parser;
1513 FILE *file;
1514 int ret = 0;
1515 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001516 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001517 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001518
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001519 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001520 if (filename == NULL)
1521 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1522 MIXER_PATH_MAX_LENGTH);
1523 else
1524 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1525
1526 ALOGV("%s: platform info file name is %s", __func__,
1527 platform_info_file_name);
1528
1529 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001530 section = ROOT;
1531
Ben Romberger55886882014-01-10 13:49:02 -08001532 if (!file) {
1533 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001534 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001535 ret = -ENODEV;
1536 goto done;
1537 }
1538
1539 parser = XML_ParserCreate(NULL);
1540 if (!parser) {
1541 ALOGE("%s: Failed to create XML parser!", __func__);
1542 ret = -ENODEV;
1543 goto err_close_file;
1544 }
1545
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001546 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001547 my_data.platform = platform;
1548 my_data.kvpairs = str_parms_create();
1549
Ben Romberger55886882014-01-10 13:49:02 -08001550 XML_SetElementHandler(parser, start_tag, end_tag);
1551
1552 while (1) {
1553 buf = XML_GetBuffer(parser, BUF_SIZE);
1554 if (buf == NULL) {
1555 ALOGE("%s: XML_GetBuffer failed", __func__);
1556 ret = -ENOMEM;
1557 goto err_free_parser;
1558 }
1559
1560 bytes_read = fread(buf, 1, BUF_SIZE, file);
1561 if (bytes_read < 0) {
1562 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1563 ret = bytes_read;
1564 goto err_free_parser;
1565 }
1566
1567 if (XML_ParseBuffer(parser, bytes_read,
1568 bytes_read == 0) == XML_STATUS_ERROR) {
1569 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001570 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001571 ret = -EINVAL;
1572 goto err_free_parser;
1573 }
1574
1575 if (bytes_read == 0)
1576 break;
1577 }
1578
Ben Romberger55886882014-01-10 13:49:02 -08001579err_free_parser:
1580 XML_ParserFree(parser);
1581err_close_file:
1582 fclose(file);
1583done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001584 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001585 return ret;
1586}