History

B-frame decoding support for Main and High Profile with two test cases.

xiaotianshi2 committed 8 years ago

Commit 657d2171 parent e3e838355 files · +17936 −13825Browse files

Showing the changes to test/api/decode_api_test.cpp (1 of 55 files). Show all

Unified · Split

test/api/decode_api_test.cpp+1276−1276
@@ -1,1276 +1,1276 @@
1#include <gtest/gtest.h>1#include <gtest/gtest.h>
2#include "codec_def.h"2#include "codec_def.h"
3#include "utils/BufferedData.h"3#include "utils/BufferedData.h"
4#include "utils/FileInputStream.h"4#include "utils/FileInputStream.h"
5#include "BaseDecoderTest.h"5#include "BaseDecoderTest.h"
6#include "BaseEncoderTest.h"6#include "BaseEncoderTest.h"
7#include "wels_common_defs.h"7#include "wels_common_defs.h"
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"11#include "encode_decode_api_test.h"
12using namespace WelsCommon;12using namespace WelsCommon;
13 13
14static void TestOutPutTrace (void* ctx, int level, const char* string) {14static void TestOutPutTrace (void* ctx, int level, const char* string) {
15 STraceUnit* pTraceUnit = (STraceUnit*) ctx;15 STraceUnit* pTraceUnit = (STraceUnit*) ctx;
16 EXPECT_LE (level, pTraceUnit->iTarLevel);16 EXPECT_LE (level, pTraceUnit->iTarLevel);
17}17}
18 18
19TEST_P (EncodeDecodeTestAPI, DecoderVclNal) {19TEST_P (EncodeDecodeTestAPI, DecoderVclNal) {
20 EncodeDecodeFileParamBase p = GetParam();20 EncodeDecodeFileParamBase p = GetParam();
21 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);21 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
22 encoder_->Uninitialize();22 encoder_->Uninitialize();
23 int rv = encoder_->InitializeExt (&param_);23 int rv = encoder_->InitializeExt (&param_);
24 ASSERT_TRUE (rv == cmResultSuccess);24 ASSERT_TRUE (rv == cmResultSuccess);
25 25
26 int32_t iTraceLevel = WELS_LOG_QUIET;26 int32_t iTraceLevel = WELS_LOG_QUIET;
27 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);27 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
28 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);28 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
29 29
30 ASSERT_TRUE (InitialEncDec (p.width, p.height));30 ASSERT_TRUE (InitialEncDec (p.width, p.height));
31 31
32 int iIdx = 0;32 int iIdx = 0;
33 while (iIdx <= p.numframes) {33 while (iIdx <= p.numframes) {
34 34
35 EncodeOneFrame (0);35 EncodeOneFrame (0);
36 36
37 //decoding after each encoding frame37 //decoding after each encoding frame
38 int vclNal, len = 0;38 int vclNal, len = 0;
39 encToDecData (info, len);39 encToDecData (info, len);
40 unsigned char* pData[3] = { NULL };40 unsigned char* pData[3] = { NULL };
41 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));41 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
42 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);42 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
43 ASSERT_TRUE (rv == cmResultSuccess);43 ASSERT_TRUE (rv == cmResultSuccess);
44 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);44 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);
45 EXPECT_EQ (vclNal, FEEDBACK_UNKNOWN_NAL); //no reconstruction, unknown return45 EXPECT_EQ (vclNal, FEEDBACK_UNKNOWN_NAL); //no reconstruction, unknown return
46 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction46 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
47 ASSERT_TRUE (rv == cmResultSuccess);47 ASSERT_TRUE (rv == cmResultSuccess);
48 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);48 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);
49 EXPECT_EQ (vclNal, FEEDBACK_VCL_NAL);49 EXPECT_EQ (vclNal, FEEDBACK_VCL_NAL);
50 iIdx++;50 iIdx++;
51 } //while51 } //while
52 //ignore last frame52 //ignore last frame
53}53}
54 54
55TEST_P (EncodeDecodeTestAPI, GetOptionFramenum) {55TEST_P (EncodeDecodeTestAPI, GetOptionFramenum) {
56 EncodeDecodeFileParamBase p = GetParam();56 EncodeDecodeFileParamBase p = GetParam();
57 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);57 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
58 encoder_->Uninitialize();58 encoder_->Uninitialize();
59 int rv = encoder_->InitializeExt (&param_);59 int rv = encoder_->InitializeExt (&param_);
60 ASSERT_TRUE (rv == cmResultSuccess);60 ASSERT_TRUE (rv == cmResultSuccess);
61 61
62 int32_t iTraceLevel = WELS_LOG_QUIET;62 int32_t iTraceLevel = WELS_LOG_QUIET;
63 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);63 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
64 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);64 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
65 65
66 ASSERT_TRUE (InitialEncDec (p.width, p.height));66 ASSERT_TRUE (InitialEncDec (p.width, p.height));
67 67
68 int32_t iEncFrameNum = -1;68 int32_t iEncFrameNum = -1;
69 int32_t iDecFrameNum;69 int32_t iDecFrameNum;
70 int iIdx = 0;70 int iIdx = 0;
71 while (iIdx <= p.numframes) {71 while (iIdx <= p.numframes) {
72 EncodeOneFrame (0);72 EncodeOneFrame (0);
73 //decoding after each encoding frame73 //decoding after each encoding frame
74 int len = 0;74 int len = 0;
75 encToDecData (info, len);75 encToDecData (info, len);
76 unsigned char* pData[3] = { NULL };76 unsigned char* pData[3] = { NULL };
77 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));77 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
78 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);78 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
79 ASSERT_TRUE (rv == cmResultSuccess);79 ASSERT_TRUE (rv == cmResultSuccess);
80 decoder_->GetOption (DECODER_OPTION_FRAME_NUM, &iDecFrameNum);80 decoder_->GetOption (DECODER_OPTION_FRAME_NUM, &iDecFrameNum);
81 EXPECT_EQ (iDecFrameNum, -1);81 EXPECT_EQ (iDecFrameNum, -1);
82 iEncFrameNum++;82 iEncFrameNum++;
83 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction83 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
84 ASSERT_TRUE (rv == cmResultSuccess);84 ASSERT_TRUE (rv == cmResultSuccess);
85 decoder_->GetOption (DECODER_OPTION_FRAME_NUM, &iDecFrameNum);85 decoder_->GetOption (DECODER_OPTION_FRAME_NUM, &iDecFrameNum);
86 EXPECT_EQ (iEncFrameNum, iDecFrameNum);86 EXPECT_EQ (iEncFrameNum, iDecFrameNum);
87 iIdx++;87 iIdx++;
88 } //while88 } //while
89 //ignore last frame89 //ignore last frame
90}90}
91 91
92TEST_P (EncodeDecodeTestAPI, GetOptionIDR) {92TEST_P (EncodeDecodeTestAPI, GetOptionIDR) {
93 EncodeDecodeFileParamBase p = GetParam();93 EncodeDecodeFileParamBase p = GetParam();
94 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);94 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
95 encoder_->Uninitialize();95 encoder_->Uninitialize();
96 int rv = encoder_->InitializeExt (&param_);96 int rv = encoder_->InitializeExt (&param_);
97 ASSERT_TRUE (rv == cmResultSuccess);97 ASSERT_TRUE (rv == cmResultSuccess);
98 98
99 //init for encoder99 //init for encoder
100 // I420: 1(Y) + 1/4(U) + 1/4(V)100 // I420: 1(Y) + 1/4(U) + 1/4(V)
101 int32_t iTraceLevel = WELS_LOG_QUIET;101 int32_t iTraceLevel = WELS_LOG_QUIET;
102 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);102 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
103 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);103 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
104 104
105 ASSERT_TRUE (InitialEncDec (p.width, p.height));105 ASSERT_TRUE (InitialEncDec (p.width, p.height));
106 106
107 int32_t iEncCurIdrPicId = 0;107 int32_t iEncCurIdrPicId = 0;
108 int32_t iDecCurIdrPicId;108 int32_t iDecCurIdrPicId;
109 int32_t iIDRPeriod = 1;109 int32_t iIDRPeriod = 1;
110 int32_t iSpsPpsIdAddition = 0;110 int32_t iSpsPpsIdAddition = 0;
111 int iIdx = 0;111 int iIdx = 0;
112 while (iIdx <= p.numframes) {112 while (iIdx <= p.numframes) {
113 iSpsPpsIdAddition = rand() %113 iSpsPpsIdAddition = rand() %
114 2; //the current strategy supports more than 2 modes, but the switch between the modes>2 is not allowed114 2; //the current strategy supports more than 2 modes, but the switch between the modes>2 is not allowed
115 iIDRPeriod = (rand() % 150) + 1;115 iIDRPeriod = (rand() % 150) + 1;
116 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);116 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
117 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);117 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
118 118
119 EncodeOneFrame (0);119 EncodeOneFrame (0);
120 120
121 if (info.eFrameType == videoFrameTypeIDR) {121 if (info.eFrameType == videoFrameTypeIDR) {
122 iEncCurIdrPicId = iEncCurIdrPicId + 1;122 iEncCurIdrPicId = iEncCurIdrPicId + 1;
123 }123 }
124 //decoding after each encoding frame124 //decoding after each encoding frame
125 int len = 0;125 int len = 0;
126 encToDecData (info, len);126 encToDecData (info, len);
127 unsigned char* pData[3] = { NULL };127 unsigned char* pData[3] = { NULL };
128 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));128 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
129 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);129 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
130 ASSERT_TRUE (rv == cmResultSuccess);130 ASSERT_TRUE (rv == cmResultSuccess);
131 decoder_->GetOption (DECODER_OPTION_IDR_PIC_ID, &iDecCurIdrPicId);131 decoder_->GetOption (DECODER_OPTION_IDR_PIC_ID, &iDecCurIdrPicId);
132 EXPECT_EQ (iDecCurIdrPicId, iEncCurIdrPicId);132 EXPECT_EQ (iDecCurIdrPicId, iEncCurIdrPicId);
133 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction133 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
134 ASSERT_TRUE (rv == cmResultSuccess);134 ASSERT_TRUE (rv == cmResultSuccess);
135 decoder_->GetOption (DECODER_OPTION_IDR_PIC_ID, &iDecCurIdrPicId);135 decoder_->GetOption (DECODER_OPTION_IDR_PIC_ID, &iDecCurIdrPicId);
136 EXPECT_EQ (iDecCurIdrPicId, iEncCurIdrPicId);136 EXPECT_EQ (iDecCurIdrPicId, iEncCurIdrPicId);
137 iIdx++;137 iIdx++;
138 } //while138 } //while
139 //ignore last frame139 //ignore last frame
140}140}
141 141
142TEST_P (EncodeDecodeTestAPI, InOutTimeStamp) {142TEST_P (EncodeDecodeTestAPI, InOutTimeStamp) {
143 EncodeDecodeFileParamBase p = GetParam();143 EncodeDecodeFileParamBase p = GetParam();
144 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);144 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
145 encoder_->Uninitialize();145 encoder_->Uninitialize();
146 int rv = encoder_->InitializeExt (&param_);146 int rv = encoder_->InitializeExt (&param_);
147 ASSERT_TRUE (rv == cmResultSuccess);147 ASSERT_TRUE (rv == cmResultSuccess);
148 148
149 ASSERT_TRUE (InitialEncDec (p.width, p.height));149 ASSERT_TRUE (InitialEncDec (p.width, p.height));
150 int32_t iTraceLevel = WELS_LOG_QUIET;150 int32_t iTraceLevel = WELS_LOG_QUIET;
151 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);151 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
152 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);152 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
153 int32_t iSpsPpsIdAddition = 1;153 int32_t iSpsPpsIdAddition = 1;
154 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);154 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
155 int32_t iIDRPeriod = 60;155 int32_t iIDRPeriod = 60;
156 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);156 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
157 SLTRConfig sLtrConfigVal;157 SLTRConfig sLtrConfigVal;
158 sLtrConfigVal.bEnableLongTermReference = 1;158 sLtrConfigVal.bEnableLongTermReference = 1;
159 sLtrConfigVal.iLTRRefNum = 1;159 sLtrConfigVal.iLTRRefNum = 1;
160 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);160 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
161 int32_t iLtrPeriod = 2;161 int32_t iLtrPeriod = 2;
162 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);162 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
163 int iIdx = 0;163 int iIdx = 0;
164 int iSkipedBytes;164 int iSkipedBytes;
165 unsigned long long uiEncTimeStamp = 100;165 unsigned long long uiEncTimeStamp = 100;
166 while (iIdx <= p.numframes) {166 while (iIdx <= p.numframes) {
167 EncodeOneFrame (1);167 EncodeOneFrame (1);
168 //decoding after each encoding frame168 //decoding after each encoding frame
169 int len = 0;169 int len = 0;
170 encToDecData (info, len);170 encToDecData (info, len);
171 unsigned char* pData[3] = { NULL };171 unsigned char* pData[3] = { NULL };
172 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));172 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
173 uint32_t uiEcIdc = ERROR_CON_SLICE_COPY_CROSS_IDR_FREEZE_RES_CHANGE;173 uint32_t uiEcIdc = ERROR_CON_SLICE_COPY_CROSS_IDR_FREEZE_RES_CHANGE;
174 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);174 decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc);
175 dstBufInfo_.uiInBsTimeStamp = uiEncTimeStamp;175 dstBufInfo_.uiInBsTimeStamp = uiEncTimeStamp;
176 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);176 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
177 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));177 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
178 dstBufInfo_.uiInBsTimeStamp = uiEncTimeStamp;178 dstBufInfo_.uiInBsTimeStamp = uiEncTimeStamp;
179 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction179 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
180 if (dstBufInfo_.iBufferStatus == 1) {180 if (dstBufInfo_.iBufferStatus == 1) {
181 EXPECT_EQ (uiEncTimeStamp, dstBufInfo_.uiOutYuvTimeStamp);181 EXPECT_EQ (uiEncTimeStamp, dstBufInfo_.uiOutYuvTimeStamp);
182 }182 }
183 iIdx++;183 iIdx++;
184 uiEncTimeStamp++;184 uiEncTimeStamp++;
185 }185 }
186 (void) iSkipedBytes;186 (void) iSkipedBytes;
187}187}
188 188
189TEST_P(EncodeDecodeTestAPI, GetOptionIsRefPic) {189TEST_P (EncodeDecodeTestAPI, GetOptionIsRefPic) {
190 EncodeDecodeFileParamBase p = GetParam();190 EncodeDecodeFileParamBase p = GetParam();
191 prepareParamDefault(1, p.slicenum, p.width, p.height, p.frameRate, &param_);191 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
192 encoder_->Uninitialize();192 encoder_->Uninitialize();
193 int rv = encoder_->InitializeExt(&param_);193 int rv = encoder_->InitializeExt (&param_);
194 ASSERT_TRUE(rv == cmResultSuccess);194 ASSERT_TRUE (rv == cmResultSuccess);
195 195
196 ASSERT_TRUE(InitialEncDec(p.width, p.height));196 ASSERT_TRUE (InitialEncDec (p.width, p.height));
197 int32_t iTraceLevel = WELS_LOG_QUIET;197 int32_t iTraceLevel = WELS_LOG_QUIET;
198 encoder_->SetOption(ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);198 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
199 decoder_->SetOption(DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);199 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
200 int iIdx = 0;200 int iIdx = 0;
201 int iSkipedBytes;201 int iSkipedBytes;
202 int iIsRefPic;202 int iIsRefPic;
203 decoder_->GetOption(DECODER_OPTION_IS_REF_PIC, &iIsRefPic);203 decoder_->GetOption (DECODER_OPTION_IS_REF_PIC, &iIsRefPic);
204 ASSERT_EQ(iIsRefPic, -1);204 ASSERT_EQ (iIsRefPic, -1);
205 205
206 while (iIdx <= p.numframes) {206 while (iIdx <= p.numframes) {
207 EncodeOneFrame(1);207 EncodeOneFrame (1);
208 //decoding after each encoding frame208 //decoding after each encoding frame
209 int len = 0;209 int len = 0;
210 encToDecData(info, len);210 encToDecData (info, len);
211 unsigned char* pData[3] = { NULL };211 unsigned char* pData[3] = { NULL };
212 memset(&dstBufInfo_, 0, sizeof(SBufferInfo));212 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
213 rv = decoder_->DecodeFrame2(info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);213 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
214 memset(&dstBufInfo_, 0, sizeof(SBufferInfo));214 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
215 decoder_->GetOption(DECODER_OPTION_IS_REF_PIC, &iIsRefPic);215 decoder_->GetOption (DECODER_OPTION_IS_REF_PIC, &iIsRefPic);
216 ASSERT_EQ(iIsRefPic, -1);216 ASSERT_EQ (iIsRefPic, -1);
217 rv = decoder_->DecodeFrame2(NULL, 0, pData, &dstBufInfo_); //reconstruction217 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
218 if (dstBufInfo_.iBufferStatus == 1) {218 if (dstBufInfo_.iBufferStatus == 1) {
219 decoder_->GetOption(DECODER_OPTION_IS_REF_PIC, &iIsRefPic);219 decoder_->GetOption (DECODER_OPTION_IS_REF_PIC, &iIsRefPic);
220 ASSERT_TRUE(iIsRefPic >= 0);220 ASSERT_TRUE (iIsRefPic >= 0);
221 }221 }
222 iIdx++;222 iIdx++;
223 }223 }
224 (void)iSkipedBytes;224 (void)iSkipedBytes;
225}225}
226 226
227TEST_P (EncodeDecodeTestAPI, GetOptionTid_AVC_NOPREFIX) {227TEST_P (EncodeDecodeTestAPI, GetOptionTid_AVC_NOPREFIX) {
228 SLTRMarkingFeedback m_LTR_Marking_Feedback;228 SLTRMarkingFeedback m_LTR_Marking_Feedback;
229 SLTRRecoverRequest m_LTR_Recover_Request;229 SLTRRecoverRequest m_LTR_Recover_Request;
230 m_LTR_Recover_Request.uiIDRPicId = 0;230 m_LTR_Recover_Request.uiIDRPicId = 0;
231 m_LTR_Recover_Request.iLayerId = 0;231 m_LTR_Recover_Request.iLayerId = 0;
232 m_LTR_Marking_Feedback.iLayerId = 0;232 m_LTR_Marking_Feedback.iLayerId = 0;
233 EncodeDecodeFileParamBase p = GetParam();233 EncodeDecodeFileParamBase p = GetParam();
234 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);234 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
235 param_.bPrefixNalAddingCtrl = false;235 param_.bPrefixNalAddingCtrl = false;
236 param_.iTemporalLayerNum = (rand() % 4) + 1;236 param_.iTemporalLayerNum = (rand() % 4) + 1;
237 encoder_->Uninitialize();237 encoder_->Uninitialize();
238 int rv = encoder_->InitializeExt (&param_);238 int rv = encoder_->InitializeExt (&param_);
239 ASSERT_TRUE (rv == cmResultSuccess);239 ASSERT_TRUE (rv == cmResultSuccess);
240 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;240 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
241 ASSERT_TRUE (InitialEncDec (p.width, p.height));241 ASSERT_TRUE (InitialEncDec (p.width, p.height));
242 int32_t iTraceLevel = WELS_LOG_QUIET;242 int32_t iTraceLevel = WELS_LOG_QUIET;
243 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);243 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
244 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);244 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
245 int32_t iSpsPpsIdAddition = 1;245 int32_t iSpsPpsIdAddition = 1;
246 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);246 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
247 int32_t iIDRPeriod = 60;247 int32_t iIDRPeriod = 60;
248 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);248 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
249 SLTRConfig sLtrConfigVal;249 SLTRConfig sLtrConfigVal;
250 sLtrConfigVal.bEnableLongTermReference = 1;250 sLtrConfigVal.bEnableLongTermReference = 1;
251 sLtrConfigVal.iLTRRefNum = 1;251 sLtrConfigVal.iLTRRefNum = 1;
252 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);252 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
253 int32_t iLtrPeriod = 2;253 int32_t iLtrPeriod = 2;
254 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);254 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
255 int iIdx = 0;255 int iIdx = 0;
256 int iLossIdx = 0;256 int iLossIdx = 0;
257 bool bVCLLoss = false;257 bool bVCLLoss = false;
258 while (iIdx <= p.numframes) {258 while (iIdx <= p.numframes) {
259 EncodeOneFrame (1);259 EncodeOneFrame (1);
260 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {260 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
261 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);261 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
262 }262 }
263 //decoding after each encoding frame263 //decoding after each encoding frame
264 int len = 0;264 int len = 0;
265 encToDecData (info, len);265 encToDecData (info, len);
266 unsigned char* pData[3] = { NULL };266 unsigned char* pData[3] = { NULL };
267 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));267 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
268 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);268 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);
269 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);269 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
270 int iTid = -1;270 int iTid = -1;
271 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);271 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
272 if (iTid != -1) {272 if (iTid != -1) {
273 ASSERT_EQ (iTid, 0);273 ASSERT_EQ (iTid, 0);
274 }274 }
275 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;275 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
276 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);276 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
277 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction277 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
278 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);278 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
279 std::vector<SLostSim>::iterator iter = m_SLostSim.begin();279 std::vector<SLostSim>::iterator iter = m_SLostSim.begin();
280 bool bHasVCL = false;280 bool bHasVCL = false;
281 for (unsigned int k = 0; k < m_SLostSim.size(); k++) {281 for (unsigned int k = 0; k < m_SLostSim.size(); k++) {
282 if (IS_VCL_NAL (iter->eNalType, 0) && iter->isLost == false) {282 if (IS_VCL_NAL (iter->eNalType, 0) && iter->isLost == false) {
283 bHasVCL = true;283 bHasVCL = true;
284 break;284 break;
285 }285 }
286 iter++;286 iter++;
287 }287 }
288 (void) bHasVCL;288 (void) bHasVCL;
289 if (iTid != -1) {289 if (iTid != -1) {
290 ASSERT_EQ (iTid, 0);290 ASSERT_EQ (iTid, 0);
291 }291 }
292 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);292 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
293 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);293 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
294 iIdx++;294 iIdx++;
295 }295 }
296}296}
297 297
298TEST_P (EncodeDecodeTestAPI, GetOptionTid_AVC_WITH_PREFIX_NOLOSS) {298TEST_P (EncodeDecodeTestAPI, GetOptionTid_AVC_WITH_PREFIX_NOLOSS) {
299 SLTRMarkingFeedback m_LTR_Marking_Feedback;299 SLTRMarkingFeedback m_LTR_Marking_Feedback;
300 SLTRRecoverRequest m_LTR_Recover_Request;300 SLTRRecoverRequest m_LTR_Recover_Request;
301 m_LTR_Recover_Request.uiIDRPicId = 0;301 m_LTR_Recover_Request.uiIDRPicId = 0;
302 m_LTR_Recover_Request.iLayerId = 0;302 m_LTR_Recover_Request.iLayerId = 0;
303 m_LTR_Marking_Feedback.iLayerId = 0;303 m_LTR_Marking_Feedback.iLayerId = 0;
304 EncodeDecodeFileParamBase p = GetParam();304 EncodeDecodeFileParamBase p = GetParam();
305 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);305 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
306 param_.bPrefixNalAddingCtrl = true;306 param_.bPrefixNalAddingCtrl = true;
307 param_.iTemporalLayerNum = (rand() % 4) + 1;307 param_.iTemporalLayerNum = (rand() % 4) + 1;
308 param_.iSpatialLayerNum = 1;308 param_.iSpatialLayerNum = 1;
309 encoder_->Uninitialize();309 encoder_->Uninitialize();
310 int rv = encoder_->InitializeExt (&param_);310 int rv = encoder_->InitializeExt (&param_);
311 ASSERT_TRUE (rv == cmResultSuccess);311 ASSERT_TRUE (rv == cmResultSuccess);
312 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;312 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
313 313
314 ASSERT_TRUE (InitialEncDec (p.width, p.height));314 ASSERT_TRUE (InitialEncDec (p.width, p.height));
315 int32_t iTraceLevel = WELS_LOG_QUIET;315 int32_t iTraceLevel = WELS_LOG_QUIET;
316 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);316 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
317 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);317 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
318 int32_t iSpsPpsIdAddition = 1;318 int32_t iSpsPpsIdAddition = 1;
319 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);319 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
320 int32_t iIDRPeriod = 60;320 int32_t iIDRPeriod = 60;
321 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);321 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
322 SLTRConfig sLtrConfigVal;322 SLTRConfig sLtrConfigVal;
323 sLtrConfigVal.bEnableLongTermReference = 1;323 sLtrConfigVal.bEnableLongTermReference = 1;
324 sLtrConfigVal.iLTRRefNum = 1;324 sLtrConfigVal.iLTRRefNum = 1;
325 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);325 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
326 int32_t iLtrPeriod = 2;326 int32_t iLtrPeriod = 2;
327 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);327 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
328 int iIdx = 0;328 int iIdx = 0;
329 while (iIdx <= p.numframes) {329 while (iIdx <= p.numframes) {
330 EncodeOneFrame (1);330 EncodeOneFrame (1);
331 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {331 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
332 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);332 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
333 }333 }
334 //decoding after each encoding frame334 //decoding after each encoding frame
335 int len = 0;335 int len = 0;
336 encToDecData (info, len);336 encToDecData (info, len);
337 unsigned char* pData[3] = { NULL };337 unsigned char* pData[3] = { NULL };
338 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));338 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
339 ExtractDidNal (&info, len, &m_SLostSim, 0);339 ExtractDidNal (&info, len, &m_SLostSim, 0);
340 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);340 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
341 int iTid = -1;341 int iTid = -1;
342 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);342 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
343 ASSERT_EQ (iTid, -1);343 ASSERT_EQ (iTid, -1);
344 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;344 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
345 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);345 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
346 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction346 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
347 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);347 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
348 ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId);348 ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId);
349 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);349 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
350 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);350 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
351 iIdx++;351 iIdx++;
352 }352 }
353}353}
354 354
355TEST_P (EncodeDecodeTestAPI, GetOptionTid_SVC_L1_NOLOSS) {355TEST_P (EncodeDecodeTestAPI, GetOptionTid_SVC_L1_NOLOSS) {
356 SLTRMarkingFeedback m_LTR_Marking_Feedback;356 SLTRMarkingFeedback m_LTR_Marking_Feedback;
357 SLTRRecoverRequest m_LTR_Recover_Request;357 SLTRRecoverRequest m_LTR_Recover_Request;
358 m_LTR_Recover_Request.uiIDRPicId = 0;358 m_LTR_Recover_Request.uiIDRPicId = 0;
359 m_LTR_Recover_Request.iLayerId = 0;359 m_LTR_Recover_Request.iLayerId = 0;
360 m_LTR_Marking_Feedback.iLayerId = 0;360 m_LTR_Marking_Feedback.iLayerId = 0;
361 EncodeDecodeFileParamBase p = GetParam();361 EncodeDecodeFileParamBase p = GetParam();
362 prepareParamDefault (2, p.slicenum, p.width, p.height, p.frameRate, &param_);362 prepareParamDefault (2, p.slicenum, p.width, p.height, p.frameRate, &param_);
363 param_.iTemporalLayerNum = (rand() % 4) + 1;363 param_.iTemporalLayerNum = (rand() % 4) + 1;
364 param_.iSpatialLayerNum = 2;364 param_.iSpatialLayerNum = 2;
365 encoder_->Uninitialize();365 encoder_->Uninitialize();
366 int rv = encoder_->InitializeExt (&param_);366 int rv = encoder_->InitializeExt (&param_);
367 ASSERT_TRUE (rv == cmResultSuccess);367 ASSERT_TRUE (rv == cmResultSuccess);
368 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;368 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
369 369
370 ASSERT_TRUE (InitialEncDec (p.width, p.height));370 ASSERT_TRUE (InitialEncDec (p.width, p.height));
371 int32_t iTraceLevel = WELS_LOG_QUIET;371 int32_t iTraceLevel = WELS_LOG_QUIET;
372 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);372 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
373 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);373 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
374 int32_t iSpsPpsIdAddition = 1;374 int32_t iSpsPpsIdAddition = 1;
375 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);375 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
376 int32_t iIDRPeriod = 60;376 int32_t iIDRPeriod = 60;
377 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);377 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
378 SLTRConfig sLtrConfigVal;378 SLTRConfig sLtrConfigVal;
379 sLtrConfigVal.bEnableLongTermReference = 1;379 sLtrConfigVal.bEnableLongTermReference = 1;
380 sLtrConfigVal.iLTRRefNum = 1;380 sLtrConfigVal.iLTRRefNum = 1;
381 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);381 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
382 int32_t iLtrPeriod = 2;382 int32_t iLtrPeriod = 2;
383 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);383 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
384 int iIdx = 0;384 int iIdx = 0;
385 while (iIdx <= p.numframes) {385 while (iIdx <= p.numframes) {
386 EncodeOneFrame (1);386 EncodeOneFrame (1);
387 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {387 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
388 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);388 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
389 }389 }
390 //decoding after each encoding frame390 //decoding after each encoding frame
391 int len = 0;391 int len = 0;
392 encToDecData (info, len);392 encToDecData (info, len);
393 unsigned char* pData[3] = { NULL };393 unsigned char* pData[3] = { NULL };
394 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));394 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
395 ExtractDidNal (&info, len, &m_SLostSim, 1);395 ExtractDidNal (&info, len, &m_SLostSim, 1);
396 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);396 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
397 int iTid = -1;397 int iTid = -1;
398 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);398 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
399 ASSERT_EQ (iTid, -1);399 ASSERT_EQ (iTid, -1);
400 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;400 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
401 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);401 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
402 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction402 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
403 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);403 decoder_->GetOption (DECODER_OPTION_TEMPORAL_ID, &iTid);
404 ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId);404 ASSERT_EQ (iTid, info.sLayerInfo[0].uiTemporalId);
405 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);405 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
406 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);406 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
407 iIdx++;407 iIdx++;
408 }408 }
409}409}
410 410
411 411
412 412
413TEST_P (EncodeDecodeTestAPI, SetOption_Trace) {413TEST_P (EncodeDecodeTestAPI, SetOption_Trace) {
414 SLTRMarkingFeedback m_LTR_Marking_Feedback;414 SLTRMarkingFeedback m_LTR_Marking_Feedback;
415 SLTRRecoverRequest m_LTR_Recover_Request;415 SLTRRecoverRequest m_LTR_Recover_Request;
416 m_LTR_Recover_Request.uiIDRPicId = 0;416 m_LTR_Recover_Request.uiIDRPicId = 0;
417 m_LTR_Recover_Request.iLayerId = 0;417 m_LTR_Recover_Request.iLayerId = 0;
418 m_LTR_Marking_Feedback.iLayerId = 0;418 m_LTR_Marking_Feedback.iLayerId = 0;
419 EncodeDecodeFileParamBase p = GetParam();419 EncodeDecodeFileParamBase p = GetParam();
420 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);420 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
421 param_.iSpatialLayerNum = 1;421 param_.iSpatialLayerNum = 1;
422 422
423 int rv = encoder_->InitializeExt (&param_);423 int rv = encoder_->InitializeExt (&param_);
424 ASSERT_TRUE (rv == cmResultSuccess);424 ASSERT_TRUE (rv == cmResultSuccess);
425 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;425 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
426 426
427 ASSERT_TRUE (InitialEncDec (p.width, p.height));427 ASSERT_TRUE (InitialEncDec (p.width, p.height));
428 int32_t iTraceLevel = WELS_LOG_QUIET;428 int32_t iTraceLevel = WELS_LOG_QUIET;
429 pFunc = TestOutPutTrace;429 pFunc = TestOutPutTrace;
430 pTraceInfo = &sTrace;430 pTraceInfo = &sTrace;
431 sTrace.iTarLevel = iTraceLevel;431 sTrace.iTarLevel = iTraceLevel;
432 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);432 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
433 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);433 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
434 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK, &pFunc);434 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK, &pFunc);
435 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);435 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
436 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK, &pFunc);436 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK, &pFunc);
437 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);437 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
438 438
439 439
440 int32_t iSpsPpsIdAddition = 1;440 int32_t iSpsPpsIdAddition = 1;
441 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);441 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
442 int32_t iIDRPeriod = 60;442 int32_t iIDRPeriod = 60;
443 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);443 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
444 SLTRConfig sLtrConfigVal;444 SLTRConfig sLtrConfigVal;
445 sLtrConfigVal.bEnableLongTermReference = 1;445 sLtrConfigVal.bEnableLongTermReference = 1;
446 sLtrConfigVal.iLTRRefNum = 1;446 sLtrConfigVal.iLTRRefNum = 1;
447 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);447 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
448 int32_t iLtrPeriod = 2;448 int32_t iLtrPeriod = 2;
449 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);449 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
450 int iIdx = 0;450 int iIdx = 0;
451 int iLossIdx = 0;451 int iLossIdx = 0;
452 bool bVCLLoss = false;452 bool bVCLLoss = false;
453 while (iIdx <= p.numframes) {453 while (iIdx <= p.numframes) {
454 iTraceLevel = rand() % 33;454 iTraceLevel = rand() % 33;
455 sTrace.iTarLevel = iTraceLevel;455 sTrace.iTarLevel = iTraceLevel;
456 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);456 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
457 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);457 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
458 EncodeOneFrame (1);458 EncodeOneFrame (1);
459 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {459 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
460 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);460 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
461 }461 }
462 //decoding after each encoding frame462 //decoding after each encoding frame
463 int len = 0;463 int len = 0;
464 encToDecData (info, len);464 encToDecData (info, len);
465 unsigned char* pData[3] = { NULL };465 unsigned char* pData[3] = { NULL };
466 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));466 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
467 ExtractDidNal (&info, len, &m_SLostSim, 0);467 ExtractDidNal (&info, len, &m_SLostSim, 0);
468 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);468 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);
469 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);469 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
470 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;470 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
471 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);471 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
472 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction472 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
473 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);473 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
474 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);474 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
475 iIdx++;475 iIdx++;
476 }476 }
477}477}
478 478
479TEST_P (EncodeDecodeTestAPI, SetOption_Trace_NULL) {479TEST_P (EncodeDecodeTestAPI, SetOption_Trace_NULL) {
480 SLTRMarkingFeedback m_LTR_Marking_Feedback;480 SLTRMarkingFeedback m_LTR_Marking_Feedback;
481 SLTRRecoverRequest m_LTR_Recover_Request;481 SLTRRecoverRequest m_LTR_Recover_Request;
482 m_LTR_Recover_Request.uiIDRPicId = 0;482 m_LTR_Recover_Request.uiIDRPicId = 0;
483 m_LTR_Recover_Request.iLayerId = 0;483 m_LTR_Recover_Request.iLayerId = 0;
484 m_LTR_Marking_Feedback.iLayerId = 0;484 m_LTR_Marking_Feedback.iLayerId = 0;
485 EncodeDecodeFileParamBase p = GetParam();485 EncodeDecodeFileParamBase p = GetParam();
486 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);486 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
487 param_.iSpatialLayerNum = 1;487 param_.iSpatialLayerNum = 1;
488 int rv = encoder_->InitializeExt (&param_);488 int rv = encoder_->InitializeExt (&param_);
489 ASSERT_TRUE (rv == cmResultSuccess);489 ASSERT_TRUE (rv == cmResultSuccess);
490 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;490 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
491 491
492 ASSERT_TRUE (InitialEncDec (p.width, p.height));492 ASSERT_TRUE (InitialEncDec (p.width, p.height));
493 493
494 int32_t iTraceLevel = WELS_LOG_QUIET;494 int32_t iTraceLevel = WELS_LOG_QUIET;
495 pFunc = NULL;495 pFunc = NULL;
496 pTraceInfo = NULL;496 pTraceInfo = NULL;
497 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK, &pFunc);497 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK, &pFunc);
498 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);498 encoder_->SetOption (ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
499 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK, &pFunc);499 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK, &pFunc);
500 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);500 decoder_->SetOption (DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &pTraceInfo);
501 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);501 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
502 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);502 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
503 503
504 int32_t iSpsPpsIdAddition = 1;504 int32_t iSpsPpsIdAddition = 1;
505 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);505 encoder_->SetOption (ENCODER_OPTION_SPS_PPS_ID_STRATEGY, &iSpsPpsIdAddition);
506 int32_t iIDRPeriod = 60;506 int32_t iIDRPeriod = 60;
507 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);507 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
508 SLTRConfig sLtrConfigVal;508 SLTRConfig sLtrConfigVal;
509 sLtrConfigVal.bEnableLongTermReference = 1;509 sLtrConfigVal.bEnableLongTermReference = 1;
510 sLtrConfigVal.iLTRRefNum = 1;510 sLtrConfigVal.iLTRRefNum = 1;
511 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);511 encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal);
512 int32_t iLtrPeriod = 2;512 int32_t iLtrPeriod = 2;
513 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);513 encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod);
514 int iIdx = 0;514 int iIdx = 0;
515 int iLossIdx = 0;515 int iLossIdx = 0;
516 bool bVCLLoss = false;516 bool bVCLLoss = false;
517 while (iIdx <= p.numframes) {517 while (iIdx <= p.numframes) {
518 iTraceLevel = rand() % 33;518 iTraceLevel = rand() % 33;
519 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);519 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
520 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);520 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
521 EncodeOneFrame (1);521 EncodeOneFrame (1);
522 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {522 if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) {
523 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);523 ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR);
524 }524 }
525 //decoding after each encoding frame525 //decoding after each encoding frame
526 int len = 0;526 int len = 0;
527 encToDecData (info, len);527 encToDecData (info, len);
528 unsigned char* pData[3] = { NULL };528 unsigned char* pData[3] = { NULL };
529 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));529 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
530 ExtractDidNal (&info, len, &m_SLostSim, 0);530 ExtractDidNal (&info, len, &m_SLostSim, 0);
531 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);531 SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss);
532 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);532 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
533 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;533 m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET;
534 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);534 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
535 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction535 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
536 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);536 LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv, true);
537 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);537 LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv);
538 iIdx++;538 iIdx++;
539 }539 }
540}540}
541 541
542 542
543 543
544 544
545class DecodeCrashTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase {545class DecodeCrashTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase {
546 public:546 public:
547 void SetUp() {547 void SetUp() {
548 EncodeDecodeTestBase::SetUp();548 EncodeDecodeTestBase::SetUp();
549 ucBuf_ = NULL;549 ucBuf_ = NULL;
550 ucBuf_ = new unsigned char [1000000];550 ucBuf_ = new unsigned char [1000000];
551 ASSERT_TRUE (ucBuf_ != NULL);551 ASSERT_TRUE (ucBuf_ != NULL);
552 }552 }
553 553
554 void TearDown() {554 void TearDown() {
555 EncodeDecodeTestBase::TearDown();555 EncodeDecodeTestBase::TearDown();
556 if (NULL != ucBuf_) {556 if (NULL != ucBuf_) {
557 delete[] ucBuf_;557 delete[] ucBuf_;
558 ucBuf_ = NULL;558 ucBuf_ = NULL;
559 }559 }
560 ASSERT_TRUE (ucBuf_ == NULL);560 ASSERT_TRUE (ucBuf_ == NULL);
561 }561 }
562 562
563 void prepareParam (int iLayerNum, int iSliceNum, int width, int height, float framerate, SEncParamExt* pParam) {563 void prepareParam (int iLayerNum, int iSliceNum, int width, int height, float framerate, SEncParamExt* pParam) {
564 memset (pParam, 0, sizeof (SEncParamExt));564 memset (pParam, 0, sizeof (SEncParamExt));
565 EncodeDecodeTestBase::prepareParam (iLayerNum, iSliceNum, width, height, framerate, pParam);565 EncodeDecodeTestBase::prepareParam (iLayerNum, iSliceNum, width, height, framerate, pParam);
566 }566 }
567 567
568 void EncodeOneFrame() {568 void EncodeOneFrame() {
569 int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;569 int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;
570 memset (buf_.data(), iRandValue, (frameSize >> 2));570 memset (buf_.data(), iRandValue, (frameSize >> 2));
571 memset (buf_.data() + (frameSize >> 2), rand() % 256, (frameSize - (frameSize >> 2)));571 memset (buf_.data() + (frameSize >> 2), rand() % 256, (frameSize - (frameSize >> 2)));
572 int rv = encoder_->EncodeFrame (&EncPic, &info);572 int rv = encoder_->EncodeFrame (&EncPic, &info);
573 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);573 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);
574 }574 }
575 protected:575 protected:
576 unsigned char* ucBuf_;576 unsigned char* ucBuf_;
577};577};
578 578
579struct EncodeDecodeParamBase {579struct EncodeDecodeParamBase {
580 int width;580 int width;
581 int height;581 int height;
582 float frameRate;582 float frameRate;
583 int iTarBitrate;583 int iTarBitrate;
584};584};
585 585
586#define NUM_OF_POSSIBLE_RESOLUTION (9)586#define NUM_OF_POSSIBLE_RESOLUTION (9)
587static const EncodeDecodeParamBase kParamArray[] = {587static const EncodeDecodeParamBase kParamArray[] = {
588 {160, 90, 6.0f, 250000},588 {160, 90, 6.0f, 250000},
589 {90, 160, 6.0f, 250000},589 {90, 160, 6.0f, 250000},
590 {320, 180, 12.0f, 500000},590 {320, 180, 12.0f, 500000},
591 {180, 320, 12.0f, 500000},591 {180, 320, 12.0f, 500000},
592 {480, 270, 12.0f, 600000},592 {480, 270, 12.0f, 600000},
593 {270, 480, 12.0f, 600000},593 {270, 480, 12.0f, 600000},
594 {640, 360, 24.0f, 800000},594 {640, 360, 24.0f, 800000},
595 {360, 640, 24.0f, 800000},595 {360, 640, 24.0f, 800000},
596 {1280, 720, 24.0f, 1000000},596 {1280, 720, 24.0f, 1000000},
597};597};
598 598
599//#define DEBUG_FILE_SAVE_CRA599//#define DEBUG_FILE_SAVE_CRA
600TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {600TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
601 uint32_t uiGet;601 uint32_t uiGet;
602 encoder_->Uninitialize();602 encoder_->Uninitialize();
603 603
604 //do tests until crash604 //do tests until crash
605 unsigned int uiLoopRound = 0;605 unsigned int uiLoopRound = 0;
606 unsigned char* pucBuf = ucBuf_;606 unsigned char* pucBuf = ucBuf_;
607 int iDecAuSize;607 int iDecAuSize;
608#ifdef DEBUG_FILE_SAVE_CRA608#ifdef DEBUG_FILE_SAVE_CRA
609 //open file to save tested BS609 //open file to save tested BS
610 FILE* fDataFile = fopen ("test_crash.264", "wb");610 FILE* fDataFile = fopen ("test_crash.264", "wb");
611 FILE* fLenFile = fopen ("test_crash_len.log", "w");611 FILE* fLenFile = fopen ("test_crash_len.log", "w");
612 int iFileSize = 0;612 int iFileSize = 0;
613#endif613#endif
614 614
615 //set eCurStrategy for one test615 //set eCurStrategy for one test
616 EParameterSetStrategy eCurStrategy = CONSTANT_ID;616 EParameterSetStrategy eCurStrategy = CONSTANT_ID;
617 switch (rand() % 7) {617 switch (rand() % 7) {
618 case 1:618 case 1:
619 eCurStrategy = INCREASING_ID;619 eCurStrategy = INCREASING_ID;
620 break;620 break;
621 case 2:621 case 2:
622 eCurStrategy = SPS_LISTING;622 eCurStrategy = SPS_LISTING;
623 break;623 break;
624 case 3:624 case 3:
625 eCurStrategy = SPS_LISTING_AND_PPS_INCREASING;625 eCurStrategy = SPS_LISTING_AND_PPS_INCREASING;
626 break;626 break;
627 case 6:627 case 6:
628 eCurStrategy = SPS_PPS_LISTING;628 eCurStrategy = SPS_PPS_LISTING;
629 break;629 break;
630 default:630 default:
631 //using the initial value631 //using the initial value
632 break;632 break;
633 }633 }
634 634
635 do {635 do {
636 int iTotalFrameNum = (rand() % 100) + 1;636 int iTotalFrameNum = (rand() % 100) + 1;
637 int iSeed = rand() % NUM_OF_POSSIBLE_RESOLUTION;637 int iSeed = rand() % NUM_OF_POSSIBLE_RESOLUTION;
638 EncodeDecodeParamBase p = kParamArray[iSeed];638 EncodeDecodeParamBase p = kParamArray[iSeed];
639#ifdef DEBUG_FILE_SAVE_CRA639#ifdef DEBUG_FILE_SAVE_CRA
640 printf ("using param set %d in loop %d\n", iSeed, uiLoopRound);640 printf ("using param set %d in loop %d\n", iSeed, uiLoopRound);
641#endif641#endif
642 //Initialize Encoder642 //Initialize Encoder
643 prepareParam (1, 1, p.width, p.height, p.frameRate, &param_);643 prepareParam (1, 1, p.width, p.height, p.frameRate, &param_);
644 param_.iRCMode = RC_TIMESTAMP_MODE;644 param_.iRCMode = RC_TIMESTAMP_MODE;
645 param_.iTargetBitrate = p.iTarBitrate;645 param_.iTargetBitrate = p.iTarBitrate;
646 param_.uiIntraPeriod = 0;646 param_.uiIntraPeriod = 0;
647 param_.eSpsPpsIdStrategy = eCurStrategy;647 param_.eSpsPpsIdStrategy = eCurStrategy;
648 param_.bEnableBackgroundDetection = true;648 param_.bEnableBackgroundDetection = true;
649 param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false;649 param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false;
650 param_.bPrefixNalAddingCtrl = (rand() % 2) ? true : false;650 param_.bPrefixNalAddingCtrl = (rand() % 2) ? true : false;
651 param_.iEntropyCodingModeFlag = 0;651 param_.iEntropyCodingModeFlag = 0;
652 param_.bEnableFrameSkip = true;652 param_.bEnableFrameSkip = true;
653 param_.iMultipleThreadIdc = 0;653 param_.iMultipleThreadIdc = 0;
654 param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;654 param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;
655 param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;655 param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;
656 param_.sSpatialLayers[0].sSliceArgument.uiSliceMode = (rand() % 2) ? SM_SIZELIMITED_SLICE : SM_SINGLE_SLICE;656 param_.sSpatialLayers[0].sSliceArgument.uiSliceMode = (rand() % 2) ? SM_SIZELIMITED_SLICE : SM_SINGLE_SLICE;
657 if (param_.sSpatialLayers[0].sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE) {657 if (param_.sSpatialLayers[0].sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE) {
658 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 1400;658 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 1400;
659 param_.uiMaxNalSize = 1400;659 param_.uiMaxNalSize = 1400;
660 } else {660 } else {
661 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 0;661 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 0;
662 param_.uiMaxNalSize = 0;662 param_.uiMaxNalSize = 0;
663 }663 }
664 664
665 int rv = encoder_->InitializeExt (&param_);665 int rv = encoder_->InitializeExt (&param_);
666 ASSERT_TRUE (rv == cmResultSuccess);666 ASSERT_TRUE (rv == cmResultSuccess);
667 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);667 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
668 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY668 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY); //default value should be ERROR_CON_SLICE_COPY
669 int32_t iTraceLevel = WELS_LOG_QUIET;669 int32_t iTraceLevel = WELS_LOG_QUIET;
670 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);670 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
671 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);671 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
672 672
673 //Start for enc/dec673 //Start for enc/dec
674 int iIdx = 0;674 int iIdx = 0;
675 unsigned char* pData[3] = { NULL };675 unsigned char* pData[3] = { NULL };
676 676
677 EncodeDecodeFileParamBase pInput; //to conform with old functions677 EncodeDecodeFileParamBase pInput; //to conform with old functions
678 pInput.width = p.width;678 pInput.width = p.width;
679 pInput.height = p.height;679 pInput.height = p.height;
680 pInput.frameRate = p.frameRate;680 pInput.frameRate = p.frameRate;
681 ASSERT_TRUE (prepareEncDecParam (pInput));681 ASSERT_TRUE (prepareEncDecParam (pInput));
682 while (iIdx++ < iTotalFrameNum) { // loop in frame682 while (iIdx++ < iTotalFrameNum) { // loop in frame
683 EncodeOneFrame();683 EncodeOneFrame();
684#ifdef DEBUG_FILE_SAVE_CRA684#ifdef DEBUG_FILE_SAVE_CRA
685 //reset file if file size large685 //reset file if file size large
686 if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {686 if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {
687 fclose (fDataFile);687 fclose (fDataFile);
688 fDataFile = fopen ("test_crash.264", "wb");688 fDataFile = fopen ("test_crash.264", "wb");
689 iFileSize = 0;689 iFileSize = 0;
690 decoder_->Uninitialize();690 decoder_->Uninitialize();
691 691
692 SDecodingParam decParam;692 SDecodingParam decParam;
693 memset (&decParam, 0, sizeof (SDecodingParam));693 memset (&decParam, 0, sizeof (SDecodingParam));
694 decParam.uiTargetDqLayer = UCHAR_MAX;694 decParam.uiTargetDqLayer = UCHAR_MAX;
695 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;695 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
696 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;696 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
697 697
698 rv = decoder_->Initialize (&decParam);698 rv = decoder_->Initialize (&decParam);
699 ASSERT_EQ (0, rv);699 ASSERT_EQ (0, rv);
700 }700 }
701#endif701#endif
702 if (info.eFrameType == videoFrameTypeSkip)702 if (info.eFrameType == videoFrameTypeSkip)
703 continue;703 continue;
704 //deal with packets704 //deal with packets
705 unsigned char* pBsBuf;705 unsigned char* pBsBuf;
706 iDecAuSize = 0;706 iDecAuSize = 0;
707 pucBuf = ucBuf_; //init buf start pos for decoder usage707 pucBuf = ucBuf_; //init buf start pos for decoder usage
708 for (int iLayerNum = 0; iLayerNum < info.iLayerNum; iLayerNum++) {708 for (int iLayerNum = 0; iLayerNum < info.iLayerNum; iLayerNum++) {
709 SLayerBSInfo* pLayerBsInfo = &info.sLayerInfo[iLayerNum];709 SLayerBSInfo* pLayerBsInfo = &info.sLayerInfo[iLayerNum];
710 pBsBuf = info.sLayerInfo[iLayerNum].pBsBuf;710 pBsBuf = info.sLayerInfo[iLayerNum].pBsBuf;
711 int iTotalNalCnt = pLayerBsInfo->iNalCount;711 int iTotalNalCnt = pLayerBsInfo->iNalCount;
712 for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL712 for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL
713 int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];713 int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];
714 //packet loss714 //packet loss
715 int iLossRateRange = (uiLoopRound % 100) + 1; //1-100715 int iLossRateRange = (uiLoopRound % 100) + 1; //1-100
716 int iLossRate = (rand() % iLossRateRange);716 int iLossRate = (rand() % iLossRateRange);
717 bool bPacketLost = (rand() % 101) > (100 -717 bool bPacketLost = (rand() % 101) > (100 -
718 iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS718 iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS
719 if (!bPacketLost) { //no loss719 if (!bPacketLost) { //no loss
720 memcpy (pucBuf, pBsBuf, iPacketSize);720 memcpy (pucBuf, pBsBuf, iPacketSize);
721 pucBuf += iPacketSize;721 pucBuf += iPacketSize;
722 iDecAuSize += iPacketSize;722 iDecAuSize += iPacketSize;
723 }723 }
724#ifdef DEBUG_FILE_SAVE_CRA724#ifdef DEBUG_FILE_SAVE_CRA
725 else {725 else {
726 printf ("lost packet size=%d at frame-type=%d at loss rate %d (%d)\n", iPacketSize, info.eFrameType, iLossRate,726 printf ("lost packet size=%d at frame-type=%d at loss rate %d (%d)\n", iPacketSize, info.eFrameType, iLossRate,
727 iLossRateRange);727 iLossRateRange);
728 }728 }
729#endif729#endif
730 //update bs info730 //update bs info
731 pBsBuf += iPacketSize;731 pBsBuf += iPacketSize;
732 } //nal732 } //nal
733 } //layer733 } //layer
734 734
735#ifdef DEBUG_FILE_SAVE_CRA735#ifdef DEBUG_FILE_SAVE_CRA
736 //save to file736 //save to file
737 fwrite (ucBuf_, 1, iDecAuSize, fDataFile);737 fwrite (ucBuf_, 1, iDecAuSize, fDataFile);
738 fflush (fDataFile);738 fflush (fDataFile);
739 iFileSize += iDecAuSize;739 iFileSize += iDecAuSize;
740 740
741 //save to len file741 //save to len file
742 unsigned long ulTmp[4];742 unsigned long ulTmp[4];
743 ulTmp[0] = ulTmp[1] = ulTmp[2] = iIdx;743 ulTmp[0] = ulTmp[1] = ulTmp[2] = iIdx;
744 ulTmp[3] = iDecAuSize;744 ulTmp[3] = iDecAuSize;
745 fwrite (ulTmp, sizeof (unsigned long), 4, fLenFile); // index, timeStamp, data size745 fwrite (ulTmp, sizeof (unsigned long), 4, fLenFile); // index, timeStamp, data size
746 fflush (fLenFile);746 fflush (fLenFile);
747#endif747#endif
748 748
749 //decode749 //decode
750 pData[0] = pData[1] = pData[2] = 0;750 pData[0] = pData[1] = pData[2] = 0;
751 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));751 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
752 752
753 rv = decoder_->DecodeFrame2 (ucBuf_, iDecAuSize, pData, &dstBufInfo_);753 rv = decoder_->DecodeFrame2 (ucBuf_, iDecAuSize, pData, &dstBufInfo_);
754 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction754 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
755 //guarantee decoder EC status755 //guarantee decoder EC status
756 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);756 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
757 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY);757 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_SLICE_COPY);
758 } //frame758 } //frame
759 uiLoopRound ++;759 uiLoopRound ++;
760 if (uiLoopRound >= (1 << 30))760 if (uiLoopRound >= (1 << 30))
761 uiLoopRound = 0;761 uiLoopRound = 0;
762#ifdef DEBUG_FILE_SAVE_CRA762#ifdef DEBUG_FILE_SAVE_CRA
763 if (uiLoopRound % 100 == 0)763 if (uiLoopRound % 100 == 0)
764 printf ("run %d times.\n", uiLoopRound);764 printf ("run %d times.\n", uiLoopRound);
765 } while (1); //while (iLoopRound<100);765 } while (1); //while (iLoopRound<100);
766 fclose (fDataFile);766 fclose (fDataFile);
767 fclose (fLenFile);767 fclose (fLenFile);
768#else768#else
769 }769 }
770 while (uiLoopRound < 10);770 while (uiLoopRound < 10);
771#endif771#endif
772 772
773}773}
774 774
775const uint32_t kiTotalLayer = 3; //DO NOT CHANGE!775const uint32_t kiTotalLayer = 3; //DO NOT CHANGE!
776const uint32_t kiSliceNum = 2; //DO NOT CHANGE!776const uint32_t kiSliceNum = 2; //DO NOT CHANGE!
777const uint32_t kiWidth = 160; //DO NOT CHANGE!777const uint32_t kiWidth = 160; //DO NOT CHANGE!
778const uint32_t kiHeight = 96; //DO NOT CHANGE!778const uint32_t kiHeight = 96; //DO NOT CHANGE!
779const uint32_t kiFrameRate = 12; //DO NOT CHANGE!779const uint32_t kiFrameRate = 12; //DO NOT CHANGE!
780const uint32_t kiFrameNum = 100; //DO NOT CHANGE!780const uint32_t kiFrameNum = 100; //DO NOT CHANGE!
781const char* const pHashStr[][2] = { //DO NOT CHANGE!781const char* const pHashStr[][2] = { //DO NOT CHANGE!
782 // Allow for different output depending on whether averaging is done782 // Allow for different output depending on whether averaging is done
783 // vertically or horizontally first when downsampling.783 // vertically or horizontally first when downsampling.
784 { "caaaa3352ab8614e3a35836f5d7c9a528294e953", "326cc236e9ba5277aedc5cf0865dd4cbd2f89fe0" },784 { "caaaa3352ab8614e3a35836f5d7c9a528294e953", "326cc236e9ba5277aedc5cf0865dd4cbd2f89fe0" },
785 { "2dc97661e94515d9947a344127062f82814afc2a", "72f36bb33d190979be88077c6166a09767dd2992" },785 { "2dc97661e94515d9947a344127062f82814afc2a", "72f36bb33d190979be88077c6166a09767dd2992" },
786 { "106ec96a90412aabea5c0cfa6bfc654a0b5db33e", "998c2947bccf140bde1e43e29376614038eb7c71" }786 { "106ec96a90412aabea5c0cfa6bfc654a0b5db33e", "998c2947bccf140bde1e43e29376614038eb7c71" }
787};787};
788 788
789class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase {789class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase {
790 public:790 public:
791 DecodeParseAPI() {791 DecodeParseAPI() {
792 memset (&BsInfo_, 0, sizeof (SParserBsInfo));792 memset (&BsInfo_, 0, sizeof (SParserBsInfo));
793 fYuv_ = NULL;793 fYuv_ = NULL;
794 iWidth_ = 0;794 iWidth_ = 0;
795 iHeight_ = 0;795 iHeight_ = 0;
796 memset (&ctx_, 0, sizeof (SHA1Context));796 memset (&ctx_, 0, sizeof (SHA1Context));
797 }797 }
798 void SetUp() {798 void SetUp() {
799 SHA1Reset (&ctx_);799 SHA1Reset (&ctx_);
800 EncodeDecodeTestBase::SetUp();800 EncodeDecodeTestBase::SetUp();
801 801
802 if (decoder_)802 if (decoder_)
803 decoder_->Uninitialize();803 decoder_->Uninitialize();
804 SDecodingParam decParam;804 SDecodingParam decParam;
805 memset (&decParam, 0, sizeof (SDecodingParam));805 memset (&decParam, 0, sizeof (SDecodingParam));
806 decParam.uiTargetDqLayer = UCHAR_MAX;806 decParam.uiTargetDqLayer = UCHAR_MAX;
807 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;807 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
808 decParam.bParseOnly = true;808 decParam.bParseOnly = true;
809 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;809 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
810 810
811 int rv = decoder_->Initialize (&decParam);811 int rv = decoder_->Initialize (&decParam);
812 ASSERT_EQ (0, rv);812 ASSERT_EQ (0, rv);
813 memset (&BsInfo_, 0, sizeof (SParserBsInfo));813 memset (&BsInfo_, 0, sizeof (SParserBsInfo));
814 const char* sFileName = "res/CiscoVT2people_160x96_6fps.yuv";814 const char* sFileName = "res/CiscoVT2people_160x96_6fps.yuv";
815#if defined(ANDROID_NDK)815#if defined(ANDROID_NDK)
816 std::string filename = std::string ("/sdcard/") + sFileName;816 std::string filename = std::string ("/sdcard/") + sFileName;
817 ASSERT_TRUE ((fYuv_ = fopen (filename.c_str(), "rb")) != NULL);817 ASSERT_TRUE ((fYuv_ = fopen (filename.c_str(), "rb")) != NULL);
818#else818#else
819 ASSERT_TRUE ((fYuv_ = fopen (sFileName, "rb")) != NULL);819 ASSERT_TRUE ((fYuv_ = fopen (sFileName, "rb")) != NULL);
820#endif820#endif
821 iWidth_ = kiWidth;821 iWidth_ = kiWidth;
822 iHeight_ = kiHeight;822 iHeight_ = kiHeight;
823 }823 }
824 void TearDown() {824 void TearDown() {
825 EncodeDecodeTestBase::TearDown();825 EncodeDecodeTestBase::TearDown();
826 if (fYuv_ != NULL) {826 if (fYuv_ != NULL) {
827 fclose (fYuv_);827 fclose (fYuv_);
828 fYuv_ = NULL;828 fYuv_ = NULL;
829 }829 }
830 }830 }
831 831
832 bool prepareEncDecParam (const EncodeDecodeFileParamBase p) {832 bool prepareEncDecParam (const EncodeDecodeFileParamBase p) {
833 if (!EncodeDecodeTestBase::prepareEncDecParam (p))833 if (!EncodeDecodeTestBase::prepareEncDecParam (p))
834 return false;834 return false;
835 unsigned char* pTmpPtr = BsInfo_.pDstBuff; //store for restore835 unsigned char* pTmpPtr = BsInfo_.pDstBuff; //store for restore
836 memset (&BsInfo_, 0, sizeof (SParserBsInfo));836 memset (&BsInfo_, 0, sizeof (SParserBsInfo));
837 BsInfo_.pDstBuff = pTmpPtr;837 BsInfo_.pDstBuff = pTmpPtr;
838 return true;838 return true;
839 }839 }
840 840
841 void MockInputData (uint8_t* pData, int32_t iSize) {841 void MockInputData (uint8_t* pData, int32_t iSize) {
842 int32_t iCurr = 0;842 int32_t iCurr = 0;
843 while (iCurr < iSize) {843 while (iCurr < iSize) {
844 * (pData + iCurr) = (* (pData + iCurr) + (rand() % 20) + 256) & 0x00ff;844 * (pData + iCurr) = (* (pData + iCurr) + (rand() % 20) + 256) & 0x00ff;
845 iCurr++;845 iCurr++;
846 }846 }
847 }847 }
848 848
849 void EncodeOneFrame (bool bMock) {849 void EncodeOneFrame (bool bMock) {
850 int iFrameSize = iWidth_ * iHeight_ * 3 / 2;850 int iFrameSize = iWidth_ * iHeight_ * 3 / 2;
851 int iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_);851 int iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_);
852 if (feof (fYuv_) || iSize != iFrameSize) {852 if (feof (fYuv_) || iSize != iFrameSize) {
853 rewind (fYuv_);853 rewind (fYuv_);
854 iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_);854 iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_);
855 ASSERT_TRUE (iSize == iFrameSize);855 ASSERT_TRUE (iSize == iFrameSize);
856 }856 }
857 if (bMock) {857 if (bMock) {
858 MockInputData (buf_.data(), iWidth_ * iHeight_);858 MockInputData (buf_.data(), iWidth_ * iHeight_);
859 }859 }
860 int rv = encoder_->EncodeFrame (&EncPic, &info);860 int rv = encoder_->EncodeFrame (&EncPic, &info);
861 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);861 ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);
862 }862 }
863 863
864 void prepareParam (int iLayerNum, int iSliceNum, int width, int height, float framerate, SEncParamExt* pParam) {864 void prepareParam (int iLayerNum, int iSliceNum, int width, int height, float framerate, SEncParamExt* pParam) {
865 memset (pParam, 0, sizeof (SEncParamExt));865 memset (pParam, 0, sizeof (SEncParamExt));
866 EncodeDecodeTestBase::prepareParam (iLayerNum, iSliceNum, width, height, framerate, pParam);866 EncodeDecodeTestBase::prepareParam (iLayerNum, iSliceNum, width, height, framerate, pParam);
867 }867 }
868 868
869 protected:869 protected:
870 SParserBsInfo BsInfo_;870 SParserBsInfo BsInfo_;
871 FILE* fYuv_;871 FILE* fYuv_;
872 int iWidth_;872 int iWidth_;
873 int iHeight_;873 int iHeight_;
874 SHA1Context ctx_;874 SHA1Context ctx_;
875};875};
876 876
877//#define DEBUG_FILE_SAVE_PARSEONLY_GENERAL877//#define DEBUG_FILE_SAVE_PARSEONLY_GENERAL
878TEST_F (DecodeParseAPI, ParseOnly_General) {878TEST_F (DecodeParseAPI, ParseOnly_General) {
879 EncodeDecodeFileParamBase p;879 EncodeDecodeFileParamBase p;
880 p.width = iWidth_;880 p.width = iWidth_;
881 p.height = iHeight_;881 p.height = iHeight_;
882 p.frameRate = kiFrameRate;882 p.frameRate = kiFrameRate;
883 p.numframes = kiFrameNum;883 p.numframes = kiFrameNum;
884 prepareParam (kiTotalLayer, kiSliceNum, p.width, p.height, p.frameRate, &param_);884 prepareParam (kiTotalLayer, kiSliceNum, p.width, p.height, p.frameRate, &param_);
885 param_.iSpatialLayerNum = kiTotalLayer;885 param_.iSpatialLayerNum = kiTotalLayer;
886 encoder_->Uninitialize();886 encoder_->Uninitialize();
887 int rv = encoder_->InitializeExt (&param_);887 int rv = encoder_->InitializeExt (&param_);
888 ASSERT_TRUE (rv == 0);888 ASSERT_TRUE (rv == 0);
889 int32_t iTraceLevel = WELS_LOG_QUIET;889 int32_t iTraceLevel = WELS_LOG_QUIET;
890 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);890 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
891 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);891 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
892 uint32_t uiTargetLayerId = rand() % kiTotalLayer; //run only once892 uint32_t uiTargetLayerId = rand() % kiTotalLayer; //run only once
893#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL893#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL
894 FILE* fDec = fopen ("output.264", "wb");894 FILE* fDec = fopen ("output.264", "wb");
895 FILE* fEnc = fopen ("enc.264", "wb");895 FILE* fEnc = fopen ("enc.264", "wb");
896 FILE* fExtract = fopen ("extract.264", "wb");896 FILE* fExtract = fopen ("extract.264", "wb");
897#endif897#endif
898 if (uiTargetLayerId < kiTotalLayer) { //should always be true898 if (uiTargetLayerId < kiTotalLayer) { //should always be true
899 //Start for enc899 //Start for enc
900 int iLen = 0;900 int iLen = 0;
901 ASSERT_TRUE (prepareEncDecParam (p));901 ASSERT_TRUE (prepareEncDecParam (p));
902 int iFrame = 0;902 int iFrame = 0;
903 903
904 while (iFrame < p.numframes) {904 while (iFrame < p.numframes) {
905 //encode905 //encode
906 EncodeOneFrame (0);906 EncodeOneFrame (0);
907 //extract target layer data907 //extract target layer data
908 encToDecData (info, iLen);908 encToDecData (info, iLen);
909#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL909#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL
910 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fEnc);910 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fEnc);
911#endif911#endif
912 ExtractDidNal (&info, iLen, &m_SLostSim, uiTargetLayerId);912 ExtractDidNal (&info, iLen, &m_SLostSim, uiTargetLayerId);
913#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL913#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL
914 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fExtract);914 fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fExtract);
915#endif915#endif
916 //parseonly916 //parseonly
917 //BsInfo_.pDstBuff = new unsigned char [1000000];917 //BsInfo_.pDstBuff = new unsigned char [1000000];
918 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf, iLen, &BsInfo_);918 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf, iLen, &BsInfo_);
919 EXPECT_TRUE (rv == 0);919 EXPECT_TRUE (rv == 0);
920 EXPECT_TRUE (BsInfo_.iNalNum == 0);920 EXPECT_TRUE (BsInfo_.iNalNum == 0);
921 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);921 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);
922 EXPECT_TRUE (rv == 0);922 EXPECT_TRUE (rv == 0);
923 EXPECT_TRUE (BsInfo_.iNalNum != 0);923 EXPECT_TRUE (BsInfo_.iNalNum != 0);
924 //get final output bs924 //get final output bs
925 iLen = 0;925 iLen = 0;
926 int i = 0;926 int i = 0;
927 while (i < BsInfo_.iNalNum) {927 while (i < BsInfo_.iNalNum) {
928 iLen += BsInfo_.pNalLenInByte[i];928 iLen += BsInfo_.pNalLenInByte[i];
929 i++;929 i++;
930 }930 }
931#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL931#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL
932 fwrite (BsInfo_.pDstBuff, iLen, 1, fDec);932 fwrite (BsInfo_.pDstBuff, iLen, 1, fDec);
933#endif933#endif
934 SHA1Input (&ctx_, BsInfo_.pDstBuff, iLen);934 SHA1Input (&ctx_, BsInfo_.pDstBuff, iLen);
935 iFrame++;935 iFrame++;
936 }936 }
937 //calculate final SHA1 value937 //calculate final SHA1 value
938 unsigned char digest[SHA_DIGEST_LENGTH];938 unsigned char digest[SHA_DIGEST_LENGTH];
939 SHA1Result (&ctx_, digest);939 SHA1Result (&ctx_, digest);
940 if (!HasFatalFailure()) {940 if (!HasFatalFailure()) {
941 CompareHashAnyOf (digest, pHashStr[uiTargetLayerId], sizeof * pHashStr / sizeof** pHashStr);941 CompareHashAnyOf (digest, pHashStr[uiTargetLayerId], sizeof * pHashStr / sizeof** pHashStr);
942 }942 }
943 } //while943 } //while
944#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL944#ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL
945 fclose (fEnc);945 fclose (fEnc);
946 fclose (fExtract);946 fclose (fExtract);
947 fclose (fDec);947 fclose (fDec);
948#endif948#endif
949}949}
950 950
951//This case is for one layer only, for incomplete frame input951//This case is for one layer only, for incomplete frame input
952//First slice is loss for random one picture with 2 slices per pic952//First slice is loss for random one picture with 2 slices per pic
953TEST_F (DecodeParseAPI, ParseOnly_SpecSliceLoss) {953TEST_F (DecodeParseAPI, ParseOnly_SpecSliceLoss) {
954 int32_t iLayerNum = 1;954 int32_t iLayerNum = 1;
955 int32_t iSliceNum = 2;955 int32_t iSliceNum = 2;
956 EncodeDecodeFileParamBase p;956 EncodeDecodeFileParamBase p;
957 p.width = iWidth_;957 p.width = iWidth_;
958 p.height = iHeight_;958 p.height = iHeight_;
959 p.frameRate = kiFrameRate;959 p.frameRate = kiFrameRate;
960 p.numframes = 5;960 p.numframes = 5;
961 prepareParam (iLayerNum, iSliceNum, p.width, p.height, p.frameRate, &param_);961 prepareParam (iLayerNum, iSliceNum, p.width, p.height, p.frameRate, &param_);
962 param_.iSpatialLayerNum = iLayerNum;962 param_.iSpatialLayerNum = iLayerNum;
963 encoder_->Uninitialize();963 encoder_->Uninitialize();
964 int rv = encoder_->InitializeExt (&param_);964 int rv = encoder_->InitializeExt (&param_);
965 ASSERT_TRUE (rv == 0);965 ASSERT_TRUE (rv == 0);
966 int32_t iTraceLevel = WELS_LOG_QUIET;966 int32_t iTraceLevel = WELS_LOG_QUIET;
967 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);967 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
968 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);968 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
969 969
970 int32_t iMissedPicNum = rand() % (p.numframes - 1) + 1; //IDR no loss970 int32_t iMissedPicNum = rand() % (p.numframes - 1) + 1; //IDR no loss
971 //Start for enc971 //Start for enc
972 int iLen = 0;972 int iLen = 0;
973 uint32_t uiGet;973 uint32_t uiGet;
974 ASSERT_TRUE (prepareEncDecParam (p));974 ASSERT_TRUE (prepareEncDecParam (p));
975 int iFrame = 0;975 int iFrame = 0;
976 976
977 while (iFrame < p.numframes) {977 while (iFrame < p.numframes) {
978 //encode978 //encode
979 EncodeOneFrame (0);979 EncodeOneFrame (0);
980 //parseonly980 //parseonly
981 if (iFrame == iMissedPicNum) { //make current frame partly missing981 if (iFrame == iMissedPicNum) { //make current frame partly missing
982 //Frame: P, first slice loss982 //Frame: P, first slice loss
983 int32_t iTotalSliceSize = 0;983 int32_t iTotalSliceSize = 0;
984 encToDecSliceData (0, 0, info, iTotalSliceSize); //slice 1 lost984 encToDecSliceData (0, 0, info, iTotalSliceSize); //slice 1 lost
985 encToDecSliceData (0, 1, info, iLen); //slice 2985 encToDecSliceData (0, 1, info, iLen); //slice 2
986 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);986 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
987 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);987 EXPECT_EQ (uiGet, (uint32_t) ERROR_CON_DISABLE);
988 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, iLen, &BsInfo_);988 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf + iTotalSliceSize, iLen, &BsInfo_);
989 EXPECT_TRUE (rv == 0);989 EXPECT_TRUE (rv == 0);
990 EXPECT_TRUE (BsInfo_.iNalNum == 0);990 EXPECT_TRUE (BsInfo_.iNalNum == 0);
991 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);991 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);
992 EXPECT_TRUE (rv != 0);992 EXPECT_TRUE (rv != 0);
993 } else { //normal frame, complete993 } else { //normal frame, complete
994 encToDecData (info, iLen);994 encToDecData (info, iLen);
995 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf, iLen, &BsInfo_);995 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf, iLen, &BsInfo_);
996 EXPECT_TRUE (rv == 0); //parse correct996 EXPECT_TRUE (rv == 0); //parse correct
997 EXPECT_TRUE (BsInfo_.iNalNum == 0);997 EXPECT_TRUE (BsInfo_.iNalNum == 0);
998 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);998 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);
999 if (iFrame < iMissedPicNum) { //correct frames, all OK with output999 if (iFrame < iMissedPicNum) { //correct frames, all OK with output
1000 EXPECT_TRUE (rv == 0);1000 EXPECT_TRUE (rv == 0);
1001 EXPECT_TRUE (BsInfo_.iNalNum != 0);1001 EXPECT_TRUE (BsInfo_.iNalNum != 0);
1002 } else { //(iFrame > iMissedPicNum), should output nothing as error1002 } else { //(iFrame > iMissedPicNum), should output nothing as error
1003 EXPECT_TRUE (rv != 0);1003 EXPECT_TRUE (rv != 0);
1004 EXPECT_TRUE (BsInfo_.iNalNum == 0);1004 EXPECT_TRUE (BsInfo_.iNalNum == 0);
1005 }1005 }
1006 }1006 }
1007 iFrame++;1007 iFrame++;
1008 } //while1008 } //while
1009}1009}
1010 1010
1011TEST_F (DecodeParseAPI, ParseOnly_SpecStatistics) {1011TEST_F (DecodeParseAPI, ParseOnly_SpecStatistics) {
1012 //set params1012 //set params
1013 int32_t iLayerNum = 1;1013 int32_t iLayerNum = 1;
1014 int32_t iSliceNum = 1;1014 int32_t iSliceNum = 1;
1015 EncodeDecodeFileParamBase p;1015 EncodeDecodeFileParamBase p;
1016 const int iLoopNum = 10;1016 const int iLoopNum = 10;
1017 p.frameRate = kiFrameRate;1017 p.frameRate = kiFrameRate;
1018 p.numframes = 2; //encode 2 frames in each test1018 p.numframes = 2; //encode 2 frames in each test
1019 p.width = iWidth_ = 16;1019 p.width = iWidth_ = 16;
1020 p.height = iHeight_ = 16; //default start width/height = 16, will be modified each time1020 p.height = iHeight_ = 16; //default start width/height = 16, will be modified each time
1021 int iTotalFrmCnt = 0;1021 int iTotalFrmCnt = 0;
1022 for (int i = 0; i < iLoopNum; ++i) {1022 for (int i = 0; i < iLoopNum; ++i) {
1023 prepareParam (iLayerNum, iSliceNum, p.width, p.height, p.frameRate, &param_);1023 prepareParam (iLayerNum, iSliceNum, p.width, p.height, p.frameRate, &param_);
1024 param_.iSpatialLayerNum = iLayerNum;1024 param_.iSpatialLayerNum = iLayerNum;
1025 param_.sSpatialLayers[0].iDLayerQp = 40; //to revent size too limited to encoding fail1025 param_.sSpatialLayers[0].iDLayerQp = 40; //to revent size too limited to encoding fail
1026 encoder_->Uninitialize();1026 encoder_->Uninitialize();
1027 int rv = encoder_->InitializeExt (&param_);1027 int rv = encoder_->InitializeExt (&param_);
1028 ASSERT_TRUE (rv == 0);1028 ASSERT_TRUE (rv == 0);
1029 int32_t iTraceLevel = WELS_LOG_QUIET;1029 int32_t iTraceLevel = WELS_LOG_QUIET;
1030 rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);1030 rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1031 ASSERT_TRUE (rv == 0);1031 ASSERT_TRUE (rv == 0);
1032 rv = decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);1032 rv = decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1033 ASSERT_TRUE (rv == 0);1033 ASSERT_TRUE (rv == 0);
1034 //Start for enc1034 //Start for enc
1035 int iLen = 0;1035 int iLen = 0;
1036 ASSERT_TRUE (prepareEncDecParam (p));1036 ASSERT_TRUE (prepareEncDecParam (p));
1037 int iFrame = 0;1037 int iFrame = 0;
1038 while (iFrame < p.numframes) {1038 while (iFrame < p.numframes) {
1039 EncodeOneFrame (0);1039 EncodeOneFrame (0);
1040 encToDecData (info, iLen);1040 encToDecData (info, iLen);
1041 iFrame++;1041 iFrame++;
1042 iTotalFrmCnt++;1042 iTotalFrmCnt++;
1043 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf, iLen, &BsInfo_);1043 rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf, iLen, &BsInfo_);
1044 ASSERT_TRUE (rv == 0);1044 ASSERT_TRUE (rv == 0);
1045 ASSERT_TRUE (BsInfo_.iNalNum == 0);1045 ASSERT_TRUE (BsInfo_.iNalNum == 0);
1046 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);1046 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);
1047 ASSERT_TRUE (rv == 0);1047 ASSERT_TRUE (rv == 0);
1048 ASSERT_TRUE (BsInfo_.iNalNum != 0);1048 ASSERT_TRUE (BsInfo_.iNalNum != 0);
1049 SDecoderStatistics sDecStat;1049 SDecoderStatistics sDecStat;
1050 rv = decoder_->GetOption (DECODER_OPTION_GET_STATISTICS, &sDecStat);1050 rv = decoder_->GetOption (DECODER_OPTION_GET_STATISTICS, &sDecStat);
1051 ASSERT_TRUE (rv == 0);1051 ASSERT_TRUE (rv == 0);
1052 uint32_t uiProfile, uiLevel;1052 uint32_t uiProfile, uiLevel;
1053 rv = decoder_->GetOption (DECODER_OPTION_PROFILE, &uiProfile);1053 rv = decoder_->GetOption (DECODER_OPTION_PROFILE, &uiProfile);
1054 ASSERT_TRUE (rv == 0);1054 ASSERT_TRUE (rv == 0);
1055 rv = decoder_->GetOption (DECODER_OPTION_LEVEL, &uiLevel);1055 rv = decoder_->GetOption (DECODER_OPTION_LEVEL, &uiLevel);
1056 ASSERT_TRUE (rv == 0);1056 ASSERT_TRUE (rv == 0);
1057 1057
1058 ASSERT_EQ (sDecStat.uiWidth, (unsigned int) p.width);1058 ASSERT_EQ (sDecStat.uiWidth, (unsigned int) p.width);
1059 ASSERT_EQ (sDecStat.uiHeight, (unsigned int) p.height);1059 ASSERT_EQ (sDecStat.uiHeight, (unsigned int) p.height);
1060 ASSERT_EQ (sDecStat.uiResolutionChangeTimes, (unsigned int) (i + 1));1060 ASSERT_EQ (sDecStat.uiResolutionChangeTimes, (unsigned int) (i + 1));
1061 EXPECT_EQ (sDecStat.iCurrentActiveSpsId, 0);1061 EXPECT_EQ (sDecStat.iCurrentActiveSpsId, 0);
1062 EXPECT_EQ (sDecStat.iCurrentActivePpsId, 0);1062 EXPECT_EQ (sDecStat.iCurrentActivePpsId, 0);
1063 ASSERT_EQ (sDecStat.uiDecodedFrameCount, (unsigned int) iTotalFrmCnt);1063 ASSERT_EQ (sDecStat.uiDecodedFrameCount, (unsigned int) iTotalFrmCnt);
1064 ASSERT_EQ (sDecStat.uiProfile, uiProfile);1064 ASSERT_EQ (sDecStat.uiProfile, uiProfile);
1065 ASSERT_EQ (sDecStat.uiLevel, uiLevel);1065 ASSERT_EQ (sDecStat.uiLevel, uiLevel);
1066 EXPECT_TRUE (sDecStat.fActualAverageFrameSpeedInMs != 0.);1066 EXPECT_TRUE (sDecStat.fActualAverageFrameSpeedInMs != 0.);
1067 EXPECT_TRUE (sDecStat.fAverageFrameSpeedInMs != 0.);1067 EXPECT_TRUE (sDecStat.fAverageFrameSpeedInMs != 0.);
1068 EXPECT_TRUE (sDecStat.iAvgLumaQp != 0);1068 EXPECT_TRUE (sDecStat.iAvgLumaQp != 0);
1069 EXPECT_EQ (sDecStat.uiIDRCorrectNum, (unsigned int) (i + 1));1069 EXPECT_EQ (sDecStat.uiIDRCorrectNum, (unsigned int) (i + 1));
1070 }1070 }
1071 //set next width & height1071 //set next width & height
1072 p.width += 16;1072 p.width += 16;
1073 p.height += 16;1073 p.height += 16;
1074 if ((unsigned int) p.width > kiWidth) //exceeds max frame size1074 if ((unsigned int) p.width > kiWidth) //exceeds max frame size
1075 p.width = 16;1075 p.width = 16;
1076 if ((unsigned int) p.height > kiHeight)1076 if ((unsigned int) p.height > kiHeight)
1077 p.height = 16;1077 p.height = 16;
1078 iWidth_ = p.width;1078 iWidth_ = p.width;
1079 iHeight_ = p.height;1079 iHeight_ = p.height;
1080 }1080 }
1081}1081}
1082 1082
1083 1083
1084//Test parseonly crash cases1084//Test parseonly crash cases
1085class DecodeParseCrashAPI : public DecodeParseAPI {1085class DecodeParseCrashAPI : public DecodeParseAPI {
1086 public:1086 public:
1087 DecodeParseCrashAPI() {1087 DecodeParseCrashAPI() {
1088 }1088 }
1089 void SetUp() {1089 void SetUp() {
1090 DecodeParseAPI::SetUp();1090 DecodeParseAPI::SetUp();
1091 iWidth_ = 1280;1091 iWidth_ = 1280;
1092 iHeight_ = 720;1092 iHeight_ = 720;
1093 1093
1094 ucBuf_ = NULL;1094 ucBuf_ = NULL;
1095 ucBuf_ = new unsigned char[1000000];1095 ucBuf_ = new unsigned char[1000000];
1096 ASSERT_TRUE (ucBuf_ != NULL);1096 ASSERT_TRUE (ucBuf_ != NULL);
1097 1097
1098 }1098 }
1099 void TearDown() {1099 void TearDown() {
1100 DecodeParseAPI::TearDown();1100 DecodeParseAPI::TearDown();
1101 if (NULL != ucBuf_) {1101 if (NULL != ucBuf_) {
1102 delete[] ucBuf_;1102 delete[] ucBuf_;
1103 ucBuf_ = NULL;1103 ucBuf_ = NULL;
1104 }1104 }
1105 ASSERT_TRUE (ucBuf_ == NULL);1105 ASSERT_TRUE (ucBuf_ == NULL);
1106 }1106 }
1107 1107
1108 protected:1108 protected:
1109 unsigned char* ucBuf_;1109 unsigned char* ucBuf_;
1110};1110};
1111 1111
1112//#define DEBUG_FILE_SAVE_PARSE_CRA11112//#define DEBUG_FILE_SAVE_PARSE_CRA1
1113TEST_F (DecodeParseCrashAPI, ParseOnlyCrash_General) {1113TEST_F (DecodeParseCrashAPI, ParseOnlyCrash_General) {
1114 if (fYuv_)1114 if (fYuv_)
1115 fclose (fYuv_);1115 fclose (fYuv_);
1116 const char* sFileName = "res/Cisco_Absolute_Power_1280x720_30fps.yuv";1116 const char* sFileName = "res/Cisco_Absolute_Power_1280x720_30fps.yuv";
1117#if defined(ANDROID_NDK)1117#if defined(ANDROID_NDK)
1118 std::string filename = std::string ("/sdcard/") + sFileName;1118 std::string filename = std::string ("/sdcard/") + sFileName;
1119 ASSERT_TRUE ((fYuv_ = fopen (filename.c_str(), "rb")) != NULL);1119 ASSERT_TRUE ((fYuv_ = fopen (filename.c_str(), "rb")) != NULL);
1120#else1120#else
1121 ASSERT_TRUE ((fYuv_ = fopen (sFileName, "rb")) != NULL);1121 ASSERT_TRUE ((fYuv_ = fopen (sFileName, "rb")) != NULL);
1122#endif1122#endif
1123 uint32_t uiGet;1123 uint32_t uiGet;
1124 encoder_->Uninitialize();1124 encoder_->Uninitialize();
1125 //do tests until crash1125 //do tests until crash
1126 unsigned int uiLoopRound = 0;1126 unsigned int uiLoopRound = 0;
1127 unsigned char* pucBuf = ucBuf_;1127 unsigned char* pucBuf = ucBuf_;
1128 int iDecAuSize;1128 int iDecAuSize;
1129#ifdef DEBUG_FILE_SAVE_PARSE_CRA11129#ifdef DEBUG_FILE_SAVE_PARSE_CRA1
1130 //open file to save tested BS1130 //open file to save tested BS
1131 FILE* fDataFile = fopen ("test_parseonly_crash.264", "wb");1131 FILE* fDataFile = fopen ("test_parseonly_crash.264", "wb");
1132 FILE* fLenFile = fopen ("test_parseonly_crash_len.log", "w");1132 FILE* fLenFile = fopen ("test_parseonly_crash_len.log", "w");
1133 int iFileSize = 0;1133 int iFileSize = 0;
1134#endif1134#endif
1135 1135
1136 do {1136 do {
1137#ifdef DEBUG_FILE_SAVE_PARSE_CRA11137#ifdef DEBUG_FILE_SAVE_PARSE_CRA1
1138 int iTotalFrameNum = (rand() % 1200) + 1;1138 int iTotalFrameNum = (rand() % 1200) + 1;
1139#else1139#else
1140 int iTotalFrameNum = (rand() % 100) + 1;1140 int iTotalFrameNum = (rand() % 100) + 1;
1141#endif1141#endif
1142 EncodeDecodeParamBase p = kParamArray[8]; //720p by default1142 EncodeDecodeParamBase p = kParamArray[8]; //720p by default
1143 1143
1144 //Initialize Encoder1144 //Initialize Encoder
1145 prepareParam (1, 4, p.width, p.height, p.frameRate, &param_);1145 prepareParam (1, 4, p.width, p.height, p.frameRate, &param_);
1146 param_.iRCMode = RC_TIMESTAMP_MODE;1146 param_.iRCMode = RC_TIMESTAMP_MODE;
1147 param_.iTargetBitrate = p.iTarBitrate;1147 param_.iTargetBitrate = p.iTarBitrate;
1148 param_.uiIntraPeriod = 0;1148 param_.uiIntraPeriod = 0;
1149 param_.eSpsPpsIdStrategy = CONSTANT_ID;1149 param_.eSpsPpsIdStrategy = CONSTANT_ID;
1150 param_.bEnableBackgroundDetection = true;1150 param_.bEnableBackgroundDetection = true;
1151 param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false;1151 param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false;
1152 param_.bPrefixNalAddingCtrl = 0;// (rand() % 2) ? true : false;1152 param_.bPrefixNalAddingCtrl = 0;// (rand() % 2) ? true : false;
1153 param_.iEntropyCodingModeFlag = 0;1153 param_.iEntropyCodingModeFlag = 0;
1154 param_.bEnableFrameSkip = true;1154 param_.bEnableFrameSkip = true;
1155 param_.iMultipleThreadIdc = 0;1155 param_.iMultipleThreadIdc = 0;
1156 param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;1156 param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;
1157 param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;1157 param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;
1158 param_.sSpatialLayers[0].sSliceArgument.uiSliceMode =1158 param_.sSpatialLayers[0].sSliceArgument.uiSliceMode =
1159 SM_FIXEDSLCNUM_SLICE; // (rand() % 2) ? SM_SIZELIMITED_SLICE : SM_SINGLE_SLICE;1159 SM_FIXEDSLCNUM_SLICE; // (rand() % 2) ? SM_SIZELIMITED_SLICE : SM_SINGLE_SLICE;
1160 if (param_.sSpatialLayers[0].sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE) {1160 if (param_.sSpatialLayers[0].sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE) {
1161 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 1400;1161 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 1400;
1162 param_.uiMaxNalSize = 1400;1162 param_.uiMaxNalSize = 1400;
1163 } else {1163 } else {
1164 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 0;1164 param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 0;
1165 param_.uiMaxNalSize = 0;1165 param_.uiMaxNalSize = 0;
1166 }1166 }
1167 1167
1168 int rv = encoder_->InitializeExt (&param_);1168 int rv = encoder_->InitializeExt (&param_);
1169 ASSERT_TRUE (rv == cmResultSuccess);1169 ASSERT_TRUE (rv == cmResultSuccess);
1170 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);1170 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1171 EXPECT_EQ (uiGet, (uint32_t)ERROR_CON_DISABLE); //default value should be ERROR_CON_SLICE_COPY1171 EXPECT_EQ (uiGet, (uint32_t)ERROR_CON_DISABLE); //default value should be ERROR_CON_SLICE_COPY
1172 int32_t iTraceLevel = WELS_LOG_QUIET;1172 int32_t iTraceLevel = WELS_LOG_QUIET;
1173 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);1173 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1174 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);1174 decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
1175 1175
1176 //Start for enc/dec1176 //Start for enc/dec
1177 int iIdx = 0;1177 int iIdx = 0;
1178 unsigned char* pData[3] = { NULL };1178 unsigned char* pData[3] = { NULL };
1179 1179
1180 EncodeDecodeFileParamBase pInput; //to conform with old functions1180 EncodeDecodeFileParamBase pInput; //to conform with old functions
1181 pInput.width = p.width;1181 pInput.width = p.width;
1182 pInput.height = p.height;1182 pInput.height = p.height;
1183 pInput.frameRate = p.frameRate;1183 pInput.frameRate = p.frameRate;
1184 prepareEncDecParam (pInput);1184 prepareEncDecParam (pInput);
1185 while (iIdx++ < iTotalFrameNum) { // loop in frame1185 while (iIdx++ < iTotalFrameNum) { // loop in frame
1186 EncodeOneFrame (1);1186 EncodeOneFrame (1);
1187#ifdef DEBUG_FILE_SAVE_PARSE_CRA11187#ifdef DEBUG_FILE_SAVE_PARSE_CRA1
1188 //reset file if file size large1188 //reset file if file size large
1189 if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {1189 if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {
1190 fclose (fDataFile);1190 fclose (fDataFile);
1191 fclose (fLenFile);1191 fclose (fLenFile);
1192 fDataFile = fopen ("test_parseonly_crash.264", "wb");1192 fDataFile = fopen ("test_parseonly_crash.264", "wb");
1193 fLenFile = fopen ("test_parseonly_crash_len.log", "w");1193 fLenFile = fopen ("test_parseonly_crash_len.log", "w");
1194 iFileSize = 0;1194 iFileSize = 0;
1195 decoder_->Uninitialize();1195 decoder_->Uninitialize();
1196 1196
1197 SDecodingParam decParam;1197 SDecodingParam decParam;
1198 memset (&decParam, 0, sizeof (SDecodingParam));1198 memset (&decParam, 0, sizeof (SDecodingParam));
1199 decParam.uiTargetDqLayer = UCHAR_MAX;1199 decParam.uiTargetDqLayer = UCHAR_MAX;
1200 decParam.eEcActiveIdc = ERROR_CON_DISABLE;1200 decParam.eEcActiveIdc = ERROR_CON_DISABLE;
1201 decParam.bParseOnly = true;1201 decParam.bParseOnly = true;
1202 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;1202 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
1203 1203
1204 rv = decoder_->Initialize (&decParam);1204 rv = decoder_->Initialize (&decParam);
1205 ASSERT_EQ (0, rv);1205 ASSERT_EQ (0, rv);
1206 }1206 }
1207#endif1207#endif
1208 if (info.eFrameType == videoFrameTypeSkip)1208 if (info.eFrameType == videoFrameTypeSkip)
1209 continue;1209 continue;
1210 //deal with packets1210 //deal with packets
1211 unsigned char* pBsBuf;1211 unsigned char* pBsBuf;
1212 iDecAuSize = 0;1212 iDecAuSize = 0;
1213 pucBuf = ucBuf_; //init buf start pos for decoder usage1213 pucBuf = ucBuf_; //init buf start pos for decoder usage
1214 for (int iLayerNum = 0; iLayerNum < info.iLayerNum; iLayerNum++) {1214 for (int iLayerNum = 0; iLayerNum < info.iLayerNum; iLayerNum++) {
1215 SLayerBSInfo* pLayerBsInfo = &info.sLayerInfo[iLayerNum];1215 SLayerBSInfo* pLayerBsInfo = &info.sLayerInfo[iLayerNum];
1216 pBsBuf = info.sLayerInfo[iLayerNum].pBsBuf;1216 pBsBuf = info.sLayerInfo[iLayerNum].pBsBuf;
1217 int iTotalNalCnt = pLayerBsInfo->iNalCount;1217 int iTotalNalCnt = pLayerBsInfo->iNalCount;
1218 for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL1218 for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL
1219 int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];1219 int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];
1220 //packet loss1220 //packet loss
1221 int iLossRateRange = (uiLoopRound % 20) + 1; //1-1001221 int iLossRateRange = (uiLoopRound % 20) + 1; //1-100
1222 int iLossRate = (rand() % iLossRateRange);1222 int iLossRate = (rand() % iLossRateRange);
1223 bool bPacketLost = (rand() % 101) > (100 -1223 bool bPacketLost = (rand() % 101) > (100 -
1224 iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS1224 iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS
1225 if (!bPacketLost) { //no loss1225 if (!bPacketLost) { //no loss
1226 memcpy (pucBuf, pBsBuf, iPacketSize);1226 memcpy (pucBuf, pBsBuf, iPacketSize);
1227 pucBuf += iPacketSize;1227 pucBuf += iPacketSize;
1228 iDecAuSize += iPacketSize;1228 iDecAuSize += iPacketSize;
1229 }1229 }
1230 //update bs info1230 //update bs info
1231 pBsBuf += iPacketSize;1231 pBsBuf += iPacketSize;
1232 } //nal1232 } //nal
1233 } //layer1233 } //layer
1234 1234
1235#ifdef DEBUG_FILE_SAVE_PARSE_CRA11235#ifdef DEBUG_FILE_SAVE_PARSE_CRA1
1236 //save to file1236 //save to file
1237 if (iDecAuSize != 0) {1237 if (iDecAuSize != 0) {
1238 fwrite (ucBuf_, 1, iDecAuSize, fDataFile);1238 fwrite (ucBuf_, 1, iDecAuSize, fDataFile);
1239 fflush (fDataFile);1239 fflush (fDataFile);
1240 iFileSize += iDecAuSize;1240 iFileSize += iDecAuSize;
1241 }1241 }
1242 1242
1243 //save to len file1243 //save to len file
1244 unsigned long ulTmp[4];1244 unsigned long ulTmp[4];
1245 ulTmp[0] = ulTmp[1] = ulTmp[2] = iIdx;1245 ulTmp[0] = ulTmp[1] = ulTmp[2] = iIdx;
1246 ulTmp[3] = iDecAuSize;1246 ulTmp[3] = iDecAuSize;
1247 fwrite (ulTmp, sizeof (unsigned long), 4, fLenFile); // index, timeStamp, data size1247 fwrite (ulTmp, sizeof (unsigned long), 4, fLenFile); // index, timeStamp, data size
1248 fflush (fLenFile);1248 fflush (fLenFile);
1249#endif1249#endif
1250 1250
1251 //decode1251 //decode
1252 pData[0] = pData[1] = pData[2] = 0;1252 pData[0] = pData[1] = pData[2] = 0;
1253 memset (&BsInfo_, 0, sizeof (SParserBsInfo));1253 memset (&BsInfo_, 0, sizeof (SParserBsInfo));
1254 1254
1255 rv = decoder_->DecodeParser (ucBuf_, iDecAuSize, &BsInfo_);1255 rv = decoder_->DecodeParser (ucBuf_, iDecAuSize, &BsInfo_);
1256 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_); //reconstruction1256 rv = decoder_->DecodeParser (NULL, 0, &BsInfo_); //reconstruction
1257 //guarantee decoder EC status1257 //guarantee decoder EC status
1258 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);1258 decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet);
1259 EXPECT_EQ (uiGet, (uint32_t)ERROR_CON_DISABLE);1259 EXPECT_EQ (uiGet, (uint32_t)ERROR_CON_DISABLE);
1260 } //frame1260 } //frame
1261 uiLoopRound++;1261 uiLoopRound++;
1262 if (uiLoopRound >= (1 << 30))1262 if (uiLoopRound >= (1 << 30))
1263 uiLoopRound = 0;1263 uiLoopRound = 0;
1264#ifdef DEBUG_FILE_SAVE_PARSE_CRA11264#ifdef DEBUG_FILE_SAVE_PARSE_CRA1
1265 if (uiLoopRound % 10 == 0)1265 if (uiLoopRound % 10 == 0)
1266 printf ("run %d times.\n", uiLoopRound);1266 printf ("run %d times.\n", uiLoopRound);
1267 } while (1);1267 } while (1);
1268 fclose (fDataFile);1268 fclose (fDataFile);
1269 fclose (fLenFile);1269 fclose (fLenFile);
1270#else1270#else
1271 }1271 }
1272 while (0);1272 while (0);
1273#endif1273#endif
1274 1274
1275}1275}
1276 1276

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