Showing the changes to test/api/encode_decode_api_test.cpp (1 of 8 files). Show all
Unified · Split
| @@ -3921,3 +3921,122 @@ TEST_F (EncodeDecodeTestAPI, ThreadNumAndSliceNum) { · 3920 unmodified lines | |||
| 3921 | } | 3921 | } |
| 3922 | } | 3922 | } |
| 3923 | 3923 | ||
| 3924 | |||
| 3925 | TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) { | ||
| 3926 | int iSpatialLayerNum = 1; | ||
| 3927 | int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, (64 << 2), MAX_WIDTH); | ||
| 3928 | int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, (64 << 2), | ||
| 3929 | 2240);//TODO: use MAX_HEIGHT after the limit is removed | ||
| 3930 | float fFrameRate = rand() + 0.5f; | ||
| 3931 | int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM); | ||
| 3932 | |||
| 3933 | // prepare params | ||
| 3934 | SEncParamExt sParam; | ||
| 3935 | encoder_->GetDefaultParams (&sParam); | ||
| 3936 | prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam); | ||
| 3937 | sParam.iMultipleThreadIdc = (rand() % 8) + 1; | ||
| 3938 | sParam.bSimulcastAVC = 1; | ||
| 3939 | sParam.sSpatialLayers[0].iVideoWidth = iWidth; | ||
| 3940 | sParam.sSpatialLayers[0].iVideoHeight = iHeight; | ||
| 3941 | sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE; | ||
| 3942 | sParam.sSpatialLayers[0].sSliceArgument.uiSliceNum = sParam.iMultipleThreadIdc; | ||
| 3943 | |||
| 3944 | int rv = encoder_->InitializeExt (&sParam); | ||
| 3945 | ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;; | ||
| 3946 | |||
| 3947 | unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM]; | ||
| 3948 | ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM]; | ||
| 3949 | |||
| 3950 | int iIdx = 0; | ||
| 3951 | int aLen[MAX_SPATIAL_LAYER_NUM] = {}; | ||
| 3952 | |||
| 3953 | //create decoder | ||
| 3954 | for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | ||
| 3955 | pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2)); | ||
| 3956 | EXPECT_TRUE (pBsBuf[iIdx] != NULL); | ||
| 3957 | |||
| 3958 | long rv = WelsCreateDecoder (&decoder[iIdx]); | ||
| 3959 | ASSERT_EQ (0, rv); | ||
| 3960 | EXPECT_TRUE (decoder[iIdx] != NULL); | ||
| 3961 | |||
| 3962 | SDecodingParam decParam; | ||
| 3963 | memset (&decParam, 0, sizeof (SDecodingParam)); | ||
| 3964 | decParam.eOutputColorFormat = videoFormatI420; | ||
| 3965 | decParam.uiTargetDqLayer = UCHAR_MAX; | ||
| 3966 | decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY; | ||
| 3967 | decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT; | ||
| 3968 | |||
| 3969 | rv = decoder[iIdx]->Initialize (&decParam); | ||
| 3970 | ASSERT_EQ (0, rv); | ||
| 3971 | } | ||
| 3972 | |||
| 3973 | rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sParam); | ||
| 3974 | ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed pParam: rv = " << rv; | ||
| 3975 | |||
| 3976 | //begin testing | ||
| 3977 | for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) { | ||
| 3978 | int iResult; | ||
| 3979 | int iLayerLen = 0; | ||
| 3980 | unsigned char* pData[3] = { NULL }; | ||
| 3981 | |||
| 3982 | InitialEncDec (sParam.iPicWidth, sParam.iPicHeight); | ||
| 3983 | int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2; | ||
| 3984 | memset (buf_.data(), rand() % 256, (frameSize >> 2)); | ||
| 3985 | memset (buf_.data() + (frameSize >> 2), rand() % 256, (frameSize - (frameSize >> 2))); | ||
| 3986 | |||
| 3987 | int iStartStrip = 0; | ||
| 3988 | //during first half the complex strip is at top, then during the second half it is at bottom | ||
| 3989 | if (iFrame > iEncFrameNum / 2) { | ||
| 3990 | iStartStrip = EncPic.iPicHeight * EncPic.iPicWidth; | ||
| 3991 | } | ||
| 3992 | for (int k = 0; k < (EncPic.iPicHeight / 2); k++) { | ||
| 3993 | memset (buf_.data() + k * EncPic.iPicWidth + iStartStrip, rand() % 256, (EncPic.iPicWidth)); | ||
| 3994 | } | ||
| 3995 | |||
| 3996 | int rv = encoder_->EncodeFrame (&EncPic, &info); | ||
| 3997 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 3998 | |||
| 3999 | // init | ||
| 4000 | for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | ||
| 4001 | aLen[iIdx] = 0; | ||
| 4002 | } | ||
| 4003 | for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) { | ||
| 4004 | iLayerLen = 0; | ||
| 4005 | const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer]; | ||
| 4006 | for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) { | ||
| 4007 | iLayerLen += layerInfo.pNalLengthInByte[iNal]; | ||
| 4008 | } | ||
| 4009 | |||
| 4010 | iIdx = layerInfo.uiSpatialId; | ||
| 4011 | EXPECT_TRUE (iIdx < iSpatialLayerNum) << "iIdx = " << iIdx << ", iSpatialLayerNum = " << iSpatialLayerNum; | ||
| 4012 | memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char)); | ||
| 4013 | aLen[iIdx] += iLayerLen; | ||
| 4014 | } | ||
| 4015 | |||
| 4016 | for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | ||
| 4017 | pData[0] = pData[1] = pData[2] = 0; | ||
| 4018 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 4019 | |||
| 4020 | #ifdef DEBUG_FILE_SAVE4 | ||
| 4021 | fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]); | ||
| 4022 | #endif | ||
| 4023 | iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_); | ||
| 4024 | EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx; | ||
| 4025 | |||
| 4026 | iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); | ||
| 4027 | EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx; | ||
| 4028 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx; | ||
| 4029 | } | ||
| 4030 | } | ||
| 4031 | |||
| 4032 | for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | ||
| 4033 | free (pBsBuf[iIdx]); | ||
| 4034 | |||
| 4035 | if (decoder[iIdx] != NULL) { | ||
| 4036 | decoder[iIdx]->Uninitialize(); | ||
| 4037 | WelsDestroyDecoder (decoder[iIdx]); | ||
| 4038 | } | ||
| 4039 | |||
| 4040 | } | ||
| 4041 | } | ||
| 4042 | |||