1*bebae9c0SAndroid Build Coastguard Worker /*
2*bebae9c0SAndroid Build Coastguard Worker * Copyright (C) 2014 The Android Open Source Project
3*bebae9c0SAndroid Build Coastguard Worker *
4*bebae9c0SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*bebae9c0SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*bebae9c0SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*bebae9c0SAndroid Build Coastguard Worker *
8*bebae9c0SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*bebae9c0SAndroid Build Coastguard Worker *
10*bebae9c0SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*bebae9c0SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*bebae9c0SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*bebae9c0SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*bebae9c0SAndroid Build Coastguard Worker * limitations under the License.
15*bebae9c0SAndroid Build Coastguard Worker */
16*bebae9c0SAndroid Build Coastguard Worker
17*bebae9c0SAndroid Build Coastguard Worker /* Acoustic Echo Cancellation implementation */
18*bebae9c0SAndroid Build Coastguard Worker #include "sles_allinclusive.h"
19*bebae9c0SAndroid Build Coastguard Worker
20*bebae9c0SAndroid Build Coastguard Worker #include <system/audio_effects/effect_aec.h>
21*bebae9c0SAndroid Build Coastguard Worker
22*bebae9c0SAndroid Build Coastguard Worker /**
23*bebae9c0SAndroid Build Coastguard Worker * returns true if this interface is not associated with an initialized AEC effect
24*bebae9c0SAndroid Build Coastguard Worker */
NO_ECHOCANCEL(IAndroidAcousticEchoCancellation * v)25*bebae9c0SAndroid Build Coastguard Worker static inline bool NO_ECHOCANCEL(IAndroidAcousticEchoCancellation* v) {
26*bebae9c0SAndroid Build Coastguard Worker return (v->mAECEffect == 0);
27*bebae9c0SAndroid Build Coastguard Worker }
28*bebae9c0SAndroid Build Coastguard Worker
IAndroidAcousticEchoCancellation_SetEnabled(SLAndroidAcousticEchoCancellationItf self,SLboolean enabled)29*bebae9c0SAndroid Build Coastguard Worker static SLresult IAndroidAcousticEchoCancellation_SetEnabled(
30*bebae9c0SAndroid Build Coastguard Worker SLAndroidAcousticEchoCancellationItf self,
31*bebae9c0SAndroid Build Coastguard Worker SLboolean enabled)
32*bebae9c0SAndroid Build Coastguard Worker {
33*bebae9c0SAndroid Build Coastguard Worker SL_ENTER_INTERFACE
34*bebae9c0SAndroid Build Coastguard Worker
35*bebae9c0SAndroid Build Coastguard Worker IAndroidAcousticEchoCancellation *thiz = (IAndroidAcousticEchoCancellation *) self;
36*bebae9c0SAndroid Build Coastguard Worker interface_lock_exclusive(thiz);
37*bebae9c0SAndroid Build Coastguard Worker thiz->mEnabled = (SLboolean) enabled;
38*bebae9c0SAndroid Build Coastguard Worker if (NO_ECHOCANCEL(thiz)) {
39*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_CONTROL_LOST;
40*bebae9c0SAndroid Build Coastguard Worker } else {
41*bebae9c0SAndroid Build Coastguard Worker android::status_t status = thiz->mAECEffect->setEnabled((bool) thiz->mEnabled);
42*bebae9c0SAndroid Build Coastguard Worker result = android_fx_statusToResult(status);
43*bebae9c0SAndroid Build Coastguard Worker }
44*bebae9c0SAndroid Build Coastguard Worker interface_unlock_exclusive(thiz);
45*bebae9c0SAndroid Build Coastguard Worker
46*bebae9c0SAndroid Build Coastguard Worker SL_LEAVE_INTERFACE
47*bebae9c0SAndroid Build Coastguard Worker }
48*bebae9c0SAndroid Build Coastguard Worker
IAndroidAcousticEchoCancellation_IsEnabled(SLAndroidAcousticEchoCancellationItf self,SLboolean * pEnabled)49*bebae9c0SAndroid Build Coastguard Worker static SLresult IAndroidAcousticEchoCancellation_IsEnabled(
50*bebae9c0SAndroid Build Coastguard Worker SLAndroidAcousticEchoCancellationItf self,
51*bebae9c0SAndroid Build Coastguard Worker SLboolean *pEnabled)
52*bebae9c0SAndroid Build Coastguard Worker {
53*bebae9c0SAndroid Build Coastguard Worker SL_ENTER_INTERFACE
54*bebae9c0SAndroid Build Coastguard Worker
55*bebae9c0SAndroid Build Coastguard Worker if (NULL == pEnabled) {
56*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_PARAMETER_INVALID;
57*bebae9c0SAndroid Build Coastguard Worker } else {
58*bebae9c0SAndroid Build Coastguard Worker IAndroidAcousticEchoCancellation *thiz = (IAndroidAcousticEchoCancellation *) self;
59*bebae9c0SAndroid Build Coastguard Worker interface_lock_exclusive(thiz);
60*bebae9c0SAndroid Build Coastguard Worker if (NO_ECHOCANCEL(thiz)) {
61*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_CONTROL_LOST;
62*bebae9c0SAndroid Build Coastguard Worker } else {
63*bebae9c0SAndroid Build Coastguard Worker *pEnabled = (SLboolean) thiz->mAECEffect->getEnabled();
64*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_SUCCESS;
65*bebae9c0SAndroid Build Coastguard Worker }
66*bebae9c0SAndroid Build Coastguard Worker interface_unlock_exclusive(thiz);
67*bebae9c0SAndroid Build Coastguard Worker }
68*bebae9c0SAndroid Build Coastguard Worker
69*bebae9c0SAndroid Build Coastguard Worker SL_LEAVE_INTERFACE
70*bebae9c0SAndroid Build Coastguard Worker }
71*bebae9c0SAndroid Build Coastguard Worker
72*bebae9c0SAndroid Build Coastguard Worker static const struct SLAndroidAcousticEchoCancellationItf_ IAndroidAcousticEchoCancellation_Itf = {
73*bebae9c0SAndroid Build Coastguard Worker IAndroidAcousticEchoCancellation_SetEnabled,
74*bebae9c0SAndroid Build Coastguard Worker IAndroidAcousticEchoCancellation_IsEnabled
75*bebae9c0SAndroid Build Coastguard Worker };
76*bebae9c0SAndroid Build Coastguard Worker
IAndroidAcousticEchoCancellation_init(void * self)77*bebae9c0SAndroid Build Coastguard Worker void IAndroidAcousticEchoCancellation_init(void *self)
78*bebae9c0SAndroid Build Coastguard Worker {
79*bebae9c0SAndroid Build Coastguard Worker IAndroidAcousticEchoCancellation *thiz = (IAndroidAcousticEchoCancellation *) self;
80*bebae9c0SAndroid Build Coastguard Worker thiz->mItf = &IAndroidAcousticEchoCancellation_Itf;
81*bebae9c0SAndroid Build Coastguard Worker thiz->mEnabled = SL_BOOLEAN_FALSE;
82*bebae9c0SAndroid Build Coastguard Worker memset(&thiz->mAECDescriptor, 0, sizeof(effect_descriptor_t));
83*bebae9c0SAndroid Build Coastguard Worker // placement new (explicit constructor)
84*bebae9c0SAndroid Build Coastguard Worker (void) new (&thiz->mAECEffect) android::sp<android::AudioEffect>();
85*bebae9c0SAndroid Build Coastguard Worker }
86*bebae9c0SAndroid Build Coastguard Worker
IAndroidAcousticEchoCancellation_deinit(void * self)87*bebae9c0SAndroid Build Coastguard Worker void IAndroidAcousticEchoCancellation_deinit(void *self)
88*bebae9c0SAndroid Build Coastguard Worker {
89*bebae9c0SAndroid Build Coastguard Worker IAndroidAcousticEchoCancellation *thiz = (IAndroidAcousticEchoCancellation *) self;
90*bebae9c0SAndroid Build Coastguard Worker // explicit destructor
91*bebae9c0SAndroid Build Coastguard Worker thiz->mAECEffect.~sp();
92*bebae9c0SAndroid Build Coastguard Worker }
93*bebae9c0SAndroid Build Coastguard Worker
IAndroidAcousticEchoCancellation_Expose(void * self)94*bebae9c0SAndroid Build Coastguard Worker bool IAndroidAcousticEchoCancellation_Expose(void *self)
95*bebae9c0SAndroid Build Coastguard Worker {
96*bebae9c0SAndroid Build Coastguard Worker IAndroidAcousticEchoCancellation *thiz = (IAndroidAcousticEchoCancellation *) self;
97*bebae9c0SAndroid Build Coastguard Worker if (!android_fx_initEffectDescriptor(SL_IID_ANDROIDACOUSTICECHOCANCELLATION,
98*bebae9c0SAndroid Build Coastguard Worker &thiz->mAECDescriptor)) {
99*bebae9c0SAndroid Build Coastguard Worker SL_LOGE("Acoustic Echo Cancellation initialization failed.");
100*bebae9c0SAndroid Build Coastguard Worker return false;
101*bebae9c0SAndroid Build Coastguard Worker }
102*bebae9c0SAndroid Build Coastguard Worker return true;
103*bebae9c0SAndroid Build Coastguard Worker }
104