• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 DISTRIBUTED_CAMERA_METADATA_PROCESSOR_H
17 #define DISTRIBUTED_CAMERA_METADATA_PROCESSOR_H
18 
19 #include <set>
20 #include <map>
21 #include <mutex>
22 #include <vector>
23 #include "constants.h"
24 #include "dcamera.h"
25 #include "json/json.h"
26 #include "v1_0/dcamera_types.h"
27 #include "v1_0/types.h"
28 
29 namespace OHOS {
30 namespace DistributedHardware {
31 using namespace OHOS::HDI::Camera::V1_0;
32 using namespace OHOS::HDI::DistributedCamera::V1_0;
33 class DMetadataProcessor {
34 public:
35     DMetadataProcessor() = default;
36     ~DMetadataProcessor() = default;
37     DMetadataProcessor(const DMetadataProcessor &other) = delete;
38     DMetadataProcessor(DMetadataProcessor &&other) = delete;
39     DMetadataProcessor& operator=(const DMetadataProcessor &other) = delete;
40     DMetadataProcessor& operator=(DMetadataProcessor &&other) = delete;
41 
42 public:
43     DCamRetCode InitDCameraAbility(const std::string &abilityInfo);
44     DCamRetCode GetDCameraAbility(std::shared_ptr<CameraAbility> &ability);
45     DCamRetCode SetMetadataResultMode(const ResultCallbackMode &mode);
46     DCamRetCode GetEnabledMetadataResults(std::vector<MetaType> &results);
47     DCamRetCode EnableMetadataResult(const std::vector<MetaType> &results);
48     DCamRetCode DisableMetadataResult(const std::vector<MetaType> &results);
49     DCamRetCode ResetEnableResults();
50     DCamRetCode SaveResultMetadata(std::string resultStr);
51     void UpdateResultMetadata(const uint64_t &resultTimestamp);
52     void SetResultCallback(std::function<void(uint64_t, std::shared_ptr<OHOS::Camera::CameraMetadata>)> &resultCbk);
53     void PrintDCameraMetadata(const common_metadata_header_t *metadata);
54 
55 private:
56     DCamRetCode InitDCameraDefaultAbilityKeys(const std::string &abilityInfo);
57     DCamRetCode InitDCameraOutputAbilityKeys(const std::string &abilityInfo);
58     DCamRetCode AddAbilityEntry(uint32_t tag, const void *data, size_t size);
59     DCamRetCode UpdateAbilityEntry(uint32_t tag, const void *data, size_t size);
60     void ConvertToCameraMetadata(common_metadata_header_t *&input,
61         std::shared_ptr<OHOS::Camera::CameraMetadata> &output);
62     void ResizeMetadataHeader(common_metadata_header_t *&header, uint32_t itemCapacity, uint32_t dataCapacity);
63     void UpdateAllResult(const uint64_t &resultTimestamp);
64     void UpdateOnChanged(const uint64_t &resultTimestamp);
65     uint32_t GetDataSize(uint32_t type);
66     void* GetMetadataItemData(const camera_metadata_item_t &item);
67     std::map<int, std::vector<DCResolution>> GetDCameraSupportedFormats(const std::string &abilityInfo);
68     void ParsePhotoFormats(Json::Value& rootValue, std::map<int, std::vector<DCResolution>>& supportedFormats);
69     void ParsePreviewFormats(Json::Value& rootValue, std::map<int, std::vector<DCResolution>>& supportedFormats);
70     void ParseVideoFormats(Json::Value& rootValue, std::map<int, std::vector<DCResolution>>& supportedFormats);
71     void InitDcameraBaseAbility();
72     void GetEachNodeSupportedResolution(std::vector<int>& formats, const std::string rootNode,
73         std::map<int, std::vector<DCResolution>>& supportedFormats, Json::Value& rootValue);
74     void GetNodeSupportedResolution(int format, std::string formatStr, const std::string rootNode,
75         std::map<int, std::vector<DCResolution>>& supportedFormats, Json::Value& rootValue);
76     void SetFpsRanges();
77 
78 private:
79     constexpr static uint32_t JSON_ARRAY_MAX_SIZE = 1000;
80     std::function<void(uint64_t, std::shared_ptr<OHOS::Camera::CameraMetadata>)> resultCallback_;
81     std::shared_ptr<CameraAbility> dCameraAbility_;
82     std::string protocolVersion_;
83     std::string dCameraPosition_;
84     DCResolution maxPreviewResolution_;
85     DCResolution maxPhotoResolution_;
86     ResultCallbackMode metaResultMode_;
87     std::set<MetaType> allResultSet_;
88     std::set<MetaType> enabledResultSet_;
89     std::mutex producerMutex_;
90 
91     // The latest result metadata that received from the sink device.
92     std::shared_ptr<OHOS::Camera::CameraMetadata> latestProducerMetadataResult_;
93 
94     // The latest result metadata that replied to the camera service.
95     std::shared_ptr<OHOS::Camera::CameraMetadata> latestConsumerMetadataResult_;
96 };
97 } // namespace DistributedHardware
98 } // namespace OHOS
99 #endif // DISTRIBUTED_CAMERA_METADATA_PROCESSOR_H