1 /*
2 * Copyright (c) 2025-2025 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 OHOS_CAMERA_METADATA_H
17 #define OHOS_CAMERA_METADATA_H
18
19 #include <cstdint>
20 #include "camera_metadata_operator.h"
21 #include "metadata_utils.h"
22
23 namespace OHOS {
24 namespace CameraStandard {
25 template<typename T>
AddOrUpdateMetadata(common_metadata_header_t * src,uint32_t tag,const T * data,uint32_t dataCount)26 bool AddOrUpdateMetadata(common_metadata_header_t* src, uint32_t tag, const T* data, uint32_t dataCount)
27 {
28 if (src == nullptr) {
29 return false;
30 }
31 uint32_t index = 0;
32 int ret = OHOS::Camera::CameraMetadata::FindCameraMetadataItemIndex(src, tag, &index, false);
33 if (ret == CAM_META_SUCCESS) {
34 ret = OHOS::Camera::CameraMetadata::UpdateCameraMetadataItemByIndex(src, index, data, dataCount, nullptr);
35 } else if (ret == CAM_META_ITEM_NOT_FOUND) {
36 ret = OHOS::Camera::CameraMetadata::AddCameraMetadataItem(src, tag, data, dataCount);
37 }
38 return ret == CAM_META_SUCCESS;
39 }
40
41 template<typename T>
AddOrUpdateMetadata(std::shared_ptr<OHOS::Camera::CameraMetadata> & metadata,uint32_t tag,const T * data,uint32_t dataCount)42 bool AddOrUpdateMetadata(
43 std::shared_ptr<OHOS::Camera::CameraMetadata>& metadata, uint32_t tag, const T* data, uint32_t dataCount)
44 {
45 common_metadata_header_t* src = metadata->get();
46 if (src == nullptr) {
47 return false;
48 }
49
50 uint32_t index = 0;
51 int ret = OHOS::Camera::CameraMetadata::FindCameraMetadataItemIndex(src, tag, &index);
52 if (ret == CAM_META_SUCCESS) {
53 ret = OHOS::Camera::CameraMetadata::UpdateCameraMetadataItemByIndex(src, index, data, dataCount, nullptr);
54 } else if (ret == CAM_META_ITEM_NOT_FOUND) {
55 // addEntry can resize if need
56 return metadata->addEntry(tag, data, dataCount);
57 }
58 return ret == CAM_META_SUCCESS;
59 }
60
61 std::shared_ptr<OHOS::Camera::CameraMetadata> CopyMetadata(
62 const std::shared_ptr<OHOS::Camera::CameraMetadata> srcMetadata);
63
64 std::shared_ptr<camera_metadata_item_t> GetMetadataItem(const common_metadata_header_t* src, uint32_t tag);
65
66 } // namespace CameraStandard
67 } // namespace OHOS
68 #endif
69