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