History

moving test cases to specific files to avoid the too long encode_decode_api_test.cpp

sijchen committed 10 years ago

Commit 46667581 parent f679da97 files · +3619 −3554Browse files

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

Unified · Split

test/api/encode_decode_api_test.cpp+9−3548
@@ -5,7 +5,6 @@ · 4 unmodified lines
5#include "BaseDecoderTest.h"5#include "BaseDecoderTest.h"
6#include "BaseEncoderTest.h"6#include "BaseEncoderTest.h"
7#include "wels_common_defs.h"7#include "wels_common_defs.h"
8#include "utils/HashFunctions.h"
9#include <string>8#include <string>
10#include <vector>9#include <vector>
11#include "encode_decode_api_test.h"10#include "encode_decode_api_test.h"
@@ -112,23 +111,21 @@ void EncodeDecodeTestAPIBase::EncDecOneFrame (const int iWidth, const int iHeigh · 100 unmodified lines
112 111
113void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, int iSpatialLayerNum,112void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, int iSpatialLayerNum,
114 int iEncFrameNum,113 int iEncFrameNum,
115 int iCallTimes) {114 int iSaveFileIdx) {
116//#define DEBUG_FILE_SAVE4
117 int aLen[MAX_SPATIAL_LAYER_NUM] = {0, 0, 0, 0};115 int aLen[MAX_SPATIAL_LAYER_NUM] = {0, 0, 0, 0};
118#ifdef DEBUG_FILE_SAVE4116
119 FILE* fEnc[MAX_SPATIAL_LAYER_NUM];117 FILE* fEnc[MAX_SPATIAL_LAYER_NUM];
120 if (iCallTimes == 0) {118 if (iSaveFileIdx == 1) {
121 fEnc[0] = fopen ("enc00.264", "wb");119 fEnc[0] = fopen ("enc00.264", "wb");
122 fEnc[1] = fopen ("enc01.264", "wb");120 fEnc[1] = fopen ("enc01.264", "wb");
123 fEnc[2] = fopen ("enc02.264", "wb");121 fEnc[2] = fopen ("enc02.264", "wb");
124 fEnc[3] = fopen ("enc03.264", "wb");122 fEnc[3] = fopen ("enc03.264", "wb");
125 } else {123 } else if (iSaveFileIdx > 1) {
126 fEnc[0] = fopen ("enc10.264", "wb");124 fEnc[0] = fopen ("enc10.264", "wb");
127 fEnc[1] = fopen ("enc11.264", "wb");125 fEnc[1] = fopen ("enc11.264", "wb");
128 fEnc[2] = fopen ("enc12.264", "wb");126 fEnc[2] = fopen ("enc12.264", "wb");
129 fEnc[3] = fopen ("enc13.264", "wb");127 fEnc[3] = fopen ("enc13.264", "wb");
130 }128 }
131#endif
132 129
133 int rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, pParam);130 int rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, pParam);
134 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed pParam: rv = " << rv;131 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed pParam: rv = " << rv;
@@ -164,9 +161,10 @@ void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDec · 29 unmodified lines
164 pData[0] = pData[1] = pData[2] = 0;161 pData[0] = pData[1] = pData[2] = 0;
165 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));162 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
166 163
167#ifdef DEBUG_FILE_SAVE4164 if (iSaveFileIdx > 0) {
168 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);165 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);
169#endif166 }
167
170 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);168 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
171 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;169 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;
172 170
@@ -176,426 +174,14 @@ void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDec · 3 unmodified lines
176 }174 }
177 }175 }
178 176
179#ifdef DEBUG_FILE_SAVE4177 if (iSaveFileIdx > 0) {
180 fclose (fEnc[0]);178 fclose (fEnc[0]);
181 fclose (fEnc[1]);179 fclose (fEnc[1]);
182 fclose (fEnc[2]);180 fclose (fEnc[2]);
183 fclose (fEnc[3]);181 fclose (fEnc[3]);
184#endif
185}
186
187void EncodeDecodeTestAPIBase::InitialEncDec (int iWidth, int iHeight) {
188
189 // for encoder
190 // I420: 1(Y) + 1/4(U) + 1/4(V)
191 int frameSize = iWidth * iHeight * 3 / 2;
192
193 buf_.SetLength (frameSize);
194 ASSERT_TRUE (buf_.Length() == (size_t)frameSize);
195
196 memset (&EncPic, 0, sizeof (SSourcePicture));
197 EncPic.iPicWidth = iWidth;
198 EncPic.iPicHeight = iHeight;
199 EncPic.iColorFormat = videoFormatI420;
200 EncPic.iStride[0] = EncPic.iPicWidth;
201 EncPic.iStride[1] = EncPic.iStride[2] = EncPic.iPicWidth >> 1;
202 EncPic.pData[0] = buf_.data();
203 EncPic.pData[1] = EncPic.pData[0] + iWidth * iHeight;
204 EncPic.pData[2] = EncPic.pData[1] + (iWidth * iHeight >> 2);
205
206 //for decoder
207 memset (&info, 0, sizeof (SFrameBSInfo));
208
209 //set a fixed random value
210 iRandValue = rand() % 256;
211}
212
213void EncodeDecodeTestAPIBase::RandomParamExtCombination() {
214
215 param_.iPicWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
216 param_.iPicHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT);
217
218 param_.fMaxFrameRate = rand() % FRAME_RATE_RANGE + 0.5f;
219 param_.iUsageType = static_cast<EUsageType> (rand() % 2);
220 param_.iTemporalLayerNum = rand() % TEMPORAL_LAYER_NUM_RANGE;
221 param_.iSpatialLayerNum = rand() % SPATIAL_LAYER_NUM_RANGE;
222
223 param_.uiIntraPeriod = rand() - 1;
224 param_.iNumRefFrame = AUTO_REF_PIC_COUNT;
225 param_.iMultipleThreadIdc = rand();
226
227 int iValue = rand() % 7;
228 switch (iValue) {
229 case 0:
230 param_.eSpsPpsIdStrategy = CONSTANT_ID;
231 break;
232 case 0x01:
233 param_.eSpsPpsIdStrategy = INCREASING_ID;
234 break;
235 case 0x02:
236 param_.eSpsPpsIdStrategy = SPS_LISTING;
237 break;
238 case 0x03:
239 param_.eSpsPpsIdStrategy = SPS_LISTING_AND_PPS_INCREASING;
240 break;
241 case 0x06:
242 param_.eSpsPpsIdStrategy = SPS_PPS_LISTING;
243 break;
244 default:
245 param_.eSpsPpsIdStrategy = CONSTANT_ID;
246 break;
247 }
248 param_.bPrefixNalAddingCtrl = (rand() % 2 == 0) ? false : true;
249 param_.bEnableSSEI = (rand() % 2 == 0) ? false : true;
250 param_.iPaddingFlag = rand() % 2;
251
252 //LTR
253 param_.bEnableLongTermReference = (rand() % 2 == 0) ? false : true;
254 param_.bIsLosslessLink = (rand() % 2 == 0) ? false : true;
255 param_.iLTRRefNum = rand();
256 param_.iLtrMarkPeriod = rand();
257
258 //loop filter
259 param_.iLoopFilterDisableIdc = rand() % 7;
260 param_.iLoopFilterAlphaC0Offset = rand();
261 param_.iLoopFilterBetaOffset = rand();
262
263 param_.bEnableDenoise = (rand() % 2 == 0) ? false : true;
264 param_.bEnableBackgroundDetection = (rand() % 2 == 0) ? false : true;
265 param_.bEnableAdaptiveQuant = (rand() % 2 == 0) ? false : true;
266 param_.bEnableFrameCroppingFlag = (rand() % 2 == 0) ? false : true;
267 param_.bEnableSceneChangeDetect = (rand() % 2 == 0) ? false : true;
268
269 //for rc
270 param_.iRCMode = static_cast<RC_MODES> (rand() % RC_MODE_RANGE - 1);
271 param_.iMaxBitrate = rand() % BIT_RATE_RANGE;
272 param_.iTargetBitrate = rand() % BIT_RATE_RANGE;
273 param_.iMaxQp = rand() % QP_RANGE;
274 param_.iMinQp = rand() % QP_RANGE;
275 param_.uiMaxNalSize = rand();
276 param_.bEnableFrameSkip = (rand() % 2 == 0) ? false : true;
277
278 for (int iSpatialIdx = 0; iSpatialIdx < param_.iSpatialLayerNum; iSpatialIdx++) {
279 if (iSpatialIdx < MAX_SPATIAL_LAYER_NUM) {
280 SSpatialLayerConfig* pSpatialLayer = &param_.sSpatialLayers[iSpatialIdx];
281
282 //to do: profile and level id
283 //pSpatialLayer->uiProfileIdc = 0;
284 //pSpatialLayer->uiLevelIdc = 0;
285 pSpatialLayer->iVideoWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
286 pSpatialLayer->iVideoHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT);
287 pSpatialLayer->fFrameRate = rand() % FRAME_RATE_RANGE + 0.5f;
288 pSpatialLayer->iMaxSpatialBitrate = rand() % BIT_RATE_RANGE;
289 pSpatialLayer->iSpatialBitrate = rand() % BIT_RATE_RANGE;
290
291
292 pSpatialLayer->sSliceArgument.uiSliceMode = static_cast<SliceModeEnum> (rand() % SLICE_MODE_NUM);
293 if (pSpatialLayer->sSliceArgument.uiSliceMode != SM_SIZELIMITED_SLICE) {
294 param_.uiMaxNalSize = 0;
295 }
296 pSpatialLayer->sSliceArgument.uiSliceNum = rand();
297 pSpatialLayer->sSliceArgument.uiSliceSizeConstraint = rand();
298 }
299 }
300}
301
302void EncodeDecodeTestAPIBase::ValidateParamExtCombination() {
303
304 bool bDynSliceModeFlag = false;
305 unsigned int uiGOPSize = 0;
306 unsigned int uiSliceNum = 0;
307 int iTotalBitRate = 0;
308 int iMinQP = 0;
309
310 param_.iPicWidth = WELS_CLIP3 (param_.iPicWidth, 2, MAX_WIDTH);
311 param_.iPicHeight = WELS_CLIP3 (param_.iPicHeight, 2, MAX_HEIGHT);
312 param_.fMaxFrameRate = WELS_CLIP3 (param_.fMaxFrameRate, MIN_FRAME_RATE, MAX_FRAME_RATE);
313 param_.iTemporalLayerNum = WELS_CLIP3 (param_.iTemporalLayerNum, 1, MAX_TEMPORAL_LAYER_NUM);
314
315 if (CAMERA_VIDEO_REAL_TIME == param_.iUsageType)
316 param_.iSpatialLayerNum = WELS_CLIP3 (param_.iSpatialLayerNum, 1, MAX_SPATIAL_LAYER_NUM);
317 else
318 param_.iSpatialLayerNum = 1;
319
320 //IntraPeriod
321 uiGOPSize = 1 << (param_.iTemporalLayerNum - 1);
322 param_.uiIntraPeriod -= param_.uiIntraPeriod % uiGOPSize;
323
324 //RefNum
325 int32_t iRefUpperBound = (param_.iUsageType == CAMERA_VIDEO_REAL_TIME) ?
326 MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA : MAX_REFERENCE_PICTURE_COUNT_NUM_SCREEN;
327 param_.iNumRefFrame = WELS_CLIP3 (param_.iNumRefFrame, MIN_REF_PIC_COUNT, iRefUpperBound);
328
329 //to do: will add more validate logic for thread number
330 param_.iMultipleThreadIdc = 1;
331
332 //LTR
333 //iLTRRefNum: not supported to set it arbitrary yet
334 if (true == param_.bEnableLongTermReference) {
335 param_.iLTRRefNum = (SCREEN_CONTENT_REAL_TIME == param_.iUsageType) ? LONG_TERM_REF_NUM_SCREEN : LONG_TERM_REF_NUM;
336 param_.iLtrMarkPeriod = (0 == param_.iLtrMarkPeriod) ? 1 : param_.iLtrMarkPeriod;
337
338 } else {
339 param_.iLTRRefNum = 0;
340 }
341
342 //loop filter
343 param_.iLoopFilterDisableIdc = param_.iLoopFilterDisableIdc % LOOP_FILTER_IDC_NUM;
344 param_.iLoopFilterAlphaC0Offset = param_.iLoopFilterAlphaC0Offset % (2 * LOOF_FILTER_OFFSET_RANGE + 1) -
345 LOOF_FILTER_OFFSET_RANGE;
346 param_.iLoopFilterBetaOffset = param_.iLoopFilterBetaOffset % (2 * LOOF_FILTER_OFFSET_RANGE + 1) -
347 LOOF_FILTER_OFFSET_RANGE;
348
349 for (int iSpatialIdx = 0; iSpatialIdx < param_.iSpatialLayerNum; iSpatialIdx++) {
350 SSpatialLayerConfig* pSpatialLayer = &param_.sSpatialLayers[iSpatialIdx];
351 pSpatialLayer->iVideoWidth = param_.iPicWidth >> (param_.iSpatialLayerNum - 1 - iSpatialIdx);
352 pSpatialLayer->iVideoHeight = param_.iPicHeight >> (param_.iSpatialLayerNum - 1 - iSpatialIdx);
353 pSpatialLayer->fFrameRate = param_.fMaxFrameRate;
354
355 pSpatialLayer->iMaxSpatialBitrate = WELS_CLIP3 (pSpatialLayer->iMaxSpatialBitrate, 1, BIT_RATE_RANGE);
356 pSpatialLayer->iSpatialBitrate = WELS_CLIP3 (pSpatialLayer->iSpatialBitrate, 1, pSpatialLayer->iMaxSpatialBitrate);
357 iTotalBitRate += pSpatialLayer->iSpatialBitrate;
358
359 uiSliceNum = pSpatialLayer->sSliceArgument.uiSliceNum;
360 pSpatialLayer->sSliceArgument.uiSliceNum = WELS_CLIP3 (uiSliceNum, 1, MAX_SLICES_NUM);
361 pSpatialLayer->sSliceArgument.uiSliceSizeConstraint = 0;
362
363
364 //for SM_FIXEDSLCNUM_SLICE
365 // to do will add this when GOM bug fixed
366 if (SM_FIXEDSLCNUM_SLICE == pSpatialLayer->sSliceArgument.uiSliceMode) {
367 pSpatialLayer->sSliceArgument.uiSliceMode = SM_SINGLE_SLICE;
368 }
369
370 //for slice mode = SM_SIZELIMITED_SLICE
371 if (SM_SIZELIMITED_SLICE == pSpatialLayer->sSliceArgument.uiSliceMode) {
372 bDynSliceModeFlag = true;
373 }
374
375 //for slice mode = SM_RASTER_SLICE
376 if (SM_RASTER_SLICE == pSpatialLayer->sSliceArgument.uiSliceMode) {
377 if (0 != pSpatialLayer->sSliceArgument.uiSliceMbNum[0]) {
378 SliceParamValidationForMode2 (iSpatialIdx);
379 } else {
380 SliceParamValidationForMode3 (iSpatialIdx);
381 }
382 }
383 }
384
385 //for RC
386 if ((RC_QUALITY_MODE == param_.iRCMode) || (RC_BITRATE_MODE == param_.iRCMode)) {
387 param_.bEnableFrameSkip = true;
388 }
389 if (param_.iTargetBitrate < iTotalBitRate) {
390 param_.iTargetBitrate = iTotalBitRate;
391 }
392 if (param_.iMaxBitrate < param_.iTargetBitrate) {
393 param_.iMaxBitrate = param_.iTargetBitrate;
394 }
395 param_.iMaxQp = WELS_CLIP3 (param_.iMaxQp, MIN_QP, MAX_QP);
396 param_.iMinQp = WELS_CLIP3 (param_.iMinQp, MIN_QP, MAX_QP);
397 iMinQP = (param_.iMaxQp < param_.iMinQp) ? param_.iMaxQp : param_.iMinQp;
398 param_.iMaxQp = (param_.iMaxQp > param_.iMinQp) ? param_.iMaxQp : param_.iMinQp;
399 param_.iMinQp = iMinQP;
400 param_.uiMaxNalSize = 0;
401
402 //for slice mode = SM_SIZELIMITED_SLICE
403 if (true == bDynSliceModeFlag) {
404 SliceParamValidationForMode4();
405 }
406
407}
408
409
410void EncodeDecodeTestAPIBase::SliceParamValidationForMode2 (int iSpatialIdx) {
411
412 unsigned int uiMbWidth = 0;
413 unsigned int uiMbHeight = 0;
414 unsigned int uiMbNumInFrame = 0;
415 unsigned int uiCountMb = 0;
416 unsigned int uiSliceIdx = 0;
417 unsigned int uiActualSliceCount = 0;
418
419 uiMbWidth = (param_.iPicWidth + 15) >> 4;
420 uiMbHeight = (param_.iPicHeight + 15) >> 4;
421 uiMbNumInFrame = uiMbWidth * uiMbHeight;
422
423 uiSliceIdx = 0;
424 while (uiSliceIdx < MAX_SLICES_NUM) {
425 param_.sSpatialLayers[iSpatialIdx].sSliceArgument.uiSliceMbNum[uiSliceIdx] = rand() % uiMbNumInFrame;
426 uiCountMb += param_.sSpatialLayers[iSpatialIdx].sSliceArgument.uiSliceMbNum[uiSliceIdx];
427 uiActualSliceCount = uiSliceIdx + 1;
428
429 if (uiCountMb >= uiMbNumInFrame) {
430 break;
431 }
432
433 ++ uiSliceIdx;
434 }
435
436 if (uiCountMb >= uiMbNumInFrame) {
437 param_.sSpatialLayers[iSpatialIdx].sSliceArgument.uiSliceMbNum[uiActualSliceCount - 1] -=
438 (uiCountMb - uiMbNumInFrame);
439
440 } else {
441 param_.sSpatialLayers[iSpatialIdx].sSliceArgument.uiSliceMbNum[uiActualSliceCount - 1 ] +=
442 (uiMbNumInFrame - uiCountMb);
443 }
444 param_.sSpatialLayers[iSpatialIdx].sSliceArgument.uiSliceNum = uiActualSliceCount;
445
446}
447void EncodeDecodeTestAPIBase::SliceParamValidationForMode3 (int iSpatialIdx) {
448
449 unsigned int uiMbHeight = 0;
450
451 uiMbHeight = (param_.iPicHeight + 15) >> 4;
452
453 //change slice mode to SM_SINGLE_SLICE
454 if (uiMbHeight > MAX_SLICES_NUM) {
455 param_.sSpatialLayers[iSpatialIdx].sSliceArgument.uiSliceMode = SM_SINGLE_SLICE;
456 }
457
458}
459
460void EncodeDecodeTestAPIBase::SliceParamValidationForMode4() {
461 //slice mode of all spatial layer should be set as SM_SIZELIMITED_SLICE
462 for (int iSpatialIdx = 0; iSpatialIdx < param_.iSpatialLayerNum; iSpatialIdx++) {
463 param_.sSpatialLayers[iSpatialIdx].sSliceArgument.uiSliceSizeConstraint = 600;
464 param_.sSpatialLayers[iSpatialIdx].sSliceArgument.uiSliceMode = SM_SIZELIMITED_SLICE;
465 }182 }
466 param_.uiMaxNalSize = 1500;
467}
468
469static const EncodeDecodeFileParamBase kFileParamArray[] = {
470 {300, 160, 96, 6.0f, 2, 1, "000000000000001010101010101010101010101001101010100000010101000011"},
471 {300, 140, 96, 6.0f, 4, 1, "000000000000001010101010101010101010101001101010100000010101000011"},
472 {300, 140, 96, 6.0f, 4, 1, "000000000000001010111010101011101010101001101010100000010101110011010101"},
473};
474
475TEST_P (EncodeDecodeTestAPI, DecoderVclNal) {
476 EncodeDecodeFileParamBase p = GetParam();
477 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
478 encoder_->Uninitialize();
479 int rv = encoder_->InitializeExt (&param_);
480 ASSERT_TRUE (rv == cmResultSuccess);
481
482 int32_t iTraceLevel = WELS_LOG_QUIET;
483 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
484 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
485
486 InitialEncDec (p.width, p.height);
487
488 int iIdx = 0;
489 while (iIdx <= p.numframes) {
490
491 EncodeOneFrame (0);
492
493 //decoding after each encoding frame
494 int vclNal, len = 0;
495 encToDecData (info, len);
496 unsigned char* pData[3] = { NULL };
497 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
498 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
499 ASSERT_TRUE (rv == cmResultSuccess);
500 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);
501 EXPECT_EQ (vclNal, FEEDBACK_UNKNOWN_NAL); //no reconstruction, unknown return
502 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
503 ASSERT_TRUE (rv == cmResultSuccess);
504 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);
505 EXPECT_EQ (vclNal, FEEDBACK_VCL_NAL);
506 iIdx++;
507 } //while
508 //ignore last frame
509}183}
510 184
511TEST_P (EncodeDecodeTestAPI, GetOptionFramenum) {
512 EncodeDecodeFileParamBase p = GetParam();
513 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
514 encoder_->Uninitialize();
515 int rv = encoder_->InitializeExt (&param_);
516 ASSERT_TRUE (rv == cmResultSuccess);
517
518 int32_t iTraceLevel = WELS_LOG_QUIET;
519 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
520 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
521
522 InitialEncDec (p.width, p.height);
523
524 int32_t iEncFrameNum = -1;
525 int32_t iDecFrameNum;
526 int iIdx = 0;
527 while (iIdx <= p.numframes) {
528 EncodeOneFrame (0);
529 //decoding after each encoding frame
530 int len = 0;
531 encToDecData (info, len);
532 unsigned char* pData[3] = { NULL };
533 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
534 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
535 ASSERT_TRUE (rv == cmResultSuccess);
536 decoder_->GetOption (DECODER_OPTION_FRAME_NUM, &iDecFrameNum);
537 EXPECT_EQ (iDecFrameNum, -1);
538 iEncFrameNum++;
539 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
540 ASSERT_TRUE (rv == cmResultSuccess);
541 decoder_->GetOption (DECODER_OPTION_FRAME_NUM, &iDecFrameNum);
542 EXPECT_EQ (iEncFrameNum, iDecFrameNum);
543 iIdx++;
544 } //while
545 //ignore last frame
546}
547
548TEST_P (EncodeDecodeTestAPI, GetOptionIDR) {
549 EncodeDecodeFileParamBase p = GetParam();
550 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
551 encoder_->Uninitialize();
552 int rv = encoder_->InitializeExt (&param_);
553 ASSERT_TRUE (rv == cmResultSuccess);
554
555 //init for encoder
556 // I420: 1(Y) + 1/4(U) + 1/4(V)
557 int32_t iTraceLevel = WELS_LOG_QUIET;
558 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
559 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
560
561 InitialEncDec (p.width, p.height);
562
563 int32_t iEncCurIdrPicId = 0;
564 int32_t iDecCurIdrPicId;
565 int32_t iIDRPeriod = 1;
566 int32_t iSpsPpsIdAddition = 0;
567 int iIdx = 0;
568 while (iIdx <= p.numframes) {
569 iSpsPpsIdAddition = rand() %
570 2; //the current strategy supports more than 2 modes, but the switch between the modes>2 is not allowed
571 iIDRPeriod = (rand() % 150) + 1;
572 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
573 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
574
575 EncodeOneFrame (0);
576
577 if (info.eFrameType == videoFrameTypeIDR) {
578 iEncCurIdrPicId = iEncCurIdrPicId + 1;
579 }
580 //decoding after each encoding frame
581 int len = 0;
582 encToDecData (info, len);
583 unsigned char* pData[3] = { NULL };
584 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
585 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
586 ASSERT_TRUE (rv == cmResultSuccess);
587 decoder_->GetOption (DECODER_OPTION_IDR_PIC_ID, &iDecCurIdrPicId);
588 EXPECT_EQ (iDecCurIdrPicId, iEncCurIdrPicId);
589 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
590 ASSERT_TRUE (rv == cmResultSuccess);
591 decoder_->GetOption (DECODER_OPTION_IDR_PIC_ID, &iDecCurIdrPicId);
592 EXPECT_EQ (iDecCurIdrPicId, iEncCurIdrPicId);
593 iIdx++;
594 } //while
595 //ignore last frame
596}
597
598
599long IsKeyFrameLost (ISVCDecoder* pDecoder, SLTRRecoverRequest* p_LTR_Recover_Request, long hr) {185long IsKeyFrameLost (ISVCDecoder* pDecoder, SLTRRecoverRequest* p_LTR_Recover_Request, long hr) {
600 long bLost = NO_RECOVERY_REQUSET;186 long bLost = NO_RECOVERY_REQUSET;
601 int tempInt = -1;187 int tempInt = -1;
@@ -787,3128 +373,3 @@ int SimulateNALLoss (const unsigned char* pSrc, int& iSrcLen, std::vector<SLost · 185 unmodified lines
787 return iSkipedBytes;373 return iSkipedBytes;
788}374}
789 375
790TEST_P (EncodeDecodeTestAPI, GetOptionLTR_ALLIDR) {
791 EncodeDecodeFileParamBase p = GetParam();
792 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
793 encoder_->Uninitialize();
794 int rv = encoder_->InitializeExt (&param_);
795 ASSERT_TRUE (rv == cmResultSuccess);
796
797 InitialEncDec (p.width, p.height);
798
799 int32_t iTraceLevel = WELS_LOG_QUIET;
800 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
801 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
802 int32_t iSpsPpsIdAddition = 1;
803 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
804 int32_t iIDRPeriod = (int32_t) pow (2.0f, (param_.iTemporalLayerNum - 1)) * ((rand() % 5) + 1);
805 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
806 SLTRConfig sLtrConfigVal;
807 sLtrConfigVal.bEnableLongTermReference = 1;
808 sLtrConfigVal.iLTRRefNum = 1;
809 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
810 int32_t iLtrPeriod = 2;
811 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
812 int iIdx = 0;
813 while (iIdx <= p.numframes) {
814 EncodeOneFrame (0);
815 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
816 encoder_->ForceIntraFrame (true);
817 iIdx++;
818 }
819}
820
821TEST_P (EncodeDecodeTestAPI, GetOptionLTR_ALLLTR) {
822 SLTRMarkingFeedback m_LTR_Marking_Feedback;
823 SLTRRecoverRequest m_LTR_Recover_Request;
824 EncodeDecodeFileParamBase p = GetParam();
825 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
826 encoder_->Uninitialize();
827 int rv = encoder_->InitializeExt (&param_);
828 ASSERT_TRUE (rv == cmResultSuccess);
829 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
830 int frameSize = p.width * p.height * 3 / 2;
831 buf_.SetLength (frameSize);
832 ASSERT_TRUE (buf_.Length() == (size_t)frameSize);
833 SFrameBSInfo info;
834 memset (&info, 0, sizeof (SFrameBSInfo));
835
836 SSourcePicture pic;
837 memset (&pic, 0, sizeof (SSourcePicture));
838 pic.iPicWidth = p.width;
839 pic.iPicHeight = p.height;
840 pic.iColorFormat = videoFormatI420;
841 pic.iStride[0] = pic.iPicWidth;
842 pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
843 pic.pData[0] = buf_.data();
844 pic.pData[1] = pic.pData[0] + p.width * p.height;
845 pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2);
846 int32_t iTraceLevel = WELS_LOG_QUIET;
847 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
848 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
849 int32_t iSpsPpsIdAddition = 1;
850 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
851 int32_t iIDRPeriod = 60;
852 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
853 SLTRConfig sLtrConfigVal;
854 sLtrConfigVal.bEnableLongTermReference = 1;
855 sLtrConfigVal.iLTRRefNum = 1;
856 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
857 int32_t iLtrPeriod = 2;
858 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
859 int iIdx = 0;
860 while (iIdx <= p.numframes) {
861 memset (buf_.data(), rand() % 256, frameSize);
862 rv = encoder_->EncodeFrame (&pic, &info);
863 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
864 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
865 }
866 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);
867 m_LTR_Recover_Request.uiFeedbackType = LTR_RECOVERY_REQUEST;
868 m_LTR_Recover_Request.iCurrentFrameNum = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
869 m_LTR_Recover_Request.uiIDRPicId = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
870 m_LTR_Recover_Request.iLastCorrectFrameNum = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
871 encoder_->SetOption (ENCODER_LTR_RECOVERY_REQUEST, &m_LTR_Recover_Request);
872 m_LTR_Marking_Feedback.uiFeedbackType = rand() % 2 == 1 ? LTR_MARKING_SUCCESS : LTR_MARKING_FAILED;
873 m_LTR_Marking_Feedback.uiIDRPicId = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
874 m_LTR_Marking_Feedback.iLTRFrameNum = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
875 encoder_->SetOption (ENCODER_LTR_MARKING_FEEDBACK, &m_LTR_Marking_Feedback);
876 iIdx++;
877 }
878}
879
880TEST_P (EncodeDecodeTestAPI, GetOptionLTR_Engine) {
881 SLTRMarkingFeedback m_LTR_Marking_Feedback;
882 SLTRRecoverRequest m_LTR_Recover_Request;
883 m_LTR_Recover_Request.uiIDRPicId = 0;
884 EncodeDecodeFileParamBase p = GetParam();
885 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
886 encoder_->Uninitialize();
887 int rv = encoder_->InitializeExt (&param_);
888 ASSERT_TRUE (rv == cmResultSuccess);
889 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
890
891 InitialEncDec (p.width, p.height);
892
893 int32_t iTraceLevel = WELS_LOG_QUIET;
894 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
895 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
896 int32_t iSpsPpsIdAddition = 1;
897 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
898 int32_t iIDRPeriod = 60;
899 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
900 SLTRConfig sLtrConfigVal;
901 sLtrConfigVal.bEnableLongTermReference = 1;
902 sLtrConfigVal.iLTRRefNum = 1;
903 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
904 int32_t iLtrPeriod = 2;
905 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
906 int iIdx = 0;
907 int iLossIdx = 0;
908 bool bVCLLoss = false;
909 while (iIdx <= p.numframes) {
910 EncodeOneFrame (1);
911 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
912 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
913 }
914 //decoding after each encoding frame
915 int len = 0;
916 encToDecData (info, len);
917 unsigned char* pData[3] = { NULL };
918 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
919 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);
920 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
921 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
922 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
923 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
924 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
925 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
926 iIdx++;
927 }
928}
929
930TEST_P (EncodeDecodeTestAPI, SetOptionECFlag_ERROR_CON_DISABLE) {
931 SLTRMarkingFeedback m_LTR_Marking_Feedback;
932 SLTRRecoverRequest m_LTR_Recover_Request;
933 m_LTR_Recover_Request.uiIDRPicId = 0;
934 EncodeDecodeFileParamBase p = GetParam();
935 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
936 param_.bEnableLongTermReference = true;
937 param_.iLTRRefNum = 1;
938 encoder_->Uninitialize();
939 int rv = encoder_->InitializeExt (&param_);
940 ASSERT_TRUE (rv == cmResultSuccess);
941 if (decoder_ != NULL) {
942 decoder_->Uninitialize();
943 }
944 SDecodingParam decParam;
945 memset (&decParam, 0, sizeof (SDecodingParam));
946 decParam.uiTargetDqLayer = UCHAR_MAX;
947 decParam.eEcActiveIdc = ERROR_CON_DISABLE;
948 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
949 rv = decoder_->Initialize (&decParam);
950 ASSERT_EQ (0, rv);
951 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
952
953 InitialEncDec (p.width, p.height);
954 int32_t iTraceLevel = WELS_LOG_QUIET;
955 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
956 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
957 int32_t iSpsPpsIdAddition = 1;
958 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
959 int32_t iIDRPeriod = 60;
960 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
961 SLTRConfig sLtrConfigVal;
962 sLtrConfigVal.bEnableLongTermReference = 1;
963 sLtrConfigVal.iLTRRefNum = 1;
964 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
965 int32_t iLtrPeriod = 2;
966 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
967 int iIdx = 0;
968 int iLossIdx = 0;
969 int iSkipedBytes;
970 bool bVCLLoss = false;
971 while (iIdx <= p.numframes) {
972 EncodeOneFrame (1);
973 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
974 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
975 }
976 //decoding after each encoding frame
977 int len = 0;
978 encToDecData (info, len);
979 unsigned char* pData[3] = { NULL };
980 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
981 iSkipedBytes = SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx,
982 bVCLLoss);
983 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
984 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
985 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
986 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
987 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
988 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
989 if (iSkipedBytes && bVCLLoss) {
990 ASSERT_TRUE (dstBufInfo_.iBufferStatus == 0);
991 }
992 iIdx++;
993 }
994}
995
996TEST_P (EncodeDecodeTestAPI, SetOptionECFlag_ERROR_CON_SLICE_COPY) {
997 SLTRMarkingFeedback m_LTR_Marking_Feedback;
998 SLTRRecoverRequest m_LTR_Recover_Request;
999 m_LTR_Recover_Request.uiIDRPicId = 0;
1000 EncodeDecodeFileParamBase p = GetParam();
1001 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
1002 encoder_->Uninitialize();
1003 int rv = encoder_->InitializeExt (&param_);
1004 ASSERT_TRUE (rv == cmResultSuccess);
1005 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1006
1007 InitialEncDec (p.width, p.height);
1008 int32_t iTraceLevel = WELS_LOG_QUIET;
1009 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1010 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1011 int32_t iSpsPpsIdAddition = 1;
1012 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
1013 int32_t iIDRPeriod = 60;
1014 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
1015 SLTRConfig sLtrConfigVal;
1016 sLtrConfigVal.bEnableLongTermReference = 1;
1017 sLtrConfigVal.iLTRRefNum = 1;
1018 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
1019 int32_t iLtrPeriod = 2;
1020 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
1021 int iIdx = 0;
1022 int iLossIdx = 0;
1023 int iSkipedBytes;
1024 bool bVCLLoss = false;
1025 while (iIdx <= p.numframes) {
1026 EncodeOneFrame (1);
1027 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
1028 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
1029 }
1030 //decoding after each encoding frame
1031 int len = 0;
1032 encToDecData (info, len);
1033 unsigned char* pData[3] = { NULL };
1034 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1035 iSkipedBytes = SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx,
1036 bVCLLoss);
1037 uint32_t uiEcIdc = rand() % 2 == 1 ? ERROR_CON_DISABLE : ERROR_CON_SLICE_COPY;
1038 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1039 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1040 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1041 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1042 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1043 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1044 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
1045 iIdx++;
1046 }
1047 (void) iSkipedBytes;
1048}
1049
1050TEST_P (EncodeDecodeTestAPI, InOutTimeStamp) {
1051 EncodeDecodeFileParamBase p = GetParam();
1052 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
1053 encoder_->Uninitialize();
1054 int rv = encoder_->InitializeExt (&param_);
1055 ASSERT_TRUE (rv == cmResultSuccess);
1056
1057 InitialEncDec (p.width, p.height);
1058 int32_t iTraceLevel = WELS_LOG_QUIET;
1059 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1060 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1061 int32_t iSpsPpsIdAddition = 1;
1062 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
1063 int32_t iIDRPeriod = 60;
1064 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
1065 SLTRConfig sLtrConfigVal;
1066 sLtrConfigVal.bEnableLongTermReference = 1;
1067 sLtrConfigVal.iLTRRefNum = 1;
1068 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
1069 int32_t iLtrPeriod = 2;
1070 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
1071 int iIdx = 0;
1072 int iSkipedBytes;
1073 unsigned long long uiEncTimeStamp = 100;
1074 while (iIdx <= p.numframes) {
1075 EncodeOneFrame (1);
1076 //decoding after each encoding frame
1077 int len = 0;
1078 encToDecData (info, len);
1079 unsigned char* pData[3] = { NULL };
1080 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1081 uint32_t uiEcIdc = ERROR_CON_SLICE_COPY_CROSS_IDR_FREEZE_RES_CHANGE;
1082 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1083 dstBufInfo_.uiInBsTimeStamp = uiEncTimeStamp;
1084 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1085 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1086 dstBufInfo_.uiInBsTimeStamp = uiEncTimeStamp;
1087 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1088 if (dstBufInfo_.iBufferStatus == 1) {
1089 EXPECT_EQ (uiEncTimeStamp, dstBufInfo_.uiOutYuvTimeStamp);
1090 }
1091 iIdx++;
1092 uiEncTimeStamp++;
1093 }
1094 (void) iSkipedBytes;
1095}
1096
1097TEST_P (EncodeDecodeTestAPI, GetOptionTid_AVC_NOPREFIX) {
1098 SLTRMarkingFeedback m_LTR_Marking_Feedback;
1099 SLTRRecoverRequest m_LTR_Recover_Request;
1100 m_LTR_Recover_Request.uiIDRPicId = 0;
1101 EncodeDecodeFileParamBase p = GetParam();
1102 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
1103 param_.bPrefixNalAddingCtrl = false;
1104 param_.iTemporalLayerNum = (rand() % 4) + 1;
1105 encoder_->Uninitialize();
1106 int rv = encoder_->InitializeExt (&param_);
1107 ASSERT_TRUE (rv == cmResultSuccess);
1108 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1109 InitialEncDec (p.width, p.height);
1110 int32_t iTraceLevel = WELS_LOG_QUIET;
1111 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1112 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1113 int32_t iSpsPpsIdAddition = 1;
1114 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
1115 int32_t iIDRPeriod = 60;
1116 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
1117 SLTRConfig sLtrConfigVal;
1118 sLtrConfigVal.bEnableLongTermReference = 1;
1119 sLtrConfigVal.iLTRRefNum = 1;
1120 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
1121 int32_t iLtrPeriod = 2;
1122 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
1123 int iIdx = 0;
1124 int iLossIdx = 0;
1125 bool bVCLLoss = false;
1126 while (iIdx <= p.numframes) {
1127 EncodeOneFrame (1);
1128 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
1129 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
1130 }
1131 //decoding after each encoding frame
1132 int len = 0;
1133 encToDecData (info, len);
1134 unsigned char* pData[3] = { NULL };
1135 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1136 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);
1137 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1138 int iTid = -1;
1139 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
1140 if (iTid != -1) {
1141 ASSERT_EQ (iTid, 0);
1142 }
1143 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1144 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1145 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1146 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
1147 std::vector<SLostSim>::iterator iter = m_SLostSim.begin();
1148 bool bHasVCL = false;
1149 for (unsigned int k = 0; k < m_SLostSim.size(); k++) {
1150 if (IS_VCL_NAL (iter->eNalType, 0) && iter->isLost == false) {
1151 bHasVCL = true;
1152 break;
1153 }
1154 iter++;
1155 }
1156 (void) bHasVCL;
1157 if (iTid != -1) {
1158 ASSERT_EQ (iTid, 0);
1159 }
1160 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1161 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
1162 iIdx++;
1163 }
1164}
1165
1166TEST_P (EncodeDecodeTestAPI, GetOptionTid_AVC_WITH_PREFIX_NOLOSS) {
1167 SLTRMarkingFeedback m_LTR_Marking_Feedback;
1168 SLTRRecoverRequest m_LTR_Recover_Request;
1169 m_LTR_Recover_Request.uiIDRPicId = 0;
1170 EncodeDecodeFileParamBase p = GetParam();
1171 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
1172 param_.bPrefixNalAddingCtrl = true;
1173 param_.iTemporalLayerNum = (rand() % 4) + 1;
1174 param_.iSpatialLayerNum = 1;
1175 encoder_->Uninitialize();
1176 int rv = encoder_->InitializeExt (&param_);
1177 ASSERT_TRUE (rv == cmResultSuccess);
1178 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1179
1180 InitialEncDec (p.width, p.height);
1181 int32_t iTraceLevel = WELS_LOG_QUIET;
1182 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1183 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1184 int32_t iSpsPpsIdAddition = 1;
1185 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
1186 int32_t iIDRPeriod = 60;
1187 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
1188 SLTRConfig sLtrConfigVal;
1189 sLtrConfigVal.bEnableLongTermReference = 1;
1190 sLtrConfigVal.iLTRRefNum = 1;
1191 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
1192 int32_t iLtrPeriod = 2;
1193 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
1194 int iIdx = 0;
1195 while (iIdx <= p.numframes) {
1196 EncodeOneFrame (1);
1197 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
1198 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
1199 }
1200 //decoding after each encoding frame
1201 int len = 0;
1202 encToDecData (info, len);
1203 unsigned char* pData[3] = { NULL };
1204 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1205 ExtractDidNal (&info, len, &m_SLostSim, 0);
1206 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1207 int iTid = -1;
1208 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
1209 ASSERT_EQ (iTid, -1);
1210 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1211 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1212 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1213 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
1214 ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId);
1215 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1216 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
1217 iIdx++;
1218 }
1219}
1220
1221TEST_P (EncodeDecodeTestAPI, GetOptionTid_SVC_L1_NOLOSS) {
1222 SLTRMarkingFeedback m_LTR_Marking_Feedback;
1223 SLTRRecoverRequest m_LTR_Recover_Request;
1224 m_LTR_Recover_Request.uiIDRPicId = 0;
1225 EncodeDecodeFileParamBase p = GetParam();
1226 prepareParamDefault (2, p.slicenum, p.width, p.height, p.frameRate, &param_);
1227 param_.iTemporalLayerNum = (rand() % 4) + 1;
1228 param_.iSpatialLayerNum = 2;
1229 encoder_->Uninitialize();
1230 int rv = encoder_->InitializeExt (&param_);
1231 ASSERT_TRUE (rv == cmResultSuccess);
1232 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1233
1234 InitialEncDec (p.width, p.height);
1235 int32_t iTraceLevel = WELS_LOG_QUIET;
1236 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1237 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1238 int32_t iSpsPpsIdAddition = 1;
1239 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
1240 int32_t iIDRPeriod = 60;
1241 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
1242 SLTRConfig sLtrConfigVal;
1243 sLtrConfigVal.bEnableLongTermReference = 1;
1244 sLtrConfigVal.iLTRRefNum = 1;
1245 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
1246 int32_t iLtrPeriod = 2;
1247 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
1248 int iIdx = 0;
1249 while (iIdx <= p.numframes) {
1250 EncodeOneFrame (1);
1251 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
1252 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
1253 }
1254 //decoding after each encoding frame
1255 int len = 0;
1256 encToDecData (info, len);
1257 unsigned char* pData[3] = { NULL };
1258 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1259 ExtractDidNal (&info, len, &m_SLostSim, 1);
1260 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1261 int iTid = -1;
1262 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
1263 ASSERT_EQ (iTid, -1);
1264 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1265 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1266 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1267 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
1268 ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId);
1269 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1270 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
1271 iIdx++;
1272 }
1273}
1274
1275
1276
1277TEST_P (EncodeDecodeTestAPI, SetOption_Trace) {
1278 SLTRMarkingFeedback m_LTR_Marking_Feedback;
1279 SLTRRecoverRequest m_LTR_Recover_Request;
1280 m_LTR_Recover_Request.uiIDRPicId = 0;
1281 EncodeDecodeFileParamBase p = GetParam();
1282 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
1283 param_.iSpatialLayerNum = 1;
1284
1285 int rv = encoder_->InitializeExt (&param_);
1286 ASSERT_TRUE (rv == cmResultSuccess);
1287 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1288
1289 InitialEncDec (p.width, p.height);
1290 int32_t iTraceLevel = WELS_LOG_QUIET;
1291 pFunc = TestOutPutTrace;
1292 pTraceInfo = &sTrace;
1293 sTrace.iTarLevel = iTraceLevel;
1294 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1295 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1296 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK, &pFunc);
1297 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
1298 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK, &pFunc);
1299 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
1300
1301
1302 int32_t iSpsPpsIdAddition = 1;
1303 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
1304 int32_t iIDRPeriod = 60;
1305 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
1306 SLTRConfig sLtrConfigVal;
1307 sLtrConfigVal.bEnableLongTermReference = 1;
1308 sLtrConfigVal.iLTRRefNum = 1;
1309 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
1310 int32_t iLtrPeriod = 2;
1311 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
1312 int iIdx = 0;
1313 int iLossIdx = 0;
1314 bool bVCLLoss = false;
1315 while (iIdx <= p.numframes) {
1316 iTraceLevel = rand() % 33;
1317 sTrace.iTarLevel = iTraceLevel;
1318 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1319 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1320 EncodeOneFrame (1);
1321 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
1322 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
1323 }
1324 //decoding after each encoding frame
1325 int len = 0;
1326 encToDecData (info, len);
1327 unsigned char* pData[3] = { NULL };
1328 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1329 ExtractDidNal (&info, len, &m_SLostSim, 0);
1330 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);
1331 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1332 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1333 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1334 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1335 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1336 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
1337 iIdx++;
1338 }
1339}
1340
1341TEST_P (EncodeDecodeTestAPI, SetOption_Trace_NULL) {
1342 SLTRMarkingFeedback m_LTR_Marking_Feedback;
1343 SLTRRecoverRequest m_LTR_Recover_Request;
1344 m_LTR_Recover_Request.uiIDRPicId = 0;
1345 EncodeDecodeFileParamBase p = GetParam();
1346 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
1347 param_.iSpatialLayerNum = 1;
1348 int rv = encoder_->InitializeExt (&param_);
1349 ASSERT_TRUE (rv == cmResultSuccess);
1350 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1351
1352 InitialEncDec (p.width, p.height);
1353
1354 int32_t iTraceLevel = WELS_LOG_QUIET;
1355 pFunc = NULL;
1356 pTraceInfo = NULL;
1357 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK, &pFunc);
1358 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
1359 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK, &pFunc);
1360 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
1361 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1362 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1363
1364 int32_t iSpsPpsIdAddition = 1;
1365 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
1366 int32_t iIDRPeriod = 60;
1367 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
1368 SLTRConfig sLtrConfigVal;
1369 sLtrConfigVal.bEnableLongTermReference = 1;
1370 sLtrConfigVal.iLTRRefNum = 1;
1371 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
1372 int32_t iLtrPeriod = 2;
1373 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
1374 int iIdx = 0;
1375 int iLossIdx = 0;
1376 bool bVCLLoss = false;
1377 while (iIdx <= p.numframes) {
1378 iTraceLevel = rand() % 33;
1379 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1380 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1381 EncodeOneFrame (1);
1382 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
1383 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
1384 }
1385 //decoding after each encoding frame
1386 int len = 0;
1387 encToDecData (info, len);
1388 unsigned char* pData[3] = { NULL };
1389 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1390 ExtractDidNal (&info, len, &m_SLostSim, 0);
1391 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);
1392 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1393 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1394 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1395 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1396 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1397 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
1398 iIdx++;
1399 }
1400}
1401
1402INSTANTIATE_TEST_CASE_P (EncodeDecodeTestAPIBase, EncodeDecodeTestAPI,
1403 ::testing::ValuesIn (kFileParamArray));
1404
1405TEST_P (EncodeDecodeTestAPI, SetOptionECIDC_GeneralSliceChange) {
1406 uint32_t uiEcIdc;
1407 uint32_t uiGet;
1408 EncodeDecodeFileParamBase p = GetParam();
1409 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
1410 param_.iSpatialLayerNum = 1;
1411 encoder_->Uninitialize();
1412 int rv = encoder_->InitializeExt (&param_);
1413 ASSERT_TRUE (rv == cmResultSuccess);
1414 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1415 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY
1416
1417 uiEcIdc = 0;
1418 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1419 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1420 EXPECT_EQ (uiGet, uiEcIdc);
1421
1422 //Start for enc/dec
1423
1424 InitialEncDec (p.width, p.height);
1425 int32_t iTraceLevel = WELS_LOG_QUIET;
1426 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1427 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1428 int iIdx = 0;
1429 bool bVCLLoss = false;
1430 int iPacketNum;
1431 int len;
1432 int iTotalSliceSize;
1433
1434 //enc/dec pictures
1435 while (iIdx <= p.numframes) {
1436 EncodeOneFrame (1);
1437 //decoding after each encoding frame
1438 len = 0;
1439 iPacketNum = 0;
1440 iTotalSliceSize = 0;
1441 unsigned char* pData[3] = { NULL };
1442 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1443 while (iPacketNum < info.sLayerInfo[0].iNalCount) {
1444 encToDecSliceData (0, iPacketNum, info, len);
1445 uiEcIdc = (ERROR_CON_IDC) (rand() % 2);
1446 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1447 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1448 EXPECT_EQ (uiGet, uiEcIdc);
1449
1450 bVCLLoss = rand() & 1; //loss or not
1451 if (!bVCLLoss) { //not loss
1452 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf + iTotalSliceSize,
1453 info.sLayerInfo[0].pNalLengthInByte[iPacketNum], pData, &dstBufInfo_);
1454 if (uiEcIdc == ERROR_CON_DISABLE)
1455 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0);
1456 }
1457 //EC_IDC should not change till now
1458 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1459 EXPECT_EQ (uiGet, uiEcIdc);
1460 //Set again inside
1461 uiEcIdc = (ERROR_CON_IDC) (rand() % 2);
1462 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1463 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1464 EXPECT_EQ (uiGet, uiEcIdc);
1465
1466 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1467 //EXPECT_EQ (dstBufInfo_.iBufferStatus, 0);
1468 if (uiEcIdc == ERROR_CON_DISABLE && rv != 0)
1469 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0);
1470
1471 //deal with next slice
1472 iTotalSliceSize += len;
1473 iPacketNum++;
1474 } //while slice
1475 iIdx++;
1476 } //while frame
1477}
1478
1479//This case contain 1 slice per picture
1480//coding order: 0 1 2 3 4 5 6 7
1481//frame type: IDR P P P P P P P
1482//EC_IDC: 0 0 0 2 0 0 1 1
1483//loss: N Y N N N Y Y N
1484
1485TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificFrameChange) {
1486 uint32_t uiEcIdc;
1487 uint32_t uiGet;
1488 EncodeDecodeFileParamBase p = kFileParamArray[0];
1489 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
1490
1491 param_.iSpatialLayerNum = 1;
1492 encoder_->Uninitialize();
1493 int rv = encoder_->InitializeExt (&param_);
1494 ASSERT_TRUE (rv == cmResultSuccess);
1495 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1496 EXPECT_EQ (uiGet, (ERROR_CON_IDC) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY
1497 int32_t iTraceLevel = WELS_LOG_QUIET;
1498 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1499 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1500
1501 //set EC=DISABLE
1502 uiEcIdc = (uint32_t) (ERROR_CON_DISABLE);
1503 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1504 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1505 EXPECT_EQ (uiGet, uiEcIdc);
1506
1507 //Start for enc/dec
1508 int iIdx = 0;
1509 int len = 0;
1510 unsigned char* pData[3] = { NULL };
1511 InitialEncDec (p.width, p.height);
1512 //Frame 0: IDR, EC_IDC=DISABLE, loss = 0
1513 EncodeOneFrame (1);
1514 encToDecData (info, len);
1515 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1516 EXPECT_EQ (uiGet, (ERROR_CON_IDC) ERROR_CON_DISABLE);
1517 pData[0] = pData[1] = pData[2] = 0;
1518 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1519 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1520 EXPECT_EQ (rv, 0);
1521 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0);
1522 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1523 EXPECT_EQ (rv, 0);
1524 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1);
1525 iIdx++;
1526
1527 //Frame 1: P, EC_IDC=DISABLE, loss = 1
1528 EncodeOneFrame (1);
1529 iIdx++;
1530
1531 //Frame 2: P, EC_IDC=DISABLE, loss = 0
1532 EncodeOneFrame (1);
1533 encToDecData (info, len);
1534 pData[0] = pData[1] = pData[2] = 0;
1535 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1536 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1537 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
1538 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1539 EXPECT_EQ (rv, 0); //parse correct
1540 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output
1541 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1542 EXPECT_TRUE (rv != 0); //construction error due to data loss
1543 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output due to EC DISABLE
1544 iIdx++;
1545
1546 //set EC=SLICE_COPY
1547 uiEcIdc = (uint32_t) (ERROR_CON_SLICE_COPY);
1548 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1549 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1550 EXPECT_EQ (uiGet, uiEcIdc);
1551 //Frame 3: P, EC_IDC=SLICE_COPY, loss = 0
1552 EncodeOneFrame (1);
1553 encToDecData (info, len);
1554 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1555 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY);
1556 pData[0] = pData[1] = pData[2] = 0;
1557 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1558 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1559 EXPECT_EQ (rv, 0); //parse correct
1560 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output
1561 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1562 EXPECT_TRUE (rv != 0); //construction error due to data loss
1563 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1);
1564 iIdx++;
1565
1566 //set EC=DISABLE
1567 uiEcIdc = (uint32_t) (ERROR_CON_DISABLE);
1568 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1569 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1570 EXPECT_EQ (uiGet, uiEcIdc);
1571 //Frame 4: P, EC_IDC=DISABLE, loss = 0
1572 EncodeOneFrame (1);
1573 encToDecData (info, len);
1574 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1575 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
1576 pData[0] = pData[1] = pData[2] = 0;
1577 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1578 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1579 EXPECT_EQ (rv, 0); //parse correct
1580 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output
1581 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1582 //Ref picture is ECed, so current status is ECed, when EC disable, NO output
1583 EXPECT_TRUE (rv != 0);
1584 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0);
1585 iIdx++;
1586
1587 //Frame 5: P, EC_IDC=DISABLE, loss = 1
1588 EncodeOneFrame (1);
1589 iIdx++;
1590
1591 //set EC=FRAME_COPY
1592 uiEcIdc = (uint32_t) (ERROR_CON_FRAME_COPY);
1593 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1594 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1595 EXPECT_EQ (uiGet, uiEcIdc);
1596 //Frame 6: P, EC_IDC=FRAME_COPY, loss = 1
1597 EncodeOneFrame (1);
1598 EXPECT_EQ (uiGet, uiEcIdc);
1599 iIdx++;
1600
1601 //Frame 7: P, EC_IDC=FRAME_COPY, loss = 0
1602 EncodeOneFrame (1);
1603 encToDecData (info, len);
1604 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1605 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_FRAME_COPY);
1606 pData[0] = pData[1] = pData[2] = 0;
1607 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1608 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1609 EXPECT_TRUE (rv == 0); // Now the parse process is Error_None, and the reconstruction will has error return
1610 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output
1611 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1612 EXPECT_TRUE (rv != 0); //not sure if previous data drop would be detected in construction
1613 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1);
1614 iIdx++;
1615}
1616
1617//This case contain 2 slices per picture for IDR loss
1618//coding order: 0 1 2 3 4
1619//frame type IDR P P P P
1620//EC_IDC 2 2 0 1 0
1621//loss (2 slice: 1,2): 2 0 0 1 0
1622
1623TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificSliceChange_IDRLoss) {
1624 uint32_t uiEcIdc = 2; //default set as SLICE_COPY
1625 uint32_t uiGet;
1626 EncodeDecodeFileParamBase p = kFileParamArray[0];
1627 prepareParamDefault (1, 2, p.width, p.height, p.frameRate, &param_);
1628 param_.iSpatialLayerNum = 1;
1629 encoder_->Uninitialize();
1630 int rv = encoder_->InitializeExt (&param_);
1631 ASSERT_TRUE (rv == cmResultSuccess);
1632 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1633 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1634 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY
1635 int32_t iTraceLevel = WELS_LOG_QUIET;
1636 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1637 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1638
1639 //Start for enc/dec
1640 int iIdx = 0;
1641 int len = 0;
1642 unsigned char* pData[3] = { NULL };
1643 int iTotalSliceSize = 0;
1644
1645 InitialEncDec (p.width, p.height);
1646
1647 //Frame 0: IDR, EC_IDC=2, loss = 2
1648 EncodeOneFrame (1);
1649 iTotalSliceSize = 0;
1650 encToDecSliceData (0, 0, info, len); //SPS
1651 iTotalSliceSize = len;
1652 encToDecSliceData (0, 1, info, len); //PPS
1653 iTotalSliceSize += len;
1654 encToDecSliceData (1, 0, info, len); //first slice
1655 iTotalSliceSize += len;
1656 //second slice loss
1657 pData[0] = pData[1] = pData[2] = 0;
1658 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1659 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1660 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY);
1661 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, iTotalSliceSize, pData, &dstBufInfo_);
1662 EXPECT_EQ (rv, 0); //parse correct
1663 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1664 EXPECT_EQ (rv, 0); // Reconstruct first slice OK
1665 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //slice incomplete, no output
1666 iIdx++;
1667
1668 //Frame 1: P, EC_IDC=2, loss = 0
1669 //will clean SPS/PPS status
1670 EncodeOneFrame (1);
1671 encToDecData (info, len); //all slice together
1672 pData[0] = pData[1] = pData[2] = 0;
1673 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1674 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1675 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY);
1676 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1677 EXPECT_TRUE ((rv & 32) != 0); //parse correct, but reconstruct ECed
1678 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //ECed output for frame 0
1679 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //ECed status, reconstruction current frame 1
1680 EXPECT_TRUE ((rv & 32) != 0); //decoder ECed status
1681 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //ECed output for frame 1
1682 iIdx++;
1683
1684 //set EC=DISABLE
1685 uiEcIdc = (uint32_t) (ERROR_CON_DISABLE);
1686 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1687 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1688 EXPECT_EQ (uiGet, uiEcIdc);
1689 //Frame 2: P, EC_IDC=0, loss = 0
1690 /////will clean SPS/PPS status
1691 EncodeOneFrame (1);
1692 encToDecData (info, len); //all slice together
1693 pData[0] = pData[1] = pData[2] = 0;
1694 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1695 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1696 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
1697 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1698 EXPECT_EQ (rv, 0); //parse correct
1699 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1700 // Ref picture is ECed, so reconstructed picture is ECed
1701 EXPECT_TRUE ((rv & 32) != 0);
1702 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0);
1703 iIdx++;
1704
1705 //set EC=SLICE_COPY
1706 uiEcIdc = (uint32_t) (ERROR_CON_FRAME_COPY);
1707 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1708 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1709 EXPECT_EQ (uiGet, uiEcIdc);
1710 //Frame 3: P, EC_IDC=2, loss = 1
1711 EncodeOneFrame (1);
1712 encToDecSliceData (0, 0, info, iTotalSliceSize); //slice 1 lost
1713 encToDecSliceData (0, 1, info, len); //slice 2
1714 pData[0] = pData[1] = pData[2] = 0;
1715 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1716 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1717 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_FRAME_COPY);
1718 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, len, pData, &dstBufInfo_);
1719 EXPECT_EQ (rv, 0); //parse correct
1720 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0);
1721 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1722 EXPECT_TRUE ((rv & 32) != 0);
1723 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //slice loss
1724 iIdx++;
1725
1726 //set EC=DISABLE
1727 uiEcIdc = (uint32_t) (ERROR_CON_DISABLE);
1728 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1729 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1730 EXPECT_EQ (uiGet, uiEcIdc);
1731 //Frame 4: P, EC_IDC=0, loss = 0
1732 EncodeOneFrame (1);
1733 encToDecData (info, len); //all slice
1734 pData[0] = pData[1] = pData[2] = 0;
1735 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1736 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1737 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
1738 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1739 EXPECT_TRUE (rv != 0);
1740 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); // EC_IDC=0, previous picture slice lost, no output
1741 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1742 EXPECT_TRUE (rv != 0);
1743 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); // No ref picture, no output
1744 iIdx++;
1745
1746}
1747
1748
1749
1750//This case contain 2 slices per picture for no IDR loss
1751//coding order: 0 1 2 3 4 5
1752//frame type IDR P P P P IDR
1753//EC_IDC 0 2 0 2 0 ^2^
1754//loss (2 slice: 1,2): 0 0 1 2 0 0
1755
1756TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificSliceChange_IDRNoLoss) {
1757 uint32_t uiEcIdc;
1758 uint32_t uiGet;
1759 EncodeDecodeFileParamBase p = kFileParamArray[0];
1760 prepareParamDefault (1, 2, p.width, p.height, p.frameRate, &param_);
1761 param_.iSpatialLayerNum = 1;
1762 encoder_->Uninitialize();
1763 int rv = encoder_->InitializeExt (&param_);
1764 ASSERT_TRUE (rv == cmResultSuccess);
1765 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1766 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY
1767 int32_t iTraceLevel = WELS_LOG_QUIET;
1768 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1769 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1770
1771 //Start for enc/dec
1772 int iIdx = 0;
1773 int len = 0;
1774 unsigned char* pData[3] = { NULL };
1775 int iTotalSliceSize = 0;
1776
1777 InitialEncDec (p.width, p.height);
1778
1779 //set EC=DISABLE
1780 uiEcIdc = (uint32_t) (ERROR_CON_DISABLE);
1781 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1782 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1783 EXPECT_EQ (uiGet, uiEcIdc);
1784 //Frame 0: IDR, EC_IDC=0, loss = 0
1785 //Expected result: all OK, 2nd Output
1786 EncodeOneFrame (1);
1787 encToDecData (info, len); //all slice
1788 pData[0] = pData[1] = pData[2] = 0;
1789 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1790 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1791 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
1792 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1793 EXPECT_EQ (rv, 0); //parse correct
1794 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1795 EXPECT_EQ (rv, 0); //parse correct
1796 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //output frame 0
1797 iIdx++;
1798
1799 //Frame 1: P, EC_IDC=0, loss = 0
1800 //Expected result: all OK, 2nd Output
1801 EncodeOneFrame (1);
1802 encToDecData (info, len); //all slice together
1803 pData[0] = pData[1] = pData[2] = 0;
1804 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1805 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1806 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
1807 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1808 EXPECT_EQ (rv, 0); //parse correct
1809 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //ECed output for frame 0
1810 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction current frame 1
1811 EXPECT_EQ (rv, 0); //parse correct
1812 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //ECed output for frame 1
1813 iIdx++;
1814
1815 //Frame 2: P, EC_IDC=0, loss = 1
1816 //Expected result: all OK, no Output
1817 EncodeOneFrame (1);
1818 encToDecSliceData (0, 0, info, iTotalSliceSize); // slice 1 lost
1819 encToDecSliceData (0, 1, info, len); // slice 2 only
1820 pData[0] = pData[1] = pData[2] = 0;
1821 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1822 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1823 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
1824 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, len, pData, &dstBufInfo_);
1825 EXPECT_EQ (rv, 0); //parse correct
1826 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0);
1827 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1828 EXPECT_EQ (rv, 0); //parse correct
1829 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0);
1830 iIdx++;
1831
1832 //set EC=SLICE_COPY
1833 uiEcIdc = (uint32_t) (ERROR_CON_SLICE_COPY);
1834 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1835 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1836 EXPECT_EQ (uiGet, uiEcIdc);
1837 //Frame 3: P, EC_IDC=2, loss = 2
1838 //Expected result: neither OK, 1st Output
1839 EncodeOneFrame (1);
1840 encToDecSliceData (0, 0, info, len); //slice 1 only
1841 pData[0] = pData[1] = pData[2] = 0;
1842 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1843 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1844 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY);
1845 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1846 EXPECT_TRUE ((rv & 32) != 0); //parse OK but frame 2 ECed
1847 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //slice loss but ECed output Frame 2
1848 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1849 EXPECT_TRUE ((rv & 32) != 0);
1850 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //slice loss
1851 iIdx++;
1852
1853 //set EC=DISABLE
1854 uiEcIdc = (uint32_t) (ERROR_CON_DISABLE);
1855 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1856 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1857 EXPECT_EQ (uiGet, uiEcIdc);
1858 //Frame 4: P, EC_IDC=0, loss = 0
1859 //Expected result: depends on DecodeFrame2 result. If OK, output; else ,no output
1860 EncodeOneFrame (1);
1861 encToDecData (info, len); //all slice
1862 pData[0] = pData[1] = pData[2] = 0;
1863 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1864 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1865 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
1866 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1867 EXPECT_TRUE (rv != 0); //previous slice not outputted, will return error due to incomplete frame
1868 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //output previous pic
1869 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction,
1870 // previous frame NOT output, no ref
1871 EXPECT_TRUE (rv != 0);
1872 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //output previous pic
1873 iIdx++;
1874
1875 //Frame 5: IDR, EC_IDC=2->0, loss = 0
1876 //Expected result: depends on DecodeFrame2 result. If OK, output; else ,no output
1877 int32_t iIDRPeriod = 1;
1878 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
1879 EncodeOneFrame (1);
1880 EXPECT_TRUE (info.eFrameType == videoFrameTypeIDR);
1881 encToDecSliceData (0, 0, info, len); //SPS
1882 iTotalSliceSize = len;
1883 encToDecSliceData (0, 1, info, len); //PPS
1884 iTotalSliceSize += len;
1885 encToDecSliceData (1, 0, info, len); //slice 1
1886 iTotalSliceSize += len;
1887 //set EC=SLICE_COPY for slice 1
1888 uiEcIdc = (uint32_t) (ERROR_CON_SLICE_COPY);
1889 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1890 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1891 EXPECT_EQ (uiGet, uiEcIdc);
1892 pData[0] = pData[1] = pData[2] = 0;
1893 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1894 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, iTotalSliceSize, pData, &dstBufInfo_);
1895 EXPECT_TRUE (rv == 0); // IDR status return error_free
1896 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //frame incomplete
1897 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction,
1898 EXPECT_TRUE (rv == 0);
1899 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //output previous pic
1900 //set EC=DISABLE for slice 2
1901 encToDecSliceData (1, 1, info, len); //slice 1
1902 uiEcIdc = (int) (ERROR_CON_DISABLE);
1903 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
1904 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1905 EXPECT_EQ (uiGet, uiEcIdc);
1906 pData[0] = pData[1] = pData[2] = 0;
1907 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1908 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, len, pData, &dstBufInfo_);
1909 EXPECT_EQ (rv, 0); //Parse correct under no EC
1910 EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //frame incomplete
1911 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction,
1912 EXPECT_EQ (rv, 0);
1913 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //output previous pic
1914 iIdx++;
1915
1916}
1917
1918static const EncodeDecodeFileParamBase kSVCSwitch[] = {
1919 {300, 160, 96, 6.0f, 2, 1, "120012130101012311201221323"},
1920};
1921
1922TEST_F (EncodeDecodeTestAPI, Engine_SVC_Switch_I) {
1923 SLTRMarkingFeedback m_LTR_Marking_Feedback;
1924 SLTRRecoverRequest m_LTR_Recover_Request;
1925 m_LTR_Recover_Request.uiIDRPicId = 0;
1926 EncodeDecodeFileParamBase p = kSVCSwitch[0];
1927 p.width = p.width << 2;
1928 p.height = p.height << 2;
1929 prepareParamDefault (4, p.slicenum, p.width, p.height, p.frameRate, &param_);
1930 param_.iTemporalLayerNum = (rand() % 4) + 1;
1931 param_.iSpatialLayerNum = 4;
1932 encoder_->Uninitialize();
1933 int rv = encoder_->InitializeExt (&param_);
1934 ASSERT_TRUE (rv == cmResultSuccess);
1935 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1936
1937 InitialEncDec (p.width, p.height);
1938 int32_t iTraceLevel = WELS_LOG_QUIET;
1939 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1940 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1941 int32_t iSpsPpsIdAddition = 1;
1942 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
1943 int32_t iIDRPeriod = (int32_t) pow (2.0f, (param_.iTemporalLayerNum - 1)) * ((rand() % 5) + 1);
1944 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
1945 SLTRConfig sLtrConfigVal;
1946 sLtrConfigVal.bEnableLongTermReference = 1;
1947 sLtrConfigVal.iLTRRefNum = 1;
1948 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
1949 int32_t iLtrPeriod = 2;
1950 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
1951 int iIdx = 0;
1952 int iTarDid = 0;
1953 while (iIdx <= p.numframes) {
1954 EncodeOneFrame (1);
1955 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
1956 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
1957 }
1958 if (info.eFrameType == videoFrameTypeIDR) {
1959 iTarDid = rand() % 4;
1960 }
1961 //decoding after each encoding frame
1962 int len = 0;
1963 encToDecData (info, len);
1964 unsigned char* pData[3] = { NULL };
1965 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
1966
1967 ExtractDidNal (&info, len, &m_SLostSim, iTarDid);
1968 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
1969 ASSERT_EQ (rv, 0);
1970 int iTid = -1;
1971 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
1972 ASSERT_EQ (iTid, -1);
1973 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
1974 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1975 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
1976 ASSERT_EQ (rv, 0);
1977 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
1978 ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId);
1979 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
1980 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
1981 iIdx++;
1982 }
1983}
1984
1985TEST_F (EncodeDecodeTestAPI, Engine_SVC_Switch_P) {
1986 SLTRMarkingFeedback m_LTR_Marking_Feedback;
1987 SLTRRecoverRequest m_LTR_Recover_Request;
1988 m_LTR_Recover_Request.uiIDRPicId = 0;
1989 EncodeDecodeFileParamBase p = kSVCSwitch[0];
1990 int iTarDid = 0;
1991 int iLastDid = 0;
1992 p.width = p.width << 2;
1993 p.height = p.height << 2;
1994 prepareParamDefault (4, p.slicenum, p.width, p.height, p.frameRate, &param_);
1995 param_.iTemporalLayerNum = (rand() % 4) + 1;
1996 param_.iSpatialLayerNum = 4;
1997 encoder_->Uninitialize();
1998 int rv = encoder_->InitializeExt (&param_);
1999 ASSERT_TRUE (rv == cmResultSuccess);
2000 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
2001
2002 InitialEncDec (p.width, p.height);
2003 int32_t iTraceLevel = WELS_LOG_QUIET;
2004 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2005 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2006 int32_t iSpsPpsIdAddition = 1;
2007 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
2008 int32_t iIDRPeriod = 60;
2009 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
2010 SLTRConfig sLtrConfigVal;
2011 sLtrConfigVal.bEnableLongTermReference = 1;
2012 sLtrConfigVal.iLTRRefNum = 1;
2013 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
2014 int32_t iLtrPeriod = 2;
2015 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
2016 int iIdx = 0;
2017
2018 while (iIdx <= p.numframes) {
2019 EncodeOneFrame (1);
2020 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
2021 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
2022 }
2023 //decoding after each encoding frame
2024 int len = 0;
2025 encToDecData (info, len);
2026 unsigned char* pData[3] = { NULL };
2027 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
2028 if (iIdx < (int) strlen (p.pLossSequence)) {
2029 switch (p.pLossSequence[iIdx]) {
2030 case '0':
2031 iTarDid = 0;
2032 break;
2033 case '1':
2034 iTarDid = 1;
2035 break;
2036 case '2':
2037 iTarDid = 2;
2038 break;
2039 case '3':
2040 iTarDid = 3;
2041 break;
2042 default :
2043 iTarDid = rand() % 4;
2044 break;
2045 }
2046 } else {
2047 iTarDid = rand() % 4;
2048 }
2049
2050 ExtractDidNal (&info, len, &m_SLostSim, iTarDid);
2051 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
2052 int iTid = -1;
2053 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
2054 ASSERT_EQ (iTid, -1);
2055 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
2056 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, false);
2057 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
2058 if (info.eFrameType == videoFrameTypeP && iIdx > 0 && iLastDid != iTarDid) {
2059 ASSERT_NE (rv, 0);
2060 } else if (info.eFrameType == videoFrameTypeIDR) {
2061 ASSERT_EQ (rv, 0);
2062 }
2063 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
2064 ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId);
2065 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, false);
2066 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
2067 iIdx++;
2068 iLastDid = iTarDid;
2069 }
2070}
2071
2072TEST_F (EncodeDecodeTestAPI, SetOptionEncParamExt) {
2073 int iSpatialLayerNum = 4;
2074 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_WIDTH);
2075 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_HEIGHT);
2076 float fFrameRate = rand() + 0.5f;
2077 int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
2078 int iSliceNum = 1;
2079 encoder_->GetDefaultParams (&param_);
2080 prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &param_);
2081
2082 int rv = encoder_->InitializeExt (&param_);
2083 ASSERT_TRUE (rv == cmResultSuccess);
2084
2085 int iTraceLevel = WELS_LOG_QUIET;
2086 rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2087 ASSERT_TRUE (rv == cmResultSuccess);
2088
2089 for (int i = 0; i < iEncFrameNum; i++) {
2090 int iResult;
2091 int len = 0;
2092 unsigned char* pData[3] = { NULL };
2093
2094 RandomParamExtCombination();
2095 iResult = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &param_);
2096 //ValidateParamExtCombination();
2097 //ASSERT_TRUE (iResult == cmResultSuccess);
2098 //to do
2099 // currently, there are still some error cases even though under condition cmResultSuccess == iResult
2100 // so need to enhance the validation check for any random value of each variable in ParamExt
2101
2102 if (cmResultSuccess == iResult) {
2103 InitialEncDec (param_.iPicWidth, param_.iPicHeight);
2104 EncodeOneFrame (0);
2105 encToDecData (info, len);
2106 pData[0] = pData[1] = pData[2] = 0;
2107 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
2108
2109 iResult = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
2110 ASSERT_TRUE (iResult == cmResultSuccess);
2111 iResult = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);
2112 ASSERT_TRUE (iResult == cmResultSuccess);
2113 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1);
2114 }
2115 }
2116
2117 iTraceLevel = WELS_LOG_ERROR;
2118 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2119}
2120
2121class DecodeCrashTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase {
2122 public:
2123 uint8_t iRandValue;
2124 public:
2125 void SetUp() {
2126 EncodeDecodeTestBase::SetUp();
2127 ucBuf_ = NULL;
2128 ucBuf_ = new unsigned char [1000000];
2129 ASSERT_TRUE (ucBuf_ != NULL);
2130 }
2131
2132 void TearDown() {
2133 EncodeDecodeTestBase::TearDown();
2134 if (NULL != ucBuf_) {
2135 delete[] ucBuf_;
2136 ucBuf_ = NULL;
2137 }
2138 ASSERT_TRUE (ucBuf_ == NULL);
2139 }
2140
2141 void prepareParam (int iLayerNum, int iSliceNum, int width, int height, float framerate, SEncParamExt* pParam) {
2142 memset (pParam, 0, sizeof (SEncParamExt));
2143 EncodeDecodeTestBase::prepareParam (iLayerNum, iSliceNum, width, height, framerate, pParam);
2144 }
2145
2146 void prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam);
2147 void EncodeOneFrame() {
2148 int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;
2149 memset (buf_.data(), iRandValue, (frameSize >> 2));
2150 memset (buf_.data() + (frameSize >> 2), rand() % 256, (frameSize - (frameSize >> 2)));
2151 int rv = encoder_->EncodeFrame (&EncPic, &info);
2152 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);
2153 }
2154 protected:
2155 unsigned char* ucBuf_;
2156};
2157
2158void DecodeCrashTestAPI::prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) {
2159 // for encoder
2160 // I420: 1(Y) + 1/4(U) + 1/4(V)
2161 int frameSize = EncDecFileParam.width * EncDecFileParam.height * 3 / 2;
2162
2163 buf_.SetLength (frameSize);
2164 ASSERT_TRUE (buf_.Length() == (size_t)frameSize);
2165
2166 memset (&EncPic, 0, sizeof (SSourcePicture));
2167 EncPic.iPicWidth = EncDecFileParam.width;
2168 EncPic.iPicHeight = EncDecFileParam.height;
2169 EncPic.iColorFormat = videoFormatI420;
2170 EncPic.iStride[0] = EncPic.iPicWidth;
2171 EncPic.iStride[1] = EncPic.iStride[2] = EncPic.iPicWidth >> 1;
2172 EncPic.pData[0] = buf_.data();
2173 EncPic.pData[1] = EncPic.pData[0] + EncDecFileParam.width * EncDecFileParam.height;
2174 EncPic.pData[2] = EncPic.pData[1] + (EncDecFileParam.width * EncDecFileParam.height >> 2);
2175
2176 //for decoder
2177 memset (&info, 0, sizeof (SFrameBSInfo));
2178
2179 //set a fixed random value
2180 iRandValue = rand() % 256;
2181}
2182
2183struct EncodeDecodeParamBase {
2184 int width;
2185 int height;
2186 float frameRate;
2187 int iTarBitrate;
2188};
2189
2190#define NUM_OF_POSSIBLE_RESOLUTION (9)
2191static const EncodeDecodeParamBase kParamArray[] = {
2192 {160, 90, 6.0f, 250000},
2193 {90, 160, 6.0f, 250000},
2194 {320, 180, 12.0f, 500000},
2195 {180, 320, 12.0f, 500000},
2196 {480, 270, 12.0f, 600000},
2197 {270, 480, 12.0f, 600000},
2198 {640, 360, 24.0f, 800000},
2199 {360, 640, 24.0f, 800000},
2200 {1280, 720, 24.0f, 1000000},
2201};
2202
2203//#define DEBUG_FILE_SAVE_CRA
2204TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
2205 uint32_t uiGet;
2206 encoder_->Uninitialize();
2207
2208 //do tests until crash
2209 unsigned int uiLoopRound = 0;
2210 unsigned char* pucBuf = ucBuf_;
2211 int iDecAuSize;
2212#ifdef DEBUG_FILE_SAVE_CRA
2213 //open file to save tested BS
2214 FILE* fDataFile = fopen ("test_crash.264", "wb");
2215 FILE* fLenFile = fopen ("test_crash_len.log", "w");
2216 int iFileSize = 0;
2217#endif
2218
2219 //set eCurStrategy for one test
2220 EParameterSetStrategy eCurStrategy = CONSTANT_ID;
2221 switch (rand() % 7) {
2222 case 1:
2223 eCurStrategy = INCREASING_ID;
2224 break;
2225 case 2:
2226 eCurStrategy = SPS_LISTING;
2227 break;
2228 case 3:
2229 eCurStrategy = SPS_LISTING_AND_PPS_INCREASING;
2230 break;
2231 case 6:
2232 eCurStrategy = SPS_PPS_LISTING;
2233 break;
2234 default:
2235 //using the initial value
2236 break;
2237 }
2238
2239 do {
2240 int iTotalFrameNum = (rand() % 100) + 1;
2241 int iSeed = rand() % NUM_OF_POSSIBLE_RESOLUTION;
2242 EncodeDecodeParamBase p = kParamArray[iSeed];
2243#ifdef DEBUG_FILE_SAVE_CRA
2244 printf ("using param set %d in loop %d\n", iSeed, uiLoopRound);
2245#endif
2246 //Initialize Encoder
2247 prepareParam (1, 1, p.width, p.height, p.frameRate, &param_);
2248 param_.iRCMode = RC_TIMESTAMP_MODE;
2249 param_.iTargetBitrate = p.iTarBitrate;
2250 param_.uiIntraPeriod = 0;
2251 param_.eSpsPpsIdStrategy = eCurStrategy;
2252 param_.bEnableBackgroundDetection = true;
2253 param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false;
2254 param_.bPrefixNalAddingCtrl = (rand() % 2) ? true : false;
2255 param_.iEntropyCodingModeFlag = 0;
2256 param_.bEnableFrameSkip = true;
2257 param_.iMultipleThreadIdc = 0;
2258 param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;
2259 param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;
2260 param_.sSpatialLayers[0].sSliceArgument.uiSliceMode = (rand() % 2) ? SM_SIZELIMITED_SLICE : SM_SINGLE_SLICE;
2261 if (param_.sSpatialLayers[0].sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE) {
2262 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 1400;
2263 param_.uiMaxNalSize = 1400;
2264 } else {
2265 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 0;
2266 param_.uiMaxNalSize = 0;
2267 }
2268
2269 int rv = encoder_->InitializeExt (&param_);
2270 ASSERT_TRUE (rv == cmResultSuccess);
2271 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
2272 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY
2273 int32_t iTraceLevel = WELS_LOG_QUIET;
2274 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2275 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2276
2277 //Start for enc/dec
2278 int iIdx = 0;
2279 unsigned char* pData[3] = { NULL };
2280
2281 EncodeDecodeFileParamBase pInput; //to conform with old functions
2282 pInput.width = p.width;
2283 pInput.height = p.height;
2284 pInput.frameRate = p.frameRate;
2285 prepareEncDecParam (pInput);
2286 while (iIdx++ < iTotalFrameNum) { // loop in frame
2287 EncodeOneFrame();
2288#ifdef DEBUG_FILE_SAVE_CRA
2289 //reset file if file size large
2290 if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {
2291 fclose (fDataFile);
2292 fDataFile = fopen ("test_crash.264", "wb");
2293 iFileSize = 0;
2294 decoder_->Uninitialize();
2295
2296 SDecodingParam decParam;
2297 memset (&decParam, 0, sizeof (SDecodingParam));
2298 decParam.uiTargetDqLayer = UCHAR_MAX;
2299 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
2300 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
2301
2302 rv = decoder_->Initialize (&decParam);
2303 ASSERT_EQ (0, rv);
2304 }
2305#endif
2306 if (info.eFrameType == videoFrameTypeSkip)
2307 continue;
2308 //deal with packets
2309 unsigned char* pBsBuf;
2310 iDecAuSize = 0;
2311 pucBuf = ucBuf_; //init buf start pos for decoder usage
2312 for (int iLayerNum = 0; iLayerNum < info.iLayerNum; iLayerNum++) {
2313 SLayerBSInfo* pLayerBsInfo = &info.sLayerInfo[iLayerNum];
2314 pBsBuf = info.sLayerInfo[iLayerNum].pBsBuf;
2315 int iTotalNalCnt = pLayerBsInfo->iNalCount;
2316 for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL
2317 int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];
2318 //packet loss
2319 int iLossRateRange = (uiLoopRound % 100) + 1; //1-100
2320 int iLossRate = (rand() % iLossRateRange);
2321 bool bPacketLost = (rand() % 101) > (100 -
2322 iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS
2323 if (!bPacketLost) { //no loss
2324 memcpy (pucBuf, pBsBuf, iPacketSize);
2325 pucBuf += iPacketSize;
2326 iDecAuSize += iPacketSize;
2327 }
2328#ifdef DEBUG_FILE_SAVE_CRA
2329 else {
2330 printf ("lost packet size=%d at frame-type=%d at loss rate %d (%d)\n", iPacketSize, info.eFrameType, iLossRate,
2331 iLossRateRange);
2332 }
2333#endif
2334 //update bs info
2335 pBsBuf += iPacketSize;
2336 } //nal
2337 } //layer
2338
2339#ifdef DEBUG_FILE_SAVE_CRA
2340 //save to file
2341 fwrite (ucBuf_, 1, iDecAuSize, fDataFile);
2342 fflush (fDataFile);
2343 iFileSize += iDecAuSize;
2344
2345 //save to len file
2346 unsigned long ulTmp[4];
2347 ulTmp[0] = ulTmp[1] = ulTmp[2] = iIdx;
2348 ulTmp[3] = iDecAuSize;
2349 fwrite (ulTmp, sizeof (unsigned long), 4, fLenFile); // index, timeStamp, data size
2350 fflush (fLenFile);
2351#endif
2352
2353 //decode
2354 pData[0] = pData[1] = pData[2] = 0;
2355 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
2356
2357 rv = decoder_->DecodeFrame2 (ucBuf_, iDecAuSize, pData, &dstBufInfo_);
2358 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
2359 //guarantee decoder EC status
2360 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
2361 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY);
2362 } //frame
2363 uiLoopRound ++;
2364 if (uiLoopRound >= (1 << 30))
2365 uiLoopRound = 0;
2366#ifdef DEBUG_FILE_SAVE_CRA
2367 if (uiLoopRound % 100 == 0)
2368 printf ("run %d times.\n", uiLoopRound);
2369 } while (1); //while (iLoopRound<100);
2370 fclose (fDataFile);
2371 fclose (fLenFile);
2372#else
2373 }
2374 while (uiLoopRound < 10);
2375#endif
2376
2377}
2378
2379const uint32_t kiTotalLayer = 3; //DO NOT CHANGE!
2380const uint32_t kiSliceNum = 2; //DO NOT CHANGE!
2381const uint32_t kiWidth = 160; //DO NOT CHANGE!
2382const uint32_t kiHeight = 96; //DO NOT CHANGE!
2383const uint32_t kiFrameRate = 12; //DO NOT CHANGE!
2384const uint32_t kiFrameNum = 100; //DO NOT CHANGE!
2385const char* pHashStr[] = { //DO NOT CHANGE!
2386 "585663f78cadb70d9c9f179b9b53b90ffddf3178",
2387 "f350001c333902029800bd291fbed915a4bdf19a",
2388 "eb9d853b7daec03052c4850027ac94adc84c3a7e"
2389};
2390
2391class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase {
2392 public:
2393 void SetUp() {
2394 SHA1Reset (&ctx_);
2395 EncodeDecodeTestBase::SetUp();
2396
2397 if (decoder_)
2398 decoder_->Uninitialize();
2399 SDecodingParam decParam;
2400 memset (&decParam, 0, sizeof (SDecodingParam));
2401 decParam.uiTargetDqLayer = UCHAR_MAX;
2402 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
2403 decParam.bParseOnly = true;
2404 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
2405
2406 int rv = decoder_->Initialize (&decParam);
2407 ASSERT_EQ (0, rv);
2408 memset (&BsInfo_, 0, sizeof (SParserBsInfo));
2409 fYuv_ = fopen ("./res/CiscoVT2people_160x96_6fps.yuv", "rb");
2410 ASSERT_TRUE (fYuv_ != NULL);
2411 iWidth_ = kiWidth;
2412 iHeight_ = kiHeight;
2413 }
2414 void TearDown() {
2415 EncodeDecodeTestBase::TearDown();
2416 fclose (fYuv_);
2417 }
2418
2419 void prepareEncDecParam (const EncodeDecodeFileParamBase p) {
2420 EncodeDecodeTestBase::prepareEncDecParam (p);
2421 unsigned char* pTmpPtr = BsInfo_.pDstBuff; //store for restore
2422 memset (&BsInfo_, 0, sizeof (SParserBsInfo));
2423 BsInfo_.pDstBuff = pTmpPtr;
2424 }
2425
2426 void EncodeOneFrame (int iIdx) {
2427 int iFrameSize = iWidth_ * iHeight_ * 3 / 2;
2428 int iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_);
2429 if (feof (fYuv_) || iSize != iFrameSize) {
2430 rewind (fYuv_);
2431 iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_);
2432 ASSERT_TRUE (iSize == iFrameSize);
2433 }
2434 int rv = encoder_->EncodeFrame (&EncPic, &info);
2435 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);
2436 }
2437
2438 void prepareParam (int iLayerNum, int iSliceNum, int width, int height, float framerate, SEncParamExt* pParam) {
2439 memset (pParam, 0, sizeof (SEncParamExt));
2440 EncodeDecodeTestBase::prepareParam (iLayerNum, iSliceNum, width, height, framerate, pParam);
2441 }
2442
2443 protected:
2444 SParserBsInfo BsInfo_;
2445 FILE* fYuv_;
2446 int iWidth_;
2447 int iHeight_;
2448 SHA1Context ctx_;
2449};
2450
2451//#define DEBUG_FILE_SAVE
2452TEST_F (DecodeParseAPI, ParseOnly_General) {
2453 EncodeDecodeFileParamBase p;
2454 p.width = iWidth_;
2455 p.height = iHeight_;
2456 p.frameRate = kiFrameRate;
2457 p.numframes = kiFrameNum;
2458 prepareParam (kiTotalLayer, kiSliceNum, p.width, p.height, p.frameRate, &param_);
2459 param_.iSpatialLayerNum = kiTotalLayer;
2460 encoder_->Uninitialize();
2461 int rv = encoder_->InitializeExt (&param_);
2462 ASSERT_TRUE (rv == 0);
2463 int32_t iTraceLevel = WELS_LOG_QUIET;
2464 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2465 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2466 uint32_t uiTargetLayerId = rand() % kiTotalLayer; //run only once
2467#ifdef DEBUG_FILE_SAVE
2468 FILE* fDec = fopen ("output.264", "wb");
2469 FILE* fEnc = fopen ("enc.264", "wb");
2470 FILE* fExtract = fopen ("extract.264", "wb");
2471#endif
2472 if (uiTargetLayerId < kiTotalLayer) { //should always be true
2473 //Start for enc
2474 int iLen = 0;
2475 prepareEncDecParam (p);
2476 int iFrame = 0;
2477
2478 while (iFrame < p.numframes) {
2479 //encode
2480 EncodeOneFrame (iFrame);
2481 //extract target layer data
2482 encToDecData (info, iLen);
2483#ifdef DEBUG_FILE_SAVE
2484 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fEnc);
2485#endif
2486 ExtractDidNal (&info, iLen, &m_SLostSim, uiTargetLayerId);
2487#ifdef DEBUG_FILE_SAVE
2488 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fExtract);
2489#endif
2490 //parseonly
2491 //BsInfo_.pDstBuff = new unsigned char [1000000];
2492 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf, iLen, &BsInfo_);
2493 EXPECT_TRUE (rv == 0);
2494 EXPECT_TRUE (BsInfo_.iNalNum == 0);
2495 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);
2496 EXPECT_TRUE (rv == 0);
2497 EXPECT_TRUE (BsInfo_.iNalNum != 0);
2498 //get final output bs
2499 iLen = 0;
2500 int i = 0;
2501 while (i < BsInfo_.iNalNum) {
2502 iLen += BsInfo_.iNalLenInByte[i];
2503 i++;
2504 }
2505#ifdef DEBUG_FILE_SAVE
2506 fwrite (BsInfo_.pDstBuff, iLen, 1, fDec);
2507#endif
2508 SHA1Input (&ctx_, BsInfo_.pDstBuff, iLen);
2509 iFrame++;
2510 }
2511 //calculate final SHA1 value
2512 unsigned char digest[SHA_DIGEST_LENGTH];
2513 SHA1Result (&ctx_, digest);
2514 if (!HasFatalFailure()) {
2515 CompareHash (digest, pHashStr[uiTargetLayerId]);
2516 }
2517 } //while
2518#ifdef DEBUG_FILE_SAVE
2519 fclose (fEnc);
2520 fclose (fExtract);
2521 fclose (fDec);
2522#endif
2523}
2524
2525//This case is for one layer only, for incomplete frame input
2526//First slice is loss for random one picture with 2 slices per pic
2527TEST_F (DecodeParseAPI, ParseOnly_SpecSliceLoss) {
2528 int32_t iLayerNum = 1;
2529 int32_t iSliceNum = 2;
2530 EncodeDecodeFileParamBase p;
2531 p.width = iWidth_;
2532 p.height = iHeight_;
2533 p.frameRate = kiFrameRate;
2534 p.numframes = 5;
2535 prepareParam (iLayerNum, iSliceNum, p.width, p.height, p.frameRate, &param_);
2536 param_.iSpatialLayerNum = iLayerNum;
2537 encoder_->Uninitialize();
2538 int rv = encoder_->InitializeExt (&param_);
2539 ASSERT_TRUE (rv == 0);
2540 int32_t iTraceLevel = WELS_LOG_QUIET;
2541 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2542 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2543
2544 int32_t iMissedPicNum = rand() % (p.numframes - 1) + 1; //IDR no loss
2545 //Start for enc
2546 int iLen = 0;
2547 uint32_t uiGet;
2548 prepareEncDecParam (p);
2549 int iFrame = 0;
2550
2551 while (iFrame < p.numframes) {
2552 //encode
2553 EncodeOneFrame (iFrame);
2554 //parseonly
2555 if (iFrame == iMissedPicNum) { //make current frame partly missing
2556 //Frame: P, first slice loss
2557 int32_t iTotalSliceSize = 0;
2558 encToDecSliceData (0, 0, info, iTotalSliceSize); //slice 1 lost
2559 encToDecSliceData (0, 1, info, iLen); //slice 2
2560 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
2561 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
2562 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, iLen, &BsInfo_);
2563 EXPECT_TRUE (rv == 0);
2564 EXPECT_TRUE (BsInfo_.iNalNum == 0);
2565 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);
2566 EXPECT_TRUE (rv != 0);
2567 } else { //normal frame, complete
2568 encToDecData (info, iLen);
2569 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf, iLen, &BsInfo_);
2570 EXPECT_TRUE (rv == 0); //parse correct
2571 EXPECT_TRUE (BsInfo_.iNalNum == 0);
2572 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);
2573 if (iFrame < iMissedPicNum) { //correct frames, all OK with output
2574 EXPECT_TRUE (rv == 0);
2575 EXPECT_TRUE (BsInfo_.iNalNum != 0);
2576 } else { //(iFrame > iMissedPicNum), should output nothing as error
2577 EXPECT_TRUE (rv != 0);
2578 EXPECT_TRUE (BsInfo_.iNalNum == 0);
2579 }
2580 }
2581 iFrame++;
2582 } //while
2583}
2584
2585//#define DEBUG_FILE_SAVE2
2586TEST_F (EncodeDecodeTestAPI, ParameterSetStrategy_SPS_LISTING_AND_PPS_INCREASING1) {
2587
2588 int iWidth = GetRandWidth();
2589 int iHeight = GetRandHeight();
2590 float fFrameRate = rand() + 0.5f;
2591 int iEncFrameNum = 0;
2592 int iSpatialLayerNum = 1;
2593 int iSliceNum = 1;
2594
2595 // prepare params
2596 SEncParamExt sParam1;
2597 SEncParamExt sParam2;
2598 SEncParamExt sParam3;
2599 encoder_->GetDefaultParams (&sParam1);
2600 prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam1);
2601 sParam1.eSpsPpsIdStrategy = SPS_LISTING_AND_PPS_INCREASING;
2602 //prepare param2
2603 memcpy (&sParam2, &sParam1, sizeof (SEncParamExt));
2604 while (GET_MB_WIDTH (sParam2.iPicWidth) == GET_MB_WIDTH (sParam1.iPicWidth)) {
2605 sParam2.iPicWidth = GetRandWidth();
2606 }
2607 prepareParamDefault (iSpatialLayerNum, iSliceNum, sParam2.iPicWidth, sParam2.iPicHeight, fFrameRate, &sParam2);
2608 sParam2.eSpsPpsIdStrategy = SPS_LISTING_AND_PPS_INCREASING;
2609 //prepare param3
2610 memcpy (&sParam3, &sParam1, sizeof (SEncParamExt));
2611 while (GET_MB_WIDTH (sParam3.iPicHeight) == GET_MB_WIDTH (sParam1.iPicHeight)) {
2612 sParam3.iPicHeight = GetRandHeight();
2613 }
2614 prepareParamDefault (iSpatialLayerNum, iSliceNum, sParam3.iPicWidth, sParam3.iPicHeight, fFrameRate, &sParam3);
2615 sParam3.eSpsPpsIdStrategy = SPS_LISTING_AND_PPS_INCREASING;
2616
2617 //prepare output if needed
2618 FILE* fEnc = NULL;
2619#ifdef DEBUG_FILE_SAVE2
2620 fEnc = fopen ("enc2.264", "wb");
2621#endif
2622
2623 // Test part#1
2624 // step#1: pParam1
2625 //int TraceLevel = WELS_LOG_INFO;
2626 //encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &TraceLevel);
2627 int rv = encoder_->InitializeExt (&sParam1);
2628 ASSERT_TRUE (rv == cmResultSuccess) << "InitializeExt: rv = " << rv << " at " << sParam1.iPicWidth << "x" <<
2629 sParam1.iPicHeight;
2630 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2631
2632 // new IDR
2633 rv = encoder_->ForceIntraFrame (true);
2634 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2635 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2636
2637 // step#2: pParam2
2638 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
2639 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption: rv = " << rv << " at " << sParam2.iPicWidth << "x" <<
2640 sParam2.iPicHeight;
2641 EncDecOneFrame (sParam2.iPicWidth, sParam2.iPicHeight, iEncFrameNum++, fEnc);
2642
2643 // new IDR
2644 rv = encoder_->ForceIntraFrame (true);
2645 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2646 EncDecOneFrame (sParam2.iPicWidth, sParam2.iPicHeight, iEncFrameNum++, fEnc);
2647
2648 // step#3: back to pParam1
2649 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam1);
2650 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption: rv = " << rv << " at " << sParam1.iPicWidth << "x" <<
2651 sParam1.iPicHeight;
2652 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2653
2654 // step#4: back to pParam2
2655 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
2656 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv << sParam2.iPicWidth << sParam2.iPicHeight;
2657 EncDecOneFrame (sParam2.iPicWidth, sParam2.iPicHeight, iEncFrameNum++, fEnc);
2658
2659#ifdef DEBUG_FILE_SAVE2
2660 fclose (fEnc);
2661#endif
2662 rv = encoder_->Uninitialize();
2663 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2664
2665 // Test part#2
2666 // step#1: pParam1
2667 rv = encoder_->InitializeExt (&sParam1);
2668 ASSERT_TRUE (rv == cmResultSuccess) << "InitializeExt Failed: rv = " << rv;
2669 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
2670 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam2: rv = " << rv;
2671 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam3);
2672 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam3: rv = " << rv;
2673
2674#ifdef DEBUG_FILE_SAVE2
2675 fEnc = fopen ("enc3.264", "wb");
2676#endif
2677 iEncFrameNum = 0;
2678 EncDecOneFrame (sParam3.iPicWidth, sParam3.iPicHeight, iEncFrameNum++, fEnc);
2679
2680 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
2681 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam2: rv = " << rv;
2682 EncDecOneFrame (sParam2.iPicWidth, sParam2.iPicHeight, iEncFrameNum++, fEnc);
2683
2684 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam1);
2685 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam2: rv = " << rv;
2686 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2687
2688#ifdef DEBUG_FILE_SAVE2
2689 fclose (fEnc);
2690#endif
2691 rv = encoder_->Uninitialize();
2692 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2693}
2694
2695//#define DEBUG_FILE_SAVE5
2696TEST_F (EncodeDecodeTestAPI, ParameterSetStrategy_SPS_LISTING_AND_PPS_INCREASING2) {
2697 //usage 3: 2 Params with different num_ref, encode IDR0, P1, IDR2;
2698 //the bs will show two SPS and different PPS
2699
2700 int iWidth = GetRandWidth();
2701 int iHeight = GetRandHeight();
2702 float fFrameRate = rand() + 0.5f;
2703 int iEncFrameNum = 0;
2704 int iSpatialLayerNum = 1;
2705 int iSliceNum = 1;
2706
2707 // prepare params
2708 SEncParamExt sParam1;
2709 SEncParamExt sParam2;
2710 encoder_->GetDefaultParams (&sParam1);
2711 prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam1);
2712 sParam1.eSpsPpsIdStrategy = SPS_LISTING_AND_PPS_INCREASING;
2713 sParam1.iTemporalLayerNum = 1;
2714 //prepare param2
2715 memcpy (&sParam2, &sParam1, sizeof (SEncParamExt));
2716 prepareParamDefault (iSpatialLayerNum, iSliceNum, sParam2.iPicWidth, sParam2.iPicHeight, fFrameRate, &sParam2);
2717 sParam2.eSpsPpsIdStrategy = SPS_LISTING_AND_PPS_INCREASING;
2718 sParam2.iTemporalLayerNum = 3;
2719
2720 //prepare output if needed
2721 FILE* fEnc = NULL;
2722#ifdef DEBUG_FILE_SAVE5
2723 fEnc = fopen ("encID2.264", "wb");
2724#endif
2725
2726 // step#1: pParam1
2727 int rv = encoder_->InitializeExt (&sParam1);
2728 ASSERT_TRUE (rv == cmResultSuccess) << "InitializeExt: rv = " << rv << " at " << sParam1.iPicWidth << "x" <<
2729 sParam1.iPicHeight;
2730
2731 // step#2: pParam2
2732 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
2733 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam2: rv = " << rv;
2734
2735 // step#3: set back to pParam1, with a smaller num_ref, it still uses the previous SPS
2736 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam1);
2737 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam1: rv = " << rv;
2738 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2739
2740 // new IDR, PPS increases
2741 rv = encoder_->ForceIntraFrame (true);
2742 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2743 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2744
2745 rv = encoder_->Uninitialize();
2746 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2747
2748#ifdef DEBUG_FILE_SAVE5
2749 fclose (fEnc);
2750#endif
2751}
2752
2753TEST_F (EncodeDecodeTestAPI, ParameterSetStrategy_SPS_LISTING_AND_PPS_INCREASING3) {
2754
2755 int iWidth = GetRandWidth();
2756 int iHeight = GetRandHeight();
2757 float fFrameRate = rand() + 0.5f;
2758 int iEncFrameNum = 0;
2759 int iSpatialLayerNum = 1;
2760 int iSliceNum = 1;
2761
2762 // prepare params
2763 SEncParamExt sParam1;
2764 SEncParamExt sParam2;
2765 encoder_->GetDefaultParams (&sParam1);
2766 prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam1);
2767 sParam1.eSpsPpsIdStrategy = SPS_LISTING_AND_PPS_INCREASING;
2768
2769 //prepare output if needed
2770 FILE* fEnc = NULL;
2771#ifdef DEBUG_FILE_SAVE2
2772 fEnc = fopen ("enc4.264", "wb");
2773#endif
2774
2775 // step#1: pParam1
2776 int rv = encoder_->InitializeExt (&sParam1);
2777 ASSERT_TRUE (rv == cmResultSuccess) << "InitializeExt Failed: rv = " << rv;
2778
2779 int max_count = 65; // make it more then twice as MAX_SPS_COUNT
2780 std::vector<int> vWidthTable;
2781 vWidthTable.push_back (GET_MB_WIDTH (sParam1.iPicWidth));
2782
2783 std::vector<int>::iterator vWidthTableIt;
2784 for (int times = 0; times < max_count; times++) {
2785 //prepare param2
2786 memcpy (&sParam2, &sParam1, sizeof (SEncParamExt));
2787 do {
2788 sParam2.iPicWidth = GetRandWidth();
2789 vWidthTableIt = std::find (vWidthTable.begin(), vWidthTable.end(), GET_MB_WIDTH (sParam2.iPicWidth));
2790 } while (vWidthTableIt != vWidthTable.end());
2791 vWidthTable.push_back (GET_MB_WIDTH (sParam2.iPicWidth));
2792 prepareParamDefault (iSpatialLayerNum, iSliceNum, sParam2.iPicWidth, sParam2.iPicHeight, fFrameRate, &sParam2);
2793 sParam2.eSpsPpsIdStrategy = SPS_LISTING_AND_PPS_INCREASING;
2794
2795 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
2796 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam2: rv = " << rv << ", sParam2.iPicWidth=" <<
2797 sParam2.iPicWidth;
2798 } // end of setting loop
2799
2800 EncDecOneFrame (sParam2.iPicWidth, sParam2.iPicHeight, iEncFrameNum++, fEnc);
2801
2802#ifdef DEBUG_FILE_SAVE2
2803 fclose (fEnc);
2804#endif
2805 rv = encoder_->Uninitialize();
2806 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2807}
2808
2809//#define DEBUG_FILE_SAVE6
2810TEST_F (EncodeDecodeTestAPI, ParameterSetStrategy_SPS_PPS_LISTING1) {
2811 //usage 1: 1 resolution Params, encode IDR0, P1, IDR2;
2812 //the bs will show same SPS and different PPS
2813 // PPS: pic_parameter_set_id 1 ( 0)
2814 // PPS: seq_parameter_set_id 1 ( 0)
2815 // PPS: pic_parameter_set_id 010 ( 1)
2816 // PPS: seq_parameter_set_id 1 ( 0)
2817 // SH: slice_type 011 ( 2)
2818 // SH: pic_parameter_set_id 1 ( 0)
2819 // SH: slice_type 1 ( 0)
2820 // SH: pic_parameter_set_id 1 ( 0)
2821 // SH: slice_type 011 ( 2)
2822 // SH: pic_parameter_set_id 010 ( 1)
2823 int iWidth = GetRandWidth();
2824 int iHeight = GetRandHeight();
2825 float fFrameRate = rand() + 0.5f;
2826 int iEncFrameNum = 0;
2827 int iSpatialLayerNum = 1;
2828 int iSliceNum = 1;
2829
2830 // prepare params
2831 SEncParamExt sParam1;
2832 encoder_->GetDefaultParams (&sParam1);
2833 prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam1);
2834 sParam1.eSpsPpsIdStrategy = SPS_PPS_LISTING;
2835
2836 //prepare output if needed
2837 FILE* fEnc = NULL;
2838#ifdef DEBUG_FILE_SAVE6
2839 fEnc = fopen ("encLIST1.264", "wb");
2840#endif
2841
2842 // step#1: pParam1
2843 int rv = encoder_->InitializeExt (&sParam1);
2844 ASSERT_TRUE (rv == cmResultSuccess) << "InitializeExt: rv = " << rv << " at " << sParam1.iPicWidth << "x" <<
2845 sParam1.iPicHeight;
2846 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2847 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2848
2849 // new IDR
2850 rv = encoder_->ForceIntraFrame (true);
2851 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2852 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2853
2854 rv = encoder_->Uninitialize();
2855 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2856
2857#ifdef DEBUG_FILE_SAVE6
2858 fclose (fEnc);
2859#endif
2860}
2861
2862TEST_F (EncodeDecodeTestAPI, ParameterSetStrategy_SPS_PPS_LISTING2) {
2863 //usage 2: 2 resolution Params, encode IDR0, IDR1, IDR2;
2864 //the bs will show two SPS and different PPS
2865 // === SPS LIST ===
2866 //SPS: seq_parameter_set_id 1 ( 0) -- PARAM1
2867 //SPS: seq_parameter_set_id 010 ( 1) -- PARAM2
2868 // === PPS LIST ===
2869 //PPS: pic_parameter_set_id 1 ( 0)
2870 //PPS: seq_parameter_set_id 1 ( 0)
2871 //PPS: pic_parameter_set_id 010 ( 1)
2872 //PPS: seq_parameter_set_id 010 ( 1)
2873 //PPS: pic_parameter_set_id 011 ( 2) -- PPS2 - SPS0
2874 //PPS: seq_parameter_set_id 1 ( 0)
2875 //PPS: pic_parameter_set_id 00100 ( 3) -- PPS3 - SPS1
2876 //PPS: seq_parameter_set_id 010 ( 1)
2877 //PPS: pic_parameter_set_id 00101 ( 4) -- PPS4 - SPS0
2878 //PPS: seq_parameter_set_id 1 ( 0)
2879 // === VCL LAYER ===
2880 //SH: slice_type 011 ( 2) -- PARAM2
2881 //SH: pic_parameter_set_id 010 ( 1) -- PPS1 - SPS1 - PARAM2
2882 //SH: slice_type 011 ( 2) -- PARAM1
2883 //SH: pic_parameter_set_id 011 ( 2) -- PPS2 - SPS0 - PARAM1
2884 //SH: slice_type 011 ( 2) -- PARAM1
2885 //SH: pic_parameter_set_id 00101 ( 4) -- PPS4 - SPS0 - PARAM1
2886
2887 int iWidth = GetRandWidth();
2888 int iHeight = GetRandHeight();
2889 float fFrameRate = rand() + 0.5f;
2890 int iEncFrameNum = 0;
2891 int iSpatialLayerNum = 1;
2892 int iSliceNum = 1;
2893
2894 // prepare params
2895 SEncParamExt sParam1;
2896 SEncParamExt sParam2;
2897 encoder_->GetDefaultParams (&sParam1);
2898 prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam1);
2899 sParam1.eSpsPpsIdStrategy = SPS_PPS_LISTING;
2900 //prepare param2
2901 memcpy (&sParam2, &sParam1, sizeof (SEncParamExt));
2902 while (GET_MB_WIDTH (sParam2.iPicWidth) == GET_MB_WIDTH (sParam1.iPicWidth)) {
2903 sParam2.iPicWidth = GetRandWidth();
2904 }
2905 prepareParamDefault (iSpatialLayerNum, iSliceNum, sParam2.iPicWidth, sParam2.iPicHeight, fFrameRate, &sParam2);
2906 sParam2.eSpsPpsIdStrategy = SPS_PPS_LISTING;
2907
2908 //prepare output if needed
2909 FILE* fEnc = NULL;
2910#ifdef DEBUG_FILE_SAVE5
2911 fEnc = fopen ("encLIST2.264", "wb");
2912#endif
2913
2914 // step#1: pParam1
2915 int rv = encoder_->InitializeExt (&sParam1);
2916 ASSERT_TRUE (rv == cmResultSuccess) << "InitializeExt: rv = " << rv << " at " << sParam1.iPicWidth << "x" <<
2917 sParam1.iPicHeight;
2918
2919 // step#2: pParam2
2920 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
2921 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam2: rv = " << rv;
2922 EncDecOneFrame (sParam2.iPicWidth, sParam2.iPicHeight, iEncFrameNum++, fEnc);
2923
2924 // step#3: back to pParam1, SHOULD NOT encounter ERROR
2925 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam1);
2926 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption: rv = " << rv << " at " << sParam1.iPicWidth << "x" <<
2927 sParam1.iPicHeight;
2928 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2929
2930 // new IDR
2931 rv = encoder_->ForceIntraFrame (true);
2932 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2933 EncDecOneFrame (sParam1.iPicWidth, sParam1.iPicHeight, iEncFrameNum++, fEnc);
2934
2935 rv = encoder_->Uninitialize();
2936 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
2937
2938#ifdef DEBUG_FILE_SAVE5
2939 fclose (fEnc);
2940#endif
2941}
2942
2943TEST_F (EncodeDecodeTestAPI, ParameterSetStrategy_SPS_PPS_LISTING3) {
2944
2945 int iWidth = GetRandWidth();
2946 int iHeight = GetRandHeight();
2947 float fFrameRate = rand() + 0.5f;
2948 int iEncFrameNum = 0;
2949 int iSpatialLayerNum = 1;
2950 int iSliceNum = 1;
2951
2952 // prepare params
2953 SEncParamExt sParam1;
2954 SEncParamExt sParam2;
2955 SEncParamExt sParam3;
2956 encoder_->GetDefaultParams (&sParam1);
2957 prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam1);
2958 sParam1.eSpsPpsIdStrategy = SPS_PPS_LISTING;
2959 //prepare param2
2960 memcpy (&sParam2, &sParam1, sizeof (SEncParamExt));
2961 while (GET_MB_WIDTH (sParam2.iPicWidth) == GET_MB_WIDTH (sParam1.iPicWidth)) {
2962 sParam2.iPicWidth = GetRandWidth();
2963 }
2964 prepareParamDefault (iSpatialLayerNum, iSliceNum, sParam2.iPicWidth, sParam2.iPicHeight, fFrameRate, &sParam2);
2965 sParam2.eSpsPpsIdStrategy = SPS_PPS_LISTING;
2966 //prepare param3
2967 memcpy (&sParam3, &sParam1, sizeof (SEncParamExt));
2968 while (GET_MB_WIDTH (sParam3.iPicWidth) == GET_MB_WIDTH (sParam1.iPicWidth) ||
2969 GET_MB_WIDTH (sParam3.iPicWidth) == GET_MB_WIDTH (sParam2.iPicWidth)) {
2970 sParam3.iPicWidth = GetRandWidth();
2971 }
2972 prepareParamDefault (iSpatialLayerNum, iSliceNum, sParam3.iPicWidth, sParam3.iPicHeight, fFrameRate, &sParam3);
2973 sParam3.eSpsPpsIdStrategy = SPS_PPS_LISTING;
2974
2975 //prepare output if needed
2976 FILE* fEnc = NULL;
2977#ifdef DEBUG_FILE_SAVE5
2978 fEnc = fopen ("enc4.264", "wb");
2979#endif
2980
2981 // step#1: ordinary encoding
2982 int rv = encoder_->InitializeExt (&sParam1);
2983 ASSERT_TRUE (rv == cmResultSuccess) << "InitializeExt: rv = " << rv << " at " << sParam1.iPicWidth << "x" <<
2984 sParam1.iPicHeight;
2985 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
2986 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam2: rv = " << rv;
2987 EncDecOneFrame (sParam2.iPicWidth, sParam2.iPicHeight, iEncFrameNum++, fEnc);
2988
2989 // step#2: set strategy for success
2990 int32_t iNewStra = SPS_PPS_LISTING;
2991 rv = encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iNewStra);
2992 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv << " iNewStra=" << iNewStra;
2993
2994 // step#3: setting new strategy, SHOULD encounter ERROR
2995 unsigned int TraceLevel = WELS_LOG_QUIET;
2996 rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &TraceLevel);
2997 ASSERT_TRUE (rv == cmResultSuccess);
2998 iNewStra = CONSTANT_ID;
2999 rv = encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iNewStra);
3000 ASSERT_TRUE (rv != cmResultSuccess);
3001
3002 EncDecOneFrame (sParam2.iPicWidth, sParam2.iPicHeight, iEncFrameNum++, fEnc);
3003
3004 // step#4: pParam3, SHOULD encounter ERROR
3005 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam3);
3006 ASSERT_TRUE (rv != cmResultSuccess) << "SetOption: rv = " << rv << " at " << sParam3.iPicWidth << "x" <<
3007 sParam3.iPicHeight;
3008
3009 rv = encoder_->Uninitialize();
3010 ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
3011
3012#ifdef DEBUG_FILE_SAVE5
3013 fclose (fEnc);
3014#endif
3015}
3016
3017
3018TEST_F (EncodeDecodeTestAPI, SimulcastSVC) {
3019 int iSpatialLayerNum = WelsClip3 ((rand() % MAX_SPATIAL_LAYER_NUM), 2, MAX_SPATIAL_LAYER_NUM);
3020 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 16, MAX_WIDTH);
3021 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 16, MAX_HEIGHT);
3022 float fFrameRate = rand() + 0.5f;
3023 int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
3024 int iSliceNum = 1;
3025 encoder_->GetDefaultParams (&param_);
3026 prepareParam (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &param_);
3027
3028 int rv = encoder_->InitializeExt (&param_);
3029 ASSERT_TRUE (rv == cmResultSuccess);
3030
3031 unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
3032 int aLen[MAX_SPATIAL_LAYER_NUM] = {0};
3033 ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
3034
3035#ifdef DEBUG_FILE_SAVE2
3036 FILE* fEnc[MAX_SPATIAL_LAYER_NUM] = { NULL };
3037 fEnc[0] = fopen ("enc0.264", "wb");
3038 fEnc[1] = fopen ("enc1.264", "wb");
3039 fEnc[2] = fopen ("enc2.264", "wb");
3040 fEnc[3] = fopen ("enc3.264", "wb");
3041#endif
3042
3043 // init decoders
3044 int iIdx = 0;
3045 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3046 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
3047 EXPECT_TRUE (pBsBuf[iIdx] != NULL);
3048 aLen[iIdx] = 0;
3049
3050 long rv = WelsCreateDecoder (&decoder[iIdx]);
3051 ASSERT_EQ (0, rv);
3052 EXPECT_TRUE (decoder[iIdx] != NULL);
3053
3054 SDecodingParam decParam;
3055 memset (&decParam, 0, sizeof (SDecodingParam));
3056 decParam.uiTargetDqLayer = UCHAR_MAX;
3057 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
3058 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
3059
3060 rv = decoder[iIdx]->Initialize (&decParam);
3061 ASSERT_EQ (0, rv);
3062 }
3063
3064 for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) {
3065 int iResult;
3066 int iLayerLen = 0;
3067 unsigned char* pData[3] = { NULL };
3068
3069 InitialEncDec (param_.iPicWidth, param_.iPicHeight);
3070 EncodeOneFrame (0);
3071
3072 iLayerLen = 0;
3073 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3074 aLen[iIdx] = 0;
3075 }
3076 for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) {
3077 iLayerLen = 0;
3078 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer];
3079 for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) {
3080 iLayerLen += layerInfo.pNalLengthInByte[iNal];
3081 }
3082
3083 if (layerInfo.uiLayerType == NON_VIDEO_CODING_LAYER) {
3084 // under SimulcastSVC, need to copy non-VCL to all layers
3085 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3086 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
3087 aLen[iIdx] += iLayerLen;
3088 }
3089 } else {
3090 iIdx = layerInfo.uiSpatialId;
3091 EXPECT_TRUE (iIdx < iSpatialLayerNum);
3092 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
3093 aLen[iIdx] += iLayerLen;
3094 }
3095 }
3096
3097 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3098 pData[0] = pData[1] = pData[2] = 0;
3099 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
3100
3101#ifdef DEBUG_FILE_SAVE2
3102 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);
3103#endif
3104 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
3105 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx;
3106 iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);
3107 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx;
3108 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx;
3109 }
3110 }
3111
3112 // free all
3113 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3114 if (pBsBuf[iIdx]) {
3115 free (pBsBuf[iIdx]);
3116 }
3117
3118 if (decoder[iIdx] != NULL) {
3119 decoder[iIdx]->Uninitialize();
3120 WelsDestroyDecoder (decoder[iIdx]);
3121 }
3122
3123#ifdef DEBUG_FILE_SAVE2
3124 fclose (fEnc[iIdx]);
3125#endif
3126 }
3127
3128}
3129
3130TEST_F (EncodeDecodeTestAPI, SimulcastAVC) {
3131//#define DEBUG_FILE_SAVE3
3132 int iSpatialLayerNum = WelsClip3 ((rand() % MAX_SPATIAL_LAYER_NUM), 2, MAX_SPATIAL_LAYER_NUM);
3133 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 16, MAX_WIDTH);
3134 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 16, MAX_HEIGHT);
3135 float fFrameRate = rand() + 0.5f;
3136 int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
3137 int iSliceNum = 1;
3138 encoder_->GetDefaultParams (&param_);
3139 prepareParam (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &param_);
3140
3141 //set flag of bSimulcastAVC
3142 param_.bSimulcastAVC = true;
3143
3144 int rv = encoder_->InitializeExt (&param_);
3145 ASSERT_TRUE (rv == cmResultSuccess);
3146
3147 unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
3148 int aLen[MAX_SPATIAL_LAYER_NUM] = {0};
3149 ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
3150
3151#ifdef DEBUG_FILE_SAVE3
3152 FILE* fEnc[MAX_SPATIAL_LAYER_NUM];
3153 fEnc[0] = fopen ("enc0.264", "wb");
3154 fEnc[1] = fopen ("enc1.264", "wb");
3155 fEnc[2] = fopen ("enc2.264", "wb");
3156 fEnc[3] = fopen ("enc3.264", "wb");
3157#endif
3158
3159 int iIdx = 0;
3160
3161 //create decoder
3162 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3163 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
3164 EXPECT_TRUE (pBsBuf[iIdx] != NULL);
3165 aLen[iIdx] = 0;
3166
3167 long rv = WelsCreateDecoder (&decoder[iIdx]);
3168 ASSERT_EQ (0, rv);
3169 EXPECT_TRUE (decoder[iIdx] != NULL);
3170
3171 SDecodingParam decParam;
3172 memset (&decParam, 0, sizeof (SDecodingParam));
3173 decParam.uiTargetDqLayer = UCHAR_MAX;
3174 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
3175 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
3176
3177 rv = decoder[iIdx]->Initialize (&decParam);
3178 ASSERT_EQ (0, rv);
3179 }
3180
3181 iEncFrameNum = 10;
3182 for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) {
3183 int iResult;
3184 int iLayerLen = 0;
3185 unsigned char* pData[3] = { NULL };
3186
3187 InitialEncDec (param_.iPicWidth, param_.iPicHeight);
3188 EncodeOneFrame (0);
3189
3190 // init
3191 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3192 aLen[iIdx] = 0;
3193 }
3194 for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) {
3195 iLayerLen = 0;
3196 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer];
3197 const int kiFirstNalType = ((* (layerInfo.pBsBuf + 4)) & 0x1f);
3198 ASSERT_TRUE ((kiFirstNalType == NAL_SPS) || (kiFirstNalType == NAL_PPS) || (kiFirstNalType == NAL_SLICE)
3199 || (kiFirstNalType == NAL_SLICE_IDR) || (kiFirstNalType == NAL_SEI));
3200 for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) {
3201 iLayerLen += layerInfo.pNalLengthInByte[iNal];
3202 }
3203
3204 iIdx = layerInfo.uiSpatialId;
3205 EXPECT_TRUE (iIdx < iSpatialLayerNum);
3206 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
3207 aLen[iIdx] += iLayerLen;
3208 }
3209
3210 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3211 pData[0] = pData[1] = pData[2] = 0;
3212 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
3213
3214#ifdef DEBUG_FILE_SAVE3
3215 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);
3216#endif
3217 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
3218 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx;
3219
3220 iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);
3221 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx;
3222 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx;
3223 }
3224 }
3225
3226 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3227 free (pBsBuf[iIdx]);
3228
3229 if (decoder[iIdx] != NULL) {
3230 decoder[iIdx]->Uninitialize();
3231 WelsDestroyDecoder (decoder[iIdx]);
3232 }
3233 }
3234#ifdef DEBUG_FILE_SAVE_SimulcastAVCDiffFps
3235 for (int i = 0; i <)MAX_SPATIAL_LAYER_NUM;
3236 i++) {
3237 fclose (fEnc[i]);
3238 }
3239#endif
3240}
3241
3242TEST_F (EncodeDecodeTestAPI, SimulcastAVC_SPS_PPS_LISTING) {
3243 int iSpatialLayerNum = WelsClip3 ((rand() % MAX_SPATIAL_LAYER_NUM), 2, MAX_SPATIAL_LAYER_NUM);;
3244 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_WIDTH);
3245 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_HEIGHT);
3246 float fFrameRate = rand() + 0.5f;
3247 int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
3248 int iSliceNum = 1;
3249 iWidth = VALID_SIZE (iWidth);
3250 iHeight = VALID_SIZE (iHeight);
3251 // prepare params
3252 SEncParamExt sParam1;
3253 SEncParamExt sParam2;
3254 encoder_->GetDefaultParams (&sParam1);
3255 prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam1);
3256 //set flag of SPS_PPS_LISTING
3257 sParam1.eSpsPpsIdStrategy = SPS_PPS_LISTING;//SPS_LISTING;//
3258 //set flag of bSimulcastAVC
3259 sParam1.bSimulcastAVC = true;
3260 //prepare param2
3261 memcpy (&sParam2, &sParam1, sizeof (SEncParamExt));
3262 sParam2.sSpatialLayers[0].iVideoWidth = (sParam1.sSpatialLayers[0].iVideoWidth / 2);
3263 sParam2.sSpatialLayers[0].iVideoHeight = (sParam1.sSpatialLayers[0].iVideoHeight / 2);
3264
3265 int rv = encoder_->InitializeExt (&sParam1);
3266 ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam1: rv = " << rv;;
3267 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam2);
3268 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed sParam2: rv = " << rv;
3269
3270 unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
3271 ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
3272
3273 int iIdx = 0;
3274
3275 //create decoder
3276 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3277 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
3278 EXPECT_TRUE (pBsBuf[iIdx] != NULL);
3279
3280 long rv = WelsCreateDecoder (&decoder[iIdx]);
3281 ASSERT_EQ (0, rv);
3282 EXPECT_TRUE (decoder[iIdx] != NULL);
3283
3284 SDecodingParam decParam;
3285 memset (&decParam, 0, sizeof (SDecodingParam));
3286 decParam.uiTargetDqLayer = UCHAR_MAX;
3287 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
3288 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
3289
3290 rv = decoder[iIdx]->Initialize (&decParam);
3291 ASSERT_EQ (0, rv);
3292 }
3293
3294 TestOneSimulcastAVC (&sParam1, decoder, pBsBuf, iSpatialLayerNum, iEncFrameNum, 0);
3295 TestOneSimulcastAVC (&sParam2, decoder, pBsBuf, iSpatialLayerNum, iEncFrameNum, 1);
3296
3297 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3298 free (pBsBuf[iIdx]);
3299
3300 if (decoder[iIdx] != NULL) {
3301 decoder[iIdx]->Uninitialize();
3302 WelsDestroyDecoder (decoder[iIdx]);
3303 }
3304
3305 }
3306}
3307
3308struct EncodeOptionParam {
3309 bool bTestNalSize;
3310 bool bAllRandom;
3311 bool bTestDecoder;
3312 int iNumframes;
3313 int iWidth;
3314 int iHeight;
3315 int iQp;
3316 SliceModeEnum eSliceMode;
3317 int uiMaxNalLen;
3318 float fFramerate;
3319 int iThreads;
3320 const char* sFileSave;
3321};
3322
3323static const EncodeOptionParam kOptionParamArray[] = {
3324 {true, true, false, 30, 600, 460, 1, SM_SIZELIMITED_SLICE, 450, 15.0, 1, ""},
3325 {true, true, false, 30, 340, 96, 24, SM_SIZELIMITED_SLICE, 1000, 30.0, 1, ""},
3326 {true, true, false, 30, 140, 196, 51, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3327 {true, true, false, 30, 110, 296, 50, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3328 {true, true, false, 30, 104, 416, 44, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3329 {true, true, false, 30, 16, 16, 2, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3330 {true, false, true, 30, 600, 460, 1, SM_SIZELIMITED_SLICE, 450, 15.0, 1, ""},
3331 {true, false, true, 30, 340, 96, 24, SM_SIZELIMITED_SLICE, 1000, 30.0, 1, ""},
3332 {true, false, true, 30, 140, 196, 51, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3333 {true, false, true, 30, 110, 296, 50, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3334 {true, false, true, 30, 104, 416, 44, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3335 {true, false, true, 30, 16, 16, 2, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3336 {true, true, true, 30, 600, 460, 1, SM_SIZELIMITED_SLICE, 450, 15.0, 1, ""},
3337 {true, true, true, 30, 340, 96, 24, SM_SIZELIMITED_SLICE, 1000, 30.0, 1, ""},
3338 {true, true, true, 30, 140, 196, 51, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3339 {true, true, true, 30, 110, 296, 50, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3340 {true, true, true, 30, 104, 416, 44, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3341 {true, true, true, 30, 16, 16, 2, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3342 {false, false, true, 3, 4096, 2304, 2, SM_SINGLE_SLICE, 0, 7.5, 1, ""}, // large picture size
3343 {false, true, false, 30, 32, 16, 2, SM_SIZELIMITED_SLICE, 500, 7.5, 1, ""},
3344 {false, true, false, 30, 600, 460, 1, SM_SIZELIMITED_SLICE, 450, 15.0, 4, ""},
3345 {false, true, false, 30, 340, 96, 24, SM_SIZELIMITED_SLICE, 1000, 30.0, 2, ""},
3346 {false, true, false, 30, 140, 196, 51, SM_SIZELIMITED_SLICE, 500, 7.5, 3, ""},
3347 {false, true, false, 30, 110, 296, 50, SM_SIZELIMITED_SLICE, 500, 7.5, 2, ""},
3348 {false, true, false, 30, 104, 416, 44, SM_SIZELIMITED_SLICE, 500, 7.5, 2, ""},
3349 {false, true, false, 30, 16, 16, 2, SM_SIZELIMITED_SLICE, 500, 7.5, 3, ""},
3350 {false, true, false, 30, 32, 16, 2, SM_SIZELIMITED_SLICE, 500, 7.5, 3, ""},
3351 {false, false, true, 30, 600, 460, 1, SM_FIXEDSLCNUM_SLICE, 0, 15.0, 4, ""},
3352 {false, false, true, 30, 600, 460, 1, SM_FIXEDSLCNUM_SLICE, 0, 15.0, 8, ""},
3353};
3354
3355class EncodeTestAPI : public ::testing::TestWithParam<EncodeOptionParam>, public ::EncodeDecodeTestAPIBase {
3356 public:
3357 void SetUp() {
3358 EncodeDecodeTestAPIBase::SetUp();
3359 }
3360
3361 void TearDown() {
3362 EncodeDecodeTestAPIBase::TearDown();
3363 }
3364 void EncodeOneFrameRandom (int iCheckTypeIndex, bool bAllRandom) {
3365 int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;
3366 uint8_t* ptr = buf_.data();
3367 uint8_t uiVal = rand() % 256;
3368 for (int i = 0; i < frameSize; i++) {
3369 ptr[i] = bAllRandom ? (rand() % 256) : uiVal;
3370 }
3371 int rv = encoder_->EncodeFrame (&EncPic, &info);
3372 if (0 == iCheckTypeIndex)
3373 ASSERT_TRUE (rv == cmResultSuccess) << "rv=" << rv;
3374 else if (1 == iCheckTypeIndex)
3375 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason) << "rv=" << rv;
3376 }
3377};
3378
3379INSTANTIATE_TEST_CASE_P (EncodeDecodeTestAPIBase, EncodeTestAPI,
3380 ::testing::ValuesIn (kOptionParamArray));
3381
3382TEST_P (EncodeTestAPI, SetEncOptionSize) {
3383 EncodeOptionParam p = GetParam();
3384 FILE* pFile = NULL;
3385 if (p.sFileSave != NULL && strlen (p.sFileSave) > 0) {
3386 pFile = fopen (p.sFileSave, "wb");
3387 }
3388 memset (&param_, 0, sizeof (SEncParamExt));
3389 encoder_->GetDefaultParams (&param_);
3390 param_.uiMaxNalSize = p.uiMaxNalLen;
3391 param_.iTemporalLayerNum = (rand() % 4) + 1;
3392 param_.iSpatialLayerNum = 1;
3393 param_.iUsageType = CAMERA_VIDEO_REAL_TIME;
3394 param_.iPicWidth = p.iWidth;
3395 param_.iPicHeight = p.iHeight;
3396 param_.fMaxFrameRate = p.fFramerate;
3397 param_.iRCMode = RC_OFF_MODE; //rc off
3398 param_.iMultipleThreadIdc = p.iThreads;
3399 param_.iNumRefFrame = AUTO_REF_PIC_COUNT;
3400 param_.sSpatialLayers[0].iVideoWidth = p.iWidth ;
3401 param_.sSpatialLayers[0].iVideoHeight = p.iHeight;
3402 param_.sSpatialLayers[0].fFrameRate = p.fFramerate;
3403 param_.sSpatialLayers[0].sSliceArgument.uiSliceMode = p.eSliceMode;
3404 if (SM_FIXEDSLCNUM_SLICE == p.eSliceMode) {
3405 param_.sSpatialLayers[0].sSliceArgument.uiSliceNum = 8;
3406 }
3407
3408 encoder_->Uninitialize();
3409 int rv = encoder_->InitializeExt (&param_);
3410 ASSERT_TRUE (rv == cmResultSuccess);
3411 InitialEncDec (p.iWidth, p.iHeight);
3412
3413 int32_t iTraceLevel = WELS_LOG_QUIET;
3414 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
3415 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
3416 int32_t iSpsPpsIdAddition = 1;
3417 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
3418 int32_t iIDRPeriod = (int32_t) pow (2.0f, (param_.iTemporalLayerNum - 1)) * ((rand() % 5) + 1);
3419 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
3420 int iIdx = 0;
3421 int iLen;
3422 unsigned char* pData[3] = { NULL };
3423
3424 //FIXME: remove this after the multi-thread case is correctly handled in encoder
3425 if (p.iThreads > 1 && SM_SIZELIMITED_SLICE == p.eSliceMode) {
3426 p.bAllRandom = false;
3427 }
3428
3429 while (iIdx <= p.iNumframes) {
3430 EncodeOneFrameRandom (0, p.bAllRandom);
3431 encToDecData (info, iLen);
3432 if (pFile) {
3433 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, pFile);
3434 fflush (pFile);
3435 }
3436 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
3437 if (iLen && p.bTestDecoder) {
3438 rv = decoder_->DecodeFrameNoDelay (info.sLayerInfo[0].pBsBuf, iLen, pData, &dstBufInfo_);
3439 ASSERT_EQ (rv, 0);
3440 ASSERT_EQ (dstBufInfo_.iBufferStatus, 1);
3441 }
3442 int iLayer = 0;
3443 while (iLayer < info.iLayerNum) {
3444 SLayerBSInfo* pLayerBsInfo = &info.sLayerInfo[iLayer];
3445 if (pLayerBsInfo != NULL) {
3446 int iNalIdx = WELS_MAX (pLayerBsInfo->iNalCount - 2, 0); // ignore last slice under single slice mode
3447 do {
3448 if (p.bTestNalSize) { // ignore the case that 2 MBs in one picture, and the multithreads case, enable them when code is ready
3449 ASSERT_GE (((int)param_.uiMaxNalSize), pLayerBsInfo->pNalLengthInByte[iNalIdx]);
3450 }
3451 -- iNalIdx;
3452 } while (iNalIdx >= 0);
3453 }
3454 ++ iLayer;
3455 }
3456 iIdx++;
3457 }
3458 if (pFile) {
3459 fclose (pFile);
3460 }
3461}
3462
3463
3464
3465TEST_F (EncodeDecodeTestAPI, SimulcastAVCDiffFps) {
3466//#define DEBUG_FILE_SAVE_SimulcastAVCDiffFps
3467 int iSpatialLayerNum = WelsClip3 ((rand() % MAX_SPATIAL_LAYER_NUM), 2, MAX_SPATIAL_LAYER_NUM);
3468 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_WIDTH);
3469 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_HEIGHT);
3470 float fFrameRate = 30;
3471 int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
3472 int iSliceNum = 1;
3473 encoder_->GetDefaultParams (&param_);
3474 prepareParam (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &param_);
3475
3476 //set flag of bSimulcastAVC
3477 param_.bSimulcastAVC = true;
3478 param_.iTemporalLayerNum = (rand() % 2) ? 3 : 4;
3479
3480 unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
3481 int aLen[MAX_SPATIAL_LAYER_NUM] = {0};
3482 ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
3483
3484#ifdef DEBUG_FILE_SAVE_SimulcastAVCDiffFps
3485 FILE* fEnc[MAX_SPATIAL_LAYER_NUM];
3486 fEnc[0] = fopen ("enc0.264", "wb");
3487 fEnc[1] = fopen ("enc1.264", "wb");
3488 fEnc[2] = fopen ("enc2.264", "wb");
3489 fEnc[3] = fopen ("enc3.264", "wb");
3490#endif
3491
3492 int iIdx = 0;
3493
3494 //create decoder
3495 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3496 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
3497 EXPECT_TRUE (pBsBuf[iIdx] != NULL);
3498 aLen[iIdx] = 0;
3499
3500 long rv = WelsCreateDecoder (&decoder[iIdx]);
3501 ASSERT_EQ (0, rv);
3502 EXPECT_TRUE (decoder[iIdx] != NULL);
3503
3504 SDecodingParam decParam;
3505 memset (&decParam, 0, sizeof (SDecodingParam));
3506 decParam.uiTargetDqLayer = UCHAR_MAX;
3507 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
3508 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
3509
3510 rv = decoder[iIdx]->Initialize (&decParam);
3511 ASSERT_EQ (0, rv);
3512 }
3513
3514#define PATTERN_NUM (18)
3515 const int32_t iTemporalPattern[PATTERN_NUM][MAX_SPATIAL_LAYER_NUM] = { {2, 1, 1, 1}, {2, 2, 2, 1}, {4, 1, 1, 1}, {4, 2, 1, 1},
3516 {1, 2, 1, 1}, {1, 1, 2, 1}, {1, 4, 1, 1}, {2, 4, 2, 1}, {1, 4, 2, 1}, {1, 4, 4, 1},
3517 {1, 2, 2, 1}, {2, 1, 2, 1}, {1, 2, 4, 1},
3518 {1, 1, 1, 2}, {1, 2, 2, 2}, {1, 2, 2, 4}, {1, 2, 4, 2}, {1, 4, 4, 4},
3519 };
3520 for (int iPatternIdx = 0; iPatternIdx < PATTERN_NUM; iPatternIdx++) {
3521 for (int i = 0; i < iSpatialLayerNum; i++) {
3522 param_.sSpatialLayers[i].fFrameRate = (fFrameRate / iTemporalPattern[iPatternIdx][i]);
3523 }
3524
3525 int rv = encoder_->InitializeExt (&param_);
3526 ASSERT_TRUE (rv == cmResultSuccess);
3527
3528 iEncFrameNum = 10;
3529 int iInsertIdr = rand() % iEncFrameNum;
3530 for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) {
3531 int iResult;
3532 int iLayerLen = 0;
3533 unsigned char* pData[3] = { NULL };
3534
3535 InitialEncDec (param_.iPicWidth, param_.iPicHeight);
3536 EncodeOneFrame (0);
3537
3538 if (iInsertIdr == iFrame) {
3539 encoder_->ForceIntraFrame (true);
3540 }
3541
3542 // init aLen for the current frame
3543 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3544 aLen[iIdx] = 0;
3545 }
3546 for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) {
3547 iLayerLen = 0;
3548 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer];
3549 const int kiFirstNalType = ((* (layerInfo.pBsBuf + 4)) & 0x1f);
3550 ASSERT_TRUE ((kiFirstNalType == NAL_SPS) || (kiFirstNalType == NAL_PPS) || (kiFirstNalType == NAL_SLICE)
3551 || (kiFirstNalType == NAL_SLICE_IDR) || (kiFirstNalType == NAL_SEI));
3552 for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) {
3553 iLayerLen += layerInfo.pNalLengthInByte[iNal];
3554 }
3555
3556 iIdx = layerInfo.uiSpatialId;
3557 EXPECT_TRUE (iIdx < iSpatialLayerNum);
3558 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
3559 aLen[iIdx] += iLayerLen;
3560 }
3561
3562 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3563 pData[0] = pData[1] = pData[2] = 0;
3564 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
3565
3566 if (aLen[iIdx] > 0) {
3567#ifdef DEBUG_FILE_SAVE_SimulcastAVCDiffFps
3568 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);
3569#endif
3570 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
3571 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx;
3572
3573 iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);
3574 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx << iPatternIdx;
3575 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx;
3576 }
3577 }
3578 }
3579 }
3580
3581 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3582 free (pBsBuf[iIdx]);
3583
3584 if (decoder[iIdx] != NULL) {
3585 decoder[iIdx]->Uninitialize();
3586 WelsDestroyDecoder (decoder[iIdx]);
3587 }
3588 }
3589#ifdef DEBUG_FILE_SAVE_SimulcastAVCDiffFps
3590 for (int i = 0; i < MAX_SPATIAL_LAYER_NUM; i++) {
3591 fclose (fEnc[i]);
3592 }
3593#endif
3594}
3595
3596TEST_F (EncodeDecodeTestAPI, DiffSlicingInDlayer) {
3597 int iSpatialLayerNum = 3;
3598 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, (64 << 2), MAX_WIDTH);
3599 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, (64 << 2),
3600 2240);//TODO: use MAX_HEIGHT after the limit is removed
3601 float fFrameRate = rand() + 0.5f;
3602 int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
3603
3604 // prepare params
3605 SEncParamExt sParam;
3606 encoder_->GetDefaultParams (&sParam);
3607 prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
3608 sParam.iMultipleThreadIdc = (rand() % 4) + 1;
3609 sParam.bSimulcastAVC = 1;
3610 sParam.sSpatialLayers[0].iVideoWidth = (iWidth >> 2);
3611 sParam.sSpatialLayers[0].iVideoHeight = (iHeight >> 2);
3612 sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_RASTER_SLICE;
3613 sParam.sSpatialLayers[1].sSliceArgument.uiSliceMbNum[0] = 0;
3614
3615 sParam.sSpatialLayers[1].iVideoWidth = (iWidth >> 1);
3616 sParam.sSpatialLayers[1].iVideoHeight = (iHeight >> 1);
3617 sParam.sSpatialLayers[1].sSliceArgument.uiSliceMode = SM_RASTER_SLICE;
3618 sParam.sSpatialLayers[1].sSliceArgument.uiSliceMbNum[0] = 30;
3619 sParam.sSpatialLayers[1].sSliceArgument.uiSliceMbNum[1] = 32;
3620
3621 sParam.sSpatialLayers[2].iVideoWidth = iWidth;
3622 sParam.sSpatialLayers[2].iVideoHeight = iHeight;
3623 sParam.sSpatialLayers[2].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
3624 sParam.sSpatialLayers[2].sSliceArgument.uiSliceNum = (rand() % 30) + 1;
3625
3626 int rv = encoder_->InitializeExt (&sParam);
3627 ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
3628
3629 unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
3630 ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
3631
3632 int iIdx = 0;
3633
3634 //create decoder
3635 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3636 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
3637 EXPECT_TRUE (pBsBuf[iIdx] != NULL);
3638
3639 long rv = WelsCreateDecoder (&decoder[iIdx]);
3640 ASSERT_EQ (0, rv);
3641 EXPECT_TRUE (decoder[iIdx] != NULL);
3642
3643 SDecodingParam decParam;
3644 memset (&decParam, 0, sizeof (SDecodingParam));
3645 decParam.uiTargetDqLayer = UCHAR_MAX;
3646 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
3647 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
3648
3649 rv = decoder[iIdx]->Initialize (&decParam);
3650 ASSERT_EQ (0, rv);
3651 }
3652
3653 TestOneSimulcastAVC (&sParam, decoder, pBsBuf, iSpatialLayerNum, iEncFrameNum, 0);
3654
3655 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3656 free (pBsBuf[iIdx]);
3657
3658 if (decoder[iIdx] != NULL) {
3659 decoder[iIdx]->Uninitialize();
3660 WelsDestroyDecoder (decoder[iIdx]);
3661 }
3662
3663 }
3664}
3665
3666TEST_F (EncodeDecodeTestAPI, DiffSlicingInDlayerMixed) {
3667 int iSpatialLayerNum = 2;
3668 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, (64 << 2), MAX_WIDTH);
3669 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, (64 << 2),
3670 1120);//TODO: use MAX_HEIGHT after the limit is removed
3671 float fFrameRate = rand() + 0.5f;
3672 int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
3673
3674 // prepare params
3675 SEncParamExt sParam;
3676 encoder_->GetDefaultParams (&sParam);
3677 prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
3678 sParam.iMultipleThreadIdc = (rand() % 4) + 1;
3679 sParam.bSimulcastAVC = 1;
3680 sParam.sSpatialLayers[0].iVideoWidth = (iWidth >> 2);
3681 sParam.sSpatialLayers[0].iVideoHeight = (iHeight >> 2);
3682 sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_RASTER_SLICE;
3683
3684 sParam.sSpatialLayers[1].iVideoWidth = iWidth;
3685 sParam.sSpatialLayers[1].iVideoHeight = iHeight;
3686 sParam.sSpatialLayers[1].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
3687 sParam.sSpatialLayers[1].sSliceArgument.uiSliceNum = 1;
3688
3689 int rv = encoder_->InitializeExt (&sParam);
3690 ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
3691
3692 unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
3693 ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
3694
3695 int iIdx = 0;
3696
3697 //create decoder
3698 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3699 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
3700 EXPECT_TRUE (pBsBuf[iIdx] != NULL);
3701
3702 long rv = WelsCreateDecoder (&decoder[iIdx]);
3703 ASSERT_EQ (0, rv);
3704 EXPECT_TRUE (decoder[iIdx] != NULL);
3705
3706 SDecodingParam decParam;
3707 memset (&decParam, 0, sizeof (SDecodingParam));
3708 decParam.uiTargetDqLayer = UCHAR_MAX;
3709 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
3710 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
3711
3712 rv = decoder[iIdx]->Initialize (&decParam);
3713 ASSERT_EQ (0, rv);
3714 }
3715
3716 TestOneSimulcastAVC (&sParam, decoder, pBsBuf, iSpatialLayerNum, iEncFrameNum, 0);
3717
3718 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3719 free (pBsBuf[iIdx]);
3720
3721 if (decoder[iIdx] != NULL) {
3722 decoder[iIdx]->Uninitialize();
3723 WelsDestroyDecoder (decoder[iIdx]);
3724 }
3725
3726 }
3727}
3728
3729TEST_F (EncodeDecodeTestAPI, ThreadNumAndSliceNum) {
3730 int iSpatialLayerNum = 1;
3731 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, (64 << 2), MAX_WIDTH);
3732 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, (64 << 2),
3733 2240);//TODO: use MAX_HEIGHT after the limit is removed
3734 float fFrameRate = rand() + 0.5f;
3735 int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
3736
3737 // prepare params
3738 SEncParamExt sParam;
3739 encoder_->GetDefaultParams (&sParam);
3740 prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
3741 sParam.iMultipleThreadIdc = (rand() % 3) + 2;
3742 sParam.bSimulcastAVC = 1;
3743 sParam.sSpatialLayers[0].iVideoWidth = iWidth;
3744 sParam.sSpatialLayers[0].iVideoHeight = iHeight;
3745 sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
3746 sParam.sSpatialLayers[0].sSliceArgument.uiSliceNum = (rand() % 2) ? (sParam.iMultipleThreadIdc + 1) :
3747 (sParam.iMultipleThreadIdc - 1);
3748
3749 int rv = encoder_->InitializeExt (&sParam);
3750 ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
3751
3752 unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
3753 ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
3754
3755 int iIdx = 0;
3756
3757 //create decoder
3758 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3759 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
3760 EXPECT_TRUE (pBsBuf[iIdx] != NULL);
3761
3762 long rv = WelsCreateDecoder (&decoder[iIdx]);
3763 ASSERT_EQ (0, rv);
3764 EXPECT_TRUE (decoder[iIdx] != NULL);
3765
3766 SDecodingParam decParam;
3767 memset (&decParam, 0, sizeof (SDecodingParam));
3768 decParam.uiTargetDqLayer = UCHAR_MAX;
3769 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
3770 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
3771
3772 rv = decoder[iIdx]->Initialize (&decParam);
3773 ASSERT_EQ (0, rv);
3774 }
3775
3776 TestOneSimulcastAVC (&sParam, decoder, pBsBuf, iSpatialLayerNum, iEncFrameNum, 0);
3777
3778 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3779 free (pBsBuf[iIdx]);
3780
3781 if (decoder[iIdx] != NULL) {
3782 decoder[iIdx]->Uninitialize();
3783 WelsDestroyDecoder (decoder[iIdx]);
3784 }
3785
3786 }
3787}
3788
3789
3790TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) {
3791//#define DEBUG_FILE_SAVE_TRIGGER
3792 int iSpatialLayerNum = 1;
3793 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, (64 << 2), MAX_WIDTH);
3794 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, (64 << 2),
3795 2240);//TODO: use MAX_HEIGHT after the limit is removed
3796 float fFrameRate = rand() + 0.5f;
3797 int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
3798
3799 // prepare params
3800 SEncParamExt sParam;
3801 encoder_->GetDefaultParams (&sParam);
3802 prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
3803 sParam.iMultipleThreadIdc = 4;
3804 sParam.bSimulcastAVC = 1;
3805 sParam.sSpatialLayers[0].iVideoWidth = iWidth;
3806 sParam.sSpatialLayers[0].iVideoHeight = iHeight;
3807 sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
3808 sParam.sSpatialLayers[0].sSliceArgument.uiSliceNum = sParam.iMultipleThreadIdc;
3809
3810 int rv = encoder_->InitializeExt (&sParam);
3811 ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
3812
3813 unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
3814 ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
3815
3816 int iIdx = 0;
3817 int aLen[MAX_SPATIAL_LAYER_NUM] = {};
3818
3819#ifdef DEBUG_FILE_SAVE_TRIGGER
3820 FILE* fEnc = fopen ("trigger00.264", "wb");
3821 printf("Current Threads is %d\n", sParam.iMultipleThreadIdc);
3822#endif
3823
3824 //create decoder
3825 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3826 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
3827 EXPECT_TRUE (pBsBuf[iIdx] != NULL);
3828
3829 long rv = WelsCreateDecoder (&decoder[iIdx]);
3830 ASSERT_EQ (0, rv);
3831 EXPECT_TRUE (decoder[iIdx] != NULL);
3832
3833 SDecodingParam decParam;
3834 memset (&decParam, 0, sizeof (SDecodingParam));
3835 decParam.uiTargetDqLayer = UCHAR_MAX;
3836 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
3837 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
3838
3839 rv = decoder[iIdx]->Initialize (&decParam);
3840 ASSERT_EQ (0, rv);
3841 }
3842
3843 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam);
3844 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed pParam: rv = " << rv;
3845
3846 //begin testing
3847 for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) {
3848 int iResult;
3849 int iLayerLen = 0;
3850 unsigned char* pData[3] = { NULL };
3851
3852 InitialEncDec (sParam.iPicWidth, sParam.iPicHeight);
3853 int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;
3854 memset (buf_.data(), rand() % 256, (frameSize >> 2));
3855 memset (buf_.data() + (frameSize >> 2), rand() % 256, (frameSize - (frameSize >> 2)));
3856
3857 int iStartStrip = 0;
3858 //during first half the complex strip is at top, then during the second half it is at bottom
3859 if (iFrame > iEncFrameNum / 2) {
3860 iStartStrip = EncPic.iPicHeight * EncPic.iPicWidth;
3861 }
3862 for (int k = 0; k < (EncPic.iPicHeight / 2); k++) {
3863 memset (buf_.data() + k * EncPic.iPicWidth + iStartStrip, rand() % 256, (EncPic.iPicWidth));
3864 }
3865
3866 int rv = encoder_->EncodeFrame (&EncPic, &info);
3867 ASSERT_TRUE (rv == cmResultSuccess);
3868
3869 // init
3870 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3871 aLen[iIdx] = 0;
3872 }
3873 for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) {
3874 iLayerLen = 0;
3875 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer];
3876 for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) {
3877 iLayerLen += layerInfo.pNalLengthInByte[iNal];
3878 }
3879
3880 iIdx = layerInfo.uiSpatialId;
3881 EXPECT_TRUE (iIdx < iSpatialLayerNum) << "iIdx = " << iIdx << ", iSpatialLayerNum = " << iSpatialLayerNum;
3882 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
3883 aLen[iIdx] += iLayerLen;
3884 }
3885
3886 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3887 pData[0] = pData[1] = pData[2] = 0;
3888 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
3889
3890#ifdef DEBUG_FILE_SAVE_TRIGGER
3891 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc);
3892#endif
3893 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
3894 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;
3895
3896 iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);
3897 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;
3898 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx;
3899 }
3900 }
3901
3902 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3903 free (pBsBuf[iIdx]);
3904
3905 if (decoder[iIdx] != NULL) {
3906 decoder[iIdx]->Uninitialize();
3907 WelsDestroyDecoder (decoder[iIdx]);
3908 }
3909 }
3910#ifdef DEBUG_FILE_SAVE_TRIGGER
3911 fclose(fEnc);
3912#endif
3913}
3914

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