blob: 233e12090a0b2ce3f0eaf448d71e9ceaa19ab014 [file] [log] [blame]
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001/*
Haynes Mathew George569b7482017-05-08 14:44:27 -07002 * Copyright (C) 2014 The Android Open Source Project
Haynes Mathew George5bc18842014-06-16 16:36:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16
17#define LOG_TAG "platform_info"
18#define LOG_NDDEBUG 0
19
20#include <errno.h>
21#include <stdio.h>
22#include <expat.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080023#include <log/log.h>
Haynes Mathew George5bc18842014-06-16 16:36:20 -070024#include <audio_hw.h>
25#include "platform_api.h"
26#include <platform.h>
vivek mehtaa8d7c922016-05-25 14:40:44 -070027#include <math.h>
juyuchenbf6571f2018-11-30 18:50:47 +080028#include <pthread.h>
Haynes Mathew George5bc18842014-06-16 16:36:20 -070029
jiabin749942e2018-05-25 12:37:29 -070030/*
31 * Mandatory microphone characteristics include: device_id, type, address, location, group,
32 * index_in_the_group, directionality, num_frequency_responses, frequencies and responses.
33 * MANDATORY_MICROPHONE_CHARACTERISTICS should be updated when mandatory microphone
34 * characteristics are changed.
35 */
36#define MANDATORY_MICROPHONE_CHARACTERISTICS (1 << 10) - 1
37
Haynes Mathew George98c95622014-06-20 19:14:25 -070038typedef enum {
39 ROOT,
40 ACDB,
Vignesh Kulothungan64698822018-01-23 11:25:18 -080041 MODULE,
42 AEC,
43 NS,
Haynes Mathew George98c95622014-06-20 19:14:25 -070044 PCM_ID,
45 BACKEND_NAME,
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070046 CONFIG_PARAMS,
keunhui.park2f7306a2015-07-16 16:48:06 +090047 OPERATOR_SPECIFIC,
vivek mehtaa8d7c922016-05-25 14:40:44 -070048 GAIN_LEVEL_MAPPING,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080049 APP_TYPE,
jiabin8962a4d2018-03-19 18:21:24 -070050 MICROPHONE_CHARACTERISTIC,
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -070051 SND_DEVICES,
52 INPUT_SND_DEVICE,
53 INPUT_SND_DEVICE_TO_MIC_MAPPING,
54 SND_DEV,
55 MIC_INFO,
Ashish Jain1c849702018-05-11 20:11:55 +053056 ACDB_METAINFO_KEY,
Haynes Mathew George98c95622014-06-20 19:14:25 -070057} section_t;
58
59typedef void (* section_process_fn)(const XML_Char **attr);
60
61static void process_acdb_id(const XML_Char **attr);
Vignesh Kulothungan64698822018-01-23 11:25:18 -080062static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
63static void process_effect_aec(const XML_Char **attr);
64static void process_effect_ns(const XML_Char **attr);
Haynes Mathew George98c95622014-06-20 19:14:25 -070065static void process_pcm_id(const XML_Char **attr);
66static void process_backend_name(const XML_Char **attr);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070067static void process_config_params(const XML_Char **attr);
Haynes Mathew George98c95622014-06-20 19:14:25 -070068static void process_root(const XML_Char **attr);
keunhui.park2f7306a2015-07-16 16:48:06 +090069static void process_operator_specific(const XML_Char **attr);
vivek mehtaa8d7c922016-05-25 14:40:44 -070070static void process_gain_db_to_level_map(const XML_Char **attr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080071static void process_app_type(const XML_Char **attr);
jiabin8962a4d2018-03-19 18:21:24 -070072static void process_microphone_characteristic(const XML_Char **attr);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -070073static void process_snd_dev(const XML_Char **attr);
74static void process_mic_info(const XML_Char **attr);
Ashish Jain1c849702018-05-11 20:11:55 +053075static void process_acdb_metainfo_key(const XML_Char **attr);
Haynes Mathew George98c95622014-06-20 19:14:25 -070076
77static section_process_fn section_table[] = {
78 [ROOT] = process_root,
79 [ACDB] = process_acdb_id,
Vignesh Kulothungan64698822018-01-23 11:25:18 -080080 [AEC] = process_effect_aec,
81 [NS] = process_effect_ns,
Haynes Mathew George98c95622014-06-20 19:14:25 -070082 [PCM_ID] = process_pcm_id,
83 [BACKEND_NAME] = process_backend_name,
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070084 [CONFIG_PARAMS] = process_config_params,
keunhui.park2f7306a2015-07-16 16:48:06 +090085 [OPERATOR_SPECIFIC] = process_operator_specific,
vivek mehtaa8d7c922016-05-25 14:40:44 -070086 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080087 [APP_TYPE] = process_app_type,
jiabin8962a4d2018-03-19 18:21:24 -070088 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -070089 [SND_DEV] = process_snd_dev,
90 [MIC_INFO] = process_mic_info,
Ashish Jain1c849702018-05-11 20:11:55 +053091 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Haynes Mathew George98c95622014-06-20 19:14:25 -070092};
93
94static section_t section;
95
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070096struct platform_info {
juyuchenbf6571f2018-11-30 18:50:47 +080097 pthread_mutex_t lock;
vivek mehta0fb11312017-05-15 19:35:32 -070098 bool do_full_parse;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070099 void *platform;
100 struct str_parms *kvpairs;
juyuchenbf6571f2018-11-30 18:50:47 +0800101 set_parameters_fn set_parameters;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700102};
103
juyuchenbf6571f2018-11-30 18:50:47 +0800104static struct platform_info my_data = {PTHREAD_MUTEX_INITIALIZER,
105 true, NULL, NULL,
106 &platform_set_parameters};
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700107
jiabin8962a4d2018-03-19 18:21:24 -0700108struct audio_string_to_enum {
109 const char* name;
110 unsigned int value;
111};
112
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700113static snd_device_t in_snd_device;
114
jiabin8962a4d2018-03-19 18:21:24 -0700115static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
116 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
117 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
118 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
119 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
120};
121
122static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
123 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
124 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
125 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
126 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
127 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
128 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
129};
130
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700131static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
132 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
133 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
134 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
135};
136
jiabin8962a4d2018-03-19 18:21:24 -0700137static const struct audio_string_to_enum device_in_types[] = {
138 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
139 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
140 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
141 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
142 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
143 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
144 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
145 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
146 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
147 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
148 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
149 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
150 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
151 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
152 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
153 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
154 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
155 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
157 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
163 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
165};
166
167static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
168 int32_t len, unsigned int *value)
169{
170 if (table == NULL) {
171 ALOGE("%s: table is NULL", __func__);
172 return false;
173 }
174
175 if (name == NULL) {
176 ALOGE("null key");
177 return false;
178 }
179
180 for (int i = 0; i < len; i++) {
181 if (!strcmp(table[i].name, name)) {
182 *value = table[i].value;
183 return true;
184 }
185 }
186 return false;
187}
188
Haynes Mathew George98c95622014-06-20 19:14:25 -0700189/*
190 * <audio_platform_info>
191 * <acdb_ids>
192 * <device name="???" acdb_id="???"/>
193 * ...
194 * ...
195 * </acdb_ids>
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800196 * <module_ids>
197 * <device name="???" module_id="???"/>
198 * ...
199 * ...
200 * </module_ids>
Haynes Mathew George98c95622014-06-20 19:14:25 -0700201 * <backend_names>
202 * <device name="???" backend="???"/>
203 * ...
204 * ...
205 * </backend_names>
206 * <pcm_ids>
207 * <usecase name="???" type="in/out" id="???"/>
208 * ...
209 * ...
210 * </pcm_ids>
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700211 * <config_params>
212 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
keunhui.park2f7306a2015-07-16 16:48:06 +0900213 * <param key="operator_info" value="tmus;aa;bb;cc"/>
214 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700215 * ...
216 * ...
217 * </config_params>
218 *
keunhui.park2f7306a2015-07-16 16:48:06 +0900219 * <operator_specific>
220 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
221 * ...
222 * ...
223 * </operator_specific>
224 *
Haynes Mathew George98c95622014-06-20 19:14:25 -0700225 * </audio_platform_info>
226 */
227
228static void process_root(const XML_Char **attr __unused)
229{
230}
231
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800232static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
233{
234 int index;
235 struct audio_effect_config effect_config;
236
237 if (strncmp(attr[0], "name", strlen("name")) != 0) {
238 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
239 goto done;
240 }
241
242 index = platform_get_snd_device_index((char *)attr[1]);
243 if (index < 0) {
244 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
245 __func__, attr[1]);
246 goto done;
247 }
248
249 if (strncmp(attr[2], "module_id", strlen("module_id")) != 0) {
250 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
251 __func__, attr[2]);
252 goto done;
253 }
254
255 if (strncmp(attr[4], "instance_id", strlen("instance_id")) != 0) {
256 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
257 __func__, attr[4]);
258 goto done;
259 }
260
261 if (strncmp(attr[6], "param_id", strlen("param_id")) != 0) {
262 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
263 __func__, attr[6]);
264 goto done;
265 }
266
267 if (strncmp(attr[8], "param_value", strlen("param_value")) != 0) {
268 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
269 __func__, attr[8]);
270 goto done;
271 }
272
273 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
274 strtol((char *)attr[5], NULL, 0),
275 strtol((char *)attr[7], NULL, 0),
276 strtol((char *)attr[9], NULL, 0)};
277
278
279 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
280 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %u %u %u %u was not set!",
281 __func__, effect_type, attr[1], effect_config.module_id,
282 effect_config.instance_id, effect_config.param_id,
283 effect_config.param_value);
284 goto done;
285 }
286
287done:
288 return;
289}
290
291static void process_effect_aec(const XML_Char **attr)
292{
293 process_audio_effect(attr, EFFECT_AEC);
294 return;
295}
296
297static void process_effect_ns(const XML_Char **attr)
298{
299 process_audio_effect(attr, EFFECT_NS);
300 return;
301}
302
Haynes Mathew George98c95622014-06-20 19:14:25 -0700303/* mapping from usecase to pcm dev id */
304static void process_pcm_id(const XML_Char **attr)
305{
306 int index;
307
308 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700309 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew George98c95622014-06-20 19:14:25 -0700310 goto done;
311 }
312
313 index = platform_get_usecase_index((char *)attr[1]);
314 if (index < 0) {
315 ALOGE("%s: usecase %s in %s not found!",
316 __func__, attr[1], PLATFORM_INFO_XML_PATH);
317 goto done;
318 }
319
320 if (strcmp(attr[2], "type") != 0) {
321 ALOGE("%s: usecase type not mentioned", __func__);
322 goto done;
323 }
324
325 int type = -1;
326
327 if (!strcasecmp((char *)attr[3], "in")) {
328 type = 1;
329 } else if (!strcasecmp((char *)attr[3], "out")) {
330 type = 0;
331 } else {
332 ALOGE("%s: type must be IN or OUT", __func__);
333 goto done;
334 }
335
336 if (strcmp(attr[4], "id") != 0) {
337 ALOGE("%s: usecase id not mentioned", __func__);
338 goto done;
339 }
340
341 int id = atoi((char *)attr[5]);
342
343 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
344 ALOGE("%s: usecase %s in %s, type %d id %d was not set!",
345 __func__, attr[1], PLATFORM_INFO_XML_PATH, type, id);
346 goto done;
347 }
348
349done:
350 return;
351}
352
353/* backend to be used for a device */
354static void process_backend_name(const XML_Char **attr)
355{
356 int index;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700357 char *hw_interface = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700358
359 if (strcmp(attr[0], "name") != 0) {
360 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
361 goto done;
362 }
363
364 index = platform_get_snd_device_index((char *)attr[1]);
365 if (index < 0) {
366 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
367 __func__, attr[1], PLATFORM_INFO_XML_PATH);
368 goto done;
369 }
370
371 if (strcmp(attr[2], "backend") != 0) {
372 ALOGE("%s: Device %s in %s has no backed set!",
373 __func__, attr[1], PLATFORM_INFO_XML_PATH);
374 goto done;
375 }
376
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700377 if (attr[4] != NULL) {
378 if (strcmp(attr[4], "interface") != 0) {
379 hw_interface = NULL;
380 } else {
381 hw_interface = (char *)attr[5];
382 }
383 }
384
385 if (platform_set_snd_device_backend(index, attr[3], hw_interface) < 0) {
Haynes Mathew George98c95622014-06-20 19:14:25 -0700386 ALOGE("%s: Device %s in %s, backend %s was not set!",
387 __func__, attr[1], PLATFORM_INFO_XML_PATH, attr[3]);
388 goto done;
389 }
390
391done:
392 return;
393}
394
vivek mehtaa8d7c922016-05-25 14:40:44 -0700395static void process_gain_db_to_level_map(const XML_Char **attr)
396{
397 struct amp_db_and_gain_table tbl_entry;
398
399 if ((strcmp(attr[0], "db") != 0) ||
400 (strcmp(attr[2], "level") != 0)) {
401 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
402 __func__, attr[0], attr[2]);
403 goto done;
404 }
405
406 tbl_entry.db = atof(attr[1]);
407 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
408 tbl_entry.level = atoi(attr[3]);
409
vivek mehta40125092017-08-21 18:48:51 -0700410 //custome level should be > 0. Level 0 is fixed for default
411 CHECK(tbl_entry.level > 0);
412
vivek mehtaa8d7c922016-05-25 14:40:44 -0700413 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
414 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
415 platform_add_gain_level_mapping(&tbl_entry);
416
417done:
418 return;
419}
420
Haynes Mathew George98c95622014-06-20 19:14:25 -0700421static void process_acdb_id(const XML_Char **attr)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700422{
423 int index;
424
425 if (strcmp(attr[0], "name") != 0) {
426 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
427 goto done;
428 }
429
430 index = platform_get_snd_device_index((char *)attr[1]);
431 if (index < 0) {
432 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
433 __func__, attr[1], PLATFORM_INFO_XML_PATH);
434 goto done;
435 }
436
437 if (strcmp(attr[2], "acdb_id") != 0) {
438 ALOGE("%s: Device %s in %s has no acdb_id, no ACDB ID set!",
439 __func__, attr[1], PLATFORM_INFO_XML_PATH);
440 goto done;
441 }
442
Haynes Mathew George98c95622014-06-20 19:14:25 -0700443 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700444 ALOGE("%s: Device %s in %s, ACDB ID %d was not set!",
445 __func__, attr[1], PLATFORM_INFO_XML_PATH, atoi((char *)attr[3]));
446 goto done;
447 }
448
449done:
450 return;
451}
452
keunhui.park2f7306a2015-07-16 16:48:06 +0900453
454static void process_operator_specific(const XML_Char **attr)
455{
456 snd_device_t snd_device = SND_DEVICE_NONE;
457
458 if (strcmp(attr[0], "name") != 0) {
459 ALOGE("%s: 'name' not found", __func__);
460 goto done;
461 }
462
463 snd_device = platform_get_snd_device_index((char *)attr[1]);
464 if (snd_device < 0) {
465 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
466 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
467 goto done;
468 }
469
470 if (strcmp(attr[2], "operator") != 0) {
471 ALOGE("%s: 'operator' not found", __func__);
472 goto done;
473 }
474
475 if (strcmp(attr[4], "mixer_path") != 0) {
476 ALOGE("%s: 'mixer_path' not found", __func__);
477 goto done;
478 }
479
480 if (strcmp(attr[6], "acdb_id") != 0) {
481 ALOGE("%s: 'acdb_id' not found", __func__);
482 goto done;
483 }
484
485 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
486
487done:
488 return;
489}
490
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700491/* platform specific configuration key-value pairs */
492static void process_config_params(const XML_Char **attr)
493{
494 if (strcmp(attr[0], "key") != 0) {
495 ALOGE("%s: 'key' not found", __func__);
496 goto done;
497 }
498
499 if (strcmp(attr[2], "value") != 0) {
500 ALOGE("%s: 'value' not found", __func__);
501 goto done;
502 }
503
504 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
juyuchenbf6571f2018-11-30 18:50:47 +0800505 my_data.set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700506done:
507 return;
508}
509
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800510static void process_app_type(const XML_Char **attr)
511{
512 if (strcmp(attr[0], "uc_type")) {
513 ALOGE("%s: uc_type not found", __func__);
514 goto done;
515 }
516
vivek mehtaa68fea62017-06-08 19:04:02 -0700517 if (strcmp(attr[2], "mode")) {
518 ALOGE("%s: mode not found", __func__);
519 goto done;
520 }
521
522 if (strcmp(attr[4], "bit_width")) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800523 ALOGE("%s: bit_width not found", __func__);
524 goto done;
525 }
526
vivek mehtaa68fea62017-06-08 19:04:02 -0700527 if (strcmp(attr[6], "id")) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800528 ALOGE("%s: id not found", __func__);
529 goto done;
530 }
531
vivek mehtaa68fea62017-06-08 19:04:02 -0700532 if (strcmp(attr[8], "max_rate")) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800533 ALOGE("%s: max rate not found", __func__);
534 goto done;
535 }
536
vivek mehtaa68fea62017-06-08 19:04:02 -0700537 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
538 atoi(attr[9]));
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800539done:
540 return;
541}
542
jiabin8962a4d2018-03-19 18:21:24 -0700543static void process_microphone_characteristic(const XML_Char **attr) {
544 struct audio_microphone_characteristic_t microphone;
jiabin749942e2018-05-25 12:37:29 -0700545 uint32_t index = 0;
546 uint32_t found_mandatory_characteristics = 0;
547 uint32_t num_frequencies = 0;
548 uint32_t num_responses = 0;
549 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
550 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
551 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
552 microphone.orientation.x = 0.0f;
553 microphone.orientation.y = 0.0f;
554 microphone.orientation.z = 0.0f;
555 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
556 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
557 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
jiabin8962a4d2018-03-19 18:21:24 -0700558
jiabin749942e2018-05-25 12:37:29 -0700559 while (attr[index] != NULL) {
560 const char *attribute = attr[index++];
561 char value[strlen(attr[index]) + 1];
562 strcpy(value, attr[index++]);
563 if (strcmp(attribute, "device_id") == 0) {
564 if (strlen(value) > AUDIO_MICROPHONE_ID_MAX_LEN) {
565 ALOGE("%s: device_id %s is too long", __func__, value);
jiabin8962a4d2018-03-19 18:21:24 -0700566 goto done;
567 }
jiabin749942e2018-05-25 12:37:29 -0700568 strcpy(microphone.device_id, value);
569 found_mandatory_characteristics |= 1;
570 } else if (strcmp(attribute, "type") == 0) {
571 if (!find_enum_by_string(device_in_types, value,
572 ARRAY_SIZE(device_in_types), &microphone.device)) {
573 ALOGE("%s: type %s in %s not found!",
574 __func__, value, PLATFORM_INFO_XML_PATH);
jiabin8962a4d2018-03-19 18:21:24 -0700575 goto done;
576 }
jiabin749942e2018-05-25 12:37:29 -0700577 found_mandatory_characteristics |= (1 << 1);
578 } else if (strcmp(attribute, "address") == 0) {
579 if (strlen(value) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
580 ALOGE("%s, address %s is too long", __func__, value);
581 goto done;
582 }
583 strcpy(microphone.address, value);
584 if (strlen(microphone.address) == 0) {
585 // If the address is empty, populate the address according to device type.
586 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
587 strcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS);
588 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
589 strcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS);
590 }
591 }
592 found_mandatory_characteristics |= (1 << 2);
593 } else if (strcmp(attribute, "location") == 0) {
594 if (!find_enum_by_string(mic_locations, value,
595 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
596 ALOGE("%s: location %s in %s not found!",
597 __func__, value, PLATFORM_INFO_XML_PATH);
598 goto done;
599 }
600 found_mandatory_characteristics |= (1 << 3);
601 } else if (strcmp(attribute, "group") == 0) {
602 microphone.group = atoi(value);
603 found_mandatory_characteristics |= (1 << 4);
604 } else if (strcmp(attribute, "index_in_the_group") == 0) {
605 microphone.index_in_the_group = atoi(value);
606 found_mandatory_characteristics |= (1 << 5);
607 } else if (strcmp(attribute, "directionality") == 0) {
608 if (!find_enum_by_string(mic_directionalities, value,
609 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
610 ALOGE("%s: directionality %s in %s not found!",
611 __func__, attr[index], PLATFORM_INFO_XML_PATH);
612 goto done;
613 }
614 found_mandatory_characteristics |= (1 << 6);
615 } else if (strcmp(attribute, "num_frequency_responses") == 0) {
616 microphone.num_frequency_responses = atoi(value);
617 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
618 ALOGE("%s: num_frequency_responses is too large", __func__);
619 goto done;
620 }
621 found_mandatory_characteristics |= (1 << 7);
622 } else if (strcmp(attribute, "frequencies") == 0) {
623 char *token = strtok(value, " ");
624 while (token) {
625 microphone.frequency_responses[0][num_frequencies++] = atof(token);
626 if (num_frequencies > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
627 ALOGE("%s: num %u of frequency is too large", __func__, num_frequencies);
628 goto done;
629 }
630 token = strtok(NULL, " ");
631 }
632 found_mandatory_characteristics |= (1 << 8);
633 } else if (strcmp(attribute, "responses") == 0) {
634 char *token = strtok(value, " ");
635 while (token) {
636 microphone.frequency_responses[1][num_responses++] = atof(token);
637 if (num_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
638 ALOGE("%s: num %u of response is too large", __func__, num_responses);
639 goto done;
640 }
641 token = strtok(NULL, " ");
642 }
643 found_mandatory_characteristics |= (1 << 9);
644 } else if (strcmp(attribute, "sensitivity") == 0) {
645 microphone.sensitivity = atof(value);
646 } else if (strcmp(attribute, "max_spl") == 0) {
647 microphone.max_spl = atof(value);
648 } else if (strcmp(attribute, "min_spl") == 0) {
649 microphone.min_spl = atof(value);
650 } else if (strcmp(attribute, "orientation") == 0) {
651 char *token = strtok(value, " ");
652 float orientation[3];
653 uint32_t idx = 0;
654 while (token) {
655 orientation[idx++] = atof(token);
656 if (idx > 3) {
657 ALOGE("%s: orientation invalid", __func__);
658 goto done;
659 }
660 token = strtok(NULL, " ");
661 }
662 if (idx != 3) {
jiabin8962a4d2018-03-19 18:21:24 -0700663 ALOGE("%s: orientation invalid", __func__);
664 goto done;
665 }
jiabin749942e2018-05-25 12:37:29 -0700666 microphone.orientation.x = orientation[0];
667 microphone.orientation.y = orientation[1];
668 microphone.orientation.z = orientation[2];
669 } else if (strcmp(attribute, "geometric_location") == 0) {
670 char *token = strtok(value, " ");
671 float geometric_location[3];
672 uint32_t idx = 0;
673 while (token) {
674 geometric_location[idx++] = atof(token);
675 if (idx > 3) {
676 ALOGE("%s: geometric_location invalid", __func__);
677 goto done;
678 }
679 token = strtok(NULL, " ");
680 }
681 if (idx != 3) {
jiabin8962a4d2018-03-19 18:21:24 -0700682 ALOGE("%s: geometric_location invalid", __func__);
683 goto done;
684 }
jiabin749942e2018-05-25 12:37:29 -0700685 microphone.geometric_location.x = geometric_location[0];
686 microphone.geometric_location.y = geometric_location[1];
687 microphone.geometric_location.z = geometric_location[2];
688 } else {
689 ALOGW("%s: unknown attribute of microphone characteristics: %s",
690 __func__, attribute);
jiabin8962a4d2018-03-19 18:21:24 -0700691 }
jiabin749942e2018-05-25 12:37:29 -0700692 }
693
694 if (num_frequencies != num_responses
695 || num_frequencies != microphone.num_frequency_responses) {
696 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
697 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
698 goto done;
699 }
700
701 if (found_mandatory_characteristics != MANDATORY_MICROPHONE_CHARACTERISTICS) {
702 ALOGE("%s: some of mandatory microphone characteriscts are missed: %u",
703 __func__, found_mandatory_characteristics);
jiabin8962a4d2018-03-19 18:21:24 -0700704 }
705
706 platform_set_microphone_characteristic(my_data.platform, microphone);
707done:
708 return;
709}
710
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700711static void process_snd_dev(const XML_Char **attr)
712{
713 uint32_t curIdx = 0;
714 in_snd_device = SND_DEVICE_NONE;
715
716 if (strcmp(attr[curIdx++], "in_snd_device")) {
717 ALOGE("%s: snd_device not found", __func__);
718 return;
719 }
720 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
721 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
722 in_snd_device >= SND_DEVICE_IN_END) {
723 ALOGE("%s: Sound device not valid", __func__);
724 in_snd_device = SND_DEVICE_NONE;
725 }
726
727 return;
728}
729
730static void process_mic_info(const XML_Char **attr)
731{
732 uint32_t curIdx = 0;
733 struct mic_info microphone;
734
735 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
736 sizeof(microphone.channel_mapping));
737
738 if (strcmp(attr[curIdx++], "mic_device_id")) {
739 ALOGE("%s: mic_device_id not found", __func__);
740 goto on_error;
741 }
742 strlcpy(microphone.device_id,
743 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
744
745 if (strcmp(attr[curIdx++], "channel_mapping")) {
746 ALOGE("%s: channel_mapping not found", __func__);
747 goto on_error;
748 }
749 const char *token = strtok((char *)attr[curIdx++], " ");
750 uint32_t idx = 0;
751 while (token) {
752 if (!find_enum_by_string(mic_channel_mapping, token,
753 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
754 &microphone.channel_mapping[idx++])) {
755 ALOGE("%s: channel_mapping %s in %s not found!",
756 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
757 goto on_error;
758 }
759 token = strtok(NULL, " ");
760 }
761 microphone.channel_count = idx;
762
763 platform_set_microphone_map(my_data.platform, in_snd_device,
764 &microphone);
765 return;
766on_error:
767 in_snd_device = SND_DEVICE_NONE;
768 return;
769}
770
Ashish Jain1c849702018-05-11 20:11:55 +0530771/* process acdb meta info key value */
772static void process_acdb_metainfo_key(const XML_Char **attr)
773{
774 if (strcmp(attr[0], "name") != 0) {
775 ALOGE("%s: 'name' not found", __func__);
776 goto done;
777 }
778 if (strcmp(attr[2], "value") != 0) {
779 ALOGE("%s: 'value' not found", __func__);
780 goto done;
781 }
782
783 int key = atoi((char *)attr[3]);
784 if (platform_set_acdb_metainfo_key(my_data.platform,
785 (char*)attr[1], key) < 0) {
786 ALOGE("%s: key %d was not set!", __func__, key);
787 }
788
789done:
790 return;
791}
792
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700793static void start_tag(void *userdata __unused, const XML_Char *tag_name,
794 const XML_Char **attr)
795{
796 const XML_Char *attr_name = NULL;
797 const XML_Char *attr_value = NULL;
798 unsigned int i;
799
Haynes Mathew George98c95622014-06-20 19:14:25 -0700800
vivek mehta0fb11312017-05-15 19:35:32 -0700801 if (my_data.do_full_parse) {
802 if (strcmp(tag_name, "acdb_ids") == 0) {
803 section = ACDB;
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800804 } else if (strncmp(tag_name, "module_ids", strlen("module_ids")) == 0) {
805 section = MODULE;
vivek mehta0fb11312017-05-15 19:35:32 -0700806 } else if (strcmp(tag_name, "pcm_ids") == 0) {
807 section = PCM_ID;
808 } else if (strcmp(tag_name, "backend_names") == 0) {
809 section = BACKEND_NAME;
810 } else if (strcmp(tag_name, "config_params") == 0) {
811 section = CONFIG_PARAMS;
812 } else if (strcmp(tag_name, "operator_specific") == 0) {
813 section = OPERATOR_SPECIFIC;
814 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
815 section = GAIN_LEVEL_MAPPING;
816 } else if (strcmp(tag_name, "app_types") == 0) {
817 section = APP_TYPE;
jiabin8962a4d2018-03-19 18:21:24 -0700818 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
819 section = MICROPHONE_CHARACTERISTIC;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700820 } else if (strcmp(tag_name, "snd_devices") == 0) {
821 section = SND_DEVICES;
Ashish Jain1c849702018-05-11 20:11:55 +0530822 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
823 section = ACDB_METAINFO_KEY;
vivek mehta0fb11312017-05-15 19:35:32 -0700824 } else if (strcmp(tag_name, "device") == 0) {
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800825 if ((section != ACDB) && (section != AEC) && (section != NS) &&
826 (section != BACKEND_NAME) && (section != OPERATOR_SPECIFIC)) {
827 ALOGE("device tag only supported for acdb/backend/aec/ns/operator_specific names");
vivek mehta0fb11312017-05-15 19:35:32 -0700828 return;
829 }
Haynes Mathew George98c95622014-06-20 19:14:25 -0700830
vivek mehta0fb11312017-05-15 19:35:32 -0700831 /* call into process function for the current section */
832 section_process_fn fn = section_table[section];
833 fn(attr);
834 } else if (strcmp(tag_name, "usecase") == 0) {
835 if (section != PCM_ID) {
836 ALOGE("usecase tag only supported with PCM_ID section");
837 return;
838 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700839
vivek mehta0fb11312017-05-15 19:35:32 -0700840 section_process_fn fn = section_table[PCM_ID];
841 fn(attr);
842 } else if (strcmp(tag_name, "param") == 0) {
Ashish Jain1c849702018-05-11 20:11:55 +0530843 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
vivek mehta0fb11312017-05-15 19:35:32 -0700844 ALOGE("param tag only supported with CONFIG_PARAMS section");
845 return;
846 }
vivek mehtaa8d7c922016-05-25 14:40:44 -0700847
vivek mehta0fb11312017-05-15 19:35:32 -0700848 section_process_fn fn = section_table[section];
849 fn(attr);
850 } else if (strcmp(tag_name, "gain_level_map") == 0) {
851 if (section != GAIN_LEVEL_MAPPING) {
jiabin8962a4d2018-03-19 18:21:24 -0700852 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
vivek mehta0fb11312017-05-15 19:35:32 -0700853 return;
854 }
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800855
vivek mehta0fb11312017-05-15 19:35:32 -0700856 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
857 fn(attr);
858 } else if (!strcmp(tag_name, "app")) {
859 if (section != APP_TYPE) {
860 ALOGE("app tag only valid in section APP_TYPE");
861 return;
862 }
863
864 section_process_fn fn = section_table[APP_TYPE];
865 fn(attr);
jiabin8962a4d2018-03-19 18:21:24 -0700866 } else if (strcmp(tag_name, "microphone") == 0) {
867 if (section != MICROPHONE_CHARACTERISTIC) {
868 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
869 return;
870 }
871 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
872 fn(attr);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700873 } else if (strcmp(tag_name, "input_snd_device") == 0) {
874 if (section != SND_DEVICES) {
875 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
876 return;
877 }
878 section = INPUT_SND_DEVICE;
879 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
880 if (section != INPUT_SND_DEVICE) {
881 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
882 return;
883 }
884 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
885 } else if (strcmp(tag_name, "snd_dev") == 0) {
886 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
887 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
888 return;
889 }
890 section_process_fn fn = section_table[SND_DEV];
891 fn(attr);
892 } else if (strcmp(tag_name, "mic_info") == 0) {
893 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
894 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
895 return;
896 }
897 if (in_snd_device == SND_DEVICE_NONE) {
898 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
899 return;
900 }
901 section_process_fn fn = section_table[MIC_INFO];
902 fn(attr);
vivek mehta0fb11312017-05-15 19:35:32 -0700903 }
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800904 else if (strncmp(tag_name, "aec", strlen("aec")) == 0) {
905 if (section != MODULE) {
906 ALOGE("aec tag only supported with MODULE section");
907 return;
908 }
909 section = AEC;
910 }
911 else if (strncmp(tag_name, "ns", strlen("ns")) == 0) {
912 if (section != MODULE) {
913 ALOGE("ns tag only supported with MODULE section");
914 return;
915 }
916 section = NS;
917 }
vivek mehta0fb11312017-05-15 19:35:32 -0700918 } else {
919 if(strcmp(tag_name, "config_params") == 0) {
920 section = CONFIG_PARAMS;
921 } else if (strcmp(tag_name, "param") == 0) {
922 if (section != CONFIG_PARAMS) {
923 ALOGE("param tag only supported with CONFIG_PARAMS section");
924 return;
925 }
926
927 section_process_fn fn = section_table[section];
928 fn(attr);
929 }
Haynes Mathew George98c95622014-06-20 19:14:25 -0700930 }
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700931
932 return;
933}
934
Haynes Mathew George98c95622014-06-20 19:14:25 -0700935static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700936{
Haynes Mathew George98c95622014-06-20 19:14:25 -0700937 if (strcmp(tag_name, "acdb_ids") == 0) {
938 section = ROOT;
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800939 } else if (strncmp(tag_name, "module_ids", strlen("module_ids")) == 0) {
940 section = ROOT;
941 } else if (strncmp(tag_name, "aec", strlen("aec")) == 0) {
942 section = MODULE;
943 } else if (strncmp(tag_name, "ns", strlen("ns")) == 0) {
944 section = MODULE;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700945 } else if (strcmp(tag_name, "pcm_ids") == 0) {
946 section = ROOT;
947 } else if (strcmp(tag_name, "backend_names") == 0) {
948 section = ROOT;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700949 } else if (strcmp(tag_name, "config_params") == 0) {
950 section = ROOT;
keunhui.park2f7306a2015-07-16 16:48:06 +0900951 } else if (strcmp(tag_name, "operator_specific") == 0) {
952 section = ROOT;
vivek mehtaa8d7c922016-05-25 14:40:44 -0700953 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
954 section = ROOT;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800955 } else if (strcmp(tag_name, "app_types") == 0) {
956 section = ROOT;
jiabin8962a4d2018-03-19 18:21:24 -0700957 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
958 section = ROOT;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700959 } else if (strcmp(tag_name, "snd_devices") == 0) {
960 section = ROOT;
961 } else if (strcmp(tag_name, "input_snd_device") == 0) {
962 section = SND_DEVICES;
963 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
964 section = INPUT_SND_DEVICE;
Ashish Jain1c849702018-05-11 20:11:55 +0530965 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
966 section = ROOT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700967 }
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700968}
969
juyuchenbf6571f2018-11-30 18:50:47 +0800970int platform_info_init(const char *filename, void *platform,
971 bool do_full_parse, set_parameters_fn fn)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700972{
973 XML_Parser parser;
974 FILE *file;
975 int ret = 0;
976 int bytes_read;
977 void *buf;
978 static const uint32_t kBufSize = 1024;
vivek mehtade4849c2016-03-03 17:23:38 -0800979 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700980
vivek mehtade4849c2016-03-03 17:23:38 -0800981 if (filename == NULL) {
982 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
983 } else {
984 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
985 }
986
987 ALOGV("%s: platform info file name is %s", __func__, platform_info_file_name);
988
989 file = fopen(platform_info_file_name, "r");
990
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700991 if (!file) {
992 ALOGD("%s: Failed to open %s, using defaults.",
vivek mehtade4849c2016-03-03 17:23:38 -0800993 __func__, platform_info_file_name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700994 ret = -ENODEV;
995 goto done;
996 }
997
998 parser = XML_ParserCreate(NULL);
999 if (!parser) {
1000 ALOGE("%s: Failed to create XML parser!", __func__);
1001 ret = -ENODEV;
1002 goto err_close_file;
1003 }
1004
juyuchenbf6571f2018-11-30 18:50:47 +08001005 pthread_mutex_lock(&my_data.lock);
1006 section = ROOT;
1007 my_data.do_full_parse = do_full_parse;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001008 my_data.platform = platform;
1009 my_data.kvpairs = str_parms_create();
juyuchenbf6571f2018-11-30 18:50:47 +08001010 my_data.set_parameters = fn;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001011
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001012 XML_SetElementHandler(parser, start_tag, end_tag);
1013
1014 while (1) {
1015 buf = XML_GetBuffer(parser, kBufSize);
1016 if (buf == NULL) {
1017 ALOGE("%s: XML_GetBuffer failed", __func__);
1018 ret = -ENOMEM;
1019 goto err_free_parser;
1020 }
1021
1022 bytes_read = fread(buf, 1, kBufSize, file);
1023 if (bytes_read < 0) {
1024 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1025 ret = bytes_read;
1026 goto err_free_parser;
1027 }
1028
1029 if (XML_ParseBuffer(parser, bytes_read,
1030 bytes_read == 0) == XML_STATUS_ERROR) {
1031 ALOGE("%s: XML_ParseBuffer failed, for %s",
vivek mehtade4849c2016-03-03 17:23:38 -08001032 __func__, platform_info_file_name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001033 ret = -EINVAL;
1034 goto err_free_parser;
1035 }
1036
1037 if (bytes_read == 0)
1038 break;
1039 }
1040
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001041err_free_parser:
juyuchenbf6571f2018-11-30 18:50:47 +08001042 if (my_data.kvpairs != NULL) {
1043 str_parms_destroy(my_data.kvpairs);
1044 my_data.kvpairs = NULL;
1045 }
1046 pthread_mutex_unlock(&my_data.lock);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001047 XML_ParserFree(parser);
1048err_close_file:
1049 fclose(file);
1050done:
1051 return ret;
1052}