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