MM-Camera架构-ProcessCaptureRequest 流程分析

news2025/1/11 4:20:01

image

文章目录

  • processCaptureRequest\_3\_4
    • 1.1 mDevice
    • 1.2 mDevice->ops->process\_capture\_request
    • 1.3 hardware to vendor
  • mct\_shimlayer\_process\_event
    • 2.1 mct\_shimlayer\_handle\_parm
    • 2.2 mct\_shimlayer\_reg\_buffer

processCaptureRequest_3_4

sdm660的摄像头走camera hal 3.4接口,每个预览帧,都是由camera service发起,通过camera HAL的CameraDeviceSession::processCaptureRequest_3_4接口,通知hal,请求一个预览帧。

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

Return<void> CameraDeviceSession::processCaptureRequest_3_4(
        const hidl_vec<V3_4::CaptureRequest>& requests,
        const hidl_vec<V3_2::BufferCache>& cachesToRemove,
        ICameraDeviceSession::processCaptureRequest_3_4_cb _hidl_cb)  {
    for (size_t i = 0; i < requests.size(); i++, numRequestProcessed++) {
        s = processOneCaptureRequest_3_4(requests[i]);
        }
    ...
}

Status CameraDeviceSession::processOneCaptureRequest_3_4(const V3_4::CaptureRequest& request)  {
    ...
    //@ 1.1 - 1.2
    status_t ret = mDevice->ops->process_capture_request(mDevice, &halRequest);
    ...
}

1.1 mDevice

mDevicecamera_device_t或者camera3_device_t定义。camera1camera3代表的是CAMERA DEVICE API VERSION,camera3canera1完全不一样。这里mDevicecamera3_device_t定义。

camera3_device_t:是 camera HAL 核心结构体之一,是对 venor camera HAL 实现的抽象,APP 通过 Framework对底层Camera设备(物理设备和逻辑虚拟设备)的操作都是通过对 camera3_device_t 实例对象来进行的。
camera3_device_t:主要用来表示Camera设备,其中定义了Camera3_device_ops操作集合,用来实现正常获取图像数据以及控制Camera的功能。

typedef struct camera3_device {
    hw_device_t common;
    camera3_device_ops_t *ops;
    void *priv;
} camera3_device_t;

HAL3的核心接口都是在camera3_device_ops中被定义。
camera3_device_ops结构体定义了一系列的函数指针,用来指向平台厂商实际的实现方法。

typedef struct camera3_device_ops {
    /*
    initialize
    何时被调用:在camera_modul_t中的open方法之后,其他camera3_device_ops方法之前被调用。
    主要作用:将上层实现的回调方法注册到HAL中,并根据需要在该方法中加入自定义的一些初始化操作。
    返回时间:在5ms内返回,最长不能超过10ms。
    */
    int (*initialize)(const struct camera3_device *,
            const camera3_callback_ops_t *callback_ops);

    /*
    configure_streams
    何时被调用:在Initialize方法完成之后,在调用process_capture_request方法之前被调用
    主要作用:重设当前正在运行的Pipeline以及设执行的输入输出流,其中它回见stream_list中的新的数据流替换之前配置的数据流。
    返回时间:500ms内返回,最长不能超过1000ms
    */
    int (*configure_streams)(const struct camera3_device *,
            camera3_stream_configuration_t *stream_list);

    int (*register_stream_buffers)(const struct camera3_device *,
            const camera3_stream_buffer_set_t *buffer_set);

    const camera_metadata_t* (*construct_default_request_settings)(
            const struct camera3_device *,
            int type);

    /*
    process_capture_request
    主要作用:下发单次新的capture request到HAL中,上层必须保证该方法的调用都是在一个线程中完成,而且该方法是异步的,
    其结果是通过HAL调用另一个接口process_capture_result()来返回结果给上层,在使用过程中,通过in-flight机制,保证短时间内下发足够多的requst,从而满足帧率要求。
    */
    int (*process_capture_request)(const struct camera3_device *,
            camera3_capture_request_t *request);

    void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
            vendor_tag_query_ops_t* ops);

    void (*dump)(const struct camera3_device *, int fd);

    int (*flush)(const struct camera3_device *);

    void (*signal_stream_flush)(const struct camera3_device*,
            uint32_t num_streams,
            const camera3_stream_t* const* streams);

    int (*is_reconfiguration_required)(const struct camera3_device*,
            const camera_metadata_t* old_session_params,
            const camera_metadata_t* new_session_params);

    /* reserved for future use */
    void *reserved[6];
} camera3_device_ops_t;

