欢迎来到天天文库
浏览记录
ID:48011846
大小:217.74 KB
页数:20页
时间:2020-01-14
《Android 5.0 Camera系统源码分析(2):Camera打开流程.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Android5.0Camera系统源码分析(2):Camera打开流程1.前言本文将分析Android系统源码,从frameworks层到hal层,暂不涉及app层和kernel层。由于某些函数比较复杂,在贴出代码时会适当对其进行简化。本文属于自己对源码的总结,仅仅是贯穿代码流程,不会深入分析各个细节。欢迎联系讨论,QQ:10266568282.app层从apk开始,简单列出各个入口函数[cpp]viewplaincopyprivatevoidinitCamera(){CameramCamera=Camera.open();Camera.ParametersmParameters=mCam
2、era.getParameters();mParameters.setPictureFormat(PixelFormat.JPEG);mCamera.setParameters(mParameters);mCamera.setPreviewDisplay(mSurfaceHolder);mCamera.startPreview();mCamera.takePicture(null,null,mJpegCallback);}3.frameworks层这里将重点介绍Camera.open函数,其余函数将在后续博文分析。先来看看Camera.open函数在frameworks层的实现,代码路径为:
3、frameworks/base/core/java/android/hardware/Camera.java[cpp]viewplaincopypublicstaticCameraopen(){if(!isPermissionGranted()){returnnull;}intnumberOfCameras=getNumberOfCameras();CameraInfocameraInfo=newCameraInfo();for(inti=0;i4、meraInfo.CAMERA_FACING_BACK){returnnewCamera(i);}}returnnull;}第5行,通过getNumberOfCameras函数来获取Camera的个数。从上一篇博文CameraService的启动流程可以看出,这个信息保存在CameraService中。第10行,需重点关注,构造一个Camera对象,并将它返回给app层。3.1getNumberOfCameras函数分析getNumberOfCameras函数进入到CameraService获取Camera个数的流程如下:Camera.Java调用的getNumberOfCameras函数是5、一个JNI接口,对应的函数是android_hardware_Camera.cpp里的android_hardware_Camera_getNumberOfCameras函数[cpp]viewplaincopystaticjintandroid_hardware_Camera_getNumberOfCameras(JNIEnv*env,jobjectthiz){returnCamera::getNumberOfCameras();}这里只是简单调用了Camera.cpp的getNumberOfCameras函数,Camera继承了CameraBase,该函数由它实现[cpp]viewplai6、ncopytemplateintCameraBase::getNumberOfCameras(){constspcs=getCameraService();returncs->getNumberOfCameras();}第3行,getCameraService函数用来获取ICameraService的Bp端,代码实现如下[cpp]viewplaincopyconstchar*kCameraServiceName="media.camera";template7、ypenameTCam,typenameTCamTraits>constsp&CameraBase::getCameraService(){if(gCameraService.get()==0){spsm=defaultServiceManager();spbinder;binder=sm->
4、meraInfo.CAMERA_FACING_BACK){returnnewCamera(i);}}returnnull;}第5行,通过getNumberOfCameras函数来获取Camera的个数。从上一篇博文CameraService的启动流程可以看出,这个信息保存在CameraService中。第10行,需重点关注,构造一个Camera对象,并将它返回给app层。3.1getNumberOfCameras函数分析getNumberOfCameras函数进入到CameraService获取Camera个数的流程如下:Camera.Java调用的getNumberOfCameras函数是
5、一个JNI接口,对应的函数是android_hardware_Camera.cpp里的android_hardware_Camera_getNumberOfCameras函数[cpp]viewplaincopystaticjintandroid_hardware_Camera_getNumberOfCameras(JNIEnv*env,jobjectthiz){returnCamera::getNumberOfCameras();}这里只是简单调用了Camera.cpp的getNumberOfCameras函数,Camera继承了CameraBase,该函数由它实现[cpp]viewplai
6、ncopytemplateintCameraBase::getNumberOfCameras(){constspcs=getCameraService();returncs->getNumberOfCameras();}第3行,getCameraService函数用来获取ICameraService的Bp端,代码实现如下[cpp]viewplaincopyconstchar*kCameraServiceName="media.camera";template7、ypenameTCam,typenameTCamTraits>constsp&CameraBase::getCameraService(){if(gCameraService.get()==0){spsm=defaultServiceManager();spbinder;binder=sm->
7、ypenameTCam,typenameTCamTraits>constsp&CameraBase::getCameraService(){if(gCameraService.get()==0){spsm=defaultServiceManager();spbinder;binder=sm->
此文档下载收益归作者所有