Showing the changes to test/api/BaseEncoderTest.cpp (1 of 5 files). Show all
Unified · Split
| @@ -5,16 +5,20 @@ · 4 unmodified lines | |||
| 5 | #include "utils/FileInputStream.h" | 5 | #include "utils/FileInputStream.h" |
| 6 | #include "BaseEncoderTest.h" | 6 | #include "BaseEncoderTest.h" |
| 7 | 7 | ||
| 8 | static int InitWithParam (ISVCEncoder* encoder, EUsageType usageType, int width, | 8 | static int InitWithParam (ISVCEncoder* encoder, SEncParamExt* pEncParamExt) { |
| 9 | int height, float frameRate, SliceModeEnum sliceMode, bool denoise, int layers, bool losslessLink, bool enableLtr,bool cabac) { | 9 | |
| 10 | if (SM_SINGLE_SLICE == sliceMode && !denoise && layers == 1 && !losslessLink && !enableLtr &&!cabac) { | 10 | SliceModeEnum eSliceMode = pEncParamExt->sSpatialLayers[0].sSliceCfg.uiSliceMode; |
| 11 | bool bBaseParamFlag = (SM_SINGLE_SLICE == eSliceMode && !pEncParamExt->bEnableDenoise | ||
| 12 | && pEncParamExt->iSpatialLayerNum == 1 && !pEncParamExt->bIsLosslessLink | ||
| 13 | && !pEncParamExt->bEnableLongTermReference && !pEncParamExt->iEntropyCodingModeFlag) ? true : false; | ||
| 14 | if (bBaseParamFlag) { | ||
| 11 | SEncParamBase param; | 15 | SEncParamBase param; |
| 12 | memset (¶m, 0, sizeof (SEncParamBase)); | 16 | memset (¶m, 0, sizeof (SEncParamBase)); |
| 13 | 17 | ||
| 14 | param.iUsageType = usageType; | 18 | param.iUsageType = pEncParamExt->iUsageType; |
| 15 | param.fMaxFrameRate = frameRate; | 19 | param.fMaxFrameRate = pEncParamExt->fMaxFrameRate; |
| 16 | param.iPicWidth = width; | 20 | param.iPicWidth = pEncParamExt->iPicWidth; |
| 17 | param.iPicHeight = height; | 21 | param.iPicHeight = pEncParamExt->iPicHeight; |
| 18 | param.iTargetBitrate = 5000000; | 22 | param.iTargetBitrate = 5000000; |
| 19 | 23 | ||
| 20 | return encoder->Initialize (¶m); | 24 | return encoder->Initialize (¶m); |
| @@ -22,27 +26,27 @@ static int InitWithParam (ISVCEncoder* encoder, EUsageType usageType, int width, · 1 unmodified line | |||
| 22 | SEncParamExt param; | 26 | SEncParamExt param; |
| 23 | encoder->GetDefaultParams (¶m); | 27 | encoder->GetDefaultParams (¶m); |
| 24 | 28 | ||
| 25 | param.iUsageType = usageType; | 29 | param.iUsageType = pEncParamExt->iUsageType; |
| 26 | param.fMaxFrameRate = frameRate; | 30 | param.fMaxFrameRate = pEncParamExt->fMaxFrameRate; |
| 27 | param.iPicWidth = width; | 31 | param.iPicWidth = pEncParamExt->iPicWidth; |
| 28 | param.iPicHeight = height; | 32 | param.iPicHeight = pEncParamExt->iPicHeight; |
| 29 | param.iTargetBitrate = 5000000; | 33 | param.iTargetBitrate = 5000000; |
| 30 | param.bEnableDenoise = denoise; | 34 | param.bEnableDenoise = pEncParamExt->bEnableDenoise; |
| 31 | param.iSpatialLayerNum = layers; | 35 | param.iSpatialLayerNum = pEncParamExt->iSpatialLayerNum; |
| 32 | param.bIsLosslessLink = losslessLink; | 36 | param.bIsLosslessLink = pEncParamExt->bIsLosslessLink; |
| 33 | param.bEnableLongTermReference = enableLtr; | 37 | param.bEnableLongTermReference = pEncParamExt->bEnableLongTermReference; |
| 34 | param.iEntropyCodingModeFlag = cabac?1:0; | 38 | param.iEntropyCodingModeFlag = pEncParamExt->iEntropyCodingModeFlag ? 1 : 0; |
| 35 | if (sliceMode != SM_SINGLE_SLICE && sliceMode != SM_DYN_SLICE) //SM_DYN_SLICE don't support multi-thread now | 39 | if (eSliceMode != SM_SINGLE_SLICE && eSliceMode != SM_DYN_SLICE) //SM_DYN_SLICE don't support multi-thread now |
| 36 | param.iMultipleThreadIdc = 2; | 40 | param.iMultipleThreadIdc = 2; |
| 37 | 41 | ||
| 38 | for (int i = 0; i < param.iSpatialLayerNum; i++) { | 42 | for (int i = 0; i < param.iSpatialLayerNum; i++) { |
| 39 | param.sSpatialLayers[i].iVideoWidth = width >> (param.iSpatialLayerNum - 1 - i); | 43 | param.sSpatialLayers[i].iVideoWidth = pEncParamExt->iPicWidth >> (param.iSpatialLayerNum - 1 - i); |
| 40 | param.sSpatialLayers[i].iVideoHeight = height >> (param.iSpatialLayerNum - 1 - i); | 44 | param.sSpatialLayers[i].iVideoHeight = pEncParamExt->iPicHeight >> (param.iSpatialLayerNum - 1 - i); |
| 41 | param.sSpatialLayers[i].fFrameRate = frameRate; | 45 | param.sSpatialLayers[i].fFrameRate = pEncParamExt->fMaxFrameRate; |
| 42 | param.sSpatialLayers[i].iSpatialBitrate = param.iTargetBitrate; | 46 | param.sSpatialLayers[i].iSpatialBitrate = param.iTargetBitrate; |
| 43 | 47 | ||
| 44 | param.sSpatialLayers[i].sSliceCfg.uiSliceMode = sliceMode; | 48 | param.sSpatialLayers[i].sSliceCfg.uiSliceMode = eSliceMode; |
| 45 | if (sliceMode == SM_DYN_SLICE) { | 49 | if (eSliceMode == SM_DYN_SLICE) { |
| 46 | param.sSpatialLayers[i].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 600; | 50 | param.sSpatialLayers[i].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 600; |
| 47 | param.uiMaxNalSize = 1500; | 51 | param.uiMaxNalSize = 1500; |
| 48 | } | 52 | } |
| @@ -68,13 +72,15 @@ void BaseEncoderTest::TearDown() { · 19 unmodified lines | |||
| 68 | } | 72 | } |
| 69 | } | 73 | } |
| 70 | 74 | ||
| 71 | void BaseEncoderTest::EncodeStream (InputStream* in, EUsageType usageType, int width, int height, | 75 | void BaseEncoderTest::EncodeStream (InputStream* in, SEncParamExt* pEncParamExt, Callback* cbk) { |
| 72 | float frameRate, SliceModeEnum slices, bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac,Callback* cbk) { | 76 | |
| 73 | int rv = InitWithParam (encoder_, usageType, width, height, frameRate, slices, denoise, layers, losslessLink, enableLtr,cabac); | 77 | ASSERT_TRUE (NULL != pEncParamExt); |
| 78 | |||
| 79 | int rv = InitWithParam (encoder_, pEncParamExt); | ||
| 74 | ASSERT_TRUE (rv == cmResultSuccess); | 80 | ASSERT_TRUE (rv == cmResultSuccess); |
| 75 | 81 | ||
| 76 | // I420: 1(Y) + 1/4(U) + 1/4(V) | 82 | // I420: 1(Y) + 1/4(U) + 1/4(V) |
| 77 | int frameSize = width * height * 3 / 2; | 83 | int frameSize = pEncParamExt->iPicWidth * pEncParamExt->iPicHeight * 3 / 2; |
| 78 | 84 | ||
| 79 | BufferedData buf; | 85 | BufferedData buf; |
| 80 | buf.SetLength (frameSize); | 86 | buf.SetLength (frameSize); |
| @@ -85,14 +91,14 @@ void BaseEncoderTest::EncodeStream (InputStream* in, EUsageType usageType, int w · 4 unmodified lines | |||
| 85 | 91 | ||
| 86 | SSourcePicture pic; | 92 | SSourcePicture pic; |
| 87 | memset (&pic, 0, sizeof (SSourcePicture)); | 93 | memset (&pic, 0, sizeof (SSourcePicture)); |
| 88 | pic.iPicWidth = width; | 94 | pic.iPicWidth = pEncParamExt->iPicWidth; |
| 89 | pic.iPicHeight = height; | 95 | pic.iPicHeight = pEncParamExt->iPicHeight; |
| 90 | pic.iColorFormat = videoFormatI420; | 96 | pic.iColorFormat = videoFormatI420; |
| 91 | pic.iStride[0] = pic.iPicWidth; | 97 | pic.iStride[0] = pic.iPicWidth; |
| 92 | pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1; | 98 | pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1; |
| 93 | pic.pData[0] = buf.data(); | 99 | pic.pData[0] = buf.data(); |
| 94 | pic.pData[1] = pic.pData[0] + width * height; | 100 | pic.pData[1] = pic.pData[0] + pEncParamExt->iPicWidth * pEncParamExt->iPicHeight; |
| 95 | pic.pData[2] = pic.pData[1] + (width * height >> 2); | 101 | pic.pData[2] = pic.pData[1] + (pEncParamExt->iPicWidth * pEncParamExt->iPicHeight >> 2); |
| 96 | while (in->read (buf.data(), frameSize) == frameSize) { | 102 | while (in->read (buf.data(), frameSize) == frameSize) { |
| 97 | rv = encoder_->EncodeFrame (&pic, &info); | 103 | rv = encoder_->EncodeFrame (&pic, &info); |
| 98 | ASSERT_TRUE (rv == cmResultSuccess); | 104 | ASSERT_TRUE (rv == cmResultSuccess); |
| @@ -102,9 +108,9 @@ void BaseEncoderTest::EncodeStream (InputStream* in, EUsageType usageType, int w · 3 unmodified lines | |||
| 102 | } | 108 | } |
| 103 | } | 109 | } |
| 104 | 110 | ||
| 105 | void BaseEncoderTest::EncodeFile (const char* fileName, EUsageType usageType, int width, int height, | 111 | void BaseEncoderTest::EncodeFile (const char* fileName, SEncParamExt* pEncParamExt, Callback* cbk) { |
| 106 | float frameRate, SliceModeEnum slices, bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac,Callback* cbk) { | ||
| 107 | FileInputStream fileStream; | 112 | FileInputStream fileStream; |
| 108 | ASSERT_TRUE (fileStream.Open (fileName)); | 113 | ASSERT_TRUE (fileStream.Open (fileName)); |
| 109 | EncodeStream (&fileStream, usageType, width, height, frameRate, slices, denoise, layers, losslessLink, enableLtr, cabac,cbk); | 114 | ASSERT_TRUE (NULL != pEncParamExt); |
| 115 | EncodeStream (&fileStream, pEncParamExt, cbk); | ||
| 110 | } | 116 | } |