blob: 05ee9cd74f69a743da6ccb95969d03f9493e9107 [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Aalique Grahame22e49102018-12-18 14:23:57 -08002 * Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
Ben Romberger55886882014-01-10 13:49:02 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Ben Romberger61764e32014-01-10 13:49:02 -080030#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080031#define LOG_NDDEBUG 0
32
33#include <errno.h>
34#include <stdio.h>
35#include <expat.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080036#include <log/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070037#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080038#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070039#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080040#include "platform_api.h"
41#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070042#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080043
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053044#ifdef DYNAMIC_LOG_ENABLED
45#include <log_xml_parser.h>
46#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
47#include <log_utils.h>
48#endif
49
Ben Romberger55886882014-01-10 13:49:02 -080050#define BUF_SIZE 1024
51
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070052typedef enum {
53 ROOT,
54 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070055 MODULE,
56 AEC,
57 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070058 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070059 PCM_ID,
60 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080061 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070062 CONFIG_PARAMS,
Aalique Grahame22e49102018-12-18 14:23:57 -080063 OPERATOR_SPECIFIC,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070064 GAIN_LEVEL_MAPPING,
Aalique Grahame22e49102018-12-18 14:23:57 -080065 APP_TYPE,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053066 ACDB_METAINFO_KEY,
Naresh Tannirudcb47c52018-06-25 16:23:32 +053067 MICROPHONE_CHARACTERISTIC,
68 SND_DEVICES,
69 INPUT_SND_DEVICE,
70 INPUT_SND_DEVICE_TO_MIC_MAPPING,
71 SND_DEV,
72 MIC_INFO,
Dhananjay Kumar429eb452018-12-10 22:26:53 +053073 CUSTOM_MTMX_PARAMS,
74 CUSTOM_MTMX_PARAM_COEFFS,
Carter Hsu32a62362018-10-15 15:01:42 -070075 EXTERNAL_DEVICE_SPECIFIC,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070076} section_t;
77
78typedef void (* section_process_fn)(const XML_Char **attr);
79
80static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070081static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
82static void process_effect_aec(const XML_Char **attr);
83static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070084static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070085static void process_pcm_id(const XML_Char **attr);
86static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080087static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070088static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070089static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080090static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070091static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080092static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053093static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053094static void process_microphone_characteristic(const XML_Char **attr);
95static void process_snd_dev(const XML_Char **attr);
96static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +053097static void process_custom_mtmx_params(const XML_Char **attr);
98static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Carter Hsu32a62362018-10-15 15:01:42 -070099static void process_external_dev(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700100
101static section_process_fn section_table[] = {
102 [ROOT] = process_root,
103 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700104 [AEC] = process_effect_aec,
105 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700106 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700107 [PCM_ID] = process_pcm_id,
108 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800109 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700110 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800111 [OPERATOR_SPECIFIC] = process_operator_specific,
112 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700113 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530114 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530115 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
116 [SND_DEV] = process_snd_dev,
117 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530118 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
119 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Carter Hsu32a62362018-10-15 15:01:42 -0700120 [EXTERNAL_DEVICE_SPECIFIC] = process_external_dev,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700121};
122
123static section_t section;
124
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700125struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700126 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700127 void *platform;
128 struct str_parms *kvpairs;
129};
130
131static struct platform_info my_data;
132
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530133
134struct audio_string_to_enum {
135 const char* name;
136 unsigned int value;
137};
138
139static snd_device_t in_snd_device;
140
141static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
142 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
143 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
144 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
145 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
146};
147
148static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
149 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
150 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
151 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
152 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
153 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
154 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
155};
156
157static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
158 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
159 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
160 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
161};
162
163static const struct audio_string_to_enum device_in_types[] = {
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
167 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
188 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
189 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
190 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
191};
192
193enum {
194 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
195 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
196 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
197 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
198 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
199 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
200 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
201 | ORIENTATION) | GEOMETRIC_LOCATION) */
202};
203
204static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
205 int32_t len, unsigned int *value)
206{
207 if (table == NULL) {
208 ALOGE("%s: table is NULL", __func__);
209 return false;
210 }
211
212 if (name == NULL) {
213 ALOGE("null key");
214 return false;
215 }
216
217 for (int i = 0; i < len; i++) {
218 if (!strcmp(table[i].name, name)) {
219 *value = table[i].value;
220 return true;
221 }
222 }
223 return false;
224}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530225
226static struct audio_custom_mtmx_params_info mtmx_params_info;
227
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700228/*
229 * <audio_platform_info>
230 * <acdb_ids>
231 * <device name="???" acdb_id="???"/>
232 * ...
233 * ...
234 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700235 * <module_ids>
236 * <device name="???" module_id="???"/>
237 * ...
238 * ...
239 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700240 * <backend_names>
241 * <device name="???" backend="???"/>
242 * ...
243 * ...
244 * </backend_names>
245 * <pcm_ids>
246 * <usecase name="???" type="in/out" id="???"/>
247 * ...
248 * ...
249 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800250 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530251 * <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 -0800252 * ...
253 * ...
254 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700255 * <config_params>
256 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800257 * <param key="operator_info" value="tmus;aa;bb;cc"/>
258 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700259 * ...
260 * ...
261 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800262 *
263 * <operator_specific>
264 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
265 * ...
266 * ...
267 * </operator_specific>
268 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700269 * </audio_platform_info>
270 */
271
272static void process_root(const XML_Char **attr __unused)
273{
274}
275
276/* mapping from usecase to pcm dev id */
277static void process_pcm_id(const XML_Char **attr)
278{
279 int index;
280
281 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700282 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700283 goto done;
284 }
285
286 index = platform_get_usecase_index((char *)attr[1]);
287 if (index < 0) {
288 ALOGE("%s: usecase %s not found!",
289 __func__, attr[1]);
290 goto done;
291 }
292
293 if (strcmp(attr[2], "type") != 0) {
294 ALOGE("%s: usecase type not mentioned", __func__);
295 goto done;
296 }
297
298 int type = -1;
299
300 if (!strcasecmp((char *)attr[3], "in")) {
301 type = 1;
302 } else if (!strcasecmp((char *)attr[3], "out")) {
303 type = 0;
304 } else {
305 ALOGE("%s: type must be IN or OUT", __func__);
306 goto done;
307 }
308
309 if (strcmp(attr[4], "id") != 0) {
310 ALOGE("%s: usecase id not mentioned", __func__);
311 goto done;
312 }
313
314 int id = atoi((char *)attr[5]);
315
316 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
317 ALOGE("%s: usecase %s type %d id %d was not set!",
318 __func__, attr[1], type, id);
319 goto done;
320 }
321
322done:
323 return;
324}
325
326/* backend to be used for a device */
327static void process_backend_name(const XML_Char **attr)
328{
329 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530330 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530331 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700332
333 if (strcmp(attr[0], "name") != 0) {
334 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
335 goto done;
336 }
337
338 index = platform_get_snd_device_index((char *)attr[1]);
339 if (index < 0) {
340 ALOGE("%s: Device %s not found, no ACDB ID set!",
341 __func__, attr[1]);
342 goto done;
343 }
344
345 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530346 if (strcmp(attr[2], "interface") == 0)
347 hw_interface = (char *)attr[3];
348 } else {
349 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700350 }
351
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530352 if (attr[4] != NULL) {
353 if (strcmp(attr[4], "interface") != 0) {
354 hw_interface = NULL;
355 } else {
356 hw_interface = (char *)attr[5];
357 }
358 }
359
Ashish Jaind150d4c2017-02-03 18:44:34 +0530360 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700361 ALOGE("%s: Device %s backend %s was not set!",
362 __func__, attr[1], attr[3]);
363 goto done;
364 }
365
366done:
367 return;
368}
369
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700370static void process_gain_db_to_level_map(const XML_Char **attr)
371{
372 struct amp_db_and_gain_table tbl_entry;
373
374 if ((strcmp(attr[0], "db") != 0) ||
375 (strcmp(attr[2], "level") != 0)) {
376 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
377 __func__, attr[0], attr[2]);
378 goto done;
379 }
380
381 tbl_entry.db = atof(attr[1]);
382 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
383 tbl_entry.level = atoi(attr[3]);
384
Aalique Grahame22e49102018-12-18 14:23:57 -0800385 //custome level should be > 0. Level 0 is fixed for default
386 CHECK(tbl_entry.level > 0);
387
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700388 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
389 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
390 platform_add_gain_level_mapping(&tbl_entry);
391
392done:
393 return;
394}
395
396
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700397static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800398{
Ben Romberger61764e32014-01-10 13:49:02 -0800399 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800400
Ben Romberger61764e32014-01-10 13:49:02 -0800401 if (strcmp(attr[0], "name") != 0) {
402 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800403 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800404 }
Ben Romberger55886882014-01-10 13:49:02 -0800405
Ben Romberger61764e32014-01-10 13:49:02 -0800406 index = platform_get_snd_device_index((char *)attr[1]);
407 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800408 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
409 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800410 goto done;
411 }
412
413 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800414 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
415 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800416 goto done;
417 }
418
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700419 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
420 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800421 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800422 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800423 }
Ben Romberger55886882014-01-10 13:49:02 -0800424
Ben Romberger55886882014-01-10 13:49:02 -0800425done:
426 return;
427}
428
Aalique Grahame22e49102018-12-18 14:23:57 -0800429static void process_operator_specific(const XML_Char **attr)
430{
431 snd_device_t snd_device = SND_DEVICE_NONE;
432
433 if (strcmp(attr[0], "name") != 0) {
434 ALOGE("%s: 'name' not found", __func__);
435 goto done;
436 }
437
438 snd_device = platform_get_snd_device_index((char *)attr[1]);
439 if (snd_device < 0) {
440 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
441 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
442 goto done;
443 }
444
445 if (strcmp(attr[2], "operator") != 0) {
446 ALOGE("%s: 'operator' not found", __func__);
447 goto done;
448 }
449
450 if (strcmp(attr[4], "mixer_path") != 0) {
451 ALOGE("%s: 'mixer_path' not found", __func__);
452 goto done;
453 }
454
455 if (strcmp(attr[6], "acdb_id") != 0) {
456 ALOGE("%s: 'acdb_id' not found", __func__);
457 goto done;
458 }
459
460 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
461
462done:
463 return;
464}
465
Carter Hsu32a62362018-10-15 15:01:42 -0700466static void process_external_dev(const XML_Char **attr)
467{
468 snd_device_t snd_device = SND_DEVICE_NONE;
469
470 if (strcmp(attr[0], "name") != 0) {
471 ALOGE("%s: 'name' not found", __func__);
472 goto done;
473 }
474
475 snd_device = platform_get_snd_device_index((char *)attr[1]);
476 if (snd_device < 0) {
477 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
478 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
479 goto done;
480 }
481
482 if (strcmp(attr[2], "usbid") != 0) {
483 ALOGE("%s: 'usbid' not found", __func__);
484 goto done;
485 }
486
487 if (strcmp(attr[4], "acdb_id") != 0) {
488 ALOGE("%s: 'acdb_id' not found", __func__);
489 goto done;
490 }
491
492 platform_add_external_specific_device(snd_device, (char *)attr[3], atoi((char *)attr[5]));
493
494done:
495 return;
496}
497
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700498static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
499{
500 int index;
501 struct audio_effect_config effect_config;
502
503 if (strcmp(attr[0], "name") != 0) {
504 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
505 goto done;
506 }
507
508 index = platform_get_snd_device_index((char *)attr[1]);
509 if (index < 0) {
510 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
511 __func__, attr[1]);
512 goto done;
513 }
514
515 if (strcmp(attr[2], "module_id") != 0) {
516 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
517 __func__, attr[2]);
518 goto done;
519 }
520
521 if (strcmp(attr[4], "instance_id") != 0) {
522 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
523 __func__, attr[4]);
524 goto done;
525 }
526
527 if (strcmp(attr[6], "param_id") != 0) {
528 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
529 __func__, attr[6]);
530 goto done;
531 }
532
533 if (strcmp(attr[8], "param_value") != 0) {
534 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
535 __func__, attr[8]);
536 goto done;
537 }
538
539 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
540 strtol((char *)attr[5], NULL, 0),
541 strtol((char *)attr[7], NULL, 0),
542 strtol((char *)attr[9], NULL, 0)};
543
544
545 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
546 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
547 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
548 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
549 strtol((char *)attr[9], NULL, 0));
550 goto done;
551 }
552
553done:
554 return;
555}
556
557static void process_effect_aec(const XML_Char **attr)
558{
559 process_audio_effect(attr, EFFECT_AEC);
560 return;
561}
562
563static void process_effect_ns(const XML_Char **attr)
564{
565 process_audio_effect(attr, EFFECT_NS);
566 return;
567}
568
Amit Shekhar5a39c912014-10-14 15:39:30 -0700569static void process_bit_width(const XML_Char **attr)
570{
571 int index;
572
573 if (strcmp(attr[0], "name") != 0) {
574 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
575 goto done;
576 }
577
578 index = platform_get_snd_device_index((char *)attr[1]);
579 if (index < 0) {
580 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
581 __func__, attr[1]);
582 goto done;
583 }
584
585 if (strcmp(attr[2], "bit_width") != 0) {
586 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
587 __func__, attr[1]);
588 goto done;
589 }
590
591 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
592 ALOGE("%s: Device %s, ACDB ID %d was not set!",
593 __func__, attr[1], atoi((char *)attr[3]));
594 goto done;
595 }
596
597done:
598 return;
599}
600
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800601static void process_interface_name(const XML_Char **attr)
602{
603 int ret;
604
605 if (strcmp(attr[0], "name") != 0) {
606 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
607
608 goto done;
609 }
610
611 if (strcmp(attr[2], "interface") != 0) {
612 ALOGE("%s: Device %s has no Audio Interface set!",
613 __func__, attr[1]);
614
615 goto done;
616 }
617
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530618 if (strcmp(attr[4], "codec_type") != 0) {
619 ALOGE("%s: Device %s has no codec type set!",
620 __func__, attr[1]);
621
622 goto done;
623 }
624
625 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
626 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800627 if (ret < 0) {
628 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800629 goto done;
630 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800631
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800632done:
633 return;
634}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530635
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700636static void process_config_params(const XML_Char **attr)
637{
638 if (strcmp(attr[0], "key") != 0) {
639 ALOGE("%s: 'key' not found", __func__);
640 goto done;
641 }
642
643 if (strcmp(attr[2], "value") != 0) {
644 ALOGE("%s: 'value' not found", __func__);
645 goto done;
646 }
647
648 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
649done:
650 return;
651}
652
Aalique Grahame22e49102018-12-18 14:23:57 -0800653static void process_app_type(const XML_Char **attr)
654{
655 if (strcmp(attr[0], "uc_type")) {
656 ALOGE("%s: uc_type not found", __func__);
657 goto done;
658 }
659
660 if (strcmp(attr[2], "mode")) {
661 ALOGE("%s: mode not found", __func__);
662 goto done;
663 }
664
665 if (strcmp(attr[4], "bit_width")) {
666 ALOGE("%s: bit_width not found", __func__);
667 goto done;
668 }
669
670 if (strcmp(attr[6], "id")) {
671 ALOGE("%s: id not found", __func__);
672 goto done;
673 }
674
675 if (strcmp(attr[8], "max_rate")) {
676 ALOGE("%s: max rate not found", __func__);
677 goto done;
678 }
679
680 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
681 atoi(attr[9]));
682done:
683 return;
684}
685
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530686static void process_microphone_characteristic(const XML_Char **attr) {
687 struct audio_microphone_characteristic_t microphone;
688 uint32_t curIdx = 0;
689
690 if (strcmp(attr[curIdx++], "valid_mask")) {
691 ALOGE("%s: valid_mask not found", __func__);
692 goto done;
693 }
694 uint32_t valid_mask = atoi(attr[curIdx++]);
695
696 if (strcmp(attr[curIdx++], "device_id")) {
697 ALOGE("%s: device_id not found", __func__);
698 goto done;
699 }
700 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
701 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
702 goto done;
703 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530704 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530705
706 if (strcmp(attr[curIdx++], "type")) {
707 ALOGE("%s: device not found", __func__);
708 goto done;
709 }
710 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
711 ARRAY_SIZE(device_in_types), &microphone.device)) {
712 ALOGE("%s: type %s in %s not found!",
713 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
714 goto done;
715 }
716
717 if (strcmp(attr[curIdx++], "address")) {
718 ALOGE("%s: address not found", __func__);
719 goto done;
720 }
721 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
722 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
723 goto done;
724 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530725 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530726 if (strlen(microphone.address) == 0) {
727 // If the address is empty, populate the address according to device type.
728 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530729 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530730 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530731 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530732 }
733 }
734
735 if (strcmp(attr[curIdx++], "location")) {
736 ALOGE("%s: location not found", __func__);
737 goto done;
738 }
739 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
740 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
741 ALOGE("%s: location %s in %s not found!",
742 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
743 goto done;
744 }
745
746 if (strcmp(attr[curIdx++], "group")) {
747 ALOGE("%s: group not found", __func__);
748 goto done;
749 }
750 microphone.group = atoi(attr[curIdx++]);
751
752 if (strcmp(attr[curIdx++], "index_in_the_group")) {
753 ALOGE("%s: index_in_the_group not found", __func__);
754 goto done;
755 }
756 microphone.index_in_the_group = atoi(attr[curIdx++]);
757
758 if (strcmp(attr[curIdx++], "directionality")) {
759 ALOGE("%s: directionality not found", __func__);
760 goto done;
761 }
762 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
763 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
764 ALOGE("%s: directionality %s in %s not found!",
765 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
766 goto done;
767 }
768
769 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
770 ALOGE("%s: num_frequency_responses not found", __func__);
771 goto done;
772 }
773 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530774 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530775 ALOGE("%s: num_frequency_responses is too large", __func__);
776 goto done;
777 }
778 if (microphone.num_frequency_responses > 0) {
779 if (strcmp(attr[curIdx++], "frequencies")) {
780 ALOGE("%s: frequencies not found", __func__);
781 goto done;
782 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530783 char *context = NULL;
784 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530785 uint32_t num_frequencies = 0;
786 while (token) {
787 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800788 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530789 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530790 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530791 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530792 }
793
794 if (strcmp(attr[curIdx++], "responses")) {
795 ALOGE("%s: responses not found", __func__);
796 goto done;
797 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530798 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530799 uint32_t num_responses = 0;
800 while (token) {
801 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800802 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530803 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530804 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530805 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530806 }
807
808 if (num_frequencies != num_responses
809 || num_frequencies != microphone.num_frequency_responses) {
810 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
811 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
812 goto done;
813 }
814 }
815
816 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
817 if (strcmp(attr[curIdx++], "sensitivity")) {
818 ALOGE("%s: sensitivity not found", __func__);
819 goto done;
820 }
821 microphone.sensitivity = atof(attr[curIdx++]);
822 } else {
823 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
824 }
825
826 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
827 if (strcmp(attr[curIdx++], "max_spl")) {
828 ALOGE("%s: max_spl not found", __func__);
829 goto done;
830 }
831 microphone.max_spl = atof(attr[curIdx++]);
832 } else {
833 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
834 }
835
836 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
837 if (strcmp(attr[curIdx++], "min_spl")) {
838 ALOGE("%s: min_spl not found", __func__);
839 goto done;
840 }
841 microphone.min_spl = atof(attr[curIdx++]);
842 } else {
843 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
844 }
845
846 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
847 if (strcmp(attr[curIdx++], "orientation")) {
848 ALOGE("%s: orientation not found", __func__);
849 goto done;
850 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530851 char *context = NULL;
852 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530853 float orientation[3];
854 uint32_t idx = 0;
855 while (token) {
856 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800857 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530858 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530859 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530860 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530861 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530862 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530863 ALOGE("%s: orientation invalid", __func__);
864 goto done;
865 }
866 microphone.orientation.x = orientation[0];
867 microphone.orientation.y = orientation[1];
868 microphone.orientation.z = orientation[2];
869 } else {
870 microphone.orientation.x = 0.0f;
871 microphone.orientation.y = 0.0f;
872 microphone.orientation.z = 0.0f;
873 }
874
875 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
876 if (strcmp(attr[curIdx++], "geometric_location")) {
877 ALOGE("%s: geometric_location not found", __func__);
878 goto done;
879 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530880 char *context = NULL;
881 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530882 float geometric_location[3];
883 uint32_t idx = 0;
884 while (token) {
885 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800886 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530887 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530888 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530889 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530890 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530891 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530892 ALOGE("%s: geometric_location invalid", __func__);
893 goto done;
894 }
895 microphone.geometric_location.x = geometric_location[0];
896 microphone.geometric_location.y = geometric_location[1];
897 microphone.geometric_location.z = geometric_location[2];
898 } else {
899 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
900 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
901 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
902 }
903
904 platform_set_microphone_characteristic(my_data.platform, microphone);
905done:
906 return;
907}
908
909static void process_snd_dev(const XML_Char **attr)
910{
911 uint32_t curIdx = 0;
912 in_snd_device = SND_DEVICE_NONE;
913
914 if (strcmp(attr[curIdx++], "in_snd_device")) {
915 ALOGE("%s: snd_device not found", __func__);
916 return;
917 }
918 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
919 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
920 in_snd_device >= SND_DEVICE_IN_END) {
921 ALOGE("%s: Sound device not valid", __func__);
922 in_snd_device = SND_DEVICE_NONE;
923 }
924
925 return;
926}
927
928static void process_mic_info(const XML_Char **attr)
929{
930 uint32_t curIdx = 0;
931 struct mic_info microphone;
932
933 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
934 sizeof(microphone.channel_mapping));
935
936 if (strcmp(attr[curIdx++], "mic_device_id")) {
937 ALOGE("%s: mic_device_id not found", __func__);
938 goto on_error;
939 }
940 strlcpy(microphone.device_id,
941 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
942
943 if (strcmp(attr[curIdx++], "channel_mapping")) {
944 ALOGE("%s: channel_mapping not found", __func__);
945 goto on_error;
946 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530947 char *context = NULL;
948 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530949 uint32_t idx = 0;
950 while (token) {
951 if (!find_enum_by_string(mic_channel_mapping, token,
952 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
953 &microphone.channel_mapping[idx++])) {
954 ALOGE("%s: channel_mapping %s in %s not found!",
955 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
956 goto on_error;
957 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530958 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530959 }
960 microphone.channel_count = idx;
961
962 platform_set_microphone_map(my_data.platform, in_snd_device,
963 &microphone);
964 return;
965on_error:
966 in_snd_device = SND_DEVICE_NONE;
967 return;
968}
969
970
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530971/* process acdb meta info key value */
972static void process_acdb_metainfo_key(const XML_Char **attr)
973{
974 if (strcmp(attr[0], "name") != 0) {
975 ALOGE("%s: 'name' not found", __func__);
976 goto done;
977 }
978
979 if (strcmp(attr[2], "value") != 0) {
980 ALOGE("%s: 'value' not found", __func__);
981 goto done;
982 }
983
984 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700985 switch(my_data.caller) {
986 case ACDB_EXTN:
987 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
988 ALOGE("%s: key %d was not set!", __func__, key);
989 goto done;
990 }
991 break;
992 case PLATFORM:
993 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
994 ALOGE("%s: key %d was not set!", __func__, key);
995 goto done;
996 }
997 break;
998 default:
999 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301000 }
1001
1002done:
1003 return;
1004}
1005
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301006static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
1007{
1008 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
1009 uint32_t ip_channels = 0, op_channels = 0;
1010 char *context = NULL, *ch_coeff_value = NULL;
1011 struct audio_custom_mtmx_params *mtmx_params = NULL;
1012
1013 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
1014 ALOGE("%s: 'out_channel_index' not found", __func__);
1015 return;
1016 }
1017 out_ch_idx = atoi((char *)attr[attr_idx++]);
1018
1019 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
1020 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
1021 return;
1022 }
1023
1024 if (strcmp(attr[attr_idx++], "values") != 0) {
1025 ALOGE("%s: 'values' not found", __func__);
1026 return;
1027 }
1028 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
1029 &mtmx_params_info);
1030 if (mtmx_params == NULL) {
1031 ALOGE("%s: mtmx params with given param info, not found", __func__);
1032 return;
1033 }
1034 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1035 ip_channels = mtmx_params->info.ip_channels;
1036 op_channels = mtmx_params->info.op_channels;
1037 while(ch_coeff_value && ch_coeff_count < op_channels) {
1038 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1039 = atoi(ch_coeff_value);
1040 ch_coeff_value = strtok_r(NULL, " ", &context);
1041 }
1042 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1043 ch_coeff_value != NULL)
1044 ALOGE("%s: invalid/malformed coefficient values", __func__);
1045}
1046
1047static void process_custom_mtmx_params(const XML_Char **attr)
1048{
1049 int attr_idx = 0;
1050
1051 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1052 ALOGE("%s: 'param_id' not found", __func__);
1053 return;
1054 }
1055 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1056
1057 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1058 ALOGE("%s: 'in_channel_count' not found", __func__);
1059 return;
1060 }
1061 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1062
1063 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1064 ALOGE("%s: 'out_channel_count' not found", __func__);
1065 return;
1066 }
1067 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1068
1069 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1070 ALOGE("%s: 'usecase' not found", __func__);
1071 return;
1072 }
1073 mtmx_params_info.usecase_id = platform_get_usecase_index((char *)attr[attr_idx++]);
1074
1075 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1076 ALOGE("%s: 'snd_device' not found", __func__);
1077 return;
1078 }
1079 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
1080 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1081
1082}
1083
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001084static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001085 const XML_Char **attr)
1086{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001087 if (my_data.caller == ACDB_EXTN) {
1088 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1089 section = ACDB_METAINFO_KEY;
1090 } else if (strcmp(tag_name, "param") == 0) {
1091 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1092 ALOGE("param tag only supported with CONFIG_PARAMS section");
1093 return;
1094 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001095
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001096 section_process_fn fn = section_table[section];
1097 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001098 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001099 } else if(my_data.caller == PLATFORM) {
1100 if (strcmp(tag_name, "bit_width_configs") == 0) {
1101 section = BITWIDTH;
1102 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1103 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001104 } else if (strcmp(tag_name, "module_ids") == 0) {
1105 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001106 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1107 section = PCM_ID;
1108 } else if (strcmp(tag_name, "backend_names") == 0) {
1109 section = BACKEND_NAME;
1110 } else if (strcmp(tag_name, "config_params") == 0) {
1111 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001112 } else if (strcmp(tag_name, "operator_specific") == 0) {
1113 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001114 } else if (strcmp(tag_name, "interface_names") == 0) {
1115 section = INTERFACE_NAME;
1116 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1117 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001118 } else if (strcmp(tag_name, "app_types") == 0) {
1119 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001120 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1121 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301122 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1123 section = MICROPHONE_CHARACTERISTIC;
1124 } else if (strcmp(tag_name, "snd_devices") == 0) {
1125 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001126 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001127 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1128 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001129 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001130 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1131 return;
1132 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001133
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001134 /* call into process function for the current section */
1135 section_process_fn fn = section_table[section];
1136 fn(attr);
1137 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1138 if (section != GAIN_LEVEL_MAPPING) {
1139 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1140 return;
1141 }
1142
1143 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1144 fn(attr);
1145 } else if (strcmp(tag_name, "usecase") == 0) {
1146 if (section != PCM_ID) {
1147 ALOGE("usecase tag only supported with PCM_ID section");
1148 return;
1149 }
1150
1151 section_process_fn fn = section_table[PCM_ID];
1152 fn(attr);
1153 } else if (strcmp(tag_name, "param") == 0) {
1154 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1155 ALOGE("param tag only supported with CONFIG_PARAMS section");
1156 return;
1157 }
1158
1159 section_process_fn fn = section_table[section];
1160 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301161 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001162 if (section != MODULE) {
1163 ALOGE("aec tag only supported with MODULE section");
1164 return;
1165 }
1166 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301167 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001168 if (section != MODULE) {
1169 ALOGE("ns tag only supported with MODULE section");
1170 return;
1171 }
1172 section = NS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001173 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1174 if (section != GAIN_LEVEL_MAPPING) {
1175 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1176 return;
1177 }
1178
1179 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1180 fn(attr);
1181 } else if (!strcmp(tag_name, "app")) {
1182 if (section != APP_TYPE) {
1183 ALOGE("app tag only valid in section APP_TYPE");
1184 return;
1185 }
1186
1187 section_process_fn fn = section_table[APP_TYPE];
1188 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301189 } else if (strcmp(tag_name, "microphone") == 0) {
1190 if (section != MICROPHONE_CHARACTERISTIC) {
1191 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1192 return;
1193 }
1194 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1195 fn(attr);
1196 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1197 if (section != SND_DEVICES) {
1198 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1199 return;
1200 }
1201 section = INPUT_SND_DEVICE;
1202 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1203 if (section != INPUT_SND_DEVICE) {
1204 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1205 return;
1206 }
1207 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1208 } else if (strcmp(tag_name, "snd_dev") == 0) {
1209 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1210 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1211 return;
1212 }
1213 section_process_fn fn = section_table[SND_DEV];
1214 fn(attr);
1215 } else if (strcmp(tag_name, "mic_info") == 0) {
1216 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1217 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1218 return;
1219 }
1220 if (in_snd_device == SND_DEVICE_NONE) {
1221 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1222 return;
1223 }
1224 section_process_fn fn = section_table[MIC_INFO];
1225 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301226 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1227 if (section != ROOT) {
1228 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1229 return;
1230 }
1231 section = CUSTOM_MTMX_PARAMS;
1232 section_process_fn fn = section_table[section];
1233 fn(attr);
1234 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1235 if (section != CUSTOM_MTMX_PARAMS) {
1236 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1237 return;
1238 }
1239 section = CUSTOM_MTMX_PARAM_COEFFS;
1240 section_process_fn fn = section_table[section];
1241 fn(attr);
Carter Hsu32a62362018-10-15 15:01:42 -07001242 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1243 section = EXTERNAL_DEVICE_SPECIFIC;
1244 } else if (strcmp(tag_name, "ext_device") == 0) {
1245 section_process_fn fn = section_table[section];
1246 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301247 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001248 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001249 if(strcmp(tag_name, "config_params") == 0) {
1250 section = CONFIG_PARAMS;
1251 } else if (strcmp(tag_name, "param") == 0) {
1252 if (section != CONFIG_PARAMS) {
1253 ALOGE("param tag only supported with CONFIG_PARAMS section");
1254 return;
1255 }
1256
1257 section_process_fn fn = section_table[section];
1258 fn(attr);
1259 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001260 }
Ben Romberger55886882014-01-10 13:49:02 -08001261 return;
1262}
1263
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001264static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001265{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001266 if (strcmp(tag_name, "bit_width_configs") == 0) {
1267 section = ROOT;
1268 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001269 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001270 } else if (strcmp(tag_name, "module_ids") == 0) {
1271 section = ROOT;
1272 } else if (strcmp(tag_name, "aec") == 0) {
1273 section = MODULE;
1274 } else if (strcmp(tag_name, "ns") == 0) {
1275 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001276 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1277 section = ROOT;
1278 } else if (strcmp(tag_name, "backend_names") == 0) {
1279 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001280 } else if (strcmp(tag_name, "config_params") == 0) {
1281 section = ROOT;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001282 if (my_data.caller == PLATFORM) {
1283 platform_set_parameters(my_data.platform, my_data.kvpairs);
1284 }
Aalique Grahame22e49102018-12-18 14:23:57 -08001285 } else if (strcmp(tag_name, "operator_specific") == 0) {
1286 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001287 } else if (strcmp(tag_name, "interface_names") == 0) {
1288 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001289 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1290 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001291 } else if (strcmp(tag_name, "app_types") == 0) {
1292 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301293 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1294 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301295 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1296 section = ROOT;
1297 } else if (strcmp(tag_name, "snd_devices") == 0) {
1298 section = ROOT;
Carter Hsu32a62362018-10-15 15:01:42 -07001299 } else if (strcmp(tag_name, "external_specific_dev") == 0) {
1300 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301301 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1302 section = SND_DEVICES;
1303 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1304 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301305 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1306 section = ROOT;
1307 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1308 section = CUSTOM_MTMX_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001309 }
Ben Romberger55886882014-01-10 13:49:02 -08001310}
1311
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001312int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001313{
1314 XML_Parser parser;
1315 FILE *file;
1316 int ret = 0;
1317 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001318 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001319 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001320
Aalique Grahame22e49102018-12-18 14:23:57 -08001321 if (filename == NULL)
1322 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1323 MIXER_PATH_MAX_LENGTH);
1324 else
1325 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1326
1327 ALOGV("%s: platform info file name is %s", __func__,
1328 platform_info_file_name);
1329
1330 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001331 section = ROOT;
1332
Ben Romberger55886882014-01-10 13:49:02 -08001333 if (!file) {
1334 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001335 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001336 ret = -ENODEV;
1337 goto done;
1338 }
1339
1340 parser = XML_ParserCreate(NULL);
1341 if (!parser) {
1342 ALOGE("%s: Failed to create XML parser!", __func__);
1343 ret = -ENODEV;
1344 goto err_close_file;
1345 }
1346
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001347 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001348 my_data.platform = platform;
1349 my_data.kvpairs = str_parms_create();
1350
Ben Romberger55886882014-01-10 13:49:02 -08001351 XML_SetElementHandler(parser, start_tag, end_tag);
1352
1353 while (1) {
1354 buf = XML_GetBuffer(parser, BUF_SIZE);
1355 if (buf == NULL) {
1356 ALOGE("%s: XML_GetBuffer failed", __func__);
1357 ret = -ENOMEM;
1358 goto err_free_parser;
1359 }
1360
1361 bytes_read = fread(buf, 1, BUF_SIZE, file);
1362 if (bytes_read < 0) {
1363 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1364 ret = bytes_read;
1365 goto err_free_parser;
1366 }
1367
1368 if (XML_ParseBuffer(parser, bytes_read,
1369 bytes_read == 0) == XML_STATUS_ERROR) {
1370 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001371 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001372 ret = -EINVAL;
1373 goto err_free_parser;
1374 }
1375
1376 if (bytes_read == 0)
1377 break;
1378 }
1379
Ben Romberger55886882014-01-10 13:49:02 -08001380err_free_parser:
1381 XML_ParserFree(parser);
1382err_close_file:
1383 fclose(file);
1384done:
1385 return ret;
1386}