camera打开流程(Camera JNI--->HAL)
参考:
http://blog.csdn.net/eternity9255/article/details/52126392
一.Clinet端
.client到service的连接
看看客户端的connect函数有什么? connenct()函数的实现在libcamera_client.so中实现。它的源码在以下路径中:frameworks/av/camera/Camera.cpp
sp<Camera> Camera::connect(int cameraId)
{
LOGV("connect");
sp<Camera> c = new Camera();
const sp<ICameraService>& cs = getCameraService();//获取CameraService实例
if (cs != 0) {
c->mCamera = cs->connect(c, cameraId);
}
if (c->mCamera != 0) {
c->mCamera->asBinder()->linkToDeath(c);
c->mStatus = NO_ERROR;
} else {
c.clear();
}
return c;
}
其中通过const sp<ICameraService>& cs =getCameraService(); 获取CameraService实例,进入getCameraService( )中。
getCameraService( )源码文件如下:frameworks/av/camera/Camera.cpp
// establish binder interface to camera service
const sp<ICameraService>& Camera::getCameraService()
{
Mutex::Autolock _l(mLock);
if (mCameraService.get() == 0) {
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder;
....................
binder->linkToDeath(mDeathNotifier);
mCameraService = interface_cast<ICameraService>(binder);
}
LOGE_IF(mCameraService==0, "no CameraService!?");
return mCameraService;
}
自己的分析
frameworks/av/camera/Camera.cpp
status_t Camera::connectLegacy
sp<Camera> c = new Camera(cameraId);
sp<Camera> c = new Camera(cameraId);
const sp<ICameraService>& cs = CameraBaseT::getCameraService();
sp<IServiceManager> sm = defaultServiceManager(); //获得服务
binder = sm->getService(String16(kCameraServiceName));
binder->linkToDeath(gDeathNotifier);
gCameraService = interface_cast<ICameraService>(binder);
gCameraService 实例通过binder获取的,gCameraService 即为CameraService的实例。
status = cs.get()->connectLegacy(cl, cameraId, halVersion, clientPackageName, clientUid, /*out*/c->mCamera);
IInterface::asBinder(c->mCamera)->linkToDeath(c);//获取CameraService实例
二.service端
service端的实现在库libcameraservice.so中。
回到sp<Camera> Camera::connect(int cameraId)中
c->mCamera = cs->connect(c, cameraId);
即:执行service的connect()函数,并且返回ICamera对象,赋值给Camera的mCamera,服务端connect()返回的是他内部类的一个实例。
service的connect()函数定义库文件libcameraservice.so中实现。
connect( )源码路径:frameworks/av/services/camera/libcameraservice/CameraService.cpp
sp<ICamera> CameraService::connect(
const sp<ICameraClient>& cameraClient, int cameraId) {
int callingPid = getCallingPid();
sp<CameraHardwareInterface> hardware = NULL;
....................
hardware = new CameraHardwareInterface(camera_device_name);
if (hardware->initialize(&mModule->common) != OK) {
hardware.clear();
return NULL;
}
client = new Client(this, cameraClient, hardware, cameraId, info.facing, callingPid);
mClient[cameraId] = client;
LOG1("CameraService::connect X");
return client;
}
frameworks/av/services/camera/libcameraservice/CameraHardwareInterface.h
status_t initialize(hw_module_t *module)
{
LOGI("Opening camera %s", mName.string());
int rc = module->methods->open(module, mName.string(), (hw_device_t **)&mDevice);
if (rc != OK) {
LOGE("Could not open camera %s: %d", mName.string(), rc);
return rc;
}
initHalPreviewWindow();
return rc;
}
此处通过module->method->open()方法真正打开Camera设备,其中module是由它的调用者(serivce端:hardware->initialize(&mModule->common) )传过来的参数。该module的定义在以下路径:frameworks/av/services/camera/libcameraservice/CameraHardwareInterface.h
class CameraService :
public BinderService<CameraService>,
public BnCameraService
{
class Client : public BnCamera
{
public:
......
private:
.....
};
camera_module_t *mModule;
};
此处还必须找到camera_module_t 的定义,以更好的理解整个运行流程,通过追根溯源找到了camera_module_t 定义,
camera_module_t的定义在以下路径:hardware/av/include/hardware/camera_common.h中,定义如下
typedef struct camera_module {
hw_module_t common;
int (*get_number_of_cameras)(void);
int (*get_camera_info)(int camera_id, struct camera_info *info);
} camera_module_t;
其中包含get_number_of_cameras方法和get_camera_info方法用于获取camera info
另外hw_module_t common;这个选项十分重要,此处应重点关注,因为是使用hw_module_t结构体中的open()方法打开设备文件的
继续找到hw_module_t 结构体的定义。在以下路径:hardware/libhardware/include/hardware/hardware.h,代码如下:
struct hw_module_t;
struct hw_module_methods_t;
struct hw_device_t;
/**
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
* and the fields of this data structure must begin with hw_module_t
* followed by module specific information.
*/
typedef struct hw_module_t {
......................
/** Modules methods */
struct hw_module_methods_t* methods;
......................
} hw_module_t;
同样,找到hw_module_methods_t这个结构体的定义,代码如下:
typedef struct hw_module_methods_t {
/** Open a specific device */
int (*open)(const struct hw_module_t* module, const char* id, struct hw_device_t** device);
} hw_module_methods_t;
hw_module_methods_t 结构体中只有open()一个方法,用于打开camera driver,实现与硬件层的交互。
open()是一个函数指针,对open()赋值的代码如下:/hardware/qcom/camera/QualcommCamera.cpp
static hw_module_methods_t camera_module_methods = {
open:camera_device_open,
};
其中camera_device_open()函数调用流程如下:
上图可知,在HAL层的module->methods->open(module, mName.string(), (hw_device_t **)&mDevice)回调,最终会调用到函数mm_camera__epen()。
int32_t mm_camera_open(mm_camera_obj_t *my_obj, mm_camera_op_mode_type_t op_mode)
{
.......................................
snprintf(dev_name, sizeof(dev_name), "/dev/%s", m_camera_util_get_dev_name(my_obj));
do{
n_try--;
my_obj->ctrl_fd = open(dev_name,O_RDWR | O_NONBLOCK);
...................
}while(n_try>0);
....................
return rc;
}
自己分析:主要是这三个文件夹ext feature legacy
CameraHardwareInterface.h (frameworks\av\services\camera\libcameraservice\device1)
res = module->getCameraInfo(atoi(mName.string()), &info);
rc = module->openLegacy(mName.string(), CAMERA_DEVICE_API_VERSION_1_0, (hw_device_t **)&mDevice);
CameraModule.cpp (frameworks\av\services\camera\libcameraservice\common)
mModule->open_legacy(&mModule->common, id, halVersion, device);
Module.h (vendor\mediatek\proprietary\hardware\mtkcam\legacy\module_hal\module)
// getCamDeviceManager在CamDeviceManagerImp.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\devicemgr)
NSCam::getCamDeviceManager()->open(device, module, id, halVersion);
CamDeviceManagerBase.openDevice.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\module_hal\devicemgr)
openDeviceLocked(device, module, i4OpenId, device_version);
// [1] check to see whether it's ready to open.
if ( OK != (status = validateOpenLocked(i4OpenId, device_version)) )
// [2] get platform
IPlatform*const pPlatform = getPlatform(); //得到平台操作函数指针
[3] create device based on device version.
pDevice = pPlatform->createCam1Device(s8ClientAppMode.string(), i4DebugOpenID);
//Cam1DeviceFactory.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\v1\device)
String8 const s8LibPath = String8::format("libcam.device1.so"); //这个是一个动态库
void *handle = ::dlopen(s8LibPath.string(), RTLD_GLOBAL); //用dlopen打开库
s8CamDeviceInstFactory = String8::format("createCam1Device_Default");
void* pCreateInstance = ::dlsym(handle, s8CamDeviceInstFactory.string()); //找到库里面的createCam1Device_Default函数指针
//用createCam1Device_Default这个函数指针调用函数,单独分析1
reinterpret_cast<NSCam::Cam1Device* (*)(String8 const&, int32_t const)> (pCreateInstance)(s8ClientAppMode, i4OpenId)
//这个里会调用DefaultCam1Device.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\v1\device)的onInit,具体在哪里调用不知道,看log是有
bool DefaultCam1Device::onInit() //单独分析8
if ( OK != pdev->initialize() //前面初始化了createCam1Device_Default,这里调用他的initialize函数,单独分析2
sp<IMMSdkService> cs = getMMSdkService();
sp<IServiceManager> sm = defaultServiceManager(); //获取服务
// use checkService to avoid blocking if mmsdk service is not up yet
sp<IBinder> binder = sm->checkService(String16("media.mmsdk")); //检查是是否有media.mmsdk这个服务,编赋值并得到binder
sp<IMMSdkService> service = interface_cast<IMMSdkService>(binder); //转换
cs->registerCamera1Device(pDevice.get());
mpGestureClient = android::NSSdkClient::IGestureClient::createInstance(); //创建
mpCam1Device->addCamClient(mpGestureClient, "GestureClient"); //加入
mpHRuser->RegisterCamDev(mpCam1Device); //注册
initHalPreviewWindow(); //初始化预览的方法,单独分析3
单独分析1://用createCam1Device_Default这个函数指针调用函数,
DefaultCam1Device::DefaultCam1Device(String8 const& rDevName, int32_t const i4OpenId) //构造函数
: Cam1DeviceBase(rDevName, i4OpenId) , mpHalSensor(NULL)
#if '1'==MTKCAM_HAVE_3A_HAL
, mpHal3a(NULL)
#endif
, mbThreadRunning(MFALSE)
//
{
}
//这里继承了Cam1DeviceBase,mpHalSensor,mpHal3a,mbThreadRunning这些类
Cam1DeviceBase::Cam1DeviceBase(String8 const& rDevName,int32_t const i4OpenId)
: Cam1Device() , mpDeviceManager(NULL), mDevName(rDevName) , mi4OpenId(i4OpenId)
, mpCamMsgCbInfo(new CamMsgCbInfo), mpParamsMgr(IParamsManager::createInstance(rDevName, i4OpenId))
, mpCamAdapter(NULL) , mpCamClient(), mpDisplayClient(), vmpCamClient()
, mIsPreviewEnabled(false), mIsRaw16CBEnabled(false), mTodoCmdMap()
, mTodoCmdMapLock(), mOrientation(0), mLastEnableMsg(0) , mStartPreviewTThreadHandle(0)
, mbWindowReady(false)
}
Cam1Device::Cam1Device() : ICamDevice() , mpModuleCallbacks(NULL), mDevice() , mDeviceOps()
{
MY_LOGD("ctor");
::memset(&mDevice, 0, sizeof(mDevice));
mDevice.priv = this;
mDevice.common = gHwDevice;
mDevice.ops = (camera_device_ops*)&mDeviceOps;
mDeviceOps = gCameraDevOps;
//
}
static mtk_camera_device_ops const gCameraDevOps =
{
#define OPS(name) name: camera_##nam
{
OPS(set_preview_window),
OPS(set_callbacks),
OPS(enable_msg_type),
OPS(disable_msg_type),
OPS(msg_type_enabled),
OPS(start_preview),
OPS(stop_preview),
OPS(preview_enabled),
OPS(store_meta_data_in_buffers),
OPS(start_recording),
OPS(stop_recording),
OPS(recording_enabled),
OPS(release_recording_frame),
OPS(auto_focus),
OPS(cancel_auto_focus),
OPS(take_picture),
OPS(cancel_picture),
OPS(set_parameters),
OPS(get_parameters),
OPS(put_parameters),
OPS(send_command),
OPS(release),
OPS(dump)
},
OPS(mtk_set_callbacks),
#undef OPS
};
createCam1Device_Default
new DefaultCam1Device(rDevName, i4OpenId); //这个类就是上面那个,new一个
单独分析2:initialize
CamClient::CamClient(sp<IParamsManager> pParamsMgr) : ICamClient() , mModuleMtx() , mpCamMsgCbInfo(new CamMsgCbInfo) , mpParamsMgr(pParamsMgr)
, mpImgBufPvdrClient(NULL) , mpPreviewClient(NULL) , mpRecordClient(NULL) , mpFDClient(NULL), mpPreviewFeatureClient(NULL) , mbPreviewEnabled(false)
前面初始化了create Cam1Device_Default,这里调用他的initialize函数,
initialize调用的是createCam1Device_Default的父类Cam1DeviceBase的initialize
Cam1DeviceBase.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\v1\device)
mpCamMsgCbInfo->mCam1DeviceCb = static_cast<ICam1DeviceCallback*>(this); //设置Cam1Device回调函数
// (1) Initialize Parameters.
if ( ! mpParamsMgr->init() )
// (2) Create & Initialize ICamClient.
mpCamClient = ICamClient::createInstance(mpParamsMgr); //初始化客户端
单独分析3:初始化预览的方法,
initHalPreviewWindow();
mHalPreviewWindow.nw.cancel_buffer = __cancel_buffer;
mHalPreviewWindow.nw.lock_buffer = __lock_buffer;
mHalPreviewWindow.nw.dequeue_buffer = __dequeue_buffer;
mHalPreviewWindow.nw.enqueue_buffer = __enqueue_buffer;
mHalPreviewWindow.nw.set_buffer_count = __set_buffer_count;
mHalPreviewWindow.nw.set_buffers_geometry = __set_buffers_geometry;
mHalPreviewWindow.nw.set_crop = __set_crop;
mHalPreviewWindow.nw.set_timestamp = __set_timestamp;
mHalPreviewWindow.nw.set_usage = __set_usage;
mHalPreviewWindow.nw.set_swap_interval = __set_swap_interval;
mHalPreviewWindow.nw.get_min_undequeued_buffer_count = __get_min_undequeued_buffer_count;
单独分析4:更新摄像头相关的参数
updateDefaultParams
// (1) cleanup mParameters.
mParameters = MtkCameraParameters();
单独分析5://创建Feature的结构体
#define CUSTOM_AFLAMP "aflamp"
queryCustomFeature(mFeatureMap, String8(DLSYM_MODULE_NAME_AFLAMP)); ////获取的是custom目录下的config.ftbl.flashlight.h中的aflamp
initFeatures_CameraShot();
#define DLSYM_MODULE_NAME_CAMERASHOT "CUSTOM_CAMERASHOT"
queryCustomFeature(mFeatureMap, String8(DLSYM_MODULE_NAME_CAMERASHOT)); //获取的是custom目录下的config.ftbl.camerashot.h
initFeatures_SenIndepFeature();// [4] Correct without warning
queryCustomFeature(mFeatureMap, String8(DLSYM_MODULE_NAME_SENINDEPFEATURE)); //获取的是custom目录下的config.ftbl.senindepfeature.h,主要是美颜
initFeatures_NoWarningCorrection() //一些相关于低内存和HDR的禁止
单独分析6:updateDefaultParams2
updateDefaultParams2
//ParamsManager.update.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\v1\common\paramsmgr\params)
updateDefaultParams2_ByQuery()
//ParamsManagerImp.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\v1\common\paramsmgr\params)
sensorDev = (MUINT32)NSCam::IHalSensorList::get()->querySensorDevIdx(getOpenId()); //得到sensor
pSensorHalList = NSCam::IHalSensorList::get(); //得到sensor list
pSensorHalList->querySensorStaticInfo(sensorDev,&sensorStaticInfo); //获取sensor相关的一下参数
//HalSensorList.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)
::memcpy(pSensorStaticInfo, gQuerySensorStaticInfo(sensorDevIdx), sizeof(SensorStaticInfo));
gQuerySensorStaticInfo(sensorDev);
sensorStaticInfo[0]; //如果是主摄像头,这里实际是在Imgsensor_drv.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)中通过
pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_FAKE_ORIENTATION, (MUINTPTR)&data1); //这个应该是在开机的时候已经运行了
//Imgsensor_drv.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)
orientation = NSCamCustomSensor::getSensorOrientation(); //获取的是Cfg_setting_imgsensor.cpp (vendor\mediatek\proprietary\custom\mt6735\hal\d1\imgsensor_src)的方向值
sensorStaticInfo[idx].fakeOrientation = data1;
IHal3A* p3AHal = IHal3A::createInstance(IHal3A::E_Camera_1,getOpenId(),PARAM_NAME); //3A相关的初始化,单独分析7
p3AHal->getSupportedParams(r3ASupportedParam)
ParamsManagerImp.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\v1\common\paramsmgr\params)
mpHal3aObj->getSupportedParams(rFeatureParam); //得到AE,AF,AWB的一些值
//Aaa_hal.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\core\featureio\pipe\aaa)
rFeatureParam.bAutoWhiteBalanceLockSupported = IAwbMgr::getInstance().isAWBLockSupported();
updateDefaultParams2_ByDefault() // Fail to query => update by default
单独分析7:3A相关的初始化
Hal3AAdapter1::Hal3AAdapter1(MINT32 const i4SensorIdx) : mpHal3aObj(NULL) , mi4FrmId(-1) , mi4SensorIdx(i4SensorIdx), mi4User(0) , mLock() //初始化
{
}
IHal3A::createInstance(IHal3A::E_Camera_1,getOpenId(),PARAM_NAME);
//Hal3AAdapter1.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\core\featureio\pipe\aaa)//
static Hal3AAdapter1 _singleton(0);
_singleton.init(strUser);
mpHal3aObj = Hal3AIf::createInstance(mi4SensorIdx);
//Aaa_hal_if.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\aaa)
return Hal3AFlowCtrl::createInstance(i4SensorOpenIndex);
Hal3AFlowCtrl.cpp (vendor\mediatek\proprietary\hardware\mtkcam\aaa\source\ipv1.1)
i4SensorDev = pHalSensorList->querySensorDevIdx(i4SensorOpenIndex);
Hal3AFlowCtrlDev<SENSOR_DEV_MAIN>::getInstance()->init(i4SensorDev, i4SensorOpenIndex);
// create 3A wrapper
I3AWrapper.cpp (vendor\mediatek\proprietary\hardware\mtkcam\aaa\source\ipv1.1\wrapper)
return Hal3ARaw::createInstance(i4SensorOpenIndex);
//Hal3ARawImp.cpp (vendor\mediatek\proprietary\hardware\mtkcam\aaa\source\ipv1.1\wrapper)
Hal3ARawImpDev<SENSOR_DEV_MAIN>::getInstance(i4SensorDevId, i4SensorOpenIndex)->init();
// init Thread and state mgr
m_pThreadRaw = IThreadRaw::createInstance(this, m_i4SensorDev, m_i4SensorIdx);
ThreadRawImp.cpp (vendor\mediatek\proprietary\hardware\mtkcam\aaa\source\ipv1.1)
singleton.createAEThread(); // user count protected
MINT32 result = pthread_create(&mAEThread, NULL, onAEThreadLoop, this); //* AE thread execution function
m_pStateMgr = new StateMgr(m_i4SensorDev); //状态管理
m_pAfStateMgr = new AfStateMgr(m_i4SensorDev); //AF的状态管理
// AE init
IAeMgr::getInstance().cameraPreviewInit(m_i4SensorDev, m_i4SensorIdx, m_rParam); //AF管理初始化
//Ae_mgr.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\aaa\ae_mgr)
cameraPreviewInit //里面// AWB initIAwbMgr::getInstance().init(m_i4SensorDev, m_i4SensorIdx);// AF initIAfMgr::getInstance().setCallbacks(m_i4SensorDev, mpCbSet);IAfMgr::getInstance().init(m_i4SensorDev, m_i4SensorIdx);//FLASH initFlashMgr::getInstance().init(m_i4SensorDev, m_i4SensorIdx);// TuningMgr initm_pTuning = &IspTuningMgr::getInstance();m_pTuning->init(m_i4SensorDev, m_i4SensorIdx)// state mgr transit to Init state.bRet = postCommand(ECmd_Init);
return Hal3ARawImpDev<SENSOR_DEV_MAIN>::getInstance(i4SensorDevId, i4SensorOpenIndex);
return Hal3AFlowCtrlDev<SENSOR_DEV_MAIN>::getInstance();
单独分析8:mpCamClient->init()
mpCamClient->init()
CamClient.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\v1\client\camclient)
FDClient::FDClient(sp<IParamsManager> pParamsMgr): mCmdQue(), mCmdQueMtx() , mCmdQueCond() , mi4ThreadId(0)
, mModuleMtx() , mpCamMsgCbInfo(new CamMsgCbInfo) , mpParamsMgr(pParamsMgr) , mIsFDStarted(0), mi4CallbackRefCount(0)
, mi8CallbackTimeInMs(0) , mpImgBufQueue(NULL) , mpImgBufPvdrClient(NULL) , mpGDHalObj(NULL) , mpDetectedFaces(NULL)
, mpDetectedGestures(NULL) , mIsDetected_FD(false) , mIsDetected_SD(false), mIsDetected_GD(false) , mIsSDenabled(false)
, mIsGDenabled(false)
{
MY_LOGD("+ this(%p)", this);
}
单独分析8:DefaultCam1Device::onInit() //
IResManager* pResManager = IResManager::getInstance();
ResManager.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\core\drv\resmanager)
return &gResManager;
pResManager->open(USER_NAME)
android_atomic_inc(&mUser);
// (0) power on sensor
pthread_create(&mThreadHandle, NULL, doThreadInit, this)
doThreadInit
DefaultCam1Device* pSelf = reinterpret_cast<DefaultCam1Device*>(arg);
powerOnSensor()
uint32_t sensorIdx = getOpenId(); //得到open的摄像头的ID
NSCam::IHalSensorList* pHalSensorList = NSCam::IHalSensorList::get(); //获取摄像头列表
mpHalSensor = pHalSensorList->createSensor(USER_NAME, getOpenId());//创建
HalSensorList.openList.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)
vSensorIndex.add(index);
openSensor(vSensorIndex, szCallerName);
mSensorDevCreated = mEnumSensorList[vSensorIndex[0]].meSensorDev;//JH
pHalSensor = new HalSensor();
// onCreate callback
pHalSensor->onCreate(vSensorIndex)
HalSensor.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)
mSensorDataMap.setCapacity(vSensorIndex.size());
mpSensorDrv = SensorDrv::get();
//Imgsensor_drv.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)
return ImgSensorDrv::singleton()
mpSeninfDrv = SeninfDrv::createInstance();
//HalSensorList.openList.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)
SeninfDrvImp singleton;
mpHalSensor->powerOn(USER_NAME, 1, &sensorIdx) //给sensor上电,单独分析9
//HalSensor.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)
int fd = open("/dev/devmap", O_RDONLY);
// workaround: yuv sensor, 3A depends on sensor power-on
NSCam::IHalSensorList::get()->queryType( getOpenId() ) == NSCam::NSSensorType::eYUV //如果是YUV的,waitThreadInitDone()
mpHal3a = NS3A::IHal3A::createInstance( NS3A::IHal3A::E_Camera_1, getOpenId(), LOG_TAG);
IHal3A.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\aaa)
单独分析9:给sensor上电
mpHalSensor->powerOn(USER_NAME, 1, &sensorIdx)
//HalSensor.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)
int fd = open("/dev/devmap", O_RDONLY);
ioctl(fd, READ_DEV_DATA, &devinfo_data) //得到一些信息
mpSeninfDrv->init();
//Seninf_drv.cpp (vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6735\hal\sensor)
m_pIspDrv = IspDrv::createInstance();
mfd = m_pIspDrv->isp_fd_open("seninf_drv");
mfd = open(ISP_DEV_NAME, O_RDWR); //打开/dev/camera-isp
//Open sensor driver
m_fdSensor = open(SENSOR_DEV_NAME, O_RDWR); //打开/dev/kd_camera_hw
mmap seninf reg
.............分配一下内存。。。。。
// Read CIS efuse value
int fd = open("/dev/devmap", O_RDONLY, 0);
ioctl(fd, READ_DEV_DATA, &devinfo_data)
ret = mpSensorDrv->init(sensorDev);
//
sprintf(cBuf,"/dev/%s",CAMERA_HW_DEVNAME); //kd_camera_hw
m_fdSensor = ::open(cBuf, O_RDWR);
//set sensor driver
ret = ioctl(m_fdSensor, KDIMGSENSORIOC_X_SET_DRIVER,sensorDrvInit); //设置驱动
//init. resolution
getResolution
err = ioctl(m_fdSensor, KDIMGSENSORIOC_X_GETRESOLUTION2, &resolution); //获取分辨率
ret = featureControl((CAMERA_DUAL_CAMERA_SENSOR_ENUM)sensorDevId, SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ, (MUINT8*)&FeaturePara32,(MUINT32*)&FeatureParaLen);
featureCtrl.InvokeCamera = InvokeCamera;
featureCtrl.FeatureId = FeatureId;
featureCtrl.pFeaturePara = pFeaturePara;
featureCtrl.pFeatureParaLen = pFeatureParaLen;
err = ioctl(m_fdSensor, KDIMGSENSORIOC_X_FEATURECONCTROL , &featureCtrl);
ret = featureControl((CAMERA_DUAL_CAMERA_SENSOR_ENUM)sensorDevId, SENSOR_FEATURE_GET_PERIOD, (MUINT8*)pFeaturePara16,(MUINT32*)&FeatureParaLen);
setTgPhase() //设置TG的clk等
ret = pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_PAD_PCLK_INV, (MUINTPTR)&u4PadPclkInv1);
// Config TG, always use Camera PLL, 1: 48MHz, 2: 104MHz
pSeninfDrv->setMclk1(
pcEn, mclkSel1 /*sensorInfo.SensorMasterClockSwitch ? 0 : 1*/,
clkCnt1, sensorDrvInfo[0].SensorClockPolarity ? 0 : 1,
sensorDrvInfo[0].SensorClockFallingCount, sensorDrvInfo[0].SensorClockRisingCount, u4PadPclkInv1);
setSensorIODrivingCurrent() //设置摄像头io的驱动电流
switch(sensorDrvInfo[0].SensorDrivingCurrent)
case ISP_DRIVING_2MA://4 //4mA
increaseDivingCurrent1 = 0x0;
pSeninfDrv->setMclk1IODrivingCurrent(increaseDivingCurrent1);
// Open sensor, try to open 3 time
mpSensorDrv->open(sensorDev)
err = ioctl(m_fdSensor, KDIMGSENSORIOC_X_SET_CURRENT_SENSOR, &sensorIdx);
err = ioctl(m_fdSensor, KDIMGSENSORIOC_T_OPEN);