blob: 70c2b70b76a59c6261c5bcf26cffd9cba7897533 [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +05302 * 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>
36#include <cutils/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,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070063 GAIN_LEVEL_MAPPING,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053064 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053065 MICROPHONE_CHARACTERISTIC,
66 SND_DEVICES,
67 INPUT_SND_DEVICE,
68 INPUT_SND_DEVICE_TO_MIC_MAPPING,
69 SND_DEV,
70 MIC_INFO,
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +053071 CUSTOM_MTMX_PARAMS,
72 CUSTOM_MTMX_PARAM_COEFFS,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070073} section_t;
74
75typedef void (* section_process_fn)(const XML_Char **attr);
76
77static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070078static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
79static void process_effect_aec(const XML_Char **attr);
80static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070081static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070082static void process_pcm_id(const XML_Char **attr);
83static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080084static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070085static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070086static void process_root(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070087static void process_gain_db_to_level_map(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053088static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053089static void process_microphone_characteristic(const XML_Char **attr);
90static void process_snd_dev(const XML_Char **attr);
91static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +053092static void process_custom_mtmx_params(const XML_Char **attr);
93static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070094
95static section_process_fn section_table[] = {
96 [ROOT] = process_root,
97 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070098 [AEC] = process_effect_aec,
99 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700100 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700101 [PCM_ID] = process_pcm_id,
102 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800103 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700104 [CONFIG_PARAMS] = process_config_params,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700105 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530106 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530107 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
108 [SND_DEV] = process_snd_dev,
109 [MIC_INFO] = process_mic_info,
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +0530110 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
111 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700112};
113
114static section_t section;
115
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700116struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700117 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700118 void *platform;
119 struct str_parms *kvpairs;
120};
121
122static struct platform_info my_data;
123
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530124
125struct audio_string_to_enum {
126 const char* name;
127 unsigned int value;
128};
129
130static snd_device_t in_snd_device;
131
132static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
133 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
134 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
135 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
136 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
137};
138
139static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
140 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
141 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
142 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
143 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
144 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
145 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
146};
147
148static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
149 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
150 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
151 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
152};
153
154static const struct audio_string_to_enum device_in_types[] = {
155 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
157 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
163 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
167 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
182};
183
184enum {
185 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
186 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
187 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
188 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
189 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
190 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
191 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
192 | ORIENTATION) | GEOMETRIC_LOCATION) */
193};
194
195static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
196 int32_t len, unsigned int *value)
197{
198 if (table == NULL) {
199 ALOGE("%s: table is NULL", __func__);
200 return false;
201 }
202
203 if (name == NULL) {
204 ALOGE("null key");
205 return false;
206 }
207
208 for (int i = 0; i < len; i++) {
209 if (!strcmp(table[i].name, name)) {
210 *value = table[i].value;
211 return true;
212 }
213 }
214 return false;
215}
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +0530216
217static struct audio_custom_mtmx_params_info mtmx_params_info;
218
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700219/*
220 * <audio_platform_info>
221 * <acdb_ids>
222 * <device name="???" acdb_id="???"/>
223 * ...
224 * ...
225 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700226 * <module_ids>
227 * <device name="???" module_id="???"/>
228 * ...
229 * ...
230 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700231 * <backend_names>
232 * <device name="???" backend="???"/>
233 * ...
234 * ...
235 * </backend_names>
236 * <pcm_ids>
237 * <usecase name="???" type="in/out" id="???"/>
238 * ...
239 * ...
240 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800241 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530242 * <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 -0800243 * ...
244 * ...
245 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700246 * <config_params>
247 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
248 * ...
249 * ...
250 * </config_params>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700251 * </audio_platform_info>
252 */
253
254static void process_root(const XML_Char **attr __unused)
255{
256}
257
258/* mapping from usecase to pcm dev id */
259static void process_pcm_id(const XML_Char **attr)
260{
261 int index;
262
263 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700264 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700265 goto done;
266 }
267
268 index = platform_get_usecase_index((char *)attr[1]);
269 if (index < 0) {
270 ALOGE("%s: usecase %s not found!",
271 __func__, attr[1]);
272 goto done;
273 }
274
275 if (strcmp(attr[2], "type") != 0) {
276 ALOGE("%s: usecase type not mentioned", __func__);
277 goto done;
278 }
279
280 int type = -1;
281
282 if (!strcasecmp((char *)attr[3], "in")) {
283 type = 1;
284 } else if (!strcasecmp((char *)attr[3], "out")) {
285 type = 0;
286 } else {
287 ALOGE("%s: type must be IN or OUT", __func__);
288 goto done;
289 }
290
291 if (strcmp(attr[4], "id") != 0) {
292 ALOGE("%s: usecase id not mentioned", __func__);
293 goto done;
294 }
295
296 int id = atoi((char *)attr[5]);
297
298 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
299 ALOGE("%s: usecase %s type %d id %d was not set!",
300 __func__, attr[1], type, id);
301 goto done;
302 }
303
304done:
305 return;
306}
307
308/* backend to be used for a device */
309static void process_backend_name(const XML_Char **attr)
310{
311 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530312 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530313 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700314
315 if (strcmp(attr[0], "name") != 0) {
316 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
317 goto done;
318 }
319
320 index = platform_get_snd_device_index((char *)attr[1]);
321 if (index < 0) {
322 ALOGE("%s: Device %s not found, no ACDB ID set!",
323 __func__, attr[1]);
324 goto done;
325 }
326
327 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530328 if (strcmp(attr[2], "interface") == 0)
329 hw_interface = (char *)attr[3];
330 } else {
331 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700332 }
333
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530334 if (attr[4] != NULL) {
335 if (strcmp(attr[4], "interface") != 0) {
336 hw_interface = NULL;
337 } else {
338 hw_interface = (char *)attr[5];
339 }
340 }
341
Ashish Jaind150d4c2017-02-03 18:44:34 +0530342 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700343 ALOGE("%s: Device %s backend %s was not set!",
344 __func__, attr[1], attr[3]);
345 goto done;
346 }
347
348done:
349 return;
350}
351
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700352static void process_gain_db_to_level_map(const XML_Char **attr)
353{
354 struct amp_db_and_gain_table tbl_entry;
355
356 if ((strcmp(attr[0], "db") != 0) ||
357 (strcmp(attr[2], "level") != 0)) {
358 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
359 __func__, attr[0], attr[2]);
360 goto done;
361 }
362
363 tbl_entry.db = atof(attr[1]);
364 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
365 tbl_entry.level = atoi(attr[3]);
366
367 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
368 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
369 platform_add_gain_level_mapping(&tbl_entry);
370
371done:
372 return;
373}
374
375
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700376static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800377{
Ben Romberger61764e32014-01-10 13:49:02 -0800378 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800379
Ben Romberger61764e32014-01-10 13:49:02 -0800380 if (strcmp(attr[0], "name") != 0) {
381 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800382 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800383 }
Ben Romberger55886882014-01-10 13:49:02 -0800384
Ben Romberger61764e32014-01-10 13:49:02 -0800385 index = platform_get_snd_device_index((char *)attr[1]);
386 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800387 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
388 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800389 goto done;
390 }
391
392 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800393 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
394 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800395 goto done;
396 }
397
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700398 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
399 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800400 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800401 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800402 }
Ben Romberger55886882014-01-10 13:49:02 -0800403
Ben Romberger55886882014-01-10 13:49:02 -0800404done:
405 return;
406}
407
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700408static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
409{
410 int index;
411 struct audio_effect_config effect_config;
412
413 if (strcmp(attr[0], "name") != 0) {
414 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
415 goto done;
416 }
417
418 index = platform_get_snd_device_index((char *)attr[1]);
419 if (index < 0) {
420 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
421 __func__, attr[1]);
422 goto done;
423 }
424
425 if (strcmp(attr[2], "module_id") != 0) {
426 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
427 __func__, attr[2]);
428 goto done;
429 }
430
431 if (strcmp(attr[4], "instance_id") != 0) {
432 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
433 __func__, attr[4]);
434 goto done;
435 }
436
437 if (strcmp(attr[6], "param_id") != 0) {
438 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
439 __func__, attr[6]);
440 goto done;
441 }
442
443 if (strcmp(attr[8], "param_value") != 0) {
444 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
445 __func__, attr[8]);
446 goto done;
447 }
448
449 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
450 strtol((char *)attr[5], NULL, 0),
451 strtol((char *)attr[7], NULL, 0),
452 strtol((char *)attr[9], NULL, 0)};
453
454
455 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
456 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
457 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
458 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
459 strtol((char *)attr[9], NULL, 0));
460 goto done;
461 }
462
463done:
464 return;
465}
466
467static void process_effect_aec(const XML_Char **attr)
468{
469 process_audio_effect(attr, EFFECT_AEC);
470 return;
471}
472
473static void process_effect_ns(const XML_Char **attr)
474{
475 process_audio_effect(attr, EFFECT_NS);
476 return;
477}
478
Amit Shekhar5a39c912014-10-14 15:39:30 -0700479static void process_bit_width(const XML_Char **attr)
480{
481 int index;
482
483 if (strcmp(attr[0], "name") != 0) {
484 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
485 goto done;
486 }
487
488 index = platform_get_snd_device_index((char *)attr[1]);
489 if (index < 0) {
490 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
491 __func__, attr[1]);
492 goto done;
493 }
494
495 if (strcmp(attr[2], "bit_width") != 0) {
496 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
497 __func__, attr[1]);
498 goto done;
499 }
500
501 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
502 ALOGE("%s: Device %s, ACDB ID %d was not set!",
503 __func__, attr[1], atoi((char *)attr[3]));
504 goto done;
505 }
506
507done:
508 return;
509}
510
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800511static void process_interface_name(const XML_Char **attr)
512{
513 int ret;
514
515 if (strcmp(attr[0], "name") != 0) {
516 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
517
518 goto done;
519 }
520
521 if (strcmp(attr[2], "interface") != 0) {
522 ALOGE("%s: Device %s has no Audio Interface set!",
523 __func__, attr[1]);
524
525 goto done;
526 }
527
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530528 if (strcmp(attr[4], "codec_type") != 0) {
529 ALOGE("%s: Device %s has no codec type set!",
530 __func__, attr[1]);
531
532 goto done;
533 }
534
535 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
536 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800537 if (ret < 0) {
538 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800539 goto done;
540 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800541
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800542done:
543 return;
544}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530545
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700546static void process_config_params(const XML_Char **attr)
547{
548 if (strcmp(attr[0], "key") != 0) {
549 ALOGE("%s: 'key' not found", __func__);
550 goto done;
551 }
552
553 if (strcmp(attr[2], "value") != 0) {
554 ALOGE("%s: 'value' not found", __func__);
555 goto done;
556 }
557
558 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
559done:
560 return;
561}
562
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530563static void process_microphone_characteristic(const XML_Char **attr) {
564 struct audio_microphone_characteristic_t microphone;
565 uint32_t curIdx = 0;
566
567 if (strcmp(attr[curIdx++], "valid_mask")) {
568 ALOGE("%s: valid_mask not found", __func__);
569 goto done;
570 }
571 uint32_t valid_mask = atoi(attr[curIdx++]);
572
573 if (strcmp(attr[curIdx++], "device_id")) {
574 ALOGE("%s: device_id not found", __func__);
575 goto done;
576 }
577 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
578 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
579 goto done;
580 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530581 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530582
583 if (strcmp(attr[curIdx++], "type")) {
584 ALOGE("%s: device not found", __func__);
585 goto done;
586 }
587 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
588 ARRAY_SIZE(device_in_types), &microphone.device)) {
589 ALOGE("%s: type %s in %s not found!",
590 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
591 goto done;
592 }
593
594 if (strcmp(attr[curIdx++], "address")) {
595 ALOGE("%s: address not found", __func__);
596 goto done;
597 }
598 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
599 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
600 goto done;
601 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530602 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530603 if (strlen(microphone.address) == 0) {
604 // If the address is empty, populate the address according to device type.
605 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530606 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530607 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530608 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530609 }
610 }
611
612 if (strcmp(attr[curIdx++], "location")) {
613 ALOGE("%s: location not found", __func__);
614 goto done;
615 }
616 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
617 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
618 ALOGE("%s: location %s in %s not found!",
619 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
620 goto done;
621 }
622
623 if (strcmp(attr[curIdx++], "group")) {
624 ALOGE("%s: group not found", __func__);
625 goto done;
626 }
627 microphone.group = atoi(attr[curIdx++]);
628
629 if (strcmp(attr[curIdx++], "index_in_the_group")) {
630 ALOGE("%s: index_in_the_group not found", __func__);
631 goto done;
632 }
633 microphone.index_in_the_group = atoi(attr[curIdx++]);
634
635 if (strcmp(attr[curIdx++], "directionality")) {
636 ALOGE("%s: directionality not found", __func__);
637 goto done;
638 }
639 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
640 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
641 ALOGE("%s: directionality %s in %s not found!",
642 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
643 goto done;
644 }
645
646 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
647 ALOGE("%s: num_frequency_responses not found", __func__);
648 goto done;
649 }
650 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530651 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530652 ALOGE("%s: num_frequency_responses is too large", __func__);
653 goto done;
654 }
655 if (microphone.num_frequency_responses > 0) {
656 if (strcmp(attr[curIdx++], "frequencies")) {
657 ALOGE("%s: frequencies not found", __func__);
658 goto done;
659 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530660 char *context = NULL;
661 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530662 uint32_t num_frequencies = 0;
663 while (token) {
664 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800665 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530666 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530667 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530668 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530669 }
670
671 if (strcmp(attr[curIdx++], "responses")) {
672 ALOGE("%s: responses not found", __func__);
673 goto done;
674 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530675 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530676 uint32_t num_responses = 0;
677 while (token) {
678 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800679 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530680 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530681 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530682 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530683 }
684
685 if (num_frequencies != num_responses
686 || num_frequencies != microphone.num_frequency_responses) {
687 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
688 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
689 goto done;
690 }
691 }
692
693 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
694 if (strcmp(attr[curIdx++], "sensitivity")) {
695 ALOGE("%s: sensitivity not found", __func__);
696 goto done;
697 }
698 microphone.sensitivity = atof(attr[curIdx++]);
699 } else {
700 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
701 }
702
703 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
704 if (strcmp(attr[curIdx++], "max_spl")) {
705 ALOGE("%s: max_spl not found", __func__);
706 goto done;
707 }
708 microphone.max_spl = atof(attr[curIdx++]);
709 } else {
710 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
711 }
712
713 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
714 if (strcmp(attr[curIdx++], "min_spl")) {
715 ALOGE("%s: min_spl not found", __func__);
716 goto done;
717 }
718 microphone.min_spl = atof(attr[curIdx++]);
719 } else {
720 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
721 }
722
723 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
724 if (strcmp(attr[curIdx++], "orientation")) {
725 ALOGE("%s: orientation not found", __func__);
726 goto done;
727 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530728 char *context = NULL;
729 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530730 float orientation[3];
731 uint32_t idx = 0;
732 while (token) {
733 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800734 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530735 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530736 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530737 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530738 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530739 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530740 ALOGE("%s: orientation invalid", __func__);
741 goto done;
742 }
743 microphone.orientation.x = orientation[0];
744 microphone.orientation.y = orientation[1];
745 microphone.orientation.z = orientation[2];
746 } else {
747 microphone.orientation.x = 0.0f;
748 microphone.orientation.y = 0.0f;
749 microphone.orientation.z = 0.0f;
750 }
751
752 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
753 if (strcmp(attr[curIdx++], "geometric_location")) {
754 ALOGE("%s: geometric_location not found", __func__);
755 goto done;
756 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530757 char *context = NULL;
758 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530759 float geometric_location[3];
760 uint32_t idx = 0;
761 while (token) {
762 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800763 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530764 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530765 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530766 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530767 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530768 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530769 ALOGE("%s: geometric_location invalid", __func__);
770 goto done;
771 }
772 microphone.geometric_location.x = geometric_location[0];
773 microphone.geometric_location.y = geometric_location[1];
774 microphone.geometric_location.z = geometric_location[2];
775 } else {
776 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
777 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
778 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
779 }
780
781 platform_set_microphone_characteristic(my_data.platform, microphone);
782done:
783 return;
784}
785
786static void process_snd_dev(const XML_Char **attr)
787{
788 uint32_t curIdx = 0;
789 in_snd_device = SND_DEVICE_NONE;
790
791 if (strcmp(attr[curIdx++], "in_snd_device")) {
792 ALOGE("%s: snd_device not found", __func__);
793 return;
794 }
795 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
796 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
797 in_snd_device >= SND_DEVICE_IN_END) {
798 ALOGE("%s: Sound device not valid", __func__);
799 in_snd_device = SND_DEVICE_NONE;
800 }
801
802 return;
803}
804
805static void process_mic_info(const XML_Char **attr)
806{
807 uint32_t curIdx = 0;
808 struct mic_info microphone;
809
810 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
811 sizeof(microphone.channel_mapping));
812
813 if (strcmp(attr[curIdx++], "mic_device_id")) {
814 ALOGE("%s: mic_device_id not found", __func__);
815 goto on_error;
816 }
817 strlcpy(microphone.device_id,
818 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
819
820 if (strcmp(attr[curIdx++], "channel_mapping")) {
821 ALOGE("%s: channel_mapping not found", __func__);
822 goto on_error;
823 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530824 char *context = NULL;
825 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530826 uint32_t idx = 0;
827 while (token) {
828 if (!find_enum_by_string(mic_channel_mapping, token,
829 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
830 &microphone.channel_mapping[idx++])) {
831 ALOGE("%s: channel_mapping %s in %s not found!",
832 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
833 goto on_error;
834 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530835 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530836 }
837 microphone.channel_count = idx;
838
839 platform_set_microphone_map(my_data.platform, in_snd_device,
840 &microphone);
841 return;
842on_error:
843 in_snd_device = SND_DEVICE_NONE;
844 return;
845}
846
847
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530848/* process acdb meta info key value */
849static void process_acdb_metainfo_key(const XML_Char **attr)
850{
851 if (strcmp(attr[0], "name") != 0) {
852 ALOGE("%s: 'name' not found", __func__);
853 goto done;
854 }
855
856 if (strcmp(attr[2], "value") != 0) {
857 ALOGE("%s: 'value' not found", __func__);
858 goto done;
859 }
860
861 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700862 switch(my_data.caller) {
863 case ACDB_EXTN:
864 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
865 ALOGE("%s: key %d was not set!", __func__, key);
866 goto done;
867 }
868 break;
869 case PLATFORM:
870 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
871 ALOGE("%s: key %d was not set!", __func__, key);
872 goto done;
873 }
874 break;
875 default:
876 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530877 }
878
879done:
880 return;
881}
882
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +0530883static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
884{
885 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
886 uint32_t ip_channels = 0, op_channels = 0;
887 char *context = NULL, *ch_coeff_value = NULL;
888 struct audio_custom_mtmx_params *mtmx_params = NULL;
889
890 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
891 ALOGE("%s: 'out_channel_index' not found", __func__);
892 return;
893 }
894 out_ch_idx = atoi((char *)attr[attr_idx++]);
895
896 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
897 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
898 return;
899 }
900
901 if (strcmp(attr[attr_idx++], "values") != 0) {
902 ALOGE("%s: 'values' not found", __func__);
903 return;
904 }
905 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
906 &mtmx_params_info);
907 if (mtmx_params == NULL) {
908 ALOGE("%s: mtmx params with given param info, not found", __func__);
909 return;
910 }
911 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
912 ip_channels = mtmx_params->info.ip_channels;
913 op_channels = mtmx_params->info.op_channels;
914 while(ch_coeff_value && ch_coeff_count < op_channels) {
915 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
916 = atoi(ch_coeff_value);
917 ch_coeff_value = strtok_r(NULL, " ", &context);
918 }
919 if (ch_coeff_count != mtmx_params->info.ip_channels ||
920 ch_coeff_value != NULL)
921 ALOGE("%s: invalid/malformed coefficient values", __func__);
922}
923
924static void process_custom_mtmx_params(const XML_Char **attr)
925{
926 int attr_idx = 0;
927
928 if (strcmp(attr[attr_idx++], "param_id") != 0) {
929 ALOGE("%s: 'param_id' not found", __func__);
930 return;
931 }
932 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
933
934 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
935 ALOGE("%s: 'in_channel_count' not found", __func__);
936 return;
937 }
938 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
939
940 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
941 ALOGE("%s: 'out_channel_count' not found", __func__);
942 return;
943 }
944 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
945
946 if (strcmp(attr[attr_idx++], "usecase") != 0) {
947 ALOGE("%s: 'usecase' not found", __func__);
948 return;
949 }
950 mtmx_params_info.usecase_id = platform_get_usecase_index((char *)attr[attr_idx++]);
951
952 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
953 ALOGE("%s: 'snd_device' not found", __func__);
954 return;
955 }
956 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
957 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
958
959}
960
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700961static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -0800962 const XML_Char **attr)
963{
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700964 if (my_data.caller == ACDB_EXTN) {
965 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
966 section = ACDB_METAINFO_KEY;
967 } else if (strcmp(tag_name, "param") == 0) {
968 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
969 ALOGE("param tag only supported with CONFIG_PARAMS section");
970 return;
971 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700972
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700973 section_process_fn fn = section_table[section];
974 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700975 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700976 } else if(my_data.caller == PLATFORM) {
977 if (strcmp(tag_name, "bit_width_configs") == 0) {
978 section = BITWIDTH;
979 } else if (strcmp(tag_name, "acdb_ids") == 0) {
980 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700981 } else if (strcmp(tag_name, "module_ids") == 0) {
982 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700983 } else if (strcmp(tag_name, "pcm_ids") == 0) {
984 section = PCM_ID;
985 } else if (strcmp(tag_name, "backend_names") == 0) {
986 section = BACKEND_NAME;
987 } else if (strcmp(tag_name, "config_params") == 0) {
988 section = CONFIG_PARAMS;
989 } else if (strcmp(tag_name, "interface_names") == 0) {
990 section = INTERFACE_NAME;
991 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
992 section = GAIN_LEVEL_MAPPING;
993 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
994 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530995 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
996 section = MICROPHONE_CHARACTERISTIC;
997 } else if (strcmp(tag_name, "snd_devices") == 0) {
998 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700999 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001000 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1001 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001002 (section != INTERFACE_NAME)) {
1003 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1004 return;
1005 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001006
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001007 /* call into process function for the current section */
1008 section_process_fn fn = section_table[section];
1009 fn(attr);
1010 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1011 if (section != GAIN_LEVEL_MAPPING) {
1012 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1013 return;
1014 }
1015
1016 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1017 fn(attr);
1018 } else if (strcmp(tag_name, "usecase") == 0) {
1019 if (section != PCM_ID) {
1020 ALOGE("usecase tag only supported with PCM_ID section");
1021 return;
1022 }
1023
1024 section_process_fn fn = section_table[PCM_ID];
1025 fn(attr);
1026 } else if (strcmp(tag_name, "param") == 0) {
1027 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1028 ALOGE("param tag only supported with CONFIG_PARAMS section");
1029 return;
1030 }
1031
1032 section_process_fn fn = section_table[section];
1033 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301034 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001035 if (section != MODULE) {
1036 ALOGE("aec tag only supported with MODULE section");
1037 return;
1038 }
1039 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301040 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001041 if (section != MODULE) {
1042 ALOGE("ns tag only supported with MODULE section");
1043 return;
1044 }
1045 section = NS;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301046 } else if (strcmp(tag_name, "microphone") == 0) {
1047 if (section != MICROPHONE_CHARACTERISTIC) {
1048 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1049 return;
1050 }
1051 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1052 fn(attr);
1053 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1054 if (section != SND_DEVICES) {
1055 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1056 return;
1057 }
1058 section = INPUT_SND_DEVICE;
1059 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1060 if (section != INPUT_SND_DEVICE) {
1061 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1062 return;
1063 }
1064 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1065 } else if (strcmp(tag_name, "snd_dev") == 0) {
1066 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1067 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1068 return;
1069 }
1070 section_process_fn fn = section_table[SND_DEV];
1071 fn(attr);
1072 } else if (strcmp(tag_name, "mic_info") == 0) {
1073 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1074 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1075 return;
1076 }
1077 if (in_snd_device == SND_DEVICE_NONE) {
1078 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1079 return;
1080 }
1081 section_process_fn fn = section_table[MIC_INFO];
1082 fn(attr);
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +05301083 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1084 if (section != ROOT) {
1085 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1086 return;
1087 }
1088 section = CUSTOM_MTMX_PARAMS;
1089 section_process_fn fn = section_table[section];
1090 fn(attr);
1091 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1092 if (section != CUSTOM_MTMX_PARAMS) {
1093 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1094 return;
1095 }
1096 section = CUSTOM_MTMX_PARAM_COEFFS;
1097 section_process_fn fn = section_table[section];
1098 fn(attr);
1099 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001100 } else {
1101 ALOGE("%s: unknown caller!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001102 }
Ben Romberger55886882014-01-10 13:49:02 -08001103 return;
1104}
1105
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001106static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001107{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001108 if (strcmp(tag_name, "bit_width_configs") == 0) {
1109 section = ROOT;
1110 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001111 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001112 } else if (strcmp(tag_name, "module_ids") == 0) {
1113 section = ROOT;
1114 } else if (strcmp(tag_name, "aec") == 0) {
1115 section = MODULE;
1116 } else if (strcmp(tag_name, "ns") == 0) {
1117 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001118 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1119 section = ROOT;
1120 } else if (strcmp(tag_name, "backend_names") == 0) {
1121 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001122 } else if (strcmp(tag_name, "config_params") == 0) {
1123 section = ROOT;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001124 if (my_data.caller == PLATFORM) {
1125 platform_set_parameters(my_data.platform, my_data.kvpairs);
1126 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001127 } else if (strcmp(tag_name, "interface_names") == 0) {
1128 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001129 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1130 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301131 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1132 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301133 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1134 section = ROOT;
1135 } else if (strcmp(tag_name, "snd_devices") == 0) {
1136 section = ROOT;
1137 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1138 section = SND_DEVICES;
1139 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1140 section = INPUT_SND_DEVICE;
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +05301141 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1142 section = ROOT;
1143 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1144 section = CUSTOM_MTMX_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001145 }
Ben Romberger55886882014-01-10 13:49:02 -08001146}
1147
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001148int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001149{
1150 XML_Parser parser;
1151 FILE *file;
1152 int ret = 0;
1153 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001154 void *buf;
1155
Helen Zeng6a16ad72014-02-23 22:04:44 -08001156 file = fopen(filename, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001157 section = ROOT;
1158
Ben Romberger55886882014-01-10 13:49:02 -08001159 if (!file) {
1160 ALOGD("%s: Failed to open %s, using defaults.",
Helen Zeng6a16ad72014-02-23 22:04:44 -08001161 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -08001162 ret = -ENODEV;
1163 goto done;
1164 }
1165
1166 parser = XML_ParserCreate(NULL);
1167 if (!parser) {
1168 ALOGE("%s: Failed to create XML parser!", __func__);
1169 ret = -ENODEV;
1170 goto err_close_file;
1171 }
1172
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001173 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001174 my_data.platform = platform;
1175 my_data.kvpairs = str_parms_create();
1176
Ben Romberger55886882014-01-10 13:49:02 -08001177 XML_SetElementHandler(parser, start_tag, end_tag);
1178
1179 while (1) {
1180 buf = XML_GetBuffer(parser, BUF_SIZE);
1181 if (buf == NULL) {
1182 ALOGE("%s: XML_GetBuffer failed", __func__);
1183 ret = -ENOMEM;
1184 goto err_free_parser;
1185 }
1186
1187 bytes_read = fread(buf, 1, BUF_SIZE, file);
1188 if (bytes_read < 0) {
1189 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1190 ret = bytes_read;
1191 goto err_free_parser;
1192 }
1193
1194 if (XML_ParseBuffer(parser, bytes_read,
1195 bytes_read == 0) == XML_STATUS_ERROR) {
1196 ALOGE("%s: XML_ParseBuffer failed, for %s",
Helen Zeng6a16ad72014-02-23 22:04:44 -08001197 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -08001198 ret = -EINVAL;
1199 goto err_free_parser;
1200 }
1201
1202 if (bytes_read == 0)
1203 break;
1204 }
1205
Ben Romberger55886882014-01-10 13:49:02 -08001206err_free_parser:
1207 XML_ParserFree(parser);
1208err_close_file:
1209 fclose(file);
1210done:
1211 return ret;
1212}