blob: da0223e1f88a62b95ef77f4e521bb13ec5b83776 [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,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070075} section_t;
76
77typedef void (* section_process_fn)(const XML_Char **attr);
78
79static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070080static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
81static void process_effect_aec(const XML_Char **attr);
82static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070083static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070084static void process_pcm_id(const XML_Char **attr);
85static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080086static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070087static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070088static void process_root(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080089static void process_operator_specific(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070090static void process_gain_db_to_level_map(const XML_Char **attr);
Aalique Grahame22e49102018-12-18 14:23:57 -080091static void process_app_type(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053092static void process_acdb_metainfo_key(const XML_Char **attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053093static void process_microphone_characteristic(const XML_Char **attr);
94static void process_snd_dev(const XML_Char **attr);
95static void process_mic_info(const XML_Char **attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +053096static void process_custom_mtmx_params(const XML_Char **attr);
97static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070098
99static section_process_fn section_table[] = {
100 [ROOT] = process_root,
101 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700102 [AEC] = process_effect_aec,
103 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -0700104 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700105 [PCM_ID] = process_pcm_id,
106 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800107 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700108 [CONFIG_PARAMS] = process_config_params,
Aalique Grahame22e49102018-12-18 14:23:57 -0800109 [OPERATOR_SPECIFIC] = process_operator_specific,
110 [APP_TYPE] = process_app_type,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700111 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530112 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530113 [MICROPHONE_CHARACTERISTIC] = process_microphone_characteristic,
114 [SND_DEV] = process_snd_dev,
115 [MIC_INFO] = process_mic_info,
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530116 [CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
117 [CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700118};
119
120static section_t section;
121
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700122struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700123 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700124 void *platform;
125 struct str_parms *kvpairs;
126};
127
128static struct platform_info my_data;
129
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530130
131struct audio_string_to_enum {
132 const char* name;
133 unsigned int value;
134};
135
136static snd_device_t in_snd_device;
137
138static const struct audio_string_to_enum mic_locations[AUDIO_MICROPHONE_LOCATION_CNT] = {
139 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_UNKNOWN),
140 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY),
141 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE),
142 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_LOCATION_PERIPHERAL),
143};
144
145static const struct audio_string_to_enum mic_directionalities[AUDIO_MICROPHONE_DIRECTIONALITY_CNT] = {
146 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_OMNI),
147 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL),
148 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN),
149 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID),
150 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID),
151 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID),
152};
153
154static const struct audio_string_to_enum mic_channel_mapping[AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT] = {
155 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED),
156 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT),
157 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED),
158};
159
160static const struct audio_string_to_enum device_in_types[] = {
161 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
162 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
163 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
164 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
165 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
166 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
167 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
168 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
169 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
170 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
171 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
172 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
173 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
174 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
175 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
176 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
177 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
178 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
179 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
180 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
181 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
182 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
183 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
184 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
185 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
186 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_BLE),
187 AUDIO_MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
188};
189
190enum {
191 AUDIO_MICROPHONE_CHARACTERISTIC_NONE = 0u, // 0x0
192 AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY = 1u, // 0x1
193 AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL = 2u, // 0x2
194 AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL = 4u, // 0x4
195 AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION = 8u, // 0x8
196 AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION = 16u, // 0x10
197 AUDIO_MICROPHONE_CHARACTERISTIC_ALL = 31u, /* ((((SENSITIVITY | MAX_SPL) | MIN_SPL)
198 | ORIENTATION) | GEOMETRIC_LOCATION) */
199};
200
201static bool find_enum_by_string(const struct audio_string_to_enum * table, const char * name,
202 int32_t len, unsigned int *value)
203{
204 if (table == NULL) {
205 ALOGE("%s: table is NULL", __func__);
206 return false;
207 }
208
209 if (name == NULL) {
210 ALOGE("null key");
211 return false;
212 }
213
214 for (int i = 0; i < len; i++) {
215 if (!strcmp(table[i].name, name)) {
216 *value = table[i].value;
217 return true;
218 }
219 }
220 return false;
221}
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530222
223static struct audio_custom_mtmx_params_info mtmx_params_info;
224
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700225/*
226 * <audio_platform_info>
227 * <acdb_ids>
228 * <device name="???" acdb_id="???"/>
229 * ...
230 * ...
231 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700232 * <module_ids>
233 * <device name="???" module_id="???"/>
234 * ...
235 * ...
236 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700237 * <backend_names>
238 * <device name="???" backend="???"/>
239 * ...
240 * ...
241 * </backend_names>
242 * <pcm_ids>
243 * <usecase name="???" type="in/out" id="???"/>
244 * ...
245 * ...
246 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800247 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530248 * <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 -0800249 * ...
250 * ...
251 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700252 * <config_params>
253 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
Aalique Grahame22e49102018-12-18 14:23:57 -0800254 * <param key="operator_info" value="tmus;aa;bb;cc"/>
255 * <param key="operator_info" value="sprint;xx;yy;zz"/>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700256 * ...
257 * ...
258 * </config_params>
Aalique Grahame22e49102018-12-18 14:23:57 -0800259 *
260 * <operator_specific>
261 * <device name="???" operator="???" mixer_path="???" acdb_id="???"/>
262 * ...
263 * ...
264 * </operator_specific>
265 *
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700266 * </audio_platform_info>
267 */
268
269static void process_root(const XML_Char **attr __unused)
270{
271}
272
273/* mapping from usecase to pcm dev id */
274static void process_pcm_id(const XML_Char **attr)
275{
276 int index;
277
278 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700279 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700280 goto done;
281 }
282
283 index = platform_get_usecase_index((char *)attr[1]);
284 if (index < 0) {
285 ALOGE("%s: usecase %s not found!",
286 __func__, attr[1]);
287 goto done;
288 }
289
290 if (strcmp(attr[2], "type") != 0) {
291 ALOGE("%s: usecase type not mentioned", __func__);
292 goto done;
293 }
294
295 int type = -1;
296
297 if (!strcasecmp((char *)attr[3], "in")) {
298 type = 1;
299 } else if (!strcasecmp((char *)attr[3], "out")) {
300 type = 0;
301 } else {
302 ALOGE("%s: type must be IN or OUT", __func__);
303 goto done;
304 }
305
306 if (strcmp(attr[4], "id") != 0) {
307 ALOGE("%s: usecase id not mentioned", __func__);
308 goto done;
309 }
310
311 int id = atoi((char *)attr[5]);
312
313 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
314 ALOGE("%s: usecase %s type %d id %d was not set!",
315 __func__, attr[1], type, id);
316 goto done;
317 }
318
319done:
320 return;
321}
322
323/* backend to be used for a device */
324static void process_backend_name(const XML_Char **attr)
325{
326 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530327 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530328 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700329
330 if (strcmp(attr[0], "name") != 0) {
331 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
332 goto done;
333 }
334
335 index = platform_get_snd_device_index((char *)attr[1]);
336 if (index < 0) {
337 ALOGE("%s: Device %s not found, no ACDB ID set!",
338 __func__, attr[1]);
339 goto done;
340 }
341
342 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530343 if (strcmp(attr[2], "interface") == 0)
344 hw_interface = (char *)attr[3];
345 } else {
346 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700347 }
348
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530349 if (attr[4] != NULL) {
350 if (strcmp(attr[4], "interface") != 0) {
351 hw_interface = NULL;
352 } else {
353 hw_interface = (char *)attr[5];
354 }
355 }
356
Ashish Jaind150d4c2017-02-03 18:44:34 +0530357 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700358 ALOGE("%s: Device %s backend %s was not set!",
359 __func__, attr[1], attr[3]);
360 goto done;
361 }
362
363done:
364 return;
365}
366
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700367static void process_gain_db_to_level_map(const XML_Char **attr)
368{
369 struct amp_db_and_gain_table tbl_entry;
370
371 if ((strcmp(attr[0], "db") != 0) ||
372 (strcmp(attr[2], "level") != 0)) {
373 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
374 __func__, attr[0], attr[2]);
375 goto done;
376 }
377
378 tbl_entry.db = atof(attr[1]);
379 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
380 tbl_entry.level = atoi(attr[3]);
381
Aalique Grahame22e49102018-12-18 14:23:57 -0800382 //custome level should be > 0. Level 0 is fixed for default
383 CHECK(tbl_entry.level > 0);
384
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700385 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
386 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
387 platform_add_gain_level_mapping(&tbl_entry);
388
389done:
390 return;
391}
392
393
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700394static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800395{
Ben Romberger61764e32014-01-10 13:49:02 -0800396 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800397
Ben Romberger61764e32014-01-10 13:49:02 -0800398 if (strcmp(attr[0], "name") != 0) {
399 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800400 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800401 }
Ben Romberger55886882014-01-10 13:49:02 -0800402
Ben Romberger61764e32014-01-10 13:49:02 -0800403 index = platform_get_snd_device_index((char *)attr[1]);
404 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800405 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
406 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800407 goto done;
408 }
409
410 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800411 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
412 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800413 goto done;
414 }
415
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700416 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
417 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800418 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800419 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800420 }
Ben Romberger55886882014-01-10 13:49:02 -0800421
Ben Romberger55886882014-01-10 13:49:02 -0800422done:
423 return;
424}
425
Aalique Grahame22e49102018-12-18 14:23:57 -0800426static void process_operator_specific(const XML_Char **attr)
427{
428 snd_device_t snd_device = SND_DEVICE_NONE;
429
430 if (strcmp(attr[0], "name") != 0) {
431 ALOGE("%s: 'name' not found", __func__);
432 goto done;
433 }
434
435 snd_device = platform_get_snd_device_index((char *)attr[1]);
436 if (snd_device < 0) {
437 ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
438 __func__, (char *)attr[3], PLATFORM_INFO_XML_PATH);
439 goto done;
440 }
441
442 if (strcmp(attr[2], "operator") != 0) {
443 ALOGE("%s: 'operator' not found", __func__);
444 goto done;
445 }
446
447 if (strcmp(attr[4], "mixer_path") != 0) {
448 ALOGE("%s: 'mixer_path' not found", __func__);
449 goto done;
450 }
451
452 if (strcmp(attr[6], "acdb_id") != 0) {
453 ALOGE("%s: 'acdb_id' not found", __func__);
454 goto done;
455 }
456
457 platform_add_operator_specific_device(snd_device, (char *)attr[3], (char *)attr[5], atoi((char *)attr[7]));
458
459done:
460 return;
461}
462
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700463static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
464{
465 int index;
466 struct audio_effect_config effect_config;
467
468 if (strcmp(attr[0], "name") != 0) {
469 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
470 goto done;
471 }
472
473 index = platform_get_snd_device_index((char *)attr[1]);
474 if (index < 0) {
475 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
476 __func__, attr[1]);
477 goto done;
478 }
479
480 if (strcmp(attr[2], "module_id") != 0) {
481 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
482 __func__, attr[2]);
483 goto done;
484 }
485
486 if (strcmp(attr[4], "instance_id") != 0) {
487 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
488 __func__, attr[4]);
489 goto done;
490 }
491
492 if (strcmp(attr[6], "param_id") != 0) {
493 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
494 __func__, attr[6]);
495 goto done;
496 }
497
498 if (strcmp(attr[8], "param_value") != 0) {
499 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
500 __func__, attr[8]);
501 goto done;
502 }
503
504 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
505 strtol((char *)attr[5], NULL, 0),
506 strtol((char *)attr[7], NULL, 0),
507 strtol((char *)attr[9], NULL, 0)};
508
509
510 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
511 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
512 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
513 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
514 strtol((char *)attr[9], NULL, 0));
515 goto done;
516 }
517
518done:
519 return;
520}
521
522static void process_effect_aec(const XML_Char **attr)
523{
524 process_audio_effect(attr, EFFECT_AEC);
525 return;
526}
527
528static void process_effect_ns(const XML_Char **attr)
529{
530 process_audio_effect(attr, EFFECT_NS);
531 return;
532}
533
Amit Shekhar5a39c912014-10-14 15:39:30 -0700534static void process_bit_width(const XML_Char **attr)
535{
536 int index;
537
538 if (strcmp(attr[0], "name") != 0) {
539 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
540 goto done;
541 }
542
543 index = platform_get_snd_device_index((char *)attr[1]);
544 if (index < 0) {
545 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
546 __func__, attr[1]);
547 goto done;
548 }
549
550 if (strcmp(attr[2], "bit_width") != 0) {
551 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
552 __func__, attr[1]);
553 goto done;
554 }
555
556 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
557 ALOGE("%s: Device %s, ACDB ID %d was not set!",
558 __func__, attr[1], atoi((char *)attr[3]));
559 goto done;
560 }
561
562done:
563 return;
564}
565
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800566static void process_interface_name(const XML_Char **attr)
567{
568 int ret;
569
570 if (strcmp(attr[0], "name") != 0) {
571 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
572
573 goto done;
574 }
575
576 if (strcmp(attr[2], "interface") != 0) {
577 ALOGE("%s: Device %s has no Audio Interface set!",
578 __func__, attr[1]);
579
580 goto done;
581 }
582
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530583 if (strcmp(attr[4], "codec_type") != 0) {
584 ALOGE("%s: Device %s has no codec type set!",
585 __func__, attr[1]);
586
587 goto done;
588 }
589
590 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
591 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800592 if (ret < 0) {
593 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800594 goto done;
595 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800596
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800597done:
598 return;
599}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530600
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700601static void process_config_params(const XML_Char **attr)
602{
603 if (strcmp(attr[0], "key") != 0) {
604 ALOGE("%s: 'key' not found", __func__);
605 goto done;
606 }
607
608 if (strcmp(attr[2], "value") != 0) {
609 ALOGE("%s: 'value' not found", __func__);
610 goto done;
611 }
612
613 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
614done:
615 return;
616}
617
Aalique Grahame22e49102018-12-18 14:23:57 -0800618static void process_app_type(const XML_Char **attr)
619{
620 if (strcmp(attr[0], "uc_type")) {
621 ALOGE("%s: uc_type not found", __func__);
622 goto done;
623 }
624
625 if (strcmp(attr[2], "mode")) {
626 ALOGE("%s: mode not found", __func__);
627 goto done;
628 }
629
630 if (strcmp(attr[4], "bit_width")) {
631 ALOGE("%s: bit_width not found", __func__);
632 goto done;
633 }
634
635 if (strcmp(attr[6], "id")) {
636 ALOGE("%s: id not found", __func__);
637 goto done;
638 }
639
640 if (strcmp(attr[8], "max_rate")) {
641 ALOGE("%s: max rate not found", __func__);
642 goto done;
643 }
644
645 platform_add_app_type(attr[1], attr[3], atoi(attr[5]), atoi(attr[7]),
646 atoi(attr[9]));
647done:
648 return;
649}
650
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530651static void process_microphone_characteristic(const XML_Char **attr) {
652 struct audio_microphone_characteristic_t microphone;
653 uint32_t curIdx = 0;
654
655 if (strcmp(attr[curIdx++], "valid_mask")) {
656 ALOGE("%s: valid_mask not found", __func__);
657 goto done;
658 }
659 uint32_t valid_mask = atoi(attr[curIdx++]);
660
661 if (strcmp(attr[curIdx++], "device_id")) {
662 ALOGE("%s: device_id not found", __func__);
663 goto done;
664 }
665 if (strlen(attr[curIdx]) > AUDIO_MICROPHONE_ID_MAX_LEN) {
666 ALOGE("%s: device_id %s is too long", __func__, attr[curIdx]);
667 goto done;
668 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530669 strlcpy(microphone.device_id, attr[curIdx++], sizeof(microphone.device_id));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530670
671 if (strcmp(attr[curIdx++], "type")) {
672 ALOGE("%s: device not found", __func__);
673 goto done;
674 }
675 if (!find_enum_by_string(device_in_types, (char*)attr[curIdx++],
676 ARRAY_SIZE(device_in_types), &microphone.device)) {
677 ALOGE("%s: type %s in %s not found!",
678 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
679 goto done;
680 }
681
682 if (strcmp(attr[curIdx++], "address")) {
683 ALOGE("%s: address not found", __func__);
684 goto done;
685 }
686 if (strlen(attr[curIdx]) > AUDIO_DEVICE_MAX_ADDRESS_LEN) {
687 ALOGE("%s, address %s is too long", __func__, attr[curIdx]);
688 goto done;
689 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530690 strlcpy(microphone.address, attr[curIdx++], sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530691 if (strlen(microphone.address) == 0) {
692 // If the address is empty, populate the address according to device type.
693 if (microphone.device == AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530694 strlcpy(microphone.address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530695 } else if (microphone.device == AUDIO_DEVICE_IN_BACK_MIC) {
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530696 strlcpy(microphone.address, AUDIO_BACK_MICROPHONE_ADDRESS, sizeof(microphone.address));
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530697 }
698 }
699
700 if (strcmp(attr[curIdx++], "location")) {
701 ALOGE("%s: location not found", __func__);
702 goto done;
703 }
704 if (!find_enum_by_string(mic_locations, (char*)attr[curIdx++],
705 AUDIO_MICROPHONE_LOCATION_CNT, &microphone.location)) {
706 ALOGE("%s: location %s in %s not found!",
707 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
708 goto done;
709 }
710
711 if (strcmp(attr[curIdx++], "group")) {
712 ALOGE("%s: group not found", __func__);
713 goto done;
714 }
715 microphone.group = atoi(attr[curIdx++]);
716
717 if (strcmp(attr[curIdx++], "index_in_the_group")) {
718 ALOGE("%s: index_in_the_group not found", __func__);
719 goto done;
720 }
721 microphone.index_in_the_group = atoi(attr[curIdx++]);
722
723 if (strcmp(attr[curIdx++], "directionality")) {
724 ALOGE("%s: directionality not found", __func__);
725 goto done;
726 }
727 if (!find_enum_by_string(mic_directionalities, (char*)attr[curIdx++],
728 AUDIO_MICROPHONE_DIRECTIONALITY_CNT, &microphone.directionality)) {
729 ALOGE("%s: directionality %s in %s not found!",
730 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
731 goto done;
732 }
733
734 if (strcmp(attr[curIdx++], "num_frequency_responses")) {
735 ALOGE("%s: num_frequency_responses not found", __func__);
736 goto done;
737 }
738 microphone.num_frequency_responses = atoi(attr[curIdx++]);
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530739 if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530740 ALOGE("%s: num_frequency_responses is too large", __func__);
741 goto done;
742 }
743 if (microphone.num_frequency_responses > 0) {
744 if (strcmp(attr[curIdx++], "frequencies")) {
745 ALOGE("%s: frequencies not found", __func__);
746 goto done;
747 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530748 char *context = NULL;
749 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530750 uint32_t num_frequencies = 0;
751 while (token) {
752 microphone.frequency_responses[0][num_frequencies++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800753 if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530754 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530755 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530756 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530757 }
758
759 if (strcmp(attr[curIdx++], "responses")) {
760 ALOGE("%s: responses not found", __func__);
761 goto done;
762 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530763 token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530764 uint32_t num_responses = 0;
765 while (token) {
766 microphone.frequency_responses[1][num_responses++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800767 if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530768 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530769 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530770 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530771 }
772
773 if (num_frequencies != num_responses
774 || num_frequencies != microphone.num_frequency_responses) {
775 ALOGE("%s: num of frequency and response not match: %u, %u, %u",
776 __func__, num_frequencies, num_responses, microphone.num_frequency_responses);
777 goto done;
778 }
779 }
780
781 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_SENSITIVITY) {
782 if (strcmp(attr[curIdx++], "sensitivity")) {
783 ALOGE("%s: sensitivity not found", __func__);
784 goto done;
785 }
786 microphone.sensitivity = atof(attr[curIdx++]);
787 } else {
788 microphone.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
789 }
790
791 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MAX_SPL) {
792 if (strcmp(attr[curIdx++], "max_spl")) {
793 ALOGE("%s: max_spl not found", __func__);
794 goto done;
795 }
796 microphone.max_spl = atof(attr[curIdx++]);
797 } else {
798 microphone.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
799 }
800
801 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_MIN_SPL) {
802 if (strcmp(attr[curIdx++], "min_spl")) {
803 ALOGE("%s: min_spl not found", __func__);
804 goto done;
805 }
806 microphone.min_spl = atof(attr[curIdx++]);
807 } else {
808 microphone.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
809 }
810
811 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_ORIENTATION) {
812 if (strcmp(attr[curIdx++], "orientation")) {
813 ALOGE("%s: orientation not found", __func__);
814 goto done;
815 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530816 char *context = NULL;
817 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530818 float orientation[3];
819 uint32_t idx = 0;
820 while (token) {
821 orientation[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800822 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530823 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530824 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530825 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530826 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530827 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530828 ALOGE("%s: orientation invalid", __func__);
829 goto done;
830 }
831 microphone.orientation.x = orientation[0];
832 microphone.orientation.y = orientation[1];
833 microphone.orientation.z = orientation[2];
834 } else {
835 microphone.orientation.x = 0.0f;
836 microphone.orientation.y = 0.0f;
837 microphone.orientation.z = 0.0f;
838 }
839
840 if (valid_mask & AUDIO_MICROPHONE_CHARACTERISTIC_GEOMETRIC_LOCATION) {
841 if (strcmp(attr[curIdx++], "geometric_location")) {
842 ALOGE("%s: geometric_location not found", __func__);
843 goto done;
844 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530845 char *context = NULL;
846 char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530847 float geometric_location[3];
848 uint32_t idx = 0;
849 while (token) {
850 geometric_location[idx++] = atof(token);
Weiyin Jiang20d3fa62018-08-01 18:06:27 +0800851 if (idx >= 3) {
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530852 break;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530853 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530854 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530855 }
Ramjee Singhf57ff2a2018-08-27 16:22:16 +0530856 if (idx != 3) {
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530857 ALOGE("%s: geometric_location invalid", __func__);
858 goto done;
859 }
860 microphone.geometric_location.x = geometric_location[0];
861 microphone.geometric_location.y = geometric_location[1];
862 microphone.geometric_location.z = geometric_location[2];
863 } else {
864 microphone.geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
865 microphone.geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
866 microphone.geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
867 }
868
869 platform_set_microphone_characteristic(my_data.platform, microphone);
870done:
871 return;
872}
873
874static void process_snd_dev(const XML_Char **attr)
875{
876 uint32_t curIdx = 0;
877 in_snd_device = SND_DEVICE_NONE;
878
879 if (strcmp(attr[curIdx++], "in_snd_device")) {
880 ALOGE("%s: snd_device not found", __func__);
881 return;
882 }
883 in_snd_device = platform_get_snd_device_index((char *)attr[curIdx++]);
884 if (in_snd_device < SND_DEVICE_IN_BEGIN ||
885 in_snd_device >= SND_DEVICE_IN_END) {
886 ALOGE("%s: Sound device not valid", __func__);
887 in_snd_device = SND_DEVICE_NONE;
888 }
889
890 return;
891}
892
893static void process_mic_info(const XML_Char **attr)
894{
895 uint32_t curIdx = 0;
896 struct mic_info microphone;
897
898 memset(&microphone.channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED,
899 sizeof(microphone.channel_mapping));
900
901 if (strcmp(attr[curIdx++], "mic_device_id")) {
902 ALOGE("%s: mic_device_id not found", __func__);
903 goto on_error;
904 }
905 strlcpy(microphone.device_id,
906 (char *)attr[curIdx++], AUDIO_MICROPHONE_ID_MAX_LEN);
907
908 if (strcmp(attr[curIdx++], "channel_mapping")) {
909 ALOGE("%s: channel_mapping not found", __func__);
910 goto on_error;
911 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530912 char *context = NULL;
913 const char *token = strtok_r((char *)attr[curIdx++], " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530914 uint32_t idx = 0;
915 while (token) {
916 if (!find_enum_by_string(mic_channel_mapping, token,
917 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT,
918 &microphone.channel_mapping[idx++])) {
919 ALOGE("%s: channel_mapping %s in %s not found!",
920 __func__, attr[--curIdx], PLATFORM_INFO_XML_PATH);
921 goto on_error;
922 }
Ramjee Singh83e1eb12018-07-11 16:22:46 +0530923 token = strtok_r(NULL, " ", &context);
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530924 }
925 microphone.channel_count = idx;
926
927 platform_set_microphone_map(my_data.platform, in_snd_device,
928 &microphone);
929 return;
930on_error:
931 in_snd_device = SND_DEVICE_NONE;
932 return;
933}
934
935
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530936/* process acdb meta info key value */
937static void process_acdb_metainfo_key(const XML_Char **attr)
938{
939 if (strcmp(attr[0], "name") != 0) {
940 ALOGE("%s: 'name' not found", __func__);
941 goto done;
942 }
943
944 if (strcmp(attr[2], "value") != 0) {
945 ALOGE("%s: 'value' not found", __func__);
946 goto done;
947 }
948
949 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700950 switch(my_data.caller) {
951 case ACDB_EXTN:
952 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
953 ALOGE("%s: key %d was not set!", __func__, key);
954 goto done;
955 }
956 break;
957 case PLATFORM:
958 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
959 ALOGE("%s: key %d was not set!", __func__, key);
960 goto done;
961 }
962 break;
963 default:
964 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530965 }
966
967done:
968 return;
969}
970
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530971static void process_custom_mtmx_param_coeffs(const XML_Char **attr)
972{
973 uint32_t attr_idx = 0, out_ch_idx = -1, ch_coeff_count = 0;
974 uint32_t ip_channels = 0, op_channels = 0;
975 char *context = NULL, *ch_coeff_value = NULL;
976 struct audio_custom_mtmx_params *mtmx_params = NULL;
977
978 if (strcmp(attr[attr_idx++], "out_channel_index") != 0) {
979 ALOGE("%s: 'out_channel_index' not found", __func__);
980 return;
981 }
982 out_ch_idx = atoi((char *)attr[attr_idx++]);
983
984 if (out_ch_idx < 0 || out_ch_idx >= mtmx_params_info.op_channels) {
985 ALOGE("%s: invalid out channel index(%d)", __func__, out_ch_idx);
986 return;
987 }
988
989 if (strcmp(attr[attr_idx++], "values") != 0) {
990 ALOGE("%s: 'values' not found", __func__);
991 return;
992 }
993 mtmx_params = platform_get_custom_mtmx_params((void *)my_data.platform,
994 &mtmx_params_info);
995 if (mtmx_params == NULL) {
996 ALOGE("%s: mtmx params with given param info, not found", __func__);
997 return;
998 }
999 ch_coeff_value = strtok_r((char *)attr[attr_idx++], " ", &context);
1000 ip_channels = mtmx_params->info.ip_channels;
1001 op_channels = mtmx_params->info.op_channels;
1002 while(ch_coeff_value && ch_coeff_count < op_channels) {
1003 mtmx_params->coeffs[ip_channels * out_ch_idx + ch_coeff_count++]
1004 = atoi(ch_coeff_value);
1005 ch_coeff_value = strtok_r(NULL, " ", &context);
1006 }
1007 if (ch_coeff_count != mtmx_params->info.ip_channels ||
1008 ch_coeff_value != NULL)
1009 ALOGE("%s: invalid/malformed coefficient values", __func__);
1010}
1011
1012static void process_custom_mtmx_params(const XML_Char **attr)
1013{
1014 int attr_idx = 0;
1015
1016 if (strcmp(attr[attr_idx++], "param_id") != 0) {
1017 ALOGE("%s: 'param_id' not found", __func__);
1018 return;
1019 }
1020 mtmx_params_info.id = atoi((char *)attr[attr_idx++]);
1021
1022 if (strcmp(attr[attr_idx++], "in_channel_count") != 0) {
1023 ALOGE("%s: 'in_channel_count' not found", __func__);
1024 return;
1025 }
1026 mtmx_params_info.ip_channels = atoi((char *)attr[attr_idx++]);
1027
1028 if (strcmp(attr[attr_idx++], "out_channel_count") != 0) {
1029 ALOGE("%s: 'out_channel_count' not found", __func__);
1030 return;
1031 }
1032 mtmx_params_info.op_channels = atoi((char *)attr[attr_idx++]);
1033
1034 if (strcmp(attr[attr_idx++], "usecase") != 0) {
1035 ALOGE("%s: 'usecase' not found", __func__);
1036 return;
1037 }
1038 mtmx_params_info.usecase_id = platform_get_usecase_index((char *)attr[attr_idx++]);
1039
1040 if (strcmp(attr[attr_idx++], "snd_device") != 0) {
1041 ALOGE("%s: 'snd_device' not found", __func__);
1042 return;
1043 }
1044 mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
1045 platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
1046
1047}
1048
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001049static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -08001050 const XML_Char **attr)
1051{
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001052 if (my_data.caller == ACDB_EXTN) {
1053 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1054 section = ACDB_METAINFO_KEY;
1055 } else if (strcmp(tag_name, "param") == 0) {
1056 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1057 ALOGE("param tag only supported with CONFIG_PARAMS section");
1058 return;
1059 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001060
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001061 section_process_fn fn = section_table[section];
1062 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001063 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001064 } else if(my_data.caller == PLATFORM) {
1065 if (strcmp(tag_name, "bit_width_configs") == 0) {
1066 section = BITWIDTH;
1067 } else if (strcmp(tag_name, "acdb_ids") == 0) {
1068 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001069 } else if (strcmp(tag_name, "module_ids") == 0) {
1070 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001071 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1072 section = PCM_ID;
1073 } else if (strcmp(tag_name, "backend_names") == 0) {
1074 section = BACKEND_NAME;
1075 } else if (strcmp(tag_name, "config_params") == 0) {
1076 section = CONFIG_PARAMS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001077 } else if (strcmp(tag_name, "operator_specific") == 0) {
1078 section = OPERATOR_SPECIFIC;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001079 } else if (strcmp(tag_name, "interface_names") == 0) {
1080 section = INTERFACE_NAME;
1081 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1082 section = GAIN_LEVEL_MAPPING;
Aalique Grahame22e49102018-12-18 14:23:57 -08001083 } else if (strcmp(tag_name, "app_types") == 0) {
1084 section = APP_TYPE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001085 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
1086 section = ACDB_METAINFO_KEY;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301087 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1088 section = MICROPHONE_CHARACTERISTIC;
1089 } else if (strcmp(tag_name, "snd_devices") == 0) {
1090 section = SND_DEVICES;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001091 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001092 if ((section != ACDB) && (section != AEC) && (section != NS) &&
1093 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08001094 (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001095 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
1096 return;
1097 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001098
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001099 /* call into process function for the current section */
1100 section_process_fn fn = section_table[section];
1101 fn(attr);
1102 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1103 if (section != GAIN_LEVEL_MAPPING) {
1104 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
1105 return;
1106 }
1107
1108 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1109 fn(attr);
1110 } else if (strcmp(tag_name, "usecase") == 0) {
1111 if (section != PCM_ID) {
1112 ALOGE("usecase tag only supported with PCM_ID section");
1113 return;
1114 }
1115
1116 section_process_fn fn = section_table[PCM_ID];
1117 fn(attr);
1118 } else if (strcmp(tag_name, "param") == 0) {
1119 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
1120 ALOGE("param tag only supported with CONFIG_PARAMS section");
1121 return;
1122 }
1123
1124 section_process_fn fn = section_table[section];
1125 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301126 } else if (strcmp(tag_name, "aec") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001127 if (section != MODULE) {
1128 ALOGE("aec tag only supported with MODULE section");
1129 return;
1130 }
1131 section = AEC;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301132 } else if (strcmp(tag_name, "ns") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001133 if (section != MODULE) {
1134 ALOGE("ns tag only supported with MODULE section");
1135 return;
1136 }
1137 section = NS;
Aalique Grahame22e49102018-12-18 14:23:57 -08001138 } else if (strcmp(tag_name, "gain_level_map") == 0) {
1139 if (section != GAIN_LEVEL_MAPPING) {
1140 ALOGE("gain_level_map tag only supported with GAIN_LEVEL_MAPPING section");
1141 return;
1142 }
1143
1144 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
1145 fn(attr);
1146 } else if (!strcmp(tag_name, "app")) {
1147 if (section != APP_TYPE) {
1148 ALOGE("app tag only valid in section APP_TYPE");
1149 return;
1150 }
1151
1152 section_process_fn fn = section_table[APP_TYPE];
1153 fn(attr);
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301154 } else if (strcmp(tag_name, "microphone") == 0) {
1155 if (section != MICROPHONE_CHARACTERISTIC) {
1156 ALOGE("microphone tag only supported with MICROPHONE_CHARACTERISTIC section");
1157 return;
1158 }
1159 section_process_fn fn = section_table[MICROPHONE_CHARACTERISTIC];
1160 fn(attr);
1161 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1162 if (section != SND_DEVICES) {
1163 ALOGE("input_snd_device tag only supported with SND_DEVICES section");
1164 return;
1165 }
1166 section = INPUT_SND_DEVICE;
1167 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1168 if (section != INPUT_SND_DEVICE) {
1169 ALOGE("input_snd_device_mic_mapping tag only supported with INPUT_SND_DEVICE section");
1170 return;
1171 }
1172 section = INPUT_SND_DEVICE_TO_MIC_MAPPING;
1173 } else if (strcmp(tag_name, "snd_dev") == 0) {
1174 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1175 ALOGE("snd_dev tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1176 return;
1177 }
1178 section_process_fn fn = section_table[SND_DEV];
1179 fn(attr);
1180 } else if (strcmp(tag_name, "mic_info") == 0) {
1181 if (section != INPUT_SND_DEVICE_TO_MIC_MAPPING) {
1182 ALOGE("mic_info tag only supported with INPUT_SND_DEVICE_TO_MIC_MAPPING section");
1183 return;
1184 }
1185 if (in_snd_device == SND_DEVICE_NONE) {
1186 ALOGE("%s: Error in previous tags, do not process mic info", __func__);
1187 return;
1188 }
1189 section_process_fn fn = section_table[MIC_INFO];
1190 fn(attr);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301191 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1192 if (section != ROOT) {
1193 ALOGE("custom_mtmx_params tag supported only in ROOT section");
1194 return;
1195 }
1196 section = CUSTOM_MTMX_PARAMS;
1197 section_process_fn fn = section_table[section];
1198 fn(attr);
1199 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1200 if (section != CUSTOM_MTMX_PARAMS) {
1201 ALOGE("custom_mtmx_param_coeffs tag supported only with CUSTOM_MTMX_PARAMS section");
1202 return;
1203 }
1204 section = CUSTOM_MTMX_PARAM_COEFFS;
1205 section_process_fn fn = section_table[section];
1206 fn(attr);
1207 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001208 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08001209 if(strcmp(tag_name, "config_params") == 0) {
1210 section = CONFIG_PARAMS;
1211 } else if (strcmp(tag_name, "param") == 0) {
1212 if (section != CONFIG_PARAMS) {
1213 ALOGE("param tag only supported with CONFIG_PARAMS section");
1214 return;
1215 }
1216
1217 section_process_fn fn = section_table[section];
1218 fn(attr);
1219 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001220 }
Ben Romberger55886882014-01-10 13:49:02 -08001221 return;
1222}
1223
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001224static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -08001225{
Amit Shekhar5a39c912014-10-14 15:39:30 -07001226 if (strcmp(tag_name, "bit_width_configs") == 0) {
1227 section = ROOT;
1228 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001229 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07001230 } else if (strcmp(tag_name, "module_ids") == 0) {
1231 section = ROOT;
1232 } else if (strcmp(tag_name, "aec") == 0) {
1233 section = MODULE;
1234 } else if (strcmp(tag_name, "ns") == 0) {
1235 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001236 } else if (strcmp(tag_name, "pcm_ids") == 0) {
1237 section = ROOT;
1238 } else if (strcmp(tag_name, "backend_names") == 0) {
1239 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001240 } else if (strcmp(tag_name, "config_params") == 0) {
1241 section = ROOT;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001242 if (my_data.caller == PLATFORM) {
1243 platform_set_parameters(my_data.platform, my_data.kvpairs);
1244 }
Aalique Grahame22e49102018-12-18 14:23:57 -08001245 } else if (strcmp(tag_name, "operator_specific") == 0) {
1246 section = ROOT;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001247 } else if (strcmp(tag_name, "interface_names") == 0) {
1248 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07001249 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
1250 section = ROOT;
Aalique Grahame22e49102018-12-18 14:23:57 -08001251 } else if (strcmp(tag_name, "app_types") == 0) {
1252 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301253 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
1254 section = ROOT;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05301255 } else if (strcmp(tag_name, "microphone_characteristics") == 0) {
1256 section = ROOT;
1257 } else if (strcmp(tag_name, "snd_devices") == 0) {
1258 section = ROOT;
1259 } else if (strcmp(tag_name, "input_snd_device") == 0) {
1260 section = SND_DEVICES;
1261 } else if (strcmp(tag_name, "input_snd_device_mic_mapping") == 0) {
1262 section = INPUT_SND_DEVICE;
Dhananjay Kumar429eb452018-12-10 22:26:53 +05301263 } else if (strcmp(tag_name, "custom_mtmx_params") == 0) {
1264 section = ROOT;
1265 } else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
1266 section = CUSTOM_MTMX_PARAMS;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001267 }
Ben Romberger55886882014-01-10 13:49:02 -08001268}
1269
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001270int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -08001271{
1272 XML_Parser parser;
1273 FILE *file;
1274 int ret = 0;
1275 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -08001276 void *buf;
Aalique Grahame22e49102018-12-18 14:23:57 -08001277 char platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};
Ben Romberger55886882014-01-10 13:49:02 -08001278
Aalique Grahame22e49102018-12-18 14:23:57 -08001279 if (filename == NULL)
1280 strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
1281 MIXER_PATH_MAX_LENGTH);
1282 else
1283 strlcpy(platform_info_file_name, filename, MIXER_PATH_MAX_LENGTH);
1284
1285 ALOGV("%s: platform info file name is %s", __func__,
1286 platform_info_file_name);
1287
1288 file = fopen(platform_info_file_name, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001289 section = ROOT;
1290
Ben Romberger55886882014-01-10 13:49:02 -08001291 if (!file) {
1292 ALOGD("%s: Failed to open %s, using defaults.",
Aalique Grahame22e49102018-12-18 14:23:57 -08001293 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001294 ret = -ENODEV;
1295 goto done;
1296 }
1297
1298 parser = XML_ParserCreate(NULL);
1299 if (!parser) {
1300 ALOGE("%s: Failed to create XML parser!", __func__);
1301 ret = -ENODEV;
1302 goto err_close_file;
1303 }
1304
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001305 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001306 my_data.platform = platform;
1307 my_data.kvpairs = str_parms_create();
1308
Ben Romberger55886882014-01-10 13:49:02 -08001309 XML_SetElementHandler(parser, start_tag, end_tag);
1310
1311 while (1) {
1312 buf = XML_GetBuffer(parser, BUF_SIZE);
1313 if (buf == NULL) {
1314 ALOGE("%s: XML_GetBuffer failed", __func__);
1315 ret = -ENOMEM;
1316 goto err_free_parser;
1317 }
1318
1319 bytes_read = fread(buf, 1, BUF_SIZE, file);
1320 if (bytes_read < 0) {
1321 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
1322 ret = bytes_read;
1323 goto err_free_parser;
1324 }
1325
1326 if (XML_ParseBuffer(parser, bytes_read,
1327 bytes_read == 0) == XML_STATUS_ERROR) {
1328 ALOGE("%s: XML_ParseBuffer failed, for %s",
Aalique Grahame22e49102018-12-18 14:23:57 -08001329 __func__, platform_info_file_name);
Ben Romberger55886882014-01-10 13:49:02 -08001330 ret = -EINVAL;
1331 goto err_free_parser;
1332 }
1333
1334 if (bytes_read == 0)
1335 break;
1336 }
1337
Ben Romberger55886882014-01-10 13:49:02 -08001338err_free_parser:
1339 XML_ParserFree(parser);
1340err_close_file:
1341 fclose(file);
1342done:
1343 return ret;
1344}