Android Camera HAL浅析

1、Camera成像原理介绍

Camera工作流程图

Camera的成像原理可以简单概括如下:

景物(SCENE)通过镜头(LENS)生成的光学图像投射到图像传感器(Sensor)表面上,然后转为电信号,经过A/D(模数转换)转换后变为数字 图像信号,再送到数字信号处理芯片(DSP)中加工处理,再通过IO接口传输到CPU中处理,通过DISPLAY就可以看到图像了。

电荷耦合器件(CCD)互补金属氧化物半导体(CMOS)接收光学镜头传递来的影像,经模/数转换器(A/D)转换成数字信号,经过编码后存储。

流程如下: 
1)、CCD/CMOS将被摄体的光信号转变为电信号—电子图像(模拟信号) 
2)、由模/数转换器(ADC)芯片来将模拟信号转化为数字信号 
3)、数字信号形成后,由DSP或编码库对信号进行压缩并转化为特定的图像文件格式储存

数码相机的光学镜头与传统相机相同,将影像聚到感光器件上,即(光)电荷耦合器件(CCD) 。CCD替代了传统相机中的感光胶片的位置,其功能是将光信号转换成电信号,与电视摄像相同。

CCD是半导体器件,是数码相机的核心,其内含器件的单元数量决定了数码相机的成像质量——像素,单元越多,即像素数高,成像质量越好,通常情况下像素的高低代表了数码相机的档次和技术指标。

2、Android Camera框架

Android的Camera子系统提供一个拍照和录制视频的框架。

它将Camera的上层应用与Application Framework、用户库串接起来,而正是这个用户库来与Camera的硬件层通信,从而实现操作camera硬件。

--------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------

3.Camera HAL层部分 
代码存放目录:hardware\rk29\camera
编译:

[cpp] view plaincopy

  1. LOCAL_PATH:= $(call my-dir)
  2. include $(CLEAR_VARS)
  3. LOCAL_SRC_FILES:=\
  4. CameraHal_Module.cpp\
  5. CameraHal.cpp\
  6. CameraHal_Utils.cpp\
  7. MessageQueue.cpp\
  8. CameraHal_Mem.cpp
  9. ...................
  10. ifeq ($(strip $(TARGET_BOARD_HARDWARE)),rk30board)
  11. LOCAL_MODULE:= camera.rk30board

为了实现一个具体功能的Camera,在HAL层需要一个硬件相关的Camera库(例如通过调用video for linux驱动程序和Jpeg编码程序实现或者直接用各个chip厂商实现的私有库来实现,比如Qualcomm实现的libcamera.so和 libqcamera.so),此处为camera.rk30board.so实现CameraHardwareInterface规定的接口,来调用相 关的库,驱动相关的driver,实现对camera硬件的操作。这个库将被Camera的服务库libcameraservice.so调用。

3.1CameraHal_Module.cpp主要是Camera HAL对上层提供的接口,和实际设备无关,上层的本地库都直接调用这个文件里面提供的接口。

[cpp] view plaincopy

  1. static int camera_device_open(const hw_module_t* module, const char* name,
  2. hw_device_t** device);
  3. static int camera_device_close(hw_device_t* device);
  4. static int camera_get_number_of_cameras(void);
  5. static int camera_get_camera_info(int camera_id, struct camera_info *info);
  6. static struct hw_module_methods_t camera_module_methods = {
  7. open: camera_device_open
  8. };
  9. camera_module_t HAL_MODULE_INFO_SYM = {
  10. common: {
  11. tag: HARDWARE_MODULE_TAG,
  12. version_major: ((CONFIG_CAMERAHAL_VERSION&0xff00)>>8),
  13. version_minor: CONFIG_CAMERAHAL_VERSION&0xff,
  14. id: CAMERA_HARDWARE_MODULE_ID,
  15. name: CAMERA_MODULE_NAME,
  16. author: "RockChip",
  17. methods: &camera_module_methods,
  18. dso: NULL, /* remove compilation warnings */
  19. reserved: {0}, /* remove compilation warnings */
  20. },
  21. get_number_of_cameras: camera_get_number_of_cameras,
  22. get_camera_info: camera_get_camera_info,
  23. };

//CAMERA_DEVICE_NAME              "/dev/video" 以下都是通过读取节点信息来获取摄像头的数目及摄像头设备信息

