Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3029197
  • 博文数量: 396
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 4209
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-04 13:04
文章分类

全部博文(396)

文章存档

2022年(1)

2021年(2)

2020年(8)

2019年(24)

2018年(135)

2017年(158)

2016年(68)

我的朋友

分类: Android平台

2021-05-19 13:35:58

camera HAL层数据结构非常多,看代码的时候常常为了了解这些数据结构找半天,为了方便大家学习,特地总结了一些数据结构以及这些数据结构的位置:

1.hardware/libhardware/include/hardware/camera_common.h:

1.1 camera_info_t : camera_info

  1. typedef struct camera_info {
  2. int facing;
  3. int orientation;
  4. uint32_t device_version;
  5. const camera_metadata_t *static_camera_characteristics;
  6. int resource_cost;
  7. char** conflicting_devices;
  8. size_t conflicting_devices_length;
  9. } camera_info_t;

1.2 camera_device_status_t : camera_device_status

  1. typedef enum camera_device_status {
  2. CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
  3. CAMERA_DEVICE_STATUS_PRESENT = 1,
  4. CAMERA_DEVICE_STATUS_ENUMERATING = 2,
  5. } camera_device_status_t;

1.3 torch_mode_status_t : torch_mode_status

  1. typedef enum torch_mode_status {
  2. TORCH_MODE_STATUS_NOT_AVAILABLE = 0,
  3. TORCH_MODE_STATUS_AVAILABLE_OFF = 1,
  4. TORCH_MODE_STATUS_AVAILABLE_ON = 2,
  5. } torch_mode_status_t;

1.4 camera_module_callbacks_t : camera_module_callbacks

  1. typedef struct camera_module_callbacks {
  2. void (*camera_device_status_change)(const struct camera_module_callbacks*,
  3. int camera_id,
  4. int new_status);
  5. void (*torch_mode_status_change)(const struct camera_module_callbacks*,
  6. const char* camera_id,
  7. int new_status);
  8. } camera_module_callbacks_t;

1.5 camera_module_t : camera_module

  1. typedef struct camera_module {
  2. hw_module_t common;
  3. int (*get_number_of_cameras)(void);
  4. int (*get_camera_info)(int camera_id, struct camera_info *info);
  5. int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
  6. void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
  7. int (*open_legacy)(const struct hw_module_t* module, const char* id,
  8. uint32_t halVersion, struct hw_device_t** device);
  9. int (*set_torch_mode)(const char* camera_id, bool enabled);
  10. int (*init)();
  11. void* reserved[5];
  12. } camera_module_t;

2.hardware/libhardware/include/hardware/hardware.h:

2.1 hw_module_t : hw_module_t

  1. typedef struct hw_module_t {
  2. /** tag must be initialized to HARDWARE_MODULE_TAG */
  3. uint32_t tag;
  4. uint16_t module_api_version;
  5. #define version_major module_api_version
  6. uint16_t hal_api_version;
  7. #define version_minor hal_api_version
  8. /** Identifier of module */
  9. const char *id;
  10. /** Name of this module */
  11. const char *name;
  12. /** Author/owner/implementor of the module */
  13. const char *author;
  14. /** Modules methods */
  15. struct hw_module_methods_t* methods;
  16. /** module's dso */
  17. void* dso;
  18. #ifdef __LP64__
  19. uint64_t reserved[32-7];
  20. #else
  21. /** padding to 128 bytes, reserved for future use */
  22. uint32_t reserved[32-7];
  23. #endif
  24. } hw_module_t;

2.2 hw_module_methods_t : hw_module_methods_t

其中 hw_module_methods_t 结构如下:

  1. typedef struct hw_module_methods_t {
  2. /** Open a specific device */
  3. int (*open)(const struct hw_module_t* module, const char* id,
  4. struct hw_device_t** device);
  5. } hw_module_methods_t;

这个结构体里面有一个函数指针,什么地方明确了函数指针的指向了?

在 hardware/libhardware/modules/camera/3_0/CameraHAL.cpp中的167行明确了函数指针指向。指向其中的open_dev函数。

  1. 162static int open_dev(const hw_module_t* mod, const char* name, hw_device_t** dev)
  2. 163{
  3. 164 return gCameraHAL.open(mod, name, dev);
  4. 165}
  5. 166
  6. 167static hw_module_methods_t gCameraModuleMethods = {
  7. 168 .open = open_dev
  8. 169};

