版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/TaylorPotter/article/details/105707181
记录下 Mtk的Hal3架构笔记,正在进行学习,后续仍会更新
mtk online里搜Camera 可以搜到很全面的Mtk Hal3的学习文档,Mtk整理的文档很棒,简单到位!
https://online.mediatek.com/QuickStart/2a17666a-9d46-4686-9222-610ec0f087cc
下述的代码结构只是列出了mtk平台的camera路径,Android Camera相关路径并未记录
APP
MTK Camera
vendor/mediatek/proprietary/packages/apps/
HAL
MTK Camera Hal,目前最新Android Camera Api2下用的都是HAL3的内存,HAL3主要代码在mtkcam3中,有些工具类复用了mtkcam中
vendor/mediatek/proprietary/hardware/mtkcam/
vendor/mediatek/proprietary/hardware/mtkcam3/
以下是和camera强相关
vendor/mediatek/proprietary/hardware/jpeg/
vendor/mediatek/proprietary/hardware/bwc/
vendor/mediatek/proprietary/hardware/m4u/
Kernel
kernel-x.xx/drivers/misc/mediatek/imgsensor/
MtkCam3实现了Android定义的几个HAL3的接口:ICameraProvider, ICameraDevice, ICameraDeviceSession, ICameraDeviceCallback;ICameraProvider 的实现类CameraProviderImpl包在 camera device manager 外围,只是一个 adapter, 适配不同版本的 camera device interface。 Camera Service(指的是camera android层的进程: cameraserver ) 可以通过 ICameraProvider 去拿到 ICameraDevice 。ICameraDevice 和 ICameraDeviceSession 的实现类 CameraDevice3Impl, CameraDevice3SessionImpl 。用于Camera Service 去操作每一个 camera。 比如: open, close, configureStreams, processCaptureRequest 。
AppStreamManager位于framework与pipeline之间,主要职责有如下三条:
1、 Callback result to Android framework according to the returning rules which are defined in camera3.h
2、Update vendor defined gralloc usage
3、Android/ MTK streamInfo conversion
IPipelineModel的角色
在open/close stage,Power on/off sensor;在config stage,根据APP的createCaptureSession里面带下来的surface list,推测Output以及按照Topological推测Pipeline各个Node是否需要创建以及各个Node的I/O buffer,建立整条PipelineModel;在Request Stage,接到上层queue下来的request,转化为Pipleline统一的IPipelineFrame,决定这个request的I/O buffer、Topological、sub frame、dummy frame、feature set等信息;
HWNode是大Node,三方算法的挂载在这些node里面,作为小node.
P1Node负责输出raw图,P2CaptureNode主要负责拍照的frame的处理,P2StreamingNode主要负责录像预览的数据处理,JpegNode的输入时main YUV、Thumbnail YUV及metadata,输出是Jpeg及App metadata。
1.Mtk日志开关
设置log level,cameraHalserver重启生效
persist.vendor.mtk.camera.log_level
控制代码如下:
#define CAM_ULOGMD(fmt, arg...) ALOGD(fmt, ##arg)
mtkcam/include/mtkcam/utils/std/Log.h
#define CAM_LOGD(fmt, arg...) do{ if(0!=mtkcam_testLog(LOG_TAG, 'D')) ALOGD(fmt, ##arg); } while(0)
mtkcam/utils/std/Misc.cpp
static int32_t determinePersistLogLevel()
{
int32_t level = ::property_get_int32("persist.vendor.mtk.camera.log_level", -1);
CAM_ULOGMD("###### get camera log property =%d", level);
if (-1 == level) {
level = MTKCAM_LOG_LEVEL_DEFAULT;
}
return level;
}
__BEGIN_DECLS
static int32_t gLogLevel = determinePersistLogLevel();
int mtkcam_testLog(char const* /*tag*/, int prio)
{
switch (prio)
{
case 'V': return (gLogLevel>=4);
case 'D': return (gLogLevel>=3);
case 'I': return (gLogLevel>=2);
case 'W': return (gLogLevel>=1);
case 'E': return (1);
default: break;
}
return 0;
}