blob: 578cf0b799551b17652ef2d5b47ab709d635d3a5 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Trinath Thammishettyefab6192018-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 Thammishettyefab6192018-08-20 13:23:24 +053032#define VIRUALIZER_MAX_LATENCY 30
33
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080034/* Offload Virtualizer UUID: 509a4498-561a-4bea-b3b1-0002a5d5c51b */
35const effect_descriptor_t virtualizer_descriptor = {
36 {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
37 {0x509a4498, 0x561a, 0x4bea, 0xb3b1, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
38 EFFECT_CONTROL_API_VERSION,
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +080039 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL |
40 EFFECT_FLAG_VOLUME_CTRL),
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080041 0, /* TODO */
42 1,
43 "MSM offload virtualizer",
44 "The Android Open Source Project",
45};
46
47/*
48 * Virtualizer operations
49 */
50
51int virtualizer_get_strength(virtualizer_context_t *context)
52{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053053 ALOGV("%s: ctxt %p, strength: %d", __func__, context, context->strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080054 return context->strength;
55}
56
57int virtualizer_set_strength(virtualizer_context_t *context, uint32_t strength)
58{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053059 ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080060 context->strength = strength;
61
Weiyin Jiangc8082d92015-07-21 11:26:02 +080062 /*
63 * Zero strength is not equivalent to disable state as down mix
64 * is still happening for multichannel inputs.
65 * For better user experience, explicitly disable virtualizer module
66 * when strength is 0.
67 */
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +053068 if (context->enabled_by_client)
69 offload_virtualizer_set_enable_flag(&(context->offload_virt),
Weiyin Jiangc8082d92015-07-21 11:26:02 +080070 ((strength > 0) && !(context->temp_disabled)) ?
71 true : false);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080072 offload_virtualizer_set_strength(&(context->offload_virt), strength);
73 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070074 offload_virtualizer_send_params(context->ctl, &context->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080075 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
76 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070077 if (context->hw_acc_fd > 0)
78 hw_acc_virtualizer_send_params(context->hw_acc_fd,
79 &context->offload_virt,
80 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
81 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080082 return 0;
83}
84
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +080085/*
86 * Check if an audio device is supported by this implementation
87 *
88 * [in]
89 * device device that is intented for processing (e.g. for binaural vs transaural)
90 * [out]
91 * false device is not applicable for effect
92 * true device is applicable for effect
93 */
94bool virtualizer_is_device_supported(audio_devices_t device) {
95 switch (device) {
96 case AUDIO_DEVICE_OUT_SPEAKER:
97 case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
98 case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
99#ifdef AFE_PROXY_ENABLED
100 case AUDIO_DEVICE_OUT_PROXY:
101#endif
102 case AUDIO_DEVICE_OUT_AUX_DIGITAL:
103 case AUDIO_DEVICE_OUT_USB_ACCESSORY:
104 case AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET:
105 return false;
106 default :
107 return true;
108 }
109}
110
111/*
112 * Check if a channel mask + audio device is supported by this implementation
113 *
114 * [in]
115 * channel_mask channel mask of input buffer
116 * device device that is intented for processing (e.g. for binaural vs transaural)
117 * [out]
118 * false if the configuration is not supported or it is unknown
119 * true if the configuration is supported
120 */
121bool virtualizer_is_configuration_supported(audio_channel_mask_t channel_mask,
122 audio_devices_t device) {
123 uint32_t channelCount = audio_channel_count_from_out_mask(channel_mask);
124 if ((channelCount == 0) || (channelCount > 2)) {
125 return false;
126 }
127
128 return virtualizer_is_device_supported(device);
129}
130
131/*
132 * Force the virtualization mode to that of the given audio device
133 *
134 * [in]
135 * context effect engine context
136 * forced_device device whose virtualization mode we'll always use
137 * [out]
138 * -EINVAL if the device is not supported or is unknown
139 * 0 if the device is supported and the virtualization mode forced
140 */
141int virtualizer_force_virtualization_mode(virtualizer_context_t *context,
142 audio_devices_t forced_device) {
143 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
144 int status = 0;
145 bool use_virt = false;
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530146 int is_virt_enabled = virt_ctxt->enabled_by_client;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800147
148 ALOGV("%s: ctxt %p, forcedDev=0x%x enabled=%d tmpDisabled=%d", __func__, virt_ctxt,
149 forced_device, is_virt_enabled, virt_ctxt->temp_disabled);
150
151 if (virtualizer_is_device_supported(forced_device) == false) {
152 if (forced_device != AUDIO_DEVICE_NONE) {
153 //forced device is not supported, make it behave as a reset of forced mode
154 forced_device = AUDIO_DEVICE_NONE;
155 // but return an error
156 status = -EINVAL;
157 }
158 }
159
160 if (forced_device == AUDIO_DEVICE_NONE) {
161 // disabling forced virtualization mode:
162 // verify whether the virtualization should be enabled or disabled
163 if (virtualizer_is_device_supported(virt_ctxt->device)) {
164 use_virt = (is_virt_enabled == true);
165 }
166 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
167 } else {
168 // forcing virtualization mode:
169 // TODO: we assume device is supported, so hard coded a fixed one.
170 virt_ctxt->forced_device = AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
171 // TODO: only enable for a supported mode, when the effect is enabled
172 use_virt = (is_virt_enabled == true);
173 }
174
175 if (use_virt) {
176 if (virt_ctxt->temp_disabled == true) {
177 if (effect_is_active(&virt_ctxt->common)) {
178 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
179 if (virt_ctxt->ctl)
180 offload_virtualizer_send_params(virt_ctxt->ctl,
181 &virt_ctxt->offload_virt,
182 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
183 if (virt_ctxt->hw_acc_fd > 0)
184 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
185 &virt_ctxt->offload_virt,
186 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
187 }
188 ALOGV("%s: re-enable VIRTUALIZER", __func__);
189 virt_ctxt->temp_disabled = false;
190 } else {
191 ALOGV("%s: leaving VIRTUALIZER enabled", __func__);
192 }
193 } else {
194 if (virt_ctxt->temp_disabled == false) {
195 if (effect_is_active(&virt_ctxt->common)) {
196 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
197 if (virt_ctxt->ctl)
198 offload_virtualizer_send_params(virt_ctxt->ctl,
199 &virt_ctxt->offload_virt,
200 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
201 if (virt_ctxt->hw_acc_fd > 0)
202 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
203 &virt_ctxt->offload_virt,
204 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
205 }
206 ALOGV("%s: disable VIRTUALIZER", __func__);
207 virt_ctxt->temp_disabled = true;
208 } else {
209 ALOGV("%s: leaving VIRTUALIZER disabled", __func__);
210 }
211 }
212
213 ALOGV("after %s: ctxt %p, enabled=%d tmpDisabled=%d", __func__, virt_ctxt,
214 is_virt_enabled, virt_ctxt->temp_disabled);
215
216 return status;
217}
218
219/*
220 * Get the virtual speaker angles for a channel mask + audio device configuration
221 * which is guaranteed to be supported by this implementation
222 *
223 * [in]
224 * channel_mask the channel mask of the input to virtualize
225 * device the type of device that affects the processing (e.g. for binaural vs transaural)
226 * [in/out]
227 * speaker_angles the array of integer where each speaker angle is written as a triplet in the
228 * following format:
229 * int32_t a bit mask with a single value selected for each speaker, following
230 * the convention of the audio_channel_mask_t type
231 * int32_t a value in degrees expressing the speaker azimuth, where 0 is in front
232 * of the user, 180 behind, -90 to the left, 90 to the right of the user
233 * int32_t a value in degrees expressing the speaker elevation, where 0 is the
234 * horizontal plane, +90 is directly above the user, -90 below
235 *
236 */
237void virtualizer_get_speaker_angles(audio_channel_mask_t channel_mask __unused,
238 audio_devices_t device __unused, int32_t *speaker_angles) {
239 // the channel count is guaranteed to be 1 or 2
240 // the device is guaranteed to be of type headphone
241 // this virtualizer is always 2in with speakers at -90 and 90deg of azimuth, 0deg of elevation
242 *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_LEFT;
243 *speaker_angles++ = -90; // azimuth
244 *speaker_angles++ = 0; // elevation
245 *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_RIGHT;
246 *speaker_angles++ = 90; // azimuth
247 *speaker_angles = 0; // elevation
248}
249
250/*
251 * Retrieve the current device whose processing mode is used by this effect
252 *
253 * [out]
254 * AUDIO_DEVICE_NONE if the effect is not virtualizing
255 * or the device type if the effect is virtualizing
256 */
257audio_devices_t virtualizer_get_virtualization_mode(virtualizer_context_t *context) {
258 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
259 audio_devices_t device = AUDIO_DEVICE_NONE;
260
261 if ((offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)))
262 && (virt_ctxt->temp_disabled == false)) {
263 if (virt_ctxt->forced_device != AUDIO_DEVICE_NONE) {
264 // virtualization mode is forced, return that device
265 device = virt_ctxt->forced_device;
266 } else {
267 // no forced mode, return the current device
268 device = virt_ctxt->device;
269 }
270 }
271 ALOGV("%s: returning 0x%x", __func__, device);
272 return device;
273}
274
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800275int virtualizer_get_parameter(effect_context_t *context, effect_param_t *p,
276 uint32_t *size)
277{
278 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
279 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
280 int32_t *param_tmp = (int32_t *)p->data;
281 int32_t param = *param_tmp++;
282 void *value = p->data + voffset;
283 int i;
284
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530285 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800286
287 p->status = 0;
288
289 switch (param) {
290 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
291 if (p->vsize < sizeof(uint32_t))
292 p->status = -EINVAL;
293 p->vsize = sizeof(uint32_t);
294 break;
295 case VIRTUALIZER_PARAM_STRENGTH:
296 if (p->vsize < sizeof(int16_t))
297 p->status = -EINVAL;
298 p->vsize = sizeof(int16_t);
299 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800300 case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
301 // return value size can only be interpreted as relative to input value,
302 // deferring validity check to below
303 break;
304 case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
305 if (p->vsize != sizeof(uint32_t))
306 p->status = -EINVAL;
307 p->vsize = sizeof(uint32_t);
308 break;
Trinath Thammishettyefab6192018-08-20 13:23:24 +0530309 case VIRTUALIZER_PARAM_LATENCY:
310 if (p->vsize < sizeof(uint32_t))
311 p->status = -EINVAL;
312 p->vsize = sizeof(uint32_t);
313 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800314 default:
315 p->status = -EINVAL;
316 }
317
318 *size = sizeof(effect_param_t) + voffset + p->vsize;
319
320 if (p->status != 0)
321 return 0;
322
323 switch (param) {
324 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800325 *(uint32_t *)value = 1;
326 break;
327
328 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800329 *(int16_t *)value = virtualizer_get_strength(virt_ctxt);
330 break;
331
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800332 case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
333 {
334 const audio_channel_mask_t channel_mask = (audio_channel_mask_t) *param_tmp++;
335 const audio_devices_t device = (audio_devices_t) *param_tmp;
336 uint32_t channel_cnt = audio_channel_count_from_out_mask(channel_mask);
337
338 if (p->vsize < 3 * channel_cnt * sizeof(int32_t)){
339 p->status = -EINVAL;
340 break;
341 }
342 // verify the configuration is supported
343 if(virtualizer_is_configuration_supported(channel_mask, device)) {
344 // configuration is supported, get the angles
345 virtualizer_get_speaker_angles(channel_mask, device, (int32_t *)value);
346 } else {
347 p->status = -EINVAL;
348 }
349
350 break;
351 }
352
353 case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
354 *(uint32_t *)value = (uint32_t) virtualizer_get_virtualization_mode(virt_ctxt);
355 break;
356
Trinath Thammishettyefab6192018-08-20 13:23:24 +0530357 case VIRTUALIZER_PARAM_LATENCY:
358 *(uint32_t *)value = VIRUALIZER_MAX_LATENCY;
359 break;
360
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800361 default:
362 p->status = -EINVAL;
363 break;
364 }
365
366 return 0;
367}
368
369int virtualizer_set_parameter(effect_context_t *context, effect_param_t *p,
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800370 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800371{
372 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
373 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
374 void *value = p->data + voffset;
375 int32_t *param_tmp = (int32_t *)p->data;
376 int32_t param = *param_tmp++;
377 uint32_t strength;
378
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530379 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800380
381 p->status = 0;
382
383 switch (param) {
384 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800385 strength = (uint32_t)(*(int16_t *)value);
386 virtualizer_set_strength(virt_ctxt, strength);
387 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800388 case VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE:
389 {
390 const audio_devices_t device = *(audio_devices_t *)value;
391 if (0 != virtualizer_force_virtualization_mode(virt_ctxt, device)) {
392 p->status = -EINVAL;
393 }
394 break;
395 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800396 default:
397 p->status = -EINVAL;
398 break;
399 }
400
401 return 0;
402}
403
404int virtualizer_set_device(effect_context_t *context, uint32_t device)
405{
406 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
407
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530408 ALOGV("%s: ctxt %p, device: 0x%x", __func__, virt_ctxt, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800409 virt_ctxt->device = device;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800410
411 if (virt_ctxt->forced_device == AUDIO_DEVICE_NONE) {
412 // default case unless configuration is forced
413 if (virtualizer_is_device_supported(device) == false) {
414 if (!virt_ctxt->temp_disabled) {
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530415 if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) {
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800416 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
417 if (virt_ctxt->ctl)
418 offload_virtualizer_send_params(virt_ctxt->ctl,
419 &virt_ctxt->offload_virt,
420 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
421 if (virt_ctxt->hw_acc_fd > 0)
422 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
423 &virt_ctxt->offload_virt,
424 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
425 }
426 virt_ctxt->temp_disabled = true;
427 ALOGI("%s: ctxt %p, disabled based on device", __func__, virt_ctxt);
wjiang50b81f42014-08-06 08:03:14 +0800428 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800429 } else {
430 if (virt_ctxt->temp_disabled) {
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530431 if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) {
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800432 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
433 if (virt_ctxt->ctl)
434 offload_virtualizer_send_params(virt_ctxt->ctl,
435 &virt_ctxt->offload_virt,
436 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
437 if (virt_ctxt->hw_acc_fd > 0)
438 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
439 &virt_ctxt->offload_virt,
440 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
441 }
442 virt_ctxt->temp_disabled = false;
wjiang50b81f42014-08-06 08:03:14 +0800443 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800444 }
445 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800446 // else virtualization mode is forced to a certain device, nothing to do
447
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800448 offload_virtualizer_set_device(&(virt_ctxt->offload_virt), device);
449 return 0;
450}
451
452int virtualizer_reset(effect_context_t *context)
453{
454 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
455
456 return 0;
457}
458
459int virtualizer_init(effect_context_t *context)
460{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530461 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800462 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
463
464 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
465 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
466 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
467 context->config.inputCfg.samplingRate = 44100;
468 context->config.inputCfg.bufferProvider.getBuffer = NULL;
469 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
470 context->config.inputCfg.bufferProvider.cookie = NULL;
471 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
472 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
473 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
474 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
475 context->config.outputCfg.samplingRate = 44100;
476 context->config.outputCfg.bufferProvider.getBuffer = NULL;
477 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
478 context->config.outputCfg.bufferProvider.cookie = NULL;
479 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
480
481 set_config(context, &context->config);
482
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530483 virt_ctxt->enabled_by_client = false;
wjiang50b81f42014-08-06 08:03:14 +0800484 virt_ctxt->temp_disabled = false;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700485 virt_ctxt->hw_acc_fd = -1;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800486 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
487 virt_ctxt->device = AUDIO_DEVICE_NONE;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800488 memset(&(virt_ctxt->offload_virt), 0, sizeof(struct virtualizer_params));
489
490 return 0;
491}
492
493int virtualizer_enable(effect_context_t *context)
494{
495 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
496
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530497 ALOGV("%s: ctxt %p, strength %d", __func__, virt_ctxt, virt_ctxt->strength);
wjiang95d74c22014-03-28 12:29:58 +0800498
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530499 virt_ctxt->enabled_by_client = true;
wjiang95d74c22014-03-28 12:29:58 +0800500 if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
501 !(virt_ctxt->temp_disabled)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800502 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
wjiangd45948e2014-02-24 22:19:43 +0800503 if (virt_ctxt->ctl && virt_ctxt->strength)
504 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700505 &virt_ctxt->offload_virt,
wjiangd45948e2014-02-24 22:19:43 +0800506 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700507 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
508 if ((virt_ctxt->hw_acc_fd > 0) && virt_ctxt->strength)
509 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
510 &virt_ctxt->offload_virt,
511 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
512 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
wjiangd45948e2014-02-24 22:19:43 +0800513 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800514 return 0;
515}
516
517int virtualizer_disable(effect_context_t *context)
518{
519 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
520
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530521 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530522
523 virt_ctxt->enabled_by_client = false;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800524 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
525 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
526 if (virt_ctxt->ctl)
527 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700528 &virt_ctxt->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800529 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700530 if (virt_ctxt->hw_acc_fd > 0)
531 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
532 &virt_ctxt->offload_virt,
533 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800534 }
535 return 0;
536}
537
538int virtualizer_start(effect_context_t *context, output_context_t *output)
539{
540 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
541
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530542 ALOGV("%s: ctxt %p, ctl %p", __func__, virt_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800543 virt_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700544 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800545 if (virt_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700546 offload_virtualizer_send_params(virt_ctxt->ctl, &virt_ctxt->offload_virt,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800547 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
548 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700549 if (virt_ctxt->hw_acc_fd > 0)
550 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
551 &virt_ctxt->offload_virt,
552 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
553 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
554 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800555 return 0;
556}
557
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700558int virtualizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800559{
560 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
561
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530562 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700563 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
564 virt_ctxt->ctl) {
565 struct virtualizer_params virt;
566 virt.enable_flag = false;
567 offload_virtualizer_send_params(virt_ctxt->ctl, &virt,
568 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
569 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800570 virt_ctxt->ctl = NULL;
571 return 0;
572}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700573
574int virtualizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
575{
576 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
577
578 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
579 virt_ctxt->hw_acc_fd = hw_acc_fd;
580 if ((virt_ctxt->hw_acc_fd > 0) &&
581 (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))))
582 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
583 &virt_ctxt->offload_virt,
584 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
585 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
586 return 0;
587}