Camera3BufferManager returnBufferForStream

Camera3BufferManager::returnBufferForStream

主要是涉及几个count map的管理,将streamIdGraphicBuffer组合成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;
}

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程