Camera3BufferManager unregisterStream

显而易见,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;
}

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程