1.2 mDevice->ops->process_capture_request

继续mDevice->ops->process_capture_request
hardware/qcom/camera/QCamera2/HAL3/QCamera3HWI.h中camera3_device_ops_t定义了mCameraOps:

static camera3_device_ops_t mCameraOps;

camera3_device_ops_t QCamera3HardwareInterface::mCameraOps = {
    .initialize                         = QCamera3HardwareInterface::initialize,
    .configure_streams                  = QCamera3HardwareInterface::configure_streams,
    .register_stream_buffers            = NULL,
    .construct_default_request_settings = QCamera3HardwareInterface::construct_default_request_settings,
    .process_capture_request            = QCamera3HardwareInterface::process_capture_request,
    .get_metadata_vendor_tag_ops        = NULL,
    .dump                               = QCamera3HardwareInterface::dump,
    .flush                              = QCamera3HardwareInterface::flush,
    .reserved                           = {0},
};

hardware/qcom/camera/QCamera2/HAL3/QCamera3HWI.cpp

int QCamera3HardwareInterface::process_capture_request(
                    const struct camera3_device *device,
                    camera3_capture_request_t *request)
{
    LOGE("sundpmy_ process_capture_request E");
    ...
    QCamera3HardwareInterface *hw =
        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);

    int rc = hw->orchestrateRequest(request);
    LOGE("sundpmy_ process_capture_request X");
    return rc;
}

int32_t QCamera3HardwareInterface::orchestrateRequest(
        camera3_capture_request_t *request)
{
    int32_t ret = NO_ERROR;
    ...
    ret = processCaptureRequest(request, internallyRequestedStreams);
    ...
}

1.3 hardware to vendor

QCamera2Factory构造的时候调用get_num_of_cameras_to_expose,一直到用到mm_camera_load_shim_lib。

 QCamera2Factory::QCamera2Factory()
 {
     mHalDescriptors = NULL;
     mCallbacks = NULL;
     mNumOfCameras = get_num_of_cameras();
     mNumOfCameras_expose = get_num_of_cameras_to_expose();
        get_num_of_cameras_to_expose()---> 
                      get_num_of_cameras()--->
                           mm_camera_load_shim_lib() 
}

mm_camera_load_shim_lib里面dlopen:libmmcamera2_mct_shimlayer.so。dlsym获取入口函数:mct_shimlayer_process_module_init

#define SHIMLAYER_LIB "/system/vendor/lib/libmmcamera2_mct_shimlayer.so"

int32_t mm_camera_load_shim_lib()
{
    const char* error = NULL;
    void *qdaemon_lib = NULL;

    LOGD("E");
    qdaemon_lib = dlopen(SHIMLAYER_LIB, RTLD_NOW);
    if (!qdaemon_lib) {
        error = dlerror();
        LOGE("dlopen failed with error %s", error ? error : "");
        return -1;
    }

    *(void **)&mm_camera_shim_module_init =
            dlsym(qdaemon_lib, "mct_shimlayer_process_module_init");
    if (!mm_camera_shim_module_init) {
        error = dlerror();
        LOGE("dlsym failed with error code %s", error ? error: "");
        dlclose(qdaemon_lib);
        return -1;
    }

    return mm_camera_shim_module_init(&g_cam_ctrl.cam_shim_ops);
}

mct_shimlayer_process_module_init给shim_ops_tbl赋值: @vendor/qcom/proprietary/mm-camera/mm-camera2/media-controller/mct_shim_layer/mct_shim_layer.c

int mct_shimlayer_process_module_init(mm_camera_shim_ops_t
  *shim_ops_tbl)
{
    ...
    shim_ops_tbl->mm_camera_shim_open_session = mct_shimlayer_start_session;
    shim_ops_tbl->mm_camera_shim_close_session = mct_shimlayer_stop_session;
    shim_ops_tbl->mm_camera_shim_send_cmd = mct_shimlayer_process_event;
    ...
}

mm_camera_shim_send_cmd的调用:

int32_t mm_camera_module_send_cmd(cam_shim_packet_t *event)
{
    int32_t rc = -1;
    if(g_cam_ctrl.cam_shim_ops.mm_camera_shim_send_cmd) {
        rc = g_cam_ctrl.cam_shim_ops.mm_camera_shim_send_cmd(event);
    }
    return rc;
}

