History

complete logic of simulcastavc with sps_pps_listing

Sijia Chen committed 11 years ago

Commit f9080ac1 parent a73c1e63 files · +289 −36Browse files

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

Unified · Split

test/api/encode_decode_api_test.cpp+140−5
@@ -224,6 +224,80 @@ class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase { · 223 unmodified lines
224224 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, pfEnc);
225225 }
226226 }
227+
228+ void TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, int iSpatialLayerNum,
229+ int iEncFrameNum,
230+ int iCallTimes) {
231+//#define DEBUG_FILE_SAVE4
232+ int aLen[MAX_SPATIAL_LAYER_NUM] = {0, 0, 0, 0};
233+#ifdef DEBUG_FILE_SAVE4
234+ FILE* fEnc[MAX_SPATIAL_LAYER_NUM];
235+ if (iCallTimes == 0) {
236+ fEnc[0] = fopen ("enc00.264", "wb");
237+ fEnc[1] = fopen ("enc01.264", "wb");
238+ fEnc[2] = fopen ("enc02.264", "wb");
239+ fEnc[3] = fopen ("enc03.264", "wb");
240+ } else {
241+ fEnc[0] = fopen ("enc10.264", "wb");
242+ fEnc[1] = fopen ("enc11.264", "wb");
243+ fEnc[2] = fopen ("enc12.264", "wb");
244+ fEnc[3] = fopen ("enc13.264", "wb");
245+ }
246+#endif
247+
248+ int rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, pParam);
249+ ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed pParam: rv = " << rv;
250+
251+ int iIdx;
252+ //begin testing
253+ for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) {
254+ int iResult;
255+ int iLayerLen = 0;
256+ unsigned char* pData[3] = { NULL };
257+
258+ InitialEncDec (pParam->iPicWidth, pParam->iPicHeight);
259+ EncodeOneFrame (0);
260+
261+ // init
262+ for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
263+ aLen[iIdx] = 0;
264+ }
265+ for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) {
266+ iLayerLen = 0;
267+ const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer];
268+ for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) {
269+ iLayerLen += layerInfo.pNalLengthInByte[iNal];
270+ }
271+
272+ iIdx = layerInfo.uiSpatialId;
273+ EXPECT_TRUE (iIdx < iSpatialLayerNum) << "iIdx = " << iIdx << ", iSpatialLayerNum = " << iSpatialLayerNum;
274+ memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
275+ aLen[iIdx] += iLayerLen;
276+ }
277+
278+ for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
279+ pData[0] = pData[1] = pData[2] = 0;
280+ memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
281+
282+#ifdef DEBUG_FILE_SAVE4
283+ fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);
284+#endif
285+ iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
286+ EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;
287+
288+ iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);
289+ EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;
290+ EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx;
291+ }
292+ }
293+
294+#ifdef DEBUG_FILE_SAVE4
295+ fclose (fEnc[0]);
296+ fclose (fEnc[1]);
297+ fclose (fEnc[2]);
298+ fclose (fEnc[3]);
299+#endif
300+ }
227301 };
228302
229303 class EncodeDecodeTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestAPIBase {
@@ -3194,7 +3268,7 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVC) { · 2964 unmodified lines
31943268 ASSERT_EQ (0, rv);
31953269 }
31963270
3197− iEncFrameNum = 1;
3271+ iEncFrameNum = 10;
31983272 for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) {
31993273 int iResult;
32003274 int iLayerLen = 0;
@@ -3237,8 +3311,72 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVC) { · 36 unmodified lines
32373311 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx;
32383312 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx;
32393313 }
3314+ }
32403315
3316+ for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3317+ free (pBsBuf[iIdx]);
3318+
3319+ if (decoder[iIdx] != NULL) {
3320+ decoder[iIdx]->Uninitialize();
3321+ WelsDestroyDecoder (decoder[iIdx]);
3322+ }
32413323 }
3324+}
3325+
3326+TEST_F (EncodeDecodeTestAPI, SimulcastAVC_SPS_PPS_LISTING) {
3327+ int iSpatialLayerNum = WelsClip3 ((rand() % MAX_SPATIAL_LAYER_NUM), 2, MAX_SPATIAL_LAYER_NUM);;
3328+ int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_WIDTH);
3329+ int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_HEIGHT);
3330+ float fFrameRate = rand() + 0.5f;
3331+ int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
3332+ int iSliceNum = 1;
3333+
3334+ // prepare params
3335+ SEncParamExt sParam1;
3336+ SEncParamExt sParam2;
3337+ encoder_->GetDefaultParams (&sParam1);
3338+ prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam1);
3339+ //set flag of SPS_PPS_LISTING
3340+ sParam1.eSpsPpsIdStrategy = SPS_PPS_LISTING;//SPS_LISTING;//
3341+ //set flag of bSimulcastAVC
3342+ sParam1.bSimulcastAVC = true;
3343+ //prepare param2
3344+ memcpy (&sParam2, &sParam1, sizeof (SEncParamExt));
3345+ sParam2.sSpatialLayers[0].iVideoWidth = (sParam1.sSpatialLayers[0].iVideoWidth / 2);
3346+ sParam2.sSpatialLayers[0].iVideoHeight = (sParam1.sSpatialLayers[0].iVideoHeight / 2);
3347+
3348+ int rv = encoder_->InitializeExt (&sParam1);
3349+ ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam1: rv = " << rv;;
3350+ rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
3351+ ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam2: rv = " << rv;
3352+
3353+ unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
3354+ ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
3355+
3356+ int iIdx = 0;
3357+
3358+ //create decoder
3359+ for (int iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3360+ pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
3361+ EXPECT_TRUE (pBsBuf[iIdx] != NULL);
3362+
3363+ long rv = WelsCreateDecoder (&decoder[iIdx]);
3364+ ASSERT_EQ (0, rv);
3365+ EXPECT_TRUE (decoder[iIdx] != NULL);
3366+
3367+ SDecodingParam decParam;
3368+ memset (&decParam, 0, sizeof (SDecodingParam));
3369+ decParam.eOutputColorFormat = videoFormatI420;
3370+ decParam.uiTargetDqLayer = UCHAR_MAX;
3371+ decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
3372+ decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
3373+
3374+ rv = decoder[iIdx]->Initialize (&decParam);
3375+ ASSERT_EQ (0, rv);
3376+ }
3377+
3378+ TestOneSimulcastAVC (&sParam1, decoder, pBsBuf, iSpatialLayerNum, iEncFrameNum, 0);
3379+ TestOneSimulcastAVC (&sParam2, decoder, pBsBuf, iSpatialLayerNum, iEncFrameNum, 1);
32423380
32433381 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
32443382 free (pBsBuf[iIdx]);
@@ -3247,9 +3385,7 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVC) { · 2 unmodified lines
32473385 decoder[iIdx]->Uninitialize();
32483386 WelsDestroyDecoder (decoder[iIdx]);
32493387 }
3250−#ifdef DEBUG_FILE_SAVE3
3251− fclose (fEnc[iIdx]);
3252−#endif
3388+
32533389 }
32543390 }
32553391
@@ -3399,4 +3535,3 @@ TEST_P (EncodeTestAPI, SetEncOptionSize) { · 143 unmodified lines
33993535 }
34003536 }
34013537
3402−

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