1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CAMERA_METADATA_OPERATOR_H 17 #define CAMERA_METADATA_OPERATOR_H 18 19 #include <cstdio> 20 #include <cstdint> 21 #include <string> 22 23 #include "camera_device_ability_items.h" 24 25 /** Versioning information */ 26 #define CURRENT_CAMERA_METADATA_VERSION 1 27 28 #define ITEM_ALIGNMENT ((size_t) 4) 29 30 #define DATA_ALIGNMENT ((size_t) 8) 31 32 #define METADATA_ALIGNMENT ((size_t) 4) 33 34 #define INDEX_COUNTER 2 35 #define WRAP_LENGTH 4 36 37 // data type 38 enum { 39 // uint8_t 40 META_TYPE_BYTE = 0, 41 // int32_t 42 META_TYPE_INT32 = 1, 43 // uint32_t 44 META_TYPE_UINT32 = 2, 45 // float 46 META_TYPE_FLOAT = 3, 47 // int64_t 48 META_TYPE_INT64 = 4, 49 // double 50 META_TYPE_DOUBLE = 5, 51 // A 64-bit fraction (camera_metadata_rational_t) 52 META_TYPE_RATIONAL = 6, 53 // Number of data type 54 META_NUM_TYPES 55 }; 56 57 const static char *OHOS_CAMERA_METADATA_TYPE[META_NUM_TYPES] = { 58 [META_TYPE_BYTE] = "byte", 59 [META_TYPE_INT32] = "int32", 60 [META_TYPE_UINT32] = "uint32", 61 [META_TYPE_FLOAT] = "float", 62 [META_TYPE_INT64] = "int64", 63 [META_TYPE_DOUBLE] = "double", 64 [META_TYPE_RATIONAL] = "rational" 65 }; 66 67 typedef struct camera_rational { 68 int32_t numerator; 69 int32_t denominator; 70 } camera_rational_t; 71 72 // common metadata header 73 typedef struct common_metadata_header { 74 uint32_t version; 75 uint32_t size; 76 uint32_t item_count; 77 uint32_t item_capacity; 78 uint32_t items_start; // Offset from common_metadata_header 79 uint32_t data_count; 80 uint32_t data_capacity; 81 uint32_t data_start; // Offset from common_metadata_header 82 } common_metadata_header_t; 83 84 typedef struct camera_metadata_item_entry { 85 uint32_t item; 86 uint32_t data_type; 87 uint32_t count; 88 union { 89 uint32_t offset; 90 uint8_t value[4]; 91 } data; 92 } camera_metadata_item_entry_t; 93 94 typedef struct camera_metadata_item { 95 uint32_t index; 96 uint32_t item; 97 uint32_t data_type; 98 uint32_t count; 99 union { 100 uint8_t *u8; 101 int32_t *i32; 102 uint32_t *ui32; 103 float *f; 104 int64_t *i64; 105 double *d; 106 camera_rational_t *r; 107 } data; 108 } camera_metadata_item_t; 109 110 typedef struct item_info { 111 const char *item_name; 112 uint8_t item_type; 113 int32_t dataCnt; 114 } item_info_t; 115 116 /* camera_metadata_section */ 117 typedef enum camera_metadata_sec { 118 OHOS_SECTION_CAMERA_PROPERTIES, 119 OHOS_SECTION_CAMERA_SENSOR, 120 OHOS_SECTION_CAMERA_SENSOR_INFO, 121 OHOS_SECTION_CAMERA_STATISTICS, 122 OHOS_SECTION_CAMERA_CONTROL, 123 OHOS_SECTION_DEVICE_EXPOSURE, 124 OHOS_SECTION_DEVICE_FOCUS, 125 OHOS_SECTION_DEVICE_WHITE, 126 OHOS_SECTION_DEVICE_FLASH, 127 OHOS_SECTION_DEVICE_ZOOM, 128 OHOS_SECTION_STREAM_ABILITY, 129 OHOS_SECTION_STREAM_JPEG, 130 OHOS_SECTION_STREAM_VIDEO, 131 OHOS_SECTION_CAMERA_EFFECT, 132 OHOS_SECTION_CAMERA_SECURE, 133 OHOS_SECTION_CAMERA_XMAGE, 134 OHOS_SECTION_COUNT, 135 } camera_metadata_sec_t; 136 137 typedef struct VendoTagInfo { 138 uint32_t tagId; 139 const char* tagName; 140 uint8_t tagType; 141 } vendorTag_t; 142 143 /* Return codes */ 144 #define CAM_META_FAILURE (-1) 145 #define CAM_META_SUCCESS 0 146 #define CAM_META_INVALID_PARAM 2 147 #define CAM_META_ITEM_NOT_FOUND 3 148 #define CAM_META_ITEM_CAP_EXCEED 4 149 #define CAM_META_DATA_CAP_EXCEED 5 150 151 /* for shift opereration */ 152 #define BITWISE_SHIFT_16 16 153 154 namespace OHOS::Camera { 155 // Allocate a new camera metadata buffer and return the metadata header 156 common_metadata_header_t *AllocateCameraMetadataBuffer(uint32_t item_capacity, uint32_t data_capacity); 157 158 // Is camera metadata item exist 159 bool IsCameraMetadataItemExist(const common_metadata_header_t *src, uint32_t item); 160 161 // Find camera metadata item and fill the found item 162 int FindCameraMetadataItem(const common_metadata_header_t *src, uint32_t item, 163 camera_metadata_item_t *metadataItem); 164 165 // Find camera metadata item index if the item exists 166 int FindCameraMetadataItemIndex(const common_metadata_header_t *src, uint32_t item, uint32_t *index); 167 168 // Get camera metadata item name 169 const char *GetCameraMetadataItemName(uint32_t item); 170 171 // Update camera metadata item and fill the updated item 172 int UpdateCameraMetadataItem(common_metadata_header_t *dst, uint32_t item, const void *data, uint32_t dataCount, 173 camera_metadata_item_t *updatedItem); 174 175 // Update camera metadata item by index and fill the updated item 176 int UpdateCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t index, const void *data, 177 uint32_t dataCount, camera_metadata_item_t *updated_item); 178 179 // Add camera metadata item 180 int AddCameraMetadataItem(common_metadata_header_t *dst, uint32_t item, const void *data, size_t dataCount); 181 182 // Delete camera metadata item 183 int DeleteCameraMetadataItem(common_metadata_header_t *dst, uint32_t item); 184 185 // Delete camera metadata item by index 186 int DeleteCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t index); 187 188 // Free camera metadata buffer 189 void FreeCameraMetadataBuffer(common_metadata_header_t *dst); 190 191 std::string MetadataItemDump(const common_metadata_header_t *metadataHeader, uint32_t item); 192 193 std::string FormatCameraMetadataToString(const common_metadata_header_t *metadataHeader); 194 195 // Internal use 196 camera_metadata_item_entry_t *GetMetadataItems(const common_metadata_header_t *metadataHeader); 197 uint8_t *GetMetadataData(const common_metadata_header_t *metadataHeader); 198 int GetCameraMetadataItem(const common_metadata_header_t *src, uint32_t index, camera_metadata_item_t *item); 199 uint32_t GetCameraMetadataItemCount(const common_metadata_header_t *metadata_header); 200 uint32_t GetCameraMetadataItemCapacity(const common_metadata_header_t *metadata_header); 201 uint32_t GetCameraMetadataDataSize(const common_metadata_header_t *metadata_header); 202 int32_t CopyCameraMetadataItems(common_metadata_header_t *newMetadata, 203 const common_metadata_header_t *oldMetadata); 204 size_t CalculateCameraMetadataItemDataSize(uint32_t type, size_t data_count); 205 int32_t GetCameraMetadataItemType(uint32_t item, uint32_t *data_type); 206 common_metadata_header_t *FillCameraMetadata(common_metadata_header_t *buffer, size_t memoryRequired, 207 uint32_t itemCapacity, uint32_t dataCapacity); 208 int32_t GetMetadataSection(uint32_t itemSection, uint32_t *section); 209 int MetadataExpandItemMem(common_metadata_header_t *dst, camera_metadata_item_entry_t *item, 210 size_t oldItemSize); 211 int32_t GetAllVendorTags(std::vector<vendorTag_t>& tagVec); 212 } // Camera 213 #endif // CAMERA_METADATA_OPERATOR_H 214