• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_CAMERA_DEVICE_H
17 #define OHOS_CAMERA_CAMERA_DEVICE_H
18 
19 #include <iostream>
20 #include <memory>
21 #include <refbase.h>
22 #include <type_traits>
23 #include <unordered_map>
24 #include <vector>
25 
26 #include "camera_metadata_info.h"
27 #include "output/camera_output_capability.h"
28 #include "output/capture_output.h"
29 #include "ability/camera_ability.h"
30 #include "ability/camera_ability_parse_util.h"
31 
32 namespace OHOS {
33 namespace CameraStandard {
34 enum CameraPosition {
35     CAMERA_POSITION_UNSPECIFIED = 0,
36     CAMERA_POSITION_BACK,
37     CAMERA_POSITION_FRONT,
38     CAMERA_POSITION_FOLD_INNER
39 };
40 
41 enum CameraType {
42     CAMERA_TYPE_UNSUPPORTED = -1,
43     CAMERA_TYPE_DEFAULT = 0,
44     CAMERA_TYPE_WIDE_ANGLE,
45     CAMERA_TYPE_ULTRA_WIDE,
46     CAMERA_TYPE_TELEPHOTO,
47     CAMERA_TYPE_TRUE_DEPTH
48 };
49 
50 enum ConnectionType {
51     CAMERA_CONNECTION_BUILT_IN = 0,
52     CAMERA_CONNECTION_USB_PLUGIN,
53     CAMERA_CONNECTION_REMOTE
54 };
55 
56 enum CameraFoldScreenType {
57     CAMERA_FOLDSCREEN_UNSPECIFIED = 0,
58     CAMERA_FOLDSCREEN_INNER,
59     CAMERA_FOLDSCREEN_OUTER
60 };
61 
62 enum AuxiliaryType {
63     CONTRACTLENS = 0
64 };
65 
66 enum AuxiliaryStatus {
67     AUXILIARY_LOCKED = 0,
68     AUXILIARY_ON,
69     AUXILIARY_OFF
70 };
71 
72 typedef struct dmDeviceInfo {
73     /**
74      * Device name of the device.
75      */
76     std::string deviceName;
77     /**
78      * Device type of the device.
79      */
80     uint16_t deviceTypeId;
81     /**
82      * NetworkId of the device.
83      */
84     std::string networkId;
85 } dmDeviceInfo;
86 
87 class CameraDevice : public RefBase {
88 public:
89     explicit CameraDevice(std::string cameraID, std::shared_ptr<OHOS::Camera::CameraMetadata> metadata);
90     explicit CameraDevice(
91         std::string cameraID, std::shared_ptr<OHOS::Camera::CameraMetadata> metadata, dmDeviceInfo deviceInfo);
92     virtual ~CameraDevice() = default;
93     /**
94     * @brief Get the camera Id.
95     *
96     * @return Returns the camera Id.
97     */
98     std::string GetID();
99 
100     /**
101     * @brief Get the metadata corresponding to current camera object.
102     *
103     * @return Returns the metadata corresponding to current object.
104     */
105     std::shared_ptr<OHOS::Camera::CameraMetadata> GetMetadata();
106 
107     /**
108     * @brief Reset cachedMetadata_ to default status
109     */
110     void ResetMetadata();
111 
112     /**
113     * @brief Get the current camera static abilities.
114     *
115     * @return Returns the current camera static abilities.
116     */
117     const std::shared_ptr<OHOS::Camera::CameraMetadata> GetCameraAbility();
118 
119     /**
120     * @brief Get the position of the camera.
121     *
122     * @return Returns the position of the camera.
123     */
124     CameraPosition GetPosition();
125 
126     /**
127     * @brief Get the used as position of the camera.
128     *
129     * @return Returns the used as position of the camera.
130     */
131     CameraPosition GetUsedAsPosition();
132 
133     /**
134     * @brief Get the Camera type of the camera.
135     *
136     * @return Returns the Camera type of the camera.
137     */
138     CameraType GetCameraType();
139 
140     /**
141     * @brief Get the Camera connection type.
142     *
143     * @return Returns the Camera type of the camera.
144     */
145     ConnectionType GetConnectionType();
146 
147     /**
148     * @brief Get the facing for foldScreen device.
149     *
150     * @return Returns the Camera type of the camera.
151     */
152     CameraFoldScreenType GetCameraFoldScreenType();
153 
154     /**
155     * @brief Get the Distributed Camera Host Name.
156     *
157     * @return Returns the  Host Name of the Distributed camera.
158     */
159     std::string GetHostName();
160 
161     /**
162     * @brief Get the Distributed Camera deviceType.
163     *
164     * @return Returns the deviceType of the Distributed camera.
165     */
166     uint16_t GetDeviceType();
167 
168     /**
169     * @brief Get the Distributed Camera networkId.
170     *
171     * @return Returns the networkId of the Distributed camera.
172     */
173     std::string GetNetWorkId();
174 
175     /**
176     * @brief Get the camera orientation.
177     *
178     * @return Returns the camera orientation.
179     */
180     uint32_t GetCameraOrientation();
181 
182     // or can we move definition completely in session only?
183     /**
184     * @brief Get the supported Zoom Ratio range.
185     *
186     * @return Returns vector<float> of supported Zoom ratio range.
187     */
188     std::vector<float> GetZoomRatioRange();
189 
190     /**
191     * @brief Get the supported exposure compensation range.
192     *
193     * @return Returns vector<int32_t> of supported exposure compensation range.
194     */
195     std::vector<float> GetExposureBiasRange();
196 
197     void SetProfile(sptr<CameraOutputCapability> cameraOutputCapability);
198 
199     void SetProfile(sptr<CameraOutputCapability> cameraOutputCapability, int32_t modename);
200 
201     void SetCameraDeviceUsedAsPosition(CameraPosition usedAsPosition);
202 
203     /**
204     * @brief Get sensor module type
205     *
206     * @return moduleType sensor module type.
207     */
208     uint32_t GetModuleType();
209 
210     /**
211     * @brief Get the supported fold status of the device
212     * @return The supported fold status of the device
213     *
214     * foldStatus enum values:
215     *   0: OHOS_CAMERA_FOLD_STATUS_NONFOLDABLE
216     *   1: OHOS_CAMERA_FOLD_STATUS_EXPANDED
217     *   2: OHOS_CAMERA_FOLD_STATUS_FOLDED
218     *   3: OHOS_CAMERA_FOLD_STATUS_EXPANDED + OHOS_CAMERA_FOLD_STATUS_FOLDED
219     */
220     uint32_t GetSupportedFoldStatus();
221 
222     template<typename T, typename = std::enable_if_t<std::is_same_v<T, Profile> || std::is_same_v<T, VideoProfile>>>
GetMaxSizeProfile(std::vector<T> & profiles,float profileRatioValue,CameraFormat format)223     std::shared_ptr<T> GetMaxSizeProfile(std::vector<T>& profiles, float profileRatioValue, CameraFormat format)
224     {
225         if (profileRatioValue <= 0) {
226             return nullptr;
227         }
228         std::shared_ptr<T> maxSizeProfile = nullptr;
229         for (auto& profile : profiles) {
230             if (profile.size_.width == 0 || profile.size_.height == 0) {
231                 continue;
232             }
233             if (profile.format_ != format) {
234                 continue;
235             }
236             float ratio = ((float)profile.size_.width) / profile.size_.height;
237             if (abs(ratio - profileRatioValue) / profileRatioValue > 0.05f) { // 0.05f is 5% tolerance
238                 continue;
239             }
240             if (maxSizeProfile == nullptr || profile.size_.width > maxSizeProfile->size_.width) {
241                 maxSizeProfile = std::make_shared<T>(profile);
242             }
243         }
244         return maxSizeProfile;
245     }
246 
247     std::unordered_map<int32_t, std::vector<Profile>> modePreviewProfiles_ = {};
248     std::unordered_map<int32_t, std::vector<Profile>> modePhotoProfiles_ = {};
249     std::unordered_map<int32_t, std::vector<VideoProfile>> modeVideoProfiles_ = {};
250     std::unordered_map<int32_t, DeferredDeliveryImageType> modeDeferredType_ = {};
251     CameraPosition usedAsCameraPosition_ = CAMERA_POSITION_UNSPECIFIED;
252     std::unordered_map<int32_t, int32_t> modeVideoDeferredType_ = {};
253 private:
254     std::string cameraID_;
255     const std::shared_ptr<OHOS::Camera::CameraMetadata> baseAbility_;
256     std::mutex cachedMetadataMutex_;
257     std::shared_ptr<OHOS::Camera::CameraMetadata> cachedMetadata_;
258     CameraPosition cameraPosition_ = CAMERA_POSITION_UNSPECIFIED;
259     CameraType cameraType_ = CAMERA_TYPE_DEFAULT;
260     ConnectionType connectionType_ = CAMERA_CONNECTION_BUILT_IN;
261     CameraFoldScreenType foldScreenType_ = CAMERA_FOLDSCREEN_UNSPECIFIED;
262     uint32_t cameraOrientation_ = 0;
263     uint32_t moduleType_ = 0;
264     uint32_t foldStatus_ = 0;
265     dmDeviceInfo dmDeviceInfo_ = {};
266     std::vector<float> zoomRatioRange_;
267     std::vector<float> exposureBiasRange_;
268     static const std::unordered_map<camera_type_enum_t, CameraType> metaToFwCameraType_;
269     static const std::unordered_map<camera_position_enum_t, CameraPosition> metaToFwCameraPosition_;
270     static const std::unordered_map<camera_connection_type_t, ConnectionType> metaToFwConnectionType_;
271     static const std::unordered_map<camera_foldscreen_enum_t, CameraFoldScreenType> metaToFwCameraFoldScreenType_;
272     void init(common_metadata_header_t* metadataHeader);
273     bool isFindModuleTypeTag(uint32_t &tagId);
274 };
275 } // namespace CameraStandard
276 } // namespace OHOS
277 #endif // OHOS_CAMERA_CAMERA_DEVICE_H
278