History

refactor and add decode_encode_test to pipeline decoder outoput to encoder test

jwwang committed 12 years ago

Commit 8247eef1 parent db6ce9c10 files · +443 −247Browse files

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

Unified · Split

test/BaseDecoderTest.cpp+128−0
@@ -0,0 +1,128 @@
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->Push(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() : decoder_(NULL) {}
47+
48+void BaseDecoderTest::SetUp() {
49+ long rv = CreateDecoder(&decoder_);
50+ ASSERT_EQ(0, rv);
51+ ASSERT_TRUE(decoder_ != NULL);
52+
53+ SDecodingParam decParam;
54+ memset(&decParam, 0, sizeof(SDecodingParam));
55+ decParam.iOutputColorFormat = videoFormatI420;
56+ decParam.uiTargetDqLayer = UCHAR_MAX;
57+ decParam.uiEcActiveFlag = 1;
58+ decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
59+
60+ rv = decoder_->Initialize(&decParam, INIT_TYPE_PARAMETER_BASED);
61+ ASSERT_EQ(0, rv);
62+}
63+
64+void BaseDecoderTest::TearDown() {
65+ if (decoder_ != NULL) {
66+ decoder_->Uninitialize();
67+ DestroyDecoder(decoder_);
68+ }
69+}
70+
71+
72+void BaseDecoderTest::DecodeFrame(const uint8_t* src, int sliceSize, Callback* cbk) {
73+ void* data[3];
74+ SBufferInfo bufInfo;
75+ memset(data, 0, sizeof(data));
76+ memset(&bufInfo, 0, sizeof(SBufferInfo));
77+
78+ DECODING_STATE rv = decoder_->DecodeFrame(src, sliceSize, data, &bufInfo);
79+ ASSERT_TRUE(rv == dsErrorFree);
80+
81+ if (bufInfo.iBufferStatus == 1 && cbk != NULL) {
82+ const Frame frame = {
83+ { // y plane
84+ static_cast<uint8_t*>(data[0]),
85+ bufInfo.UsrData.sSystemBuffer.iWidth,
86+ bufInfo.UsrData.sSystemBuffer.iHeight,
87+ bufInfo.UsrData.sSystemBuffer.iStride[0]
88+ },
89+ { // u plane
90+ static_cast<uint8_t*>(data[1]),
91+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
92+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
93+ bufInfo.UsrData.sSystemBuffer.iStride[1]
94+ },
95+ { // v plane
96+ static_cast<uint8_t*>(data[2]),
97+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
98+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
99+ bufInfo.UsrData.sSystemBuffer.iStride[1]
100+ },
101+ };
102+ cbk->onDecodeFrame(frame);
103+ }
104+}
105+void BaseDecoderTest::DecodeFile(const char* fileName, Callback* cbk) {
106+ std::ifstream file(fileName, std::ios::in | std::ios::binary);
107+ ASSERT_TRUE(file.is_open());
108+
109+ for (BufferedData buf;;) {
110+ ReadFrame(&file, &buf);
111+ if (::testing::Test::HasFatalFailure()) {
112+ return;
113+ }
114+ if (buf.Length() == 0) {
115+ break;
116+ }
117+ DecodeFrame(buf.data(), buf.Length(), cbk);
118+ if (::testing::Test::HasFatalFailure()) {
119+ return;
120+ }
121+ }
122+
123+ int32_t iEndOfStreamFlag = 1;
124+ decoder_->SetOption(DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
125+
126+ // Get pending last frame
127+ DecodeFrame(NULL, 0, cbk);
128+}

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