blob: e99a4182694257e75973157ef4a8b23d930efb21 [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>
Michael Bestas3ddd20f2019-10-19 12:48:27 +030043#include <pthread.h>
Ben Romberger55886882014-01-10 13:49:02 -080044
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053045#ifdef DYNAMIC_LOG_ENABLED
46#include <log_xml_parser.h>
47#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
48#include <log_utils.h>
49#endif
50
Ben Romberger55886882014-01-10 13:49:02 -080051#define BUF_SIZE 1024
52
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070053typedef enum {
54 ROOT,
55 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070056 MODULE,
57 AEC,
58 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070059 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070060 PCM_ID,
61 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080062 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070063 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080064 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070065 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080066 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053067 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053068 MICROPHONE_CHARACTERISTIC,
69 SND_DEVICES,
70 INPUT_SND_DEVICE,
71 INPUT_SND_DEVICE_TO_MIC_MAPPING,
72 SND_DEV,
73 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053074 CUSTOM_MTMX_PARAMS,
75 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070076 EXTERNAL_DEVICE_SPECIFIC,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +053077 CUSTOM_MTMX_IN_PARAMS,
78 CUSTOM_MTMX_PARAM_IN_CH_INFO,
Ethan Chen97564d42014-09-05 13:01:26 -070079 DEVICE_NAME,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070080} section_t;
81
82typedef void (* section_process_fn)(const XML_Char **attr);
83
84static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070085static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
86static void process_effect_aec(const XML_Char **attr);
87static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070088static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070089static void process_pcm_id(const XML_Char **attr);
90static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080091static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070092static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070093static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080094static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070095static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080096static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053097static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053098static void process_microphone_characteristic(const XML_Char **attr);
99static void process_snd_dev(const XML_Char **attr);
100static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530101static void process_custom_mtmx_params(const XML_Char **attr);
102static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -0700103static void process_external_dev(const XML_Char **attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530104static void process_custom_mtmx_in_params(const XML_Char **attr);
105static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
Ethan Chen97564d42014-09-05 13:01:26 -0700106static void process_device_name(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700107
108static section_process_fn section_table[] = {
109 [ROOT] = process_root,
110 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700111 [AEC] = process_effect_aec,
112 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700113 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700114 [PCM_ID] = process_pcm_id,
115 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800116 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700117 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800118 [OPERATOR_SPECIFIC] = process_operator_specific,
119 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700120 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530121 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530122 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
123 [SND_DEV] = process_snd_dev,
124 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530125 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
126 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700127 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530128 [CUSTOM_MTMX_IN_PARAMS] = process_custom_mtmx_in_params,
129 [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
Ethan Chen97564d42014-09-05 13:01:26 -0700130 [DEVICE_NAME] = process_device_name,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700131};
132
133static section_t section;
134
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700135struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700136 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700137 void *platform;
138 struct str_parms *kvpairs;
139};
140
141static struct platform_info my_data;
Weiyin Jiang63f4d8c2019-09-06 16:59:32 +0800142static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700143
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530144
145struct audio_string_to_enum {
146 const char* name;
147 unsigned int value;
148};
149
150static snd_device_t in_snd_device;
151
152static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
153 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
154 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
155 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
157};
158
159static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
163 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
166};
167
168static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
172};
173
174static const struct audio_string_to_enum device_in_types[] = {
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
198 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
199 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
200 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
201 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
202};
203
204enum {
205 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
206 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
207 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
208 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
209 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
210 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
211 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
212 | ORIENTATION) | GEOMETRIC_LOCATION) */
213};
214
215static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
216 int32_t len, unsigned int *value)
217{
218 if (table == NULL) {
219 ALOGE("%s: table is NULL", __func__);
220 return false;
221 }
222
223 if (name == NULL) {
224 ALOGE("null key");
225 return false;
226 }
227
228 for (int i = 0; i < len; i++) {
229 if (!strcmp(table[i].name, name)) {
230 *value = table[i].value;
231 return true;
232 }
233 }
234 return false;
235}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530236
237static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530238static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530239
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700240/*
241 * <audio_platform_info>
242 * <acdb_ids>
243 * <device name="???" acdb_id="???"/>
244 * ...
245 * ...
246 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700247 * <module_ids>
248 * <device name="???" module_id="???"/>
249 * ...
250 * ...
251 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700252 * <backend_names>
253 * <device name="???" backend="???"/>
254 * ...
255 * ...
256 * </backend_names>
257 * <pcm_ids>
258 * <usecase name="???" type="in/out" id="???"/>
259 * ...
260 * ...
261 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800262 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530263 * <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 -0800264 * ...
265 * ...
266 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700267 * <config_params>
268 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800269 * <param key="operator_info" value="tmus;aa;bb;cc"/>
270 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700271 * ...
272 * ...
273 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800274 *
275 * <operator_specific>
276 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
277 * ...
278 * ...
279 * </operator_specific>
280 *
Ethan Chen97564d42014-09-05 13:01:26 -0700281 * <device_names>
282 * <device name="???" alias="???"/>
283 * ...
284 * ...
285 * </device_names>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700286 * </audio_platform_info>
287 */
288
289static void process_root(const XML_Char **attr __unused)
290{
291}
292
293/* mapping from usecase to pcm dev id */
294static void process_pcm_id(const XML_Char **attr)
295{
296 int index;
297
298 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700299 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700300 goto done;
301 }
302
303 index = platform_get_usecase_index((char *)attr[1]);
304 if (index < 0) {
305 ALOGE("%s: usecase %s not found!",
306 __func__, attr[1]);
307 goto done;
308 }
309
310 if (strcmp(attr[2], "type") != 0) {
311 ALOGE("%s: usecase type not mentioned", __func__);
312 goto done;
313 }
314
315 int type = -1;
316
317 if (!strcasecmp((char *)attr[3], "in")) {
318 type = 1;
319 } else if (!strcasecmp((char *)attr[3], "out")) {
320 type = 0;
321 } else {
322 ALOGE("%s: type must be IN or OUT", __func__);
323 goto done;
324 }
325
326 if (strcmp(attr[4], "id") != 0) {
327 ALOGE("%s: usecase id not mentioned", __func__);
328 goto done;
329 }
330
331 int id = atoi((char *)attr[5]);
332
333 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
334 ALOGE("%s: usecase %s type %d id %d was not set!",
335 __func__, attr[1], type, id);
336 goto done;
337 }
338
339done:
340 return;
341}
342
343/* backend to be used for a device */
344static void process_backend_name(const XML_Char **attr)
345{
346 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530347 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530348 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700349
350 if (strcmp(attr[0], "name") != 0) {
351 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
352 goto done;
353 }
354
355 index = platform_get_snd_device_index((char *)attr[1]);
356 if (index < 0) {
357 ALOGE("%s: Device %s not found, no ACDB ID set!",
358 __func__, attr[1]);
359 goto done;
360 }
361
362 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530363 if (strcmp(attr[2], "interface") == 0)
364 hw_interface = (char *)attr[3];
365 } else {
366 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700367 }
368
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530369 if (attr[4] != NULL) {
370 if (strcmp(attr[4], "interface") != 0) {
371 hw_interface = NULL;
372 } else {
373 hw_interface = (char *)attr[5];
374 }
375 }
376
Ashish Jaind150d4c2017-02-03 18:44:34 +0530377 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700378 ALOGE("%s: Device %s backend %s was not set!",
379 __func__, attr[1], attr[3]);
380 goto done;
381 }
382
383done:
384 return;
385}
386
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700387static void process_gain_db_to_level_map(const XML_Char **attr)
388{
389 struct amp_db_and_gain_table tbl_entry;
390
391 if ((strcmp(attr[0], "db") != 0) ||
392 (strcmp(attr[2], "level") != 0)) {
393 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
394 __func__, attr[0], attr[2]);
395 goto done;
396 }
397
398 tbl_entry.db = atof(attr[1]);
399 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
400 tbl_entry.level = atoi(attr[3]);
401
Aalique Grahame22e49102018-12-18 14:23:57 -0800402 //custome level should be > 0. Level 0 is fixed for default
403 CHECK(tbl_entry.level > 0);
404
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700405 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
406 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
407 platform_add_gain_level_mapping(&tbl_entry);
408
409done:
410 return;
411}
412
413
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700414static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800415{
Ben Romberger61764e32014-01-10 13:49:02 -0800416 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800417
Ben Romberger61764e32014-01-10 13:49:02 -0800418 if (strcmp(attr[0], "name") != 0) {
419 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800420 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800421 }
Ben Romberger55886882014-01-10 13:49:02 -0800422
Ben Romberger61764e32014-01-10 13:49:02 -0800423 index = platform_get_snd_device_index((char *)attr[1]);
424 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800425 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
426 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800427 goto done;
428 }
429
430 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800431 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
432 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800433 goto done;
434 }
435
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700436 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
437 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800438 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800439 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800440 }
Ben Romberger55886882014-01-10 13:49:02 -0800441
Ben Romberger55886882014-01-10 13:49:02 -0800442done:
443 return;
444}
445
Aalique Grahame22e49102018-12-18 14:23:57 -0800446static void process_operator_specific(const XML_Char **attr)
447{
448 snd_device_t snd_device = SND_DEVICE_NONE;
449
450 if (strcmp(attr[0], "name") != 0) {
451 ALOGE("%s: 'name' not found", __func__);
452 goto done;
453 }
454
455 snd_device = platform_get_snd_device_index((char *)attr[1]);
456 if (snd_device < 0) {
457 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
458 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
459 goto done;
460 }
461
462 if (strcmp(attr[2], "operator") != 0) {
463 ALOGE("%s: 'operator' not found", __func__);
464 goto done;
465 }
466
467 if (strcmp(attr[4], "mixer_path") != 0) {
468 ALOGE("%s: 'mixer_path' not found", __func__);
469 goto done;
470 }
471
472 if (strcmp(attr[6], "acdb_id") != 0) {
473 ALOGE("%s: 'acdb_id' not found", __func__);
474 goto done;
475 }
476
477 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
478
479done:
480 return;
481}
482
Carter Hsu32a62362018-10-15 15:01:42 -0700483static void process_external_dev(const XML_Char **attr)
484{
485 snd_device_t snd_device = SND_DEVICE_NONE;
486
487 if (strcmp(attr[0], "name") != 0) {
488 ALOGE("%s: 'name' not found", __func__);
489 goto done;
490 }
491
492 snd_device = platform_get_snd_device_index((char *)attr[1]);
493 if (snd_device < 0) {
494 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
495 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
496 goto done;
497 }
498
499 if (strcmp(attr[2], "usbid") != 0) {
500 ALOGE("%s: 'usbid' not found", __func__);
501 goto done;
502 }
503
504 if (strcmp(attr[4], "acdb_id") != 0) {
505 ALOGE("%s: 'acdb_id' not found", __func__);
506 goto done;
507 }
508
509 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
510
511done:
512 return;
513}
514
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700515static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
516{
517 int index;
518 struct audio_effect_config effect_config;
519
520 if (strcmp(attr[0], "name") != 0) {
521 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
522 goto done;
523 }
524
525 index = platform_get_snd_device_index((char *)attr[1]);
526 if (index < 0) {
527 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
528 __func__, attr[1]);
529 goto done;
530 }
531
532 if (strcmp(attr[2], "module_id") != 0) {
533 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
534 __func__, attr[2]);
535 goto done;
536 }
537
538 if (strcmp(attr[4], "instance_id") != 0) {
539 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
540 __func__, attr[4]);
541 goto done;
542 }
543
544 if (strcmp(attr[6], "param_id") != 0) {
545 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
546 __func__, attr[6]);
547 goto done;
548 }
549
550 if (strcmp(attr[8], "param_value") != 0) {
551 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
552 __func__, attr[8]);
553 goto done;
554 }
555
556 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
557 strtol((char *)attr[5], NULL, 0),
558 strtol((char *)attr[7], NULL, 0),
559 strtol((char *)attr[9], NULL, 0)};
560
561
562 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
563 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
564 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
565 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
566 strtol((char *)attr[9], NULL, 0));
567 goto done;
568 }
569
570done:
571 return;
572}
573
574static void process_effect_aec(const XML_Char **attr)
575{
576 process_audio_effect(attr, EFFECT_AEC);
577 return;
578}
579
580static void process_effect_ns(const XML_Char **attr)
581{
582 process_audio_effect(attr, EFFECT_NS);
583 return;
584}
585
Amit Shekhar5a39c912014-10-14 15:39:30 -0700586static void process_bit_width(const XML_Char **attr)
587{
588 int index;
589
590 if (strcmp(attr[0], "name") != 0) {
591 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
592 goto done;
593 }
594
595 index = platform_get_snd_device_index((char *)attr[1]);
596 if (index < 0) {
597 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
598 __func__, attr[1]);
599 goto done;
600 }
601
602 if (strcmp(attr[2], "bit_width") != 0) {
603 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
604 __func__, attr[1]);
605 goto done;
606 }
607
608 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
609 ALOGE("%s: Device %s, ACDB ID %d was not set!",
610 __func__, attr[1], atoi((char *)attr[3]));
611 goto done;
612 }
613
614done:
615 return;
616}
617
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800618static void process_interface_name(const XML_Char **attr)
619{
620 int ret;
621
622 if (strcmp(attr[0], "name") != 0) {
623 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
624
625 goto done;
626 }
627
628 if (strcmp(attr[2], "interface") != 0) {
629 ALOGE("%s: Device %s has no Audio Interface set!",
630 __func__, attr[1]);
631
632 goto done;
633 }
634
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530635 if (strcmp(attr[4], "codec_type") != 0) {
636 ALOGE("%s: Device %s has no codec type set!",
637 __func__, attr[1]);
638
639 goto done;
640 }
641
642 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
643 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800644 if (ret < 0) {
645 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800646 goto done;
647 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800648
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800649done:
650 return;
651}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530652
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700653static void process_config_params(const XML_Char **attr)
654{
655 if (strcmp(attr[0], "key") != 0) {
656 ALOGE("%s: 'key' not found", __func__);
657 goto done;
658 }
659
660 if (strcmp(attr[2], "value") != 0) {
661 ALOGE("%s: 'value' not found", __func__);
662 goto done;
663 }
664
665 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700666 if (my_data.caller == PLATFORM)
667 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700668done:
669 return;
670}
671
Aalique Grahame22e49102018-12-18 14:23:57 -0800672static void process_app_type(const XML_Char **attr)
673{
674 if (strcmp(attr[0], "uc_type")) {
675 ALOGE("%s: uc_type not found", __func__);
676 goto done;
677 }
678
679 if (strcmp(attr[2], "mode")) {
680 ALOGE("%s: mode not found", __func__);
681 goto done;
682 }
683
684 if (strcmp(attr[4], "bit_width")) {
685 ALOGE("%s: bit_width not found", __func__);
686 goto done;
687 }
688
689 if (strcmp(attr[6], "id")) {
690 ALOGE("%s: id not found", __func__);
691 goto done;
692 }
693
694 if (strcmp(attr[8], "max_rate")) {
695 ALOGE("%s: max rate not found", __func__);
696 goto done;
697 }
698
699 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
700 atoi(attr[9]));
701done:
702 return;
703}
704
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530705static void process_microphone_characteristic(const XML_Char **attr) {
706 struct audio_microphone_characteristic_t microphone;
707 uint32_t curIdx = 0;
708
709 if (strcmp(attr[curIdx++], "valid_mask")) {
710 ALOGE("%s: valid_mask not found", __func__);
711 goto done;
712 }
713 uint32_t valid_mask = atoi(attr[curIdx++]);
714
715 if (strcmp(attr[curIdx++], "device_id")) {
716 ALOGE("%s: device_id not found", __func__);
717 goto done;
718 }
719 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
720 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
721 goto done;
722 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530723 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530724
725 if (strcmp(attr[curIdx++], "type")) {
726 ALOGE("%s: device not found", __func__);
727 goto done;
728 }
729 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
730 ARRAY_SIZE(device_in_types), &microphone.device)) {
731 ALOGE("%s: type %s in %s not found!",
732 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
733 goto done;
734 }
735
736 if (strcmp(attr[curIdx++], "address")) {
737 ALOGE("%s: address not found", __func__);
738 goto done;
739 }
740 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
741 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
742 goto done;
743 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530744 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530745 if (strlen(microphone.address) == 0) {
746 // If the address is empty, populate the address according to device type.
747 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530748 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530749 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530750 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530751 }
752 }
753
754 if (strcmp(attr[curIdx++], "location")) {
755 ALOGE("%s: location not found", __func__);
756 goto done;
757 }
758 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
759 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
760 ALOGE("%s: location %s in %s not found!",
761 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
762 goto done;
763 }
764
765 if (strcmp(attr[curIdx++], "group")) {
766 ALOGE("%s: group not found", __func__);
767 goto done;
768 }
769 microphone.group = atoi(attr[curIdx++]);
770
771 if (strcmp(attr[curIdx++], "index_in_the_group")) {
772 ALOGE("%s: index_in_the_group not found", __func__);
773 goto done;
774 }
775 microphone.index_in_the_group = atoi(attr[curIdx++]);
776
777 if (strcmp(attr[curIdx++], "directionality")) {
778 ALOGE("%s: directionality not found", __func__);
779 goto done;
780 }
781 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
782 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
783 ALOGE("%s: directionality %s in %s not found!",
784 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
785 goto done;
786 }
787
788 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
789 ALOGE("%s: num_frequency_responses not found", __func__);
790 goto done;
791 }
792 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530793 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530794 ALOGE("%s: num_frequency_responses is too large", __func__);
795 goto done;
796 }
797 if (microphone.num_frequency_responses > 0) {
798 if (strcmp(attr[curIdx++], "frequencies")) {
799 ALOGE("%s: frequencies not found", __func__);
800 goto done;
801 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530802 char *context = NULL;
803 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530804 uint32_t num_frequencies = 0;
805 while (token) {
806 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800807 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530808 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530809 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530810 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530811 }
812
813 if (strcmp(attr[curIdx++], "responses")) {
814 ALOGE("%s: responses not found", __func__);
815 goto done;
816 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530817 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530818 uint32_t num_responses = 0;
819 while (token) {
820 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800821 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530822 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530823 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530824 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530825 }
826
827 if (num_frequencies != num_responses
828 || num_frequencies != microphone.num_frequency_responses) {
829 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
830 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
831 goto done;
832 }
833 }
834
835 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
836 if (strcmp(attr[curIdx++], "sensitivity")) {
837 ALOGE("%s: sensitivity not found", __func__);
838 goto done;
839 }
840 microphone.sensitivity = atof(attr[curIdx++]);
841 } else {
842 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
843 }
844
845 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
846 if (strcmp(attr[curIdx++], "max_spl")) {
847 ALOGE("%s: max_spl not found", __func__);
848 goto done;
849 }
850 microphone.max_spl = atof(attr[curIdx++]);
851 } else {
852 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
853 }
854
855 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
856 if (strcmp(attr[curIdx++], "min_spl")) {
857 ALOGE("%s: min_spl not found", __func__);
858 goto done;
859 }
860 microphone.min_spl = atof(attr[curIdx++]);
861 } else {
862 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
863 }
864
865 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
866 if (strcmp(attr[curIdx++], "orientation")) {
867 ALOGE("%s: orientation not found", __func__);
868 goto done;
869 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530870 char *context = NULL;
871 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530872 float orientation[3];
873 uint32_t idx = 0;
874 while (token) {
875 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800876 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530877 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530878 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530879 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530880 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530881 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530882 ALOGE("%s: orientation invalid", __func__);
883 goto done;
884 }
885 microphone.orientation.x = orientation[0];
886 microphone.orientation.y = orientation[1];
887 microphone.orientation.z = orientation[2];
888 } else {
889 microphone.orientation.x = 0.0f;
890 microphone.orientation.y = 0.0f;
891 microphone.orientation.z = 0.0f;
892 }
893
894 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
895 if (strcmp(attr[curIdx++], "geometric_location")) {
896 ALOGE("%s: geometric_location not found", __func__);
897 goto done;
898 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530899 char *context = NULL;
900 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530901 float geometric_location[3];
902 uint32_t idx = 0;
903 while (token) {
904 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800905 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530906 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530907 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530908 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530909 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530910 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530911 ALOGE("%s: geometric_location invalid", __func__);
912 goto done;
913 }
914 microphone.geometric_location.x = geometric_location[0];
915 microphone.geometric_location.y = geometric_location[1];
916 microphone.geometric_location.z = geometric_location[2];
917 } else {
918 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
919 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
920 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
921 }
922
923 platform_set_microphone_characteristic(my_data.platform, microphone);
924done:
925 return;
926}
927
928static void process_snd_dev(const XML_Char **attr)
929{
930 uint32_t curIdx = 0;
931 in_snd_device = SND_DEVICE_NONE;
932
933 if (strcmp(attr[curIdx++], "in_snd_device")) {
934 ALOGE("%s: snd_device not found", __func__);
935 return;
936 }
937 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
938 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
939 in_snd_device >= SND_DEVICE_IN_END) {
940 ALOGE("%s: Sound device not valid", __func__);
941 in_snd_device = SND_DEVICE_NONE;
942 }
943
944 return;
945}
946
947static void process_mic_info(const XML_Char **attr)
948{
949 uint32_t curIdx = 0;
950 struct mic_info microphone;
951
952 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
953 sizeof(microphone.channel_mapping));
954
955 if (strcmp(attr[curIdx++], "mic_device_id")) {
956 ALOGE("%s: mic_device_id not found", __func__);
957 goto on_error;
958 }
959 strlcpy(microphone.device_id,
960 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
961
962 if (strcmp(attr[curIdx++], "channel_mapping")) {
963 ALOGE("%s: channel_mapping not found", __func__);
964 goto on_error;
965 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530966 char *context = NULL;
967 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530968 uint32_t idx = 0;
969 while (token) {
970 if (!find_enum_by_string(mic_channel_mapping, token,
971 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
972 &microphone.channel_mapping[idx++])) {
973 ALOGE("%s: channel_mapping %s in %s not found!",
974 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
975 goto on_error;
976 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530977 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530978 }
979 microphone.channel_count = idx;
980
981 platform_set_microphone_map(my_data.platform, in_snd_device,
982 &microphone);
983 return;
984on_error:
985 in_snd_device = SND_DEVICE_NONE;
986 return;
987}
988
989
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530990/* process acdb meta info key value */
991static void process_acdb_metainfo_key(const XML_Char **attr)
992{
993 if (strcmp(attr[0], "name") != 0) {
994 ALOGE("%s: 'name' not found", __func__);
995 goto done;
996 }
997
998 if (strcmp(attr[2], "value") != 0) {
999 ALOGE("%s: 'value' not found", __func__);
1000 goto done;
1001 }
1002
1003 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001004 switch(my_data.caller) {
1005 case ACDB_EXTN:
1006 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1007 ALOGE("%s: key %d was not set!", __func__, key);
1008 goto done;
1009 }
1010 break;
1011 case PLATFORM:
1012 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1013 ALOGE("%s: key %d was not set!", __func__, key);
1014 goto done;
1015 }
1016 break;
1017 default:
1018 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301019 }
1020
1021done:
1022 return;
1023}
1024
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301025static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1026{
1027 uint32_t attr_idx = 0;
1028 int32_t in_ch_idx = -1;
1029 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1030
1031 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1032 &mtmx_in_params_info);
1033 if (mtmx_in_params == NULL) {
1034 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1035 return;
1036 }
1037
1038 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1039 ALOGE("%s: 'in_channel_index' not found", __func__);
1040 return;
1041 }
1042
1043 in_ch_idx = atoi((char *)attr[attr_idx++]);
1044 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1045 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1046 return;
1047 }
1048
1049 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1050 ALOGE("%s: 'channel_count' not found", __func__);
1051 return;
1052 }
1053 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1054
1055 if (strcmp(attr[attr_idx++], "device") != 0) {
1056 ALOGE("%s: 'device' not found", __func__);
1057 return;
1058 }
1059 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1060 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1061
1062 if (strcmp(attr[attr_idx++], "interface") != 0) {
1063 ALOGE("%s: 'interface' not found", __func__);
1064 return;
1065 }
1066 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1067 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1068
1069 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1070 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1071 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1072 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1073 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1074 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1075 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1076 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1077
1078 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1079}
1080
1081static void process_custom_mtmx_in_params(const XML_Char **attr)
1082{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301083 int attr_idx = 0, i = 0;
1084 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301085
1086 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1087 ALOGE("%s: 'usecase' not found", __func__);
1088 return;
1089 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301090 /* Check if multi usecases are supported for this custom mtrx params */
1091 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1092 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1093 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1094 value = strtok_r(NULL, ",", &context);
1095 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301096
1097 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1098 ALOGE("%s: 'out_channel_count' not found", __func__);
1099 return;
1100 }
1101 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1102
1103 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1104
1105}
1106
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301107static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1108{
1109 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301110 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301111 char *context = NULL, *ch_coeff_value = NULL;
1112 struct audio_custom_mtmx_params *mtmx_params = NULL;
1113
1114 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1115 ALOGE("%s: 'out_channel_index' not found", __func__);
1116 return;
1117 }
1118 out_ch_idx = atoi((char *)attr[attr_idx++]);
1119
1120 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1121 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1122 return;
1123 }
1124
1125 if (strcmp(attr[attr_idx++], "values") != 0) {
1126 ALOGE("%s: 'values' not found", __func__);
1127 return;
1128 }
1129 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301130 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301131 if (mtmx_params == NULL) {
1132 ALOGE("%s: mtmx params with given param info, not found", __func__);
1133 return;
1134 }
1135 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1136 ip_channels = mtmx_params->info.ip_channels;
1137 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301138 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301139 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1140 = atoi(ch_coeff_value);
1141 ch_coeff_value = strtok_r(NULL, " ", &context);
1142 }
1143 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1144 ch_coeff_value != NULL)
1145 ALOGE("%s: invalid/malformed coefficient values", __func__);
1146}
1147
1148static void process_custom_mtmx_params(const XML_Char **attr)
1149{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301150 int attr_idx = 0, i = 0;
1151 char *context = NULL, *value = NULL;
1152
1153 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301154
1155 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1156 ALOGE("%s: 'param_id' not found", __func__);
1157 return;
1158 }
1159 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1160
1161 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1162 ALOGE("%s: 'in_channel_count' not found", __func__);
1163 return;
1164 }
1165 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1166
1167 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1168 ALOGE("%s: 'out_channel_count' not found", __func__);
1169 return;
1170 }
1171 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1172
1173 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1174 ALOGE("%s: 'usecase' not found", __func__);
1175 return;
1176 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301177
1178 /* check if multi usecases are supported for this custom mtrx params */
1179 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1180 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1181 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1182 value = strtok_r(NULL, ",", &context);
1183 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301184
1185 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1186 ALOGE("%s: 'snd_device' not found", __func__);
1187 return;
1188 }
1189 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301190
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301191 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1192 i = 0;
1193 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1194 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1195 mtmx_params_info.fe_id[i++] = atoi(value);
1196 value = strtok_r(NULL, ",", &context);
1197 }
1198
1199 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301200 }
1201
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301202 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
Ethan Chen97564d42014-09-05 13:01:26 -07001203}
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301204
Ethan Chen97564d42014-09-05 13:01:26 -07001205static void process_device_name(const XML_Char **attr)
1206{
1207 int index;
1208
1209 if (strcmp(attr[0], "name") != 0) {
1210 ALOGE("%s: 'name' not found, no alias set!", __func__);
1211 goto done;
1212 }
1213
1214 index = platform_get_snd_device_index((char *)attr[1]);
1215 if (index < 0) {
1216 ALOGE("%s: Device %s in platform info xml not found, no alias set!",
1217 __func__, attr[1]);
1218 goto done;
1219 }
1220
1221 if (strcmp(attr[2], "alias") != 0) {
1222 ALOGE("%s: Device %s in platform info xml has no alias, no alias set!",
1223 __func__, attr[1]);
1224 goto done;
1225 }
1226
1227 if (platform_set_snd_device_name(index, attr[3]) < 0) {
1228 ALOGE("%s: Device %s, alias %s was not set!",
1229 __func__, attr[1], attr[3]);
1230 goto done;
1231 }
1232
1233done:
1234 return;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301235}
1236
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001237static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001238 const XML_Char **attr)
1239{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001240 if (my_data.caller == ACDB_EXTN) {
1241 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1242 section = ACDB_METAINFO_KEY;
1243 } else if (strcmp(tag_name, "param") == 0) {
1244 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1245 ALOGE("param tag only supported with CONFIG_PARAMS section");
1246 return;
1247 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001248
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001249 section_process_fn fn = section_table[section];
1250 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001251 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001252 } else if(my_data.caller == PLATFORM) {
1253 if (strcmp(tag_name, "bit_width_configs") == 0) {
1254 section = BITWIDTH;
1255 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1256 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001257 } else if (strcmp(tag_name, "module_ids") == 0) {
1258 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001259 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1260 section = PCM_ID;
1261 } else if (strcmp(tag_name, "backend_names") == 0) {
1262 section = BACKEND_NAME;
1263 } else if (strcmp(tag_name, "config_params") == 0) {
1264 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001265 } else if (strcmp(tag_name, "operator_specific") == 0) {
1266 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001267 } else if (strcmp(tag_name, "interface_names") == 0) {
1268 section = INTERFACE_NAME;
1269 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1270 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001271 } else if (strcmp(tag_name, "app_types") == 0) {
1272 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001273 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1274 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301275 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1276 section = MICROPHONE_CHARACTERISTIC;
1277 } else if (strcmp(tag_name, "snd_devices") == 0) {
1278 section = SND_DEVICES;
Ethan Chen97564d42014-09-05 13:01:26 -07001279 } else if (strcmp(tag_name, "device_names") == 0) {
1280 section = DEVICE_NAME;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001281 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001282 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1283 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Ethan Chen97564d42014-09-05 13:01:26 -07001284 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC) &&
1285 (section != DEVICE_NAME)) {
1286 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface/device names");
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001287 return;
1288 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001289
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001290 /* call into process function for the current section */
1291 section_process_fn fn = section_table[section];
1292 fn(attr);
1293 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1294 if (section != GAIN_LEVEL_MAPPING) {
1295 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1296 return;
1297 }
1298
1299 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1300 fn(attr);
1301 } else if (strcmp(tag_name, "usecase") == 0) {
1302 if (section != PCM_ID) {
1303 ALOGE("usecase tag only supported with PCM_ID section");
1304 return;
1305 }
1306
1307 section_process_fn fn = section_table[PCM_ID];
1308 fn(attr);
1309 } else if (strcmp(tag_name, "param") == 0) {
1310 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1311 ALOGE("param tag only supported with CONFIG_PARAMS section");
1312 return;
1313 }
1314
1315 section_process_fn fn = section_table[section];
1316 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301317 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001318 if (section != MODULE) {
1319 ALOGE("aec tag only supported with MODULE section");
1320 return;
1321 }
1322 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301323 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001324 if (section != MODULE) {
1325 ALOGE("ns tag only supported with MODULE section");
1326 return;
1327 }
1328 section = NS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001329 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1330 if (section != GAIN_LEVEL_MAPPING) {
1331 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1332 return;
1333 }
1334
1335 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1336 fn(attr);
1337 } else if (!strcmp(tag_name, "app")) {
1338 if (section != APP_TYPE) {
1339 ALOGE("app tag only valid in section APP_TYPE");
1340 return;
1341 }
1342
1343 section_process_fn fn = section_table[APP_TYPE];
1344 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301345 } else if (strcmp(tag_name, "microphone") == 0) {
1346 if (section != MICROPHONE_CHARACTERISTIC) {
1347 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1348 return;
1349 }
1350 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1351 fn(attr);
1352 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1353 if (section != SND_DEVICES) {
1354 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1355 return;
1356 }
1357 section = INPUT_SND_DEVICE;
1358 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1359 if (section != INPUT_SND_DEVICE) {
1360 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1361 return;
1362 }
1363 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1364 } else if (strcmp(tag_name, "snd_dev") == 0) {
1365 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1366 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1367 return;
1368 }
1369 section_process_fn fn = section_table[SND_DEV];
1370 fn(attr);
1371 } else if (strcmp(tag_name, "mic_info") == 0) {
1372 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1373 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1374 return;
1375 }
1376 if (in_snd_device == SND_DEVICE_NONE) {
1377 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1378 return;
1379 }
1380 section_process_fn fn = section_table[MIC_INFO];
1381 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301382 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1383 if (section != ROOT) {
1384 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1385 return;
1386 }
1387 section = CUSTOM_MTMX_PARAMS;
1388 section_process_fn fn = section_table[section];
1389 fn(attr);
1390 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1391 if (section != CUSTOM_MTMX_PARAMS) {
1392 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1393 return;
1394 }
1395 section = CUSTOM_MTMX_PARAM_COEFFS;
1396 section_process_fn fn = section_table[section];
1397 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001398 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1399 section = EXTERNAL_DEVICE_SPECIFIC;
1400 } else if (strcmp(tag_name, "ext_device") == 0) {
1401 section_process_fn fn = section_table[section];
1402 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301403 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1404 if (section != ROOT) {
1405 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1406 return;
1407 }
1408 section = CUSTOM_MTMX_IN_PARAMS;
1409 section_process_fn fn = section_table[section];
1410 fn(attr);
1411 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1412 if (section != CUSTOM_MTMX_IN_PARAMS) {
1413 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1414 return;
1415 }
1416 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
1417 section_process_fn fn = section_table[section];
1418 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301419 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001420 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001421 if(strcmp(tag_name, "config_params") == 0) {
1422 section = CONFIG_PARAMS;
1423 } else if (strcmp(tag_name, "param") == 0) {
1424 if (section != CONFIG_PARAMS) {
1425 ALOGE("param tag only supported with CONFIG_PARAMS section");
1426 return;
1427 }
1428
1429 section_process_fn fn = section_table[section];
1430 fn(attr);
1431 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001432 }
Ben Romberger55886882014-01-10 13:49:02 -08001433 return;
1434}
1435
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001436static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001437{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001438 if (strcmp(tag_name, "bit_width_configs") == 0) {
1439 section = ROOT;
1440 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001441 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001442 } else if (strcmp(tag_name, "module_ids") == 0) {
1443 section = ROOT;
1444 } else if (strcmp(tag_name, "aec") == 0) {
1445 section = MODULE;
1446 } else if (strcmp(tag_name, "ns") == 0) {
1447 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001448 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1449 section = ROOT;
1450 } else if (strcmp(tag_name, "backend_names") == 0) {
1451 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001452 } else if (strcmp(tag_name, "config_params") == 0) {
1453 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001454 } else if (strcmp(tag_name, "operator_specific") == 0) {
1455 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001456 } else if (strcmp(tag_name, "interface_names") == 0) {
1457 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001458 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1459 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001460 } else if (strcmp(tag_name, "app_types") == 0) {
1461 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301462 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1463 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301464 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1465 section = ROOT;
1466 } else if (strcmp(tag_name, "snd_devices") == 0) {
1467 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001468 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1469 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301470 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1471 section = SND_DEVICES;
1472 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1473 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301474 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1475 section = ROOT;
1476 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1477 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301478 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1479 section = ROOT;
1480 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1481 section = CUSTOM_MTMX_IN_PARAMS;
Ethan Chen97564d42014-09-05 13:01:26 -07001482 } else if (strcmp(tag_name, "device_names") == 0) {
1483 section = ROOT;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001484 }
Ben Romberger55886882014-01-10 13:49:02 -08001485}
1486
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001487int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001488{
1489 XML_Parser parser;
1490 FILE *file;
1491 int ret = 0;
1492 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001493 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001494 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001495
Weiyin Jiang63f4d8c2019-09-06 16:59:32 +08001496 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001497 if (filename == NULL)
1498 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1499 MIXER_PATH_MAX_LENGTH);
1500 else
1501 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1502
1503 ALOGV("%s: platform info file name is %s", __func__,
1504 platform_info_file_name);
1505
1506 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001507 section = ROOT;
1508
Ben Romberger55886882014-01-10 13:49:02 -08001509 if (!file) {
1510 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001511 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001512 ret = -ENODEV;
1513 goto done;
1514 }
1515
1516 parser = XML_ParserCreate(NULL);
1517 if (!parser) {
1518 ALOGE("%s: Failed to create XML parser!", __func__);
1519 ret = -ENODEV;
1520 goto err_close_file;
1521 }
1522
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001523 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001524 my_data.platform = platform;
1525 my_data.kvpairs = str_parms_create();
1526
Ben Romberger55886882014-01-10 13:49:02 -08001527 XML_SetElementHandler(parser, start_tag, end_tag);
1528
1529 while (1) {
1530 buf = XML_GetBuffer(parser, BUF_SIZE);
1531 if (buf == NULL) {
1532 ALOGE("%s: XML_GetBuffer failed", __func__);
1533 ret = -ENOMEM;
1534 goto err_free_parser;
1535 }
1536
1537 bytes_read = fread(buf, 1, BUF_SIZE, file);
1538 if (bytes_read < 0) {
1539 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1540 ret = bytes_read;
1541 goto err_free_parser;
1542 }
1543
1544 if (XML_ParseBuffer(parser, bytes_read,
1545 bytes_read == 0) == XML_STATUS_ERROR) {
1546 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001547 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001548 ret = -EINVAL;
1549 goto err_free_parser;
1550 }
1551
1552 if (bytes_read == 0)
1553 break;
1554 }
1555
Ben Romberger55886882014-01-10 13:49:02 -08001556err_free_parser:
1557 XML_ParserFree(parser);
1558err_close_file:
1559 fclose(file);
1560done:
Weiyin Jiang63f4d8c2019-09-06 16:59:32 +08001561 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001562 return ret;
1563}