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 #ifndef METADATA_CONTROLLER_H 17 #define METADATA_CONTROLLER_H 18 19 #include "metadata_config.h" 20 #include <list> 21 #include <mutex> 22 #include <queue> 23 #include <thread> 24 #include <unordered_set> 25 26 namespace OHOS { 27 namespace Camera { 28 class MetadataController { 29 using CameraNode = std::vector<std::function<void(std::shared_ptr<CameraMetadata>)>>; 30 31 public: 32 static MetadataController &GetInstance(); 33 void SetUpdateSettingCallback(const MetaDataCb &cb); 34 void UnSetUpdateSettingCallback(); 35 void AddNodeCallback(const MetaDataCb &cb); 36 void ClearNodeCallback(); 37 void SetPeerFrameFlag(bool flag); 38 void AddEnabledAbility(const std::vector<int32_t> &abilityMetaDataTag); 39 int32_t GetEnabledAbility(std::vector<int32_t> &results); 40 int32_t DelEnabledAbility(const std::vector<int32_t> &results); 41 bool UpdateSettingsConfig(const std::shared_ptr<CameraMetadata> &meta); 42 void GetSettingsConfig(std::shared_ptr<CameraMetadata> &meta); 43 void NotifyMetaData(int32_t streamId); 44 void SetDeviceDefaultMetadata(std::shared_ptr<CameraMetadata> &meta); 45 void Start(); 46 void Stop(); 47 48 private: 49 MetadataController(); 50 ~MetadataController(); 51 52 void DealMessage(); 53 void StopThread(); 54 int32_t GetStreamId(const std::shared_ptr<CameraMetadata> &meta); 55 bool FilterUpdateKeys(int32_t streamId, const std::shared_ptr<CameraMetadata> &meta); 56 bool DealMetadata(int32_t streamId, const std::shared_ptr<CameraMetadata> &meta); 57 bool CompareMetadata(int32_t streamId, const std::shared_ptr<CameraMetadata> &oldMeta, 58 const std::shared_ptr<CameraMetadata> &newMeta, std::shared_ptr<CameraMetadata> &outMetadata); 59 bool UpdateChangeMetadata(int32_t streamId, const std::vector<int32_t> &updateKeys, 60 const std::vector<int32_t> &newKeys, const std::shared_ptr<CameraMetadata> &newMeta, 61 std::shared_ptr<CameraMetadata> &outMetadata); 62 bool IsChangeTagData(int32_t key, const camera_metadata_item_t &baseEntry, const camera_metadata_item_t &newEntry); 63 bool IsChangeU8Metadata(const camera_metadata_item_t &baseEntry, const camera_metadata_item_t &newEntry); 64 bool IsChangeI32Metadata(const camera_metadata_item_t &baseEntry, const camera_metadata_item_t &newEntry); 65 bool IsChangeI64Metadata(const camera_metadata_item_t &baseEntry, const camera_metadata_item_t &newEntry); 66 bool IsChangeFloatMetadata(const camera_metadata_item_t &baseEntry, const camera_metadata_item_t &newEntry); 67 bool IsChangeI32ArrayMetadata(const camera_metadata_item_t &baseEntry, const camera_metadata_item_t &newEntry); 68 bool UpdateNewTagData(const std::vector<int32_t> &keys, const std::shared_ptr<CameraMetadata> &inMeta, 69 std::shared_ptr<CameraMetadata> &outMeta); 70 bool DealUpdateNewTagData( 71 const std::vector<int32_t> &keys, common_metadata_header_t *data, std::shared_ptr<CameraMetadata> &outMeta); 72 73 std::shared_ptr<MetadataConfig> metaDataConfig_ = nullptr; 74 MetaDataCb updateSettingFunc_; 75 CameraNode nodeFunc_; 76 std::unordered_set<int32_t> firstNotifyNodes_; 77 std::map<int32_t, std::vector<int32_t>> updateMetaDataKeys_; 78 std::map<int32_t, std::vector<int32_t>> changeDataKeys_; 79 bool peerFrame_; 80 std::vector<int32_t> abilityMetaData_; 81 std::mutex dataConfigLock_; 82 std::mutex queueLock_; 83 std::condition_variable cv_; 84 std::queue<std::shared_ptr<CameraMetadata>> queue_; 85 std::atomic_bool isRunning_; 86 std::thread *notifyChangedMetadata_ = nullptr; 87 bool isInit_ = false; 88 }; 89 } // namespace Camera 90 } // namespace OHOS 91 #endif 92