[cpp] view plaincopy

  1. int camera_device_close(hw_device_t* device)
  2. {
  3. int ret = 0;
  4. rk_camera_device_t* rk_dev = NULL;
  5. LOGD("%s", __FUNCTION__);
  6. android::Mutex::Autolock lock(gCameraHalDeviceLock);
  7. if (!device) {
  8. ret = -EINVAL;
  9. goto done;
  10. }
  11. rk_dev = (rk_camera_device_t*) device;
  12. if (rk_dev) {
  13. if (gCameraHals[rk_dev->cameraid]) {
  14. delete gCameraHals[rk_dev->cameraid];
  15. gCameraHals[rk_dev->cameraid] = NULL;
  16. gCamerasOpen--;
  17. }
  18. if (rk_dev->base.ops) {
  19. free(rk_dev->base.ops);
  20. }
  21. free(rk_dev);
  22. }
  23. done:
  24. return ret;
  25. }
  26. /*******************************************************************
  27. * implementation of camera_module functions
  28. *******************************************************************/
  29. /* open device handle to one of the cameras
  30. *
  31. * assume camera service will keep singleton of each camera
  32. * so this function will always only be called once per camera instance
  33. */
  34. int camera_device_open(const hw_module_t* module, const char* name,
  35. hw_device_t** device)
  36. {
  37. int rv = 0;
  38. int cameraid;
  39. rk_camera_device_t* camera_device = NULL;
  40. camera_device_ops_t* camera_ops = NULL;
  41. android::CameraHal* camera = NULL;
  42. android::Mutex::Autolock lock(gCameraHalDeviceLock);
  43. LOGI("camera_device open");
  44. if (name != NULL) {
  45. cameraid = atoi(name);
  46. if(cameraid > gCamerasNumber) {
  47. LOGE("camera service provided cameraid out of bounds, "
  48. "cameraid = %d, num supported = %d",
  49. cameraid, gCamerasNumber);
  50. rv = -EINVAL;
  51. goto fail;
  52. }
  53. if(gCamerasOpen >= CAMERAS_SUPPORTED_SIMUL_MAX) {
  54. LOGE("maximum number(%d) of cameras already open",gCamerasOpen);
  55. rv = -ENOMEM;
  56. goto fail;
  57. }
  58. camera_device = (rk_camera_device_t*)malloc(sizeof(*camera_device));
  59. if(!camera_device) {
  60. LOGE("camera_device allocation fail");
  61. rv = -ENOMEM;
  62. goto fail;
  63. }
  64. camera_ops = (camera_device_ops_t*)malloc(sizeof(*camera_ops));
  65. if(!camera_ops) {
  66. LOGE("camera_ops allocation fail");
  67. rv = -ENOMEM;
  68. goto fail;
  69. }
  70. memset(camera_device, 0, sizeof(*camera_device));
  71. memset(camera_ops, 0, sizeof(*camera_ops));
  72. camera_device->base.common.tag = HARDWARE_DEVICE_TAG;
  73. camera_device->base.common.version = 0;
  74. camera_device->base.common.module = (hw_module_t *)(module);
  75. camera_device->base.common.close = camera_device_close;
  76. camera_device->base.ops = camera_ops;
  77. camera_ops->set_preview_window = camera_set_preview_window;
  78. camera_ops->set_callbacks = camera_set_callbacks;
  79. camera_ops->enable_msg_type = camera_enable_msg_type;
  80. camera_ops->disable_msg_type = camera_disable_msg_type;
  81. camera_ops->msg_type_enabled = camera_msg_type_enabled;
  82. camera_ops->start_preview = camera_start_preview;
  83. camera_ops->stop_preview = camera_stop_preview;
  84. camera_ops->preview_enabled = camera_preview_enabled;
  85. camera_ops->store_meta_data_in_buffers = camera_store_meta_data_in_buffers;
  86. camera_ops->start_recording = camera_start_recording;
  87. camera_ops->stop_recording = camera_stop_recording;
  88. camera_ops->recording_enabled = camera_recording_enabled;
  89. camera_ops->release_recording_frame = camera_release_recording_frame;
  90. camera_ops->auto_focus = camera_auto_focus;
  91. camera_ops->cancel_auto_focus = camera_cancel_auto_focus;
  92. camera_ops->take_picture = camera_take_picture;
  93. camera_ops->cancel_picture = camera_cancel_picture;
  94. camera_ops->set_parameters = camera_set_parameters;
  95. camera_ops->get_parameters = camera_get_parameters;
  96. camera_ops->put_parameters = camera_put_parameters;
  97. camera_ops->send_command = camera_send_command;
  98. camera_ops->release = camera_release;
  99. camera_ops->dump = camera_dump;
  100. *device = &camera_device->base.common;
  101. // -------- RockChip specific stuff --------
  102. camera_device->cameraid = cameraid;
  103. camera = new android::CameraHal(cameraid);
  104. if(!camera) {
  105. LOGE("Couldn‘t create instance of CameraHal class");
  106. rv = -ENOMEM;
  107. goto fail;
  108. }
  109. gCameraHals[cameraid] = camera;
  110. gCamerasOpen++;
  111. }
  112. return rv;
  113. fail:
  114. if(camera_device) {
  115. free(camera_device);
  116. camera_device = NULL;
  117. }
  118. if(camera_ops) {
  119. free(camera_ops);
  120. camera_ops = NULL;
  121. }
  122. if(camera) {
  123. delete camera;
  124. camera = NULL;
  125. }
  126. *device = NULL;
  127. return rv;
  128. }
  129. int camera_get_number_of_cameras(void)
  130. {
  131. char cam_path[20];
  132. char cam_num[3],i;
  133. int cam_cnt=0,fd=-1,rk29_cam[CAMERAS_SUPPORT_MAX];
  134. struct v4l2_capability capability;
  135. rk_cam_info_t camInfoTmp[CAMERAS_SUPPORT_MAX];
  136. char *ptr,**ptrr;
  137. char version[PROPERTY_VALUE_MAX];
  138. if (gCamerasNumber > 0)
  139. goto camera_get_number_of_cameras_end;
  140. memset(version,0x00,sizeof(version));
  141. sprintf(version,"%d.%d.%d",((CONFIG_CAMERAHAL_VERSION&0xff0000)>>16),
  142. ((CONFIG_CAMERAHAL_VERSION&0xff00)>>8),CONFIG_CAMERAHAL_VERSION&0xff);
  143. property_set(CAMERAHAL_VERSION_PROPERTY_KEY,version);
  144. memset(&camInfoTmp[0],0x00,sizeof(rk_cam_info_t));
  145. memset(&camInfoTmp[1],0x00,sizeof(rk_cam_info_t));
  146. for (i=0; i<10; i++) {
  147. cam_path[0] = 0x00;
  148. strcat(cam_path, CAMERA_DEVICE_NAME);
  149. sprintf(cam_num, "%d", i);
  150. strcat(cam_path,cam_num);
  151. fd = open(cam_path, O_RDONLY);
  152. if (fd < 0)
  153. break;
  154. memset(&capability, 0, sizeof(struct v4l2_capability));
  155. if (ioctl(fd, VIDIOC_QUERYCAP, &capability) < 0) {
  156. LOGE("Video device(%s): query capability not supported.\n",cam_path);
  157. goto loop_continue;
  158. }
  159. if ((capability.capabilities & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING)) != (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING)) {
  160. LOGD("Video device(%s): video capture not supported.\n",cam_path);
  161. } else {
  162. memset(camInfoTmp[cam_cnt&0x01].device_path,0x00, sizeof(camInfoTmp[cam_cnt&0x01].device_path));
  163. strcat(camInfoTmp[cam_cnt&0x01].device_path,cam_path);
  164. memset(camInfoTmp[cam_cnt&0x01].fival_list,0x00, sizeof(camInfoTmp[cam_cnt&0x01].fival_list));
  165. memcpy(camInfoTmp[cam_cnt&0x01].driver,capability.driver, sizeof(camInfoTmp[cam_cnt&0x01].driver));
  166. camInfoTmp[cam_cnt&0x01].version = capability.version;
  167. if (strstr((char*)&capability.card[0], "front") != NULL) {
  168. camInfoTmp[cam_cnt&0x01].facing_info.facing = CAMERA_FACING_FRONT;
  169. } else {
  170. camInfoTmp[cam_cnt&0x01].facing_info.facing = CAMERA_FACING_BACK;
  171. }
  172. ptr = strstr((char*)&capability.card[0],"-");
  173. if (ptr != NULL) {
  174. ptr++;
  175. camInfoTmp[cam_cnt&0x01].facing_info.orientation = atoi(ptr);
  176. } else {
  177. camInfoTmp[cam_cnt&0x01].facing_info.orientation = 0;
  178. }
  179. cam_cnt++;
  180. memset(version,0x00,sizeof(version));
  181. sprintf(version,"%d.%d.%d",((capability.version&0xff0000)>>16),
  182. ((capability.version&0xff00)>>8),capability.version&0xff);
  183. property_set(CAMERADRIVER_VERSION_PROPERTY_KEY,version);
  184. LOGD("%s(%d): %s:%s",__FUNCTION__,__LINE__,CAMERADRIVER_VERSION_PROPERTY_KEY,version);
  185. if (cam_cnt >= CAMERAS_SUPPORT_MAX)
  186. i = 10;
  187. }
  188. loop_continue:
  189. if (fd > 0) {
  190. close(fd);
  191. fd = -1;
  192. }
  193. continue;
  194. }
  195. //zyc , change the camera infomation if there is a usb camera
  196. if((strcmp(camInfoTmp[0].driver,"uvcvideo") == 0)) {
  197. camInfoTmp[0].facing_info.facing = (camInfoTmp[1].facing_info.facing == CAMERA_FACING_FRONT) ? CAMERA_FACING_BACK:CAMERA_FACING_FRONT;
  198. camInfoTmp[0].facing_info.orientation = (camInfoTmp[0].facing_info.facing == CAMERA_FACING_FRONT)?270:90;
  199. } else if((strcmp(camInfoTmp[1].driver,"uvcvideo") == 0)) {
  200. camInfoTmp[1].facing_info.facing = (camInfoTmp[0].facing_info.facing == CAMERA_FACING_FRONT) ? CAMERA_FACING_BACK:CAMERA_FACING_FRONT;
  201. camInfoTmp[1].facing_info.orientation = (camInfoTmp[1].facing_info.facing == CAMERA_FACING_FRONT)?270:90;
  202. }
  203. gCamerasNumber = cam_cnt;
  204. #if CONFIG_AUTO_DETECT_FRAMERATE
  205. rk29_cam[0] = 0xff;
  206. rk29_cam[1] = 0xff;
  207. for (i=0; i<cam_cnt; i++) {  < span="">
  208. if (strcmp((char*)&camInfoTmp[i].driver[0],"rk29xx-camera") == 0) {
  209. if (strcmp((char*)&camInfoTmp[i].driver[0],(char*)&gCamInfos[i].driver[0]) != 0) {
  210. rk29_cam[i] = i;
  211. }
  212. } else {
  213. rk29_cam[i] = 0xff;
  214. }
  215. }
  216. if ((rk29_cam[0] != 0xff) || (rk29_cam[1] != 0xff)) {
  217. if (gCameraFpsDetectThread == NULL) {
  218. gCameraFpsDetectThread = new CameraFpsDetectThread();
  219. LOGD("%s create CameraFpsDetectThread for enum camera framerate!!",__FUNCTION__);
  220. gCameraFpsDetectThread->run("CameraFpsDetectThread", ANDROID_PRIORITY_AUDIO);
  221. }
  222. }
  223. #endif
  224. #if CONFIG_CAMERA_SINGLE_SENSOR_FORCE_BACK_FOR_CTS
  225. if ((gCamerasNumber==1) && (camInfoTmp[0].facing_info.facing==CAMERA_FACING_FRONT)) {
  226. gCamerasNumber = 2;
  227. memcpy(&camInfoTmp[1],&camInfoTmp[0], sizeof(rk_cam_info_t));
  228. camInfoTmp[1].facing_info.facing = CAMERA_FACING_BACK;
  229. }
  230. #endif
  231. memcpy(&gCamInfos[0], &camInfoTmp[0], sizeof(rk_cam_info_t));
  232. memcpy(&gCamInfos[1], &camInfoTmp[1], sizeof(rk_cam_info_t));
  233. camera_get_number_of_cameras_end:
  234. LOGD("%s(%d): Current board have %d cameras attached.",__FUNCTION__, __LINE__, gCamerasNumber);
  235. return gCamerasNumber;
  236. }
  237. int camera_get_camera_info(int camera_id, struct camera_info *info)
  238. {
  239. int rv = 0,fp;
  240. int face_value = CAMERA_FACING_BACK;
  241. int orientation = 0;
  242. char process_name[30];
  243. if(camera_id > gCamerasNumber) {
  244. LOGE("%s camera_id out of bounds, camera_id = %d, num supported = %d",__FUNCTION__,
  245. camera_id, gCamerasNumber);
  246. rv = -EINVAL;
  247. goto end;
  248. }
  249. info->facing = gCamInfos[camera_id].facing_info.facing;
  250. info->orientation = gCamInfos[camera_id].facing_info.orientation;
  251. end:
  252. LOGD("%s(%d): camera_%d facing(%d), orientation(%d)",__FUNCTION__,__LINE__,camera_id,info->facing,info->orientation);
  253. return rv;
  254. }

