mtk camera configureStreams 流程

和你一起终身学习,这里是程序员 Android

经典好文推荐,通过阅读本文,您将收获以下知识点:

一、camera configureStreams 流程
二、Log 分析

一、camera configureStreams 流程

1.1 相机api简述

as we all know Android Camera API的 步骤

(1)、监听和枚举相机设备

get_number_of_cameras、get_camera_characteristic

(2)、打开设备并连接监听器

connect、open

(3)、配置目标使用情形的输出(如static 、capture、video等)

 configure_stream

(4)、为目标使用情形创建请求  (5)捕获/重复请求和连拍

process_capture_request

(6) 、接受结果metadata和图片数据

proces_capture_result

(7)、切换使用情形时,返回第三步
1.2 原文阅读

The framework calls camera3_device_t->ops->configure_streams() with a list * of input/output streams to the HAL device.

简单翻译-->

framework调用结构体camera_device方法ops调用结构体camera3_device_ops的configure_streams方法配流,camera3_device_t-> ops-> configure_streams(),并把input stream&output stream 的列表作为参数送到Hal层。

1.3 结构体

hardware/libhardware/include/hardware/camera3.h

camera3_device_ops_t 映射函数指针操作: hardware/libhardware/modules/camera/3_0/Camera.cpp

1.4 代码流程

hardware/interfaces/camera/device/3.2/default/CameraDeviceSession.cpp

Return CameraDeviceSession::configureStreams(
        const StreamConfiguration& requestedConfiguration,
        ICameraDeviceSession::configureStreams_cb _hidl_cb)  {
    Status status = initStatus();
    HalStreamConfiguration outStreams;

    ATRACE_BEGIN("camera3->configure_streams");
    status_t ret = mDevice->ops->configure_streams(mDevice, &stream_list);
    ATRACE_END();
}

frameworks/av/services/camera/libcameraservice/device3/Camera3Device.cpp

status_t Camera3Device::configureStreamsLocked(int operatingMode,
        const CameraMetadata& sessionParams, bool notifyRequestThread) {
   

    //配流开始log
    ALOGV("%s: Camera %s: Starting stream configuration", __FUNCTION__, mId.string());

  略...

    //创建buffer

    const camera_metadata_t *sessionBuffer = sessionParams.getAndLock();
    res = mInterface->configureStreams(sessionBuffer, &config, bufferSizes);

   //这里还有重新配流的代码,省略

  // Update device state
    const camera_metadata_t *newSessionParams = sessionParams.getAndLock();
       省略部分代码

    ALOGV("%s: Camera %s: Stream configuration complete", __FUNCTION__, mId.string());

    // tear down the deleted streams after configure streams.
    mDeletedStreams.clear();

    return OK;
}

status_t Camera3Device::HalInterface::configureStreams(const camera_metadata_t *sessionParams,
        camera3_stream_configuration *config, const std::vector& bufferSizes) {
    ATRACE_NAME("CameraHal::configureStreams");
 略...
        auto err = mHidlSession_3_4->configureStreams_3_4(
                requestedConfiguration3_4, configStream34Cb);
   略...

    return res;
}

vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/device/CameraDevice3SessionImpl.cpp

//V3_4
Return
ThisNamespace::
configureStreams_3_3(const V3_2::StreamConfiguration& requestedConfiguration, configureStreams_3_3_cb _hidl_cb)
{ 省略部分代码
            err = onConfigureStreamsLocked(requestedConfiguration, halStreamConfiguration);

}

vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/device/CameraDevice3SessionImpl.cpp

auto
ThisNamespace::
onConfigureStreamsLocked(
    const WrappedStreamConfiguration& requestedConfiguration,
    WrappedHalStreamConfiguration& halConfiguration
) -> ::android::status_t
{  
    IAppStreamManager::ConfigAppStreams appStreams;
    auto pAppStreamManager = getSafeAppStreamManager();

    err = pAppStreamManager->beginConfigureStreams(requestedConfiguration, halConfiguration, appStreams);
        auto pPipelineModel = getSafePipelineModel();      
        err = pPipelineModel->configure(pParams);   //配置pipeline
    err = pAppStreamManager->endConfigureStreams(halConfiguration);
}

vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/app/AppStreamMgr.cpp

auto
AppStreamMgr::
beginConfigureStreams(
    const V3_5::StreamConfiguration& requestedConfiguration,
    V3_4::HalStreamConfiguration& halConfiguration,
    ConfigAppStreams& rStreams
)   -> int
{
    auto err = mConfigHandler->beginConfigureStreams(requestedConfiguration, halConfiguration, rStreams);
}

vendor/mediatek/proprietary/hardware/mtkcam/main/hal/device/3.x/app/AppStreamMgr.ConfigHandler.cpp

