http://blog.csdn.net/lushengchu_luis/article/details/11033095hw_get_module获取硬件模块
看一下CAMERA_HARDWARE_MODULE_ID
hardware/libhardware/include/hardware/camera_common.h:35:#define CAMERA_HARDWARE_MODULE_ID "camera"
看一下我们打印出来的日志
weiqifa@weiqifa-Inspiron-3847:~/weiqifa/log$ grep -wrn "CameraService::onFirstRef" ./ ./mobilelog/APLog_2010_0105_214945/main_log.boot:922:01-05 22:49:08.208839 194 194 D CameraService: CameraService::onFirstRef weiqifa weiqifa@weiqifa-Inspiron-3847:~/weiqifa/log$
hw_get_module
然后我们就找到了这个地方
./mediatek/hardware/mtkcam/module/module.hstatic
camera_moduleget_camera_module()
{
camera_module module = { common: { tag: HARDWARE_MODULE_TAG,
module_api_version: CAMERA_MODULE_API_VERSION_2_1,
hal_api_version: HARDWARE_HAL_API_VERSION,
id: CAMERA_HARDWARE_MODULE_ID,
name: "MediaTek Camera Module",
author: "MediaTek",
methods: get_module_methods(),
dso: NULL,
reserved: {0},
},
get_number_of_cameras: get_number_of_cameras,
get_camera_info: get_camera_info,
set_callbacks: set_callbacks,
};
return module;}
里面的methods: get_module_methods()这个就是我们hardware的open函数
open_device(hw_module_t const* module, const char* name, hw_device_t** device)
{ return NSCam::getCamDeviceManager()->open(module, name, device);
}statichw_module_methods_t*
get_module_methods()
{ static
hw_module_methods_t
_methods =
{
open: open_device
}; return &_methods;
}
open_device就会找到NScam::getCamDeviceManager()->open
NSCam这个是一个命名空间,我看了网上的解释,更像是类引用,后面我再跟进去找到open的地方
./mediatek/hardware/mtkcam/devicemgr/CamDeviceManagerBase.cpp
status_t
CamDeviceManagerBase::
open(
hw_module_t const* module,
char const* name,
hw_device_t** device
)
{
RWLock::AutoWLock _l(mRWLock); //
return openDeviceLocked(module, name, device);
}
这里调用到了openDeviceLocked 我们找到这个地方
./mediatek/hardware/mtkcam/devicemgr/CamDeviceManagerBase.openDevice.cpp
/******************************************************************************
*
******************************************************************************/status_t
CamDeviceManagerBase::
openDeviceLocked(
hw_module_t const* module,
char const* name,
hw_device_t** device
)
{
status_t status = OK;
sp pDevice = NULL;
int32_t const i4OpenId = (name != NULL) ? ::atoi(name) : -1; //
String8 const s8ClientAppMode = queryClientAppMode();
uint32_t const version = determineOpenDeviceVersionLocked(s8ClientAppMode, i4OpenId); //
MY_LOGD("+ mOpenMap.size:%d mEnumMap.size:%d", mOpenMap.size(), mEnumMap.size()); //
// [1] check to see whether it's ready to open.
if ( OK != (status = validateOpenLocked(i4OpenId)) )
{ return status;
} //
// [2] get platform
IPlatform*const pPlatform = getPlatform(); if ( ! pPlatform )
{
MY_LOGE("No Platform"); return NAME_NOT_FOUND;
} //
// [3] create device based on device version.
if ( version == CAMERA_DEVICE_API_VERSION_1_0 )
{
pDevice = pPlatform->createCam1Device(s8ClientAppMode.string(), i4OpenId);
} else
if ( version >= CAMERA_DEVICE_API_VERSION_3_0 )
{
MY_LOGE("Unsupported version:0x%x >= CAMERA_DEVICE_API_VERSION_3_0", version); return UNKNOWN_ERROR;
} else
{
MY_LOGE("Unsupported version:0x%x", version); return UNKNOWN_ERROR;
} //
if ( pDevice == 0 )
{
MY_LOGE("device creation failure"); return NO_MEMORY;
} //
// [4] open device successfully.
{
*device = const_cast(pDevice->get_hw_device()); //
pDevice->set_hw_module(module);
pDevice->set_module_callbacks(mpModuleCallbacks);
pDevice->setDeviceManager(this); //
attachDeviceLocked(pDevice);
} //
return OK;
}