而对于为上层提供的HAL层接口函数,并不直接操作节点,而是间接的去调用CameraHal.cpp去操作节点。

[cpp] view plaincopy

  1. int camera_start_preview(struct camera_device * device)
  2. {
  3. int rv = -EINVAL;
  4. rk_camera_device_t* rk_dev = NULL;
  5. LOGV("%s", __FUNCTION__);
  6. if(!device)
  7. return rv;
  8. rk_dev = (rk_camera_device_t*) device;
  9. rv = gCameraHals[rk_dev->cameraid]->startPreview();
  10. return rv;
  11. }
  12. void camera_stop_preview(struct camera_device * device)
  13. {
  14. rk_camera_device_t* rk_dev = NULL;
  15. LOGV("%s", __FUNCTION__);
  16. if(!device)
  17. return;
  18. rk_dev = (rk_camera_device_t*) device;
  19. gCameraHals[rk_dev->cameraid]->stopPreview();
  20. }

3.2CameraHal.cpp去操作节点来进行实际的操作。
//这个几个线程很关键,分别对应着各种不同的情况,但是一直在运行

[cpp] view plaincopy

  1. CameraHal::CameraHal(int cameraId)
  2. :mParameters(),
  3. mSnapshotRunning(-1),
  4. mCommandRunning(-1),
  5. mPreviewRunning(STA_PREVIEW_PAUSE),
  6. mPreviewLock(),
  7. mPreviewCond(),
  8. mDisplayRuning(STA_DISPLAY_PAUSE),
  9. mDisplayLock(),
  10. mDisplayCond(),
  11. mANativeWindowLock(),
  12. mANativeWindowCond(),
  13. mANativeWindow(NULL),
  14. mPreviewErrorFrameCount(0),
  15. mPreviewFrameSize(0),
  16. mCamDriverFrmHeightMax(0),
  17. mCamDriverFrmWidthMax(0),
  18. mPreviewBufferCount(0),
  19. mCamDriverPreviewFmt(0),
  20. mCamDriverPictureFmt(0),
  21. mCamDriverV4l2BufferLen(0),
  22. mPreviewMemory(NULL),
  23. mRawBufferSize(0),
  24. mJpegBufferSize(0),
  25. mMsgEnabled(0),
  26. mEffect_number(0),
  27. mScene_number(0),
  28. mWhiteBalance_number(0),
  29. mFlashMode_number(0),
  30. mGps_latitude(-1),
  31. mGps_longitude(-1),
  32. mGps_altitude(-1),
  33. mGps_timestamp(-1),
  34. displayThreadCommandQ("displayCmdQ"),
  35. displayThreadAckQ("displayAckQ"),
  36. previewThreadCommandQ("previewCmdQ"),
  37. previewThreadAckQ("previewAckQ"),
  38. commandThreadCommandQ("commandCmdQ"),
  39. commandThreadAckQ("commandAckQ"),
  40. snapshotThreadCommandQ("snapshotCmdQ"),
  41. snapshotThreadAckQ("snapshotAckQ"),
  42. mCamBuffer(NULL)
  43. {
  44. int fp,i;
  45. cameraCallProcess[0] = 0x00;
  46. sprintf(cameraCallProcess,"/proc/%d/cmdline",getCallingPid());
  47. fp = open(cameraCallProcess, O_RDONLY);
  48. if (fp < 0) {
  49. memset(cameraCallProcess,0x00,sizeof(cameraCallProcess));
  50. LOGE("Obtain calling process info failed");
  51. } else {
  52. memset(cameraCallProcess,0x00,sizeof(cameraCallProcess));
  53. read(fp, cameraCallProcess, 30);
  54. close(fp);
  55. fp = -1;
  56. LOGD("Calling process is: %s",cameraCallProcess);
  57. }
  58. iCamFd = -1;
  59. memset(&mCamDriverSupportFmt[0],0, sizeof(mCamDriverSupportFmt));
  60. mRecordRunning = false;
  61. mPictureRunning = STA_PICTURE_STOP;
  62. mExitAutoFocusThread = false;
  63. mDriverMirrorSupport = false;
  64. mDriverFlipSupport = false;
  65. mPreviewCmdReceived = false;
  66. mPreviewStartTimes = 0x00;
  67. memset(mCamDriverV4l2Buffer, 0x00, sizeof(mCamDriverV4l2Buffer));
  68. memset(mDisplayFormat,0x00,sizeof(mDisplayFormat));
  69. for (i=0; i<config_camera_prview_buf_cnt; i++) {  < span="">
  70. mPreviewBufferMap[i] = NULL;
  71. mDisplayBufferMap[i] = NULL;
  72. memset(&mGrallocBufferMap[i],0x00,sizeof(rk_previewbuf_info_t));
  73. mPreviewBufs[i] = NULL;
  74. mVideoBufs[i] = NULL;
  75. mPreviewBuffer[i] = NULL;
  76. }
  77. //open the rga device,zyc
  78. mRGAFd = -1;
  79. if (cameraCreate(cameraId) == 0) {
  80. initDefaultParameters();
  81. cameraRawJpegBufferCreate(mRawBufferSize,mJpegBufferSize);
  82. mDisplayThread = new DisplayThread(this);
  83. mPreviewThread = new PreviewThread(this);
  84. mCommandThread = new CommandThread(this);
  85. mPictureThread = new PictureThread(this);
  86. mSnapshotThread = new SnapshotThread(this);
  87. mAutoFocusThread = new AutoFocusThread(this);
  88. mDisplayThread->run("CameraDispThread",ANDROID_PRIORITY_URGENT_DISPLAY);
  89. mPreviewThread->run("CameraPreviewThread",ANDROID_PRIORITY_DISPLAY);
  90. mCommandThread->run("CameraCmdThread", ANDROID_PRIORITY_URGENT_DISPLAY);
  91. mAutoFocusThread->run("CameraAutoFocusThread", ANDROID_PRIORITY_DISPLAY);
  92. mSnapshotThread->run("CameraSnapshotThread", ANDROID_PRIORITY_NORMAL);
  93. LOGD("CameraHal create success!");
  94. } else {
  95. mPreviewThread = NULL;
  96. mDisplayThread = NULL;
  97. mCommandThread = NULL;
  98. mPictureThread = NULL;
  99. mSnapshotThread = NULL;
  100. mAutoFocusThread = NULL;
  101. }
  102. }

