blob: b3b17a7bde874abd07e3e242be5328fbd820e4ef [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Aalique Grahame22e49102018-12-18 14:23:57 -08002 * Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
Ben Romberger55886882014-01-10 13:49:02 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Ben Romberger61764e32014-01-10 13:49:02 -080030#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080031#define LOG_NDDEBUG 0
32
33#include <errno.h>
34#include <stdio.h>
35#include <expat.h>
Jiangen Jiao334224b2019-09-12 15:47:46 +080036#include <pthread.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080037#include <log/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070038#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080039#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070040#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080041#include "platform_api.h"
42#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070043#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080044
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053045#ifdef DYNAMIC_LOG_ENABLED
46#include <log_xml_parser.h>
47#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
48#include <log_utils.h>
49#endif
50
Ben Romberger55886882014-01-10 13:49:02 -080051#define BUF_SIZE 1024
52
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070053typedef enum {
54 ROOT,
55 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070056 MODULE,
57 AEC,
58 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070059 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070060 PCM_ID,
61 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080062 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070063 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080064 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070065 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080066 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053067 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053068 MICROPHONE_CHARACTERISTIC,
69 SND_DEVICES,
70 INPUT_SND_DEVICE,
71 INPUT_SND_DEVICE_TO_MIC_MAPPING,
72 SND_DEV,
73 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053074 CUSTOM_MTMX_PARAMS,
75 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070076 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053077 CUSTOM_MTMX_IN_PARAMS,
78 CUSTOM_MTMX_PARAM_IN_CH_INFO,
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);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700105
106static section_process_fn section_table[] = {
107 [ROOT] = process_root,
108 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700109 [AEC] = process_effect_aec,
110 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700111 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700112 [PCM_ID] = process_pcm_id,
113 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800114 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700115 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800116 [OPERATOR_SPECIFIC] = process_operator_specific,
117 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700118 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530119 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530120 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
121 [SND_DEV] = process_snd_dev,
122 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530123 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
124 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700125 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530126 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
127 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700128};
129
130static section_t section;
131
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700132struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700133 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700134 void *platform;
135 struct str_parms *kvpairs;
136};
137
138static struct platform_info my_data;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800139static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700140
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530141
142struct audio_string_to_enum {
143 const char* name;
144 unsigned int value;
145};
146
147static snd_device_t in_snd_device;
148
149static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
150 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
151 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
152 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
153 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
154};
155
156static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
157 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
163};
164
165static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
167 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
169};
170
171static const struct audio_string_to_enum device_in_types[] = {
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
199};
200
201enum {
202 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
203 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
204 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
205 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
206 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
207 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
208 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
209 | ORIENTATION) | GEOMETRIC_LOCATION) */
210};
211
212static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
213 int32_t len, unsigned int *value)
214{
215 if (table == NULL) {
216 ALOGE("%s: table is NULL", __func__);
217 return false;
218 }
219
220 if (name == NULL) {
221 ALOGE("null key");
222 return false;
223 }
224
225 for (int i = 0; i < len; i++) {
226 if (!strcmp(table[i].name, name)) {
227 *value = table[i].value;
228 return true;
229 }
230 }
231 return false;
232}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530233
234static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530235static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530236
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700237/*
238 * <audio_platform_info>
239 * <acdb_ids>
240 * <device name="???" acdb_id="???"/>
241 * ...
242 * ...
243 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700244 * <module_ids>
245 * <device name="???" module_id="???"/>
246 * ...
247 * ...
248 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700249 * <backend_names>
250 * <device name="???" backend="???"/>
251 * ...
252 * ...
253 * </backend_names>
254 * <pcm_ids>
255 * <usecase name="???" type="in/out" id="???"/>
256 * ...
257 * ...
258 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800259 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530260 * <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 -0800261 * ...
262 * ...
263 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700264 * <config_params>
265 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800266 * <param key="operator_info" value="tmus;aa;bb;cc"/>
267 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700268 * ...
269 * ...
270 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800271 *
272 * <operator_specific>
273 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
274 * ...
275 * ...
276 * </operator_specific>
277 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700278 * </audio_platform_info>
279 */
280
281static void process_root(const XML_Char **attr __unused)
282{
283}
284
285/* mapping from usecase to pcm dev id */
286static void process_pcm_id(const XML_Char **attr)
287{
288 int index;
289
290 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700291 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700292 goto done;
293 }
294
295 index = platform_get_usecase_index((char *)attr[1]);
296 if (index < 0) {
297 ALOGE("%s: usecase %s not found!",
298 __func__, attr[1]);
299 goto done;
300 }
301
302 if (strcmp(attr[2], "type") != 0) {
303 ALOGE("%s: usecase type not mentioned", __func__);
304 goto done;
305 }
306
307 int type = -1;
308
309 if (!strcasecmp((char *)attr[3], "in")) {
310 type = 1;
311 } else if (!strcasecmp((char *)attr[3], "out")) {
312 type = 0;
313 } else {
314 ALOGE("%s: type must be IN or OUT", __func__);
315 goto done;
316 }
317
318 if (strcmp(attr[4], "id") != 0) {
319 ALOGE("%s: usecase id not mentioned", __func__);
320 goto done;
321 }
322
323 int id = atoi((char *)attr[5]);
324
325 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
326 ALOGE("%s: usecase %s type %d id %d was not set!",
327 __func__, attr[1], type, id);
328 goto done;
329 }
330
331done:
332 return;
333}
334
335/* backend to be used for a device */
336static void process_backend_name(const XML_Char **attr)
337{
338 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530339 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530340 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700341
342 if (strcmp(attr[0], "name") != 0) {
343 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
344 goto done;
345 }
346
347 index = platform_get_snd_device_index((char *)attr[1]);
348 if (index < 0) {
349 ALOGE("%s: Device %s not found, no ACDB ID set!",
350 __func__, attr[1]);
351 goto done;
352 }
353
354 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530355 if (strcmp(attr[2], "interface") == 0)
356 hw_interface = (char *)attr[3];
357 } else {
358 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700359 }
360
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530361 if (attr[4] != NULL) {
362 if (strcmp(attr[4], "interface") != 0) {
363 hw_interface = NULL;
364 } else {
365 hw_interface = (char *)attr[5];
366 }
367 }
368
Ashish Jaind150d4c2017-02-03 18:44:34 +0530369 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700370 ALOGE("%s: Device %s backend %s was not set!",
371 __func__, attr[1], attr[3]);
372 goto done;
373 }
374
375done:
376 return;
377}
378
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700379static void process_gain_db_to_level_map(const XML_Char **attr)
380{
381 struct amp_db_and_gain_table tbl_entry;
382
383 if ((strcmp(attr[0], "db") != 0) ||
384 (strcmp(attr[2], "level") != 0)) {
385 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
386 __func__, attr[0], attr[2]);
387 goto done;
388 }
389
390 tbl_entry.db = atof(attr[1]);
391 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
392 tbl_entry.level = atoi(attr[3]);
393
Aalique Grahame22e49102018-12-18 14:23:57 -0800394 //custome level should be > 0. Level 0 is fixed for default
395 CHECK(tbl_entry.level > 0);
396
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700397 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
398 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
399 platform_add_gain_level_mapping(&tbl_entry);
400
401done:
402 return;
403}
404
405
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700406static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800407{
Ben Romberger61764e32014-01-10 13:49:02 -0800408 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800409
Ben Romberger61764e32014-01-10 13:49:02 -0800410 if (strcmp(attr[0], "name") != 0) {
411 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800412 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800413 }
Ben Romberger55886882014-01-10 13:49:02 -0800414
Ben Romberger61764e32014-01-10 13:49:02 -0800415 index = platform_get_snd_device_index((char *)attr[1]);
416 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800417 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
418 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800419 goto done;
420 }
421
422 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800423 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
424 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800425 goto done;
426 }
427
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700428 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
429 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800430 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800431 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800432 }
Ben Romberger55886882014-01-10 13:49:02 -0800433
Ben Romberger55886882014-01-10 13:49:02 -0800434done:
435 return;
436}
437
Aalique Grahame22e49102018-12-18 14:23:57 -0800438static void process_operator_specific(const XML_Char **attr)
439{
440 snd_device_t snd_device = SND_DEVICE_NONE;
441
442 if (strcmp(attr[0], "name") != 0) {
443 ALOGE("%s: 'name' not found", __func__);
444 goto done;
445 }
446
447 snd_device = platform_get_snd_device_index((char *)attr[1]);
448 if (snd_device < 0) {
449 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
450 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
451 goto done;
452 }
453
454 if (strcmp(attr[2], "operator") != 0) {
455 ALOGE("%s: 'operator' not found", __func__);
456 goto done;
457 }
458
459 if (strcmp(attr[4], "mixer_path") != 0) {
460 ALOGE("%s: 'mixer_path' not found", __func__);
461 goto done;
462 }
463
464 if (strcmp(attr[6], "acdb_id") != 0) {
465 ALOGE("%s: 'acdb_id' not found", __func__);
466 goto done;
467 }
468
469 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
470
471done:
472 return;
473}
474
Carter Hsu32a62362018-10-15 15:01:42 -0700475static void process_external_dev(const XML_Char **attr)
476{
477 snd_device_t snd_device = SND_DEVICE_NONE;
478
479 if (strcmp(attr[0], "name") != 0) {
480 ALOGE("%s: 'name' not found", __func__);
481 goto done;
482 }
483
484 snd_device = platform_get_snd_device_index((char *)attr[1]);
485 if (snd_device < 0) {
486 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
487 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
488 goto done;
489 }
490
491 if (strcmp(attr[2], "usbid") != 0) {
492 ALOGE("%s: 'usbid' not found", __func__);
493 goto done;
494 }
495
496 if (strcmp(attr[4], "acdb_id") != 0) {
497 ALOGE("%s: 'acdb_id' not found", __func__);
498 goto done;
499 }
500
501 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
502
503done:
504 return;
505}
506
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700507static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
508{
509 int index;
510 struct audio_effect_config effect_config;
511
512 if (strcmp(attr[0], "name") != 0) {
513 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
514 goto done;
515 }
516
517 index = platform_get_snd_device_index((char *)attr[1]);
518 if (index < 0) {
519 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
520 __func__, attr[1]);
521 goto done;
522 }
523
524 if (strcmp(attr[2], "module_id") != 0) {
525 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
526 __func__, attr[2]);
527 goto done;
528 }
529
530 if (strcmp(attr[4], "instance_id") != 0) {
531 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
532 __func__, attr[4]);
533 goto done;
534 }
535
536 if (strcmp(attr[6], "param_id") != 0) {
537 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
538 __func__, attr[6]);
539 goto done;
540 }
541
542 if (strcmp(attr[8], "param_value") != 0) {
543 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
544 __func__, attr[8]);
545 goto done;
546 }
547
548 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
549 strtol((char *)attr[5], NULL, 0),
550 strtol((char *)attr[7], NULL, 0),
551 strtol((char *)attr[9], NULL, 0)};
552
553
554 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
555 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
556 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
557 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
558 strtol((char *)attr[9], NULL, 0));
559 goto done;
560 }
561
562done:
563 return;
564}
565
566static void process_effect_aec(const XML_Char **attr)
567{
568 process_audio_effect(attr, EFFECT_AEC);
569 return;
570}
571
572static void process_effect_ns(const XML_Char **attr)
573{
574 process_audio_effect(attr, EFFECT_NS);
575 return;
576}
577
Amit Shekhar5a39c912014-10-14 15:39:30 -0700578static void process_bit_width(const XML_Char **attr)
579{
580 int index;
581
582 if (strcmp(attr[0], "name") != 0) {
583 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
584 goto done;
585 }
586
587 index = platform_get_snd_device_index((char *)attr[1]);
588 if (index < 0) {
589 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
590 __func__, attr[1]);
591 goto done;
592 }
593
594 if (strcmp(attr[2], "bit_width") != 0) {
595 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
596 __func__, attr[1]);
597 goto done;
598 }
599
600 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
601 ALOGE("%s: Device %s, ACDB ID %d was not set!",
602 __func__, attr[1], atoi((char *)attr[3]));
603 goto done;
604 }
605
606done:
607 return;
608}
609
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800610static void process_interface_name(const XML_Char **attr)
611{
612 int ret;
613
614 if (strcmp(attr[0], "name") != 0) {
615 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
616
617 goto done;
618 }
619
620 if (strcmp(attr[2], "interface") != 0) {
621 ALOGE("%s: Device %s has no Audio Interface set!",
622 __func__, attr[1]);
623
624 goto done;
625 }
626
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530627 if (strcmp(attr[4], "codec_type") != 0) {
628 ALOGE("%s: Device %s has no codec type set!",
629 __func__, attr[1]);
630
631 goto done;
632 }
633
634 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
635 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800636 if (ret < 0) {
637 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800638 goto done;
639 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800640
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800641done:
642 return;
643}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530644
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700645static void process_config_params(const XML_Char **attr)
646{
647 if (strcmp(attr[0], "key") != 0) {
648 ALOGE("%s: 'key' not found", __func__);
649 goto done;
650 }
651
652 if (strcmp(attr[2], "value") != 0) {
653 ALOGE("%s: 'value' not found", __func__);
654 goto done;
655 }
656
657 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700658 if (my_data.caller == PLATFORM)
659 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700660done:
661 return;
662}
663
Aalique Grahame22e49102018-12-18 14:23:57 -0800664static void process_app_type(const XML_Char **attr)
665{
666 if (strcmp(attr[0], "uc_type")) {
667 ALOGE("%s: uc_type not found", __func__);
668 goto done;
669 }
670
671 if (strcmp(attr[2], "mode")) {
672 ALOGE("%s: mode not found", __func__);
673 goto done;
674 }
675
676 if (strcmp(attr[4], "bit_width")) {
677 ALOGE("%s: bit_width not found", __func__);
678 goto done;
679 }
680
681 if (strcmp(attr[6], "id")) {
682 ALOGE("%s: id not found", __func__);
683 goto done;
684 }
685
686 if (strcmp(attr[8], "max_rate")) {
687 ALOGE("%s: max rate not found", __func__);
688 goto done;
689 }
690
691 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
692 atoi(attr[9]));
693done:
694 return;
695}
696
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530697static void process_microphone_characteristic(const XML_Char **attr) {
698 struct audio_microphone_characteristic_t microphone;
699 uint32_t curIdx = 0;
700
701 if (strcmp(attr[curIdx++], "valid_mask")) {
702 ALOGE("%s: valid_mask not found", __func__);
703 goto done;
704 }
705 uint32_t valid_mask = atoi(attr[curIdx++]);
706
707 if (strcmp(attr[curIdx++], "device_id")) {
708 ALOGE("%s: device_id not found", __func__);
709 goto done;
710 }
711 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
712 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
713 goto done;
714 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530715 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530716
717 if (strcmp(attr[curIdx++], "type")) {
718 ALOGE("%s: device not found", __func__);
719 goto done;
720 }
721 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
722 ARRAY_SIZE(device_in_types), &microphone.device)) {
723 ALOGE("%s: type %s in %s not found!",
724 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
725 goto done;
726 }
727
728 if (strcmp(attr[curIdx++], "address")) {
729 ALOGE("%s: address not found", __func__);
730 goto done;
731 }
732 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
733 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
734 goto done;
735 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530736 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530737 if (strlen(microphone.address) == 0) {
738 // If the address is empty, populate the address according to device type.
739 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530740 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530741 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530742 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530743 }
744 }
745
746 if (strcmp(attr[curIdx++], "location")) {
747 ALOGE("%s: location not found", __func__);
748 goto done;
749 }
750 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
751 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
752 ALOGE("%s: location %s in %s not found!",
753 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
754 goto done;
755 }
756
757 if (strcmp(attr[curIdx++], "group")) {
758 ALOGE("%s: group not found", __func__);
759 goto done;
760 }
761 microphone.group = atoi(attr[curIdx++]);
762
763 if (strcmp(attr[curIdx++], "index_in_the_group")) {
764 ALOGE("%s: index_in_the_group not found", __func__);
765 goto done;
766 }
767 microphone.index_in_the_group = atoi(attr[curIdx++]);
768
769 if (strcmp(attr[curIdx++], "directionality")) {
770 ALOGE("%s: directionality not found", __func__);
771 goto done;
772 }
773 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
774 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
775 ALOGE("%s: directionality %s in %s not found!",
776 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
777 goto done;
778 }
779
780 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
781 ALOGE("%s: num_frequency_responses not found", __func__);
782 goto done;
783 }
784 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530785 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530786 ALOGE("%s: num_frequency_responses is too large", __func__);
787 goto done;
788 }
789 if (microphone.num_frequency_responses > 0) {
790 if (strcmp(attr[curIdx++], "frequencies")) {
791 ALOGE("%s: frequencies not found", __func__);
792 goto done;
793 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530794 char *context = NULL;
795 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530796 uint32_t num_frequencies = 0;
797 while (token) {
798 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800799 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530800 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530801 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530802 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530803 }
804
805 if (strcmp(attr[curIdx++], "responses")) {
806 ALOGE("%s: responses not found", __func__);
807 goto done;
808 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530809 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530810 uint32_t num_responses = 0;
811 while (token) {
812 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800813 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530814 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530815 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530816 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530817 }
818
819 if (num_frequencies != num_responses
820 || num_frequencies != microphone.num_frequency_responses) {
821 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
822 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
823 goto done;
824 }
825 }
826
827 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
828 if (strcmp(attr[curIdx++], "sensitivity")) {
829 ALOGE("%s: sensitivity not found", __func__);
830 goto done;
831 }
832 microphone.sensitivity = atof(attr[curIdx++]);
833 } else {
834 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
835 }
836
837 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
838 if (strcmp(attr[curIdx++], "max_spl")) {
839 ALOGE("%s: max_spl not found", __func__);
840 goto done;
841 }
842 microphone.max_spl = atof(attr[curIdx++]);
843 } else {
844 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
845 }
846
847 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
848 if (strcmp(attr[curIdx++], "min_spl")) {
849 ALOGE("%s: min_spl not found", __func__);
850 goto done;
851 }
852 microphone.min_spl = atof(attr[curIdx++]);
853 } else {
854 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
855 }
856
857 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
858 if (strcmp(attr[curIdx++], "orientation")) {
859 ALOGE("%s: orientation not found", __func__);
860 goto done;
861 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530862 char *context = NULL;
863 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530864 float orientation[3];
865 uint32_t idx = 0;
866 while (token) {
867 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800868 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530869 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530870 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530871 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530872 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530873 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530874 ALOGE("%s: orientation invalid", __func__);
875 goto done;
876 }
877 microphone.orientation.x = orientation[0];
878 microphone.orientation.y = orientation[1];
879 microphone.orientation.z = orientation[2];
880 } else {
881 microphone.orientation.x = 0.0f;
882 microphone.orientation.y = 0.0f;
883 microphone.orientation.z = 0.0f;
884 }
885
886 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
887 if (strcmp(attr[curIdx++], "geometric_location")) {
888 ALOGE("%s: geometric_location not found", __func__);
889 goto done;
890 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530891 char *context = NULL;
892 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530893 float geometric_location[3];
894 uint32_t idx = 0;
895 while (token) {
896 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800897 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530898 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530899 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530900 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530901 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530902 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530903 ALOGE("%s: geometric_location invalid", __func__);
904 goto done;
905 }
906 microphone.geometric_location.x = geometric_location[0];
907 microphone.geometric_location.y = geometric_location[1];
908 microphone.geometric_location.z = geometric_location[2];
909 } else {
910 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
911 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
912 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
913 }
914
915 platform_set_microphone_characteristic(my_data.platform, microphone);
916done:
917 return;
918}
919
920static void process_snd_dev(const XML_Char **attr)
921{
922 uint32_t curIdx = 0;
923 in_snd_device = SND_DEVICE_NONE;
924
925 if (strcmp(attr[curIdx++], "in_snd_device")) {
926 ALOGE("%s: snd_device not found", __func__);
927 return;
928 }
929 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
930 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
931 in_snd_device >= SND_DEVICE_IN_END) {
932 ALOGE("%s: Sound device not valid", __func__);
933 in_snd_device = SND_DEVICE_NONE;
934 }
935
936 return;
937}
938
939static void process_mic_info(const XML_Char **attr)
940{
941 uint32_t curIdx = 0;
942 struct mic_info microphone;
943
944 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
945 sizeof(microphone.channel_mapping));
946
947 if (strcmp(attr[curIdx++], "mic_device_id")) {
948 ALOGE("%s: mic_device_id not found", __func__);
949 goto on_error;
950 }
951 strlcpy(microphone.device_id,
952 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
953
954 if (strcmp(attr[curIdx++], "channel_mapping")) {
955 ALOGE("%s: channel_mapping not found", __func__);
956 goto on_error;
957 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530958 char *context = NULL;
959 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530960 uint32_t idx = 0;
961 while (token) {
962 if (!find_enum_by_string(mic_channel_mapping, token,
963 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
964 &microphone.channel_mapping[idx++])) {
965 ALOGE("%s: channel_mapping %s in %s not found!",
966 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
967 goto on_error;
968 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530969 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530970 }
971 microphone.channel_count = idx;
972
973 platform_set_microphone_map(my_data.platform, in_snd_device,
974 &microphone);
975 return;
976on_error:
977 in_snd_device = SND_DEVICE_NONE;
978 return;
979}
980
981
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530982/* process acdb meta info key value */
983static void process_acdb_metainfo_key(const XML_Char **attr)
984{
985 if (strcmp(attr[0], "name") != 0) {
986 ALOGE("%s: 'name' not found", __func__);
987 goto done;
988 }
989
990 if (strcmp(attr[2], "value") != 0) {
991 ALOGE("%s: 'value' not found", __func__);
992 goto done;
993 }
994
995 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700996 switch(my_data.caller) {
997 case ACDB_EXTN:
998 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
999 ALOGE("%s: key %d was not set!", __func__, key);
1000 goto done;
1001 }
1002 break;
1003 case PLATFORM:
1004 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1005 ALOGE("%s: key %d was not set!", __func__, key);
1006 goto done;
1007 }
1008 break;
1009 default:
1010 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301011 }
1012
1013done:
1014 return;
1015}
1016
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301017static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1018{
1019 uint32_t attr_idx = 0;
1020 int32_t in_ch_idx = -1;
1021 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1022
1023 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1024 &mtmx_in_params_info);
1025 if (mtmx_in_params == NULL) {
1026 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1027 return;
1028 }
1029
1030 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1031 ALOGE("%s: 'in_channel_index' not found", __func__);
1032 return;
1033 }
1034
1035 in_ch_idx = atoi((char *)attr[attr_idx++]);
1036 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1037 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1038 return;
1039 }
1040
1041 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1042 ALOGE("%s: 'channel_count' not found", __func__);
1043 return;
1044 }
1045 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1046
1047 if (strcmp(attr[attr_idx++], "device") != 0) {
1048 ALOGE("%s: 'device' not found", __func__);
1049 return;
1050 }
1051 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1052 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1053
1054 if (strcmp(attr[attr_idx++], "interface") != 0) {
1055 ALOGE("%s: 'interface' not found", __func__);
1056 return;
1057 }
1058 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1059 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1060
1061 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1062 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1063 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1064 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1065 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1066 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1067 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1068 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1069
1070 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1071}
1072
1073static void process_custom_mtmx_in_params(const XML_Char **attr)
1074{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301075 int attr_idx = 0, i = 0;
1076 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301077
1078 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1079 ALOGE("%s: 'usecase' not found", __func__);
1080 return;
1081 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301082 /* Check if multi usecases are supported for this custom mtrx params */
1083 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1084 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1085 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1086 value = strtok_r(NULL, ",", &context);
1087 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301088
1089 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1090 ALOGE("%s: 'out_channel_count' not found", __func__);
1091 return;
1092 }
1093 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1094
1095 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1096
1097}
1098
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301099static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1100{
1101 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301102 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301103 char *context = NULL, *ch_coeff_value = NULL;
1104 struct audio_custom_mtmx_params *mtmx_params = NULL;
1105
1106 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1107 ALOGE("%s: 'out_channel_index' not found", __func__);
1108 return;
1109 }
1110 out_ch_idx = atoi((char *)attr[attr_idx++]);
1111
1112 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1113 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1114 return;
1115 }
1116
1117 if (strcmp(attr[attr_idx++], "values") != 0) {
1118 ALOGE("%s: 'values' not found", __func__);
1119 return;
1120 }
1121 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301122 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301123 if (mtmx_params == NULL) {
1124 ALOGE("%s: mtmx params with given param info, not found", __func__);
1125 return;
1126 }
1127 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1128 ip_channels = mtmx_params->info.ip_channels;
1129 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301130 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301131 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1132 = atoi(ch_coeff_value);
1133 ch_coeff_value = strtok_r(NULL, " ", &context);
1134 }
1135 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1136 ch_coeff_value != NULL)
1137 ALOGE("%s: invalid/malformed coefficient values", __func__);
1138}
1139
1140static void process_custom_mtmx_params(const XML_Char **attr)
1141{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301142 int attr_idx = 0, i = 0;
1143 char *context = NULL, *value = NULL;
1144
1145 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301146
1147 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1148 ALOGE("%s: 'param_id' not found", __func__);
1149 return;
1150 }
1151 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1152
1153 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1154 ALOGE("%s: 'in_channel_count' not found", __func__);
1155 return;
1156 }
1157 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1158
1159 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1160 ALOGE("%s: 'out_channel_count' not found", __func__);
1161 return;
1162 }
1163 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1164
1165 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1166 ALOGE("%s: 'usecase' not found", __func__);
1167 return;
1168 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301169
1170 /* check if multi usecases are supported for this custom mtrx params */
1171 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1172 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1173 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1174 value = strtok_r(NULL, ",", &context);
1175 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301176
1177 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1178 ALOGE("%s: 'snd_device' not found", __func__);
1179 return;
1180 }
1181 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301182
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301183 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1184 i = 0;
1185 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1186 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1187 mtmx_params_info.fe_id[i++] = atoi(value);
1188 value = strtok_r(NULL, ",", &context);
1189 }
1190
1191 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301192 }
1193
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301194 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1195
1196}
1197
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001198static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001199 const XML_Char **attr)
1200{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001201 if (my_data.caller == ACDB_EXTN) {
1202 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1203 section = ACDB_METAINFO_KEY;
1204 } else if (strcmp(tag_name, "param") == 0) {
1205 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1206 ALOGE("param tag only supported with CONFIG_PARAMS section");
1207 return;
1208 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001209
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001210 section_process_fn fn = section_table[section];
1211 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001212 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001213 } else if(my_data.caller == PLATFORM) {
1214 if (strcmp(tag_name, "bit_width_configs") == 0) {
1215 section = BITWIDTH;
1216 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1217 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001218 } else if (strcmp(tag_name, "module_ids") == 0) {
1219 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001220 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1221 section = PCM_ID;
1222 } else if (strcmp(tag_name, "backend_names") == 0) {
1223 section = BACKEND_NAME;
1224 } else if (strcmp(tag_name, "config_params") == 0) {
1225 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001226 } else if (strcmp(tag_name, "operator_specific") == 0) {
1227 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001228 } else if (strcmp(tag_name, "interface_names") == 0) {
1229 section = INTERFACE_NAME;
1230 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1231 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001232 } else if (strcmp(tag_name, "app_types") == 0) {
1233 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001234 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1235 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301236 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1237 section = MICROPHONE_CHARACTERISTIC;
1238 } else if (strcmp(tag_name, "snd_devices") == 0) {
1239 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001240 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001241 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1242 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001243 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001244 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1245 return;
1246 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001247
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001248 /* call into process function for the current section */
1249 section_process_fn fn = section_table[section];
1250 fn(attr);
1251 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1252 if (section != GAIN_LEVEL_MAPPING) {
1253 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1254 return;
1255 }
1256
1257 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1258 fn(attr);
1259 } else if (strcmp(tag_name, "usecase") == 0) {
1260 if (section != PCM_ID) {
1261 ALOGE("usecase tag only supported with PCM_ID section");
1262 return;
1263 }
1264
1265 section_process_fn fn = section_table[PCM_ID];
1266 fn(attr);
1267 } else if (strcmp(tag_name, "param") == 0) {
1268 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1269 ALOGE("param tag only supported with CONFIG_PARAMS section");
1270 return;
1271 }
1272
1273 section_process_fn fn = section_table[section];
1274 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301275 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001276 if (section != MODULE) {
1277 ALOGE("aec tag only supported with MODULE section");
1278 return;
1279 }
1280 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301281 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001282 if (section != MODULE) {
1283 ALOGE("ns tag only supported with MODULE section");
1284 return;
1285 }
1286 section = NS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001287 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1288 if (section != GAIN_LEVEL_MAPPING) {
1289 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1290 return;
1291 }
1292
1293 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1294 fn(attr);
1295 } else if (!strcmp(tag_name, "app")) {
1296 if (section != APP_TYPE) {
1297 ALOGE("app tag only valid in section APP_TYPE");
1298 return;
1299 }
1300
1301 section_process_fn fn = section_table[APP_TYPE];
1302 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301303 } else if (strcmp(tag_name, "microphone") == 0) {
1304 if (section != MICROPHONE_CHARACTERISTIC) {
1305 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1306 return;
1307 }
1308 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1309 fn(attr);
1310 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1311 if (section != SND_DEVICES) {
1312 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1313 return;
1314 }
1315 section = INPUT_SND_DEVICE;
1316 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1317 if (section != INPUT_SND_DEVICE) {
1318 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1319 return;
1320 }
1321 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1322 } else if (strcmp(tag_name, "snd_dev") == 0) {
1323 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1324 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1325 return;
1326 }
1327 section_process_fn fn = section_table[SND_DEV];
1328 fn(attr);
1329 } else if (strcmp(tag_name, "mic_info") == 0) {
1330 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1331 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1332 return;
1333 }
1334 if (in_snd_device == SND_DEVICE_NONE) {
1335 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1336 return;
1337 }
1338 section_process_fn fn = section_table[MIC_INFO];
1339 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301340 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1341 if (section != ROOT) {
1342 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1343 return;
1344 }
1345 section = CUSTOM_MTMX_PARAMS;
1346 section_process_fn fn = section_table[section];
1347 fn(attr);
1348 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1349 if (section != CUSTOM_MTMX_PARAMS) {
1350 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1351 return;
1352 }
1353 section = CUSTOM_MTMX_PARAM_COEFFS;
1354 section_process_fn fn = section_table[section];
1355 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001356 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1357 section = EXTERNAL_DEVICE_SPECIFIC;
1358 } else if (strcmp(tag_name, "ext_device") == 0) {
1359 section_process_fn fn = section_table[section];
1360 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301361 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1362 if (section != ROOT) {
1363 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1364 return;
1365 }
1366 section = CUSTOM_MTMX_IN_PARAMS;
1367 section_process_fn fn = section_table[section];
1368 fn(attr);
1369 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1370 if (section != CUSTOM_MTMX_IN_PARAMS) {
1371 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1372 return;
1373 }
1374 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
1375 section_process_fn fn = section_table[section];
1376 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301377 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001378 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001379 if(strcmp(tag_name, "config_params") == 0) {
1380 section = CONFIG_PARAMS;
1381 } else if (strcmp(tag_name, "param") == 0) {
1382 if (section != CONFIG_PARAMS) {
1383 ALOGE("param tag only supported with CONFIG_PARAMS section");
1384 return;
1385 }
1386
1387 section_process_fn fn = section_table[section];
1388 fn(attr);
1389 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001390 }
Ben Romberger55886882014-01-10 13:49:02 -08001391 return;
1392}
1393
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001394static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001395{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001396 if (strcmp(tag_name, "bit_width_configs") == 0) {
1397 section = ROOT;
1398 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001399 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001400 } else if (strcmp(tag_name, "module_ids") == 0) {
1401 section = ROOT;
1402 } else if (strcmp(tag_name, "aec") == 0) {
1403 section = MODULE;
1404 } else if (strcmp(tag_name, "ns") == 0) {
1405 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001406 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1407 section = ROOT;
1408 } else if (strcmp(tag_name, "backend_names") == 0) {
1409 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001410 } else if (strcmp(tag_name, "config_params") == 0) {
1411 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001412 } else if (strcmp(tag_name, "operator_specific") == 0) {
1413 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001414 } else if (strcmp(tag_name, "interface_names") == 0) {
1415 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001416 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1417 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001418 } else if (strcmp(tag_name, "app_types") == 0) {
1419 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301420 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1421 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301422 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1423 section = ROOT;
1424 } else if (strcmp(tag_name, "snd_devices") == 0) {
1425 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001426 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1427 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301428 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1429 section = SND_DEVICES;
1430 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1431 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301432 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1433 section = ROOT;
1434 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1435 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301436 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1437 section = ROOT;
1438 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1439 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001440 }
Ben Romberger55886882014-01-10 13:49:02 -08001441}
1442
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001443int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001444{
1445 XML_Parser parser;
1446 FILE *file;
1447 int ret = 0;
1448 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001449 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001450 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001451
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001452 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001453 if (filename == NULL)
1454 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1455 MIXER_PATH_MAX_LENGTH);
1456 else
1457 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1458
1459 ALOGV("%s: platform info file name is %s", __func__,
1460 platform_info_file_name);
1461
1462 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001463 section = ROOT;
1464
Ben Romberger55886882014-01-10 13:49:02 -08001465 if (!file) {
1466 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001467 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001468 ret = -ENODEV;
1469 goto done;
1470 }
1471
1472 parser = XML_ParserCreate(NULL);
1473 if (!parser) {
1474 ALOGE("%s: Failed to create XML parser!", __func__);
1475 ret = -ENODEV;
1476 goto err_close_file;
1477 }
1478
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001479 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001480 my_data.platform = platform;
1481 my_data.kvpairs = str_parms_create();
1482
Ben Romberger55886882014-01-10 13:49:02 -08001483 XML_SetElementHandler(parser, start_tag, end_tag);
1484
1485 while (1) {
1486 buf = XML_GetBuffer(parser, BUF_SIZE);
1487 if (buf == NULL) {
1488 ALOGE("%s: XML_GetBuffer failed", __func__);
1489 ret = -ENOMEM;
1490 goto err_free_parser;
1491 }
1492
1493 bytes_read = fread(buf, 1, BUF_SIZE, file);
1494 if (bytes_read < 0) {
1495 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1496 ret = bytes_read;
1497 goto err_free_parser;
1498 }
1499
1500 if (XML_ParseBuffer(parser, bytes_read,
1501 bytes_read == 0) == XML_STATUS_ERROR) {
1502 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001503 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001504 ret = -EINVAL;
1505 goto err_free_parser;
1506 }
1507
1508 if (bytes_read == 0)
1509 break;
1510 }
1511
Ben Romberger55886882014-01-10 13:49:02 -08001512err_free_parser:
1513 XML_ParserFree(parser);
1514err_close_file:
1515 fclose(file);
1516done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001517 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001518 return ret;
1519}