1 /* 2 * Copyright (c) 2020.Huawei Technologies Co., Ltd. All rights reserved. 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 COMMONDATATYPE_H 17 #define COMMONDATATYPE_H 18 #ifndef ENABLE_DVPP_INTERFACE 19 #define ENABLE_DVPP_INTERFACE 20 #endif 21 #include <cstdio> 22 #include <iostream> 23 #include <memory> 24 #include <vector> 25 #include "acl/acl.h" 26 #include "acl/ops/acl_dvpp.h" 27 28 #define DVPP_ALIGN_UP(x, align) ((((x) + ((align)-1)) / (align)) * (align)) 29 30 const uint32_t VIDEO_H264 = 0; 31 const uint32_t VIDEO_H265 = 1; 32 33 const float SEC2MS = 1000.0; 34 const uint32_t VIDEO_PROCESS_THREAD = 16; 35 const int YUV_BGR_SIZE_CONVERT_3 = 3; 36 const int YUV_BGR_SIZE_CONVERT_2 = 2; 37 const int DVPP_JPEG_OFFSET = 8; 38 const int VPC_WIDTH_ALIGN = 16; 39 const int VPC_HEIGHT_ALIGN = 2; 40 const int JPEG_WIDTH_ALIGN = 128; 41 const int JPEG_HEIGHT_ALIGN = 16; 42 const int VPC_OFFSET_ALIGN = 2; 43 44 // Data type of tensor 45 enum OpAttrType { 46 BOOL = 0, 47 INT = 1, 48 FLOAT = 2, 49 STRING = 3, 50 LIST_BOOL = 4, 51 LIST_INT = 6, 52 LIST_FLOAT = 7, 53 LIST_STRING = 8, 54 LIST_LIST_INT = 9, 55 }; 56 57 // operator attribution describe 58 // type decide whether the other attribute needed to set a value 59 struct OpAttr { 60 std::string name; 61 OpAttrType type; 62 int num; // LIST_BOOL/INT/FLOAT/STRING/LIST_LIST_INT need 63 uint8_t numBool; // BOOL need 64 int64_t numInt; // INT need 65 float numFloat; // FLOAT need 66 std::string numString; // STRING need 67 std::vector<uint8_t> valuesBool; // LIST_BOOL need 68 std::vector<int64_t> valuesInt; // LIST_INT need 69 std::vector<float> valuesFloat; // LIST_FLOAT need 70 std::vector<std::string> valuesString; // LIST_STRING need 71 std::vector<int> numLists; // LIST_LIST_INT need 72 std::vector<std::vector<int64_t>> valuesListList; // LIST_LIST_INT need 73 }; 74 75 // Description of image data 76 struct ImageInfo { 77 uint32_t width; // Image width 78 uint32_t height; // Image height 79 uint32_t lenOfByte; // Size of image data, bytes 80 std::shared_ptr<uint8_t> data; // Smart pointer of image data 81 }; 82 83 // Description of data in device 84 struct RawData { 85 size_t lenOfByte; // Size of memory, bytes 86 void *data; // Pointer of data 87 }; 88 89 // Description of data in device 90 struct StreamData { 91 size_t size; // Size of memory, bytes 92 std::shared_ptr<void> data; // Smart pointer of data 93 }; 94 95 // Description of stream data 96 struct StreamInfo { 97 std::string format; 98 uint32_t height; 99 uint32_t width; 100 uint32_t channelId; 101 std::string streamPath; 102 }; 103 104 // define the structure of an rectangle 105 struct Rectangle { 106 uint32_t leftTopX; 107 uint32_t leftTopY; 108 uint32_t rightBottomX; 109 uint32_t rightBottomY; 110 }; 111 112 struct ObjectDetectInfo { 113 int32_t classId; 114 float confidence; 115 Rectangle location; 116 }; 117 118 enum VpcProcessType { 119 VPC_PT_DEFAULT = 0, 120 VPC_PT_PADDING, // Resize with locked ratio and paste on upper left corner 121 VPC_PT_FIT, // Resize with locked ratio and paste on middle location 122 VPC_PT_FILL, // Resize with locked ratio and paste on whole locatin, the input image may be cropped 123 }; 124 125 struct DvppDataInfo { 126 uint32_t width = 0; // Width of image 127 uint32_t height = 0; // Height of image 128 uint32_t widthStride = 0; // Width after align up 129 uint32_t heightStride = 0; // Height after align up 130 acldvppPixelFormat format = PIXEL_FORMAT_YUV_SEMIPLANAR_420; // Format of image 131 uint32_t frameId = 0; // Needed by video 132 uint32_t dataSize = 0; // Size of data in byte 133 uint8_t *data = nullptr; // Image data 134 }; 135 136 struct CropRoiConfig { 137 uint32_t left; 138 uint32_t right; 139 uint32_t down; 140 uint32_t up; 141 }; 142 143 struct DvppCropInputInfo { 144 DvppDataInfo dataInfo; 145 CropRoiConfig roi; 146 }; 147 148 // Description of matrix info 149 struct MatrixInfo { 150 uint32_t row = 0; // row of matrix 151 uint32_t col = 0; // col of matrix 152 uint32_t dataSize = 0; // size of memory, bytes 153 std::shared_ptr<void> data = nullptr; // data of matrix 154 aclDataType dataType = ACL_FLOAT16; // data Type of matrix 155 }; 156 157 // Description of coefficient info 158 struct CoefficientInfo { 159 std::shared_ptr<void> data = nullptr; // data of coefficient 160 aclDataType dataType = ACL_FLOAT16; // dataType 161 }; 162 163 // define the input of BLAS operator such as producing: 164 // C = alpha * A * B + beta * C 165 struct BlasInput { 166 MatrixInfo A; 167 MatrixInfo B; 168 MatrixInfo C; 169 CoefficientInfo alpha; 170 CoefficientInfo beta; 171 }; 172 173 extern bool g_vdecNotified[VIDEO_PROCESS_THREAD]; 174 extern bool g_vpcNotified[VIDEO_PROCESS_THREAD]; 175 extern bool g_inferNotified[VIDEO_PROCESS_THREAD]; 176 extern bool g_postNotified[VIDEO_PROCESS_THREAD]; 177 178 #endif 179