Skip to content

Commit df8ab51

Browse files
author
Eric Laurent
committed
visualizer: reset buffer if playback is idle
Visualizer capture buffer must be reset if audio framework has stopped calling process for a given period of time to get read of residual data from previous captures. Issue 5571920. Change-Id: I6e73f971bb812cdbb2979a3b5e763abab07634eb
1 parent 843e04d commit df8ab51

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

media/libeffects/visualizer/EffectVisualizer.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,22 @@ enum visualizer_state_e {
4747
VISUALIZER_STATE_ACTIVE,
4848
};
4949

50+
// maximum number of reads from same buffer before resetting capture buffer. This means
51+
// that the framework has stopped playing audio and we must start returning silence
52+
#define MAX_STALL_COUNT 10
53+
5054
struct VisualizerContext {
5155
const struct effect_interface_s *mItfe;
5256
effect_config_t mConfig;
53-
uint32_t mState;
5457
uint32_t mCaptureIdx;
5558
uint32_t mCaptureSize;
56-
uint32_t mCurrentBuf;
59+
uint8_t mState;
60+
uint8_t mCurrentBuf;
61+
uint8_t mLastBuf;
62+
uint8_t mStallCount;
5763
uint8_t mCaptureBuf[2][VISUALIZER_CAPTURE_SIZE_MAX];
5864
};
5965

60-
6166
//
6267
//--- Local functions
6368
//
@@ -66,6 +71,8 @@ void Visualizer_reset(VisualizerContext *pContext)
6671
{
6772
pContext->mCaptureIdx = 0;
6873
pContext->mCurrentBuf = 0;
74+
pContext->mLastBuf = 1;
75+
pContext->mStallCount = 0;
6976
memset(pContext->mCaptureBuf[0], 0x80, VISUALIZER_CAPTURE_SIZE_MAX);
7077
memset(pContext->mCaptureBuf[1], 0x80, VISUALIZER_CAPTURE_SIZE_MAX);
7178
}
@@ -417,9 +424,24 @@ int Visualizer_command(effect_handle_t self, uint32_t cmdCode, uint32_t cmdSize,
417424
memcpy(pReplyData,
418425
pContext->mCaptureBuf[pContext->mCurrentBuf ^ 1],
419426
pContext->mCaptureSize);
427+
// if audio framework has stopped playing audio although the effect is still
428+
// active we must clear the capture buffer to return silence
429+
if (pContext->mLastBuf == pContext->mCurrentBuf) {
430+
if (pContext->mStallCount < MAX_STALL_COUNT) {
431+
if (++pContext->mStallCount == MAX_STALL_COUNT) {
432+
memset(pContext->mCaptureBuf[pContext->mCurrentBuf ^ 1],
433+
0x80,
434+
pContext->mCaptureSize);
435+
}
436+
}
437+
} else {
438+
pContext->mStallCount = 0;
439+
}
440+
pContext->mLastBuf = pContext->mCurrentBuf;
420441
} else {
421442
memset(pReplyData, 0x80, pContext->mCaptureSize);
422443
}
444+
423445
break;
424446

425447
default:

0 commit comments

Comments
 (0)