显而易见,Camera3BufferManager Register 的逆操作,就是 StreamSet 的数据结构的解构。
加入知识星球与更多Camera同学交流
– 星球名称:深入浅出Android Camera
– 星球ID: 17296815
status_t Camera3BufferManager::unregisterStream(int streamId, int streamSetId) {
Mutex::Autolock l(mLock);
// 删掉Stream关联的所有Buffer.
StreamSet& currentSet = mStreamSetMap.editValueFor(streamSetId);
BufferList& freeBufs = currentSet.freeBuffers;//取出StreamSet的freeBuffers链表.
BufferCountMap& handOutBufferCounts = currentSet.handoutBufferCountMap;
BufferCountMap& attachedBufferCounts = currentSet.attachedBufferCountMap;//从Set中取出handout,attached的计数Map
InfoMap& infoMap = currentSet.streamInfoMap;
removeBuffersFromBufferListLocked(freeBufs, streamId);//这里是删掉buf的地方.
handOutBufferCounts.removeItem(streamId); // 删掉对应的id
attachedBufferCounts.removeItem(streamId);
infoMap.removeItem(streamId); // 删掉streamid的infoMap
currentSet.maxAllowedBufferCount = 0;
for (size_t i = 0; i < infoMap.size(); i++) {
if (infoMap[i].totalBufferCount > currentSet.maxAllowedBufferCount) {
currentSet.maxAllowedBufferCount = infoMap[i].totalBufferCount;
}
}
mStreamMap.removeItem(streamId); // 删除streamId的mStreamMap
return OK;
}
Camera3BufferManager::unregisterStream 的调用时机
status_t Camera3OutputStream::disconnectLocked() {
status_t res;
// 和native window disconnect
res = native_window_api_disconnect(mConsumer.get(), NATIVE_WINDOW_API_CAMERA);
// 此时,Camera 设备是Idle的,不会再有想Camera3BufferManager的Get Buffer的请求.此时注销掉这个StreamSet是安全的.
if (mUseBufferManager) {
res = mBufferManager->unregisterStream(getId(), getStreamSetId());
mUseBufferManager = false;
}
return OK;
}