diff options
author | vivek mehta <mvivek@codeaurora.org> | 2015-07-16 12:56:57 -0700 |
---|---|---|
committer | Satish Kamuju <skamuj@codeaurora.org> | 2015-10-06 17:36:46 +0530 |
commit | bc3028750d3438ebf108298e93f12de461f56430 (patch) | |
tree | 20081f78f461ee05b8a1c2cf842387ca3c89f4e5 /media/libstagefright/codecs/aacdec/SoftAAC2.cpp | |
parent | 9953765019ae2243e98e8e74eee327c9893b93d1 (diff) | |
download | frameworks_av-bc3028750d3438ebf108298e93f12de461f56430.zip frameworks_av-bc3028750d3438ebf108298e93f12de461f56430.tar.gz frameworks_av-bc3028750d3438ebf108298e93f12de461f56430.tar.bz2 |
stagefright: Add support for custom size i/p buffer
- handle non default input buffer size
- fix issues associated with non-default buffer size
Change-Id: Iad31f5c85601983b01e18e130b1c3eecb3988e30
Diffstat (limited to 'media/libstagefright/codecs/aacdec/SoftAAC2.cpp')
-rw-r--r-- | media/libstagefright/codecs/aacdec/SoftAAC2.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp index 965c55e..c945305 100644 --- a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp +++ b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp @@ -68,6 +68,8 @@ SoftAAC2::SoftAAC2( mOutputBufferCount(0), mSignalledError(false), mLastInHeader(NULL), + mLastHeaderTimeUs(-1), + mNextOutBufferTimeUs(0), mOutputPortSettingsChange(NONE) { initPorts(); CHECK_EQ(initDecoder(), (status_t)OK); @@ -492,6 +494,27 @@ int32_t SoftAAC2::outputDelayRingBufferSpaceLeft() { return mOutputDelayRingBufferSize - outputDelayRingBufferSamplesAvailable(); } +void SoftAAC2::updateTimeStamp(int64_t inHeaderTimeUs) { + // use new input buffer timestamp as Anchor Time if its + // a) first buffer or + // b) first buffer post seek or + // c) different from last buffer timestamp + //If input buffer timestamp is same as last input buffer timestamp then + //treat this as a erroneous timestamp and ignore new input buffer + //timestamp and use last output buffer timestamp as Anchor Time. + int64_t anchorTimeUs = 0; + if ((mLastHeaderTimeUs != inHeaderTimeUs)) { + anchorTimeUs = inHeaderTimeUs; + mLastHeaderTimeUs = inHeaderTimeUs; + //Store current buffer's timestamp so that it can used as reference + //in cases where first frame/buffer is skipped/dropped. + //e.g to compensate decoder delay + mNextOutBufferTimeUs = inHeaderTimeUs; + } else { + anchorTimeUs = mNextOutBufferTimeUs; + } + mBufferTimestamps.add(anchorTimeUs); +} void SoftAAC2::onQueueFilled(OMX_U32 /* portIndex */) { if (mSignalledError || mOutputPortSettingsChange != NONE) { @@ -618,7 +641,7 @@ void SoftAAC2::onQueueFilled(OMX_U32 /* portIndex */) { // insert buffer size and time stamp mBufferSizes.add(inBufferLength[0]); if (mLastInHeader != inHeader) { - mBufferTimestamps.add(inHeader->nTimeStamp); + updateTimeStamp(inHeader->nTimeStamp); mLastInHeader = inHeader; } else { int64_t currentTime = mBufferTimestamps.top(); @@ -630,7 +653,7 @@ void SoftAAC2::onQueueFilled(OMX_U32 /* portIndex */) { inBuffer[0] = inHeader->pBuffer + inHeader->nOffset; inBufferLength[0] = inHeader->nFilledLen; mLastInHeader = inHeader; - mBufferTimestamps.add(inHeader->nTimeStamp); + updateTimeStamp(inHeader->nTimeStamp); mBufferSizes.add(inHeader->nFilledLen); } @@ -755,6 +778,14 @@ void SoftAAC2::onQueueFilled(OMX_U32 /* portIndex */) { if (inHeader && inHeader->nFilledLen == 0) { inInfo->mOwnedByUs = false; mInputBufferCount++; + + //During Port reconfiguration current frames is skipped and next frame + //is sent for decoding. + //Update mNextOutBufferTimeUs with current frame's timestamp if port reconfiguration is + //happening in last frame of current buffer otherwise LastOutBufferTimeUs + //will be zero(post seek). + mNextOutBufferTimeUs = mBufferTimestamps.top() + mStreamInfo->aacSamplesPerFrame * + 1000000ll / mStreamInfo->aacSampleRate; inQueue.erase(inQueue.begin()); mLastInHeader = NULL; inInfo = NULL; @@ -875,6 +906,7 @@ void SoftAAC2::onQueueFilled(OMX_U32 /* portIndex */) { *currentBufLeft -= decodedSize; *nextTimeStamp += mStreamInfo->aacSamplesPerFrame * 1000000ll / mStreamInfo->aacSampleRate; + mNextOutBufferTimeUs = *nextTimeStamp; ALOGV("adjusted nextTimeStamp/size to %lld/%d", (long long) *nextTimeStamp, *currentBufLeft); } else { @@ -882,6 +914,7 @@ void SoftAAC2::onQueueFilled(OMX_U32 /* portIndex */) { if (mBufferTimestamps.size() > 0) { mBufferTimestamps.removeAt(0); nextTimeStamp = &mBufferTimestamps.editItemAt(0); + mNextOutBufferTimeUs = *nextTimeStamp; mBufferSizes.removeAt(0); currentBufLeft = &mBufferSizes.editItemAt(0); ALOGV("moved to next time/size: %lld/%d", @@ -976,6 +1009,8 @@ void SoftAAC2::onPortFlushCompleted(OMX_U32 portIndex) { mDecodedSizes.clear(); mLastInHeader = NULL; mEndOfInput = false; + mLastHeaderTimeUs = -1; + mNextOutBufferTimeUs = 0; } else { int avail; while ((avail = outputDelayRingBufferSamplesAvailable()) > 0) { @@ -1038,6 +1073,8 @@ void SoftAAC2::onReset() { mBufferSizes.clear(); mDecodedSizes.clear(); mLastInHeader = NULL; + mLastHeaderTimeUs = -1; + mNextOutBufferTimeUs = 0; // To make the codec behave the same before and after a reset, we need to invalidate the // streaminfo struct. This does that: |