lock(mCore->mMutex); if (mCore->mConsumerListener == nullptr) { BQ_LOGE("disconnect: no consumer is connected"); return BAD_VALUE; } mCore->mIsAbandoned = true; mCore->mConsumerListener = nullptr; mCore->mQueue.clear(); mCore->freeAllBuffersLocked(); mCore->mSharedBufferSlot = BufferQueueCore::INVALID_BUFFER_SLOT; mCore->mDequeueCondition.notify_all(); return NO_ERROR; } "> lock(mCore->mMutex); if (mCore->mConsumerListener == nullptr) { BQ_LOGE("disconnect: no consumer is connected"); return BAD_VALUE; } mCore->mIsAbandoned = true; mCore->mConsumerListener = nullptr; mCore->mQueue.clear(); mCore->freeAllBuffersLocked(); mCore->mSharedBufferSlot = BufferQueueCore::INVALID_BUFFER_SLOT; mCore->mDequeueCondition.notify_all(); return NO_ERROR; } "> lock(mCore->mMutex); if (mCore->mConsumerListener == nullptr) { BQ_LOGE("disconnect: no consumer is connected"); return BAD_VALUE; } mCore->mIsAbandoned = true; mCore->mConsumerListener = nullptr; mCore->mQueue.clear(); mCore->freeAllBuffersLocked(); mCore->mSharedBufferSlot = BufferQueueCore::INVALID_BUFFER_SLOT; mCore->mDequeueCondition.notify_all(); return NO_ERROR; } ">
virtual status_t consumerDisconnect() { return disconnect(); }
// disconnect disconnects a consumer from the BufferQueue. All
// buffers will be freed and the BufferQueue is placed in the "abandoned"
// state, causing most interactions with the BufferQueue by the producer to
// fail.
status_t BufferQueueConsumer::disconnect() {
ATRACE_CALL();
BQ_LOGV("disconnect");
std::lock_guard<std::mutex> lock(mCore->mMutex);
if (mCore->mConsumerListener == nullptr) {
BQ_LOGE("disconnect: no consumer is connected");
return BAD_VALUE;
}
mCore->mIsAbandoned = true;
mCore->mConsumerListener = nullptr;
mCore->mQueue.clear();
mCore->freeAllBuffersLocked();
mCore->mSharedBufferSlot = BufferQueueCore::INVALID_BUFFER_SLOT;
mCore->mDequeueCondition.notify_all();
return NO_ERROR;
}
consumerDisconnect()
是 IGraphicBufferConsumer 的接口,在 BufferQueueConsumer 的实现是调用 disconnect()
。mConsumerListener
是 nullptr
表示还未连接。mQueue
,调用 BufferQueueCore::freeAllBuffersLocked() 释放所有 buffer。通知 mDequeueCondition
。