• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include "codec_def.h"
3 #include "utils/BufferedData.h"
4 #include "utils/FileInputStream.h"
5 #include "BaseDecoderTest.h"
6 #include "BaseEncoderTest.h"
7 #include "wels_common_defs.h"
8 #include <string>
9 #include <vector>
10 #include "encode_decode_api_test.h"
11 using namespace WelsCommon;
12 
13 
TEST_P(EncodeDecodeTestAPI,GetOptionLTR_ALLIDR)14 TEST_P (EncodeDecodeTestAPI, GetOptionLTR_ALLIDR) {
15   EncodeDecodeFileParamBase p = GetParam();
16   prepareParamDefault (1, p.slicenum,  p.width, p.height, p.frameRate, &param_);
17   encoder_->Uninitialize();
18   int rv = encoder_->InitializeExt (&param_);
19   ASSERT_TRUE (rv == cmResultSuccess);
20 
21   ASSERT_TRUE (InitialEncDec (p.width, p.height));
22 
23   int32_t iTraceLevel = WELS_LOG_QUIET;
24   encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
25   decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
26   int32_t iSpsPpsIdAddition = 1;
27   encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
28   int32_t iIDRPeriod = (int32_t) pow (2.0f, (param_.iTemporalLayerNum - 1)) * ((rand() % 5) + 1);
29   encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
30   SLTRConfig sLtrConfigVal;
31   sLtrConfigVal.bEnableLongTermReference = 1;
32   sLtrConfigVal.iLTRRefNum = 1;
33   encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
34   int32_t iLtrPeriod = 2;
35   encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
36   int iIdx = 0;
37   while (iIdx <= p.numframes) {
38     EncodeOneFrame (0);
39     ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
40     encoder_->ForceIntraFrame (true);
41     iIdx++;
42   }
43 }
44 
TEST_P(EncodeDecodeTestAPI,GetOptionLTR_ALLLTR)45 TEST_P (EncodeDecodeTestAPI, GetOptionLTR_ALLLTR) {
46   SLTRMarkingFeedback m_LTR_Marking_Feedback;
47   SLTRRecoverRequest m_LTR_Recover_Request;
48   m_LTR_Recover_Request.iLayerId = 0;
49   m_LTR_Marking_Feedback.iLayerId = 0;
50   EncodeDecodeFileParamBase p = GetParam();
51   prepareParamDefault (1, p.slicenum,  p.width, p.height, p.frameRate, &param_);
52   encoder_->Uninitialize();
53   int rv = encoder_->InitializeExt (&param_);
54   ASSERT_TRUE (rv == cmResultSuccess);
55   m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
56   int frameSize = p.width * p.height * 3 / 2;
57   buf_.SetLength (frameSize);
58   ASSERT_TRUE (buf_.Length() == (size_t)frameSize);
59   SFrameBSInfo info;
60   memset (&info, 0, sizeof (SFrameBSInfo));
61 
62   SSourcePicture pic;
63   memset (&pic, 0, sizeof (SSourcePicture));
64   pic.iPicWidth = p.width;
65   pic.iPicHeight = p.height;
66   pic.iColorFormat = videoFormatI420;
67   pic.iStride[0] = pic.iPicWidth;
68   pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
69   pic.pData[0] = buf_.data();
70   pic.pData[1] = pic.pData[0] + p.width * p.height;
71   pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2);
72   int32_t iTraceLevel = WELS_LOG_QUIET;
73   encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
74   decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
75   int32_t iSpsPpsIdAddition = 1;
76   encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
77   int32_t iIDRPeriod = 60;
78   encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
79   SLTRConfig sLtrConfigVal;
80   sLtrConfigVal.bEnableLongTermReference = 1;
81   sLtrConfigVal.iLTRRefNum = 1;
82   encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
83   int32_t iLtrPeriod = 2;
84   encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
85   int iIdx = 0;
86   while (iIdx <= p.numframes) {
87     memset (buf_.data(), rand() % 256, frameSize);
88     rv = encoder_->EncodeFrame (&pic, &info);
89     if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
90       ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
91     }
92     ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);
93     m_LTR_Recover_Request.uiFeedbackType = LTR_RECOVERY_REQUEST;
94     m_LTR_Recover_Request.iCurrentFrameNum = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
95     m_LTR_Recover_Request.uiIDRPicId = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
96     m_LTR_Recover_Request.iLastCorrectFrameNum = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
97     encoder_->SetOption (ENCODER_LTR_RECOVERY_REQUEST, &m_LTR_Recover_Request);
98     m_LTR_Marking_Feedback.uiFeedbackType = rand() % 2 == 1 ? LTR_MARKING_SUCCESS : LTR_MARKING_FAILED;
99     m_LTR_Marking_Feedback.uiIDRPicId = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
100     m_LTR_Marking_Feedback.iLTRFrameNum = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000;
101     encoder_->SetOption (ENCODER_LTR_MARKING_FEEDBACK, &m_LTR_Marking_Feedback);
102     iIdx++;
103   }
104 }
105 
TEST_P(EncodeDecodeTestAPI,GetOptionLTR_Engine)106 TEST_P (EncodeDecodeTestAPI, GetOptionLTR_Engine) {
107   SLTRMarkingFeedback m_LTR_Marking_Feedback;
108   SLTRRecoverRequest m_LTR_Recover_Request;
109   m_LTR_Recover_Request.uiIDRPicId = 0;
110   m_LTR_Recover_Request.iLayerId = 0;
111   m_LTR_Marking_Feedback.iLayerId = 0;
112   EncodeDecodeFileParamBase p = GetParam();
113   prepareParamDefault (1, p.slicenum,  p.width, p.height, p.frameRate, &param_);
114   encoder_->Uninitialize();
115   int rv = encoder_->InitializeExt (&param_);
116   ASSERT_TRUE (rv == cmResultSuccess);
117   m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
118 
119   ASSERT_TRUE (InitialEncDec (p.width, p.height));
120 
121   int32_t iTraceLevel = WELS_LOG_QUIET;
122   encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
123   decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
124   int32_t iSpsPpsIdAddition = 1;
125   encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
126   int32_t iIDRPeriod = 60;
127   encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
128   SLTRConfig sLtrConfigVal;
129   sLtrConfigVal.bEnableLongTermReference = 1;
130   sLtrConfigVal.iLTRRefNum = 1;
131   encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
132   int32_t iLtrPeriod = 2;
133   encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
134   int iIdx = 0;
135   int iLossIdx = 0;
136   bool bVCLLoss = false;
137   while (iIdx <= p.numframes) {
138     EncodeOneFrame (1);
139     if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
140       ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
141     }
142     //decoding after each encoding frame
143     int len = 0;
144     encToDecData (info, len);
145     unsigned char* pData[3] = { NULL };
146     memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
147     SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);
148     rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
149     m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
150     LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
151     rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
152     LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
153     LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
154     iIdx++;
155   }
156 }
157 
158