CameraMetaData
2021-03-02 02:25
标签:generate hat 信息 char session methods mil 摄像头 dde 一、camera_metadata简介 Camera API2/HAL3架构下使用了全新的CameraMetadata结构取代了之前的SetParameter/Paramters等操作,实现了Java到native到HAL3的参数传递。引入了管道的概念将安卓设备和摄像头之间联系起来,系统向摄像头发送 Capture 请求,而摄像头会返回 CameraMetadata,这一切建立在一个叫作 CameraCaptureSession 的会话中。和Camera_metadata数据结构相关的主要有以下几个文件: system/media/camera/include/system/camera_metadata_tags.h(不允许直接引用该头文件,如需引用,可以引用camera_metadata.h) 二、Framework到HAL层的转换 Camera2Client 使用 API1 传递参数采用的逻辑是还是在Java层预留了setParameters接口,只是当Parameter在设置时比起CameraClient而言,是将这个Parameter根据不同的TAG形式直接绑定到CameraMetadata mPreviewRequest/mRecordRequest/mCaptureRequest中,这些数据会由Capture_Request转为camera3_capture_request中的camera_metadata_t settings完成参数从Java到native到HAL3的传递。 但是在Camera API2下,不再需要那么复杂的转换过程,在Java层中直接对参数进行设置并将其封装到Capture_Request即可,即参数控制由Java层来完成。这也体现了API2中Request和Result在APP中就大量存在的原因。对此为了和Framework Native层相关TAG数据的统一,在Java层中大量出现的参数设置是通过Section Tag的name来交由Native完成转换生成在Java层的TAG。 (1)Java层对应代码位置:frameworks/base/core/java/android/hardware/camera2/impl/CameraMetadataNative.java (2)Native层对应代码位置:frameworks/base/core/jni/android_hardware_camera2_CameraMetadata.cpp 其中CameraMetadata_getTagFromKey是实现将一个Java层的string转为一个tag的值,如:android.control.mode。对比最初不同的Section name就可以发现前面两个x.y的字符串就是代表是Section name.而后面mode即是在该section下的tag数值,所以通过对这个string的分析可知,就可以定位对应的section以及tag值,这样返回到Java层的就是key相应的tag值了。继续追踪到 \system\media\camera\src\camera_metadata.c: 相关文件调用关系如下: 其中 camera_metadata_tags.h 包含了所有的基本宏,每一个section的大小是64K(每个section_start 由section偏移16位,也就是2^16=65536,即64K)。tag也就是又section_start偏移而来,比如android.control.mode,由camera_metadata_section--->ANDROID_CONTROL找到对应的camera_metadata_section_start--->ANDROID_CONTROL_START,然后在camera_metadata_tag找到对应的ANDROID_CONTROL_MODE,也就是tag值。 对应关系如图所示: 然后在 camera_metadata_tag_info.c 中进行了映射和绑定,前面Native层CameraMetadata_getTagFromKey--->getTagFromName--->camera_metadata_section_bounds调用的camera_metadata_section_bounds实现在这里: 由 tag_info 结构体统一管理: 下图是Camera Metadata对不同section以及相应section下不同tag的布局图,以最常见的android.control Section为例进行描述: CameraMetaData 标签:generate hat 信息 char session methods mil 摄像头 dde 原文地址:https://www.cnblogs.com/SaraMoring/p/14385967.html
system/media/camera/include/system/camera_metadata.h
system/media/camera/include/system/camera_vendor_tags.h(给各个芯片厂商扩展的tag)
system/media/camera/src/camera_metadata_tag_info.c(不允许直接调用该文件中的函数,如需调用,调用camera_metadata.c中包装函数)
system/media/camera/src/camera_metadata.c
framework/av/camera/CameraMetadata.cpp
framework/av/include/camera/CameraMetadata.h
frameworks/base/core/jni/android_hardware_camera2_CameraMetadata.cpp 1 private
1 static const JNINativeMethod gCameraMetadataMethods[] = {
2 // static methods
3 { "nativeGetTagFromKey",
4 "(Ljava/lang/String;J)I",
5 (void *)CameraMetadata_getTagFromKey },
6 { "nativeGetTypeFromTag",
7 "(IJ)I",
8 (void *)CameraMetadata_getTypeFromTag },
9 { "nativeSetupGlobalVendorTagDescriptor",
10 "()I",
11 (void*)CameraMetadata_setupGlobalVendorTagDescriptor },
12 // instance methods
13 { "nativeAllocate",
14 "()J",
15 (void*)CameraMetadata_allocate },
16 { "nativeAllocateCopy",
17 "(L" CAMERA_METADATA_CLASS_NAME ";)J",
18 (void *)CameraMetadata_allocateCopy },
19 { "nativeIsEmpty",
20 "()Z",
21 (void*)CameraMetadata_isEmpty },
22 { "nativeGetEntryCount",
23 "()I",
24 (void*)CameraMetadata_getEntryCount },
25 { "nativeClose",
26 "()V",
27 (void*)CameraMetadata_close },
28 { "nativeSwap",
29 "(L" CAMERA_METADATA_CLASS_NAME ";)V",
30 (void *)CameraMetadata_swap },
31 { "nativeGetTagFromKeyLocal",
32 "(Ljava/lang/String;)I",
33 (void *)CameraMetadata_getTagFromKeyLocal },
34 { "nativeGetTypeFromTagLocal",
35 "(I)I",
36 (void *)CameraMetadata_getTypeFromTagLocal },
37 ...
38 };
1 // Declared in system/media/private/camera/include/camera_metadata_hidden.h
2 const char *get_local_camera_metadata_tag_name_vendor_id(uint32_t tag,
3 metadata_vendor_id_t id) {
4 uint32_t tag_section = tag >> 16;
5 if (tag_section >= VENDOR_SECTION && vendor_cache_ops != NULL &&
6 id != CAMERA_METADATA_INVALID_VENDOR_ID) {
7 return vendor_cache_ops->get_tag_name(tag, id);
8 } else if (tag_section >= VENDOR_SECTION && vendor_tag_ops != NULL) {
9 return vendor_tag_ops->get_tag_name(
10 vendor_tag_ops,
11 tag);
12 }
13 if (tag_section >= ANDROID_SECTION_COUNT ||
14 tag >= camera_metadata_section_bounds[tag_section][1] ) { // 关键是camera_metadata_section_bounds这个数组,保存了各个tag的绑定信息
15 return NULL;
16 }
17 uint32_t tag_index = tag & 0xFFFF;
18 return tag_info[tag_section][tag_index].tag_name;
19 }
1 /**
2 * !! Do not include this file directly !!
3 *
4 * Include camera_metadata.h instead.
5 */
6
7 /**
8 * ! Do not edit this file directly !
9 *
10 * Generated automatically from camera_metadata_tags.mako
11 */
12
13 /** TODO: Nearly every enum in this file needs a description */
14
15 /**
16 * Top level hierarchy definitions for camera metadata. *_INFO sections are for
17 * the static metadata that can be retrived without opening the camera device.
18 * New sections must be added right before ANDROID_SECTION_COUNT to maintain
19 * existing enumerations.
20 */
21 typedef enum camera_metadata_section {
22 ANDROID_COLOR_CORRECTION,
23 ANDROID_CONTROL,
24 ANDROID_DEMOSAIC,
25 ANDROID_EDGE,
26 ANDROID_FLASH,
27 ANDROID_FLASH_INFO,
28 ANDROID_HOT_PIXEL,
29 ANDROID_JPEG,
30 ANDROID_LENS,
31 ANDROID_LENS_INFO,
32 ANDROID_NOISE_REDUCTION,
33 ANDROID_QUIRKS,
34 ANDROID_REQUEST,
35 ANDROID_SCALER,
36 ANDROID_SENSOR,
37 ANDROID_SENSOR_INFO,
38 ANDROID_SHADING,
39 ANDROID_STATISTICS,
40 ANDROID_STATISTICS_INFO,
41 ANDROID_TONEMAP,
42 ANDROID_LED,
43 ANDROID_INFO,
44 ANDROID_BLACK_LEVEL,
45 ANDROID_SYNC,
46 ANDROID_REPROCESS,
47 ANDROID_DEPTH,
48 ANDROID_LOGICAL_MULTI_CAMERA,
49 ANDROID_DISTORTION_CORRECTION,
50 ANDROID_HEIC,
51 ANDROID_HEIC_INFO,
52 ANDROID_H264,
53 ANDROID_H265,
54 ANDROID_SECTION_COUNT,
55
56 VENDOR_SECTION = 0x8000
57 } camera_metadata_section_t;
58
59 /**
60 * Hierarchy positions in enum space. All vendor extension tags must be
61 * defined with tag >= VENDOR_SECTION_START
62 */
63 typedef enum camera_metadata_section_start {
64 ANDROID_COLOR_CORRECTION_START = ANDROID_COLOR_CORRECTION 16,
65 ANDROID_CONTROL_START = ANDROID_CONTROL 16,
66 ANDROID_DEMOSAIC_START = ANDROID_DEMOSAIC 16,
67 ANDROID_EDGE_START = ANDROID_EDGE 16,
68 ANDROID_FLASH_START = ANDROID_FLASH 16,
69 ANDROID_FLASH_INFO_START = ANDROID_FLASH_INFO 16,
70 ANDROID_HOT_PIXEL_START = ANDROID_HOT_PIXEL 16,
71 ANDROID_JPEG_START = ANDROID_JPEG 16,
72 ANDROID_LENS_START = ANDROID_LENS 16,
73 ANDROID_LENS_INFO_START = ANDROID_LENS_INFO 16,
74 ANDROID_NOISE_REDUCTION_START = ANDROID_NOISE_REDUCTION 16,
75 ANDROID_QUIRKS_START = ANDROID_QUIRKS 16,
76 ANDROID_REQUEST_START = ANDROID_REQUEST 16,
77 ANDROID_SCALER_START = ANDROID_SCALER 16,
78 ANDROID_SENSOR_START = ANDROID_SENSOR 16,
79 ANDROID_SENSOR_INFO_START = ANDROID_SENSOR_INFO 16,
80 ANDROID_SHADING_START = ANDROID_SHADING 16,
81 ANDROID_STATISTICS_START = ANDROID_STATISTICS 16,
82 ANDROID_STATISTICS_INFO_START = ANDROID_STATISTICS_INFO 16,
83 ANDROID_TONEMAP_START = ANDROID_TONEMAP 16,
84 ANDROID_LED_START = ANDROID_LED 16,
85 ANDROID_INFO_START = ANDROID_INFO 16,
86 ANDROID_BLACK_LEVEL_START = ANDROID_BLACK_LEVEL 16,
87 ANDROID_SYNC_START = ANDROID_SYNC 16,
88 ANDROID_REPROCESS_START = ANDROID_REPROCESS 16,
89 ANDROID_DEPTH_START = ANDROID_DEPTH 16,
90 ANDROID_LOGICAL_MULTI_CAMERA_START
91 = ANDROID_LOGICAL_MULTI_CAMERA
92 16,
93 ANDROID_DISTORTION_CORRECTION_START
94 = ANDROID_DISTORTION_CORRECTION
95 16,
96 ANDROID_HEIC_START = ANDROID_HEIC 16,
97 ANDROID_HEIC_INFO_START = ANDROID_HEIC_INFO 16,
98 ANDROID_H264_START = ANDROID_H264 16,
99 ANDROID_H265_START = ANDROID_H265 16,
100 VENDOR_SECTION_START = VENDOR_SECTION 16
101 } camera_metadata_section_start_t;
1 /**
2 * Main enum for defining camera metadata tags. New entries must always go
3 * before the section _END tag to preserve existing enumeration values. In
4 * addition, the name and type of the tag needs to be added to
5 * system/media/camera/src/camera_metadata_tag_info.c
6 */
7 typedef enum camera_metadata_tag {
8 ANDROID_COLOR_CORRECTION_MODE = // enum | public | HIDL v3.2
9 ANDROID_COLOR_CORRECTION_START,
10 ANDROID_COLOR_CORRECTION_TRANSFORM, // rational[] | public | HIDL v3.2
11 ANDROID_COLOR_CORRECTION_GAINS, // float[] | public | HIDL v3.2
12 ANDROID_COLOR_CORRECTION_ABERRATION_MODE, // enum | public | HIDL v3.2
13 ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES,
14 // byte[] | public | HIDL v3.2
15 ANDROID_COLOR_CORRECTION_END,
16
17 ANDROID_CONTROL_AE_ANTIBANDING_MODE = // enum | public | HIDL v3.2
18 ANDROID_CONTROL_START,
19 ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, // int32 | public | HIDL v3.2
20 ANDROID_CONTROL_AE_LOCK, // enum | public | HIDL v3.2
21 ANDROID_CONTROL_AE_MODE, // enum | public | HIDL v3.2
22 ANDROID_CONTROL_AE_REGIONS, // int32[] | public | HIDL v3.2
23 ANDROID_CONTROL_AE_TARGET_FPS_RANGE, // int32[] | public | HIDL v3.2
24 ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, // enum | public | HIDL v3.2
25 ANDROID_CONTROL_AF_MODE, // enum | public | HIDL v3.2
26 ANDROID_CONTROL_AF_REGIONS, // int32[] | public | HIDL v3.2
27 ANDROID_CONTROL_AF_TRIGGER, // enum | public | HIDL v3.2
28 ANDROID_CONTROL_AWB_LOCK, // enum | public | HIDL v3.2
29 ANDROID_CONTROL_AWB_MODE, // enum | public | HIDL v3.2
30 ANDROID_CONTROL_AWB_REGIONS, // int32[] | public | HIDL v3.2
31 ANDROID_CONTROL_CAPTURE_INTENT, // enum | public | HIDL v3.2
32 ANDROID_CONTROL_EFFECT_MODE, // enum | public | HIDL v3.2
33 ANDROID_CONTROL_MODE, // enum | public | HIDL v3.2
34 ANDROID_CONTROL_SCENE_MODE, // enum | public | HIDL v3.2
35 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, // enum | public | HIDL v3.2
36 ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, // byte[] | public | HIDL v3.2
37 ANDROID_CONTROL_AE_AVAILABLE_MODES, // byte[] | public | HIDL v3.2
38 ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, // int32[] | public | HIDL v3.2
39 ANDROID_CONTROL_AE_COMPENSATION_RANGE, // int32[] | public | HIDL v3.2
40 ANDROID_CONTROL_AE_COMPENSATION_STEP, // rational | public | HIDL v3.2
41 ANDROID_CONTROL_AF_AVAILABLE_MODES, // byte[] | public | HIDL v3.2
42 ANDROID_CONTROL_AVAILABLE_EFFECTS, // byte[] | public | HIDL v3.2
43 ANDROID_CONTROL_AVAILABLE_SCENE_MODES, // byte[] | public | HIDL v3.2
44 ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES,
45 // byte[] | public | HIDL v3.2
46 ANDROID_CONTROL_AWB_AVAILABLE_MODES, // byte[] | public | HIDL v3.2
47 ANDROID_CONTROL_MAX_REGIONS, // int32[] | ndk_public | HIDL v3.2
48 ANDROID_CONTROL_SCENE_MODE_OVERRIDES, // byte[] | system | HIDL v3.2
49 ANDROID_CONTROL_AE_PRECAPTURE_ID, // int32 | system | HIDL v3.2
50 ANDROID_CONTROL_AE_STATE, // enum | public | HIDL v3.2
51 ANDROID_CONTROL_AF_STATE, // enum | public | HIDL v3.2
52 ANDROID_CONTROL_AF_TRIGGER_ID, // int32 | system | HIDL v3.2
53 ANDROID_CONTROL_AWB_STATE, // enum | public | HIDL v3.2
54 ANDROID_CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS,
55 // int32[] | hidden | HIDL v3.2
56 ANDROID_CONTROL_AE_LOCK_AVAILABLE, // enum | public | HIDL v3.2
57 ANDROID_CONTROL_AWB_LOCK_AVAILABLE, // enum | public | HIDL v3.2
58 ANDROID_CONTROL_AVAILABLE_MODES, // byte[] | public | HIDL v3.2
59 ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE, // int32[] | public | HIDL v3.2
60 ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST, // int32 | public | HIDL v3.2
61 ANDROID_CONTROL_ENABLE_ZSL, // enum | public | HIDL v3.2
62 ANDROID_CONTROL_AF_SCENE_CHANGE, // enum | public | HIDL v3.3
63 ANDROID_CONTROL_END,
64
65 ......
1 /**
2 * ! Do not edit this file directly !
3 *
4 * Generated automatically from camera_metadata_tag_info.mako
5 */
6
7 const char *camera_metadata_section_names[ANDROID_SECTION_COUNT] = {
8 [ANDROID_COLOR_CORRECTION] = "android.colorCorrection",
9 [ANDROID_CONTROL] = "android.control",
10 [ANDROID_DEMOSAIC] = "android.demosaic",
11 [ANDROID_EDGE] = "android.edge",
12 [ANDROID_FLASH] = "android.flash",
13 [ANDROID_FLASH_INFO] = "android.flash.info",
14 [ANDROID_HOT_PIXEL] = "android.hotPixel",
15 [ANDROID_JPEG] = "android.jpeg",
16 [ANDROID_LENS] = "android.lens",
17 [ANDROID_LENS_INFO] = "android.lens.info",
18 [ANDROID_NOISE_REDUCTION] = "android.noiseReduction",
19 [ANDROID_QUIRKS] = "android.quirks",
20 [ANDROID_REQUEST] = "android.request",
21 [ANDROID_SCALER] = "android.scaler",
22 [ANDROID_SENSOR] = "android.sensor",
23 [ANDROID_SENSOR_INFO] = "android.sensor.info",
24 [ANDROID_SHADING] = "android.shading",
25 [ANDROID_STATISTICS] = "android.statistics",
26 [ANDROID_STATISTICS_INFO] = "android.statistics.info",
27 [ANDROID_TONEMAP] = "android.tonemap",
28 [ANDROID_LED] = "android.led",
29 [ANDROID_INFO] = "android.info",
30 [ANDROID_BLACK_LEVEL] = "android.blackLevel",
31 [ANDROID_SYNC] = "android.sync",
32 [ANDROID_REPROCESS] = "android.reprocess",
33 [ANDROID_DEPTH] = "android.depth",
34 [ANDROID_LOGICAL_MULTI_CAMERA] = "android.logicalMultiCamera",
35 [ANDROID_DISTORTION_CORRECTION]
36 = "android.distortionCorrection",
37 };
38
39 unsigned int camera_metadata_section_bounds[ANDROID_SECTION_COUNT][2] = {
40 [ANDROID_COLOR_CORRECTION] = { ANDROID_COLOR_CORRECTION_START,
41 ANDROID_COLOR_CORRECTION_END },
42 [ANDROID_CONTROL] = { ANDROID_CONTROL_START,
43 ANDROID_CONTROL_END },
44 [ANDROID_DEMOSAIC] = { ANDROID_DEMOSAIC_START,
45 ANDROID_DEMOSAIC_END },
46 [ANDROID_EDGE] = { ANDROID_EDGE_START,
47 ANDROID_EDGE_END },
48 [ANDROID_FLASH] = { ANDROID_FLASH_START,
49 ANDROID_FLASH_END },
50 [ANDROID_FLASH_INFO] = { ANDROID_FLASH_INFO_START,
51 ANDROID_FLASH_INFO_END },
52 [ANDROID_HOT_PIXEL] = { ANDROID_HOT_PIXEL_START,
53 ANDROID_HOT_PIXEL_END },
54 [ANDROID_JPEG] = { ANDROID_JPEG_START,
55 ANDROID_JPEG_END },
56 [ANDROID_LENS] = { ANDROID_LENS_START,
57 ANDROID_LENS_END },
58 [ANDROID_LENS_INFO] = { ANDROID_LENS_INFO_START,
59 ANDROID_LENS_INFO_END },
60 [ANDROID_NOISE_REDUCTION] = { ANDROID_NOISE_REDUCTION_START,
61 ANDROID_NOISE_REDUCTION_END },
62 [ANDROID_QUIRKS] = { ANDROID_QUIRKS_START,
63 ANDROID_QUIRKS_END },
64 [ANDROID_REQUEST] = { ANDROID_REQUEST_START,
65 ANDROID_REQUEST_END },
66 [ANDROID_SCALER] = { ANDROID_SCALER_START,
67 ANDROID_SCALER_END },
68 [ANDROID_SENSOR] = { ANDROID_SENSOR_START,
69 ANDROID_SENSOR_END },
70 [ANDROID_SENSOR_INFO] = { ANDROID_SENSOR_INFO_START,
71 ANDROID_SENSOR_INFO_END },
72 [ANDROID_SHADING] = { ANDROID_SHADING_START,
73 ANDROID_SHADING_END },
74 [ANDROID_STATISTICS] = { ANDROID_STATISTICS_START,
75 ANDROID_STATISTICS_END },
76 [ANDROID_STATISTICS_INFO] = { ANDROID_STATISTICS_INFO_START,
77 ANDROID_STATISTICS_INFO_END },
78 [ANDROID_TONEMAP] = { ANDROID_TONEMAP_START,
79 ANDROID_TONEMAP_END },
80 [ANDROID_LED] = { ANDROID_LED_START,
81 ANDROID_LED_END },
82 [ANDROID_INFO] = { ANDROID_INFO_START,
83 ANDROID_INFO_END },
84 [ANDROID_BLACK_LEVEL] = { ANDROID_BLACK_LEVEL_START,
85 ANDROID_BLACK_LEVEL_END },
86 [ANDROID_SYNC] = { ANDROID_SYNC_START,
87 ANDROID_SYNC_END },
88 [ANDROID_REPROCESS] = { ANDROID_REPROCESS_START,
89 ANDROID_REPROCESS_END },
90 [ANDROID_DEPTH] = { ANDROID_DEPTH_START,
91 ANDROID_DEPTH_END },
92 [ANDROID_LOGICAL_MULTI_CAMERA] = { ANDROID_LOGICAL_MULTI_CAMERA_START,
93 ANDROID_LOGICAL_MULTI_CAMERA_END },
94 [ANDROID_DISTORTION_CORRECTION]
95 = { ANDROID_DISTORTION_CORRECTION_START,
96 ANDROID_DISTORTION_CORRECTION_END },
97 };
1 static tag_info_t android_color_correction[ANDROID_COLOR_CORRECTION_END -
2 ANDROID_COLOR_CORRECTION_START] = {
3 [ ANDROID_COLOR_CORRECTION_MODE - ANDROID_COLOR_CORRECTION_START ] =
4 { "mode", TYPE_BYTE },
5 [ ANDROID_COLOR_CORRECTION_TRANSFORM - ANDROID_COLOR_CORRECTION_START ] =
6 { "transform", TYPE_RATIONAL
7 },
8 [ ANDROID_COLOR_CORRECTION_GAINS - ANDROID_COLOR_CORRECTION_START ] =
9 { "gains", TYPE_FLOAT },
10 [ ANDROID_COLOR_CORRECTION_ABERRATION_MODE - ANDROID_COLOR_CORRECTION_START ] =
11 { "aberrationMode", TYPE_BYTE },
12 [ ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES - ANDROID_COLOR_CORRECTION_START ] =
13 { "availableAberrationModes", TYPE_BYTE },
14 };
15
16 -------------------------------------------------------------
17
18 tag_info_t *tag_info[ANDROID_SECTION_COUNT] = {
19 android_color_correction,
20 android_control,
21 android_demosaic,
22 android_edge,
23 android_flash,
24 android_flash_info,
25 android_hot_pixel,
26 android_jpeg,
27 android_lens,
28 android_lens_info,
29 android_noise_reduction,
30 android_quirks,
31 android_request,
32 android_scaler,
33 android_sensor,
34 android_sensor_info,
35 android_shading,
36 android_statistics,
37 android_statistics_info,
38 android_tonemap,
39 android_led,
40 android_info,
41 android_black_level,
42 android_sync,
43 android_reprocess,
44 android_depth,
45 android_logical_multi_camera,
46 android_distortion_correction,
47 };