blob: e35b7c40b51f6fc5ef2e59d8c01ca088c2ddf752 [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++]);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800642 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) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530657 ALOGE("%s: num %u of frequency is too large", __func__, num_frequencies);
658 goto done;
659 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530660 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530661 }
662
663 if (strcmp(attr[curIdx++], "responses")) {
664 ALOGE("%s: responses not found", __func__);
665 goto done;
666 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530667 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530668 uint32_t num_responses = 0;
669 while (token) {
670 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800671 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530672 ALOGE("%s: num %u of response is too large", __func__, num_responses);
673 goto done;
674 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530675 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530676 }
677
678 if (num_frequencies != num_responses
679 || num_frequencies != microphone.num_frequency_responses) {
680 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
681 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
682 goto done;
683 }
684 }
685
686 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
687 if (strcmp(attr[curIdx++], "sensitivity")) {
688 ALOGE("%s: sensitivity not found", __func__);
689 goto done;
690 }
691 microphone.sensitivity = atof(attr[curIdx++]);
692 } else {
693 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
694 }
695
696 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
697 if (strcmp(attr[curIdx++], "max_spl")) {
698 ALOGE("%s: max_spl not found", __func__);
699 goto done;
700 }
701 microphone.max_spl = atof(attr[curIdx++]);
702 } else {
703 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
704 }
705
706 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
707 if (strcmp(attr[curIdx++], "min_spl")) {
708 ALOGE("%s: min_spl not found", __func__);
709 goto done;
710 }
711 microphone.min_spl = atof(attr[curIdx++]);
712 } else {
713 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
714 }
715
716 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
717 if (strcmp(attr[curIdx++], "orientation")) {
718 ALOGE("%s: orientation not found", __func__);
719 goto done;
720 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530721 char *context = NULL;
722 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530723 float orientation[3];
724 uint32_t idx = 0;
725 while (token) {
726 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800727 if (idx >= 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530728 ALOGE("%s: orientation invalid", __func__);
729 goto done;
730 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530731 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530732 }
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800733 if (idx != 2) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530734 ALOGE("%s: orientation invalid", __func__);
735 goto done;
736 }
737 microphone.orientation.x = orientation[0];
738 microphone.orientation.y = orientation[1];
739 microphone.orientation.z = orientation[2];
740 } else {
741 microphone.orientation.x = 0.0f;
742 microphone.orientation.y = 0.0f;
743 microphone.orientation.z = 0.0f;
744 }
745
746 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
747 if (strcmp(attr[curIdx++], "geometric_location")) {
748 ALOGE("%s: geometric_location not found", __func__);
749 goto done;
750 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530751 char *context = NULL;
752 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530753 float geometric_location[3];
754 uint32_t idx = 0;
755 while (token) {
756 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800757 if (idx >= 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530758 ALOGE("%s: geometric_location invalid", __func__);
759 goto done;
760 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530761 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530762 }
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800763 if (idx != 2) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530764 ALOGE("%s: geometric_location invalid", __func__);
765 goto done;
766 }
767 microphone.geometric_location.x = geometric_location[0];
768 microphone.geometric_location.y = geometric_location[1];
769 microphone.geometric_location.z = geometric_location[2];
770 } else {
771 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
772 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
773 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
774 }
775
776 platform_set_microphone_characteristic(my_data.platform, microphone);
777done:
778 return;
779}
780
781static void process_snd_dev(const XML_Char **attr)
782{
783 uint32_t curIdx = 0;
784 in_snd_device = SND_DEVICE_NONE;
785
786 if (strcmp(attr[curIdx++], "in_snd_device")) {
787 ALOGE("%s: snd_device not found", __func__);
788 return;
789 }
790 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
791 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
792 in_snd_device >= SND_DEVICE_IN_END) {
793 ALOGE("%s: Sound device not valid", __func__);
794 in_snd_device = SND_DEVICE_NONE;
795 }
796
797 return;
798}
799
800static void process_mic_info(const XML_Char **attr)
801{
802 uint32_t curIdx = 0;
803 struct mic_info microphone;
804
805 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
806 sizeof(microphone.channel_mapping));
807
808 if (strcmp(attr[curIdx++], "mic_device_id")) {
809 ALOGE("%s: mic_device_id not found", __func__);
810 goto on_error;
811 }
812 strlcpy(microphone.device_id,
813 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
814
815 if (strcmp(attr[curIdx++], "channel_mapping")) {
816 ALOGE("%s: channel_mapping not found", __func__);
817 goto on_error;
818 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530819 char *context = NULL;
820 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530821 uint32_t idx = 0;
822 while (token) {
823 if (!find_enum_by_string(mic_channel_mapping, token,
824 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
825 &microphone.channel_mapping[idx++])) {
826 ALOGE("%s: channel_mapping %s in %s not found!",
827 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
828 goto on_error;
829 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530830 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530831 }
832 microphone.channel_count = idx;
833
834 platform_set_microphone_map(my_data.platform, in_snd_device,
835 &microphone);
836 return;
837on_error:
838 in_snd_device = SND_DEVICE_NONE;
839 return;
840}
841
842
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530843/* process acdb meta info key value */
844static void process_acdb_metainfo_key(const XML_Char **attr)
845{
846 if (strcmp(attr[0], "name") != 0) {
847 ALOGE("%s: 'name' not found", __func__);
848 goto done;
849 }
850
851 if (strcmp(attr[2], "value") != 0) {
852 ALOGE("%s: 'value' not found", __func__);
853 goto done;
854 }
855
856 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700857 switch(my_data.caller) {
858 case ACDB_EXTN:
859 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
860 ALOGE("%s: key %d was not set!", __func__, key);
861 goto done;
862 }
863 break;
864 case PLATFORM:
865 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
866 ALOGE("%s: key %d was not set!", __func__, key);
867 goto done;
868 }
869 break;
870 default:
871 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530872 }
873
874done:
875 return;
876}
877
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700878static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -0800879 const XML_Char **attr)
880{
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700881 if (my_data.caller == ACDB_EXTN) {
882 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
883 section = ACDB_METAINFO_KEY;
884 } else if (strcmp(tag_name, "param") == 0) {
885 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
886 ALOGE("param tag only supported with CONFIG_PARAMS section");
887 return;
888 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700889
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700890 section_process_fn fn = section_table[section];
891 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700892 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700893 } else if(my_data.caller == PLATFORM) {
894 if (strcmp(tag_name, "bit_width_configs") == 0) {
895 section = BITWIDTH;
896 } else if (strcmp(tag_name, "acdb_ids") == 0) {
897 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700898 } else if (strcmp(tag_name, "module_ids") == 0) {
899 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700900 } else if (strcmp(tag_name, "pcm_ids") == 0) {
901 section = PCM_ID;
902 } else if (strcmp(tag_name, "backend_names") == 0) {
903 section = BACKEND_NAME;
904 } else if (strcmp(tag_name, "config_params") == 0) {
905 section = CONFIG_PARAMS;
906 } else if (strcmp(tag_name, "interface_names") == 0) {
907 section = INTERFACE_NAME;
908 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
909 section = GAIN_LEVEL_MAPPING;
910 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
911 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530912 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
913 section = MICROPHONE_CHARACTERISTIC;
914 } else if (strcmp(tag_name, "snd_devices") == 0) {
915 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700916 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700917 if ((section != ACDB) && (section != AEC) && (section != NS) &&
918 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700919 (section != INTERFACE_NAME)) {
920 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
921 return;
922 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700923
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700924 /* call into process function for the current section */
925 section_process_fn fn = section_table[section];
926 fn(attr);
927 } else if (strcmp(tag_name, "gain_level_map") == 0) {
928 if (section != GAIN_LEVEL_MAPPING) {
929 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
930 return;
931 }
932
933 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
934 fn(attr);
935 } else if (strcmp(tag_name, "usecase") == 0) {
936 if (section != PCM_ID) {
937 ALOGE("usecase tag only supported with PCM_ID section");
938 return;
939 }
940
941 section_process_fn fn = section_table[PCM_ID];
942 fn(attr);
943 } else if (strcmp(tag_name, "param") == 0) {
944 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
945 ALOGE("param tag only supported with CONFIG_PARAMS section");
946 return;
947 }
948
949 section_process_fn fn = section_table[section];
950 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530951 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700952 if (section != MODULE) {
953 ALOGE("aec tag only supported with MODULE section");
954 return;
955 }
956 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530957 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700958 if (section != MODULE) {
959 ALOGE("ns tag only supported with MODULE section");
960 return;
961 }
962 section = NS;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530963 } else if (strcmp(tag_name, "microphone") == 0) {
964 if (section != MICROPHONE_CHARACTERISTIC) {
965 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
966 return;
967 }
968 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
969 fn(attr);
970 } else if (strcmp(tag_name, "input_snd_device") == 0) {
971 if (section != SND_DEVICES) {
972 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
973 return;
974 }
975 section = INPUT_SND_DEVICE;
976 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
977 if (section != INPUT_SND_DEVICE) {
978 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
979 return;
980 }
981 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
982 } else if (strcmp(tag_name, "snd_dev") == 0) {
983 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
984 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
985 return;
986 }
987 section_process_fn fn = section_table[SND_DEV];
988 fn(attr);
989 } else if (strcmp(tag_name, "mic_info") == 0) {
990 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
991 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
992 return;
993 }
994 if (in_snd_device == SND_DEVICE_NONE) {
995 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
996 return;
997 }
998 section_process_fn fn = section_table[MIC_INFO];
999 fn(attr);
1000 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001001 } else {
1002 ALOGE("%s: unknown caller!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001003 }
Ben Romberger55886882014-01-10 13:49:02 -08001004 return;
1005}
1006
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001007static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001008{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001009 if (strcmp(tag_name, "bit_width_configs") == 0) {
1010 section = ROOT;
1011 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001012 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001013 } else if (strcmp(tag_name, "module_ids") == 0) {
1014 section = ROOT;
1015 } else if (strcmp(tag_name, "aec") == 0) {
1016 section = MODULE;
1017 } else if (strcmp(tag_name, "ns") == 0) {
1018 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001019 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1020 section = ROOT;
1021 } else if (strcmp(tag_name, "backend_names") == 0) {
1022 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001023 } else if (strcmp(tag_name, "config_params") == 0) {
1024 section = ROOT;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001025 if (my_data.caller == PLATFORM) {
1026 platform_set_parameters(my_data.platform, my_data.kvpairs);
1027 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001028 } else if (strcmp(tag_name, "interface_names") == 0) {
1029 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001030 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1031 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301032 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1033 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301034 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1035 section = ROOT;
1036 } else if (strcmp(tag_name, "snd_devices") == 0) {
1037 section = ROOT;
1038 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1039 section = SND_DEVICES;
1040 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1041 section = INPUT_SND_DEVICE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001042 }
Ben Romberger55886882014-01-10 13:49:02 -08001043}
1044
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001045int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001046{
1047 XML_Parser parser;
1048 FILE *file;
1049 int ret = 0;
1050 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001051 void *buf;
1052
Helen Zeng6a16ad72014-02-23 22:04:44 -08001053 file = fopen(filename, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001054 section = ROOT;
1055
Ben Romberger55886882014-01-10 13:49:02 -08001056 if (!file) {
1057 ALOGD("%s: Failed to open %s, using defaults.",
Helen Zeng6a16ad72014-02-23 22:04:44 -08001058 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -08001059 ret = -ENODEV;
1060 goto done;
1061 }
1062
1063 parser = XML_ParserCreate(NULL);
1064 if (!parser) {
1065 ALOGE("%s: Failed to create XML parser!", __func__);
1066 ret = -ENODEV;
1067 goto err_close_file;
1068 }
1069
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001070 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001071 my_data.platform = platform;
1072 my_data.kvpairs = str_parms_create();
1073
Ben Romberger55886882014-01-10 13:49:02 -08001074 XML_SetElementHandler(parser, start_tag, end_tag);
1075
1076 while (1) {
1077 buf = XML_GetBuffer(parser, BUF_SIZE);
1078 if (buf == NULL) {
1079 ALOGE("%s: XML_GetBuffer failed", __func__);
1080 ret = -ENOMEM;
1081 goto err_free_parser;
1082 }
1083
1084 bytes_read = fread(buf, 1, BUF_SIZE, file);
1085 if (bytes_read < 0) {
1086 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1087 ret = bytes_read;
1088 goto err_free_parser;
1089 }
1090
1091 if (XML_ParseBuffer(parser, bytes_read,
1092 bytes_read == 0) == XML_STATUS_ERROR) {
1093 ALOGE("%s: XML_ParseBuffer failed, for %s",
Helen Zeng6a16ad72014-02-23 22:04:44 -08001094 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -08001095 ret = -EINVAL;
1096 goto err_free_parser;
1097 }
1098
1099 if (bytes_read == 0)
1100 break;
1101 }
1102
Ben Romberger55886882014-01-10 13:49:02 -08001103err_free_parser:
1104 XML_ParserFree(parser);
1105err_close_file:
1106 fclose(file);
1107done:
1108 return ret;
1109}