2.3 hw_device_t : hw_device_t

  1. typedef struct hw_device_t {
  2. /** tag must be initialized to HARDWARE_DEVICE_TAG */
  3. uint32_t tag;
  4. uint32_t version;
  5. /** reference to the module this device belongs to */
  6. struct hw_module_t* module;
  7. /** padding reserved for future use */
  8. #ifdef __LP64__
  9. uint64_t reserved[12];
  10. #else
  11. uint32_t reserved[12];
  12. #endif
  13. /** Close this device */
  14. int (*close)(struct hw_device_t* device);
  15. } hw_device_t;

3.hardware/libhardware/include/hardware/camera3.h

3.1 camera3_device_t : camera3_device

  1. typedef struct camera3_device {
  2. hw_device_t common;
  3. camera3_device_ops_t *ops;
  4. void *priv;
  5. } camera3_device_t;

3.2 camera3_device_ops_t : camera3_device_ops

  1. typedef struct camera3_device_ops {
  2. int (*initialize)(const struct camera3_device *,
  3. const camera3_callback_ops_t *callback_ops);
  4. int (*configure_streams)(const struct camera3_device *,
  5. camera3_stream_configuration_t *stream_list);
  6. int (*register_stream_buffers)(const struct camera3_device *,
  7. const camera3_stream_buffer_set_t *buffer_set);
  8. const camera_metadata_t* (*construct_default_request_settings)(
  9. const struct camera3_device *,
  10. int type);
  11. int (*process_capture_request)(const struct camera3_device *,
  12. camera3_capture_request_t *request);
  13. void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
  14. vendor_tag_query_ops_t* ops);
  15. void (*dump)(const struct camera3_device *, int fd);
  16. int (*flush)(const struct camera3_device *);
  17. /* reserved for future use */
  18. void *reserved[8];
  19. } camera3_device_ops_t;

camera3_device_ops_t 映射函数指针操作: hardware/libhardware/modules/camera/3_0/Camera.cpp

  1. const camera3_device_ops_t Camera::sOps = {
  2. .initialize = default_camera_hal::initialize,
  3. .configure_streams = default_camera_hal::configure_streams,
  4. .register_stream_buffers = default_camera_hal::register_stream_buffers,
  5. .construct_default_request_settings
  6. = default_camera_hal::construct_default_request_settings,
  7. .process_capture_request = default_camera_hal::process_capture_request,
  8. .get_metadata_vendor_tag_ops = NULL,
  9. .dump = default_camera_hal::dump,
  10. .flush = default_camera_hal::flush,
  11. .reserved = {0},
  12. };

上面的函数指针映射只是抽象层提供一个默认映射方法,实际上芯片中都会复写这个指针函数的映射关系。
以高通660芯片为例,实际上映射的函数指针映射关系是hardware/qcom/camera/QCamera2/HAL3/QCamera3HWI.cpp中,不同的芯片会在不同的地方,但是不会相差太大,况且这些函数指针都是一样的,这是android hal层提供的通用调用方法。

  1. camera3_device_ops_t QCamera3HardwareInterface::mCameraOps = {
  2. .initialize = QCamera3HardwareInterface::initialize,
  3. .configure_streams = QCamera3HardwareInterface::configure_streams,
  4. .register_stream_buffers = NULL,
  5. .construct_default_request_settings = QCamera3HardwareInterface::construct_default_request_settings,
  6. .process_capture_request = QCamera3HardwareInterface::process_capture_request,
  7. .get_metadata_vendor_tag_ops = NULL,
  8. .dump = QCamera3HardwareInterface::dump,
  9. .flush = QCamera3HardwareInterface::flush,
  10. .reserved = {0},
  11. };

在hardware/qcom/camera/QCamera2/HAL3/QCamera3HWI.cpp构造函数中已经建立了这种联系了。

mCameraDevice.ops = &mCameraOps; 

3.3 camera3_callback_ops_t : camera3_callback_ops

  1. typedef struct camera3_callback_ops {
  2. void (*process_capture_result)(const struct camera3_callback_ops *,
  3. const camera3_capture_result_t *result);
  4. void (*notify)(const struct camera3_callback_ops *,
  5. const camera3_notify_msg_t *msg);
  6. } camera3_callback_ops_t;

