blob: 181460e61e3d228d61064fcc2813454e136b0505 [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>
Haynes Mathew George5bc18842014-06-16 16:36:20 -070028
Haynes Mathew George98c95622014-06-20 19:14:25 -070029typedef enum {
30 ROOT,
31 ACDB,
32 PCM_ID,
33 BACKEND_NAME,
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070034 CONFIG_PARAMS,
keunhui.park2f7306a2015-07-16 16:48:06 +090035 OPERATOR_SPECIFIC,
vivek mehtaa8d7c922016-05-25 14:40:44 -070036 GAIN_LEVEL_MAPPING,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080037 APP_TYPE,
jiabin8962a4d2018-03-19 18:21:24 -070038 MICROPHONE_CHARACTERISTIC,
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -070039 SND_DEVICES,
40 INPUT_SND_DEVICE,
41 INPUT_SND_DEVICE_TO_MIC_MAPPING,
42 SND_DEV,
43 MIC_INFO,
Haynes Mathew George98c95622014-06-20 19:14:25 -070044} section_t;
45
46typedef void (* section_process_fn)(const XML_Char **attr);
47
48static void process_acdb_id(const XML_Char **attr);
49static void process_pcm_id(const XML_Char **attr);
50static void process_backend_name(const XML_Char **attr);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070051static void process_config_params(const XML_Char **attr);
Haynes Mathew George98c95622014-06-20 19:14:25 -070052static void process_root(const XML_Char **attr);
keunhui.park2f7306a2015-07-16 16:48:06 +090053static void process_operator_specific(const XML_Char **attr);
vivek mehtaa8d7c922016-05-25 14:40:44 -070054static void process_gain_db_to_level_map(const XML_Char **attr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080055static void process_app_type(const XML_Char **attr);
jiabin8962a4d2018-03-19 18:21:24 -070056static void process_microphone_characteristic(const XML_Char **attr);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -070057static void process_snd_dev(const XML_Char **attr);
58static void process_mic_info(const XML_Char **attr);
Haynes Mathew George98c95622014-06-20 19:14:25 -070059
60static section_process_fn section_table[] = {
61 [ROOT] = process_root,
62 [ACDB] = process_acdb_id,
63 [PCM_ID] = process_pcm_id,
64 [BACKEND_NAME] = process_backend_name,
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070065 [CONFIG_PARAMS] = process_config_params,
keunhui.park2f7306a2015-07-16 16:48:06 +090066 [OPERATOR_SPECIFIC] = process_operator_specific,
vivek mehtaa8d7c922016-05-25 14:40:44 -070067 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080068 [APP_TYPE] = process_app_type,
jiabin8962a4d2018-03-19 18:21:24 -070069 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -070070 [SND_DEV] = process_snd_dev,
71 [MIC_INFO] = process_mic_info,
Haynes Mathew George98c95622014-06-20 19:14:25 -070072};
73
vivek mehta0fb11312017-05-15 19:35:32 -070074static set_parameters_fn set_parameters = &platform_set_parameters;
75
Haynes Mathew George98c95622014-06-20 19:14:25 -070076static section_t section;
77
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070078struct platform_info {
vivek mehta0fb11312017-05-15 19:35:32 -070079 bool do_full_parse;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070080 void *platform;
81 struct str_parms *kvpairs;
82};
83
vivek mehta0fb11312017-05-15 19:35:32 -070084static struct platform_info my_data = {true, NULL, NULL};
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070085
jiabin8962a4d2018-03-19 18:21:24 -070086struct audio_string_to_enum {
87 const char* name;
88 unsigned int value;
89};
90
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -070091static snd_device_t in_snd_device;
92
jiabin8962a4d2018-03-19 18:21:24 -070093static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
94 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
95 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
96 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
97 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
98};
99
100static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
101 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
102 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
103 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
104 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
105 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
106 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
107};
108
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700109static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
110 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
111 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
112 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
113};
114
jiabin8962a4d2018-03-19 18:21:24 -0700115static const struct audio_string_to_enum device_in_types[] = {
116 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
117 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
118 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
119 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
120 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
121 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
122 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
123 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
124 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
125 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
126 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
127 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
128 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
129 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
130 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
131 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
132 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
133 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
134 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
135 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
136 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
137 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
138 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
139 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
140 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
141 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
142 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
143};
144
jiabina43dd882018-05-07 10:52:37 -0700145enum {
146 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
147 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
148 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
149 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
150 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
151 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
152 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
153 | ORIENTATION) | GEOMETRIC_LOCATION) */
154};
155
jiabin8962a4d2018-03-19 18:21:24 -0700156static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
157 int32_t len, unsigned int *value)
158{
159 if (table == NULL) {
160 ALOGE("%s: table is NULL", __func__);
161 return false;
162 }
163
164 if (name == NULL) {
165 ALOGE("null key");
166 return false;
167 }
168
169 for (int i = 0; i < len; i++) {
170 if (!strcmp(table[i].name, name)) {
171 *value = table[i].value;
172 return true;
173 }
174 }
175 return false;
176}
177
Haynes Mathew George98c95622014-06-20 19:14:25 -0700178/*
179 * <audio_platform_info>
180 * <acdb_ids>
181 * <device name="???" acdb_id="???"/>
182 * ...
183 * ...
184 * </acdb_ids>
185 * <backend_names>
186 * <device name="???" backend="???"/>
187 * ...
188 * ...
189 * </backend_names>
190 * <pcm_ids>
191 * <usecase name="???" type="in/out" id="???"/>
192 * ...
193 * ...
194 * </pcm_ids>
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700195 * <config_params>
196 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
keunhui.park2f7306a2015-07-16 16:48:06 +0900197 * <param key="operator_info" value="tmus;aa;bb;cc"/>
198 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700199 * ...
200 * ...
201 * </config_params>
202 *
keunhui.park2f7306a2015-07-16 16:48:06 +0900203 * <operator_specific>
204 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
205 * ...
206 * ...
207 * </operator_specific>
208 *
Haynes Mathew George98c95622014-06-20 19:14:25 -0700209 * </audio_platform_info>
210 */
211
212static void process_root(const XML_Char **attr __unused)
213{
214}
215
216/* mapping from usecase to pcm dev id */
217static void process_pcm_id(const XML_Char **attr)
218{
219 int index;
220
221 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700222 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew George98c95622014-06-20 19:14:25 -0700223 goto done;
224 }
225
226 index = platform_get_usecase_index((char *)attr[1]);
227 if (index < 0) {
228 ALOGE("%s: usecase %s in %s not found!",
229 __func__, attr[1], PLATFORM_INFO_XML_PATH);
230 goto done;
231 }
232
233 if (strcmp(attr[2], "type") != 0) {
234 ALOGE("%s: usecase type not mentioned", __func__);
235 goto done;
236 }
237
238 int type = -1;
239
240 if (!strcasecmp((char *)attr[3], "in")) {
241 type = 1;
242 } else if (!strcasecmp((char *)attr[3], "out")) {
243 type = 0;
244 } else {
245 ALOGE("%s: type must be IN or OUT", __func__);
246 goto done;
247 }
248
249 if (strcmp(attr[4], "id") != 0) {
250 ALOGE("%s: usecase id not mentioned", __func__);
251 goto done;
252 }
253
254 int id = atoi((char *)attr[5]);
255
256 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
257 ALOGE("%s: usecase %s in %s, type %d id %d was not set!",
258 __func__, attr[1], PLATFORM_INFO_XML_PATH, type, id);
259 goto done;
260 }
261
262done:
263 return;
264}
265
266/* backend to be used for a device */
267static void process_backend_name(const XML_Char **attr)
268{
269 int index;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700270 char *hw_interface = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700271
272 if (strcmp(attr[0], "name") != 0) {
273 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
274 goto done;
275 }
276
277 index = platform_get_snd_device_index((char *)attr[1]);
278 if (index < 0) {
279 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
280 __func__, attr[1], PLATFORM_INFO_XML_PATH);
281 goto done;
282 }
283
284 if (strcmp(attr[2], "backend") != 0) {
285 ALOGE("%s: Device %s in %s has no backed set!",
286 __func__, attr[1], PLATFORM_INFO_XML_PATH);
287 goto done;
288 }
289
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700290 if (attr[4] != NULL) {
291 if (strcmp(attr[4], "interface") != 0) {
292 hw_interface = NULL;
293 } else {
294 hw_interface = (char *)attr[5];
295 }
296 }
297
298 if (platform_set_snd_device_backend(index, attr[3], hw_interface) < 0) {
Haynes Mathew George98c95622014-06-20 19:14:25 -0700299 ALOGE("%s: Device %s in %s, backend %s was not set!",
300 __func__, attr[1], PLATFORM_INFO_XML_PATH, attr[3]);
301 goto done;
302 }
303
304done:
305 return;
306}
307
vivek mehtaa8d7c922016-05-25 14:40:44 -0700308static void process_gain_db_to_level_map(const XML_Char **attr)
309{
310 struct amp_db_and_gain_table tbl_entry;
311
312 if ((strcmp(attr[0], "db") != 0) ||
313 (strcmp(attr[2], "level") != 0)) {
314 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
315 __func__, attr[0], attr[2]);
316 goto done;
317 }
318
319 tbl_entry.db = atof(attr[1]);
320 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
321 tbl_entry.level = atoi(attr[3]);
322
vivek mehta40125092017-08-21 18:48:51 -0700323 //custome level should be > 0. Level 0 is fixed for default
324 CHECK(tbl_entry.level > 0);
325
vivek mehtaa8d7c922016-05-25 14:40:44 -0700326 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
327 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
328 platform_add_gain_level_mapping(&tbl_entry);
329
330done:
331 return;
332}
333
Haynes Mathew George98c95622014-06-20 19:14:25 -0700334static void process_acdb_id(const XML_Char **attr)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700335{
336 int index;
337
338 if (strcmp(attr[0], "name") != 0) {
339 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
340 goto done;
341 }
342
343 index = platform_get_snd_device_index((char *)attr[1]);
344 if (index < 0) {
345 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
346 __func__, attr[1], PLATFORM_INFO_XML_PATH);
347 goto done;
348 }
349
350 if (strcmp(attr[2], "acdb_id") != 0) {
351 ALOGE("%s: Device %s in %s has no acdb_id, no ACDB ID set!",
352 __func__, attr[1], PLATFORM_INFO_XML_PATH);
353 goto done;
354 }
355
Haynes Mathew George98c95622014-06-20 19:14:25 -0700356 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700357 ALOGE("%s: Device %s in %s, ACDB ID %d was not set!",
358 __func__, attr[1], PLATFORM_INFO_XML_PATH, atoi((char *)attr[3]));
359 goto done;
360 }
361
362done:
363 return;
364}
365
keunhui.park2f7306a2015-07-16 16:48:06 +0900366
367static void process_operator_specific(const XML_Char **attr)
368{
369 snd_device_t snd_device = SND_DEVICE_NONE;
370
371 if (strcmp(attr[0], "name") != 0) {
372 ALOGE("%s: 'name' not found", __func__);
373 goto done;
374 }
375
376 snd_device = platform_get_snd_device_index((char *)attr[1]);
377 if (snd_device < 0) {
378 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
379 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
380 goto done;
381 }
382
383 if (strcmp(attr[2], "operator") != 0) {
384 ALOGE("%s: 'operator' not found", __func__);
385 goto done;
386 }
387
388 if (strcmp(attr[4], "mixer_path") != 0) {
389 ALOGE("%s: 'mixer_path' not found", __func__);
390 goto done;
391 }
392
393 if (strcmp(attr[6], "acdb_id") != 0) {
394 ALOGE("%s: 'acdb_id' not found", __func__);
395 goto done;
396 }
397
398 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
399
400done:
401 return;
402}
403
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700404/* platform specific configuration key-value pairs */
405static void process_config_params(const XML_Char **attr)
406{
407 if (strcmp(attr[0], "key") != 0) {
408 ALOGE("%s: 'key' not found", __func__);
409 goto done;
410 }
411
412 if (strcmp(attr[2], "value") != 0) {
413 ALOGE("%s: 'value' not found", __func__);
414 goto done;
415 }
416
417 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
vivek mehta0fb11312017-05-15 19:35:32 -0700418 set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700419done:
420 return;
421}
422
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800423static void process_app_type(const XML_Char **attr)
424{
425 if (strcmp(attr[0], "uc_type")) {
426 ALOGE("%s: uc_type not found", __func__);
427 goto done;
428 }
429
vivek mehtaa68fea62017-06-08 19:04:02 -0700430 if (strcmp(attr[2], "mode")) {
431 ALOGE("%s: mode not found", __func__);
432 goto done;
433 }
434
435 if (strcmp(attr[4], "bit_width")) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800436 ALOGE("%s: bit_width not found", __func__);
437 goto done;
438 }
439
vivek mehtaa68fea62017-06-08 19:04:02 -0700440 if (strcmp(attr[6], "id")) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800441 ALOGE("%s: id not found", __func__);
442 goto done;
443 }
444
vivek mehtaa68fea62017-06-08 19:04:02 -0700445 if (strcmp(attr[8], "max_rate")) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800446 ALOGE("%s: max rate not found", __func__);
447 goto done;
448 }
449
vivek mehtaa68fea62017-06-08 19:04:02 -0700450 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
451 atoi(attr[9]));
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800452done:
453 return;
454}
455
jiabin8962a4d2018-03-19 18:21:24 -0700456static void process_microphone_characteristic(const XML_Char **attr) {
457 struct audio_microphone_characteristic_t microphone;
458 uint32_t curIdx = 0;
459
460 if (strcmp(attr[curIdx++], "valid_mask")) {
461 ALOGE("%s: valid_mask not found", __func__);
462 goto done;
463 }
jiabina43dd882018-05-07 10:52:37 -0700464 uint32_t valid_mask = atoi(attr[curIdx++]);
jiabin8962a4d2018-03-19 18:21:24 -0700465
466 if (strcmp(attr[curIdx++], "device_id")) {
467 ALOGE("%s: device_id not found", __func__);
468 goto done;
469 }
470 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
471 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
472 goto done;
473 }
474 strcpy(microphone.device_id, attr[curIdx++]);
475
476 if (strcmp(attr[curIdx++], "type")) {
477 ALOGE("%s: device not found", __func__);
478 goto done;
479 }
480 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
481 ARRAY_SIZE(device_in_types), &microphone.device)) {
482 ALOGE("%s: type %s in %s not found!",
483 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
484 goto done;
485 }
486
487 if (strcmp(attr[curIdx++], "address")) {
488 ALOGE("%s: address not found", __func__);
489 goto done;
490 }
491 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
492 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
493 goto done;
494 }
495 strcpy(microphone.address, attr[curIdx++]);
496 if (strlen(microphone.address) == 0) {
497 // If the address is empty, populate the address according to device type.
498 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
499 strcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS);
500 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
501 strcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS);
502 }
503 }
504
505 if (strcmp(attr[curIdx++], "location")) {
506 ALOGE("%s: location not found", __func__);
507 goto done;
508 }
509 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
510 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
511 ALOGE("%s: location %s in %s not found!",
512 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
513 goto done;
514 }
515
516 if (strcmp(attr[curIdx++], "group")) {
517 ALOGE("%s: group not found", __func__);
518 goto done;
519 }
520 microphone.group = atoi(attr[curIdx++]);
521
522 if (strcmp(attr[curIdx++], "index_in_the_group")) {
523 ALOGE("%s: index_in_the_group not found", __func__);
524 goto done;
525 }
526 microphone.index_in_the_group = atoi(attr[curIdx++]);
527
528 if (strcmp(attr[curIdx++], "directionality")) {
529 ALOGE("%s: directionality not found", __func__);
530 goto done;
531 }
532 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
533 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
534 ALOGE("%s: directionality %s in %s not found!",
535 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
536 goto done;
537 }
538
539 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
540 ALOGE("%s: num_frequency_responses not found", __func__);
541 goto done;
542 }
543 microphone.num_frequency_responses = atoi(attr[curIdx++]);
544 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
545 ALOGE("%s: num_frequency_responses is too large", __func__);
546 goto done;
547 }
548 if (microphone.num_frequency_responses > 0) {
549 if (strcmp(attr[curIdx++], "frequencies")) {
550 ALOGE("%s: frequencies not found", __func__);
551 goto done;
552 }
jiabin196df232018-05-03 14:00:20 -0700553 char *token = strtok((char *)attr[curIdx++], " ");
jiabin8962a4d2018-03-19 18:21:24 -0700554 uint32_t num_frequencies = 0;
555 while (token) {
556 microphone.frequency_responses[0][num_frequencies++] = atof(token);
557 if (num_frequencies > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
558 ALOGE("%s: num %u of frequency is too large", __func__, num_frequencies);
559 goto done;
560 }
jiabin196df232018-05-03 14:00:20 -0700561 token = strtok(NULL, " ");
jiabin8962a4d2018-03-19 18:21:24 -0700562 }
563
564 if (strcmp(attr[curIdx++], "responses")) {
565 ALOGE("%s: responses not found", __func__);
566 goto done;
567 }
jiabin196df232018-05-03 14:00:20 -0700568 token = strtok((char *)attr[curIdx++], " ");
jiabin8962a4d2018-03-19 18:21:24 -0700569 uint32_t num_responses = 0;
570 while (token) {
571 microphone.frequency_responses[1][num_responses++] = atof(token);
572 if (num_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
573 ALOGE("%s: num %u of response is too large", __func__, num_responses);
574 goto done;
575 }
jiabin196df232018-05-03 14:00:20 -0700576 token = strtok(NULL, " ");
jiabin8962a4d2018-03-19 18:21:24 -0700577 }
578
579 if (num_frequencies != num_responses
580 || num_frequencies != microphone.num_frequency_responses) {
581 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
582 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
583 goto done;
584 }
585 }
586
jiabina43dd882018-05-07 10:52:37 -0700587 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
jiabin8962a4d2018-03-19 18:21:24 -0700588 if (strcmp(attr[curIdx++], "sensitivity")) {
589 ALOGE("%s: sensitivity not found", __func__);
590 goto done;
591 }
592 microphone.sensitivity = atof(attr[curIdx++]);
593 } else {
594 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
595 }
596
jiabina43dd882018-05-07 10:52:37 -0700597 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
jiabin8962a4d2018-03-19 18:21:24 -0700598 if (strcmp(attr[curIdx++], "max_spl")) {
599 ALOGE("%s: max_spl not found", __func__);
600 goto done;
601 }
602 microphone.max_spl = atof(attr[curIdx++]);
603 } else {
604 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
605 }
606
jiabina43dd882018-05-07 10:52:37 -0700607 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
jiabin8962a4d2018-03-19 18:21:24 -0700608 if (strcmp(attr[curIdx++], "min_spl")) {
609 ALOGE("%s: min_spl not found", __func__);
610 goto done;
611 }
612 microphone.min_spl = atof(attr[curIdx++]);
613 } else {
614 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
615 }
616
jiabina43dd882018-05-07 10:52:37 -0700617 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
jiabin8962a4d2018-03-19 18:21:24 -0700618 if (strcmp(attr[curIdx++], "orientation")) {
619 ALOGE("%s: orientation not found", __func__);
620 goto done;
621 }
jiabin196df232018-05-03 14:00:20 -0700622 char *token = strtok((char *)attr[curIdx++], " ");
jiabin8962a4d2018-03-19 18:21:24 -0700623 float orientation[3];
624 uint32_t idx = 0;
625 while (token) {
626 orientation[idx++] = atof(token);
627 if (idx > 3) {
628 ALOGE("%s: orientation invalid", __func__);
629 goto done;
630 }
jiabin196df232018-05-03 14:00:20 -0700631 token = strtok(NULL, " ");
jiabin8962a4d2018-03-19 18:21:24 -0700632 }
633 if (idx != 3) {
634 ALOGE("%s: orientation invalid", __func__);
635 goto done;
636 }
637 microphone.orientation.x = orientation[0];
638 microphone.orientation.y = orientation[1];
639 microphone.orientation.z = orientation[2];
640 } else {
641 microphone.orientation.x = 0.0f;
642 microphone.orientation.y = 0.0f;
643 microphone.orientation.z = 0.0f;
644 }
645
jiabina43dd882018-05-07 10:52:37 -0700646 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
jiabin8962a4d2018-03-19 18:21:24 -0700647 if (strcmp(attr[curIdx++], "geometric_location")) {
648 ALOGE("%s: geometric_location not found", __func__);
649 goto done;
650 }
jiabin196df232018-05-03 14:00:20 -0700651 char *token = strtok((char *)attr[curIdx++], " ");
jiabin8962a4d2018-03-19 18:21:24 -0700652 float geometric_location[3];
653 uint32_t idx = 0;
654 while (token) {
655 geometric_location[idx++] = atof(token);
656 if (idx > 3) {
657 ALOGE("%s: geometric_location invalid", __func__);
658 goto done;
659 }
jiabin196df232018-05-03 14:00:20 -0700660 token = strtok(NULL, " ");
jiabin8962a4d2018-03-19 18:21:24 -0700661 }
662 if (idx != 3) {
663 ALOGE("%s: geometric_location invalid", __func__);
664 goto done;
665 }
666 microphone.geometric_location.x = geometric_location[0];
667 microphone.geometric_location.y = geometric_location[1];
668 microphone.geometric_location.z = geometric_location[2];
669 } else {
670 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
671 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
672 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
673 }
674
675 platform_set_microphone_characteristic(my_data.platform, microphone);
676done:
677 return;
678}
679
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700680static void process_snd_dev(const XML_Char **attr)
681{
682 uint32_t curIdx = 0;
683 in_snd_device = SND_DEVICE_NONE;
684
685 if (strcmp(attr[curIdx++], "in_snd_device")) {
686 ALOGE("%s: snd_device not found", __func__);
687 return;
688 }
689 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
690 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
691 in_snd_device >= SND_DEVICE_IN_END) {
692 ALOGE("%s: Sound device not valid", __func__);
693 in_snd_device = SND_DEVICE_NONE;
694 }
695
696 return;
697}
698
699static void process_mic_info(const XML_Char **attr)
700{
701 uint32_t curIdx = 0;
702 struct mic_info microphone;
703
704 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
705 sizeof(microphone.channel_mapping));
706
707 if (strcmp(attr[curIdx++], "mic_device_id")) {
708 ALOGE("%s: mic_device_id not found", __func__);
709 goto on_error;
710 }
711 strlcpy(microphone.device_id,
712 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
713
714 if (strcmp(attr[curIdx++], "channel_mapping")) {
715 ALOGE("%s: channel_mapping not found", __func__);
716 goto on_error;
717 }
718 const char *token = strtok((char *)attr[curIdx++], " ");
719 uint32_t idx = 0;
720 while (token) {
721 if (!find_enum_by_string(mic_channel_mapping, token,
722 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
723 &microphone.channel_mapping[idx++])) {
724 ALOGE("%s: channel_mapping %s in %s not found!",
725 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
726 goto on_error;
727 }
728 token = strtok(NULL, " ");
729 }
730 microphone.channel_count = idx;
731
732 platform_set_microphone_map(my_data.platform, in_snd_device,
733 &microphone);
734 return;
735on_error:
736 in_snd_device = SND_DEVICE_NONE;
737 return;
738}
739
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700740static void start_tag(void *userdata __unused, const XML_Char *tag_name,
741 const XML_Char **attr)
742{
743 const XML_Char *attr_name = NULL;
744 const XML_Char *attr_value = NULL;
745 unsigned int i;
746
Haynes Mathew George98c95622014-06-20 19:14:25 -0700747
vivek mehta0fb11312017-05-15 19:35:32 -0700748 if (my_data.do_full_parse) {
749 if (strcmp(tag_name, "acdb_ids") == 0) {
750 section = ACDB;
751 } else if (strcmp(tag_name, "pcm_ids") == 0) {
752 section = PCM_ID;
753 } else if (strcmp(tag_name, "backend_names") == 0) {
754 section = BACKEND_NAME;
755 } else if (strcmp(tag_name, "config_params") == 0) {
756 section = CONFIG_PARAMS;
757 } else if (strcmp(tag_name, "operator_specific") == 0) {
758 section = OPERATOR_SPECIFIC;
759 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
760 section = GAIN_LEVEL_MAPPING;
761 } else if (strcmp(tag_name, "app_types") == 0) {
762 section = APP_TYPE;
jiabin8962a4d2018-03-19 18:21:24 -0700763 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
764 section = MICROPHONE_CHARACTERISTIC;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700765 } else if (strcmp(tag_name, "snd_devices") == 0) {
766 section = SND_DEVICES;
vivek mehta0fb11312017-05-15 19:35:32 -0700767 } else if (strcmp(tag_name, "device") == 0) {
768 if ((section != ACDB) && (section != BACKEND_NAME) && (section != OPERATOR_SPECIFIC)) {
769 ALOGE("device tag only supported for acdb/backend names");
770 return;
771 }
Haynes Mathew George98c95622014-06-20 19:14:25 -0700772
vivek mehta0fb11312017-05-15 19:35:32 -0700773 /* call into process function for the current section */
774 section_process_fn fn = section_table[section];
775 fn(attr);
776 } else if (strcmp(tag_name, "usecase") == 0) {
777 if (section != PCM_ID) {
778 ALOGE("usecase tag only supported with PCM_ID section");
779 return;
780 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700781
vivek mehta0fb11312017-05-15 19:35:32 -0700782 section_process_fn fn = section_table[PCM_ID];
783 fn(attr);
784 } else if (strcmp(tag_name, "param") == 0) {
785 if (section != CONFIG_PARAMS) {
786 ALOGE("param tag only supported with CONFIG_PARAMS section");
787 return;
788 }
vivek mehtaa8d7c922016-05-25 14:40:44 -0700789
vivek mehta0fb11312017-05-15 19:35:32 -0700790 section_process_fn fn = section_table[section];
791 fn(attr);
792 } else if (strcmp(tag_name, "gain_level_map") == 0) {
793 if (section != GAIN_LEVEL_MAPPING) {
jiabin8962a4d2018-03-19 18:21:24 -0700794 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
vivek mehta0fb11312017-05-15 19:35:32 -0700795 return;
796 }
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800797
vivek mehta0fb11312017-05-15 19:35:32 -0700798 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
799 fn(attr);
800 } else if (!strcmp(tag_name, "app")) {
801 if (section != APP_TYPE) {
802 ALOGE("app tag only valid in section APP_TYPE");
803 return;
804 }
805
806 section_process_fn fn = section_table[APP_TYPE];
807 fn(attr);
jiabin8962a4d2018-03-19 18:21:24 -0700808 } else if (strcmp(tag_name, "microphone") == 0) {
809 if (section != MICROPHONE_CHARACTERISTIC) {
810 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
811 return;
812 }
813 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
814 fn(attr);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700815 } else if (strcmp(tag_name, "input_snd_device") == 0) {
816 if (section != SND_DEVICES) {
817 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
818 return;
819 }
820 section = INPUT_SND_DEVICE;
821 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
822 if (section != INPUT_SND_DEVICE) {
823 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
824 return;
825 }
826 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
827 } else if (strcmp(tag_name, "snd_dev") == 0) {
828 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
829 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
830 return;
831 }
832 section_process_fn fn = section_table[SND_DEV];
833 fn(attr);
834 } else if (strcmp(tag_name, "mic_info") == 0) {
835 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
836 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
837 return;
838 }
839 if (in_snd_device == SND_DEVICE_NONE) {
840 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
841 return;
842 }
843 section_process_fn fn = section_table[MIC_INFO];
844 fn(attr);
vivek mehta0fb11312017-05-15 19:35:32 -0700845 }
846 } else {
847 if(strcmp(tag_name, "config_params") == 0) {
848 section = CONFIG_PARAMS;
849 } else if (strcmp(tag_name, "param") == 0) {
850 if (section != CONFIG_PARAMS) {
851 ALOGE("param tag only supported with CONFIG_PARAMS section");
852 return;
853 }
854
855 section_process_fn fn = section_table[section];
856 fn(attr);
857 }
Haynes Mathew George98c95622014-06-20 19:14:25 -0700858 }
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700859
860 return;
861}
862
Haynes Mathew George98c95622014-06-20 19:14:25 -0700863static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700864{
Haynes Mathew George98c95622014-06-20 19:14:25 -0700865 if (strcmp(tag_name, "acdb_ids") == 0) {
866 section = ROOT;
867 } else if (strcmp(tag_name, "pcm_ids") == 0) {
868 section = ROOT;
869 } else if (strcmp(tag_name, "backend_names") == 0) {
870 section = ROOT;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700871 } else if (strcmp(tag_name, "config_params") == 0) {
872 section = ROOT;
keunhui.park2f7306a2015-07-16 16:48:06 +0900873 } else if (strcmp(tag_name, "operator_specific") == 0) {
874 section = ROOT;
vivek mehtaa8d7c922016-05-25 14:40:44 -0700875 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
876 section = ROOT;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800877 } else if (strcmp(tag_name, "app_types") == 0) {
878 section = ROOT;
jiabin8962a4d2018-03-19 18:21:24 -0700879 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
880 section = ROOT;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700881 } else if (strcmp(tag_name, "snd_devices") == 0) {
882 section = ROOT;
883 } else if (strcmp(tag_name, "input_snd_device") == 0) {
884 section = SND_DEVICES;
885 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
886 section = INPUT_SND_DEVICE;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700887 }
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700888}
889
vivek mehta0fb11312017-05-15 19:35:32 -0700890int snd_card_info_init(const char *filename, void *platform, set_parameters_fn fn)
891{
892 set_parameters = fn;
893 my_data.do_full_parse = false;
894 return platform_info_init(filename, platform);
895}
896
vivek mehtade4849c2016-03-03 17:23:38 -0800897int platform_info_init(const char *filename, void *platform)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700898{
899 XML_Parser parser;
900 FILE *file;
901 int ret = 0;
902 int bytes_read;
903 void *buf;
904 static const uint32_t kBufSize = 1024;
vivek mehtade4849c2016-03-03 17:23:38 -0800905 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700906 section = ROOT;
907
vivek mehtade4849c2016-03-03 17:23:38 -0800908 if (filename == NULL) {
909 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
910 } else {
911 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
912 }
913
914 ALOGV("%s: platform info file name is %s", __func__, platform_info_file_name);
915
916 file = fopen(platform_info_file_name, "r");
917
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700918 if (!file) {
919 ALOGD("%s: Failed to open %s, using defaults.",
vivek mehtade4849c2016-03-03 17:23:38 -0800920 __func__, platform_info_file_name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700921 ret = -ENODEV;
922 goto done;
923 }
924
925 parser = XML_ParserCreate(NULL);
926 if (!parser) {
927 ALOGE("%s: Failed to create XML parser!", __func__);
928 ret = -ENODEV;
929 goto err_close_file;
930 }
931
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700932 my_data.platform = platform;
933 my_data.kvpairs = str_parms_create();
934
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700935 XML_SetElementHandler(parser, start_tag, end_tag);
936
937 while (1) {
938 buf = XML_GetBuffer(parser, kBufSize);
939 if (buf == NULL) {
940 ALOGE("%s: XML_GetBuffer failed", __func__);
941 ret = -ENOMEM;
942 goto err_free_parser;
943 }
944
945 bytes_read = fread(buf, 1, kBufSize, file);
946 if (bytes_read < 0) {
947 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
948 ret = bytes_read;
949 goto err_free_parser;
950 }
951
952 if (XML_ParseBuffer(parser, bytes_read,
953 bytes_read == 0) == XML_STATUS_ERROR) {
954 ALOGE("%s: XML_ParseBuffer failed, for %s",
vivek mehtade4849c2016-03-03 17:23:38 -0800955 __func__, platform_info_file_name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700956 ret = -EINVAL;
957 goto err_free_parser;
958 }
959
960 if (bytes_read == 0)
961 break;
962 }
963
vivek mehta0fb11312017-05-15 19:35:32 -0700964 set_parameters = &platform_set_parameters;
965 my_data.do_full_parse = true;
966
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700967err_free_parser:
968 XML_ParserFree(parser);
969err_close_file:
970 fclose(file);
971done:
972 return ret;
973}