mm_camera_module_send_cmd是个包装函数:
mm_camera_module_send_cmd被调用的地方比较多,打印log看一下:

D mm-camera: <CPP   >< HIGH> 1485: cpp_hardware_process_frame: [CPP_BUF:] stream_status:0xe7f1608c, iden:0x40002, cur_frame_id:17
E QCamera : <MCI><ERROR> mm_stream_unmap_buf: 2327: sundp_mc func:mm_stream_unmap_buf line:2327 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =2
E QCamera : <MCI><ERROR> mm_stream_map_buf: 2168: sundp_mc func:mm_stream_map_buf line:2168 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =2
E QCamera : <MCI><ERROR> mm_camera_util_s_ctrl: 2111: sundp_mc func:mm_camera_util_s_ctrl line:2111 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =0
D mm-camera: <CPP   >< HIGH> 1485: cpp_hardware_process_frame: [CPP_BUF:] stream_status:0xe7f1608c, iden:0x40002, cur_frame_id:18
E QCamera : <MCI><ERROR> mm_stream_unmap_buf: 2327: sundp_mc func:mm_stream_unmap_buf line:2327 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =2
E QCamera : <MCI><ERROR> mm_stream_map_buf: 2168: sundp_mc func:mm_stream_map_buf line:2168 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =2
E QCamera : <MCI><ERROR> mm_camera_util_s_ctrl: 2111: sundp_mc func:mm_camera_util_s_ctrl line:2111 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =0
D mm-camera: <CPP   >< HIGH> 1485: cpp_hardware_process_frame: [CPP_BUF:] stream_status:0xe7f1608c, iden:0x40002, cur_frame_id:19
E QCamera : <MCI><ERROR> mm_stream_unmap_buf: 2327: sundp_mc func:mm_stream_unmap_buf line:2327 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =2
E QCamera : <MCI><ERROR> mm_stream_map_buf: 2168: sundp_mc func:mm_stream_map_buf line:2168 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =2
E QCamera : <MCI><ERROR> mm_camera_util_s_ctrl: 2111: sundp_mc func:mm_camera_util_s_ctrl line:2111 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =0
D mm-camera: <CPP   >< HIGH> 1485: cpp_hardware_process_frame: [CPP_BUF:] stream_status:0xe7f1608c, iden:0x40002, cur_frame_id:20
E QCamera : <MCI><ERROR> mm_stream_unmap_buf: 2327: sundp_mc func:mm_stream_unmap_buf line:2327 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =2
E QCamera : <MCI><ERROR> mm_stream_map_buf: 2168: sundp_mc func:mm_stream_map_buf line:2168 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =2
E QCamera : <MCI><ERROR> mm_camera_util_s_ctrl: 2111: sundp_mc func:mm_camera_util_s_ctrl line:2111 here
E mm-camera: <SHIM  ><ERROR> 481: mct_shimlayer_process_event: sundp_mct Received event from HAL type =0
D mm-camera: <CPP   >< HIGH> 1485: cpp_hardware_process_frame: [CPP_BUF:] stream_status:0xe7f1608c, iden:0x40002, cur_frame_id:21

以上log,可以看出每一帧,每次captureRequest,mm_camera_module_send_cmd会被调用三次。func:mm_stream_map_buf,func:mm_camera_util_s_ctrl,以及每一帧结束后的func:mm_stream_unmap_buf。


mct_shimlayer_process_event

从cameraservice层到qcom的hal层,到了shimlayer。 vendor/qcom/proprietary/mm-camera/mm-camera2/media-controller/mct_shim_layer/mct_shim_layer.c
从日志看,每次captureRequest,mct_shimlayer_process_event会被调用两次,cmd_type分别是CAM_SHIM_REG_BUF和CAM_SHIM_SET_PARM。

packet->cmd_type----->
typedef enum {
    CAM_SHIM_SET_PARM,   /*v4l2 set parameter*/
    CAM_SHIM_GET_PARM,   /*v4l2 get parameter*/
    CAM_SHIM_REG_BUF,    /*Reg/unreg buffers with back-end*/
    CAM_SHIM_BUNDLE_CMD, /*Bundled command for streams*/
} cam_shim_cmd_type;

