blob: 40b22bcc7d7839460a77909b307a77bb3dbfd095 [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Robert Lee58215542019-07-15 20:55:12 +08002 * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved.
Ben Romberger55886882014-01-10 13:49:02 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Ben Romberger61764e32014-01-10 13:49:02 -080030#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080031#define LOG_NDDEBUG 0
32
33#include <errno.h>
34#include <stdio.h>
35#include <expat.h>
Jiangen Jiao334224b2019-09-12 15:47:46 +080036#include <pthread.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080037#include <log/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070038#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080039#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070040#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080041#include "platform_api.h"
42#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070043#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080044
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053045#ifdef DYNAMIC_LOG_ENABLED
46#include <log_xml_parser.h>
47#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
48#include <log_utils.h>
49#endif
50
Ben Romberger55886882014-01-10 13:49:02 -080051#define BUF_SIZE 1024
52
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070053typedef enum {
54 ROOT,
55 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070056 MODULE,
57 AEC,
58 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070059 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070060 PCM_ID,
61 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080062 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070063 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080064 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070065 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080066 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053067 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053068 MICROPHONE_CHARACTERISTIC,
69 SND_DEVICES,
70 INPUT_SND_DEVICE,
71 INPUT_SND_DEVICE_TO_MIC_MAPPING,
72 SND_DEV,
73 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053074 CUSTOM_MTMX_PARAMS,
75 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070076 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053077 CUSTOM_MTMX_IN_PARAMS,
78 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Guodong Hu1d46f342019-06-28 16:57:30 +080079 MMSECNS,
Robert Lee58215542019-07-15 20:55:12 +080080 SND_DEV_DELAY,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070081} section_t;
82
83typedef void (* section_process_fn)(const XML_Char **attr);
84
85static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070086static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
87static void process_effect_aec(const XML_Char **attr);
88static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070089static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070090static void process_pcm_id(const XML_Char **attr);
91static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080092static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070093static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070094static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080095static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070096static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080097static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053098static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053099static void process_microphone_characteristic(const XML_Char **attr);
100static void process_snd_dev(const XML_Char **attr);
101static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530102static void process_custom_mtmx_params(const XML_Char **attr);
103static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700104static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530105static void process_custom_mtmx_in_params(const XML_Char **attr);
106static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Guodong Hu1d46f342019-06-28 16:57:30 +0800107static void process_fluence_mmsecns(const XML_Char **attr);
Robert Lee58215542019-07-15 20:55:12 +0800108static void process_snd_device_delay(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700109
110static section_process_fn section_table[] = {
111 [ROOT] = process_root,
112 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700113 [AEC] = process_effect_aec,
114 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700115 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700116 [PCM_ID] = process_pcm_id,
117 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800118 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700119 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800120 [OPERATOR_SPECIFIC] = process_operator_specific,
121 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700122 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530123 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530124 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
125 [SND_DEV] = process_snd_dev,
126 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530127 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
128 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700129 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530130 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
131 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Guodong Hu1d46f342019-06-28 16:57:30 +0800132 [MMSECNS] = process_fluence_mmsecns,
Robert Lee58215542019-07-15 20:55:12 +0800133 [SND_DEV_DELAY] = process_snd_device_delay,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700134};
135
136static section_t section;
137
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700138struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700139 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700140 void *platform;
141 struct str_parms *kvpairs;
142};
143
144static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800145static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700146
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530147
148struct audio_string_to_enum {
149 const char* name;
150 unsigned int value;
151};
152
153static snd_device_t in_snd_device;
154
155static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
157 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
160};
161
162static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
163 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
167 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
169};
170
171static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
175};
176
177static const struct audio_string_to_enum device_in_types[] = {
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
199 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
200 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
201 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
202 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
203 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
204 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
205};
206
207enum {
208 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
209 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
210 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
211 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
212 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
213 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
214 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
215 | ORIENTATION) | GEOMETRIC_LOCATION) */
216};
217
218static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
219 int32_t len, unsigned int *value)
220{
221 if (table == NULL) {
222 ALOGE("%s: table is NULL", __func__);
223 return false;
224 }
225
226 if (name == NULL) {
227 ALOGE("null key");
228 return false;
229 }
230
231 for (int i = 0; i < len; i++) {
232 if (!strcmp(table[i].name, name)) {
233 *value = table[i].value;
234 return true;
235 }
236 }
237 return false;
238}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530239
240static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530241static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530242
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700243/*
244 * <audio_platform_info>
245 * <acdb_ids>
246 * <device name="???" acdb_id="???"/>
247 * ...
248 * ...
249 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700250 * <module_ids>
251 * <device name="???" module_id="???"/>
252 * ...
253 * ...
254 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700255 * <backend_names>
256 * <device name="???" backend="???"/>
257 * ...
258 * ...
259 * </backend_names>
260 * <pcm_ids>
261 * <usecase name="???" type="in/out" id="???"/>
262 * ...
263 * ...
264 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800265 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530266 * <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 -0800267 * ...
268 * ...
269 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700270 * <config_params>
271 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800272 * <param key="operator_info" value="tmus;aa;bb;cc"/>
273 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700274 * ...
275 * ...
276 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800277 *
278 * <operator_specific>
279 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
280 * ...
281 * ...
282 * </operator_specific>
283 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700284 * </audio_platform_info>
285 */
286
287static void process_root(const XML_Char **attr __unused)
288{
289}
290
291/* mapping from usecase to pcm dev id */
292static void process_pcm_id(const XML_Char **attr)
293{
294 int index;
295
296 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700297 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700298 goto done;
299 }
300
301 index = platform_get_usecase_index((char *)attr[1]);
302 if (index < 0) {
303 ALOGE("%s: usecase %s not found!",
304 __func__, attr[1]);
305 goto done;
306 }
307
308 if (strcmp(attr[2], "type") != 0) {
309 ALOGE("%s: usecase type not mentioned", __func__);
310 goto done;
311 }
312
313 int type = -1;
314
315 if (!strcasecmp((char *)attr[3], "in")) {
316 type = 1;
317 } else if (!strcasecmp((char *)attr[3], "out")) {
318 type = 0;
319 } else {
320 ALOGE("%s: type must be IN or OUT", __func__);
321 goto done;
322 }
323
324 if (strcmp(attr[4], "id") != 0) {
325 ALOGE("%s: usecase id not mentioned", __func__);
326 goto done;
327 }
328
329 int id = atoi((char *)attr[5]);
330
331 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
332 ALOGE("%s: usecase %s type %d id %d was not set!",
333 __func__, attr[1], type, id);
334 goto done;
335 }
336
337done:
338 return;
339}
340
341/* backend to be used for a device */
342static void process_backend_name(const XML_Char **attr)
343{
344 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530345 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530346 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700347
348 if (strcmp(attr[0], "name") != 0) {
349 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
350 goto done;
351 }
352
353 index = platform_get_snd_device_index((char *)attr[1]);
354 if (index < 0) {
355 ALOGE("%s: Device %s not found, no ACDB ID set!",
356 __func__, attr[1]);
357 goto done;
358 }
359
360 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530361 if (strcmp(attr[2], "interface") == 0)
362 hw_interface = (char *)attr[3];
363 } else {
364 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700365 }
366
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530367 if (attr[4] != NULL) {
368 if (strcmp(attr[4], "interface") != 0) {
369 hw_interface = NULL;
370 } else {
371 hw_interface = (char *)attr[5];
372 }
373 }
374
Ashish Jaind150d4c2017-02-03 18:44:34 +0530375 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700376 ALOGE("%s: Device %s backend %s was not set!",
377 __func__, attr[1], attr[3]);
378 goto done;
379 }
380
381done:
382 return;
383}
384
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700385static void process_gain_db_to_level_map(const XML_Char **attr)
386{
387 struct amp_db_and_gain_table tbl_entry;
388
389 if ((strcmp(attr[0], "db") != 0) ||
390 (strcmp(attr[2], "level") != 0)) {
391 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
392 __func__, attr[0], attr[2]);
393 goto done;
394 }
395
396 tbl_entry.db = atof(attr[1]);
397 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
398 tbl_entry.level = atoi(attr[3]);
399
Aalique Grahame22e49102018-12-18 14:23:57 -0800400 //custome level should be > 0. Level 0 is fixed for default
401 CHECK(tbl_entry.level > 0);
402
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700403 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
404 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
405 platform_add_gain_level_mapping(&tbl_entry);
406
407done:
408 return;
409}
410
411
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700412static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800413{
Ben Romberger61764e32014-01-10 13:49:02 -0800414 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800415
Ben Romberger61764e32014-01-10 13:49:02 -0800416 if (strcmp(attr[0], "name") != 0) {
417 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800418 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800419 }
Ben Romberger55886882014-01-10 13:49:02 -0800420
Ben Romberger61764e32014-01-10 13:49:02 -0800421 index = platform_get_snd_device_index((char *)attr[1]);
422 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800423 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
424 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800425 goto done;
426 }
427
428 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800429 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
430 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800431 goto done;
432 }
433
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700434 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
435 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800436 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800437 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800438 }
Ben Romberger55886882014-01-10 13:49:02 -0800439
Ben Romberger55886882014-01-10 13:49:02 -0800440done:
441 return;
442}
443
Aalique Grahame22e49102018-12-18 14:23:57 -0800444static void process_operator_specific(const XML_Char **attr)
445{
446 snd_device_t snd_device = SND_DEVICE_NONE;
447
448 if (strcmp(attr[0], "name") != 0) {
449 ALOGE("%s: 'name' not found", __func__);
450 goto done;
451 }
452
453 snd_device = platform_get_snd_device_index((char *)attr[1]);
454 if (snd_device < 0) {
455 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
456 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
457 goto done;
458 }
459
460 if (strcmp(attr[2], "operator") != 0) {
461 ALOGE("%s: 'operator' not found", __func__);
462 goto done;
463 }
464
465 if (strcmp(attr[4], "mixer_path") != 0) {
466 ALOGE("%s: 'mixer_path' not found", __func__);
467 goto done;
468 }
469
470 if (strcmp(attr[6], "acdb_id") != 0) {
471 ALOGE("%s: 'acdb_id' not found", __func__);
472 goto done;
473 }
474
475 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
476
477done:
478 return;
479}
480
Carter Hsu32a62362018-10-15 15:01:42 -0700481static void process_external_dev(const XML_Char **attr)
482{
483 snd_device_t snd_device = SND_DEVICE_NONE;
484
485 if (strcmp(attr[0], "name") != 0) {
486 ALOGE("%s: 'name' not found", __func__);
487 goto done;
488 }
489
490 snd_device = platform_get_snd_device_index((char *)attr[1]);
491 if (snd_device < 0) {
492 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
493 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
494 goto done;
495 }
496
497 if (strcmp(attr[2], "usbid") != 0) {
498 ALOGE("%s: 'usbid' not found", __func__);
499 goto done;
500 }
501
502 if (strcmp(attr[4], "acdb_id") != 0) {
503 ALOGE("%s: 'acdb_id' not found", __func__);
504 goto done;
505 }
506
507 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
508
509done:
510 return;
511}
512
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700513static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
514{
515 int index;
516 struct audio_effect_config effect_config;
517
518 if (strcmp(attr[0], "name") != 0) {
519 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
520 goto done;
521 }
522
523 index = platform_get_snd_device_index((char *)attr[1]);
524 if (index < 0) {
525 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
526 __func__, attr[1]);
527 goto done;
528 }
529
530 if (strcmp(attr[2], "module_id") != 0) {
531 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
532 __func__, attr[2]);
533 goto done;
534 }
535
536 if (strcmp(attr[4], "instance_id") != 0) {
537 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
538 __func__, attr[4]);
539 goto done;
540 }
541
542 if (strcmp(attr[6], "param_id") != 0) {
543 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
544 __func__, attr[6]);
545 goto done;
546 }
547
548 if (strcmp(attr[8], "param_value") != 0) {
549 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
550 __func__, attr[8]);
551 goto done;
552 }
553
554 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
555 strtol((char *)attr[5], NULL, 0),
556 strtol((char *)attr[7], NULL, 0),
557 strtol((char *)attr[9], NULL, 0)};
558
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700559 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
560 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
561 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
562 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
563 strtol((char *)attr[9], NULL, 0));
564 goto done;
565 }
566
567done:
568 return;
569}
570
571static void process_effect_aec(const XML_Char **attr)
572{
573 process_audio_effect(attr, EFFECT_AEC);
574 return;
575}
576
577static void process_effect_ns(const XML_Char **attr)
578{
579 process_audio_effect(attr, EFFECT_NS);
580 return;
581}
582
Guodong Hu1d46f342019-06-28 16:57:30 +0800583static void process_fluence_mmsecns(const XML_Char **attr)
584{
585 int index;
586 struct audio_fluence_mmsecns_config fluence_mmsecns_config;
587
588 if (strcmp(attr[0], "name") != 0) {
589 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
590 goto done;
591 }
592
593 index = platform_get_snd_device_index((char *)attr[1]);
594 if (index < 0) {
595 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
596 __func__, attr[1]);
597 goto done;
598 }
599
600 if (strcmp(attr[2], "topology_id") != 0) {
601 ALOGE("%s: Device %s in platform info xml has no topology_id, no MODULE ID set!",
602 __func__, attr[2]);
603 goto done;
604 }
605
606 if (strcmp(attr[4], "module_id") != 0) {
607 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
608 __func__, attr[4]);
609 goto done;
610 }
611
612 if (strcmp(attr[6], "instance_id") != 0) {
613 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
614 __func__, attr[6]);
615 goto done;
616 }
617
618 if (strcmp(attr[8], "param_id") != 0) {
619 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
620 __func__, attr[8]);
621 goto done;
622 }
623
624 fluence_mmsecns_config = (struct audio_fluence_mmsecns_config){strtol((char *)attr[3], NULL, 0),
625 strtol((char *)attr[5], NULL, 0),
626 strtol((char *)attr[7], NULL, 0),
627 strtol((char *)attr[9], NULL, 0)};
628
629
630 if (platform_set_fluence_mmsecns_config(fluence_mmsecns_config) < 0) {
631 ALOGE("%s: Device %s, TOPOLOGY/MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
632 __func__, attr[1], strtol((char *)attr[3], NULL, 0), strtol((char *)attr[5], NULL, 0),
633 strtol((char *)attr[7], NULL, 0), strtol((char *)attr[9], NULL, 0));
634 goto done;
635 }
636
637done:
638 return;
639}
Amit Shekhar5a39c912014-10-14 15:39:30 -0700640static void process_bit_width(const XML_Char **attr)
641{
642 int index;
643
644 if (strcmp(attr[0], "name") != 0) {
645 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
646 goto done;
647 }
648
649 index = platform_get_snd_device_index((char *)attr[1]);
650 if (index < 0) {
651 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
652 __func__, attr[1]);
653 goto done;
654 }
655
656 if (strcmp(attr[2], "bit_width") != 0) {
657 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
658 __func__, attr[1]);
659 goto done;
660 }
661
662 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
663 ALOGE("%s: Device %s, ACDB ID %d was not set!",
664 __func__, attr[1], atoi((char *)attr[3]));
665 goto done;
666 }
667
668done:
669 return;
670}
671
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800672static void process_interface_name(const XML_Char **attr)
673{
674 int ret;
675
676 if (strcmp(attr[0], "name") != 0) {
677 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
678
679 goto done;
680 }
681
682 if (strcmp(attr[2], "interface") != 0) {
683 ALOGE("%s: Device %s has no Audio Interface set!",
684 __func__, attr[1]);
685
686 goto done;
687 }
688
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530689 if (strcmp(attr[4], "codec_type") != 0) {
690 ALOGE("%s: Device %s has no codec type set!",
691 __func__, attr[1]);
692
693 goto done;
694 }
695
696 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
697 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800698 if (ret < 0) {
699 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800700 goto done;
701 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800702
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800703done:
704 return;
705}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530706
Robert Lee58215542019-07-15 20:55:12 +0800707
708static void process_snd_device_delay(const XML_Char **attr)
709{
710 snd_device_t snd_device = SND_DEVICE_NONE;
711
712 if (strcmp(attr[0], "name") != 0) {
713 ALOGE("%s: 'name' not found", __func__);
714 goto done;
715 }
716
717 snd_device = platform_get_snd_device_index((char *)attr[1]);
718 if (snd_device < 0) {
719 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
720 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
721 goto done;
722 }
723
724 if (strcmp(attr[2], "delay") != 0) {
725 ALOGE("%s: 'delay' not found", __func__);
726 goto done;
727 }
728
729 platform_set_snd_device_delay(snd_device, atoi((char *)attr[3]));
730
731done:
732 return;
733}
734
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700735static void process_config_params(const XML_Char **attr)
736{
737 if (strcmp(attr[0], "key") != 0) {
738 ALOGE("%s: 'key' not found", __func__);
739 goto done;
740 }
741
742 if (strcmp(attr[2], "value") != 0) {
743 ALOGE("%s: 'value' not found", __func__);
744 goto done;
745 }
746
747 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700748 if (my_data.caller == PLATFORM)
749 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700750done:
751 return;
752}
753
Aalique Grahame22e49102018-12-18 14:23:57 -0800754static void process_app_type(const XML_Char **attr)
755{
756 if (strcmp(attr[0], "uc_type")) {
757 ALOGE("%s: uc_type not found", __func__);
758 goto done;
759 }
760
761 if (strcmp(attr[2], "mode")) {
762 ALOGE("%s: mode not found", __func__);
763 goto done;
764 }
765
766 if (strcmp(attr[4], "bit_width")) {
767 ALOGE("%s: bit_width not found", __func__);
768 goto done;
769 }
770
771 if (strcmp(attr[6], "id")) {
772 ALOGE("%s: id not found", __func__);
773 goto done;
774 }
775
776 if (strcmp(attr[8], "max_rate")) {
777 ALOGE("%s: max rate not found", __func__);
778 goto done;
779 }
780
781 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
782 atoi(attr[9]));
783done:
784 return;
785}
786
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530787static void process_microphone_characteristic(const XML_Char **attr) {
788 struct audio_microphone_characteristic_t microphone;
789 uint32_t curIdx = 0;
790
791 if (strcmp(attr[curIdx++], "valid_mask")) {
792 ALOGE("%s: valid_mask not found", __func__);
793 goto done;
794 }
795 uint32_t valid_mask = atoi(attr[curIdx++]);
796
797 if (strcmp(attr[curIdx++], "device_id")) {
798 ALOGE("%s: device_id not found", __func__);
799 goto done;
800 }
801 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
802 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
803 goto done;
804 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530805 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530806
807 if (strcmp(attr[curIdx++], "type")) {
808 ALOGE("%s: device not found", __func__);
809 goto done;
810 }
811 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
812 ARRAY_SIZE(device_in_types), &microphone.device)) {
813 ALOGE("%s: type %s in %s not found!",
814 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
815 goto done;
816 }
817
818 if (strcmp(attr[curIdx++], "address")) {
819 ALOGE("%s: address not found", __func__);
820 goto done;
821 }
822 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
823 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
824 goto done;
825 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530826 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530827 if (strlen(microphone.address) == 0) {
828 // If the address is empty, populate the address according to device type.
829 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530830 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530831 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530832 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530833 }
834 }
835
836 if (strcmp(attr[curIdx++], "location")) {
837 ALOGE("%s: location not found", __func__);
838 goto done;
839 }
840 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
841 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
842 ALOGE("%s: location %s in %s not found!",
843 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
844 goto done;
845 }
846
847 if (strcmp(attr[curIdx++], "group")) {
848 ALOGE("%s: group not found", __func__);
849 goto done;
850 }
851 microphone.group = atoi(attr[curIdx++]);
852
853 if (strcmp(attr[curIdx++], "index_in_the_group")) {
854 ALOGE("%s: index_in_the_group not found", __func__);
855 goto done;
856 }
857 microphone.index_in_the_group = atoi(attr[curIdx++]);
858
859 if (strcmp(attr[curIdx++], "directionality")) {
860 ALOGE("%s: directionality not found", __func__);
861 goto done;
862 }
863 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
864 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
865 ALOGE("%s: directionality %s in %s not found!",
866 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
867 goto done;
868 }
869
870 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
871 ALOGE("%s: num_frequency_responses not found", __func__);
872 goto done;
873 }
874 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530875 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530876 ALOGE("%s: num_frequency_responses is too large", __func__);
877 goto done;
878 }
879 if (microphone.num_frequency_responses > 0) {
880 if (strcmp(attr[curIdx++], "frequencies")) {
881 ALOGE("%s: frequencies not found", __func__);
882 goto done;
883 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530884 char *context = NULL;
885 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530886 uint32_t num_frequencies = 0;
887 while (token) {
888 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800889 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530890 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530891 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530892 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530893 }
894
895 if (strcmp(attr[curIdx++], "responses")) {
896 ALOGE("%s: responses not found", __func__);
897 goto done;
898 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530899 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530900 uint32_t num_responses = 0;
901 while (token) {
902 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800903 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530904 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530905 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530906 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530907 }
908
909 if (num_frequencies != num_responses
910 || num_frequencies != microphone.num_frequency_responses) {
911 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
912 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
913 goto done;
914 }
915 }
916
917 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
918 if (strcmp(attr[curIdx++], "sensitivity")) {
919 ALOGE("%s: sensitivity not found", __func__);
920 goto done;
921 }
922 microphone.sensitivity = atof(attr[curIdx++]);
923 } else {
924 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
925 }
926
927 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
928 if (strcmp(attr[curIdx++], "max_spl")) {
929 ALOGE("%s: max_spl not found", __func__);
930 goto done;
931 }
932 microphone.max_spl = atof(attr[curIdx++]);
933 } else {
934 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
935 }
936
937 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
938 if (strcmp(attr[curIdx++], "min_spl")) {
939 ALOGE("%s: min_spl not found", __func__);
940 goto done;
941 }
942 microphone.min_spl = atof(attr[curIdx++]);
943 } else {
944 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
945 }
946
947 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
948 if (strcmp(attr[curIdx++], "orientation")) {
949 ALOGE("%s: orientation not found", __func__);
950 goto done;
951 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530952 char *context = NULL;
953 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530954 float orientation[3];
955 uint32_t idx = 0;
956 while (token) {
957 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800958 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530959 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530960 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530961 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530962 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530963 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530964 ALOGE("%s: orientation invalid", __func__);
965 goto done;
966 }
967 microphone.orientation.x = orientation[0];
968 microphone.orientation.y = orientation[1];
969 microphone.orientation.z = orientation[2];
970 } else {
971 microphone.orientation.x = 0.0f;
972 microphone.orientation.y = 0.0f;
973 microphone.orientation.z = 0.0f;
974 }
975
976 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
977 if (strcmp(attr[curIdx++], "geometric_location")) {
978 ALOGE("%s: geometric_location not found", __func__);
979 goto done;
980 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530981 char *context = NULL;
982 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530983 float geometric_location[3];
984 uint32_t idx = 0;
985 while (token) {
986 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800987 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530988 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530989 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530990 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530991 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530992 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530993 ALOGE("%s: geometric_location invalid", __func__);
994 goto done;
995 }
996 microphone.geometric_location.x = geometric_location[0];
997 microphone.geometric_location.y = geometric_location[1];
998 microphone.geometric_location.z = geometric_location[2];
999 } else {
1000 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1001 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1002 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
1003 }
1004
1005 platform_set_microphone_characteristic(my_data.platform, microphone);
1006done:
1007 return;
1008}
1009
1010static void process_snd_dev(const XML_Char **attr)
1011{
1012 uint32_t curIdx = 0;
1013 in_snd_device = SND_DEVICE_NONE;
1014
1015 if (strcmp(attr[curIdx++], "in_snd_device")) {
1016 ALOGE("%s: snd_device not found", __func__);
1017 return;
1018 }
1019 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
1020 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
1021 in_snd_device >= SND_DEVICE_IN_END) {
1022 ALOGE("%s: Sound device not valid", __func__);
1023 in_snd_device = SND_DEVICE_NONE;
1024 }
1025
1026 return;
1027}
1028
1029static void process_mic_info(const XML_Char **attr)
1030{
1031 uint32_t curIdx = 0;
1032 struct mic_info microphone;
1033
1034 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
1035 sizeof(microphone.channel_mapping));
1036
1037 if (strcmp(attr[curIdx++], "mic_device_id")) {
1038 ALOGE("%s: mic_device_id not found", __func__);
1039 goto on_error;
1040 }
1041 strlcpy(microphone.device_id,
1042 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
1043
1044 if (strcmp(attr[curIdx++], "channel_mapping")) {
1045 ALOGE("%s: channel_mapping not found", __func__);
1046 goto on_error;
1047 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301048 char *context = NULL;
1049 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301050 uint32_t idx = 0;
1051 while (token) {
1052 if (!find_enum_by_string(mic_channel_mapping, token,
1053 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
1054 &microphone.channel_mapping[idx++])) {
1055 ALOGE("%s: channel_mapping %s in %s not found!",
1056 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
1057 goto on_error;
1058 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +05301059 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301060 }
1061 microphone.channel_count = idx;
1062
1063 platform_set_microphone_map(my_data.platform, in_snd_device,
1064 &microphone);
1065 return;
1066on_error:
1067 in_snd_device = SND_DEVICE_NONE;
1068 return;
1069}
1070
1071
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301072/* process acdb meta info key value */
1073static void process_acdb_metainfo_key(const XML_Char **attr)
1074{
1075 if (strcmp(attr[0], "name") != 0) {
1076 ALOGE("%s: 'name' not found", __func__);
1077 goto done;
1078 }
1079
1080 if (strcmp(attr[2], "value") != 0) {
1081 ALOGE("%s: 'value' not found", __func__);
1082 goto done;
1083 }
1084
1085 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001086 switch(my_data.caller) {
1087 case ACDB_EXTN:
1088 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1089 ALOGE("%s: key %d was not set!", __func__, key);
1090 goto done;
1091 }
1092 break;
1093 case PLATFORM:
1094 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1095 ALOGE("%s: key %d was not set!", __func__, key);
1096 goto done;
1097 }
1098 break;
1099 default:
1100 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301101 }
1102
1103done:
1104 return;
1105}
1106
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301107static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1108{
1109 uint32_t attr_idx = 0;
1110 int32_t in_ch_idx = -1;
1111 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1112
1113 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1114 &mtmx_in_params_info);
1115 if (mtmx_in_params == NULL) {
1116 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1117 return;
1118 }
1119
1120 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1121 ALOGE("%s: 'in_channel_index' not found", __func__);
1122 return;
1123 }
1124
1125 in_ch_idx = atoi((char *)attr[attr_idx++]);
1126 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1127 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1128 return;
1129 }
1130
1131 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1132 ALOGE("%s: 'channel_count' not found", __func__);
1133 return;
1134 }
1135 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1136
1137 if (strcmp(attr[attr_idx++], "device") != 0) {
1138 ALOGE("%s: 'device' not found", __func__);
1139 return;
1140 }
1141 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1142 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1143
1144 if (strcmp(attr[attr_idx++], "interface") != 0) {
1145 ALOGE("%s: 'interface' not found", __func__);
1146 return;
1147 }
1148 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1149 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1150
1151 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1152 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1153 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1154 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1155 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1156 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1157 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1158 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1159
1160 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1161}
1162
1163static void process_custom_mtmx_in_params(const XML_Char **attr)
1164{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301165 int attr_idx = 0, i = 0;
1166 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301167
1168 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1169 ALOGE("%s: 'usecase' not found", __func__);
1170 return;
1171 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301172 /* Check if multi usecases are supported for this custom mtrx params */
1173 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1174 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1175 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1176 value = strtok_r(NULL, ",", &context);
1177 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301178
1179 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1180 ALOGE("%s: 'out_channel_count' not found", __func__);
1181 return;
1182 }
1183 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1184
1185 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1186
1187}
1188
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301189static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1190{
1191 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301192 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301193 char *context = NULL, *ch_coeff_value = NULL;
1194 struct audio_custom_mtmx_params *mtmx_params = NULL;
1195
1196 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1197 ALOGE("%s: 'out_channel_index' not found", __func__);
1198 return;
1199 }
1200 out_ch_idx = atoi((char *)attr[attr_idx++]);
1201
1202 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1203 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1204 return;
1205 }
1206
1207 if (strcmp(attr[attr_idx++], "values") != 0) {
1208 ALOGE("%s: 'values' not found", __func__);
1209 return;
1210 }
1211 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301212 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301213 if (mtmx_params == NULL) {
1214 ALOGE("%s: mtmx params with given param info, not found", __func__);
1215 return;
1216 }
1217 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1218 ip_channels = mtmx_params->info.ip_channels;
1219 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301220 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301221 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1222 = atoi(ch_coeff_value);
1223 ch_coeff_value = strtok_r(NULL, " ", &context);
1224 }
1225 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1226 ch_coeff_value != NULL)
1227 ALOGE("%s: invalid/malformed coefficient values", __func__);
1228}
1229
1230static void process_custom_mtmx_params(const XML_Char **attr)
1231{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301232 int attr_idx = 0, i = 0;
1233 char *context = NULL, *value = NULL;
1234
1235 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301236
1237 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1238 ALOGE("%s: 'param_id' not found", __func__);
1239 return;
1240 }
1241 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1242
1243 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1244 ALOGE("%s: 'in_channel_count' not found", __func__);
1245 return;
1246 }
1247 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1248
1249 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1250 ALOGE("%s: 'out_channel_count' not found", __func__);
1251 return;
1252 }
1253 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1254
1255 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1256 ALOGE("%s: 'usecase' not found", __func__);
1257 return;
1258 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301259
1260 /* check if multi usecases are supported for this custom mtrx params */
1261 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1262 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1263 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1264 value = strtok_r(NULL, ",", &context);
1265 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301266
1267 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1268 ALOGE("%s: 'snd_device' not found", __func__);
1269 return;
1270 }
1271 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301272
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301273 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1274 i = 0;
1275 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1276 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1277 mtmx_params_info.fe_id[i++] = atoi(value);
1278 value = strtok_r(NULL, ",", &context);
1279 }
1280
1281 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301282 }
1283
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301284 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1285
1286}
1287
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001288static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001289 const XML_Char **attr)
1290{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001291 if (my_data.caller == ACDB_EXTN) {
1292 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1293 section = ACDB_METAINFO_KEY;
1294 } else if (strcmp(tag_name, "param") == 0) {
1295 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1296 ALOGE("param tag only supported with CONFIG_PARAMS section");
1297 return;
1298 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001299
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001300 section_process_fn fn = section_table[section];
1301 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001302 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001303 } else if(my_data.caller == PLATFORM) {
1304 if (strcmp(tag_name, "bit_width_configs") == 0) {
1305 section = BITWIDTH;
1306 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1307 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001308 } else if (strcmp(tag_name, "module_ids") == 0) {
1309 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001310 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1311 section = PCM_ID;
1312 } else if (strcmp(tag_name, "backend_names") == 0) {
1313 section = BACKEND_NAME;
1314 } else if (strcmp(tag_name, "config_params") == 0) {
1315 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001316 } else if (strcmp(tag_name, "operator_specific") == 0) {
1317 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001318 } else if (strcmp(tag_name, "interface_names") == 0) {
1319 section = INTERFACE_NAME;
1320 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1321 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001322 } else if (strcmp(tag_name, "app_types") == 0) {
1323 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001324 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1325 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301326 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1327 section = MICROPHONE_CHARACTERISTIC;
1328 } else if (strcmp(tag_name, "snd_devices") == 0) {
1329 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001330 } else if (strcmp(tag_name, "device") == 0) {
Guodong Hu1d46f342019-06-28 16:57:30 +08001331 if ((section != ACDB) && (section != AEC) && (section != NS) && (section != MMSECNS) &&
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001332 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001333 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001334 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1335 return;
1336 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001337
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001338 /* call into process function for the current section */
1339 section_process_fn fn = section_table[section];
1340 fn(attr);
1341 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1342 if (section != GAIN_LEVEL_MAPPING) {
1343 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1344 return;
1345 }
1346
1347 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1348 fn(attr);
1349 } else if (strcmp(tag_name, "usecase") == 0) {
1350 if (section != PCM_ID) {
1351 ALOGE("usecase tag only supported with PCM_ID section");
1352 return;
1353 }
1354
1355 section_process_fn fn = section_table[PCM_ID];
1356 fn(attr);
1357 } else if (strcmp(tag_name, "param") == 0) {
1358 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1359 ALOGE("param tag only supported with CONFIG_PARAMS section");
1360 return;
1361 }
1362
1363 section_process_fn fn = section_table[section];
1364 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301365 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001366 if (section != MODULE) {
1367 ALOGE("aec tag only supported with MODULE section");
1368 return;
1369 }
1370 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301371 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001372 if (section != MODULE) {
1373 ALOGE("ns tag only supported with MODULE section");
1374 return;
1375 }
1376 section = NS;
Guodong Hu1d46f342019-06-28 16:57:30 +08001377 } else if (strcmp(tag_name, "mmsecns") == 0) {
1378 if (section != MODULE) {
1379 ALOGE("mmsecns tag only supported with MODULE section");
1380 return;
1381 }
1382 section = MMSECNS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001383 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1384 if (section != GAIN_LEVEL_MAPPING) {
1385 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1386 return;
1387 }
1388
1389 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1390 fn(attr);
1391 } else if (!strcmp(tag_name, "app")) {
1392 if (section != APP_TYPE) {
1393 ALOGE("app tag only valid in section APP_TYPE");
1394 return;
1395 }
1396
1397 section_process_fn fn = section_table[APP_TYPE];
1398 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301399 } else if (strcmp(tag_name, "microphone") == 0) {
1400 if (section != MICROPHONE_CHARACTERISTIC) {
1401 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1402 return;
1403 }
1404 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1405 fn(attr);
1406 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1407 if (section != SND_DEVICES) {
1408 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1409 return;
1410 }
1411 section = INPUT_SND_DEVICE;
1412 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1413 if (section != INPUT_SND_DEVICE) {
1414 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1415 return;
1416 }
1417 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1418 } else if (strcmp(tag_name, "snd_dev") == 0) {
1419 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1420 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1421 return;
1422 }
1423 section_process_fn fn = section_table[SND_DEV];
1424 fn(attr);
1425 } else if (strcmp(tag_name, "mic_info") == 0) {
1426 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1427 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1428 return;
1429 }
1430 if (in_snd_device == SND_DEVICE_NONE) {
1431 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1432 return;
1433 }
1434 section_process_fn fn = section_table[MIC_INFO];
1435 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301436 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1437 if (section != ROOT) {
1438 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1439 return;
1440 }
1441 section = CUSTOM_MTMX_PARAMS;
1442 section_process_fn fn = section_table[section];
1443 fn(attr);
1444 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1445 if (section != CUSTOM_MTMX_PARAMS) {
1446 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1447 return;
1448 }
1449 section = CUSTOM_MTMX_PARAM_COEFFS;
1450 section_process_fn fn = section_table[section];
1451 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001452 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1453 section = EXTERNAL_DEVICE_SPECIFIC;
1454 } else if (strcmp(tag_name, "ext_device") == 0) {
1455 section_process_fn fn = section_table[section];
1456 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301457 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1458 if (section != ROOT) {
1459 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1460 return;
1461 }
1462 section = CUSTOM_MTMX_IN_PARAMS;
1463 section_process_fn fn = section_table[section];
1464 fn(attr);
1465 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1466 if (section != CUSTOM_MTMX_IN_PARAMS) {
1467 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1468 return;
1469 }
1470 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
Robert Lee58215542019-07-15 20:55:12 +08001471 } else if (strcmp(tag_name, "snd_device_delay") == 0) {
1472 section = SND_DEV_DELAY;
1473 } else if (strcmp(tag_name, "device_delay") == 0) {
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301474 section_process_fn fn = section_table[section];
1475 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301476 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001477 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001478 if(strcmp(tag_name, "config_params") == 0) {
1479 section = CONFIG_PARAMS;
1480 } else if (strcmp(tag_name, "param") == 0) {
1481 if (section != CONFIG_PARAMS) {
1482 ALOGE("param tag only supported with CONFIG_PARAMS section");
1483 return;
1484 }
1485
1486 section_process_fn fn = section_table[section];
1487 fn(attr);
1488 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001489 }
Ben Romberger55886882014-01-10 13:49:02 -08001490 return;
1491}
1492
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001493static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001494{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001495 if (strcmp(tag_name, "bit_width_configs") == 0) {
1496 section = ROOT;
1497 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001498 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001499 } else if (strcmp(tag_name, "module_ids") == 0) {
1500 section = ROOT;
1501 } else if (strcmp(tag_name, "aec") == 0) {
1502 section = MODULE;
1503 } else if (strcmp(tag_name, "ns") == 0) {
1504 section = MODULE;
Guodong Hu1d46f342019-06-28 16:57:30 +08001505 } else if (strcmp(tag_name, "mmsecns") == 0) {
1506 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001507 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1508 section = ROOT;
1509 } else if (strcmp(tag_name, "backend_names") == 0) {
1510 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001511 } else if (strcmp(tag_name, "config_params") == 0) {
1512 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001513 } else if (strcmp(tag_name, "operator_specific") == 0) {
1514 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001515 } else if (strcmp(tag_name, "interface_names") == 0) {
1516 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001517 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1518 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001519 } else if (strcmp(tag_name, "app_types") == 0) {
1520 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301521 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1522 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301523 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1524 section = ROOT;
1525 } else if (strcmp(tag_name, "snd_devices") == 0) {
1526 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001527 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1528 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301529 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1530 section = SND_DEVICES;
1531 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1532 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301533 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1534 section = ROOT;
1535 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1536 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301537 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1538 section = ROOT;
1539 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1540 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001541 }
Ben Romberger55886882014-01-10 13:49:02 -08001542}
1543
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001544int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001545{
1546 XML_Parser parser;
1547 FILE *file;
1548 int ret = 0;
1549 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001550 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001551 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001552
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001553 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001554 if (filename == NULL)
1555 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1556 MIXER_PATH_MAX_LENGTH);
1557 else
1558 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1559
1560 ALOGV("%s: platform info file name is %s", __func__,
1561 platform_info_file_name);
1562
1563 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001564 section = ROOT;
1565
Ben Romberger55886882014-01-10 13:49:02 -08001566 if (!file) {
1567 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001568 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001569 ret = -ENODEV;
1570 goto done;
1571 }
1572
1573 parser = XML_ParserCreate(NULL);
1574 if (!parser) {
1575 ALOGE("%s: Failed to create XML parser!", __func__);
1576 ret = -ENODEV;
1577 goto err_close_file;
1578 }
1579
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001580 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001581 my_data.platform = platform;
1582 my_data.kvpairs = str_parms_create();
1583
Ben Romberger55886882014-01-10 13:49:02 -08001584 XML_SetElementHandler(parser, start_tag, end_tag);
1585
1586 while (1) {
1587 buf = XML_GetBuffer(parser, BUF_SIZE);
1588 if (buf == NULL) {
1589 ALOGE("%s: XML_GetBuffer failed", __func__);
1590 ret = -ENOMEM;
1591 goto err_free_parser;
1592 }
1593
1594 bytes_read = fread(buf, 1, BUF_SIZE, file);
1595 if (bytes_read < 0) {
1596 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1597 ret = bytes_read;
1598 goto err_free_parser;
1599 }
1600
1601 if (XML_ParseBuffer(parser, bytes_read,
1602 bytes_read == 0) == XML_STATUS_ERROR) {
1603 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001604 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001605 ret = -EINVAL;
1606 goto err_free_parser;
1607 }
1608
1609 if (bytes_read == 0)
1610 break;
1611 }
1612
Ben Romberger55886882014-01-10 13:49:02 -08001613err_free_parser:
1614 XML_ParserFree(parser);
1615err_close_file:
1616 fclose(file);
1617done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001618 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001619 return ret;
1620}