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/decode_encode_test.cpp (1 of 10 files). Show all

Unified · Split

test/decode_encode_test.cpp+108−0
@@ -0,0 +1,108 @@
1#include <cstdio>
2#include <gtest/gtest.h>
3#include "codec_def.h"
4#include "utils/HashFunctions.h"
5#include "BaseDecoderTest.h"
6#include "BaseEncoderTest.h"
7
8static void UpdateHashFromFrame(const SFrameBSInfo& info, SHA_CTX* ctx) {
9 for (int i = 0; i < info.iLayerNum; ++i) {
10 const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
11 int layerSize = 0;
12 for (int j = 0; j < layerInfo.iNalCount; ++j) {
13 layerSize += layerInfo.iNalLengthInByte[j];
14 }
15 SHA1_Update(ctx, layerInfo.pBsBuf, layerSize);
16 }
17}
18
19static void WritePlaneToFile(FILE* file, const uint8_t* plane,
20 int width, int height, int stride) {
21 for (int i = 0; i < height; i++) {
22 fwrite(plane, 1, width, file);
23 plane += stride;
24 }
25}
26
27struct DecodeEncodeFileParam {
28 const char* fileName;
29 const char* hashStr;
30 int width;
31 int height;
32 float frameRate;
33};
34
35class DecodeEncodeTest : public ::testing::TestWithParam<DecodeEncodeFileParam>,
36 public BaseDecoderTest, public BaseDecoderTest::Callback,
37 public BaseEncoderTest , public BaseEncoderTest::Callback {
38 public:
39 DecodeEncodeTest() : tmpFileName_(NULL), tmpFile_(NULL) {}
40
41 virtual void SetUp() {
42 BaseDecoderTest::SetUp();
43 if (HasFatalFailure()) {
44 return;
45 }
46 BaseEncoderTest::SetUp();
47 if (HasFatalFailure()) {
48 return;
49 }
50
51 tmpFileName_ = tmpnam(NULL);
52 tmpFile_ = fopen(tmpFileName_, "wb");
53 ASSERT_TRUE(tmpFile_ != NULL);
54
55 SHA1_Init(&ctx_);
56 }
57
58 virtual void TearDown() {
59 if (tmpFile_ != NULL) {
60 fclose(tmpFile_);
61 remove(tmpFileName_);
62 }
63 BaseDecoderTest::TearDown();
64 BaseEncoderTest::TearDown();
65 }
66
67 virtual void onDecodeFrame(const Frame& frame) {
68 const Plane& y = frame.y;
69 const Plane& u = frame.u;
70 const Plane& v = frame.v;
71 WritePlaneToFile(tmpFile_, y.data, y.width, y.height, y.stride);
72 WritePlaneToFile(tmpFile_, u.data, u.width, u.height, u.stride);
73 WritePlaneToFile(tmpFile_, v.data, v.width, v.height, v.stride);
74 }
75
76 virtual void onEncodeFrame(const SFrameBSInfo& frameInfo) {
77 UpdateHashFromFrame(frameInfo, &ctx_);
78 }
79
80 protected:
81 SHA_CTX ctx_;
82 const char* tmpFileName_;
83 FILE* tmpFile_;
84};
85
86TEST_P(DecodeEncodeTest, CompareOutput) {
87 DecodeEncodeFileParam p = GetParam();
88
89 DecodeFile(p.fileName, this);
90 if (HasFatalFailure()) {
91 return;
92 }
93
94 EncodeFile(tmpFileName_, p.width, p.height, p.frameRate, this);
95 unsigned char digest[SHA_DIGEST_LENGTH];
96 SHA1_Final(digest, &ctx_);
97 if (!HasFatalFailure()) {
98 ASSERT_TRUE(CompareHash(digest, p.hashStr));
99 }
100}
101
102static const DecodeEncodeFileParam kFileParamArray[] = {
103 {"res/test_vd_1d.264", "c17a760c3bc5d8682aae7f49dddebd2593071711", 320, 192, 12.0f},
104 {"res/test_vd_rc.264", "41e3e90f159fade7a89a4540c4fb9f8ac8f4d7da", 320, 192, 12.0f},
105};
106
107INSTANTIATE_TEST_CASE_P(DecodeEncodeFile, DecodeEncodeTest,
108 ::testing::ValuesIn(kFileParamArray));

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