camera3_callback_ops_t 是camera provider 到camera service 之间的回调,直接和 ICameraDeviceCallback.h对应,可以直接回调这个接口中的方法IPC调用到 camera service进程中。

3.4 camera3_capture_result_t : camera3_capture_result

  1. typedef struct camera3_capture_result {
  2. uint32_t frame_number;
  3. const camera_metadata_t *result;
  4. uint32_t num_output_buffers;
  5. const camera3_stream_buffer_t *output_buffers;
  6. const camera3_stream_buffer_t *input_buffer;
  7. uint32_t partial_result;
  8. uint32_t num_physcam_metadata;
  9. const char **physcam_ids;
  10. const camera_metadata_t **physcam_metadata;
  11. } camera3_capture_result_t;

3.5 camera3_capture_request_t : camera3_capture_request

  1. typedef struct camera3_capture_request {
  2. uint32_t frame_number;
  3. const camera_metadata_t *settings;
  4. camera3_stream_buffer_t *input_buffer;
  5. uint32_t num_output_buffers;
  6. const camera3_stream_buffer_t *output_buffers;
  7. uint32_t num_physcam_settings;
  8. const char **physcam_id;
  9. const camera_metadata_t **physcam_settings;
  10. } camera3_capture_request_t;

执行相机预览的操作,单个camera request请求通过camera service层的 processCaptureRequest()函数发送到HAL 设备上,来进行图像捕获或者图像缓冲区重新处理。

该请求包含用于此捕获的设置,以及用于将结果图像数据写入的输出缓冲区集。它可以选择性地包含输入缓冲区,在这种情况下,请求用于重新处理该输入缓冲区而不是捕获新的用相机传感器拍摄图像。捕获由frame_number标识。

作为响应,相机HAL设备必须发送camera3_capture_result使用process_capture_result()与框架异步结构打回来。

3.6 camera3_request_template_t : camera3_request_template

  1. typedef enum camera3_request_template {
  2. /**
  3. * Standard camera preview operation with 3A on auto.
  4. */
  5. CAMERA3_TEMPLATE_PREVIEW = 1,
  6. /**
  7. * Standard camera high-quality still capture with 3A and flash on auto.
  8. */
  9. CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
  10. /**
  11. * Standard video recording plus preview with 3A on auto, torch off.
  12. */
  13. CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
  14. /**
  15. * High-quality still capture while recording video. Application will
  16. * include preview, video record, and full-resolution YUV or JPEG streams in
  17. * request. Must not cause stuttering on video stream. 3A on auto.
  18. */
  19. CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
  20. /**
  21. * Zero-shutter-lag mode. Application will request preview and
  22. * full-resolution data for each frame, and reprocess it to JPEG when a
  23. * still image is requested by user. Settings should provide highest-quality
  24. * full-resolution images without compromising preview frame rate. 3A on
  25. * auto.
  26. */
  27. CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
  28. /**
  29. * A basic template for direct application control of capture
  30. * parameters. All automatic control is disabled (auto-exposure, auto-white
  31. * balance, auto-focus), and post-processing parameters are set to preview
  32. * quality. The manual capture parameters (exposure, sensitivity, etc.)
  33. * are set to reasonable defaults, but should be overridden by the
  34. * application depending on the intended use case.
  35. */
  36. CAMERA3_TEMPLATE_MANUAL = 6,
  37. /* Total number of templates */
  38. CAMERA3_TEMPLATE_COUNT,
  39. /**
  40. * First value for vendor-defined request templates
  41. */
  42. CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
  43. } camera3_request_template_t;

3.7 camera3_notify_msg_t : camera3_notify_msg

  1. typedef struct camera3_notify_msg {
  2. int type;
  3. union {
  4. camera3_error_msg_t error;
  5. camera3_shutter_msg_t shutter;
  6. uint8_t generic[32];
  7. } message;
  8. } camera3_notify_msg_t;

3.8 camera3_shutter_msg_t : camera3_shutter_msg

  1. typedef struct camera3_shutter_msg {
  2. uint32_t frame_number;
  3. uint64_t timestamp;
  4. } camera3_shutter_msg_t;

3.9 camera3_error_msg_t : camera3_error_msg

  1. typedef struct camera3_error_msg {
  2. uint32_t frame_number;
  3. camera3_stream_t *error_stream;
  4. int error_code;
  5. } camera3_error_msg_t;

