blob: 827c55813ae1285f5244f842961ba11af6f7f205 [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Aalique Grahame22e49102018-12-18 14:23:57 -08002 * Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
Ben Romberger55886882014-01-10 13:49:02 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Ben Romberger61764e32014-01-10 13:49:02 -080030#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080031#define LOG_NDDEBUG 0
32
33#include <errno.h>
34#include <stdio.h>
35#include <expat.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080036#include <log/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070037#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080038#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070039#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080040#include "platform_api.h"
41#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070042#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080043
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053044#ifdef DYNAMIC_LOG_ENABLED
45#include <log_xml_parser.h>
46#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
47#include <log_utils.h>
48#endif
49
Ben Romberger55886882014-01-10 13:49:02 -080050#define BUF_SIZE 1024
51
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070052typedef enum {
53 ROOT,
54 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070055 MODULE,
56 AEC,
57 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070058 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070059 PCM_ID,
60 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080061 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070062 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080063 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070064 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080065 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053066 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053067 MICROPHONE_CHARACTERISTIC,
68 SND_DEVICES,
69 INPUT_SND_DEVICE,
70 INPUT_SND_DEVICE_TO_MIC_MAPPING,
71 SND_DEV,
72 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053073 CUSTOM_MTMX_PARAMS,
74 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070075 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053076 CUSTOM_MTMX_IN_PARAMS,
77 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070078} section_t;
79
80typedef void (* section_process_fn)(const XML_Char **attr);
81
82static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070083static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
84static void process_effect_aec(const XML_Char **attr);
85static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070086static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070087static void process_pcm_id(const XML_Char **attr);
88static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080089static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070090static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070091static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080092static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070093static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080094static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053095static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053096static void process_microphone_characteristic(const XML_Char **attr);
97static void process_snd_dev(const XML_Char **attr);
98static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +053099static void process_custom_mtmx_params(const XML_Char **attr);
100static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700101static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530102static void process_custom_mtmx_in_params(const XML_Char **attr);
103static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700104
105static section_process_fn section_table[] = {
106 [ROOT] = process_root,
107 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700108 [AEC] = process_effect_aec,
109 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700110 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700111 [PCM_ID] = process_pcm_id,
112 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800113 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700114 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800115 [OPERATOR_SPECIFIC] = process_operator_specific,
116 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700117 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530118 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530119 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
120 [SND_DEV] = process_snd_dev,
121 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530122 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
123 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700124 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530125 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
126 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700127};
128
129static section_t section;
130
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700131struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700132 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700133 void *platform;
134 struct str_parms *kvpairs;
135};
136
137static struct platform_info my_data;
138
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530139
140struct audio_string_to_enum {
141 const char* name;
142 unsigned int value;
143};
144
145static snd_device_t in_snd_device;
146
147static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
148 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
149 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
150 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
151 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
152};
153
154static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
155 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
157 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
161};
162
163static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
167};
168
169static const struct audio_string_to_enum device_in_types[] = {
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
197};
198
199enum {
200 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
201 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
202 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
203 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
204 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
205 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
206 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
207 | ORIENTATION) | GEOMETRIC_LOCATION) */
208};
209
210static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
211 int32_t len, unsigned int *value)
212{
213 if (table == NULL) {
214 ALOGE("%s: table is NULL", __func__);
215 return false;
216 }
217
218 if (name == NULL) {
219 ALOGE("null key");
220 return false;
221 }
222
223 for (int i = 0; i < len; i++) {
224 if (!strcmp(table[i].name, name)) {
225 *value = table[i].value;
226 return true;
227 }
228 }
229 return false;
230}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530231
232static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530233static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530234
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700235/*
236 * <audio_platform_info>
237 * <acdb_ids>
238 * <device name="???" acdb_id="???"/>
239 * ...
240 * ...
241 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700242 * <module_ids>
243 * <device name="???" module_id="???"/>
244 * ...
245 * ...
246 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700247 * <backend_names>
248 * <device name="???" backend="???"/>
249 * ...
250 * ...
251 * </backend_names>
252 * <pcm_ids>
253 * <usecase name="???" type="in/out" id="???"/>
254 * ...
255 * ...
256 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800257 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530258 * <device name="Use audio device name here, not sound device name" interface="PRIMARY_I2S" codec_type="external/internal"/>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800259 * ...
260 * ...
261 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700262 * <config_params>
263 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800264 * <param key="operator_info" value="tmus;aa;bb;cc"/>
265 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700266 * ...
267 * ...
268 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800269 *
270 * <operator_specific>
271 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
272 * ...
273 * ...
274 * </operator_specific>
275 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700276 * </audio_platform_info>
277 */
278
279static void process_root(const XML_Char **attr __unused)
280{
281}
282
283/* mapping from usecase to pcm dev id */
284static void process_pcm_id(const XML_Char **attr)
285{
286 int index;
287
288 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700289 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700290 goto done;
291 }
292
293 index = platform_get_usecase_index((char *)attr[1]);
294 if (index < 0) {
295 ALOGE("%s: usecase %s not found!",
296 __func__, attr[1]);
297 goto done;
298 }
299
300 if (strcmp(attr[2], "type") != 0) {
301 ALOGE("%s: usecase type not mentioned", __func__);
302 goto done;
303 }
304
305 int type = -1;
306
307 if (!strcasecmp((char *)attr[3], "in")) {
308 type = 1;
309 } else if (!strcasecmp((char *)attr[3], "out")) {
310 type = 0;
311 } else {
312 ALOGE("%s: type must be IN or OUT", __func__);
313 goto done;
314 }
315
316 if (strcmp(attr[4], "id") != 0) {
317 ALOGE("%s: usecase id not mentioned", __func__);
318 goto done;
319 }
320
321 int id = atoi((char *)attr[5]);
322
323 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
324 ALOGE("%s: usecase %s type %d id %d was not set!",
325 __func__, attr[1], type, id);
326 goto done;
327 }
328
329done:
330 return;
331}
332
333/* backend to be used for a device */
334static void process_backend_name(const XML_Char **attr)
335{
336 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530337 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530338 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700339
340 if (strcmp(attr[0], "name") != 0) {
341 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
342 goto done;
343 }
344
345 index = platform_get_snd_device_index((char *)attr[1]);
346 if (index < 0) {
347 ALOGE("%s: Device %s not found, no ACDB ID set!",
348 __func__, attr[1]);
349 goto done;
350 }
351
352 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530353 if (strcmp(attr[2], "interface") == 0)
354 hw_interface = (char *)attr[3];
355 } else {
356 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700357 }
358
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530359 if (attr[4] != NULL) {
360 if (strcmp(attr[4], "interface") != 0) {
361 hw_interface = NULL;
362 } else {
363 hw_interface = (char *)attr[5];
364 }
365 }
366
Ashish Jaind150d4c2017-02-03 18:44:34 +0530367 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700368 ALOGE("%s: Device %s backend %s was not set!",
369 __func__, attr[1], attr[3]);
370 goto done;
371 }
372
373done:
374 return;
375}
376
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700377static void process_gain_db_to_level_map(const XML_Char **attr)
378{
379 struct amp_db_and_gain_table tbl_entry;
380
381 if ((strcmp(attr[0], "db") != 0) ||
382 (strcmp(attr[2], "level") != 0)) {
383 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
384 __func__, attr[0], attr[2]);
385 goto done;
386 }
387
388 tbl_entry.db = atof(attr[1]);
389 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
390 tbl_entry.level = atoi(attr[3]);
391
Aalique Grahame22e49102018-12-18 14:23:57 -0800392 //custome level should be > 0. Level 0 is fixed for default
393 CHECK(tbl_entry.level > 0);
394
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700395 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
396 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
397 platform_add_gain_level_mapping(&tbl_entry);
398
399done:
400 return;
401}
402
403
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700404static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800405{
Ben Romberger61764e32014-01-10 13:49:02 -0800406 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800407
Ben Romberger61764e32014-01-10 13:49:02 -0800408 if (strcmp(attr[0], "name") != 0) {
409 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800410 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800411 }
Ben Romberger55886882014-01-10 13:49:02 -0800412
Ben Romberger61764e32014-01-10 13:49:02 -0800413 index = platform_get_snd_device_index((char *)attr[1]);
414 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800415 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
416 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800417 goto done;
418 }
419
420 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800421 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
422 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800423 goto done;
424 }
425
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700426 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
427 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800428 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800429 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800430 }
Ben Romberger55886882014-01-10 13:49:02 -0800431
Ben Romberger55886882014-01-10 13:49:02 -0800432done:
433 return;
434}
435
Aalique Grahame22e49102018-12-18 14:23:57 -0800436static void process_operator_specific(const XML_Char **attr)
437{
438 snd_device_t snd_device = SND_DEVICE_NONE;
439
440 if (strcmp(attr[0], "name") != 0) {
441 ALOGE("%s: 'name' not found", __func__);
442 goto done;
443 }
444
445 snd_device = platform_get_snd_device_index((char *)attr[1]);
446 if (snd_device < 0) {
447 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
448 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
449 goto done;
450 }
451
452 if (strcmp(attr[2], "operator") != 0) {
453 ALOGE("%s: 'operator' not found", __func__);
454 goto done;
455 }
456
457 if (strcmp(attr[4], "mixer_path") != 0) {
458 ALOGE("%s: 'mixer_path' not found", __func__);
459 goto done;
460 }
461
462 if (strcmp(attr[6], "acdb_id") != 0) {
463 ALOGE("%s: 'acdb_id' not found", __func__);
464 goto done;
465 }
466
467 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
468
469done:
470 return;
471}
472
Carter Hsu32a62362018-10-15 15:01:42 -0700473static void process_external_dev(const XML_Char **attr)
474{
475 snd_device_t snd_device = SND_DEVICE_NONE;
476
477 if (strcmp(attr[0], "name") != 0) {
478 ALOGE("%s: 'name' not found", __func__);
479 goto done;
480 }
481
482 snd_device = platform_get_snd_device_index((char *)attr[1]);
483 if (snd_device < 0) {
484 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
485 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
486 goto done;
487 }
488
489 if (strcmp(attr[2], "usbid") != 0) {
490 ALOGE("%s: 'usbid' not found", __func__);
491 goto done;
492 }
493
494 if (strcmp(attr[4], "acdb_id") != 0) {
495 ALOGE("%s: 'acdb_id' not found", __func__);
496 goto done;
497 }
498
499 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
500
501done:
502 return;
503}
504
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700505static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
506{
507 int index;
508 struct audio_effect_config effect_config;
509
510 if (strcmp(attr[0], "name") != 0) {
511 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
512 goto done;
513 }
514
515 index = platform_get_snd_device_index((char *)attr[1]);
516 if (index < 0) {
517 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
518 __func__, attr[1]);
519 goto done;
520 }
521
522 if (strcmp(attr[2], "module_id") != 0) {
523 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
524 __func__, attr[2]);
525 goto done;
526 }
527
528 if (strcmp(attr[4], "instance_id") != 0) {
529 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
530 __func__, attr[4]);
531 goto done;
532 }
533
534 if (strcmp(attr[6], "param_id") != 0) {
535 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
536 __func__, attr[6]);
537 goto done;
538 }
539
540 if (strcmp(attr[8], "param_value") != 0) {
541 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
542 __func__, attr[8]);
543 goto done;
544 }
545
546 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
547 strtol((char *)attr[5], NULL, 0),
548 strtol((char *)attr[7], NULL, 0),
549 strtol((char *)attr[9], NULL, 0)};
550
551
552 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
553 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
554 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
555 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
556 strtol((char *)attr[9], NULL, 0));
557 goto done;
558 }
559
560done:
561 return;
562}
563
564static void process_effect_aec(const XML_Char **attr)
565{
566 process_audio_effect(attr, EFFECT_AEC);
567 return;
568}
569
570static void process_effect_ns(const XML_Char **attr)
571{
572 process_audio_effect(attr, EFFECT_NS);
573 return;
574}
575
Amit Shekhar5a39c912014-10-14 15:39:30 -0700576static void process_bit_width(const XML_Char **attr)
577{
578 int index;
579
580 if (strcmp(attr[0], "name") != 0) {
581 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
582 goto done;
583 }
584
585 index = platform_get_snd_device_index((char *)attr[1]);
586 if (index < 0) {
587 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
588 __func__, attr[1]);
589 goto done;
590 }
591
592 if (strcmp(attr[2], "bit_width") != 0) {
593 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
594 __func__, attr[1]);
595 goto done;
596 }
597
598 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
599 ALOGE("%s: Device %s, ACDB ID %d was not set!",
600 __func__, attr[1], atoi((char *)attr[3]));
601 goto done;
602 }
603
604done:
605 return;
606}
607
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800608static void process_interface_name(const XML_Char **attr)
609{
610 int ret;
611
612 if (strcmp(attr[0], "name") != 0) {
613 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
614
615 goto done;
616 }
617
618 if (strcmp(attr[2], "interface") != 0) {
619 ALOGE("%s: Device %s has no Audio Interface set!",
620 __func__, attr[1]);
621
622 goto done;
623 }
624
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530625 if (strcmp(attr[4], "codec_type") != 0) {
626 ALOGE("%s: Device %s has no codec type set!",
627 __func__, attr[1]);
628
629 goto done;
630 }
631
632 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
633 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800634 if (ret < 0) {
635 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800636 goto done;
637 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800638
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800639done:
640 return;
641}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530642
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700643static void process_config_params(const XML_Char **attr)
644{
645 if (strcmp(attr[0], "key") != 0) {
646 ALOGE("%s: 'key' not found", __func__);
647 goto done;
648 }
649
650 if (strcmp(attr[2], "value") != 0) {
651 ALOGE("%s: 'value' not found", __func__);
652 goto done;
653 }
654
655 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700656 if (my_data.caller == PLATFORM)
657 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700658done:
659 return;
660}
661
Aalique Grahame22e49102018-12-18 14:23:57 -0800662static void process_app_type(const XML_Char **attr)
663{
664 if (strcmp(attr[0], "uc_type")) {
665 ALOGE("%s: uc_type not found", __func__);
666 goto done;
667 }
668
669 if (strcmp(attr[2], "mode")) {
670 ALOGE("%s: mode not found", __func__);
671 goto done;
672 }
673
674 if (strcmp(attr[4], "bit_width")) {
675 ALOGE("%s: bit_width not found", __func__);
676 goto done;
677 }
678
679 if (strcmp(attr[6], "id")) {
680 ALOGE("%s: id not found", __func__);
681 goto done;
682 }
683
684 if (strcmp(attr[8], "max_rate")) {
685 ALOGE("%s: max rate not found", __func__);
686 goto done;
687 }
688
689 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
690 atoi(attr[9]));
691done:
692 return;
693}
694
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530695static void process_microphone_characteristic(const XML_Char **attr) {
696 struct audio_microphone_characteristic_t microphone;
697 uint32_t curIdx = 0;
698
699 if (strcmp(attr[curIdx++], "valid_mask")) {
700 ALOGE("%s: valid_mask not found", __func__);
701 goto done;
702 }
703 uint32_t valid_mask = atoi(attr[curIdx++]);
704
705 if (strcmp(attr[curIdx++], "device_id")) {
706 ALOGE("%s: device_id not found", __func__);
707 goto done;
708 }
709 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
710 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
711 goto done;
712 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530713 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530714
715 if (strcmp(attr[curIdx++], "type")) {
716 ALOGE("%s: device not found", __func__);
717 goto done;
718 }
719 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
720 ARRAY_SIZE(device_in_types), &microphone.device)) {
721 ALOGE("%s: type %s in %s not found!",
722 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
723 goto done;
724 }
725
726 if (strcmp(attr[curIdx++], "address")) {
727 ALOGE("%s: address not found", __func__);
728 goto done;
729 }
730 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
731 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
732 goto done;
733 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530734 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530735 if (strlen(microphone.address) == 0) {
736 // If the address is empty, populate the address according to device type.
737 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530738 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530739 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530740 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530741 }
742 }
743
744 if (strcmp(attr[curIdx++], "location")) {
745 ALOGE("%s: location not found", __func__);
746 goto done;
747 }
748 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
749 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
750 ALOGE("%s: location %s in %s not found!",
751 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
752 goto done;
753 }
754
755 if (strcmp(attr[curIdx++], "group")) {
756 ALOGE("%s: group not found", __func__);
757 goto done;
758 }
759 microphone.group = atoi(attr[curIdx++]);
760
761 if (strcmp(attr[curIdx++], "index_in_the_group")) {
762 ALOGE("%s: index_in_the_group not found", __func__);
763 goto done;
764 }
765 microphone.index_in_the_group = atoi(attr[curIdx++]);
766
767 if (strcmp(attr[curIdx++], "directionality")) {
768 ALOGE("%s: directionality not found", __func__);
769 goto done;
770 }
771 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
772 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
773 ALOGE("%s: directionality %s in %s not found!",
774 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
775 goto done;
776 }
777
778 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
779 ALOGE("%s: num_frequency_responses not found", __func__);
780 goto done;
781 }
782 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530783 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530784 ALOGE("%s: num_frequency_responses is too large", __func__);
785 goto done;
786 }
787 if (microphone.num_frequency_responses > 0) {
788 if (strcmp(attr[curIdx++], "frequencies")) {
789 ALOGE("%s: frequencies not found", __func__);
790 goto done;
791 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530792 char *context = NULL;
793 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530794 uint32_t num_frequencies = 0;
795 while (token) {
796 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800797 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530798 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530799 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530800 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530801 }
802
803 if (strcmp(attr[curIdx++], "responses")) {
804 ALOGE("%s: responses not found", __func__);
805 goto done;
806 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530807 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530808 uint32_t num_responses = 0;
809 while (token) {
810 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800811 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530812 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530813 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530814 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530815 }
816
817 if (num_frequencies != num_responses
818 || num_frequencies != microphone.num_frequency_responses) {
819 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
820 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
821 goto done;
822 }
823 }
824
825 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
826 if (strcmp(attr[curIdx++], "sensitivity")) {
827 ALOGE("%s: sensitivity not found", __func__);
828 goto done;
829 }
830 microphone.sensitivity = atof(attr[curIdx++]);
831 } else {
832 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
833 }
834
835 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
836 if (strcmp(attr[curIdx++], "max_spl")) {
837 ALOGE("%s: max_spl not found", __func__);
838 goto done;
839 }
840 microphone.max_spl = atof(attr[curIdx++]);
841 } else {
842 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
843 }
844
845 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
846 if (strcmp(attr[curIdx++], "min_spl")) {
847 ALOGE("%s: min_spl not found", __func__);
848 goto done;
849 }
850 microphone.min_spl = atof(attr[curIdx++]);
851 } else {
852 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
853 }
854
855 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
856 if (strcmp(attr[curIdx++], "orientation")) {
857 ALOGE("%s: orientation not found", __func__);
858 goto done;
859 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530860 char *context = NULL;
861 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530862 float orientation[3];
863 uint32_t idx = 0;
864 while (token) {
865 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800866 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530867 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530868 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530869 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530870 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530871 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530872 ALOGE("%s: orientation invalid", __func__);
873 goto done;
874 }
875 microphone.orientation.x = orientation[0];
876 microphone.orientation.y = orientation[1];
877 microphone.orientation.z = orientation[2];
878 } else {
879 microphone.orientation.x = 0.0f;
880 microphone.orientation.y = 0.0f;
881 microphone.orientation.z = 0.0f;
882 }
883
884 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
885 if (strcmp(attr[curIdx++], "geometric_location")) {
886 ALOGE("%s: geometric_location not found", __func__);
887 goto done;
888 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530889 char *context = NULL;
890 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530891 float geometric_location[3];
892 uint32_t idx = 0;
893 while (token) {
894 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800895 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530896 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530897 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530898 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530899 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530900 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530901 ALOGE("%s: geometric_location invalid", __func__);
902 goto done;
903 }
904 microphone.geometric_location.x = geometric_location[0];
905 microphone.geometric_location.y = geometric_location[1];
906 microphone.geometric_location.z = geometric_location[2];
907 } else {
908 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
909 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
910 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
911 }
912
913 platform_set_microphone_characteristic(my_data.platform, microphone);
914done:
915 return;
916}
917
918static void process_snd_dev(const XML_Char **attr)
919{
920 uint32_t curIdx = 0;
921 in_snd_device = SND_DEVICE_NONE;
922
923 if (strcmp(attr[curIdx++], "in_snd_device")) {
924 ALOGE("%s: snd_device not found", __func__);
925 return;
926 }
927 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
928 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
929 in_snd_device >= SND_DEVICE_IN_END) {
930 ALOGE("%s: Sound device not valid", __func__);
931 in_snd_device = SND_DEVICE_NONE;
932 }
933
934 return;
935}
936
937static void process_mic_info(const XML_Char **attr)
938{
939 uint32_t curIdx = 0;
940 struct mic_info microphone;
941
942 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
943 sizeof(microphone.channel_mapping));
944
945 if (strcmp(attr[curIdx++], "mic_device_id")) {
946 ALOGE("%s: mic_device_id not found", __func__);
947 goto on_error;
948 }
949 strlcpy(microphone.device_id,
950 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
951
952 if (strcmp(attr[curIdx++], "channel_mapping")) {
953 ALOGE("%s: channel_mapping not found", __func__);
954 goto on_error;
955 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530956 char *context = NULL;
957 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530958 uint32_t idx = 0;
959 while (token) {
960 if (!find_enum_by_string(mic_channel_mapping, token,
961 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
962 &microphone.channel_mapping[idx++])) {
963 ALOGE("%s: channel_mapping %s in %s not found!",
964 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
965 goto on_error;
966 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530967 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530968 }
969 microphone.channel_count = idx;
970
971 platform_set_microphone_map(my_data.platform, in_snd_device,
972 &microphone);
973 return;
974on_error:
975 in_snd_device = SND_DEVICE_NONE;
976 return;
977}
978
979
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530980/* process acdb meta info key value */
981static void process_acdb_metainfo_key(const XML_Char **attr)
982{
983 if (strcmp(attr[0], "name") != 0) {
984 ALOGE("%s: 'name' not found", __func__);
985 goto done;
986 }
987
988 if (strcmp(attr[2], "value") != 0) {
989 ALOGE("%s: 'value' not found", __func__);
990 goto done;
991 }
992
993 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700994 switch(my_data.caller) {
995 case ACDB_EXTN:
996 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
997 ALOGE("%s: key %d was not set!", __func__, key);
998 goto done;
999 }
1000 break;
1001 case PLATFORM:
1002 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1003 ALOGE("%s: key %d was not set!", __func__, key);
1004 goto done;
1005 }
1006 break;
1007 default:
1008 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301009 }
1010
1011done:
1012 return;
1013}
1014
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301015static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1016{
1017 uint32_t attr_idx = 0;
1018 int32_t in_ch_idx = -1;
1019 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1020
1021 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1022 &mtmx_in_params_info);
1023 if (mtmx_in_params == NULL) {
1024 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1025 return;
1026 }
1027
1028 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1029 ALOGE("%s: 'in_channel_index' not found", __func__);
1030 return;
1031 }
1032
1033 in_ch_idx = atoi((char *)attr[attr_idx++]);
1034 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1035 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1036 return;
1037 }
1038
1039 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1040 ALOGE("%s: 'channel_count' not found", __func__);
1041 return;
1042 }
1043 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1044
1045 if (strcmp(attr[attr_idx++], "device") != 0) {
1046 ALOGE("%s: 'device' not found", __func__);
1047 return;
1048 }
1049 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1050 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1051
1052 if (strcmp(attr[attr_idx++], "interface") != 0) {
1053 ALOGE("%s: 'interface' not found", __func__);
1054 return;
1055 }
1056 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1057 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1058
1059 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1060 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1061 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1062 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1063 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1064 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1065 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1066 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1067
1068 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1069}
1070
1071static void process_custom_mtmx_in_params(const XML_Char **attr)
1072{
1073 int attr_idx = 0;
1074
1075 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1076 ALOGE("%s: 'usecase' not found", __func__);
1077 return;
1078 }
1079 mtmx_in_params_info.usecase_id = platform_get_usecase_index((char *)attr[attr_idx++]);
1080
1081 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1082 ALOGE("%s: 'out_channel_count' not found", __func__);
1083 return;
1084 }
1085 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1086
1087 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1088
1089}
1090
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301091static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1092{
1093 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
1094 uint32_t ip_channels = 0, op_channels = 0;
1095 char *context = NULL, *ch_coeff_value = NULL;
1096 struct audio_custom_mtmx_params *mtmx_params = NULL;
1097
1098 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1099 ALOGE("%s: 'out_channel_index' not found", __func__);
1100 return;
1101 }
1102 out_ch_idx = atoi((char *)attr[attr_idx++]);
1103
1104 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1105 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1106 return;
1107 }
1108
1109 if (strcmp(attr[attr_idx++], "values") != 0) {
1110 ALOGE("%s: 'values' not found", __func__);
1111 return;
1112 }
1113 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
1114 &mtmx_params_info);
1115 if (mtmx_params == NULL) {
1116 ALOGE("%s: mtmx params with given param info, not found", __func__);
1117 return;
1118 }
1119 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1120 ip_channels = mtmx_params->info.ip_channels;
1121 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301122 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301123 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1124 = atoi(ch_coeff_value);
1125 ch_coeff_value = strtok_r(NULL, " ", &context);
1126 }
1127 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1128 ch_coeff_value != NULL)
1129 ALOGE("%s: invalid/malformed coefficient values", __func__);
1130}
1131
1132static void process_custom_mtmx_params(const XML_Char **attr)
1133{
1134 int attr_idx = 0;
1135
1136 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1137 ALOGE("%s: 'param_id' not found", __func__);
1138 return;
1139 }
1140 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1141
1142 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1143 ALOGE("%s: 'in_channel_count' not found", __func__);
1144 return;
1145 }
1146 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1147
1148 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1149 ALOGE("%s: 'out_channel_count' not found", __func__);
1150 return;
1151 }
1152 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1153
1154 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1155 ALOGE("%s: 'usecase' not found", __func__);
1156 return;
1157 }
1158 mtmx_params_info.usecase_id = platform_get_usecase_index((char *)attr[attr_idx++]);
1159
1160 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1161 ALOGE("%s: 'snd_device' not found", __func__);
1162 return;
1163 }
1164 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301165
1166 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_name") == 0)) {
1167 strlcpy(mtmx_params_info.fe_name, (char *)attr[attr_idx++],
1168 sizeof(mtmx_params_info.fe_name));
1169 } else {
1170 ALOGD("%s: 'fe_name' not found", __func__);
1171 mtmx_params_info.fe_name[0] = '\0';
1172 }
1173
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301174 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1175
1176}
1177
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001178static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001179 const XML_Char **attr)
1180{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001181 if (my_data.caller == ACDB_EXTN) {
1182 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1183 section = ACDB_METAINFO_KEY;
1184 } else if (strcmp(tag_name, "param") == 0) {
1185 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1186 ALOGE("param tag only supported with CONFIG_PARAMS section");
1187 return;
1188 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001189
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001190 section_process_fn fn = section_table[section];
1191 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001192 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001193 } else if(my_data.caller == PLATFORM) {
1194 if (strcmp(tag_name, "bit_width_configs") == 0) {
1195 section = BITWIDTH;
1196 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1197 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001198 } else if (strcmp(tag_name, "module_ids") == 0) {
1199 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001200 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1201 section = PCM_ID;
1202 } else if (strcmp(tag_name, "backend_names") == 0) {
1203 section = BACKEND_NAME;
1204 } else if (strcmp(tag_name, "config_params") == 0) {
1205 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001206 } else if (strcmp(tag_name, "operator_specific") == 0) {
1207 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001208 } else if (strcmp(tag_name, "interface_names") == 0) {
1209 section = INTERFACE_NAME;
1210 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1211 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001212 } else if (strcmp(tag_name, "app_types") == 0) {
1213 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001214 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1215 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301216 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1217 section = MICROPHONE_CHARACTERISTIC;
1218 } else if (strcmp(tag_name, "snd_devices") == 0) {
1219 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001220 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001221 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1222 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001223 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001224 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1225 return;
1226 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001227
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001228 /* call into process function for the current section */
1229 section_process_fn fn = section_table[section];
1230 fn(attr);
1231 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1232 if (section != GAIN_LEVEL_MAPPING) {
1233 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1234 return;
1235 }
1236
1237 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1238 fn(attr);
1239 } else if (strcmp(tag_name, "usecase") == 0) {
1240 if (section != PCM_ID) {
1241 ALOGE("usecase tag only supported with PCM_ID section");
1242 return;
1243 }
1244
1245 section_process_fn fn = section_table[PCM_ID];
1246 fn(attr);
1247 } else if (strcmp(tag_name, "param") == 0) {
1248 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1249 ALOGE("param tag only supported with CONFIG_PARAMS section");
1250 return;
1251 }
1252
1253 section_process_fn fn = section_table[section];
1254 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301255 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001256 if (section != MODULE) {
1257 ALOGE("aec tag only supported with MODULE section");
1258 return;
1259 }
1260 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301261 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001262 if (section != MODULE) {
1263 ALOGE("ns tag only supported with MODULE section");
1264 return;
1265 }
1266 section = NS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001267 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1268 if (section != GAIN_LEVEL_MAPPING) {
1269 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1270 return;
1271 }
1272
1273 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1274 fn(attr);
1275 } else if (!strcmp(tag_name, "app")) {
1276 if (section != APP_TYPE) {
1277 ALOGE("app tag only valid in section APP_TYPE");
1278 return;
1279 }
1280
1281 section_process_fn fn = section_table[APP_TYPE];
1282 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301283 } else if (strcmp(tag_name, "microphone") == 0) {
1284 if (section != MICROPHONE_CHARACTERISTIC) {
1285 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1286 return;
1287 }
1288 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1289 fn(attr);
1290 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1291 if (section != SND_DEVICES) {
1292 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1293 return;
1294 }
1295 section = INPUT_SND_DEVICE;
1296 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1297 if (section != INPUT_SND_DEVICE) {
1298 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1299 return;
1300 }
1301 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1302 } else if (strcmp(tag_name, "snd_dev") == 0) {
1303 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1304 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1305 return;
1306 }
1307 section_process_fn fn = section_table[SND_DEV];
1308 fn(attr);
1309 } else if (strcmp(tag_name, "mic_info") == 0) {
1310 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1311 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1312 return;
1313 }
1314 if (in_snd_device == SND_DEVICE_NONE) {
1315 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1316 return;
1317 }
1318 section_process_fn fn = section_table[MIC_INFO];
1319 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301320 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1321 if (section != ROOT) {
1322 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1323 return;
1324 }
1325 section = CUSTOM_MTMX_PARAMS;
1326 section_process_fn fn = section_table[section];
1327 fn(attr);
1328 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1329 if (section != CUSTOM_MTMX_PARAMS) {
1330 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1331 return;
1332 }
1333 section = CUSTOM_MTMX_PARAM_COEFFS;
1334 section_process_fn fn = section_table[section];
1335 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001336 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1337 section = EXTERNAL_DEVICE_SPECIFIC;
1338 } else if (strcmp(tag_name, "ext_device") == 0) {
1339 section_process_fn fn = section_table[section];
1340 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301341 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1342 if (section != ROOT) {
1343 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1344 return;
1345 }
1346 section = CUSTOM_MTMX_IN_PARAMS;
1347 section_process_fn fn = section_table[section];
1348 fn(attr);
1349 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1350 if (section != CUSTOM_MTMX_IN_PARAMS) {
1351 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1352 return;
1353 }
1354 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
1355 section_process_fn fn = section_table[section];
1356 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301357 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001358 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001359 if(strcmp(tag_name, "config_params") == 0) {
1360 section = CONFIG_PARAMS;
1361 } else if (strcmp(tag_name, "param") == 0) {
1362 if (section != CONFIG_PARAMS) {
1363 ALOGE("param tag only supported with CONFIG_PARAMS section");
1364 return;
1365 }
1366
1367 section_process_fn fn = section_table[section];
1368 fn(attr);
1369 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001370 }
Ben Romberger55886882014-01-10 13:49:02 -08001371 return;
1372}
1373
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001374static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001375{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001376 if (strcmp(tag_name, "bit_width_configs") == 0) {
1377 section = ROOT;
1378 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001379 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001380 } else if (strcmp(tag_name, "module_ids") == 0) {
1381 section = ROOT;
1382 } else if (strcmp(tag_name, "aec") == 0) {
1383 section = MODULE;
1384 } else if (strcmp(tag_name, "ns") == 0) {
1385 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001386 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1387 section = ROOT;
1388 } else if (strcmp(tag_name, "backend_names") == 0) {
1389 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001390 } else if (strcmp(tag_name, "config_params") == 0) {
1391 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001392 } else if (strcmp(tag_name, "operator_specific") == 0) {
1393 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001394 } else if (strcmp(tag_name, "interface_names") == 0) {
1395 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001396 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1397 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001398 } else if (strcmp(tag_name, "app_types") == 0) {
1399 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301400 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1401 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301402 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1403 section = ROOT;
1404 } else if (strcmp(tag_name, "snd_devices") == 0) {
1405 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001406 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1407 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301408 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1409 section = SND_DEVICES;
1410 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1411 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301412 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1413 section = ROOT;
1414 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1415 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301416 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1417 section = ROOT;
1418 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1419 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001420 }
Ben Romberger55886882014-01-10 13:49:02 -08001421}
1422
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001423int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001424{
1425 XML_Parser parser;
1426 FILE *file;
1427 int ret = 0;
1428 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001429 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001430 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001431
Aalique Grahame22e49102018-12-18 14:23:57 -08001432 if (filename == NULL)
1433 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1434 MIXER_PATH_MAX_LENGTH);
1435 else
1436 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1437
1438 ALOGV("%s: platform info file name is %s", __func__,
1439 platform_info_file_name);
1440
1441 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001442 section = ROOT;
1443
Ben Romberger55886882014-01-10 13:49:02 -08001444 if (!file) {
1445 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001446 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001447 ret = -ENODEV;
1448 goto done;
1449 }
1450
1451 parser = XML_ParserCreate(NULL);
1452 if (!parser) {
1453 ALOGE("%s: Failed to create XML parser!", __func__);
1454 ret = -ENODEV;
1455 goto err_close_file;
1456 }
1457
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001458 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001459 my_data.platform = platform;
1460 my_data.kvpairs = str_parms_create();
1461
Ben Romberger55886882014-01-10 13:49:02 -08001462 XML_SetElementHandler(parser, start_tag, end_tag);
1463
1464 while (1) {
1465 buf = XML_GetBuffer(parser, BUF_SIZE);
1466 if (buf == NULL) {
1467 ALOGE("%s: XML_GetBuffer failed", __func__);
1468 ret = -ENOMEM;
1469 goto err_free_parser;
1470 }
1471
1472 bytes_read = fread(buf, 1, BUF_SIZE, file);
1473 if (bytes_read < 0) {
1474 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1475 ret = bytes_read;
1476 goto err_free_parser;
1477 }
1478
1479 if (XML_ParseBuffer(parser, bytes_read,
1480 bytes_read == 0) == XML_STATUS_ERROR) {
1481 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001482 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001483 ret = -EINVAL;
1484 goto err_free_parser;
1485 }
1486
1487 if (bytes_read == 0)
1488 break;
1489 }
1490
Ben Romberger55886882014-01-10 13:49:02 -08001491err_free_parser:
1492 XML_ParserFree(parser);
1493err_close_file:
1494 fclose(file);
1495done:
1496 return ret;
1497}