Home | History | Annotate | Download | only in libopensles
      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 
     22 static SLresult IAndroidEffect_CreateEffect(SLAndroidEffectItf self,
     23         SLInterfaceID effectImplementationId) {
     24 
     25     SL_ENTER_INTERFACE
     26 
     27     IAndroidEffect *this = (IAndroidEffect *) self;
     28     if (SL_OBJECTID_AUDIOPLAYER == IObjectToObjectID(this->mThis)) {
     29         CAudioPlayer *ap = (CAudioPlayer *)this->mThis;
     30         if (NULL != ap->mAudioTrack) {
     31             result = android_genericFx_createEffect(this, effectImplementationId, ap->mSessionId);
     32         } else {
     33             result = SL_RESULT_RESOURCE_ERROR;
     34         }
     35     } else if (SL_OBJECTID_OUTPUTMIX == IObjectToObjectID(this->mThis)) {
     36         result = android_genericFx_createEffect(this, 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 
     48 static SLresult IAndroidEffect_ReleaseEffect(SLAndroidEffectItf self,
     49         SLInterfaceID effectImplementationId) {
     50 
     51     SL_ENTER_INTERFACE
     52 
     53     IAndroidEffect *this = (IAndroidEffect *) self;
     54     result = android_genericFx_releaseEffect(this, effectImplementationId);
     55 
     56     SL_LEAVE_INTERFACE
     57 }
     58 
     59 
     60 static SLresult IAndroidEffect_SetEnabled(SLAndroidEffectItf self,
     61         SLInterfaceID effectImplementationId, SLboolean enabled) {
     62 
     63     SL_ENTER_INTERFACE
     64 
     65     IAndroidEffect *this = (IAndroidEffect *) self;
     66     result = android_genericFx_setEnabled(this, effectImplementationId, enabled);
     67 
     68     SL_LEAVE_INTERFACE
     69 }
     70 
     71 
     72 static SLresult IAndroidEffect_IsEnabled(SLAndroidEffectItf self,
     73         SLInterfaceID effectImplementationId, SLboolean * pEnabled) {
     74 
     75     SL_ENTER_INTERFACE
     76 
     77     IAndroidEffect *this = (IAndroidEffect *) self;
     78     result = android_genericFx_isEnabled(this, effectImplementationId, pEnabled);
     79 
     80     SL_LEAVE_INTERFACE
     81 }
     82 
     83 
     84 static 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 *this = (IAndroidEffect *) self;
     91     result = android_genericFx_sendCommand(this, effectImplementationId, command, commandSize,
     92             pCommand, replySize, pReply);
     93 
     94     SL_LEAVE_INTERFACE
     95 }
     96 
     97 
     98 static const struct SLAndroidEffectItf_ IAndroidEffect_Itf = {
     99         IAndroidEffect_CreateEffect,
    100         IAndroidEffect_ReleaseEffect,
    101         IAndroidEffect_SetEnabled,
    102         IAndroidEffect_IsEnabled,
    103         IAndroidEffect_SendCommand
    104 };
    105 
    106 void IAndroidEffect_init(void *self)
    107 {
    108     IAndroidEffect *this = (IAndroidEffect *) self;
    109     this->mItf = &IAndroidEffect_Itf;
    110 #ifndef TARGET_SIMULATOR
    111     this->mEffects = new android::KeyedVector<SLuint32, android::AudioEffect* >();
    112 #endif
    113 }
    114 
    115 void IAndroidEffect_deinit(void *self)
    116 {
    117     IAndroidEffect *this = (IAndroidEffect *) self;
    118 #ifndef TARGET_SIMULATOR
    119     if (NULL != this->mEffects) {
    120         if (!this->mEffects->isEmpty()) {
    121             for (size_t i = 0 ; i < this->mEffects->size() ; i++) {
    122                 delete this->mEffects->valueAt(i);
    123             }
    124             this->mEffects->clear();
    125         }
    126         delete this->mEffects;
    127         this->mEffects = NULL;
    128     }
    129 #endif
    130 }
    131