Loading media/codec2/hal/client/GraphicBufferAllocator.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,10 @@ c2_status_t GraphicBufferAllocator::displayBuffer( return mGraphicsTracker->render(block, input, output); } void GraphicBufferAllocator::onRequestStop() { mGraphicsTracker->onRequestStop(); } GraphicBufferAllocator::~GraphicBufferAllocator() {} std::shared_ptr<GraphicBufferAllocator> GraphicBufferAllocator::CreateGraphicBufferAllocator( Loading media/codec2/hal/client/GraphicsTracker.cpp +59 −6 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ namespace { static constexpr int kMaxDequeueMin = 1; static constexpr int kMaxDequeueMax = ::android::BufferQueueDefs::NUM_BUFFER_SLOTS - 2; // Just some delay for HAL to receive the stop()/release() request. static constexpr int kAllocateDirectDelayUs = 16666; c2_status_t retrieveAHardwareBufferId(const C2ConstGraphicBlock &blk, uint64_t *bid) { std::shared_ptr<const _C2BlockPoolData> bpData = _C2BlockFactory::GetGraphicBlockPoolData(blk); if (!bpData || bpData->getType() != _C2BlockPoolData::TYPE_AHWBUFFER) { Loading Loading @@ -177,7 +180,7 @@ GraphicsTracker::GraphicsTracker(int maxDequeueCount) mMaxDequeueCommitted{maxDequeueCount}, mDequeueable{maxDequeueCount}, mTotalDequeued{0}, mTotalCancelled{0}, mTotalDropped{0}, mTotalReleased{0}, mInConfig{false}, mStopped{false} { mInConfig{false}, mStopped{false}, mStopRequested{false}, mAllocAfterStopRequested{0} { if (maxDequeueCount < kMaxDequeueMin) { mMaxDequeue = kMaxDequeueMin; mMaxDequeueCommitted = kMaxDequeueMin; Loading Loading @@ -490,6 +493,18 @@ void GraphicsTracker::stop() { } } void GraphicsTracker::onRequestStop() { std::unique_lock<std::mutex> l(mLock); if (mStopped) { return; } if (mStopRequested) { return; } mStopRequested = true; writeIncDequeueableLocked(kMaxDequeueMax - 1); } void GraphicsTracker::writeIncDequeueableLocked(int inc) { CHECK(inc > 0 && inc < kMaxDequeueMax); thread_local char buf[kMaxDequeueMax]; Loading Loading @@ -544,8 +559,7 @@ c2_status_t GraphicsTracker::getWaitableFd(int *pipeFd) { return C2_OK; } c2_status_t GraphicsTracker::requestAllocate(std::shared_ptr<BufferCache> *cache) { std::lock_guard<std::mutex> l(mLock); c2_status_t GraphicsTracker::requestAllocateLocked(std::shared_ptr<BufferCache> *cache) { if (mDequeueable > 0) { char buf[1]; int ret = ::read(mReadPipeFd.get(), buf, 1); Loading Loading @@ -728,6 +742,34 @@ c2_status_t GraphicsTracker::_allocate(const std::shared_ptr<BufferCache> &cache return C2_OK; } c2_status_t GraphicsTracker::_allocateDirect( uint32_t width, uint32_t height, PixelFormat format, uint64_t usage, AHardwareBuffer **buf, sp<Fence> *rFence) { AHardwareBuffer_Desc desc; desc.width = width; desc.height = height; desc.layers = 1u; desc.format = ::android::AHardwareBuffer_convertFromPixelFormat(format); desc.usage = ::android::AHardwareBuffer_convertFromGrallocUsageBits(usage); desc.rfu0 = 0; desc.rfu1 = 0; int res = AHardwareBuffer_allocate(&desc, buf); if (res != ::android::OK) { ALOGE("_allocateDirect() failed(%d)", res); if (res == ::android::NO_MEMORY) { return C2_NO_MEMORY; } else { return C2_CORRUPTED; } } int alloced = mAllocAfterStopRequested++; *rFence = Fence::NO_FENCE; ALOGD("_allocateDirect() allocated %d buffer", alloced); return C2_OK; } c2_status_t GraphicsTracker::allocate( uint32_t width, uint32_t height, PixelFormat format, uint64_t usage, AHardwareBuffer **buf, sp<Fence> *rFence) { Loading @@ -735,11 +777,22 @@ c2_status_t GraphicsTracker::allocate( ALOGE("cannot allocate due to being stopped"); return C2_BAD_STATE; } c2_status_t res = C2_OK; std::shared_ptr<BufferCache> cache; c2_status_t res = requestAllocate(&cache); { std::unique_lock<std::mutex> l(mLock); if (mStopRequested) { l.unlock(); res = _allocateDirect(width, height, format, usage, buf, rFence); // Delay a little bit for HAL to receive stop()/release() request. ::usleep(kAllocateDirectDelayUs); return res; } c2_status_t res = requestAllocateLocked(&cache); if (res != C2_OK) { return res; } } ALOGV("allocatable or dequeueable"); bool cached = false; Loading media/codec2/hal/client/client.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -3170,6 +3170,11 @@ c2_status_t Codec2Client::Component::start() { c2_status_t Codec2Client::Component::stop() { if (mAidlBase) { std::shared_ptr<AidlGraphicBufferAllocator> gba = mGraphicBufferAllocators->current(); if (gba) { gba->onRequestStop(); } ::ndk::ScopedAStatus transStatus = mAidlBase->stop(); return GetC2Status(transStatus, "stop"); } Loading Loading @@ -3220,6 +3225,11 @@ c2_status_t Codec2Client::Component::release() { } } if (mAidlBase) { std::shared_ptr<AidlGraphicBufferAllocator> gba = mGraphicBufferAllocators->current(); if (gba) { gba->onRequestStop(); } ::ndk::ScopedAStatus transStatus = mAidlBase->release(); return GetC2Status(transStatus, "release"); } Loading media/codec2/hal/client/include/codec2/aidl/GraphicBufferAllocator.h +5 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,11 @@ public: const ::android::IGraphicBufferProducer::QueueBufferInput& input, ::android::IGraphicBufferProducer::QueueBufferOutput *output); /** * Notify stop()/release() is in progress. */ void onRequestStop(); ~GraphicBufferAllocator(); /** Loading media/codec2/hal/client/include/codec2/aidl/GraphicsTracker.h +17 −1 Original line number Diff line number Diff line Loading @@ -175,6 +175,14 @@ public: */ void stop(); /** * stop()/release() request to HAL is in process from the client. * The class will never be active again after the request. * Still, allocation requests from HAL should be served until stop() * is being called. */ void onRequestStop(); private: struct BufferCache; Loading Loading @@ -290,6 +298,10 @@ private: std::atomic<bool> mStopped; bool mStopRequested; std::atomic<int> mAllocAfterStopRequested; private: explicit GraphicsTracker(int maxDequeueCount); Loading @@ -304,7 +316,7 @@ private: const std::shared_ptr<BufferCache> &cache, int maxDequeueCommitted); c2_status_t requestAllocate(std::shared_ptr<BufferCache> *cache); c2_status_t requestAllocateLocked(std::shared_ptr<BufferCache> *cache); c2_status_t requestDeallocate(uint64_t bid, const sp<Fence> &fence, bool *completed, bool *updateDequeue, std::shared_ptr<BufferCache> *cache, int *slotId, Loading Loading @@ -334,6 +346,10 @@ private: bool *cached, int *rSlotId, sp<Fence> *rFence, std::shared_ptr<BufferItem> *buffer); c2_status_t _allocateDirect( uint32_t width, uint32_t height, PixelFormat format, uint64_t usage, AHardwareBuffer **buf, sp<Fence> *fence); void writeIncDequeueableLocked(int inc); void drainDequeueableLocked(int dec); }; Loading Loading
media/codec2/hal/client/GraphicBufferAllocator.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,10 @@ c2_status_t GraphicBufferAllocator::displayBuffer( return mGraphicsTracker->render(block, input, output); } void GraphicBufferAllocator::onRequestStop() { mGraphicsTracker->onRequestStop(); } GraphicBufferAllocator::~GraphicBufferAllocator() {} std::shared_ptr<GraphicBufferAllocator> GraphicBufferAllocator::CreateGraphicBufferAllocator( Loading
media/codec2/hal/client/GraphicsTracker.cpp +59 −6 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ namespace { static constexpr int kMaxDequeueMin = 1; static constexpr int kMaxDequeueMax = ::android::BufferQueueDefs::NUM_BUFFER_SLOTS - 2; // Just some delay for HAL to receive the stop()/release() request. static constexpr int kAllocateDirectDelayUs = 16666; c2_status_t retrieveAHardwareBufferId(const C2ConstGraphicBlock &blk, uint64_t *bid) { std::shared_ptr<const _C2BlockPoolData> bpData = _C2BlockFactory::GetGraphicBlockPoolData(blk); if (!bpData || bpData->getType() != _C2BlockPoolData::TYPE_AHWBUFFER) { Loading Loading @@ -177,7 +180,7 @@ GraphicsTracker::GraphicsTracker(int maxDequeueCount) mMaxDequeueCommitted{maxDequeueCount}, mDequeueable{maxDequeueCount}, mTotalDequeued{0}, mTotalCancelled{0}, mTotalDropped{0}, mTotalReleased{0}, mInConfig{false}, mStopped{false} { mInConfig{false}, mStopped{false}, mStopRequested{false}, mAllocAfterStopRequested{0} { if (maxDequeueCount < kMaxDequeueMin) { mMaxDequeue = kMaxDequeueMin; mMaxDequeueCommitted = kMaxDequeueMin; Loading Loading @@ -490,6 +493,18 @@ void GraphicsTracker::stop() { } } void GraphicsTracker::onRequestStop() { std::unique_lock<std::mutex> l(mLock); if (mStopped) { return; } if (mStopRequested) { return; } mStopRequested = true; writeIncDequeueableLocked(kMaxDequeueMax - 1); } void GraphicsTracker::writeIncDequeueableLocked(int inc) { CHECK(inc > 0 && inc < kMaxDequeueMax); thread_local char buf[kMaxDequeueMax]; Loading Loading @@ -544,8 +559,7 @@ c2_status_t GraphicsTracker::getWaitableFd(int *pipeFd) { return C2_OK; } c2_status_t GraphicsTracker::requestAllocate(std::shared_ptr<BufferCache> *cache) { std::lock_guard<std::mutex> l(mLock); c2_status_t GraphicsTracker::requestAllocateLocked(std::shared_ptr<BufferCache> *cache) { if (mDequeueable > 0) { char buf[1]; int ret = ::read(mReadPipeFd.get(), buf, 1); Loading Loading @@ -728,6 +742,34 @@ c2_status_t GraphicsTracker::_allocate(const std::shared_ptr<BufferCache> &cache return C2_OK; } c2_status_t GraphicsTracker::_allocateDirect( uint32_t width, uint32_t height, PixelFormat format, uint64_t usage, AHardwareBuffer **buf, sp<Fence> *rFence) { AHardwareBuffer_Desc desc; desc.width = width; desc.height = height; desc.layers = 1u; desc.format = ::android::AHardwareBuffer_convertFromPixelFormat(format); desc.usage = ::android::AHardwareBuffer_convertFromGrallocUsageBits(usage); desc.rfu0 = 0; desc.rfu1 = 0; int res = AHardwareBuffer_allocate(&desc, buf); if (res != ::android::OK) { ALOGE("_allocateDirect() failed(%d)", res); if (res == ::android::NO_MEMORY) { return C2_NO_MEMORY; } else { return C2_CORRUPTED; } } int alloced = mAllocAfterStopRequested++; *rFence = Fence::NO_FENCE; ALOGD("_allocateDirect() allocated %d buffer", alloced); return C2_OK; } c2_status_t GraphicsTracker::allocate( uint32_t width, uint32_t height, PixelFormat format, uint64_t usage, AHardwareBuffer **buf, sp<Fence> *rFence) { Loading @@ -735,11 +777,22 @@ c2_status_t GraphicsTracker::allocate( ALOGE("cannot allocate due to being stopped"); return C2_BAD_STATE; } c2_status_t res = C2_OK; std::shared_ptr<BufferCache> cache; c2_status_t res = requestAllocate(&cache); { std::unique_lock<std::mutex> l(mLock); if (mStopRequested) { l.unlock(); res = _allocateDirect(width, height, format, usage, buf, rFence); // Delay a little bit for HAL to receive stop()/release() request. ::usleep(kAllocateDirectDelayUs); return res; } c2_status_t res = requestAllocateLocked(&cache); if (res != C2_OK) { return res; } } ALOGV("allocatable or dequeueable"); bool cached = false; Loading
media/codec2/hal/client/client.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -3170,6 +3170,11 @@ c2_status_t Codec2Client::Component::start() { c2_status_t Codec2Client::Component::stop() { if (mAidlBase) { std::shared_ptr<AidlGraphicBufferAllocator> gba = mGraphicBufferAllocators->current(); if (gba) { gba->onRequestStop(); } ::ndk::ScopedAStatus transStatus = mAidlBase->stop(); return GetC2Status(transStatus, "stop"); } Loading Loading @@ -3220,6 +3225,11 @@ c2_status_t Codec2Client::Component::release() { } } if (mAidlBase) { std::shared_ptr<AidlGraphicBufferAllocator> gba = mGraphicBufferAllocators->current(); if (gba) { gba->onRequestStop(); } ::ndk::ScopedAStatus transStatus = mAidlBase->release(); return GetC2Status(transStatus, "release"); } Loading
media/codec2/hal/client/include/codec2/aidl/GraphicBufferAllocator.h +5 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,11 @@ public: const ::android::IGraphicBufferProducer::QueueBufferInput& input, ::android::IGraphicBufferProducer::QueueBufferOutput *output); /** * Notify stop()/release() is in progress. */ void onRequestStop(); ~GraphicBufferAllocator(); /** Loading
media/codec2/hal/client/include/codec2/aidl/GraphicsTracker.h +17 −1 Original line number Diff line number Diff line Loading @@ -175,6 +175,14 @@ public: */ void stop(); /** * stop()/release() request to HAL is in process from the client. * The class will never be active again after the request. * Still, allocation requests from HAL should be served until stop() * is being called. */ void onRequestStop(); private: struct BufferCache; Loading Loading @@ -290,6 +298,10 @@ private: std::atomic<bool> mStopped; bool mStopRequested; std::atomic<int> mAllocAfterStopRequested; private: explicit GraphicsTracker(int maxDequeueCount); Loading @@ -304,7 +316,7 @@ private: const std::shared_ptr<BufferCache> &cache, int maxDequeueCommitted); c2_status_t requestAllocate(std::shared_ptr<BufferCache> *cache); c2_status_t requestAllocateLocked(std::shared_ptr<BufferCache> *cache); c2_status_t requestDeallocate(uint64_t bid, const sp<Fence> &fence, bool *completed, bool *updateDequeue, std::shared_ptr<BufferCache> *cache, int *slotId, Loading Loading @@ -334,6 +346,10 @@ private: bool *cached, int *rSlotId, sp<Fence> *rFence, std::shared_ptr<BufferItem> *buffer); c2_status_t _allocateDirect( uint32_t width, uint32_t height, PixelFormat format, uint64_t usage, AHardwareBuffer **buf, sp<Fence> *fence); void writeIncDequeueableLocked(int inc); void drainDequeueableLocked(int dec); }; Loading