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