blob: 1969f52ebc261b1d3716a4c3c5acf4f2e58cb1a2 [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;
Weiyin Jiang13bcdde2019-09-06 16:59:32 +0800138static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700139
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530140
141struct audio_string_to_enum {
142 const char* name;
143 unsigned int value;
144};
145
146static snd_device_t in_snd_device;
147
148static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
149 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
150 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
151 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
152 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
153};
154
155static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
157 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
162};
163
164static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
167 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
168};
169
170static const struct audio_string_to_enum device_in_types[] = {
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
191 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
192 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
193 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
194 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
195 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
196 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
197 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
198};
199
200enum {
201 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
202 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
203 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
204 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
205 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
206 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
207 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
208 | ORIENTATION) | GEOMETRIC_LOCATION) */
209};
210
211static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
212 int32_t len, unsigned int *value)
213{
214 if (table == NULL) {
215 ALOGE("%s: table is NULL", __func__);
216 return false;
217 }
218
219 if (name == NULL) {
220 ALOGE("null key");
221 return false;
222 }
223
224 for (int i = 0; i < len; i++) {
225 if (!strcmp(table[i].name, name)) {
226 *value = table[i].value;
227 return true;
228 }
229 }
230 return false;
231}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530232
233static struct audio_custom_mtmx_params_info mtmx_params_info;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530234static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530235
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700236/*
237 * <audio_platform_info>
238 * <acdb_ids>
239 * <device name="???" acdb_id="???"/>
240 * ...
241 * ...
242 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700243 * <module_ids>
244 * <device name="???" module_id="???"/>
245 * ...
246 * ...
247 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700248 * <backend_names>
249 * <device name="???" backend="???"/>
250 * ...
251 * ...
252 * </backend_names>
253 * <pcm_ids>
254 * <usecase name="???" type="in/out" id="???"/>
255 * ...
256 * ...
257 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800258 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530259 * <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 -0800260 * ...
261 * ...
262 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700263 * <config_params>
264 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800265 * <param key="operator_info" value="tmus;aa;bb;cc"/>
266 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700267 * ...
268 * ...
269 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800270 *
271 * <operator_specific>
272 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
273 * ...
274 * ...
275 * </operator_specific>
276 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700277 * </audio_platform_info>
278 */
279
280static void process_root(const XML_Char **attr __unused)
281{
282}
283
284/* mapping from usecase to pcm dev id */
285static void process_pcm_id(const XML_Char **attr)
286{
287 int index;
288
289 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700290 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700291 goto done;
292 }
293
294 index = platform_get_usecase_index((char *)attr[1]);
295 if (index < 0) {
296 ALOGE("%s: usecase %s not found!",
297 __func__, attr[1]);
298 goto done;
299 }
300
301 if (strcmp(attr[2], "type") != 0) {
302 ALOGE("%s: usecase type not mentioned", __func__);
303 goto done;
304 }
305
306 int type = -1;
307
308 if (!strcasecmp((char *)attr[3], "in")) {
309 type = 1;
310 } else if (!strcasecmp((char *)attr[3], "out")) {
311 type = 0;
312 } else {
313 ALOGE("%s: type must be IN or OUT", __func__);
314 goto done;
315 }
316
317 if (strcmp(attr[4], "id") != 0) {
318 ALOGE("%s: usecase id not mentioned", __func__);
319 goto done;
320 }
321
322 int id = atoi((char *)attr[5]);
323
324 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
325 ALOGE("%s: usecase %s type %d id %d was not set!",
326 __func__, attr[1], type, id);
327 goto done;
328 }
329
330done:
331 return;
332}
333
334/* backend to be used for a device */
335static void process_backend_name(const XML_Char **attr)
336{
337 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530338 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530339 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700340
341 if (strcmp(attr[0], "name") != 0) {
342 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
343 goto done;
344 }
345
346 index = platform_get_snd_device_index((char *)attr[1]);
347 if (index < 0) {
348 ALOGE("%s: Device %s not found, no ACDB ID set!",
349 __func__, attr[1]);
350 goto done;
351 }
352
353 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530354 if (strcmp(attr[2], "interface") == 0)
355 hw_interface = (char *)attr[3];
356 } else {
357 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700358 }
359
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530360 if (attr[4] != NULL) {
361 if (strcmp(attr[4], "interface") != 0) {
362 hw_interface = NULL;
363 } else {
364 hw_interface = (char *)attr[5];
365 }
366 }
367
Ashish Jaind150d4c2017-02-03 18:44:34 +0530368 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700369 ALOGE("%s: Device %s backend %s was not set!",
370 __func__, attr[1], attr[3]);
371 goto done;
372 }
373
374done:
375 return;
376}
377
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700378static void process_gain_db_to_level_map(const XML_Char **attr)
379{
380 struct amp_db_and_gain_table tbl_entry;
381
382 if ((strcmp(attr[0], "db") != 0) ||
383 (strcmp(attr[2], "level") != 0)) {
384 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
385 __func__, attr[0], attr[2]);
386 goto done;
387 }
388
389 tbl_entry.db = atof(attr[1]);
390 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
391 tbl_entry.level = atoi(attr[3]);
392
Aalique Grahame22e49102018-12-18 14:23:57 -0800393 //custome level should be > 0. Level 0 is fixed for default
394 CHECK(tbl_entry.level > 0);
395
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700396 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
397 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
398 platform_add_gain_level_mapping(&tbl_entry);
399
400done:
401 return;
402}
403
404
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700405static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800406{
Ben Romberger61764e32014-01-10 13:49:02 -0800407 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800408
Ben Romberger61764e32014-01-10 13:49:02 -0800409 if (strcmp(attr[0], "name") != 0) {
410 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800411 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800412 }
Ben Romberger55886882014-01-10 13:49:02 -0800413
Ben Romberger61764e32014-01-10 13:49:02 -0800414 index = platform_get_snd_device_index((char *)attr[1]);
415 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800416 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
417 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800418 goto done;
419 }
420
421 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800422 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
423 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800424 goto done;
425 }
426
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700427 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
428 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800429 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800430 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800431 }
Ben Romberger55886882014-01-10 13:49:02 -0800432
Ben Romberger55886882014-01-10 13:49:02 -0800433done:
434 return;
435}
436
Aalique Grahame22e49102018-12-18 14:23:57 -0800437static void process_operator_specific(const XML_Char **attr)
438{
439 snd_device_t snd_device = SND_DEVICE_NONE;
440
441 if (strcmp(attr[0], "name") != 0) {
442 ALOGE("%s: 'name' not found", __func__);
443 goto done;
444 }
445
446 snd_device = platform_get_snd_device_index((char *)attr[1]);
447 if (snd_device < 0) {
448 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
449 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
450 goto done;
451 }
452
453 if (strcmp(attr[2], "operator") != 0) {
454 ALOGE("%s: 'operator' not found", __func__);
455 goto done;
456 }
457
458 if (strcmp(attr[4], "mixer_path") != 0) {
459 ALOGE("%s: 'mixer_path' not found", __func__);
460 goto done;
461 }
462
463 if (strcmp(attr[6], "acdb_id") != 0) {
464 ALOGE("%s: 'acdb_id' not found", __func__);
465 goto done;
466 }
467
468 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
469
470done:
471 return;
472}
473
Carter Hsu32a62362018-10-15 15:01:42 -0700474static void process_external_dev(const XML_Char **attr)
475{
476 snd_device_t snd_device = SND_DEVICE_NONE;
477
478 if (strcmp(attr[0], "name") != 0) {
479 ALOGE("%s: 'name' not found", __func__);
480 goto done;
481 }
482
483 snd_device = platform_get_snd_device_index((char *)attr[1]);
484 if (snd_device < 0) {
485 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
486 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
487 goto done;
488 }
489
490 if (strcmp(attr[2], "usbid") != 0) {
491 ALOGE("%s: 'usbid' not found", __func__);
492 goto done;
493 }
494
495 if (strcmp(attr[4], "acdb_id") != 0) {
496 ALOGE("%s: 'acdb_id' not found", __func__);
497 goto done;
498 }
499
500 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
501
502done:
503 return;
504}
505
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700506static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
507{
508 int index;
509 struct audio_effect_config effect_config;
510
511 if (strcmp(attr[0], "name") != 0) {
512 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
513 goto done;
514 }
515
516 index = platform_get_snd_device_index((char *)attr[1]);
517 if (index < 0) {
518 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
519 __func__, attr[1]);
520 goto done;
521 }
522
523 if (strcmp(attr[2], "module_id") != 0) {
524 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
525 __func__, attr[2]);
526 goto done;
527 }
528
529 if (strcmp(attr[4], "instance_id") != 0) {
530 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
531 __func__, attr[4]);
532 goto done;
533 }
534
535 if (strcmp(attr[6], "param_id") != 0) {
536 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
537 __func__, attr[6]);
538 goto done;
539 }
540
541 if (strcmp(attr[8], "param_value") != 0) {
542 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
543 __func__, attr[8]);
544 goto done;
545 }
546
547 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
548 strtol((char *)attr[5], NULL, 0),
549 strtol((char *)attr[7], NULL, 0),
550 strtol((char *)attr[9], NULL, 0)};
551
552
553 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
554 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
555 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
556 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
557 strtol((char *)attr[9], NULL, 0));
558 goto done;
559 }
560
561done:
562 return;
563}
564
565static void process_effect_aec(const XML_Char **attr)
566{
567 process_audio_effect(attr, EFFECT_AEC);
568 return;
569}
570
571static void process_effect_ns(const XML_Char **attr)
572{
573 process_audio_effect(attr, EFFECT_NS);
574 return;
575}
576
Amit Shekhar5a39c912014-10-14 15:39:30 -0700577static void process_bit_width(const XML_Char **attr)
578{
579 int index;
580
581 if (strcmp(attr[0], "name") != 0) {
582 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
583 goto done;
584 }
585
586 index = platform_get_snd_device_index((char *)attr[1]);
587 if (index < 0) {
588 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
589 __func__, attr[1]);
590 goto done;
591 }
592
593 if (strcmp(attr[2], "bit_width") != 0) {
594 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
595 __func__, attr[1]);
596 goto done;
597 }
598
599 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
600 ALOGE("%s: Device %s, ACDB ID %d was not set!",
601 __func__, attr[1], atoi((char *)attr[3]));
602 goto done;
603 }
604
605done:
606 return;
607}
608
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800609static void process_interface_name(const XML_Char **attr)
610{
611 int ret;
612
613 if (strcmp(attr[0], "name") != 0) {
614 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
615
616 goto done;
617 }
618
619 if (strcmp(attr[2], "interface") != 0) {
620 ALOGE("%s: Device %s has no Audio Interface set!",
621 __func__, attr[1]);
622
623 goto done;
624 }
625
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530626 if (strcmp(attr[4], "codec_type") != 0) {
627 ALOGE("%s: Device %s has no codec type set!",
628 __func__, attr[1]);
629
630 goto done;
631 }
632
633 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
634 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800635 if (ret < 0) {
636 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800637 goto done;
638 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800639
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800640done:
641 return;
642}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530643
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700644static void process_config_params(const XML_Char **attr)
645{
646 if (strcmp(attr[0], "key") != 0) {
647 ALOGE("%s: 'key' not found", __func__);
648 goto done;
649 }
650
651 if (strcmp(attr[2], "value") != 0) {
652 ALOGE("%s: 'value' not found", __func__);
653 goto done;
654 }
655
656 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
Aniket Kumar Latad64bfbd2019-07-09 12:01:16 -0700657 if (my_data.caller == PLATFORM)
658 platform_set_parameters(my_data.platform, my_data.kvpairs);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700659done:
660 return;
661}
662
Aalique Grahame22e49102018-12-18 14:23:57 -0800663static void process_app_type(const XML_Char **attr)
664{
665 if (strcmp(attr[0], "uc_type")) {
666 ALOGE("%s: uc_type not found", __func__);
667 goto done;
668 }
669
670 if (strcmp(attr[2], "mode")) {
671 ALOGE("%s: mode not found", __func__);
672 goto done;
673 }
674
675 if (strcmp(attr[4], "bit_width")) {
676 ALOGE("%s: bit_width not found", __func__);
677 goto done;
678 }
679
680 if (strcmp(attr[6], "id")) {
681 ALOGE("%s: id not found", __func__);
682 goto done;
683 }
684
685 if (strcmp(attr[8], "max_rate")) {
686 ALOGE("%s: max rate not found", __func__);
687 goto done;
688 }
689
690 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
691 atoi(attr[9]));
692done:
693 return;
694}
695
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530696static void process_microphone_characteristic(const XML_Char **attr) {
697 struct audio_microphone_characteristic_t microphone;
698 uint32_t curIdx = 0;
699
700 if (strcmp(attr[curIdx++], "valid_mask")) {
701 ALOGE("%s: valid_mask not found", __func__);
702 goto done;
703 }
704 uint32_t valid_mask = atoi(attr[curIdx++]);
705
706 if (strcmp(attr[curIdx++], "device_id")) {
707 ALOGE("%s: device_id not found", __func__);
708 goto done;
709 }
710 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
711 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
712 goto done;
713 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530714 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530715
716 if (strcmp(attr[curIdx++], "type")) {
717 ALOGE("%s: device not found", __func__);
718 goto done;
719 }
720 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
721 ARRAY_SIZE(device_in_types), &microphone.device)) {
722 ALOGE("%s: type %s in %s not found!",
723 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
724 goto done;
725 }
726
727 if (strcmp(attr[curIdx++], "address")) {
728 ALOGE("%s: address not found", __func__);
729 goto done;
730 }
731 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
732 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
733 goto done;
734 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530735 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530736 if (strlen(microphone.address) == 0) {
737 // If the address is empty, populate the address according to device type.
738 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530739 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530740 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530741 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530742 }
743 }
744
745 if (strcmp(attr[curIdx++], "location")) {
746 ALOGE("%s: location not found", __func__);
747 goto done;
748 }
749 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
750 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
751 ALOGE("%s: location %s in %s not found!",
752 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
753 goto done;
754 }
755
756 if (strcmp(attr[curIdx++], "group")) {
757 ALOGE("%s: group not found", __func__);
758 goto done;
759 }
760 microphone.group = atoi(attr[curIdx++]);
761
762 if (strcmp(attr[curIdx++], "index_in_the_group")) {
763 ALOGE("%s: index_in_the_group not found", __func__);
764 goto done;
765 }
766 microphone.index_in_the_group = atoi(attr[curIdx++]);
767
768 if (strcmp(attr[curIdx++], "directionality")) {
769 ALOGE("%s: directionality not found", __func__);
770 goto done;
771 }
772 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
773 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
774 ALOGE("%s: directionality %s in %s not found!",
775 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
776 goto done;
777 }
778
779 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
780 ALOGE("%s: num_frequency_responses not found", __func__);
781 goto done;
782 }
783 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530784 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530785 ALOGE("%s: num_frequency_responses is too large", __func__);
786 goto done;
787 }
788 if (microphone.num_frequency_responses > 0) {
789 if (strcmp(attr[curIdx++], "frequencies")) {
790 ALOGE("%s: frequencies not found", __func__);
791 goto done;
792 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530793 char *context = NULL;
794 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530795 uint32_t num_frequencies = 0;
796 while (token) {
797 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800798 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530799 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530800 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530801 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530802 }
803
804 if (strcmp(attr[curIdx++], "responses")) {
805 ALOGE("%s: responses not found", __func__);
806 goto done;
807 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530808 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530809 uint32_t num_responses = 0;
810 while (token) {
811 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800812 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530813 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530814 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530815 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530816 }
817
818 if (num_frequencies != num_responses
819 || num_frequencies != microphone.num_frequency_responses) {
820 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
821 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
822 goto done;
823 }
824 }
825
826 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
827 if (strcmp(attr[curIdx++], "sensitivity")) {
828 ALOGE("%s: sensitivity not found", __func__);
829 goto done;
830 }
831 microphone.sensitivity = atof(attr[curIdx++]);
832 } else {
833 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
834 }
835
836 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
837 if (strcmp(attr[curIdx++], "max_spl")) {
838 ALOGE("%s: max_spl not found", __func__);
839 goto done;
840 }
841 microphone.max_spl = atof(attr[curIdx++]);
842 } else {
843 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
844 }
845
846 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
847 if (strcmp(attr[curIdx++], "min_spl")) {
848 ALOGE("%s: min_spl not found", __func__);
849 goto done;
850 }
851 microphone.min_spl = atof(attr[curIdx++]);
852 } else {
853 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
854 }
855
856 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
857 if (strcmp(attr[curIdx++], "orientation")) {
858 ALOGE("%s: orientation not found", __func__);
859 goto done;
860 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530861 char *context = NULL;
862 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530863 float orientation[3];
864 uint32_t idx = 0;
865 while (token) {
866 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800867 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530868 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530869 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530870 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530871 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530872 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530873 ALOGE("%s: orientation invalid", __func__);
874 goto done;
875 }
876 microphone.orientation.x = orientation[0];
877 microphone.orientation.y = orientation[1];
878 microphone.orientation.z = orientation[2];
879 } else {
880 microphone.orientation.x = 0.0f;
881 microphone.orientation.y = 0.0f;
882 microphone.orientation.z = 0.0f;
883 }
884
885 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
886 if (strcmp(attr[curIdx++], "geometric_location")) {
887 ALOGE("%s: geometric_location not found", __func__);
888 goto done;
889 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530890 char *context = NULL;
891 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530892 float geometric_location[3];
893 uint32_t idx = 0;
894 while (token) {
895 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800896 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530897 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530898 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530899 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530900 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530901 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530902 ALOGE("%s: geometric_location invalid", __func__);
903 goto done;
904 }
905 microphone.geometric_location.x = geometric_location[0];
906 microphone.geometric_location.y = geometric_location[1];
907 microphone.geometric_location.z = geometric_location[2];
908 } else {
909 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
910 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
911 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
912 }
913
914 platform_set_microphone_characteristic(my_data.platform, microphone);
915done:
916 return;
917}
918
919static void process_snd_dev(const XML_Char **attr)
920{
921 uint32_t curIdx = 0;
922 in_snd_device = SND_DEVICE_NONE;
923
924 if (strcmp(attr[curIdx++], "in_snd_device")) {
925 ALOGE("%s: snd_device not found", __func__);
926 return;
927 }
928 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
929 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
930 in_snd_device >= SND_DEVICE_IN_END) {
931 ALOGE("%s: Sound device not valid", __func__);
932 in_snd_device = SND_DEVICE_NONE;
933 }
934
935 return;
936}
937
938static void process_mic_info(const XML_Char **attr)
939{
940 uint32_t curIdx = 0;
941 struct mic_info microphone;
942
943 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
944 sizeof(microphone.channel_mapping));
945
946 if (strcmp(attr[curIdx++], "mic_device_id")) {
947 ALOGE("%s: mic_device_id not found", __func__);
948 goto on_error;
949 }
950 strlcpy(microphone.device_id,
951 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
952
953 if (strcmp(attr[curIdx++], "channel_mapping")) {
954 ALOGE("%s: channel_mapping not found", __func__);
955 goto on_error;
956 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530957 char *context = NULL;
958 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530959 uint32_t idx = 0;
960 while (token) {
961 if (!find_enum_by_string(mic_channel_mapping, token,
962 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
963 &microphone.channel_mapping[idx++])) {
964 ALOGE("%s: channel_mapping %s in %s not found!",
965 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
966 goto on_error;
967 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530968 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530969 }
970 microphone.channel_count = idx;
971
972 platform_set_microphone_map(my_data.platform, in_snd_device,
973 &microphone);
974 return;
975on_error:
976 in_snd_device = SND_DEVICE_NONE;
977 return;
978}
979
980
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530981/* process acdb meta info key value */
982static void process_acdb_metainfo_key(const XML_Char **attr)
983{
984 if (strcmp(attr[0], "name") != 0) {
985 ALOGE("%s: 'name' not found", __func__);
986 goto done;
987 }
988
989 if (strcmp(attr[2], "value") != 0) {
990 ALOGE("%s: 'value' not found", __func__);
991 goto done;
992 }
993
994 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700995 switch(my_data.caller) {
996 case ACDB_EXTN:
997 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
998 ALOGE("%s: key %d was not set!", __func__, key);
999 goto done;
1000 }
1001 break;
1002 case PLATFORM:
1003 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
1004 ALOGE("%s: key %d was not set!", __func__, key);
1005 goto done;
1006 }
1007 break;
1008 default:
1009 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301010 }
1011
1012done:
1013 return;
1014}
1015
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301016static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr)
1017{
1018 uint32_t attr_idx = 0;
1019 int32_t in_ch_idx = -1;
1020 struct audio_custom_mtmx_in_params *mtmx_in_params = NULL;
1021
1022 mtmx_in_params = platform_get_custom_mtmx_in_params((void *)my_data.platform,
1023 &mtmx_in_params_info);
1024 if (mtmx_in_params == NULL) {
1025 ALOGE("%s: mtmx in params with given param info, not found", __func__);
1026 return;
1027 }
1028
1029 if (strcmp(attr[attr_idx++], "in_channel_index") != 0) {
1030 ALOGE("%s: 'in_channel_index' not found", __func__);
1031 return;
1032 }
1033
1034 in_ch_idx = atoi((char *)attr[attr_idx++]);
1035 if (in_ch_idx < 0 || in_ch_idx >= MAX_IN_CHANNELS) {
1036 ALOGE("%s: invalid input channel index(%d)", __func__, in_ch_idx);
1037 return;
1038 }
1039
1040 if (strcmp(attr[attr_idx++], "channel_count") != 0) {
1041 ALOGE("%s: 'channel_count' not found", __func__);
1042 return;
1043 }
1044 mtmx_in_params->in_ch_info[in_ch_idx].ch_count = atoi((char *)attr[attr_idx++]);
1045
1046 if (strcmp(attr[attr_idx++], "device") != 0) {
1047 ALOGE("%s: 'device' not found", __func__);
1048 return;
1049 }
1050 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].device, attr[attr_idx++],
1051 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device));
1052
1053 if (strcmp(attr[attr_idx++], "interface") != 0) {
1054 ALOGE("%s: 'interface' not found", __func__);
1055 return;
1056 }
1057 strlcpy(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface, attr[attr_idx++],
1058 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].hw_interface));
1059
1060 if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1061 ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC),
1062 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1063 mtmx_in_params->mic_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1064 else if (!strncmp(mtmx_in_params->in_ch_info[in_ch_idx].device,
1065 ENUM_TO_STRING(AUDIO_DEVICE_IN_LOOPBACK),
1066 sizeof(mtmx_in_params->in_ch_info[in_ch_idx].device)))
1067 mtmx_in_params->ec_ref_ch = mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1068
1069 mtmx_in_params->ip_channels += mtmx_in_params->in_ch_info[in_ch_idx].ch_count;
1070}
1071
1072static void process_custom_mtmx_in_params(const XML_Char **attr)
1073{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301074 int attr_idx = 0, i = 0;
1075 char *context = NULL, *value = NULL;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301076
1077 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1078 ALOGE("%s: 'usecase' not found", __func__);
1079 return;
1080 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301081 /* Check if multi usecases are supported for this custom mtrx params */
1082 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1083 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1084 mtmx_in_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1085 value = strtok_r(NULL, ",", &context);
1086 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301087
1088 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1089 ALOGE("%s: 'out_channel_count' not found", __func__);
1090 return;
1091 }
1092 mtmx_in_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1093
1094 platform_add_custom_mtmx_in_params((void *)my_data.platform, &mtmx_in_params_info);
1095
1096}
1097
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301098static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1099{
1100 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301101 uint32_t ip_channels = 0, op_channels = 0, idx = 0;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301102 char *context = NULL, *ch_coeff_value = NULL;
1103 struct audio_custom_mtmx_params *mtmx_params = NULL;
1104
1105 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1106 ALOGE("%s: 'out_channel_index' not found", __func__);
1107 return;
1108 }
1109 out_ch_idx = atoi((char *)attr[attr_idx++]);
1110
1111 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1112 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1113 return;
1114 }
1115
1116 if (strcmp(attr[attr_idx++], "values") != 0) {
1117 ALOGE("%s: 'values' not found", __func__);
1118 return;
1119 }
1120 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301121 &mtmx_params_info, &idx);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301122 if (mtmx_params == NULL) {
1123 ALOGE("%s: mtmx params with given param info, not found", __func__);
1124 return;
1125 }
1126 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1127 ip_channels = mtmx_params->info.ip_channels;
1128 op_channels = mtmx_params->info.op_channels;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301129 while(ch_coeff_value && ch_coeff_count < ip_channels) {
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301130 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1131 = atoi(ch_coeff_value);
1132 ch_coeff_value = strtok_r(NULL, " ", &context);
1133 }
1134 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1135 ch_coeff_value != NULL)
1136 ALOGE("%s: invalid/malformed coefficient values", __func__);
1137}
1138
1139static void process_custom_mtmx_params(const XML_Char **attr)
1140{
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301141 int attr_idx = 0, i = 0;
1142 char *context = NULL, *value = NULL;
1143
1144 memset(&mtmx_params_info, 0, sizeof(mtmx_params_info));
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301145
1146 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1147 ALOGE("%s: 'param_id' not found", __func__);
1148 return;
1149 }
1150 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1151
1152 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1153 ALOGE("%s: 'in_channel_count' not found", __func__);
1154 return;
1155 }
1156 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1157
1158 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1159 ALOGE("%s: 'out_channel_count' not found", __func__);
1160 return;
1161 }
1162 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1163
1164 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1165 ALOGE("%s: 'usecase' not found", __func__);
1166 return;
1167 }
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301168
1169 /* check if multi usecases are supported for this custom mtrx params */
1170 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1171 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1172 mtmx_params_info.usecase_id[i++] = platform_get_usecase_index(value);
1173 value = strtok_r(NULL, ",", &context);
1174 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301175
1176 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1177 ALOGE("%s: 'snd_device' not found", __func__);
1178 return;
1179 }
1180 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301181
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05301182 if ((attr[attr_idx] != NULL) && (strcmp(attr[attr_idx++], "fe_id") == 0)) {
1183 i = 0;
1184 value = strtok_r((char *)attr[attr_idx++], ",", &context);
1185 while (value && (i < CUSTOM_MTRX_PARAMS_MAX_USECASE)) {
1186 mtmx_params_info.fe_id[i++] = atoi(value);
1187 value = strtok_r(NULL, ",", &context);
1188 }
1189
1190 attr_idx++;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301191 }
1192
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301193 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1194
1195}
1196
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001197static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001198 const XML_Char **attr)
1199{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001200 if (my_data.caller == ACDB_EXTN) {
1201 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1202 section = ACDB_METAINFO_KEY;
1203 } else if (strcmp(tag_name, "param") == 0) {
1204 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1205 ALOGE("param tag only supported with CONFIG_PARAMS section");
1206 return;
1207 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001208
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001209 section_process_fn fn = section_table[section];
1210 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001211 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001212 } else if(my_data.caller == PLATFORM) {
1213 if (strcmp(tag_name, "bit_width_configs") == 0) {
1214 section = BITWIDTH;
1215 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1216 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001217 } else if (strcmp(tag_name, "module_ids") == 0) {
1218 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001219 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1220 section = PCM_ID;
1221 } else if (strcmp(tag_name, "backend_names") == 0) {
1222 section = BACKEND_NAME;
1223 } else if (strcmp(tag_name, "config_params") == 0) {
1224 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001225 } else if (strcmp(tag_name, "operator_specific") == 0) {
1226 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001227 } else if (strcmp(tag_name, "interface_names") == 0) {
1228 section = INTERFACE_NAME;
1229 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1230 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001231 } else if (strcmp(tag_name, "app_types") == 0) {
1232 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001233 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1234 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301235 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1236 section = MICROPHONE_CHARACTERISTIC;
1237 } else if (strcmp(tag_name, "snd_devices") == 0) {
1238 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001239 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001240 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1241 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001242 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001243 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1244 return;
1245 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001246
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001247 /* call into process function for the current section */
1248 section_process_fn fn = section_table[section];
1249 fn(attr);
1250 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1251 if (section != GAIN_LEVEL_MAPPING) {
1252 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1253 return;
1254 }
1255
1256 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1257 fn(attr);
1258 } else if (strcmp(tag_name, "usecase") == 0) {
1259 if (section != PCM_ID) {
1260 ALOGE("usecase tag only supported with PCM_ID section");
1261 return;
1262 }
1263
1264 section_process_fn fn = section_table[PCM_ID];
1265 fn(attr);
1266 } else if (strcmp(tag_name, "param") == 0) {
1267 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1268 ALOGE("param tag only supported with CONFIG_PARAMS section");
1269 return;
1270 }
1271
1272 section_process_fn fn = section_table[section];
1273 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301274 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001275 if (section != MODULE) {
1276 ALOGE("aec tag only supported with MODULE section");
1277 return;
1278 }
1279 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301280 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001281 if (section != MODULE) {
1282 ALOGE("ns tag only supported with MODULE section");
1283 return;
1284 }
1285 section = NS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001286 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1287 if (section != GAIN_LEVEL_MAPPING) {
1288 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1289 return;
1290 }
1291
1292 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1293 fn(attr);
1294 } else if (!strcmp(tag_name, "app")) {
1295 if (section != APP_TYPE) {
1296 ALOGE("app tag only valid in section APP_TYPE");
1297 return;
1298 }
1299
1300 section_process_fn fn = section_table[APP_TYPE];
1301 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301302 } else if (strcmp(tag_name, "microphone") == 0) {
1303 if (section != MICROPHONE_CHARACTERISTIC) {
1304 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1305 return;
1306 }
1307 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1308 fn(attr);
1309 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1310 if (section != SND_DEVICES) {
1311 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1312 return;
1313 }
1314 section = INPUT_SND_DEVICE;
1315 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1316 if (section != INPUT_SND_DEVICE) {
1317 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1318 return;
1319 }
1320 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1321 } else if (strcmp(tag_name, "snd_dev") == 0) {
1322 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1323 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1324 return;
1325 }
1326 section_process_fn fn = section_table[SND_DEV];
1327 fn(attr);
1328 } else if (strcmp(tag_name, "mic_info") == 0) {
1329 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1330 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1331 return;
1332 }
1333 if (in_snd_device == SND_DEVICE_NONE) {
1334 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1335 return;
1336 }
1337 section_process_fn fn = section_table[MIC_INFO];
1338 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301339 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1340 if (section != ROOT) {
1341 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1342 return;
1343 }
1344 section = CUSTOM_MTMX_PARAMS;
1345 section_process_fn fn = section_table[section];
1346 fn(attr);
1347 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1348 if (section != CUSTOM_MTMX_PARAMS) {
1349 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1350 return;
1351 }
1352 section = CUSTOM_MTMX_PARAM_COEFFS;
1353 section_process_fn fn = section_table[section];
1354 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001355 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1356 section = EXTERNAL_DEVICE_SPECIFIC;
1357 } else if (strcmp(tag_name, "ext_device") == 0) {
1358 section_process_fn fn = section_table[section];
1359 fn(attr);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301360 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1361 if (section != ROOT) {
1362 ALOGE("custom_mtmx_in_params tag supported only in ROOT section");
1363 return;
1364 }
1365 section = CUSTOM_MTMX_IN_PARAMS;
1366 section_process_fn fn = section_table[section];
1367 fn(attr);
1368 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1369 if (section != CUSTOM_MTMX_IN_PARAMS) {
1370 ALOGE("custom_mtmx_param_in_chs tag supported only with CUSTOM_MTMX_IN_PARAMS section");
1371 return;
1372 }
1373 section = CUSTOM_MTMX_PARAM_IN_CH_INFO;
1374 section_process_fn fn = section_table[section];
1375 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301376 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001377 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001378 if(strcmp(tag_name, "config_params") == 0) {
1379 section = CONFIG_PARAMS;
1380 } else if (strcmp(tag_name, "param") == 0) {
1381 if (section != CONFIG_PARAMS) {
1382 ALOGE("param tag only supported with CONFIG_PARAMS section");
1383 return;
1384 }
1385
1386 section_process_fn fn = section_table[section];
1387 fn(attr);
1388 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001389 }
Ben Romberger55886882014-01-10 13:49:02 -08001390 return;
1391}
1392
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001393static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001394{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001395 if (strcmp(tag_name, "bit_width_configs") == 0) {
1396 section = ROOT;
1397 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001398 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001399 } else if (strcmp(tag_name, "module_ids") == 0) {
1400 section = ROOT;
1401 } else if (strcmp(tag_name, "aec") == 0) {
1402 section = MODULE;
1403 } else if (strcmp(tag_name, "ns") == 0) {
1404 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001405 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1406 section = ROOT;
1407 } else if (strcmp(tag_name, "backend_names") == 0) {
1408 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001409 } else if (strcmp(tag_name, "config_params") == 0) {
1410 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001411 } else if (strcmp(tag_name, "operator_specific") == 0) {
1412 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001413 } else if (strcmp(tag_name, "interface_names") == 0) {
1414 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001415 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1416 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001417 } else if (strcmp(tag_name, "app_types") == 0) {
1418 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301419 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1420 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301421 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1422 section = ROOT;
1423 } else if (strcmp(tag_name, "snd_devices") == 0) {
1424 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001425 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1426 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301427 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1428 section = SND_DEVICES;
1429 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1430 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301431 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1432 section = ROOT;
1433 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1434 section = CUSTOM_MTMX_PARAMS;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301435 } else if (strcmp(tag_name, "custom_mtmx_in_params") == 0) {
1436 section = ROOT;
1437 } else if (strcmp(tag_name, "custom_mtmx_param_in_chs") == 0) {
1438 section = CUSTOM_MTMX_IN_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001439 }
Ben Romberger55886882014-01-10 13:49:02 -08001440}
1441
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001442int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001443{
1444 XML_Parser parser;
1445 FILE *file;
1446 int ret = 0;
1447 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001448 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001449 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001450
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001451 pthread_mutex_lock(&parser_lock);
Aalique Grahame22e49102018-12-18 14:23:57 -08001452 if (filename == NULL)
1453 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1454 MIXER_PATH_MAX_LENGTH);
1455 else
1456 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1457
1458 ALOGV("%s: platform info file name is %s", __func__,
1459 platform_info_file_name);
1460
1461 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001462 section = ROOT;
1463
Ben Romberger55886882014-01-10 13:49:02 -08001464 if (!file) {
1465 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001466 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001467 ret = -ENODEV;
1468 goto done;
1469 }
1470
1471 parser = XML_ParserCreate(NULL);
1472 if (!parser) {
1473 ALOGE("%s: Failed to create XML parser!", __func__);
1474 ret = -ENODEV;
1475 goto err_close_file;
1476 }
1477
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001478 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001479 my_data.platform = platform;
1480 my_data.kvpairs = str_parms_create();
1481
Ben Romberger55886882014-01-10 13:49:02 -08001482 XML_SetElementHandler(parser, start_tag, end_tag);
1483
1484 while (1) {
1485 buf = XML_GetBuffer(parser, BUF_SIZE);
1486 if (buf == NULL) {
1487 ALOGE("%s: XML_GetBuffer failed", __func__);
1488 ret = -ENOMEM;
1489 goto err_free_parser;
1490 }
1491
1492 bytes_read = fread(buf, 1, BUF_SIZE, file);
1493 if (bytes_read < 0) {
1494 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1495 ret = bytes_read;
1496 goto err_free_parser;
1497 }
1498
1499 if (XML_ParseBuffer(parser, bytes_read,
1500 bytes_read == 0) == XML_STATUS_ERROR) {
1501 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001502 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001503 ret = -EINVAL;
1504 goto err_free_parser;
1505 }
1506
1507 if (bytes_read == 0)
1508 break;
1509 }
1510
Ben Romberger55886882014-01-10 13:49:02 -08001511err_free_parser:
1512 XML_ParserFree(parser);
1513err_close_file:
1514 fclose(file);
1515done:
Weiyin Jiang13bcdde2019-09-06 16:59:32 +08001516 pthread_mutex_unlock(&parser_lock);
Ben Romberger55886882014-01-10 13:49:02 -08001517 return ret;
1518}