IAndroidEffect.cpp revision bcc5c7225e3b7a1dbf2e9e830987f69167acf06f
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* Android Effect implementation */
18
19#include "sles_allinclusive.h"
20
21
22static SLresult IAndroidEffect_CreateEffect(SLAndroidEffectItf self,
23        SLInterfaceID effectImplementationId) {
24
25    SL_ENTER_INTERFACE
26
27    IAndroidEffect *thiz = (IAndroidEffect *) self;
28    if (SL_OBJECTID_AUDIOPLAYER == IObjectToObjectID(thiz->mThis)) {
29        CAudioPlayer *ap = (CAudioPlayer *)thiz->mThis;
30        if (NULL != ap->mAudioTrack) {
31            result = android_genericFx_createEffect(thiz, effectImplementationId, ap->mSessionId);
32        } else {
33            result = SL_RESULT_RESOURCE_ERROR;
34        }
35    } else if (SL_OBJECTID_OUTPUTMIX == IObjectToObjectID(thiz->mThis)) {
36        result = android_genericFx_createEffect(thiz, effectImplementationId,
37                android::AudioSystem::SESSION_OUTPUT_MIX);
38    } else {
39        // the interface itself is invalid because it is not attached to an AudioPlayer or
40        // an OutputMix
41        result = SL_RESULT_PARAMETER_INVALID;
42    }
43
44    SL_LEAVE_INTERFACE
45}
46
47
48static SLresult IAndroidEffect_ReleaseEffect(SLAndroidEffectItf self,
49        SLInterfaceID effectImplementationId) {
50
51    SL_ENTER_INTERFACE
52
53    IAndroidEffect *thiz = (IAndroidEffect *) self;
54    result = android_genericFx_releaseEffect(thiz, effectImplementationId);
55
56    SL_LEAVE_INTERFACE
57}
58
59
60static SLresult IAndroidEffect_SetEnabled(SLAndroidEffectItf self,
61        SLInterfaceID effectImplementationId, SLboolean enabled) {
62
63    SL_ENTER_INTERFACE
64
65    IAndroidEffect *thiz = (IAndroidEffect *) self;
66    result = android_genericFx_setEnabled(thiz, effectImplementationId, enabled);
67
68    SL_LEAVE_INTERFACE
69}
70
71
72static SLresult IAndroidEffect_IsEnabled(SLAndroidEffectItf self,
73        SLInterfaceID effectImplementationId, SLboolean * pEnabled) {
74
75    SL_ENTER_INTERFACE
76
77    IAndroidEffect *thiz = (IAndroidEffect *) self;
78    result = android_genericFx_isEnabled(thiz, effectImplementationId, pEnabled);
79
80    SL_LEAVE_INTERFACE
81}
82
83
84static SLresult IAndroidEffect_SendCommand(SLAndroidEffectItf self,
85        SLInterfaceID effectImplementationId, SLuint32 command, SLuint32 commandSize,
86        void* pCommand, SLuint32 *replySize, void *pReply) {
87
88    SL_ENTER_INTERFACE
89
90    IAndroidEffect *thiz = (IAndroidEffect *) self;
91    result = android_genericFx_sendCommand(thiz, effectImplementationId, command, commandSize,
92            pCommand, replySize, pReply);
93
94    SL_LEAVE_INTERFACE
95}
96
97
98static const struct SLAndroidEffectItf_ IAndroidEffect_Itf = {
99        IAndroidEffect_CreateEffect,
100        IAndroidEffect_ReleaseEffect,
101        IAndroidEffect_SetEnabled,
102        IAndroidEffect_IsEnabled,
103        IAndroidEffect_SendCommand
104};
105
106void IAndroidEffect_init(void *self)
107{
108    IAndroidEffect *thiz = (IAndroidEffect *) self;
109    thiz->mItf = &IAndroidEffect_Itf;
110#ifndef TARGET_SIMULATOR
111    thiz->mEffects = new android::KeyedVector<SLuint32, android::AudioEffect* >();
112#endif
113}
114
115void IAndroidEffect_deinit(void *self)
116{
117    IAndroidEffect *thiz = (IAndroidEffect *) self;
118#ifndef TARGET_SIMULATOR
119    if (NULL != thiz->mEffects) {
120        if (!thiz->mEffects->isEmpty()) {
121            for (size_t i = 0 ; i < thiz->mEffects->size() ; i++) {
122                delete thiz->mEffects->valueAt(i);
123            }
124            thiz->mEffects->clear();
125        }
126        delete thiz->mEffects;
127        thiz->mEffects = NULL;
128    }
129#endif
130}
131