/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HOS_CAMERA_H #define HOS_CAMERA_H #include "securec.h" #include #include #include #include #include #include #include #include #include #include #include #ifdef HITRACE_LOG_ENABLED #include "hitrace.h" #define DFX_LOCAL_HITRACE_BEGIN \ HiviewDFX::HiTraceId _trace_id; \ _trace_id = OHOS::HiviewDFX::HiTrace::Begin(__FUNCTION__, HITRACE_FLAG_DEFAULT); #define DFX_LOCAL_HITRACE_END OHOS::HiviewDFX::HiTrace::End(_trace_id); #else #define DFX_LOCAL_HITRACE_BEGIN #define DFX_LOCAL_HITRACE_END #endif // HITRACE_LOG_ENABLED #if 0 #if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 #include #define gettid() (pid_t) syscall(SYS_gettid) #endif #endif namespace OHOS::Camera { #define HDF_LOG_TAG camera_host #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) #ifndef OHOS_DEBUG #define DECORATOR_HDFLOG(op, fmt, args...) \ do { \ op("%{public}s() " fmt, __FUNCTION__, ##args); \ } while (0) #else #define DECORATOR_HDFLOG(op, fmt, args...) \ do { \ op("{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \ } while (0) #endif #define CAMERA_LOGE(fmt, ...) DECORATOR_HDFLOG(HDF_LOGE, fmt, ##__VA_ARGS__) #define CAMERA_LOGW(fmt, ...) DECORATOR_HDFLOG(HDF_LOGW, fmt, ##__VA_ARGS__) #define CAMERA_LOGI(fmt, ...) DECORATOR_HDFLOG(HDF_LOGI, fmt, ##__VA_ARGS__) #define CAMERA_LOGV(fmt, ...) DECORATOR_HDFLOG(HDF_LOGV, fmt, ##__VA_ARGS__) #define CAMERA_LOGD(fmt, ...) DECORATOR_HDFLOG(HDF_LOGD, fmt, ##__VA_ARGS__) #if 0 #define GET_CURRENT_TIME_MS \ struct timeval _tv; \ gettimeofday(&_tv, NULL); \ struct tm* _tm = localtime(&_tv.tv_sec); \ int _ms = _tv.tv_usec / 1000; \ char now[25] = {0}; \ sprintf_s(now, sizeof(now), "%02d-%02d %02d:%02d:%02d.%03d", _tm->tm_mon + 1, _tm->tm_mday, _tm->tm_hour, \ _tm->tm_min, _tm->tm_sec, _ms); #define CAMERA_LOGE(fmt, ...) \ do { \ GET_CURRENT_TIME_MS; \ pid_t pid = getpid(); \ pid_t tid = gettid(); \ printf("%s %4u %4u E " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ fflush(stdout); \ } while (0); #define CAMERA_LOGW(fmt, ...) \ do { \ GET_CURRENT_TIME_MS; \ pid_t pid = getpid(); \ pid_t tid = gettid(); \ printf("%s %4u %4u W " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ fflush(stdout); \ } while (0); #define CAMERA_LOGI(fmt, ...) \ do { \ GET_CURRENT_TIME_MS; \ pid_t pid = getpid(); \ pid_t tid = gettid(); \ printf("%s %4u %4u I " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ fflush(stdout); \ } while (0); #define CAMERA_LOGV(fmt, ...) \ do { \ GET_CURRENT_TIME_MS; \ pid_t pid = getpid(); \ pid_t tid = gettid(); \ printf("%s %4u %4u V " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ fflush(stdout); \ } while (0); #define CAMERA_LOGD(fmt, ...) \ do { \ GET_CURRENT_TIME_MS; \ pid_t pid = getpid(); \ pid_t tid = gettid(); \ printf("%s %4u %4u D " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ fflush(stdout); \ } while (0); #endif constexpr uint32_t FRAME_SIZE_TAG = 100; using RetCode = uint32_t; enum Ret : uint32_t { RC_OK = 0, RC_ERROR, }; enum BufferSourceType { CAMERA_BUFFER_SOURCE_TYPE_NONE = -1, CAMERA_BUFFER_SOURCE_TYPE_GRALLOC, CAMERA_BUFFER_SOURCE_TYPE_HEAP, CAMERA_BUFFER_SOURCE_TYPE_EXTERNAL, CAMERA_BUFFER_SOURCE_TYPE_MAX, }; enum CameraBufferUsage : uint64_t { CAMERA_USAGE_SW_READ_OFTEN = (1 << 0), CAMERA_USAGE_SW_WRITE_OFTEN = (1 << 1), CAMERA_USAGE_MEM_DMA = (1 << 2), }; enum CameraBufferFormat : uint32_t { CAMERA_FORMAT_INVALID, /* invalid format */ CAMERA_FORMAT_RGB_565, /* RGB565 format */ CAMERA_FORMAT_RGBA_5658, /* RGBA5658 format */ CAMERA_FORMAT_RGBX_4444, /* RGBX4444 format */ CAMERA_FORMAT_RGBA_4444, /* RGBA4444 format */ CAMERA_FORMAT_RGB_444, /* RGB444 format */ CAMERA_FORMAT_RGBX_5551, /* RGBX5551 format */ CAMERA_FORMAT_RGBA_5551, /* RGBA5551 format */ CAMERA_FORMAT_RGB_555, /* RGB555 format */ CAMERA_FORMAT_RGBX_8888, /* RGBX8888 format */ CAMERA_FORMAT_RGBA_8888, /* RGBA8888 format */ CAMERA_FORMAT_RGB_888, /* RGB888 format */ CAMERA_FORMAT_BGR_565, /* BGR565 format */ CAMERA_FORMAT_BGRX_4444, /* BGRX4444 format */ CAMERA_FORMAT_BGRA_4444, /* BGRA4444 format */ CAMERA_FORMAT_BGRX_5551, /* BGRX5551 format */ CAMERA_FORMAT_BGRA_5551, /* BGRA5551 format */ CAMERA_FORMAT_BGRX_8888, /* BGRX8888 format */ CAMERA_FORMAT_BGRA_8888, /* BGRA8888 format */ CAMERA_FORMAT_YUV_422_I, /* YUV422 interleaved format */ CAMERA_FORMAT_YCBCR_422_SP, /* YCBCR422 semi-planar format */ CAMERA_FORMAT_YCRCB_422_SP, /* YCRCB422 semi-planar format */ CAMERA_FORMAT_YCBCR_420_SP, /* YCBCR420 semi-planar format */ CAMERA_FORMAT_YCRCB_420_SP, /* YCRCB420 semi-planar format */ CAMERA_FORMAT_YCBCR_422_P, /* YCBCR422 planar format */ CAMERA_FORMAT_YCRCB_422_P, /* YCRCB422 planar format */ CAMERA_FORMAT_YCBCR_420_P, /* YCBCR420 planar format */ CAMERA_FORMAT_YCRCB_420_P, /* YCRCB420 planar format */ CAMERA_FORMAT_YUYV_422_PKG, /* YUYV422 packed format */ CAMERA_FORMAT_UYVY_422_PKG, /* UYVY422 packed format */ CAMERA_FORMAT_YVYU_422_PKG, /* YVYU422 packed format */ CAMERA_FORMAT_VYUY_422_PKG, /* VYUY422 packed format */ }; enum CameraEncodeType : int32_t { /** * 未设置编码类型 */ CAMERA_ENCODE_NULL = 0, /** * 编码类型为H264 */ CAMERA_ENCODE_H264 = 1, /** * 编码类型为H265 */ CAMERA_ENCODE_H265 = 2, /** * 编码类型为JPEG */ CAMERA_ENCODE_JPEG = 3, }; enum FlashMode : uint32_t { FlASH_OFF = 0, FlASH_SINGLE, FLASH_TORCH, FLASH_AUTO }; enum AdapterCmd : uint32_t { CMD_AE_EXPO, CMD_AWB_MODE, CMD_AE_EXPOTIME, CMD_AWB_COLORGAINS }; enum AwbMode : uint32_t { AWB_MODE_AUTO, AWB_MODE_CLOUDY_DAYLIGHT, AWB_MODE_TWILIGHT, AWB_MODE_FLUORESCENT, AWB_MODE_WARM_FLUORESCENT, }; using EsFrmaeInfo = struct EsFrmaeInfo { int32_t size; int32_t align; int32_t isKey; int64_t timestamp; int32_t frameNum; }; #define CHECK_IF_NOT_EQUAL_RETURN_VALUE(arg1, arg2, ret) \ if ((arg1) != (arg2)) { \ CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, \ #ret); \ return (ret); \ } #define CHECK_IF_EQUAL_RETURN_VALUE(arg1, arg2, ret) \ if ((arg1) == (arg2)) { \ CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, #ret); \ return (ret); \ } #define CHECK_IF_PTR_NULL_RETURN_VALUE(ptr, ret) CHECK_IF_EQUAL_RETURN_VALUE(ptr, nullptr, ret) #define CHECK_IF_NOT_EQUAL_RETURN_VOID(arg1, arg2) \ if ((arg1) != (arg2)) { \ CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return", __LINE__, #arg1, #arg2); \ return; \ } #define CHECK_IF_EQUAL_RETURN_VOID(arg1, arg2) \ if ((arg1) == (arg2)) { \ CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return", __LINE__, #arg1, #arg2); \ return; \ } #define CHECK_IF_PTR_NULL_RETURN_VOID(ptr) CHECK_IF_EQUAL_RETURN_VOID(ptr, nullptr) } // namespace OHOS::Camera #endif