• 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_INPUT_H
17 #define OHOS_CAMERA_CAMERA_INPUT_H
18 
19 #include <iostream>
20 #include <unordered_map>
21 #include <set>
22 #include <vector>
23 #include "camera_info.h"
24 #include "camera_device.h"
25 #include "capture_input.h"
26 #include "icamera_device_service.h"
27 #include "icamera_device_service_callback.h"
28 namespace OHOS {
29 namespace CameraStandard {
30 class ErrorCallback {
31 public:
32     ErrorCallback() = default;
33     virtual ~ErrorCallback() = default;
34     virtual void OnError(const int32_t errorType, const int32_t errorMsg) const;
35 };
36 
37 class CameraInput : public CaptureInput {
38 public:
39     [[deprecated]] CameraInput(sptr<ICameraDeviceService> &deviceObj, sptr<CameraInfo> &camera);
40     CameraInput(sptr<ICameraDeviceService> &deviceObj, sptr<CameraDevice> &camera);
41     virtual ~CameraInput();
42 
43     /**
44     * @brief open camera.
45     */
46     int Open() override;
47 
48     /**
49     * @brief close camera.
50     */
51     int Close() override;
52 
53     /**
54     * @brief create new device control setting.
55     */
56     [[deprecated]] void LockForControl();
57 
58     /**
59     * @brief submit device control setting.
60     *
61     * @return Returns CAMERA_OK is success.
62     */
63     [[deprecated]] int32_t UnlockForControl();
64 
65     /**
66     * @brief Get the supported format for photo.
67     *
68     * @return Returns vector of camera_format_t supported format for photo.
69     */
70     [[deprecated]] std::vector<camera_format_t> GetSupportedPhotoFormats();
71 
72     /**
73     * @brief Get the supported format for video.
74     *
75     * @return Returns vector of camera_format_t supported format for video.
76     */
77     [[deprecated]] std::vector<camera_format_t> GetSupportedVideoFormats();
78 
79     /**
80     * @brief Get the supported format for preview.
81     *
82     * @return Returns vector of camera_format_t supported format for preview.
83     */
84     [[deprecated]] std::vector<camera_format_t> GetSupportedPreviewFormats();
85 
86     /**
87     * @brief Get the supported exposure modes.
88     *
89     * @return Returns vector of camera_exposure_mode_enum_t supported exposure modes.
90     */
91     [[deprecated]] std::vector<camera_exposure_mode_enum_t> GetSupportedExposureModes();
92 
93     /**
94     * @brief Query whether given exposure mode supported.
95     *
96     * @param camera_exposure_mode_enum_t exposure mode to query.
97     * @return True is supported false otherwise.
98     */
99     [[deprecated]] bool IsExposureModeSupported(camera_exposure_mode_enum_t exposureMode);
100 
101     /**
102     * @brief Set exposure mode.
103     *
104     * @param camera_exposure_mode_enum_t exposure mode to be set.
105     */
106     [[deprecated]] void SetExposureMode(camera_exposure_mode_enum_t exposureMode);
107 
108     /**
109     * @brief Get the current exposure mode.
110     *
111     * @return Returns current exposure mode.
112     */
113     [[deprecated]] camera_exposure_mode_enum_t GetExposureMode();
114 
115     /**
116     * @brief Get the supported Focus modes.
117     *
118     * @return Returns vector of camera_focus_mode_enum_t supported exposure modes.
119     */
120     [[deprecated]] std::vector<camera_focus_mode_enum_t> GetSupportedFocusModes();
121 
122     /**
123     * @brief Get exposure compensation range.
124     *
125     * @return Returns supported exposure compensation range.
126     */
127     [[deprecated]] std::vector<int32_t> GetExposureBiasRange();
128 
129     /**
130     * @brief Set exposure compensation value.
131     *
132     * @param exposure compensation value to be set.
133     */
134     [[deprecated]] void SetExposureBias(int32_t exposureBias);
135 
136     /**
137     * @brief Get exposure compensation value.
138     *
139     * @return Returns current exposure compensation value.
140     */
141     [[deprecated]] int32_t GetExposureValue();
142 
143     /**
144     * @brief Query whether given focus mode supported.
145     *
146     * @param camera_focus_mode_enum_t focus mode to query.
147     * @return True is supported false otherwise.
148     */
149     [[deprecated]] bool IsFocusModeSupported(camera_focus_mode_enum_t focusMode);
150 
151     /**
152     * @brief Set Focus mode.
153     *
154     * @param camera_focus_mode_enum_t focus mode to be set.
155     */
156     [[deprecated]] void SetFocusMode(camera_focus_mode_enum_t focusMode);
157 
158     /**
159     * @brief Get the current focus mode.
160     *
161     * @return Returns current focus mode.
162     */
163     [[deprecated]] camera_focus_mode_enum_t GetFocusMode();
164 
165     /**
166     * @brief Get focal length.
167     *
168     * @return Returns focal length value.
169     */
170     [[deprecated]] float GetFocalLength();
171 
172     /**
173     * @brief Get the supported Zoom Ratio range.
174     *
175     * @return Returns vector<float> of supported Zoom ratio range.
176     */
177     [[deprecated]] std::vector<float> GetSupportedZoomRatioRange();
178 
179     /**
180     * @brief Get the current Zoom Ratio.
181     *
182     * @return Returns current Zoom Ratio.
183     */
184     [[deprecated]] float GetZoomRatio();
185 
186     /**
187     * @brief Set Zoom ratio.
188     *
189     * @param Zoom ratio to be set.
190     */
191     [[deprecated]] void SetZoomRatio(float zoomRatio);
192 
193     /**
194     * @brief Get the supported Focus modes.
195     *
196     * @return Returns vector of camera_focus_mode_enum_t supported exposure modes.
197     */
198     [[deprecated]] std::vector<camera_flash_mode_enum_t> GetSupportedFlashModes();
199 
200     /**
201     * @brief Get the current flash mode.
202     *
203     * @return Returns current flash mode.
204     */
205     [[deprecated]] camera_flash_mode_enum_t GetFlashMode();
206 
207     /**
208     * @brief Set flash mode.
209     *
210     * @param camera_flash_mode_enum_t flash mode to be set.
211     */
212     [[deprecated]] void SetFlashMode(camera_flash_mode_enum_t flashMode);
213 
214     /**
215     * @brief Set the error callback.
216     * which will be called when error occurs.
217     *
218     * @param The ErrorCallback pointer.
219     */
220     void SetErrorCallback(std::shared_ptr<ErrorCallback> errorCallback);
221 
222     /**
223     * @brief Release camera input.
224     */
225     int Release() override;
226 
227     /**
228     * @brief Get the camera Id.
229     *
230     * @return Returns the camera Id.
231     */
232     std::string GetCameraId();
233 
234     /**
235     * @brief Get Camera Device.
236     *
237     * @return Returns Camera Device pointer.
238     */
239     sptr<ICameraDeviceService> GetCameraDevice();
240 
241     /**
242     * @brief Get ErrorCallback pointer.
243     *
244     * @return Returns ErrorCallback pointer.
245     */
246     std::shared_ptr<ErrorCallback> GetErrorCallback();
247 
248     /**
249     * @brief get the camera info associated with the device.
250     *
251     * @return Returns camera info.
252     */
253     sptr<CameraDevice> GetCameraDeviceInfo() override;
254 
255     /**
256     * @brief This function is called when there is device setting state change
257     * and process the state callback.
258     *
259     * @param result metadata got from callback from service layer.
260     */
261     void ProcessDeviceCallbackUpdates(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result);
262 
263     /**
264     * @brief This function is called when there is focus state change
265     * and process the focus state callback.
266     *
267     * @param result metadata got from callback from service layer.
268     */
269     [[deprecated]] void ProcessAutoFocusUpdates(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result);
270 
271     /**
272     * @brief This function is called when there is exposure state change
273     * and process the exposure state callback.
274     *
275     * @param result metadata got from callback from service layer.
276     */
277     [[deprecated]] void ProcessAutoExposureUpdates(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result);
278 
279     /**
280     * @brief Get current Camera Settings.
281     *
282     * @return Returns string encoded metadata setting.
283     */
284     std::string GetCameraSettings();
285 
286     /**
287     * @brief set the camera metadata setting.
288     *
289     * @param string encoded camera metadata setting.
290     * @return Returns 0 if success or appropriate error code if failed.
291     */
292     int32_t SetCameraSettings(std::string setting);
293 
294 private:
295     sptr<CameraDevice> cameraObj_;
296     sptr<ICameraDeviceService> deviceObj_;
297     std::shared_ptr<ErrorCallback> errorCallback_;
298     sptr<ICameraDeviceServiceCallback> CameraDeviceSvcCallback_;
299     std::mutex interfaceMutex_;
300 
301     int32_t UpdateSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata);
302 };
303 } // namespace CameraStandard
304 } // namespace OHOS
305 #endif // OHOS_CAMERA_CAMERA_INPUT_H
306 
307