• 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 #include <string>
32 #include "camera_metadata_info.h"
33 
34 #ifdef HITRACE_DFX_ENABLED
35 #include "hitrace/hitracechain.h"
36 #define DFX_LOCAL_HITRACE_BEGIN     \
37     HiviewDFX::HiTraceId _trace_id; \
38     _trace_id = OHOS::HiviewDFX::HiTraceChain::Begin(__FUNCTION__, HITRACE_FLAG_DEFAULT)
39 #define DFX_LOCAL_HITRACE_END OHOS::HiviewDFX::HiTraceChain::End(_trace_id)
40 #else
41 #define DFX_LOCAL_HITRACE_BEGIN
42 #define DFX_LOCAL_HITRACE_END
43 #endif // HITRACE_DFX_ENABLED
44 
45 namespace OHOS {
46 namespace Camera {
47 
48 #ifdef HDF_LOG_TAG
49 #undef HDF_LOG_TAG
50 #endif
51 
52 #define HDF_LOG_TAG camera_hdi_service
53 
54 #ifdef LOG_DOMAIN
55 #undef LOG_DOMAIN
56 #endif
57 #define LOG_DOMAIN 0xD002513
58 
59 #define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
60 
61 #ifndef OHOS_DEBUG
62 #define DECORATOR_HDFLOG(op, fmt, args...)             \
63     do {                                               \
64         op("%{public}s() " fmt, __FUNCTION__, ##args); \
65     } while (0)
66 #else
67 #define DECORATOR_HDFLOG(op, fmt, args...)                                     \
68     do {                                                                       \
69         op("{%s()-%s:%d} " fmt, __FUNCTION__, FILENAME, __LINE__, ##args); \
70     } while (0)
71 #endif
72 
73 #define CAMERA_LOGE(fmt, ...) DECORATOR_HDFLOG(HDF_LOGE, fmt, ##__VA_ARGS__)
74 #define CAMERA_LOGW(fmt, ...) DECORATOR_HDFLOG(HDF_LOGW, fmt, ##__VA_ARGS__)
75 #define CAMERA_LOGI(fmt, ...) DECORATOR_HDFLOG(HDF_LOGI, fmt, ##__VA_ARGS__)
76 #define CAMERA_LOGV(fmt, ...) DECORATOR_HDFLOG(HDF_LOGV, fmt, ##__VA_ARGS__)
77 #define CAMERA_LOGD(fmt, ...) DECORATOR_HDFLOG(HDF_LOGD, fmt, ##__VA_ARGS__)
78 
79 constexpr uint32_t FRAME_SIZE_TAG_UINT32 = 100;
80 const std::string FRAME_SIZE_TAG_STRING = "FRAME_SIZE";
81 
82 using CameraAbility = CameraMetadata;
83 using CameraSetting = CameraMetadata;
84 using MetaType = int32_t;
85 
86 using RetCode = uint32_t;
87 enum Ret : uint32_t {
88     RC_OK = 0,
89     RC_ERROR,
90 };
91 
92 enum BufferSourceType {
93     CAMERA_BUFFER_SOURCE_TYPE_NONE = -1,
94     CAMERA_BUFFER_SOURCE_TYPE_GRALLOC,
95     CAMERA_BUFFER_SOURCE_TYPE_HEAP,
96     CAMERA_BUFFER_SOURCE_TYPE_EXTERNAL,
97     CAMERA_BUFFER_SOURCE_TYPE_MAX,
98 };
99 
100 enum CameraBufferUsage : uint64_t {
101     CAMERA_USAGE_SW_READ_OFTEN = (1 << 0),
102     CAMERA_USAGE_SW_WRITE_OFTEN = (1 << 1),
103     CAMERA_USAGE_MEM_DMA = (1 << 2),
104     CAMERA_USAGE_MEM_SHARE = (1 << 3),
105     CAMERA_USAGE_MEM_MMZ = (1 << 4),
106     CAMERA_USAGE_MEM_MMZ_CACHE = (1 << 5),
107     CAMERA_USAGE_MEM_FB = (1 << 6),
108 };
109 
110 enum CameraBufferFormat : uint32_t {
111     CAMERA_FORMAT_INVALID,      /* invalid format */
112     CAMERA_FORMAT_RGB_565,      /* RGB565 format */
113     CAMERA_FORMAT_RGBA_5658,    /* RGBA5658 format */
114     CAMERA_FORMAT_RGBX_4444,    /* RGBX4444 format */
115     CAMERA_FORMAT_RGBA_4444,    /* RGBA4444 format */
116     CAMERA_FORMAT_RGB_444,      /* RGB444 format */
117     CAMERA_FORMAT_RGBX_5551,    /* RGBX5551 format */
118     CAMERA_FORMAT_RGBA_5551,    /* RGBA5551 format */
119     CAMERA_FORMAT_RGB_555,      /* RGB555 format */
120     CAMERA_FORMAT_RGBX_8888,    /* RGBX8888 format */
121     CAMERA_FORMAT_RGBA_8888,    /* RGBA8888 format */
122     CAMERA_FORMAT_RGB_888,      /* RGB888 format */
123     CAMERA_FORMAT_BGR_565,      /* BGR565 format */
124     CAMERA_FORMAT_BGRX_4444,    /* BGRX4444 format */
125     CAMERA_FORMAT_BGRA_4444,    /* BGRA4444 format */
126     CAMERA_FORMAT_BGRX_5551,    /* BGRX5551 format */
127     CAMERA_FORMAT_BGRA_5551,    /* BGRA5551 format */
128     CAMERA_FORMAT_BGRX_8888,    /* BGRX8888 format */
129     CAMERA_FORMAT_BGRA_8888,    /* BGRA8888 format */
130     CAMERA_FORMAT_YUV_422_I,    /* YUV422 interleaved format */
131     CAMERA_FORMAT_YCBCR_422_SP, /* YCBCR422 semi-planar format */
132     CAMERA_FORMAT_YCRCB_422_SP, /* YCRCB422 semi-planar format */
133     CAMERA_FORMAT_YCBCR_420_SP, /* YCBCR420 semi-planar format */
134     CAMERA_FORMAT_YCRCB_420_SP, /* YCRCB420 semi-planar format */
135     CAMERA_FORMAT_YCBCR_422_P,  /* YCBCR422 planar format */
136     CAMERA_FORMAT_YCRCB_422_P,  /* YCRCB422 planar format */
137     CAMERA_FORMAT_YCBCR_420_P,  /* YCBCR420 planar format */
138     CAMERA_FORMAT_YCRCB_420_P,  /* YCRCB420 planar format */
139     CAMERA_FORMAT_YUYV_422_PKG, /* YUYV422 packed format */
140     CAMERA_FORMAT_UYVY_422_PKG, /* UYVY422 packed format */
141     CAMERA_FORMAT_YVYU_422_PKG, /* YVYU422 packed format */
142     CAMERA_FORMAT_VYUY_422_PKG, /* VYUY422 packed format */
143     CAMERA_FORMAT_BLOB,         /* MJPEG packed format */
144 };
145 
146 enum CameraEncodeType : int32_t {
147     CAMERA_ENCODE_NULL = 0,
148     CAMERA_ENCODE_H264 = 1,
149     CAMERA_ENCODE_H265 = 2,
150     CAMERA_ENCODE_JPEG = 3,
151 };
152 
153 enum FlashMode : uint32_t { FlASH_OFF = 0, FlASH_SINGLE, FLASH_TORCH, FLASH_AUTO };
154 
155 enum AdapterCmd : uint32_t {
156     CMD_AE_EXPO,
157     CMD_AWB_MODE,
158     CMD_AWB_LOCK,
159     CMD_AE_EXPOTIME,
160     CMD_AE_LOCK,
161     CMD_EXPOSURE_MODE,
162     CMD_EXPOSURE_COMPENSATION,
163     CMD_EXPOSURE_STATE,
164     CMD_EXPOSURE_LOCK,
165     CMD_AWB_COLORGAINS,
166     CMD_FOCUS_AUTO,
167     CMD_FOCUS_ABSOLUTE,
168     CMD_AUTO_FOCUS_START,
169     CMD_AUTO_FOCUS_STOP,
170     CMD_FOCUS_REGION,
171     CMD_FOCUS_LOCK,
172     CMD_METER_MODE,
173     CMD_METER_POINT,
174     CMD_FLASH_MODE,
175     CMD_FPS_RANGE
176 };
177 
178 enum AwbMode : uint32_t {
179     AWB_MODE_AUTO,
180     AWB_MODE_CLOUDY_DAYLIGHT,
181     AWB_MODE_TWILIGHT,
182     AWB_MODE_FLUORESCENT,
183     AWB_MODE_WARM_FLUORESCENT,
184 };
185 
186 using EsFrameInfo = struct {
187     int32_t size;
188     int32_t align;
189     int32_t isKey;
190     int64_t timestamp;
191     int32_t frameNum;
192 };
193 
194 #define CHECK_IF_NOT_EQUAL_RETURN_VALUE(arg1, arg2, ret)                                                            \
195     if ((arg1) != (arg2)) {                                                                                         \
196         CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, \
197                     #ret);                                                                                          \
198         return (ret);                                                                                               \
199     }
200 
201 #define CHECK_IF_EQUAL_RETURN_VALUE(arg1, arg2, ret)                                                                   \
202     if ((arg1) == (arg2)) {                                                                                            \
203         CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, #ret); \
204         return (ret);                                                                                                  \
205     }
206 
207 #define CHECK_IF_PTR_NULL_RETURN_VALUE(ptr, ret) CHECK_IF_EQUAL_RETURN_VALUE(ptr, nullptr, ret)
208 
209 #define CHECK_IF_NOT_EQUAL_RETURN_VOID(arg1, arg2)                                                        \
210     if ((arg1) != (arg2)) {                                                                               \
211         CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return", __LINE__, #arg1, #arg2); \
212         return;                                                                                           \
213     }
214 
215 #define CHECK_IF_EQUAL_RETURN_VOID(arg1, arg2)                                                        \
216     if ((arg1) == (arg2)) {                                                                           \
217         CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return", __LINE__, #arg1, #arg2); \
218         return;                                                                                       \
219     }
220 
221 #define CHECK_IF_PTR_NULL_RETURN_VOID(ptr) CHECK_IF_EQUAL_RETURN_VOID(ptr, nullptr)
222 } // namespace Camera
223 } // namespace OHOS
224 #endif
225