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