1.java调用
frameworks/base/core/java/android/hardware/Camera.java
+open(int cameraId)
+Camera(int cameraId) //new Camera()调用构造
+native_setup(new WeakReference
2.jni调用(libandroid_runtime.so)
frameworks/base/core/jni/android_hardware_Camera.cpp
+android_hardware_Camera_native_setup(...) //调用此方法
frameworks/av/include/camera/Camera.h //camera头文件,方法实现在libcamera_client.so
+Camera::connect()
注:之所以能调用上述方法,是通过AndroidRuntime::registerNativeMethods(...) 注册了native_setup参数和方法android_hardware_Camera_native_setup的对应关系
{ "native_setup",
"(Ljava/lang/Object;ILjava/lang/String;)V",
(void*)android_hardware_Camera_native_setup },
第二行参数引用参数类型表示(L包名),I表示 jint,V表示void,即参数类型为:(Object,int,String)void
libandroid_runtime.so 将目录文件 frameworks/av/include编译进去了,所以Camera.h位于frameworks/av/include/camera/Camera.h
3.camera客户端调用(libcamera_client.so) **
frameworks/av/camera/Camera.cpp //mk如何引用Camera.h?
+Camera::connect() //定义方法
frameworks/av/camera/CameraBase.cpp
+CameraBase
+CameraBase
binder = sm->getService(String16(kCameraServiceName)); //根据camera服务字符串,获取对应的binder对象
gCameraService = interface_cast
TCamConnectService fnConnectService = TCamTraits::fnConnectService;
frameworks/av/camera/Camera.cpp
CameraTraits
4.camera服务端调用(libcameraservice.so)
frameworks/av/services/camera/libcameraservice/CameraService.cpp //通过binder调用
+CameraService::connect()
5.hal open 调用
5.1 hardware/libhardware/include/hardware/hardware.h
typedef struct hw_module_t {
struct hw_module_methods_t* methods;
} hw_module_t;
typedef struct hw_module_methods_t {
/** Open a specific device */
int (*open)(const struct hw_module_t* module, const char* id,
struct hw_device_t** device);
} hw_module_methods_t;
5.2 hardware/qcom/camera/QCamera/HAL2/wrapper/QualcommCamera.cpp
static hw_module_methods_t camera_module_methods = {
open: camera_device_open,
};
open 方法被赋值为camera_device_open
hardware/qcom/camera/QCamera2/HAL/wrapper/QualcommCamera.cpp
+camera_device_open() //调用open方法
camHal->hardware = new QCamera2HardwareInterface(cameraId);
5.3 hardware/qcom/camera/QCamera2/HAL/QCamera2HWI.cpp
QCamera2HardwareInterface::QCamera2HardwareInterface(int cameraId) //构造函数
调用?
mCameraHandle=camera_open(mCameraId, &mem_hooks);
+camera_open(mCameraId);
5.4
hardware/qcom/camera/QCamera2/stack/mm-camera-interface/src/mm_camera_interface.c
+camera_open(uint8_t camera_idx)
5.5
hardware/qcom/camera/QCamera2/stack/mm-camera-interface/src/mm_camera.c
+mm_camera_open(mm_camera_obj_t *my_obj)
+open(dev_name, O_RDWR | O_NONBLOCK)
这个将调用系统调用open的方法,打开设备节点dev/video0(后置相机),/dev/video2(前置相机),这个顺序是和内核在启动的是和video的注册顺序相关的。
6.kernel 驱动最终调用
kernel/drivers/media/platform/msm/camera_v2/msm.c
msm_open(struct file *filep)
v4l2_fh_open