blob: b3dc273cd50ac420c48eeec3070aa6879d89284e [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>
Michael Bestas8e923ec2019-12-10 02:13:27 +020036#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,
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,
Ethan Chen87c0d772014-09-05 13:01:26 -070073 DEVICE_NAME,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070074} section_t;
75
76typedef void (* section_process_fn)(const XML_Char **attr);
77
78static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070079static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
80static void process_effect_aec(const XML_Char **attr);
81static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070082static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070083static void process_pcm_id(const XML_Char **attr);
84static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080085static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070086static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070087static void process_root(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070088static void process_gain_db_to_level_map(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053089static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053090static void process_microphone_characteristic(const XML_Char **attr);
91static void process_snd_dev(const XML_Char **attr);
92static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +053093static void process_custom_mtmx_params(const XML_Char **attr);
94static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Ethan Chen87c0d772014-09-05 13:01:26 -070095static void process_device_name(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070096
97static section_process_fn section_table[] = {
98 [ROOT] = process_root,
99 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700100 [AEC] = process_effect_aec,
101 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700102 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700103 [PCM_ID] = process_pcm_id,
104 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800105 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700106 [CONFIG_PARAMS] = process_config_params,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700107 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530108 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530109 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
110 [SND_DEV] = process_snd_dev,
111 [MIC_INFO] = process_mic_info,
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +0530112 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
113 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Ethan Chen87c0d772014-09-05 13:01:26 -0700114 [DEVICE_NAME] = process_device_name,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700115};
116
117static section_t section;
118
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700119struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700120 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700121 void *platform;
122 struct str_parms *kvpairs;
123};
124
125static struct platform_info my_data;
126
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530127
128struct audio_string_to_enum {
129 const char* name;
130 unsigned int value;
131};
132
133static snd_device_t in_snd_device;
134
135static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
136 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
137 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
138 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
139 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
140};
141
142static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
143 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
144 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
145 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
146 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
147 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
148 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
149};
150
151static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
152 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
153 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
154 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
155};
156
157static const struct audio_string_to_enum device_in_types[] = {
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
163 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
167 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
185};
186
187enum {
188 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
189 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
190 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
191 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
192 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
193 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
194 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
195 | ORIENTATION) | GEOMETRIC_LOCATION) */
196};
197
198static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
199 int32_t len, unsigned int *value)
200{
201 if (table == NULL) {
202 ALOGE("%s: table is NULL", __func__);
203 return false;
204 }
205
206 if (name == NULL) {
207 ALOGE("null key");
208 return false;
209 }
210
211 for (int i = 0; i < len; i++) {
212 if (!strcmp(table[i].name, name)) {
213 *value = table[i].value;
214 return true;
215 }
216 }
217 return false;
218}
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +0530219
220static struct audio_custom_mtmx_params_info mtmx_params_info;
221
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700222/*
223 * <audio_platform_info>
224 * <acdb_ids>
225 * <device name="???" acdb_id="???"/>
226 * ...
227 * ...
228 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700229 * <module_ids>
230 * <device name="???" module_id="???"/>
231 * ...
232 * ...
233 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700234 * <backend_names>
235 * <device name="???" backend="???"/>
236 * ...
237 * ...
238 * </backend_names>
239 * <pcm_ids>
240 * <usecase name="???" type="in/out" id="???"/>
241 * ...
242 * ...
243 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800244 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530245 * <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 -0800246 * ...
247 * ...
248 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700249 * <config_params>
250 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
251 * ...
252 * ...
253 * </config_params>
Ethan Chen87c0d772014-09-05 13:01:26 -0700254 * <device_names>
255 * <device name="???" alias="???"/>
256 * ...
257 * ...
258 * </device_names>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700259 * </audio_platform_info>
260 */
261
262static void process_root(const XML_Char **attr __unused)
263{
264}
265
266/* mapping from usecase to pcm dev id */
267static void process_pcm_id(const XML_Char **attr)
268{
269 int index;
270
271 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700272 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700273 goto done;
274 }
275
276 index = platform_get_usecase_index((char *)attr[1]);
277 if (index < 0) {
278 ALOGE("%s: usecase %s not found!",
279 __func__, attr[1]);
280 goto done;
281 }
282
283 if (strcmp(attr[2], "type") != 0) {
284 ALOGE("%s: usecase type not mentioned", __func__);
285 goto done;
286 }
287
288 int type = -1;
289
290 if (!strcasecmp((char *)attr[3], "in")) {
291 type = 1;
292 } else if (!strcasecmp((char *)attr[3], "out")) {
293 type = 0;
294 } else {
295 ALOGE("%s: type must be IN or OUT", __func__);
296 goto done;
297 }
298
299 if (strcmp(attr[4], "id") != 0) {
300 ALOGE("%s: usecase id not mentioned", __func__);
301 goto done;
302 }
303
304 int id = atoi((char *)attr[5]);
305
306 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
307 ALOGE("%s: usecase %s type %d id %d was not set!",
308 __func__, attr[1], type, id);
309 goto done;
310 }
311
312done:
313 return;
314}
315
316/* backend to be used for a device */
317static void process_backend_name(const XML_Char **attr)
318{
319 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530320 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530321 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700322
323 if (strcmp(attr[0], "name") != 0) {
324 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
325 goto done;
326 }
327
328 index = platform_get_snd_device_index((char *)attr[1]);
329 if (index < 0) {
330 ALOGE("%s: Device %s not found, no ACDB ID set!",
331 __func__, attr[1]);
332 goto done;
333 }
334
335 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530336 if (strcmp(attr[2], "interface") == 0)
337 hw_interface = (char *)attr[3];
338 } else {
339 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700340 }
341
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530342 if (attr[4] != NULL) {
343 if (strcmp(attr[4], "interface") != 0) {
344 hw_interface = NULL;
345 } else {
346 hw_interface = (char *)attr[5];
347 }
348 }
349
Ashish Jaind150d4c2017-02-03 18:44:34 +0530350 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700351 ALOGE("%s: Device %s backend %s was not set!",
352 __func__, attr[1], attr[3]);
353 goto done;
354 }
355
356done:
357 return;
358}
359
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700360static void process_gain_db_to_level_map(const XML_Char **attr)
361{
362 struct amp_db_and_gain_table tbl_entry;
363
364 if ((strcmp(attr[0], "db") != 0) ||
365 (strcmp(attr[2], "level") != 0)) {
366 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
367 __func__, attr[0], attr[2]);
368 goto done;
369 }
370
371 tbl_entry.db = atof(attr[1]);
372 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
373 tbl_entry.level = atoi(attr[3]);
374
375 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
376 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
377 platform_add_gain_level_mapping(&tbl_entry);
378
379done:
380 return;
381}
382
383
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700384static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800385{
Ben Romberger61764e32014-01-10 13:49:02 -0800386 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800387
Ben Romberger61764e32014-01-10 13:49:02 -0800388 if (strcmp(attr[0], "name") != 0) {
389 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800390 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800391 }
Ben Romberger55886882014-01-10 13:49:02 -0800392
Ben Romberger61764e32014-01-10 13:49:02 -0800393 index = platform_get_snd_device_index((char *)attr[1]);
394 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800395 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
396 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800397 goto done;
398 }
399
400 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800401 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
402 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800403 goto done;
404 }
405
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700406 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
407 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800408 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800409 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800410 }
Ben Romberger55886882014-01-10 13:49:02 -0800411
Ben Romberger55886882014-01-10 13:49:02 -0800412done:
413 return;
414}
415
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700416static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
417{
418 int index;
419 struct audio_effect_config effect_config;
420
421 if (strcmp(attr[0], "name") != 0) {
422 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
423 goto done;
424 }
425
426 index = platform_get_snd_device_index((char *)attr[1]);
427 if (index < 0) {
428 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
429 __func__, attr[1]);
430 goto done;
431 }
432
433 if (strcmp(attr[2], "module_id") != 0) {
434 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
435 __func__, attr[2]);
436 goto done;
437 }
438
439 if (strcmp(attr[4], "instance_id") != 0) {
440 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
441 __func__, attr[4]);
442 goto done;
443 }
444
445 if (strcmp(attr[6], "param_id") != 0) {
446 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
447 __func__, attr[6]);
448 goto done;
449 }
450
451 if (strcmp(attr[8], "param_value") != 0) {
452 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
453 __func__, attr[8]);
454 goto done;
455 }
456
457 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
458 strtol((char *)attr[5], NULL, 0),
459 strtol((char *)attr[7], NULL, 0),
460 strtol((char *)attr[9], NULL, 0)};
461
462
463 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
464 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
465 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
466 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
467 strtol((char *)attr[9], NULL, 0));
468 goto done;
469 }
470
471done:
472 return;
473}
474
475static void process_effect_aec(const XML_Char **attr)
476{
477 process_audio_effect(attr, EFFECT_AEC);
478 return;
479}
480
481static void process_effect_ns(const XML_Char **attr)
482{
483 process_audio_effect(attr, EFFECT_NS);
484 return;
485}
486
Amit Shekhar5a39c912014-10-14 15:39:30 -0700487static void process_bit_width(const XML_Char **attr)
488{
489 int index;
490
491 if (strcmp(attr[0], "name") != 0) {
492 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
493 goto done;
494 }
495
496 index = platform_get_snd_device_index((char *)attr[1]);
497 if (index < 0) {
498 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
499 __func__, attr[1]);
500 goto done;
501 }
502
503 if (strcmp(attr[2], "bit_width") != 0) {
504 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
505 __func__, attr[1]);
506 goto done;
507 }
508
509 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
510 ALOGE("%s: Device %s, ACDB ID %d was not set!",
511 __func__, attr[1], atoi((char *)attr[3]));
512 goto done;
513 }
514
515done:
516 return;
517}
518
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800519static void process_interface_name(const XML_Char **attr)
520{
521 int ret;
522
523 if (strcmp(attr[0], "name") != 0) {
524 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
525
526 goto done;
527 }
528
529 if (strcmp(attr[2], "interface") != 0) {
530 ALOGE("%s: Device %s has no Audio Interface set!",
531 __func__, attr[1]);
532
533 goto done;
534 }
535
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530536 if (strcmp(attr[4], "codec_type") != 0) {
537 ALOGE("%s: Device %s has no codec type set!",
538 __func__, attr[1]);
539
540 goto done;
541 }
542
543 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
544 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800545 if (ret < 0) {
546 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800547 goto done;
548 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800549
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800550done:
551 return;
552}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530553
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700554static void process_config_params(const XML_Char **attr)
555{
556 if (strcmp(attr[0], "key") != 0) {
557 ALOGE("%s: 'key' not found", __func__);
558 goto done;
559 }
560
561 if (strcmp(attr[2], "value") != 0) {
562 ALOGE("%s: 'value' not found", __func__);
563 goto done;
564 }
565
566 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
567done:
568 return;
569}
570
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530571static void process_microphone_characteristic(const XML_Char **attr) {
572 struct audio_microphone_characteristic_t microphone;
573 uint32_t curIdx = 0;
574
575 if (strcmp(attr[curIdx++], "valid_mask")) {
576 ALOGE("%s: valid_mask not found", __func__);
577 goto done;
578 }
579 uint32_t valid_mask = atoi(attr[curIdx++]);
580
581 if (strcmp(attr[curIdx++], "device_id")) {
582 ALOGE("%s: device_id not found", __func__);
583 goto done;
584 }
585 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
586 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
587 goto done;
588 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530589 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530590
591 if (strcmp(attr[curIdx++], "type")) {
592 ALOGE("%s: device not found", __func__);
593 goto done;
594 }
595 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
596 ARRAY_SIZE(device_in_types), &microphone.device)) {
597 ALOGE("%s: type %s in %s not found!",
598 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
599 goto done;
600 }
601
602 if (strcmp(attr[curIdx++], "address")) {
603 ALOGE("%s: address not found", __func__);
604 goto done;
605 }
606 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
607 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
608 goto done;
609 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530610 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530611 if (strlen(microphone.address) == 0) {
612 // If the address is empty, populate the address according to device type.
613 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530614 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530615 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530616 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530617 }
618 }
619
620 if (strcmp(attr[curIdx++], "location")) {
621 ALOGE("%s: location not found", __func__);
622 goto done;
623 }
624 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
625 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
626 ALOGE("%s: location %s in %s not found!",
627 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
628 goto done;
629 }
630
631 if (strcmp(attr[curIdx++], "group")) {
632 ALOGE("%s: group not found", __func__);
633 goto done;
634 }
635 microphone.group = atoi(attr[curIdx++]);
636
637 if (strcmp(attr[curIdx++], "index_in_the_group")) {
638 ALOGE("%s: index_in_the_group not found", __func__);
639 goto done;
640 }
641 microphone.index_in_the_group = atoi(attr[curIdx++]);
642
643 if (strcmp(attr[curIdx++], "directionality")) {
644 ALOGE("%s: directionality not found", __func__);
645 goto done;
646 }
647 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
648 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
649 ALOGE("%s: directionality %s in %s not found!",
650 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
651 goto done;
652 }
653
654 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
655 ALOGE("%s: num_frequency_responses not found", __func__);
656 goto done;
657 }
658 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530659 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530660 ALOGE("%s: num_frequency_responses is too large", __func__);
661 goto done;
662 }
663 if (microphone.num_frequency_responses > 0) {
664 if (strcmp(attr[curIdx++], "frequencies")) {
665 ALOGE("%s: frequencies not found", __func__);
666 goto done;
667 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530668 char *context = NULL;
669 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530670 uint32_t num_frequencies = 0;
671 while (token) {
672 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800673 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530674 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530675 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530676 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530677 }
678
679 if (strcmp(attr[curIdx++], "responses")) {
680 ALOGE("%s: responses not found", __func__);
681 goto done;
682 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530683 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530684 uint32_t num_responses = 0;
685 while (token) {
686 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800687 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530688 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530689 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530690 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530691 }
692
693 if (num_frequencies != num_responses
694 || num_frequencies != microphone.num_frequency_responses) {
695 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
696 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
697 goto done;
698 }
699 }
700
701 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
702 if (strcmp(attr[curIdx++], "sensitivity")) {
703 ALOGE("%s: sensitivity not found", __func__);
704 goto done;
705 }
706 microphone.sensitivity = atof(attr[curIdx++]);
707 } else {
708 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
709 }
710
711 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
712 if (strcmp(attr[curIdx++], "max_spl")) {
713 ALOGE("%s: max_spl not found", __func__);
714 goto done;
715 }
716 microphone.max_spl = atof(attr[curIdx++]);
717 } else {
718 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
719 }
720
721 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
722 if (strcmp(attr[curIdx++], "min_spl")) {
723 ALOGE("%s: min_spl not found", __func__);
724 goto done;
725 }
726 microphone.min_spl = atof(attr[curIdx++]);
727 } else {
728 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
729 }
730
731 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
732 if (strcmp(attr[curIdx++], "orientation")) {
733 ALOGE("%s: orientation not found", __func__);
734 goto done;
735 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530736 char *context = NULL;
737 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530738 float orientation[3];
739 uint32_t idx = 0;
740 while (token) {
741 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800742 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530743 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530744 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530745 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530746 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530747 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530748 ALOGE("%s: orientation invalid", __func__);
749 goto done;
750 }
751 microphone.orientation.x = orientation[0];
752 microphone.orientation.y = orientation[1];
753 microphone.orientation.z = orientation[2];
754 } else {
755 microphone.orientation.x = 0.0f;
756 microphone.orientation.y = 0.0f;
757 microphone.orientation.z = 0.0f;
758 }
759
760 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
761 if (strcmp(attr[curIdx++], "geometric_location")) {
762 ALOGE("%s: geometric_location not found", __func__);
763 goto done;
764 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530765 char *context = NULL;
766 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530767 float geometric_location[3];
768 uint32_t idx = 0;
769 while (token) {
770 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800771 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530772 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530773 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530774 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530775 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530776 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530777 ALOGE("%s: geometric_location invalid", __func__);
778 goto done;
779 }
780 microphone.geometric_location.x = geometric_location[0];
781 microphone.geometric_location.y = geometric_location[1];
782 microphone.geometric_location.z = geometric_location[2];
783 } else {
784 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
785 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
786 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
787 }
788
789 platform_set_microphone_characteristic(my_data.platform, microphone);
790done:
791 return;
792}
793
794static void process_snd_dev(const XML_Char **attr)
795{
796 uint32_t curIdx = 0;
797 in_snd_device = SND_DEVICE_NONE;
798
799 if (strcmp(attr[curIdx++], "in_snd_device")) {
800 ALOGE("%s: snd_device not found", __func__);
801 return;
802 }
803 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
804 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
805 in_snd_device >= SND_DEVICE_IN_END) {
806 ALOGE("%s: Sound device not valid", __func__);
807 in_snd_device = SND_DEVICE_NONE;
808 }
809
810 return;
811}
812
813static void process_mic_info(const XML_Char **attr)
814{
815 uint32_t curIdx = 0;
816 struct mic_info microphone;
817
818 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
819 sizeof(microphone.channel_mapping));
820
821 if (strcmp(attr[curIdx++], "mic_device_id")) {
822 ALOGE("%s: mic_device_id not found", __func__);
823 goto on_error;
824 }
825 strlcpy(microphone.device_id,
826 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
827
828 if (strcmp(attr[curIdx++], "channel_mapping")) {
829 ALOGE("%s: channel_mapping not found", __func__);
830 goto on_error;
831 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530832 char *context = NULL;
833 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530834 uint32_t idx = 0;
835 while (token) {
836 if (!find_enum_by_string(mic_channel_mapping, token,
837 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
838 &microphone.channel_mapping[idx++])) {
839 ALOGE("%s: channel_mapping %s in %s not found!",
840 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
841 goto on_error;
842 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530843 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530844 }
845 microphone.channel_count = idx;
846
847 platform_set_microphone_map(my_data.platform, in_snd_device,
848 &microphone);
849 return;
850on_error:
851 in_snd_device = SND_DEVICE_NONE;
852 return;
853}
854
855
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530856/* process acdb meta info key value */
857static void process_acdb_metainfo_key(const XML_Char **attr)
858{
859 if (strcmp(attr[0], "name") != 0) {
860 ALOGE("%s: 'name' not found", __func__);
861 goto done;
862 }
863
864 if (strcmp(attr[2], "value") != 0) {
865 ALOGE("%s: 'value' not found", __func__);
866 goto done;
867 }
868
869 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700870 switch(my_data.caller) {
871 case ACDB_EXTN:
872 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
873 ALOGE("%s: key %d was not set!", __func__, key);
874 goto done;
875 }
876 break;
877 case PLATFORM:
878 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
879 ALOGE("%s: key %d was not set!", __func__, key);
880 goto done;
881 }
882 break;
883 default:
884 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530885 }
886
887done:
888 return;
889}
890
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +0530891static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
892{
893 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
894 uint32_t ip_channels = 0, op_channels = 0;
895 char *context = NULL, *ch_coeff_value = NULL;
896 struct audio_custom_mtmx_params *mtmx_params = NULL;
897
898 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
899 ALOGE("%s: 'out_channel_index' not found", __func__);
900 return;
901 }
902 out_ch_idx = atoi((char *)attr[attr_idx++]);
903
904 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
905 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
906 return;
907 }
908
909 if (strcmp(attr[attr_idx++], "values") != 0) {
910 ALOGE("%s: 'values' not found", __func__);
911 return;
912 }
913 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
914 &mtmx_params_info);
915 if (mtmx_params == NULL) {
916 ALOGE("%s: mtmx params with given param info, not found", __func__);
917 return;
918 }
919 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
920 ip_channels = mtmx_params->info.ip_channels;
921 op_channels = mtmx_params->info.op_channels;
922 while(ch_coeff_value && ch_coeff_count < op_channels) {
923 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
924 = atoi(ch_coeff_value);
925 ch_coeff_value = strtok_r(NULL, " ", &context);
926 }
927 if (ch_coeff_count != mtmx_params->info.ip_channels ||
928 ch_coeff_value != NULL)
929 ALOGE("%s: invalid/malformed coefficient values", __func__);
930}
931
932static void process_custom_mtmx_params(const XML_Char **attr)
933{
934 int attr_idx = 0;
935
936 if (strcmp(attr[attr_idx++], "param_id") != 0) {
937 ALOGE("%s: 'param_id' not found", __func__);
938 return;
939 }
940 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
941
942 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
943 ALOGE("%s: 'in_channel_count' not found", __func__);
944 return;
945 }
946 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
947
948 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
949 ALOGE("%s: 'out_channel_count' not found", __func__);
950 return;
951 }
952 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
953
954 if (strcmp(attr[attr_idx++], "usecase") != 0) {
955 ALOGE("%s: 'usecase' not found", __func__);
956 return;
957 }
958 mtmx_params_info.usecase_id = platform_get_usecase_index((char *)attr[attr_idx++]);
959
960 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
961 ALOGE("%s: 'snd_device' not found", __func__);
962 return;
963 }
964 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
965 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
Ethan Chen87c0d772014-09-05 13:01:26 -0700966}
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +0530967
Ethan Chen87c0d772014-09-05 13:01:26 -0700968static void process_device_name(const XML_Char **attr)
969{
970 int index;
971
972 if (strcmp(attr[0], "name") != 0) {
973 ALOGE("%s: 'name' not found, no alias set!", __func__);
974 goto done;
975 }
976
977 index = platform_get_snd_device_index((char *)attr[1]);
978 if (index < 0) {
979 ALOGE("%s: Device %s in platform info xml not found, no alias set!",
980 __func__, attr[1]);
981 goto done;
982 }
983
984 if (strcmp(attr[2], "alias") != 0) {
985 ALOGE("%s: Device %s in platform info xml has no alias, no alias set!",
986 __func__, attr[1]);
987 goto done;
988 }
989
990 if (platform_set_snd_device_name(index, attr[3]) < 0) {
991 ALOGE("%s: Device %s, alias %s was not set!",
992 __func__, attr[1], attr[3]);
993 goto done;
994 }
995
996done:
997 return;
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +0530998}
999
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001000static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001001 const XML_Char **attr)
1002{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001003 if (my_data.caller == ACDB_EXTN) {
1004 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1005 section = ACDB_METAINFO_KEY;
1006 } else if (strcmp(tag_name, "param") == 0) {
1007 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1008 ALOGE("param tag only supported with CONFIG_PARAMS section");
1009 return;
1010 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001011
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001012 section_process_fn fn = section_table[section];
1013 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001014 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001015 } else if(my_data.caller == PLATFORM) {
1016 if (strcmp(tag_name, "bit_width_configs") == 0) {
1017 section = BITWIDTH;
1018 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1019 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001020 } else if (strcmp(tag_name, "module_ids") == 0) {
1021 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001022 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1023 section = PCM_ID;
1024 } else if (strcmp(tag_name, "backend_names") == 0) {
1025 section = BACKEND_NAME;
1026 } else if (strcmp(tag_name, "config_params") == 0) {
1027 section = CONFIG_PARAMS;
1028 } else if (strcmp(tag_name, "interface_names") == 0) {
1029 section = INTERFACE_NAME;
1030 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1031 section = GAIN_LEVEL_MAPPING;
1032 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1033 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301034 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1035 section = MICROPHONE_CHARACTERISTIC;
1036 } else if (strcmp(tag_name, "snd_devices") == 0) {
1037 section = SND_DEVICES;
Ethan Chen87c0d772014-09-05 13:01:26 -07001038 } else if (strcmp(tag_name, "device_names") == 0) {
1039 section = DEVICE_NAME;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001040 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001041 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1042 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Ethan Chen87c0d772014-09-05 13:01:26 -07001043 (section != INTERFACE_NAME) && (section != DEVICE_NAME)) {
1044 ALOGE("device tag only supported for acdb/backend names/bitwidth/interface/device names");
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001045 return;
1046 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001047
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001048 /* call into process function for the current section */
1049 section_process_fn fn = section_table[section];
1050 fn(attr);
1051 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1052 if (section != GAIN_LEVEL_MAPPING) {
1053 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1054 return;
1055 }
1056
1057 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1058 fn(attr);
1059 } else if (strcmp(tag_name, "usecase") == 0) {
1060 if (section != PCM_ID) {
1061 ALOGE("usecase tag only supported with PCM_ID section");
1062 return;
1063 }
1064
1065 section_process_fn fn = section_table[PCM_ID];
1066 fn(attr);
1067 } else if (strcmp(tag_name, "param") == 0) {
1068 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1069 ALOGE("param tag only supported with CONFIG_PARAMS section");
1070 return;
1071 }
1072
1073 section_process_fn fn = section_table[section];
1074 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301075 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001076 if (section != MODULE) {
1077 ALOGE("aec tag only supported with MODULE section");
1078 return;
1079 }
1080 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301081 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001082 if (section != MODULE) {
1083 ALOGE("ns tag only supported with MODULE section");
1084 return;
1085 }
1086 section = NS;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301087 } else if (strcmp(tag_name, "microphone") == 0) {
1088 if (section != MICROPHONE_CHARACTERISTIC) {
1089 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1090 return;
1091 }
1092 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1093 fn(attr);
1094 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1095 if (section != SND_DEVICES) {
1096 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1097 return;
1098 }
1099 section = INPUT_SND_DEVICE;
1100 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1101 if (section != INPUT_SND_DEVICE) {
1102 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1103 return;
1104 }
1105 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1106 } else if (strcmp(tag_name, "snd_dev") == 0) {
1107 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1108 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1109 return;
1110 }
1111 section_process_fn fn = section_table[SND_DEV];
1112 fn(attr);
1113 } else if (strcmp(tag_name, "mic_info") == 0) {
1114 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1115 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1116 return;
1117 }
1118 if (in_snd_device == SND_DEVICE_NONE) {
1119 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1120 return;
1121 }
1122 section_process_fn fn = section_table[MIC_INFO];
1123 fn(attr);
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +05301124 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1125 if (section != ROOT) {
1126 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1127 return;
1128 }
1129 section = CUSTOM_MTMX_PARAMS;
1130 section_process_fn fn = section_table[section];
1131 fn(attr);
1132 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1133 if (section != CUSTOM_MTMX_PARAMS) {
1134 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1135 return;
1136 }
1137 section = CUSTOM_MTMX_PARAM_COEFFS;
1138 section_process_fn fn = section_table[section];
1139 fn(attr);
1140 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001141 } else {
1142 ALOGE("%s: unknown caller!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001143 }
Ben Romberger55886882014-01-10 13:49:02 -08001144 return;
1145}
1146
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001147static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001148{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001149 if (strcmp(tag_name, "bit_width_configs") == 0) {
1150 section = ROOT;
1151 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001152 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001153 } else if (strcmp(tag_name, "module_ids") == 0) {
1154 section = ROOT;
1155 } else if (strcmp(tag_name, "aec") == 0) {
1156 section = MODULE;
1157 } else if (strcmp(tag_name, "ns") == 0) {
1158 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001159 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1160 section = ROOT;
1161 } else if (strcmp(tag_name, "backend_names") == 0) {
1162 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001163 } else if (strcmp(tag_name, "config_params") == 0) {
1164 section = ROOT;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001165 if (my_data.caller == PLATFORM) {
1166 platform_set_parameters(my_data.platform, my_data.kvpairs);
1167 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001168 } else if (strcmp(tag_name, "interface_names") == 0) {
1169 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001170 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1171 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301172 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1173 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301174 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1175 section = ROOT;
1176 } else if (strcmp(tag_name, "snd_devices") == 0) {
1177 section = ROOT;
1178 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1179 section = SND_DEVICES;
1180 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1181 section = INPUT_SND_DEVICE;
Dhananjay Kumar2a7f75b2018-12-10 22:26:53 +05301182 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1183 section = ROOT;
1184 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1185 section = CUSTOM_MTMX_PARAMS;
Ethan Chen87c0d772014-09-05 13:01:26 -07001186 } else if (strcmp(tag_name, "device_names") == 0) {
1187 section = ROOT;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001188 }
Ben Romberger55886882014-01-10 13:49:02 -08001189}
1190
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001191int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001192{
1193 XML_Parser parser;
1194 FILE *file;
1195 int ret = 0;
1196 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001197 void *buf;
1198
Helen Zeng6a16ad72014-02-23 22:04:44 -08001199 file = fopen(filename, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001200 section = ROOT;
1201
Ben Romberger55886882014-01-10 13:49:02 -08001202 if (!file) {
1203 ALOGD("%s: Failed to open %s, using defaults.",
Helen Zeng6a16ad72014-02-23 22:04:44 -08001204 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -08001205 ret = -ENODEV;
1206 goto done;
1207 }
1208
1209 parser = XML_ParserCreate(NULL);
1210 if (!parser) {
1211 ALOGE("%s: Failed to create XML parser!", __func__);
1212 ret = -ENODEV;
1213 goto err_close_file;
1214 }
1215
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001216 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001217 my_data.platform = platform;
1218 my_data.kvpairs = str_parms_create();
1219
Ben Romberger55886882014-01-10 13:49:02 -08001220 XML_SetElementHandler(parser, start_tag, end_tag);
1221
1222 while (1) {
1223 buf = XML_GetBuffer(parser, BUF_SIZE);
1224 if (buf == NULL) {
1225 ALOGE("%s: XML_GetBuffer failed", __func__);
1226 ret = -ENOMEM;
1227 goto err_free_parser;
1228 }
1229
1230 bytes_read = fread(buf, 1, BUF_SIZE, file);
1231 if (bytes_read < 0) {
1232 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1233 ret = bytes_read;
1234 goto err_free_parser;
1235 }
1236
1237 if (XML_ParseBuffer(parser, bytes_read,
1238 bytes_read == 0) == XML_STATUS_ERROR) {
1239 ALOGE("%s: XML_ParseBuffer failed, for %s",
Helen Zeng6a16ad72014-02-23 22:04:44 -08001240 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -08001241 ret = -EINVAL;
1242 goto err_free_parser;
1243 }
1244
1245 if (bytes_read == 0)
1246 break;
1247 }
1248
Ben Romberger55886882014-01-10 13:49:02 -08001249err_free_parser:
1250 XML_ParserFree(parser);
1251err_close_file:
1252 fclose(file);
1253done:
1254 return ret;
1255}