blob: d73792c549e2abe5fc8953e2229c8c68b9b2140e [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{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301073 int attr_idx = 0, i = 0;
1074 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301075
1076 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1077 ALOGE("%s: 'usecase' not found", __func__);
1078 return;
1079 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301080 /* Check if multi usecases are supported for this custom mtrx params */
1081 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1082 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1083 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1084 value = strtok_r(NULL, ",", &context);
1085 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301086
1087 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1088 ALOGE("%s: 'out_channel_count' not found", __func__);
1089 return;
1090 }
1091 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1092
1093 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1094
1095}
1096
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301097static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1098{
1099 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301100 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301101 char *context = NULL, *ch_coeff_value = NULL;
1102 struct audio_custom_mtmx_params *mtmx_params = NULL;
1103
1104 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1105 ALOGE("%s: 'out_channel_index' not found", __func__);
1106 return;
1107 }
1108 out_ch_idx = atoi((char *)attr[attr_idx++]);
1109
1110 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1111 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1112 return;
1113 }
1114
1115 if (strcmp(attr[attr_idx++], "values") != 0) {
1116 ALOGE("%s: 'values' not found", __func__);
1117 return;
1118 }
1119 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301120 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301121 if (mtmx_params == NULL) {
1122 ALOGE("%s: mtmx params with given param info, not found", __func__);
1123 return;
1124 }
1125 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1126 ip_channels = mtmx_params->info.ip_channels;
1127 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301128 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301129 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1130 = atoi(ch_coeff_value);
1131 ch_coeff_value = strtok_r(NULL, " ", &context);
1132 }
1133 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1134 ch_coeff_value != NULL)
1135 ALOGE("%s: invalid/malformed coefficient values", __func__);
1136}
1137
1138static void process_custom_mtmx_params(const XML_Char **attr)
1139{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301140 int attr_idx = 0, i = 0;
1141 char *context = NULL, *value = NULL;
1142
1143 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301144
1145 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1146 ALOGE("%s: 'param_id' not found", __func__);
1147 return;
1148 }
1149 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1150
1151 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1152 ALOGE("%s: 'in_channel_count' not found", __func__);
1153 return;
1154 }
1155 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1156
1157 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1158 ALOGE("%s: 'out_channel_count' not found", __func__);
1159 return;
1160 }
1161 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1162
1163 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1164 ALOGE("%s: 'usecase' not found", __func__);
1165 return;
1166 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301167
1168 /* check if multi usecases are supported for this custom mtrx params */
1169 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1170 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1171 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1172 value = strtok_r(NULL, ",", &context);
1173 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301174
1175 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1176 ALOGE("%s: 'snd_device' not found", __func__);
1177 return;
1178 }
1179 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301180
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301181 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1182 i = 0;
1183 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1184 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1185 mtmx_params_info.fe_id[i++] = atoi(value);
1186 value = strtok_r(NULL, ",", &context);
1187 }
1188
1189 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301190 }
1191
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301192 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1193
1194}
1195
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001196static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001197 const XML_Char **attr)
1198{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001199 if (my_data.caller == ACDB_EXTN) {
1200 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1201 section = ACDB_METAINFO_KEY;
1202 } else if (strcmp(tag_name, "param") == 0) {
1203 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1204 ALOGE("param tag only supported with CONFIG_PARAMS section");
1205 return;
1206 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001207
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001208 section_process_fn fn = section_table[section];
1209 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001210 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001211 } else if(my_data.caller == PLATFORM) {
1212 if (strcmp(tag_name, "bit_width_configs") == 0) {
1213 section = BITWIDTH;
1214 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1215 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001216 } else if (strcmp(tag_name, "module_ids") == 0) {
1217 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001218 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1219 section = PCM_ID;
1220 } else if (strcmp(tag_name, "backend_names") == 0) {
1221 section = BACKEND_NAME;
1222 } else if (strcmp(tag_name, "config_params") == 0) {
1223 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001224 } else if (strcmp(tag_name, "operator_specific") == 0) {
1225 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001226 } else if (strcmp(tag_name, "interface_names") == 0) {
1227 section = INTERFACE_NAME;
1228 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1229 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001230 } else if (strcmp(tag_name, "app_types") == 0) {
1231 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001232 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1233 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301234 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1235 section = MICROPHONE_CHARACTERISTIC;
1236 } else if (strcmp(tag_name, "snd_devices") == 0) {
1237 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001238 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001239 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1240 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001241 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001242 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1243 return;
1244 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001245
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001246 /* call into process function for the current section */
1247 section_process_fn fn = section_table[section];
1248 fn(attr);
1249 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1250 if (section != GAIN_LEVEL_MAPPING) {
1251 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1252 return;
1253 }
1254
1255 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1256 fn(attr);
1257 } else if (strcmp(tag_name, "usecase") == 0) {
1258 if (section != PCM_ID) {
1259 ALOGE("usecase tag only supported with PCM_ID section");
1260 return;
1261 }
1262
1263 section_process_fn fn = section_table[PCM_ID];
1264 fn(attr);
1265 } else if (strcmp(tag_name, "param") == 0) {
1266 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1267 ALOGE("param tag only supported with CONFIG_PARAMS section");
1268 return;
1269 }
1270
1271 section_process_fn fn = section_table[section];
1272 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301273 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001274 if (section != MODULE) {
1275 ALOGE("aec tag only supported with MODULE section");
1276 return;
1277 }
1278 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301279 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001280 if (section != MODULE) {
1281 ALOGE("ns tag only supported with MODULE section");
1282 return;
1283 }
1284 section = NS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001285 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1286 if (section != GAIN_LEVEL_MAPPING) {
1287 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1288 return;
1289 }
1290
1291 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1292 fn(attr);
1293 } else if (!strcmp(tag_name, "app")) {
1294 if (section != APP_TYPE) {
1295 ALOGE("app tag only valid in section APP_TYPE");
1296 return;
1297 }
1298
1299 section_process_fn fn = section_table[APP_TYPE];
1300 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301301 } else if (strcmp(tag_name, "microphone") == 0) {
1302 if (section != MICROPHONE_CHARACTERISTIC) {
1303 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1304 return;
1305 }
1306 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1307 fn(attr);
1308 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1309 if (section != SND_DEVICES) {
1310 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1311 return;
1312 }
1313 section = INPUT_SND_DEVICE;
1314 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1315 if (section != INPUT_SND_DEVICE) {
1316 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1317 return;
1318 }
1319 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1320 } else if (strcmp(tag_name, "snd_dev") == 0) {
1321 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1322 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1323 return;
1324 }
1325 section_process_fn fn = section_table[SND_DEV];
1326 fn(attr);
1327 } else if (strcmp(tag_name, "mic_info") == 0) {
1328 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1329 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1330 return;
1331 }
1332 if (in_snd_device == SND_DEVICE_NONE) {
1333 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1334 return;
1335 }
1336 section_process_fn fn = section_table[MIC_INFO];
1337 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301338 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1339 if (section != ROOT) {
1340 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1341 return;
1342 }
1343 section = CUSTOM_MTMX_PARAMS;
1344 section_process_fn fn = section_table[section];
1345 fn(attr);
1346 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1347 if (section != CUSTOM_MTMX_PARAMS) {
1348 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1349 return;
1350 }
1351 section = CUSTOM_MTMX_PARAM_COEFFS;
1352 section_process_fn fn = section_table[section];
1353 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001354 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1355 section = EXTERNAL_DEVICE_SPECIFIC;
1356 } else if (strcmp(tag_name, "ext_device") == 0) {
1357 section_process_fn fn = section_table[section];
1358 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301359 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1360 if (section != ROOT) {
1361 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1362 return;
1363 }
1364 section = CUSTOM_MTMX_IN_PARAMS;
1365 section_process_fn fn = section_table[section];
1366 fn(attr);
1367 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1368 if (section != CUSTOM_MTMX_IN_PARAMS) {
1369 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1370 return;
1371 }
1372 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
1373 section_process_fn fn = section_table[section];
1374 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301375 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001376 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001377 if(strcmp(tag_name, "config_params") == 0) {
1378 section = CONFIG_PARAMS;
1379 } else if (strcmp(tag_name, "param") == 0) {
1380 if (section != CONFIG_PARAMS) {
1381 ALOGE("param tag only supported with CONFIG_PARAMS section");
1382 return;
1383 }
1384
1385 section_process_fn fn = section_table[section];
1386 fn(attr);
1387 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001388 }
Ben Romberger55886882014-01-10 13:49:02 -08001389 return;
1390}
1391
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001392static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001393{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001394 if (strcmp(tag_name, "bit_width_configs") == 0) {
1395 section = ROOT;
1396 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001397 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001398 } else if (strcmp(tag_name, "module_ids") == 0) {
1399 section = ROOT;
1400 } else if (strcmp(tag_name, "aec") == 0) {
1401 section = MODULE;
1402 } else if (strcmp(tag_name, "ns") == 0) {
1403 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001404 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1405 section = ROOT;
1406 } else if (strcmp(tag_name, "backend_names") == 0) {
1407 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001408 } else if (strcmp(tag_name, "config_params") == 0) {
1409 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001410 } else if (strcmp(tag_name, "operator_specific") == 0) {
1411 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001412 } else if (strcmp(tag_name, "interface_names") == 0) {
1413 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001414 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1415 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001416 } else if (strcmp(tag_name, "app_types") == 0) {
1417 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301418 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1419 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301420 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1421 section = ROOT;
1422 } else if (strcmp(tag_name, "snd_devices") == 0) {
1423 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001424 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1425 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301426 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1427 section = SND_DEVICES;
1428 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1429 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301430 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1431 section = ROOT;
1432 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1433 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301434 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1435 section = ROOT;
1436 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1437 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001438 }
Ben Romberger55886882014-01-10 13:49:02 -08001439}
1440
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001441int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001442{
1443 XML_Parser parser;
1444 FILE *file;
1445 int ret = 0;
1446 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001447 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001448 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001449
Aalique Grahame22e49102018-12-18 14:23:57 -08001450 if (filename == NULL)
1451 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1452 MIXER_PATH_MAX_LENGTH);
1453 else
1454 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1455
1456 ALOGV("%s: platform info file name is %s", __func__,
1457 platform_info_file_name);
1458
1459 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001460 section = ROOT;
1461
Ben Romberger55886882014-01-10 13:49:02 -08001462 if (!file) {
1463 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001464 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001465 ret = -ENODEV;
1466 goto done;
1467 }
1468
1469 parser = XML_ParserCreate(NULL);
1470 if (!parser) {
1471 ALOGE("%s: Failed to create XML parser!", __func__);
1472 ret = -ENODEV;
1473 goto err_close_file;
1474 }
1475
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001476 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001477 my_data.platform = platform;
1478 my_data.kvpairs = str_parms_create();
1479
Ben Romberger55886882014-01-10 13:49:02 -08001480 XML_SetElementHandler(parser, start_tag, end_tag);
1481
1482 while (1) {
1483 buf = XML_GetBuffer(parser, BUF_SIZE);
1484 if (buf == NULL) {
1485 ALOGE("%s: XML_GetBuffer failed", __func__);
1486 ret = -ENOMEM;
1487 goto err_free_parser;
1488 }
1489
1490 bytes_read = fread(buf, 1, BUF_SIZE, file);
1491 if (bytes_read < 0) {
1492 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1493 ret = bytes_read;
1494 goto err_free_parser;
1495 }
1496
1497 if (XML_ParseBuffer(parser, bytes_read,
1498 bytes_read == 0) == XML_STATUS_ERROR) {
1499 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001500 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001501 ret = -EINVAL;
1502 goto err_free_parser;
1503 }
1504
1505 if (bytes_read == 0)
1506 break;
1507 }
1508
Ben Romberger55886882014-01-10 13:49:02 -08001509err_free_parser:
1510 XML_ParserFree(parser);
1511err_close_file:
1512 fclose(file);
1513done:
1514 return ret;
1515}