DeviceMemory.hpp
5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef __DVPP_DEVICE_MEMORY_H__
#define __DVPP_DEVICE_MEMORY_H__
#include <string.h>
#include <memory>
#include <vector>
#include "utiltools.hpp"
using namespace std;
struct AreaInfo {
string task_id; //该物体属于的任务ID号
int task_frame_count; //该物体当前出现的帧号
int object_id; //该物体的ID号
int index; //该物体所属类别的编号
double confidence; //该物体的置信度
int left; //该物体位置的左坐标
int top; //该物体位置的上坐标
int right; //该物体位置的右坐标
int bottom; //该物体位置的下坐标
};
struct HostData {
unsigned char * pData {nullptr};
int width{0};
int width_stride{0};
int height{0};
int height_stride{0};
int data_size{0};
int channel{3};
string id;
HostData(int w, int w_s, int h, int h_s, int s, string _id) {
width = w;
width_stride = w_s;
height = h;
height_stride = h_s;
data_size = s;
id = _id;
pData = (unsigned char *)malloc(data_size);
}
HostData(HostData* pSrc) {
width = pSrc->width;
width_stride = pSrc->width_stride;
height = pSrc->height;
height_stride = pSrc->height_stride;
data_size = pSrc->data_size;
id = pSrc->id;
pData = (unsigned char *)malloc(data_size);
memcpy(pData, pSrc->pData, data_size);
}
HostData* clone() {
return new HostData(this);
}
~HostData() {
if(pData) {
free(pData);
pData = nullptr;
}
width = 0;
width_stride = 0;
height = 0;
height_stride = 0;
data_size = 0;
channel = 0;
id = "";
}
};
// typedef shared_ptr<HostData> HostDataPtr;
class DeviceMemory {
public:
DeviceMemory(int _channel, int _width, int _width_stride, int _height, int _height_stride, int _size, string _id, string _dev_id, bool _key_frame, unsigned long long _frame_nb, bool _isused){
channel = _channel;
width = _width;
width_stride = _width_stride;
height = _height;
height_stride = _height_stride;
data_size = _size;
isused = _isused;
id = _id;
device_id = _dev_id;
key_frame = _key_frame;
frame_nb = _frame_nb;
timestamp = UtilTools::get_cur_time_ms();
}
virtual ~DeviceMemory(){
}
virtual HostData* memCpy2Host() = 0;
virtual DeviceMemory* clone() = 0;
int getSize() {
return data_size;
}
void setSize(int size) {
data_size = size;
}
bool isIsused() {
return isused;
}
void setIsused(bool _isused) {
isused = _isused;
// 更新时间戳
timestamp = UtilTools::get_cur_time_ms();
}
string getId() {
return id;
}
void setId(string _id) {
id = _id;
}
string getDeviceId() {
return device_id;
}
int getDeviceId_i() {
return atoi(device_id.c_str());
}
void setDeviceId(string _device_id) {
device_id = _device_id;
}
unsigned char* getMem(){
return pHwRgb;
}
void setMem(unsigned char* _pHwRgb) {
pHwRgb = _pHwRgb;
}
long long getTimesstamp(){
return timestamp;
}
void setTimesstamp(long long _timestamp) {
timestamp = _timestamp;
}
int getWidth(){
return width;
}
void setWidth(int _width) {
width = _width;
}
int getWidthStride(){
return width_stride;
}
void setWidthStride(int _width_stride) {
width_stride = _width_stride;
}
int getHeight(){
return height;
}
void setHeight(int _height) {
height = _height;
}
int getHeightStride(){
return height_stride;
}
void setHeightStride(int _height_stride) {
height_stride = _height_stride;
}
int getChannel(){
return channel;
}
void setChannel(int _channel) {
channel = _channel;
}
bool isKeyFrame(){
return key_frame;
}
void setKeyFrame(bool _key_frame) {
key_frame = _key_frame;
}
unsigned long long getFrameNb() {
return frame_nb;
}
void setFrameNb(unsigned long long _frame_nb) {
frame_nb = _frame_nb;
}
unsigned long long getDisplayFrameNb() {
return display_frame_nb;
}
void setDisplayFrameNb(unsigned long long _display_frame_nb) {
display_frame_nb = _display_frame_nb;
}
public:
int data_size;
bool isused;
string id;
string device_id;
unsigned char * pHwRgb{nullptr};
long long timestamp;
int width{0};
int width_stride{0};
int height{0};
int height_stride{0};
int channel{3};
bool key_frame;
unsigned long long frame_nb;
unsigned long long display_frame_nb;
};
// typedef std::shared_ptr<DeviceMemory> DeviceMemoryPtr;
#endif // __DVPP_DEVICE_MEMORY_H__