1 #include <gtest/gtest.h>
2 #include "codec_def.h"
3 #include "codec_api.h"
4 #include "utils/BufferedData.h"
5 #include "utils/FileInputStream.h"
6 #include "BaseEncoderTest.h"
7
8 class EncInterfaceCallTest : public ::testing::Test, public BaseEncoderTest {
9 public:
SetUp()10 virtual void SetUp() {
11 BaseEncoderTest::SetUp();
12 };
TearDown()13 virtual void TearDown() {
14 BaseEncoderTest::TearDown();
15 };
16
onEncodeFrame(const SFrameBSInfo & frameInfo)17 virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) {
18 //nothing
19 }
20 //testing case
21
22 };
23
24
TEST_F(EncInterfaceCallTest,BaseParameterVerify)25 TEST_F (EncInterfaceCallTest, BaseParameterVerify) {
26 int uiTraceLevel = WELS_LOG_QUIET;
27 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel);
28
29 int ret = cmResultSuccess;
30 SEncParamBase baseparam;
31 memset (&baseparam, 0, sizeof (SEncParamBase));
32
33 baseparam.iPicWidth = 0;
34 baseparam.iPicHeight = 7896;
35
36 ret = encoder_->Initialize (&baseparam);
37 EXPECT_EQ (ret, static_cast<int> (cmInitParaError));
38
39 uiTraceLevel = WELS_LOG_ERROR;
40 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel);
41 }
42
outputData()43 void outputData() {
44
45 }
46
TEST_F(EncInterfaceCallTest,SetOptionLTR)47 TEST_F (EncInterfaceCallTest, SetOptionLTR) {
48
49 int iTotalFrameNum = 100;
50 int iFrameNum = 0;
51 int frameSize = 0;
52 int ret = cmResultSuccess;
53 int width = 320;
54 int height = 192;
55
56
57 SEncParamBase baseparam;
58 memset (&baseparam, 0, sizeof (SEncParamBase));
59
60 baseparam.iUsageType = CAMERA_VIDEO_REAL_TIME;
61 baseparam.fMaxFrameRate = 12;
62 baseparam.iPicWidth = width;
63 baseparam.iPicHeight = height;
64 baseparam.iTargetBitrate = 5000000;
65 encoder_->Initialize (&baseparam);
66
67 frameSize = width * height * 3 / 2;
68
69 BufferedData buf;
70 buf.SetLength (frameSize);
71 ASSERT_TRUE (buf.Length() == (size_t)frameSize); //include memory fail (-1) case
72
73 SFrameBSInfo info;
74 memset (&info, 0, sizeof (SFrameBSInfo));
75
76 SSourcePicture pic;
77 memset (&pic, 0, sizeof (SSourcePicture));
78 pic.iPicWidth = width;
79 pic.iPicHeight = height;
80 pic.iColorFormat = videoFormatI420;
81 pic.iStride[0] = pic.iPicWidth;
82 pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
83 pic.pData[0] = buf.data();
84 pic.pData[1] = pic.pData[0] + width * height;
85 pic.pData[2] = pic.pData[1] + (width * height >> 2);
86
87 SLTRConfig config;
88 config.bEnableLongTermReference = true;
89 config.iLTRRefNum = rand() % 4;
90 encoder_->SetOption (ENCODER_OPTION_LTR, &config);
91 do {
92 FileInputStream fileStream;
93 ASSERT_TRUE (fileStream.Open ("res/CiscoVT2people_320x192_12fps.yuv"));
94
95 while (fileStream.read (buf.data(), frameSize) == frameSize) {
96 ret = encoder_->EncodeFrame (&pic, &info);
97 ASSERT_TRUE (ret == cmResultSuccess);
98 if (info.eFrameType != videoFrameTypeSkip) {
99 this->onEncodeFrame (info);
100 iFrameNum++;
101 }
102 }
103 } while (iFrameNum < iTotalFrameNum);
104
105 }