diff options
author | Marco Nelissen <marcone@google.com> | 2012-03-21 13:36:07 -0700 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2012-03-22 10:06:03 -0700 |
commit | da9deca7bab75f39a236d04b9e43d9da833ce4a0 (patch) | |
tree | da55de4303ab3e4a2e32c70e9fc539dbc3da5745 /media/libstagefright/codecs | |
parent | 222dfc784e5c5b4eb6a4770b9f46fe96eecbd65d (diff) | |
download | frameworks_base-da9deca7bab75f39a236d04b9e43d9da833ce4a0.zip frameworks_base-da9deca7bab75f39a236d04b9e43d9da833ce4a0.tar.gz frameworks_base-da9deca7bab75f39a236d04b9e43d9da833ce4a0.tar.bz2 |
Support gapless playback for mp3 and m4a
Gapless playback for appropriately tagged mp3 and m4a files.
Currently this is implemented in OMXCodec, which most players
use, but should be easy to support in other players as well by
using the SkipCutBuffer utility class.
Change-Id: I748c669adc1cfbe5ee9a7dea2fad945d48882551
Diffstat (limited to 'media/libstagefright/codecs')
-rw-r--r-- | media/libstagefright/codecs/mp3dec/SoftMP3.cpp | 20 | ||||
-rw-r--r-- | media/libstagefright/codecs/mp3dec/SoftMP3.h | 6 |
2 files changed, 20 insertions, 6 deletions
diff --git a/media/libstagefright/codecs/mp3dec/SoftMP3.cpp b/media/libstagefright/codecs/mp3dec/SoftMP3.cpp index ad55295..92009ee 100644 --- a/media/libstagefright/codecs/mp3dec/SoftMP3.cpp +++ b/media/libstagefright/codecs/mp3dec/SoftMP3.cpp @@ -115,6 +115,7 @@ void SoftMP3::initDecoder() { mDecoderBuf = malloc(memRequirements); pvmp3_InitDecoder(mConfig, mDecoderBuf); + mIsFirst = true; } OMX_ERRORTYPE SoftMP3::internalGetParameter( @@ -190,7 +191,10 @@ void SoftMP3::onQueueFilled(OMX_U32 portIndex) { inInfo->mOwnedByUs = false; notifyEmptyBufferDone(inHeader); - outHeader->nFilledLen = 0; + // pad the end of the stream with 529 samples, since that many samples + // were trimmed off the beginning when decoding started + outHeader->nFilledLen = kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t); + memset(outHeader->pBuffer, 0, outHeader->nFilledLen); outHeader->nFlags = OMX_BUFFERFLAG_EOS; outQueue.erase(outQueue.begin()); @@ -251,8 +255,17 @@ void SoftMP3::onQueueFilled(OMX_U32 portIndex) { return; } - outHeader->nOffset = 0; - outHeader->nFilledLen = mConfig->outputFrameSize * sizeof(int16_t); + if (mIsFirst) { + mIsFirst = false; + // The decoder delay is 529 samples, so trim that many samples off + // the start of the first output buffer. This essentially makes this + // decoder have zero delay, which the rest of the pipeline assumes. + outHeader->nOffset = kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t); + outHeader->nFilledLen = mConfig->outputFrameSize * sizeof(int16_t) - outHeader->nOffset; + } else { + outHeader->nOffset = 0; + outHeader->nFilledLen = mConfig->outputFrameSize * sizeof(int16_t); + } outHeader->nTimeStamp = mAnchorTimeUs @@ -288,6 +301,7 @@ void SoftMP3::onPortFlushCompleted(OMX_U32 portIndex) { // Make sure that the next buffer output does not still // depend on fragments from the last one decoded. pvmp3_InitDecoder(mConfig, mDecoderBuf); + mIsFirst = true; } } diff --git a/media/libstagefright/codecs/mp3dec/SoftMP3.h b/media/libstagefright/codecs/mp3dec/SoftMP3.h index 70d0682..3a05466 100644 --- a/media/libstagefright/codecs/mp3dec/SoftMP3.h +++ b/media/libstagefright/codecs/mp3dec/SoftMP3.h @@ -46,7 +46,8 @@ protected: private: enum { kNumBuffers = 4, - kOutputBufferSize = 4608 * 2 + kOutputBufferSize = 4608 * 2, + kPVMP3DecoderDelay = 529 // frames }; tPVMP3DecoderExternal *mConfig; @@ -57,8 +58,7 @@ private: int32_t mNumChannels; int32_t mSamplingRate; - bool mConfigured; - + bool mIsFirst; bool mSignalledError; enum { |