[RK3288][Android6.0]CameraHAL流程小结

更新时间:2023-07-25 17:33:40 阅读: 评论:0

[RK3288][Android6.0]CameraHAL流程⼩结Platform: RK3288
OS: Android 6.0
Kernel: 3.10.922015mbc歌谣大祭典
虽然是Android6.0, 但是rockchip⽤的是Camera HAL 1.0的架构,没有更新到3.x.
开机:(MediaServer会调⽤)
transistor
camera_get_number_of_cameras ->        CameraHal_Module.cpp
camera_board_profiles::getInstance ->
createInstance ->
new camera_board_profiles
fopen    //打开/etc/l
XML_ParrCreate
fread
XML_ParBuffer    //解析⽂件
LoadSensor ->
OpenAndRegistALLSensor    //第⼀次会去尝试注册所有l⾥的nsor.
OpenAndRegistOneSensor ->
RegisterSensorDevice    //通过ioctl来执⾏nsor的初始化过程。
ReadDevNameFromXML ->    //如果已经初始化过,那么直接读取/data/camera/l⾥被第⼀次初始化添加进去的nsor.            OpenAndRegistOneSensor //注册只在l中存在的nsor,uvc camera除外。
open    //打开/dev/videox
ioctl    //cmd VIDIOC_QUERYCAP, 获取driver name, front/back, orientation, capabilityies(capture, streming等), version.
v4l_querycap    ->    v4l2-ioctl.c
ops->vidioc_querycap ->
soc_camera_querycap    ->    soc_camera.c
ici->ops->querycap ->
rk29_camera_querycap ->    rk30_camera_oneframe.c
ioctl -> CameraHal_module.cpp    //cmd: VIDIOC_TRY_FMT type:V4L2_BUF_TYPE_VIDEO_CAPTURE
v4l_try_fmt ->    v4l2-ioctl.c
ops->vidioc_try_fmt_vid_cap ->    //type: V4L2_BUF_TYPE_VIDEO_CAPTURE
soc_camera_try_fmt_vid_cap ->    soc_camera.c
soc_camera_try_fmt ->
ici->ops->try_fmt ->
rk_camera_try_fmt ->    rk30_camera_oneframe.c
v4l2_subdev_call -> //args: try_mbus_fmt
generic_nsor_try_fmt    //generic_nsor.c
new rk_cam_total_info    //所有nsor的信息都放在⾥⾯。
new rk_DV_info    //每个分辨率都会new⼀个出来。
ioctl ->    //cmd VIDIOC_ENUM_FRAMEINTERVALS    获取⼀个nsor各个分辨率对应的fps。
ProduceNewXml    //重新⽣成 l
APP打开Camera:
fungus
camera_device_open -> CameraHal_Module.cpp    //提供上层ops,
new android::CameraHal ->    //HAL层和上层的处理都⽤这个类实现了。
commandThreadCommandQ //创建commandCmdQ的message queue.
new IonMemManager    //申请ion内存
new PreviewBufferProvider    //preview buffer
new BufferProvider        //video buffer
new BufferProvider        //Raw buffer
new BufferProvider    //jpeg buffer
new CameraSOCAdapter    //⼀般的isp camera, uvc camera是new CameraUSBAdapter
CameraAdapter    //各种adapter的⽗类。
new DisplayAdapter ->    //new⼀个显⽰相关的adapter
displayThreadCommandQ    //创建名为displayCmdQ的message queue.
displayThreadCommandQ    //创建名为displayCmdQ的message queue.
new DisplayThread    //处理显⽰相关事物。
new AppMsgNotifier ->
encProcessThreadCommandQ //创建名字为pictureEncThreadQ的message queue.
eventThreadCommandQ    //创建名字为eventThreadQ的message queue.
create_vpu_memory_pool_allocator
new CameraAppMsgThread
new EncProcessThread
new CameraAppFaceDetThread
new CameraAppCallbackThread
mCameraAdapter->initialize ->
CameraAdapter::initialize -> CameraAdapter.cpp
cameraCreate ->    //找vpu, jpeg相关的库
open
ioctl    //cmd: VIDIOC_QUERYCAP
ioctl    //cmd: VIDIOC_ENUM_FMT
v4l_enum_fmt ->
ops->vidioc_enum_fmt_vid_cap -> //type: V4L2_BUF_TYPE_VIDEO_CAPTURE
soc_camera_enum_fmt_vid_cap soc_camera.c
mCamDriverPreviewFmt = CameraHal_SupportFmt    //找到hal和kernel都⽀持的preview format.
new AutoFocusThread
initDefaultParameters ->
CameraSOCAdapter::initDefaultParameters -> CameraSocAdapter.cpp    //初始化各个参数,preview size, picture size, zoom等。
ioctl ->  //cmd: VIDIOC_TRY_FMT
new CommandThread ->
CameraHal::commandThread    //loop线程。
设置参数:
CameraHal::tParameters    //参数是char*
tParameters ->    //参数是CameraParameters
commandThreadCommandQ.put    //cmd是 CMD_SET_PARAMETERS
commandThread ->
mCameraAdapter->tParameters
CameraSOCAdapter::tParameters ->
mRefEventNotifier->tPreviewDataCbRes
rhodesiacameraConfig
spread是什么意思
设置显⽰窗⼝:
CameraHal::tPreviewWindow ->
commandThreadCommandQ.put ->    //cmd: CMD_SET_PREVIEW_WINDOW
法硕考研培训
commandThread ->
mDisplayAdapter->tPreviewWindow
Start preview:
CameraHal::startPreview ->
new SensorListener
mSensorListener->initialize ->
SensorListener::initialize ->
new Looper
mLooper->addFd    //listener是nsor_events_listener
new SensorLooperThread ->
threadLoop    ->
mLooper->pollOnce    //循环查询是否有event上报,有就会运⾏nsor_events_listener()获取Orientation。
mSensorListener->tCallbacks    //cb是gnsor_orientation_cb,在handleOrientation()中调⽤,⽽nsor_events_listener()⼜会调⽤前者。
mSensorListener->tCallbacks    //cb是gnsor_orientation_cb,在handleOrientation()中调⽤,⽽nsor_events_listener()⼜会调⽤前者。        mSensorListener->enableSensor  ->
SensorManager::getInstanceForPackage
commandThreadCommandQ.put -> //cmd: CMD_PREVIEW_START
commandThread ->
mEventNotifier->stopReceiveFrame ->
AppMsgNotifier::stopReceiveFrame ->
flushPicture ->
encProcessThreadCommandQ.put -> //cmd: EncProcessThread::CMD_ENCPROCESS_PAUSE
AppMsgNotifier::encProcessThread
pauPreviewCBFrameProcess ->
eventThreadCommandQ.put ->    //cmd: CameraAppMsgThread::CMD_EVENT_PAUSE
AppMsgNotifier::eventThread
stopFaceDection    //同上。
mCameraAdapter->startPreview ->
CameraAdapter::startPreview ->
mPreviewBufProvider->createBuffer ->    //type: PREVIEWBUFFER
mCamBuffer->createPreviewBuffer ->
IonMemManager::createPreviewBuffer ->
createIonBuffer
cameraSetSize ->
ioctl    //cmd: VIDIOC_S_FMT
cameraStart ->
ioctl //cmd:VIDIOC_REQBUFS
ioctl    //cmd: VIDIOC_QUERYBUF
mmap
ioctl    //cmd: VIDIOC_QBUF
cameraStream ->    //on
ioctl    //cmd: VIDIOC_STREAMON
new CameraPreviewThread ->
threadLoop ->
mPreivewCameraAdapter->previewThread    //进⼊preview thread loop
mEventNotifier->startReceiveFrame
mDisplayAdapter->startDisplay ->
DisplayAdapter::startDisplay ->princess of china
displayThreadCommandQ.put ->    //cmd: CMD_DISPLAY_START
displayThread ->
cameraDisplayBufferDestory
cameraDisplayBufferCreate    //准备display buffer放frame,然后thread进⼊休眠等待frame的到来。
ize
ioctl stream on后frame就会从kernel上来,接着调⽤previewthread:
CameraAdapter::previewThread ->
getFrame ->    //获取⼀帧frame
ioctl //cmd:VIDIOC_DQBUF    //过滤掉前⾯FILTER_FRAME_NUMBER 帧。
mRefDisplayAdapter->notifyNewFrame ->
DisplayAdapter::notifyNewFrame ->
displayThreadCommandQ.put ->    //cmd: CMD_DISPLAY_FRAME
DisplayAdapter::displayThread ->
mANativeWindow->dequeue_buffer
mANativeWindow->lock_buffer
mANativeWindow->enqueue_buffer
vot
mFrameProvider->returnFrame
returnFrame ->
adapterReturnFrame //把使⽤好的buffer还给系统。
Stop preview:
Stop preview:
camera_stop_preview ->
gCameraHals[rk_dev->cameraid]->stopPreview ->
CameraHal::stopPreview ->
commandThreadCommandQ.put ->    //cmd: CMD_PREVIEW_STOP
mDisplayAdapter->pauDisplay ->
DisplayAdapter::pauDisplay ->
displayThreadCommandQ.put ->    //cmd: CMD_DISPLAY_PAUSE
DisplayAdapter::displayThread ->
cameraDisplayBufferDestory ->
mANativeWindow->cancel_buffer
mEventNotifier->stopReceiveFrame
mCameraAdapter->stopPreview ->
cameraStream ->    //off
ioctl    //cmd:VIDIOC_STREAMOFF
mCameraPreviewThread->requestExitAndWait    //等待preview thread 退出。
mPreviewBufProvider->freeBuffer
Take picture:(需要先执⾏上⾯的stop preview)
camera_disable_msg_type ->
disableMsgType
camera_enable_msg_type ->
enableMsgType
camera_take_picture ->
gCameraHals[rk_dev->cameraid]->takePicture ->
commandThreadCommandQ.put ->    //cmd: CMD_CONTINUOS_PICTURE
CameraHal::commandThread ->
mDisplayAdapter->pauDisplay ->
displayThreadCommandQ.put-> //cmd:CMD_DISPLAY_PAUSE
cameraDisplayBufferDestory
lectPreferedDrvSize    //选择picture size, 如果和preview 分辨率不⼀样,那需要stop preview再start preview.
mDisplayAdapter->pauDisplay        //参照前⾯
mEventNotifier->stopReceiveFrame    //参照前⾯
mCameraAdapter->stopPreview        //参照上⾯stop preview流程
mCameraAdapter->startPreview    //参照上⾯start preview流程
fillPicturInfo
mEventNotifier->takePicture ->
AppMsgNotifier::takePicture    //设置running state为STA_RECEIVE_PIC_FRAME,等着previewThread去get frame
//previewThread接到frame之后
CameraAdapter::previewThread ->
getFrame    //参照前⾯
mRefEventNotifier->isNeedSendToPicture      //此时条件成⽴
mRefEventNotifier->notifyNewPicFrame ->
AppMsgNotifier::notifyNewPicFrame ->
encProcessThreadCommandQ.put ->    //cmd: EncProcessThread::CMD_ENCPROCESS_SNAPSHOT
captureEncProcessPicture ->
callback_notify_shutter ->    // 如果enable了CAMERA_MSG_SHUTTER的话调⽤此函数。
AppMsgNotifier::callback_notify_shutter ->
callbackThreadCommandQ.put    //cmd: CameraAppCallbackThread::CMD_MSG_SHUTTER
AppMsgNotifier::callbackThread ->
mNotifyCb    //CAMERA_MSG_SHUTTER
copyAndSendCompresdImage ->
callback_compresd_image ->
callbackThreadCommandQ.put ->    //cmd: CameraAppCallbackThread::CMD_MSG_COMPRESSED_IMAGE                                                AppMsgNotifier::callbackThread ->
mDataCb    //CAMERA_MSG_COMPRESSED_IMAGE
mDataCb    //CAMERA_MSG_COMPRESSED_IMAGE
frame->relea
cross是什么意思mFrameProvider->returnFrame
Record video:
CameraAdapter::previewThread ->
getFrame
mRefEventNotifier->notifyNewVideoFrame
eventThreadCommandQ.put ->    //cmd: CameraAppMsgThread::CMD_EVENT_VIDEO_ENCING
AppMsgNotifier::eventThread ->
processVideoCb ->
AppMsgNotifier::processVideoCb ->
callback_video_frame ->
callbackThreadCommandQ.put ->    //cmd: CameraAppCallbackThread::CMD_MSG_VIDEO_FRAME
AppMsgNotifier::callbackThread ->
mDataCbTimestamp
Preview datacallback:
CameraAdapter::previewThread ->
mRefEventNotifier->notifyNewPreviewCbFrame    ->    //前提是设置了callback回调函数
AppMsgNotifier::notifyNewPreviewCbFrame ->
eventThreadCommandQ.put ->    //cmd: CameraAppMsgThread::CMD_EVENT_PREVIEW_DATA_CB
AppMsgNotifier::eventThread ->
processPreviewDataCb ->
AppMsgNotifier::processPreviewDataCb ->    //格式转换在这⾥完成
cameraFormatConvert
callback_preview_frame ->
callbackThreadCommandQ.put    ->    //cmd: CameraAppCallbackThread::CMD_MSG_PREVIEW_FRAME                                    AppMsgNotifier::callbackThread ->
mDataCb    //调⽤上层传递下来的callback.
frame->relea    //relea buffer.
mFrameProvider->returnFrame
参考:

本文发布于:2023-07-25 17:33:40,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/188497.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:设置   转换   创建   查询   是否
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图