int mct_shimlayer_process_event(cam_shim_packet_t *packet)
{
  switch (packet->cmd_type) {
    case CAM_SHIM_SET_PARM:
    case CAM_SHIM_GET_PARM: {
      session_id = packet->session_id;
      parm_event = &packet->cmd_data;
      @2.1
      rc = mct_shimlayer_handle_parm(packet->cmd_type, session_id, parm_event);  
    }
      break;
      
    case CAM_SHIM_REG_BUF: {
      session_id = packet->session_id;
      reg_buf = &packet->reg_buf;
      @2.2
      rc = mct_shimlayer_reg_buffer(session_id, reg_buf);  
    }
      break;
    ......
}

接下来看mct_shimlayer_process_event中的2.1 和 2.2。

2.1 mct_shimlayer_handle_parm

2.2 mct_shimlayer_reg_buffer

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1068065.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

stm32的时钟、中断的配置(针对寄存器),一些基础知识

一、学习参考资料 &#xff08;1&#xff09;正点原子的寄存器源码。 &#xff08;2&#xff09;STM32F103最小系统板开发指南-寄存器版本_V1.1&#xff08;正点&#xff09; &#xff08;3&#xff09;STM32F103最小系统板开发指南-库函数版本_V1.1&#xff08;正点&#xff0…

QChart使用说明

一.使用说明 Qt官网例程&#xff1a;https://doc.qt.io/qt-5/qtcharts-examples.html QChart&#xff1a;用于管理图表中的线、图例和轴的图形表示。可以简单理解为是一个画布。QChartView&#xff1a;视图组件&#xff0c;无法单独进行显示&#xff0c;需要依附其他组件进行…

高德地图开发实战案例:实现信息弹出框的富文本展示效果

marker.content "<p classcardsBg></p>";.cardsBg {width: 246px;height: 426px;background: url(../images/cards.png) no-repeat center center; }其中cards.png为整个弹出模态框的背景图片&#xff0c;做到这一步。仍旧会自带高德地图的样式&#xf…

C指针【嵌入式】

一、到底什么是指针 1.指针变量和普通变量的区别 &#xff08;1&#xff09;首先非常关键的是&#xff0c;指针的实质就是一个变量&#xff0c;它根普通变量没有任何本质区别。指针完整的名字应该叫指针变量&#xff0c;简称为指针。 #include<stdio.h> void main(){//a…

perl语言——length.pl脚本(统计fasta文件序列长度)

Perl脚本——stat.pl&#xff08;统计fasta文件序列长度&#xff09; 相比Perl语言&#xff0c;现在python用的多。但是perl依旧是生信学习的一门课程&#xff0c;还是有人在写&#xff0c;所以你至少要会读。 #!/use/bin/perl #perl解析器$inputFile $ARGV[0]; #输…

ComplexHeatmap热图专栏 | 1.1 基础热图绘制

1 写在前面 最近在作图&#xff0c;一直在寻找《小杜的生信笔记》前期发表的代码。众所周知&#xff0c;小杜的教程基本都是平时自己用到的绘图教程&#xff0c;也是自己一个分享和总结。 自己在后期作图的时候&#xff0c;也会去寻找自己前期的教程作为基础&#xff0c;进行…

吃鸡达人必备!超实用干货激爽分享!

大家好&#xff01;作为一名专业吃鸡行家&#xff0c;今天我将为大家分享一些关于提高游戏战斗力和分享顶级游戏作战干货的秘诀&#xff0c;还有一些方便吃鸡作图、装备皮肤库存展示和查询的技巧&#xff01; 首先&#xff0c;让我们来介绍一些吃鸡作图工具推荐。无论是新手还是…

卷积神经网络的发展历史-VGG

VGG的产生 2014 年&#xff0c;Simonyan和Zisserman提出了VGG系列模型&#xff08;包括VGG-11/VGG-13/VGG-16/VGG-19&#xff09;&#xff0c;并在当年的ImageNet Challenge上作为分类任务第二名、定位&#xff08;Localization&#xff09;任务第一名的基础网络出现。 VGG的…

[数据结构]迷宫问题求解

目录 数据结构——迷宫问题求解&#xff1a;&#xff1a; 1.迷宫问题 2.迷宫最短路径问题 数据结构——迷宫问题求解&#xff1a;&#xff1a; 1.迷宫问题 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #includ…

mysql面试题26:MySQL中什么是MVCC,它的底层原理是什么

该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 面试官:什么是MVCC,它的底层原理是什么? MVCC(Multi-Version Concurrency Control)是一种并发控制机制,用于在数据库中实现并发事务的隔离性和一致性…

互联网Java工程师面试题·Redis 篇·第二弹

目录 16、Redis 集群方案什么情况下会导致整个集群不可用&#xff1f; 17、Redis 支持的 Java 客户端都有哪些&#xff1f;官方推荐用哪个&#xff1f; 18、Jedis 与 Redisson 对比有什么优缺点&#xff1f; 19、Redis 如何设置密码及验证密码&#xff1f; 20、说说 Redis…

卷积神经网络的发展历史-ResNet

ResNet的产生 2015 年&#xff0c;Kaiming He 提出了ResNet&#xff08;拿到了 2016 年 CVPR Best Paper Award&#xff09;&#xff0c;不仅解决了神经网络中的退化问题还在同年的ILSVRC和COCO 竞赛横扫竞争对手&#xff0c;分别拿下分类、定位、检测、分割任务的第一名。 R…

山东省赛二阶段第一部分解题思路

提交攻击者的IP地址 192.168.1.7 这个直接awk过滤一下ip次数&#xff0c;这个ip多得离谱&#xff0c;在日志里面也发现了它的恶意行为&#xff0c;后门&#xff0c;反弹shell 识别攻击者使用的操作系统 Linux 找出攻击者资产收集所使用的平台 shodan 提交攻击者目…

给 Linux0.11 添加网络通信功能 (Day3: 完成 MIT6.S081 最终实验 网卡驱动(1. 安装工具链和依赖))

url: https://pdos.csail.mit.edu/6.S081/2020/labs/net.html 首先看 tools章节&#xff1a;https://pdos.csail.mit.edu/6.S081/2020/tools.html 浏览了一下&#xff0c;就是要我们安装依赖 执行以下命令 sudo apt-get install git build-essential gdb-multiarch qemu-syst…

CentOS Stream9 安装远程桌面服务 Xrdp

1. 安装 XRDP 若服务器本身没有桌面则首先需要安装本地桌面&#xff1a; yum -y groups install "GNOME Desktop" startx配置源&#xff1a; dnf install epel-release安装 xrdp dnf install xrdp 2. 配置 Xrdp Xrdp 配置文件位于 /etc/xrdp 目录中。对于常规 X…

学信息系统项目管理师第4版系列20_风险管理

1. 针对不确定性的应对方法 1.1. 【高23上选58】 1.2. 收集信息 1.2.1. 可以对信息收集和分析工作进行规划&#xff0c;以便发现更多信息&#xff08;如进行研究、争取专家参与或进行市场分析&#xff09;来减少不确定性 1.3. 为多种结果做好准备 1.3.1. 制定可用的解决方…

【b站韩顺平 快速学Java课】Java的JDK8(包括公共JRE8)安装教程 总结

最近开始学Java&#xff0c;如果是程序员的话要使用Java——需要安装JDK。 不同操作系统&#xff08;Win/Linux/Mac&#xff09;——需要安装不同的JDK。 1.JDK安装官网链接&#xff1a; Java Downloads | Oracle 我的电脑是win x64,以下笔记总结就暂且以本人电脑操作系统版本…

Python编程:创建图像浏览器应用程序

介绍&#xff1a; 图像浏览器应用程序是一种非常常见和实用的工具。它们使用户能够轻松地浏览和管理计算机中的图像文件。本文将介绍如何使用Python编程语言和wxPython库创建一个简单的图像浏览器应用程序。我们将学习如何利用Python的os模块进行文件和文件夹操作&#xff0c;以…

2023去水印小程序源码修复版-前端后端内置接口+第三方接口

去水印小程序源码&#xff0c;前端后端&#xff0c;内置接口第三方接口&#xff0c;修复数据库账号密码错误问题&#xff0c;内置接口支持替换第三方接口&#xff0c;看了一下文件挺全的&#xff0c;可以添加流量主代码&#xff0c;搭建需要准备一台服务器&#xff0c;备案域名…

顺序表存储一元多项式,并实现两个多项式相加运算(C++,无序输入)

采用顺序表存储一元多项式&#xff0c;并实现两个多项式相加运算&#xff0c;要求&#xff1a; &#xff08;1&#xff09;创建存储多项式的有序表&#xff08;按无序输入&#xff09;ha和hb&#xff1b; &#xff08;2&#xff09;求ha和hb相加产生多项式hc。 &#xff08;…