1 /*
2  * Copyright (c) 2020 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 HI_CAMERA_H
17 #define HI_CAMERA_H
18 #include <stdint.h>
19 
20 #ifdef __cplusplus
21 #if __cplusplus
22 extern "C" {
23 #endif
24 #endif /* End of #ifdef __cplusplus */
25 
26 
27 #define CAMERA_FPS_MAX_NUM  16
28 #define CAMERA_DESC_MAX_LEN 32
29 #define INFO_MAX_LEN 1024
30 #define DESC_MAX_LEN 64
31 #define AUTO_MODE_MAX_NUM 16
32 #define PRIVATE_META_MAX_LEN 32
33 
34 typedef struct {
35     int32_t x;
36     int32_t y;
37     int32_t w;
38     int32_t h;
39 } RectInfo;
40 
41 typedef enum {
42     STREAM_INFO_ATTR = 0,
43     STREAM_INFO_POS,
44     STERAM_INFO_PRIVATE,
45     STREAM_INFO_BUTT,
46 } StreamInfoType;
47 
48 typedef enum {
49     CAMERA_CONTROL_3A_MODE = 0,
50     CAMERA_CONTROL_PRIVATE,
51     CAMERA_CONTROL_BUTT,
52 } DeviceType;
53 
54 typedef enum {
55     FORMAT_YVU420 = 0,
56     FORMAT_JPEG,
57     FORMAT_AVC,
58     FORMAT_HEVC,
59     FORMAT_RGB_BAYER_12BPP,
60     FORMAT_PRIVATE,
61     FORMAT_IMAGE_BUTT
62 } ImageFormat;
63 
64 typedef enum {
65     STREAM_PREVIEW = 0,
66     STREAM_VIDEO,
67     STREAM_CAPTURE,
68     STREAM_CALLBACK,
69     STREAM_TYPE_BUTT
70 } StreamType;
71 
72 typedef struct {
73     StreamType type;
74     ImageFormat format;
75     int32_t width;
76     int32_t height;
77     uint16_t fps;
78     RectInfo crop;
79     uint8_t invertMode;
80 } StreamAttr;
81 
82 typedef enum {
83     CAP_DESC_RANGE,
84     CAP_DESC_ENUM,
85     CAP_DESC_MAX,
86 } CapDescType;
87 
88 typedef struct {
89     ImageFormat format;  /**< the format of memory */
90     int32_t width;        /**< the width of memory */
91     int32_t height;       /**< the heigh of memory */
92     int32_t stride0;       /**< the stride of memory */
93     int32_t stride1;
94     int32_t size;         /* < size of memory */
95     int32_t fd;           /**< buffer fd, -1 if not supported */
96     uint32_t flag;         /**< flag */
97     int64_t usage;        /**< the usage of memory */
98     uint64_t phyAddr;      /**< Physical address */
99     uint64_t pts;          /**< pts */
100     uint64_t timeStamp;
101     void *virAddr;    /**< Virtual address of memory  */
102 } HalBuffer;
103 
104 typedef struct {
105     int32_t maxWidth;
106     int32_t minWidth;
107     int32_t maxHeight;
108     int32_t minHeight;
109     int32_t maxFps;
110     int32_t minFps;
111 } FormatRange;
112 
113 typedef struct Format {
114     int32_t width;
115     int32_t height;
116     uint8_t frame_rate_num;
117     uint8_t frame_rate[CAMERA_FPS_MAX_NUM];
118 } FormatEnum;
119 
120 typedef struct {
121     CapDescType type;
122     char description[CAMERA_DESC_MAX_LEN]; /* like YUYV 4:2:2 (YUYV) */
123     ImageFormat format; // 只支持YUV
124     union {
125         FormatRange range;
126         FormatEnum formatEnum;
127     } u;
128 } StreamCap;
129 
130 typedef enum status {
131     CAMERA_STATUS_NOT_PRESENT,
132     CAMERA_STATUS_PRESENT,
133     CAMERA_STATUS_BUTT,
134 } CameraStatus;
135 
136 typedef void (*BufferAvailable)(uint32_t streamId, HalBuffer *halBuffer, uint32_t bufferNum);
137 typedef void (*CameraDetectCb)(uint32_t cameraId, CameraStatus status);
138 
139 typedef struct {
140     DeviceType type;
141     union {
142         uint8_t data[INFO_MAX_LEN];
143     } u;
144 } DeviceInfo;
145 
146 typedef struct {
147     int32_t x;
148     int32_t y;
149 } PosInfo;
150 
151 typedef struct {
152     StreamInfoType type;
153     union {
154         uint8_t data[INFO_MAX_LEN];
155         StreamAttr attr;
156         PosInfo pos;
157     } u;
158 } StreamInfo;
159 
160 typedef enum {
161     ORIENTATION_FRONT,
162     ORIENTATION_REAR,
163     ORIENTATION_OTHER,
164     ORIENTATION_BUTT,
165 } CameraOrientation;
166 
167 typedef enum {
168     AE_MODE_ON,
169     AE_MODE_OFF,
170     AE_BUTT,
171 } CameraAEMode;
172 
173 typedef enum {
174     AF_MODE_AUTO,
175     AF_MODE_OFF,
176     AF_BUTT,
177 } CameraAFMode;
178 
179 typedef enum {
180     AWB_MODE_AUTO,
181     AWB_MODE_OFF,
182     AWB_BUTT,
183 } CameraAWBMode;
184 
185 typedef enum {
186     CAM_TYPE_WIDE_ANGLE,
187     CAM_TYPE_FISH_EYE,
188     CAM_TYPE_TRUE_DEAPTH,
189     CAM_TYPE_BUTT,
190 } CameraType;
191 
192 typedef struct {
193     CameraOrientation orientation;
194     uint8_t aeModeNum;
195     uint8_t afModeNum;
196     uint8_t awbModeNum;
197     CameraAEMode aeModes[AUTO_MODE_MAX_NUM];
198     CameraAFMode afModes[AUTO_MODE_MAX_NUM];
199     CameraAWBMode awbModes[AUTO_MODE_MAX_NUM];
200     CameraType type;
201     char cameraDesc[DESC_MAX_LEN];
202 } AbilityInfo;
203 
204 typedef struct {
205     CameraAEMode aeMode;
206     CameraAFMode afMode;
207     CameraAWBMode awbMode;
208     uint32_t privateData[PRIVATE_META_MAX_LEN];
209 } CameraMetaResult;
210 
211 typedef void (*CameraResultCb)(uint32_t cameraId, CameraMetaResult result);
212 
213 int32_t HalCameraInit(void);
214 int32_t HalCameraDeinit(void);
215 int32_t HalCameraGetModeNum(uint8_t *num);
216 int32_t HalCameraSetMode(uint8_t index);
217 int32_t HalCameraSetDeviceDetectCb(const CameraDetectCb cb);
218 int32_t HalCameraGetDeviceNum(uint8_t *num);
219 int32_t HalCameraGetDeviceList(uint32_t *cameraList, uint8_t listNum);
220 int32_t HalCameraGetStreamCapNum(uint32_t cameraId, uint32_t *num);
221 int32_t HalCameraGetStreamCap(uint32_t cameraId, StreamCap *streamCap, uint32_t streamNum);
222 int32_t HalCameraDeviceOpen(uint32_t cameraId);
223 int32_t HalCameraDeviceClose(uint32_t cameraId);
224 int32_t HalCameraStreamCreate(uint32_t cameraId, const StreamAttr *stream, uint32_t *streamId);
225 int32_t HalCameraStreamDestroy(uint32_t cameraId, uint32_t streamId);
226 int32_t HalCameraGetDeviceId(uint32_t cameraId, uint32_t streamId, uint32_t *deviceId);
227 int32_t HalCameraStreamOn(uint32_t cameraId, uint32_t streamId);
228 int32_t HalCameraStreamOff(uint32_t cameraId, uint32_t streamId);
229 int32_t HalCameraDequeueBuf(uint32_t cameraId, uint32_t streamId, HalBuffer *buffer);
230 int32_t HalCameraQueueBuf(uint32_t cameraId, uint32_t streamId, const HalBuffer *buffer);
231 int32_t HalCameraSetBufferCallback(uint32_t cameraId, const BufferAvailable callback);
232 int32_t HalCameraStreamSetInfo(uint32_t cameraId, uint32_t streamId, const StreamInfo *info);
233 int32_t HalCameraStreamGetInfo(uint32_t cameraId, uint32_t streamId, StreamInfo *info);
234 int32_t HalCameraDeviceSetInfo(uint32_t cameraId, const DeviceInfo *info);
235 int32_t HalCameraDeviceGetInfo(uint32_t cameraId, DeviceInfo *info);
236 int32_t HalCameraGetAbility(uint32_t cameraId, AbilityInfo *ability);
237 int32_t HalCameraSetResultCb(uint32_t cameraId, CameraResultCb cb);
238 
239 #ifdef __cplusplus
240 #if __cplusplus
241 }
242 #endif
243 #endif /* End of #ifdef __cplusplus */
244 
245 #endif
246