Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 1 | /* |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +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 | |
| 30 | #define LOG_TAG "audio_hw_generic_effect" |
| 31 | //#define LOG_NDEBUG 0 |
| 32 | #define LOG_NDDEBUG 0 |
| 33 | |
| 34 | #include <errno.h> |
| 35 | #include <math.h> |
Weiyin Jiang | 2995f66 | 2019-04-17 14:25:12 +0800 | [diff] [blame] | 36 | #include <log/log.h> |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 37 | #include <fcntl.h> |
| 38 | #include <dirent.h> |
| 39 | #include "audio_hw.h" |
| 40 | #include "platform.h" |
| 41 | #include "platform_api.h" |
| 42 | #include <sys/stat.h> |
| 43 | #include <stdlib.h> |
| 44 | #include <dlfcn.h> |
| 45 | #include <math.h> |
| 46 | #include <cutils/properties.h> |
| 47 | #include "audio_extn.h" |
| 48 | #include "audio_hw.h" |
trkzmn | ab2e2dc | 2020-02-03 18:07:31 +0300 | [diff] [blame^] | 49 | #include <pthread.h> |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 50 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 51 | #ifdef DYNAMIC_LOG_ENABLED |
| 52 | #include <log_xml_parser.h> |
| 53 | #define LOG_MASK HAL_MOD_FILE_GEF |
| 54 | #include <log_utils.h> |
| 55 | #endif |
| 56 | |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 57 | #ifdef AUDIO_GENERIC_EFFECT_FRAMEWORK_ENABLED |
| 58 | |
Weiyin Jiang | 82e4094 | 2017-01-10 16:07:34 +0800 | [diff] [blame] | 59 | #if LINUX_ENABLED |
Manish Dewangan | 6a36d00 | 2017-10-09 14:11:00 +0530 | [diff] [blame] | 60 | #define GEF_LIBRARY "libqtigef.so" |
Weiyin Jiang | 82e4094 | 2017-01-10 16:07:34 +0800 | [diff] [blame] | 61 | #else |
David Ng | 06ccd87 | 2017-03-15 11:39:33 -0700 | [diff] [blame] | 62 | #define GEF_LIBRARY "/vendor/lib/libqtigef.so" |
Weiyin Jiang | 82e4094 | 2017-01-10 16:07:34 +0800 | [diff] [blame] | 63 | #endif |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 64 | |
| 65 | typedef void* (*gef_init_t)(void*); |
Dhananjay Kumar | a427f14 | 2017-07-10 13:49:13 +0530 | [diff] [blame] | 66 | typedef void (*gef_deinit_t)(void*); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 67 | typedef void (*gef_device_config_cb_t)(void*, audio_devices_t, |
Weiyin Jiang | 40dcdb9 | 2019-07-08 17:31:52 +0800 | [diff] [blame] | 68 | audio_channel_mask_t, int, int, int); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 69 | |
| 70 | typedef struct { |
| 71 | void* handle; |
| 72 | void* gef_ptr; |
| 73 | gef_init_t init; |
Dhananjay Kumar | a427f14 | 2017-07-10 13:49:13 +0530 | [diff] [blame] | 74 | gef_deinit_t deinit; |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 75 | gef_device_config_cb_t device_config_cb; |
| 76 | } gef_data; |
| 77 | |
| 78 | static gef_data gef_hal_handle; |
| 79 | |
| 80 | typedef enum { |
| 81 | ASM = 0, |
| 82 | ADM |
| 83 | } gef_calibration_type; |
| 84 | |
| 85 | typedef enum { |
| 86 | AUDIO_DEVICE_CAL_TYPE = 0, |
| 87 | AUDIO_STREAM_CAL_TYPE, |
| 88 | } acdb_device_type; |
| 89 | |
| 90 | |
| 91 | static acdb_device_type make_acdb_device_type_from_gef_cal_type |
| 92 | (gef_calibration_type gef_cal_type) |
| 93 | { |
| 94 | int acdb_device_type = 0; |
| 95 | |
| 96 | switch (gef_cal_type) { |
| 97 | case ASM: |
| 98 | acdb_device_type = AUDIO_STREAM_CAL_TYPE; |
| 99 | break; |
| 100 | case ADM: |
| 101 | acdb_device_type = AUDIO_DEVICE_CAL_TYPE; |
| 102 | break; |
| 103 | default: |
| 104 | acdb_device_type = -1; |
| 105 | break; |
| 106 | } |
| 107 | |
| 108 | return ((int)acdb_device_type); |
| 109 | } |
| 110 | |
| 111 | void audio_extn_gef_init(struct audio_device *adev) |
| 112 | { |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 113 | const char* error = NULL; |
| 114 | |
| 115 | ALOGV("%s: Enter with error", __func__); |
| 116 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 117 | pthread_mutex_init(&adev->cal_lock, (const pthread_mutexattr_t *) NULL); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 118 | memset(&gef_hal_handle, 0, sizeof(gef_data)); |
| 119 | |
Satish Babu Patakokila | 3823096 | 2017-10-18 20:34:56 +0530 | [diff] [blame] | 120 | //: check error for dlopen |
| 121 | gef_hal_handle.handle = dlopen(GEF_LIBRARY, RTLD_LAZY); |
| 122 | if (gef_hal_handle.handle == NULL) { |
| 123 | ALOGE("%s: DLOPEN failed for %s with error %s", |
| 124 | __func__, GEF_LIBRARY, dlerror()); |
| 125 | goto ERROR_RETURN; |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 126 | } else { |
Satish Babu Patakokila | 3823096 | 2017-10-18 20:34:56 +0530 | [diff] [blame] | 127 | ALOGV("%s: DLOPEN successful for %s", __func__, GEF_LIBRARY); |
| 128 | |
| 129 | //call dlerror to clear the error |
| 130 | dlerror(); |
| 131 | gef_hal_handle.init = |
| 132 | (gef_init_t)dlsym(gef_hal_handle.handle, "gef_init"); |
| 133 | error = dlerror(); |
| 134 | |
| 135 | if(error != NULL) { |
| 136 | ALOGE("%s: dlsym of %s failed with error %s", |
| 137 | __func__, "gef_init", error); |
| 138 | goto ERROR_RETURN; |
| 139 | } |
| 140 | |
| 141 | //call dlerror to clear the error |
| 142 | dlerror(); |
| 143 | gef_hal_handle.deinit = |
| 144 | (gef_deinit_t)dlsym(gef_hal_handle.handle, "gef_deinit"); |
| 145 | error = dlerror(); |
| 146 | |
| 147 | if(error != NULL) { |
| 148 | ALOGE("%s: dlsym of %s failed with error %s", |
| 149 | __func__, "gef_deinit", error); |
| 150 | goto ERROR_RETURN; |
| 151 | } |
| 152 | |
| 153 | //call dlerror to clear the error |
| 154 | error = dlerror(); |
| 155 | gef_hal_handle.device_config_cb = |
| 156 | (gef_device_config_cb_t)dlsym(gef_hal_handle.handle, |
| 157 | "gef_device_config_cb"); |
| 158 | error = dlerror(); |
| 159 | |
| 160 | if(error != NULL) { |
| 161 | ALOGE("%s: dlsym of %s failed with error %s", |
| 162 | __func__, "gef_device_config_cb", error); |
| 163 | goto ERROR_RETURN; |
| 164 | } |
| 165 | |
| 166 | gef_hal_handle.gef_ptr = gef_hal_handle.init((void*)adev); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | ERROR_RETURN: |
Satish Babu Patakokila | 3823096 | 2017-10-18 20:34:56 +0530 | [diff] [blame] | 170 | ALOGV("%s: Exit with error ", __func__); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 171 | return; |
| 172 | } |
| 173 | |
| 174 | |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 175 | #ifdef INSTANCE_ID_ENABLED |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 176 | //this will be called from GEF to exchange calibration using acdb |
| 177 | int audio_extn_gef_send_audio_cal(void* dev, int acdb_dev_id, |
| 178 | int gef_cal_type, int app_type, int topology_id, int sample_rate, |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 179 | uint32_t module_id, uint16_t instance_id, uint32_t param_id, |
| 180 | void* data, int length, bool persist) |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 181 | { |
| 182 | int ret = 0; |
| 183 | struct audio_device *adev = (struct audio_device*)dev; |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 184 | acdb_audio_cal_cfg_t cal; |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 185 | int acdb_device_type = |
| 186 | make_acdb_device_type_from_gef_cal_type(gef_cal_type); |
| 187 | |
| 188 | ALOGV("%s: Enter", __func__); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 189 | memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t)); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 190 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 191 | //lock adev->cal_lock |
| 192 | pthread_mutex_lock(&adev->cal_lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 193 | |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 194 | //pack cal |
| 195 | platform_make_cal_cfg(&cal, acdb_dev_id, |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 196 | acdb_device_type, app_type, topology_id, sample_rate, |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 197 | module_id, instance_id, param_id, true); |
| 198 | |
| 199 | ret = platform_send_audio_cal(adev->platform, &cal, data, length, persist); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 200 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 201 | pthread_mutex_unlock(&adev->cal_lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 202 | |
| 203 | ALOGV("%s: Exit with error %d", __func__, ret); |
| 204 | |
| 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | //this will be called from GEF to exchange calibration using acdb |
| 209 | int audio_extn_gef_get_audio_cal(void* dev, int acdb_dev_id, |
| 210 | int gef_cal_type, int app_type, int topology_id, int sample_rate, |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 211 | uint32_t module_id, uint16_t instance_id, uint32_t param_id, |
| 212 | void* data, int* length, bool persist) |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 213 | { |
| 214 | int ret = 0; |
| 215 | struct audio_device *adev = (struct audio_device*)dev; |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 216 | acdb_audio_cal_cfg_t cal; |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 217 | int acdb_device_type = |
| 218 | make_acdb_device_type_from_gef_cal_type(gef_cal_type); |
| 219 | |
| 220 | ALOGV("%s: Enter", __func__); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 221 | memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t)); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 222 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 223 | //lock adev->cal_lock |
| 224 | pthread_mutex_lock(&adev->cal_lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 225 | |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 226 | //pack cal |
| 227 | platform_make_cal_cfg(&cal, acdb_dev_id, |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 228 | acdb_device_type, app_type, topology_id, sample_rate, |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 229 | module_id, instance_id, param_id, false); |
| 230 | |
| 231 | ret = platform_get_audio_cal(adev->platform, &cal, data, length, persist); |
| 232 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 233 | pthread_mutex_unlock(&adev->cal_lock); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 234 | |
| 235 | ALOGV("%s: Exit with error %d", __func__, ret); |
| 236 | |
| 237 | return ret; |
| 238 | } |
| 239 | |
| 240 | //this will be called from GEF to store into acdb |
| 241 | int audio_extn_gef_store_audio_cal(void* dev, int acdb_dev_id, |
| 242 | int gef_cal_type, int app_type, int topology_id, int sample_rate, |
| 243 | uint32_t module_id, uint16_t instance_id, |
| 244 | uint32_t param_id, void* data, int length) |
| 245 | { |
| 246 | int ret = 0; |
| 247 | struct audio_device *adev = (struct audio_device*)dev; |
| 248 | acdb_audio_cal_cfg_t cal; |
| 249 | int acdb_device_type = |
| 250 | make_acdb_device_type_from_gef_cal_type(gef_cal_type); |
| 251 | |
| 252 | ALOGV("%s: Enter", __func__); |
| 253 | memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t)); |
| 254 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 255 | //lock adev->cal_lock |
| 256 | pthread_mutex_lock(&adev->cal_lock); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 257 | |
| 258 | //pack cal |
| 259 | platform_make_cal_cfg(&cal, acdb_dev_id, |
| 260 | acdb_device_type, app_type, topology_id, sample_rate, |
| 261 | module_id, instance_id, param_id, true); |
| 262 | |
| 263 | ret = platform_store_audio_cal(adev->platform, &cal, data, length); |
| 264 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 265 | pthread_mutex_unlock(&adev->cal_lock); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 266 | |
| 267 | ALOGV("%s: Exit with error %d", __func__, ret); |
| 268 | |
| 269 | return ret; |
| 270 | } |
| 271 | |
| 272 | //this will be called from GEF to retrieve calibration using acdb |
| 273 | int audio_extn_gef_retrieve_audio_cal(void* dev, int acdb_dev_id, |
| 274 | int gef_cal_type, int app_type, int topology_id, int sample_rate, |
| 275 | uint32_t module_id, uint16_t instance_id, uint32_t param_id, void* data, int* length) |
| 276 | { |
| 277 | int ret = 0; |
| 278 | struct audio_device *adev = (struct audio_device*)dev; |
| 279 | acdb_audio_cal_cfg_t cal; |
| 280 | int acdb_device_type = |
| 281 | make_acdb_device_type_from_gef_cal_type(gef_cal_type); |
| 282 | |
| 283 | ALOGV("%s: Enter", __func__); |
| 284 | memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t)); |
| 285 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 286 | //lock adev->cal_lock |
| 287 | pthread_mutex_lock(&adev->cal_lock); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 288 | |
| 289 | //pack cal |
| 290 | platform_make_cal_cfg(&cal, acdb_dev_id, |
| 291 | acdb_device_type, app_type, topology_id, sample_rate, |
| 292 | module_id, instance_id, param_id, true); |
| 293 | |
| 294 | ret = platform_retrieve_audio_cal(adev->platform, &cal, data, length); |
| 295 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 296 | pthread_mutex_unlock(&adev->cal_lock); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 297 | |
| 298 | ALOGV("%s: Exit with error %d", __func__, ret); |
| 299 | |
| 300 | return ret; |
| 301 | } |
| 302 | #else |
| 303 | //this will be called from GEF to exchange calibration using acdb |
| 304 | int audio_extn_gef_send_audio_cal(void* dev, int acdb_dev_id, |
| 305 | int gef_cal_type, int app_type, int topology_id, int sample_rate, |
| 306 | uint32_t module_id, uint32_t param_id, void* data, int length, |
| 307 | bool persist) |
| 308 | { |
| 309 | int ret = 0; |
| 310 | struct audio_device *adev = (struct audio_device*)dev; |
| 311 | acdb_audio_cal_cfg_t cal; |
| 312 | int acdb_device_type = |
| 313 | make_acdb_device_type_from_gef_cal_type(gef_cal_type); |
| 314 | |
| 315 | ALOGV("%s: Enter", __func__); |
| 316 | memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t)); |
| 317 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 318 | //lock adev->cal_lock |
| 319 | pthread_mutex_lock(&adev->cal_lock); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 320 | |
| 321 | //pack cal |
| 322 | platform_make_cal_cfg(&cal, acdb_dev_id, |
| 323 | acdb_device_type, app_type, topology_id, sample_rate, |
| 324 | module_id, param_id, true); |
| 325 | |
| 326 | ret = platform_send_audio_cal(adev->platform, &cal, data, length, persist); |
| 327 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 328 | pthread_mutex_unlock(&adev->cal_lock); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 329 | |
| 330 | ALOGV("%s: Exit with error %d", __func__, ret); |
| 331 | |
| 332 | return ret; |
| 333 | } |
| 334 | |
| 335 | //this will be called from GEF to exchange calibration using acdb |
| 336 | int audio_extn_gef_get_audio_cal(void* dev, int acdb_dev_id, |
| 337 | int gef_cal_type, int app_type, int topology_id, int sample_rate, |
| 338 | uint32_t module_id, uint32_t param_id, void* data, int* length, |
| 339 | bool persist) |
| 340 | { |
| 341 | int ret = 0; |
| 342 | struct audio_device *adev = (struct audio_device*)dev; |
| 343 | acdb_audio_cal_cfg_t cal; |
| 344 | int acdb_device_type = |
| 345 | make_acdb_device_type_from_gef_cal_type(gef_cal_type); |
| 346 | |
| 347 | ALOGV("%s: Enter", __func__); |
| 348 | memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t)); |
| 349 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 350 | //lock adev->cal_lock |
| 351 | pthread_mutex_lock(&adev->cal_lock); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 352 | |
| 353 | //pack cal |
| 354 | platform_make_cal_cfg(&cal, acdb_dev_id, |
| 355 | acdb_device_type, app_type, topology_id, sample_rate, |
| 356 | module_id, param_id, false); |
| 357 | |
| 358 | ret = platform_get_audio_cal(adev->platform, &cal, data, length, persist); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 359 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 360 | pthread_mutex_unlock(&adev->cal_lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 361 | |
| 362 | ALOGV("%s: Exit with error %d", __func__, ret); |
| 363 | |
| 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | //this will be called from GEF to store into acdb |
| 368 | int audio_extn_gef_store_audio_cal(void* dev, int acdb_dev_id, |
| 369 | int gef_cal_type, int app_type, int topology_id, int sample_rate, |
| 370 | uint32_t module_id, uint32_t param_id, void* data, int length) |
| 371 | { |
| 372 | int ret = 0; |
| 373 | struct audio_device *adev = (struct audio_device*)dev; |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 374 | acdb_audio_cal_cfg_t cal; |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 375 | int acdb_device_type = |
| 376 | make_acdb_device_type_from_gef_cal_type(gef_cal_type); |
| 377 | |
| 378 | ALOGV("%s: Enter", __func__); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 379 | memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t)); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 380 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 381 | //lock adev->cal_lock |
| 382 | pthread_mutex_lock(&adev->cal_lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 383 | |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 384 | //pack cal |
| 385 | platform_make_cal_cfg(&cal, acdb_dev_id, |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 386 | acdb_device_type, app_type, topology_id, sample_rate, |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 387 | module_id, param_id, true); |
| 388 | |
| 389 | ret = platform_store_audio_cal(adev->platform, &cal, data, length); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 390 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 391 | pthread_mutex_unlock(&adev->cal_lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 392 | |
| 393 | ALOGV("%s: Exit with error %d", __func__, ret); |
| 394 | |
| 395 | return ret; |
| 396 | } |
| 397 | |
| 398 | //this will be called from GEF to retrieve calibration using acdb |
| 399 | int audio_extn_gef_retrieve_audio_cal(void* dev, int acdb_dev_id, |
| 400 | int gef_cal_type, int app_type, int topology_id, int sample_rate, |
| 401 | uint32_t module_id, uint32_t param_id, void* data, int* length) |
| 402 | { |
| 403 | int ret = 0; |
| 404 | struct audio_device *adev = (struct audio_device*)dev; |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 405 | acdb_audio_cal_cfg_t cal; |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 406 | int acdb_device_type = |
| 407 | make_acdb_device_type_from_gef_cal_type(gef_cal_type); |
| 408 | |
| 409 | ALOGV("%s: Enter", __func__); |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 410 | memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t)); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 411 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 412 | //lock adev->cal_lock |
| 413 | pthread_mutex_lock(&adev->cal_lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 414 | |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 415 | //pack cal |
| 416 | platform_make_cal_cfg(&cal, acdb_dev_id, |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 417 | acdb_device_type, app_type, topology_id, sample_rate, |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 418 | module_id, param_id, true); |
| 419 | |
| 420 | ret = platform_retrieve_audio_cal(adev->platform, &cal, data, length); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 421 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 422 | pthread_mutex_unlock(&adev->cal_lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 423 | |
| 424 | ALOGV("%s: Exit with error %d", __func__, ret); |
| 425 | |
| 426 | return ret; |
| 427 | } |
Aditya Bavanari | 29bcea2 | 2017-10-03 20:10:35 +0530 | [diff] [blame] | 428 | #endif |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 429 | |
| 430 | //this will be called from HAL to notify GEF of new device configuration |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 431 | void audio_extn_gef_notify_device_config(struct listnode *audio_devices, |
Weiyin Jiang | 40dcdb9 | 2019-07-08 17:31:52 +0800 | [diff] [blame] | 432 | audio_channel_mask_t channel_mask, int sample_rate, int acdb_id, int app_type) |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 433 | { |
| 434 | ALOGV("%s: Enter", __func__); |
| 435 | |
| 436 | //call into GEF to share channel mask and device info |
| 437 | if (gef_hal_handle.handle && gef_hal_handle.device_config_cb) { |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 438 | gef_hal_handle.device_config_cb(gef_hal_handle.gef_ptr, get_device_types(audio_devices), |
| 439 | channel_mask, sample_rate, acdb_id, app_type); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | ALOGV("%s: Exit", __func__); |
| 443 | |
| 444 | return; |
| 445 | } |
| 446 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 447 | void audio_extn_gef_deinit(struct audio_device *adev) |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 448 | { |
| 449 | ALOGV("%s: Enter", __func__); |
| 450 | |
| 451 | if (gef_hal_handle.handle) { |
Dhananjay Kumar | a427f14 | 2017-07-10 13:49:13 +0530 | [diff] [blame] | 452 | if (gef_hal_handle.handle && gef_hal_handle.deinit) |
| 453 | gef_hal_handle.deinit(gef_hal_handle.gef_ptr); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 454 | dlclose(gef_hal_handle.handle); |
| 455 | } |
| 456 | |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 457 | pthread_mutex_destroy(&adev->cal_lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 458 | memset(&gef_hal_handle, 0, sizeof(gef_data)); |
| 459 | |
| 460 | ALOGV("%s: Exit", __func__); |
| 461 | } |
| 462 | |
| 463 | #endif |