History

astyle all

huili2 committed 12 years ago

Commit dc3fae41 parent 101265385 files · +4906 −4701Browse files

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

Unified · Split

test/api/BaseDecoderTest.cpp+54−51
@@ -5,18 +5,18 @@ · 4 unmodified lines
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
@@ -28,8 +28,8 @@ static void ReadFrame(std::ifstream* file, BufferedData* buf) { · 5 unmodified lines
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";
@@ -44,94 +44,97 @@ static void ReadFrame(std::ifstream* file, BufferedData* buf) { · 8 unmodified lines
44}44}
45 45
46BaseDecoderTest::BaseDecoderTest()46BaseDecoderTest::BaseDecoderTest()
47 : decoder_(NULL), decodeStatus_(OpenFile) {}47 : decoder_ (NULL), decodeStatus_ (OpenFile) {}
48 48
49void BaseDecoderTest::SetUp() {49void BaseDecoderTest::SetUp() {
50 long rv = WelsCreateDecoder(&decoder_);50 long rv = WelsCreateDecoder (&decoder_);
51 ASSERT_EQ(0, rv);51 ASSERT_EQ (0, rv);
52 ASSERT_TRUE(decoder_ != NULL);52 ASSERT_TRUE (decoder_ != NULL);
53 53
54 SDecodingParam decParam;54 SDecodingParam decParam;
55 memset(&decParam, 0, sizeof(SDecodingParam));55 memset (&decParam, 0, sizeof (SDecodingParam));
56 decParam.iOutputColorFormat = videoFormatI420;56 decParam.iOutputColorFormat = videoFormatI420;
57 decParam.uiTargetDqLayer = UCHAR_MAX;57 decParam.uiTargetDqLayer = UCHAR_MAX;
58 decParam.uiEcActiveFlag = 1;58 decParam.uiEcActiveFlag = 1;
59 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;59 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
60 60
61 rv = decoder_->Initialize(&decParam);61 rv = decoder_->Initialize (&decParam);
62 ASSERT_EQ(0, rv);62 ASSERT_EQ (0, rv);
63}63}
64 64
65void BaseDecoderTest::TearDown() {65void BaseDecoderTest::TearDown() {
66 if (decoder_ != NULL) {66 if (decoder_ != NULL) {
67 decoder_->Uninitialize();67 decoder_->Uninitialize();
68 WelsDestroyDecoder(decoder_);68 WelsDestroyDecoder (decoder_);
69 }69 }
70}70}
71 71
72 72
73void BaseDecoderTest::DecodeFrame(const uint8_t* src, int sliceSize, Callback* cbk) {73void BaseDecoderTest::DecodeFrame (const uint8_t* src, int sliceSize, Callback* cbk) {
74 uint8_t* data[3];74 uint8_t* data[3];
75 SBufferInfo bufInfo;75 SBufferInfo bufInfo;
76 memset(data, 0, sizeof(data));76 memset (data, 0, sizeof (data));
77 memset(&bufInfo, 0, sizeof(SBufferInfo));77 memset (&bufInfo, 0, sizeof (SBufferInfo));
78 78
79 DECODING_STATE rv = decoder_->DecodeFrame2(src, sliceSize, data, &bufInfo);79 DECODING_STATE rv = decoder_->DecodeFrame2 (src, sliceSize, data, &bufInfo);
80 ASSERT_TRUE(rv == dsErrorFree);80 ASSERT_TRUE (rv == dsErrorFree);
81 81
82 if (bufInfo.iBufferStatus == 1 && cbk != NULL) {82 if (bufInfo.iBufferStatus == 1 && cbk != NULL) {
83 const Frame frame = {83 const Frame frame = {
84 { // y plane84 {
85 data[0],85 // y plane
86 bufInfo.UsrData.sSystemBuffer.iWidth,86 data[0],
87 bufInfo.UsrData.sSystemBuffer.iHeight,87 bufInfo.UsrData.sSystemBuffer.iWidth,
88 bufInfo.UsrData.sSystemBuffer.iStride[0]88 bufInfo.UsrData.sSystemBuffer.iHeight,
89 },89 bufInfo.UsrData.sSystemBuffer.iStride[0]
90 { // u plane90 },
91 data[1],91 {
92 bufInfo.UsrData.sSystemBuffer.iWidth / 2,92 // u plane
93 bufInfo.UsrData.sSystemBuffer.iHeight / 2,93 data[1],
94 bufInfo.UsrData.sSystemBuffer.iStride[1]94 bufInfo.UsrData.sSystemBuffer.iWidth / 2,
95 },95 bufInfo.UsrData.sSystemBuffer.iHeight / 2,
96 { // v plane96 bufInfo.UsrData.sSystemBuffer.iStride[1]
97 data[2],97 },
98 bufInfo.UsrData.sSystemBuffer.iWidth / 2,98 {
99 bufInfo.UsrData.sSystemBuffer.iHeight / 2,99 // v plane
100 bufInfo.UsrData.sSystemBuffer.iStride[1]100 data[2],
101 },101 bufInfo.UsrData.sSystemBuffer.iWidth / 2,
102 bufInfo.UsrData.sSystemBuffer.iHeight / 2,
103 bufInfo.UsrData.sSystemBuffer.iStride[1]
104 },
102 };105 };
103 cbk->onDecodeFrame(frame);106 cbk->onDecodeFrame (frame);
104 }107 }
105}108}
106void BaseDecoderTest::DecodeFile(const char* fileName, Callback* cbk) {109void BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) {
107 std::ifstream file(fileName, std::ios::in | std::ios::binary);110 std::ifstream file (fileName, std::ios::in | std::ios::binary);
108 ASSERT_TRUE(file.is_open());111 ASSERT_TRUE (file.is_open());
109 112
110 BufferedData buf;113 BufferedData buf;
111 while (true) {114 while (true) {
112 ReadFrame(&file, &buf);115 ReadFrame (&file, &buf);
113 if (::testing::Test::HasFatalFailure()) {116 if (::testing::Test::HasFatalFailure()) {
114 return;117 return;
115 }118 }
116 if (buf.Length() == 0) {119 if (buf.Length() == 0) {
117 break;120 break;
118 }121 }
119 DecodeFrame(buf.data(), buf.Length(), cbk);122 DecodeFrame (buf.data(), buf.Length(), cbk);
120 if (::testing::Test::HasFatalFailure()) {123 if (::testing::Test::HasFatalFailure()) {
121 return;124 return;
122 }125 }
123 }126 }
124 127
125 int32_t iEndOfStreamFlag = 1;128 int32_t iEndOfStreamFlag = 1;
126 decoder_->SetOption(DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);129 decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
127 130
128 // Get pending last frame131 // Get pending last frame
129 DecodeFrame(NULL, 0, cbk);132 DecodeFrame (NULL, 0, cbk);
130}133}
131 134
132bool BaseDecoderTest::Open(const char* fileName) {135bool BaseDecoderTest::Open (const char* fileName) {
133 if (decodeStatus_ == OpenFile) {136 if (decodeStatus_ == OpenFile) {
134 file_.open(fileName, std::ios_base::out | std::ios_base::binary);137 file_.open (fileName, std::ios_base::out | std::ios_base::binary);
135 if (file_.is_open()) {138 if (file_.is_open()) {
136 decodeStatus_ = Decoding;139 decodeStatus_ = Decoding;
137 return true;140 return true;
@@ -140,10 +143,10 @@ bool BaseDecoderTest::Open(const char* fileName) { · 2 unmodified lines
140 return false;143 return false;
141}144}
142 145
143bool BaseDecoderTest::DecodeNextFrame(Callback* cbk) {146bool BaseDecoderTest::DecodeNextFrame (Callback* cbk) {
144 switch (decodeStatus_) {147 switch (decodeStatus_) {
145 case Decoding:148 case Decoding:
146 ReadFrame(&file_, &buf_);149 ReadFrame (&file_, &buf_);
147 if (::testing::Test::HasFatalFailure()) {150 if (::testing::Test::HasFatalFailure()) {
148 return false;151 return false;
149 }152 }
@@ -151,15 +154,15 @@ bool BaseDecoderTest::DecodeNextFrame(Callback* cbk) { · 1 unmodified line
151 decodeStatus_ = EndOfStream;154 decodeStatus_ = EndOfStream;
152 return true;155 return true;
153 }156 }
154 DecodeFrame(buf_.data(), buf_.Length(), cbk);157 DecodeFrame (buf_.data(), buf_.Length(), cbk);
155 if (::testing::Test::HasFatalFailure()) {158 if (::testing::Test::HasFatalFailure()) {
156 return false;159 return false;
157 }160 }
158 return true;161 return true;
159 case EndOfStream: {162 case EndOfStream: {
160 int32_t iEndOfStreamFlag = 1;163 int32_t iEndOfStreamFlag = 1;
161 decoder_->SetOption(DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);164 decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
162 DecodeFrame(NULL, 0, cbk);165 DecodeFrame (NULL, 0, cbk);
163 decodeStatus_ = End;166 decodeStatus_ = End;
164 break;167 break;
165 }168 }

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