• 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 <vector>
22 #include "camera_info.h"
23 #include "capture_input.h"
24 #include "icamera_device_service.h"
25 #include "icamera_device_service_callback.h"
26 
27 namespace OHOS {
28 namespace CameraStandard {
29 typedef struct {
30     uint32_t height;
31     uint32_t width;
32 } CameraPicSize;
33 
34 class ErrorCallback {
35 public:
36     ErrorCallback() = default;
37     virtual ~ErrorCallback() = default;
38     virtual void OnError(const int32_t errorType, const int32_t errorMsg) const;
39 };
40 
41 class ExposureCallback {
42 public:
43     enum ExposureState {
44         SCAN = 0,
45         CONVERGED,
46     };
47     ExposureCallback() = default;
48     virtual ~ExposureCallback() = default;
49     virtual void OnExposureState(ExposureState state) = 0;
50 };
51 
52 class FocusCallback {
53 public:
54     enum FocusState {
55         SCAN = 0,
56         FOCUSED,
57         UNFOCUSED
58     };
59     FocusCallback() = default;
60     virtual ~FocusCallback() = default;
61     virtual void OnFocusState(FocusState state) = 0;
62 };
63 
64 class CameraInput : public CaptureInput {
65 public:
66     CameraInput(sptr<ICameraDeviceService> &deviceObj, sptr<CameraInfo> &camera);
~CameraInput()67     ~CameraInput() {};
68     void LockForControl();
69     int32_t UnlockForControl();
70     std::vector<camera_format_t> GetSupportedPhotoFormats();
71     std::vector<camera_format_t> GetSupportedVideoFormats();
72     std::vector<camera_format_t> GetSupportedPreviewFormats();
73     std::vector<CameraPicSize> getSupportedSizes(camera_format_t format);
74     std::vector<camera_ae_mode_t> GetSupportedExposureModes();
75     void SetExposureMode(camera_ae_mode_t exposureMode);
76     camera_ae_mode_t GetExposureMode();
77     void SetExposureCallback(std::shared_ptr<ExposureCallback> exposureCallback);
78     std::vector<camera_af_mode_t> GetSupportedFocusModes();
79     void SetFocusCallback(std::shared_ptr<FocusCallback> focusCallback);
80     void SetFocusMode(camera_af_mode_t focusMode);
81     camera_af_mode_t GetFocusMode();
82     std::vector<float> GetSupportedZoomRatioRange();
83     float GetZoomRatio();
84     void SetZoomRatio(float zoomRatio);
85     std::vector<camera_flash_mode_enum_t> GetSupportedFlashModes();
86     camera_flash_mode_enum_t GetFlashMode();
87     void SetFlashMode(camera_flash_mode_enum_t flashMode);
88     void SetErrorCallback(std::shared_ptr<ErrorCallback> errorCallback);
89     void Release() override;
90     sptr<ICameraDeviceService> GetCameraDevice();
91     std::shared_ptr<ErrorCallback> GetErrorCallback();
92     void ProcessAutoFocusUpdates(const std::shared_ptr<Camera::CameraMetadata> &result);
93     std::string GetCameraSettings();
94     int32_t SetCameraSettings(std::string setting);
95 
96 private:
97     std::mutex changeMetaMutex_;
98     std::shared_ptr<Camera::CameraMetadata> changedMetadata_;
99     sptr<CameraInfo> cameraObj_;
100     sptr<ICameraDeviceService> deviceObj_;
101     std::shared_ptr<ErrorCallback> errorCallback_;
102     sptr<ICameraDeviceServiceCallback> CameraDeviceSvcCallback_;
103     std::shared_ptr<ExposureCallback> exposurecallback_;
104     std::shared_ptr<FocusCallback> focusCallback_;
105     static const std::unordered_map<camera_af_state_t, FocusCallback::FocusState> mapFromMetadataFocus_;
106 
107     template<typename DataPtr, typename Vec, typename VecType>
108     static void getVector(DataPtr data, size_t count, Vec &vect, VecType dataType);
109     int32_t SetCropRegion(float zoomRatio);
110     int32_t StartFocus(camera_af_mode_t focusMode);
111     int32_t UpdateSetting(std::shared_ptr<Camera::CameraMetadata> changedMetadata);
112 };
113 } // namespace CameraStandard
114 } // namespace OHOS
115 #endif // OHOS_CAMERA_CAMERA_INPUT_H
116