1 #include <gtest/gtest.h>
2 #include "codec_def.h"
3 #include "utils/BufferedData.h"
4 #include "utils/FileInputStream.h"
5 #include "BaseDecoderTest.h"
6 #include "BaseEncoderTest.h"
7 #include "wels_common_defs.h"
8 #include <string>
9 #include <vector>
10 using namespace WelsCommon;
11
12 //TODO: some content here in this file is the same with encode_decode_api_test.cpp
13 //plan to combine them after some on-going code reviews in that file to avoid merging conflict
14
15 #define TRY_TIME_RANGE (10)
16 #define ENCODE_FRAME_NUM (30)
17 #define LEVEL_ID_RANGE (18)
18 #define MAX_WIDTH (4096)
19 #define MAX_HEIGHT (2304)
20 #define MAX_FRAME_RATE (30)
21 #define MIN_FRAME_RATE (1)
22 #define FRAME_RATE_RANGE (2*MAX_FRAME_RATE)
23 #define RC_MODE_RANGE (4)
24 #define BIT_RATE_RANGE (10000)
25 #define MAX_QP (51)
26 #define MIN_QP (0)
27 #define QP_RANGE (2*MAX_QP)
28 #define SPATIAL_LAYER_NUM_RANGE (2*MAX_SPATIAL_LAYER_NUM)
29 #define TEMPORAL_LAYER_NUM_RANGE (2*MAX_TEMPORAL_LAYER_NUM)
30 #define SAVED_NALUNIT_NUM ( (MAX_SPATIAL_LAYER_NUM*MAX_QUALITY_LAYER_NUM) + 1 + MAX_SPATIAL_LAYER_NUM )
31 #define MAX_SLICES_NUM ( ( MAX_NAL_UNITS_IN_LAYER - SAVED_NALUNIT_NUM ) / 3 )
32 #define SLICE_MODE_NUM (SM_RESERVED)
33 #define LOOP_FILTER_IDC_NUM (3)
34 #define LOOF_FILTER_OFFSET_RANGE (6)
35 #define MAX_REF_PIC_COUNT (16)
36 #define MIN_REF_PIC_COUNT (1)
37 #define LONG_TERM_REF_NUM (2)
38 #define LONG_TERM_REF_NUM_SCREEN (4)
39 #define MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA (6)
40 #define MAX_REFERENCE_PICTURE_COUNT_NUM_SCREEN (8)
41 #define VALID_SIZE(iSize) (((iSize)>16)?(iSize):16)
42 #define GET_MB_WIDTH(x) (((x) + 15)/16)
43
44 typedef struct SLost_Sim {
45 WelsCommon::EWelsNalUnitType eNalType;
46 bool isLost;
47 } SLostSim;
48
49
50 struct EncodeDecodeFileParamBase {
51 int numframes;
52 int width;
53 int height;
54 float frameRate;
55 int slicenum;
56 bool bLostPara;
57 const char* pLossSequence;
58 };
59
welsStderrTraceOrigin(void * ctx,int level,const char * string)60 static void welsStderrTraceOrigin (void* ctx, int level, const char* string) {
61 fprintf (stderr, "%s\n", string);
62 }
63
64 typedef struct STrace_Unit {
65 int iTarLevel;
66 } STraceUnit;
67
68 class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest {
69 public:
70 uint8_t iRandValue;
71 public:
SetUp()72 virtual void SetUp() {
73 BaseEncoderTest::SetUp();
74 BaseDecoderTest::SetUp();
75 pFunc = welsStderrTraceOrigin;
76 pTraceInfo = NULL;
77 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK, &pFunc);
78 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
79 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK, &pFunc);
80 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
81 }
82
TearDown()83 virtual void TearDown() {
84 BaseEncoderTest::TearDown();
85 BaseDecoderTest::TearDown();
86 }
87
88 virtual void prepareParam (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam);
89
90 virtual bool prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam);
91
92 virtual void encToDecData (const SFrameBSInfo& info, int& len);
93
94 virtual void encToDecSliceData (const int iLayerNum, const int iSliceNum, const SFrameBSInfo& info, int& len);
95
GetRandWidth()96 virtual int GetRandWidth() {
97 return WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 16, MAX_WIDTH);
98 }
99
GetRandHeight()100 virtual int GetRandHeight() {
101 return WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 16, MAX_HEIGHT);
102 }
103
104 protected:
105 SEncParamExt param_;
106 BufferedData buf_;
107 SSourcePicture EncPic;
108 SFrameBSInfo info;
109 SBufferInfo dstBufInfo_;
110 std::vector<SLostSim> m_SLostSim;
111 WelsTraceCallback pFunc;
112 STraceUnit sTrace;
113 STraceUnit* pTraceInfo;
114 };
115
116 class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase {
117 public:
118 uint8_t iRandValue;
119 public:
SetUp()120 void SetUp() {
121 EncodeDecodeTestBase::SetUp();
122 }
123
TearDown()124 void TearDown() {
125 EncodeDecodeTestBase::TearDown();
126 }
127
128 void prepareParam0 (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam);
129
130 void prepareParamDefault (int iLayers, int iSlices, int width, int height, float framerate, SEncParamExt* pParam);
131
132 bool InitialEncDec (int iWidth, int iHeight);
133 void RandomParamExtCombination();
134 void ValidateParamExtCombination();
135 void SliceParamValidationForMode2 (int iSpatialIdx);
136 void SliceParamValidationForMode3 (int iSpatialIdx);
137 void SliceParamValidationForMode4();
138
139 void EncodeOneFrame (int iCheckTypeIndex);
140 bool EncDecOneFrame (const int iWidth, const int iHeight, const int iFrame, FILE* pfEnc);
141 bool TestOneSimulcastAVC (SEncParamExt* pParam, ISVCDecoder** decoder, unsigned char** pBsBuf, int iSpatialLayerNum,
142 int iEncFrameNum,
143 int iCallTimes);
144 };
145
146 class EncodeDecodeTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestAPIBase {
SetUp()147 void SetUp() {
148 EncodeDecodeTestAPIBase::SetUp();
149 }
150
TearDown()151 void TearDown() {
152 EncodeDecodeTestAPIBase::TearDown();
153 }
154 };
155
156
157 bool ToRemainDidNal (const unsigned char* pSrc, EWelsNalUnitType eNalType, int iTarDid);
158 void ExtractDidNal (SFrameBSInfo* pBsInfo, int& iSrcLen, std::vector<SLostSim>* p_SLostSim, int iTarDid);
159 int SimulateNALLoss (const unsigned char* pSrc, int& iSrcLen, std::vector<SLostSim>* p_SLostSim,
160 const char* pLossChars, bool bLossPara, int& iLossIdx, bool& bVCLLoss);
161
162 long IsKeyFrameLost (ISVCDecoder* pDecoder, SLTRRecoverRequest* p_LTR_Recover_Request, long hr);
163 bool IsLTRMarking (ISVCDecoder* pDecoder);
164 void LTRRecoveryRequest (ISVCDecoder* pDecoder, ISVCEncoder* pEncoder, SLTRRecoverRequest* p_LTR_Recover_Request,
165 long hr, bool m_P2PmodeFlag);
166 void LTRMarkFeedback (ISVCDecoder* pDecoder, ISVCEncoder* pEncoder, SLTRMarkingFeedback* p_LTR_Marking_Feedback,
167 long hr);
168