-、AndroID app
private Camera mCamera; <<==========>> frameworks/base/core/java/androID/harDWare/Camera.java
Camera.getNumberOfCameras();<<==========>> frameworks/base/core/jni/androID_harDWare_Camera.cpp
二、androID_harDWare_Camera.cpp 调用的是 Camera.cpp 里面的方法 <<==========>>frameworks/av/camera/Camera.cpp
我们看看Camera 这个类的定义
class Camera :public CameraBase<Camera>,
public ::androID::harDWare::BnCameraClIEnt
{
.....
}
这个类继承与CameraBase 和 BnCameraClIEnt
三、我们看 CameraBase 这个类的定义
template <typename TCam, typename TCamTraits = CameraTraits<TCam> >
class CameraBase : public IBinder::DeathRecipIEnt
{
.......
}
这是一个模板类该类继承于 IBinder::DeathRecipIEnt 而 IBinder::DeathRecipIEnt 继承于 public virtual RefBase hal层的智能指针
static jint androID_harDWare_Camera_getNumberOfCameras(jnienv *env, jobject thiz)
{
return Camera::getNumberOfCameras();
}
这个方法的最终实现是在CameraBase里面
我们再看看CameraBase这个类的方法实现 <<==========>> frameworks/av/camera/CameraBase.cpp
template <typename TCam, typename TCamTraits>
int CameraBase<TCam, TCamTraits>::getNumberOfCameras() {
const sp<::androID::harDWare::ICameraService> cs = getCameraService();
if (!cs.get()) {
// as required by the public Java APIs
return 0;
}
int32_t count;
binder::Status res = cs->getNumberOfCameras(
::androID::harDWare::ICameraService::CAMERA_TYPE_BACKWARD_COMPATIBLE,
&count);
if (!res.isOk()) {
ALOGE("Error reading number of cameras: %s",
res.toString8().string());
count = 0;
}
return count;
}
我们发现该方法最终调用了getCameraService 方法来获取了CameraService 服务。再继续跟踪代码,
template <typename TCam, typename TCamTraits>
const sp<::androID::harDWare::ICameraService> CameraBase<TCam, TCamTraits>::getCameraService()
{
Mutex::autolock _l(gLock);
if (gCameraService.get() == 0) {
char value[PROPERTY_VALUE_MAX];
property_get("config.disable_cameraservice", value, "0");
if (strncmp(value, "0", 2) != 0 && strncasecmp(value, "false", 6) != 0) {
return gCameraService;
}
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder;
do {
binder = sm->getService(String16(kCameraServicename));
if (binder != 0) {
break;
}
ALOGW("CameraService not published, waiting...");
usleep(kCameraServicePollDelay);
} while(true);
if (gDeathNotifIEr == NulL) {
gDeathNotifIEr = new DeathNotifIEr();
}
binder->linkToDeath(gDeathNotifIEr);
gCameraService = interface_cast<::androID::harDWare::ICameraService>(binder);
}
ALOGE_IF(gCameraService == 0, "no CameraService!?");
return gCameraService;
}
我们发现 getCameraService 方法返回了一个静态全局指针 gCameraService 继续查找 gCameraService 的声明与初始化,
发现在 CameraService.cpp 里面初始化 <<==========>> frameworks/av/services/camera/libcameraservice/CameraService.cpp
static CameraService *gCameraService;
CameraService::CameraService() :
mEventLog(DEFAulT_EVENT_LOG_LENGTH),
mNumberOfCameras(0), mNumberOfnormalCameras(0),
mSoundRef(0), mModule(nullptr) {
ALOGI("CameraService started (pID=%d)", getpID());
gCameraService = this;
this->camera_device_status_change = androID::camera_device_status_change;
this->torch_mode_status_change = androID::torch_mode_status_change;
mServiceLockWrapper = std::make_shared<WaitableMutexWrapper>(&mServiceLock);
}
而 CameraServic的初始化是在androID开机的时候就启动了的这个服务,这个我们后续再详细讲解。
我们继续跟踪代码 cs->getNumberOfCameras(::androID::harDWare::ICameraService::CAMERA_TYPE_BACKWARD_COMPATIBLE,&count);
此方法的实现为
Status CameraService::getNumberOfCameras(int32_t type, int32_t* numCameras) {
ATRACE_CALL();
switch (type) {
case CAMERA_TYPE_BACKWARD_COMPATIBLE:
if(0 == mNumberOfnormalCameras) {
ALOGE("No camera be found ! check again...");
onFirstRef();
}
*numCameras = mNumberOfnormalCameras;
break;
case CAMERA_TYPE_ALL:
*numCameras = mNumberOfCameras;
break;
default:
ALOGW("%s: UnkNown camera type %d",
__FUNCTION__, type);
return STATUS_ERROR_FMT(ERROR_ILLEgal_ARGUMENT,
"UnkNown camera type %d", type);
}
return Status::ok();
}
如果开机阶段没有找到Camera 这里会从新再找一次。 我们假设这里没有找到camera 继续跟踪代码。 跟踪onFirstRef();
进入 onFirstRef();我们跟踪 hw_get_module()方法。 <<==========>> harDWare/libharDWare$
int hw_get_module(const char *ID, const struct hw_module_t **module)
{
return hw_get_module_by_class(ID, NulL, module);
}
hw_get_module()方法只是对 hw_get_module_by_class(ID, NulL, module)方法的一种封装,
未完待续.......
以上是内存溢出为你收集整理的Rk3399 android7.1 camera 分析全部内容,希望文章能够帮你解决Rk3399 android7.1 camera 分析所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)