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#include <system/audio.h> 22 23static SLresult IAndroidEffect_CreateEffect(SLAndroidEffectItf self, 24 SLInterfaceID effectImplementationId) { 25 26 SL_ENTER_INTERFACE 27 28 IAndroidEffect *thiz = (IAndroidEffect *) self; 29 if (SL_OBJECTID_AUDIOPLAYER == IObjectToObjectID(thiz->mThis)) { 30 CAudioPlayer *ap = (CAudioPlayer *)thiz->mThis; 31 if (ap->mAudioTrack != 0) { 32 result = android_genericFx_createEffect(thiz, effectImplementationId, ap->mSessionId); 33 } else { 34 result = SL_RESULT_RESOURCE_ERROR; 35 } 36 } else if (SL_OBJECTID_OUTPUTMIX == IObjectToObjectID(thiz->mThis)) { 37 result = android_genericFx_createEffect(thiz, effectImplementationId, 38 AUDIO_SESSION_OUTPUT_MIX); 39 } else { 40 // the interface itself is invalid because it is not attached to an AudioPlayer or 41 // an OutputMix 42 result = SL_RESULT_PARAMETER_INVALID; 43 } 44 45 SL_LEAVE_INTERFACE 46} 47 48 49static SLresult IAndroidEffect_ReleaseEffect(SLAndroidEffectItf self, 50 SLInterfaceID effectImplementationId) { 51 52 SL_ENTER_INTERFACE 53 54 IAndroidEffect *thiz = (IAndroidEffect *) self; 55 result = android_genericFx_releaseEffect(thiz, effectImplementationId); 56 57 SL_LEAVE_INTERFACE 58} 59 60 61static SLresult IAndroidEffect_SetEnabled(SLAndroidEffectItf self, 62 SLInterfaceID effectImplementationId, SLboolean enabled) { 63 64 SL_ENTER_INTERFACE 65 66 IAndroidEffect *thiz = (IAndroidEffect *) self; 67 result = android_genericFx_setEnabled(thiz, effectImplementationId, enabled); 68 69 SL_LEAVE_INTERFACE 70} 71 72 73static SLresult IAndroidEffect_IsEnabled(SLAndroidEffectItf self, 74 SLInterfaceID effectImplementationId, SLboolean * pEnabled) { 75 76 SL_ENTER_INTERFACE 77 78 IAndroidEffect *thiz = (IAndroidEffect *) self; 79 result = android_genericFx_isEnabled(thiz, effectImplementationId, pEnabled); 80 81 SL_LEAVE_INTERFACE 82} 83 84 85static SLresult IAndroidEffect_SendCommand(SLAndroidEffectItf self, 86 SLInterfaceID effectImplementationId, SLuint32 command, SLuint32 commandSize, 87 void* pCommand, SLuint32 *replySize, void *pReply) { 88 89 SL_ENTER_INTERFACE 90 91 IAndroidEffect *thiz = (IAndroidEffect *) self; 92 result = android_genericFx_sendCommand(thiz, effectImplementationId, command, commandSize, 93 pCommand, replySize, pReply); 94 95 SL_LEAVE_INTERFACE 96} 97 98 99static const struct SLAndroidEffectItf_ IAndroidEffect_Itf = { 100 IAndroidEffect_CreateEffect, 101 IAndroidEffect_ReleaseEffect, 102 IAndroidEffect_SetEnabled, 103 IAndroidEffect_IsEnabled, 104 IAndroidEffect_SendCommand 105}; 106 107void IAndroidEffect_init(void *self) 108{ 109 IAndroidEffect *thiz = (IAndroidEffect *) self; 110 thiz->mItf = &IAndroidEffect_Itf; 111 thiz->mEffects = new android::KeyedVector<SLuint32, android::AudioEffect* >(); 112} 113 114void IAndroidEffect_deinit(void *self) 115{ 116 IAndroidEffect *thiz = (IAndroidEffect *) self; 117 if (NULL != thiz->mEffects) { 118 if (!thiz->mEffects->isEmpty()) { 119 for (size_t i = 0 ; i < thiz->mEffects->size() ; i++) { 120 delete thiz->mEffects->valueAt(i); 121 } 122 thiz->mEffects->clear(); 123 } 124 delete thiz->mEffects; 125 thiz->mEffects = NULL; 126 } 127} 128