Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 1 | /* |
Aditya Bavanari | 3db4a29 | 2017-10-04 20:59:41 +0530 | [diff] [blame^] | 2 | * Copyright (c) 2013-2015, 2017-2018, The Linux Foundation. All rights reserved. |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright (C) 2013 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 20 | #define LOG_TAG "offload_effect_bass" |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 21 | //#define LOG_NDEBUG 0 |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 22 | |
| 23 | #include <cutils/list.h> |
| 24 | #include <cutils/log.h> |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 25 | #include <cutils/properties.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 26 | #include <tinyalsa/asoundlib.h> |
Subhash Chandra Bose Naripeddy | 090a2aa | 2014-01-30 14:03:12 -0800 | [diff] [blame] | 27 | #include <sound/audio_effects.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 28 | #include <audio_effects/effect_bassboost.h> |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 29 | #include <stdlib.h> |
| 30 | #include <dlfcn.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 31 | |
| 32 | #include "effect_api.h" |
| 33 | #include "bass_boost.h" |
| 34 | |
| 35 | /* Offload bassboost UUID: 2c4a8c24-1581-487f-94f6-0002a5d5c51b */ |
| 36 | const effect_descriptor_t bassboost_descriptor = { |
| 37 | {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, |
| 38 | {0x2c4a8c24, 0x1581, 0x487f, 0x94f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid |
| 39 | EFFECT_CONTROL_API_VERSION, |
Weiyin Jiang | 90ac1ea | 2017-04-13 14:18:23 +0800 | [diff] [blame] | 40 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL | |
| 41 | EFFECT_FLAG_VOLUME_CTRL), |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 42 | 0, /* TODO */ |
| 43 | 1, |
| 44 | "MSM offload bassboost", |
| 45 | "The Android Open Source Project", |
| 46 | }; |
| 47 | |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 48 | #define LIB_ACDB_LOADER "libacdbloader.so" |
| 49 | #define PBE_CONF_APP_ID 0x00011134 |
| 50 | |
| 51 | enum { |
| 52 | AUDIO_DEVICE_CAL_TYPE = 0, |
| 53 | AUDIO_STREAM_CAL_TYPE, |
| 54 | }; |
| 55 | |
| 56 | typedef struct acdb_audio_cal_cfg { |
| 57 | uint32_t persist; |
| 58 | uint32_t snd_dev_id; |
| 59 | uint32_t dev_id; |
| 60 | int32_t acdb_dev_id; |
| 61 | uint32_t app_type; |
| 62 | uint32_t topo_id; |
| 63 | uint32_t sampling_rate; |
| 64 | uint32_t cal_type; |
| 65 | uint32_t module_id; |
Aditya Bavanari | 3db4a29 | 2017-10-04 20:59:41 +0530 | [diff] [blame^] | 66 | #ifdef INSTANCE_ID_ENABLED |
| 67 | uint16_t instance_id; |
| 68 | uint16_t reserved; |
| 69 | #endif |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 70 | uint32_t param_id; |
| 71 | } acdb_audio_cal_cfg_t; |
| 72 | |
| 73 | typedef int (*acdb_get_audio_cal_t) (void *, void *, uint32_t*); |
| 74 | static int pbe_load_config(struct pbe_params *params); |
| 75 | |
| 76 | /* |
| 77 | * Bass operations |
| 78 | */ |
| 79 | int bass_get_parameter(effect_context_t *context, effect_param_t *p, |
| 80 | uint32_t *size) |
| 81 | { |
| 82 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 83 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 84 | int32_t *param_tmp = (int32_t *)p->data; |
| 85 | int32_t param = *param_tmp++; |
| 86 | void *value = p->data + voffset; |
| 87 | int i; |
| 88 | |
| 89 | ALOGV("%s", __func__); |
| 90 | |
| 91 | p->status = 0; |
| 92 | |
| 93 | switch (param) { |
| 94 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: |
| 95 | if (p->vsize < sizeof(uint32_t)) |
| 96 | p->status = -EINVAL; |
| 97 | p->vsize = sizeof(uint32_t); |
| 98 | break; |
| 99 | case BASSBOOST_PARAM_STRENGTH: |
| 100 | if (p->vsize < sizeof(int16_t)) |
| 101 | p->status = -EINVAL; |
| 102 | p->vsize = sizeof(int16_t); |
| 103 | break; |
| 104 | default: |
| 105 | p->status = -EINVAL; |
| 106 | } |
| 107 | |
| 108 | *size = sizeof(effect_param_t) + voffset + p->vsize; |
| 109 | |
| 110 | if (p->status != 0) |
| 111 | return 0; |
| 112 | |
| 113 | switch (param) { |
| 114 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: |
| 115 | ALOGV("%s: BASSBOOST_PARAM_STRENGTH_SUPPORTED", __func__); |
| 116 | if (bass_ctxt->active_index == BASS_BOOST) |
| 117 | *(uint32_t *)value = 1; |
| 118 | else |
| 119 | *(uint32_t *)value = 0; |
| 120 | break; |
| 121 | |
| 122 | case BASSBOOST_PARAM_STRENGTH: |
| 123 | ALOGV("%s: BASSBOOST_PARAM_STRENGTH", __func__); |
| 124 | if (bass_ctxt->active_index == BASS_BOOST) |
| 125 | *(int16_t *)value = bassboost_get_strength(&(bass_ctxt->bassboost_ctxt)); |
| 126 | else |
| 127 | *(int16_t *)value = 0; |
| 128 | break; |
| 129 | |
| 130 | default: |
| 131 | p->status = -EINVAL; |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | int bass_set_parameter(effect_context_t *context, effect_param_t *p, |
| 139 | uint32_t size __unused) |
| 140 | { |
| 141 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 142 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 143 | void *value = p->data + voffset; |
| 144 | int32_t *param_tmp = (int32_t *)p->data; |
| 145 | int32_t param = *param_tmp++; |
| 146 | uint32_t strength; |
| 147 | |
| 148 | ALOGV("%s", __func__); |
| 149 | |
| 150 | p->status = 0; |
| 151 | |
| 152 | switch (param) { |
| 153 | case BASSBOOST_PARAM_STRENGTH: |
| 154 | ALOGV("%s BASSBOOST_PARAM_STRENGTH", __func__); |
| 155 | if (bass_ctxt->active_index == BASS_BOOST) { |
| 156 | strength = (uint32_t)(*(int16_t *)value); |
| 157 | bassboost_set_strength(&(bass_ctxt->bassboost_ctxt), strength); |
| 158 | } else { |
| 159 | /* stength supported only for BB and not for PBE, but do not |
| 160 | * return error for unsupported case, as it fails cts test |
| 161 | */ |
| 162 | ALOGD("%s ignore set strength, index %d", |
| 163 | __func__, bass_ctxt->active_index); |
| 164 | break; |
| 165 | } |
| 166 | break; |
| 167 | default: |
| 168 | p->status = -EINVAL; |
| 169 | break; |
| 170 | } |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | int bass_set_device(effect_context_t *context, uint32_t device) |
| 176 | { |
| 177 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 178 | |
| 179 | if (device == AUDIO_DEVICE_OUT_SPEAKER) { |
| 180 | bass_ctxt->active_index = BASS_PBE; |
| 181 | ALOGV("%s: set PBE mode, device: %x", __func__, device); |
| 182 | } else if (device == AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 183 | device == AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Dhananjay Kumar | 8413788 | 2015-06-05 20:34:50 +0530 | [diff] [blame] | 184 | device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP || |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 185 | device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES) { |
| 186 | ALOGV("%s: set BB mode, device: %x", __func__, device); |
| 187 | bass_ctxt->active_index = BASS_BOOST; |
| 188 | } else { |
| 189 | ALOGI("%s: disabled by device: %x", __func__, device); |
| 190 | bass_ctxt->active_index = BASS_INVALID; |
| 191 | } |
| 192 | |
| 193 | bassboost_set_device((effect_context_t *)&(bass_ctxt->bassboost_ctxt), device); |
| 194 | pbe_set_device((effect_context_t *)&(bass_ctxt->pbe_ctxt), device); |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | int bass_reset(effect_context_t *context) |
| 200 | { |
| 201 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 202 | |
| 203 | bassboost_reset((effect_context_t *)&(bass_ctxt->bassboost_ctxt)); |
| 204 | pbe_reset((effect_context_t *)&(bass_ctxt->pbe_ctxt)); |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | int bass_init(effect_context_t *context) |
| 210 | { |
| 211 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 212 | |
| 213 | // convery i/o channel config to sub effects |
| 214 | bass_ctxt->bassboost_ctxt.common.config = context->config; |
| 215 | bass_ctxt->pbe_ctxt.common.config = context->config; |
| 216 | |
| 217 | ALOGV("%s", __func__); |
| 218 | |
| 219 | bass_ctxt->active_index = BASS_BOOST; |
| 220 | |
| 221 | |
| 222 | bassboost_init((effect_context_t *)&(bass_ctxt->bassboost_ctxt)); |
| 223 | pbe_init((effect_context_t *)&(bass_ctxt->pbe_ctxt)); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | int bass_enable(effect_context_t *context) |
| 229 | { |
| 230 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 231 | |
| 232 | ALOGV("%s", __func__); |
| 233 | |
| 234 | bassboost_enable((effect_context_t *)&(bass_ctxt->bassboost_ctxt)); |
| 235 | pbe_enable((effect_context_t *)&(bass_ctxt->pbe_ctxt)); |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | int bass_disable(effect_context_t *context) |
| 241 | { |
| 242 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 243 | |
| 244 | ALOGV("%s", __func__); |
| 245 | |
| 246 | bassboost_disable((effect_context_t *)&(bass_ctxt->bassboost_ctxt)); |
| 247 | pbe_disable((effect_context_t *)&(bass_ctxt->pbe_ctxt)); |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | int bass_start(effect_context_t *context, output_context_t *output) |
| 253 | { |
| 254 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 255 | |
| 256 | ALOGV("%s", __func__); |
| 257 | |
| 258 | bassboost_start((effect_context_t *)&(bass_ctxt->bassboost_ctxt), output); |
| 259 | pbe_start((effect_context_t *)&(bass_ctxt->pbe_ctxt), output); |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | int bass_stop(effect_context_t *context, output_context_t *output) |
| 265 | { |
| 266 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 267 | |
| 268 | ALOGV("%s", __func__); |
| 269 | |
| 270 | bassboost_stop((effect_context_t *)&(bass_ctxt->bassboost_ctxt), output); |
| 271 | pbe_stop((effect_context_t *)&(bass_ctxt->pbe_ctxt), output); |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | int bass_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 277 | { |
| 278 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 279 | |
| 280 | ALOGV("%s", __func__); |
| 281 | |
| 282 | bassboost_set_mode((effect_context_t *)&(bass_ctxt->bassboost_ctxt), hw_acc_fd); |
| 283 | pbe_set_mode((effect_context_t *)&(bass_ctxt->pbe_ctxt), hw_acc_fd); |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | #undef LOG_TAG |
| 289 | #define LOG_TAG "offload_effect_bb" |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 290 | /* |
| 291 | * Bassboost operations |
| 292 | */ |
| 293 | |
| 294 | int bassboost_get_strength(bassboost_context_t *context) |
| 295 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 296 | ALOGV("%s: ctxt %p, strength: %d", __func__, |
| 297 | context, context->strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 298 | return context->strength; |
| 299 | } |
| 300 | |
| 301 | int bassboost_set_strength(bassboost_context_t *context, uint32_t strength) |
| 302 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 303 | ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 304 | context->strength = strength; |
| 305 | |
| 306 | offload_bassboost_set_strength(&(context->offload_bass), strength); |
| 307 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 308 | offload_bassboost_send_params(context->ctl, &context->offload_bass, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 309 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 310 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 311 | if (context->hw_acc_fd > 0) |
| 312 | hw_acc_bassboost_send_params(context->hw_acc_fd, |
| 313 | &context->offload_bass, |
| 314 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 315 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 319 | int bassboost_set_device(effect_context_t *context, uint32_t device) |
| 320 | { |
| 321 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 322 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 323 | ALOGV("%s: ctxt %p, device 0x%x", __func__, bass_ctxt, device); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 324 | bass_ctxt->device = device; |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 325 | if (device == AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 326 | device == AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Dhananjay Kumar | 8413788 | 2015-06-05 20:34:50 +0530 | [diff] [blame] | 327 | device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP || |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 328 | device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES) { |
| 329 | if (bass_ctxt->temp_disabled) { |
| 330 | if (effect_is_active(&bass_ctxt->common)) { |
| 331 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true); |
| 332 | if (bass_ctxt->ctl) |
| 333 | offload_bassboost_send_params(bass_ctxt->ctl, |
| 334 | &bass_ctxt->offload_bass, |
| 335 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
| 336 | if (bass_ctxt->hw_acc_fd > 0) |
| 337 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 338 | &bass_ctxt->offload_bass, |
| 339 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
| 340 | } |
| 341 | bass_ctxt->temp_disabled = false; |
| 342 | } |
| 343 | } else { |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 344 | if (!bass_ctxt->temp_disabled) { |
| 345 | if (effect_is_active(&bass_ctxt->common)) { |
| 346 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false); |
| 347 | if (bass_ctxt->ctl) |
| 348 | offload_bassboost_send_params(bass_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 349 | &bass_ctxt->offload_bass, |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 350 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 351 | if (bass_ctxt->hw_acc_fd > 0) |
| 352 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 353 | &bass_ctxt->offload_bass, |
| 354 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 355 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 356 | bass_ctxt->temp_disabled = true; |
| 357 | } |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 358 | ALOGI("%s: ctxt %p, disabled based on device", __func__, bass_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 359 | } |
| 360 | offload_bassboost_set_device(&(bass_ctxt->offload_bass), device); |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | int bassboost_reset(effect_context_t *context) |
| 365 | { |
| 366 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | int bassboost_init(effect_context_t *context) |
| 372 | { |
| 373 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 374 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 375 | ALOGV("%s: ctxt %p", __func__, bass_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 376 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
| 377 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 378 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 379 | context->config.inputCfg.samplingRate = 44100; |
| 380 | context->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 381 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 382 | context->config.inputCfg.bufferProvider.cookie = NULL; |
| 383 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 384 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
| 385 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 386 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 387 | context->config.outputCfg.samplingRate = 44100; |
| 388 | context->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 389 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 390 | context->config.outputCfg.bufferProvider.cookie = NULL; |
| 391 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
| 392 | |
| 393 | set_config(context, &context->config); |
| 394 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 395 | bass_ctxt->hw_acc_fd = -1; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 396 | bass_ctxt->temp_disabled = false; |
| 397 | memset(&(bass_ctxt->offload_bass), 0, sizeof(struct bass_boost_params)); |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | int bassboost_enable(effect_context_t *context) |
| 403 | { |
| 404 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 405 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 406 | ALOGV("%s: ctxt %p, strength %d", __func__, bass_ctxt, bass_ctxt->strength); |
wjiang | 95d74c2 | 2014-03-28 12:29:58 +0800 | [diff] [blame] | 407 | |
| 408 | if (!offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)) && |
| 409 | !(bass_ctxt->temp_disabled)) { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 410 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true); |
wjiang | d45948e | 2014-02-24 22:19:43 +0800 | [diff] [blame] | 411 | if (bass_ctxt->ctl && bass_ctxt->strength) |
| 412 | offload_bassboost_send_params(bass_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 413 | &bass_ctxt->offload_bass, |
wjiang | d45948e | 2014-02-24 22:19:43 +0800 | [diff] [blame] | 414 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 415 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 416 | if ((bass_ctxt->hw_acc_fd > 0) && (bass_ctxt->strength)) |
| 417 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 418 | &bass_ctxt->offload_bass, |
| 419 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 420 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
wjiang | d45948e | 2014-02-24 22:19:43 +0800 | [diff] [blame] | 421 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | int bassboost_disable(effect_context_t *context) |
| 426 | { |
| 427 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 428 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 429 | ALOGV("%s: ctxt %p", __func__, bass_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 430 | if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) { |
| 431 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false); |
| 432 | if (bass_ctxt->ctl) |
| 433 | offload_bassboost_send_params(bass_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 434 | &bass_ctxt->offload_bass, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 435 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 436 | if (bass_ctxt->hw_acc_fd > 0) |
| 437 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 438 | &bass_ctxt->offload_bass, |
| 439 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 440 | } |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | int bassboost_start(effect_context_t *context, output_context_t *output) |
| 445 | { |
| 446 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 447 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 448 | ALOGV("%s: ctxt %p, ctl %p, strength %d", __func__, bass_ctxt, |
| 449 | output->ctl, bass_ctxt->strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 450 | bass_ctxt->ctl = output->ctl; |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 451 | if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) { |
Amit Shekhar | d02f2cd | 2014-01-16 16:51:43 -0800 | [diff] [blame] | 452 | if (bass_ctxt->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 453 | offload_bassboost_send_params(bass_ctxt->ctl, &bass_ctxt->offload_bass, |
Amit Shekhar | d02f2cd | 2014-01-16 16:51:43 -0800 | [diff] [blame] | 454 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 455 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 456 | if (bass_ctxt->hw_acc_fd > 0) |
| 457 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 458 | &bass_ctxt->offload_bass, |
| 459 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 460 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
| 461 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 465 | int bassboost_stop(effect_context_t *context, output_context_t *output __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 466 | { |
| 467 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 468 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 469 | ALOGV("%s: ctxt %p", __func__, bass_ctxt); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 470 | if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)) && |
| 471 | bass_ctxt->ctl) { |
| 472 | struct bass_boost_params bassboost; |
| 473 | bassboost.enable_flag = false; |
| 474 | offload_bassboost_send_params(bass_ctxt->ctl, &bassboost, |
| 475 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
| 476 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 477 | bass_ctxt->ctl = NULL; |
| 478 | return 0; |
| 479 | } |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 480 | |
| 481 | int bassboost_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 482 | { |
| 483 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 484 | |
| 485 | ALOGV("%s: ctxt %p", __func__, bass_ctxt); |
| 486 | bass_ctxt->hw_acc_fd = hw_acc_fd; |
| 487 | if ((bass_ctxt->hw_acc_fd > 0) && |
| 488 | (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)))) |
| 489 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 490 | &bass_ctxt->offload_bass, |
| 491 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 492 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
| 493 | return 0; |
| 494 | } |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 495 | |
| 496 | #undef LOG_TAG |
| 497 | #define LOG_TAG "offload_effect_pbe" |
| 498 | /* |
| 499 | * PBE operations |
| 500 | */ |
| 501 | |
| 502 | int pbe_set_device(effect_context_t *context, uint32_t device) |
| 503 | { |
| 504 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 505 | char propValue[PROPERTY_VALUE_MAX]; |
| 506 | bool pbe_enabled_by_prop = false; |
| 507 | |
| 508 | ALOGV("%s: device: %d", __func__, device); |
| 509 | pbe_ctxt->device = device; |
| 510 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 511 | if (property_get("vendor.audio.safx.pbe.enabled", propValue, NULL)) { |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 512 | pbe_enabled_by_prop = atoi(propValue) || |
| 513 | !strncmp("true", propValue, 4); |
| 514 | } |
| 515 | |
| 516 | if (device == AUDIO_DEVICE_OUT_SPEAKER && pbe_enabled_by_prop == true) { |
| 517 | if (pbe_ctxt->temp_disabled) { |
| 518 | if (effect_is_active(&pbe_ctxt->common)) { |
| 519 | offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), true); |
| 520 | if (pbe_ctxt->ctl) |
| 521 | offload_pbe_send_params(pbe_ctxt->ctl, |
| 522 | &pbe_ctxt->offload_pbe, |
| 523 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 524 | OFFLOAD_SEND_PBE_CONFIG); |
| 525 | if (pbe_ctxt->hw_acc_fd > 0) |
| 526 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 527 | &pbe_ctxt->offload_pbe, |
| 528 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 529 | OFFLOAD_SEND_PBE_CONFIG); |
| 530 | } |
| 531 | pbe_ctxt->temp_disabled = false; |
| 532 | } |
| 533 | } else { |
| 534 | if (!pbe_ctxt->temp_disabled) { |
| 535 | if (effect_is_active(&pbe_ctxt->common)) { |
| 536 | offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), false); |
| 537 | if (pbe_ctxt->ctl) |
| 538 | offload_pbe_send_params(pbe_ctxt->ctl, |
| 539 | &pbe_ctxt->offload_pbe, |
| 540 | OFFLOAD_SEND_PBE_ENABLE_FLAG); |
| 541 | if (pbe_ctxt->hw_acc_fd > 0) |
| 542 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 543 | &pbe_ctxt->offload_pbe, |
| 544 | OFFLOAD_SEND_PBE_ENABLE_FLAG); |
| 545 | } |
| 546 | pbe_ctxt->temp_disabled = true; |
| 547 | } |
| 548 | } |
| 549 | offload_pbe_set_device(&(pbe_ctxt->offload_pbe), device); |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | int pbe_reset(effect_context_t *context) |
| 554 | { |
| 555 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | int pbe_init(effect_context_t *context) |
| 561 | { |
| 562 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 563 | |
| 564 | ALOGV("%s", __func__); |
| 565 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
| 566 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 567 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 568 | context->config.inputCfg.samplingRate = 44100; |
| 569 | context->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 570 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 571 | context->config.inputCfg.bufferProvider.cookie = NULL; |
| 572 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 573 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
| 574 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 575 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 576 | context->config.outputCfg.samplingRate = 44100; |
| 577 | context->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 578 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 579 | context->config.outputCfg.bufferProvider.cookie = NULL; |
| 580 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
| 581 | |
| 582 | set_config(context, &context->config); |
| 583 | |
| 584 | pbe_ctxt->hw_acc_fd = -1; |
| 585 | pbe_ctxt->temp_disabled = false; |
| 586 | memset(&(pbe_ctxt->offload_pbe), 0, sizeof(struct pbe_params)); |
| 587 | pbe_load_config(&(pbe_ctxt->offload_pbe)); |
| 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | int pbe_enable(effect_context_t *context) |
| 593 | { |
| 594 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 595 | |
| 596 | ALOGV("%s", __func__); |
| 597 | |
| 598 | if (!offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe)) && |
| 599 | !(pbe_ctxt->temp_disabled)) { |
| 600 | offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), true); |
| 601 | if (pbe_ctxt->ctl) |
| 602 | offload_pbe_send_params(pbe_ctxt->ctl, |
| 603 | &pbe_ctxt->offload_pbe, |
| 604 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 605 | OFFLOAD_SEND_PBE_CONFIG); |
| 606 | if (pbe_ctxt->hw_acc_fd > 0) |
| 607 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 608 | &pbe_ctxt->offload_pbe, |
| 609 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 610 | OFFLOAD_SEND_PBE_CONFIG); |
| 611 | } |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | int pbe_disable(effect_context_t *context) |
| 616 | { |
| 617 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 618 | |
| 619 | ALOGV("%s", __func__); |
| 620 | if (offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe))) { |
| 621 | offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), false); |
| 622 | if (pbe_ctxt->ctl) |
| 623 | offload_pbe_send_params(pbe_ctxt->ctl, |
| 624 | &pbe_ctxt->offload_pbe, |
| 625 | OFFLOAD_SEND_PBE_ENABLE_FLAG); |
| 626 | if (pbe_ctxt->hw_acc_fd > 0) |
| 627 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 628 | &pbe_ctxt->offload_pbe, |
| 629 | OFFLOAD_SEND_PBE_ENABLE_FLAG); |
| 630 | } |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | int pbe_start(effect_context_t *context, output_context_t *output) |
| 635 | { |
| 636 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 637 | |
| 638 | ALOGV("%s", __func__); |
| 639 | pbe_ctxt->ctl = output->ctl; |
| 640 | ALOGV("output->ctl: %p", output->ctl); |
| 641 | if (offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe))) { |
| 642 | if (pbe_ctxt->ctl) |
| 643 | offload_pbe_send_params(pbe_ctxt->ctl, &pbe_ctxt->offload_pbe, |
| 644 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 645 | OFFLOAD_SEND_PBE_CONFIG); |
| 646 | if (pbe_ctxt->hw_acc_fd > 0) |
| 647 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 648 | &pbe_ctxt->offload_pbe, |
| 649 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 650 | OFFLOAD_SEND_PBE_CONFIG); |
| 651 | } |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | int pbe_stop(effect_context_t *context, output_context_t *output __unused) |
| 656 | { |
| 657 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 658 | |
| 659 | ALOGV("%s", __func__); |
| 660 | pbe_ctxt->ctl = NULL; |
| 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | int pbe_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 665 | { |
| 666 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 667 | |
| 668 | ALOGV("%s: ctxt %p", __func__, pbe_ctxt); |
| 669 | pbe_ctxt->hw_acc_fd = hw_acc_fd; |
| 670 | if ((pbe_ctxt->hw_acc_fd > 0) && |
| 671 | (offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe)))) |
| 672 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 673 | &pbe_ctxt->offload_pbe, |
| 674 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 675 | OFFLOAD_SEND_PBE_CONFIG); |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | static int pbe_load_config(struct pbe_params *params) |
| 680 | { |
| 681 | int ret = 0; |
| 682 | uint32_t len = 0; |
| 683 | uint32_t propValue = 0; |
| 684 | uint32_t pbe_app_type = PBE_CONF_APP_ID; |
| 685 | char propValueStr[PROPERTY_VALUE_MAX]; |
| 686 | void *acdb_handle = NULL; |
| 687 | acdb_get_audio_cal_t acdb_get_audio_cal = NULL; |
Weiyin Jiang | 90ac1ea | 2017-04-13 14:18:23 +0800 | [diff] [blame] | 688 | acdb_audio_cal_cfg_t cal_cfg; |
| 689 | memset(&cal_cfg, 0, sizeof(acdb_audio_cal_cfg_t)); |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 690 | |
| 691 | acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 692 | if (acdb_handle == NULL) { |
| 693 | ALOGE("%s error opening library %s", __func__, LIB_ACDB_LOADER); |
| 694 | return -EFAULT; |
| 695 | } |
| 696 | |
| 697 | acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(acdb_handle, |
| 698 | "acdb_loader_get_audio_cal_v2"); |
| 699 | if (acdb_get_audio_cal == NULL) { |
| 700 | dlclose(acdb_handle); |
| 701 | ALOGE("%s error resolving acdb func symbols", __func__); |
| 702 | return -EFAULT; |
| 703 | } |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 704 | if (property_get("vendor.audio.safx.pbe.app.type", propValueStr, "0")) { |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 705 | propValue = atoll(propValueStr); |
| 706 | if (propValue != 0) { |
| 707 | pbe_app_type = propValue; |
| 708 | } |
| 709 | } |
| 710 | ALOGD("%s pbe_app_type = 0x%.8x", __func__, pbe_app_type); |
| 711 | |
| 712 | cal_cfg.persist = 1; |
| 713 | cal_cfg.cal_type = AUDIO_STREAM_CAL_TYPE; |
| 714 | cal_cfg.app_type = pbe_app_type; |
| 715 | cal_cfg.module_id = PBE_CONF_MODULE_ID; |
| 716 | cal_cfg.param_id = PBE_CONF_PARAM_ID; |
| 717 | |
| 718 | len = sizeof(params->config); |
| 719 | ret = acdb_get_audio_cal((void *)&cal_cfg, (void*)&(params->config), &len); |
| 720 | ALOGD("%s ret = %d, len = %u", __func__, ret, len); |
| 721 | if (ret == 0) |
| 722 | params->cfg_len = len; |
| 723 | |
| 724 | dlclose(acdb_handle); |
| 725 | return ret; |
| 726 | } |