Camera3BufferManager::returnBufferForStream
主要是涉及几个count map的管理,将streamId
和GraphicBuffer
组合成BufferEntry
,放到freeBuffers
中,前面我们也遇到过BufferEntry
结构。
加入知识星球与更多Camera同学交流
– 星球名称:深入浅出Android Camera
– 星球ID: 17296815
status_t Camera3BufferManager::returnBufferForStream(int streamId,
int streamSetId, const sp<GraphicBuffer>& buffer, int fenceFd) {
Mutex::Autolock l(mLock);
if (mGrallocVersion < HARDWARE_DEVICE_API_VERSION(1,0)) {
// 取出对应StreamSetId的StreamSet.
StreamSet& streamSet = mStreamSetMap.editValueFor(streamSetId);
if (buffer != 0) {
BufferEntry entry;
entry.add(streamId, GraphicBufferEntry(buffer, fenceFd));
status_t res = addBufferToBufferListLocked(streamSet.freeBuffers, entry);// 把返回的buf再次加回freeBuffers列表.
}
// Update the handed out and attached buffer count for this buffer.
// 把返回的buf放到freeBuffers中.handout描述的给client buffer的个数应该减一.
BufferCountMap& handOutBufferCounts = streamSet.handoutBufferCountMap;
size_t& bufferCount = handOutBufferCounts.editValueFor(streamId);
bufferCount--;
// 由于返回的buf,我们认为是free,给到freebuffers.这个freeBuffers属于全体stream组成的streamSet的.
// 而attachedBufferCount描述的是给stream的count的个数,它包含handout和从client上release的buffer的集合.此// 处也会减一,以作为handout的相应.
size_t& attachedBufferCount = streamSet.attachedBufferCountMap.editValueFor(streamId);
attachedBufferCount--;
} else {
// TODO: implement this.
return BAD_VALUE;
}
return OK;
}
status_t Camera3BufferManager::addBufferToBufferListLocked(BufferList& bufList,
const BufferEntry& buffer) {
bufList.push_back(buffer);
return OK;
}