初始化时参数的配置,默认参数图片大小,分辨率,帧等:

[cpp] view plaincopy

  1. void CameraHal::initDefaultParameters()
  2. {
  3. CameraParameters params;
  4. String8 parameterString;
  5. int i,j,previewFrameSizeMax;
  6. char cur_param[32],cam_size[10];
  7. char str_picturesize[100];//We support at most 4 resolutions: 2592x1944,2048x1536,1600x1200,1024x768
  8. int ret,picture_size_bit;
  9. struct v4l2_format fmt;
  10. LOG_FUNCTION_NAME
  11. memset(str_picturesize,0x00,sizeof(str_picturesize));
  12. if (CAMERA_IS_UVC_CAMERA()) {
  13. /*preview size setting*/
  14. struct v4l2_frmsizeenum fsize;
  15. memset(&fsize, 0, sizeof(fsize));
  16. picture_size_bit = 0;
  17. fsize.index = 0;
  18. fsize.pixel_format = mCamDriverPreviewFmt;
  19. while ((ret = ioctl(iCamFd, VIDIOC_ENUM_FRAMESIZES, &fsize)) == 0) {
  20. if (fsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
  21. if ((fsize.discrete.width == 320) && (fsize.discrete.height == 240)) {
  22. if (strcmp(cameraCallProcess,"com.tencent.android.pad") == 0) {
  23. fsize.index++;
  24. continue;
  25. }
  26. }
  27. memset(cam_size,0x00,sizeof(cam_size));
  28. if (parameterString.size() != 0)
  29. cam_size[0]=‘,‘;
  30. sprintf((char*)(&cam_size[strlen(cam_size)]),"%d",fsize.discrete.width);
  31. strcat(cam_size, "x");
  32. sprintf((char*)(&cam_size[strlen(cam_size)]),"%d",fsize.discrete.height);
  33. parameterString.append((const char*)cam_size);
  34. if ((strlen(str_picturesize)+strlen(cam_size))<sizeof(str_picturesize)) {
  35. if (fsize.discrete.width <= 2592) {
  36. strcat(str_picturesize, cam_size);
  37. if (fsize.discrete.width > mCamDriverFrmWidthMax) {
  38. mCamDriverFrmWidthMax = fsize.discrete.width;
  39. mCamDriverFrmHeightMax = fsize.discrete.height;
  40. }
  41. }
  42. } else {
  43. break;
  44. }
  45. } else if (fsize.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
  46. break;
  47. } else if (fsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
  48. break;
  49. }
  50. fsize.index++;
  51. }
  52. if (ret != 0 && errno != EINVAL) {
  53. LOGE("ERROR enumerating frame sizes: %d\n", errno);
  54. }
  55. params.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, parameterString.string());
  56. params.setPreviewSize(640,480);
  57. /*picture size setting*/
  58. params.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, str_picturesize);
  59. params.setPictureSize(mCamDriverFrmWidthMax,  mCamDriverFrmHeightMax);
  60. if (mCamDriverFrmWidthMax <= 1024) {
  61. mRawBufferSize = RAW_BUFFER_SIZE_1M;
  62. mJpegBufferSize = JPEG_BUFFER_SIZE_1M;
  63. } else if (mCamDriverFrmWidthMax <= 1600) {
  64. mRawBufferSize = RAW_BUFFER_SIZE_2M;
  65. mJpegBufferSize = JPEG_BUFFER_SIZE_2M;
  66. } else if (mCamDriverFrmWidthMax <= 2048) {
  67. mRawBufferSize = RAW_BUFFER_SIZE_3M;
  68. mJpegBufferSize = JPEG_BUFFER_SIZE_3M;
  69. } else if (mCamDriverFrmWidthMax <= 2592) {
  70. mRawBufferSize = RAW_BUFFER_SIZE_5M;
  71. mJpegBufferSize = JPEG_BUFFER_SIZE_5M;
  72. } else {
  73. LOGE("%s(%d):Camera Hal is only support 5Mega camera, but the uvc camera is %dx%d",
  74. __FUNCTION__,__LINE__,mCamDriverFrmWidthMax, mCamDriverFrmHeightMax);
  75. mRawBufferSize = RAW_BUFFER_SIZE_5M;
  76. mJpegBufferSize = JPEG_BUFFER_SIZE_5M;
  77. }
  78. /* set framerate */
  79. struct v4l2_streamparm setfps;
  80. memset(&setfps, 0, sizeof(struct v4l2_streamparm));
  81. setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  82. setfps.parm.capture.timeperframe.numerator=1;
  83. setfps.parm.capture.timeperframe.denominator=15;
  84. ret = ioctl(iCamFd, VIDIOC_S_PARM, &setfps);
  85. /*frame rate setting*/
  86. params.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, "15");
  87. params.setPreviewFrameRate(15);
  88. /*frame per second setting*/
  89. parameterString = "15000,15000";
  90. params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, parameterString.string());
  91. parameterString = "(15000,15000)";
  92. params.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, parameterString.string());
  93. /*not support zoom */
  94. params.set(CameraParameters::KEY_ZOOM_SUPPORTED, "false");
  95. } else if (CAMERA_IS_RKSOC_CAMERA()) {
  96. fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  97. fmt.fmt.pix.pixelformat= mCamDriverPreviewFmt;
  98. fmt.fmt.pix.field = V4L2_FIELD_NONE;
  99. /*picture size setting*/
  100. fmt.fmt.pix.width = 10000;
  101. fmt.fmt.pix.height = 10000;
  102. ret = ioctl(iCamFd, VIDIOC_TRY_FMT, &fmt);
  103. mCamDriverFrmWidthMax = fmt.fmt.pix.width;
  104. mCamDriverFrmHeightMax = fmt.fmt.pix.height;
  105. if (mCamDriverFrmWidthMax > 2592) {
  106. LOGE("Camera driver support maximum resolution(%dx%d) is overflow 5Mega!",mCamDriverFrmWidthMax,mCamDriverFrmHeightMax);
  107. mCamDriverFrmWidthMax = 2592;
  108. mCamDriverFrmHeightMax = 1944;
  109. }
  110. /*preview size setting*/
  111. if (mCamDriverFrmWidthMax >= 176) {
  112. fmt.fmt.pix.width = 176;
  113. fmt.fmt.pix.height = 144;
  114. if (ioctl(iCamFd, VIDIOC_TRY_FMT, &fmt) == 0) {
  115. if ((fmt.fmt.pix.width == 176) && (fmt.fmt.pix.height == 144)) {
  116. parameterString.append("176x144");
  117. params.setPreviewSize(176, 144);
  118. previewFrameSizeMax =  PAGE_ALIGN(176*144*2)*2;          // 176*144*2     rgb565
  119. //params.set(CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO,"176x144");
  120. }
  121. }
  122. }
  123. if ((mCamDriverCapability.version & 0xff) >= 0x07) {
  124. int tmp0,tmp1;
  125. if (cameraFramerateQuery(mCamDriverPreviewFmt, 240,160,&tmp1,&tmp0) == 0) {
  126. if (mCamDriverFrmWidthMax >= 240) {
  127. fmt.fmt.pix.width = 240;
  128. fmt.fmt.pix.height = 160;
  129. if (ioctl(iCamFd, VIDIOC_TRY_FMT, &fmt) == 0) {
  130. if ((fmt.fmt.pix.width == 240) && (fmt.fmt.pix.height == 160)) {
  131. parameterString.append(",240x160");
  132. params.setPreviewSize(240, 160);
  133. previewFrameSizeMax =  PAGE_ALIGN(240*160*2)*2;          // 240*160*2     rgb565
  134. }
  135. }
  136. }
  137. }
  138. }
  139. if (strcmp(cameraCallProcess,"com.tencent.android.pad")) {
  140. if (mCamDriverFrmWidthMax >= 320) {
  141. fmt.fmt.pix.width = 320;
  142. fmt.fmt.pix.height = 240;
  143. if (ioctl(iCamFd, VIDIOC_TRY_FMT, &fmt) == 0) {
  144. if ((fmt.fmt.pix.width == 320) && (fmt.fmt.pix.height == 240)) {
  145. parameterString.append(",320x240");
  146. params.setPreviewSize(320, 240);
  147. previewFrameSizeMax =  PAGE_ALIGN(320*240*2)*2;          // 320*240*2
  148. }
  149. }
  150. }
  151. }
  152. if (mCamDriverFrmWidthMax >= 352) {
  153. fmt.fmt.pix.width = 352;
  154. fmt.fmt.pix.height = 288;
  155. if (ioctl(iCamFd, VIDIOC_TRY_FMT, &fmt) == 0) {
  156. if ((fmt.fmt.pix.width == 352) && (fmt.fmt.pix.height == 288)) {
  157. parameterString.append(",352x288");
  158. params.setPreviewSize(352, 288);
  159. previewFrameSizeMax =  PAGE_ALIGN(352*288*2)*2;          // 352*288*1.5*2
  160. }
  161. }
  162. }
  163. if (mCamDriverFrmWidthMax >= 640) {
  164. fmt.fmt.pix.width = 640;
  165. fmt.fmt.pix.height = 480;
  166. if (ioctl(iCamFd, VIDIOC_TRY_FMT, &fmt) == 0) {
  167. if ((fmt.fmt.pix.width == 640) && (fmt.fmt.pix.height == 480)) {
  168. parameterString.append(",640x480");
  169. params.setPreviewSize(640, 480);
  170. previewFrameSizeMax =  PAGE_ALIGN(640*480*2)*2;          // 640*480*1.5*2
  171. }
  172. }
  173. }
  174. if (mCamDriverFrmWidthMax >= 720) {
  175. fmt.fmt.pix.width = 720;
  176. fmt.fmt.pix.height = 480;
  177. if (ioctl(iCamFd, VIDIOC_TRY_FMT, &fmt) == 0) {
  178. if ((fmt.fmt.pix.width == 720) && (fmt.fmt.pix.height == 480)) {
  179. parameterString.append(",720x480");
  180. previewFrameSizeMax =  PAGE_ALIGN(720*480*2)*2;          // 720*480*1.5*2
  181. }
  182. }
  183. }
  184. if (mCamDriverFrmWidthMax >= 1280) {
  185. fmt.fmt.pix.width = 1280;
  186. fmt.fmt.pix.height = 720;
  187. if (ioctl(iCamFd, VIDIOC_TRY_FMT, &fmt) == 0) {
  188. if ((fmt.fmt.pix.width == 1280) && (fmt.fmt.pix.height == 720)) {
  189. parameterString.append(",1280x720");
  190. previewFrameSizeMax =  PAGE_ALIGN(1280*720*2)*2;          // 1280*720*1.5*2
  191. }
  192. }
  193. }
  194. mSupportPreviewSizeReally = parameterString;
  195. /* [email protected]: Facelock speed is low, so scale down preview data to facelock for speed up */
  196. if ((strcmp(cameraCallProcess,"com.android.facelock")==0)) {
  197. if (strstr(mSupportPreviewSizeReally.string(),"640x480")||
  198. strstr(mSupportPreviewSizeReally.string(),"320x240")) {
  199. parameterString = "160x120";
  200. params.setPreviewSize(160, 120);
  201. }
  202. }
  203. params.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, parameterString.string());
  204. strcat(str_picturesize,parameterString.string());
  205. strcat(str_picturesize,",");
  206. if(mCamDriverFrmWidthMax <= 640){
  207. strcat( str_picturesize,"640x480,320x240");
  208. mRawBufferSize = RAW_BUFFER_SIZE_0M3;
  209. mJpegBufferSize = JPEG_BUFFER_SIZE_0M3;
  210. params.setPictureSize(640,480);
  211. }else if (mCamDriverFrmWidthMax <= 1280) {
  212. strcat( str_picturesize,"1024x768,640x480,320x240");
  213. mRawBufferSize = RAW_BUFFER_SIZE_1M;
  214. mJpegBufferSize = JPEG_BUFFER_SIZE_1M;
  215. params.setPictureSize(1024,768);
  216. } else if (mCamDriverFrmWidthMax <= 1600) {
  217. strcat( str_picturesize,"1600x1200,1024x768,640x480");
  218. mRawBufferSize = RAW_BUFFER_SIZE_2M;
  219. mJpegBufferSize = JPEG_BUFFER_SIZE_2M;
  220. params.setPictureSize(1600,1200);
  221. } else if (mCamDriverFrmWidthMax <= 2048) {
  222. strcat( str_picturesize,"2048x1536,1600x1200,1024x768");
  223. mRawBufferSize = RAW_BUFFER_SIZE_3M;
  224. mJpegBufferSize = JPEG_BUFFER_SIZE_3M;
  225. params.setPictureSize(2048,1536);
  226. } else if (mCamDriverFrmWidthMax <= 2592) {
  227. strcat( str_picturesize,"2592x1944,2048x1536,1600x1200,1024x768");
  228. params.setPictureSize(2592,1944);
  229. mRawBufferSize = RAW_BUFFER_SIZE_5M;
  230. mJpegBufferSize = JPEG_BUFFER_SIZE_5M;
  231. } else {
  232. sprintf(str_picturesize, "%dx%d", mCamDriverFrmWidthMax,mCamDriverFrmHeightMax);
  233. mRawBufferSize = RAW_BUFFER_SIZE_5M;
  234. mJpegBufferSize = JPEG_BUFFER_SIZE_5M;
  235. params.setPictureSize(mCamDriverFrmWidthMax,mCamDriverFrmHeightMax);
  236. }
  237. params.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, str_picturesize);
  238. /*frame rate setting*/
  239. cameraFpsInfoSet(params);
  240. /*zoom setting*/
  241. struct v4l2_queryctrl zoom;
  242. char str_zoom_max[3],str_zoom_element[5];
  243. char str_zoom[200];
  244. strcpy(str_zoom, "");//default zoom
  245. int max;
  246. zoom.id = V4L2_CID_ZOOM_ABSOLUTE;
  247. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &zoom)) {
  248. mZoomMax = zoom.maximum;
  249. mZoomMin= zoom.minimum;
  250. mZoomStep = zoom.step;
  251. max = (mZoomMax - mZoomMin)/mZoomStep;
  252. sprintf(str_zoom_max,"%d",max);
  253. params.set(CameraParameters::KEY_ZOOM_SUPPORTED, "true");
  254. params.set(CameraParameters::KEY_MAX_ZOOM, str_zoom_max);
  255. params.set(CameraParameters::KEY_ZOOM, "0");
  256. for (i=mZoomMin; i<=mZoomMax; i+=mZoomStep) {
  257. sprintf(str_zoom_element,"%d,", i);
  258. strcat(str_zoom,str_zoom_element);
  259. }
  260. params.set(CameraParameters::KEY_ZOOM_RATIOS, str_zoom);
  261. }
  262. }
  263. /*preview format setting*/
  264. params.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, "yuv420sp,rgb565,yuv420p");
  265. params.set(CameraParameters::KEY_VIDEO_FRAME_FORMAT,CameraParameters::PIXEL_FORMAT_YUV420SP);
  266. if (strcmp(cameraCallProcess,"com.android.camera")==0) {    //for PanoramaActivity
  267. params.setPreviewFormat(CameraParameters::PIXEL_FORMAT_RGB565);
  268. } else {
  269. params.setPreviewFormat(CameraParameters::PIXEL_FORMAT_YUV420SP);
  270. }
  271. /* [email protected]: preset the displayformat for cts */
  272. strcpy(mDisplayFormat,CAMERA_DISPLAY_FORMAT_NV12);
  273. params.set(CameraParameters::KEY_VIDEO_FRAME_FORMAT,CameraParameters::PIXEL_FORMAT_YUV420SP);
  274. /*picture format setting*/
  275. params.set(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS, CameraParameters::PIXEL_FORMAT_JPEG);
  276. params.setPictureFormat(CameraParameters::PIXEL_FORMAT_JPEG);
  277. /*jpeg quality setting*/
  278. params.set(CameraParameters::KEY_JPEG_QUALITY, "70");
  279. /*white balance setting*/
  280. struct v4l2_queryctrl whiteBalance;
  281. struct v4l2_querymenu *whiteBalance_menu = mWhiteBalance_menu;
  282. char str_whitebalance[200];
  283. strcpy(str_whitebalance, "");//default whitebalance
  284. whiteBalance.id = V4L2_CID_DO_WHITE_BALANCE;
  285. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &whiteBalance)) {
  286. for (i = whiteBalance.minimum; i <= whiteBalance.maximum; i += whiteBalance.step) {
  287. whiteBalance_menu->id = V4L2_CID_DO_WHITE_BALANCE;
  288. whiteBalance_menu->index = i;
  289. if (!ioctl(iCamFd, VIDIOC_QUERYMENU, whiteBalance_menu)) {
  290. if (i != whiteBalance.minimum)
  291. strcat(str_whitebalance, ",");
  292. strcat(str_whitebalance, (char *)whiteBalance_menu->name);
  293. if (whiteBalance.default_value == i) {
  294. strcpy(cur_param, (char *)whiteBalance_menu->name);
  295. }
  296. mWhiteBalance_number++;
  297. }
  298. whiteBalance_menu++;
  299. }
  300. params.set(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE, str_whitebalance);
  301. params.set(CameraParameters::KEY_WHITE_BALANCE, cur_param);
  302. }
  303. /*color effect setting*/
  304. struct v4l2_queryctrl effect;
  305. struct v4l2_querymenu *effect_menu = mEffect_menu;
  306. char str_effect[200];
  307. strcpy(str_effect, "");//default effect
  308. effect.id = V4L2_CID_EFFECT;
  309. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &effect)) {
  310. for (i = effect.minimum; i <= effect.maximum; i += effect.step) {
  311. effect_menu->id = V4L2_CID_EFFECT;
  312. effect_menu->index = i;
  313. if (!ioctl(iCamFd, VIDIOC_QUERYMENU, effect_menu)) {
  314. if (i != effect.minimum)
  315. strcat(str_effect, ",");
  316. strcat(str_effect, (char *)effect_menu->name);
  317. if (effect.default_value == i) {
  318. strcpy(cur_param, (char *)effect_menu->name);
  319. }
  320. mEffect_number++;
  321. }
  322. effect_menu++;
  323. }
  324. params.set(CameraParameters::KEY_SUPPORTED_EFFECTS, str_effect);
  325. params.set(CameraParameters::KEY_EFFECT, cur_param);
  326. }
  327. /*scene setting*/
  328. struct v4l2_queryctrl scene;
  329. struct v4l2_querymenu *scene_menu = mScene_menu;
  330. char str_scene[200];
  331. strcpy(str_scene, "");//default scene
  332. scene.id = V4L2_CID_SCENE;
  333. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &scene)) {
  334. for (i=scene.minimum; i<=scene.maximum; i+=scene.step) {
  335. scene_menu->id = V4L2_CID_SCENE;
  336. scene_menu->index = i;
  337. if (!ioctl(iCamFd, VIDIOC_QUERYMENU, scene_menu)) {
  338. if (i != scene.minimum)
  339. strcat(str_scene, ",");
  340. strcat(str_scene, (char *)scene_menu->name);
  341. if (scene.default_value == i) {
  342. strcpy(cur_param, (char *)scene_menu->name);
  343. }
  344. mScene_number++;
  345. }
  346. scene_menu++;
  347. }
  348. params.set(CameraParameters::KEY_SUPPORTED_SCENE_MODES, str_scene);
  349. params.set(CameraParameters::KEY_SCENE_MODE, cur_param);
  350. }
  351. /*flash mode setting*/
  352. struct v4l2_queryctrl flashMode;
  353. struct v4l2_querymenu *flashMode_menu = mFlashMode_menu;
  354. char str_flash[200];
  355. strcpy(str_flash, "");//default flash
  356. flashMode.id = V4L2_CID_FLASH;
  357. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &flashMode)) {
  358. for (i = flashMode.minimum; i <= flashMode.maximum; i += flashMode.step) {
  359. flashMode_menu->id = V4L2_CID_FLASH;
  360. flashMode_menu->index = i;
  361. if (!ioctl(iCamFd, VIDIOC_QUERYMENU, flashMode_menu)) {
  362. if (i != flashMode.minimum)
  363. strcat(str_flash, ",");
  364. strcat(str_flash, (char *)flashMode_menu->name);
  365. if (flashMode.default_value == i) {
  366. strcpy(cur_param, (char *)flashMode_menu->name);
  367. }
  368. mFlashMode_number++;
  369. }
  370. flashMode_menu++;
  371. }
  372. params.set(CameraParameters::KEY_SUPPORTED_FLASH_MODES, str_flash);
  373. params.set(CameraParameters::KEY_FLASH_MODE, cur_param);
  374. }
  375. /*focus mode setting*/
  376. struct v4l2_queryctrl focus;
  377. parameterString = CameraParameters::FOCUS_MODE_FIXED;
  378. params.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_FIXED);
  379. focus.id = V4L2_CID_FOCUS_AUTO;
  380. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &focus)) {
  381. parameterString.append(",");
  382. parameterString.append(CameraParameters::FOCUS_MODE_AUTO);
  383. params.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_AUTO);
  384. }
  385. focus.id = V4L2_CID_FOCUS_CONTINUOUS;
  386. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &focus)) {
  387. parameterString.append(",");
  388. parameterString.append(CameraParameters::FOCUS_MODE_EDOF);
  389. }
  390. focus.id = V4L2_CID_FOCUS_ABSOLUTE;
  391. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &focus)) {
  392. parameterString.append(",");
  393. parameterString.append(CameraParameters::FOCUS_MODE_INFINITY);
  394. parameterString.append(",");
  395. parameterString.append(CameraParameters::FOCUS_MODE_MACRO);
  396. }
  397. params.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, parameterString.string());
  398. /*mirror and flip query*/
  399. struct v4l2_queryctrl mirror,flip;
  400. mirror.id = V4L2_CID_HFLIP;
  401. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &mirror)) {
  402. mDriverMirrorSupport = true;
  403. } else {
  404. mDriverMirrorSupport = false;
  405. }
  406. flip.id = V4L2_CID_VFLIP;
  407. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &flip)) {
  408. mDriverFlipSupport = true;
  409. } else {
  410. mDriverFlipSupport = false;
  411. }
  412. /*Exposure setting*/
  413. struct v4l2_queryctrl exposure;
  414. char str_exposure[16];
  415. exposure.id = V4L2_CID_EXPOSURE;
  416. if (!ioctl(iCamFd, VIDIOC_QUERYCTRL, &exposure)) {
  417. sprintf(str_exposure,"%d",exposure.default_value);
  418. params.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, str_exposure);
  419. sprintf(str_exposure,"%d",exposure.maximum);
  420. params.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, str_exposure);
  421. sprintf(str_exposure,"%d",exposure.minimum);
  422. params.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, str_exposure);
  423. sprintf(str_exposure,"%d",exposure.step);
  424. params.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, str_exposure);
  425. } else {
  426. params.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, "0");
  427. params.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, "0");
  428. params.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, "0");
  429. params.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, "0.000001f");
  430. }
  431. /*rotation setting*/
  432. params.set(CameraParameters::KEY_ROTATION, "0");
  433. /*[email protected] :add some settings to pass cts*/
  434. /*focus distance setting ,no much meaning ,only for passing cts */
  435. parameterString = "0.3,50,Infinity";
  436. params.set(CameraParameters::KEY_FOCUS_DISTANCES, parameterString.string());
  437. /*focus length setting ,no much meaning ,only for passing cts */
  438. parameterString = "35";
  439. params.set(CameraParameters::KEY_FOCAL_LENGTH, parameterString.string());
  440. /*horizontal angle of view setting ,no much meaning ,only for passing cts */
  441. parameterString = "100";
  442. params.set(CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, parameterString.string());
  443. /*vertical angle of view setting ,no much meaning ,only for passing cts */
  444. parameterString = "100";
  445. params.set(CameraParameters::KEY_VERTICAL_VIEW_ANGLE, parameterString.string());
  446. /*quality of the EXIF thumbnail in Jpeg picture setting */
  447. parameterString = "50";
  448. params.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, parameterString.string());
  449. /*supported size of the EXIF thumbnail in Jpeg picture setting */
  450. parameterString = "0x0,160x128";
  451. params.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, parameterString.string());
  452. parameterString = "160";
  453. params.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, parameterString.string());
  454. parameterString = "128";
  455. params.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, parameterString.string());
  456. /* [email protected]: for cts ,KEY_MAX_NUM_DETECTED_FACES_HW should not be 0 */
  457. params.set(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW, "0");
  458. params.set(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_SW, "0");
  459. params.set(CameraParameters::KEY_RECORDING_HINT,"false");
  460. params.set(CameraParameters::KEY_VIDEO_STABILIZATION_SUPPORTED,"false");
  461. params.set(CameraParameters::KEY_VIDEO_SNAPSHOT_SUPPORTED,"true");
  462. params.set(CameraParameters::KEY_MAX_NUM_METERING_AREAS,"0");
  463. LOGD ("Support Preview format: %s ",params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS));
  464. LOGD ("Support Preview sizes: %s ",params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES));
  465. LOGD ("Support Preview FPS range: %s",params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE));
  466. LOGD ("Support Preview framerate: %s",params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES));
  467. LOGD ("Support Picture sizes: %s ",params.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES));
  468. if (params.get(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE))
  469. LOGD ("Support white balance: %s",params.get(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE));
  470. if (params.get(CameraParameters::KEY_SUPPORTED_EFFECTS))
  471. LOGD ("Support color effect: %s",params.get(CameraParameters::KEY_SUPPORTED_EFFECTS));
  472. if (params.get(CameraParameters::KEY_SUPPORTED_SCENE_MODES))
  473. LOGD ("Support scene: %s",params.get(CameraParameters::KEY_SUPPORTED_SCENE_MODES));
  474. if (params.get(CameraParameters::KEY_SUPPORTED_FLASH_MODES))
  475. LOGD ("Support flash: %s",params.get(CameraParameters::KEY_SUPPORTED_FLASH_MODES));
  476. LOGD ("Support focus: %s",params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES));
  477. LOGD ("Support zoom: %s(ratios: %s)",params.get(CameraParameters::KEY_ZOOM_SUPPORTED),
  478. params.get(CameraParameters::KEY_ZOOM_RATIOS));
  479. if (strcmp("0", params.get(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION))
  480. || strcmp("0", params.get(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION))) {
  481. LOGD ("Support exposure: (%s -> %s)",params.get(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION),
  482. params.get(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION));
  483. }
  484. LOGD ("Support hardware faces detecte: %s",params.get(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW));
  485. LOGD ("Support software faces detecte: %s",params.get(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_SW));
  486. LOGD ("Support video stabilization: %s",params.get(CameraParameters::KEY_VIDEO_STABILIZATION_SUPPORTED));
  487. LOGD ("Support recording hint: %s",params.get(CameraParameters::KEY_RECORDING_HINT));
  488. LOGD ("Support video snapshot: %s",params.get(CameraParameters::KEY_VIDEO_SNAPSHOT_SUPPORTED));
  489. LOGD ("Support Mirror and Filp: %s",(mDriverMirrorSupport && mDriverFlipSupport)? "true":"false");
  490. cameraConfig(params);
  491. LOG_FUNCTION_NAME_EXIT
  492. }

