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