blob: f47630bb251d8610bafe58708ba8ddb08a3698cb [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +08002 * Copyright (c) 2013-2015, 2017, 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
Vatsal Buchaa1358992018-11-14 13:25:08 +053032#define VIRUALIZER_MAX_LATENCY 30
33
34#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;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800321 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 Naripeddy3eedc002013-11-12 20:45:15 -0800332 *(uint32_t *)value = 1;
333 break;
334
335 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800336 *(int16_t *)value = virtualizer_get_strength(virt_ctxt);
337 break;
338
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800339 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 Naripeddy3eedc002013-11-12 20:45:15 -0800364 default:
365 p->status = -EINVAL;
366 break;
367 }
368
369 return 0;
370}
371
372int virtualizer_set_parameter(effect_context_t *context, effect_param_t *p,
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800373 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800374{
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 Kumar574f3922014-03-25 17:41:44 +0530382 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800383
384 p->status = 0;
385
386 switch (param) {
387 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800388 strength = (uint32_t)(*(int16_t *)value);
389 virtualizer_set_strength(virt_ctxt, strength);
390 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800391 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 Naripeddy3eedc002013-11-12 20:45:15 -0800399 default:
400 p->status = -EINVAL;
401 break;
402 }
403
404 return 0;
405}
406
407int virtualizer_set_device(effect_context_t *context, uint32_t device)
408{
409 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
410
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530411 ALOGV("%s: ctxt %p, device: 0x%x", __func__, virt_ctxt, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800412 virt_ctxt->device = device;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800413
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 Kumarf7026ef2015-12-15 10:51:10 +0530418 if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) {
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800419 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);
wjiang50b81f42014-08-06 08:03:14 +0800431 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800432 } else {
433 if (virt_ctxt->temp_disabled) {
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530434 if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) {
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800435 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;
wjiang50b81f42014-08-06 08:03:14 +0800446 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800447 }
448 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800449 // else virtualization mode is forced to a certain device, nothing to do
450
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800451 offload_virtualizer_set_device(&(virt_ctxt->offload_virt), device);
452 return 0;
453}
454
455int virtualizer_reset(effect_context_t *context)
456{
457 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
458
459 return 0;
460}
461
462int virtualizer_init(effect_context_t *context)
463{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530464 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800465 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 Kumarf7026ef2015-12-15 10:51:10 +0530486 virt_ctxt->enabled_by_client = false;
wjiang50b81f42014-08-06 08:03:14 +0800487 virt_ctxt->temp_disabled = false;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700488 virt_ctxt->hw_acc_fd = -1;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800489 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
490 virt_ctxt->device = AUDIO_DEVICE_NONE;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800491 memset(&(virt_ctxt->offload_virt), 0, sizeof(struct virtualizer_params));
Vatsal Buchaa1358992018-11-14 13:25:08 +0530492 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800493 return 0;
494}
495
496int virtualizer_enable(effect_context_t *context)
497{
498 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
499
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530500 ALOGV("%s: ctxt %p, strength %d", __func__, virt_ctxt, virt_ctxt->strength);
wjiang95d74c22014-03-28 12:29:58 +0800501
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530502 virt_ctxt->enabled_by_client = true;
wjiang95d74c22014-03-28 12:29:58 +0800503 if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
504 !(virt_ctxt->temp_disabled)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800505 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
wjiangd45948e2014-02-24 22:19:43 +0800506 if (virt_ctxt->ctl && virt_ctxt->strength)
507 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700508 &virt_ctxt->offload_virt,
wjiangd45948e2014-02-24 22:19:43 +0800509 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700510 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);
wjiangd45948e2014-02-24 22:19:43 +0800516 }
Vatsal Buchaa1358992018-11-14 13:25:08 +0530517 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800518 return 0;
519}
520
521int virtualizer_disable(effect_context_t *context)
522{
523 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
524
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530525 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530526
527 virt_ctxt->enabled_by_client = false;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800528 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 Naripeddye40a7cd2014-06-03 19:42:41 -0700532 &virt_ctxt->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800533 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700534 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 Naripeddy3eedc002013-11-12 20:45:15 -0800538 }
Vatsal Buchaa1358992018-11-14 13:25:08 +0530539 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800540 return 0;
541}
542
543int virtualizer_start(effect_context_t *context, output_context_t *output)
544{
545 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
546
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530547 ALOGV("%s: ctxt %p, ctl %p", __func__, virt_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800548 virt_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700549 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800550 if (virt_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700551 offload_virtualizer_send_params(virt_ctxt->ctl, &virt_ctxt->offload_virt,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800552 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
553 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700554 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 Buchaa1358992018-11-14 13:25:08 +0530560 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800561 return 0;
562}
563
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700564int virtualizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800565{
566 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
567
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530568 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700569 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 Naripeddy3eedc002013-11-12 20:45:15 -0800576 virt_ctxt->ctl = NULL;
Vatsal Buchaa1358992018-11-14 13:25:08 +0530577 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800578 return 0;
579}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700580
581int 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}