然后剩下的大部分都是针对这个线程的运行实现以及对于CameraHal_Module.cpp中实现的为上层提供的接口的具体实现,比如:

[cpp] view plaincopy

  1. int CameraHal::startPreview()
  2. {
  3. LOG_FUNCTION_NAME
  4. Message msg;
  5. Mutex::Autolock lock(mLock);
  6. if ((mPreviewThread != NULL) && (mCommandThread != NULL)) {
  7. msg.command = CMD_PREVIEW_START;
  8. msg.arg1 = (void*)CMDARG_NACK;
  9. commandThreadCommandQ.put(&msg);
  10. }
  11. mPreviewCmdReceived = true;
  12. LOG_FUNCTION_NAME_EXIT
  13. return NO_ERROR ;
  14. }
  15. void CameraHal::stopPreview()
  16. {
  17. LOG_FUNCTION_NAME
  18. Message msg;
  19. int ret = 0;
  20. Mutex::Autolock lock(mLock);
  21. if ((mPreviewThread != NULL) && (mCommandThread != NULL)) {
  22. msg.command = CMD_PREVIEW_STOP;
  23. msg.arg1 = (void*)CMDARG_ACK;
  24. commandThreadCommandQ.put(&msg);
  25. if (mANativeWindow == NULL) {
  26. mANativeWindowCond.signal();
  27. LOGD("%s(%d): wake up command thread for stop preview",__FUNCTION__,__LINE__);
  28. }
  29. while (ret == 0) {
  30. ret = commandThreadAckQ.get(&msg);
  31. if (ret == 0) {
  32. if (msg.command == CMD_PREVIEW_STOP) {
  33. ret = 1;
  34. }
  35. }
  36. }
  37. } else {
  38. LOGE("%s(%d): cancel, because thread (%s %s) is NULL", __FUNCTION__,__LINE__,(mPreviewThread == NULL)?"mPreviewThread":" ",
  39. (mCommandThread == NULL)?"mCommandThread":" ");
  40. }
  41. mPreviewCmdReceived = false;
  42. LOG_FUNCTION_NAME_EXIT
  43. }
  44. int CameraHal::autoFocus()
  45. {
  46. LOG_FUNCTION_NAME
  47. int ret = 0;
  48. Message msg;
  49. Mutex::Autolock lock(mLock);
  50. if ((mPreviewThread != NULL) && (mCommandThread != NULL)) {
  51. msg.command = CMD_AF_START;
  52. msg.arg1 = (void*)CMDARG_ACK;
  53. commandThreadCommandQ.put(&msg);
  54. while (ret == 0) {
  55. ret = commandThreadAckQ.get(&msg,5000);
  56. if (ret == 0) {
  57. if (msg.command == CMD_AF_START) {
  58. ret = 1;
  59. }
  60. } else {
  61. LOGE("%s(%d): AutoFocus is time out!!!\n",__FUNCTION__,__LINE__);
  62. }
  63. }
  64. } else {
  65. LOGE("%s(%d):  cancel, because thread (%s %s) is NULL", __FUNCTION__,__LINE__,(mPreviewThread == NULL)?"mPreviewThread":" ",
  66. (mCommandThread == NULL)?"mCommandThread":" ");
  67. }
  68. LOG_FUNCTION_NAME_EXIT
  69. return NO_ERROR;
  70. }

