• 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 <iostream>
20 #include <unordered_map>
21 #include <vector>
22 #include <refbase.h>
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 class CameraDevice : public RefBase {
49 public:
50     CameraDevice() = default;
51     CameraDevice(std::string cameraID, std::shared_ptr<OHOS::Camera::CameraMetadata> metadata);
52     ~CameraDevice();
53     /**
54     * @brief Get the camera Id.
55     *
56     * @return Returns the camera Id.
57     */
58     std::string GetID();
59 
60     /**
61     * @brief Get the metadata corresponding to current camera object.
62     *
63     * @return Returns the metadata corresponding to current object.
64     */
65     std::shared_ptr<OHOS::Camera::CameraMetadata> GetMetadata();
66 
67     /**
68     * @brief Get the position of the camera.
69     *
70     * @return Returns the position of the camera.
71     */
72     CameraPosition GetPosition();
73 
74     /**
75     * @brief Get the Camera type of the camera.
76     *
77     * @return Returns the Camera type of the camera.
78     */
79     CameraType GetCameraType();
80 
81     /**
82     * @brief Get the Camera connection type.
83     *
84     * @return Returns the Camera type of the camera.
85     */
86     ConnectionType GetConnectionType();
87 
88     /**
89     * @brief Check if mirror mode supported.
90     *
91     * @return Returns True is supported.
92     */
93     bool IsMirrorSupported();
94 
95     // or can we move definition completely in session only?
96     /**
97     * @brief Get the supported Zoom Ratio range.
98     *
99     * @return Returns vector<float> of supported Zoom ratio range.
100     */
101     std::vector<float> GetZoomRatioRange();
102 
103     /**
104     * @brief Get the supported exposure compensation range.
105     *
106     * @return Returns vector<int32_t> of supported exposure compensation range.
107     */
108     std::vector<int32_t> GetExposureBiasRange();
109 
110 private:
111     std::string cameraID_;
112     std::shared_ptr<OHOS::Camera::CameraMetadata> metadata_;
113     CameraPosition cameraPosition_ = CAMERA_POSITION_UNSPECIFIED;
114     CameraType cameraType_ = CAMERA_TYPE_DEFAULT;
115     ConnectionType connectionType_ = CAMERA_CONNECTION_BUILT_IN;
116     bool isMirrorSupported_ = false;
117     std::vector<float> zoomRatioRange_;
118     std::vector<int32_t> exposureBiasRange_;
119     static const std::unordered_map<camera_type_enum_t, CameraType> metaToFwCameraType_;
120     static const std::unordered_map<camera_position_enum_t, CameraPosition> metaToFwCameraPosition_;
121     static const std::unordered_map<camera_connection_type_t, ConnectionType> metaToFwConnectionType_;
122 
123     void init(common_metadata_header_t* metadataHeader);
124     std::vector<float> CalculateZoomRange();
125 };
126 } // namespace CameraStandard
127 } // namespace OHOS
128 #endif // OHOS_CAMERA_CAMERA_DEVICE_H
129