简述下这里面干了些啥事

1 .检测stream
2 .设置OperationMode
3.生成MetaStreamInfo,并把前者加到Stream中

auto
ThisNamespace::
beginConfigureStreams(
    const V3_5::StreamConfiguration& requestedConfiguration,
    V3_4::HalStreamConfiguration& halConfiguration,
    ConfigAppStreams& rStreams
)   -> int
{   
                rStreams.vMinFrameDuration.add(  //这块为上层下发的流配置格式
                    pStreamInfo->getStreamId(),
                    mEntryMinDuration.itemAt(j + 3, Type2Type())
                );
                rStreams.vStallFrameDuration.add(  //这块为上层下发的流配置格式
                    pStreamInfo->getStreamId(),
                    mEntryStallDuration.itemAt(j + 3, Type2Type())
                );
                MY_LOGI("[addFrameDuration] format:%" PRId64 " size:%" PRId64 "x%" PRId64 " min_duration:%" PRId64 ", stall_duration:%" PRId64 ,
                    mEntryMinDuration.itemAt(j, Type2Type()),
                    mEntryMinDuration.itemAt(j + 1, Type2Type()),
                    mEntryMinDuration.itemAt(j + 2, Type2Type()),
                    mEntryMinDuration.itemAt(j + 3, Type2Type()),
                    mEntryStallDuration.itemAt(j + 3, Type2Type()));
                break;
  
    mFrameHandler->setOperationMode((uint32_t)requestedConfiguration.v3_4.operationMode);
        std::string const streamName = "Meta:App:Control";
        auto pStreamInfo = createMetaStreamInfo(streamName.c_str(), streamId);
        mFrameHandler->addConfigStream(pStreamInfo);

        rStreams.vMetaStreams.add(streamId, pStreamInfo);
    }
        sp pStreamInfo = mFrameHandler->getConfigImageStream(streamId);
            mFrameHandler->addConfigStream(pStreamInfo.get(), false/*keepBufferCache*/);
     
                //physical settings
                String8 const streamName = String8::format("Meta:App:Physical_%s", ((std::string)srcStream.physicalCameraId).c_str());
                StreamId_T const streamId = eSTREAMID_BEGIN_OF_PHYSIC_ID + (int64_t)pcId;
                auto pMetaStreamInfo = createMetaStreamInfo(streamName.c_str(), streamId, pcId);
                mFrameHandler->addConfigStream(pMetaStreamInfo);
                rStreams.vMetaStreams_physical.add(pcId, pMetaStreamInfo);
            }
        }
}

vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/app/AppStreamMgr.FrameHandler.cpp

这块有一些具体的函数就不继续罗列了

图略

2、log分析

08-26 11:30:38.599694  4145  4164 D mtkcam-dev3: [0-session::onConfigureStreamsLocked] +
08-26 11:30:38.662202  4145  4164 D mtkcam-dev3: [0-session::onConfigureStreamsLocked] -


08-26 11:30:38.602389  4145  4164 D mtkcam-AppStreamMgr: [beginConfigureStreams] StreamConfiguration=

