History

B-frame decoding support for Main and High Profile with two test cases.

xiaotianshi2 committed 8 years ago

Commit 657d2171 parent e3e838355 files · +17936 −13825Browse files

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

Unified · Split

test/api/BaseDecoderTest.cpp+219−177
@@ -1,177 +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::DecodeFile (const char* fileName, Callback* cbk) {112void BaseDecoderTest::FlushFrame (Callback* cbk) {
113 std::ifstream file (fileName, std::ios::in | std::ios::binary);113 uint8_t* data[3];
114 ASSERT_TRUE (file.is_open());114 SBufferInfo bufInfo;
115 115 memset (data, 0, sizeof (data));
116 BufferedData buf;116 memset (&bufInfo, 0, sizeof (SBufferInfo));
117 while (true) {117
118 ReadFrame (&file, &buf);118 DECODING_STATE rv = decoder_->FlushFrame (data, &bufInfo);
119 if (::testing::Test::HasFatalFailure()) {119 ASSERT_TRUE (rv == dsErrorFree);
120 return;120
121 }121 if (bufInfo.iBufferStatus == 1 && cbk != NULL) {
122 if (buf.Length() == 0) {122 const Frame frame = {
123 break;123 {
124 }124 // y plane
125 DecodeFrame (buf.data(), buf.Length(), cbk);125 data[0],
126 if (::testing::Test::HasFatalFailure()) {126 bufInfo.UsrData.sSystemBuffer.iWidth,
127 return;127 bufInfo.UsrData.sSystemBuffer.iHeight,
128 }128 bufInfo.UsrData.sSystemBuffer.iStride[0]
129 }129 },
130 130 {
131 int32_t iEndOfStreamFlag = 1;131 // u plane
132 decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);132 data[1],
133 133 bufInfo.UsrData.sSystemBuffer.iWidth / 2,
134 // Get pending last frame134 bufInfo.UsrData.sSystemBuffer.iHeight / 2,
135 DecodeFrame (NULL, 0, cbk);135 bufInfo.UsrData.sSystemBuffer.iStride[1]
136}136 },
137 137 {
138bool BaseDecoderTest::Open (const char* fileName) {138 // v plane
139 if (decodeStatus_ == OpenFile) {139 data[2],
140 file_.open (fileName, std::ios_base::out | std::ios_base::binary);140 bufInfo.UsrData.sSystemBuffer.iWidth / 2,
141 if (file_.is_open()) {141 bufInfo.UsrData.sSystemBuffer.iHeight / 2,
142 decodeStatus_ = Decoding;142 bufInfo.UsrData.sSystemBuffer.iStride[1]
143 return true;143 },
144 }144 };
145 }145 cbk->onDecodeFrame (frame);
146 return false;146 }
147}147}
148 148void BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) {
149bool BaseDecoderTest::DecodeNextFrame (Callback* cbk) {149 std::ifstream file (fileName, std::ios::in | std::ios::binary);
150 switch (decodeStatus_) {150 ASSERT_TRUE (file.is_open());
151 case Decoding:151
152 ReadFrame (&file_, &buf_);152 BufferedData buf;
153 if (::testing::Test::HasFatalFailure()) {153 while (true) {
154 return false;154 ReadFrame (&file, &buf);
155 }155 if (::testing::Test::HasFatalFailure()) {
156 if (buf_.Length() == 0) {156 return;
157 decodeStatus_ = EndOfStream;157 }
158 return true;158 if (buf.Length() == 0) {
159 }159 break;
160 DecodeFrame (buf_.data(), buf_.Length(), cbk);160 }
161 if (::testing::Test::HasFatalFailure()) {161 DecodeFrame (buf.data(), buf.Length(), cbk);
162 return false;162 if (::testing::Test::HasFatalFailure()) {
163 }163 return;
164 return true;164 }
165 case EndOfStream: {165 }
166 int32_t iEndOfStreamFlag = 1;166
167 decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);167 int32_t iEndOfStreamFlag = 1;
168 DecodeFrame (NULL, 0, cbk);168 decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
169 decodeStatus_ = End;169
170 break;170 // Get pending last frame
171 }171 DecodeFrame (NULL, 0, cbk);
172 case OpenFile:172 // Flush out last frames in decoder buffer
173 case End:173 int32_t num_of_frames_in_buffer = 0;
174 break;174 decoder_->GetOption (DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER, &num_of_frames_in_buffer);
175 }175 for (int32_t i = 0; i < num_of_frames_in_buffer; ++i) {
176 return false;176 FlushFrame (cbk);
177}177 }
178}
179
180bool 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
191bool 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