Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1 | /* |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 3 | * |
| 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 Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 30 | #define LOG_TAG "platform_info" |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 31 | #define LOG_NDDEBUG 0 |
| 32 | |
| 33 | #include <errno.h> |
| 34 | #include <stdio.h> |
| 35 | #include <expat.h> |
| 36 | #include <cutils/log.h> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 37 | #include <cutils/str_parms.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 38 | #include <audio_hw.h> |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 39 | #include "acdb.h" |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 40 | #include "platform_api.h" |
| 41 | #include <platform.h> |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 42 | #include <math.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 43 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 44 | #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 Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 50 | #define BUF_SIZE 1024 |
| 51 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 52 | typedef enum { |
| 53 | ROOT, |
| 54 | ACDB, |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 55 | MODULE, |
| 56 | AEC, |
| 57 | NS, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 58 | BITWIDTH, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 59 | PCM_ID, |
| 60 | BACKEND_NAME, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 61 | INTERFACE_NAME, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 62 | CONFIG_PARAMS, |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 63 | GAIN_LEVEL_MAPPING, |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 64 | ACDB_METAINFO_KEY, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 65 | } section_t; |
| 66 | |
| 67 | typedef void (* section_process_fn)(const XML_Char **attr); |
| 68 | |
| 69 | static void process_acdb_id(const XML_Char **attr); |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 70 | static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type); |
| 71 | static void process_effect_aec(const XML_Char **attr); |
| 72 | static void process_effect_ns(const XML_Char **attr); |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 73 | static void process_bit_width(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 74 | static void process_pcm_id(const XML_Char **attr); |
| 75 | static void process_backend_name(const XML_Char **attr); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 76 | static void process_interface_name(const XML_Char **attr); |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 77 | static void process_config_params(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 78 | static void process_root(const XML_Char **attr); |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 79 | static void process_gain_db_to_level_map(const XML_Char **attr); |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 80 | static void process_acdb_metainfo_key(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 81 | |
| 82 | static section_process_fn section_table[] = { |
| 83 | [ROOT] = process_root, |
| 84 | [ACDB] = process_acdb_id, |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 85 | [AEC] = process_effect_aec, |
| 86 | [NS] = process_effect_ns, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 87 | [BITWIDTH] = process_bit_width, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 88 | [PCM_ID] = process_pcm_id, |
| 89 | [BACKEND_NAME] = process_backend_name, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 90 | [INTERFACE_NAME] = process_interface_name, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 91 | [CONFIG_PARAMS] = process_config_params, |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 92 | [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map, |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 93 | [ACDB_METAINFO_KEY] = process_acdb_metainfo_key, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | static section_t section; |
| 97 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 98 | struct platform_info { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 99 | caller_t caller; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 100 | void *platform; |
| 101 | struct str_parms *kvpairs; |
| 102 | }; |
| 103 | |
| 104 | static struct platform_info my_data; |
| 105 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 106 | /* |
| 107 | * <audio_platform_info> |
| 108 | * <acdb_ids> |
| 109 | * <device name="???" acdb_id="???"/> |
| 110 | * ... |
| 111 | * ... |
| 112 | * </acdb_ids> |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 113 | * <module_ids> |
| 114 | * <device name="???" module_id="???"/> |
| 115 | * ... |
| 116 | * ... |
| 117 | * </module_ids> |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 118 | * <backend_names> |
| 119 | * <device name="???" backend="???"/> |
| 120 | * ... |
| 121 | * ... |
| 122 | * </backend_names> |
| 123 | * <pcm_ids> |
| 124 | * <usecase name="???" type="in/out" id="???"/> |
| 125 | * ... |
| 126 | * ... |
| 127 | * </pcm_ids> |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 128 | * <interface_names> |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 129 | * <device name="Use audio device name here, not sound device name" interface="PRIMARY_I2S" codec_type="external/internal"/> |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 130 | * ... |
| 131 | * ... |
| 132 | * </interface_names> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 133 | * <config_params> |
| 134 | * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/> |
| 135 | * ... |
| 136 | * ... |
| 137 | * </config_params> |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 138 | * </audio_platform_info> |
| 139 | */ |
| 140 | |
| 141 | static void process_root(const XML_Char **attr __unused) |
| 142 | { |
| 143 | } |
| 144 | |
| 145 | /* mapping from usecase to pcm dev id */ |
| 146 | static void process_pcm_id(const XML_Char **attr) |
| 147 | { |
| 148 | int index; |
| 149 | |
| 150 | if (strcmp(attr[0], "name") != 0) { |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 151 | ALOGE("%s: 'name' not found, no pcm_id set!", __func__); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 152 | goto done; |
| 153 | } |
| 154 | |
| 155 | index = platform_get_usecase_index((char *)attr[1]); |
| 156 | if (index < 0) { |
| 157 | ALOGE("%s: usecase %s not found!", |
| 158 | __func__, attr[1]); |
| 159 | goto done; |
| 160 | } |
| 161 | |
| 162 | if (strcmp(attr[2], "type") != 0) { |
| 163 | ALOGE("%s: usecase type not mentioned", __func__); |
| 164 | goto done; |
| 165 | } |
| 166 | |
| 167 | int type = -1; |
| 168 | |
| 169 | if (!strcasecmp((char *)attr[3], "in")) { |
| 170 | type = 1; |
| 171 | } else if (!strcasecmp((char *)attr[3], "out")) { |
| 172 | type = 0; |
| 173 | } else { |
| 174 | ALOGE("%s: type must be IN or OUT", __func__); |
| 175 | goto done; |
| 176 | } |
| 177 | |
| 178 | if (strcmp(attr[4], "id") != 0) { |
| 179 | ALOGE("%s: usecase id not mentioned", __func__); |
| 180 | goto done; |
| 181 | } |
| 182 | |
| 183 | int id = atoi((char *)attr[5]); |
| 184 | |
| 185 | if (platform_set_usecase_pcm_id(index, type, id) < 0) { |
| 186 | ALOGE("%s: usecase %s type %d id %d was not set!", |
| 187 | __func__, attr[1], type, id); |
| 188 | goto done; |
| 189 | } |
| 190 | |
| 191 | done: |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | /* backend to be used for a device */ |
| 196 | static void process_backend_name(const XML_Char **attr) |
| 197 | { |
| 198 | int index; |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 199 | char *hw_interface = NULL; |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 200 | char *backend = NULL; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 201 | |
| 202 | if (strcmp(attr[0], "name") != 0) { |
| 203 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 204 | goto done; |
| 205 | } |
| 206 | |
| 207 | index = platform_get_snd_device_index((char *)attr[1]); |
| 208 | if (index < 0) { |
| 209 | ALOGE("%s: Device %s not found, no ACDB ID set!", |
| 210 | __func__, attr[1]); |
| 211 | goto done; |
| 212 | } |
| 213 | |
| 214 | if (strcmp(attr[2], "backend") != 0) { |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 215 | if (strcmp(attr[2], "interface") == 0) |
| 216 | hw_interface = (char *)attr[3]; |
| 217 | } else { |
| 218 | backend = (char *)attr[3]; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 221 | if (attr[4] != NULL) { |
| 222 | if (strcmp(attr[4], "interface") != 0) { |
| 223 | hw_interface = NULL; |
| 224 | } else { |
| 225 | hw_interface = (char *)attr[5]; |
| 226 | } |
| 227 | } |
| 228 | |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 229 | if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 230 | ALOGE("%s: Device %s backend %s was not set!", |
| 231 | __func__, attr[1], attr[3]); |
| 232 | goto done; |
| 233 | } |
| 234 | |
| 235 | done: |
| 236 | return; |
| 237 | } |
| 238 | |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 239 | static void process_gain_db_to_level_map(const XML_Char **attr) |
| 240 | { |
| 241 | struct amp_db_and_gain_table tbl_entry; |
| 242 | |
| 243 | if ((strcmp(attr[0], "db") != 0) || |
| 244 | (strcmp(attr[2], "level") != 0)) { |
| 245 | ALOGE("%s: invalid attribute passed %s %sexpected amp db level", |
| 246 | __func__, attr[0], attr[2]); |
| 247 | goto done; |
| 248 | } |
| 249 | |
| 250 | tbl_entry.db = atof(attr[1]); |
| 251 | tbl_entry.amp = exp(tbl_entry.db * 0.115129f); |
| 252 | tbl_entry.level = atoi(attr[3]); |
| 253 | |
| 254 | ALOGV("%s: amp [%f] db [%f] level [%d]", __func__, |
| 255 | tbl_entry.amp, tbl_entry.db, tbl_entry.level); |
| 256 | platform_add_gain_level_mapping(&tbl_entry); |
| 257 | |
| 258 | done: |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 263 | static void process_acdb_id(const XML_Char **attr) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 264 | { |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 265 | int index; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 266 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 267 | if (strcmp(attr[0], "name") != 0) { |
| 268 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 269 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 270 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 271 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 272 | index = platform_get_snd_device_index((char *)attr[1]); |
| 273 | if (index < 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 274 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 275 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 276 | goto done; |
| 277 | } |
| 278 | |
| 279 | if (strcmp(attr[2], "acdb_id") != 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 280 | ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!", |
| 281 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 282 | goto done; |
| 283 | } |
| 284 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 285 | if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) { |
| 286 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 287 | __func__, attr[1], atoi((char *)attr[3])); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 288 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 289 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 290 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 291 | done: |
| 292 | return; |
| 293 | } |
| 294 | |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 295 | static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type) |
| 296 | { |
| 297 | int index; |
| 298 | struct audio_effect_config effect_config; |
| 299 | |
| 300 | if (strcmp(attr[0], "name") != 0) { |
| 301 | ALOGE("%s: 'name' not found, no MODULE ID set!", __func__); |
| 302 | goto done; |
| 303 | } |
| 304 | |
| 305 | index = platform_get_snd_device_index((char *)attr[1]); |
| 306 | if (index < 0) { |
| 307 | ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!", |
| 308 | __func__, attr[1]); |
| 309 | goto done; |
| 310 | } |
| 311 | |
| 312 | if (strcmp(attr[2], "module_id") != 0) { |
| 313 | ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!", |
| 314 | __func__, attr[2]); |
| 315 | goto done; |
| 316 | } |
| 317 | |
| 318 | if (strcmp(attr[4], "instance_id") != 0) { |
| 319 | ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!", |
| 320 | __func__, attr[4]); |
| 321 | goto done; |
| 322 | } |
| 323 | |
| 324 | if (strcmp(attr[6], "param_id") != 0) { |
| 325 | ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!", |
| 326 | __func__, attr[6]); |
| 327 | goto done; |
| 328 | } |
| 329 | |
| 330 | if (strcmp(attr[8], "param_value") != 0) { |
| 331 | ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!", |
| 332 | __func__, attr[8]); |
| 333 | goto done; |
| 334 | } |
| 335 | |
| 336 | effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0), |
| 337 | strtol((char *)attr[5], NULL, 0), |
| 338 | strtol((char *)attr[7], NULL, 0), |
| 339 | strtol((char *)attr[9], NULL, 0)}; |
| 340 | |
| 341 | |
| 342 | if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) { |
| 343 | ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!", |
| 344 | __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0), |
| 345 | strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0), |
| 346 | strtol((char *)attr[9], NULL, 0)); |
| 347 | goto done; |
| 348 | } |
| 349 | |
| 350 | done: |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | static void process_effect_aec(const XML_Char **attr) |
| 355 | { |
| 356 | process_audio_effect(attr, EFFECT_AEC); |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | static void process_effect_ns(const XML_Char **attr) |
| 361 | { |
| 362 | process_audio_effect(attr, EFFECT_NS); |
| 363 | return; |
| 364 | } |
| 365 | |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 366 | static void process_bit_width(const XML_Char **attr) |
| 367 | { |
| 368 | int index; |
| 369 | |
| 370 | if (strcmp(attr[0], "name") != 0) { |
| 371 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 372 | goto done; |
| 373 | } |
| 374 | |
| 375 | index = platform_get_snd_device_index((char *)attr[1]); |
| 376 | if (index < 0) { |
| 377 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 378 | __func__, attr[1]); |
| 379 | goto done; |
| 380 | } |
| 381 | |
| 382 | if (strcmp(attr[2], "bit_width") != 0) { |
| 383 | ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!", |
| 384 | __func__, attr[1]); |
| 385 | goto done; |
| 386 | } |
| 387 | |
| 388 | if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) { |
| 389 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
| 390 | __func__, attr[1], atoi((char *)attr[3])); |
| 391 | goto done; |
| 392 | } |
| 393 | |
| 394 | done: |
| 395 | return; |
| 396 | } |
| 397 | |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 398 | static void process_interface_name(const XML_Char **attr) |
| 399 | { |
| 400 | int ret; |
| 401 | |
| 402 | if (strcmp(attr[0], "name") != 0) { |
| 403 | ALOGE("%s: 'name' not found, no Audio Interface set!", __func__); |
| 404 | |
| 405 | goto done; |
| 406 | } |
| 407 | |
| 408 | if (strcmp(attr[2], "interface") != 0) { |
| 409 | ALOGE("%s: Device %s has no Audio Interface set!", |
| 410 | __func__, attr[1]); |
| 411 | |
| 412 | goto done; |
| 413 | } |
| 414 | |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 415 | if (strcmp(attr[4], "codec_type") != 0) { |
| 416 | ALOGE("%s: Device %s has no codec type set!", |
| 417 | __func__, attr[1]); |
| 418 | |
| 419 | goto done; |
| 420 | } |
| 421 | |
| 422 | ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3], |
| 423 | (char *)attr[5]); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 424 | if (ret < 0) { |
| 425 | ALOGE("%s: Audio Interface not set!", __func__); |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 426 | goto done; |
| 427 | } |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 428 | |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 429 | done: |
| 430 | return; |
| 431 | } |
Laxminath Kasam | 44f4940 | 2015-05-29 18:37:11 +0530 | [diff] [blame] | 432 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 433 | static void process_config_params(const XML_Char **attr) |
| 434 | { |
| 435 | if (strcmp(attr[0], "key") != 0) { |
| 436 | ALOGE("%s: 'key' not found", __func__); |
| 437 | goto done; |
| 438 | } |
| 439 | |
| 440 | if (strcmp(attr[2], "value") != 0) { |
| 441 | ALOGE("%s: 'value' not found", __func__); |
| 442 | goto done; |
| 443 | } |
| 444 | |
| 445 | str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]); |
| 446 | done: |
| 447 | return; |
| 448 | } |
| 449 | |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 450 | /* process acdb meta info key value */ |
| 451 | static void process_acdb_metainfo_key(const XML_Char **attr) |
| 452 | { |
| 453 | if (strcmp(attr[0], "name") != 0) { |
| 454 | ALOGE("%s: 'name' not found", __func__); |
| 455 | goto done; |
| 456 | } |
| 457 | |
| 458 | if (strcmp(attr[2], "value") != 0) { |
| 459 | ALOGE("%s: 'value' not found", __func__); |
| 460 | goto done; |
| 461 | } |
| 462 | |
| 463 | int key = atoi((char *)attr[3]); |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 464 | switch(my_data.caller) { |
| 465 | case ACDB_EXTN: |
| 466 | if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) { |
| 467 | ALOGE("%s: key %d was not set!", __func__, key); |
| 468 | goto done; |
| 469 | } |
| 470 | break; |
| 471 | case PLATFORM: |
| 472 | if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) { |
| 473 | ALOGE("%s: key %d was not set!", __func__, key); |
| 474 | goto done; |
| 475 | } |
| 476 | break; |
| 477 | default: |
| 478 | ALOGE("%s: unknown caller!", __func__); |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | done: |
| 482 | return; |
| 483 | } |
| 484 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 485 | static void start_tag(void *userdata __unused, const XML_Char *tag_name, |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 486 | const XML_Char **attr) |
| 487 | { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 488 | if (my_data.caller == ACDB_EXTN) { |
| 489 | if(strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 490 | section = ACDB_METAINFO_KEY; |
| 491 | } else if (strcmp(tag_name, "param") == 0) { |
| 492 | if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) { |
| 493 | ALOGE("param tag only supported with CONFIG_PARAMS section"); |
| 494 | return; |
| 495 | } |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 496 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 497 | section_process_fn fn = section_table[section]; |
| 498 | fn(attr); |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 499 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 500 | } else if(my_data.caller == PLATFORM) { |
| 501 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 502 | section = BITWIDTH; |
| 503 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
| 504 | section = ACDB; |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 505 | } else if (strcmp(tag_name, "module_ids") == 0) { |
| 506 | section = MODULE; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 507 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 508 | section = PCM_ID; |
| 509 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 510 | section = BACKEND_NAME; |
| 511 | } else if (strcmp(tag_name, "config_params") == 0) { |
| 512 | section = CONFIG_PARAMS; |
| 513 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 514 | section = INTERFACE_NAME; |
| 515 | } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) { |
| 516 | section = GAIN_LEVEL_MAPPING; |
| 517 | } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 518 | section = ACDB_METAINFO_KEY; |
| 519 | } else if (strcmp(tag_name, "device") == 0) { |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 520 | if ((section != ACDB) && (section != AEC) && (section != NS) && |
| 521 | (section != BACKEND_NAME) && (section != BITWIDTH) && |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 522 | (section != INTERFACE_NAME)) { |
| 523 | ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names"); |
| 524 | return; |
| 525 | } |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 526 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 527 | /* call into process function for the current section */ |
| 528 | section_process_fn fn = section_table[section]; |
| 529 | fn(attr); |
| 530 | } else if (strcmp(tag_name, "gain_level_map") == 0) { |
| 531 | if (section != GAIN_LEVEL_MAPPING) { |
| 532 | ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section"); |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | section_process_fn fn = section_table[GAIN_LEVEL_MAPPING]; |
| 537 | fn(attr); |
| 538 | } else if (strcmp(tag_name, "usecase") == 0) { |
| 539 | if (section != PCM_ID) { |
| 540 | ALOGE("usecase tag only supported with PCM_ID section"); |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | section_process_fn fn = section_table[PCM_ID]; |
| 545 | fn(attr); |
| 546 | } else if (strcmp(tag_name, "param") == 0) { |
| 547 | if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) { |
| 548 | ALOGE("param tag only supported with CONFIG_PARAMS section"); |
| 549 | return; |
| 550 | } |
| 551 | |
| 552 | section_process_fn fn = section_table[section]; |
| 553 | fn(attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 554 | } |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 555 | else if (strcmp(tag_name, "aec") == 0) { |
| 556 | if (section != MODULE) { |
| 557 | ALOGE("aec tag only supported with MODULE section"); |
| 558 | return; |
| 559 | } |
| 560 | section = AEC; |
| 561 | } |
| 562 | else if (strcmp(tag_name, "ns") == 0) { |
| 563 | if (section != MODULE) { |
| 564 | ALOGE("ns tag only supported with MODULE section"); |
| 565 | return; |
| 566 | } |
| 567 | section = NS; |
| 568 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 569 | } else { |
| 570 | ALOGE("%s: unknown caller!", __func__); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 571 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 572 | return; |
| 573 | } |
| 574 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 575 | static void end_tag(void *userdata __unused, const XML_Char *tag_name) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 576 | { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 577 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 578 | section = ROOT; |
| 579 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 580 | section = ROOT; |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 581 | } else if (strcmp(tag_name, "module_ids") == 0) { |
| 582 | section = ROOT; |
| 583 | } else if (strcmp(tag_name, "aec") == 0) { |
| 584 | section = MODULE; |
| 585 | } else if (strcmp(tag_name, "ns") == 0) { |
| 586 | section = MODULE; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 587 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 588 | section = ROOT; |
| 589 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 590 | section = ROOT; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 591 | } else if (strcmp(tag_name, "config_params") == 0) { |
| 592 | section = ROOT; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 593 | if (my_data.caller == PLATFORM) { |
| 594 | platform_set_parameters(my_data.platform, my_data.kvpairs); |
| 595 | } |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 596 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 597 | section = ROOT; |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 598 | } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) { |
| 599 | section = ROOT; |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 600 | } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 601 | section = ROOT; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 602 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 603 | } |
| 604 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 605 | int platform_info_init(const char *filename, void *platform, caller_t caller_type) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 606 | { |
| 607 | XML_Parser parser; |
| 608 | FILE *file; |
| 609 | int ret = 0; |
| 610 | int bytes_read; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 611 | void *buf; |
| 612 | |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 613 | file = fopen(filename, "r"); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 614 | section = ROOT; |
| 615 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 616 | if (!file) { |
| 617 | ALOGD("%s: Failed to open %s, using defaults.", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 618 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 619 | ret = -ENODEV; |
| 620 | goto done; |
| 621 | } |
| 622 | |
| 623 | parser = XML_ParserCreate(NULL); |
| 624 | if (!parser) { |
| 625 | ALOGE("%s: Failed to create XML parser!", __func__); |
| 626 | ret = -ENODEV; |
| 627 | goto err_close_file; |
| 628 | } |
| 629 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 630 | my_data.caller = caller_type; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 631 | my_data.platform = platform; |
| 632 | my_data.kvpairs = str_parms_create(); |
| 633 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 634 | XML_SetElementHandler(parser, start_tag, end_tag); |
| 635 | |
| 636 | while (1) { |
| 637 | buf = XML_GetBuffer(parser, BUF_SIZE); |
| 638 | if (buf == NULL) { |
| 639 | ALOGE("%s: XML_GetBuffer failed", __func__); |
| 640 | ret = -ENOMEM; |
| 641 | goto err_free_parser; |
| 642 | } |
| 643 | |
| 644 | bytes_read = fread(buf, 1, BUF_SIZE, file); |
| 645 | if (bytes_read < 0) { |
| 646 | ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read); |
| 647 | ret = bytes_read; |
| 648 | goto err_free_parser; |
| 649 | } |
| 650 | |
| 651 | if (XML_ParseBuffer(parser, bytes_read, |
| 652 | bytes_read == 0) == XML_STATUS_ERROR) { |
| 653 | ALOGE("%s: XML_ParseBuffer failed, for %s", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 654 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 655 | ret = -EINVAL; |
| 656 | goto err_free_parser; |
| 657 | } |
| 658 | |
| 659 | if (bytes_read == 0) |
| 660 | break; |
| 661 | } |
| 662 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 663 | err_free_parser: |
| 664 | XML_ParserFree(parser); |
| 665 | err_close_file: |
| 666 | fclose(file); |
| 667 | done: |
| 668 | return ret; |
| 669 | } |