From 4edf384a512748b871f24e4c03afaa3c1151ca23 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Thu, 25 Sep 2014 14:25:18 -0700 Subject: [PATCH] Fix SoftAAC2 flush If there were less than a full frame worth of samples in the ring buffer, then flush would loop forever trying to empty the ring buffer. Bug: 17646525 Change-Id: I68ec87352a91ce3a96d05e9b3f60a6e7975f9156 --- media/libstagefright/codecs/aacdec/SoftAAC2.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp index fb27dca41b..e701e9efef 100644 --- a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp +++ b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp @@ -974,11 +974,15 @@ void SoftAAC2::onPortFlushCompleted(OMX_U32 portIndex) { mDecodedSizes.clear(); mLastInHeader = NULL; } else { - while (outputDelayRingBufferSamplesAvailable() > 0) { - int32_t ns = outputDelayRingBufferGetSamples(0, - mStreamInfo->frameSize * mStreamInfo->numChannels); - if (ns != mStreamInfo->frameSize * mStreamInfo->numChannels) { + int avail; + while ((avail = outputDelayRingBufferSamplesAvailable()) > 0) { + if (avail > mStreamInfo->frameSize * mStreamInfo->numChannels) { + avail = mStreamInfo->frameSize * mStreamInfo->numChannels; + } + int32_t ns = outputDelayRingBufferGetSamples(0, avail); + if (ns != avail) { ALOGE("not a complete frame of samples available"); + break; } mOutputBufferCount++; } -- 2.11.0