1 #include <gtest/gtest.h>
2
3 #include "codec_def.h"
4 #include "codec_app_def.h"
5 #include "codec_api.h"
6 #include "error_code.h"
7 #include "wels_common_basis.h"
8 #include "memory_align.h"
9 #include "ls_defines.h"
10
11 using namespace WelsDec;
12 #define BUF_SIZE 100
13 //payload size exclude 6 bytes: 0001, nal type and final '\0'
14 #define PAYLOAD_SIZE (BUF_SIZE - 6)
15 class DecoderInterfaceTest : public ::testing::Test {
16 public:
SetUp()17 virtual void SetUp() {
18 int rv = WelsCreateDecoder (&m_pDec);
19 ASSERT_EQ (0, rv);
20 ASSERT_TRUE (m_pDec != NULL);
21 }
22
TearDown()23 virtual void TearDown() {
24 if (m_pDec) {
25 WelsDestroyDecoder (m_pDec);
26 }
27 }
28 //Init members
29 int32_t Init();
30 //Init valid members
31 int32_t ValidInit();
32 //Uninit members
33 void Uninit();
34 //Mock input data for test
35 void MockPacketType (const EWelsNalUnitType eNalUnitType, const int iPacketLength);
36 //Decoder real bitstream
37 void DecoderBs (const char* sFileName);
38 //Test Initialize/Uninitialize
39 void TestInitUninit();
40 //Test parse only API
41 void TestParseOnlyAPI();
42 //DECODER_OPTION_END_OF_STREAM
43 void TestEndOfStream();
44 //DECODER_OPTION_VCL_NAL
45 void TestVclNal();
46 //DECODER_OPTION_TEMPORAL_ID
47 void TestTemporalId();
48 //DECODER_OPTION_FRAME_NUM
49 void TestFrameNum();
50 //DECODER_OPTION_IDR_PIC_ID
51 void TestIdrPicId();
52 //DECODER_OPTION_LTR_MARKING_FLAG
53 void TestLtrMarkingFlag();
54 //DECODER_OPTION_LTR_MARKED_FRAME_NUM
55 void TestLtrMarkedFrameNum();
56 //DECODER_OPTION_ERROR_CON_IDC
57 void TestErrorConIdc();
58 //DECODER_OPTION_TRACE_LEVEL
59 void TestTraceLevel();
60 //DECODER_OPTION_TRACE_CALLBACK
61 void TestTraceCallback();
62 //DECODER_OPTION_TRACE_CALLBACK_CONTEXT
63 void TestTraceCallbackContext();
64 //DECODER_OPTION_GET_DECODER_STATICTIS
65 void TestGetDecStatistics();
66 //DECODER_OPTION_GET_SAR_INFO
67 void TestGetDecSarInfo();
68 //Additional test on correctness of vui in subset sps
69 void TestVuiInSubsetSps();
70 //Do whole tests here
71 void DecoderInterfaceAll();
72
73
74 public:
75 ISVCDecoder* m_pDec;
76 SDecodingParam m_sDecParam;
77 SBufferInfo m_sBufferInfo;
78 SParserBsInfo m_sParserBsInfo;
79 uint8_t* m_pData[3];
80 unsigned char m_szBuffer[BUF_SIZE]; //for mocking packet
81 int m_iBufLength; //record the valid data in m_szBuffer
82 };
83
84 //Init members
Init()85 int32_t DecoderInterfaceTest::Init() {
86 memset (&m_sBufferInfo, 0, sizeof (SBufferInfo));
87 memset (&m_sParserBsInfo, 0, sizeof (SParserBsInfo));
88 memset (&m_sDecParam, 0, sizeof (SDecodingParam));
89 m_sDecParam.pFileNameRestructed = NULL;
90 m_sDecParam.uiCpuLoad = rand() % 100;
91 m_sDecParam.uiTargetDqLayer = rand() % 100;
92 m_sDecParam.eEcActiveIdc = (ERROR_CON_IDC) (rand() & 7);
93 m_sDecParam.sVideoProperty.size = sizeof (SVideoProperty);
94 m_sDecParam.sVideoProperty.eVideoBsType = (VIDEO_BITSTREAM_TYPE) (rand() % 2);
95
96 m_pData[0] = m_pData[1] = m_pData[2] = NULL;
97 m_szBuffer[0] = m_szBuffer[1] = m_szBuffer[2] = 0;
98 m_szBuffer[3] = 1;
99 m_iBufLength = 4;
100 CM_RETURN eRet = (CM_RETURN) m_pDec->Initialize (&m_sDecParam);
101 EXPECT_EQ (eRet, cmResultSuccess);
102 return (int32_t)eRet;
103 }
104
ValidInit()105 int32_t DecoderInterfaceTest::ValidInit() {
106 memset (&m_sBufferInfo, 0, sizeof (SBufferInfo));
107 memset (&m_sDecParam, 0, sizeof (SDecodingParam));
108 m_sDecParam.pFileNameRestructed = NULL;
109 m_sDecParam.uiCpuLoad = 1;
110 m_sDecParam.uiTargetDqLayer = 1;
111 m_sDecParam.eEcActiveIdc = (ERROR_CON_IDC) (rand() & 7);
112 m_sDecParam.sVideoProperty.size = sizeof (SVideoProperty);
113 m_sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
114
115 m_pData[0] = m_pData[1] = m_pData[2] = NULL;
116 m_szBuffer[0] = m_szBuffer[1] = m_szBuffer[2] = 0;
117 m_szBuffer[3] = 1;
118 m_iBufLength = 4;
119 CM_RETURN eRet = (CM_RETURN) m_pDec->Initialize (&m_sDecParam);
120 EXPECT_EQ (eRet, cmResultSuccess);
121 return (int32_t)eRet;
122 }
123
Uninit()124 void DecoderInterfaceTest::Uninit() {
125 if (m_pDec) {
126 CM_RETURN eRet = (CM_RETURN) m_pDec->Uninitialize();
127 ASSERT_EQ (eRet, cmResultSuccess);
128 }
129 memset (&m_sDecParam, 0, sizeof (SDecodingParam));
130 memset (&m_sParserBsInfo, 0, sizeof (SParserBsInfo));
131 memset (&m_sBufferInfo, 0, sizeof (SBufferInfo));
132 m_pData[0] = m_pData[1] = m_pData[2] = NULL;
133 m_iBufLength = 0;
134 }
135
DecoderBs(const char * sFileName)136 void DecoderInterfaceTest::DecoderBs (const char* sFileName) {
137
138 uint8_t* pBuf = NULL;
139 int32_t iBufPos = 0;
140 int32_t iFileSize;
141 int32_t i = 0;
142 int32_t iSliceSize;
143 int32_t iSliceIndex = 0;
144 int32_t iEndOfStreamFlag = 0;
145 FILE* pH264File;
146 uint8_t uiStartCode[4] = {0, 0, 0, 1};
147
148 #if defined(ANDROID_NDK)
149 std::string filename = std::string ("/sdcard/") + sFileName;
150 ASSERT_TRUE ((pH264File = fopen (filename.c_str(), "rb")) != NULL);
151 #else
152 ASSERT_TRUE ((pH264File = fopen (sFileName, "rb")) != NULL);
153 #endif
154 fseek (pH264File, 0L, SEEK_END);
155 iFileSize = (int32_t) ftell (pH264File);
156 fseek (pH264File, 0L, SEEK_SET);
157 pBuf = new uint8_t[iFileSize + 4];
158 ASSERT_EQ (fread (pBuf, 1, iFileSize, pH264File), (unsigned int) iFileSize);
159 memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage
160 while (true) {
161 if (iBufPos >= iFileSize) {
162 iEndOfStreamFlag = true;
163 if (iEndOfStreamFlag)
164 m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, (void*)&iEndOfStreamFlag);
165 break;
166 }
167 for (i = 0; i < iFileSize; i++) {
168 if ((pBuf[iBufPos + i] == 0 && pBuf[iBufPos + i + 1] == 0 && pBuf[iBufPos + i + 2] == 0 && pBuf[iBufPos + i + 3] == 1
169 && i > 0)) {
170 break;
171 }
172 }
173 iSliceSize = i;
174 m_pDec->DecodeFrame2 (pBuf + iBufPos, iSliceSize, m_pData, &m_sBufferInfo);
175 m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
176 iBufPos += iSliceSize;
177 ++ iSliceIndex;
178 }
179
180 fclose (pH264File);
181 if (pBuf) {
182 delete[] pBuf;
183 pBuf = NULL;
184 }
185
186
187 }
188 //Mock input data for test
MockPacketType(const EWelsNalUnitType eNalUnitType,const int iPacketLength)189 void DecoderInterfaceTest::MockPacketType (const EWelsNalUnitType eNalUnitType, const int iPacketLength) {
190 switch (eNalUnitType) {
191 case NAL_UNIT_SEI:
192 m_szBuffer[m_iBufLength++] = 6;
193 break;
194 case NAL_UNIT_SPS:
195 m_szBuffer[m_iBufLength++] = 67;
196 break;
197 case NAL_UNIT_PPS:
198 m_szBuffer[m_iBufLength++] = 68;
199 break;
200 case NAL_UNIT_SUBSET_SPS:
201 m_szBuffer[m_iBufLength++] = 15;
202 break;
203 case NAL_UNIT_PREFIX:
204 m_szBuffer[m_iBufLength++] = 14;
205 break;
206 case NAL_UNIT_CODED_SLICE:
207 m_szBuffer[m_iBufLength++] = 61;
208 break;
209 case NAL_UNIT_CODED_SLICE_IDR:
210 m_szBuffer[m_iBufLength++] = 65;
211 break;
212 default:
213 m_szBuffer[m_iBufLength++] = 0; //NAL_UNIT_UNSPEC_0
214 break;
215 }
216 int iAddLength = iPacketLength - 5; //excluding 0001 and type
217 if (iAddLength > PAYLOAD_SIZE)
218 iAddLength = PAYLOAD_SIZE;
219 for (int i = 0; i < iAddLength; ++i) {
220 m_szBuffer[m_iBufLength++] = rand() % 256;
221 }
222 m_szBuffer[m_iBufLength++] = '\0';
223
224 }
225
226 //Test Initialize/Uninitialize
TestInitUninit()227 void DecoderInterfaceTest::TestInitUninit() {
228 int iOutput;
229 CM_RETURN eRet;
230 int32_t iRet = ERR_NONE;
231 //No initialize, no GetOption can be done
232 m_pDec->Uninitialize();
233 for (int i = 0; i <= (int) DECODER_OPTION_TRACE_CALLBACK_CONTEXT; ++i) {
234 eRet = (CM_RETURN) m_pDec->GetOption ((DECODER_OPTION) i, &iOutput);
235 EXPECT_EQ (eRet, cmInitExpected);
236 }
237 //Initialize first, can get input color format
238 iRet = Init();
239 ASSERT_EQ (iRet, ERR_NONE);
240
241 m_sDecParam.bParseOnly = false;
242 eRet = (CM_RETURN)m_pDec->Initialize (&m_sDecParam);
243 ASSERT_EQ (eRet, cmResultSuccess);
244
245 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOutput);
246 EXPECT_EQ (eRet, cmResultSuccess);
247 EXPECT_EQ (iOutput, 0);
248
249 //Uninitialize, no GetOption can be done
250 m_pDec->Uninitialize();
251 iOutput = 21;
252 for (int i = 0; i <= (int) DECODER_OPTION_TRACE_CALLBACK_CONTEXT; ++i) {
253 eRet = (CM_RETURN) m_pDec->GetOption ((DECODER_OPTION) i, &iOutput);
254 EXPECT_EQ (iOutput, 21);
255 EXPECT_EQ (eRet, cmInitExpected);
256 }
257 }
258
259 //Test parse only API
TestParseOnlyAPI()260 void DecoderInterfaceTest::TestParseOnlyAPI() {
261 int iOutput;
262 int iRet;
263
264 m_pData[0] = m_pData[1] = m_pData[2] = NULL;
265 m_szBuffer[0] = m_szBuffer[1] = m_szBuffer[2] = 0;
266 m_szBuffer[3] = 1;
267 m_iBufLength = 4;
268 MockPacketType (NAL_UNIT_SPS, 12);
269
270 m_pDec->Uninitialize();
271
272 //test 1: bParseOnly = true; eEcActiveIdc = 0,1
273 for (int iNum = 0; iNum < 2; ++iNum) { //loop for EC
274 memset (&m_sBufferInfo, 0, sizeof (SBufferInfo));
275 memset (&m_sParserBsInfo, 0, sizeof (SParserBsInfo));
276 memset (&m_sDecParam, 0, sizeof (SDecodingParam));
277 m_sDecParam.pFileNameRestructed = NULL;
278 m_sDecParam.uiCpuLoad = rand() % 100;
279 m_sDecParam.uiTargetDqLayer = -1;
280 m_sDecParam.bParseOnly = true;
281 m_sDecParam.eEcActiveIdc = (ERROR_CON_IDC) iNum;
282 m_sDecParam.sVideoProperty.size = sizeof (SVideoProperty);
283 m_sDecParam.sVideoProperty.eVideoBsType = (VIDEO_BITSTREAM_TYPE) (rand() % 2);
284
285 iRet = m_pDec->Initialize (&m_sDecParam);
286 ASSERT_EQ (iRet, (int32_t) cmResultSuccess);
287 iRet = m_pDec->GetOption (DECODER_OPTION_ERROR_CON_IDC, &iOutput);
288 EXPECT_EQ (iRet, (int32_t) cmResultSuccess);
289 EXPECT_EQ (iOutput, (int32_t) ERROR_CON_DISABLE); //should be 0
290 //call DecodeParser(), correct call
291 iRet = (int32_t) m_pDec->DecodeParser (m_szBuffer, m_iBufLength, &m_sParserBsInfo);
292 EXPECT_EQ (iRet, (int32_t) dsNoParamSets);
293 iRet = m_pDec->GetOption (DECODER_OPTION_ERROR_CON_IDC, &iOutput);
294 EXPECT_EQ (iRet, (int32_t) cmResultSuccess);
295 EXPECT_EQ (iOutput, (int32_t) ERROR_CON_DISABLE); //should be 0
296 //call DecodeFrame2(), incorrect call
297 iRet = (int32_t) m_pDec->DecodeFrame2 (m_szBuffer, m_iBufLength, m_pData, &m_sBufferInfo);
298 EXPECT_EQ (iRet, (int32_t) dsInvalidArgument);
299 iRet = m_pDec->GetOption (DECODER_OPTION_ERROR_CON_IDC, &iOutput);
300 EXPECT_EQ (iRet, (int32_t) cmResultSuccess);
301 EXPECT_EQ (iOutput, (int32_t) ERROR_CON_DISABLE); //should be 0
302 m_pDec->Uninitialize();
303 }
304
305 //test 2: bParseOnly = false; eEcActiveIdc = 0,1
306 for (int iNum = 0; iNum < 2; ++iNum) { //loop for EC
307 memset (&m_sBufferInfo, 0, sizeof (SBufferInfo));
308 memset (&m_sParserBsInfo, 0, sizeof (SParserBsInfo));
309 memset (&m_sDecParam, 0, sizeof (SDecodingParam));
310 m_sDecParam.pFileNameRestructed = NULL;
311 m_sDecParam.uiCpuLoad = rand() % 100;
312 m_sDecParam.uiTargetDqLayer = -1;
313 m_sDecParam.bParseOnly = false;
314 m_sDecParam.eEcActiveIdc = (ERROR_CON_IDC) iNum;
315 m_sDecParam.sVideoProperty.size = sizeof (SVideoProperty);
316 m_sDecParam.sVideoProperty.eVideoBsType = (VIDEO_BITSTREAM_TYPE) (rand() % 2);
317
318 iRet = m_pDec->Initialize (&m_sDecParam);
319 ASSERT_EQ (iRet, (int32_t) cmResultSuccess);
320 iRet = m_pDec->GetOption (DECODER_OPTION_ERROR_CON_IDC, &iOutput);
321 EXPECT_EQ (iRet, (int32_t) cmResultSuccess);
322 EXPECT_EQ (iOutput, iNum);
323 //call DecodeParser(), incorrect call
324 iRet = (int32_t) m_pDec->DecodeParser (m_szBuffer, m_iBufLength, &m_sParserBsInfo);
325 EXPECT_EQ (iRet, (int32_t) dsInvalidArgument); //error call
326 iRet = m_pDec->GetOption (DECODER_OPTION_ERROR_CON_IDC, &iOutput);
327 EXPECT_EQ (iRet, (int32_t) cmResultSuccess);
328 EXPECT_EQ (iOutput, iNum);
329 //call DecodeFrame2(), correct call
330 iRet = (int32_t) m_pDec->DecodeFrame2 (m_szBuffer, m_iBufLength, m_pData, &m_sBufferInfo);
331 EXPECT_EQ (iRet, (int32_t) dsNoParamSets);
332 iRet = m_pDec->GetOption (DECODER_OPTION_ERROR_CON_IDC, &iOutput);
333 EXPECT_EQ (iRet, (int32_t) cmResultSuccess);
334 EXPECT_EQ (iOutput, iNum);
335 m_pDec->Uninitialize();
336 }
337
338 }
339
340 //DECODER_OPTION_END_OF_STREAM
TestEndOfStream()341 void DecoderInterfaceTest::TestEndOfStream() {
342 int iTmp, iOut;
343 CM_RETURN eRet;
344 int32_t iRet = ERR_NONE;
345
346 iRet = ValidInit();
347 ASSERT_EQ (iRet, ERR_NONE);
348
349 //invalid input
350 eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, NULL);
351 EXPECT_EQ (eRet, cmInitParaError);
352
353 //valid random input
354 for (int i = 0; i < 10; ++i) {
355 iTmp = rand();
356 eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, &iTmp);
357 EXPECT_EQ (eRet, cmResultSuccess);
358 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
359 EXPECT_EQ (eRet, cmResultSuccess);
360 EXPECT_EQ (iOut, iTmp != 0 ? 1 : 0);
361 }
362
363 //set false as input
364 iTmp = false;
365 eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, &iTmp);
366 EXPECT_EQ (eRet, cmResultSuccess);
367 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
368 EXPECT_EQ (eRet, cmResultSuccess);
369
370 EXPECT_EQ (iOut, 0);
371
372 //set true as input
373 iTmp = true;
374 eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, &iTmp);
375 EXPECT_EQ (eRet, cmResultSuccess);
376 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
377 EXPECT_EQ (eRet, cmResultSuccess);
378
379 EXPECT_EQ (iOut, 1);
380
381 //Mock data packet in
382 //Test NULL data input for decoder, should be true for EOS
383 eRet = (CM_RETURN) m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
384 EXPECT_EQ (eRet, 0); //decode should return OK
385 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
386 EXPECT_EQ (iOut, 1); //decoder should have EOS == true
387
388 //Test valid data input for decoder, should be false for EOS
389 MockPacketType (NAL_UNIT_UNSPEC_0, 50);
390 eRet = (CM_RETURN) m_pDec->DecodeFrame2 (m_szBuffer, m_iBufLength, m_pData, &m_sBufferInfo);
391 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
392 EXPECT_EQ (iOut, 0); //decoder should have EOS == false
393 //Test NULL data input for decoder, should be true for EOS
394 eRet = (CM_RETURN) m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
395 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
396 EXPECT_EQ (iOut, 1); //decoder should have EOS == true
397
398 Uninit();
399 }
400
401
402 //DECODER_OPTION_VCL_NAL
403 //Here Test illegal bitstream input
404 //legal bitstream decoding test, please see api test
TestVclNal()405 void DecoderInterfaceTest::TestVclNal() {
406 int iTmp, iOut;
407 CM_RETURN eRet;
408 int32_t iRet = ERR_NONE;
409
410 iRet = ValidInit();
411 ASSERT_EQ (iRet, ERR_NONE);
412
413 //Test SetOption
414 //VclNal never supports SetOption
415 iTmp = rand();
416 eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_VCL_NAL, &iTmp);
417 EXPECT_EQ (eRet, cmInitParaError);
418
419 //Test GetOption
420 //invalid input
421 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_VCL_NAL, NULL);
422 EXPECT_EQ (eRet, cmInitParaError);
423
424 //valid input without actual decoding
425 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_VCL_NAL, &iOut);
426 EXPECT_EQ (eRet, cmResultSuccess);
427 EXPECT_EQ (iOut, FEEDBACK_NON_VCL_NAL);
428
429 //valid input with decoding error
430 MockPacketType (NAL_UNIT_CODED_SLICE_IDR, 50);
431 m_pDec->DecodeFrame2 (m_szBuffer, m_iBufLength, m_pData, &m_sBufferInfo);
432 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_VCL_NAL, &iOut);
433 EXPECT_EQ (eRet, cmResultSuccess);
434 EXPECT_EQ (iOut, FEEDBACK_UNKNOWN_NAL);
435 m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
436 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_VCL_NAL, &iOut);
437 EXPECT_EQ (eRet, cmResultSuccess);
438 EXPECT_EQ (iOut, FEEDBACK_UNKNOWN_NAL);
439
440 Uninit();
441 }
442
443 //DECODER_OPTION_TEMPORAL_ID
TestTemporalId()444 void DecoderInterfaceTest::TestTemporalId() {
445 //TODO
446 }
447
448 //DECODER_OPTION_FRAME_NUM
TestFrameNum()449 void DecoderInterfaceTest::TestFrameNum() {
450 //TODO
451 }
452
453 //DECODER_OPTION_IDR_PIC_ID
TestIdrPicId()454 void DecoderInterfaceTest::TestIdrPicId() {
455 //TODO
456 }
457
458 //DECODER_OPTION_LTR_MARKING_FLAG
TestLtrMarkingFlag()459 void DecoderInterfaceTest::TestLtrMarkingFlag() {
460 //TODO
461 }
462
463 //DECODER_OPTION_LTR_MARKED_FRAME_NUM
TestLtrMarkedFrameNum()464 void DecoderInterfaceTest::TestLtrMarkedFrameNum() {
465 //TODO
466 }
467
468 //DECODER_OPTION_ERROR_CON_IDC
TestErrorConIdc()469 void DecoderInterfaceTest::TestErrorConIdc() {
470 int iTmp, iOut;
471 CM_RETURN eRet;
472 int32_t iRet = ERR_NONE;
473
474 iRet = Init();
475 ASSERT_EQ (iRet, ERR_NONE);
476
477 //Test GetOption
478 //invalid input
479 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_ERROR_CON_IDC, NULL);
480 EXPECT_EQ (eRet, cmInitParaError);
481
482 //Test GetOption
483 //valid input
484 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_ERROR_CON_IDC, &iOut);
485 EXPECT_EQ (eRet, cmResultSuccess);
486
487 //Test SetOption
488 iTmp = rand() & 7;
489 eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_ERROR_CON_IDC, &iTmp);
490 EXPECT_EQ (eRet, cmResultSuccess);
491
492 //Test GetOption
493 eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_ERROR_CON_IDC, &iOut);
494 EXPECT_EQ (eRet, cmResultSuccess);
495 EXPECT_EQ (iTmp, iOut);
496
497 Uninit();
498
499 }
500
501 //DECODER_OPTION_TRACE_LEVEL
TestTraceLevel()502 void DecoderInterfaceTest::TestTraceLevel() {
503 //TODO
504 }
505
506 //DECODER_OPTION_TRACE_CALLBACK
TestTraceCallback()507 void DecoderInterfaceTest::TestTraceCallback() {
508 //TODO
509 }
510
511 //DECODER_OPTION_TRACE_CALLBACK_CONTEXT
TestTraceCallbackContext()512 void DecoderInterfaceTest::TestTraceCallbackContext() {
513 //TODO
514 }
515
516 //DECODER_OPTION_GET_STATISTICS
TestGetDecStatistics()517 void DecoderInterfaceTest::TestGetDecStatistics() {
518 CM_RETURN eRet;
519 int32_t iRet;
520 SDecoderStatistics sDecStatic;
521 int32_t iError = 0;
522
523 iRet = ValidInit();
524 ASSERT_EQ (iRet, ERR_NONE);
525 //GetOption before decoding
526 m_pDec->GetOption (DECODER_OPTION_GET_STATISTICS, &sDecStatic);
527 EXPECT_EQ (0u, sDecStatic.uiDecodedFrameCount);
528 EXPECT_TRUE (-1 == sDecStatic.iAvgLumaQp);
529 // setoption not support,
530 eRet = (CM_RETURN)m_pDec->SetOption (DECODER_OPTION_GET_STATISTICS, NULL);
531 EXPECT_EQ (eRet, cmInitParaError);
532 //EC on UT
533 iError = 2;
534 m_pDec->SetOption (DECODER_OPTION_ERROR_CON_IDC, &iError);
535 //Decoder error bs
536 DecoderBs ("res/Error_I_P.264");
537 m_pDec->GetOption (DECODER_OPTION_GET_STATISTICS, &sDecStatic);
538 EXPECT_EQ (65u, sDecStatic.uiAvgEcRatio);
539 EXPECT_EQ (7u, sDecStatic.uiAvgEcPropRatio);
540 EXPECT_EQ (5u, sDecStatic.uiDecodedFrameCount);
541 EXPECT_EQ (288u, sDecStatic.uiHeight);
542 EXPECT_EQ (1u, sDecStatic.uiIDRCorrectNum);
543 EXPECT_EQ (3u, sDecStatic.uiResolutionChangeTimes);
544 EXPECT_EQ (352u, sDecStatic.uiWidth);
545 EXPECT_EQ (4u, sDecStatic.uiEcFrameNum);
546 EXPECT_EQ (2u, sDecStatic.uiEcIDRNum);
547 EXPECT_EQ (0u, sDecStatic.uiIDRLostNum);
548 Uninit();
549
550 //Decoder error bs when the first IDR lost
551 iRet = ValidInit();
552 ASSERT_EQ (iRet, ERR_NONE);
553 iError = 2;
554 m_pDec->SetOption (DECODER_OPTION_ERROR_CON_IDC, &iError);
555 DecoderBs ("res/BA_MW_D_IDR_LOST.264");
556 m_pDec->GetOption (DECODER_OPTION_GET_STATISTICS, &sDecStatic);
557 EXPECT_EQ (88u, sDecStatic.uiAvgEcRatio);
558 EXPECT_EQ (88u, sDecStatic.uiAvgEcPropRatio);
559 EXPECT_EQ (97u, sDecStatic.uiDecodedFrameCount);
560 EXPECT_EQ (144u, sDecStatic.uiHeight);
561 EXPECT_EQ (3u, sDecStatic.uiIDRCorrectNum);
562 EXPECT_EQ (0u, sDecStatic.uiEcIDRNum);
563 EXPECT_EQ (1u, sDecStatic.uiResolutionChangeTimes);
564 EXPECT_EQ (176u, sDecStatic.uiWidth);
565 EXPECT_EQ (27u, sDecStatic.uiEcFrameNum);
566 EXPECT_EQ (1u, sDecStatic.uiIDRLostNum);
567 Uninit();
568
569 //ecoder error bs when the first P lost
570 iRet = ValidInit();
571 ASSERT_EQ (iRet, ERR_NONE);
572
573 iError = 2;
574 m_pDec->SetOption (DECODER_OPTION_ERROR_CON_IDC, &iError);
575
576 DecoderBs ("res/BA_MW_D_P_LOST.264");
577
578 m_pDec->GetOption (DECODER_OPTION_GET_STATISTICS, &sDecStatic);
579 EXPECT_EQ (85u, sDecStatic.uiAvgEcRatio);
580 EXPECT_EQ (85u, sDecStatic.uiAvgEcPropRatio);
581 EXPECT_EQ (99u, sDecStatic.uiDecodedFrameCount);
582 EXPECT_EQ (144u, sDecStatic.uiHeight);
583 EXPECT_EQ (4u, sDecStatic.uiIDRCorrectNum);
584 EXPECT_EQ (0u, sDecStatic.uiEcIDRNum);
585 EXPECT_EQ (1u, sDecStatic.uiResolutionChangeTimes);
586 EXPECT_EQ (176u, sDecStatic.uiWidth);
587 EXPECT_EQ (28u, sDecStatic.uiEcFrameNum);
588 EXPECT_EQ (0u, sDecStatic.uiIDRLostNum);
589 Uninit();
590 //EC enable
591
592 //EC Off UT just correc bitstream
593 iRet = ValidInit();
594 ASSERT_EQ (iRet, ERR_NONE);
595
596 iError = 0;
597 m_pDec->SetOption (DECODER_OPTION_ERROR_CON_IDC, &iError);
598 DecoderBs ("res/test_vd_1d.264");
599
600 m_pDec->GetOption (DECODER_OPTION_GET_STATISTICS, &sDecStatic);
601
602 EXPECT_EQ (0u, sDecStatic.uiAvgEcRatio);
603 EXPECT_EQ (0u, sDecStatic.uiAvgEcPropRatio);
604 EXPECT_EQ (9u, sDecStatic.uiDecodedFrameCount);
605 EXPECT_EQ (192u, sDecStatic.uiHeight);
606 EXPECT_EQ (1u, sDecStatic.uiIDRCorrectNum);
607 EXPECT_EQ (1u, sDecStatic.uiResolutionChangeTimes);
608 EXPECT_EQ (320u, sDecStatic.uiWidth);
609 EXPECT_EQ (0u, sDecStatic.uiEcFrameNum);
610 EXPECT_EQ (0u, sDecStatic.uiIDRLostNum);
611 Uninit();
612
613 }
614
615 //DECODER_OPTION_GET_SAR_INFO
TestGetDecSarInfo()616 void DecoderInterfaceTest::TestGetDecSarInfo() {
617 CM_RETURN eRet;
618 int32_t iRet;
619 SVuiSarInfo sVuiSarInfo;
620
621 iRet = ValidInit();
622 ASSERT_EQ (iRet, ERR_NONE);
623 //GetOption before decoding
624 m_pDec->GetOption (DECODER_OPTION_GET_SAR_INFO, &sVuiSarInfo);
625 EXPECT_EQ (0u, sVuiSarInfo.uiSarWidth);
626 EXPECT_EQ (0u, sVuiSarInfo.uiSarHeight);
627 EXPECT_EQ (sVuiSarInfo.bOverscanAppropriateFlag, false); // EXPECT_EQ does not like "false" as its first arg
628 // setoption not support,
629 eRet = (CM_RETURN)m_pDec->SetOption (DECODER_OPTION_GET_SAR_INFO, NULL);
630 EXPECT_EQ (eRet, cmInitParaError);
631
632 //Decoder specific bs
633 DecoderBs ("res/SarVui.264");
634 m_pDec->GetOption (DECODER_OPTION_GET_SAR_INFO, &sVuiSarInfo);
635 EXPECT_EQ (80u, sVuiSarInfo.uiSarWidth); //DO NOT MODIFY the data value
636 EXPECT_EQ (33u, sVuiSarInfo.uiSarHeight); //DO NOT MODIFY the data value
637 EXPECT_EQ (true, sVuiSarInfo.bOverscanAppropriateFlag); //DO NOT MODIFY the data value
638 Uninit();
639 }
640
641 //DECODER_OPTION_GET_SAR_INFO, test Vui in subset sps
TestVuiInSubsetSps()642 void DecoderInterfaceTest::TestVuiInSubsetSps() {
643 int32_t iRet;
644 SVuiSarInfo sVuiSarInfo;
645
646 iRet = ValidInit();
647 ASSERT_EQ (iRet, ERR_NONE);
648
649 //GetOption before decoding
650 m_pDec->GetOption (DECODER_OPTION_GET_SAR_INFO, &sVuiSarInfo);
651 EXPECT_EQ (0u, sVuiSarInfo.uiSarWidth);
652 EXPECT_EQ (0u, sVuiSarInfo.uiSarHeight);
653 EXPECT_EQ (sVuiSarInfo.bOverscanAppropriateFlag, false);
654
655 DecoderBs ("res/sps_subsetsps_bothVUI.264");
656 m_pDec->GetOption (DECODER_OPTION_GET_SAR_INFO, &sVuiSarInfo);
657 EXPECT_EQ (1u, sVuiSarInfo.uiSarWidth); //DO NOT MODIFY the data value
658 EXPECT_EQ (1u, sVuiSarInfo.uiSarHeight); //DO NOT MODIFY the data value
659 EXPECT_EQ (sVuiSarInfo.bOverscanAppropriateFlag, false); //DO NOT MODIFY the data value
660 Uninit();
661 }
662
663 //TEST here for whole tests
TEST_F(DecoderInterfaceTest,DecoderInterfaceAll)664 TEST_F (DecoderInterfaceTest, DecoderInterfaceAll) {
665
666 //Initialize Uninitialize
667 TestInitUninit();
668 //DECODER_OPTION_END_OF_STREAM
669 TestEndOfStream();
670 //DECODER_OPTION_VCL_NAL
671 TestVclNal();
672 //DECODER_OPTION_TEMPORAL_ID
673 TestTemporalId();
674 //DECODER_OPTION_FRAME_NUM
675 TestFrameNum();
676 //DECODER_OPTION_IDR_PIC_ID
677 TestIdrPicId();
678 //DECODER_OPTION_LTR_MARKING_FLAG
679 TestLtrMarkingFlag();
680 //DECODER_OPTION_LTR_MARKED_FRAME_NUM
681 TestLtrMarkedFrameNum();
682 //DECODER_OPTION_ERROR_CON_IDC
683 TestErrorConIdc();
684 //DECODER_OPTION_TRACE_LEVEL
685 TestTraceLevel();
686 //DECODER_OPTION_TRACE_CALLBACK
687 TestTraceCallback();
688 //DECODER_OPTION_TRACE_CALLBACK_CONTEXT
689 TestTraceCallbackContext();
690 //DECODER_OPTION_GET_STATISTICS
691 TestGetDecStatistics();
692 //DECODER_OPTION_GET_SAR_INFO
693 TestGetDecSarInfo();
694 //DECODER_OPTION_GET_SAR_INFO with vui in subsetsps
695 TestVuiInSubsetSps();
696 }
697
698
699