blob: 6c08bd7d897f351d30a53e2de9b3d6d6299f2fe9 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Aalique Grahame22e49102018-12-18 14:23:57 -08002 * Copyright (c) 2013-2015, 2017-2019, 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>
vivek mehtaae1018c2019-05-09 12:19:57 -070024#include <cutils/properties.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080025#include <log/log.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080026#include <tinyalsa/asoundlib.h>
Subhash Chandra Bose Naripeddy090a2aa2014-01-30 14:03:12 -080027#include <sound/audio_effects.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080028#include <audio_effects/effect_virtualizer.h>
29
30#include "effect_api.h"
31#include "virtualizer.h"
32
Trinath Thammishetty765efd22018-08-20 13:23:24 +053033#define VIRUALIZER_MAX_LATENCY 30
34
Vatsal Buchac09ae062018-11-14 13:25:08 +053035#ifdef AUDIO_FEATURE_ENABLED_GCOV
36extern void __gcov_flush();
37static void enable_gcov()
38{
39 __gcov_flush();
40}
41#else
42static void enable_gcov()
43{
44}
45#endif
46
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080047/* Offload Virtualizer UUID: 509a4498-561a-4bea-b3b1-0002a5d5c51b */
48const effect_descriptor_t virtualizer_descriptor = {
49 {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
50 {0x509a4498, 0x561a, 0x4bea, 0xb3b1, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
51 EFFECT_CONTROL_API_VERSION,
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +080052 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL |
53 EFFECT_FLAG_VOLUME_CTRL),
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080054 0, /* TODO */
55 1,
56 "MSM offload virtualizer",
57 "The Android Open Source Project",
58};
59
60/*
61 * Virtualizer operations
62 */
63
64int virtualizer_get_strength(virtualizer_context_t *context)
65{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053066 ALOGV("%s: ctxt %p, strength: %d", __func__, context, context->strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080067 return context->strength;
68}
69
70int virtualizer_set_strength(virtualizer_context_t *context, uint32_t strength)
71{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053072 ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080073 context->strength = strength;
74
Weiyin Jiangc8082d92015-07-21 11:26:02 +080075 /*
76 * Zero strength is not equivalent to disable state as down mix
77 * is still happening for multichannel inputs.
78 * For better user experience, explicitly disable virtualizer module
79 * when strength is 0.
80 */
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +053081 if (context->enabled_by_client)
82 offload_virtualizer_set_enable_flag(&(context->offload_virt),
Weiyin Jiangc8082d92015-07-21 11:26:02 +080083 ((strength > 0) && !(context->temp_disabled)) ?
84 true : false);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080085 offload_virtualizer_set_strength(&(context->offload_virt), strength);
86 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070087 offload_virtualizer_send_params(context->ctl, &context->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080088 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
89 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070090 if (context->hw_acc_fd > 0)
91 hw_acc_virtualizer_send_params(context->hw_acc_fd,
92 &context->offload_virt,
93 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
94 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080095 return 0;
96}
97
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +080098/*
99 * Check if an audio device is supported by this implementation
100 *
101 * [in]
102 * device device that is intented for processing (e.g. for binaural vs transaural)
103 * [out]
104 * false device is not applicable for effect
105 * true device is applicable for effect
106 */
107bool virtualizer_is_device_supported(audio_devices_t device) {
vivek mehtaae1018c2019-05-09 12:19:57 -0700108 if ((property_get_bool("vendor.audio.feature.afe_proxy.enable", false)) &&
109 (device == AUDIO_DEVICE_OUT_PROXY))
110 return false;
Arun Mirpurib1bec9c2019-01-29 16:42:45 -0800111
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800112 switch (device) {
113 case AUDIO_DEVICE_OUT_SPEAKER:
114 case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
115 case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800116 case AUDIO_DEVICE_OUT_AUX_DIGITAL:
117 case AUDIO_DEVICE_OUT_USB_ACCESSORY:
118 case AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET:
119 return false;
120 default :
121 return true;
122 }
123}
124
125/*
126 * Check if a channel mask + audio device is supported by this implementation
127 *
128 * [in]
129 * channel_mask channel mask of input buffer
130 * device device that is intented for processing (e.g. for binaural vs transaural)
131 * [out]
132 * false if the configuration is not supported or it is unknown
133 * true if the configuration is supported
134 */
135bool virtualizer_is_configuration_supported(audio_channel_mask_t channel_mask,
136 audio_devices_t device) {
137 uint32_t channelCount = audio_channel_count_from_out_mask(channel_mask);
138 if ((channelCount == 0) || (channelCount > 2)) {
139 return false;
140 }
141
142 return virtualizer_is_device_supported(device);
143}
144
145/*
146 * Force the virtualization mode to that of the given audio device
147 *
148 * [in]
149 * context effect engine context
150 * forced_device device whose virtualization mode we'll always use
151 * [out]
152 * -EINVAL if the device is not supported or is unknown
153 * 0 if the device is supported and the virtualization mode forced
154 */
155int virtualizer_force_virtualization_mode(virtualizer_context_t *context,
156 audio_devices_t forced_device) {
157 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
158 int status = 0;
159 bool use_virt = false;
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530160 int is_virt_enabled = virt_ctxt->enabled_by_client;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800161
162 ALOGV("%s: ctxt %p, forcedDev=0x%x enabled=%d tmpDisabled=%d", __func__, virt_ctxt,
163 forced_device, is_virt_enabled, virt_ctxt->temp_disabled);
164
165 if (virtualizer_is_device_supported(forced_device) == false) {
166 if (forced_device != AUDIO_DEVICE_NONE) {
167 //forced device is not supported, make it behave as a reset of forced mode
168 forced_device = AUDIO_DEVICE_NONE;
169 // but return an error
170 status = -EINVAL;
171 }
172 }
173
174 if (forced_device == AUDIO_DEVICE_NONE) {
175 // disabling forced virtualization mode:
176 // verify whether the virtualization should be enabled or disabled
177 if (virtualizer_is_device_supported(virt_ctxt->device)) {
178 use_virt = (is_virt_enabled == true);
179 }
180 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
181 } else {
182 // forcing virtualization mode:
183 // TODO: we assume device is supported, so hard coded a fixed one.
184 virt_ctxt->forced_device = AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
185 // TODO: only enable for a supported mode, when the effect is enabled
186 use_virt = (is_virt_enabled == true);
187 }
188
189 if (use_virt) {
190 if (virt_ctxt->temp_disabled == true) {
191 if (effect_is_active(&virt_ctxt->common)) {
192 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
193 if (virt_ctxt->ctl)
194 offload_virtualizer_send_params(virt_ctxt->ctl,
195 &virt_ctxt->offload_virt,
196 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
197 if (virt_ctxt->hw_acc_fd > 0)
198 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
199 &virt_ctxt->offload_virt,
200 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
201 }
202 ALOGV("%s: re-enable VIRTUALIZER", __func__);
203 virt_ctxt->temp_disabled = false;
204 } else {
205 ALOGV("%s: leaving VIRTUALIZER enabled", __func__);
206 }
207 } else {
208 if (virt_ctxt->temp_disabled == false) {
209 if (effect_is_active(&virt_ctxt->common)) {
210 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
211 if (virt_ctxt->ctl)
212 offload_virtualizer_send_params(virt_ctxt->ctl,
213 &virt_ctxt->offload_virt,
214 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
215 if (virt_ctxt->hw_acc_fd > 0)
216 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
217 &virt_ctxt->offload_virt,
218 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
219 }
220 ALOGV("%s: disable VIRTUALIZER", __func__);
221 virt_ctxt->temp_disabled = true;
222 } else {
223 ALOGV("%s: leaving VIRTUALIZER disabled", __func__);
224 }
225 }
226
227 ALOGV("after %s: ctxt %p, enabled=%d tmpDisabled=%d", __func__, virt_ctxt,
228 is_virt_enabled, virt_ctxt->temp_disabled);
229
230 return status;
231}
232
233/*
234 * Get the virtual speaker angles for a channel mask + audio device configuration
235 * which is guaranteed to be supported by this implementation
236 *
237 * [in]
238 * channel_mask the channel mask of the input to virtualize
239 * device the type of device that affects the processing (e.g. for binaural vs transaural)
240 * [in/out]
241 * speaker_angles the array of integer where each speaker angle is written as a triplet in the
242 * following format:
243 * int32_t a bit mask with a single value selected for each speaker, following
244 * the convention of the audio_channel_mask_t type
245 * int32_t a value in degrees expressing the speaker azimuth, where 0 is in front
246 * of the user, 180 behind, -90 to the left, 90 to the right of the user
247 * int32_t a value in degrees expressing the speaker elevation, where 0 is the
248 * horizontal plane, +90 is directly above the user, -90 below
249 *
250 */
251void virtualizer_get_speaker_angles(audio_channel_mask_t channel_mask __unused,
252 audio_devices_t device __unused, int32_t *speaker_angles) {
253 // the channel count is guaranteed to be 1 or 2
254 // the device is guaranteed to be of type headphone
255 // this virtualizer is always 2in with speakers at -90 and 90deg of azimuth, 0deg of elevation
256 *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_LEFT;
257 *speaker_angles++ = -90; // azimuth
258 *speaker_angles++ = 0; // elevation
259 *speaker_angles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_RIGHT;
260 *speaker_angles++ = 90; // azimuth
261 *speaker_angles = 0; // elevation
262}
263
264/*
265 * Retrieve the current device whose processing mode is used by this effect
266 *
267 * [out]
268 * AUDIO_DEVICE_NONE if the effect is not virtualizing
269 * or the device type if the effect is virtualizing
270 */
271audio_devices_t virtualizer_get_virtualization_mode(virtualizer_context_t *context) {
272 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
273 audio_devices_t device = AUDIO_DEVICE_NONE;
274
275 if ((offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)))
276 && (virt_ctxt->temp_disabled == false)) {
277 if (virt_ctxt->forced_device != AUDIO_DEVICE_NONE) {
278 // virtualization mode is forced, return that device
279 device = virt_ctxt->forced_device;
280 } else {
281 // no forced mode, return the current device
282 device = virt_ctxt->device;
283 }
284 }
285 ALOGV("%s: returning 0x%x", __func__, device);
286 return device;
287}
288
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800289int virtualizer_get_parameter(effect_context_t *context, effect_param_t *p,
290 uint32_t *size)
291{
292 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
293 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
294 int32_t *param_tmp = (int32_t *)p->data;
295 int32_t param = *param_tmp++;
296 void *value = p->data + voffset;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800297
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530298 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800299
300 p->status = 0;
301
302 switch (param) {
303 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
304 if (p->vsize < sizeof(uint32_t))
305 p->status = -EINVAL;
306 p->vsize = sizeof(uint32_t);
307 break;
308 case VIRTUALIZER_PARAM_STRENGTH:
309 if (p->vsize < sizeof(int16_t))
310 p->status = -EINVAL;
311 p->vsize = sizeof(int16_t);
312 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800313 case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
314 // return value size can only be interpreted as relative to input value,
315 // deferring validity check to below
316 break;
317 case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
318 if (p->vsize != sizeof(uint32_t))
319 p->status = -EINVAL;
320 p->vsize = sizeof(uint32_t);
321 break;
Trinath Thammishetty765efd22018-08-20 13:23:24 +0530322 case VIRTUALIZER_PARAM_LATENCY:
323 if (p->vsize < sizeof(uint32_t))
324 p->status = -EINVAL;
325 p->vsize = sizeof(uint32_t);
326 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800327 default:
328 p->status = -EINVAL;
329 }
330
331 *size = sizeof(effect_param_t) + voffset + p->vsize;
332
333 if (p->status != 0)
334 return 0;
335
336 switch (param) {
337 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800338 *(uint32_t *)value = 1;
339 break;
340
341 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800342 *(int16_t *)value = virtualizer_get_strength(virt_ctxt);
343 break;
344
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800345 case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
346 {
347 const audio_channel_mask_t channel_mask = (audio_channel_mask_t) *param_tmp++;
348 const audio_devices_t device = (audio_devices_t) *param_tmp;
349 uint32_t channel_cnt = audio_channel_count_from_out_mask(channel_mask);
350
351 if (p->vsize < 3 * channel_cnt * sizeof(int32_t)){
352 p->status = -EINVAL;
353 break;
354 }
355 // verify the configuration is supported
356 if(virtualizer_is_configuration_supported(channel_mask, device)) {
357 // configuration is supported, get the angles
358 virtualizer_get_speaker_angles(channel_mask, device, (int32_t *)value);
359 } else {
360 p->status = -EINVAL;
361 }
362
363 break;
364 }
365
366 case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
367 *(uint32_t *)value = (uint32_t) virtualizer_get_virtualization_mode(virt_ctxt);
368 break;
369
Trinath Thammishetty765efd22018-08-20 13:23:24 +0530370 case VIRTUALIZER_PARAM_LATENCY:
371 *(uint32_t *)value = VIRUALIZER_MAX_LATENCY;
372 break;
373
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800374 default:
375 p->status = -EINVAL;
376 break;
377 }
378
379 return 0;
380}
381
382int virtualizer_set_parameter(effect_context_t *context, effect_param_t *p,
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800383 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800384{
385 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
386 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
387 void *value = p->data + voffset;
388 int32_t *param_tmp = (int32_t *)p->data;
389 int32_t param = *param_tmp++;
390 uint32_t strength;
391
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530392 ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800393
394 p->status = 0;
395
396 switch (param) {
397 case VIRTUALIZER_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800398 strength = (uint32_t)(*(int16_t *)value);
399 virtualizer_set_strength(virt_ctxt, strength);
400 break;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800401 case VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE:
402 {
403 const audio_devices_t device = *(audio_devices_t *)value;
404 if (0 != virtualizer_force_virtualization_mode(virt_ctxt, device)) {
405 p->status = -EINVAL;
406 }
407 break;
408 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800409 default:
410 p->status = -EINVAL;
411 break;
412 }
413
414 return 0;
415}
416
417int virtualizer_set_device(effect_context_t *context, uint32_t device)
418{
419 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
420
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530421 ALOGV("%s: ctxt %p, device: 0x%x", __func__, virt_ctxt, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800422 virt_ctxt->device = device;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800423
424 if (virt_ctxt->forced_device == AUDIO_DEVICE_NONE) {
425 // default case unless configuration is forced
426 if (virtualizer_is_device_supported(device) == false) {
427 if (!virt_ctxt->temp_disabled) {
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530428 if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) {
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800429 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
430 if (virt_ctxt->ctl)
431 offload_virtualizer_send_params(virt_ctxt->ctl,
432 &virt_ctxt->offload_virt,
433 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
434 if (virt_ctxt->hw_acc_fd > 0)
435 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
436 &virt_ctxt->offload_virt,
437 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
438 }
439 virt_ctxt->temp_disabled = true;
440 ALOGI("%s: ctxt %p, disabled based on device", __func__, virt_ctxt);
wjiang50b81f42014-08-06 08:03:14 +0800441 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800442 } else {
443 if (virt_ctxt->temp_disabled) {
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530444 if (effect_is_active(&virt_ctxt->common) && virt_ctxt->enabled_by_client) {
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800445 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
446 if (virt_ctxt->ctl)
447 offload_virtualizer_send_params(virt_ctxt->ctl,
448 &virt_ctxt->offload_virt,
449 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
450 if (virt_ctxt->hw_acc_fd > 0)
451 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
452 &virt_ctxt->offload_virt,
453 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
454 }
455 virt_ctxt->temp_disabled = false;
wjiang50b81f42014-08-06 08:03:14 +0800456 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800457 }
458 }
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800459 // else virtualization mode is forced to a certain device, nothing to do
460
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800461 offload_virtualizer_set_device(&(virt_ctxt->offload_virt), device);
462 return 0;
463}
464
Aalique Grahame22e49102018-12-18 14:23:57 -0800465int virtualizer_reset(effect_context_t *context __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800466{
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800467 return 0;
468}
469
470int virtualizer_init(effect_context_t *context)
471{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530472 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800473 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
474
475 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
476 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
477 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
478 context->config.inputCfg.samplingRate = 44100;
479 context->config.inputCfg.bufferProvider.getBuffer = NULL;
480 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
481 context->config.inputCfg.bufferProvider.cookie = NULL;
482 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
483 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
484 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
485 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
486 context->config.outputCfg.samplingRate = 44100;
487 context->config.outputCfg.bufferProvider.getBuffer = NULL;
488 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
489 context->config.outputCfg.bufferProvider.cookie = NULL;
490 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
491
492 set_config(context, &context->config);
493
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530494 virt_ctxt->enabled_by_client = false;
wjiang50b81f42014-08-06 08:03:14 +0800495 virt_ctxt->temp_disabled = false;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700496 virt_ctxt->hw_acc_fd = -1;
Weiyin Jiangb64b7dd2015-03-23 00:54:14 +0800497 virt_ctxt->forced_device = AUDIO_DEVICE_NONE;
498 virt_ctxt->device = AUDIO_DEVICE_NONE;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800499 memset(&(virt_ctxt->offload_virt), 0, sizeof(struct virtualizer_params));
Vatsal Buchac09ae062018-11-14 13:25:08 +0530500 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800501 return 0;
502}
503
504int virtualizer_enable(effect_context_t *context)
505{
506 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
507
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530508 ALOGV("%s: ctxt %p, strength %d", __func__, virt_ctxt, virt_ctxt->strength);
wjiang95d74c22014-03-28 12:29:58 +0800509
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530510 virt_ctxt->enabled_by_client = true;
wjiang95d74c22014-03-28 12:29:58 +0800511 if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
512 !(virt_ctxt->temp_disabled)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800513 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true);
wjiangd45948e2014-02-24 22:19:43 +0800514 if (virt_ctxt->ctl && virt_ctxt->strength)
515 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700516 &virt_ctxt->offload_virt,
wjiangd45948e2014-02-24 22:19:43 +0800517 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700518 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
519 if ((virt_ctxt->hw_acc_fd > 0) && virt_ctxt->strength)
520 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
521 &virt_ctxt->offload_virt,
522 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
523 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
wjiangd45948e2014-02-24 22:19:43 +0800524 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530525 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800526 return 0;
527}
528
529int virtualizer_disable(effect_context_t *context)
530{
531 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
532
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530533 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Dhananjay Kumarf7026ef2015-12-15 10:51:10 +0530534
535 virt_ctxt->enabled_by_client = false;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800536 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
537 offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
538 if (virt_ctxt->ctl)
539 offload_virtualizer_send_params(virt_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700540 &virt_ctxt->offload_virt,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800541 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700542 if (virt_ctxt->hw_acc_fd > 0)
543 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
544 &virt_ctxt->offload_virt,
545 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800546 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530547 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800548 return 0;
549}
550
551int virtualizer_start(effect_context_t *context, output_context_t *output)
552{
553 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
554
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530555 ALOGV("%s: ctxt %p, ctl %p", __func__, virt_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800556 virt_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700557 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800558 if (virt_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700559 offload_virtualizer_send_params(virt_ctxt->ctl, &virt_ctxt->offload_virt,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800560 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
561 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700562 if (virt_ctxt->hw_acc_fd > 0)
563 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
564 &virt_ctxt->offload_virt,
565 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
566 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
567 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530568 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800569 return 0;
570}
571
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700572int virtualizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800573{
574 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
575
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530576 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700577 if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
578 virt_ctxt->ctl) {
579 struct virtualizer_params virt;
580 virt.enable_flag = false;
581 offload_virtualizer_send_params(virt_ctxt->ctl, &virt,
582 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
583 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800584 virt_ctxt->ctl = NULL;
Vatsal Buchac09ae062018-11-14 13:25:08 +0530585 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800586 return 0;
587}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700588
589int virtualizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
590{
591 virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
592
593 ALOGV("%s: ctxt %p", __func__, virt_ctxt);
594 virt_ctxt->hw_acc_fd = hw_acc_fd;
595 if ((virt_ctxt->hw_acc_fd > 0) &&
596 (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))))
597 hw_acc_virtualizer_send_params(virt_ctxt->hw_acc_fd,
598 &virt_ctxt->offload_virt,
599 OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
600 OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
601 return 0;
602}