diff options
author | Marco Nelissen <marcone@google.com> | 2012-04-27 09:33:24 -0700 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2012-04-30 09:40:47 -0700 |
commit | 8b71241ce7353731ab75322c46e090ee35014a33 (patch) | |
tree | afc21859dae503e57aa5a3cc777512800d1fd64e /media/libstagefright/ACodec.cpp | |
parent | 83faee053cfd4251dbb591b62039f563ffdac399 (diff) |
Fix mono gapless playback for decoders that output stereo
The old AAC decoder always outputs stereo, even for mono source material, so we
need to use the number of channels of the output when calculating the number of
bytes to skip, not the number of channels in the source.
This makes OMXCodec skip the right amount of data, and prevents NuPlayer from
writing half a frame and then asserting when the AudioSink doesn't accept it.
Also move use of the SkipCutBuffer from NuPlayer to ACodec, so that it also
works when using the new Java APIs, and make SkipCutBuffer derive from RefBase.
b/774846
Change-Id: I34df9fea3e6730617eae559afaa556f4085ef0a0
Diffstat (limited to 'media/libstagefright/ACodec.cpp')
-rw-r--r-- | media/libstagefright/ACodec.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index c303146f..0de2d0a9 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -889,6 +889,13 @@ status_t ACodec::configureCodec( } } + if (!msg->findInt32("encoder-delay", &mEncoderDelay)) { + mEncoderDelay = 0; + } + if (!msg->findInt32("encoder-padding", &mEncoderPadding)) { + mEncoderPadding = 0; + } + int32_t maxInputSize; if (msg->findInt32("max-input-size", &maxInputSize)) { err = setMinBufferSize(kPortIndexInput, (size_t)maxInputSize); @@ -2003,6 +2010,17 @@ void ACodec::sendFormatChange() { notify->setString("mime", MEDIA_MIMETYPE_AUDIO_RAW); notify->setInt32("channel-count", params.nChannels); notify->setInt32("sample-rate", params.nSamplingRate); + if (mEncoderDelay + mEncoderPadding) { + size_t frameSize = params.nChannels * sizeof(int16_t); + if (mSkipCutBuffer != NULL) { + size_t prevbufsize = mSkipCutBuffer->size(); + if (prevbufsize != 0) { + ALOGW("Replacing SkipCutBuffer holding %d bytes", prevbufsize); + } + } + mSkipCutBuffer = new SkipCutBuffer(mEncoderDelay * frameSize, + mEncoderPadding * frameSize); + } break; } @@ -2417,6 +2435,9 @@ bool ACodec::BaseState::onOMXFillBufferDone( info->mData->setRange(rangeOffset, rangeLength); } + if (mCodec->mSkipCutBuffer != NULL) { + mCodec->mSkipCutBuffer->submit(info->mData); + } info->mData->meta()->setInt64("timeUs", timeUs); sp<AMessage> notify = mCodec->mNotify->dup(); |