[cpp] view plaincopy

    1. <pre name=< span="">"code" class="cpp"><pre name=< span="">"code" class="cpp"><pre name=< span="">"code" class="cpp">
时间: 2024-10-04 16:15:58

Android Camera HAL浅析的相关文章

Android Camera子系统之Linux C应用开发者View

Android Camera HAL通过V4L2接口与内核Camera Driver交互.本文从Linux应用开发者的角度审视Android Camera子系统. V4L2应用开发一般流程: 1. 打开设备文件. int fd=open("/dev/videoX″,O_RDWR); 2.取得设备的capability,看看设备具有什么功能,比如是否具有视频输入,或者音频输入输出等.VIDIOC_QUERYCAP,structv4l2_capability 3.选择视频输入,一个视频设备可以有多个

Qualcomm Camera HAL 2.0

We know that in the HAL Vendor implementation of dynamic to load a name for the camera.$platform$.so file, then to define the load Android HAL, here to Camera HAL 2 and Qualcomm msm8960 for example, an article with before( ). (Note: This article is t

Android Camera预览过程数据流浅析

硬件平台:Atmel SAMA5D3 SoC + OV2640 Camera Sensor Android版本:4.2.2 mediaserver进程是Camera Service的容器进程,它会动态加载Camera HAL和Gralloc HAL. 视频数据帧首先必须从Camera驱动程序到达Camera硬件抽象层. 在Camera硬件抽象层,视频数据帧被从video capture buffer拷贝到gralloc buffer. surfaceflinger进程作为显示服务器会动态加载HW

Android Camera API2.0下全新的Camera FW/HAL架构简述

本文均属自己阅读源码的点滴总结,转账请注明出处谢谢. 欢迎和大家交流.qq:1037701636 email:gzzaigcn2[email protected] Software:系统源码Android5.1 前沿: 前面博文大多少总结的是Camera HAL1到HAL3的系统架构,但这些架构对于Camera APP开发来说依旧还是处于Camera API1.0的标准.而随着Camera3.HAL3.0等的不断更新,Google先是在Framework中更改了整个架构从而去匹配Camera A

Android—Camera Framework C/S架构服务请求

在前一篇文章Camera Client/Server的binder IPC机制中阐述了Android进程间通信binder IPC机制基础,Android Camera基于这个基础设计了Camera Framework Client/Server架构,文中给出了其类图设计.本文从Android 4.4 版本源码入手,分析Camera App向Camera Service请求服务与返回的过程.服务请求的过程从上到下依次要经过三个大的过程:1. Camera App调用Framework Camer

android camera 学习

总体介绍 Android Camera框架从整体上看是一个client/service架构.有两个进程,一个是client进程,可以看成AP端 ,主要包括Java代码和一些native层的c/c++代码:另一个是service进程,属于服务端,是native c/c++代码, 主要负责和linux kernel中的camera driver交互,搜集linux kernel中driver层传上来的数据,并交给显示系统(surface)显示.client 和 service 进程通过Binder机

Android Camera子系统之源代码View

本文基于Android 4.2.2+Linux3.6.9+SAMA5D3 SoC从源代码的角度审视Android Camera子系统. 应用层 Androd原生Camera应用 /system/app/LegacyCamera.apk http://androidxref.com/4.2.2_r1/xref/packages/apps/LegacyCamera/ Camera应用调用Android应用框架提供的Camera API import android.hardware.Camera;

qcom Android Camera【转】

本文转载自:http://blog.csdn.net/Wilsonboliu/article/details/54949196 1.总体架构 Android Camera 框架从整体上看是一个 client/service 的架构, 有两个进程: client 进程,可以看成是 AP 端,主要包括 Java 代码与一些 native c/c++代码; service 进 程,属于服务端,是 native c/c++代码,主要负责和 Linux kernel 中的 camera driver 交互

Android Camera从Camera HAL1到Camera HAL3的过渡

本文均属自己阅读源码的点滴总结,转账请注明出处谢谢. 欢迎和大家交流.qq:1037701636 email:gzzaigcn2[email protected] Software:系统源码Android5.1 1. Android系统中Camera模块版本号的历史演变进度 /** * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated * as CAMERA_MODULE_API_VERSION