summaryrefslogtreecommitdiffstats
path: root/media/libeffects
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2011-11-11 11:51:14 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2011-11-11 11:51:14 -0800
commit73bb0b9f2922679d057e29e9f502988178554a02 (patch)
tree56efd281b6a1e290a497351270ea7d25d8b35065 /media/libeffects
parent516fb1dad0c434fd89624c418543d35436a5374c (diff)
parent1e809edd9b25e34d9c475ecd2c2e26ddc75cba2c (diff)
downloadframeworks_av-73bb0b9f2922679d057e29e9f502988178554a02.zip
frameworks_av-73bb0b9f2922679d057e29e9f502988178554a02.tar.gz
frameworks_av-73bb0b9f2922679d057e29e9f502988178554a02.tar.bz2
am 2c29a5cf: am 1f8c6212: Merge "visualizer: reset buffer if playback is idle" into ics-mr1
* commit '2c29a5cf1658532bca4e34f816fa30312241a336': visualizer: reset buffer if playback is idle
Diffstat (limited to 'media/libeffects')
-rw-r--r--media/libeffects/visualizer/EffectVisualizer.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp
index 6db87fe..e9b8042 100644
--- a/media/libeffects/visualizer/EffectVisualizer.cpp
+++ b/media/libeffects/visualizer/EffectVisualizer.cpp
@@ -47,17 +47,22 @@ enum visualizer_state_e {
VISUALIZER_STATE_ACTIVE,
};
+// maximum number of reads from same buffer before resetting capture buffer. This means
+// that the framework has stopped playing audio and we must start returning silence
+#define MAX_STALL_COUNT 10
+
struct VisualizerContext {
const struct effect_interface_s *mItfe;
effect_config_t mConfig;
- uint32_t mState;
uint32_t mCaptureIdx;
uint32_t mCaptureSize;
- uint32_t mCurrentBuf;
+ uint8_t mState;
+ uint8_t mCurrentBuf;
+ uint8_t mLastBuf;
+ uint8_t mStallCount;
uint8_t mCaptureBuf[2][VISUALIZER_CAPTURE_SIZE_MAX];
};
-
//
//--- Local functions
//
@@ -66,6 +71,8 @@ void Visualizer_reset(VisualizerContext *pContext)
{
pContext->mCaptureIdx = 0;
pContext->mCurrentBuf = 0;
+ pContext->mLastBuf = 1;
+ pContext->mStallCount = 0;
memset(pContext->mCaptureBuf[0], 0x80, VISUALIZER_CAPTURE_SIZE_MAX);
memset(pContext->mCaptureBuf[1], 0x80, VISUALIZER_CAPTURE_SIZE_MAX);
}
@@ -417,9 +424,24 @@ int Visualizer_command(effect_handle_t self, uint32_t cmdCode, uint32_t cmdSize,
memcpy(pReplyData,
pContext->mCaptureBuf[pContext->mCurrentBuf ^ 1],
pContext->mCaptureSize);
+ // if audio framework has stopped playing audio although the effect is still
+ // active we must clear the capture buffer to return silence
+ if (pContext->mLastBuf == pContext->mCurrentBuf) {
+ if (pContext->mStallCount < MAX_STALL_COUNT) {
+ if (++pContext->mStallCount == MAX_STALL_COUNT) {
+ memset(pContext->mCaptureBuf[pContext->mCurrentBuf ^ 1],
+ 0x80,
+ pContext->mCaptureSize);
+ }
+ }
+ } else {
+ pContext->mStallCount = 0;
+ }
+ pContext->mLastBuf = pContext->mCurrentBuf;
} else {
memset(pReplyData, 0x80, pContext->mCaptureSize);
}
+
break;
default: