• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 CAMERA_MANAGER_ADAPTER_H
17 #define CAMERA_MANAGER_ADAPTER_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 namespace OHOS::NWeb {
24 
25 typedef struct VideoControlSupportTag {
26     bool pan = false;
27     bool tilt = false;
28     bool zoom = false;
29 } VideoControlSupport;
30 
31 enum class VideoTransportType {
32     VIDEO_TRANS_TYPE_BUILD_IN,
33     VIDEO_TRANS_TYPE_USB,
34     VIDEO_TRANS_TYPE_REMOTE,
35     VIDEO_TRANS_TYPE_OTHER
36 };
37 
38 enum class VideoFacingModeAdapter {
39     FACING_NONE = 0,
40     FACING_USER,
41     FACING_ENVIRONMENT,
42 
43     NUM_FACING_MODES
44 };
45 
46 enum class VideoPixelFormatAdapter {
47     FORMAT_RGBA_8888,
48     FORMAT_YCBCR_420_888,
49     FORMAT_YUV_420_SP,
50     FORMAT_JPEG,
51     FORMAT_UNKNOWN
52 };
53 
54 enum class ExposureModeAdapter {
55     EXPOSURE_MODE_UNSUPPORTED = -1,
56     EXPOSURE_MODE_LOCKED = 0,
57     EXPOSURE_MODE_AUTO,
58     EXPOSURE_MODE_CONTINUOUS_AUTO
59 };
60 
61 enum class FocusModeAdapter {
62     FOCUS_MODE_MANUAL = 0,
63     FOCUS_MODE_CONTINUOUS_AUTO,
64     FOCUS_MODE_AUTO,
65     FOCUS_MODE_LOCKED,
66 };
67 
68 enum class FlashModeAdapter {
69     FLASH_MODE_CLOSE = 0,
70     FLASH_MODE_OPEN,
71     FLASH_MODE_AUTO,
72     FLASH_MODE_ALWAYS_OPEN,
73 };
74 
75 enum class RangeIDAdapter {
76     RANGE_ID_EXP_COMPENSATION,
77 };
78 
79 enum class CameraStopType {
80     TO_BACK = 0,
81     NORMAL
82 };
83 
84 typedef struct FormatAdapterTag {
85     uint32_t width;
86     uint32_t height;
87     float frameRate;
88     VideoPixelFormatAdapter pixelFormat;
89 } FormatAdapter;
90 
91 enum CameraStatusAdapter {
92     APPEAR = 0,
93     DISAPPEAR,
94     AVAILABLE,
95     UNAVAILABLE
96 };
97 
98 typedef struct VideoDeviceDescriptorTag {
99     std::string displayName;
100     std::string deviceId;
101     std::string modelId;
102     VideoControlSupport controlSupport;
103     VideoTransportType transportType =
104         VideoTransportType::VIDEO_TRANS_TYPE_OTHER;
105     VideoFacingModeAdapter facing = VideoFacingModeAdapter::FACING_NONE;
106     std::vector<FormatAdapter> supportCaptureFormats;
107 } VideoDeviceDescriptor;
108 typedef struct VideoCaptureParamsAdapterTag {
109     FormatAdapter captureFormat;
110     bool enableFaceDetection;
111 } VideoCaptureParamsAdapter;
112 
113 typedef struct VideoCaptureRangeAdapterTag {
114     double min;
115     double max;
116     double step;
117     double current;
118 } VideoCaptureRangeAdapter;
119 
120 enum CameraManagerAdapterCode : int32_t {
121     CAMERA_OK = 0,
122     CAMERA_ERROR = -1,
123     CAMERA_NULL_ERROR = -2,
124 };
125 
126 typedef struct CameraRotationInfoTag {
127     int32_t rotation;
128     bool isFlipX;
129     bool isFlipY;
130 } CameraRotationInfo;
131 
132 class CameraSurfaceBufferAdapter {
133 public:
134     CameraSurfaceBufferAdapter() = default;
135 
136     virtual ~CameraSurfaceBufferAdapter() = default;
137 
138     virtual int32_t GetFileDescriptor() const = 0;
139 
140     virtual int32_t GetWidth() const = 0;
141 
142     virtual int32_t GetHeight() const = 0;
143 
144     virtual int32_t GetStride() const = 0;
145 
146     virtual int32_t GetFormat() const = 0;
147 
148     virtual uint32_t GetSize() const = 0;
149 
150     virtual uint8_t* GetBufferAddr() = 0;
151 
152 protected:
153     CameraSurfaceBufferAdapter(const CameraSurfaceBufferAdapter&) = delete;
154 
155     CameraSurfaceBufferAdapter& operator=(const CameraSurfaceBufferAdapter&) = delete;
156 };
157 
158 class CameraSurfaceAdapter {
159 public:
160     CameraSurfaceAdapter() = default;
161 
162     virtual ~CameraSurfaceAdapter() = default;
163 
164     virtual int32_t ReleaseBuffer(std::unique_ptr<CameraSurfaceBufferAdapter> buffer, int32_t fence) = 0;
165 };
166 
167 class CameraBufferListenerAdapter {
168 public:
169     virtual ~CameraBufferListenerAdapter() = default;
170 
171     virtual void OnBufferAvailable(std::shared_ptr<CameraSurfaceAdapter> surface,
172         std::unique_ptr<CameraSurfaceBufferAdapter> buffer,
173         CameraRotationInfo rotationInfo) = 0;
174 };
175 
176 class CameraStatusCallbackAdapter {
177 public:
178     virtual ~CameraStatusCallbackAdapter() = default;
179 
180     virtual void OnCameraStatusChanged(CameraStatusAdapter cameraStatusAdapter,
181                                         const std::string callBackDeviceId) = 0;
182 };
183 
184 class CameraManagerAdapter {
185 public:
186     CameraManagerAdapter() = default;
187 
188     virtual ~CameraManagerAdapter() = default;
189 
190     virtual int32_t Create(std::shared_ptr<CameraStatusCallbackAdapter> cameraStatusCallback) = 0;
191 
192     virtual void GetDevicesInfo(std::vector<VideoDeviceDescriptor> &devicesDiscriptor) = 0;
193 
194     virtual int32_t ReleaseCameraManger() = 0;
195 
196     virtual int32_t GetExposureModes(std::vector<ExposureModeAdapter>& exposureModesAdapter) = 0;
197 
198     virtual int32_t GetCurrentExposureMode(ExposureModeAdapter& exposureModeAdapter) = 0;
199 
200     virtual int32_t GetCaptionRangeById(RangeIDAdapter rangeId, VideoCaptureRangeAdapter& rangeVal) = 0;
201 
202     virtual bool IsFocusModeSupported(FocusModeAdapter focusMode);
203 
204     virtual FocusModeAdapter GetCurrentFocusMode() = 0;
205 
206     virtual bool IsFlashModeSupported(FlashModeAdapter flashMode) = 0;
207 
208     virtual int32_t RestartSession() = 0;
209 
210     virtual int32_t StopSession(CameraStopType stopType) = 0;
211 
212     virtual CameraStatusAdapter GetCameraStatus() = 0;
213 
214     virtual bool IsExistCaptureTask() = 0;
215 
216     virtual int32_t StartStream(const std::string &deviceId,
217         const VideoCaptureParamsAdapter &captureParams,
218         std::shared_ptr<CameraBufferListenerAdapter> listener) = 0;
219 
220     virtual void SetForegroundFlag(bool isForeground) = 0;
221 
222     virtual void SetCameraStatus(CameraStatusAdapter status) = 0;
223 
224     virtual std::string GetCurrentDeviceId() = 0;
225 };
226 } // namespace OHOS::NWeb
227 
228 #endif // CAMERA_MANAGER_ADAPTER_H