Loading media/codec2/hal/client/client.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -1719,6 +1719,8 @@ c2_status_t Codec2Client::Component::setOutputSurface( static_cast<uint64_t>(blockPoolId), static_cast<uint64_t>(blockPoolId), bqId == 0 ? nullHgbp : igbp); bqId == 0 ? nullHgbp : igbp); mOutputBufferQueue->expireOldWaiters(); if (!transStatus.isOk()) { if (!transStatus.isOk()) { LOG(ERROR) << "setOutputSurface -- transaction failed."; LOG(ERROR) << "setOutputSurface -- transaction failed."; return C2_TRANSACTION_FAILED; return C2_TRANSACTION_FAILED; Loading Loading @@ -1764,6 +1766,7 @@ void Codec2Client::Component::stopUsingOutputSurface( << status << "."; << status << "."; } } } } mOutputBufferQueue->expireOldWaiters(); } } c2_status_t Codec2Client::Component::connectToInputSurface( c2_status_t Codec2Client::Component::connectToInputSurface( Loading media/codec2/hal/client/include/codec2/hidl/output.h +6 −0 Original line number Original line Diff line number Diff line Loading @@ -51,6 +51,10 @@ struct OutputBufferQueue { int maxDequeueBufferCount, int maxDequeueBufferCount, std::shared_ptr<V1_2::SurfaceSyncObj> *syncObj); std::shared_ptr<V1_2::SurfaceSyncObj> *syncObj); // If there are waiters to allocate from the old surface, wake up and expire // them. void expireOldWaiters(); // Stop using the current output surface. Pending buffer opeations will not // Stop using the current output surface. Pending buffer opeations will not // perform anymore. // perform anymore. void stop(); void stop(); Loading Loading @@ -90,6 +94,8 @@ private: std::weak_ptr<_C2BlockPoolData> mPoolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; std::weak_ptr<_C2BlockPoolData> mPoolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; std::shared_ptr<C2SurfaceSyncMemory> mSyncMem; std::shared_ptr<C2SurfaceSyncMemory> mSyncMem; bool mStopped; bool mStopped; std::mutex mOldMutex; std::shared_ptr<C2SurfaceSyncMemory> mOldMem; bool registerBuffer(const C2ConstGraphicBlock& block); bool registerBuffer(const C2ConstGraphicBlock& block); }; }; Loading media/codec2/hal/client/output.cpp +17 −1 Original line number Original line Diff line number Diff line Loading @@ -217,6 +217,7 @@ bool OutputBufferQueue::configure(const sp<IGraphicBufferProducer>& igbp, sp<GraphicBuffer> buffers[BufferQueueDefs::NUM_BUFFER_SLOTS]; sp<GraphicBuffer> buffers[BufferQueueDefs::NUM_BUFFER_SLOTS]; std::weak_ptr<_C2BlockPoolData> std::weak_ptr<_C2BlockPoolData> poolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; poolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; std::shared_ptr<C2SurfaceSyncMemory> oldMem; { { std::scoped_lock<std::mutex> l(mMutex); std::scoped_lock<std::mutex> l(mMutex); bool stopped = mStopped; bool stopped = mStopped; Loading @@ -238,7 +239,7 @@ bool OutputBufferQueue::configure(const sp<IGraphicBufferProducer>& igbp, } } return false; return false; } } std::shared_ptr<C2SurfaceSyncMemory> oldMem = mSyncMem; oldMem = mSyncMem; C2SyncVariables *oldSync = mSyncMem ? mSyncMem->mem() : nullptr; C2SyncVariables *oldSync = mSyncMem ? mSyncMem->mem() : nullptr; if (oldSync) { if (oldSync) { oldSync->lock(); oldSync->lock(); Loading Loading @@ -314,11 +315,26 @@ bool OutputBufferQueue::configure(const sp<IGraphicBufferProducer>& igbp, newSync->unlock(); newSync->unlock(); } } } } { std::scoped_lock<std::mutex> l(mOldMutex); mOldMem = oldMem; } ALOGD("remote graphic buffer migration %zu/%zu", ALOGD("remote graphic buffer migration %zu/%zu", success, tryNum); success, tryNum); return true; return true; } } void OutputBufferQueue::expireOldWaiters() { std::scoped_lock<std::mutex> l(mOldMutex); if (mOldMem) { C2SyncVariables *oldSync = mOldMem->mem(); if (oldSync) { oldSync->notifyAll(); } mOldMem.reset(); } } void OutputBufferQueue::stop() { void OutputBufferQueue::stop() { std::scoped_lock<std::mutex> l(mMutex); std::scoped_lock<std::mutex> l(mMutex); mStopped = true; mStopped = true; Loading media/codec2/vndk/include/C2SurfaceSyncObj.h +5 −0 Original line number Original line Diff line number Diff line Loading @@ -112,6 +112,11 @@ struct C2SyncVariables { */ */ c2_status_t waitForChange(uint32_t waitId, c2_nsecs_t timeoutNs); c2_status_t waitForChange(uint32_t waitId, c2_nsecs_t timeoutNs); /** * Wake up and expire all waitors. */ void notifyAll(); C2SyncVariables() {} C2SyncVariables() {} private: private: Loading media/codec2/vndk/platform/C2SurfaceSyncObj.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -278,6 +278,12 @@ c2_status_t C2SyncVariables::waitForChange(uint32_t waitId, c2_nsecs_t timeoutNs return C2_BAD_VALUE; return C2_BAD_VALUE; } } void C2SyncVariables::notifyAll() { this->lock(); this->broadcast(); this->unlock(); } int C2SyncVariables::signal() { int C2SyncVariables::signal() { mCond++; mCond++; Loading Loading
media/codec2/hal/client/client.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -1719,6 +1719,8 @@ c2_status_t Codec2Client::Component::setOutputSurface( static_cast<uint64_t>(blockPoolId), static_cast<uint64_t>(blockPoolId), bqId == 0 ? nullHgbp : igbp); bqId == 0 ? nullHgbp : igbp); mOutputBufferQueue->expireOldWaiters(); if (!transStatus.isOk()) { if (!transStatus.isOk()) { LOG(ERROR) << "setOutputSurface -- transaction failed."; LOG(ERROR) << "setOutputSurface -- transaction failed."; return C2_TRANSACTION_FAILED; return C2_TRANSACTION_FAILED; Loading Loading @@ -1764,6 +1766,7 @@ void Codec2Client::Component::stopUsingOutputSurface( << status << "."; << status << "."; } } } } mOutputBufferQueue->expireOldWaiters(); } } c2_status_t Codec2Client::Component::connectToInputSurface( c2_status_t Codec2Client::Component::connectToInputSurface( Loading
media/codec2/hal/client/include/codec2/hidl/output.h +6 −0 Original line number Original line Diff line number Diff line Loading @@ -51,6 +51,10 @@ struct OutputBufferQueue { int maxDequeueBufferCount, int maxDequeueBufferCount, std::shared_ptr<V1_2::SurfaceSyncObj> *syncObj); std::shared_ptr<V1_2::SurfaceSyncObj> *syncObj); // If there are waiters to allocate from the old surface, wake up and expire // them. void expireOldWaiters(); // Stop using the current output surface. Pending buffer opeations will not // Stop using the current output surface. Pending buffer opeations will not // perform anymore. // perform anymore. void stop(); void stop(); Loading Loading @@ -90,6 +94,8 @@ private: std::weak_ptr<_C2BlockPoolData> mPoolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; std::weak_ptr<_C2BlockPoolData> mPoolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; std::shared_ptr<C2SurfaceSyncMemory> mSyncMem; std::shared_ptr<C2SurfaceSyncMemory> mSyncMem; bool mStopped; bool mStopped; std::mutex mOldMutex; std::shared_ptr<C2SurfaceSyncMemory> mOldMem; bool registerBuffer(const C2ConstGraphicBlock& block); bool registerBuffer(const C2ConstGraphicBlock& block); }; }; Loading
media/codec2/hal/client/output.cpp +17 −1 Original line number Original line Diff line number Diff line Loading @@ -217,6 +217,7 @@ bool OutputBufferQueue::configure(const sp<IGraphicBufferProducer>& igbp, sp<GraphicBuffer> buffers[BufferQueueDefs::NUM_BUFFER_SLOTS]; sp<GraphicBuffer> buffers[BufferQueueDefs::NUM_BUFFER_SLOTS]; std::weak_ptr<_C2BlockPoolData> std::weak_ptr<_C2BlockPoolData> poolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; poolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; std::shared_ptr<C2SurfaceSyncMemory> oldMem; { { std::scoped_lock<std::mutex> l(mMutex); std::scoped_lock<std::mutex> l(mMutex); bool stopped = mStopped; bool stopped = mStopped; Loading @@ -238,7 +239,7 @@ bool OutputBufferQueue::configure(const sp<IGraphicBufferProducer>& igbp, } } return false; return false; } } std::shared_ptr<C2SurfaceSyncMemory> oldMem = mSyncMem; oldMem = mSyncMem; C2SyncVariables *oldSync = mSyncMem ? mSyncMem->mem() : nullptr; C2SyncVariables *oldSync = mSyncMem ? mSyncMem->mem() : nullptr; if (oldSync) { if (oldSync) { oldSync->lock(); oldSync->lock(); Loading Loading @@ -314,11 +315,26 @@ bool OutputBufferQueue::configure(const sp<IGraphicBufferProducer>& igbp, newSync->unlock(); newSync->unlock(); } } } } { std::scoped_lock<std::mutex> l(mOldMutex); mOldMem = oldMem; } ALOGD("remote graphic buffer migration %zu/%zu", ALOGD("remote graphic buffer migration %zu/%zu", success, tryNum); success, tryNum); return true; return true; } } void OutputBufferQueue::expireOldWaiters() { std::scoped_lock<std::mutex> l(mOldMutex); if (mOldMem) { C2SyncVariables *oldSync = mOldMem->mem(); if (oldSync) { oldSync->notifyAll(); } mOldMem.reset(); } } void OutputBufferQueue::stop() { void OutputBufferQueue::stop() { std::scoped_lock<std::mutex> l(mMutex); std::scoped_lock<std::mutex> l(mMutex); mStopped = true; mStopped = true; Loading
media/codec2/vndk/include/C2SurfaceSyncObj.h +5 −0 Original line number Original line Diff line number Diff line Loading @@ -112,6 +112,11 @@ struct C2SyncVariables { */ */ c2_status_t waitForChange(uint32_t waitId, c2_nsecs_t timeoutNs); c2_status_t waitForChange(uint32_t waitId, c2_nsecs_t timeoutNs); /** * Wake up and expire all waitors. */ void notifyAll(); C2SyncVariables() {} C2SyncVariables() {} private: private: Loading
media/codec2/vndk/platform/C2SurfaceSyncObj.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -278,6 +278,12 @@ c2_status_t C2SyncVariables::waitForChange(uint32_t waitId, c2_nsecs_t timeoutNs return C2_BAD_VALUE; return C2_BAD_VALUE; } } void C2SyncVariables::notifyAll() { this->lock(); this->broadcast(); this->unlock(); } int C2SyncVariables::signal() { int C2SyncVariables::signal() { mCond++; mCond++; Loading