History

reorganize tests

Licai Guo committed 12 years ago

Commit f26bb571 parent 667bfe223 files · +68 −43Browse files

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

Unified · Split

test/api/BaseEncoderTest.cpp+101−0
@@ -0,0 +1,101 @@
1#include <fstream>
2#include <gtest/gtest.h>
3#include "codec_def.h"
4#include "utils/BufferedData.h"
5#include "utils/FileInputStream.h"
6#include "BaseEncoderTest.h"
7
8static int InitWithParam(ISVCEncoder* encoder, int width,
9 int height, float frameRate, SliceModeEnum sliceMode, bool denoise, int deblock, int layers) {
10 if (SM_SINGLE_SLICE == sliceMode && !denoise && deblock == 1 && layers == 1) {
11 SEncParamBase param;
12 memset (&param, 0, sizeof(SEncParamBase));
13
14 param.fMaxFrameRate = frameRate;
15 param.iPicWidth = width;
16 param.iPicHeight = height;
17 param.iTargetBitrate = 5000000;
18 param.iInputCsp = videoFormatI420;
19
20 return encoder->Initialize(&param);
21 } else {
22 SEncParamExt param;
23 encoder->GetDefaultParams(&param);
24
25 param.fMaxFrameRate = frameRate;
26 param.iPicWidth = width;
27 param.iPicHeight = height;
28 param.iTargetBitrate = 5000000;
29 param.iInputCsp = videoFormatI420;
30 param.bEnableDenoise = denoise;
31 param.iLoopFilterDisableIdc = deblock;
32 param.iSpatialLayerNum = layers;
33
34 for (int i = 0; i < param.iSpatialLayerNum; i++) {
35 param.sSpatialLayers[i].iVideoWidth = width >> (param.iSpatialLayerNum - 1 - i);
36 param.sSpatialLayers[i].iVideoHeight = height >> (param.iSpatialLayerNum - 1 - i);
37 param.sSpatialLayers[i].fFrameRate = frameRate;
38 param.sSpatialLayers[i].iSpatialBitrate = param.iTargetBitrate;
39
40 param.sSpatialLayers[i].sSliceCfg.uiSliceMode = sliceMode;
41 }
42
43 return encoder->InitializeExt(&param);
44 }
45}
46
47BaseEncoderTest::BaseEncoderTest() : encoder_(NULL) {}
48
49void BaseEncoderTest::SetUp() {
50 int rv = CreateSVCEncoder(&encoder_);
51 ASSERT_EQ(0, rv);
52 ASSERT_TRUE(encoder_ != NULL);
53}
54
55void BaseEncoderTest::TearDown() {
56 if (encoder_) {
57 encoder_->Uninitialize();
58 DestroySVCEncoder(encoder_);
59 }
60}
61
62void BaseEncoderTest::EncodeStream(InputStream* in, int width, int height,
63 float frameRate, SliceModeEnum slices, bool denoise, int deblock, int layers, Callback* cbk) {
64 int rv = InitWithParam(encoder_, width, height, frameRate, slices, denoise, deblock, layers);
65 ASSERT_TRUE(rv == cmResultSuccess);
66
67 // I420: 1(Y) + 1/4(U) + 1/4(V)
68 int frameSize = width * height * 3 / 2;
69
70 BufferedData buf;
71 buf.SetLength(frameSize);
72 ASSERT_TRUE(buf.Length() == frameSize);
73
74 SFrameBSInfo info;
75 memset(&info, 0, sizeof(SFrameBSInfo));
76
77 SSourcePicture pic;
78 memset(&pic,0,sizeof(SSourcePicture));
79 pic.iPicWidth = width;
80 pic.iPicHeight = height;
81 pic.iColorFormat = videoFormatI420;
82 pic.iStride[0] = pic.iPicWidth;
83 pic.iStride[1] = pic.iStride[2] = pic.iPicWidth>>1;
84 pic.pData[0] = buf.data();
85 pic.pData[1] = pic.pData[0] + width *height;
86 pic.pData[2] = pic.pData[1] + (width*height>>2);
87 while (in->read(buf.data(), frameSize) == frameSize) {
88 rv = encoder_->EncodeFrame(&pic, &info);
89 ASSERT_TRUE(rv == cmResultSuccess);
90 if (info.eOutputFrameType != videoFrameTypeSkip && cbk != NULL) {
91 cbk->onEncodeFrame(info);
92 }
93 }
94}
95
96void BaseEncoderTest::EncodeFile(const char* fileName, int width, int height,
97 float frameRate, SliceModeEnum slices, bool denoise, int deblock, int layers, Callback* cbk) {
98 FileInputStream fileStream;
99 ASSERT_TRUE(fileStream.Open(fileName));
100 EncodeStream(&fileStream, width, height, frameRate, slices, denoise, deblock, layers, cbk);
101}

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