dvpp_jpegd.cpp
5.01 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
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* File dvpp_process.cpp
* Description: handle dvpp process
*/
#include <iostream>
#include "acl/acl.h"
#include "dvpp_jpegd.h"
#include "utils.h"
#include "sy_errorinfo.h"
using namespace std;
DvppJpegD::DvppJpegD(aclrtStream& stream, acldvppChannelDesc *dvppChannelDesc)
: stream_(stream), dvppChannelDesc_(dvppChannelDesc),
decodeOutBufferDev_(nullptr), decodeOutputDesc_(nullptr),
decodeOutWidthStride_(0), decodeOutHeightStride_(0)
{
}
DvppJpegD::~DvppJpegD()
{
DestroyDecodeResource();
}
int DvppJpegD::InitDecodeOutputDesc(ImageData& inputImage)
{
//230316 ascend310p兼容=================================================
auto socVersion = aclrtGetSocName();
if (strncmp(socVersion, "Ascend310P3", sizeof("Ascend310P3") - 1) == 0) {
decodeOutWidth_ = ALIGN_UP2(inputImage.width);
decodeOutHeight_ = ALIGN_UP2(inputImage.height);
decodeOutWidthStride_ = ALIGN_UP64(inputImage.width); // 64-byte alignment
decodeOutHeightStride_ = ALIGN_UP16(inputImage.height); // 16-byte alignment
} else {
decodeOutWidth_ = inputImage.width;
decodeOutHeight_ = inputImage.height;
decodeOutWidthStride_ = ALIGN_UP128(inputImage.width); // 128-byte alignment
decodeOutHeightStride_ = ALIGN_UP16(inputImage.height); // 16-byte alignment
}
if (decodeOutWidthStride_ == 0 || decodeOutHeightStride_ == 0) {
ERROR_LOG("InitDecodeOutputDesc AlignmentHelper failed");
return SY_FAILED;
}
//=====================================================================
acldvppJpegPredictDecSize(inputImage.data.get(), inputImage.size,
PIXEL_FORMAT_YUV_SEMIPLANAR_420, &decodeOutBufferSize_);
aclError aclRet = acldvppMalloc(&decodeOutBufferDev_, decodeOutBufferSize_);
//debug========================================================================
uint32_t size = ALIGN_UP(decodeOutBufferSize_,32) + 32;
aclRet = aclrtMemset(decodeOutBufferDev_,size, 128, size);
// aclRet = aclrtMemset(decodeOutBufferDev_,decodeOutBufferSize_, 0, decodeOutBufferSize_);
//debug end====================================================================
if (aclRet != ACL_SUCCESS) {
ERROR_LOG("acldvppMalloc decodeOutBufferDev_ failed, aclRet = %d", aclRet);
return SY_FAILED;
}
decodeOutputDesc_ = acldvppCreatePicDesc();
if (decodeOutputDesc_ == nullptr) {
ERROR_LOG("acldvppCreatePicDesc decodeOutputDesc_ failed");
return SY_FAILED;
}
acldvppSetPicDescData(decodeOutputDesc_, decodeOutBufferDev_);
acldvppSetPicDescFormat(decodeOutputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420);
acldvppSetPicDescWidth(decodeOutputDesc_, decodeOutWidth_);
acldvppSetPicDescHeight(decodeOutputDesc_, decodeOutHeight_);
acldvppSetPicDescWidthStride(decodeOutputDesc_, decodeOutWidthStride_);
acldvppSetPicDescHeightStride(decodeOutputDesc_, decodeOutHeightStride_);
acldvppSetPicDescSize(decodeOutputDesc_, decodeOutBufferSize_);
return SY_SUCCESS;
}
int DvppJpegD::Process(ImageData& dest, ImageData& src)
{
int ret = InitDecodeOutputDesc(src);
if (ret != SY_SUCCESS) {
ERROR_LOG("InitDecodeOutputDesc failed");
return SY_FAILED;
}
ImageData imageDevice;
Utils::CopyImageDataToDvpp(imageDevice, src);
//TODO:
aclError aclRet = acldvppJpegDecodeAsync(dvppChannelDesc_, reinterpret_cast<void *>(imageDevice.data.get()),
imageDevice.size, decodeOutputDesc_, stream_);
if (aclRet != ACL_SUCCESS) {
ERROR_LOG("acldvppJpegDecodeAsync failed, aclRet = %d", aclRet);
return SY_FAILED;
}
aclRet = aclrtSynchronizeStream(stream_);
if (aclRet != ACL_SUCCESS) {
ERROR_LOG("decode aclrtSynchronizeStream failed, aclRet = %d", aclRet);
return SY_FAILED;
}
dest.width = decodeOutWidth_;
dest.height = decodeOutHeight_;
dest.alignWidth = decodeOutWidthStride_;
dest.alignHeight = decodeOutHeightStride_;
dest.size = YUV420SP_SIZE(dest.alignWidth, dest.alignHeight);
dest.data = SHARED_PRT_DVPP_BUF(decodeOutBufferDev_);
// cout << "dvpp w:" << dest.width << " h:" << dest.height << " alignw:" << dest.alignWidth <<" alignh:" <<dest.alignHeight << " size: " << dest.size << endl;
// INFO_LOG("convert image success");
return SY_SUCCESS;
}
void DvppJpegD::DestroyDecodeResource()
{
if (decodeOutputDesc_ != nullptr) {
acldvppDestroyPicDesc(decodeOutputDesc_);
decodeOutputDesc_ = nullptr;
}
}