History

1. add encoder/decoder api test for IDR id and framenum 2. use random value as input, instead of using *.264

dong zhang committed 12 years ago

Commit 8da63ea1 parent 153a0311 file · +120 −13Browse files

Showing the changes to test/api/encode_decode_api_test.cpp (1 of 1 file). Show all

Unified · Split

test/api/encode_decode_api_test.cpp+120−13
@@ -7,7 +7,7 @@ · 6 unmodified lines
7#include <string>7#include <string>
8 8
9struct EncodeDecodeFileParamBase {9struct EncodeDecodeFileParamBase {
10 const char* fileName;10 int numframes;
11 int width;11 int width;
12 int height;12 int height;
13 float frameRate;13 float frameRate;
@@ -56,7 +56,7 @@ class EncodeDecodeTestBase : public ::testing::Test, · 42 unmodified lines
56 SBufferInfo dstBufInfo_;56 SBufferInfo dstBufInfo_;
57};57};
58 58
59class EncodeDecodeTestVclNal : public EncodeDecodeTestBase {59class EncodeDecodeTestAPI : public EncodeDecodeTestBase {
60 public:60 public:
61 void SetUp() {61 void SetUp() {
62 EncodeDecodeTestBase::SetUp();62 EncodeDecodeTestBase::SetUp();
@@ -72,18 +72,10 @@ class EncodeDecodeTestVclNal : public EncodeDecodeTestBase { · 9 unmodified lines
72};72};
73 73
74static const EncodeDecodeFileParamBase kFileParamArray =74static const EncodeDecodeFileParamBase kFileParamArray =
75{"res/CiscoVT2people_160x96_6fps.yuv", 160, 96, 6.0f};75{300, 160, 96, 6.0f};
76 76
77TEST_F (EncodeDecodeTestVclNal, DecoderVclNal) {77TEST_F (EncodeDecodeTestAPI, DecoderVclNal) {
78 EncodeDecodeFileParamBase p = kFileParamArray;78 EncodeDecodeFileParamBase p = kFileParamArray;
79 FileInputStream fileStream;
80#if defined(ANDROID_NDK)
81 std::string filename = std::string ("/sdcard/") + p.fileName;
82 ASSERT_TRUE (fileStream.Open (filename.c_str()));
83#else
84 ASSERT_TRUE (fileStream.Open (p.fileName));
85#endif
86
87 prepareParam (p.width, p.height, p.frameRate);79 prepareParam (p.width, p.height, p.frameRate);
88 int rv = encoder_->InitializeExt (&param_);80 int rv = encoder_->InitializeExt (&param_);
89 ASSERT_TRUE (rv == cmResultSuccess);81 ASSERT_TRUE (rv == cmResultSuccess);
@@ -108,7 +100,9 @@ TEST_F (EncodeDecodeTestVclNal, DecoderVclNal) { · 18 unmodified lines
108 pic.pData[0] = buf_.data();100 pic.pData[0] = buf_.data();
109 pic.pData[1] = pic.pData[0] + p.width * p.height;101 pic.pData[1] = pic.pData[0] + p.width * p.height;
110 pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2);102 pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2);
111 while (fileStream.read (buf_.data(), frameSize) == frameSize) {103 int iIdx = 0;
104 while (iIdx <= p.numframes) {
105 memset (buf_.data(), rand() % 256, frameSize);
112 rv = encoder_->EncodeFrame (&pic, &info);106 rv = encoder_->EncodeFrame (&pic, &info);
113 ASSERT_TRUE (rv == cmResultSuccess);107 ASSERT_TRUE (rv == cmResultSuccess);
114 //decoding after each encoding frame108 //decoding after each encoding frame
@@ -124,8 +118,121 @@ TEST_F (EncodeDecodeTestVclNal, DecoderVclNal) { · 9 unmodified lines
124 ASSERT_TRUE (rv == cmResultSuccess);118 ASSERT_TRUE (rv == cmResultSuccess);
125 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);119 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);
126 EXPECT_EQ (vclNal, FEEDBACK_VCL_NAL);120 EXPECT_EQ (vclNal, FEEDBACK_VCL_NAL);
121 iIdx++;
122 } //while
123 //ignore last frame
124}
125
126TEST_F (EncodeDecodeTestAPI, GetOptionFramenum) {
127 EncodeDecodeFileParamBase p = kFileParamArray;
128 prepareParam (p.width, p.height, p.frameRate);
129 int rv = encoder_->InitializeExt (&param_);
130 ASSERT_TRUE (rv == cmResultSuccess);
131
132 //init for encoder
133 // I420: 1(Y) + 1/4(U) + 1/4(V)
134 int frameSize = p.width * p.height * 3 / 2;
135
136 buf_.SetLength (frameSize);
137 ASSERT_TRUE (buf_.Length() == (size_t)frameSize);
138
139 SFrameBSInfo info;
140 memset (&info, 0, sizeof (SFrameBSInfo));
141
142 SSourcePicture pic;
143 memset (&pic, 0, sizeof (SSourcePicture));
144 pic.iPicWidth = p.width;
145 pic.iPicHeight = p.height;
146 pic.iColorFormat = videoFormatI420;
147 pic.iStride[0] = pic.iPicWidth;
148 pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
149 pic.pData[0] = buf_.data();
150 pic.pData[1] = pic.pData[0] + p.width * p.height;
151 pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2);
152 int32_t iEncFrameNum = -1;
153 int32_t iDecFrameNum;
154 int iIdx = 0;
155 while (iIdx <= p.numframes) {
156 memset (buf_.data(), rand() % 256, frameSize);
157 rv = encoder_->EncodeFrame (&pic, &info);
158 ASSERT_TRUE (rv == cmResultSuccess);
159 //decoding after each encoding frame
160 int len = 0;
161 encToDecData (info, len);
162 unsigned char* pData[3] = { NULL };
163 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
164 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
165 ASSERT_TRUE (rv == cmResultSuccess);
166 decoder_->GetOption (DECODER_OPTION_FRAME_NUM, &iDecFrameNum);
167 EXPECT_EQ (iDecFrameNum, -1);
168 iEncFrameNum++;
169 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
170 ASSERT_TRUE (rv == cmResultSuccess);
171 decoder_->GetOption (DECODER_OPTION_FRAME_NUM, &iDecFrameNum);
172 EXPECT_EQ (iEncFrameNum, iDecFrameNum);
173 iIdx++;
174 } //while
175 //ignore last frame
176}
177
178TEST_F (EncodeDecodeTestAPI, GetOptionIDR) {
179 EncodeDecodeFileParamBase p = kFileParamArray;
180 prepareParam (p.width, p.height, p.frameRate);
181 int rv = encoder_->InitializeExt (&param_);
182 ASSERT_TRUE (rv == cmResultSuccess);
183
184 //init for encoder
185 // I420: 1(Y) + 1/4(U) + 1/4(V)
186 int frameSize = p.width * p.height * 3 / 2;
187
188 buf_.SetLength (frameSize);
189 ASSERT_TRUE (buf_.Length() == (size_t)frameSize);
127 190
191 SFrameBSInfo info;
192 memset (&info, 0, sizeof (SFrameBSInfo));
193
194 SSourcePicture pic;
195 memset (&pic, 0, sizeof (SSourcePicture));
196 pic.iPicWidth = p.width;
197 pic.iPicHeight = p.height;
198 pic.iColorFormat = videoFormatI420;
199 pic.iStride[0] = pic.iPicWidth;
200 pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
201 pic.pData[0] = buf_.data();
202 pic.pData[1] = pic.pData[0] + p.width * p.height;
203 pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2);
204 int32_t iEncCurIdrPicId = 0;
205 int32_t iDecCurIdrPicId;
206 int32_t iIDRPeriod = 1;
207 int32_t iSpsPpsIdAddition = 0;
208 int iIdx = 0;
209 while (iIdx <= p.numframes) {
210 memset (buf_.data(), rand() % 256, frameSize);
211 iSpsPpsIdAddition = rand() % 2;
212 iIDRPeriod = (rand() % 150) + 1;
213 encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
214 encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
215 rv = encoder_->EncodeFrame (&pic, &info);
216 ASSERT_TRUE (rv == cmResultSuccess);
217 if (info.eFrameType == videoFrameTypeIDR) {
218 iEncCurIdrPicId = (iSpsPpsIdAddition == 0) ? 0 : (iEncCurIdrPicId + 1);
219 }
220 //decoding after each encoding frame
221 int len = 0;
222 encToDecData (info, len);
223 unsigned char* pData[3] = { NULL };
224 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
225 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
226 ASSERT_TRUE (rv == cmResultSuccess);
227 decoder_->GetOption (DECODER_OPTION_IDR_PIC_ID, &iDecCurIdrPicId);
228 EXPECT_EQ (iDecCurIdrPicId, iEncCurIdrPicId);
229 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
230 ASSERT_TRUE (rv == cmResultSuccess);
231 decoder_->GetOption (DECODER_OPTION_IDR_PIC_ID, &iDecCurIdrPicId);
232 EXPECT_EQ (iDecCurIdrPicId, iEncCurIdrPicId);
233 iIdx++;
128 } //while234 } //while
129 //ignore last frame235 //ignore last frame
130}236}
131 237
238

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