History

put class notification to header file

sijchen committed 10 years ago

Commit 5d03a8a1 parent 2d3071e1 file · +19 −145Browse files

Showing the changes to test/api/encode_decode_api_test.cpp (1 of 1 file). Show all

Unified · Split

test/api/encode_decode_api_test.cpp+19−145
@@ -8,87 +8,11 @@ · 7 unmodified lines
8#include "utils/HashFunctions.h"8#include "utils/HashFunctions.h"
9#include <string>9#include <string>
10#include <vector>10#include <vector>
11#include "encode_decode_api_test.h"
11using namespace WelsCommon;12using 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
42typedef struct SLost_Sim {
43 WelsCommon::EWelsNalUnitType eNalType;
44 bool isLost;
45} SLostSim;
46
47
48struct 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
58static void welsStderrTraceOrigin (void* ctx, int level, const char* string) {
59 fprintf (stderr, "%s\n", string);
60}
61
62typedef struct STrace_Unit {
63 int iTarLevel;
64} STraceUnit;
65
66static void TestOutPutTrace (void* ctx, int level, const char* string) {
67 STraceUnit* pTraceUnit = (STraceUnit*) ctx;
68 EXPECT_LE (level, pTraceUnit->iTarLevel);
69}
70
71class 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) {15void EncodeDecodeTestBase::prepareParam (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) {
92 pParam->iUsageType = CAMERA_VIDEO_REAL_TIME;16 pParam->iUsageType = CAMERA_VIDEO_REAL_TIME;
93 pParam->iPicWidth = width;17 pParam->iPicWidth = width;
94 pParam->iPicHeight = height;18 pParam->iPicHeight = height;
@@ -104,9 +28,9 @@ class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest { · 9 unmodified lines
104 pParam->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;28 pParam->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
105 pParam->sSpatialLayers[i].sSliceArgument.uiSliceNum = iSlices;29 pParam->sSpatialLayers[i].sSliceArgument.uiSliceNum = iSlices;
106 }30 }
107 }31}
108 32
109 virtual void prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) {33void EncodeDecodeTestBase::prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) {
110 //for encoder34 //for encoder
111 //I420: 1(Y) + 1/4(U) + 1/4(V)35 //I420: 1(Y) + 1/4(U) + 1/4(V)
112 int frameSize = EncDecFileParam.width * EncDecFileParam.height * 3 / 2;36 int frameSize = EncDecFileParam.width * EncDecFileParam.height * 3 / 2;
@@ -125,9 +49,9 @@ class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest { · 12 unmodified lines
125 memset (&info, 0, sizeof (SFrameBSInfo));49 memset (&info, 0, sizeof (SFrameBSInfo));
126 //set a fixed random value50 //set a fixed random value
127 iRandValue = rand() % 256;51 iRandValue = rand() % 256;
128 }52}
129 53
130 virtual void encToDecData (const SFrameBSInfo& info, int& len) {54void EncodeDecodeTestBase::encToDecData (const SFrameBSInfo& info, int& len) {
131 len = 0;55 len = 0;
132 for (int i = 0; i < info.iLayerNum; ++i) {56 for (int i = 0; i < info.iLayerNum; ++i) {
133 const SLayerBSInfo& layerInfo = info.sLayerInfo[i];57 const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
@@ -135,68 +59,29 @@ class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest { · 1 unmodified line
135 len += layerInfo.pNalLengthInByte[j];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) {64void EncodeDecodeTestBase::encToDecSliceData (const int iLayerNum, const int iSliceNum, const SFrameBSInfo& info, int& len) {
141 ASSERT_TRUE (iLayerNum < MAX_LAYER_NUM_OF_FRAME);65 ASSERT_TRUE (iLayerNum < MAX_LAYER_NUM_OF_FRAME);
142 len = 0;66 len = 0;
143 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayerNum];67 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayerNum];
144 if (iSliceNum < layerInfo.iNalCount)68 if (iSliceNum < layerInfo.iNalCount)
145 len = layerInfo.pNalLengthInByte[iSliceNum];69 len = layerInfo.pNalLengthInByte[iSliceNum];
146 }70}
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
169class 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 }
180 71
181 void prepareParam0 (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) {72void EncodeDecodeTestAPIBase::prepareParam0 (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) {
182 memset (pParam, 0, sizeof (SEncParamExt));73 memset (pParam, 0, sizeof (SEncParamExt));
183 EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam);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) {77void EncodeDecodeTestAPIBase::prepareParamDefault (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam) {
187 memset (pParam, 0, sizeof (SEncParamExt));78 memset (pParam, 0, sizeof (SEncParamExt));
188 encoder_->GetDefaultParams (pParam);79 encoder_->GetDefaultParams (pParam);
189 EncodeDecodeTestBase::prepareParam (iLayers, iSlices, width, height, framerate, pParam);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) {84void EncodeDecodeTestAPIBase::EncodeOneFrame (int iCheckTypeIndex) {
200 int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;85 int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;
201 memset (buf_.data(), iRandValue, (frameSize >> 2));86 memset (buf_.data(), iRandValue, (frameSize >> 2));
202 memset (buf_.data() + (frameSize >> 2), rand() % 256, (frameSize - (frameSize >> 2)));87 memset (buf_.data() + (frameSize >> 2), rand() % 256, (frameSize - (frameSize >> 2)));
@@ -205,9 +90,9 @@ class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase { · 2 unmodified lines
205 ASSERT_TRUE (rv == cmResultSuccess);90 ASSERT_TRUE (rv == cmResultSuccess);
206 else if (1 == iCheckTypeIndex)91 else if (1 == iCheckTypeIndex)
207 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);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) {95void EncodeDecodeTestAPIBase::EncDecOneFrame (const int iWidth, const int iHeight, const int iFrame, FILE* pfEnc) {
211 int iLen = 0, rv;96 int iLen = 0, rv;
212 InitialEncDec (iWidth, iHeight);97 InitialEncDec (iWidth, iHeight);
213 EncodeOneFrame (iFrame);98 EncodeOneFrame (iFrame);
@@ -223,9 +108,9 @@ class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase { · 9 unmodified lines
223 if (NULL != pfEnc) {108 if (NULL != pfEnc) {
224 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, pfEnc);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,113void EncodeDecodeTestAPIBase::TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, int iSpatialLayerNum,
229 int iEncFrameNum,114 int iEncFrameNum,
230 int iCallTimes) {115 int iCallTimes) {
231//#define DEBUG_FILE_SAVE4116//#define DEBUG_FILE_SAVE4
@@ -297,18 +182,7 @@ class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase { · 65 unmodified lines
297 fclose (fEnc[2]);182 fclose (fEnc[2]);
298 fclose (fEnc[3]);183 fclose (fEnc[3]);
299#endif184#endif
300 }185}
301};
302
303class EncodeDecodeTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestAPIBase {
304 void SetUp() {
305 EncodeDecodeTestAPIBase::SetUp();
306 }
307
308 void TearDown() {
309 EncodeDecodeTestAPIBase::TearDown();
310 }
311};
312 186
313void EncodeDecodeTestAPIBase::InitialEncDec (int iWidth, int iHeight) {187void EncodeDecodeTestAPIBase::InitialEncDec (int iWidth, int iHeight) {
314 188

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t