blob: 3341f2072b45a7492e65a343ba20ffe3518b1270 [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Naresh Tannirudcb47c52018-06-25 16:23:32 +05302 * Copyright (c) 2014-2018, 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>
36#include <cutils/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,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070063 GAIN_LEVEL_MAPPING,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053064 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053065 MICROPHONE_CHARACTERISTIC,
66 SND_DEVICES,
67 INPUT_SND_DEVICE,
68 INPUT_SND_DEVICE_TO_MIC_MAPPING,
69 SND_DEV,
70 MIC_INFO,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070071} section_t;
72
73typedef void (* section_process_fn)(const XML_Char **attr);
74
75static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070076static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
77static void process_effect_aec(const XML_Char **attr);
78static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070079static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070080static void process_pcm_id(const XML_Char **attr);
81static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080082static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070083static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070084static void process_root(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070085static void process_gain_db_to_level_map(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053086static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053087static void process_microphone_characteristic(const XML_Char **attr);
88static void process_snd_dev(const XML_Char **attr);
89static void process_mic_info(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070090
91static section_process_fn section_table[] = {
92 [ROOT] = process_root,
93 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070094 [AEC] = process_effect_aec,
95 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -070096 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070097 [PCM_ID] = process_pcm_id,
98 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080099 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700100 [CONFIG_PARAMS] = process_config_params,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700101 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530102 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530103 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
104 [SND_DEV] = process_snd_dev,
105 [MIC_INFO] = process_mic_info,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700106};
107
108static section_t section;
109
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700110struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700111 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700112 void *platform;
113 struct str_parms *kvpairs;
114};
115
116static struct platform_info my_data;
117
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530118
119struct audio_string_to_enum {
120 const char* name;
121 unsigned int value;
122};
123
124static snd_device_t in_snd_device;
125
126static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
127 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
128 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
129 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
130 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
131};
132
133static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
134 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
135 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
136 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
137 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
138 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
139 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
140};
141
142static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
143 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
144 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
145 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
146};
147
148static const struct audio_string_to_enum device_in_types[] = {
149 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
150 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
151 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
152 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
153 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
154 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
155 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
157 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
163 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
167 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
176};
177
178enum {
179 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
180 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
181 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
182 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
183 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
184 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
185 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
186 | ORIENTATION) | GEOMETRIC_LOCATION) */
187};
188
189static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
190 int32_t len, unsigned int *value)
191{
192 if (table == NULL) {
193 ALOGE("%s: table is NULL", __func__);
194 return false;
195 }
196
197 if (name == NULL) {
198 ALOGE("null key");
199 return false;
200 }
201
202 for (int i = 0; i < len; i++) {
203 if (!strcmp(table[i].name, name)) {
204 *value = table[i].value;
205 return true;
206 }
207 }
208 return false;
209}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700210/*
211 * <audio_platform_info>
212 * <acdb_ids>
213 * <device name="???" acdb_id="???"/>
214 * ...
215 * ...
216 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700217 * <module_ids>
218 * <device name="???" module_id="???"/>
219 * ...
220 * ...
221 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700222 * <backend_names>
223 * <device name="???" backend="???"/>
224 * ...
225 * ...
226 * </backend_names>
227 * <pcm_ids>
228 * <usecase name="???" type="in/out" id="???"/>
229 * ...
230 * ...
231 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800232 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530233 * <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 -0800234 * ...
235 * ...
236 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700237 * <config_params>
238 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
239 * ...
240 * ...
241 * </config_params>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700242 * </audio_platform_info>
243 */
244
245static void process_root(const XML_Char **attr __unused)
246{
247}
248
249/* mapping from usecase to pcm dev id */
250static void process_pcm_id(const XML_Char **attr)
251{
252 int index;
253
254 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700255 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700256 goto done;
257 }
258
259 index = platform_get_usecase_index((char *)attr[1]);
260 if (index < 0) {
261 ALOGE("%s: usecase %s not found!",
262 __func__, attr[1]);
263 goto done;
264 }
265
266 if (strcmp(attr[2], "type") != 0) {
267 ALOGE("%s: usecase type not mentioned", __func__);
268 goto done;
269 }
270
271 int type = -1;
272
273 if (!strcasecmp((char *)attr[3], "in")) {
274 type = 1;
275 } else if (!strcasecmp((char *)attr[3], "out")) {
276 type = 0;
277 } else {
278 ALOGE("%s: type must be IN or OUT", __func__);
279 goto done;
280 }
281
282 if (strcmp(attr[4], "id") != 0) {
283 ALOGE("%s: usecase id not mentioned", __func__);
284 goto done;
285 }
286
287 int id = atoi((char *)attr[5]);
288
289 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
290 ALOGE("%s: usecase %s type %d id %d was not set!",
291 __func__, attr[1], type, id);
292 goto done;
293 }
294
295done:
296 return;
297}
298
299/* backend to be used for a device */
300static void process_backend_name(const XML_Char **attr)
301{
302 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530303 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530304 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700305
306 if (strcmp(attr[0], "name") != 0) {
307 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
308 goto done;
309 }
310
311 index = platform_get_snd_device_index((char *)attr[1]);
312 if (index < 0) {
313 ALOGE("%s: Device %s not found, no ACDB ID set!",
314 __func__, attr[1]);
315 goto done;
316 }
317
318 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530319 if (strcmp(attr[2], "interface") == 0)
320 hw_interface = (char *)attr[3];
321 } else {
322 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700323 }
324
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530325 if (attr[4] != NULL) {
326 if (strcmp(attr[4], "interface") != 0) {
327 hw_interface = NULL;
328 } else {
329 hw_interface = (char *)attr[5];
330 }
331 }
332
Ashish Jaind150d4c2017-02-03 18:44:34 +0530333 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700334 ALOGE("%s: Device %s backend %s was not set!",
335 __func__, attr[1], attr[3]);
336 goto done;
337 }
338
339done:
340 return;
341}
342
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700343static void process_gain_db_to_level_map(const XML_Char **attr)
344{
345 struct amp_db_and_gain_table tbl_entry;
346
347 if ((strcmp(attr[0], "db") != 0) ||
348 (strcmp(attr[2], "level") != 0)) {
349 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
350 __func__, attr[0], attr[2]);
351 goto done;
352 }
353
354 tbl_entry.db = atof(attr[1]);
355 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
356 tbl_entry.level = atoi(attr[3]);
357
358 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
359 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
360 platform_add_gain_level_mapping(&tbl_entry);
361
362done:
363 return;
364}
365
366
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700367static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800368{
Ben Romberger61764e32014-01-10 13:49:02 -0800369 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800370
Ben Romberger61764e32014-01-10 13:49:02 -0800371 if (strcmp(attr[0], "name") != 0) {
372 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800373 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800374 }
Ben Romberger55886882014-01-10 13:49:02 -0800375
Ben Romberger61764e32014-01-10 13:49:02 -0800376 index = platform_get_snd_device_index((char *)attr[1]);
377 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800378 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
379 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800380 goto done;
381 }
382
383 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800384 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
385 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800386 goto done;
387 }
388
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700389 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
390 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800391 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800392 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800393 }
Ben Romberger55886882014-01-10 13:49:02 -0800394
Ben Romberger55886882014-01-10 13:49:02 -0800395done:
396 return;
397}
398
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700399static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
400{
401 int index;
402 struct audio_effect_config effect_config;
403
404 if (strcmp(attr[0], "name") != 0) {
405 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
406 goto done;
407 }
408
409 index = platform_get_snd_device_index((char *)attr[1]);
410 if (index < 0) {
411 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
412 __func__, attr[1]);
413 goto done;
414 }
415
416 if (strcmp(attr[2], "module_id") != 0) {
417 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
418 __func__, attr[2]);
419 goto done;
420 }
421
422 if (strcmp(attr[4], "instance_id") != 0) {
423 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
424 __func__, attr[4]);
425 goto done;
426 }
427
428 if (strcmp(attr[6], "param_id") != 0) {
429 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
430 __func__, attr[6]);
431 goto done;
432 }
433
434 if (strcmp(attr[8], "param_value") != 0) {
435 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
436 __func__, attr[8]);
437 goto done;
438 }
439
440 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
441 strtol((char *)attr[5], NULL, 0),
442 strtol((char *)attr[7], NULL, 0),
443 strtol((char *)attr[9], NULL, 0)};
444
445
446 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
447 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
448 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
449 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
450 strtol((char *)attr[9], NULL, 0));
451 goto done;
452 }
453
454done:
455 return;
456}
457
458static void process_effect_aec(const XML_Char **attr)
459{
460 process_audio_effect(attr, EFFECT_AEC);
461 return;
462}
463
464static void process_effect_ns(const XML_Char **attr)
465{
466 process_audio_effect(attr, EFFECT_NS);
467 return;
468}
469
Amit Shekhar5a39c912014-10-14 15:39:30 -0700470static void process_bit_width(const XML_Char **attr)
471{
472 int index;
473
474 if (strcmp(attr[0], "name") != 0) {
475 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
476 goto done;
477 }
478
479 index = platform_get_snd_device_index((char *)attr[1]);
480 if (index < 0) {
481 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
482 __func__, attr[1]);
483 goto done;
484 }
485
486 if (strcmp(attr[2], "bit_width") != 0) {
487 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
488 __func__, attr[1]);
489 goto done;
490 }
491
492 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
493 ALOGE("%s: Device %s, ACDB ID %d was not set!",
494 __func__, attr[1], atoi((char *)attr[3]));
495 goto done;
496 }
497
498done:
499 return;
500}
501
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800502static void process_interface_name(const XML_Char **attr)
503{
504 int ret;
505
506 if (strcmp(attr[0], "name") != 0) {
507 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
508
509 goto done;
510 }
511
512 if (strcmp(attr[2], "interface") != 0) {
513 ALOGE("%s: Device %s has no Audio Interface set!",
514 __func__, attr[1]);
515
516 goto done;
517 }
518
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530519 if (strcmp(attr[4], "codec_type") != 0) {
520 ALOGE("%s: Device %s has no codec type set!",
521 __func__, attr[1]);
522
523 goto done;
524 }
525
526 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
527 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800528 if (ret < 0) {
529 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800530 goto done;
531 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800532
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800533done:
534 return;
535}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530536
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700537static void process_config_params(const XML_Char **attr)
538{
539 if (strcmp(attr[0], "key") != 0) {
540 ALOGE("%s: 'key' not found", __func__);
541 goto done;
542 }
543
544 if (strcmp(attr[2], "value") != 0) {
545 ALOGE("%s: 'value' not found", __func__);
546 goto done;
547 }
548
549 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
550done:
551 return;
552}
553
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530554static void process_microphone_characteristic(const XML_Char **attr) {
555 struct audio_microphone_characteristic_t microphone;
556 uint32_t curIdx = 0;
557
558 if (strcmp(attr[curIdx++], "valid_mask")) {
559 ALOGE("%s: valid_mask not found", __func__);
560 goto done;
561 }
562 uint32_t valid_mask = atoi(attr[curIdx++]);
563
564 if (strcmp(attr[curIdx++], "device_id")) {
565 ALOGE("%s: device_id not found", __func__);
566 goto done;
567 }
568 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
569 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
570 goto done;
571 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530572 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530573
574 if (strcmp(attr[curIdx++], "type")) {
575 ALOGE("%s: device not found", __func__);
576 goto done;
577 }
578 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
579 ARRAY_SIZE(device_in_types), &microphone.device)) {
580 ALOGE("%s: type %s in %s not found!",
581 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
582 goto done;
583 }
584
585 if (strcmp(attr[curIdx++], "address")) {
586 ALOGE("%s: address not found", __func__);
587 goto done;
588 }
589 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
590 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
591 goto done;
592 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530593 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530594 if (strlen(microphone.address) == 0) {
595 // If the address is empty, populate the address according to device type.
596 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530597 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530598 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530599 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530600 }
601 }
602
603 if (strcmp(attr[curIdx++], "location")) {
604 ALOGE("%s: location not found", __func__);
605 goto done;
606 }
607 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
608 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
609 ALOGE("%s: location %s in %s not found!",
610 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
611 goto done;
612 }
613
614 if (strcmp(attr[curIdx++], "group")) {
615 ALOGE("%s: group not found", __func__);
616 goto done;
617 }
618 microphone.group = atoi(attr[curIdx++]);
619
620 if (strcmp(attr[curIdx++], "index_in_the_group")) {
621 ALOGE("%s: index_in_the_group not found", __func__);
622 goto done;
623 }
624 microphone.index_in_the_group = atoi(attr[curIdx++]);
625
626 if (strcmp(attr[curIdx++], "directionality")) {
627 ALOGE("%s: directionality not found", __func__);
628 goto done;
629 }
630 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
631 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
632 ALOGE("%s: directionality %s in %s not found!",
633 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
634 goto done;
635 }
636
637 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
638 ALOGE("%s: num_frequency_responses not found", __func__);
639 goto done;
640 }
641 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530642 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530643 ALOGE("%s: num_frequency_responses is too large", __func__);
644 goto done;
645 }
646 if (microphone.num_frequency_responses > 0) {
647 if (strcmp(attr[curIdx++], "frequencies")) {
648 ALOGE("%s: frequencies not found", __func__);
649 goto done;
650 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530651 char *context = NULL;
652 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530653 uint32_t num_frequencies = 0;
654 while (token) {
655 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800656 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530657 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530658 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530659 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530660 }
661
662 if (strcmp(attr[curIdx++], "responses")) {
663 ALOGE("%s: responses not found", __func__);
664 goto done;
665 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530666 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530667 uint32_t num_responses = 0;
668 while (token) {
669 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800670 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530671 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530672 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530673 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530674 }
675
676 if (num_frequencies != num_responses
677 || num_frequencies != microphone.num_frequency_responses) {
678 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
679 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
680 goto done;
681 }
682 }
683
684 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
685 if (strcmp(attr[curIdx++], "sensitivity")) {
686 ALOGE("%s: sensitivity not found", __func__);
687 goto done;
688 }
689 microphone.sensitivity = atof(attr[curIdx++]);
690 } else {
691 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
692 }
693
694 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
695 if (strcmp(attr[curIdx++], "max_spl")) {
696 ALOGE("%s: max_spl not found", __func__);
697 goto done;
698 }
699 microphone.max_spl = atof(attr[curIdx++]);
700 } else {
701 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
702 }
703
704 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
705 if (strcmp(attr[curIdx++], "min_spl")) {
706 ALOGE("%s: min_spl not found", __func__);
707 goto done;
708 }
709 microphone.min_spl = atof(attr[curIdx++]);
710 } else {
711 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
712 }
713
714 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
715 if (strcmp(attr[curIdx++], "orientation")) {
716 ALOGE("%s: orientation not found", __func__);
717 goto done;
718 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530719 char *context = NULL;
720 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530721 float orientation[3];
722 uint32_t idx = 0;
723 while (token) {
724 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800725 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530726 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530727 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530728 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530729 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530730 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530731 ALOGE("%s: orientation invalid", __func__);
732 goto done;
733 }
734 microphone.orientation.x = orientation[0];
735 microphone.orientation.y = orientation[1];
736 microphone.orientation.z = orientation[2];
737 } else {
738 microphone.orientation.x = 0.0f;
739 microphone.orientation.y = 0.0f;
740 microphone.orientation.z = 0.0f;
741 }
742
743 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
744 if (strcmp(attr[curIdx++], "geometric_location")) {
745 ALOGE("%s: geometric_location not found", __func__);
746 goto done;
747 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530748 char *context = NULL;
749 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530750 float geometric_location[3];
751 uint32_t idx = 0;
752 while (token) {
753 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800754 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530755 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530756 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530757 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530758 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530759 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530760 ALOGE("%s: geometric_location invalid", __func__);
761 goto done;
762 }
763 microphone.geometric_location.x = geometric_location[0];
764 microphone.geometric_location.y = geometric_location[1];
765 microphone.geometric_location.z = geometric_location[2];
766 } else {
767 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
768 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
769 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
770 }
771
772 platform_set_microphone_characteristic(my_data.platform, microphone);
773done:
774 return;
775}
776
777static void process_snd_dev(const XML_Char **attr)
778{
779 uint32_t curIdx = 0;
780 in_snd_device = SND_DEVICE_NONE;
781
782 if (strcmp(attr[curIdx++], "in_snd_device")) {
783 ALOGE("%s: snd_device not found", __func__);
784 return;
785 }
786 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
787 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
788 in_snd_device >= SND_DEVICE_IN_END) {
789 ALOGE("%s: Sound device not valid", __func__);
790 in_snd_device = SND_DEVICE_NONE;
791 }
792
793 return;
794}
795
796static void process_mic_info(const XML_Char **attr)
797{
798 uint32_t curIdx = 0;
799 struct mic_info microphone;
800
801 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
802 sizeof(microphone.channel_mapping));
803
804 if (strcmp(attr[curIdx++], "mic_device_id")) {
805 ALOGE("%s: mic_device_id not found", __func__);
806 goto on_error;
807 }
808 strlcpy(microphone.device_id,
809 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
810
811 if (strcmp(attr[curIdx++], "channel_mapping")) {
812 ALOGE("%s: channel_mapping not found", __func__);
813 goto on_error;
814 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530815 char *context = NULL;
816 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530817 uint32_t idx = 0;
818 while (token) {
819 if (!find_enum_by_string(mic_channel_mapping, token,
820 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
821 &microphone.channel_mapping[idx++])) {
822 ALOGE("%s: channel_mapping %s in %s not found!",
823 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
824 goto on_error;
825 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530826 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530827 }
828 microphone.channel_count = idx;
829
830 platform_set_microphone_map(my_data.platform, in_snd_device,
831 &microphone);
832 return;
833on_error:
834 in_snd_device = SND_DEVICE_NONE;
835 return;
836}
837
838
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530839/* process acdb meta info key value */
840static void process_acdb_metainfo_key(const XML_Char **attr)
841{
842 if (strcmp(attr[0], "name") != 0) {
843 ALOGE("%s: 'name' not found", __func__);
844 goto done;
845 }
846
847 if (strcmp(attr[2], "value") != 0) {
848 ALOGE("%s: 'value' not found", __func__);
849 goto done;
850 }
851
852 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700853 switch(my_data.caller) {
854 case ACDB_EXTN:
855 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
856 ALOGE("%s: key %d was not set!", __func__, key);
857 goto done;
858 }
859 break;
860 case PLATFORM:
861 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
862 ALOGE("%s: key %d was not set!", __func__, key);
863 goto done;
864 }
865 break;
866 default:
867 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530868 }
869
870done:
871 return;
872}
873
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700874static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -0800875 const XML_Char **attr)
876{
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700877 if (my_data.caller == ACDB_EXTN) {
878 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
879 section = ACDB_METAINFO_KEY;
880 } else if (strcmp(tag_name, "param") == 0) {
881 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
882 ALOGE("param tag only supported with CONFIG_PARAMS section");
883 return;
884 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700885
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700886 section_process_fn fn = section_table[section];
887 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700888 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700889 } else if(my_data.caller == PLATFORM) {
890 if (strcmp(tag_name, "bit_width_configs") == 0) {
891 section = BITWIDTH;
892 } else if (strcmp(tag_name, "acdb_ids") == 0) {
893 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700894 } else if (strcmp(tag_name, "module_ids") == 0) {
895 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700896 } else if (strcmp(tag_name, "pcm_ids") == 0) {
897 section = PCM_ID;
898 } else if (strcmp(tag_name, "backend_names") == 0) {
899 section = BACKEND_NAME;
900 } else if (strcmp(tag_name, "config_params") == 0) {
901 section = CONFIG_PARAMS;
902 } else if (strcmp(tag_name, "interface_names") == 0) {
903 section = INTERFACE_NAME;
904 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
905 section = GAIN_LEVEL_MAPPING;
906 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
907 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530908 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
909 section = MICROPHONE_CHARACTERISTIC;
910 } else if (strcmp(tag_name, "snd_devices") == 0) {
911 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700912 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700913 if ((section != ACDB) && (section != AEC) && (section != NS) &&
914 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700915 (section != INTERFACE_NAME)) {
916 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
917 return;
918 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700919
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700920 /* call into process function for the current section */
921 section_process_fn fn = section_table[section];
922 fn(attr);
923 } else if (strcmp(tag_name, "gain_level_map") == 0) {
924 if (section != GAIN_LEVEL_MAPPING) {
925 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
926 return;
927 }
928
929 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
930 fn(attr);
931 } else if (strcmp(tag_name, "usecase") == 0) {
932 if (section != PCM_ID) {
933 ALOGE("usecase tag only supported with PCM_ID section");
934 return;
935 }
936
937 section_process_fn fn = section_table[PCM_ID];
938 fn(attr);
939 } else if (strcmp(tag_name, "param") == 0) {
940 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
941 ALOGE("param tag only supported with CONFIG_PARAMS section");
942 return;
943 }
944
945 section_process_fn fn = section_table[section];
946 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530947 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700948 if (section != MODULE) {
949 ALOGE("aec tag only supported with MODULE section");
950 return;
951 }
952 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530953 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700954 if (section != MODULE) {
955 ALOGE("ns tag only supported with MODULE section");
956 return;
957 }
958 section = NS;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530959 } else if (strcmp(tag_name, "microphone") == 0) {
960 if (section != MICROPHONE_CHARACTERISTIC) {
961 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
962 return;
963 }
964 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
965 fn(attr);
966 } else if (strcmp(tag_name, "input_snd_device") == 0) {
967 if (section != SND_DEVICES) {
968 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
969 return;
970 }
971 section = INPUT_SND_DEVICE;
972 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
973 if (section != INPUT_SND_DEVICE) {
974 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
975 return;
976 }
977 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
978 } else if (strcmp(tag_name, "snd_dev") == 0) {
979 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
980 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
981 return;
982 }
983 section_process_fn fn = section_table[SND_DEV];
984 fn(attr);
985 } else if (strcmp(tag_name, "mic_info") == 0) {
986 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
987 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
988 return;
989 }
990 if (in_snd_device == SND_DEVICE_NONE) {
991 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
992 return;
993 }
994 section_process_fn fn = section_table[MIC_INFO];
995 fn(attr);
996 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700997 } else {
998 ALOGE("%s: unknown caller!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700999 }
Ben Romberger55886882014-01-10 13:49:02 -08001000 return;
1001}
1002
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001003static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001004{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001005 if (strcmp(tag_name, "bit_width_configs") == 0) {
1006 section = ROOT;
1007 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001008 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001009 } else if (strcmp(tag_name, "module_ids") == 0) {
1010 section = ROOT;
1011 } else if (strcmp(tag_name, "aec") == 0) {
1012 section = MODULE;
1013 } else if (strcmp(tag_name, "ns") == 0) {
1014 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001015 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1016 section = ROOT;
1017 } else if (strcmp(tag_name, "backend_names") == 0) {
1018 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001019 } else if (strcmp(tag_name, "config_params") == 0) {
1020 section = ROOT;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001021 if (my_data.caller == PLATFORM) {
1022 platform_set_parameters(my_data.platform, my_data.kvpairs);
1023 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001024 } else if (strcmp(tag_name, "interface_names") == 0) {
1025 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001026 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1027 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301028 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1029 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301030 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1031 section = ROOT;
1032 } else if (strcmp(tag_name, "snd_devices") == 0) {
1033 section = ROOT;
1034 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1035 section = SND_DEVICES;
1036 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1037 section = INPUT_SND_DEVICE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001038 }
Ben Romberger55886882014-01-10 13:49:02 -08001039}
1040
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001041int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001042{
1043 XML_Parser parser;
1044 FILE *file;
1045 int ret = 0;
1046 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001047 void *buf;
1048
Helen Zeng6a16ad72014-02-23 22:04:44 -08001049 file = fopen(filename, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001050 section = ROOT;
1051
Ben Romberger55886882014-01-10 13:49:02 -08001052 if (!file) {
1053 ALOGD("%s: Failed to open %s, using defaults.",
Helen Zeng6a16ad72014-02-23 22:04:44 -08001054 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -08001055 ret = -ENODEV;
1056 goto done;
1057 }
1058
1059 parser = XML_ParserCreate(NULL);
1060 if (!parser) {
1061 ALOGE("%s: Failed to create XML parser!", __func__);
1062 ret = -ENODEV;
1063 goto err_close_file;
1064 }
1065
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001066 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001067 my_data.platform = platform;
1068 my_data.kvpairs = str_parms_create();
1069
Ben Romberger55886882014-01-10 13:49:02 -08001070 XML_SetElementHandler(parser, start_tag, end_tag);
1071
1072 while (1) {
1073 buf = XML_GetBuffer(parser, BUF_SIZE);
1074 if (buf == NULL) {
1075 ALOGE("%s: XML_GetBuffer failed", __func__);
1076 ret = -ENOMEM;
1077 goto err_free_parser;
1078 }
1079
1080 bytes_read = fread(buf, 1, BUF_SIZE, file);
1081 if (bytes_read < 0) {
1082 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1083 ret = bytes_read;
1084 goto err_free_parser;
1085 }
1086
1087 if (XML_ParseBuffer(parser, bytes_read,
1088 bytes_read == 0) == XML_STATUS_ERROR) {
1089 ALOGE("%s: XML_ParseBuffer failed, for %s",
Helen Zeng6a16ad72014-02-23 22:04:44 -08001090 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -08001091 ret = -EINVAL;
1092 goto err_free_parser;
1093 }
1094
1095 if (bytes_read == 0)
1096 break;
1097 }
1098
Ben Romberger55886882014-01-10 13:49:02 -08001099err_free_parser:
1100 XML_ParserFree(parser);
1101err_close_file:
1102 fclose(file);
1103done:
1104 return ret;
1105}