• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INFO_H
17 #define CAMERA_METADATA_INFO_H
18 
19 #include <cstdio>
20 #include <cstdint>
21 #include <string>
22 #include <parcel.h>
23 #include "camera_metadata_operator.h"
24 
25 static constexpr uint32_t MAX_SUPPORTED_TAGS = 1000;
26 static constexpr uint32_t MAX_SUPPORTED_ITEMS = (12000 * 2 * 2);
27 static constexpr uint32_t MAX_ITEM_CAPACITY = (1000 * 10);
28 static constexpr uint32_t MAX_DATA_CAPACITY = (1000 * 10 * 10 * 10);
29 static constexpr uint32_t MIN_VEC_SIZE = 12;
30 
31 #define METADATA_PACKET_ALIGNMENT \
32     MaxAlignment(MaxAlignment(DATA_ALIGNMENT, METADATA_ALIGNMENT), ITEM_ALIGNMENT)
33 
34 namespace OHOS::Camera {
35 class CameraMetadata : public Parcelable {
36 public:
37     CameraMetadata(size_t itemCapacity, size_t dataCapacity);
38     ~CameraMetadata();
39 
40     bool addEntry(uint32_t item, const void *data, size_t data_count);
41     bool updateEntry(uint32_t tag, const void *data, size_t data_count);
42     common_metadata_header_t *get();
43     const common_metadata_header_t *get() const;
44     bool isValid() const;
45     bool Marshalling(Parcel &parcel) const override;
46     static CameraMetadata* Unmarshalling(Parcel &parcel);
47 
48 private:
49     common_metadata_header_t *metadata_;
50 
51     bool resize_add_metadata(uint32_t item, const void *data, size_t data_count);
52     void replace_metadata(common_metadata_header_t *newMetadata);
53     static uint32_t AlignTo(uint32_t val, uint32_t alignment);
54     static uint32_t MaxAlignment(uint32_t dataAlignment, uint32_t metadataAlignment);
55     static size_t CalculateCameraMetadataMemoryRequired(uint32_t itemCount, uint32_t dataCount);
56     static int UpdateCameraMetadataItemSize(camera_metadata_item_entry_t *item, uint32_t dataCount,
57         common_metadata_header_t *dst, const void *data);
58     static int AddCameraMetadataItemVerify(common_metadata_header_t *dst,
59         uint32_t item, const void *data, size_t dataCount, uint32_t *dataType);
60     static int moveMetadataMemery(common_metadata_header_t *dst,
61         camera_metadata_item_entry_t *itemToDelete, size_t dataBytes);
62     static int copyMetadataMemory(common_metadata_header_t *dst, camera_metadata_item_entry_t *item,
63         size_t dataPayloadSize, const void *data);
64     static bool CheckItemDataType(camera_metadata_item_entry_t &item);
65 
66 public:
67     // Allocate a new camera metadata buffer and return the metadata header
68     static common_metadata_header_t *AllocateCameraMetadataBuffer(uint32_t item_capacity, uint32_t data_capacity);
69 
70     // Is camera metadata item exist
71     static bool IsCameraMetadataItemExist(const common_metadata_header_t *src, uint32_t item);
72 
73     // Find camera metadata item and fill the found item
74     static int FindCameraMetadataItem(const common_metadata_header_t *src, uint32_t item,
75         camera_metadata_item_t *metadataItem);
76 
77     // Find camera metadata item index if the item exists
78     static int FindCameraMetadataItemIndex(const common_metadata_header_t *src, uint32_t item, uint32_t *index,
79         bool isPrintLog = false);
80 
81     // Get camera metadata item name
82     static const char *GetCameraMetadataItemName(uint32_t item);
83 
84     // Update camera metadata item and fill the updated item
85     static int UpdateCameraMetadataItem(common_metadata_header_t *dst, uint32_t item, const void *data,
86         uint32_t dataCount, camera_metadata_item_t *updatedItem);
87 
88     // Update camera metadata item by index and fill the updated item
89     static int UpdateCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t index, const void *data,
90         uint32_t dataCount, camera_metadata_item_t *updated_item);
91 
92     // Add camera metadata item
93     static int AddCameraMetadataItem(common_metadata_header_t *dst, uint32_t item, const void *data, size_t dataCount);
94 
95     // Delete camera metadata item
96     static int DeleteCameraMetadataItem(common_metadata_header_t *dst, uint32_t item);
97 
98     // Delete camera metadata item by index
99     static int DeleteCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t index);
100 
101     // Free camera metadata buffer
102     static void FreeCameraMetadataBuffer(common_metadata_header_t *dst);
103 
104     static std::string MetadataItemDump(const common_metadata_header_t *metadataHeader, uint32_t item);
105 
106     static std::string FormatCameraMetadataToString(const common_metadata_header_t *metadataHeader);
107 
108     // Internal use
109     static camera_metadata_item_entry_t *GetMetadataItems(const common_metadata_header_t *metadataHeader);
110     static uint8_t *GetMetadataData(const common_metadata_header_t *metadataHeader);
111     static int GetCameraMetadataItem(const common_metadata_header_t *src, uint32_t index, camera_metadata_item_t *item);
112     static uint32_t GetCameraMetadataItemCount(const common_metadata_header_t *metadata_header);
113     static uint32_t GetCameraMetadataItemCapacity(const common_metadata_header_t *metadata_header);
114     static uint32_t GetCameraMetadataDataSize(const common_metadata_header_t *metadata_header);
115     static int32_t CopyCameraMetadataItems(common_metadata_header_t *newMetadata,
116         const common_metadata_header_t *oldMetadata);
117     static int32_t CalculateCameraMetadataItemDataSize(uint32_t type, size_t data_count);
118     static int32_t GetCameraMetadataItemType(uint32_t item, uint32_t *data_type);
119     static common_metadata_header_t *FillCameraMetadata(common_metadata_header_t *buffer, size_t memoryRequired,
120         uint32_t itemCapacity, uint32_t dataCapacity);
121     static int32_t GetMetadataSection(uint32_t itemSection, uint32_t *section);
122     static int MetadataExpandItemMem(common_metadata_header_t *dst, camera_metadata_item_entry_t *item,
123         size_t oldItemSize);
124     static int32_t GetAllVendorTags(std::vector<vendorTag_t>& tagVec);
125 };
126 } // namespace Camera
127 #endif /* CAMERA_METADATA_INFO_H */
128