From eb61431af13741aa8b7e57a39f69bba5a6c190dc Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Thu, 10 May 2012 16:43:19 -0700 Subject: Increase AAC software decoder's buffer count. Refactor how clients of ACodec get notified about codec buffers and buffer ids. Change-Id: I962f873262dae7aa7b43f5f68a6d60268282f91e related-to-bug: 6478823 --- include/media/stagefright/ACodec.h | 17 +++++++++++++ media/libstagefright/ACodec.cpp | 33 ++++++++++++++++++++++--- media/libstagefright/MediaCodec.cpp | 18 +++++++------- media/libstagefright/codecs/aacdec/SoftAAC.cpp | 4 +-- media/libstagefright/codecs/aacdec/SoftAAC.h | 3 ++- media/libstagefright/codecs/aacdec/SoftAAC2.cpp | 4 +-- media/libstagefright/codecs/aacdec/SoftAAC2.h | 3 ++- 7 files changed, 63 insertions(+), 19 deletions(-) diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h index dd18e95..23e3110 100644 --- a/include/media/stagefright/ACodec.h +++ b/include/media/stagefright/ACodec.h @@ -56,6 +56,23 @@ struct ACodec : public AHierarchicalStateMachine { void initiateConfigureComponent(const sp &msg); void initiateStart(); + struct PortDescription : public RefBase { + size_t countBuffers(); + IOMX::buffer_id bufferIDAt(size_t index) const; + sp bufferAt(size_t index) const; + + private: + friend struct ACodec; + + Vector mBufferIDs; + Vector > mBuffers; + + PortDescription(); + void addBuffer(IOMX::buffer_id id, const sp &buffer); + + DISALLOW_EVIL_CONSTRUCTORS(PortDescription); + }; + protected: virtual ~ACodec(); diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 3fd6cef..7ac0f23 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -472,14 +472,16 @@ status_t ACodec::allocateBuffersOnPort(OMX_U32 portIndex) { notify->setInt32("what", ACodec::kWhatBuffersAllocated); notify->setInt32("portIndex", portIndex); + + sp desc = new PortDescription; + for (size_t i = 0; i < mBuffers[portIndex].size(); ++i) { - AString name = StringPrintf("buffer-id_%d", i); - notify->setPointer(name.c_str(), mBuffers[portIndex][i].mBufferID); + const BufferInfo &info = mBuffers[portIndex][i]; - name = StringPrintf("data_%d", i); - notify->setBuffer(name.c_str(), mBuffers[portIndex][i].mData); + desc->addBuffer(info.mBufferID, info.mData); } + notify->setObject("portDesc", desc); notify->post(); return OK; @@ -2110,6 +2112,29 @@ void ACodec::signalError(OMX_ERRORTYPE error, status_t internalError) { //////////////////////////////////////////////////////////////////////////////// +ACodec::PortDescription::PortDescription() { +} + +void ACodec::PortDescription::addBuffer( + IOMX::buffer_id id, const sp &buffer) { + mBufferIDs.push_back(id); + mBuffers.push_back(buffer); +} + +size_t ACodec::PortDescription::countBuffers() { + return mBufferIDs.size(); +} + +IOMX::buffer_id ACodec::PortDescription::bufferIDAt(size_t index) const { + return mBufferIDs.itemAt(index); +} + +sp ACodec::PortDescription::bufferAt(size_t index) const { + return mBuffers.itemAt(index); +} + +//////////////////////////////////////////////////////////////////////////////// + ACodec::BaseState::BaseState(ACodec *codec, const sp &parentState) : AState(parentState), mCodec(codec) { diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp index 5b513a8..ff71170 100644 --- a/media/libstagefright/MediaCodec.cpp +++ b/media/libstagefright/MediaCodec.cpp @@ -562,20 +562,20 @@ void MediaCodec::onMessageReceived(const sp &msg) { mPortBuffers[portIndex].clear(); Vector *buffers = &mPortBuffers[portIndex]; - for (size_t i = 0;; ++i) { - AString name = StringPrintf("buffer-id_%d", i); - void *bufferID; - if (!msg->findPointer(name.c_str(), &bufferID)) { - break; - } + sp obj; + CHECK(msg->findObject("portDesc", &obj)); + + sp portDesc = + static_cast(obj.get()); - name = StringPrintf("data_%d", i); + size_t numBuffers = portDesc->countBuffers(); + for (size_t i = 0; i < numBuffers; ++i) { BufferInfo info; - info.mBufferID = bufferID; + info.mBufferID = portDesc->bufferIDAt(i); info.mOwnedByClient = false; - CHECK(msg->findBuffer(name.c_str(), &info.mData)); + info.mData = portDesc->bufferAt(i); if (portIndex == kPortIndexInput && mCrypto != NULL) { info.mEncryptedData = diff --git a/media/libstagefright/codecs/aacdec/SoftAAC.cpp b/media/libstagefright/codecs/aacdec/SoftAAC.cpp index d509383..65aa2ad 100644 --- a/media/libstagefright/codecs/aacdec/SoftAAC.cpp +++ b/media/libstagefright/codecs/aacdec/SoftAAC.cpp @@ -69,7 +69,7 @@ void SoftAAC::initPorts() { def.nPortIndex = 0; def.eDir = OMX_DirInput; - def.nBufferCountMin = kNumBuffers; + def.nBufferCountMin = kNumInputBuffers; def.nBufferCountActual = def.nBufferCountMin; def.nBufferSize = 8192; def.bEnabled = OMX_TRUE; @@ -87,7 +87,7 @@ void SoftAAC::initPorts() { def.nPortIndex = 1; def.eDir = OMX_DirOutput; - def.nBufferCountMin = kNumBuffers; + def.nBufferCountMin = kNumOutputBuffers; def.nBufferCountActual = def.nBufferCountMin; def.nBufferSize = 8192; def.bEnabled = OMX_TRUE; diff --git a/media/libstagefright/codecs/aacdec/SoftAAC.h b/media/libstagefright/codecs/aacdec/SoftAAC.h index da0b8ed..c0789ab 100644 --- a/media/libstagefright/codecs/aacdec/SoftAAC.h +++ b/media/libstagefright/codecs/aacdec/SoftAAC.h @@ -45,7 +45,8 @@ protected: private: enum { - kNumBuffers = 4 + kNumInputBuffers = 32, + kNumOutputBuffers = 4, }; tPVMP4AudioDecoderExternal *mConfig; diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp index e499a0b..303b8ef 100644 --- a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp +++ b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp @@ -64,7 +64,7 @@ void SoftAAC2::initPorts() { def.nPortIndex = 0; def.eDir = OMX_DirInput; - def.nBufferCountMin = kNumBuffers; + def.nBufferCountMin = kNumInputBuffers; def.nBufferCountActual = def.nBufferCountMin; def.nBufferSize = 8192; def.bEnabled = OMX_TRUE; @@ -82,7 +82,7 @@ void SoftAAC2::initPorts() { def.nPortIndex = 1; def.eDir = OMX_DirOutput; - def.nBufferCountMin = kNumBuffers; + def.nBufferCountMin = kNumOutputBuffers; def.nBufferCountActual = def.nBufferCountMin; def.nBufferSize = 8192 * 2; def.bEnabled = OMX_TRUE; diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.h b/media/libstagefright/codecs/aacdec/SoftAAC2.h index e5a1e3e..57565ab 100644 --- a/media/libstagefright/codecs/aacdec/SoftAAC2.h +++ b/media/libstagefright/codecs/aacdec/SoftAAC2.h @@ -44,7 +44,8 @@ protected: private: enum { - kNumBuffers = 4 + kNumInputBuffers = 32, + kNumOutputBuffers = 4, }; HANDLE_AACDECODER mAACDecoder; -- cgit v1.1