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_TEMP_H 17 #define HOS_CAMERA_TEMP_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <iostream> 22 #include <memory> 23 #include <stdint.h> 24 #include <stdio.h> 25 #include <stdlib.h> 26 #include <hdf_log.h> 27 28 namespace OHOS::Camera { 29 enum CameraBufferStatus { 30 CAMERA_BUFFER_STATUS_OK = 0, 31 CAMERA_BUFFER_STATUS_DROP, 32 CAMERA_BUFFER_STATUS_INVALID, 33 }; 34 class IBuffer { 35 public: IBuffer()36 IBuffer() {} ~IBuffer()37 ~IBuffer() {} 38 GetIndex()39 int32_t GetIndex() 40 { 41 return index_; 42 } GetSize()43 uint32_t GetSize() 44 { 45 return size_; 46 } GetVirAddress()47 void* GetVirAddress() 48 { 49 return virAddr_; 50 } 51 GetUsage()52 uint64_t GetUsage() 53 { 54 return usage_; 55 } 56 SetIndex(const uint32_t index)57 void SetIndex(const uint32_t index) 58 { 59 index_ = index; 60 return; 61 } 62 SetSize(const uint32_t size)63 void SetSize(const uint32_t size) 64 { 65 size_ = size; 66 return; 67 } 68 SetVirAddress(void * addr)69 void SetVirAddress(void* addr) 70 { 71 virAddr_ = addr; 72 return; 73 } 74 SetUsage(const uint64_t usage)75 void SetUsage(const uint64_t usage) 76 { 77 usage_ = usage; 78 return; 79 } SetBufferStatus(const CameraBufferStatus flag)80 void SetBufferStatus(const CameraBufferStatus flag) 81 { 82 (void)flag; 83 } 84 85 private: 86 int32_t index_ = -1; 87 uint32_t size_ = 0; 88 void* virAddr_ = nullptr; 89 uint64_t usage_ = 0; 90 }; 91 92 using FrameSpec = struct { 93 int64_t bufferPoolId_; 94 std::shared_ptr<IBuffer> buffer_; 95 }; 96 97 98 enum AdapterCmd : uint32_t { 99 CMD_AE_EXPO, 100 CMD_AWB_MODE, 101 CMD_AE_EXPOTIME, 102 CMD_EXPOSURE_MODE, 103 CMD_EXPOSURE_COMPENSATION, 104 CMD_EXPOSURE_STATE, 105 CMD_AWB_COLORGAINS, 106 CMD_FOCUS_MODE, 107 CMD_FOCUS_REGION, 108 CMD_METER_MODE, 109 CMD_METER_POINT, 110 CMD_FLASH_MODE, 111 CMD_FPS_RANGE 112 }; 113 114 #ifdef DISABLE_LOGD 115 #define CAMERA_LOGD(...) 116 #else 117 #define CAMERA_LOGD(fmt, ...) \ 118 do { \ 119 HDF_LOGD("INFO:" fmt "\n", ##__VA_ARGS__); \ 120 } while (0) 121 #endif 122 123 #define CAMERA_LOGE(fmt, ...) \ 124 do { \ 125 HDF_LOGD("ERROR:" fmt "\n", ##__VA_ARGS__); \ 126 } while (0) 127 128 enum RetCode { 129 RC_OK = 0, 130 RC_ERROR, 131 }; 132 133 #define CHECK_IF_NOT_EQUAL_RETURN_VALUE(arg1, arg2, ret) \ 134 if ((arg1) != (arg2)) { \ 135 CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, \ 136 #ret); \ 137 return (ret); \ 138 } 139 140 #define CHECK_IF_EQUAL_RETURN_VALUE(arg1, arg2, ret) \ 141 if ((arg1) == (arg2)) { \ 142 CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return %{public}s", __LINE__, #arg1, #arg2, #ret); \ 143 return (ret); \ 144 } 145 146 #define CHECK_IF_PTR_NULL_RETURN_VALUE(ptr, ret) CHECK_IF_EQUAL_RETURN_VALUE(ptr, nullptr, ret) 147 148 #define CHECK_IF_NOT_EQUAL_RETURN_VOID(arg1, arg2) \ 149 if ((arg1) != (arg2)) { \ 150 CAMERA_LOGE("%{public}u, %{public}s is not equal to %{public}s, return", __LINE__, #arg1, #arg2); \ 151 return; \ 152 } 153 154 #define CHECK_IF_EQUAL_RETURN_VOID(arg1, arg2) \ 155 if ((arg1) == (arg2)) { \ 156 CAMERA_LOGE("%{public}u, %{public}s is equal to %{public}s, return", __LINE__, #arg1, #arg2); \ 157 return; \ 158 } 159 160 #define CHECK_IF_PTR_NULL_RETURN_VOID(ptr) CHECK_IF_EQUAL_RETURN_VOID(ptr, nullptr) 161 } // namespace OHOS::Camera 162 #endif // HOS_CAMERA_TEMP_H 163