History

fix low memory crash issue

huili2 committed 9 years ago

Commit d1c0a931 parent 48c2fe116 files · +401 −386Browse files

Showing the changes to test/api/encode_decode_api_test.cpp (1 of 16 files). Show all

Unified · Split

test/api/encode_decode_api_test.cpp+147−131
@@ -11,168 +11,183 @@ · 10 unmodified lines
11using namespace WelsCommon;11using namespace WelsCommon;
12 12
13 13
14void EncodeDecodeTestBase::prepareParam (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) {14void EncodeDecodeTestBase::prepareParam (int iLayers, int iSlices, int width, int height, float framerate,
15 pParam->iUsageType = CAMERA_VIDEO_REAL_TIME;15 SEncParamExt* pParam) {
16 pParam->iPicWidth = width;16 pParam->iUsageType = CAMERA_VIDEO_REAL_TIME;
17 pParam->iPicHeight = height;17 pParam->iPicWidth = width;
18 pParam->fMaxFrameRate = framerate;18 pParam->iPicHeight = height;
19 pParam->iRCMode = RC_OFF_MODE; //rc off19 pParam->fMaxFrameRate = framerate;
20 pParam->iMultipleThreadIdc = 1; //single thread20 pParam->iRCMode = RC_OFF_MODE; //rc off
21 pParam->iSpatialLayerNum = iLayers;21 pParam->iMultipleThreadIdc = 1; //single thread
22 pParam->iNumRefFrame = AUTO_REF_PIC_COUNT;22 pParam->iSpatialLayerNum = iLayers;
23 for (int i = 0; i < iLayers; i++) {23 pParam->iNumRefFrame = AUTO_REF_PIC_COUNT;
24 pParam->sSpatialLayers[i].iVideoWidth = width >> (iLayers - i - 1);24 for (int i = 0; i < iLayers; i++) {
25 pParam->sSpatialLayers[i].iVideoHeight = height >> (iLayers - i - 1);25 pParam->sSpatialLayers[i].iVideoWidth = width >> (iLayers - i - 1);
26 pParam->sSpatialLayers[i].fFrameRate = framerate;26 pParam->sSpatialLayers[i].iVideoHeight = height >> (iLayers - i - 1);
27 pParam->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;27 pParam->sSpatialLayers[i].fFrameRate = framerate;
28 pParam->sSpatialLayers[i].sSliceArgument.uiSliceNum = iSlices;28 pParam->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
29 }29 pParam->sSpatialLayers[i].sSliceArgument.uiSliceNum = iSlices;
30 }
30}31}
31 32
32void EncodeDecodeTestBase::prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) {33bool EncodeDecodeTestBase::prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) {
33 //for encoder34 //for encoder
34 //I420: 1(Y) + 1/4(U) + 1/4(V)35 //I420: 1(Y) + 1/4(U) + 1/4(V)
35 int frameSize = EncDecFileParam.width * EncDecFileParam.height * 3 / 2;36 int frameSize = EncDecFileParam.width * EncDecFileParam.height * 3 / 2;
36 buf_.SetLength (frameSize);37 buf_.SetLength (frameSize);
37 ASSERT_TRUE (buf_.Length() == (size_t)frameSize);38 if (buf_.Length() != (size_t)frameSize) {
38 memset (&EncPic, 0, sizeof (SSourcePicture));39 printf ("buf_.Length() failed! frameSize = %d\n", frameSize);
39 EncPic.iPicWidth = EncDecFileParam.width;40 return false;
40 EncPic.iPicHeight = EncDecFileParam.height;41 }
41 EncPic.iColorFormat = videoFormatI420;42 memset (&EncPic, 0, sizeof (SSourcePicture));
42 EncPic.iStride[0] = EncPic.iPicWidth;43 EncPic.iPicWidth = EncDecFileParam.width;
43 EncPic.iStride[1] = EncPic.iStride[2] = EncPic.iPicWidth >> 1;44 EncPic.iPicHeight = EncDecFileParam.height;
44 EncPic.pData[0] = buf_.data();45 EncPic.iColorFormat = videoFormatI420;
45 EncPic.pData[1] = EncPic.pData[0] + EncDecFileParam.width * EncDecFileParam.height;46 EncPic.iStride[0] = EncPic.iPicWidth;
46 EncPic.pData[2] = EncPic.pData[1] + (EncDecFileParam.width * EncDecFileParam.height >> 2);47 EncPic.iStride[1] = EncPic.iStride[2] = EncPic.iPicWidth >> 1;
47 //for decoder48 EncPic.pData[0] = buf_.data();
48 memset (&info, 0, sizeof (SFrameBSInfo));49 EncPic.pData[1] = EncPic.pData[0] + EncDecFileParam.width * EncDecFileParam.height;
49 //set a fixed random value50 EncPic.pData[2] = EncPic.pData[1] + (EncDecFileParam.width * EncDecFileParam.height >> 2);
50 iRandValue = rand() % 256;51 //for decoder
52 memset (&info, 0, sizeof (SFrameBSInfo));
53 //set a fixed random value
54 iRandValue = rand() % 256;
55 return true;
51}56}
52 57
53void EncodeDecodeTestBase::encToDecData (const SFrameBSInfo& info, int& len) {58void EncodeDecodeTestBase::encToDecData (const SFrameBSInfo& info, int& len) {
54 len = 0;59 len = 0;
55 for (int i = 0; i < info.iLayerNum; ++i) {60 for (int i = 0; i < info.iLayerNum; ++i) {
56 const SLayerBSInfo& layerInfo = info.sLayerInfo[i];61 const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
57 for (int j = 0; j < layerInfo.iNalCount; ++j) {62 for (int j = 0; j < layerInfo.iNalCount; ++j) {
58 len += layerInfo.pNalLengthInByte[j];63 len += layerInfo.pNalLengthInByte[j];
59 }
60 }64 }
65 }
61}66}
62 67
63void EncodeDecodeTestBase::encToDecSliceData (const int iLayerNum, const int iSliceNum, const SFrameBSInfo& info, int& len) {68void EncodeDecodeTestBase::encToDecSliceData (const int iLayerNum, const int iSliceNum, const SFrameBSInfo& info,
64 ASSERT_TRUE (iLayerNum < MAX_LAYER_NUM_OF_FRAME);69 int& len) {
65 len = 0;70 ASSERT_TRUE (iLayerNum < MAX_LAYER_NUM_OF_FRAME);
66 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayerNum];71 len = 0;
67 if (iSliceNum < layerInfo.iNalCount)72 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayerNum];
68 len = layerInfo.pNalLengthInByte[iSliceNum];73 if (iSliceNum < layerInfo.iNalCount)
74 len = layerInfo.pNalLengthInByte[iSliceNum];
69}75}
70 76
71void EncodeDecodeTestAPIBase::prepareParam0 (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) {77void EncodeDecodeTestAPIBase::prepareParam0 (int iLayers, int iSlices, int width, int height, float framerate,
72 memset (pParam, 0, sizeof (SEncParamExt));78 SEncParamExt* pParam) {
73 EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam);79 memset (pParam, 0, sizeof (SEncParamExt));
80 EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam);
74}81}
75 82
76void EncodeDecodeTestAPIBase::prepareParamDefault (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) {83void EncodeDecodeTestAPIBase::prepareParamDefault (int iLayers, int iSlices, int width, int height, float framerate,
77 memset (pParam, 0, sizeof (SEncParamExt));84 SEncParamExt* pParam) {
78 encoder_->GetDefaultParams (pParam);85 memset (pParam, 0, sizeof (SEncParamExt));
79 EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam);86 encoder_->GetDefaultParams (pParam);
87 EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam);
80}88}
81 89
82 90
83void EncodeDecodeTestAPIBase::EncodeOneFrame (int iCheckTypeIndex) {91void EncodeDecodeTestAPIBase::EncodeOneFrame (int iCheckTypeIndex) {
84 int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;92 int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;
85 int lumaSize = EncPic.iPicWidth * EncPic.iPicHeight;93 int lumaSize = EncPic.iPicWidth * EncPic.iPicHeight;
86 memset (buf_.data(), iRandValue, lumaSize);94 memset (buf_.data(), iRandValue, lumaSize);
87 memset (buf_.data() + lumaSize, rand() % 256, (frameSize - lumaSize));95 memset (buf_.data() + lumaSize, rand() % 256, (frameSize - lumaSize));
88 int rv = encoder_->EncodeFrame (&EncPic, &info);96 int rv = encoder_->EncodeFrame (&EncPic, &info);
89 if (0 == iCheckTypeIndex)97 if (0 == iCheckTypeIndex)
90 ASSERT_TRUE (rv == cmResultSuccess);98 ASSERT_TRUE (rv == cmResultSuccess);
91 else if (1 == iCheckTypeIndex)99 else if (1 == iCheckTypeIndex)
92 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);100 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);
93}101}
94 102
95void EncodeDecodeTestAPIBase::EncDecOneFrame (const int iWidth, const int iHeight, const int iFrame, FILE* pfEnc) {103bool EncodeDecodeTestAPIBase::EncDecOneFrame (const int iWidth, const int iHeight, const int iFrame, FILE* pfEnc) {
96 int iLen = 0, rv;104 int iLen = 0, rv;
97 InitialEncDec (iWidth, iHeight);105 if (!InitialEncDec (iWidth, iHeight))
98 EncodeOneFrame (iFrame);106 return false;
99 107 EncodeOneFrame (iFrame);
100 //extract target layer data108
101 encToDecData (info, iLen);109 //extract target layer data
102 //call decoder110 encToDecData (info, iLen);
103 unsigned char* pData[3] = { NULL };111 //call decoder
104 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));112 unsigned char* pData[3] = { NULL };
105 rv = decoder_->DecodeFrameNoDelay (info.sLayerInfo[0].pBsBuf, iLen, pData, &dstBufInfo_);113 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
106 EXPECT_TRUE (rv == cmResultSuccess) << " rv = " << rv << " iFrameIdx = " << iFrame;114 rv = decoder_->DecodeFrameNoDelay (info.sLayerInfo[0].pBsBuf, iLen, pData, &dstBufInfo_);
107 if (NULL != pfEnc) {115 EXPECT_TRUE (rv == cmResultSuccess) << " rv = " << rv << " iFrameIdx = " << iFrame;
108 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, pfEnc);116 if (NULL != pfEnc) {
109 }117 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, pfEnc);
118 }
119 return true;
110}120}
111 121
112void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, int iSpatialLayerNum,122bool EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf,
113 int iEncFrameNum,123 int iSpatialLayerNum,
114 int iSaveFileIdx) {124 int iEncFrameNum,
115 int aLen[MAX_SPATIAL_LAYER_NUM] = {0, 0, 0, 0};125 int iSaveFileIdx) {
116 126 int aLen[MAX_SPATIAL_LAYER_NUM] = {0, 0, 0, 0};
117 FILE* fEnc[MAX_SPATIAL_LAYER_NUM];127
118 if (iSaveFileIdx == 1) {128 FILE* fEnc[MAX_SPATIAL_LAYER_NUM];
119 fEnc[0] = fopen ("enc00.264", "wb");129 if (iSaveFileIdx == 1) {
120 fEnc[1] = fopen ("enc01.264", "wb");130 fEnc[0] = fopen ("enc00.264", "wb");
121 fEnc[2] = fopen ("enc02.264", "wb");131 fEnc[1] = fopen ("enc01.264", "wb");
122 fEnc[3] = fopen ("enc03.264", "wb");132 fEnc[2] = fopen ("enc02.264", "wb");
123 } else if (iSaveFileIdx > 1) {133 fEnc[3] = fopen ("enc03.264", "wb");
124 fEnc[0] = fopen ("enc10.264", "wb");134 } else if (iSaveFileIdx > 1) {
125 fEnc[1] = fopen ("enc11.264", "wb");135 fEnc[0] = fopen ("enc10.264", "wb");
126 fEnc[2] = fopen ("enc12.264", "wb");136 fEnc[1] = fopen ("enc11.264", "wb");
127 fEnc[3] = fopen ("enc13.264", "wb");137 fEnc[2] = fopen ("enc12.264", "wb");
128 }138 fEnc[3] = fopen ("enc13.264", "wb");
139 }
129 140
130 int rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, pParam);141 int rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, pParam);
131 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed pParam: rv = " << rv;142 if (rv != cmResultSuccess) {
143 printf ("SetOption Failed, rv = %d\n", rv);
144 return false;
145 }
132 146
133 int iIdx;147 int iIdx;
134 //begin testing148 //begin testing
135 for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) {149 for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) {
136 int iResult;150 int iResult;
137 int iLayerLen = 0;151 int iLayerLen = 0;
138 unsigned char* pData[3] = { NULL };152 unsigned char* pData[3] = { NULL };
139 153
140 InitialEncDec (pParam->iPicWidth, pParam->iPicHeight);154 if (!InitialEncDec (pParam->iPicWidth, pParam->iPicHeight))
141 EncodeOneFrame (0);155 return false;
156 EncodeOneFrame (0);
142 157
143 // init158 // init
144 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {159 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
145 aLen[iIdx] = 0;160 aLen[iIdx] = 0;
161 }
162 for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) {
163 iLayerLen = 0;
164 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer];
165 for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) {
166 iLayerLen += layerInfo.pNalLengthInByte[iNal];
146 }167 }
147 for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) {
148 iLayerLen = 0;
149 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer];
150 for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) {
151 iLayerLen += layerInfo.pNalLengthInByte[iNal];
152 }
153 168
154 iIdx = layerInfo.uiSpatialId;169 iIdx = layerInfo.uiSpatialId;
155 EXPECT_TRUE (iIdx < iSpatialLayerNum) << "iIdx = " << iIdx << ", iSpatialLayerNum = " << iSpatialLayerNum;170 EXPECT_TRUE (iIdx < iSpatialLayerNum) << "iIdx = " << iIdx << ", iSpatialLayerNum = " << iSpatialLayerNum;
156 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));171 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
157 aLen[iIdx] += iLayerLen;172 aLen[iIdx] += iLayerLen;
158 }173 }
159 174
160 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {175 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
161 pData[0] = pData[1] = pData[2] = 0;176 pData[0] = pData[1] = pData[2] = 0;
162 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));177 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
163 178
164 if (iSaveFileIdx > 0) {179 if (iSaveFileIdx > 0) {
165 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);180 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);
166 }181 }
167 182
168 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);183 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
169 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;184 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;
170 185
171 iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);186 iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);
172 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;187 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;
173 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx;188 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx;
174 }
175 }189 }
190 }
176 191
177 if (iSaveFileIdx > 0) {192 if (iSaveFileIdx > 0) {
178 fclose (fEnc[0]);193 fclose (fEnc[0]);
@@ -180,6 +195,7 @@ void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDec · 1 unmodified line
180 fclose (fEnc[2]);195 fclose (fEnc[2]);
181 fclose (fEnc[3]);196 fclose (fEnc[3]);
182 }197 }
198 return true;
183}199}
184 200
185long IsKeyFrameLost (ISVCDecoder* pDecoder, SLTRRecoverRequest* p_LTR_Recover_Request, long hr) {201long IsKeyFrameLost (ISVCDecoder* pDecoder, SLTRRecoverRequest* p_LTR_Recover_Request, long hr) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t