Showing the changes to test/api/encode_decode_api_test.cpp (1 of 16 files). Show all
Unified · Split
| @@ -11,168 +11,183 @@ · 10 unmodified lines | ||
| 11 | 11 | using namespace WelsCommon; |
| 12 | 12 | |
| 13 | 13 | |
| 14 | −void EncodeDecodeTestBase::prepareParam (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) { | |
| 15 | − pParam->iUsageType = CAMERA_VIDEO_REAL_TIME; | |
| 16 | − pParam->iPicWidth = width; | |
| 17 | − pParam->iPicHeight = height; | |
| 18 | − pParam->fMaxFrameRate = framerate; | |
| 19 | − pParam->iRCMode = RC_OFF_MODE; //rc off | |
| 20 | − pParam->iMultipleThreadIdc = 1; //single thread | |
| 21 | − pParam->iSpatialLayerNum = iLayers; | |
| 22 | − pParam->iNumRefFrame = AUTO_REF_PIC_COUNT; | |
| 23 | − for (int i = 0; i < iLayers; i++) { | |
| 24 | − pParam->sSpatialLayers[i].iVideoWidth = width >> (iLayers - i - 1); | |
| 25 | − pParam->sSpatialLayers[i].iVideoHeight = height >> (iLayers - i - 1); | |
| 26 | − pParam->sSpatialLayers[i].fFrameRate = framerate; | |
| 27 | − pParam->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE; | |
| 28 | − pParam->sSpatialLayers[i].sSliceArgument.uiSliceNum = iSlices; | |
| 29 | − } | |
| 14 | +void EncodeDecodeTestBase::prepareParam (int iLayers, int iSlices, int width, int height, float framerate, | |
| 15 | + SEncParamExt* pParam) { | |
| 16 | + pParam->iUsageType = CAMERA_VIDEO_REAL_TIME; | |
| 17 | + pParam->iPicWidth = width; | |
| 18 | + pParam->iPicHeight = height; | |
| 19 | + pParam->fMaxFrameRate = framerate; | |
| 20 | + pParam->iRCMode = RC_OFF_MODE; //rc off | |
| 21 | + pParam->iMultipleThreadIdc = 1; //single thread | |
| 22 | + pParam->iSpatialLayerNum = iLayers; | |
| 23 | + pParam->iNumRefFrame = AUTO_REF_PIC_COUNT; | |
| 24 | + for (int i = 0; i < iLayers; i++) { | |
| 25 | + pParam->sSpatialLayers[i].iVideoWidth = width >> (iLayers - i - 1); | |
| 26 | + pParam->sSpatialLayers[i].iVideoHeight = height >> (iLayers - i - 1); | |
| 27 | + pParam->sSpatialLayers[i].fFrameRate = framerate; | |
| 28 | + pParam->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE; | |
| 29 | + pParam->sSpatialLayers[i].sSliceArgument.uiSliceNum = iSlices; | |
| 30 | + } | |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | −void EncodeDecodeTestBase::prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) { | |
| 33 | − //for encoder | |
| 34 | − //I420: 1(Y) + 1/4(U) + 1/4(V) | |
| 35 | − int frameSize = EncDecFileParam.width * EncDecFileParam.height * 3 / 2; | |
| 36 | − buf_.SetLength (frameSize); | |
| 37 | − ASSERT_TRUE (buf_.Length() == (size_t)frameSize); | |
| 38 | − memset (&EncPic, 0, sizeof (SSourcePicture)); | |
| 39 | − EncPic.iPicWidth = EncDecFileParam.width; | |
| 40 | − EncPic.iPicHeight = EncDecFileParam.height; | |
| 41 | − EncPic.iColorFormat = videoFormatI420; | |
| 42 | − EncPic.iStride[0] = EncPic.iPicWidth; | |
| 43 | − EncPic.iStride[1] = EncPic.iStride[2] = EncPic.iPicWidth >> 1; | |
| 44 | − EncPic.pData[0] = buf_.data(); | |
| 45 | − EncPic.pData[1] = EncPic.pData[0] + EncDecFileParam.width * EncDecFileParam.height; | |
| 46 | − EncPic.pData[2] = EncPic.pData[1] + (EncDecFileParam.width * EncDecFileParam.height >> 2); | |
| 47 | − //for decoder | |
| 48 | − memset (&info, 0, sizeof (SFrameBSInfo)); | |
| 49 | − //set a fixed random value | |
| 50 | − iRandValue = rand() % 256; | |
| 33 | +bool EncodeDecodeTestBase::prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) { | |
| 34 | + //for encoder | |
| 35 | + //I420: 1(Y) + 1/4(U) + 1/4(V) | |
| 36 | + int frameSize = EncDecFileParam.width * EncDecFileParam.height * 3 / 2; | |
| 37 | + buf_.SetLength (frameSize); | |
| 38 | + if (buf_.Length() != (size_t)frameSize) { | |
| 39 | + printf ("buf_.Length() failed! frameSize = %d\n", frameSize); | |
| 40 | + return false; | |
| 41 | + } | |
| 42 | + memset (&EncPic, 0, sizeof (SSourcePicture)); | |
| 43 | + EncPic.iPicWidth = EncDecFileParam.width; | |
| 44 | + EncPic.iPicHeight = EncDecFileParam.height; | |
| 45 | + EncPic.iColorFormat = videoFormatI420; | |
| 46 | + EncPic.iStride[0] = EncPic.iPicWidth; | |
| 47 | + EncPic.iStride[1] = EncPic.iStride[2] = EncPic.iPicWidth >> 1; | |
| 48 | + EncPic.pData[0] = buf_.data(); | |
| 49 | + EncPic.pData[1] = EncPic.pData[0] + EncDecFileParam.width * EncDecFileParam.height; | |
| 50 | + EncPic.pData[2] = EncPic.pData[1] + (EncDecFileParam.width * EncDecFileParam.height >> 2); | |
| 51 | + //for decoder | |
| 52 | + memset (&info, 0, sizeof (SFrameBSInfo)); | |
| 53 | + //set a fixed random value | |
| 54 | + iRandValue = rand() % 256; | |
| 55 | + return true; | |
| 51 | 56 | } |
| 52 | 57 | |
| 53 | 58 | void EncodeDecodeTestBase::encToDecData (const SFrameBSInfo& info, int& len) { |
| 54 | − len = 0; | |
| 55 | − for (int i = 0; i < info.iLayerNum; ++i) { | |
| 56 | − const SLayerBSInfo& layerInfo = info.sLayerInfo[i]; | |
| 57 | − for (int j = 0; j < layerInfo.iNalCount; ++j) { | |
| 58 | − len += layerInfo.pNalLengthInByte[j]; | |
| 59 | − } | |
| 59 | + len = 0; | |
| 60 | + for (int i = 0; i < info.iLayerNum; ++i) { | |
| 61 | + const SLayerBSInfo& layerInfo = info.sLayerInfo[i]; | |
| 62 | + for (int j = 0; j < layerInfo.iNalCount; ++j) { | |
| 63 | + len += layerInfo.pNalLengthInByte[j]; | |
| 60 | 64 | } |
| 65 | + } | |
| 61 | 66 | } |
| 62 | 67 | |
| 63 | −void EncodeDecodeTestBase::encToDecSliceData (const int iLayerNum, const int iSliceNum, const SFrameBSInfo& info, int& len) { | |
| 64 | − ASSERT_TRUE (iLayerNum < MAX_LAYER_NUM_OF_FRAME); | |
| 65 | − len = 0; | |
| 66 | − const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayerNum]; | |
| 67 | − if (iSliceNum < layerInfo.iNalCount) | |
| 68 | − len = layerInfo.pNalLengthInByte[iSliceNum]; | |
| 68 | +void EncodeDecodeTestBase::encToDecSliceData (const int iLayerNum, const int iSliceNum, const SFrameBSInfo& info, | |
| 69 | + int& len) { | |
| 70 | + ASSERT_TRUE (iLayerNum < MAX_LAYER_NUM_OF_FRAME); | |
| 71 | + len = 0; | |
| 72 | + const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayerNum]; | |
| 73 | + if (iSliceNum < layerInfo.iNalCount) | |
| 74 | + len = layerInfo.pNalLengthInByte[iSliceNum]; | |
| 69 | 75 | } |
| 70 | 76 | |
| 71 | −void EncodeDecodeTestAPIBase::prepareParam0 (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) { | |
| 72 | − memset (pParam, 0, sizeof (SEncParamExt)); | |
| 73 | − EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam); | |
| 77 | +void EncodeDecodeTestAPIBase::prepareParam0 (int iLayers, int iSlices, int width, int height, float framerate, | |
| 78 | + SEncParamExt* pParam) { | |
| 79 | + memset (pParam, 0, sizeof (SEncParamExt)); | |
| 80 | + EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam); | |
| 74 | 81 | } |
| 75 | 82 | |
| 76 | −void EncodeDecodeTestAPIBase::prepareParamDefault (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) { | |
| 77 | − memset (pParam, 0, sizeof (SEncParamExt)); | |
| 78 | − encoder_->GetDefaultParams (pParam); | |
| 79 | − EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam); | |
| 83 | +void EncodeDecodeTestAPIBase::prepareParamDefault (int iLayers, int iSlices, int width, int height, float framerate, | |
| 84 | + SEncParamExt* pParam) { | |
| 85 | + memset (pParam, 0, sizeof (SEncParamExt)); | |
| 86 | + encoder_->GetDefaultParams (pParam); | |
| 87 | + EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam); | |
| 80 | 88 | } |
| 81 | 89 | |
| 82 | 90 | |
| 83 | 91 | void EncodeDecodeTestAPIBase::EncodeOneFrame (int iCheckTypeIndex) { |
| 84 | − int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2; | |
| 85 | − int lumaSize = EncPic.iPicWidth * EncPic.iPicHeight; | |
| 86 | − memset (buf_.data(), iRandValue, lumaSize); | |
| 87 | − memset (buf_.data() + lumaSize, rand() % 256, (frameSize - lumaSize)); | |
| 88 | − int rv = encoder_->EncodeFrame (&EncPic, &info); | |
| 89 | − if (0 == iCheckTypeIndex) | |
| 90 | − ASSERT_TRUE (rv == cmResultSuccess); | |
| 91 | − else if (1 == iCheckTypeIndex) | |
| 92 | − ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason); | |
| 92 | + int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2; | |
| 93 | + int lumaSize = EncPic.iPicWidth * EncPic.iPicHeight; | |
| 94 | + memset (buf_.data(), iRandValue, lumaSize); | |
| 95 | + memset (buf_.data() + lumaSize, rand() % 256, (frameSize - lumaSize)); | |
| 96 | + int rv = encoder_->EncodeFrame (&EncPic, &info); | |
| 97 | + if (0 == iCheckTypeIndex) | |
| 98 | + ASSERT_TRUE (rv == cmResultSuccess); | |
| 99 | + else if (1 == iCheckTypeIndex) | |
| 100 | + ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason); | |
| 93 | 101 | } |
| 94 | 102 | |
| 95 | −void EncodeDecodeTestAPIBase::EncDecOneFrame (const int iWidth, const int iHeight, const int iFrame, FILE* pfEnc) { | |
| 96 | − int iLen = 0, rv; | |
| 97 | − InitialEncDec (iWidth, iHeight); | |
| 98 | − EncodeOneFrame (iFrame); | |
| 99 | − | |
| 100 | − //extract target layer data | |
| 101 | − encToDecData (info, iLen); | |
| 102 | − //call decoder | |
| 103 | − unsigned char* pData[3] = { NULL }; | |
| 104 | − memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | |
| 105 | − rv = decoder_->DecodeFrameNoDelay (info.sLayerInfo[0].pBsBuf, iLen, pData, &dstBufInfo_); | |
| 106 | − EXPECT_TRUE (rv == cmResultSuccess) << " rv = " << rv << " iFrameIdx = " << iFrame; | |
| 107 | − if (NULL != pfEnc) { | |
| 108 | − fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, pfEnc); | |
| 109 | − } | |
| 103 | +bool EncodeDecodeTestAPIBase::EncDecOneFrame (const int iWidth, const int iHeight, const int iFrame, FILE* pfEnc) { | |
| 104 | + int iLen = 0, rv; | |
| 105 | + if (!InitialEncDec (iWidth, iHeight)) | |
| 106 | + return false; | |
| 107 | + EncodeOneFrame (iFrame); | |
| 108 | + | |
| 109 | + //extract target layer data | |
| 110 | + encToDecData (info, iLen); | |
| 111 | + //call decoder | |
| 112 | + unsigned char* pData[3] = { NULL }; | |
| 113 | + memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | |
| 114 | + rv = decoder_->DecodeFrameNoDelay (info.sLayerInfo[0].pBsBuf, iLen, pData, &dstBufInfo_); | |
| 115 | + EXPECT_TRUE (rv == cmResultSuccess) << " rv = " << rv << " iFrameIdx = " << iFrame; | |
| 116 | + if (NULL != pfEnc) { | |
| 117 | + fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, pfEnc); | |
| 118 | + } | |
| 119 | + return true; | |
| 110 | 120 | } |
| 111 | 121 | |
| 112 | −void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, int iSpatialLayerNum, | |
| 113 | − int iEncFrameNum, | |
| 114 | − int iSaveFileIdx) { | |
| 115 | − int aLen[MAX_SPATIAL_LAYER_NUM] = {0, 0, 0, 0}; | |
| 116 | − | |
| 117 | − FILE* fEnc[MAX_SPATIAL_LAYER_NUM]; | |
| 118 | − if (iSaveFileIdx == 1) { | |
| 119 | − fEnc[0] = fopen ("enc00.264", "wb"); | |
| 120 | − fEnc[1] = fopen ("enc01.264", "wb"); | |
| 121 | − fEnc[2] = fopen ("enc02.264", "wb"); | |
| 122 | − fEnc[3] = fopen ("enc03.264", "wb"); | |
| 123 | − } else if (iSaveFileIdx > 1) { | |
| 124 | − fEnc[0] = fopen ("enc10.264", "wb"); | |
| 125 | − fEnc[1] = fopen ("enc11.264", "wb"); | |
| 126 | − fEnc[2] = fopen ("enc12.264", "wb"); | |
| 127 | − fEnc[3] = fopen ("enc13.264", "wb"); | |
| 128 | − } | |
| 122 | +bool EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, | |
| 123 | + int iSpatialLayerNum, | |
| 124 | + int iEncFrameNum, | |
| 125 | + int iSaveFileIdx) { | |
| 126 | + int aLen[MAX_SPATIAL_LAYER_NUM] = {0, 0, 0, 0}; | |
| 127 | + | |
| 128 | + FILE* fEnc[MAX_SPATIAL_LAYER_NUM]; | |
| 129 | + if (iSaveFileIdx == 1) { | |
| 130 | + fEnc[0] = fopen ("enc00.264", "wb"); | |
| 131 | + fEnc[1] = fopen ("enc01.264", "wb"); | |
| 132 | + fEnc[2] = fopen ("enc02.264", "wb"); | |
| 133 | + fEnc[3] = fopen ("enc03.264", "wb"); | |
| 134 | + } else if (iSaveFileIdx > 1) { | |
| 135 | + fEnc[0] = fopen ("enc10.264", "wb"); | |
| 136 | + fEnc[1] = fopen ("enc11.264", "wb"); | |
| 137 | + fEnc[2] = fopen ("enc12.264", "wb"); | |
| 138 | + fEnc[3] = fopen ("enc13.264", "wb"); | |
| 139 | + } | |
| 129 | 140 | |
| 130 | − int rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, pParam); | |
| 131 | − ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed pParam: rv = " << rv; | |
| 141 | + int rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, pParam); | |
| 142 | + if (rv != cmResultSuccess) { | |
| 143 | + printf ("SetOption Failed, rv = %d\n", rv); | |
| 144 | + return false; | |
| 145 | + } | |
| 132 | 146 | |
| 133 | − int iIdx; | |
| 134 | − //begin testing | |
| 135 | − for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) { | |
| 136 | − int iResult; | |
| 137 | − int iLayerLen = 0; | |
| 138 | − unsigned char* pData[3] = { NULL }; | |
| 147 | + int iIdx; | |
| 148 | + //begin testing | |
| 149 | + for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) { | |
| 150 | + int iResult; | |
| 151 | + int iLayerLen = 0; | |
| 152 | + unsigned char* pData[3] = { NULL }; | |
| 139 | 153 | |
| 140 | − InitialEncDec (pParam->iPicWidth, pParam->iPicHeight); | |
| 141 | − EncodeOneFrame (0); | |
| 154 | + if (!InitialEncDec (pParam->iPicWidth, pParam->iPicHeight)) | |
| 155 | + return false; | |
| 156 | + EncodeOneFrame (0); | |
| 142 | 157 | |
| 143 | − // init | |
| 144 | − for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | |
| 145 | − aLen[iIdx] = 0; | |
| 158 | + // init | |
| 159 | + for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | |
| 160 | + aLen[iIdx] = 0; | |
| 161 | + } | |
| 162 | + for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) { | |
| 163 | + iLayerLen = 0; | |
| 164 | + const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer]; | |
| 165 | + for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) { | |
| 166 | + iLayerLen += layerInfo.pNalLengthInByte[iNal]; | |
| 146 | 167 | } |
| 147 | − for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) { | |
| 148 | − iLayerLen = 0; | |
| 149 | − const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer]; | |
| 150 | − for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) { | |
| 151 | − iLayerLen += layerInfo.pNalLengthInByte[iNal]; | |
| 152 | − } | |
| 153 | 168 | |
| 154 | − iIdx = layerInfo.uiSpatialId; | |
| 155 | − EXPECT_TRUE (iIdx < iSpatialLayerNum) << "iIdx = " << iIdx << ", iSpatialLayerNum = " << iSpatialLayerNum; | |
| 156 | − memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char)); | |
| 157 | − aLen[iIdx] += iLayerLen; | |
| 158 | − } | |
| 169 | + iIdx = layerInfo.uiSpatialId; | |
| 170 | + EXPECT_TRUE (iIdx < iSpatialLayerNum) << "iIdx = " << iIdx << ", iSpatialLayerNum = " << iSpatialLayerNum; | |
| 171 | + memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char)); | |
| 172 | + aLen[iIdx] += iLayerLen; | |
| 173 | + } | |
| 159 | 174 | |
| 160 | − for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | |
| 161 | − pData[0] = pData[1] = pData[2] = 0; | |
| 162 | − memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | |
| 175 | + for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | |
| 176 | + pData[0] = pData[1] = pData[2] = 0; | |
| 177 | + memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | |
| 163 | 178 | |
| 164 | − if (iSaveFileIdx > 0) { | |
| 165 | − fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]); | |
| 166 | − } | |
| 179 | + if (iSaveFileIdx > 0) { | |
| 180 | + fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]); | |
| 181 | + } | |
| 167 | 182 | |
| 168 | − iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_); | |
| 169 | − EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx; | |
| 183 | + iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_); | |
| 184 | + EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx; | |
| 170 | 185 | |
| 171 | − iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); | |
| 172 | − EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx; | |
| 173 | − EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx; | |
| 174 | − } | |
| 186 | + iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); | |
| 187 | + EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx; | |
| 188 | + EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx; | |
| 175 | 189 | } |
| 190 | + } | |
| 176 | 191 | |
| 177 | 192 | if (iSaveFileIdx > 0) { |
| 178 | 193 | fclose (fEnc[0]); |
| @@ -180,6 +195,7 @@ void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDec · 1 unmodified line | ||
| 180 | 195 | fclose (fEnc[2]); |
| 181 | 196 | fclose (fEnc[3]); |
| 182 | 197 | } |
| 198 | + return true; | |
| 183 | 199 | } |
| 184 | 200 | |
| 185 | 201 | long IsKeyFrameLost (ISVCDecoder* pDecoder, SLTRRecoverRequest* p_LTR_Recover_Request, long hr) { |