Chinaunix首页 | 论坛 | 博客
  • 博客访问: 848586
  • 博文数量: 143
  • 博客积分: 455
  • 博客等级: 一等列兵
  • 技术积分: 861
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-03 00:11
文章分类

全部博文(143)

文章存档

2018年(10)

2017年(6)

2016年(28)

2015年(14)

2014年(67)

2013年(1)

2012年(17)

我的朋友

分类: Android平台

2014-08-05 20:29:32

一、重要结构体

1.模块

hardware/libhardware/include/hardware/camera_common.h

点击(此处)折叠或打开

  1. typedef struct camera_module {
  2.     hw_module_t common;
  3.     int (*get_number_of_cameras)(void);
  4.     int (*get_camera_info)(int camera_id, struct camera_info *info);
  5. } camera_module_t;

2.设备

hardware/libhardware/include/hardware/camera.h

点击(此处)折叠或打开

  1. typedef struct camera_device {
  2.     /**
  3.      * camera_device.common.version must be in the range
  4.      * HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF). CAMERA_DEVICE_API_VERSION_1_0 is
  5.      * recommended.
  6.      */
  7.     hw_device_t common;
  8.     camera_device_ops_t *ops;
  9.     void *priv;
  10. } camera_device_t;
二、流程

1.模块获取

frameworks/av/services/camera/libcameraservice/CameraService.cpp

点击(此处)折叠或打开

  1. void CameraService::onFirstRef(){
  2.   BnCameraService::onFirstRef();


  3.   if (hw_get_module(CAMERA_HARDWARE_MODULE_ID,
  4.                 (const hw_module_t **)&mModule) < 0) { //获取Module
  5.     ALOGE("Could not load camera HAL module");
  6.     mNumberOfCameras = 0;
  7.   }
  8.   else {
  9.     mNumberOfCameras = mModule->get_number_of_cameras();
  10.     // if(mNumberOfCameras <= 0) mNumberOfCameras = 1 ;
  11.     char istv [10];
  12.     memset(istv,0,sizeof(istv));
  13.     if (property_get("tv.tvstart_status", istv, NULL) > 0){
  14.       ALOGD("tv.tvstart_status = %s ,mNumberOfCameras = %d \n",istv,mNumberOfCameras+1);
  15.     }
  16.     if(strcmp(istv,"false") == 0)
  17.       mNumberOfCameras = mNumberOfCameras+1 ;


  18.     if (mNumberOfCameras > MAX_CAMERAS) {
  19.       ALOGE("Number of cameras(%d) > MAX_CAMERAS(%d).",
  20.                     mNumberOfCameras, MAX_CAMERAS);
  21.       mNumberOfCameras = MAX_CAMERAS;
  22.     }
  23.     for (int i = 0; i < mNumberOfCameras; i++) {
  24.       setCameraFree(i);
  25.     }
  26.   }
  27. }
2.设备获取
frameworks/av/services/camera/libcameraservice/CameraService.cpp

点击(此处)折叠或打开

  1. sp<ICamera> CameraService::connect(
  2.         const sp<ICameraClient>& cameraClient, int cameraId) {
  3.   int deviceVersion;
  4.   if (mModule->common.module_api_version == CAMERA_MODULE_API_VERSION_2_0) {
  5.     deviceVersion = info.device_version;
  6.   } else {
  7.      deviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
  8.   }


  9.   switch(deviceVersion) {
  10.     case CAMERA_DEVICE_API_VERSION_1_0:
  11.       client = new CameraClient(this, cameraClient, cameraId, info.facing, callingPid, getpid());
  12.       break;
  13.     case CAMERA_DEVICE_API_VERSION_2_0:
  14.       client = new Camera2Client(this, cameraClient, cameraId, info.facing, callingPid, getpid());
  15.       break;
  16.     default:
  17.       ALOGE("Unknown camera device HAL version: %d", deviceVersion);
  18.       return NULL;
  19.   }
  20.   if (client->initialize(mModule) != OK) {
  21.     return NULL;
  22.   }
  23. }
frameworks/av/services/camera/libcameraservice/CameraClient.cpp

点击(此处)折叠或打开

  1. status_t CameraClient::initialize(camera_module_t *module) {
  2.   mHardware = new CameraHardwareInterface(camera_device_name);
  3.   res = mHardware->initialize(&module->common);
  4. }
frameworks/av/services/camera/libcameraservice/CameraHardwareInterface.h

点击(此处)折叠或打开

  1. status_t initialize(hw_module_t *module){
  2.   int rc = module->methods->open(module, mName.string(), (hw_device_t **)&mDevice); //获得Device
  3. }

转载自:http://blog.csdn.net/tankai19880619/article/details/17348637

阅读(3525) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~