一、重要结构体
1.模块
hardware/libhardware/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;
2.设备
hardware/libhardware/include/hardware/camera.h
-
typedef struct camera_device {
-
/**
-
* camera_device.common.version must be in the range
-
* HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF). CAMERA_DEVICE_API_VERSION_1_0 is
-
* recommended.
-
*/
-
hw_device_t common;
-
camera_device_ops_t *ops;
-
void *priv;
-
} camera_device_t;
二、流程
1.模块获取
frameworks/av/services/camera/libcameraservice/CameraService.cpp
-
void CameraService::onFirstRef(){
-
BnCameraService::onFirstRef();
-
-
-
if (hw_get_module(CAMERA_HARDWARE_MODULE_ID,
-
(const hw_module_t **)&mModule) < 0) { //获取Module
-
ALOGE("Could not load camera HAL module");
-
mNumberOfCameras = 0;
-
}
-
else {
-
mNumberOfCameras = mModule->get_number_of_cameras();
-
// if(mNumberOfCameras <= 0) mNumberOfCameras = 1 ;
-
char istv [10];
-
memset(istv,0,sizeof(istv));
-
if (property_get("tv.tvstart_status", istv, NULL) > 0){
-
ALOGD("tv.tvstart_status = %s ,mNumberOfCameras = %d \n",istv,mNumberOfCameras+1);
-
}
-
if(strcmp(istv,"false") == 0)
-
mNumberOfCameras = mNumberOfCameras+1 ;
-
-
-
if (mNumberOfCameras > MAX_CAMERAS) {
-
ALOGE("Number of cameras(%d) > MAX_CAMERAS(%d).",
-
mNumberOfCameras, MAX_CAMERAS);
-
mNumberOfCameras = MAX_CAMERAS;
-
}
-
for (int i = 0; i < mNumberOfCameras; i++) {
-
setCameraFree(i);
-
}
-
}
-
}
2.设备获取
frameworks/av/services/camera/libcameraservice/CameraService.cpp
-
sp<ICamera> CameraService::connect(
-
const sp<ICameraClient>& cameraClient, int cameraId) {
-
int deviceVersion;
-
if (mModule->common.module_api_version == CAMERA_MODULE_API_VERSION_2_0) {
-
deviceVersion = info.device_version;
-
} else {
-
deviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
-
}
-
-
-
switch(deviceVersion) {
-
case CAMERA_DEVICE_API_VERSION_1_0:
-
client = new CameraClient(this, cameraClient, cameraId, info.facing, callingPid, getpid());
-
break;
-
case CAMERA_DEVICE_API_VERSION_2_0:
-
client = new Camera2Client(this, cameraClient, cameraId, info.facing, callingPid, getpid());
-
break;
-
default:
-
ALOGE("Unknown camera device HAL version: %d", deviceVersion);
-
return NULL;
-
}
-
if (client->initialize(mModule) != OK) {
-
return NULL;
-
}
-
}
frameworks/av/services/camera/libcameraservice/CameraClient.cpp
-
status_t CameraClient::initialize(camera_module_t *module) {
-
mHardware = new CameraHardwareInterface(camera_device_name);
-
res = mHardware->initialize(&module->common);
-
}
frameworks/av/services/camera/libcameraservice/CameraHardwareInterface.h
-
status_t initialize(hw_module_t *module){
-
int rc = module->methods->open(module, mName.string(), (hw_device_t **)&mDevice); //获得Device
-
}
转载自:http://blog.csdn.net/tankai19880619/article/details/17348637
阅读(3525) | 评论(0) | 转发(0) |