blob: 18aaeecc40f230c900d5774392a42bb7cb9bf8df [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Trinath Thammishetty765efd22018-08-20 13:23:24 +05302 * Copyright (c) 2013-2015, 2017-2018, The Linux Foundation. All rights reserved.
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08003 * 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 Naripeddye40a7cd2014-06-03 19:42:41 -070021//#define LOG_NDEBUG 0
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080022
23#include <cutils/list.h>
24#include <cutils/log.h>
25#include <tinyalsa/asoundlib.h>
Subhash Chandra Bose Naripeddy090a2aa2014-01-30 14:03:12 -080026#include <sound/audio_effects.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080027#include <audio_effects/effect_virtualizer.h>
28
29#include "effect_api.h"
30#include "virtualizer.h"
31
Trinath Thammishetty765efd22018-08-20 13:23:24 +053032#define VIRUALIZER_MAX_LATENCY 30
33
Vatsal Buchac09ae062018-11-14 13:25:08 +053034#ifdef AUDIO_FEATURE_ENABLED_GCOV
35extern void __gcov_flush();
36static void enable_gcov()
37{
38 __gcov_flush();
39}
40#else
41static void enable_gcov()
42{
43}
44#endif
45
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080046/* Offload Virtualizer UUID: 509a4498-561a-4bea-b3b1-0002a5d5c51b */
47const 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 Jiang90ac1ea2017-04-13 14:18:23 +080051 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL |
52 EFFECT_FLAG_VOLUME_CTRL),
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080053 0, /* TODO */
54 1,
55 "MSM offload virtualizer",
56 "The Android Open Source Project",
57};
58
59/*
60 * Virtualizer operations
61 */
62
63int virtualizer_get_strength(virtualizer_context_t *context)
64{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053065 ALOGV("%s: ctxt %p, strength: %d", __func__, context, context->strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080066 return context->strength;
67}
68
69int virtualizer_set_strength(virtualizer_context_t *context, uint32_t strength)
70{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053071 ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080072 context->strength = strength;
73
Weiyin Jiangc8082d92015-07-21 11:26:02 +080074 /*
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 Kumarf7026ef2015-12-15 10:51:10 +053080 if (context->enabled_by_client)
81 offload_virtualizer_set_enable_flag(&(context->offload_virt),
Weiyin Jiangc8082d92015-07-21 11:26:02 +080082 ((strength > 0) && !(context->temp_disabled)) ?
83 true : false);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080084 offload_virtualizer_set_strength(&(context->offload_virt), strength);
85 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070086 offload_virtualizer_send_params(context->ctl, &context->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080087 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
88 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070089 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 Naripeddy3eedc002013-11-12 20:45:15 -080094 return 0;
95}
96
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +080097/*
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 */
106bool 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 */
133bool 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 */
153int 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 Kumarf7026ef2015-12-15 10:51:10 +0530158 int is_virt_enabled = virt_ctxt->enabled_by_client;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800159
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 */
249void 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 */
269audio_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 Naripeddy3eedc002013-11-12 20:45:15 -0800287int 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 Kumar574f3922014-03-25 17:41:44 +0530297 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800298
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 Jiangb64b7dd2015-03-23 00:54:14 +0800312 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;
Trinath Thammishetty765efd22018-08-20 13:23:24 +0530321 case VIRTUALIZER_PARAM_LATENCY:
322 if (p->vsize < sizeof(uint32_t))
323 p->status = -EINVAL;
324 p->vsize = sizeof(uint32_t);
325 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800326 default:
327 p->status = -EINVAL;
328 }
329
330 *size = sizeof(effect_param_t) + voffset + p->vsize;
331
332 if (p->status != 0)
333 return 0;
334
335 switch (param) {
336 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800337 *(uint32_t *)value = 1;
338 break;
339
340 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800341 *(int16_t *)value = virtualizer_get_strength(virt_ctxt);
342 break;
343
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800344 case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
345 {
346 const audio_channel_mask_t channel_mask = (audio_channel_mask_t) *param_tmp++;
347 const audio_devices_t device = (audio_devices_t) *param_tmp;
348 uint32_t channel_cnt = audio_channel_count_from_out_mask(channel_mask);
349
350 if (p->vsize < 3 * channel_cnt * sizeof(int32_t)){
351 p->status = -EINVAL;
352 break;
353 }
354 // verify the configuration is supported
355 if(virtualizer_is_configuration_supported(channel_mask, device)) {
356 // configuration is supported, get the angles
357 virtualizer_get_speaker_angles(channel_mask, device, (int32_t *)value);
358 } else {
359 p->status = -EINVAL;
360 }
361
362 break;
363 }
364
365 case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
366 *(uint32_t *)value = (uint32_t) virtualizer_get_virtualization_mode(virt_ctxt);
367 break;
368
Trinath Thammishetty765efd22018-08-20 13:23:24 +0530369 case VIRTUALIZER_PARAM_LATENCY:
370 *(uint32_t *)value = VIRUALIZER_MAX_LATENCY;
371 break;
372
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800373 default:
374 p->status = -EINVAL;
375 break;
376 }
377
378 return 0;
379}
380
381int virtualizer_set_parameter(effect_context_t *context, effect_param_t *p,
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800382 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800383{
384 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
385 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
386 void *value = p->data + voffset;
387 int32_t *param_tmp = (int32_t *)p->data;
388 int32_t param = *param_tmp++;
389 uint32_t strength;
390
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530391 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800392
393 p->status = 0;
394
395 switch (param) {
396 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800397 strength = (uint32_t)(*(int16_t *)value);
398 virtualizer_set_strength(virt_ctxt, strength);
399 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800400 case VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE:
401 {
402 const audio_devices_t device = *(audio_devices_t *)value;
403 if (0 != virtualizer_force_virtualization_mode(virt_ctxt, device)) {
404 p->status = -EINVAL;
405 }
406 break;
407 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800408 default:
409 p->status = -EINVAL;
410 break;
411 }
412
413 return 0;
414}
415
416int virtualizer_set_device(effect_context_t *context, uint32_t device)
417{
418 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
419
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530420 ALOGV("%s: ctxt %p, device: 0x%x", __func__, virt_ctxt, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800421 virt_ctxt->device = device;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800422
423 if (virt_ctxt->forced_device == AUDIO_DEVICE_NONE) {
424 // default case unless configuration is forced
425 if (virtualizer_is_device_supported(device) == false) {
426 if (!virt_ctxt->temp_disabled) {
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530427 if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) {
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800428 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
429 if (virt_ctxt->ctl)
430 offload_virtualizer_send_params(virt_ctxt->ctl,
431 &virt_ctxt->offload_virt,
432 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
433 if (virt_ctxt->hw_acc_fd > 0)
434 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
435 &virt_ctxt->offload_virt,
436 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
437 }
438 virt_ctxt->temp_disabled = true;
439 ALOGI("%s: ctxt %p, disabled based on device", __func__, virt_ctxt);
wjiang50b81f42014-08-06 08:03:14 +0800440 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800441 } else {
442 if (virt_ctxt->temp_disabled) {
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530443 if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) {
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800444 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
445 if (virt_ctxt->ctl)
446 offload_virtualizer_send_params(virt_ctxt->ctl,
447 &virt_ctxt->offload_virt,
448 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
449 if (virt_ctxt->hw_acc_fd > 0)
450 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
451 &virt_ctxt->offload_virt,
452 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
453 }
454 virt_ctxt->temp_disabled = false;
wjiang50b81f42014-08-06 08:03:14 +0800455 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800456 }
457 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800458 // else virtualization mode is forced to a certain device, nothing to do
459
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800460 offload_virtualizer_set_device(&(virt_ctxt->offload_virt), device);
461 return 0;
462}
463
464int virtualizer_reset(effect_context_t *context)
465{
466 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
467
468 return 0;
469}
470
471int virtualizer_init(effect_context_t *context)
472{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530473 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800474 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
475
476 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
477 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
478 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
479 context->config.inputCfg.samplingRate = 44100;
480 context->config.inputCfg.bufferProvider.getBuffer = NULL;
481 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
482 context->config.inputCfg.bufferProvider.cookie = NULL;
483 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
484 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
485 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
486 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
487 context->config.outputCfg.samplingRate = 44100;
488 context->config.outputCfg.bufferProvider.getBuffer = NULL;
489 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
490 context->config.outputCfg.bufferProvider.cookie = NULL;
491 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
492
493 set_config(context, &context->config);
494
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530495 virt_ctxt->enabled_by_client = false;
wjiang50b81f42014-08-06 08:03:14 +0800496 virt_ctxt->temp_disabled = false;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700497 virt_ctxt->hw_acc_fd = -1;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800498 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
499 virt_ctxt->device = AUDIO_DEVICE_NONE;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800500 memset(&(virt_ctxt->offload_virt), 0, sizeof(struct virtualizer_params));
Vatsal Buchac09ae062018-11-14 13:25:08 +0530501 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800502 return 0;
503}
504
505int virtualizer_enable(effect_context_t *context)
506{
507 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
508
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530509 ALOGV("%s: ctxt %p, strength %d", __func__, virt_ctxt, virt_ctxt->strength);
wjiang95d74c22014-03-28 12:29:58 +0800510
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530511 virt_ctxt->enabled_by_client = true;
wjiang95d74c22014-03-28 12:29:58 +0800512 if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
513 !(virt_ctxt->temp_disabled)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800514 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
wjiangd45948e2014-02-24 22:19:43 +0800515 if (virt_ctxt->ctl && virt_ctxt->strength)
516 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700517 &virt_ctxt->offload_virt,
wjiangd45948e2014-02-24 22:19:43 +0800518 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700519 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
520 if ((virt_ctxt->hw_acc_fd > 0) && virt_ctxt->strength)
521 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
522 &virt_ctxt->offload_virt,
523 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
524 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
wjiangd45948e2014-02-24 22:19:43 +0800525 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530526 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800527 return 0;
528}
529
530int virtualizer_disable(effect_context_t *context)
531{
532 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
533
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530534 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530535
536 virt_ctxt->enabled_by_client = false;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800537 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
538 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
539 if (virt_ctxt->ctl)
540 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700541 &virt_ctxt->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800542 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700543 if (virt_ctxt->hw_acc_fd > 0)
544 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
545 &virt_ctxt->offload_virt,
546 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800547 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530548 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800549 return 0;
550}
551
552int virtualizer_start(effect_context_t *context, output_context_t *output)
553{
554 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
555
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530556 ALOGV("%s: ctxt %p, ctl %p", __func__, virt_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800557 virt_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700558 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800559 if (virt_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700560 offload_virtualizer_send_params(virt_ctxt->ctl, &virt_ctxt->offload_virt,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800561 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
562 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700563 if (virt_ctxt->hw_acc_fd > 0)
564 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
565 &virt_ctxt->offload_virt,
566 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
567 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
568 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530569 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800570 return 0;
571}
572
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700573int virtualizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800574{
575 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
576
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530577 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700578 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
579 virt_ctxt->ctl) {
580 struct virtualizer_params virt;
581 virt.enable_flag = false;
582 offload_virtualizer_send_params(virt_ctxt->ctl, &virt,
583 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
584 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800585 virt_ctxt->ctl = NULL;
Vatsal Buchac09ae062018-11-14 13:25:08 +0530586 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800587 return 0;
588}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700589
590int virtualizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
591{
592 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
593
594 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
595 virt_ctxt->hw_acc_fd = hw_acc_fd;
596 if ((virt_ctxt->hw_acc_fd > 0) &&
597 (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))))
598 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
599 &virt_ctxt->offload_virt,
600 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
601 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
602 return 0;
603}