• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "metadata_config.h"
17 
18 namespace OHOS {
19 namespace Camera {
MetadataConfig()20 MetadataConfig::MetadataConfig()
21 {
22     metadata_.clear();
23 }
~MetadataConfig()24 MetadataConfig::~MetadataConfig() {}
25 
UpdateSettingsConfig(int32_t streamId,bool isNew,const std::vector<int32_t> & updateKeys,const std::shared_ptr<CameraMetadata> & metaData)26 bool MetadataConfig::UpdateSettingsConfig(int32_t streamId, bool isNew, const std::vector<int32_t> &updateKeys,
27     const std::shared_ptr<CameraMetadata> &metaData)
28 {
29     if (updateKeys.size() == 0) {
30         CAMERA_LOGE("invalid size");
31         return false;
32     }
33 
34     if (metadata_.count(streamId) == 0) {
35         std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraMetadata>(ENTRY_CAPACITY, DATA_CAPACITY);
36         if (meta == nullptr) {
37             CAMERA_LOGE("meta is null");
38             return false;
39         }
40         metadata_[streamId] = meta;
41     }
42 
43     common_metadata_header_t *data = metaData->get();
44     if (data == nullptr) {
45         CAMERA_LOGE("data is null");
46         return false;
47     }
48 
49     bool result = false;
50     for (auto it = updateKeys.cbegin(); it != updateKeys.cend(); it++) {
51         camera_metadata_item_t entry;
52         int ret = FindCameraMetadataItem(data, *it, &entry);
53         if (ret != 0) {
54             CAMERA_LOGE("get [%{public}d] error", *it);
55             return false;
56         }
57         if (isNew) {
58             result = metadata_[streamId]->addEntry(*it, static_cast<void *>(entry.data.u8), entry.count);
59         } else {
60             result = metadata_[streamId]->updateEntry(*it, static_cast<void *>(entry.data.u8), entry.count);
61         }
62         if (!result) {
63             CAMERA_LOGE("add key: [%{public}d] failed", *it);
64             return false;
65         }
66     }
67     return result;
68 }
69 
GetMetadata(int32_t streamId,std::shared_ptr<CameraMetadata> & metaData)70 bool MetadataConfig::GetMetadata(int32_t streamId, std::shared_ptr<CameraMetadata> &metaData)
71 {
72     if (streamId < 0 || metadata_.count(streamId) == 0) {
73         return false;
74     }
75     metaData = metadata_[streamId];
76     return true;
77 }
78 
GetDeviceDefaultMetadata(std::shared_ptr<CameraMetadata> & metaData)79 void MetadataConfig::GetDeviceDefaultMetadata(std::shared_ptr<CameraMetadata> &metaData)
80 {
81     int32_t exposureCompensation = 1;
82     constexpr uint32_t DATA_COUNT = 1;
83     metaData->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &exposureCompensation, DATA_COUNT);
84 
85     uint8_t videoStabiliMode = OHOS_CAMERA_VIDEO_STABILIZATION_OFF;
86     metaData->addEntry(OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &videoStabiliMode, DATA_COUNT);
87 
88     uint8_t focusMode = 0;
89     metaData->addEntry(OHOS_CONTROL_FOCUS_MODE, &focusMode, sizeof(focusMode));
90 
91     uint8_t meterMode = 1;
92     metaData->addEntry(OHOS_CONTROL_METER_MODE, &meterMode, sizeof(meterMode));
93 
94     uint8_t flashMode = 1;
95     metaData->addEntry(OHOS_CONTROL_FLASH_MODE, &flashMode, sizeof(flashMode));
96 }
97 } // namespace Camera
98 } // namespace OHOS
99