diff options
author | Eric Laurent <elaurent@google.com> | 2010-07-13 12:29:17 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-07-13 12:29:17 -0700 |
commit | 8e886be413570fab6c623930a5775dd36a6d11e1 (patch) | |
tree | 146b4667cd0e66891e658d9e764d81e3b94b01b8 /media | |
parent | 9d8bea11892a43eeab2a1119d68740845a8894e5 (diff) | |
parent | 7d850f23c857fe0c0deec9b9ea593d3029665a16 (diff) | |
download | frameworks_base-8e886be413570fab6c623930a5775dd36a6d11e1.zip frameworks_base-8e886be413570fab6c623930a5775dd36a6d11e1.tar.gz frameworks_base-8e886be413570fab6c623930a5775dd36a6d11e1.tar.bz2 |
Merge "Modifications in audio effect engine state management." into gingerbread
Diffstat (limited to 'media')
-rw-r--r-- | media/libeffects/EffectEqualizer.cpp | 34 | ||||
-rw-r--r-- | media/libeffects/EffectReverb.c | 38 | ||||
-rw-r--r-- | media/libeffects/EffectReverb.h | 7 | ||||
-rw-r--r-- | media/libeffects/EffectVisualizer.cpp | 2 |
4 files changed, 76 insertions, 5 deletions
diff --git a/media/libeffects/EffectEqualizer.cpp b/media/libeffects/EffectEqualizer.cpp index d19c6b9..af0c411 100644 --- a/media/libeffects/EffectEqualizer.cpp +++ b/media/libeffects/EffectEqualizer.cpp @@ -30,6 +30,12 @@ // effect_interface_t interface implementation for equalizer effect extern "C" const struct effect_interface_s gEqualizerInterface; +enum equalizer_state_e { + EQUALIZER_STATE_UNINITIALIZED, + EQUALIZER_STATE_INITIALIZED, + EQUALIZER_STATE_ACTIVE, +}; + namespace android { namespace { @@ -100,6 +106,7 @@ struct EqualizerContext { effect_config_t config; FormatAdapter adapter; AudioEqualizer * pEqualizer; + uint32_t state; }; //--- local function prototypes @@ -151,6 +158,7 @@ extern "C" int EffectCreate(effect_uuid_t *uuid, pContext->itfe = &gEqualizerInterface; pContext->pEqualizer = NULL; + pContext->state = EQUALIZER_STATE_UNINITIALIZED; ret = Equalizer_init(pContext); if (ret < 0) { @@ -160,6 +168,7 @@ extern "C" int EffectCreate(effect_uuid_t *uuid, } *pInterface = (effect_interface_t)pContext; + pContext->state = EQUALIZER_STATE_INITIALIZED; LOGV("EffectLibCreateEffect %p, size %d", pContext, AudioEqualizer::GetInstanceSize(kNumBands)+sizeof(EqualizerContext)); @@ -175,6 +184,7 @@ extern "C" int EffectRelease(effect_interface_t interface) { return -EINVAL; } + pContext->state = EQUALIZER_STATE_UNINITIALIZED; pContext->pEqualizer->free(); delete pContext; @@ -528,6 +538,13 @@ extern "C" int Equalizer_process(effect_interface_t self, audio_buffer_t *inBuff return -EINVAL; } + if (pContext->state == EQUALIZER_STATE_UNINITIALIZED) { + return -EINVAL; + } + if (pContext->state == EQUALIZER_STATE_INITIALIZED) { + return -ENODATA; + } + pContext->adapter.process(inBuffer->raw, outBuffer->raw, outBuffer->frameCount); return 0; @@ -539,7 +556,7 @@ extern "C" int Equalizer_command(effect_interface_t self, int cmdCode, int cmdSi android::EqualizerContext * pContext = (android::EqualizerContext *) self; int retsize; - if (pContext == NULL) { + if (pContext == NULL || pContext->state == EQUALIZER_STATE_UNINITIALIZED) { return -EINVAL; } @@ -594,10 +611,25 @@ extern "C" int Equalizer_command(effect_interface_t self, int cmdCode, int cmdSi p->data + p->psize); } break; case EFFECT_CMD_ENABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + if (pContext->state != EQUALIZER_STATE_INITIALIZED) { + return -ENOSYS; + } + pContext->state = EQUALIZER_STATE_ACTIVE; + LOGV("EFFECT_CMD_ENABLE() OK"); + *(int *)pReplyData = 0; + break; case EFFECT_CMD_DISABLE: if (pReplyData == NULL || *replySize != sizeof(int)) { return -EINVAL; } + if (pContext->state != EQUALIZER_STATE_ACTIVE) { + return -ENOSYS; + } + pContext->state = EQUALIZER_STATE_INITIALIZED; + LOGV("EFFECT_CMD_DISABLE() OK"); *(int *)pReplyData = 0; break; case EFFECT_CMD_SET_DEVICE: diff --git a/media/libeffects/EffectReverb.c b/media/libeffects/EffectReverb.c index 5c87f23..2ce7558 100644 --- a/media/libeffects/EffectReverb.c +++ b/media/libeffects/EffectReverb.c @@ -15,8 +15,7 @@ */ #define LOG_TAG "EffectReverb" -// -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #include <cutils/log.h> #include <stdlib.h> #include <string.h> @@ -143,6 +142,8 @@ int EffectCreate(effect_uuid_t *uuid, module->itfe = &gReverbInterface; + module->context.mState = REVERB_STATE_UNINITIALIZED; + if (memcmp(&desc->type, SL_IID_PRESETREVERB, sizeof(effect_uuid_t)) == 0) { preset = 1; } @@ -158,6 +159,8 @@ int EffectCreate(effect_uuid_t *uuid, *pInterface = (effect_interface_t) module; + module->context.mState = REVERB_STATE_INITIALIZED; + LOGV("EffectLibCreateEffect %p ,size %d", module, sizeof(reverb_module_t)); return 0; @@ -171,6 +174,8 @@ int EffectRelease(effect_interface_t interface) { return -EINVAL; } + pRvbModule->context.mState = REVERB_STATE_UNINITIALIZED; + free(pRvbModule); return 0; } @@ -195,6 +200,13 @@ static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, aud pReverb = (reverb_object_t*) &pRvbModule->context; + if (pReverb->mState == REVERB_STATE_UNINITIALIZED) { + return -EINVAL; + } + if (pReverb->mState == REVERB_STATE_INITIALIZED) { + return -ENODATA; + } + //if bypassed or the preset forces the signal to be completely dry if (pReverb->m_bBypass != 0) { if (inBuffer->raw != outBuffer->raw) { @@ -257,13 +269,15 @@ static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, aud return 0; } + static int Reverb_Command(effect_interface_t self, int cmdCode, int cmdSize, void *pCmdData, int *replySize, void *pReplyData) { reverb_module_t *pRvbModule = (reverb_module_t *) self; reverb_object_t *pReverb; int retsize; - if (pRvbModule == NULL) { + if (pRvbModule == NULL || + pRvbModule->context.mState == REVERB_STATE_UNINITIALIZED) { return -EINVAL; } @@ -277,6 +291,9 @@ static int Reverb_Command(effect_interface_t self, int cmdCode, int cmdSize, return -EINVAL; } *(int *) pReplyData = Reverb_Init(pRvbModule, pReverb->m_Aux, pReverb->m_Preset); + if (*(int *) pReplyData == 0) { + pRvbModule->context.mState = REVERB_STATE_INITIALIZED; + } break; case EFFECT_CMD_CONFIGURE: if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) @@ -315,10 +332,25 @@ static int Reverb_Command(effect_interface_t self, int cmdCode, int cmdSize, cmd->vsize, cmd->data + sizeof(int32_t)); break; case EFFECT_CMD_ENABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + if (pReverb->mState != REVERB_STATE_INITIALIZED) { + return -ENOSYS; + } + pReverb->mState = REVERB_STATE_ACTIVE; + LOGV("EFFECT_CMD_ENABLE() OK"); + *(int *)pReplyData = 0; + break; case EFFECT_CMD_DISABLE: if (pReplyData == NULL || *replySize != sizeof(int)) { return -EINVAL; } + if (pReverb->mState != REVERB_STATE_ACTIVE) { + return -ENOSYS; + } + pReverb->mState = REVERB_STATE_INITIALIZED; + LOGV("EFFECT_CMD_DISABLE() OK"); *(int *)pReplyData = 0; break; case EFFECT_CMD_SET_DEVICE: diff --git a/media/libeffects/EffectReverb.h b/media/libeffects/EffectReverb.h index 5af316d..ee8e390 100644 --- a/media/libeffects/EffectReverb.h +++ b/media/libeffects/EffectReverb.h @@ -114,6 +114,12 @@ int32_t nPanG1 = -1.0 for cos #define AP1_GAIN_RANGE (int)(22936-6553) +enum reverb_state_e { + REVERB_STATE_UNINITIALIZED, + REVERB_STATE_INITIALIZED, + REVERB_STATE_ACTIVE, +}; + /* parameters for each allpass */ typedef struct { @@ -279,6 +285,7 @@ typedef struct uint16_t m_Aux; // if TRUE, is connected as auxiliary effect uint16_t m_Preset; // if TRUE, expose preset revert interface + uint32_t mState; } reverb_object_t; diff --git a/media/libeffects/EffectVisualizer.cpp b/media/libeffects/EffectVisualizer.cpp index f27e296..bcda06e 100644 --- a/media/libeffects/EffectVisualizer.cpp +++ b/media/libeffects/EffectVisualizer.cpp @@ -231,7 +231,7 @@ extern "C" int Visualizer_process( return -EINVAL; } if (pContext->mState != VISUALIZER_STATE_ACTIVE) { - return -ENOSYS; + return -ENODATA; } if (inBuffer == NULL || inBuffer->raw == NULL || |