{.v3_4 = {.streams = [3]{

{.v3_2 ={.id = 0, .streamType = OUTPUT, .width = 1920, .height = 1080, .format = IMPLEMENTATION_DEFINED,

.usage = CPU_READ_NEVER | CPU_WRITE_NEVER | GPU_TEXTURE (0x100),

.dataSpace = UNKNOWN | STANDARD_UNSPECIFIED | TRANSFER_UNSPECIFIED | RANGE_UNSPECIFIED (0), .rotation = ROTATION_0}, .physicalCameraId = "", .bufferSize = 0},

{.v3_2 = {.id = 1, .streamType = OUTPUT, .width = 4096, .height = 2304, .format = BLOB,

.usage = CPU_READ_NEVER | CPU_READ_RARELY | CPU_READ_OFTEN | CPU_WRITE_NEVER (0x3),

.dataSpace = UNKNOWN | STANDARD_UNSPECIFIED | STANDARD_BT601_625 | TRANSFER_UNSPECIFIED | TRANSFER_LINEAR | TRANSFER_SRGB | TRANSFER_SMPTE_170M | RANGE_UNSPECIFIED | RANGE_FULL | V0_JFIF (0x8c20000),

.rotation = ROTATION_0}, .physicalCameraId = "", .bufferSize = 14227317},

{.v3_2 = {.id = 2, .streamType = OUTPUT, .width = 176, .height = 144, .format = YCBCR_420_888,

.usage = CPU_READ_NEVER | CPU_READ_RARELY | CPU_READ_OFTEN | CPU_WRITE_NEVER (0x3),
(mva=0x0/sec=0/prot=0/alpha=1:0xff/blend=0002/dim=0/fmt=4868/range=1(20000000)/x=0 y=65 w=1080 h=1 s=1088,66 -> x=0 y=0 w=1080 h=1/layer_type=0 ext_layer=-1 ds=0 fbdc=0) !


08-26 11:30:38.602796  4145  4164 W mtkcam-AppStreamMgr: [0-ConfigHandler::checkStream] framework stream dataspace:0x08c20000(V0_JFIF|STANDARD_BT601_625|TRANSFER_SMPTE_170M|RANGE_FULL)

{.v3_2 = {.id = 1, .streamType = OUTPUT, .width = 4096, .height = 2304, .format = BLOB,

.usage = CPU_READ_NEVER | CPU_READ_RARELY | CPU_READ_OFTEN | CPU_WRITE_NEVER (0x3),

.dataSpace = UNKNOWN | STANDARD_UNSPECIFIED | STANDARD_BT601_625 | TRANSFER_UNSPECIFIED | TRANSFER_LINEAR | TRANSFER_SRGB | TRANSFER_SMPTE_170M | RANGE_UNSPECIFIED | RANGE_FULL | V0_JFIF (0x8c20000),

.rotation = ROTATION_0}, .physicalCameraId = "", .bufferSize = 14227317}


08-26 11:30:38.602905  4145  4164 W mtkcam-AppStreamMgr: [0-ConfigHandler::checkStream] framework stream dataspace:0x08c20000(V0_JFIF|STANDARD_BT601_625|TRANSFER_SMPTE_170M|RANGE_FULL)

{.v3_2 = {.id = 2, .streamType = OUTPUT, .width = 176, .height = 144, .format = YCBCR_420_888,

.usage = CPU_READ_NEVER | CPU_READ_RARELY | CPU_READ_OFTEN | CPU_WRITE_NEVER (0x3),

.dataSpace = UNKNOWN | STANDARD_UNSPECIFIED | STANDARD_BT601_625 | TRANSFER_UNSPECIFIED | TRANSFER_LINEAR | TRANSFER_SRGB | TRANSFER_SMPTE_170M | RANGE_UNSPECIFIED | RANGE_FULL | V0_JFIF (0x8c20000),

.rotation = ROTATION_0}, .physicalCameraId = "", .bufferSize = 0}


08-26 11:30:38.603083  4145  4164 I mtkcam-AppStreamMgr: [0-FrameHandler::setOperationMode] operationMode change: 0xffffffff -> 0

08-26 11:30:38.608006  4145  4164 I mtkcam-AppStreamMgr: [0-ConfigHandler::operator()] [addFrameDuration] format:34 size:1920x1080 min_duration:33333333, stall_duration:0
08-26 11:30:38.608019  4145  4164 D mtkcam-AppStreamMgr: [0-ConfigHandler::beginConfigureStreams] Stream: id:0 streamType:0 1920x1080 format:0x22 usage:0x100 dataSpace:0x0 rotation:0
08-26 11:30:38.608033  4145  4164 D mtkcam-AppStreamMgr: [0-ConfigHandler::createImageStreamInfo] isSecureCameraDevice=0 usageForHal=0x0x20033 usageForHalClient=0x0x3
08-26 11:30:38.608047  4145  4164 D mtkcam-AppStreamMgr: [0-ConfigHandler::createImageStreamInfo] grallocRequest.format=33, grallocRequest.usage = 0x20033 
08-26 11:30:38.608058  4145  4164 I mtkcam-AppStreamMgr: [0-ConfigHandler::createImageStreamInfo] BLOB with widthInPixels(14227317), heightInPixels(1), bufferSize(14227317)
08-26 11:30:38.609436  4145  4164 I mtkcam-AppStreamMgr: stream id len : 0
08-26 11:30:38.609452  4145  4164 D mtkcam-AppStreamMgr: [0-ConfigHandler::createImageStreamInfo] rStream.v_32.usage(0x3) 
08-26 11:30:38.609452  4145  4164 D mtkcam-AppStreamMgr:      rStream-Info(sid=0x1, format=0x21, usage=0x3, StreamType::OUTPUT=0x0, streamType=0x0) 
08-26 11:30:38.609452  4145  4164 D mtkcam-AppStreamMgr:      grallocStaticInfo(format=0x21) 
08-26 11:30:38.609452  4145  4164 D mtkcam-AppStreamMgr:      HalStream-info(producerUsage= 0x20033,  consumerUsage= 0, overrideFormat=0x21 ) 
08-26 11:30:38.609452  4145  4164 D mtkcam-AppStreamMgr:      Blob-info(imgFmt=0x2300, allocImgFmt=0x21, allocBufPlanes(size=1, sizeInBytes=14227317, rowStrideInBytes=14227317) 
08-26 11:30:38.609452  4145  4164 D mtkcam-AppStreamMgr:      Misc-info(usageForAllocator=0x20033, NSCam::BufferUsage::PROT_CAMERA_BIDIRECTIONAL=0x64000) NSCam::BufferUsage::E2E_HDR=0x50030000)
08-26 11:30:38.609452  4145  4164 D mtkcam-AppStreamMgr:      creationInfo(secureInfo=0x0)
08-26 11:30:38.609494  4145  4164 I mtkcam-AppStreamMgr: [0-ConfigHandler::operator()] [addFrameDuration] format:33 size:4096x2304 min_duration:66666666, stall_duration:33333333
08-26 11:30:38.609508  4145  4164 D mtkcam-AppStreamMgr: [0-ConfigHandler::beginConfigureStreams] Stream: id:1 streamType:0 4096x2304 format:0x21 usage:0x3 dataSpace:0x8c20000 rotation:0
08-26 11:30:38.609524  4145  4164 D mtkcam-AppStreamMgr: [0-ConfigHandler::createImageStreamInfo] isSecureCameraDevice=0 usageForHal=0x0x20033 usageForHalClient=0x0x3
08-26 11:30:38.609539  4145  4164 D mtkcam-AppStreamMgr: [0-ConfigHandler::createImageStreamInfo] grallocRequest.format=35, grallocRequest.usage = 0x20033 
08-26 11:30:38.610509  4145  4164 I mtkcam-AppStreamMgr: [0-ConfigHandler::operator()] [addFrameDuration] format:35 size:176x144 min_duration:33333333, stall_duration:0
08-26 11:30:38.610527  4145  4164 D mtkcam-AppStreamMgr: [0-ConfigHandler::beginConfigureStreams] Stream: id:2 streamType:0 176x144 format:0x23 usage:0x3 dataSpace:0x8c20000 rotation:0
08-26 11:30:38.610540  4145  4164 D mtkcam-AppStreamMgr: [0-ConfigHandler::beginConfigureStreams] operationmode 0 videoWidth is 4096 videoWidth1 is 1920
08-26 11:30:38.610608  4145  4164 D mtkcam-dev3: [0-session::onConfigureStreamsLocked] pParams.vPhysicCameras(0)
08-26 11:30:38.610618  4145  4164 D mtkcam-dev3: [0-session::onConfigureStreamsLocked] pImageStreamBufferProvider 0x0

08-26 11:30:38.662202  4145  4164 D mtkcam-dev3: [0-session::onConfigureStreamsLocked] -
08-26 11:30:38.662271  4145  4164 I mtkcam-dev3: [0-session::tryRunCommandLocked] Run command onConfigureStreamsLocked -

这块是设置上层下发的流的格式。

2.1 config stage log
2.1.1 PipelineModelSessionFactory log
log具体含义,看《MTK_camera_pipeline_framework.pdf》

02-04 11:25:35.639   921   921 D mtkcam-PipelineModelSession-Factory: [convertToUserConfiguration] APP set init frame : 1, if not be zero, force it to be 4
02-04 11:25:35.641   921   921 I mtkcam-PipelineModelSession-Factory: [convertToUserConfiguration] force 3rd flow
02-04 11:25:35.641   921   921 I mtkcam-PipelineModelSession-Factory: [convertToUserConfiguration] dual cam device(s:0,path:1) forceFeatureMode(1) pack jpeg(0) physical(0) s(16) c(1)

02-04 11:25:33.979   921 11876 D mtkcam-PipelineModelSession-Factory: [parseAppStreamInfo] ispTuningDataEnable(0) StreamId(0) ConsumerUsage(2304) size(1440,1080) yuv_isp_tuning_data_size(1280,720) raw_isp_tuning_data_size(2560,1920)
02-04 11:25:33.979   921 11876 D mtkcam-PipelineModelSession-Factory: [parseAppStreamInfo] ispTuningDataEnable(0) StreamId(0x2) ConsumerUsage(3) size(1440,1080) yuv_isp_tuning_data_size(1280,720) raw_isp_tuning_data_size(2560,1920)

02-04 11:25:35.643   921   921 I mtkcam-PipelineModelSession-Factory: [decidePipelineModelSession] Vsdof

StreamId: pStreamInfo->getStreamId()

size(1440,1080) :StreamSize

yuv_isp_tuning_data_size(1280,720) :Tuning data size

raw_isp_tuning_data_size(2560,1920) :Tuning data size

Vsdof : PipelineModelSession类型为 Zoom

原文链接:https://blog.csdn.net/weixin_38328785/article/details/108581219

至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!

你可能感兴趣的:(mtk camera configureStreams 流程)