blob: 274856849a1522d9b744ee06ad58344a3c9a8254 [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
59 offload_virtualizer_set_strength(&(context->offload_virt), strength);
60 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070061 offload_virtualizer_send_params(context->ctl, &context->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080062 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
63 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070064 if (context->hw_acc_fd > 0)
65 hw_acc_virtualizer_send_params(context->hw_acc_fd,
66 &context->offload_virt,
67 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
68 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080069 return 0;
70}
71
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +080072/*
73 * Check if an audio device is supported by this implementation
74 *
75 * [in]
76 * device device that is intented for processing (e.g. for binaural vs transaural)
77 * [out]
78 * false device is not applicable for effect
79 * true device is applicable for effect
80 */
81bool virtualizer_is_device_supported(audio_devices_t device) {
82 switch (device) {
83 case AUDIO_DEVICE_OUT_SPEAKER:
84 case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
85 case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
86#ifdef AFE_PROXY_ENABLED
87 case AUDIO_DEVICE_OUT_PROXY:
88#endif
89 case AUDIO_DEVICE_OUT_AUX_DIGITAL:
90 case AUDIO_DEVICE_OUT_USB_ACCESSORY:
91 case AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET:
92 return false;
93 default :
94 return true;
95 }
96}
97
98/*
99 * Check if a channel mask + audio device is supported by this implementation
100 *
101 * [in]
102 * channel_mask channel mask of input buffer
103 * device device that is intented for processing (e.g. for binaural vs transaural)
104 * [out]
105 * false if the configuration is not supported or it is unknown
106 * true if the configuration is supported
107 */
108bool virtualizer_is_configuration_supported(audio_channel_mask_t channel_mask,
109 audio_devices_t device) {
110 uint32_t channelCount = audio_channel_count_from_out_mask(channel_mask);
111 if ((channelCount == 0) || (channelCount > 2)) {
112 return false;
113 }
114
115 return virtualizer_is_device_supported(device);
116}
117
118/*
119 * Force the virtualization mode to that of the given audio device
120 *
121 * [in]
122 * context effect engine context
123 * forced_device device whose virtualization mode we'll always use
124 * [out]
125 * -EINVAL if the device is not supported or is unknown
126 * 0 if the device is supported and the virtualization mode forced
127 */
128int virtualizer_force_virtualization_mode(virtualizer_context_t *context,
129 audio_devices_t forced_device) {
130 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
131 int status = 0;
132 bool use_virt = false;
133 int is_virt_enabled =
134 offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt));
135
136 ALOGV("%s: ctxt %p, forcedDev=0x%x enabled=%d tmpDisabled=%d", __func__, virt_ctxt,
137 forced_device, is_virt_enabled, virt_ctxt->temp_disabled);
138
139 if (virtualizer_is_device_supported(forced_device) == false) {
140 if (forced_device != AUDIO_DEVICE_NONE) {
141 //forced device is not supported, make it behave as a reset of forced mode
142 forced_device = AUDIO_DEVICE_NONE;
143 // but return an error
144 status = -EINVAL;
145 }
146 }
147
148 if (forced_device == AUDIO_DEVICE_NONE) {
149 // disabling forced virtualization mode:
150 // verify whether the virtualization should be enabled or disabled
151 if (virtualizer_is_device_supported(virt_ctxt->device)) {
152 use_virt = (is_virt_enabled == true);
153 }
154 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
155 } else {
156 // forcing virtualization mode:
157 // TODO: we assume device is supported, so hard coded a fixed one.
158 virt_ctxt->forced_device = AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
159 // TODO: only enable for a supported mode, when the effect is enabled
160 use_virt = (is_virt_enabled == true);
161 }
162
163 if (use_virt) {
164 if (virt_ctxt->temp_disabled == true) {
165 if (effect_is_active(&virt_ctxt->common)) {
166 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
167 if (virt_ctxt->ctl)
168 offload_virtualizer_send_params(virt_ctxt->ctl,
169 &virt_ctxt->offload_virt,
170 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
171 if (virt_ctxt->hw_acc_fd > 0)
172 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
173 &virt_ctxt->offload_virt,
174 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
175 }
176 ALOGV("%s: re-enable VIRTUALIZER", __func__);
177 virt_ctxt->temp_disabled = false;
178 } else {
179 ALOGV("%s: leaving VIRTUALIZER enabled", __func__);
180 }
181 } else {
182 if (virt_ctxt->temp_disabled == false) {
183 if (effect_is_active(&virt_ctxt->common)) {
184 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
185 if (virt_ctxt->ctl)
186 offload_virtualizer_send_params(virt_ctxt->ctl,
187 &virt_ctxt->offload_virt,
188 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
189 if (virt_ctxt->hw_acc_fd > 0)
190 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
191 &virt_ctxt->offload_virt,
192 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
193 }
194 ALOGV("%s: disable VIRTUALIZER", __func__);
195 virt_ctxt->temp_disabled = true;
196 } else {
197 ALOGV("%s: leaving VIRTUALIZER disabled", __func__);
198 }
199 }
200
201 ALOGV("after %s: ctxt %p, enabled=%d tmpDisabled=%d", __func__, virt_ctxt,
202 is_virt_enabled, virt_ctxt->temp_disabled);
203
204 return status;
205}
206
207/*
208 * Get the virtual speaker angles for a channel mask + audio device configuration
209 * which is guaranteed to be supported by this implementation
210 *
211 * [in]
212 * channel_mask the channel mask of the input to virtualize
213 * device the type of device that affects the processing (e.g. for binaural vs transaural)
214 * [in/out]
215 * speaker_angles the array of integer where each speaker angle is written as a triplet in the
216 * following format:
217 * int32_t a bit mask with a single value selected for each speaker, following
218 * the convention of the audio_channel_mask_t type
219 * int32_t a value in degrees expressing the speaker azimuth, where 0 is in front
220 * of the user, 180 behind, -90 to the left, 90 to the right of the user
221 * int32_t a value in degrees expressing the speaker elevation, where 0 is the
222 * horizontal plane, +90 is directly above the user, -90 below
223 *
224 */
225void virtualizer_get_speaker_angles(audio_channel_mask_t channel_mask __unused,
226 audio_devices_t device __unused, int32_t *speaker_angles) {
227 // the channel count is guaranteed to be 1 or 2
228 // the device is guaranteed to be of type headphone
229 // this virtualizer is always 2in with speakers at -90 and 90deg of azimuth, 0deg of elevation
230 *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_LEFT;
231 *speaker_angles++ = -90; // azimuth
232 *speaker_angles++ = 0; // elevation
233 *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_RIGHT;
234 *speaker_angles++ = 90; // azimuth
235 *speaker_angles = 0; // elevation
236}
237
238/*
239 * Retrieve the current device whose processing mode is used by this effect
240 *
241 * [out]
242 * AUDIO_DEVICE_NONE if the effect is not virtualizing
243 * or the device type if the effect is virtualizing
244 */
245audio_devices_t virtualizer_get_virtualization_mode(virtualizer_context_t *context) {
246 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
247 audio_devices_t device = AUDIO_DEVICE_NONE;
248
249 if ((offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)))
250 && (virt_ctxt->temp_disabled == false)) {
251 if (virt_ctxt->forced_device != AUDIO_DEVICE_NONE) {
252 // virtualization mode is forced, return that device
253 device = virt_ctxt->forced_device;
254 } else {
255 // no forced mode, return the current device
256 device = virt_ctxt->device;
257 }
258 }
259 ALOGV("%s: returning 0x%x", __func__, device);
260 return device;
261}
262
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800263int virtualizer_get_parameter(effect_context_t *context, effect_param_t *p,
264 uint32_t *size)
265{
266 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
267 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
268 int32_t *param_tmp = (int32_t *)p->data;
269 int32_t param = *param_tmp++;
270 void *value = p->data + voffset;
271 int i;
272
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530273 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800274
275 p->status = 0;
276
277 switch (param) {
278 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
279 if (p->vsize < sizeof(uint32_t))
280 p->status = -EINVAL;
281 p->vsize = sizeof(uint32_t);
282 break;
283 case VIRTUALIZER_PARAM_STRENGTH:
284 if (p->vsize < sizeof(int16_t))
285 p->status = -EINVAL;
286 p->vsize = sizeof(int16_t);
287 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800288 case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
289 // return value size can only be interpreted as relative to input value,
290 // deferring validity check to below
291 break;
292 case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
293 if (p->vsize != sizeof(uint32_t))
294 p->status = -EINVAL;
295 p->vsize = sizeof(uint32_t);
296 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800297 default:
298 p->status = -EINVAL;
299 }
300
301 *size = sizeof(effect_param_t) + voffset + p->vsize;
302
303 if (p->status != 0)
304 return 0;
305
306 switch (param) {
307 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800308 *(uint32_t *)value = 1;
309 break;
310
311 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800312 *(int16_t *)value = virtualizer_get_strength(virt_ctxt);
313 break;
314
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800315 case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
316 {
317 const audio_channel_mask_t channel_mask = (audio_channel_mask_t) *param_tmp++;
318 const audio_devices_t device = (audio_devices_t) *param_tmp;
319 uint32_t channel_cnt = audio_channel_count_from_out_mask(channel_mask);
320
321 if (p->vsize < 3 * channel_cnt * sizeof(int32_t)){
322 p->status = -EINVAL;
323 break;
324 }
325 // verify the configuration is supported
326 if(virtualizer_is_configuration_supported(channel_mask, device)) {
327 // configuration is supported, get the angles
328 virtualizer_get_speaker_angles(channel_mask, device, (int32_t *)value);
329 } else {
330 p->status = -EINVAL;
331 }
332
333 break;
334 }
335
336 case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
337 *(uint32_t *)value = (uint32_t) virtualizer_get_virtualization_mode(virt_ctxt);
338 break;
339
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800340 default:
341 p->status = -EINVAL;
342 break;
343 }
344
345 return 0;
346}
347
348int virtualizer_set_parameter(effect_context_t *context, effect_param_t *p,
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800349 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800350{
351 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
352 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
353 void *value = p->data + voffset;
354 int32_t *param_tmp = (int32_t *)p->data;
355 int32_t param = *param_tmp++;
356 uint32_t strength;
357
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530358 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800359
360 p->status = 0;
361
362 switch (param) {
363 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800364 strength = (uint32_t)(*(int16_t *)value);
365 virtualizer_set_strength(virt_ctxt, strength);
366 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800367 case VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE:
368 {
369 const audio_devices_t device = *(audio_devices_t *)value;
370 if (0 != virtualizer_force_virtualization_mode(virt_ctxt, device)) {
371 p->status = -EINVAL;
372 }
373 break;
374 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800375 default:
376 p->status = -EINVAL;
377 break;
378 }
379
380 return 0;
381}
382
383int virtualizer_set_device(effect_context_t *context, uint32_t device)
384{
385 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
386
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530387 ALOGV("%s: ctxt %p, device: 0x%x", __func__, virt_ctxt, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800388 virt_ctxt->device = device;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800389
390 if (virt_ctxt->forced_device == AUDIO_DEVICE_NONE) {
391 // default case unless configuration is forced
392 if (virtualizer_is_device_supported(device) == false) {
393 if (!virt_ctxt->temp_disabled) {
394 if (effect_is_active(&virt_ctxt->common)) {
395 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
396 if (virt_ctxt->ctl)
397 offload_virtualizer_send_params(virt_ctxt->ctl,
398 &virt_ctxt->offload_virt,
399 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
400 if (virt_ctxt->hw_acc_fd > 0)
401 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
402 &virt_ctxt->offload_virt,
403 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
404 }
405 virt_ctxt->temp_disabled = true;
406 ALOGI("%s: ctxt %p, disabled based on device", __func__, virt_ctxt);
wjiang50b81f42014-08-06 08:03:14 +0800407 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800408 } else {
409 if (virt_ctxt->temp_disabled) {
410 if (effect_is_active(&virt_ctxt->common)) {
411 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
412 if (virt_ctxt->ctl)
413 offload_virtualizer_send_params(virt_ctxt->ctl,
414 &virt_ctxt->offload_virt,
415 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
416 if (virt_ctxt->hw_acc_fd > 0)
417 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
418 &virt_ctxt->offload_virt,
419 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
420 }
421 virt_ctxt->temp_disabled = false;
wjiang50b81f42014-08-06 08:03:14 +0800422 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800423 }
424 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800425 // else virtualization mode is forced to a certain device, nothing to do
426
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800427 offload_virtualizer_set_device(&(virt_ctxt->offload_virt), device);
428 return 0;
429}
430
431int virtualizer_reset(effect_context_t *context)
432{
433 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
434
435 return 0;
436}
437
438int virtualizer_init(effect_context_t *context)
439{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530440 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800441 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
442
443 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
444 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
445 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
446 context->config.inputCfg.samplingRate = 44100;
447 context->config.inputCfg.bufferProvider.getBuffer = NULL;
448 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
449 context->config.inputCfg.bufferProvider.cookie = NULL;
450 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
451 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
452 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
453 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
454 context->config.outputCfg.samplingRate = 44100;
455 context->config.outputCfg.bufferProvider.getBuffer = NULL;
456 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
457 context->config.outputCfg.bufferProvider.cookie = NULL;
458 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
459
460 set_config(context, &context->config);
461
wjiang50b81f42014-08-06 08:03:14 +0800462 virt_ctxt->temp_disabled = false;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700463 virt_ctxt->hw_acc_fd = -1;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800464 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
465 virt_ctxt->device = AUDIO_DEVICE_NONE;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800466 memset(&(virt_ctxt->offload_virt), 0, sizeof(struct virtualizer_params));
467
468 return 0;
469}
470
471int virtualizer_enable(effect_context_t *context)
472{
473 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
474
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530475 ALOGV("%s: ctxt %p, strength %d", __func__, virt_ctxt, virt_ctxt->strength);
wjiang95d74c22014-03-28 12:29:58 +0800476
477 if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
478 !(virt_ctxt->temp_disabled)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800479 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
wjiangd45948e2014-02-24 22:19:43 +0800480 if (virt_ctxt->ctl && virt_ctxt->strength)
481 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700482 &virt_ctxt->offload_virt,
wjiangd45948e2014-02-24 22:19:43 +0800483 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700484 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
485 if ((virt_ctxt->hw_acc_fd > 0) && virt_ctxt->strength)
486 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
487 &virt_ctxt->offload_virt,
488 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
489 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
wjiangd45948e2014-02-24 22:19:43 +0800490 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800491 return 0;
492}
493
494int virtualizer_disable(effect_context_t *context)
495{
496 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
497
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530498 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800499 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
500 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
501 if (virt_ctxt->ctl)
502 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700503 &virt_ctxt->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800504 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700505 if (virt_ctxt->hw_acc_fd > 0)
506 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
507 &virt_ctxt->offload_virt,
508 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800509 }
510 return 0;
511}
512
513int virtualizer_start(effect_context_t *context, output_context_t *output)
514{
515 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
516
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530517 ALOGV("%s: ctxt %p, ctl %p", __func__, virt_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800518 virt_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700519 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800520 if (virt_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700521 offload_virtualizer_send_params(virt_ctxt->ctl, &virt_ctxt->offload_virt,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800522 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
523 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700524 if (virt_ctxt->hw_acc_fd > 0)
525 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
526 &virt_ctxt->offload_virt,
527 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
528 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
529 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800530 return 0;
531}
532
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700533int virtualizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800534{
535 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
536
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530537 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700538 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
539 virt_ctxt->ctl) {
540 struct virtualizer_params virt;
541 virt.enable_flag = false;
542 offload_virtualizer_send_params(virt_ctxt->ctl, &virt,
543 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
544 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800545 virt_ctxt->ctl = NULL;
546 return 0;
547}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700548
549int virtualizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
550{
551 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
552
553 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
554 virt_ctxt->hw_acc_fd = hw_acc_fd;
555 if ((virt_ctxt->hw_acc_fd > 0) &&
556 (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))))
557 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
558 &virt_ctxt->offload_virt,
559 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
560 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
561 return 0;
562}