History

enable api test for decoder VclNal

huili2 committed 12 years ago

Commit f82726d1 parent 49f8fe84 files · +185 −13Browse files

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

Unified · Split

test/api/encode_decode_api_test.cpp+131−0
@@ -0,0 +1,131 @@
1#include <gtest/gtest.h>
2#include "codec_def.h"
3#include "utils/BufferedData.h"
4#include "utils/FileInputStream.h"
5#include "BaseDecoderTest.h"
6#include "BaseEncoderTest.h"
7#include <string>
8
9struct EncodeDecodeFileParamBase {
10 const char* fileName;
11 int width;
12 int height;
13 float frameRate;
14};
15
16class EncodeDecodeTestBase : public ::testing::Test,
17 public BaseEncoderTest, public BaseDecoderTest {
18 public:
19 virtual void SetUp() {
20 BaseEncoderTest::SetUp();
21 BaseDecoderTest::SetUp();
22 }
23
24 virtual void TearDown() {
25 BaseEncoderTest::TearDown();
26 BaseDecoderTest::TearDown();
27 }
28
29 virtual void prepareParam (int width, int height, float framerate) {
30 memset (&param_, 0, sizeof (SEncParamExt));
31 param_.iUsageType = CAMERA_VIDEO_REAL_TIME;
32 param_.iPicWidth = width;
33 param_.iPicHeight = height;
34 param_.fMaxFrameRate = framerate;
35 param_.iRCMode = RC_OFF_MODE; //rc off
36 param_.iMultipleThreadIdc = 1; //single thread
37 param_.sSpatialLayers[0].iVideoWidth = width;
38 param_.sSpatialLayers[0].iVideoHeight = height;
39 param_.sSpatialLayers[0].fFrameRate = framerate;
40 param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
41 }
42
43 virtual void encToDecData (const SFrameBSInfo& info, int& len) {
44 len = 0;
45 for (int i = 0; i < info.iLayerNum; ++i) {
46 const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
47 for (int j = 0; j < layerInfo.iNalCount; ++j) {
48 len += layerInfo.pNalLengthInByte[j];
49 }
50 }
51 }
52
53 protected:
54 SEncParamExt param_;
55 BufferedData buf_;
56 SBufferInfo dstBufInfo_;
57};
58
59class EncodeDecodeTestVclNal : public EncodeDecodeTestBase {
60 public:
61 void SetUp() {
62 EncodeDecodeTestBase::SetUp();
63 }
64
65 void TearDown() {
66 EncodeDecodeTestBase::TearDown();
67 }
68
69 void prepareParam (int width, int height, float framerate) {
70 EncodeDecodeTestBase::prepareParam (width, height, framerate);
71 }
72};
73
74static const EncodeDecodeFileParamBase kFileParamArray =
75{"res/CiscoVT2people_160x96_6fps.yuv", 160, 96, 6.0f};
76
77TEST_F (EncodeDecodeTestVclNal, DecoderVclNal) {
78 EncodeDecodeFileParamBase p = kFileParamArray;
79 FileInputStream fileStream;
80#if defined(ANDROID_NDK)
81 std::string filename = std::string ("/sdcard/") + p.fileName;
82 ASSERT_TRUE (fileStream.Open (filename.c_str()));
83#else
84 ASSERT_TRUE (fileStream.Open (p.fileName));
85#endif
86
87 prepareParam (p.width, p.height, p.frameRate);
88 int rv = encoder_->InitializeExt (&param_);
89 ASSERT_TRUE (rv == cmResultSuccess);
90
91 //init for encoder
92 // I420: 1(Y) + 1/4(U) + 1/4(V)
93 int frameSize = p.width * p.height * 3 / 2;
94
95 buf_.SetLength (frameSize);
96 ASSERT_TRUE (buf_.Length() == (size_t)frameSize);
97
98 SFrameBSInfo info;
99 memset (&info, 0, sizeof (SFrameBSInfo));
100
101 SSourcePicture pic;
102 memset (&pic, 0, sizeof (SSourcePicture));
103 pic.iPicWidth = p.width;
104 pic.iPicHeight = p.height;
105 pic.iColorFormat = videoFormatI420;
106 pic.iStride[0] = pic.iPicWidth;
107 pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
108 pic.pData[0] = buf_.data();
109 pic.pData[1] = pic.pData[0] + p.width * p.height;
110 pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2);
111 while (fileStream.read (buf_.data(), frameSize) == frameSize) {
112 rv = encoder_->EncodeFrame (&pic, &info);
113 ASSERT_TRUE (rv == cmResultSuccess);
114 //decoding after each encoding frame
115 int vclNal, len = 0;
116 encToDecData (info, len);
117 unsigned char* pData[3] = { NULL };
118 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
119 rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
120 ASSERT_TRUE (rv == cmResultSuccess);
121 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);
122 EXPECT_EQ (vclNal, FEEDBACK_UNKNOWN_NAL); //no reconstruction, unknown return
123 rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
124 ASSERT_TRUE (rv == cmResultSuccess);
125 rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);
126 EXPECT_EQ (vclNal, FEEDBACK_VCL_NAL);
127
128 } //while
129 //ignore last frame
130}
131

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