blob: b0e83b36472de29675438b182413bfc4be67d92f [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>
Aalique Grahame22e49102018-12-18 14:23:57 -080036#include <log/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070037#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080038#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070039#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080040#include "platform_api.h"
41#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070042#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080043
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053044#ifdef DYNAMIC_LOG_ENABLED
45#include <log_xml_parser.h>
46#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
47#include <log_utils.h>
48#endif
49
Ben Romberger55886882014-01-10 13:49:02 -080050#define BUF_SIZE 1024
51
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070052typedef enum {
53 ROOT,
54 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070055 MODULE,
56 AEC,
57 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070058 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070059 PCM_ID,
60 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080061 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070062 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080063 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070064 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080065 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053066 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053067 MICROPHONE_CHARACTERISTIC,
68 SND_DEVICES,
69 INPUT_SND_DEVICE,
70 INPUT_SND_DEVICE_TO_MIC_MAPPING,
71 SND_DEV,
72 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053073 CUSTOM_MTMX_PARAMS,
74 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070075 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053076 CUSTOM_MTMX_IN_PARAMS,
77 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Ethan Chen97564d42014-09-05 13:01:26 -070078 DEVICE_NAME,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070079} section_t;
80
81typedef void (* section_process_fn)(const XML_Char **attr);
82
83static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070084static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
85static void process_effect_aec(const XML_Char **attr);
86static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070087static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070088static void process_pcm_id(const XML_Char **attr);
89static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080090static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070091static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070092static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080093static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070094static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080095static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053096static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053097static void process_microphone_characteristic(const XML_Char **attr);
98static void process_snd_dev(const XML_Char **attr);
99static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530100static void process_custom_mtmx_params(const XML_Char **attr);
101static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700102static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530103static void process_custom_mtmx_in_params(const XML_Char **attr);
104static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Ethan Chen97564d42014-09-05 13:01:26 -0700105static void process_device_name(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700106
107static section_process_fn section_table[] = {
108 [ROOT] = process_root,
109 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700110 [AEC] = process_effect_aec,
111 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700112 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700113 [PCM_ID] = process_pcm_id,
114 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800115 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700116 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800117 [OPERATOR_SPECIFIC] = process_operator_specific,
118 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700119 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530120 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530121 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
122 [SND_DEV] = process_snd_dev,
123 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530124 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
125 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700126 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530127 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
128 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Ethan Chen97564d42014-09-05 13:01:26 -0700129 [DEVICE_NAME] = process_device_name,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700130};
131
132static section_t section;
133
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700134struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700135 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700136 void *platform;
137 struct str_parms *kvpairs;
138};
139
140static struct platform_info my_data;
Weiyin Jiang63f4d8c2019-09-06 16:59:32 +0800141static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700142
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530143
144struct audio_string_to_enum {
145 const char* name;
146 unsigned int value;
147};
148
149static snd_device_t in_snd_device;
150
151static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
152 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
153 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
154 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
155 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
156};
157
158static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
163 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
165};
166
167static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
171};
172
173static const struct audio_string_to_enum device_in_types[] = {
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
199 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
200 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
201};
202
203enum {
204 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
205 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
206 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
207 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
208 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
209 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
210 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
211 | ORIENTATION) | GEOMETRIC_LOCATION) */
212};
213
214static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
215 int32_t len, unsigned int *value)
216{
217 if (table == NULL) {
218 ALOGE("%s: table is NULL", __func__);
219 return false;
220 }
221
222 if (name == NULL) {
223 ALOGE("null key");
224 return false;
225 }
226
227 for (int i = 0; i < len; i++) {
228 if (!strcmp(table[i].name, name)) {
229 *value = table[i].value;
230 return true;
231 }
232 }
233 return false;
234}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530235
236static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530237static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530238
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700239/*
240 * <audio_platform_info>
241 * <acdb_ids>
242 * <device name="???" acdb_id="???"/>
243 * ...
244 * ...
245 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700246 * <module_ids>
247 * <device name="???" module_id="???"/>
248 * ...
249 * ...
250 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700251 * <backend_names>
252 * <device name="???" backend="???"/>
253 * ...
254 * ...
255 * </backend_names>
256 * <pcm_ids>
257 * <usecase name="???" type="in/out" id="???"/>
258 * ...
259 * ...
260 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800261 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530262 * <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 -0800263 * ...
264 * ...
265 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700266 * <config_params>
267 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800268 * <param key="operator_info" value="tmus;aa;bb;cc"/>
269 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700270 * ...
271 * ...
272 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800273 *
274 * <operator_specific>
275 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
276 * ...
277 * ...
278 * </operator_specific>
279 *
Ethan Chen97564d42014-09-05 13:01:26 -0700280 * <device_names>
281 * <device name="???" alias="???"/>
282 * ...
283 * ...
284 * </device_names>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700285 * </audio_platform_info>
286 */
287
288static void process_root(const XML_Char **attr __unused)
289{
290}
291
292/* mapping from usecase to pcm dev id */
293static void process_pcm_id(const XML_Char **attr)
294{
295 int index;
296
297 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700298 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700299 goto done;
300 }
301
302 index = platform_get_usecase_index((char *)attr[1]);
303 if (index < 0) {
304 ALOGE("%s: usecase %s not found!",
305 __func__, attr[1]);
306 goto done;
307 }
308
309 if (strcmp(attr[2], "type") != 0) {
310 ALOGE("%s: usecase type not mentioned", __func__);
311 goto done;
312 }
313
314 int type = -1;
315
316 if (!strcasecmp((char *)attr[3], "in")) {
317 type = 1;
318 } else if (!strcasecmp((char *)attr[3], "out")) {
319 type = 0;
320 } else {
321 ALOGE("%s: type must be IN or OUT", __func__);
322 goto done;
323 }
324
325 if (strcmp(attr[4], "id") != 0) {
326 ALOGE("%s: usecase id not mentioned", __func__);
327 goto done;
328 }
329
330 int id = atoi((char *)attr[5]);
331
332 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
333 ALOGE("%s: usecase %s type %d id %d was not set!",
334 __func__, attr[1], type, id);
335 goto done;
336 }
337
338done:
339 return;
340}
341
342/* backend to be used for a device */
343static void process_backend_name(const XML_Char **attr)
344{
345 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530346 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530347 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700348
349 if (strcmp(attr[0], "name") != 0) {
350 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
351 goto done;
352 }
353
354 index = platform_get_snd_device_index((char *)attr[1]);
355 if (index < 0) {
356 ALOGE("%s: Device %s not found, no ACDB ID set!",
357 __func__, attr[1]);
358 goto done;
359 }
360
361 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530362 if (strcmp(attr[2], "interface") == 0)
363 hw_interface = (char *)attr[3];
364 } else {
365 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700366 }
367
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530368 if (attr[4] != NULL) {
369 if (strcmp(attr[4], "interface") != 0) {
370 hw_interface = NULL;
371 } else {
372 hw_interface = (char *)attr[5];
373 }
374 }
375
Ashish Jaind150d4c2017-02-03 18:44:34 +0530376 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700377 ALOGE("%s: Device %s backend %s was not set!",
378 __func__, attr[1], attr[3]);
379 goto done;
380 }
381
382done:
383 return;
384}
385
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700386static void process_gain_db_to_level_map(const XML_Char **attr)
387{
388 struct amp_db_and_gain_table tbl_entry;
389
390 if ((strcmp(attr[0], "db") != 0) ||
391 (strcmp(attr[2], "level") != 0)) {
392 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
393 __func__, attr[0], attr[2]);
394 goto done;
395 }
396
397 tbl_entry.db = atof(attr[1]);
398 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
399 tbl_entry.level = atoi(attr[3]);
400
Aalique Grahame22e49102018-12-18 14:23:57 -0800401 //custome level should be > 0. Level 0 is fixed for default
402 CHECK(tbl_entry.level > 0);
403
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700404 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
405 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
406 platform_add_gain_level_mapping(&tbl_entry);
407
408done:
409 return;
410}
411
412
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700413static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800414{
Ben Romberger61764e32014-01-10 13:49:02 -0800415 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800416
Ben Romberger61764e32014-01-10 13:49:02 -0800417 if (strcmp(attr[0], "name") != 0) {
418 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800419 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800420 }
Ben Romberger55886882014-01-10 13:49:02 -0800421
Ben Romberger61764e32014-01-10 13:49:02 -0800422 index = platform_get_snd_device_index((char *)attr[1]);
423 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800424 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
425 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800426 goto done;
427 }
428
429 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800430 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
431 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800432 goto done;
433 }
434
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700435 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
436 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800437 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800438 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800439 }
Ben Romberger55886882014-01-10 13:49:02 -0800440
Ben Romberger55886882014-01-10 13:49:02 -0800441done:
442 return;
443}
444
Aalique Grahame22e49102018-12-18 14:23:57 -0800445static void process_operator_specific(const XML_Char **attr)
446{
447 snd_device_t snd_device = SND_DEVICE_NONE;
448
449 if (strcmp(attr[0], "name") != 0) {
450 ALOGE("%s: 'name' not found", __func__);
451 goto done;
452 }
453
454 snd_device = platform_get_snd_device_index((char *)attr[1]);
455 if (snd_device < 0) {
456 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
457 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
458 goto done;
459 }
460
461 if (strcmp(attr[2], "operator") != 0) {
462 ALOGE("%s: 'operator' not found", __func__);
463 goto done;
464 }
465
466 if (strcmp(attr[4], "mixer_path") != 0) {
467 ALOGE("%s: 'mixer_path' not found", __func__);
468 goto done;
469 }
470
471 if (strcmp(attr[6], "acdb_id") != 0) {
472 ALOGE("%s: 'acdb_id' not found", __func__);
473 goto done;
474 }
475
476 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
477
478done:
479 return;
480}
481
Carter Hsu32a62362018-10-15 15:01:42 -0700482static void process_external_dev(const XML_Char **attr)
483{
484 snd_device_t snd_device = SND_DEVICE_NONE;
485
486 if (strcmp(attr[0], "name") != 0) {
487 ALOGE("%s: 'name' not found", __func__);
488 goto done;
489 }
490
491 snd_device = platform_get_snd_device_index((char *)attr[1]);
492 if (snd_device < 0) {
493 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
494 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
495 goto done;
496 }
497
498 if (strcmp(attr[2], "usbid") != 0) {
499 ALOGE("%s: 'usbid' not found", __func__);
500 goto done;
501 }
502
503 if (strcmp(attr[4], "acdb_id") != 0) {
504 ALOGE("%s: 'acdb_id' not found", __func__);
505 goto done;
506 }
507
508 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
509
510done:
511 return;
512}
513
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700514static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
515{
516 int index;
517 struct audio_effect_config effect_config;
518
519 if (strcmp(attr[0], "name") != 0) {
520 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
521 goto done;
522 }
523
524 index = platform_get_snd_device_index((char *)attr[1]);
525 if (index < 0) {
526 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
527 __func__, attr[1]);
528 goto done;
529 }
530
531 if (strcmp(attr[2], "module_id") != 0) {
532 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
533 __func__, attr[2]);
534 goto done;
535 }
536
537 if (strcmp(attr[4], "instance_id") != 0) {
538 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
539 __func__, attr[4]);
540 goto done;
541 }
542
543 if (strcmp(attr[6], "param_id") != 0) {
544 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
545 __func__, attr[6]);
546 goto done;
547 }
548
549 if (strcmp(attr[8], "param_value") != 0) {
550 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
551 __func__, attr[8]);
552 goto done;
553 }
554
555 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
556 strtol((char *)attr[5], NULL, 0),
557 strtol((char *)attr[7], NULL, 0),
558 strtol((char *)attr[9], NULL, 0)};
559
560
561 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
562 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
563 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
564 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
565 strtol((char *)attr[9], NULL, 0));
566 goto done;
567 }
568
569done:
570 return;
571}
572
573static void process_effect_aec(const XML_Char **attr)
574{
575 process_audio_effect(attr, EFFECT_AEC);
576 return;
577}
578
579static void process_effect_ns(const XML_Char **attr)
580{
581 process_audio_effect(attr, EFFECT_NS);
582 return;
583}
584
Amit Shekhar5a39c912014-10-14 15:39:30 -0700585static void process_bit_width(const XML_Char **attr)
586{
587 int index;
588
589 if (strcmp(attr[0], "name") != 0) {
590 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
591 goto done;
592 }
593
594 index = platform_get_snd_device_index((char *)attr[1]);
595 if (index < 0) {
596 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
597 __func__, attr[1]);
598 goto done;
599 }
600
601 if (strcmp(attr[2], "bit_width") != 0) {
602 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
603 __func__, attr[1]);
604 goto done;
605 }
606
607 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
608 ALOGE("%s: Device %s, ACDB ID %d was not set!",
609 __func__, attr[1], atoi((char *)attr[3]));
610 goto done;
611 }
612
613done:
614 return;
615}
616
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800617static void process_interface_name(const XML_Char **attr)
618{
619 int ret;
620
621 if (strcmp(attr[0], "name") != 0) {
622 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
623
624 goto done;
625 }
626
627 if (strcmp(attr[2], "interface") != 0) {
628 ALOGE("%s: Device %s has no Audio Interface set!",
629 __func__, attr[1]);
630
631 goto done;
632 }
633
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530634 if (strcmp(attr[4], "codec_type") != 0) {
635 ALOGE("%s: Device %s has no codec type set!",
636 __func__, attr[1]);
637
638 goto done;
639 }
640
641 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
642 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800643 if (ret < 0) {
644 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800645 goto done;
646 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800647
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800648done:
649 return;
650}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530651
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700652static void process_config_params(const XML_Char **attr)
653{
654 if (strcmp(attr[0], "key") != 0) {
655 ALOGE("%s: 'key' not found", __func__);
656 goto done;
657 }
658
659 if (strcmp(attr[2], "value") != 0) {
660 ALOGE("%s: 'value' not found", __func__);
661 goto done;
662 }
663
664 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700665 if (my_data.caller == PLATFORM)
666 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700667done:
668 return;
669}
670
Aalique Grahame22e49102018-12-18 14:23:57 -0800671static void process_app_type(const XML_Char **attr)
672{
673 if (strcmp(attr[0], "uc_type")) {
674 ALOGE("%s: uc_type not found", __func__);
675 goto done;
676 }
677
678 if (strcmp(attr[2], "mode")) {
679 ALOGE("%s: mode not found", __func__);
680 goto done;
681 }
682
683 if (strcmp(attr[4], "bit_width")) {
684 ALOGE("%s: bit_width not found", __func__);
685 goto done;
686 }
687
688 if (strcmp(attr[6], "id")) {
689 ALOGE("%s: id not found", __func__);
690 goto done;
691 }
692
693 if (strcmp(attr[8], "max_rate")) {
694 ALOGE("%s: max rate not found", __func__);
695 goto done;
696 }
697
698 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
699 atoi(attr[9]));
700done:
701 return;
702}
703
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530704static void process_microphone_characteristic(const XML_Char **attr) {
705 struct audio_microphone_characteristic_t microphone;
706 uint32_t curIdx = 0;
707
708 if (strcmp(attr[curIdx++], "valid_mask")) {
709 ALOGE("%s: valid_mask not found", __func__);
710 goto done;
711 }
712 uint32_t valid_mask = atoi(attr[curIdx++]);
713
714 if (strcmp(attr[curIdx++], "device_id")) {
715 ALOGE("%s: device_id not found", __func__);
716 goto done;
717 }
718 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
719 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
720 goto done;
721 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530722 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530723
724 if (strcmp(attr[curIdx++], "type")) {
725 ALOGE("%s: device not found", __func__);
726 goto done;
727 }
728 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
729 ARRAY_SIZE(device_in_types), &microphone.device)) {
730 ALOGE("%s: type %s in %s not found!",
731 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
732 goto done;
733 }
734
735 if (strcmp(attr[curIdx++], "address")) {
736 ALOGE("%s: address not found", __func__);
737 goto done;
738 }
739 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
740 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
741 goto done;
742 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530743 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530744 if (strlen(microphone.address) == 0) {
745 // If the address is empty, populate the address according to device type.
746 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530747 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530748 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530749 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530750 }
751 }
752
753 if (strcmp(attr[curIdx++], "location")) {
754 ALOGE("%s: location not found", __func__);
755 goto done;
756 }
757 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
758 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
759 ALOGE("%s: location %s in %s not found!",
760 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
761 goto done;
762 }
763
764 if (strcmp(attr[curIdx++], "group")) {
765 ALOGE("%s: group not found", __func__);
766 goto done;
767 }
768 microphone.group = atoi(attr[curIdx++]);
769
770 if (strcmp(attr[curIdx++], "index_in_the_group")) {
771 ALOGE("%s: index_in_the_group not found", __func__);
772 goto done;
773 }
774 microphone.index_in_the_group = atoi(attr[curIdx++]);
775
776 if (strcmp(attr[curIdx++], "directionality")) {
777 ALOGE("%s: directionality not found", __func__);
778 goto done;
779 }
780 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
781 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
782 ALOGE("%s: directionality %s in %s not found!",
783 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
784 goto done;
785 }
786
787 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
788 ALOGE("%s: num_frequency_responses not found", __func__);
789 goto done;
790 }
791 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530792 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530793 ALOGE("%s: num_frequency_responses is too large", __func__);
794 goto done;
795 }
796 if (microphone.num_frequency_responses > 0) {
797 if (strcmp(attr[curIdx++], "frequencies")) {
798 ALOGE("%s: frequencies not found", __func__);
799 goto done;
800 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530801 char *context = NULL;
802 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530803 uint32_t num_frequencies = 0;
804 while (token) {
805 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800806 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530807 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530808 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530809 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530810 }
811
812 if (strcmp(attr[curIdx++], "responses")) {
813 ALOGE("%s: responses not found", __func__);
814 goto done;
815 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530816 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530817 uint32_t num_responses = 0;
818 while (token) {
819 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800820 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530821 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530822 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530823 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530824 }
825
826 if (num_frequencies != num_responses
827 || num_frequencies != microphone.num_frequency_responses) {
828 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
829 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
830 goto done;
831 }
832 }
833
834 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
835 if (strcmp(attr[curIdx++], "sensitivity")) {
836 ALOGE("%s: sensitivity not found", __func__);
837 goto done;
838 }
839 microphone.sensitivity = atof(attr[curIdx++]);
840 } else {
841 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
842 }
843
844 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
845 if (strcmp(attr[curIdx++], "max_spl")) {
846 ALOGE("%s: max_spl not found", __func__);
847 goto done;
848 }
849 microphone.max_spl = atof(attr[curIdx++]);
850 } else {
851 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
852 }
853
854 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
855 if (strcmp(attr[curIdx++], "min_spl")) {
856 ALOGE("%s: min_spl not found", __func__);
857 goto done;
858 }
859 microphone.min_spl = atof(attr[curIdx++]);
860 } else {
861 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
862 }
863
864 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
865 if (strcmp(attr[curIdx++], "orientation")) {
866 ALOGE("%s: orientation not found", __func__);
867 goto done;
868 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530869 char *context = NULL;
870 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530871 float orientation[3];
872 uint32_t idx = 0;
873 while (token) {
874 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800875 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530876 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530877 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530878 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530879 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530880 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530881 ALOGE("%s: orientation invalid", __func__);
882 goto done;
883 }
884 microphone.orientation.x = orientation[0];
885 microphone.orientation.y = orientation[1];
886 microphone.orientation.z = orientation[2];
887 } else {
888 microphone.orientation.x = 0.0f;
889 microphone.orientation.y = 0.0f;
890 microphone.orientation.z = 0.0f;
891 }
892
893 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
894 if (strcmp(attr[curIdx++], "geometric_location")) {
895 ALOGE("%s: geometric_location not found", __func__);
896 goto done;
897 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530898 char *context = NULL;
899 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530900 float geometric_location[3];
901 uint32_t idx = 0;
902 while (token) {
903 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800904 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530905 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530906 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530907 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530908 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530909 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530910 ALOGE("%s: geometric_location invalid", __func__);
911 goto done;
912 }
913 microphone.geometric_location.x = geometric_location[0];
914 microphone.geometric_location.y = geometric_location[1];
915 microphone.geometric_location.z = geometric_location[2];
916 } else {
917 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
918 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
919 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
920 }
921
922 platform_set_microphone_characteristic(my_data.platform, microphone);
923done:
924 return;
925}
926
927static void process_snd_dev(const XML_Char **attr)
928{
929 uint32_t curIdx = 0;
930 in_snd_device = SND_DEVICE_NONE;
931
932 if (strcmp(attr[curIdx++], "in_snd_device")) {
933 ALOGE("%s: snd_device not found", __func__);
934 return;
935 }
936 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
937 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
938 in_snd_device >= SND_DEVICE_IN_END) {
939 ALOGE("%s: Sound device not valid", __func__);
940 in_snd_device = SND_DEVICE_NONE;
941 }
942
943 return;
944}
945
946static void process_mic_info(const XML_Char **attr)
947{
948 uint32_t curIdx = 0;
949 struct mic_info microphone;
950
951 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
952 sizeof(microphone.channel_mapping));
953
954 if (strcmp(attr[curIdx++], "mic_device_id")) {
955 ALOGE("%s: mic_device_id not found", __func__);
956 goto on_error;
957 }
958 strlcpy(microphone.device_id,
959 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
960
961 if (strcmp(attr[curIdx++], "channel_mapping")) {
962 ALOGE("%s: channel_mapping not found", __func__);
963 goto on_error;
964 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530965 char *context = NULL;
966 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530967 uint32_t idx = 0;
968 while (token) {
969 if (!find_enum_by_string(mic_channel_mapping, token,
970 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
971 &microphone.channel_mapping[idx++])) {
972 ALOGE("%s: channel_mapping %s in %s not found!",
973 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
974 goto on_error;
975 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530976 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530977 }
978 microphone.channel_count = idx;
979
980 platform_set_microphone_map(my_data.platform, in_snd_device,
981 &microphone);
982 return;
983on_error:
984 in_snd_device = SND_DEVICE_NONE;
985 return;
986}
987
988
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530989/* process acdb meta info key value */
990static void process_acdb_metainfo_key(const XML_Char **attr)
991{
992 if (strcmp(attr[0], "name") != 0) {
993 ALOGE("%s: 'name' not found", __func__);
994 goto done;
995 }
996
997 if (strcmp(attr[2], "value") != 0) {
998 ALOGE("%s: 'value' not found", __func__);
999 goto done;
1000 }
1001
1002 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001003 switch(my_data.caller) {
1004 case ACDB_EXTN:
1005 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1006 ALOGE("%s: key %d was not set!", __func__, key);
1007 goto done;
1008 }
1009 break;
1010 case PLATFORM:
1011 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1012 ALOGE("%s: key %d was not set!", __func__, key);
1013 goto done;
1014 }
1015 break;
1016 default:
1017 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301018 }
1019
1020done:
1021 return;
1022}
1023
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301024static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1025{
1026 uint32_t attr_idx = 0;
1027 int32_t in_ch_idx = -1;
1028 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1029
1030 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1031 &mtmx_in_params_info);
1032 if (mtmx_in_params == NULL) {
1033 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1034 return;
1035 }
1036
1037 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1038 ALOGE("%s: 'in_channel_index' not found", __func__);
1039 return;
1040 }
1041
1042 in_ch_idx = atoi((char *)attr[attr_idx++]);
1043 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1044 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1045 return;
1046 }
1047
1048 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1049 ALOGE("%s: 'channel_count' not found", __func__);
1050 return;
1051 }
1052 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1053
1054 if (strcmp(attr[attr_idx++], "device") != 0) {
1055 ALOGE("%s: 'device' not found", __func__);
1056 return;
1057 }
1058 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1059 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1060
1061 if (strcmp(attr[attr_idx++], "interface") != 0) {
1062 ALOGE("%s: 'interface' not found", __func__);
1063 return;
1064 }
1065 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1066 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1067
1068 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1069 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1070 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1071 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1072 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1073 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1074 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1075 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1076
1077 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1078}
1079
1080static void process_custom_mtmx_in_params(const XML_Char **attr)
1081{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301082 int attr_idx = 0, i = 0;
1083 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301084
1085 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1086 ALOGE("%s: 'usecase' not found", __func__);
1087 return;
1088 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301089 /* Check if multi usecases are supported for this custom mtrx params */
1090 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1091 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1092 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1093 value = strtok_r(NULL, ",", &context);
1094 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301095
1096 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1097 ALOGE("%s: 'out_channel_count' not found", __func__);
1098 return;
1099 }
1100 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1101
1102 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1103
1104}
1105
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301106static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1107{
1108 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301109 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301110 char *context = NULL, *ch_coeff_value = NULL;
1111 struct audio_custom_mtmx_params *mtmx_params = NULL;
1112
1113 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1114 ALOGE("%s: 'out_channel_index' not found", __func__);
1115 return;
1116 }
1117 out_ch_idx = atoi((char *)attr[attr_idx++]);
1118
1119 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1120 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1121 return;
1122 }
1123
1124 if (strcmp(attr[attr_idx++], "values") != 0) {
1125 ALOGE("%s: 'values' not found", __func__);
1126 return;
1127 }
1128 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301129 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301130 if (mtmx_params == NULL) {
1131 ALOGE("%s: mtmx params with given param info, not found", __func__);
1132 return;
1133 }
1134 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1135 ip_channels = mtmx_params->info.ip_channels;
1136 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301137 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301138 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1139 = atoi(ch_coeff_value);
1140 ch_coeff_value = strtok_r(NULL, " ", &context);
1141 }
1142 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1143 ch_coeff_value != NULL)
1144 ALOGE("%s: invalid/malformed coefficient values", __func__);
1145}
1146
1147static void process_custom_mtmx_params(const XML_Char **attr)
1148{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301149 int attr_idx = 0, i = 0;
1150 char *context = NULL, *value = NULL;
1151
1152 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301153
1154 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1155 ALOGE("%s: 'param_id' not found", __func__);
1156 return;
1157 }
1158 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1159
1160 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1161 ALOGE("%s: 'in_channel_count' not found", __func__);
1162 return;
1163 }
1164 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1165
1166 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1167 ALOGE("%s: 'out_channel_count' not found", __func__);
1168 return;
1169 }
1170 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1171
1172 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1173 ALOGE("%s: 'usecase' not found", __func__);
1174 return;
1175 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301176
1177 /* check if multi usecases are supported for this custom mtrx params */
1178 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1179 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1180 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1181 value = strtok_r(NULL, ",", &context);
1182 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301183
1184 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1185 ALOGE("%s: 'snd_device' not found", __func__);
1186 return;
1187 }
1188 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301189
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301190 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1191 i = 0;
1192 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1193 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1194 mtmx_params_info.fe_id[i++] = atoi(value);
1195 value = strtok_r(NULL, ",", &context);
1196 }
1197
1198 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301199 }
1200
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301201 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
Ethan Chen97564d42014-09-05 13:01:26 -07001202}
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301203
Ethan Chen97564d42014-09-05 13:01:26 -07001204static void process_device_name(const XML_Char **attr)
1205{
1206 int index;
1207
1208 if (strcmp(attr[0], "name") != 0) {
1209 ALOGE("%s: 'name' not found, no alias set!", __func__);
1210 goto done;
1211 }
1212
1213 index = platform_get_snd_device_index((char *)attr[1]);
1214 if (index < 0) {
1215 ALOGE("%s: Device %s in platform info xml not found, no alias set!",
1216 __func__, attr[1]);
1217 goto done;
1218 }
1219
1220 if (strcmp(attr[2], "alias") != 0) {
1221 ALOGE("%s: Device %s in platform info xml has no alias, no alias set!",
1222 __func__, attr[1]);
1223 goto done;
1224 }
1225
1226 if (platform_set_snd_device_name(index, attr[3]) < 0) {
1227 ALOGE("%s: Device %s, alias %s was not set!",
1228 __func__, attr[1], attr[3]);
1229 goto done;
1230 }
1231
1232done:
1233 return;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301234}
1235
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001236static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001237 const XML_Char **attr)
1238{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001239 if (my_data.caller == ACDB_EXTN) {
1240 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1241 section = ACDB_METAINFO_KEY;
1242 } else if (strcmp(tag_name, "param") == 0) {
1243 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1244 ALOGE("param tag only supported with CONFIG_PARAMS section");
1245 return;
1246 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001247
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001248 section_process_fn fn = section_table[section];
1249 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001250 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001251 } else if(my_data.caller == PLATFORM) {
1252 if (strcmp(tag_name, "bit_width_configs") == 0) {
1253 section = BITWIDTH;
1254 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1255 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001256 } else if (strcmp(tag_name, "module_ids") == 0) {
1257 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001258 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1259 section = PCM_ID;
1260 } else if (strcmp(tag_name, "backend_names") == 0) {
1261 section = BACKEND_NAME;
1262 } else if (strcmp(tag_name, "config_params") == 0) {
1263 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001264 } else if (strcmp(tag_name, "operator_specific") == 0) {
1265 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001266 } else if (strcmp(tag_name, "interface_names") == 0) {
1267 section = INTERFACE_NAME;
1268 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1269 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001270 } else if (strcmp(tag_name, "app_types") == 0) {
1271 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001272 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1273 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301274 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1275 section = MICROPHONE_CHARACTERISTIC;
1276 } else if (strcmp(tag_name, "snd_devices") == 0) {
1277 section = SND_DEVICES;
Ethan Chen97564d42014-09-05 13:01:26 -07001278 } else if (strcmp(tag_name, "device_names") == 0) {
1279 section = DEVICE_NAME;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001280 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001281 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1282 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Ethan Chen97564d42014-09-05 13:01:26 -07001283 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC) &&
1284 (section != DEVICE_NAME)) {
1285 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface/device names");
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001286 return;
1287 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001288
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001289 /* call into process function for the current section */
1290 section_process_fn fn = section_table[section];
1291 fn(attr);
1292 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1293 if (section != GAIN_LEVEL_MAPPING) {
1294 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1295 return;
1296 }
1297
1298 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1299 fn(attr);
1300 } else if (strcmp(tag_name, "usecase") == 0) {
1301 if (section != PCM_ID) {
1302 ALOGE("usecase tag only supported with PCM_ID section");
1303 return;
1304 }
1305
1306 section_process_fn fn = section_table[PCM_ID];
1307 fn(attr);
1308 } else if (strcmp(tag_name, "param") == 0) {
1309 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1310 ALOGE("param tag only supported with CONFIG_PARAMS section");
1311 return;
1312 }
1313
1314 section_process_fn fn = section_table[section];
1315 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301316 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001317 if (section != MODULE) {
1318 ALOGE("aec tag only supported with MODULE section");
1319 return;
1320 }
1321 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301322 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001323 if (section != MODULE) {
1324 ALOGE("ns tag only supported with MODULE section");
1325 return;
1326 }
1327 section = NS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001328 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1329 if (section != GAIN_LEVEL_MAPPING) {
1330 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1331 return;
1332 }
1333
1334 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1335 fn(attr);
1336 } else if (!strcmp(tag_name, "app")) {
1337 if (section != APP_TYPE) {
1338 ALOGE("app tag only valid in section APP_TYPE");
1339 return;
1340 }
1341
1342 section_process_fn fn = section_table[APP_TYPE];
1343 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301344 } else if (strcmp(tag_name, "microphone") == 0) {
1345 if (section != MICROPHONE_CHARACTERISTIC) {
1346 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1347 return;
1348 }
1349 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1350 fn(attr);
1351 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1352 if (section != SND_DEVICES) {
1353 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1354 return;
1355 }
1356 section = INPUT_SND_DEVICE;
1357 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1358 if (section != INPUT_SND_DEVICE) {
1359 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1360 return;
1361 }
1362 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1363 } else if (strcmp(tag_name, "snd_dev") == 0) {
1364 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1365 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1366 return;
1367 }
1368 section_process_fn fn = section_table[SND_DEV];
1369 fn(attr);
1370 } else if (strcmp(tag_name, "mic_info") == 0) {
1371 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1372 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1373 return;
1374 }
1375 if (in_snd_device == SND_DEVICE_NONE) {
1376 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1377 return;
1378 }
1379 section_process_fn fn = section_table[MIC_INFO];
1380 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301381 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1382 if (section != ROOT) {
1383 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1384 return;
1385 }
1386 section = CUSTOM_MTMX_PARAMS;
1387 section_process_fn fn = section_table[section];
1388 fn(attr);
1389 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1390 if (section != CUSTOM_MTMX_PARAMS) {
1391 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1392 return;
1393 }
1394 section = CUSTOM_MTMX_PARAM_COEFFS;
1395 section_process_fn fn = section_table[section];
1396 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001397 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1398 section = EXTERNAL_DEVICE_SPECIFIC;
1399 } else if (strcmp(tag_name, "ext_device") == 0) {
1400 section_process_fn fn = section_table[section];
1401 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301402 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1403 if (section != ROOT) {
1404 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1405 return;
1406 }
1407 section = CUSTOM_MTMX_IN_PARAMS;
1408 section_process_fn fn = section_table[section];
1409 fn(attr);
1410 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1411 if (section != CUSTOM_MTMX_IN_PARAMS) {
1412 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1413 return;
1414 }
1415 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
1416 section_process_fn fn = section_table[section];
1417 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301418 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001419 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001420 if(strcmp(tag_name, "config_params") == 0) {
1421 section = CONFIG_PARAMS;
1422 } else if (strcmp(tag_name, "param") == 0) {
1423 if (section != CONFIG_PARAMS) {
1424 ALOGE("param tag only supported with CONFIG_PARAMS section");
1425 return;
1426 }
1427
1428 section_process_fn fn = section_table[section];
1429 fn(attr);
1430 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001431 }
Ben Romberger55886882014-01-10 13:49:02 -08001432 return;
1433}
1434
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001435static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001436{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001437 if (strcmp(tag_name, "bit_width_configs") == 0) {
1438 section = ROOT;
1439 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001440 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001441 } else if (strcmp(tag_name, "module_ids") == 0) {
1442 section = ROOT;
1443 } else if (strcmp(tag_name, "aec") == 0) {
1444 section = MODULE;
1445 } else if (strcmp(tag_name, "ns") == 0) {
1446 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001447 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1448 section = ROOT;
1449 } else if (strcmp(tag_name, "backend_names") == 0) {
1450 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001451 } else if (strcmp(tag_name, "config_params") == 0) {
1452 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001453 } else if (strcmp(tag_name, "operator_specific") == 0) {
1454 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001455 } else if (strcmp(tag_name, "interface_names") == 0) {
1456 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001457 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1458 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001459 } else if (strcmp(tag_name, "app_types") == 0) {
1460 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301461 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1462 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301463 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1464 section = ROOT;
1465 } else if (strcmp(tag_name, "snd_devices") == 0) {
1466 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001467 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1468 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301469 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1470 section = SND_DEVICES;
1471 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1472 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301473 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1474 section = ROOT;
1475 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1476 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301477 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1478 section = ROOT;
1479 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1480 section = CUSTOM_MTMX_IN_PARAMS;
Ethan Chen97564d42014-09-05 13:01:26 -07001481 } else if (strcmp(tag_name, "device_names") == 0) {
1482 section = ROOT;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001483 }
Ben Romberger55886882014-01-10 13:49:02 -08001484}
1485
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001486int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001487{
1488 XML_Parser parser;
1489 FILE *file;
1490 int ret = 0;
1491 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001492 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001493 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001494
Weiyin Jiang63f4d8c2019-09-06 16:59:32 +08001495 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001496 if (filename == NULL)
1497 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1498 MIXER_PATH_MAX_LENGTH);
1499 else
1500 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1501
1502 ALOGV("%s: platform info file name is %s", __func__,
1503 platform_info_file_name);
1504
1505 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001506 section = ROOT;
1507
Ben Romberger55886882014-01-10 13:49:02 -08001508 if (!file) {
1509 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001510 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001511 ret = -ENODEV;
1512 goto done;
1513 }
1514
1515 parser = XML_ParserCreate(NULL);
1516 if (!parser) {
1517 ALOGE("%s: Failed to create XML parser!", __func__);
1518 ret = -ENODEV;
1519 goto err_close_file;
1520 }
1521
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001522 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001523 my_data.platform = platform;
1524 my_data.kvpairs = str_parms_create();
1525
Ben Romberger55886882014-01-10 13:49:02 -08001526 XML_SetElementHandler(parser, start_tag, end_tag);
1527
1528 while (1) {
1529 buf = XML_GetBuffer(parser, BUF_SIZE);
1530 if (buf == NULL) {
1531 ALOGE("%s: XML_GetBuffer failed", __func__);
1532 ret = -ENOMEM;
1533 goto err_free_parser;
1534 }
1535
1536 bytes_read = fread(buf, 1, BUF_SIZE, file);
1537 if (bytes_read < 0) {
1538 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1539 ret = bytes_read;
1540 goto err_free_parser;
1541 }
1542
1543 if (XML_ParseBuffer(parser, bytes_read,
1544 bytes_read == 0) == XML_STATUS_ERROR) {
1545 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001546 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001547 ret = -EINVAL;
1548 goto err_free_parser;
1549 }
1550
1551 if (bytes_read == 0)
1552 break;
1553 }
1554
Ben Romberger55886882014-01-10 13:49:02 -08001555err_free_parser:
1556 XML_ParserFree(parser);
1557err_close_file:
1558 fclose(file);
1559done:
Weiyin Jiang63f4d8c2019-09-06 16:59:32 +08001560 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001561 return ret;
1562}