54f4a423
Hu Chunming
添加resize到1920,1080设置
|
1
|
#include "VpcUtils.h"
|
09c2d08c
Hu Chunming
arm交付版
|
2
3
4
5
|
#include "depend_headers.h"
#define ALIGN_UP(val, align) (((val) % (align) == 0) ? (val) : (((val) / (align) + 1) * (align)))
|
25a4a277
Hu Chunming
简化解码器线程,解决500小站上因...
|
6
7
8
9
10
11
12
13
14
|
#define CHECK_AND_RETURN(ret, message) \
if(ret != 0) {LOG_ERROR("{}", message); return ret;}
#define CHECK_NOT_RETURN(ret, message) \
if(ret != 0) {LOG_ERROR("{}", message);}
#define CHECK_AND_RETURN_NOVALUE(ret, message) \
if(ret != 0) {LOG_ERROR("{}", message); return;}
#define CHECK_AND_BREAK(ret, message) \
if(ret != 0) {LOG_ERROR("{}", message); break;}
|
54f4a423
Hu Chunming
添加resize到1920,1080设置
|
15
|
VpcUtils::VpcUtils(){
|
09c2d08c
Hu Chunming
arm交付版
|
16
17
18
|
}
|
54f4a423
Hu Chunming
添加resize到1920,1080设置
|
19
|
VpcUtils::~VpcUtils(){
|
54f4a423
Hu Chunming
添加resize到1920,1080设置
|
20
21
22
23
24
25
26
27
28
|
if(context_){
aclrtDestroyContext(context_);
}
if (dvppChannelDesc_) {
(void)acldvppDestroyChannel(dvppChannelDesc_);
(void)acldvppDestroyChannelDesc(dvppChannelDesc_);
dvppChannelDesc_ = nullptr;
}
|
09c2d08c
Hu Chunming
arm交付版
|
29
30
|
}
|
54f4a423
Hu Chunming
添加resize到1920,1080设置
|
31
32
33
|
int VpcUtils::init(int devId){
m_devId = devId;
|
09c2d08c
Hu Chunming
arm交付版
|
34
|
|
32f28195
Hu Chunming
优化vpc图片数据类型转换
|
35
36
|
aclrtSetDevice(m_devId);
aclrtCreateContext(&context_, m_devId);
|
09c2d08c
Hu Chunming
arm交付版
|
37
|
|
32f28195
Hu Chunming
优化vpc图片数据类型转换
|
38
|
CHECK_AND_RETURN(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed");
|
09c2d08c
Hu Chunming
arm交付版
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
dvppChannelDesc_ = acldvppCreateChannelDesc();
int ret = ACL_ERROR_NONE;
do
{
ret = acldvppCreateChannel(dvppChannelDesc_);
CHECK_AND_BREAK(ret, "acldvppCreateChannel failed !");
ret = acldvppSetChannelDescMode(dvppChannelDesc_, DVPP_CHNMODE_VPC);
CHECK_AND_BREAK(ret, "acldvppSetChannelDescMode failed !");
} while (0);
return ret;
}
|
54f4a423
Hu Chunming
添加resize到1920,1080设置
|
55
|
DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){
|
09c2d08c
Hu Chunming
arm交付版
|
56
|
|
32f28195
Hu Chunming
优化vpc图片数据类型转换
|
57
58
59
|
aclrtSetDevice(m_devId);
aclrtSetCurrentContext(context_);
|
09c2d08c
Hu Chunming
arm交付版
|
60
61
62
63
|
int out_buf_width = ALIGN_UP(out_width, 16) * 3;
int out_buf_height = ALIGN_UP(out_height, 2);
int out_buf_size = out_buf_width * out_buf_height;
|
746db74c
Hu Chunming
实现recode
|
64
|
DvppDataMemory* rgbMem = new DvppDataMemory(3, out_buf_width, out_buf_width, out_buf_height, out_buf_height, out_buf_size, "", to_string(m_devId), key_frame, 0);
|
09c2d08c
Hu Chunming
arm交付版
|
65
66
67
68
69
70
71
72
73
74
75
76
|
void *outBufferDev_ = (void*)rgbMem->getMem();
acldvppPicDesc *outputDesc_= acldvppCreatePicDesc();
acldvppSetPicDescData(outputDesc_, outBufferDev_);
acldvppSetPicDescFormat(outputDesc_, PIXEL_FORMAT_BGR_888);
acldvppSetPicDescWidth(outputDesc_, out_width);
acldvppSetPicDescHeight(outputDesc_, out_height);
acldvppSetPicDescWidthStride(outputDesc_, out_buf_width);
acldvppSetPicDescHeightStride(outputDesc_, out_buf_height);
acldvppSetPicDescSize(outputDesc_, out_buf_size);
aclError ret = ACL_ERROR_NONE;
|
8a3c2932
Hu Chunming
修复任务创建失败造成的内存泄漏问题
|
77
78
79
80
|
aclrtStream stream_ = nullptr;
aclrtCreateStream(&stream_);
|
09c2d08c
Hu Chunming
arm交付版
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
do{
// 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
if(ret != ACL_ERROR_NONE){
LOG_ERROR("acldvppVpcConvertColorAsync failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
break;
}
ret = aclrtSynchronizeStream(stream_);
if(ret != ACL_ERROR_NONE){
LOG_ERROR("aclrtSynchronizeStream failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
break;
}
}while(0);
|
8a3c2932
Hu Chunming
修复任务创建失败造成的内存泄漏问题
|
95
96
97
98
|
if (stream_ != nullptr) {
aclrtDestroyStream(stream_);
}
|
09c2d08c
Hu Chunming
arm交付版
|
99
100
101
102
103
104
105
106
|
acldvppDestroyPicDesc(outputDesc_);
if(ret != ACL_ERROR_NONE){
delete rgbMem;
rgbMem = nullptr;
}
return rgbMem;
|
32f28195
Hu Chunming
优化vpc图片数据类型转换
|
107
108
|
}
|
54f4a423
Hu Chunming
添加resize到1920,1080设置
|
109
|
DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){
|
32f28195
Hu Chunming
优化vpc图片数据类型转换
|
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
|
aclrtSetDevice(m_devId);
aclrtSetCurrentContext(context_);
int out_width = inMem->getWidth();
int out_height = inMem->getHeight();
acldvppPicDesc *inputDesc_= acldvppCreatePicDesc();
acldvppSetPicDescData(inputDesc_, inMem->getMem());
acldvppSetPicDescFormat(inputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420);
acldvppSetPicDescWidth(inputDesc_, out_width);
acldvppSetPicDescHeight(inputDesc_, out_height);
acldvppSetPicDescWidthStride(inputDesc_, inMem->getWidthStride());
acldvppSetPicDescHeightStride(inputDesc_, inMem->getHeightStride());
acldvppSetPicDescSize(inputDesc_, inMem->getSize());
int out_buf_width = ALIGN_UP(out_width, 16) * 3;
int out_buf_height = ALIGN_UP(out_height, 2);
int out_buf_size = out_buf_width * out_buf_height;
DvppDataMemory* rgbMem = new DvppDataMemory(3, out_buf_width, out_buf_width, out_buf_height, out_buf_height, out_buf_size, inMem->getId(), inMem->getDeviceId(), false, inMem->getFrameNb());
void *outBufferDev_ = (void*)rgbMem->getMem();
acldvppPicDesc *outputDesc_= acldvppCreatePicDesc();
acldvppSetPicDescData(outputDesc_, outBufferDev_);
acldvppSetPicDescFormat(outputDesc_, PIXEL_FORMAT_BGR_888);
acldvppSetPicDescWidth(outputDesc_, out_width);
acldvppSetPicDescHeight(outputDesc_, out_height);
acldvppSetPicDescWidthStride(outputDesc_, out_buf_width);
acldvppSetPicDescHeightStride(outputDesc_, out_buf_height);
acldvppSetPicDescSize(outputDesc_, out_buf_size);
aclError ret = ACL_ERROR_NONE;
|
8a3c2932
Hu Chunming
修复任务创建失败造成的内存泄漏问题
|
144
145
146
|
aclrtStream stream_ = nullptr;
aclrtCreateStream(&stream_);
|
32f28195
Hu Chunming
优化vpc图片数据类型转换
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
do{
// 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
if(ret != ACL_ERROR_NONE){
LOG_ERROR("acldvppVpcConvertColorAsync failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
break;
}
ret = aclrtSynchronizeStream(stream_);
if(ret != ACL_ERROR_NONE){
LOG_ERROR("aclrtSynchronizeStream failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
break;
}
}while(0);
|
8a3c2932
Hu Chunming
修复任务创建失败造成的内存泄漏问题
|
161
162
163
164
|
if (stream_ != nullptr) {
aclrtDestroyStream(stream_);
}
|
32f28195
Hu Chunming
优化vpc图片数据类型转换
|
165
166
167
168
169
170
171
172
173
|
acldvppDestroyPicDesc(outputDesc_);
acldvppDestroyPicDesc(inputDesc_);
if(ret != ACL_ERROR_NONE){
delete rgbMem;
rgbMem = nullptr;
}
return rgbMem;
|
54f4a423
Hu Chunming
添加resize到1920,1080设置
|
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
|
}
DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int out_height){
aclrtSetDevice(m_devId);
aclrtSetCurrentContext(context_);
int out_buf_width = ALIGN_UP(out_width, 16);
int out_buf_height = ALIGN_UP(out_height, 2);
int out_buf_size = out_buf_width * out_buf_height * 3 / 2;
DvppDataMemory* rgbMem = new DvppDataMemory(1, out_width, out_buf_width, out_height, out_buf_height, out_buf_size, "", "", false, 0);
void *outBufferDev_ = (void*)rgbMem->getMem();
acldvppPicDesc *outputDesc_= acldvppCreatePicDesc();
acldvppSetPicDescData(outputDesc_, outBufferDev_);
acldvppSetPicDescFormat(outputDesc_, acldvppGetPicDescFormat(inputDesc_));
acldvppSetPicDescWidth(outputDesc_, out_width);
acldvppSetPicDescHeight(outputDesc_, out_height);
acldvppSetPicDescWidthStride(outputDesc_, out_buf_width);
acldvppSetPicDescHeightStride(outputDesc_, out_buf_height);
acldvppSetPicDescSize(outputDesc_, out_buf_size);
acldvppResizeConfig *resizeConfig_ = acldvppCreateResizeConfig();
aclError ret = ACL_ERROR_NONE;
|
8a3c2932
Hu Chunming
修复任务创建失败造成的内存泄漏问题
|
200
201
|
aclrtStream stream_ = nullptr;
aclrtCreateStream(&stream_);
|
54f4a423
Hu Chunming
添加resize到1920,1080设置
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
do{
// 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
ret = acldvppVpcResizeAsync(dvppChannelDesc_, inputDesc_, outputDesc_, resizeConfig_, stream_);
if(ret != ACL_ERROR_NONE){
LOG_ERROR("acldvppVpcResizeAsync failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
break;
}
ret = aclrtSynchronizeStream(stream_);
if(ret != ACL_ERROR_NONE){
LOG_ERROR("aclrtSynchronizeStream failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
break;
}
}while(0);
|
8a3c2932
Hu Chunming
修复任务创建失败造成的内存泄漏问题
|
216
217
218
219
|
if (stream_ != nullptr) {
aclrtDestroyStream(stream_);
}
|
54f4a423
Hu Chunming
添加resize到1920,1080设置
|
220
221
222
223
224
225
226
227
228
|
acldvppDestroyResizeConfig(resizeConfig_);
acldvppDestroyPicDesc(outputDesc_);
if(ret != ACL_ERROR_NONE){
delete rgbMem;
rgbMem = nullptr;
}
return rgbMem;
|
09c2d08c
Hu Chunming
arm交付版
|
229
|
}
|