• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2 * Copyright 2022-2023 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 
8 * http://www.apache.org/licenses/LICENSE-2.0
9 
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_UTILS_COMMON_DATA_TYPE_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_UTILS_COMMON_DATA_TYPE_H_
18 
19 #ifndef ENABLE_DVPP_INTERFACE
20 #define ENABLE_DVPP_INTERFACE
21 #endif
22 #include <cstdio>
23 #include <iostream>
24 #include <memory>
25 #include <string>
26 #include <vector>
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   kBool = 0,
47   kInt = 1,
48   kFloat = 2,
49   kString = 3,
50   kListBool = 4,
51   kListInt = 6,
52   kListFloat = 7,
53   kListString = 8,
54   kListListInt = 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 StreamData {
85   size_t size;                 // Size of memory, bytes
86   std::shared_ptr<void> data;  // Smart pointer of data
87 };
88 
89 // Description of stream data
90 struct StreamInfo {
91   std::string format;
92   uint32_t height;
93   uint32_t width;
94   uint32_t channelId;
95   std::string streamPath;
96 };
97 
98 // define the structure of an rectangle
99 struct Rectangle {
100   uint32_t leftTopX;
101   uint32_t leftTopY;
102   uint32_t rightBottomX;
103   uint32_t rightBottomY;
104 };
105 
106 struct ObjectDetectInfo {
107   int32_t classId;
108   float confidence;
109   struct Rectangle location;
110 };
111 
112 enum VpcProcessType {
113   VPC_PT_DEFAULT = 0,
114   VPC_PT_PADDING,  // Resize with locked ratio and paste on upper left corner
115   VPC_PT_FIT,      // Resize with locked ratio and paste on middle location
116   VPC_PT_FILL,     // Resize with locked ratio and paste on whole locatin, the input image may be cropped
117 };
118 
119 struct DvppDataInfo {
120   uint32_t width = 0;         // Width of image
121   uint32_t height = 0;        // Height of image
122   uint32_t widthStride = 0;   // Width after align up
123   uint32_t heightStride = 0;  // Height after align up
124   int format = 1;             // Format of image
125   uint32_t frameId = 0;       // Needed by video
126   uint32_t dataSize = 0;      // Size of data in byte
127   uint8_t *data = nullptr;    // Image data
128 };
129 
130 struct CropRoiConfig {
131   uint32_t left;
132   uint32_t right;
133   uint32_t down;
134   uint32_t up;
135 };
136 
137 struct DvppCropInputInfo {
138   struct DvppDataInfo dataInfo;
139   struct CropRoiConfig roi {};
140 };
141 
142 // Description of matrix info
143 struct MatrixInfo {
144   uint32_t row = 0;                      // row of matrix
145   uint32_t col = 0;                      // col of matrix
146   uint32_t dataSize = 0;                 // size of memory, bytes
147   std::shared_ptr<void> data = nullptr;  // data of matrix
148   int dataType = 1;                      // data Type of matrix
149 };
150 
151 // Description of coefficient info
152 struct CoefficientInfo {
153   std::shared_ptr<void> data = nullptr;  // data of coefficient
154   int dataType = 1;                      // dataType
155 };
156 
157 // define the input of BLAS operator such as producing:
158 // C = alpha * A * B + beta * C
159 struct BlasInput {
160   MatrixInfo A;
161   MatrixInfo B;
162   MatrixInfo C;
163   struct CoefficientInfo alpha;
164   struct CoefficientInfo beta;
165 };
166 
167 extern bool g_vdecNotified[VIDEO_PROCESS_THREAD];
168 extern bool g_vpcNotified[VIDEO_PROCESS_THREAD];
169 extern bool g_inferNotified[VIDEO_PROCESS_THREAD];
170 extern bool g_postNotified[VIDEO_PROCESS_THREAD];
171 
172 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_UTILS_COMMON_DATA_TYPE_H_
173