blob: 3874f0b42405bfd89b1f375c8ebf3a4035757bd7 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +08002 * Copyright (c) 2013-2015, 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
32/* Offload Virtualizer UUID: 509a4498-561a-4bea-b3b1-0002a5d5c51b */
33const 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,
37 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL),
38 0, /* TODO */
39 1,
40 "MSM offload virtualizer",
41 "The Android Open Source Project",
42};
43
44/*
45 * Virtualizer operations
46 */
47
48int virtualizer_get_strength(virtualizer_context_t *context)
49{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053050 ALOGV("%s: ctxt %p, strength: %d", __func__, context, context->strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080051 return context->strength;
52}
53
54int virtualizer_set_strength(virtualizer_context_t *context, uint32_t strength)
55{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053056 ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080057 context->strength = strength;
58
Weiyin Jiang93e10fd2015-07-21 11:26:02 +080059 /*
60 * Zero strength is not equivalent to disable state as down mix
61 * is still happening for multichannel inputs.
62 * For better user experience, explicitly disable virtualizer module
63 * when strength is 0.
64 */
65 offload_virtualizer_set_enable_flag(&(context->offload_virt),
66 ((strength > 0) && !(context->temp_disabled)) ?
67 true : false);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080068 offload_virtualizer_set_strength(&(context->offload_virt), strength);
69 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070070 offload_virtualizer_send_params(context->ctl, &context->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080071 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
72 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070073 if (context->hw_acc_fd > 0)
74 hw_acc_virtualizer_send_params(context->hw_acc_fd,
75 &context->offload_virt,
76 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
77 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080078 return 0;
79}
80
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +080081/*
82 * Check if an audio device is supported by this implementation
83 *
84 * [in]
85 * device device that is intented for processing (e.g. for binaural vs transaural)
86 * [out]
87 * false device is not applicable for effect
88 * true device is applicable for effect
89 */
90bool virtualizer_is_device_supported(audio_devices_t device) {
91 switch (device) {
92 case AUDIO_DEVICE_OUT_SPEAKER:
93 case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
94 case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
95#ifdef AFE_PROXY_ENABLED
96 case AUDIO_DEVICE_OUT_PROXY:
97#endif
98 case AUDIO_DEVICE_OUT_AUX_DIGITAL:
99 case AUDIO_DEVICE_OUT_USB_ACCESSORY:
100 case AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET:
101 return false;
102 default :
103 return true;
104 }
105}
106
107/*
108 * Check if a channel mask + audio device is supported by this implementation
109 *
110 * [in]
111 * channel_mask channel mask of input buffer
112 * device device that is intented for processing (e.g. for binaural vs transaural)
113 * [out]
114 * false if the configuration is not supported or it is unknown
115 * true if the configuration is supported
116 */
117bool virtualizer_is_configuration_supported(audio_channel_mask_t channel_mask,
118 audio_devices_t device) {
119 uint32_t channelCount = audio_channel_count_from_out_mask(channel_mask);
120 if ((channelCount == 0) || (channelCount > 2)) {
121 return false;
122 }
123
124 return virtualizer_is_device_supported(device);
125}
126
127/*
128 * Force the virtualization mode to that of the given audio device
129 *
130 * [in]
131 * context effect engine context
132 * forced_device device whose virtualization mode we'll always use
133 * [out]
134 * -EINVAL if the device is not supported or is unknown
135 * 0 if the device is supported and the virtualization mode forced
136 */
137int virtualizer_force_virtualization_mode(virtualizer_context_t *context,
138 audio_devices_t forced_device) {
139 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
140 int status = 0;
141 bool use_virt = false;
142 int is_virt_enabled =
143 offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt));
144
145 ALOGV("%s: ctxt %p, forcedDev=0x%x enabled=%d tmpDisabled=%d", __func__, virt_ctxt,
146 forced_device, is_virt_enabled, virt_ctxt->temp_disabled);
147
148 if (virtualizer_is_device_supported(forced_device) == false) {
149 if (forced_device != AUDIO_DEVICE_NONE) {
150 //forced device is not supported, make it behave as a reset of forced mode
151 forced_device = AUDIO_DEVICE_NONE;
152 // but return an error
153 status = -EINVAL;
154 }
155 }
156
157 if (forced_device == AUDIO_DEVICE_NONE) {
158 // disabling forced virtualization mode:
159 // verify whether the virtualization should be enabled or disabled
160 if (virtualizer_is_device_supported(virt_ctxt->device)) {
161 use_virt = (is_virt_enabled == true);
162 }
163 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
164 } else {
165 // forcing virtualization mode:
166 // TODO: we assume device is supported, so hard coded a fixed one.
167 virt_ctxt->forced_device = AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
168 // TODO: only enable for a supported mode, when the effect is enabled
169 use_virt = (is_virt_enabled == true);
170 }
171
172 if (use_virt) {
173 if (virt_ctxt->temp_disabled == true) {
174 if (effect_is_active(&virt_ctxt->common)) {
175 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
176 if (virt_ctxt->ctl)
177 offload_virtualizer_send_params(virt_ctxt->ctl,
178 &virt_ctxt->offload_virt,
179 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
180 if (virt_ctxt->hw_acc_fd > 0)
181 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
182 &virt_ctxt->offload_virt,
183 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
184 }
185 ALOGV("%s: re-enable VIRTUALIZER", __func__);
186 virt_ctxt->temp_disabled = false;
187 } else {
188 ALOGV("%s: leaving VIRTUALIZER enabled", __func__);
189 }
190 } else {
191 if (virt_ctxt->temp_disabled == false) {
192 if (effect_is_active(&virt_ctxt->common)) {
193 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
194 if (virt_ctxt->ctl)
195 offload_virtualizer_send_params(virt_ctxt->ctl,
196 &virt_ctxt->offload_virt,
197 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
198 if (virt_ctxt->hw_acc_fd > 0)
199 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
200 &virt_ctxt->offload_virt,
201 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
202 }
203 ALOGV("%s: disable VIRTUALIZER", __func__);
204 virt_ctxt->temp_disabled = true;
205 } else {
206 ALOGV("%s: leaving VIRTUALIZER disabled", __func__);
207 }
208 }
209
210 ALOGV("after %s: ctxt %p, enabled=%d tmpDisabled=%d", __func__, virt_ctxt,
211 is_virt_enabled, virt_ctxt->temp_disabled);
212
213 return status;
214}
215
216/*
217 * Get the virtual speaker angles for a channel mask + audio device configuration
218 * which is guaranteed to be supported by this implementation
219 *
220 * [in]
221 * channel_mask the channel mask of the input to virtualize
222 * device the type of device that affects the processing (e.g. for binaural vs transaural)
223 * [in/out]
224 * speaker_angles the array of integer where each speaker angle is written as a triplet in the
225 * following format:
226 * int32_t a bit mask with a single value selected for each speaker, following
227 * the convention of the audio_channel_mask_t type
228 * int32_t a value in degrees expressing the speaker azimuth, where 0 is in front
229 * of the user, 180 behind, -90 to the left, 90 to the right of the user
230 * int32_t a value in degrees expressing the speaker elevation, where 0 is the
231 * horizontal plane, +90 is directly above the user, -90 below
232 *
233 */
234void virtualizer_get_speaker_angles(audio_channel_mask_t channel_mask __unused,
235 audio_devices_t device __unused, int32_t *speaker_angles) {
236 // the channel count is guaranteed to be 1 or 2
237 // the device is guaranteed to be of type headphone
238 // this virtualizer is always 2in with speakers at -90 and 90deg of azimuth, 0deg of elevation
239 *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_LEFT;
240 *speaker_angles++ = -90; // azimuth
241 *speaker_angles++ = 0; // elevation
242 *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_RIGHT;
243 *speaker_angles++ = 90; // azimuth
244 *speaker_angles = 0; // elevation
245}
246
247/*
248 * Retrieve the current device whose processing mode is used by this effect
249 *
250 * [out]
251 * AUDIO_DEVICE_NONE if the effect is not virtualizing
252 * or the device type if the effect is virtualizing
253 */
254audio_devices_t virtualizer_get_virtualization_mode(virtualizer_context_t *context) {
255 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
256 audio_devices_t device = AUDIO_DEVICE_NONE;
257
258 if ((offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)))
259 && (virt_ctxt->temp_disabled == false)) {
260 if (virt_ctxt->forced_device != AUDIO_DEVICE_NONE) {
261 // virtualization mode is forced, return that device
262 device = virt_ctxt->forced_device;
263 } else {
264 // no forced mode, return the current device
265 device = virt_ctxt->device;
266 }
267 }
268 ALOGV("%s: returning 0x%x", __func__, device);
269 return device;
270}
271
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800272int virtualizer_get_parameter(effect_context_t *context, effect_param_t *p,
273 uint32_t *size)
274{
275 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
276 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
277 int32_t *param_tmp = (int32_t *)p->data;
278 int32_t param = *param_tmp++;
279 void *value = p->data + voffset;
280 int i;
281
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530282 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800283
284 p->status = 0;
285
286 switch (param) {
287 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
288 if (p->vsize < sizeof(uint32_t))
289 p->status = -EINVAL;
290 p->vsize = sizeof(uint32_t);
291 break;
292 case VIRTUALIZER_PARAM_STRENGTH:
293 if (p->vsize < sizeof(int16_t))
294 p->status = -EINVAL;
295 p->vsize = sizeof(int16_t);
296 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800297 case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
298 // return value size can only be interpreted as relative to input value,
299 // deferring validity check to below
300 break;
301 case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
302 if (p->vsize != sizeof(uint32_t))
303 p->status = -EINVAL;
304 p->vsize = sizeof(uint32_t);
305 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800306 default:
307 p->status = -EINVAL;
308 }
309
310 *size = sizeof(effect_param_t) + voffset + p->vsize;
311
312 if (p->status != 0)
313 return 0;
314
315 switch (param) {
316 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800317 *(uint32_t *)value = 1;
318 break;
319
320 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800321 *(int16_t *)value = virtualizer_get_strength(virt_ctxt);
322 break;
323
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800324 case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
325 {
326 const audio_channel_mask_t channel_mask = (audio_channel_mask_t) *param_tmp++;
327 const audio_devices_t device = (audio_devices_t) *param_tmp;
328 uint32_t channel_cnt = audio_channel_count_from_out_mask(channel_mask);
329
330 if (p->vsize < 3 * channel_cnt * sizeof(int32_t)){
331 p->status = -EINVAL;
332 break;
333 }
334 // verify the configuration is supported
335 if(virtualizer_is_configuration_supported(channel_mask, device)) {
336 // configuration is supported, get the angles
337 virtualizer_get_speaker_angles(channel_mask, device, (int32_t *)value);
338 } else {
339 p->status = -EINVAL;
340 }
341
342 break;
343 }
344
345 case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
346 *(uint32_t *)value = (uint32_t) virtualizer_get_virtualization_mode(virt_ctxt);
347 break;
348
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800349 default:
350 p->status = -EINVAL;
351 break;
352 }
353
354 return 0;
355}
356
357int virtualizer_set_parameter(effect_context_t *context, effect_param_t *p,
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800358 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800359{
360 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
361 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
362 void *value = p->data + voffset;
363 int32_t *param_tmp = (int32_t *)p->data;
364 int32_t param = *param_tmp++;
365 uint32_t strength;
366
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530367 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800368
369 p->status = 0;
370
371 switch (param) {
372 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800373 strength = (uint32_t)(*(int16_t *)value);
374 virtualizer_set_strength(virt_ctxt, strength);
375 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800376 case VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE:
377 {
378 const audio_devices_t device = *(audio_devices_t *)value;
379 if (0 != virtualizer_force_virtualization_mode(virt_ctxt, device)) {
380 p->status = -EINVAL;
381 }
382 break;
383 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800384 default:
385 p->status = -EINVAL;
386 break;
387 }
388
389 return 0;
390}
391
392int virtualizer_set_device(effect_context_t *context, uint32_t device)
393{
394 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
395
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530396 ALOGV("%s: ctxt %p, device: 0x%x", __func__, virt_ctxt, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800397 virt_ctxt->device = device;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800398
399 if (virt_ctxt->forced_device == AUDIO_DEVICE_NONE) {
400 // default case unless configuration is forced
401 if (virtualizer_is_device_supported(device) == false) {
402 if (!virt_ctxt->temp_disabled) {
403 if (effect_is_active(&virt_ctxt->common)) {
404 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
405 if (virt_ctxt->ctl)
406 offload_virtualizer_send_params(virt_ctxt->ctl,
407 &virt_ctxt->offload_virt,
408 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
409 if (virt_ctxt->hw_acc_fd > 0)
410 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
411 &virt_ctxt->offload_virt,
412 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
413 }
414 virt_ctxt->temp_disabled = true;
415 ALOGI("%s: ctxt %p, disabled based on device", __func__, virt_ctxt);
wjiang50b81f42014-08-06 08:03:14 +0800416 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800417 } else {
418 if (virt_ctxt->temp_disabled) {
419 if (effect_is_active(&virt_ctxt->common)) {
420 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
421 if (virt_ctxt->ctl)
422 offload_virtualizer_send_params(virt_ctxt->ctl,
423 &virt_ctxt->offload_virt,
424 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
425 if (virt_ctxt->hw_acc_fd > 0)
426 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
427 &virt_ctxt->offload_virt,
428 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
429 }
430 virt_ctxt->temp_disabled = false;
wjiang50b81f42014-08-06 08:03:14 +0800431 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800432 }
433 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800434 // else virtualization mode is forced to a certain device, nothing to do
435
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800436 offload_virtualizer_set_device(&(virt_ctxt->offload_virt), device);
437 return 0;
438}
439
440int virtualizer_reset(effect_context_t *context)
441{
442 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
443
444 return 0;
445}
446
447int virtualizer_init(effect_context_t *context)
448{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530449 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800450 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
451
452 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
453 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
454 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
455 context->config.inputCfg.samplingRate = 44100;
456 context->config.inputCfg.bufferProvider.getBuffer = NULL;
457 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
458 context->config.inputCfg.bufferProvider.cookie = NULL;
459 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
460 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
461 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
462 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
463 context->config.outputCfg.samplingRate = 44100;
464 context->config.outputCfg.bufferProvider.getBuffer = NULL;
465 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
466 context->config.outputCfg.bufferProvider.cookie = NULL;
467 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
468
469 set_config(context, &context->config);
470
wjiang50b81f42014-08-06 08:03:14 +0800471 virt_ctxt->temp_disabled = false;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700472 virt_ctxt->hw_acc_fd = -1;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800473 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
474 virt_ctxt->device = AUDIO_DEVICE_NONE;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800475 memset(&(virt_ctxt->offload_virt), 0, sizeof(struct virtualizer_params));
476
477 return 0;
478}
479
480int virtualizer_enable(effect_context_t *context)
481{
482 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
483
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530484 ALOGV("%s: ctxt %p, strength %d", __func__, virt_ctxt, virt_ctxt->strength);
wjiang95d74c22014-03-28 12:29:58 +0800485
486 if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
487 !(virt_ctxt->temp_disabled)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800488 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
wjiangd45948e2014-02-24 22:19:43 +0800489 if (virt_ctxt->ctl && virt_ctxt->strength)
490 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700491 &virt_ctxt->offload_virt,
wjiangd45948e2014-02-24 22:19:43 +0800492 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700493 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
494 if ((virt_ctxt->hw_acc_fd > 0) && virt_ctxt->strength)
495 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
496 &virt_ctxt->offload_virt,
497 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
498 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
wjiangd45948e2014-02-24 22:19:43 +0800499 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800500 return 0;
501}
502
503int virtualizer_disable(effect_context_t *context)
504{
505 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
506
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530507 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800508 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
509 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
510 if (virt_ctxt->ctl)
511 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700512 &virt_ctxt->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800513 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700514 if (virt_ctxt->hw_acc_fd > 0)
515 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
516 &virt_ctxt->offload_virt,
517 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800518 }
519 return 0;
520}
521
522int virtualizer_start(effect_context_t *context, output_context_t *output)
523{
524 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
525
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530526 ALOGV("%s: ctxt %p, ctl %p", __func__, virt_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800527 virt_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700528 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800529 if (virt_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700530 offload_virtualizer_send_params(virt_ctxt->ctl, &virt_ctxt->offload_virt,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800531 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
532 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700533 if (virt_ctxt->hw_acc_fd > 0)
534 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
535 &virt_ctxt->offload_virt,
536 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
537 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
538 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800539 return 0;
540}
541
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700542int virtualizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800543{
544 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
545
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530546 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700547 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
548 virt_ctxt->ctl) {
549 struct virtualizer_params virt;
550 virt.enable_flag = false;
551 offload_virtualizer_send_params(virt_ctxt->ctl, &virt,
552 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
553 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800554 virt_ctxt->ctl = NULL;
555 return 0;
556}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700557
558int virtualizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
559{
560 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
561
562 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
563 virt_ctxt->hw_acc_fd = hw_acc_fd;
564 if ((virt_ctxt->hw_acc_fd > 0) &&
565 (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))))
566 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
567 &virt_ctxt->offload_virt,
568 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
569 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
570 return 0;
571}