blob: 8ee8b07f77c8223b8313d4beba58fdaf6ea15755 [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,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070078} section_t;
79
80typedef void (* section_process_fn)(const XML_Char **attr);
81
82static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070083static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
84static void process_effect_aec(const XML_Char **attr);
85static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070086static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070087static void process_pcm_id(const XML_Char **attr);
88static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080089static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070090static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070091static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080092static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070093static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080094static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053095static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053096static void process_microphone_characteristic(const XML_Char **attr);
97static void process_snd_dev(const XML_Char **attr);
98static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +053099static void process_custom_mtmx_params(const XML_Char **attr);
100static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700101static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530102static void process_custom_mtmx_in_params(const XML_Char **attr);
103static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700104
105static section_process_fn section_table[] = {
106 [ROOT] = process_root,
107 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700108 [AEC] = process_effect_aec,
109 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700110 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700111 [PCM_ID] = process_pcm_id,
112 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800113 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700114 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800115 [OPERATOR_SPECIFIC] = process_operator_specific,
116 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700117 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530118 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530119 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
120 [SND_DEV] = process_snd_dev,
121 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530122 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
123 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700124 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530125 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
126 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700127};
128
129static section_t section;
130
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700131struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700132 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700133 void *platform;
134 struct str_parms *kvpairs;
135};
136
137static struct platform_info my_data;
138
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530139
140struct audio_string_to_enum {
141 const char* name;
142 unsigned int value;
143};
144
145static snd_device_t in_snd_device;
146
147static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
148 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
149 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
150 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
151 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
152};
153
154static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
155 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
157 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
161};
162
163static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
167};
168
169static const struct audio_string_to_enum device_in_types[] = {
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
197};
198
199enum {
200 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
201 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
202 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
203 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
204 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
205 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
206 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
207 | ORIENTATION) | GEOMETRIC_LOCATION) */
208};
209
210static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
211 int32_t len, unsigned int *value)
212{
213 if (table == NULL) {
214 ALOGE("%s: table is NULL", __func__);
215 return false;
216 }
217
218 if (name == NULL) {
219 ALOGE("null key");
220 return false;
221 }
222
223 for (int i = 0; i < len; i++) {
224 if (!strcmp(table[i].name, name)) {
225 *value = table[i].value;
226 return true;
227 }
228 }
229 return false;
230}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530231
232static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530233static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530234
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700235/*
236 * <audio_platform_info>
237 * <acdb_ids>
238 * <device name="???" acdb_id="???"/>
239 * ...
240 * ...
241 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700242 * <module_ids>
243 * <device name="???" module_id="???"/>
244 * ...
245 * ...
246 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700247 * <backend_names>
248 * <device name="???" backend="???"/>
249 * ...
250 * ...
251 * </backend_names>
252 * <pcm_ids>
253 * <usecase name="???" type="in/out" id="???"/>
254 * ...
255 * ...
256 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800257 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530258 * <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 -0800259 * ...
260 * ...
261 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700262 * <config_params>
263 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800264 * <param key="operator_info" value="tmus;aa;bb;cc"/>
265 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700266 * ...
267 * ...
268 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800269 *
270 * <operator_specific>
271 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
272 * ...
273 * ...
274 * </operator_specific>
275 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700276 * </audio_platform_info>
277 */
278
279static void process_root(const XML_Char **attr __unused)
280{
281}
282
283/* mapping from usecase to pcm dev id */
284static void process_pcm_id(const XML_Char **attr)
285{
286 int index;
287
288 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700289 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700290 goto done;
291 }
292
293 index = platform_get_usecase_index((char *)attr[1]);
294 if (index < 0) {
295 ALOGE("%s: usecase %s not found!",
296 __func__, attr[1]);
297 goto done;
298 }
299
300 if (strcmp(attr[2], "type") != 0) {
301 ALOGE("%s: usecase type not mentioned", __func__);
302 goto done;
303 }
304
305 int type = -1;
306
307 if (!strcasecmp((char *)attr[3], "in")) {
308 type = 1;
309 } else if (!strcasecmp((char *)attr[3], "out")) {
310 type = 0;
311 } else {
312 ALOGE("%s: type must be IN or OUT", __func__);
313 goto done;
314 }
315
316 if (strcmp(attr[4], "id") != 0) {
317 ALOGE("%s: usecase id not mentioned", __func__);
318 goto done;
319 }
320
321 int id = atoi((char *)attr[5]);
322
323 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
324 ALOGE("%s: usecase %s type %d id %d was not set!",
325 __func__, attr[1], type, id);
326 goto done;
327 }
328
329done:
330 return;
331}
332
333/* backend to be used for a device */
334static void process_backend_name(const XML_Char **attr)
335{
336 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530337 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530338 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700339
340 if (strcmp(attr[0], "name") != 0) {
341 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
342 goto done;
343 }
344
345 index = platform_get_snd_device_index((char *)attr[1]);
346 if (index < 0) {
347 ALOGE("%s: Device %s not found, no ACDB ID set!",
348 __func__, attr[1]);
349 goto done;
350 }
351
352 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530353 if (strcmp(attr[2], "interface") == 0)
354 hw_interface = (char *)attr[3];
355 } else {
356 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700357 }
358
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530359 if (attr[4] != NULL) {
360 if (strcmp(attr[4], "interface") != 0) {
361 hw_interface = NULL;
362 } else {
363 hw_interface = (char *)attr[5];
364 }
365 }
366
Ashish Jaind150d4c2017-02-03 18:44:34 +0530367 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700368 ALOGE("%s: Device %s backend %s was not set!",
369 __func__, attr[1], attr[3]);
370 goto done;
371 }
372
373done:
374 return;
375}
376
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700377static void process_gain_db_to_level_map(const XML_Char **attr)
378{
379 struct amp_db_and_gain_table tbl_entry;
380
381 if ((strcmp(attr[0], "db") != 0) ||
382 (strcmp(attr[2], "level") != 0)) {
383 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
384 __func__, attr[0], attr[2]);
385 goto done;
386 }
387
388 tbl_entry.db = atof(attr[1]);
389 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
390 tbl_entry.level = atoi(attr[3]);
391
Aalique Grahame22e49102018-12-18 14:23:57 -0800392 //custome level should be > 0. Level 0 is fixed for default
393 CHECK(tbl_entry.level > 0);
394
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700395 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
396 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
397 platform_add_gain_level_mapping(&tbl_entry);
398
399done:
400 return;
401}
402
403
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700404static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800405{
Ben Romberger61764e32014-01-10 13:49:02 -0800406 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800407
Ben Romberger61764e32014-01-10 13:49:02 -0800408 if (strcmp(attr[0], "name") != 0) {
409 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800410 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800411 }
Ben Romberger55886882014-01-10 13:49:02 -0800412
Ben Romberger61764e32014-01-10 13:49:02 -0800413 index = platform_get_snd_device_index((char *)attr[1]);
414 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800415 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
416 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800417 goto done;
418 }
419
420 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800421 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
422 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800423 goto done;
424 }
425
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700426 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
427 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800428 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800429 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800430 }
Ben Romberger55886882014-01-10 13:49:02 -0800431
Ben Romberger55886882014-01-10 13:49:02 -0800432done:
433 return;
434}
435
Aalique Grahame22e49102018-12-18 14:23:57 -0800436static void process_operator_specific(const XML_Char **attr)
437{
438 snd_device_t snd_device = SND_DEVICE_NONE;
439
440 if (strcmp(attr[0], "name") != 0) {
441 ALOGE("%s: 'name' not found", __func__);
442 goto done;
443 }
444
445 snd_device = platform_get_snd_device_index((char *)attr[1]);
446 if (snd_device < 0) {
447 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
448 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
449 goto done;
450 }
451
452 if (strcmp(attr[2], "operator") != 0) {
453 ALOGE("%s: 'operator' not found", __func__);
454 goto done;
455 }
456
457 if (strcmp(attr[4], "mixer_path") != 0) {
458 ALOGE("%s: 'mixer_path' not found", __func__);
459 goto done;
460 }
461
462 if (strcmp(attr[6], "acdb_id") != 0) {
463 ALOGE("%s: 'acdb_id' not found", __func__);
464 goto done;
465 }
466
467 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
468
469done:
470 return;
471}
472
Carter Hsu32a62362018-10-15 15:01:42 -0700473static void process_external_dev(const XML_Char **attr)
474{
475 snd_device_t snd_device = SND_DEVICE_NONE;
476
477 if (strcmp(attr[0], "name") != 0) {
478 ALOGE("%s: 'name' not found", __func__);
479 goto done;
480 }
481
482 snd_device = platform_get_snd_device_index((char *)attr[1]);
483 if (snd_device < 0) {
484 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
485 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
486 goto done;
487 }
488
489 if (strcmp(attr[2], "usbid") != 0) {
490 ALOGE("%s: 'usbid' not found", __func__);
491 goto done;
492 }
493
494 if (strcmp(attr[4], "acdb_id") != 0) {
495 ALOGE("%s: 'acdb_id' not found", __func__);
496 goto done;
497 }
498
499 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
500
501done:
502 return;
503}
504
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700505static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
506{
507 int index;
508 struct audio_effect_config effect_config;
509
510 if (strcmp(attr[0], "name") != 0) {
511 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
512 goto done;
513 }
514
515 index = platform_get_snd_device_index((char *)attr[1]);
516 if (index < 0) {
517 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
518 __func__, attr[1]);
519 goto done;
520 }
521
522 if (strcmp(attr[2], "module_id") != 0) {
523 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
524 __func__, attr[2]);
525 goto done;
526 }
527
528 if (strcmp(attr[4], "instance_id") != 0) {
529 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
530 __func__, attr[4]);
531 goto done;
532 }
533
534 if (strcmp(attr[6], "param_id") != 0) {
535 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
536 __func__, attr[6]);
537 goto done;
538 }
539
540 if (strcmp(attr[8], "param_value") != 0) {
541 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
542 __func__, attr[8]);
543 goto done;
544 }
545
546 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
547 strtol((char *)attr[5], NULL, 0),
548 strtol((char *)attr[7], NULL, 0),
549 strtol((char *)attr[9], NULL, 0)};
550
551
552 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
553 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
554 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
555 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
556 strtol((char *)attr[9], NULL, 0));
557 goto done;
558 }
559
560done:
561 return;
562}
563
564static void process_effect_aec(const XML_Char **attr)
565{
566 process_audio_effect(attr, EFFECT_AEC);
567 return;
568}
569
570static void process_effect_ns(const XML_Char **attr)
571{
572 process_audio_effect(attr, EFFECT_NS);
573 return;
574}
575
Amit Shekhar5a39c912014-10-14 15:39:30 -0700576static void process_bit_width(const XML_Char **attr)
577{
578 int index;
579
580 if (strcmp(attr[0], "name") != 0) {
581 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
582 goto done;
583 }
584
585 index = platform_get_snd_device_index((char *)attr[1]);
586 if (index < 0) {
587 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
588 __func__, attr[1]);
589 goto done;
590 }
591
592 if (strcmp(attr[2], "bit_width") != 0) {
593 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
594 __func__, attr[1]);
595 goto done;
596 }
597
598 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
599 ALOGE("%s: Device %s, ACDB ID %d was not set!",
600 __func__, attr[1], atoi((char *)attr[3]));
601 goto done;
602 }
603
604done:
605 return;
606}
607
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800608static void process_interface_name(const XML_Char **attr)
609{
610 int ret;
611
612 if (strcmp(attr[0], "name") != 0) {
613 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
614
615 goto done;
616 }
617
618 if (strcmp(attr[2], "interface") != 0) {
619 ALOGE("%s: Device %s has no Audio Interface set!",
620 __func__, attr[1]);
621
622 goto done;
623 }
624
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530625 if (strcmp(attr[4], "codec_type") != 0) {
626 ALOGE("%s: Device %s has no codec type set!",
627 __func__, attr[1]);
628
629 goto done;
630 }
631
632 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
633 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800634 if (ret < 0) {
635 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800636 goto done;
637 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800638
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800639done:
640 return;
641}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530642
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700643static void process_config_params(const XML_Char **attr)
644{
645 if (strcmp(attr[0], "key") != 0) {
646 ALOGE("%s: 'key' not found", __func__);
647 goto done;
648 }
649
650 if (strcmp(attr[2], "value") != 0) {
651 ALOGE("%s: 'value' not found", __func__);
652 goto done;
653 }
654
655 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
656done:
657 return;
658}
659
Aalique Grahame22e49102018-12-18 14:23:57 -0800660static void process_app_type(const XML_Char **attr)
661{
662 if (strcmp(attr[0], "uc_type")) {
663 ALOGE("%s: uc_type not found", __func__);
664 goto done;
665 }
666
667 if (strcmp(attr[2], "mode")) {
668 ALOGE("%s: mode not found", __func__);
669 goto done;
670 }
671
672 if (strcmp(attr[4], "bit_width")) {
673 ALOGE("%s: bit_width not found", __func__);
674 goto done;
675 }
676
677 if (strcmp(attr[6], "id")) {
678 ALOGE("%s: id not found", __func__);
679 goto done;
680 }
681
682 if (strcmp(attr[8], "max_rate")) {
683 ALOGE("%s: max rate not found", __func__);
684 goto done;
685 }
686
687 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
688 atoi(attr[9]));
689done:
690 return;
691}
692
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530693static void process_microphone_characteristic(const XML_Char **attr) {
694 struct audio_microphone_characteristic_t microphone;
695 uint32_t curIdx = 0;
696
697 if (strcmp(attr[curIdx++], "valid_mask")) {
698 ALOGE("%s: valid_mask not found", __func__);
699 goto done;
700 }
701 uint32_t valid_mask = atoi(attr[curIdx++]);
702
703 if (strcmp(attr[curIdx++], "device_id")) {
704 ALOGE("%s: device_id not found", __func__);
705 goto done;
706 }
707 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
708 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
709 goto done;
710 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530711 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530712
713 if (strcmp(attr[curIdx++], "type")) {
714 ALOGE("%s: device not found", __func__);
715 goto done;
716 }
717 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
718 ARRAY_SIZE(device_in_types), &microphone.device)) {
719 ALOGE("%s: type %s in %s not found!",
720 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
721 goto done;
722 }
723
724 if (strcmp(attr[curIdx++], "address")) {
725 ALOGE("%s: address not found", __func__);
726 goto done;
727 }
728 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
729 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
730 goto done;
731 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530732 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530733 if (strlen(microphone.address) == 0) {
734 // If the address is empty, populate the address according to device type.
735 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530736 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530737 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530738 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530739 }
740 }
741
742 if (strcmp(attr[curIdx++], "location")) {
743 ALOGE("%s: location not found", __func__);
744 goto done;
745 }
746 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
747 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
748 ALOGE("%s: location %s in %s not found!",
749 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
750 goto done;
751 }
752
753 if (strcmp(attr[curIdx++], "group")) {
754 ALOGE("%s: group not found", __func__);
755 goto done;
756 }
757 microphone.group = atoi(attr[curIdx++]);
758
759 if (strcmp(attr[curIdx++], "index_in_the_group")) {
760 ALOGE("%s: index_in_the_group not found", __func__);
761 goto done;
762 }
763 microphone.index_in_the_group = atoi(attr[curIdx++]);
764
765 if (strcmp(attr[curIdx++], "directionality")) {
766 ALOGE("%s: directionality not found", __func__);
767 goto done;
768 }
769 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
770 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
771 ALOGE("%s: directionality %s in %s not found!",
772 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
773 goto done;
774 }
775
776 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
777 ALOGE("%s: num_frequency_responses not found", __func__);
778 goto done;
779 }
780 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530781 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530782 ALOGE("%s: num_frequency_responses is too large", __func__);
783 goto done;
784 }
785 if (microphone.num_frequency_responses > 0) {
786 if (strcmp(attr[curIdx++], "frequencies")) {
787 ALOGE("%s: frequencies not found", __func__);
788 goto done;
789 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530790 char *context = NULL;
791 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530792 uint32_t num_frequencies = 0;
793 while (token) {
794 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800795 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530796 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530797 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530798 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530799 }
800
801 if (strcmp(attr[curIdx++], "responses")) {
802 ALOGE("%s: responses not found", __func__);
803 goto done;
804 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530805 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530806 uint32_t num_responses = 0;
807 while (token) {
808 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800809 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530810 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530811 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530812 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530813 }
814
815 if (num_frequencies != num_responses
816 || num_frequencies != microphone.num_frequency_responses) {
817 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
818 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
819 goto done;
820 }
821 }
822
823 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
824 if (strcmp(attr[curIdx++], "sensitivity")) {
825 ALOGE("%s: sensitivity not found", __func__);
826 goto done;
827 }
828 microphone.sensitivity = atof(attr[curIdx++]);
829 } else {
830 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
831 }
832
833 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
834 if (strcmp(attr[curIdx++], "max_spl")) {
835 ALOGE("%s: max_spl not found", __func__);
836 goto done;
837 }
838 microphone.max_spl = atof(attr[curIdx++]);
839 } else {
840 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
841 }
842
843 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
844 if (strcmp(attr[curIdx++], "min_spl")) {
845 ALOGE("%s: min_spl not found", __func__);
846 goto done;
847 }
848 microphone.min_spl = atof(attr[curIdx++]);
849 } else {
850 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
851 }
852
853 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
854 if (strcmp(attr[curIdx++], "orientation")) {
855 ALOGE("%s: orientation not found", __func__);
856 goto done;
857 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530858 char *context = NULL;
859 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530860 float orientation[3];
861 uint32_t idx = 0;
862 while (token) {
863 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800864 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530865 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530866 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530867 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530868 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530869 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530870 ALOGE("%s: orientation invalid", __func__);
871 goto done;
872 }
873 microphone.orientation.x = orientation[0];
874 microphone.orientation.y = orientation[1];
875 microphone.orientation.z = orientation[2];
876 } else {
877 microphone.orientation.x = 0.0f;
878 microphone.orientation.y = 0.0f;
879 microphone.orientation.z = 0.0f;
880 }
881
882 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
883 if (strcmp(attr[curIdx++], "geometric_location")) {
884 ALOGE("%s: geometric_location not found", __func__);
885 goto done;
886 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530887 char *context = NULL;
888 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530889 float geometric_location[3];
890 uint32_t idx = 0;
891 while (token) {
892 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800893 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530894 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530895 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530896 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530897 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530898 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530899 ALOGE("%s: geometric_location invalid", __func__);
900 goto done;
901 }
902 microphone.geometric_location.x = geometric_location[0];
903 microphone.geometric_location.y = geometric_location[1];
904 microphone.geometric_location.z = geometric_location[2];
905 } else {
906 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
907 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
908 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
909 }
910
911 platform_set_microphone_characteristic(my_data.platform, microphone);
912done:
913 return;
914}
915
916static void process_snd_dev(const XML_Char **attr)
917{
918 uint32_t curIdx = 0;
919 in_snd_device = SND_DEVICE_NONE;
920
921 if (strcmp(attr[curIdx++], "in_snd_device")) {
922 ALOGE("%s: snd_device not found", __func__);
923 return;
924 }
925 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
926 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
927 in_snd_device >= SND_DEVICE_IN_END) {
928 ALOGE("%s: Sound device not valid", __func__);
929 in_snd_device = SND_DEVICE_NONE;
930 }
931
932 return;
933}
934
935static void process_mic_info(const XML_Char **attr)
936{
937 uint32_t curIdx = 0;
938 struct mic_info microphone;
939
940 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
941 sizeof(microphone.channel_mapping));
942
943 if (strcmp(attr[curIdx++], "mic_device_id")) {
944 ALOGE("%s: mic_device_id not found", __func__);
945 goto on_error;
946 }
947 strlcpy(microphone.device_id,
948 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
949
950 if (strcmp(attr[curIdx++], "channel_mapping")) {
951 ALOGE("%s: channel_mapping not found", __func__);
952 goto on_error;
953 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530954 char *context = NULL;
955 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530956 uint32_t idx = 0;
957 while (token) {
958 if (!find_enum_by_string(mic_channel_mapping, token,
959 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
960 &microphone.channel_mapping[idx++])) {
961 ALOGE("%s: channel_mapping %s in %s not found!",
962 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
963 goto on_error;
964 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530965 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530966 }
967 microphone.channel_count = idx;
968
969 platform_set_microphone_map(my_data.platform, in_snd_device,
970 &microphone);
971 return;
972on_error:
973 in_snd_device = SND_DEVICE_NONE;
974 return;
975}
976
977
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530978/* process acdb meta info key value */
979static void process_acdb_metainfo_key(const XML_Char **attr)
980{
981 if (strcmp(attr[0], "name") != 0) {
982 ALOGE("%s: 'name' not found", __func__);
983 goto done;
984 }
985
986 if (strcmp(attr[2], "value") != 0) {
987 ALOGE("%s: 'value' not found", __func__);
988 goto done;
989 }
990
991 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700992 switch(my_data.caller) {
993 case ACDB_EXTN:
994 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
995 ALOGE("%s: key %d was not set!", __func__, key);
996 goto done;
997 }
998 break;
999 case PLATFORM:
1000 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1001 ALOGE("%s: key %d was not set!", __func__, key);
1002 goto done;
1003 }
1004 break;
1005 default:
1006 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301007 }
1008
1009done:
1010 return;
1011}
1012
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301013static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1014{
1015 uint32_t attr_idx = 0;
1016 int32_t in_ch_idx = -1;
1017 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1018
1019 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1020 &mtmx_in_params_info);
1021 if (mtmx_in_params == NULL) {
1022 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1023 return;
1024 }
1025
1026 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1027 ALOGE("%s: 'in_channel_index' not found", __func__);
1028 return;
1029 }
1030
1031 in_ch_idx = atoi((char *)attr[attr_idx++]);
1032 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1033 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1034 return;
1035 }
1036
1037 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1038 ALOGE("%s: 'channel_count' not found", __func__);
1039 return;
1040 }
1041 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1042
1043 if (strcmp(attr[attr_idx++], "device") != 0) {
1044 ALOGE("%s: 'device' not found", __func__);
1045 return;
1046 }
1047 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1048 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1049
1050 if (strcmp(attr[attr_idx++], "interface") != 0) {
1051 ALOGE("%s: 'interface' not found", __func__);
1052 return;
1053 }
1054 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1055 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1056
1057 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1058 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1059 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1060 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1061 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1062 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1063 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1064 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1065
1066 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1067}
1068
1069static void process_custom_mtmx_in_params(const XML_Char **attr)
1070{
1071 int attr_idx = 0;
1072
1073 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1074 ALOGE("%s: 'usecase' not found", __func__);
1075 return;
1076 }
1077 mtmx_in_params_info.usecase_id = platform_get_usecase_index((char *)attr[attr_idx++]);
1078
1079 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1080 ALOGE("%s: 'out_channel_count' not found", __func__);
1081 return;
1082 }
1083 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1084
1085 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1086
1087}
1088
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301089static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1090{
1091 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
1092 uint32_t ip_channels = 0, op_channels = 0;
1093 char *context = NULL, *ch_coeff_value = NULL;
1094 struct audio_custom_mtmx_params *mtmx_params = NULL;
1095
1096 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1097 ALOGE("%s: 'out_channel_index' not found", __func__);
1098 return;
1099 }
1100 out_ch_idx = atoi((char *)attr[attr_idx++]);
1101
1102 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1103 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1104 return;
1105 }
1106
1107 if (strcmp(attr[attr_idx++], "values") != 0) {
1108 ALOGE("%s: 'values' not found", __func__);
1109 return;
1110 }
1111 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
1112 &mtmx_params_info);
1113 if (mtmx_params == NULL) {
1114 ALOGE("%s: mtmx params with given param info, not found", __func__);
1115 return;
1116 }
1117 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1118 ip_channels = mtmx_params->info.ip_channels;
1119 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301120 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301121 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1122 = atoi(ch_coeff_value);
1123 ch_coeff_value = strtok_r(NULL, " ", &context);
1124 }
1125 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1126 ch_coeff_value != NULL)
1127 ALOGE("%s: invalid/malformed coefficient values", __func__);
1128}
1129
1130static void process_custom_mtmx_params(const XML_Char **attr)
1131{
1132 int attr_idx = 0;
1133
1134 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1135 ALOGE("%s: 'param_id' not found", __func__);
1136 return;
1137 }
1138 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1139
1140 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1141 ALOGE("%s: 'in_channel_count' not found", __func__);
1142 return;
1143 }
1144 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1145
1146 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1147 ALOGE("%s: 'out_channel_count' not found", __func__);
1148 return;
1149 }
1150 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1151
1152 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1153 ALOGE("%s: 'usecase' not found", __func__);
1154 return;
1155 }
1156 mtmx_params_info.usecase_id = platform_get_usecase_index((char *)attr[attr_idx++]);
1157
1158 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1159 ALOGE("%s: 'snd_device' not found", __func__);
1160 return;
1161 }
1162 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301163
1164 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_name") == 0)) {
1165 strlcpy(mtmx_params_info.fe_name, (char *)attr[attr_idx++],
1166 sizeof(mtmx_params_info.fe_name));
1167 } else {
1168 ALOGD("%s: 'fe_name' not found", __func__);
1169 mtmx_params_info.fe_name[0] = '\0';
1170 }
1171
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301172 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1173
1174}
1175
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001176static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001177 const XML_Char **attr)
1178{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001179 if (my_data.caller == ACDB_EXTN) {
1180 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1181 section = ACDB_METAINFO_KEY;
1182 } else if (strcmp(tag_name, "param") == 0) {
1183 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1184 ALOGE("param tag only supported with CONFIG_PARAMS section");
1185 return;
1186 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001187
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001188 section_process_fn fn = section_table[section];
1189 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001190 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001191 } else if(my_data.caller == PLATFORM) {
1192 if (strcmp(tag_name, "bit_width_configs") == 0) {
1193 section = BITWIDTH;
1194 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1195 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001196 } else if (strcmp(tag_name, "module_ids") == 0) {
1197 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001198 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1199 section = PCM_ID;
1200 } else if (strcmp(tag_name, "backend_names") == 0) {
1201 section = BACKEND_NAME;
1202 } else if (strcmp(tag_name, "config_params") == 0) {
1203 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001204 } else if (strcmp(tag_name, "operator_specific") == 0) {
1205 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001206 } else if (strcmp(tag_name, "interface_names") == 0) {
1207 section = INTERFACE_NAME;
1208 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1209 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001210 } else if (strcmp(tag_name, "app_types") == 0) {
1211 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001212 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1213 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301214 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1215 section = MICROPHONE_CHARACTERISTIC;
1216 } else if (strcmp(tag_name, "snd_devices") == 0) {
1217 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001218 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001219 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1220 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001221 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001222 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1223 return;
1224 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001225
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001226 /* call into process function for the current section */
1227 section_process_fn fn = section_table[section];
1228 fn(attr);
1229 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1230 if (section != GAIN_LEVEL_MAPPING) {
1231 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1232 return;
1233 }
1234
1235 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1236 fn(attr);
1237 } else if (strcmp(tag_name, "usecase") == 0) {
1238 if (section != PCM_ID) {
1239 ALOGE("usecase tag only supported with PCM_ID section");
1240 return;
1241 }
1242
1243 section_process_fn fn = section_table[PCM_ID];
1244 fn(attr);
1245 } else if (strcmp(tag_name, "param") == 0) {
1246 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1247 ALOGE("param tag only supported with CONFIG_PARAMS section");
1248 return;
1249 }
1250
1251 section_process_fn fn = section_table[section];
1252 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301253 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001254 if (section != MODULE) {
1255 ALOGE("aec tag only supported with MODULE section");
1256 return;
1257 }
1258 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301259 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001260 if (section != MODULE) {
1261 ALOGE("ns tag only supported with MODULE section");
1262 return;
1263 }
1264 section = NS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001265 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1266 if (section != GAIN_LEVEL_MAPPING) {
1267 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1268 return;
1269 }
1270
1271 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1272 fn(attr);
1273 } else if (!strcmp(tag_name, "app")) {
1274 if (section != APP_TYPE) {
1275 ALOGE("app tag only valid in section APP_TYPE");
1276 return;
1277 }
1278
1279 section_process_fn fn = section_table[APP_TYPE];
1280 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301281 } else if (strcmp(tag_name, "microphone") == 0) {
1282 if (section != MICROPHONE_CHARACTERISTIC) {
1283 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1284 return;
1285 }
1286 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1287 fn(attr);
1288 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1289 if (section != SND_DEVICES) {
1290 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1291 return;
1292 }
1293 section = INPUT_SND_DEVICE;
1294 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1295 if (section != INPUT_SND_DEVICE) {
1296 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1297 return;
1298 }
1299 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1300 } else if (strcmp(tag_name, "snd_dev") == 0) {
1301 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1302 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1303 return;
1304 }
1305 section_process_fn fn = section_table[SND_DEV];
1306 fn(attr);
1307 } else if (strcmp(tag_name, "mic_info") == 0) {
1308 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1309 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1310 return;
1311 }
1312 if (in_snd_device == SND_DEVICE_NONE) {
1313 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1314 return;
1315 }
1316 section_process_fn fn = section_table[MIC_INFO];
1317 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301318 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1319 if (section != ROOT) {
1320 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1321 return;
1322 }
1323 section = CUSTOM_MTMX_PARAMS;
1324 section_process_fn fn = section_table[section];
1325 fn(attr);
1326 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1327 if (section != CUSTOM_MTMX_PARAMS) {
1328 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1329 return;
1330 }
1331 section = CUSTOM_MTMX_PARAM_COEFFS;
1332 section_process_fn fn = section_table[section];
1333 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001334 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1335 section = EXTERNAL_DEVICE_SPECIFIC;
1336 } else if (strcmp(tag_name, "ext_device") == 0) {
1337 section_process_fn fn = section_table[section];
1338 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301339 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1340 if (section != ROOT) {
1341 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1342 return;
1343 }
1344 section = CUSTOM_MTMX_IN_PARAMS;
1345 section_process_fn fn = section_table[section];
1346 fn(attr);
1347 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1348 if (section != CUSTOM_MTMX_IN_PARAMS) {
1349 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1350 return;
1351 }
1352 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
1353 section_process_fn fn = section_table[section];
1354 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301355 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001356 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001357 if(strcmp(tag_name, "config_params") == 0) {
1358 section = CONFIG_PARAMS;
1359 } else if (strcmp(tag_name, "param") == 0) {
1360 if (section != CONFIG_PARAMS) {
1361 ALOGE("param tag only supported with CONFIG_PARAMS section");
1362 return;
1363 }
1364
1365 section_process_fn fn = section_table[section];
1366 fn(attr);
1367 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001368 }
Ben Romberger55886882014-01-10 13:49:02 -08001369 return;
1370}
1371
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001372static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001373{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001374 if (strcmp(tag_name, "bit_width_configs") == 0) {
1375 section = ROOT;
1376 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001377 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001378 } else if (strcmp(tag_name, "module_ids") == 0) {
1379 section = ROOT;
1380 } else if (strcmp(tag_name, "aec") == 0) {
1381 section = MODULE;
1382 } else if (strcmp(tag_name, "ns") == 0) {
1383 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001384 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1385 section = ROOT;
1386 } else if (strcmp(tag_name, "backend_names") == 0) {
1387 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001388 } else if (strcmp(tag_name, "config_params") == 0) {
1389 section = ROOT;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001390 if (my_data.caller == PLATFORM) {
1391 platform_set_parameters(my_data.platform, my_data.kvpairs);
1392 }
Aalique Grahame22e49102018-12-18 14:23:57 -08001393 } else if (strcmp(tag_name, "operator_specific") == 0) {
1394 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001395 } else if (strcmp(tag_name, "interface_names") == 0) {
1396 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001397 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1398 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001399 } else if (strcmp(tag_name, "app_types") == 0) {
1400 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301401 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1402 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301403 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1404 section = ROOT;
1405 } else if (strcmp(tag_name, "snd_devices") == 0) {
1406 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001407 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1408 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301409 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1410 section = SND_DEVICES;
1411 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1412 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301413 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1414 section = ROOT;
1415 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1416 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301417 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1418 section = ROOT;
1419 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1420 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001421 }
Ben Romberger55886882014-01-10 13:49:02 -08001422}
1423
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001424int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001425{
1426 XML_Parser parser;
1427 FILE *file;
1428 int ret = 0;
1429 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001430 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001431 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001432
Aalique Grahame22e49102018-12-18 14:23:57 -08001433 if (filename == NULL)
1434 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1435 MIXER_PATH_MAX_LENGTH);
1436 else
1437 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1438
1439 ALOGV("%s: platform info file name is %s", __func__,
1440 platform_info_file_name);
1441
1442 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001443 section = ROOT;
1444
Ben Romberger55886882014-01-10 13:49:02 -08001445 if (!file) {
1446 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001447 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001448 ret = -ENODEV;
1449 goto done;
1450 }
1451
1452 parser = XML_ParserCreate(NULL);
1453 if (!parser) {
1454 ALOGE("%s: Failed to create XML parser!", __func__);
1455 ret = -ENODEV;
1456 goto err_close_file;
1457 }
1458
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001459 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001460 my_data.platform = platform;
1461 my_data.kvpairs = str_parms_create();
1462
Ben Romberger55886882014-01-10 13:49:02 -08001463 XML_SetElementHandler(parser, start_tag, end_tag);
1464
1465 while (1) {
1466 buf = XML_GetBuffer(parser, BUF_SIZE);
1467 if (buf == NULL) {
1468 ALOGE("%s: XML_GetBuffer failed", __func__);
1469 ret = -ENOMEM;
1470 goto err_free_parser;
1471 }
1472
1473 bytes_read = fread(buf, 1, BUF_SIZE, file);
1474 if (bytes_read < 0) {
1475 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1476 ret = bytes_read;
1477 goto err_free_parser;
1478 }
1479
1480 if (XML_ParseBuffer(parser, bytes_read,
1481 bytes_read == 0) == XML_STATUS_ERROR) {
1482 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001483 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001484 ret = -EINVAL;
1485 goto err_free_parser;
1486 }
1487
1488 if (bytes_read == 0)
1489 break;
1490 }
1491
Ben Romberger55886882014-01-10 13:49:02 -08001492err_free_parser:
1493 XML_ParserFree(parser);
1494err_close_file:
1495 fclose(file);
1496done:
1497 return ret;
1498}