当前位置:网站首页>AOSP ~ Camera - RK HAL3 ( 二 )
AOSP ~ Camera - RK HAL3 ( 二 )
2022-07-22 01:24:00 【南柯好萌】
Hal需要实现的接口就是 libhardware\include\hardware\camera3.h
#ifndef ANDROID_INCLUDE_CAMERA3_H
#define ANDROID_INCLUDE_CAMERA3_H
#include <system/camera_metadata.h>
#include "camera_common.h"
......
/********************************************************************** * * Camera device definition * */
typedef struct camera3_device {
/** * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this * device as implementing version 3.0 of the camera device HAL. * * Performance requirements: * * Camera open (common.module->common.methods->open) should return in 200ms, and must return * in 500ms. * Camera close (common.close) should return in 200ms, and must return in 500ms. * */
hw_device_t common;
camera3_device_ops_t *ops;
void *priv;
} camera3_device_t;
在rk目录中hal\rockchip\camera\AAL是实现上层定义的接口,
hal\rockchip\camera\AAL\Camera3HAL.cpp
static camera3_device_ops hal_dev_ops = {
NAMED_FIELD_INITIALIZER(initialize) hal_dev_initialize,
NAMED_FIELD_INITIALIZER(configure_streams) hal_dev_configure_streams,
NAMED_FIELD_INITIALIZER(register_stream_buffers) nullptr,
NAMED_FIELD_INITIALIZER(construct_default_request_settings) hal_dev_construct_default_request_settings,
NAMED_FIELD_INITIALIZER(process_capture_request) hal_dev_process_capture_request,
NAMED_FIELD_INITIALIZER(get_metadata_vendor_tag_ops) nullptr,
NAMED_FIELD_INITIALIZER(dump) hal_dev_dump,
NAMED_FIELD_INITIALIZER(flush) hal_dev_flush,
NAMED_FIELD_INITIALIZER(reserved) {
0},
};
定义了camera3_device_ops_t交互接口
其实这些接口相较hal1有所减少,但是根据pipeline特性,hal代码实际变得更加复杂。
看一下赋值流程
hardware\rockchip\camera\Camera3HALModule.cpp
这个函数定义camerahal的接口
camera_module_t VISIBILITY_PUBLIC HAL_MODULE_INFO_SYM = {
NAMED_FIELD_INITIALIZER(common) {
……
NAMED_FIELD_INITIALIZER(methods) &hal_module_methods,
……
}
static struct hw_module_methods_t hal_module_methods = {
NAMED_FIELD_INITIALIZER(open) hal_dev_open
};
也就是camerahal模块的open函数是hal_dev_open
static int hal_dev_open(const hw_module_t* module, const char* name,
hw_device_t** device)
{
……
return openCameraHardware(camera_id, module, device);
}
int openCameraHardware(int id, const hw_module_t* module, hw_device_t** device)
{
……
Camera3HAL* halDev = new Camera3HAL(id, module);
if (halDev->init() != NO_ERROR) {
//init的时候会new mRequestThread
……
}
Camera3HAL::Camera3HAL(int cameraId, const hw_module_t* module) :
mCameraId(cameraId),
mCameraHw(nullptr),
mRequestThread(nullptr)
{
……
mDevice.common.tag = HARDWARE_DEVICE_TAG;
mDevice.common.version = info.device_version;
mDevice.common.module = (hw_module_t *)(module);
// hal_dev_close is kept in the module for symmetry with dev_open
// it will be set there
mDevice.common.close = nullptr;
mDevice.ops = &hal_dev_ops;//赋值接口函数定义
mDevice.priv = this;//记住这个私有指针就是Camera3HAL
}
这种是通用做法,将设备(camera3_device)包含在各家厂商实现的类(Camera3HAL)中,设备的私有指针又指向Camera3HAL,这样,设备camera3_device里的函数又可以通过priv调用Camera3HAL中的函数。
这样比较绕,比如
Camera3HAL* camera_priv = (Camera3HAL*)(dev->priv);
static int
hal_dev_initialize(const struct camera3_device * dev,
const camera3_callback_ops_t *callback_ops)
{
……
return camera_priv->initialize(callback_ops);
}
正常来说接口函数就只到这里,继续要看这几个接口函数的实现。
先接着看这个initialize函数的实现把
callback_ops是在Camera3Device::Camera3Device上层就已经初始化好了。
hal_dev_initialize(camera3_device-> camera3_device_ops-> initialize) 实际执行的是Camera3HAL中的initialize函数
int Camera3HAL::initialize(const camera3_callback_ops_t *callback_ops)
{
……
status = mRequestThread->init(callback_ops);
……
}
通过发现几个接口函数都是执行mRequestThread下面的对应函数
函数定义在RequestThread.cpp 关注下对应几个函数做了什么
status_t
RequestThread::init(const camera3_callback_ops_t *callback_ops)
{
……// ItemPool<Camera3Request> mRequestsPool 定义
//看init函数是分配MAX_REQUEST_IN_PROCESS_NUM个Camera3Request
status = mRequestsPool.init(MAX_REQUEST_IN_PROCESS_NUM);
……//new结果处理类,然后注册错误返回
mResultProcessor = new ResultProcessor(this, callback_ops);
mCameraHw->registerErrorCallback(mResultProcessor);
mInitialized = true;
return NO_ERROR;
}
RequestThread::configureStreams(camera3_stream_configuration_t *stream_list)
{
Message msg;
msg.id = MESSAGE_ID_CONFIGURE_STREAMS;
msg.data.streams.list = stream_list;
//只是向mMessageQueue队列发送消息,之后看处理函数
return mMessageQueue.send(&msg, MESSAGE_ID_CONFIGURE_STREAMS);
}
同理constructDefaultRequest,processCaptureRequest也是发送到消息队列
register_stream_buffers,get_metadata_vendor_tag_ops函数因为是3.2的版本,只需要为空即可
对应看看接受消息的处理
mRequestThread 里的mMessageQueue消息处理
mRequestThread 的构造函数,这个线程就跑起来了
RequestThread::messageThreadLoop是循环loop函数,里面接受消息。
switch (msg.id) {
case MESSAGE_ID_CONFIGURE_STREAMS:
status = handleConfigureStreams(msg);
break;
case MESSAGE_ID_CONSTRUCT_DEFAULT_REQUEST:
status = handleConstructDefaultRequest(msg);
break;
case MESSAGE_ID_PROCESS_CAPTURE_REQUEST:
status = handleProcessCaptureRequest(msg);
replyImmediately = (mBlockAction == REQBLK_NONBLOCKING);
break;
case MESSAGE_ID_REQUEST_DONE:
status = handleReturnRequest(msg);
break;
case MESSAGE_ID_FLUSH:
break;
default:
LOGE("ERROR @%s: Unknow message %d", __FUNCTION__, msg.id);
status = BAD_VALUE;
break;
}
这就是上层的接口都是发消息到mRequestThread,然后mRequestThread接收消息处理上层事件,所有调用统一到这里。然后处理这些消息。
边栏推荐
- Move forward in the summary of half a month's talk
- 2022起重机司机(限桥式起重机)考试题库及答案
- Utilisation et cas de regexp pour les déclarations MySQL
- UiPath被独立研究机构评为中国RPA市场领导者称号
- idm下载器是什么软件?最新V6.41版本号Win下载工具
- [multithreading] is there only one way to implement threads or four ways
- Mysql語句的RegExp的用法與案例
- 【Cicadaplayer】Release无法断点调试的问题
- 网络分析---并查集上做差分
- 【HMS core】【FAQ】Account Kit、MDM能力、push Kit典型问题合集6
猜你喜欢
IDM下载器软件激活序列号错误如何解决?
Uds02 read data service according to identifier [serviceid = 0x22]
KVM Virtualization - create - bridge - hard disk - snapshot
[daily question 1] 814. Binary tree pruning
Special analysis of China's third-party payment market in 2022
ONES「新星计划」集训之旅圆满收官|2022届校招生
IO extension control (system.io.abstractions)
2022 low voltage electrician examination simulated 100 questions and simulated examination
2022年低压电工考试模拟100题及模拟考试
堆(优先级队列)
随机推荐
[multithreading] the difference between parallelism and concurrency
2022熔化焊接与热切割操作证考试题库模拟考试平台操作
Install Wamp with Tencent ECs, which shows that MySQL cannot be connected
音量调节堆栈
2022R1快开门式压力容器操作考题及模拟考试
Cluster configuration and verification of MySQL Cluster (4)
Microwave radar sensor module, intelligent perception of human existence, real-time induction interactive control application
2022 melting welding and thermal cutting operation certificate examination question bank simulated examination platform operation
【Cicadaplayer】Release无法断点调试的问题
【HMS Core】【FAQ】运动健康、音频编辑、华为帐号服务 典型问题合集7
[deep learning] Yolo to VOC VOC to Yolo
[idea] common shortcut keys of idea
Sword finger offer special assault edition day 6
LabVIEW cluster cannot contain input and output controls at the same time
classes. Jar: another program is using this file, and the process cannot access it.
Programming example of STM32 state machine -- fully automatic washing machine (Part 1)
KVM Virtualization - create - bridge - hard disk - snapshot
UiPath被独立研究机构评为中国RPA市场领导者称号
cordove 友盟插件 ++推送和统计功能
实操演示:如何用 ONES 制定 Scrum 迭代计划?