Showing the changes to test/api/encode_decode_api_test.cpp (1 of 1 file). Show all
Unified · Split
| @@ -8,87 +8,11 @@ · 7 unmodified lines | ||
| 8 | 8 | #include "utils/HashFunctions.h" |
| 9 | 9 | #include <string> |
| 10 | 10 | #include <vector> |
| 11 | +#include "encode_decode_api_test.h" | |
| 11 | 12 | using namespace WelsCommon; |
| 12 | 13 | |
| 13 | −#define TRY_TIME_RANGE (10) | |
| 14 | −#define ENCODE_FRAME_NUM (30) | |
| 15 | −#define LEVEL_ID_RANGE (18) | |
| 16 | −#define MAX_WIDTH (4096) | |
| 17 | −#define MAX_HEIGHT (2304) | |
| 18 | −#define MAX_FRAME_RATE (30) | |
| 19 | −#define MIN_FRAME_RATE (1) | |
| 20 | −#define FRAME_RATE_RANGE (2*MAX_FRAME_RATE) | |
| 21 | −#define RC_MODE_RANGE (4) | |
| 22 | −#define BIT_RATE_RANGE (10000) | |
| 23 | −#define MAX_QP (51) | |
| 24 | −#define MIN_QP (0) | |
| 25 | −#define QP_RANGE (2*MAX_QP) | |
| 26 | −#define SPATIAL_LAYER_NUM_RANGE (2*MAX_SPATIAL_LAYER_NUM) | |
| 27 | −#define TEMPORAL_LAYER_NUM_RANGE (2*MAX_TEMPORAL_LAYER_NUM) | |
| 28 | −#define SAVED_NALUNIT_NUM ( (MAX_SPATIAL_LAYER_NUM*MAX_QUALITY_LAYER_NUM) + 1 + MAX_SPATIAL_LAYER_NUM ) | |
| 29 | −#define MAX_SLICES_NUM ( ( MAX_NAL_UNITS_IN_LAYER - SAVED_NALUNIT_NUM ) / 3 ) | |
| 30 | −#define SLICE_MODE_NUM (6) | |
| 31 | −#define LOOP_FILTER_IDC_NUM (3) | |
| 32 | −#define LOOF_FILTER_OFFSET_RANGE (6) | |
| 33 | −#define MAX_REF_PIC_COUNT (16) | |
| 34 | −#define MIN_REF_PIC_COUNT (1) | |
| 35 | −#define LONG_TERM_REF_NUM (2) | |
| 36 | −#define LONG_TERM_REF_NUM_SCREEN (4) | |
| 37 | −#define MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA (6) | |
| 38 | −#define MAX_REFERENCE_PICTURE_COUNT_NUM_SCREEN (8) | |
| 39 | −#define VALID_SIZE(iSize) (((iSize)>16)?(iSize):16) | |
| 40 | −#define GET_MB_WIDTH(x) (((x) + 15)/16) | |
| 41 | − | |
| 42 | −typedef struct SLost_Sim { | |
| 43 | − WelsCommon::EWelsNalUnitType eNalType; | |
| 44 | − bool isLost; | |
| 45 | −} SLostSim; | |
| 46 | − | |
| 47 | − | |
| 48 | −struct EncodeDecodeFileParamBase { | |
| 49 | − int numframes; | |
| 50 | − int width; | |
| 51 | − int height; | |
| 52 | − float frameRate; | |
| 53 | − int slicenum; | |
| 54 | − bool bLostPara; | |
| 55 | − const char* pLossSequence; | |
| 56 | −}; | |
| 57 | − | |
| 58 | −static void welsStderrTraceOrigin (void* ctx, int level, const char* string) { | |
| 59 | − fprintf (stderr, "%s\n", string); | |
| 60 | −} | |
| 61 | − | |
| 62 | −typedef struct STrace_Unit { | |
| 63 | − int iTarLevel; | |
| 64 | −} STraceUnit; | |
| 65 | − | |
| 66 | −static void TestOutPutTrace (void* ctx, int level, const char* string) { | |
| 67 | − STraceUnit* pTraceUnit = (STraceUnit*) ctx; | |
| 68 | − EXPECT_LE (level, pTraceUnit->iTarLevel); | |
| 69 | −} | |
| 70 | − | |
| 71 | −class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest { | |
| 72 | − public: | |
| 73 | − uint8_t iRandValue; | |
| 74 | − public: | |
| 75 | − virtual void SetUp() { | |
| 76 | − BaseEncoderTest::SetUp(); | |
| 77 | − BaseDecoderTest::SetUp(); | |
| 78 | − pFunc = welsStderrTraceOrigin; | |
| 79 | − pTraceInfo = NULL; | |
| 80 | − encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK, &pFunc); | |
| 81 | − encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo); | |
| 82 | − decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK, &pFunc); | |
| 83 | − decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo); | |
| 84 | − } | |
| 85 | − | |
| 86 | − virtual void TearDown() { | |
| 87 | − BaseEncoderTest::TearDown(); | |
| 88 | − BaseDecoderTest::TearDown(); | |
| 89 | − } | |
| 90 | 14 | |
| 91 | − virtual void prepareParam (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) { | |
| 15 | +void EncodeDecodeTestBase::prepareParam (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) { | |
| 92 | 16 | pParam->iUsageType = CAMERA_VIDEO_REAL_TIME; |
| 93 | 17 | pParam->iPicWidth = width; |
| 94 | 18 | pParam->iPicHeight = height; |
| @@ -104,9 +28,9 @@ class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest { · 9 unmodified lines | ||
| 104 | 28 | pParam->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE; |
| 105 | 29 | pParam->sSpatialLayers[i].sSliceArgument.uiSliceNum = iSlices; |
| 106 | 30 | } |
| 107 | − } | |
| 31 | +} | |
| 108 | 32 | |
| 109 | − virtual void prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) { | |
| 33 | +void EncodeDecodeTestBase::prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) { | |
| 110 | 34 | //for encoder |
| 111 | 35 | //I420: 1(Y) + 1/4(U) + 1/4(V) |
| 112 | 36 | int frameSize = EncDecFileParam.width * EncDecFileParam.height * 3 / 2; |
| @@ -125,9 +49,9 @@ class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest { · 12 unmodified lines | ||
| 125 | 49 | memset (&info, 0, sizeof (SFrameBSInfo)); |
| 126 | 50 | //set a fixed random value |
| 127 | 51 | iRandValue = rand() % 256; |
| 128 | − } | |
| 52 | +} | |
| 129 | 53 | |
| 130 | − virtual void encToDecData (const SFrameBSInfo& info, int& len) { | |
| 54 | +void EncodeDecodeTestBase::encToDecData (const SFrameBSInfo& info, int& len) { | |
| 131 | 55 | len = 0; |
| 132 | 56 | for (int i = 0; i < info.iLayerNum; ++i) { |
| 133 | 57 | const SLayerBSInfo& layerInfo = info.sLayerInfo[i]; |
| @@ -135,68 +59,29 @@ class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest { · 1 unmodified line | ||
| 135 | 59 | len += layerInfo.pNalLengthInByte[j]; |
| 136 | 60 | } |
| 137 | 61 | } |
| 138 | − } | |
| 62 | +} | |
| 139 | 63 | |
| 140 | − virtual void encToDecSliceData (const int iLayerNum, const int iSliceNum, const SFrameBSInfo& info, int& len) { | |
| 64 | +void EncodeDecodeTestBase::encToDecSliceData (const int iLayerNum, const int iSliceNum, const SFrameBSInfo& info, int& len) { | |
| 141 | 65 | ASSERT_TRUE (iLayerNum < MAX_LAYER_NUM_OF_FRAME); |
| 142 | 66 | len = 0; |
| 143 | 67 | const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayerNum]; |
| 144 | 68 | if (iSliceNum < layerInfo.iNalCount) |
| 145 | 69 | len = layerInfo.pNalLengthInByte[iSliceNum]; |
| 146 | − } | |
| 147 | − | |
| 148 | − | |
| 149 | − virtual int GetRandWidth() { | |
| 150 | − return WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 16, MAX_WIDTH); | |
| 151 | − } | |
| 152 | − | |
| 153 | − virtual int GetRandHeight() { | |
| 154 | − return WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 16, MAX_HEIGHT); | |
| 155 | − } | |
| 156 | − | |
| 157 | − protected: | |
| 158 | − SEncParamExt param_; | |
| 159 | − BufferedData buf_; | |
| 160 | − SSourcePicture EncPic; | |
| 161 | − SFrameBSInfo info; | |
| 162 | − SBufferInfo dstBufInfo_; | |
| 163 | − std::vector<SLostSim> m_SLostSim; | |
| 164 | − WelsTraceCallback pFunc; | |
| 165 | − STraceUnit sTrace; | |
| 166 | − STraceUnit* pTraceInfo; | |
| 167 | −}; | |
| 168 | − | |
| 169 | −class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase { | |
| 170 | − public: | |
| 171 | − uint8_t iRandValue; | |
| 172 | − public: | |
| 173 | − void SetUp() { | |
| 174 | − EncodeDecodeTestBase::SetUp(); | |
| 175 | − } | |
| 176 | − | |
| 177 | − void TearDown() { | |
| 178 | − EncodeDecodeTestBase::TearDown(); | |
| 179 | − } | |
| 70 | +} | |
| 180 | 71 | |
| 181 | − void prepareParam0 (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) { | |
| 72 | +void EncodeDecodeTestAPIBase::prepareParam0 (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) { | |
| 182 | 73 | memset (pParam, 0, sizeof (SEncParamExt)); |
| 183 | 74 | EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam); |
| 184 | − } | |
| 75 | +} | |
| 185 | 76 | |
| 186 | − void prepareParamDefault (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) { | |
| 77 | +void EncodeDecodeTestAPIBase::prepareParamDefault (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) { | |
| 187 | 78 | memset (pParam, 0, sizeof (SEncParamExt)); |
| 188 | 79 | encoder_->GetDefaultParams (pParam); |
| 189 | 80 | EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam); |
| 190 | − } | |
| 81 | +} | |
| 191 | 82 | |
| 192 | − void InitialEncDec (int iWidth, int iHeight); | |
| 193 | − void RandomParamExtCombination(); | |
| 194 | − void ValidateParamExtCombination(); | |
| 195 | − void SliceParamValidationForMode2 (int iSpatialIdx); | |
| 196 | − void SliceParamValidationForMode3 (int iSpatialIdx); | |
| 197 | − void SliceParamValidationForMode4(); | |
| 198 | 83 | |
| 199 | − void EncodeOneFrame (int iCheckTypeIndex) { | |
| 84 | +void EncodeDecodeTestAPIBase::EncodeOneFrame (int iCheckTypeIndex) { | |
| 200 | 85 | int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2; |
| 201 | 86 | memset (buf_.data(), iRandValue, (frameSize >> 2)); |
| 202 | 87 | memset (buf_.data() + (frameSize >> 2), rand() % 256, (frameSize - (frameSize >> 2))); |
| @@ -205,9 +90,9 @@ class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase { · 2 unmodified lines | ||
| 205 | 90 | ASSERT_TRUE (rv == cmResultSuccess); |
| 206 | 91 | else if (1 == iCheckTypeIndex) |
| 207 | 92 | ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason); |
| 208 | − } | |
| 93 | +} | |
| 209 | 94 | |
| 210 | − void EncDecOneFrame (const int iWidth, const int iHeight, const int iFrame, FILE* pfEnc) { | |
| 95 | +void EncodeDecodeTestAPIBase::EncDecOneFrame (const int iWidth, const int iHeight, const int iFrame, FILE* pfEnc) { | |
| 211 | 96 | int iLen = 0, rv; |
| 212 | 97 | InitialEncDec (iWidth, iHeight); |
| 213 | 98 | EncodeOneFrame (iFrame); |
| @@ -223,9 +108,9 @@ class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase { · 9 unmodified lines | ||
| 223 | 108 | if (NULL != pfEnc) { |
| 224 | 109 | fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, pfEnc); |
| 225 | 110 | } |
| 226 | − } | |
| 111 | +} | |
| 227 | 112 | |
| 228 | − void TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, int iSpatialLayerNum, | |
| 113 | +void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, int iSpatialLayerNum, | |
| 229 | 114 | int iEncFrameNum, |
| 230 | 115 | int iCallTimes) { |
| 231 | 116 | //#define DEBUG_FILE_SAVE4 |
| @@ -297,18 +182,7 @@ class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase { · 65 unmodified lines | ||
| 297 | 182 | fclose (fEnc[2]); |
| 298 | 183 | fclose (fEnc[3]); |
| 299 | 184 | #endif |
| 300 | − } | |
| 301 | −}; | |
| 302 | − | |
| 303 | −class EncodeDecodeTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestAPIBase { | |
| 304 | − void SetUp() { | |
| 305 | − EncodeDecodeTestAPIBase::SetUp(); | |
| 306 | − } | |
| 307 | − | |
| 308 | − void TearDown() { | |
| 309 | − EncodeDecodeTestAPIBase::TearDown(); | |
| 310 | − } | |
| 311 | −}; | |
| 185 | +} | |
| 312 | 186 | |
| 313 | 187 | void EncodeDecodeTestAPIBase::InitialEncDec (int iWidth, int iHeight) { |
| 314 | 188 | |