1 /* 2 * Copyright (C) 2021 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 <stdint.h> 20 #include <stdio.h> 21 22 #include "camera_device_ability_items.h" 23 24 /** Versioning information */ 25 #define CURRENT_CAMERA_METADATA_VERSION 1 26 27 #define ITEM_ALIGNMENT ((size_t) 4) 28 29 #define DATA_ALIGNMENT ((size_t) 8) 30 31 #define METADATA_ALIGNMENT ((size_t) 4) 32 33 #define METADATA_PACKET_ALIGNMENT \ 34 MaxAlignment(MaxAlignment(DATA_ALIGNMENT, METADATA_ALIGNMENT), ITEM_ALIGNMENT) 35 36 #define INDEX_COUNTER 2 37 38 // data type 39 enum { 40 // uint8_t 41 META_TYPE_BYTE = 0, 42 // int32_t 43 META_TYPE_INT32 = 1, 44 // uint32_t 45 META_TYPE_UINT32 = 2, 46 // float 47 META_TYPE_FLOAT = 3, 48 // int64_t 49 META_TYPE_INT64 = 4, 50 // double 51 META_TYPE_DOUBLE = 5, 52 // A 64-bit fraction (camera_metadata_rational_t) 53 META_TYPE_RATIONAL = 6, 54 // Number of data type 55 META_NUM_TYPES 56 }; 57 58 typedef struct camera_rational { 59 int32_t numerator; 60 int32_t denominator; 61 } camera_rational_t; 62 63 // common metadata header 64 typedef struct common_metadata_header { 65 uint32_t version; 66 uint32_t size; 67 uint32_t item_count; 68 uint32_t item_capacity; 69 uint32_t items_start; // Offset from common_metadata_header 70 uint32_t data_count; 71 uint32_t data_capacity; 72 uint32_t data_start; // Offset from common_metadata_header 73 } common_metadata_header_t; 74 75 typedef struct camera_metadata_item_entry { 76 uint32_t item; 77 uint32_t data_type; 78 uint32_t count; 79 union { 80 uint32_t offset; 81 uint8_t value[4]; 82 } data; 83 } camera_metadata_item_entry_t; 84 85 typedef struct camera_metadata_item { 86 uint32_t index; 87 uint32_t item; 88 uint32_t data_type; 89 uint32_t count; 90 union { 91 uint8_t *u8; 92 int32_t *i32; 93 uint32_t *ui32; 94 float *f; 95 int64_t *i64; 96 double *d; 97 camera_rational_t *r; 98 } data; 99 } camera_metadata_item_t; 100 101 typedef struct item_info { 102 const char *item_name; 103 uint8_t item_type; 104 int32_t dataCnt; 105 } item_info_t; 106 107 /* camera_metadata_section */ 108 typedef enum camera_metadata_sec { 109 OHOS_SECTION_CAMERA_PROPERTIES, 110 OHOS_SECTION_CAMERA_SENSOR, 111 OHOS_SECTION_CAMERA_SENSOR_INFO, 112 OHOS_SECTION_CAMERA_STATISTICS, 113 OHOS_SECTION_CAMERA_CONTROL, 114 OHOS_SECTION_DEVICE_EXPOSURE, 115 OHOS_SECTION_DEVICE_FOCUS, 116 OHOS_SECTION_DEVICE_FLASH, 117 OHOS_SECTION_DEVICE_ZOOM, 118 OHOS_SECTION_STREAM_ABILITY, 119 OHOS_SECTION_STREAM_JPEG, 120 OHOS_SECTION_COUNT, 121 } camera_metadata_sec_t; 122 123 /* Return codes */ 124 #define CAM_META_FAILURE -1 125 #define CAM_META_SUCCESS 0 126 #define CAM_META_INVALID_PARAM 2 127 #define CAM_META_ITEM_NOT_FOUND 3 128 #define CAM_META_ITEM_CAP_EXCEED 4 129 #define CAM_META_DATA_CAP_EXCEED 5 130 131 /* for shift opereration */ 132 #define BITWISE_SHIFT_16 16 133 134 namespace OHOS { 135 namespace Camera { 136 uint32_t AlignTo(uint32_t val, uint32_t alignment); 137 138 uint32_t MaxAlignment(uint32_t dataAlignment, uint32_t metadataAlignment); 139 140 // Allocate a new camera metadata buffer and return the metadata header 141 common_metadata_header_t *AllocateCameraMetadataBuffer(uint32_t item_capacity, uint32_t data_capacity); 142 143 // Find camera metadata item and fill the found item 144 int FindCameraMetadataItem(const common_metadata_header_t *src, uint32_t item, camera_metadata_item_t *metadataItem); 145 146 // Get camera metadata item name 147 const char *GetCameraMetadataItemName(uint32_t item); 148 149 // Update camera metadata item and fill the updated item 150 int UpdateCameraMetadataItem(common_metadata_header_t *dst, uint32_t item, const void *data, uint32_t dataCount, 151 camera_metadata_item_t *updatedItem); 152 153 // Update camera metadata item by index and fill the updated item 154 int UpdateCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t index, const void *data, 155 uint32_t dataCount, camera_metadata_item_t *updated_item); 156 157 // Add camera metadata item 158 int AddCameraMetadataItem(common_metadata_header_t *dst, uint32_t item, const void *data, size_t dataCount); 159 160 // Delete camera metadata item 161 int DeleteCameraMetadataItem(common_metadata_header_t *dst, uint32_t item); 162 163 // Delete camera metadata item by index 164 int DeleteCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t index); 165 166 // Free camera metadata buffer 167 void FreeCameraMetadataBuffer(common_metadata_header_t *dst); 168 169 // Internal use 170 camera_metadata_item_entry_t *GetMetadataItems(const common_metadata_header_t *metadataHeader); 171 uint8_t *GetMetadataData(const common_metadata_header_t *metadataHeader); 172 int GetCameraMetadataItem(const common_metadata_header_t *src, uint32_t index, camera_metadata_item_t *item); 173 uint32_t GetCameraMetadataItemCount(const common_metadata_header_t *metadata_header); 174 uint32_t GetCameraMetadataItemCapacity(const common_metadata_header_t *metadata_header); 175 uint32_t GetCameraMetadataDataSize(const common_metadata_header_t *metadata_header); 176 uint32_t CopyCameraMetadataItems(common_metadata_header_t *newMetadata, const common_metadata_header_t *oldMetadata); 177 size_t CalculateCameraMetadataItemDataSize(uint32_t type, size_t data_count); 178 int32_t GetCameraMetadataItemType(uint32_t item, uint32_t *data_type); 179 } // Camera 180 } // OHOS 181 #endif