• 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 OHOS_CAMERA_CAMERA_DEVICE_H
17 #define OHOS_CAMERA_CAMERA_DEVICE_H
18 
19 #include <refbase.h>
20 #include <iostream>
21 #include <unordered_map>
22 #include <vector>
23 #include "camera_metadata_info.h"
24 
25 namespace OHOS {
26 namespace CameraStandard {
27 enum CameraPosition {
28     CAMERA_POSITION_UNSPECIFIED = 0,
29     CAMERA_POSITION_BACK,
30     CAMERA_POSITION_FRONT
31 };
32 
33 enum CameraType {
34     CAMERA_TYPE_UNSUPPORTED = -1,
35     CAMERA_TYPE_DEFAULT = 0,
36     CAMERA_TYPE_WIDE_ANGLE,
37     CAMERA_TYPE_ULTRA_WIDE,
38     CAMERA_TYPE_TELEPHOTO,
39     CAMERA_TYPE_TRUE_DEPTH
40 };
41 
42 enum ConnectionType {
43     CAMERA_CONNECTION_BUILT_IN = 0,
44     CAMERA_CONNECTION_USB_PLUGIN,
45     CAMERA_CONNECTION_REMOTE
46 };
47 
48 typedef struct dmDeviceInfo {
49     /**
50      * Device name of the device.
51      */
52     std::string deviceName;
53     /**
54      * Device type of the device.
55      */
56     uint16_t deviceTypeId;
57     /**
58      * NetworkId of the device.
59      */
60     std::string networkId;
61 } dmDeviceInfo;
62 
63 class CameraDevice : public RefBase {
64 public:
65     CameraDevice() = default;
66     CameraDevice(std::string cameraID, std::shared_ptr<OHOS::Camera::CameraMetadata> metadata);
67     CameraDevice(std::string cameraID, std::shared_ptr<OHOS::Camera::CameraMetadata> metadata, dmDeviceInfo deviceInfo);
68     ~CameraDevice();
69     /**
70     * @brief Get the camera Id.
71     *
72     * @return Returns the camera Id.
73     */
74     std::string GetID();
75 
76     /**
77     * @brief Get the metadata corresponding to current camera object.
78     *
79     * @return Returns the metadata corresponding to current object.
80     */
81     std::shared_ptr<OHOS::Camera::CameraMetadata> GetMetadata();
82 
83     /**
84     * @brief Get the position of the camera.
85     *
86     * @return Returns the position of the camera.
87     */
88     CameraPosition GetPosition();
89 
90     /**
91     * @brief Get the Camera type of the camera.
92     *
93     * @return Returns the Camera type of the camera.
94     */
95     CameraType GetCameraType();
96 
97     /**
98     * @brief Get the Camera connection type.
99     *
100     * @return Returns the Camera type of the camera.
101     */
102     ConnectionType GetConnectionType();
103 
104     /**
105     * @brief Get the Distributed Camera Host Name.
106     *
107     * @return Returns the  Host Name of the Distributed camera.
108     */
109     std::string GetHostName();
110 
111     /**
112     * @brief Get the Distributed Camera deviceType.
113     *
114     * @return Returns the deviceType of the Distributed camera.
115     */
116     uint16_t GetDeviceType();
117 
118     /**
119     * @brief Get the Distributed Camera networkId.
120     *
121     * @return Returns the networkId of the Distributed camera.
122     */
123     std::string GetNetWorkId();
124     /**
125     * @brief Check if mirror mode supported.
126     *
127     * @return Returns True is supported.
128     */
129     bool IsMirrorSupported();
130 
131     // or can we move definition completely in session only?
132     /**
133     * @brief Get the supported Zoom Ratio range.
134     *
135     * @return Returns vector<float> of supported Zoom ratio range.
136     */
137     std::vector<float> GetZoomRatioRange();
138 
139     /**
140     * @brief Get the supported exposure compensation range.
141     *
142     * @return Returns vector<int32_t> of supported exposure compensation range.
143     */
144     std::vector<float> GetExposureBiasRange();
145 
146 private:
147     std::string cameraID_;
148     std::shared_ptr<OHOS::Camera::CameraMetadata> metadata_;
149     CameraPosition cameraPosition_ = CAMERA_POSITION_UNSPECIFIED;
150     CameraType cameraType_ = CAMERA_TYPE_DEFAULT;
151     ConnectionType connectionType_ = CAMERA_CONNECTION_BUILT_IN;
152     bool isMirrorSupported_ = false;
153     dmDeviceInfo dmDeviceInfo_ = {};
154     std::vector<float> zoomRatioRange_;
155     std::vector<float> exposureBiasRange_;
156     static const std::unordered_map<camera_type_enum_t, CameraType> metaToFwCameraType_;
157     static const std::unordered_map<camera_position_enum_t, CameraPosition> metaToFwCameraPosition_;
158     static const std::unordered_map<camera_connection_type_t, ConnectionType> metaToFwConnectionType_;
159 
160     void init(common_metadata_header_t* metadataHeader);
161     std::vector<float> CalculateZoomRange();
162 };
163 } // namespace CameraStandard
164 } // namespace OHOS
165 #endif // OHOS_CAMERA_CAMERA_DEVICE_H
166