Underlying logic of camera's native code

我们两清 提交于 2019-12-10 15:56:43

问题


I'm trying to better understand the underlying logic of camera's native code, but I appear to be hitting a dead-end when looking for the method definition for Camera::connect() and other functions declared from Camera.h.

The steps I've followed are these:

  1. In the master branch I located Camera.java, which contains the logic for resolving cameras, selecting CameraInfo.CAMERA_FACING_BACK when it is encountered:
    • Camera.open() calls Camera.getCameraInfo(int, CameraInfo) for each int in Camera.getNumberOfCameras().
    • Camera.getCameraInfo(int, CameraInfo) in turn calls the native function Camera._getCameraInfo(int, CameraInfo).
  2. Delving into the JNI:

    • android_hardware_Camera_getCameraInfo(JNIEnv*, jobject, jint, jobject) then invokes the static method Camera::getCameraInfo(jint, CameraInfo*), which appears to be declared through:

      #include <camera/Camera.h>
      
  3. Browsing and searching the master branch doesn't seem to give any hits for camera/Camera.h. The only result I could find was in older tags, for instance in the gingerbread branch. Here there's only a method declaration:

    static  status_t    getCameraInfo(int cameraId,
                                  struct CameraInfo* cameraInfo);
    
  4. However, the method body doesn't appear to be defined anywhere.

The last two steps are where I am confused. Where is camera/Camera.h defined for more recent versions of Android? And finally, where are the method bodies of Camera actually defined?


回答1:


In ICS, the Camera::getCameraInfo(jint, CameraInfo*) is defined in frameworks/av/camera/Camera.cpp as

status_t Camera::getCameraInfo(int cameraId,
                               struct CameraInfo* cameraInfo) {
    const sp<ICameraService>& cs = getCameraService();
    if (cs == 0) return UNKNOWN_ERROR;
    return cs->getCameraInfo(cameraId, cameraInfo);
}

Then it grabs a binder object of CameraService and call the getCameraInfo on CameraService.

status_t CameraService::getCameraInfo(int cameraId,
                                      struct CameraInfo* cameraInfo) {
    ...
    struct camera_info info;
    status_t rc = mModule->get_camera_info(cameraId, &info);
    ...
    return rc;
}

The mModule contains the actual implementation of camera on your device. Different devices may have different implementations. For example you can find QualcommCamera under hardware/qcom/camera/QualcommCamera.cpp.

Then take a look at connect. The connect does a similar work and finally calls CameraService::connect. In that method, there is a CameraClient initialized by the mModule. So when you do something with the Client, you are actually working with the device-specific implementation.

One more word, the mModule is initialized by hw_get_module in CameraService::onFirstRef.




回答2:


It seems that after Gingerbread, some code moved to a different framework. I located camera/Camera.h in the platform/frameworks/av repository.

I found the definition of the method body in Camera.cpp.



来源:https://stackoverflow.com/questions/15863203/underlying-logic-of-cameras-native-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!