Showing the changes to test/api/decoder_ec_test.cpp (1 of 7 files). Show all
Unified · Split
| @@ -0,0 +1,809 @@ | |||
| 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, SetOptionECFlag_ERROR_CON_DISABLE) { | ||
| 14 | SLTRMarkingFeedback m_LTR_Marking_Feedback; | ||
| 15 | SLTRRecoverRequest m_LTR_Recover_Request; | ||
| 16 | m_LTR_Recover_Request.uiIDRPicId = 0; | ||
| 17 | EncodeDecodeFileParamBase p = GetParam(); | ||
| 18 | prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, ¶m_); | ||
| 19 | param_.bEnableLongTermReference = true; | ||
| 20 | param_.iLTRRefNum = 1; | ||
| 21 | encoder_->Uninitialize(); | ||
| 22 | int rv = encoder_->InitializeExt (¶m_); | ||
| 23 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 24 | if (decoder_ != NULL) { | ||
| 25 | decoder_->Uninitialize(); | ||
| 26 | } | ||
| 27 | SDecodingParam decParam; | ||
| 28 | memset (&decParam, 0, sizeof (SDecodingParam)); | ||
| 29 | decParam.uiTargetDqLayer = UCHAR_MAX; | ||
| 30 | decParam.eEcActiveIdc = ERROR_CON_DISABLE; | ||
| 31 | decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT; | ||
| 32 | rv = decoder_->Initialize (&decParam); | ||
| 33 | ASSERT_EQ (0, rv); | ||
| 34 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 35 | |||
| 36 | InitialEncDec (p.width, p.height); | ||
| 37 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 38 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 39 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 40 | int32_t iSpsPpsIdAddition = 1; | ||
| 41 | encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition); | ||
| 42 | int32_t iIDRPeriod = 60; | ||
| 43 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 44 | SLTRConfig sLtrConfigVal; | ||
| 45 | sLtrConfigVal.bEnableLongTermReference = 1; | ||
| 46 | sLtrConfigVal.iLTRRefNum = 1; | ||
| 47 | encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal); | ||
| 48 | int32_t iLtrPeriod = 2; | ||
| 49 | encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod); | ||
| 50 | int iIdx = 0; | ||
| 51 | int iLossIdx = 0; | ||
| 52 | int iSkipedBytes; | ||
| 53 | bool bVCLLoss = false; | ||
| 54 | while (iIdx <= p.numframes) { | ||
| 55 | EncodeOneFrame (1); | ||
| 56 | if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) { | ||
| 57 | ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 58 | } | ||
| 59 | //decoding after each encoding frame | ||
| 60 | int len = 0; | ||
| 61 | encToDecData (info, len); | ||
| 62 | unsigned char* pData[3] = { NULL }; | ||
| 63 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 64 | iSkipedBytes = SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, | ||
| 65 | bVCLLoss); | ||
| 66 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 67 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 68 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true); | ||
| 69 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 70 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true); | ||
| 71 | LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv); | ||
| 72 | if (iSkipedBytes && bVCLLoss) { | ||
| 73 | ASSERT_TRUE (dstBufInfo_.iBufferStatus == 0); | ||
| 74 | } | ||
| 75 | iIdx++; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | TEST_P (EncodeDecodeTestAPI, SetOptionECFlag_ERROR_CON_SLICE_COPY) { | ||
| 80 | SLTRMarkingFeedback m_LTR_Marking_Feedback; | ||
| 81 | SLTRRecoverRequest m_LTR_Recover_Request; | ||
| 82 | m_LTR_Recover_Request.uiIDRPicId = 0; | ||
| 83 | EncodeDecodeFileParamBase p = GetParam(); | ||
| 84 | prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, ¶m_); | ||
| 85 | encoder_->Uninitialize(); | ||
| 86 | int rv = encoder_->InitializeExt (¶m_); | ||
| 87 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 88 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 89 | |||
| 90 | InitialEncDec (p.width, p.height); | ||
| 91 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 92 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 93 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 94 | int32_t iSpsPpsIdAddition = 1; | ||
| 95 | encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition); | ||
| 96 | int32_t iIDRPeriod = 60; | ||
| 97 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 98 | SLTRConfig sLtrConfigVal; | ||
| 99 | sLtrConfigVal.bEnableLongTermReference = 1; | ||
| 100 | sLtrConfigVal.iLTRRefNum = 1; | ||
| 101 | encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal); | ||
| 102 | int32_t iLtrPeriod = 2; | ||
| 103 | encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod); | ||
| 104 | int iIdx = 0; | ||
| 105 | int iLossIdx = 0; | ||
| 106 | int iSkipedBytes; | ||
| 107 | bool bVCLLoss = false; | ||
| 108 | while (iIdx <= p.numframes) { | ||
| 109 | EncodeOneFrame (1); | ||
| 110 | if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) { | ||
| 111 | ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 112 | } | ||
| 113 | //decoding after each encoding frame | ||
| 114 | int len = 0; | ||
| 115 | encToDecData (info, len); | ||
| 116 | unsigned char* pData[3] = { NULL }; | ||
| 117 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 118 | iSkipedBytes = SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, | ||
| 119 | bVCLLoss); | ||
| 120 | uint32_t uiEcIdc = rand() % 2 == 1 ? ERROR_CON_DISABLE : ERROR_CON_SLICE_COPY; | ||
| 121 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 122 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 123 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 124 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true); | ||
| 125 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 126 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true); | ||
| 127 | LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv); | ||
| 128 | iIdx++; | ||
| 129 | } | ||
| 130 | (void) iSkipedBytes; | ||
| 131 | } | ||
| 132 | |||
| 133 | static const EncodeDecodeFileParamBase kFileParamArray[] = { | ||
| 134 | {300, 160, 96, 6.0f, 2, 1, "000000000000001010101010101010101010101001101010100000010101000011"}, | ||
| 135 | {300, 140, 96, 6.0f, 4, 1, "000000000000001010101010101010101010101001101010100000010101000011"}, | ||
| 136 | {300, 140, 96, 6.0f, 4, 1, "000000000000001010111010101011101010101001101010100000010101110011010101"}, | ||
| 137 | }; | ||
| 138 | |||
| 139 | INSTANTIATE_TEST_CASE_P (EncodeDecodeTestAPIBase, EncodeDecodeTestAPI, | ||
| 140 | ::testing::ValuesIn (kFileParamArray)); | ||
| 141 | |||
| 142 | TEST_P (EncodeDecodeTestAPI, SetOptionECIDC_GeneralSliceChange) { | ||
| 143 | uint32_t uiEcIdc; | ||
| 144 | uint32_t uiGet; | ||
| 145 | EncodeDecodeFileParamBase p = GetParam(); | ||
| 146 | prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, ¶m_); | ||
| 147 | param_.iSpatialLayerNum = 1; | ||
| 148 | encoder_->Uninitialize(); | ||
| 149 | int rv = encoder_->InitializeExt (¶m_); | ||
| 150 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 151 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 152 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY | ||
| 153 | |||
| 154 | uiEcIdc = 0; | ||
| 155 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 156 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 157 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 158 | |||
| 159 | //Start for enc/dec | ||
| 160 | |||
| 161 | InitialEncDec (p.width, p.height); | ||
| 162 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 163 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 164 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 165 | int iIdx = 0; | ||
| 166 | bool bVCLLoss = false; | ||
| 167 | int iPacketNum; | ||
| 168 | int len; | ||
| 169 | int iTotalSliceSize; | ||
| 170 | |||
| 171 | //enc/dec pictures | ||
| 172 | while (iIdx <= p.numframes) { | ||
| 173 | EncodeOneFrame (1); | ||
| 174 | //decoding after each encoding frame | ||
| 175 | len = 0; | ||
| 176 | iPacketNum = 0; | ||
| 177 | iTotalSliceSize = 0; | ||
| 178 | unsigned char* pData[3] = { NULL }; | ||
| 179 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 180 | while (iPacketNum < info.sLayerInfo[0].iNalCount) { | ||
| 181 | encToDecSliceData (0, iPacketNum, info, len); | ||
| 182 | uiEcIdc = (ERROR_CON_IDC) (rand() % 2); | ||
| 183 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 184 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 185 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 186 | |||
| 187 | bVCLLoss = rand() & 1; //loss or not | ||
| 188 | if (!bVCLLoss) { //not loss | ||
| 189 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, | ||
| 190 | info.sLayerInfo[0].pNalLengthInByte[iPacketNum], pData, &dstBufInfo_); | ||
| 191 | if (uiEcIdc == ERROR_CON_DISABLE) | ||
| 192 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); | ||
| 193 | } | ||
| 194 | //EC_IDC should not change till now | ||
| 195 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 196 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 197 | //Set again inside | ||
| 198 | uiEcIdc = (ERROR_CON_IDC) (rand() % 2); | ||
| 199 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 200 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 201 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 202 | |||
| 203 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 204 | //EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); | ||
| 205 | if (uiEcIdc == ERROR_CON_DISABLE && rv != 0) | ||
| 206 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); | ||
| 207 | |||
| 208 | //deal with next slice | ||
| 209 | iTotalSliceSize += len; | ||
| 210 | iPacketNum++; | ||
| 211 | } //while slice | ||
| 212 | iIdx++; | ||
| 213 | } //while frame | ||
| 214 | } | ||
| 215 | |||
| 216 | //This case contain 1 slice per picture | ||
| 217 | //coding order: 0 1 2 3 4 5 6 7 | ||
| 218 | //frame type: IDR P P P P P P P | ||
| 219 | //EC_IDC: 0 0 0 2 0 0 1 1 | ||
| 220 | //loss: N Y N N N Y Y N | ||
| 221 | |||
| 222 | TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificFrameChange) { | ||
| 223 | uint32_t uiEcIdc; | ||
| 224 | uint32_t uiGet; | ||
| 225 | EncodeDecodeFileParamBase p = kFileParamArray[0]; | ||
| 226 | prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, ¶m_); | ||
| 227 | |||
| 228 | param_.iSpatialLayerNum = 1; | ||
| 229 | encoder_->Uninitialize(); | ||
| 230 | int rv = encoder_->InitializeExt (¶m_); | ||
| 231 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 232 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 233 | EXPECT_EQ (uiGet, (ERROR_CON_IDC) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY | ||
| 234 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 235 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 236 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 237 | |||
| 238 | //set EC=DISABLE | ||
| 239 | uiEcIdc = (uint32_t) (ERROR_CON_DISABLE); | ||
| 240 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 241 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 242 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 243 | |||
| 244 | //Start for enc/dec | ||
| 245 | int iIdx = 0; | ||
| 246 | int len = 0; | ||
| 247 | unsigned char* pData[3] = { NULL }; | ||
| 248 | InitialEncDec (p.width, p.height); | ||
| 249 | //Frame 0: IDR, EC_IDC=DISABLE, loss = 0 | ||
| 250 | EncodeOneFrame (1); | ||
| 251 | encToDecData (info, len); | ||
| 252 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 253 | EXPECT_EQ (uiGet, (ERROR_CON_IDC) ERROR_CON_DISABLE); | ||
| 254 | pData[0] = pData[1] = pData[2] = 0; | ||
| 255 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 256 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 257 | EXPECT_EQ (rv, 0); | ||
| 258 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); | ||
| 259 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 260 | EXPECT_EQ (rv, 0); | ||
| 261 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); | ||
| 262 | iIdx++; | ||
| 263 | |||
| 264 | //Frame 1: P, EC_IDC=DISABLE, loss = 1 | ||
| 265 | EncodeOneFrame (1); | ||
| 266 | iIdx++; | ||
| 267 | |||
| 268 | //Frame 2: P, EC_IDC=DISABLE, loss = 0 | ||
| 269 | EncodeOneFrame (1); | ||
| 270 | encToDecData (info, len); | ||
| 271 | pData[0] = pData[1] = pData[2] = 0; | ||
| 272 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 273 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 274 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE); | ||
| 275 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 276 | EXPECT_EQ (rv, 0); //parse correct | ||
| 277 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output | ||
| 278 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 279 | EXPECT_TRUE (rv != 0); //construction error due to data loss | ||
| 280 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output due to EC DISABLE | ||
| 281 | iIdx++; | ||
| 282 | |||
| 283 | //set EC=SLICE_COPY | ||
| 284 | uiEcIdc = (uint32_t) (ERROR_CON_SLICE_COPY); | ||
| 285 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 286 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 287 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 288 | //Frame 3: P, EC_IDC=SLICE_COPY, loss = 0 | ||
| 289 | EncodeOneFrame (1); | ||
| 290 | encToDecData (info, len); | ||
| 291 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 292 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); | ||
| 293 | pData[0] = pData[1] = pData[2] = 0; | ||
| 294 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 295 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 296 | EXPECT_EQ (rv, 0); //parse correct | ||
| 297 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output | ||
| 298 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 299 | EXPECT_TRUE (rv != 0); //construction error due to data loss | ||
| 300 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); | ||
| 301 | iIdx++; | ||
| 302 | |||
| 303 | //set EC=DISABLE | ||
| 304 | uiEcIdc = (uint32_t) (ERROR_CON_DISABLE); | ||
| 305 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 306 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 307 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 308 | //Frame 4: P, EC_IDC=DISABLE, loss = 0 | ||
| 309 | EncodeOneFrame (1); | ||
| 310 | encToDecData (info, len); | ||
| 311 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 312 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE); | ||
| 313 | pData[0] = pData[1] = pData[2] = 0; | ||
| 314 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 315 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 316 | EXPECT_EQ (rv, 0); //parse correct | ||
| 317 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output | ||
| 318 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 319 | //Ref picture is ECed, so current status is ECed, when EC disable, NO output | ||
| 320 | EXPECT_TRUE (rv != 0); | ||
| 321 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); | ||
| 322 | iIdx++; | ||
| 323 | |||
| 324 | //Frame 5: P, EC_IDC=DISABLE, loss = 1 | ||
| 325 | EncodeOneFrame (1); | ||
| 326 | iIdx++; | ||
| 327 | |||
| 328 | //set EC=FRAME_COPY | ||
| 329 | uiEcIdc = (uint32_t) (ERROR_CON_FRAME_COPY); | ||
| 330 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 331 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 332 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 333 | //Frame 6: P, EC_IDC=FRAME_COPY, loss = 1 | ||
| 334 | EncodeOneFrame (1); | ||
| 335 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 336 | iIdx++; | ||
| 337 | |||
| 338 | //Frame 7: P, EC_IDC=FRAME_COPY, loss = 0 | ||
| 339 | EncodeOneFrame (1); | ||
| 340 | encToDecData (info, len); | ||
| 341 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 342 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_FRAME_COPY); | ||
| 343 | pData[0] = pData[1] = pData[2] = 0; | ||
| 344 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 345 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 346 | EXPECT_TRUE (rv == 0); // Now the parse process is Error_None, and the reconstruction will has error return | ||
| 347 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //no output | ||
| 348 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 349 | EXPECT_TRUE (rv != 0); //not sure if previous data drop would be detected in construction | ||
| 350 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); | ||
| 351 | iIdx++; | ||
| 352 | } | ||
| 353 | |||
| 354 | //This case contain 2 slices per picture for IDR loss | ||
| 355 | //coding order: 0 1 2 3 4 | ||
| 356 | //frame type IDR P P P P | ||
| 357 | //EC_IDC 2 2 0 1 0 | ||
| 358 | //loss (2 slice: 1,2): 2 0 0 1 0 | ||
| 359 | |||
| 360 | TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificSliceChange_IDRLoss) { | ||
| 361 | uint32_t uiEcIdc = 2; //default set as SLICE_COPY | ||
| 362 | uint32_t uiGet; | ||
| 363 | EncodeDecodeFileParamBase p = kFileParamArray[0]; | ||
| 364 | prepareParamDefault (1, 2, p.width, p.height, p.frameRate, ¶m_); | ||
| 365 | param_.iSpatialLayerNum = 1; | ||
| 366 | encoder_->Uninitialize(); | ||
| 367 | int rv = encoder_->InitializeExt (¶m_); | ||
| 368 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 369 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 370 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 371 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY | ||
| 372 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 373 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 374 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 375 | |||
| 376 | //Start for enc/dec | ||
| 377 | int iIdx = 0; | ||
| 378 | int len = 0; | ||
| 379 | unsigned char* pData[3] = { NULL }; | ||
| 380 | int iTotalSliceSize = 0; | ||
| 381 | |||
| 382 | InitialEncDec (p.width, p.height); | ||
| 383 | |||
| 384 | //Frame 0: IDR, EC_IDC=2, loss = 2 | ||
| 385 | EncodeOneFrame (1); | ||
| 386 | iTotalSliceSize = 0; | ||
| 387 | encToDecSliceData (0, 0, info, len); //SPS | ||
| 388 | iTotalSliceSize = len; | ||
| 389 | encToDecSliceData (0, 1, info, len); //PPS | ||
| 390 | iTotalSliceSize += len; | ||
| 391 | encToDecSliceData (1, 0, info, len); //first slice | ||
| 392 | iTotalSliceSize += len; | ||
| 393 | //second slice loss | ||
| 394 | pData[0] = pData[1] = pData[2] = 0; | ||
| 395 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 396 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 397 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); | ||
| 398 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, iTotalSliceSize, pData, &dstBufInfo_); | ||
| 399 | EXPECT_EQ (rv, 0); //parse correct | ||
| 400 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 401 | EXPECT_EQ (rv, 0); // Reconstruct first slice OK | ||
| 402 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //slice incomplete, no output | ||
| 403 | iIdx++; | ||
| 404 | |||
| 405 | //Frame 1: P, EC_IDC=2, loss = 0 | ||
| 406 | //will clean SPS/PPS status | ||
| 407 | EncodeOneFrame (1); | ||
| 408 | encToDecData (info, len); //all slice together | ||
| 409 | pData[0] = pData[1] = pData[2] = 0; | ||
| 410 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 411 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 412 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); | ||
| 413 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 414 | EXPECT_TRUE ((rv & 32) != 0); //parse correct, but reconstruct ECed | ||
| 415 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //ECed output for frame 0 | ||
| 416 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //ECed status, reconstruction current frame 1 | ||
| 417 | EXPECT_TRUE ((rv & 32) != 0); //decoder ECed status | ||
| 418 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //ECed output for frame 1 | ||
| 419 | iIdx++; | ||
| 420 | |||
| 421 | //set EC=DISABLE | ||
| 422 | uiEcIdc = (uint32_t) (ERROR_CON_DISABLE); | ||
| 423 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 424 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 425 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 426 | //Frame 2: P, EC_IDC=0, loss = 0 | ||
| 427 | /////will clean SPS/PPS status | ||
| 428 | EncodeOneFrame (1); | ||
| 429 | encToDecData (info, len); //all slice together | ||
| 430 | pData[0] = pData[1] = pData[2] = 0; | ||
| 431 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 432 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 433 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE); | ||
| 434 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 435 | EXPECT_EQ (rv, 0); //parse correct | ||
| 436 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 437 | // Ref picture is ECed, so reconstructed picture is ECed | ||
| 438 | EXPECT_TRUE ((rv & 32) != 0); | ||
| 439 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); | ||
| 440 | iIdx++; | ||
| 441 | |||
| 442 | //set EC=SLICE_COPY | ||
| 443 | uiEcIdc = (uint32_t) (ERROR_CON_FRAME_COPY); | ||
| 444 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 445 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 446 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 447 | //Frame 3: P, EC_IDC=2, loss = 1 | ||
| 448 | EncodeOneFrame (1); | ||
| 449 | encToDecSliceData (0, 0, info, iTotalSliceSize); //slice 1 lost | ||
| 450 | encToDecSliceData (0, 1, info, len); //slice 2 | ||
| 451 | pData[0] = pData[1] = pData[2] = 0; | ||
| 452 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 453 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 454 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_FRAME_COPY); | ||
| 455 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, len, pData, &dstBufInfo_); | ||
| 456 | EXPECT_EQ (rv, 0); //parse correct | ||
| 457 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); | ||
| 458 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 459 | EXPECT_TRUE ((rv & 32) != 0); | ||
| 460 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //slice loss | ||
| 461 | iIdx++; | ||
| 462 | |||
| 463 | //set EC=DISABLE | ||
| 464 | uiEcIdc = (uint32_t) (ERROR_CON_DISABLE); | ||
| 465 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 466 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 467 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 468 | //Frame 4: P, EC_IDC=0, loss = 0 | ||
| 469 | EncodeOneFrame (1); | ||
| 470 | encToDecData (info, len); //all slice | ||
| 471 | pData[0] = pData[1] = pData[2] = 0; | ||
| 472 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 473 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 474 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE); | ||
| 475 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 476 | EXPECT_TRUE (rv != 0); | ||
| 477 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); // EC_IDC=0, previous picture slice lost, no output | ||
| 478 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 479 | EXPECT_TRUE (rv != 0); | ||
| 480 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); // No ref picture, no output | ||
| 481 | iIdx++; | ||
| 482 | |||
| 483 | } | ||
| 484 | |||
| 485 | |||
| 486 | |||
| 487 | //This case contain 2 slices per picture for no IDR loss | ||
| 488 | //coding order: 0 1 2 3 4 5 | ||
| 489 | //frame type IDR P P P P IDR | ||
| 490 | //EC_IDC 0 2 0 2 0 ^2^ | ||
| 491 | //loss (2 slice: 1,2): 0 0 1 2 0 0 | ||
| 492 | |||
| 493 | TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificSliceChange_IDRNoLoss) { | ||
| 494 | uint32_t uiEcIdc; | ||
| 495 | uint32_t uiGet; | ||
| 496 | EncodeDecodeFileParamBase p = kFileParamArray[0]; | ||
| 497 | prepareParamDefault (1, 2, p.width, p.height, p.frameRate, ¶m_); | ||
| 498 | param_.iSpatialLayerNum = 1; | ||
| 499 | encoder_->Uninitialize(); | ||
| 500 | int rv = encoder_->InitializeExt (¶m_); | ||
| 501 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 502 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 503 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY | ||
| 504 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 505 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 506 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 507 | |||
| 508 | //Start for enc/dec | ||
| 509 | int iIdx = 0; | ||
| 510 | int len = 0; | ||
| 511 | unsigned char* pData[3] = { NULL }; | ||
| 512 | int iTotalSliceSize = 0; | ||
| 513 | |||
| 514 | InitialEncDec (p.width, p.height); | ||
| 515 | |||
| 516 | //set EC=DISABLE | ||
| 517 | uiEcIdc = (uint32_t) (ERROR_CON_DISABLE); | ||
| 518 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 519 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 520 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 521 | //Frame 0: IDR, EC_IDC=0, loss = 0 | ||
| 522 | //Expected result: all OK, 2nd Output | ||
| 523 | EncodeOneFrame (1); | ||
| 524 | encToDecData (info, len); //all slice | ||
| 525 | pData[0] = pData[1] = pData[2] = 0; | ||
| 526 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 527 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 528 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE); | ||
| 529 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 530 | EXPECT_EQ (rv, 0); //parse correct | ||
| 531 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 532 | EXPECT_EQ (rv, 0); //parse correct | ||
| 533 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //output frame 0 | ||
| 534 | iIdx++; | ||
| 535 | |||
| 536 | //Frame 1: P, EC_IDC=0, loss = 0 | ||
| 537 | //Expected result: all OK, 2nd Output | ||
| 538 | EncodeOneFrame (1); | ||
| 539 | encToDecData (info, len); //all slice together | ||
| 540 | pData[0] = pData[1] = pData[2] = 0; | ||
| 541 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 542 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 543 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE); | ||
| 544 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 545 | EXPECT_EQ (rv, 0); //parse correct | ||
| 546 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //ECed output for frame 0 | ||
| 547 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction current frame 1 | ||
| 548 | EXPECT_EQ (rv, 0); //parse correct | ||
| 549 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //ECed output for frame 1 | ||
| 550 | iIdx++; | ||
| 551 | |||
| 552 | //Frame 2: P, EC_IDC=0, loss = 1 | ||
| 553 | //Expected result: all OK, no Output | ||
| 554 | EncodeOneFrame (1); | ||
| 555 | encToDecSliceData (0, 0, info, iTotalSliceSize); // slice 1 lost | ||
| 556 | encToDecSliceData (0, 1, info, len); // slice 2 only | ||
| 557 | pData[0] = pData[1] = pData[2] = 0; | ||
| 558 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 559 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 560 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE); | ||
| 561 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, len, pData, &dstBufInfo_); | ||
| 562 | EXPECT_EQ (rv, 0); //parse correct | ||
| 563 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); | ||
| 564 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 565 | EXPECT_EQ (rv, 0); //parse correct | ||
| 566 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); | ||
| 567 | iIdx++; | ||
| 568 | |||
| 569 | //set EC=SLICE_COPY | ||
| 570 | uiEcIdc = (uint32_t) (ERROR_CON_SLICE_COPY); | ||
| 571 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 572 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 573 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 574 | //Frame 3: P, EC_IDC=2, loss = 2 | ||
| 575 | //Expected result: neither OK, 1st Output | ||
| 576 | EncodeOneFrame (1); | ||
| 577 | encToDecSliceData (0, 0, info, len); //slice 1 only | ||
| 578 | pData[0] = pData[1] = pData[2] = 0; | ||
| 579 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 580 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 581 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); | ||
| 582 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 583 | EXPECT_TRUE ((rv & 32) != 0); //parse OK but frame 2 ECed | ||
| 584 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //slice loss but ECed output Frame 2 | ||
| 585 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 586 | EXPECT_TRUE ((rv & 32) != 0); | ||
| 587 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //slice loss | ||
| 588 | iIdx++; | ||
| 589 | |||
| 590 | //set EC=DISABLE | ||
| 591 | uiEcIdc = (uint32_t) (ERROR_CON_DISABLE); | ||
| 592 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 593 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 594 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 595 | //Frame 4: P, EC_IDC=0, loss = 0 | ||
| 596 | //Expected result: depends on DecodeFrame2 result. If OK, output; else ,no output | ||
| 597 | EncodeOneFrame (1); | ||
| 598 | encToDecData (info, len); //all slice | ||
| 599 | pData[0] = pData[1] = pData[2] = 0; | ||
| 600 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 601 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 602 | EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE); | ||
| 603 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 604 | EXPECT_TRUE (rv != 0); //previous slice not outputted, will return error due to incomplete frame | ||
| 605 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //output previous pic | ||
| 606 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction, | ||
| 607 | // previous frame NOT output, no ref | ||
| 608 | EXPECT_TRUE (rv != 0); | ||
| 609 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //output previous pic | ||
| 610 | iIdx++; | ||
| 611 | |||
| 612 | //Frame 5: IDR, EC_IDC=2->0, loss = 0 | ||
| 613 | //Expected result: depends on DecodeFrame2 result. If OK, output; else ,no output | ||
| 614 | int32_t iIDRPeriod = 1; | ||
| 615 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 616 | EncodeOneFrame (1); | ||
| 617 | EXPECT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 618 | encToDecSliceData (0, 0, info, len); //SPS | ||
| 619 | iTotalSliceSize = len; | ||
| 620 | encToDecSliceData (0, 1, info, len); //PPS | ||
| 621 | iTotalSliceSize += len; | ||
| 622 | encToDecSliceData (1, 0, info, len); //slice 1 | ||
| 623 | iTotalSliceSize += len; | ||
| 624 | //set EC=SLICE_COPY for slice 1 | ||
| 625 | uiEcIdc = (uint32_t) (ERROR_CON_SLICE_COPY); | ||
| 626 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 627 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 628 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 629 | pData[0] = pData[1] = pData[2] = 0; | ||
| 630 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 631 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, iTotalSliceSize, pData, &dstBufInfo_); | ||
| 632 | EXPECT_TRUE (rv == 0); // IDR status return error_free | ||
| 633 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //frame incomplete | ||
| 634 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction, | ||
| 635 | EXPECT_TRUE (rv == 0); | ||
| 636 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //output previous pic | ||
| 637 | //set EC=DISABLE for slice 2 | ||
| 638 | encToDecSliceData (1, 1, info, len); //slice 1 | ||
| 639 | uiEcIdc = (int) (ERROR_CON_DISABLE); | ||
| 640 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 641 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 642 | EXPECT_EQ (uiGet, uiEcIdc); | ||
| 643 | pData[0] = pData[1] = pData[2] = 0; | ||
| 644 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 645 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, len, pData, &dstBufInfo_); | ||
| 646 | EXPECT_EQ (rv, 0); //Parse correct under no EC | ||
| 647 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 0); //frame incomplete | ||
| 648 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction, | ||
| 649 | EXPECT_EQ (rv, 0); | ||
| 650 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); //output previous pic | ||
| 651 | iIdx++; | ||
| 652 | |||
| 653 | } | ||
| 654 | |||
| 655 | static const EncodeDecodeFileParamBase kSVCSwitch[] = { | ||
| 656 | {300, 160, 96, 6.0f, 2, 1, "120012130101012311201221323"}, | ||
| 657 | }; | ||
| 658 | |||
| 659 | TEST_F (EncodeDecodeTestAPI, Engine_SVC_Switch_I) { | ||
| 660 | SLTRMarkingFeedback m_LTR_Marking_Feedback; | ||
| 661 | SLTRRecoverRequest m_LTR_Recover_Request; | ||
| 662 | m_LTR_Recover_Request.uiIDRPicId = 0; | ||
| 663 | EncodeDecodeFileParamBase p = kSVCSwitch[0]; | ||
| 664 | p.width = p.width << 2; | ||
| 665 | p.height = p.height << 2; | ||
| 666 | prepareParamDefault (4, p.slicenum, p.width, p.height, p.frameRate, ¶m_); | ||
| 667 | param_.iTemporalLayerNum = (rand() % 4) + 1; | ||
| 668 | param_.iSpatialLayerNum = 4; | ||
| 669 | encoder_->Uninitialize(); | ||
| 670 | int rv = encoder_->InitializeExt (¶m_); | ||
| 671 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 672 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 673 | |||
| 674 | InitialEncDec (p.width, p.height); | ||
| 675 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 676 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 677 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 678 | int32_t iSpsPpsIdAddition = 1; | ||
| 679 | encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition); | ||
| 680 | int32_t iIDRPeriod = (int32_t) pow (2.0f, (param_.iTemporalLayerNum - 1)) * ((rand() % 5) + 1); | ||
| 681 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 682 | SLTRConfig sLtrConfigVal; | ||
| 683 | sLtrConfigVal.bEnableLongTermReference = 1; | ||
| 684 | sLtrConfigVal.iLTRRefNum = 1; | ||
| 685 | encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal); | ||
| 686 | int32_t iLtrPeriod = 2; | ||
| 687 | encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod); | ||
| 688 | int iIdx = 0; | ||
| 689 | int iTarDid = 0; | ||
| 690 | while (iIdx <= p.numframes) { | ||
| 691 | EncodeOneFrame (1); | ||
| 692 | if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) { | ||
| 693 | ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 694 | } | ||
| 695 | if (info.eFrameType == videoFrameTypeIDR) { | ||
| 696 | iTarDid = rand() % 4; | ||
| 697 | } | ||
| 698 | //decoding after each encoding frame | ||
| 699 | int len = 0; | ||
| 700 | encToDecData (info, len); | ||
| 701 | unsigned char* pData[3] = { NULL }; | ||
| 702 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 703 | |||
| 704 | ExtractDidNal (&info, len, &m_SLostSim, iTarDid); | ||
| 705 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 706 | ASSERT_EQ (rv, 0); | ||
| 707 | int iTid = -1; | ||
| 708 | decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid); | ||
| 709 | ASSERT_EQ (iTid, -1); | ||
| 710 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 711 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true); | ||
| 712 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 713 | ASSERT_EQ (rv, 0); | ||
| 714 | decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid); | ||
| 715 | ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId); | ||
| 716 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true); | ||
| 717 | LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv); | ||
| 718 | iIdx++; | ||
| 719 | } | ||
| 720 | } | ||
| 721 | |||
| 722 | TEST_F (EncodeDecodeTestAPI, Engine_SVC_Switch_P) { | ||
| 723 | SLTRMarkingFeedback m_LTR_Marking_Feedback; | ||
| 724 | SLTRRecoverRequest m_LTR_Recover_Request; | ||
| 725 | m_LTR_Recover_Request.uiIDRPicId = 0; | ||
| 726 | EncodeDecodeFileParamBase p = kSVCSwitch[0]; | ||
| 727 | int iTarDid = 0; | ||
| 728 | int iLastDid = 0; | ||
| 729 | p.width = p.width << 2; | ||
| 730 | p.height = p.height << 2; | ||
| 731 | prepareParamDefault (4, p.slicenum, p.width, p.height, p.frameRate, ¶m_); | ||
| 732 | param_.iTemporalLayerNum = (rand() % 4) + 1; | ||
| 733 | param_.iSpatialLayerNum = 4; | ||
| 734 | encoder_->Uninitialize(); | ||
| 735 | int rv = encoder_->InitializeExt (¶m_); | ||
| 736 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 737 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 738 | |||
| 739 | InitialEncDec (p.width, p.height); | ||
| 740 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 741 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 742 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 743 | int32_t iSpsPpsIdAddition = 1; | ||
| 744 | encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition); | ||
| 745 | int32_t iIDRPeriod = 60; | ||
| 746 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 747 | SLTRConfig sLtrConfigVal; | ||
| 748 | sLtrConfigVal.bEnableLongTermReference = 1; | ||
| 749 | sLtrConfigVal.iLTRRefNum = 1; | ||
| 750 | encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal); | ||
| 751 | int32_t iLtrPeriod = 2; | ||
| 752 | encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod); | ||
| 753 | int iIdx = 0; | ||
| 754 | |||
| 755 | while (iIdx <= p.numframes) { | ||
| 756 | EncodeOneFrame (1); | ||
| 757 | if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) { | ||
| 758 | ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 759 | } | ||
| 760 | //decoding after each encoding frame | ||
| 761 | int len = 0; | ||
| 762 | encToDecData (info, len); | ||
| 763 | unsigned char* pData[3] = { NULL }; | ||
| 764 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 765 | if (iIdx < (int) strlen (p.pLossSequence)) { | ||
| 766 | switch (p.pLossSequence[iIdx]) { | ||
| 767 | case '0': | ||
| 768 | iTarDid = 0; | ||
| 769 | break; | ||
| 770 | case '1': | ||
| 771 | iTarDid = 1; | ||
| 772 | break; | ||
| 773 | case '2': | ||
| 774 | iTarDid = 2; | ||
| 775 | break; | ||
| 776 | case '3': | ||
| 777 | iTarDid = 3; | ||
| 778 | break; | ||
| 779 | default : | ||
| 780 | iTarDid = rand() % 4; | ||
| 781 | break; | ||
| 782 | } | ||
| 783 | } else { | ||
| 784 | iTarDid = rand() % 4; | ||
| 785 | } | ||
| 786 | |||
| 787 | ExtractDidNal (&info, len, &m_SLostSim, iTarDid); | ||
| 788 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 789 | int iTid = -1; | ||
| 790 | decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid); | ||
| 791 | ASSERT_EQ (iTid, -1); | ||
| 792 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 793 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, false); | ||
| 794 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 795 | if (info.eFrameType == videoFrameTypeP && iIdx > 0 && iLastDid != iTarDid) { | ||
| 796 | ASSERT_NE (rv, 0); | ||
| 797 | } else if (info.eFrameType == videoFrameTypeIDR) { | ||
| 798 | ASSERT_EQ (rv, 0); | ||
| 799 | } | ||
| 800 | decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid); | ||
| 801 | ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId); | ||
| 802 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, false); | ||
| 803 | LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv); | ||
| 804 | iIdx++; | ||
| 805 | iLastDid = iTarDid; | ||
| 806 | } | ||
| 807 | } | ||
| 808 | |||
| 809 | |||