• 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 #ifndef HOS_CAMERA_H
17 #define HOS_CAMERA_H
18 
19 #include "securec.h"
20 #include <cstdint>
21 #include <cstdio>
22 #include <functional>
23 #include <hdf_log.h>
24 #include <pthread.h>
25 #include <stdint.h>
26 #include <sys/prctl.h>
27 #include <sys/time.h>
28 #include <sys/types.h>
29 #include <time.h>
30 #include <unistd.h>
31 
32 #ifdef HITRACE_LOG_ENABLED
33 #include "hitrace.h"
34 #define DFX_LOCAL_HITRACE_BEGIN     \
35     HiviewDFX::HiTraceId _trace_id; \
36     _trace_id = OHOS::HiviewDFX::HiTrace::Begin(__FUNCTION__, HITRACE_FLAG_DEFAULT);
37 #define DFX_LOCAL_HITRACE_END OHOS::HiviewDFX::HiTrace::End(_trace_id);
38 #else
39 #define DFX_LOCAL_HITRACE_BEGIN
40 #define DFX_LOCAL_HITRACE_END
41 #endif // HITRACE_LOG_ENABLED
42 
43 #if 0
44 #if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
45 #include <sys/syscall.h>
46 #define gettid() (pid_t) syscall(SYS_gettid)
47 #endif
48 #endif
49 
50 namespace OHOS::Camera {
51 #define HDF_LOG_TAG camera_host
52 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
53 
54 #ifndef OHOS_DEBUG
55 #define DECORATOR_HDFLOG(op, fmt, args...)             \
56     do {                                               \
57         op("%{public}s() " fmt, __FUNCTION__, ##args); \
58     } while (0)
59 #else
60 #define DECORATOR_HDFLOG(op, fmt, args...)                                     \
61     do {                                                                       \
62         op("{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \
63     } while (0)
64 #endif
65 
66 #define CAMERA_LOGE(fmt, ...) DECORATOR_HDFLOG(HDF_LOGE, fmt, ##__VA_ARGS__)
67 #define CAMERA_LOGW(fmt, ...) DECORATOR_HDFLOG(HDF_LOGW, fmt, ##__VA_ARGS__)
68 #define CAMERA_LOGI(fmt, ...) DECORATOR_HDFLOG(HDF_LOGI, fmt, ##__VA_ARGS__)
69 #define CAMERA_LOGV(fmt, ...) DECORATOR_HDFLOG(HDF_LOGV, fmt, ##__VA_ARGS__)
70 #define CAMERA_LOGD(fmt, ...) DECORATOR_HDFLOG(HDF_LOGD, fmt, ##__VA_ARGS__)
71 
72 #if 0
73 #define GET_CURRENT_TIME_MS                                                                                   \
74     struct timeval _tv;                                                                                       \
75     gettimeofday(&_tv, NULL);                                                                                 \
76     struct tm* _tm = localtime(&_tv.tv_sec);                                                                  \
77     int _ms = _tv.tv_usec / 1000;                                                                             \
78     char now[25] = {0};                                                                                       \
79     sprintf_s(now, sizeof(now), "%02d-%02d %02d:%02d:%02d.%03d", _tm->tm_mon + 1, _tm->tm_mday, _tm->tm_hour, \
80               _tm->tm_min, _tm->tm_sec, _ms);
81 
82 #define CAMERA_LOGE(fmt, ...)                                                               \
83     do {                                                                                    \
84         GET_CURRENT_TIME_MS;                                                                \
85         pid_t pid = getpid();                                                               \
86         pid_t tid = gettid();                                                               \
87         printf("%s %4u %4u E " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \
88         fflush(stdout);                                                                     \
89     } while (0);
90 
91 #define CAMERA_LOGW(fmt, ...)                                                               \
92     do {                                                                                    \
93         GET_CURRENT_TIME_MS;                                                                \
94         pid_t pid = getpid();                                                               \
95         pid_t tid = gettid();                                                               \
96         printf("%s %4u %4u W " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \
97         fflush(stdout);                                                                     \
98     } while (0);
99 
100 #define CAMERA_LOGI(fmt, ...)                                                               \
101     do {                                                                                    \
102         GET_CURRENT_TIME_MS;                                                                \
103         pid_t pid = getpid();                                                               \
104         pid_t tid = gettid();                                                               \
105         printf("%s %4u %4u I " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \
106         fflush(stdout);                                                                     \
107     } while (0);
108 
109 #define CAMERA_LOGV(fmt, ...)                                                               \
110     do {                                                                                    \
111         GET_CURRENT_TIME_MS;                                                                \
112         pid_t pid = getpid();                                                               \
113         pid_t tid = gettid();                                                               \
114         printf("%s %4u %4u V " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \
115         fflush(stdout);                                                                     \
116     } while (0);
117 
118 #define CAMERA_LOGD(fmt, ...)                                                               \
119     do {                                                                                    \
120         GET_CURRENT_TIME_MS;                                                                \
121         pid_t pid = getpid();                                                               \
122         pid_t tid = gettid();                                                               \
123         printf("%s %4u %4u D " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \
124         fflush(stdout);                                                                     \
125     } while (0);
126 #endif
127 
128 constexpr uint32_t FRAME_SIZE_TAG = 100;
129 
130 using RetCode = uint32_t;
131 enum Ret : uint32_t {
132     RC_OK = 0,
133     RC_ERROR,
134 };
135 
136 enum BufferSourceType {
137     CAMERA_BUFFER_SOURCE_TYPE_NONE = -1,
138     CAMERA_BUFFER_SOURCE_TYPE_GRALLOC,
139     CAMERA_BUFFER_SOURCE_TYPE_HEAP,
140     CAMERA_BUFFER_SOURCE_TYPE_EXTERNAL,
141     CAMERA_BUFFER_SOURCE_TYPE_MAX,
142 };
143 
144 enum CameraBufferUsage : uint64_t {
145     CAMERA_USAGE_SW_READ_OFTEN = (1 << 0),
146     CAMERA_USAGE_SW_WRITE_OFTEN = (1 << 1),
147     CAMERA_USAGE_MEM_DMA = (1 << 2),
148 };
149 
150 enum CameraBufferFormat : uint32_t {
151     CAMERA_FORMAT_INVALID,      /* invalid format */
152     CAMERA_FORMAT_RGB_565,      /* RGB565 format */
153     CAMERA_FORMAT_RGBA_5658,    /* RGBA5658 format */
154     CAMERA_FORMAT_RGBX_4444,    /* RGBX4444 format */
155     CAMERA_FORMAT_RGBA_4444,    /* RGBA4444 format */
156     CAMERA_FORMAT_RGB_444,      /* RGB444 format */
157     CAMERA_FORMAT_RGBX_5551,    /* RGBX5551 format */
158     CAMERA_FORMAT_RGBA_5551,    /* RGBA5551 format */
159     CAMERA_FORMAT_RGB_555,      /* RGB555 format */
160     CAMERA_FORMAT_RGBX_8888,    /* RGBX8888 format */
161     CAMERA_FORMAT_RGBA_8888,    /* RGBA8888 format */
162     CAMERA_FORMAT_RGB_888,      /* RGB888 format */
163     CAMERA_FORMAT_BGR_565,      /* BGR565 format */
164     CAMERA_FORMAT_BGRX_4444,    /* BGRX4444 format */
165     CAMERA_FORMAT_BGRA_4444,    /* BGRA4444 format */
166     CAMERA_FORMAT_BGRX_5551,    /* BGRX5551 format */
167     CAMERA_FORMAT_BGRA_5551,    /* BGRA5551 format */
168     CAMERA_FORMAT_BGRX_8888,    /* BGRX8888 format */
169     CAMERA_FORMAT_BGRA_8888,    /* BGRA8888 format */
170     CAMERA_FORMAT_YUV_422_I,    /* YUV422 interleaved format */
171     CAMERA_FORMAT_YCBCR_422_SP, /* YCBCR422 semi-planar format */
172     CAMERA_FORMAT_YCRCB_422_SP, /* YCRCB422 semi-planar format */
173     CAMERA_FORMAT_YCBCR_420_SP, /* YCBCR420 semi-planar format */
174     CAMERA_FORMAT_YCRCB_420_SP, /* YCRCB420 semi-planar format */
175     CAMERA_FORMAT_YCBCR_422_P,  /* YCBCR422 planar format */
176     CAMERA_FORMAT_YCRCB_422_P,  /* YCRCB422 planar format */
177     CAMERA_FORMAT_YCBCR_420_P,  /* YCBCR420 planar format */
178     CAMERA_FORMAT_YCRCB_420_P,  /* YCRCB420 planar format */
179     CAMERA_FORMAT_YUYV_422_PKG, /* YUYV422 packed format */
180     CAMERA_FORMAT_UYVY_422_PKG, /* UYVY422 packed format */
181     CAMERA_FORMAT_YVYU_422_PKG, /* YVYU422 packed format */
182     CAMERA_FORMAT_VYUY_422_PKG, /* VYUY422 packed format */
183 };
184 
185 enum CameraEncodeType : int32_t {
186     /**
187      * δ���ñ�������
188      */
189     CAMERA_ENCODE_NULL = 0,
190     /**
191      * ��������ΪH264
192      */
193     CAMERA_ENCODE_H264 = 1,
194     /**
195      * ��������ΪH265
196      */
197     CAMERA_ENCODE_H265 = 2,
198     /**
199      * ��������ΪJPEG
200      */
201     CAMERA_ENCODE_JPEG = 3,
202 };
203 
204 enum FlashMode : uint32_t { FlASH_OFF = 0, FlASH_SINGLE, FLASH_TORCH, FLASH_AUTO };
205 
206 enum AdapterCmd : uint32_t { CMD_AE_EXPO, CMD_AWB_MODE, CMD_AE_EXPOTIME, CMD_AWB_COLORGAINS };
207 
208 enum AwbMode : uint32_t {
209     AWB_MODE_AUTO,
210     AWB_MODE_CLOUDY_DAYLIGHT,
211     AWB_MODE_TWILIGHT,
212     AWB_MODE_FLUORESCENT,
213     AWB_MODE_WARM_FLUORESCENT,
214 };
215 
216 using EsFrmaeInfo = struct EsFrmaeInfo {
217     int32_t size;
218     int32_t align;
219     int32_t isKey;
220     int64_t timestamp;
221     int32_t frameNum;
222 };
223 
224 #define CHECK_IF_NOT_EQUAL_RETURN_VALUE(arg1, arg2, ret)                                                            \
225     if ((arg1) != (arg2)) {                                                                                         \
226         CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, \
227                     #ret);                                                                                          \
228         return (ret);                                                                                               \
229     }
230 
231 #define CHECK_IF_EQUAL_RETURN_VALUE(arg1, arg2, ret)                                                                   \
232     if ((arg1) == (arg2)) {                                                                                            \
233         CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, #ret); \
234         return (ret);                                                                                                  \
235     }
236 
237 #define CHECK_IF_PTR_NULL_RETURN_VALUE(ptr, ret) CHECK_IF_EQUAL_RETURN_VALUE(ptr, nullptr, ret)
238 
239 #define CHECK_IF_NOT_EQUAL_RETURN_VOID(arg1, arg2)                                                        \
240     if ((arg1) != (arg2)) {                                                                               \
241         CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return", __LINE__, #arg1, #arg2); \
242         return;                                                                                           \
243     }
244 
245 #define CHECK_IF_EQUAL_RETURN_VOID(arg1, arg2)                                                        \
246     if ((arg1) == (arg2)) {                                                                           \
247         CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return", __LINE__, #arg1, #arg2); \
248         return;                                                                                       \
249     }
250 
251 #define CHECK_IF_PTR_NULL_RETURN_VOID(ptr) CHECK_IF_EQUAL_RETURN_VOID(ptr, nullptr)
252 } // namespace OHOS::Camera
253 #endif
254