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 45namespace OHOS { 46namespace 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 79constexpr uint32_t FRAME_SIZE_TAG_UINT32 = 100; 80const std::string FRAME_SIZE_TAG_STRING = "FRAME_SIZE"; 81 82using CameraAbility = CameraMetadata; 83using CameraSetting = CameraMetadata; 84using MetaType = int32_t; 85 86using RetCode = uint32_t; 87enum Ret : uint32_t { 88 RC_OK = 0, 89 RC_ERROR, 90}; 91 92enum 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 100enum 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 110enum 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}; 144 145enum CameraEncodeType : int32_t { 146 CAMERA_ENCODE_NULL = 0, 147 CAMERA_ENCODE_H264 = 1, 148 CAMERA_ENCODE_H265 = 2, 149 CAMERA_ENCODE_JPEG = 3, 150}; 151 152enum FlashMode : uint32_t { FlASH_OFF = 0, FlASH_SINGLE, FLASH_TORCH, FLASH_AUTO }; 153 154enum AdapterCmd : uint32_t { 155 CMD_AE_EXPO, 156 CMD_AWB_MODE, 157 CMD_AWB_LOCK, 158 CMD_AE_EXPOTIME, 159 CMD_AE_LOCK, 160 CMD_EXPOSURE_MODE, 161 CMD_EXPOSURE_COMPENSATION, 162 CMD_EXPOSURE_STATE, 163 CMD_EXPOSURE_LOCK, 164 CMD_AWB_COLORGAINS, 165 CMD_FOCUS_AUTO, 166 CMD_FOCUS_ABSOLUTE, 167 CMD_AUTO_FOCUS_START, 168 CMD_AUTO_FOCUS_STOP, 169 CMD_FOCUS_REGION, 170 CMD_FOCUS_LOCK, 171 CMD_METER_MODE, 172 CMD_METER_POINT, 173 CMD_FLASH_MODE, 174 CMD_FPS_RANGE 175}; 176 177enum AwbMode : uint32_t { 178 AWB_MODE_AUTO, 179 AWB_MODE_CLOUDY_DAYLIGHT, 180 AWB_MODE_TWILIGHT, 181 AWB_MODE_FLUORESCENT, 182 AWB_MODE_WARM_FLUORESCENT, 183}; 184 185using EsFrameInfo = struct { 186 int32_t size; 187 int32_t align; 188 int32_t isKey; 189 int64_t timestamp; 190 int32_t frameNum; 191}; 192 193#define CHECK_IF_NOT_EQUAL_RETURN_VALUE(arg1, arg2, ret) \ 194 if ((arg1) != (arg2)) { \ 195 CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, \ 196 #ret); \ 197 return (ret); \ 198 } 199 200#define CHECK_IF_EQUAL_RETURN_VALUE(arg1, arg2, ret) \ 201 if ((arg1) == (arg2)) { \ 202 CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, #ret); \ 203 return (ret); \ 204 } 205 206#define CHECK_IF_PTR_NULL_RETURN_VALUE(ptr, ret) CHECK_IF_EQUAL_RETURN_VALUE(ptr, nullptr, ret) 207 208#define CHECK_IF_NOT_EQUAL_RETURN_VOID(arg1, arg2) \ 209 if ((arg1) != (arg2)) { \ 210 CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return", __LINE__, #arg1, #arg2); \ 211 return; \ 212 } 213 214#define CHECK_IF_EQUAL_RETURN_VOID(arg1, arg2) \ 215 if ((arg1) == (arg2)) { \ 216 CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return", __LINE__, #arg1, #arg2); \ 217 return; \ 218 } 219 220#define CHECK_IF_PTR_NULL_RETURN_VOID(ptr) CHECK_IF_EQUAL_RETURN_VOID(ptr, nullptr) 221} // namespace Camera 222} // namespace OHOS 223#endif 224