3.10 camera3_error_msg_code_t : camera3_error_msg_code

  1. typedef enum camera3_error_msg_code {
  2. CAMERA3_MSG_ERROR_DEVICE = 1,
  3. CAMERA3_MSG_ERROR_REQUEST = 2,
  4. CAMERA3_MSG_ERROR_RESULT = 3,
  5. CAMERA3_MSG_ERROR_BUFFER = 4,
  6. CAMERA3_MSG_NUM_ERRORS
  7. } camera3_error_msg_code_t;

3.11 camera3_msg_type_t : camera3_msg_type

  1. typedef enum camera3_msg_type {
  2. CAMERA3_MSG_ERROR = 1,
  3. CAMERA3_MSG_SHUTTER = 2,
  4. CAMERA3_NUM_MESSAGES
  5. } camera3_msg_type_t;

3.12 camera3_jpeg_blob_t : camera3_jpeg_blob

  1. typedef struct camera3_jpeg_blob {
  2. uint16_t jpeg_blob_id;
  3. uint32_t jpeg_size;
  4. } camera3_jpeg_blob_t;

3.13 camera3_stream_buffer_set_t : camera3_stream_buffer_set

  1. typedef struct camera3_stream_buffer_set {
  2. camera3_stream_t *stream;
  3. uint32_t num_buffers;
  4. buffer_handle_t **buffers;
  5. } camera3_stream_buffer_set_t;

3.14 camera3_stream_buffer_t : camera3_stream_buffer

  1. typedef struct camera3_stream_buffer {
  2. camera3_stream_t *stream;
  3. buffer_handle_t *buffer;
  4. int status;
  5. int acquire_fence;
  6. int release_fence;
  7. } camera3_stream_buffer_t;

3.15 camera3_buffer_status_t : camera3_buffer_status

  1. typedef enum camera3_buffer_status {
  2. CAMERA3_BUFFER_STATUS_OK = 0,
  3. CAMERA3_BUFFER_STATUS_ERROR = 1
  4. } camera3_buffer_status_t;

3.16 camera3_stream_configuration_t : camera3_stream_configuration

  1. typedef struct camera3_stream_configuration {
  2. uint32_t num_streams;
  3. camera3_stream_t **streams;
  4. uint32_t operation_mode;
  5. const camera_metadata_t *session_parameters;
  6. } camera3_stream_configuration_t;

3.17 camera3_stream_t : camera3_stream

  1. typedef struct camera3_stream {
  2. int stream_type;
  3. uint32_t width;
  4. uint32_t height;
  5. int format;
  6. uint32_t usage;
  7. uint32_t max_buffers;
  8. void *priv;
  9. android_dataspace_t data_space;
  10. int rotation;
  11. const char* physical_camera_id;
  12. void *reserved[6];
  13. } camera3_stream_t;

3.18 camera3_stream_configuration_mode_t : camera3_stream_configuration_mode

  1. typedef enum camera3_stream_configuration_mode {
  2. CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE = 0,
  3. CAMERA3_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE = 1,
  4. CAMERA3_VENDOR_STREAM_CONFIGURATION_MODE_START = 0x8000
  5. } camera3_stream_configuration_mode_t;

3.19 camera3_stream_rotation_t : camera3_stream_rotation

  1. typedef enum camera3_stream_rotation {
  2. /* No rotation */
  3. CAMERA3_STREAM_ROTATION_0 = 0,
  4. /* Rotate by 90 degree counterclockwise */
  5. CAMERA3_STREAM_ROTATION_90 = 1,
  6. /* Rotate by 180 degree counterclockwise */
  7. CAMERA3_STREAM_ROTATION_180 = 2,
  8. /* Rotate by 270 degree counterclockwise */
  9. CAMERA3_STREAM_ROTATION_270 = 3
  10. } camera3_stream_rotation_t;

3.20 camera3_stream_type_t : camera3_stream_type

  1. typedef enum camera3_stream_type {
  2. CAMERA3_STREAM_OUTPUT = 0,
  3. CAMERA3_STREAM_INPUT = 1,
  4. CAMERA3_STREAM_BIDIRECTIONAL = 2,
  5. CAMERA3_NUM_STREAM_TYPES
  6. } camera3_stream_type_t;
阅读(15568) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~