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