• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 /**
17  * @file types.h
18  *
19  * @brief Declares data types
20  * used by the Hardware Driver Interfaces (HDIs) of this module.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 #ifndef CAMERA_DEVICE_DRIVER_TYPES_H
27 #define CAMERA_DEVICE_DRIVER_TYPES_H
28 
29 #include <functional>
30 #include <memory>
31 #include <string>
32 #include <vector>
33 #include <surface.h>
34 #include "camera_metadata_info.h"
35 #include "type_common.h"
36 
37 namespace OHOS::Camera {
38 using CameraAbility = CameraMetadata;
39 using CameraSetting = CameraMetadata;
40 
41 /**
42  * @brief Enumerates return values of the HDIs.
43  */
44 enum CamRetCode : int32_t {
45     /**
46      * Successful call.
47      */
48     NO_ERROR = 0,
49 
50     /**
51      * The camera device is busy.
52      */
53     CAMERA_BUSY = -1,
54 
55     /**
56      * Insufficient resources.
57      */
58     INSUFFICIENT_RESOURCES = -2,
59 
60     /**
61      * Invalid parameters.
62      */
63     INVALID_ARGUMENT = -3,
64 
65     /**
66      * Unsupported function.
67      */
68     METHOD_NOT_SUPPORTED = -4,
69 
70     /**
71      * The camera device is closed.
72      */
73     CAMERA_CLOSED = -5,
74 
75     /**
76      * A critical error occurs at the driver layer.
77      */
78     DEVICE_ERROR = -6,
79 };
80 
81 /**
82  * @brief Enumerates metadata reporting modes.
83  */
84 enum ResultCallbackMode : int32_t {
85     /**
86      * Frame-by-frame reporting
87      */
88     PER_FRAME,
89 
90     /**
91      * Reporting upon device status change
92      */
93     ON_CHANGED
94 };
95 
96 /**
97  * @brief Enumerates stream operation modes.
98  */
99 enum OperationMode : int32_t {
100     /**
101      * Normal
102      */
103     NORMAL = 0,
104 };
105 
106 /**
107  * @brief Enumerates stream types.
108  */
109 enum StreamIntent : int32_t {
110     /**
111      * Preview streams, indicating that stream data is used for preview
112      */
113     PREVIEW = 0,
114 
115     /**
116      * Video streams, indicating that stream data is used to encode and generate videos
117      */
118     VIDEO = 1,
119 
120     /**
121      * Photographing streams, indicating that stream data is used to encode and generate images
122      */
123     STILL_CAPTURE = 2,
124 
125     /**
126      * Stream data that is used to store thumbnails
127      */
128     POST_VIEW = 3,
129 
130     /**
131      * Stream data that is used for image analysis
132      */
133     ANALYZE = 4,
134 
135     /**
136      * Custom type
137      */
138     CUSTOM = 5,
139 };
140 
141 /**
142  * @brief Enumerates encoding types of stream data.
143  */
144 enum EncodeType : int32_t {
145     /**
146      * Unspecified
147      */
148     ENCODE_TYPE_NULL = 0,
149 
150     /**
151      * H.264
152      */
153     ENCODE_TYPE_H264 = 1,
154 
155     /**
156      * H.265
157      */
158     ENCODE_TYPE_H265 = 2,
159 
160     /**
161      * JPEG
162      */
163     ENCODE_TYPE_JPEG = 3,
164 };
165 
166 /**
167  * @brief Defines the stream information, which is used to pass configuration parameters during stream creation.
168  */
169 struct StreamInfo {
170     /**
171      * Stream ID, which uniquely identifies a stream on a camera device.
172      */
173     int streamId_;
174 
175     /**
176      * Image width.
177      */
178     int width_;
179 
180     /**
181      * Image height.
182      */
183     int height_;
184 
185     /**
186      * Image format.
187      */
188     int format_;
189 
190     /**
191      * Image color space.
192      */
193     int datasapce_;
194 
195     /**
196      * Stream type.
197      */
198     StreamIntent intent_;
199 
200     /**
201      * Tunnel mode. The value <b>true</b> means that the tunnel mode is enabled, and <b>false</b> means the opposite.
202      *
203      * After the tunnel mode is enabled,
204      * the hardware abstraction layer (HAL) does not directly interact with the upper layer.
205      * Instead, it uses the producer handle provided by the graphics layer to transfer frame data.
206      * You need to disable the tunnel mode for IoT devices that do not support
207      * or require image data caching and forwarding of preview streams.
208      */
209     bool tunneledMode_;
210 
211     /**
212      * Producer handle provided by the graphics layer.
213      */
214     OHOS::sptr<OHOS::IBufferProducer> bufferQueue_;
215 
216     /**
217      * Minimum frame interval.
218      */
219     int minFrameDuration_;
220 
221     /**
222      * Encoding type.
223      */
224     EncodeType encodeType_;
225 };
226 
227 /**
228  * @brief Enumerates the support types of the stream. For details about the application scenario,
229  * see {@link IsStreamsSupported}.
230  */
231 enum StreamSupportType : int32_t {
232     /**
233      * The stream can be dynamically created, and the corresponding stream parameters take effect directly.
234      */
235     DYNAMIC_SUPPORTED,
236 
237     /**
238      * The stream cannot be dynamically created,
239      * and the corresponding parameters take effect only after the existing stream is stopped and reconfigured.
240      */
241     RE_CONFIGURED_REQUIRED,
242 
243     /**
244      * The stream cannot be dynamically created.
245      */
246     NOT_SUPPORTED,
247 };
248 
249 /**
250  * @brief Defines the stream attributes.
251  */
252 struct StreamAttribute {
253     /**
254      * Stream ID, which uniquely identifies a stream on a camera device.
255      */
256     int streamId_;
257 
258     /**
259      * Image width.
260      */
261     int width_;
262 
263     /**
264      * Image height.
265      */
266     int height_;
267 
268     /**
269      * New image format.
270      */
271     int overrideFormat_;
272 
273     /**
274      * New image color space.
275      */
276     int overrideDatasapce_;
277 
278     /**
279      * New procedure usage.
280      */
281     int producerUsage_;
282 
283     /**
284      * New number of produce buffers.
285      */
286     int producerBufferCount_;
287 
288     /**
289      * Maximum number of frames that can be captured in a continuous capture.
290      */
291     int maxBatchCaptureCount_;
292 
293     /**
294      * Maximum number of concurrent capture requests. The default value is <b>1</b>.
295     */
296     int maxCaptureCount_;
297 };
298 
299 /**
300  * @brief Defines the information about a capture request.
301  */
302 struct CaptureInfo {
303     /**
304      * IDs of captured streams.
305     */
306     std::vector<int> streamIds_;
307 
308     /**
309      * Captured configuration information.
310      */
311     std::shared_ptr<CameraMetadata> captureSetting_;
312 
313     /**
314      * Whether to enable callback for each capture. If enabled, {@link OnFrameShutter} is called upon each capture.
315     */
316     bool enableShutterCallback_;
317 };
318 
319 /**
320  * @brief Enumerates camera device statuses.
321  */
322 enum CameraStatus {
323     /**
324      * The camera device is not in position or is unavailable.
325      */
326     UN_AVAILABLE = 0,
327 
328     /**
329      * The camera device is available.
330      */
331     AVAILABLE = 1,
332 };
333 
334 /**
335  * @brief Enumerates flash statuses.
336  */
337 enum FlashlightStatus : uint32_t {
338     /**
339      * The flash is off.
340      */
341     FLASHLIGHT_OFF = 0,
342 
343     /**
344      * The flash is on.
345      */
346     FLASHLIGHT_ON = 1,
347 
348     /**
349      * The flash is unavailable.
350      */
351     FLASHLIGHT_UNAVAILABLE = 2,
352 };
353 
354 /**
355  * @brief Camera event.
356  */
357 enum CameraEvent : uint32_t {
358     /**
359      * Camera device add event.
360      */
361     CAMERA_EVENT_DEVICE_ADD = 0,
362 
363     /**
364      * Camera device remove event.
365      */
366     CAMERA_EVENT_DEVICE_RMV = 1,
367 };
368 
369 /**
370  * @brief Enumerates camera device error types, which are used by {@link OnError}.
371  */
372 enum ErrorType : uint32_t {
373     /**
374      * A critical error occurs. The camera device needs to be closed.
375      */
376     FATAL_ERROR = 0,
377 
378     /**
379      * A request timeout occurs. The camera device needs to be closed.
380      */
381     REQUEST_TIMEOUT = 1,
382 };
383 
384 /**
385  * @brief Defines the information about the end of packet capture, which is used by {@link OnCaptureEnded}.
386  */
387 struct CaptureEndedInfo {
388     /**
389      * ID of a captured stream.
390      */
391     int streamId_;
392 
393     /**
394      * Number of frames that have been captured when the capture ends.
395      */
396     int frameCount_;
397 };
398 
399 /**
400  * @brief Enumerates stream error types, which are used by {@link CaptureErrorInfo}.
401  */
402 enum StreamError {
403     /**
404      * Unknown error
405      */
406     UNKNOWN_ERROR = 0,
407 
408     /**
409      * Packet loss
410      */
411     BUFFER_LOST = 1,
412 };
413 
414 /**
415  * @brief Defines the stream error information, which is used by {@link OnCaptureError}.
416  */
417 struct CaptureErrorInfo {
418     /**
419      * Stream ID
420      */
421     int streamId_;
422 
423     /**
424      * Error type
425      */
426     StreamError error_;
427 };
428 
429 using MetaType = int32_t;
430 }
431 #endif /* CAMERA_DEVICE_DRIVER_TYPES_H */
432