summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/AudioResamplerDyn.cpp
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2014-05-27 12:32:17 -0700
committerAndy Hung <hunga@google.com>2014-05-28 14:20:23 -0700
commit411cb8e45442d16d983a38722c7c7bce487bde6b (patch)
treee819e73fe603393fa8f80dc0c12be7e2434cd43b /services/audioflinger/AudioResamplerDyn.cpp
parent498692535c7ceecb3434a99c47e4c90ba3fdd90e (diff)
downloadframeworks_av-411cb8e45442d16d983a38722c7c7bce487bde6b.zip
frameworks_av-411cb8e45442d16d983a38722c7c7bce487bde6b.tar.gz
frameworks_av-411cb8e45442d16d983a38722c7c7bce487bde6b.tar.bz2
Update dynamic resampler buffer fetching
Make the criteria tight for fetching to avoid storing excessive frame data internal to the resampler. This should reduce jitter in frame delivery computation. Bug: 14962343 Change-Id: I7adaf714d11c272696ccdbf218bda994c7217477
Diffstat (limited to 'services/audioflinger/AudioResamplerDyn.cpp')
-rw-r--r--services/audioflinger/AudioResamplerDyn.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/services/audioflinger/AudioResamplerDyn.cpp b/services/audioflinger/AudioResamplerDyn.cpp
index 3abe8fd..a4446a4 100644
--- a/services/audioflinger/AudioResamplerDyn.cpp
+++ b/services/audioflinger/AudioResamplerDyn.cpp
@@ -455,12 +455,13 @@ void AudioResamplerDyn<TC, TI, TO>::resample(TO* out, size_t outFrameCount,
const Constants& c(mConstants);
const TC* const coefs = mConstants.mFirCoefs;
TI* impulse = mInBuffer.getImpulse();
- size_t inputIndex = mInputIndex;
+ size_t inputIndex = 0;
uint32_t phaseFraction = mPhaseFraction;
const uint32_t phaseIncrement = mPhaseIncrement;
size_t outputIndex = 0;
size_t outputSampleCount = outFrameCount * 2; // stereo output
- size_t inFrameCount = getInFrameCountRequired(outFrameCount);
+ size_t inFrameCount = getInFrameCountRequired(outFrameCount) + (phaseFraction != 0);
+ ALOG_ASSERT(0 < inFrameCount && inFrameCount < (1U << 31));
const uint32_t phaseWrapLimit = c.mL << c.mShift;
// NOTE: be very careful when modifying the code here. register
@@ -474,11 +475,13 @@ void AudioResamplerDyn<TC, TI, TO>::resample(TO* out, size_t outFrameCount,
// buffer is empty, fetch a new one
while (mBuffer.frameCount == 0) {
mBuffer.frameCount = inFrameCount;
+ ALOG_ASSERT(inFrameCount > 0);
provider->getNextBuffer(&mBuffer,
calculateOutputPTS(outputIndex / 2));
if (mBuffer.raw == NULL) {
goto resample_exit;
}
+ inFrameCount -= mBuffer.frameCount;
if (phaseFraction >= phaseWrapLimit) { // read in data
mInBuffer.template readAdvance<CHANNELS>(
impulse, c.mHalfNumCoefs,
@@ -487,7 +490,7 @@ void AudioResamplerDyn<TC, TI, TO>::resample(TO* out, size_t outFrameCount,
while (phaseFraction >= phaseWrapLimit) {
inputIndex++;
if (inputIndex >= mBuffer.frameCount) {
- inputIndex -= mBuffer.frameCount;
+ inputIndex = 0;
provider->releaseBuffer(&mBuffer);
break;
}
@@ -535,15 +538,22 @@ void AudioResamplerDyn<TC, TI, TO>::resample(TO* out, size_t outFrameCount,
done:
// often arrives here when input buffer runs out
if (inputIndex >= frameCount) {
- inputIndex -= frameCount;
+ inputIndex = 0;
provider->releaseBuffer(&mBuffer);
- // mBuffer.frameCount MUST be zero here.
+ ALOG_ASSERT(mBuffer.frameCount == 0);
}
}
resample_exit:
+ // Release frames to avoid the count being inaccurate for pts timing.
+ // TODO: Avoid this extra check by making fetch count exact. This is tricky
+ // due to the overfetching mechanism which loads unnecessarily when
+ // mBuffer.frameCount == 0.
+ if (inputIndex) {
+ mBuffer.frameCount = inputIndex;
+ provider->releaseBuffer(&mBuffer);
+ }
mInBuffer.setImpulse(impulse);
- mInputIndex = inputIndex;
mPhaseFraction = phaseFraction;
}