和你一起终身学习,这里是程序员Android
经典好文推荐,通过阅读本文,您将收获以下知识点:
一、Camx 代码结构
二、Camx 编译
三、Camx 代码流程分析
四、Camx 调试
一、Camx 代码结构
目前主流的机型都使用camx架构,这个架构和之前架构的主要区别就是 芯片接口层的代码从hardware/qcom
迁移到 vendor/qcom/proprietary/
下面,我们主要关注的camera hal层的源码也是放在vendor/qcom/proprietary/camx/
下面。
1.1 camera 相关代码目录
二、camx 编译
camx的核心目录是 vendor/qcom/proprietary/camx/src/
目录下面:
total 40
drwxrwxr-x 10 lxl lxl 4096 4月 4 10:52 ./
drwxrwxr-x 4 lxl lxl 4096 4月 4 10:52 ../
drwxrwxr-x 3 lxl lxl 4096 4月 4 10:52 chiiqutils/
drwxrwxr-x 7 lxl lxl 4096 4月 4 10:56 core/
drwxrwxr-x 7 lxl lxl 4096 4月 4 10:52 csl/
drwxrwxr-x 14 lxl lxl 4096 4月 4 10:52 hwl/
drwxrwxr-x 3 lxl lx 4096 4月 4 10:52 lib/
drwxrwxr-x 3 lxl lxl 4096 4月 4 10:52 osutils/
drwxrwxr-x 11 lxl lxl 4096 4月 4 10:52 swl/
drwxrwxr-x 3 lxl lxl 4096 4月 4 10:52 utils/
核心的Android.mk在 ./lib/build/android/Android.mk
中。
其中包括的静态库如下:
# Libraries to link
LOCAL_STATIC_LIBRARIES := \
libcamxcore \
libcamxchi \
libcamxcsl \
libcamxofflinestats \
libnc \
libcamxncs \
libifestriping \
libstriping
LOCAL_WHOLE_STATIC_LIBRARIES := \
libcamxdspstreamer \
libcamxhwlbps \
libcamxgenerated \
libcamxhal \
libcamxhalutils \
libcamxhwlfd \
libcamxhwlife \
libcamxhwlipe \
libcamxhwliqmodule \
libcamxswlfdmanager \
libcamxswljpeg \
libcamxhwljpeg \
libcamxhwllrme \
libcamxswlransac \
libcamxhwltitan17x \
libcamxiqsetting \
libcamxosutils \
libcamxstats \
libcamxsensor \
libcamxutils
这些静态库都是camx或者其他的目录下编译的,编译工程的时候,我们要先编译这些静态库,然后编译camx的动态库(/vendor/lib/hw/camera.qcom.so
)。
三、camx 代码流程分析
camera.provider中如何实现到camera hal层的跳跃,camera service调用到camera provider中的接口方法,现在调用到 camera provider中的 hardware/interfaces/camera/device/3.2/default/CameraDeviceSession.cpp
中的processCaptureRequest(...)
方法,最终会调用到:
status_t ret = mDevice->ops->process_capture_request(mDevice, &halRequest);
这个mDevice->ops 就是 hardware/libhardware/include/hardware/camera3.h
中的 camera3_device_ops 结构体: (参考:https://www.jianshu.com/p/099cc3b0ab25)
typedef struct camera3_device_ops {
int (*initialize)(const struct camera3_device *,
const camera3_callback_ops_t *callback_ops);
int (*configure_streams)(const struct camera3_device *,
camera3_stream_configuration_t *stream_list);
int (*register_stream_buffers)(const struct camera3_device *,
const camera3_stream_buffer_set_t *buffer_set);
const camera_metadata_t* (*construct_default_request_settings)(
const struct camera3_device *,
int type);
int (*process_capture_request)(const struct camera3_device *,
camera3_capture_request_t *request);
void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
vendor_tag_query_ops_t* ops);
void (*dump)(const struct camera3_device *, int fd);
int (*flush)(const struct camera3_device *);
/* reserved for future use */
void *reserved[8];
} camera3_device_ops_t;
camera3_device_ops_t 映射函数指针操作: hardware/libhardware/modules/camera/3_0/Camera.cpp
const camera3_device_ops_t Camera::sOps = {
.initialize = default_camera_hal::initialize,
.configure_streams = default_camera_hal::configure_streams,
.register_stream_buffers = default_camera_hal::register_stream_buffers,
.construct_default_request_settings
= default_camera_hal::construct_default_request_settings,
.process_capture_request = default_camera_hal::process_capture_request,
.get_metadata_vendor_tag_ops = NULL,
.dump = default_camera_hal::dump,
.flush = default_camera_hal::flush,
.reserved = {0},
};
这样找到在camera hal层的函数指针的映射关系。
映射到:vendor/qcom/proprietary/camx/src/core/hal/camxhal3entry.cpp
中的static Dispatch g_dispatchHAL3(&g_jumpTableHAL3);
:
/// Array containing camera3_device_ops_t methods
static camera3_device_ops_t g_camera3DeviceOps =
{
CamX::initialize,
CamX::configure_streams,
NULL,
CamX::construct_default_request_settings,
CamX::process_capture_request,
NULL,
CamX::dump,
CamX::flush,
{0},
};
定义了g_camera3DeviceOps变量:
/// Array containing camera3_device_ops_t methods
static camera3_device_ops_t g_camera3DeviceOps =
{
CamX::initialize,
CamX::configure_streams,
NULL,
CamX::construct_default_request_settings,
CamX::process_capture_request,
NULL,
CamX::dump,
CamX::flush,
{0},
};
并在\vendor\qcom\proprietary\camx\src\core\hal\camxhaldevice.cpp
的Initialize方法中通过GetCamera3DeviceOps获取,建立联系:
CamxResult HALDevice::Initialize(
const HwModule* pHwModule,
UINT32 cameraId)
{