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