1 #include <gtest/gtest.h>
2 #include "utils/HashFunctions.h"
3 #include "BaseEncoderTest.h"
4 #include <string>
5
UpdateHashFromFrame(const SFrameBSInfo & info,SHA1Context * ctx)6 static void UpdateHashFromFrame (const SFrameBSInfo& info, SHA1Context* ctx) {
7 for (int i = 0; i < info.iLayerNum; ++i) {
8 const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
9 int layerSize = 0;
10 for (int j = 0; j < layerInfo.iNalCount; ++j) {
11 layerSize += layerInfo.pNalLengthInByte[j];
12 }
13 SHA1Input (ctx, layerInfo.pBsBuf, layerSize);
14 }
15 }
16
17 class EncoderInitTest : public ::testing::Test, public BaseEncoderTest {
18 public:
SetUp()19 virtual void SetUp() {
20 BaseEncoderTest::SetUp();
21 }
TearDown()22 virtual void TearDown() {
23 BaseEncoderTest::TearDown();
24 }
25 };
26
TEST_F(EncoderInitTest,JustInit)27 TEST_F (EncoderInitTest, JustInit) {}
28
29 struct EncodeFileParam {
30 const char* pkcFileName;
31 const char* pkcHashStr[2];
32 EUsageType eUsageType;
33 int iWidth;
34 int iHeight;
35 float fFrameRate;
36 SliceModeEnum eSliceMode;
37 bool bDenoise;
38 int iLayerNum;
39 bool bLossless;
40 bool bEnableLtr;
41 bool bCabac;
42 // unsigned short iMultipleThreadIdc;
43 };
44
EncFileParamToParamExt(EncodeFileParam * pEncFileParam,SEncParamExt * pEnxParamExt)45 void EncFileParamToParamExt (EncodeFileParam* pEncFileParam, SEncParamExt* pEnxParamExt) {
46 ASSERT_TRUE (NULL != pEncFileParam && NULL != pEnxParamExt);
47 pEnxParamExt->iUsageType = pEncFileParam->eUsageType;
48 pEnxParamExt->iPicWidth = pEncFileParam->iWidth;
49 pEnxParamExt->iPicHeight = pEncFileParam->iHeight;
50 pEnxParamExt->fMaxFrameRate = pEncFileParam->fFrameRate;
51 pEnxParamExt->iSpatialLayerNum = pEncFileParam->iLayerNum;
52
53 pEnxParamExt->bEnableDenoise = pEncFileParam->bDenoise;
54 pEnxParamExt->bIsLosslessLink = pEncFileParam->bLossless;
55 pEnxParamExt->bEnableLongTermReference = pEncFileParam->bEnableLtr;
56 pEnxParamExt->iEntropyCodingModeFlag = pEncFileParam->bCabac ? 1 : 0;
57
58 for (int i = 0; i < pEnxParamExt->iSpatialLayerNum; i++) {
59 pEnxParamExt->sSpatialLayers[i].sSliceArgument.uiSliceMode = pEncFileParam->eSliceMode;
60 }
61
62 }
63
64 class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>,
65 public EncoderInitTest , public BaseEncoderTest::Callback {
66 public:
SetUp()67 virtual void SetUp() {
68 EncoderInitTest::SetUp();
69 if (HasFatalFailure()) {
70 return;
71 }
72 SHA1Reset (&ctx_);
73 }
onEncodeFrame(const SFrameBSInfo & frameInfo)74 virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) {
75 UpdateHashFromFrame (frameInfo, &ctx_);
76 }
77
78 protected:
79 SHA1Context ctx_;
80 };
81
82
TEST_P(EncoderOutputTest,CompareOutput)83 TEST_P (EncoderOutputTest, CompareOutput) {
84 EncodeFileParam p = GetParam();
85 SEncParamExt EnxParamExt;
86
87 EncFileParamToParamExt (&p, &EnxParamExt);
88
89 #if defined(ANDROID_NDK)
90 std::string filename = std::string ("/sdcard/") + p.pkcFileName;
91 EncodeFile (p.pkcFileName, &EnxParamExt, this);
92 #else
93 EncodeFile (p.pkcFileName, &EnxParamExt, this);
94 #endif
95 //will remove this after screen content algorithms are ready,
96 //because the bitstream output will vary when the different algorithms are added.
97 unsigned char digest[SHA_DIGEST_LENGTH];
98 SHA1Result (&ctx_, digest);
99 if (!HasFatalFailure()) {
100 CompareHashAnyOf (digest, p.pkcHashStr, sizeof p.pkcHashStr / sizeof *p.pkcHashStr);
101 }
102 }
103 static const EncodeFileParam kFileParamArray[] = {
104 {
105 "res/CiscoVT2people_320x192_12fps.yuv",
106 {"19dd24f5a3ae9e9582024db5b63696948b8ac82f"}, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false
107 },
108 {
109 "res/CiscoVT2people_160x96_6fps.yuv",
110 {"7acf58ba0e72ffc4725ad897ed45f990b9ab8413"}, CAMERA_VIDEO_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false
111 },
112 {
113 "res/Static_152_100.yuv",
114 {"d27c6a56efe899528ddd3f8f3b33efb8f3ce2d51"}, CAMERA_VIDEO_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false
115 },
116 {
117 "res/CiscoVT2people_320x192_12fps.yuv",
118 {"5111d90ce90849020b7ed830cc2f962ccfea4457"}, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_RASTER_SLICE, false, 1, false, false, false // One slice per MB row
119 },
120 {
121 "res/CiscoVT2people_320x192_12fps.yuv",
122 {"91ca058f728a001546ae34ce1b7a00163800faac"}, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, true, 1, false, false, false
123 },
124 {
125 "res/CiscoVT2people_320x192_12fps.yuv",
126 // Allow for different output depending on whether averaging is done
127 // vertically or horizontally first when downsampling.
128 { "4faa2a17c6629135af43c2392531f4ce954ec92d", "a4c2caccada00189c683cd61c6f0bb995d09aeff" },
129 CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 2, false, false, false
130 },
131 {
132 "res/Cisco_Absolute_Power_1280x720_30fps.yuv",
133 {"abd7aa034f916659a9f68b33160b404fb43411dd"}, CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false
134 },
135 {
136 "res/Cisco_Absolute_Power_1280x720_30fps.yuv",
137 // Allow for different output depending on whether averaging is done
138 // vertically or horizontally first when downsampling.
139 { "291fba557fdfd0e077ff6681425dc81c65704b62", "9e4fb2b503a877c21441545ee4f0cd5416dbe5e9" },
140 CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SINGLE_SLICE, false, 4, false, false, false
141 },
142
143 // the following values may be adjusted for times since we start tuning the strategy
144 {
145 "res/CiscoVT2people_320x192_12fps.yuv",
146 {"dd51c2007f944ee752532c74c4d38da1413acd88"}, SCREEN_CONTENT_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false
147 },
148 {
149 "res/CiscoVT2people_160x96_6fps.yuv",
150 {"564b0e774f0157c91c7ff3548708f88fb0f3abc6"}, SCREEN_CONTENT_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false
151 },
152 {
153 "res/Static_152_100.yuv",
154 {"9b88952f0ec5ebf3e25e642b8a9f355854681f57"}, SCREEN_CONTENT_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false
155 },
156 {
157 "res/Cisco_Absolute_Power_1280x720_30fps.yuv",
158 {"7db72f0d6f347f57d5137a5cd4de2a3e3fba5b95"}, SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false
159 },
160 //for different strategy
161 {
162 "res/Cisco_Absolute_Power_1280x720_30fps.yuv",
163 {"30b877303081e2c5ee579d8bbeb2094abd2018c1"}, SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, true, true, false
164 },
165 {
166 "res/CiscoVT2people_320x192_12fps.yuv",
167 {"3c27f9134d79edaa769741005b569565c2367e6f"}, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, true //turn on cabac
168 },
169
170 {
171 "res/Cisco_Absolute_Power_1280x720_30fps.yuv",
172 {"e5a91447595a2a3560f7cdabbb62b694134fe4ca"}, CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, true
173 },
174
175 {
176 "res/Cisco_Absolute_Power_1280x720_30fps.yuv",
177 {"77aa8bc391a84d308a09d4fbb859f4a0e8ae8196"}, CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_FIXEDSLCNUM_SLICE, false, 1, false, false, true
178 },
179
180 };
181
182 INSTANTIATE_TEST_CASE_P (EncodeFile, EncoderOutputTest,
183 ::testing::ValuesIn (kFileParamArray));
184