History

Restore unix newlines after "Merge pull request #2991 from xiaotianshi2/master"

Some newlines were fixed in "Merge pull request #2997 from GuangweiWang/fix-issue-external", but lots were still left behind.

Martin Storsjö committed 8 years ago

Commit 1fb2f7d1 parent d43bfc114 files · +9238 −9238Browse files

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

Unified · Split

test/api/BaseDecoderTest.cpp+219−219
@@ -1,219 +1,219 @@
1−#include <fstream>
2−#include <gtest/gtest.h>
3−#include "codec_def.h"
4−#include "codec_app_def.h"
5−#include "utils/BufferedData.h"
6−#include "BaseDecoderTest.h"
7−
8−static void ReadFrame (std::ifstream* file, BufferedData* buf) {
9− // start code of a frame is {0, 0, 0, 1}
10− int zeroCount = 0;
11− char b;
12−
13− buf->Clear();
14− for (;;) {
15− file->read (&b, 1);
16− if (file->gcount() != 1) { // end of file
17− return;
18− }
19− if (!buf->PushBack (b)) {
20− FAIL() << "unable to allocate memory";
21− }
22−
23− if (buf->Length() <= 4) {
24− continue;
25− }
26−
27− if (zeroCount < 3) {
28− zeroCount = b != 0 ? 0 : zeroCount + 1;
29− } else {
30− if (b == 1) {
31− if (file->seekg (-4, file->cur).good()) {
32− buf->SetLength (buf->Length() - 4);
33− return;
34− } else {
35− FAIL() << "unable to seek file";
36− }
37− } else if (b == 0) {
38− zeroCount = 3;
39− } else {
40− zeroCount = 0;
41− }
42− }
43− }
44−}
45−
46−BaseDecoderTest::BaseDecoderTest()
47− : decoder_ (NULL), decodeStatus_ (OpenFile) {}
48−
49−int32_t BaseDecoderTest::SetUp() {
50− long rv = WelsCreateDecoder (&decoder_);
51− EXPECT_EQ (0, rv);
52− EXPECT_TRUE (decoder_ != NULL);
53− if (decoder_ == NULL) {
54− return rv;
55− }
56−
57− SDecodingParam decParam;
58− memset (&decParam, 0, sizeof (SDecodingParam));
59− decParam.uiTargetDqLayer = UCHAR_MAX;
60− decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
61− decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
62−
63− rv = decoder_->Initialize (&decParam);
64− EXPECT_EQ (0, rv);
65− return (int32_t)rv;
66−}
67−
68−void BaseDecoderTest::TearDown() {
69− if (decoder_ != NULL) {
70− decoder_->Uninitialize();
71− WelsDestroyDecoder (decoder_);
72− }
73−}
74−
75−
76−void BaseDecoderTest::DecodeFrame (const uint8_t* src, size_t sliceSize, Callback* cbk) {
77− uint8_t* data[3];
78− SBufferInfo bufInfo;
79− memset (data, 0, sizeof (data));
80− memset (&bufInfo, 0, sizeof (SBufferInfo));
81−
82− DECODING_STATE rv = decoder_->DecodeFrame2 (src, (int) sliceSize, data, &bufInfo);
83− ASSERT_TRUE (rv == dsErrorFree);
84−
85− if (bufInfo.iBufferStatus == 1 && cbk != NULL) {
86− const Frame frame = {
87− {
88− // y plane
89− data[0],
90− bufInfo.UsrData.sSystemBuffer.iWidth,
91− bufInfo.UsrData.sSystemBuffer.iHeight,
92− bufInfo.UsrData.sSystemBuffer.iStride[0]
93− },
94− {
95− // u plane
96− data[1],
97− bufInfo.UsrData.sSystemBuffer.iWidth / 2,
98− bufInfo.UsrData.sSystemBuffer.iHeight / 2,
99− bufInfo.UsrData.sSystemBuffer.iStride[1]
100− },
101− {
102− // v plane
103− data[2],
104− bufInfo.UsrData.sSystemBuffer.iWidth / 2,
105− bufInfo.UsrData.sSystemBuffer.iHeight / 2,
106− bufInfo.UsrData.sSystemBuffer.iStride[1]
107− },
108− };
109− cbk->onDecodeFrame (frame);
110− }
111−}
112−void BaseDecoderTest::FlushFrame (Callback* cbk) {
113− uint8_t* data[3];
114− SBufferInfo bufInfo;
115− memset (data, 0, sizeof (data));
116− memset (&bufInfo, 0, sizeof (SBufferInfo));
117−
118− DECODING_STATE rv = decoder_->FlushFrame (data, &bufInfo);
119− ASSERT_TRUE (rv == dsErrorFree);
120−
121− if (bufInfo.iBufferStatus == 1 && cbk != NULL) {
122− const Frame frame = {
123− {
124− // y plane
125− data[0],
126− bufInfo.UsrData.sSystemBuffer.iWidth,
127− bufInfo.UsrData.sSystemBuffer.iHeight,
128− bufInfo.UsrData.sSystemBuffer.iStride[0]
129− },
130− {
131− // u plane
132− data[1],
133− bufInfo.UsrData.sSystemBuffer.iWidth / 2,
134− bufInfo.UsrData.sSystemBuffer.iHeight / 2,
135− bufInfo.UsrData.sSystemBuffer.iStride[1]
136− },
137− {
138− // v plane
139− data[2],
140− bufInfo.UsrData.sSystemBuffer.iWidth / 2,
141− bufInfo.UsrData.sSystemBuffer.iHeight / 2,
142− bufInfo.UsrData.sSystemBuffer.iStride[1]
143− },
144− };
145− cbk->onDecodeFrame (frame);
146− }
147−}
148−void BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) {
149− std::ifstream file (fileName, std::ios::in | std::ios::binary);
150− ASSERT_TRUE (file.is_open());
151−
152− BufferedData buf;
153− while (true) {
154− ReadFrame (&file, &buf);
155− if (::testing::Test::HasFatalFailure()) {
156− return;
157− }
158− if (buf.Length() == 0) {
159− break;
160− }
161− DecodeFrame (buf.data(), buf.Length(), cbk);
162− if (::testing::Test::HasFatalFailure()) {
163− return;
164− }
165− }
166−
167− int32_t iEndOfStreamFlag = 1;
168− decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
169−
170− // Get pending last frame
171− DecodeFrame (NULL, 0, cbk);
172− // Flush out last frames in decoder buffer
173− int32_t num_of_frames_in_buffer = 0;
174− decoder_->GetOption (DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER, &num_of_frames_in_buffer);
175− for (int32_t i = 0; i < num_of_frames_in_buffer; ++i) {
176− FlushFrame (cbk);
177− }
178−}
179−
180−bool BaseDecoderTest::Open (const char* fileName) {
181− if (decodeStatus_ == OpenFile) {
182− file_.open (fileName, std::ios_base::out | std::ios_base::binary);
183− if (file_.is_open()) {
184− decodeStatus_ = Decoding;
185− return true;
186− }
187− }
188− return false;
189−}
190−
191−bool BaseDecoderTest::DecodeNextFrame (Callback* cbk) {
192− switch (decodeStatus_) {
193− case Decoding:
194− ReadFrame (&file_, &buf_);
195− if (::testing::Test::HasFatalFailure()) {
196− return false;
197− }
198− if (buf_.Length() == 0) {
199− decodeStatus_ = EndOfStream;
200− return true;
201− }
202− DecodeFrame (buf_.data(), buf_.Length(), cbk);
203− if (::testing::Test::HasFatalFailure()) {
204− return false;
205− }
206− return true;
207− case EndOfStream: {
208− int32_t iEndOfStreamFlag = 1;
209− decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
210− DecodeFrame (NULL, 0, cbk);
211− decodeStatus_ = End;
212− break;
213− }
214− case OpenFile:
215− case End:
216− break;
217− }
218− return false;
219−}
1+#include <fstream>
2+#include <gtest/gtest.h>
3+#include "codec_def.h"
4+#include "codec_app_def.h"
5+#include "utils/BufferedData.h"
6+#include "BaseDecoderTest.h"
7+
8+static void ReadFrame (std::ifstream* file, BufferedData* buf) {
9+ // start code of a frame is {0, 0, 0, 1}
10+ int zeroCount = 0;
11+ char b;
12+
13+ buf->Clear();
14+ for (;;) {
15+ file->read (&b, 1);
16+ if (file->gcount() != 1) { // end of file
17+ return;
18+ }
19+ if (!buf->PushBack (b)) {
20+ FAIL() << "unable to allocate memory";
21+ }
22+
23+ if (buf->Length() <= 4) {
24+ continue;
25+ }
26+
27+ if (zeroCount < 3) {
28+ zeroCount = b != 0 ? 0 : zeroCount + 1;
29+ } else {
30+ if (b == 1) {
31+ if (file->seekg (-4, file->cur).good()) {
32+ buf->SetLength (buf->Length() - 4);
33+ return;
34+ } else {
35+ FAIL() << "unable to seek file";
36+ }
37+ } else if (b == 0) {
38+ zeroCount = 3;
39+ } else {
40+ zeroCount = 0;
41+ }
42+ }
43+ }
44+}
45+
46+BaseDecoderTest::BaseDecoderTest()
47+ : decoder_ (NULL), decodeStatus_ (OpenFile) {}
48+
49+int32_t BaseDecoderTest::SetUp() {
50+ long rv = WelsCreateDecoder (&decoder_);
51+ EXPECT_EQ (0, rv);
52+ EXPECT_TRUE (decoder_ != NULL);
53+ if (decoder_ == NULL) {
54+ return rv;
55+ }
56+
57+ SDecodingParam decParam;
58+ memset (&decParam, 0, sizeof (SDecodingParam));
59+ decParam.uiTargetDqLayer = UCHAR_MAX;
60+ decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
61+ decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
62+
63+ rv = decoder_->Initialize (&decParam);
64+ EXPECT_EQ (0, rv);
65+ return (int32_t)rv;
66+}
67+
68+void BaseDecoderTest::TearDown() {
69+ if (decoder_ != NULL) {
70+ decoder_->Uninitialize();
71+ WelsDestroyDecoder (decoder_);
72+ }
73+}
74+
75+
76+void BaseDecoderTest::DecodeFrame (const uint8_t* src, size_t sliceSize, Callback* cbk) {
77+ uint8_t* data[3];
78+ SBufferInfo bufInfo;
79+ memset (data, 0, sizeof (data));
80+ memset (&bufInfo, 0, sizeof (SBufferInfo));
81+
82+ DECODING_STATE rv = decoder_->DecodeFrame2 (src, (int) sliceSize, data, &bufInfo);
83+ ASSERT_TRUE (rv == dsErrorFree);
84+
85+ if (bufInfo.iBufferStatus == 1 && cbk != NULL) {
86+ const Frame frame = {
87+ {
88+ // y plane
89+ data[0],
90+ bufInfo.UsrData.sSystemBuffer.iWidth,
91+ bufInfo.UsrData.sSystemBuffer.iHeight,
92+ bufInfo.UsrData.sSystemBuffer.iStride[0]
93+ },
94+ {
95+ // u plane
96+ data[1],
97+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
98+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
99+ bufInfo.UsrData.sSystemBuffer.iStride[1]
100+ },
101+ {
102+ // v plane
103+ data[2],
104+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
105+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
106+ bufInfo.UsrData.sSystemBuffer.iStride[1]
107+ },
108+ };
109+ cbk->onDecodeFrame (frame);
110+ }
111+}
112+void BaseDecoderTest::FlushFrame (Callback* cbk) {
113+ uint8_t* data[3];
114+ SBufferInfo bufInfo;
115+ memset (data, 0, sizeof (data));
116+ memset (&bufInfo, 0, sizeof (SBufferInfo));
117+
118+ DECODING_STATE rv = decoder_->FlushFrame (data, &bufInfo);
119+ ASSERT_TRUE (rv == dsErrorFree);
120+
121+ if (bufInfo.iBufferStatus == 1 && cbk != NULL) {
122+ const Frame frame = {
123+ {
124+ // y plane
125+ data[0],
126+ bufInfo.UsrData.sSystemBuffer.iWidth,
127+ bufInfo.UsrData.sSystemBuffer.iHeight,
128+ bufInfo.UsrData.sSystemBuffer.iStride[0]
129+ },
130+ {
131+ // u plane
132+ data[1],
133+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
134+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
135+ bufInfo.UsrData.sSystemBuffer.iStride[1]
136+ },
137+ {
138+ // v plane
139+ data[2],
140+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
141+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
142+ bufInfo.UsrData.sSystemBuffer.iStride[1]
143+ },
144+ };
145+ cbk->onDecodeFrame (frame);
146+ }
147+}
148+void BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) {
149+ std::ifstream file (fileName, std::ios::in | std::ios::binary);
150+ ASSERT_TRUE (file.is_open());
151+
152+ BufferedData buf;
153+ while (true) {
154+ ReadFrame (&file, &buf);
155+ if (::testing::Test::HasFatalFailure()) {
156+ return;
157+ }
158+ if (buf.Length() == 0) {
159+ break;
160+ }
161+ DecodeFrame (buf.data(), buf.Length(), cbk);
162+ if (::testing::Test::HasFatalFailure()) {
163+ return;
164+ }
165+ }
166+
167+ int32_t iEndOfStreamFlag = 1;
168+ decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
169+
170+ // Get pending last frame
171+ DecodeFrame (NULL, 0, cbk);
172+ // Flush out last frames in decoder buffer
173+ int32_t num_of_frames_in_buffer = 0;
174+ decoder_->GetOption (DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER, &num_of_frames_in_buffer);
175+ for (int32_t i = 0; i < num_of_frames_in_buffer; ++i) {
176+ FlushFrame (cbk);
177+ }
178+}
179+
180+bool BaseDecoderTest::Open (const char* fileName) {
181+ if (decodeStatus_ == OpenFile) {
182+ file_.open (fileName, std::ios_base::out | std::ios_base::binary);
183+ if (file_.is_open()) {
184+ decodeStatus_ = Decoding;
185+ return true;
186+ }
187+ }
188+ return false;
189+}
190+
191+bool BaseDecoderTest::DecodeNextFrame (Callback* cbk) {
192+ switch (decodeStatus_) {
193+ case Decoding:
194+ ReadFrame (&file_, &buf_);
195+ if (::testing::Test::HasFatalFailure()) {
196+ return false;
197+ }
198+ if (buf_.Length() == 0) {
199+ decodeStatus_ = EndOfStream;
200+ return true;
201+ }
202+ DecodeFrame (buf_.data(), buf_.Length(), cbk);
203+ if (::testing::Test::HasFatalFailure()) {
204+ return false;
205+ }
206+ return true;
207+ case EndOfStream: {
208+ int32_t iEndOfStreamFlag = 1;
209+ decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
210+ DecodeFrame (NULL, 0, cbk);
211+ decodeStatus_ = End;
212+ break;
213+ }
214+ case OpenFile:
215+ case End:
216+ break;
217+ }
218+ return false;
219+}

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