Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 1 | /* |
Weiyin Jiang | 90ac1ea | 2017-04-13 14:18:23 +0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, 2017, 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 | |
| 20 | #define LOG_TAG "offload_effect_virtualizer" |
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> |
| 25 | #include <tinyalsa/asoundlib.h> |
Subhash Chandra Bose Naripeddy | 090a2aa | 2014-01-30 14:03:12 -0800 | [diff] [blame] | 26 | #include <sound/audio_effects.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 27 | #include <audio_effects/effect_virtualizer.h> |
| 28 | |
| 29 | #include "effect_api.h" |
| 30 | #include "virtualizer.h" |
| 31 | |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 32 | #define VIRUALIZER_MAX_LATENCY 30 |
| 33 | |
| 34 | #ifdef AUDIO_FEATURE_ENABLED_GCOV |
| 35 | extern void __gcov_flush(); |
| 36 | static void enable_gcov() |
| 37 | { |
| 38 | __gcov_flush(); |
| 39 | } |
| 40 | #else |
| 41 | static void enable_gcov() |
| 42 | { |
| 43 | } |
| 44 | #endif |
| 45 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 46 | /* Offload Virtualizer UUID: 509a4498-561a-4bea-b3b1-0002a5d5c51b */ |
| 47 | const effect_descriptor_t virtualizer_descriptor = { |
| 48 | {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
| 49 | {0x509a4498, 0x561a, 0x4bea, 0xb3b1, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid |
| 50 | EFFECT_CONTROL_API_VERSION, |
Weiyin Jiang | 90ac1ea | 2017-04-13 14:18:23 +0800 | [diff] [blame] | 51 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL | |
| 52 | EFFECT_FLAG_VOLUME_CTRL), |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 53 | 0, /* TODO */ |
| 54 | 1, |
| 55 | "MSM offload virtualizer", |
| 56 | "The Android Open Source Project", |
| 57 | }; |
| 58 | |
| 59 | /* |
| 60 | * Virtualizer operations |
| 61 | */ |
| 62 | |
| 63 | int virtualizer_get_strength(virtualizer_context_t *context) |
| 64 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 65 | ALOGV("%s: ctxt %p, strength: %d", __func__, context, context->strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 66 | return context->strength; |
| 67 | } |
| 68 | |
| 69 | int virtualizer_set_strength(virtualizer_context_t *context, uint32_t strength) |
| 70 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 71 | ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 72 | context->strength = strength; |
| 73 | |
Weiyin Jiang | c8082d9 | 2015-07-21 11:26:02 +0800 | [diff] [blame] | 74 | /* |
| 75 | * Zero strength is not equivalent to disable state as down mix |
| 76 | * is still happening for multichannel inputs. |
| 77 | * For better user experience, explicitly disable virtualizer module |
| 78 | * when strength is 0. |
| 79 | */ |
Dhananjay Kumar | f7026ef | 2015-12-15 10:51:10 +0530 | [diff] [blame] | 80 | if (context->enabled_by_client) |
| 81 | offload_virtualizer_set_enable_flag(&(context->offload_virt), |
Weiyin Jiang | c8082d9 | 2015-07-21 11:26:02 +0800 | [diff] [blame] | 82 | ((strength > 0) && !(context->temp_disabled)) ? |
| 83 | true : false); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 84 | offload_virtualizer_set_strength(&(context->offload_virt), strength); |
| 85 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 86 | offload_virtualizer_send_params(context->ctl, &context->offload_virt, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 87 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | |
| 88 | OFFLOAD_SEND_VIRTUALIZER_STRENGTH); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 89 | if (context->hw_acc_fd > 0) |
| 90 | hw_acc_virtualizer_send_params(context->hw_acc_fd, |
| 91 | &context->offload_virt, |
| 92 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | |
| 93 | OFFLOAD_SEND_VIRTUALIZER_STRENGTH); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 97 | /* |
| 98 | * Check if an audio device is supported by this implementation |
| 99 | * |
| 100 | * [in] |
| 101 | * device device that is intented for processing (e.g. for binaural vs transaural) |
| 102 | * [out] |
| 103 | * false device is not applicable for effect |
| 104 | * true device is applicable for effect |
| 105 | */ |
| 106 | bool virtualizer_is_device_supported(audio_devices_t device) { |
| 107 | switch (device) { |
| 108 | case AUDIO_DEVICE_OUT_SPEAKER: |
| 109 | case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT: |
| 110 | case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER: |
| 111 | #ifdef AFE_PROXY_ENABLED |
| 112 | case AUDIO_DEVICE_OUT_PROXY: |
| 113 | #endif |
| 114 | case AUDIO_DEVICE_OUT_AUX_DIGITAL: |
| 115 | case AUDIO_DEVICE_OUT_USB_ACCESSORY: |
| 116 | case AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET: |
| 117 | return false; |
| 118 | default : |
| 119 | return true; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * Check if a channel mask + audio device is supported by this implementation |
| 125 | * |
| 126 | * [in] |
| 127 | * channel_mask channel mask of input buffer |
| 128 | * device device that is intented for processing (e.g. for binaural vs transaural) |
| 129 | * [out] |
| 130 | * false if the configuration is not supported or it is unknown |
| 131 | * true if the configuration is supported |
| 132 | */ |
| 133 | bool virtualizer_is_configuration_supported(audio_channel_mask_t channel_mask, |
| 134 | audio_devices_t device) { |
| 135 | uint32_t channelCount = audio_channel_count_from_out_mask(channel_mask); |
| 136 | if ((channelCount == 0) || (channelCount > 2)) { |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | return virtualizer_is_device_supported(device); |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Force the virtualization mode to that of the given audio device |
| 145 | * |
| 146 | * [in] |
| 147 | * context effect engine context |
| 148 | * forced_device device whose virtualization mode we'll always use |
| 149 | * [out] |
| 150 | * -EINVAL if the device is not supported or is unknown |
| 151 | * 0 if the device is supported and the virtualization mode forced |
| 152 | */ |
| 153 | int virtualizer_force_virtualization_mode(virtualizer_context_t *context, |
| 154 | audio_devices_t forced_device) { |
| 155 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 156 | int status = 0; |
| 157 | bool use_virt = false; |
Dhananjay Kumar | f7026ef | 2015-12-15 10:51:10 +0530 | [diff] [blame] | 158 | int is_virt_enabled = virt_ctxt->enabled_by_client; |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 159 | |
| 160 | ALOGV("%s: ctxt %p, forcedDev=0x%x enabled=%d tmpDisabled=%d", __func__, virt_ctxt, |
| 161 | forced_device, is_virt_enabled, virt_ctxt->temp_disabled); |
| 162 | |
| 163 | if (virtualizer_is_device_supported(forced_device) == false) { |
| 164 | if (forced_device != AUDIO_DEVICE_NONE) { |
| 165 | //forced device is not supported, make it behave as a reset of forced mode |
| 166 | forced_device = AUDIO_DEVICE_NONE; |
| 167 | // but return an error |
| 168 | status = -EINVAL; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (forced_device == AUDIO_DEVICE_NONE) { |
| 173 | // disabling forced virtualization mode: |
| 174 | // verify whether the virtualization should be enabled or disabled |
| 175 | if (virtualizer_is_device_supported(virt_ctxt->device)) { |
| 176 | use_virt = (is_virt_enabled == true); |
| 177 | } |
| 178 | virt_ctxt->forced_device = AUDIO_DEVICE_NONE; |
| 179 | } else { |
| 180 | // forcing virtualization mode: |
| 181 | // TODO: we assume device is supported, so hard coded a fixed one. |
| 182 | virt_ctxt->forced_device = AUDIO_DEVICE_OUT_WIRED_HEADPHONE; |
| 183 | // TODO: only enable for a supported mode, when the effect is enabled |
| 184 | use_virt = (is_virt_enabled == true); |
| 185 | } |
| 186 | |
| 187 | if (use_virt) { |
| 188 | if (virt_ctxt->temp_disabled == true) { |
| 189 | if (effect_is_active(&virt_ctxt->common)) { |
| 190 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true); |
| 191 | if (virt_ctxt->ctl) |
| 192 | offload_virtualizer_send_params(virt_ctxt->ctl, |
| 193 | &virt_ctxt->offload_virt, |
| 194 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
| 195 | if (virt_ctxt->hw_acc_fd > 0) |
| 196 | hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd, |
| 197 | &virt_ctxt->offload_virt, |
| 198 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
| 199 | } |
| 200 | ALOGV("%s: re-enable VIRTUALIZER", __func__); |
| 201 | virt_ctxt->temp_disabled = false; |
| 202 | } else { |
| 203 | ALOGV("%s: leaving VIRTUALIZER enabled", __func__); |
| 204 | } |
| 205 | } else { |
| 206 | if (virt_ctxt->temp_disabled == false) { |
| 207 | if (effect_is_active(&virt_ctxt->common)) { |
| 208 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false); |
| 209 | if (virt_ctxt->ctl) |
| 210 | offload_virtualizer_send_params(virt_ctxt->ctl, |
| 211 | &virt_ctxt->offload_virt, |
| 212 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
| 213 | if (virt_ctxt->hw_acc_fd > 0) |
| 214 | hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd, |
| 215 | &virt_ctxt->offload_virt, |
| 216 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
| 217 | } |
| 218 | ALOGV("%s: disable VIRTUALIZER", __func__); |
| 219 | virt_ctxt->temp_disabled = true; |
| 220 | } else { |
| 221 | ALOGV("%s: leaving VIRTUALIZER disabled", __func__); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | ALOGV("after %s: ctxt %p, enabled=%d tmpDisabled=%d", __func__, virt_ctxt, |
| 226 | is_virt_enabled, virt_ctxt->temp_disabled); |
| 227 | |
| 228 | return status; |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * Get the virtual speaker angles for a channel mask + audio device configuration |
| 233 | * which is guaranteed to be supported by this implementation |
| 234 | * |
| 235 | * [in] |
| 236 | * channel_mask the channel mask of the input to virtualize |
| 237 | * device the type of device that affects the processing (e.g. for binaural vs transaural) |
| 238 | * [in/out] |
| 239 | * speaker_angles the array of integer where each speaker angle is written as a triplet in the |
| 240 | * following format: |
| 241 | * int32_t a bit mask with a single value selected for each speaker, following |
| 242 | * the convention of the audio_channel_mask_t type |
| 243 | * int32_t a value in degrees expressing the speaker azimuth, where 0 is in front |
| 244 | * of the user, 180 behind, -90 to the left, 90 to the right of the user |
| 245 | * int32_t a value in degrees expressing the speaker elevation, where 0 is the |
| 246 | * horizontal plane, +90 is directly above the user, -90 below |
| 247 | * |
| 248 | */ |
| 249 | void virtualizer_get_speaker_angles(audio_channel_mask_t channel_mask __unused, |
| 250 | audio_devices_t device __unused, int32_t *speaker_angles) { |
| 251 | // the channel count is guaranteed to be 1 or 2 |
| 252 | // the device is guaranteed to be of type headphone |
| 253 | // this virtualizer is always 2in with speakers at -90 and 90deg of azimuth, 0deg of elevation |
| 254 | *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_LEFT; |
| 255 | *speaker_angles++ = -90; // azimuth |
| 256 | *speaker_angles++ = 0; // elevation |
| 257 | *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_RIGHT; |
| 258 | *speaker_angles++ = 90; // azimuth |
| 259 | *speaker_angles = 0; // elevation |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * Retrieve the current device whose processing mode is used by this effect |
| 264 | * |
| 265 | * [out] |
| 266 | * AUDIO_DEVICE_NONE if the effect is not virtualizing |
| 267 | * or the device type if the effect is virtualizing |
| 268 | */ |
| 269 | audio_devices_t virtualizer_get_virtualization_mode(virtualizer_context_t *context) { |
| 270 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 271 | audio_devices_t device = AUDIO_DEVICE_NONE; |
| 272 | |
| 273 | if ((offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) |
| 274 | && (virt_ctxt->temp_disabled == false)) { |
| 275 | if (virt_ctxt->forced_device != AUDIO_DEVICE_NONE) { |
| 276 | // virtualization mode is forced, return that device |
| 277 | device = virt_ctxt->forced_device; |
| 278 | } else { |
| 279 | // no forced mode, return the current device |
| 280 | device = virt_ctxt->device; |
| 281 | } |
| 282 | } |
| 283 | ALOGV("%s: returning 0x%x", __func__, device); |
| 284 | return device; |
| 285 | } |
| 286 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 287 | int virtualizer_get_parameter(effect_context_t *context, effect_param_t *p, |
| 288 | uint32_t *size) |
| 289 | { |
| 290 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 291 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 292 | int32_t *param_tmp = (int32_t *)p->data; |
| 293 | int32_t param = *param_tmp++; |
| 294 | void *value = p->data + voffset; |
| 295 | int i; |
| 296 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 297 | ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 298 | |
| 299 | p->status = 0; |
| 300 | |
| 301 | switch (param) { |
| 302 | case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED: |
| 303 | if (p->vsize < sizeof(uint32_t)) |
| 304 | p->status = -EINVAL; |
| 305 | p->vsize = sizeof(uint32_t); |
| 306 | break; |
| 307 | case VIRTUALIZER_PARAM_STRENGTH: |
| 308 | if (p->vsize < sizeof(int16_t)) |
| 309 | p->status = -EINVAL; |
| 310 | p->vsize = sizeof(int16_t); |
| 311 | break; |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 312 | case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES: |
| 313 | // return value size can only be interpreted as relative to input value, |
| 314 | // deferring validity check to below |
| 315 | break; |
| 316 | case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE: |
| 317 | if (p->vsize != sizeof(uint32_t)) |
| 318 | p->status = -EINVAL; |
| 319 | p->vsize = sizeof(uint32_t); |
| 320 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 321 | default: |
| 322 | p->status = -EINVAL; |
| 323 | } |
| 324 | |
| 325 | *size = sizeof(effect_param_t) + voffset + p->vsize; |
| 326 | |
| 327 | if (p->status != 0) |
| 328 | return 0; |
| 329 | |
| 330 | switch (param) { |
| 331 | case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 332 | *(uint32_t *)value = 1; |
| 333 | break; |
| 334 | |
| 335 | case VIRTUALIZER_PARAM_STRENGTH: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 336 | *(int16_t *)value = virtualizer_get_strength(virt_ctxt); |
| 337 | break; |
| 338 | |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 339 | case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES: |
| 340 | { |
| 341 | const audio_channel_mask_t channel_mask = (audio_channel_mask_t) *param_tmp++; |
| 342 | const audio_devices_t device = (audio_devices_t) *param_tmp; |
| 343 | uint32_t channel_cnt = audio_channel_count_from_out_mask(channel_mask); |
| 344 | |
| 345 | if (p->vsize < 3 * channel_cnt * sizeof(int32_t)){ |
| 346 | p->status = -EINVAL; |
| 347 | break; |
| 348 | } |
| 349 | // verify the configuration is supported |
| 350 | if(virtualizer_is_configuration_supported(channel_mask, device)) { |
| 351 | // configuration is supported, get the angles |
| 352 | virtualizer_get_speaker_angles(channel_mask, device, (int32_t *)value); |
| 353 | } else { |
| 354 | p->status = -EINVAL; |
| 355 | } |
| 356 | |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE: |
| 361 | *(uint32_t *)value = (uint32_t) virtualizer_get_virtualization_mode(virt_ctxt); |
| 362 | break; |
| 363 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 364 | default: |
| 365 | p->status = -EINVAL; |
| 366 | break; |
| 367 | } |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | int virtualizer_set_parameter(effect_context_t *context, effect_param_t *p, |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 373 | uint32_t size __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 374 | { |
| 375 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 376 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 377 | void *value = p->data + voffset; |
| 378 | int32_t *param_tmp = (int32_t *)p->data; |
| 379 | int32_t param = *param_tmp++; |
| 380 | uint32_t strength; |
| 381 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 382 | ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 383 | |
| 384 | p->status = 0; |
| 385 | |
| 386 | switch (param) { |
| 387 | case VIRTUALIZER_PARAM_STRENGTH: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 388 | strength = (uint32_t)(*(int16_t *)value); |
| 389 | virtualizer_set_strength(virt_ctxt, strength); |
| 390 | break; |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 391 | case VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE: |
| 392 | { |
| 393 | const audio_devices_t device = *(audio_devices_t *)value; |
| 394 | if (0 != virtualizer_force_virtualization_mode(virt_ctxt, device)) { |
| 395 | p->status = -EINVAL; |
| 396 | } |
| 397 | break; |
| 398 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 399 | default: |
| 400 | p->status = -EINVAL; |
| 401 | break; |
| 402 | } |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | int virtualizer_set_device(effect_context_t *context, uint32_t device) |
| 408 | { |
| 409 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 410 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 411 | ALOGV("%s: ctxt %p, device: 0x%x", __func__, virt_ctxt, device); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 412 | virt_ctxt->device = device; |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 413 | |
| 414 | if (virt_ctxt->forced_device == AUDIO_DEVICE_NONE) { |
| 415 | // default case unless configuration is forced |
| 416 | if (virtualizer_is_device_supported(device) == false) { |
| 417 | if (!virt_ctxt->temp_disabled) { |
Dhananjay Kumar | f7026ef | 2015-12-15 10:51:10 +0530 | [diff] [blame] | 418 | if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) { |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 419 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false); |
| 420 | if (virt_ctxt->ctl) |
| 421 | offload_virtualizer_send_params(virt_ctxt->ctl, |
| 422 | &virt_ctxt->offload_virt, |
| 423 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
| 424 | if (virt_ctxt->hw_acc_fd > 0) |
| 425 | hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd, |
| 426 | &virt_ctxt->offload_virt, |
| 427 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
| 428 | } |
| 429 | virt_ctxt->temp_disabled = true; |
| 430 | ALOGI("%s: ctxt %p, disabled based on device", __func__, virt_ctxt); |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 431 | } |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 432 | } else { |
| 433 | if (virt_ctxt->temp_disabled) { |
Dhananjay Kumar | f7026ef | 2015-12-15 10:51:10 +0530 | [diff] [blame] | 434 | if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) { |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 435 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true); |
| 436 | if (virt_ctxt->ctl) |
| 437 | offload_virtualizer_send_params(virt_ctxt->ctl, |
| 438 | &virt_ctxt->offload_virt, |
| 439 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
| 440 | if (virt_ctxt->hw_acc_fd > 0) |
| 441 | hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd, |
| 442 | &virt_ctxt->offload_virt, |
| 443 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
| 444 | } |
| 445 | virt_ctxt->temp_disabled = false; |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 446 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 447 | } |
| 448 | } |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 449 | // else virtualization mode is forced to a certain device, nothing to do |
| 450 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 451 | offload_virtualizer_set_device(&(virt_ctxt->offload_virt), device); |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | int virtualizer_reset(effect_context_t *context) |
| 456 | { |
| 457 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | int virtualizer_init(effect_context_t *context) |
| 463 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 464 | ALOGV("%s: ctxt %p", __func__, context); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 465 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 466 | |
| 467 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
| 468 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 469 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 470 | context->config.inputCfg.samplingRate = 44100; |
| 471 | context->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 472 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 473 | context->config.inputCfg.bufferProvider.cookie = NULL; |
| 474 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 475 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
| 476 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 477 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 478 | context->config.outputCfg.samplingRate = 44100; |
| 479 | context->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 480 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 481 | context->config.outputCfg.bufferProvider.cookie = NULL; |
| 482 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
| 483 | |
| 484 | set_config(context, &context->config); |
| 485 | |
Dhananjay Kumar | f7026ef | 2015-12-15 10:51:10 +0530 | [diff] [blame] | 486 | virt_ctxt->enabled_by_client = false; |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 487 | virt_ctxt->temp_disabled = false; |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 488 | virt_ctxt->hw_acc_fd = -1; |
Weiyin Jiang | b64b7dd | 2015-03-23 00:54:14 +0800 | [diff] [blame] | 489 | virt_ctxt->forced_device = AUDIO_DEVICE_NONE; |
| 490 | virt_ctxt->device = AUDIO_DEVICE_NONE; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 491 | memset(&(virt_ctxt->offload_virt), 0, sizeof(struct virtualizer_params)); |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 492 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | int virtualizer_enable(effect_context_t *context) |
| 497 | { |
| 498 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 499 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 500 | ALOGV("%s: ctxt %p, strength %d", __func__, virt_ctxt, virt_ctxt->strength); |
wjiang | 95d74c2 | 2014-03-28 12:29:58 +0800 | [diff] [blame] | 501 | |
Dhananjay Kumar | f7026ef | 2015-12-15 10:51:10 +0530 | [diff] [blame] | 502 | virt_ctxt->enabled_by_client = true; |
wjiang | 95d74c2 | 2014-03-28 12:29:58 +0800 | [diff] [blame] | 503 | if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) && |
| 504 | !(virt_ctxt->temp_disabled)) { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 505 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true); |
wjiang | d45948e | 2014-02-24 22:19:43 +0800 | [diff] [blame] | 506 | if (virt_ctxt->ctl && virt_ctxt->strength) |
| 507 | offload_virtualizer_send_params(virt_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 508 | &virt_ctxt->offload_virt, |
wjiang | d45948e | 2014-02-24 22:19:43 +0800 | [diff] [blame] | 509 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 510 | OFFLOAD_SEND_VIRTUALIZER_STRENGTH); |
| 511 | if ((virt_ctxt->hw_acc_fd > 0) && virt_ctxt->strength) |
| 512 | hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd, |
| 513 | &virt_ctxt->offload_virt, |
| 514 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | |
| 515 | OFFLOAD_SEND_VIRTUALIZER_STRENGTH); |
wjiang | d45948e | 2014-02-24 22:19:43 +0800 | [diff] [blame] | 516 | } |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 517 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | int virtualizer_disable(effect_context_t *context) |
| 522 | { |
| 523 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 524 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 525 | ALOGV("%s: ctxt %p", __func__, virt_ctxt); |
Dhananjay Kumar | f7026ef | 2015-12-15 10:51:10 +0530 | [diff] [blame] | 526 | |
| 527 | virt_ctxt->enabled_by_client = false; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 528 | if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) { |
| 529 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false); |
| 530 | if (virt_ctxt->ctl) |
| 531 | offload_virtualizer_send_params(virt_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 532 | &virt_ctxt->offload_virt, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 533 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 534 | if (virt_ctxt->hw_acc_fd > 0) |
| 535 | hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd, |
| 536 | &virt_ctxt->offload_virt, |
| 537 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 538 | } |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 539 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | int virtualizer_start(effect_context_t *context, output_context_t *output) |
| 544 | { |
| 545 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 546 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 547 | ALOGV("%s: ctxt %p, ctl %p", __func__, virt_ctxt, output->ctl); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 548 | virt_ctxt->ctl = output->ctl; |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 549 | if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) { |
Amit Shekhar | d02f2cd | 2014-01-16 16:51:43 -0800 | [diff] [blame] | 550 | if (virt_ctxt->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 551 | offload_virtualizer_send_params(virt_ctxt->ctl, &virt_ctxt->offload_virt, |
Amit Shekhar | d02f2cd | 2014-01-16 16:51:43 -0800 | [diff] [blame] | 552 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | |
| 553 | OFFLOAD_SEND_VIRTUALIZER_STRENGTH); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 554 | if (virt_ctxt->hw_acc_fd > 0) |
| 555 | hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd, |
| 556 | &virt_ctxt->offload_virt, |
| 557 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | |
| 558 | OFFLOAD_SEND_VIRTUALIZER_STRENGTH); |
| 559 | } |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 560 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 561 | return 0; |
| 562 | } |
| 563 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 564 | int virtualizer_stop(effect_context_t *context, output_context_t *output __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 565 | { |
| 566 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 567 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 568 | ALOGV("%s: ctxt %p", __func__, virt_ctxt); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 569 | if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) && |
| 570 | virt_ctxt->ctl) { |
| 571 | struct virtualizer_params virt; |
| 572 | virt.enable_flag = false; |
| 573 | offload_virtualizer_send_params(virt_ctxt->ctl, &virt, |
| 574 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); |
| 575 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 576 | virt_ctxt->ctl = NULL; |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 577 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 578 | return 0; |
| 579 | } |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 580 | |
| 581 | int virtualizer_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 582 | { |
| 583 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; |
| 584 | |
| 585 | ALOGV("%s: ctxt %p", __func__, virt_ctxt); |
| 586 | virt_ctxt->hw_acc_fd = hw_acc_fd; |
| 587 | if ((virt_ctxt->hw_acc_fd > 0) && |
| 588 | (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)))) |
| 589 | hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd, |
| 590 | &virt_ctxt->offload_virt, |
| 591 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | |
| 592 | OFFLOAD_SEND_VIRTUALIZER_STRENGTH); |
| 593 | return 0; |
| 594 | } |