From 35cbc3d57dc962ebbb9bd0fa522cfd2ec3dbf4d6 Mon Sep 17 00:00:00 2001 From: Zhou Song Date: Tue, 30 Aug 2016 16:44:55 +0800 Subject: [PATCH] audio: add support to return unreleased frames The unreleased frames(frames already consumed but not yet released by the resampler) are not excluded during prepareTracks, so track can be in fake ready state when actually there're not enough frames available, then 0s can be inserted during audio mixing and glitches can be heard. Save the unreleased frames to audioflinger to make the track in NOT_READY state when not enough buffers available to avoid track to be processed this time. CRs-Fixed: 1058677 Change-Id: Ib54ca1726ff3994bb7289c3b95ca04fe2c483d08 --- services/audioflinger/AudioResamplerQTI.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/audioflinger/AudioResamplerQTI.cpp b/services/audioflinger/AudioResamplerQTI.cpp index 3f6138fb31..0f1d26fa10 100644 --- a/services/audioflinger/AudioResamplerQTI.cpp +++ b/services/audioflinger/AudioResamplerQTI.cpp @@ -100,6 +100,7 @@ size_t AudioResamplerQTI::resample(int32_t* out, size_t outFrameCount, if (frameIndex >= mBuffer.frameCount) { provider->releaseBuffer(&mBuffer); + mInputIndex = 0; } } @@ -126,6 +127,7 @@ size_t AudioResamplerQTI::resample(int32_t* out, size_t outFrameCount, pBuf[index++] = clampq4_27_from_float(*((float *)mBuffer.raw + frameIndex++)); if (frameIndex >= mBuffer.frameCount * 2) { provider->releaseBuffer(&mBuffer); + mInputIndex = 0; } } @@ -142,6 +144,10 @@ resample_exit: fout[i+1] += float_from_q4_27((int32_t)(tempR>>12)); } + // save the unreleased frame count to mInputIndex + if (mBuffer.frameCount) { + mInputIndex = mChannelCount == 1 ? frameIndex : frameIndex/2; + } mFrameIndex = frameIndex; return index; } -- GitLab