Showing the changes to test/BaseEncoderTest.cpp (1 of 10 files). Show all
Unified · Split
| @@ -0,0 +1,79 @@ | ||
| 1 | +#include <fstream> | |
| 2 | +#include <gtest/gtest.h> | |
| 3 | +#include "codec_def.h" | |
| 4 | +#include "utils/BufferedData.h" | |
| 5 | +#include "BaseEncoderTest.h" | |
| 6 | + | |
| 7 | +static int InitWithParam(ISVCEncoder* encoder, int width, | |
| 8 | + int height, float frameRate) { | |
| 9 | + SVCEncodingParam param; | |
| 10 | + memset (¶m, 0, sizeof(SVCEncodingParam)); | |
| 11 | + | |
| 12 | + param.sSpatialLayers[0].iVideoWidth = width; | |
| 13 | + param.sSpatialLayers[0].iVideoHeight = height; | |
| 14 | + param.sSpatialLayers[0].fFrameRate = frameRate; | |
| 15 | + param.sSpatialLayers[0].iQualityLayerNum = 1; | |
| 16 | + param.sSpatialLayers[0].iSpatialBitrate = 600000; | |
| 17 | + | |
| 18 | + SSliceConfig* sliceCfg = ¶m.sSpatialLayers[0].sSliceCfg; | |
| 19 | + sliceCfg->sSliceArgument.uiSliceNum = 1; | |
| 20 | + sliceCfg->sSliceArgument.uiSliceSizeConstraint = 1500; | |
| 21 | + sliceCfg->sSliceArgument.uiSliceMbNum[0] = 960; | |
| 22 | + | |
| 23 | + param.fFrameRate = param.sSpatialLayers[0].fFrameRate; | |
| 24 | + param.iPicWidth = param.sSpatialLayers[0].iVideoWidth; | |
| 25 | + param.iPicHeight = param.sSpatialLayers[0].iVideoHeight; | |
| 26 | + param.iTargetBitrate = 5000000; | |
| 27 | + param.iTemporalLayerNum = 3; | |
| 28 | + param.iSpatialLayerNum = 1; | |
| 29 | + param.bEnableBackgroundDetection = true; | |
| 30 | + param.bEnableLongTermReference = true; | |
| 31 | + param.iLtrMarkPeriod = 30; | |
| 32 | + param.iInputCsp = videoFormatI420; | |
| 33 | + param.bEnableSpsPpsIdAddition = true; | |
| 34 | + | |
| 35 | + return encoder->Initialize(¶m, INIT_TYPE_PARAMETER_BASED); | |
| 36 | +} | |
| 37 | + | |
| 38 | +BaseEncoderTest::BaseEncoderTest() : encoder_(NULL) {} | |
| 39 | + | |
| 40 | +void BaseEncoderTest::SetUp() { | |
| 41 | + int rv = CreateSVCEncoder(&encoder_); | |
| 42 | + ASSERT_EQ(0, rv); | |
| 43 | + ASSERT_TRUE(encoder_ != NULL); | |
| 44 | +} | |
| 45 | + | |
| 46 | +void BaseEncoderTest::TearDown() { | |
| 47 | + if (encoder_) { | |
| 48 | + encoder_->Uninitialize(); | |
| 49 | + DestroySVCEncoder(encoder_); | |
| 50 | + } | |
| 51 | +} | |
| 52 | + | |
| 53 | +void BaseEncoderTest::EncodeFile(const char* fileName, int width, int height, | |
| 54 | + float frameRate, Callback* cbk) { | |
| 55 | + std::ifstream file(fileName, std::ios::in | std::ios::binary); | |
| 56 | + ASSERT_TRUE(file.is_open()); | |
| 57 | + | |
| 58 | + int rv = InitWithParam(encoder_, width, height, frameRate); | |
| 59 | + ASSERT_TRUE(rv == cmResultSuccess); | |
| 60 | + | |
| 61 | + // I420: 1(Y) + 1/4(U) + 1/4(V) | |
| 62 | + int frameSize = width * height * 3 / 2; | |
| 63 | + | |
| 64 | + BufferedData buf; | |
| 65 | + buf.SetLength(frameSize); | |
| 66 | + ASSERT_TRUE(buf.Length() == frameSize); | |
| 67 | + char* data = reinterpret_cast<char*>(buf.data()); | |
| 68 | + | |
| 69 | + SFrameBSInfo info; | |
| 70 | + memset(&info, 0, sizeof(SFrameBSInfo)); | |
| 71 | + | |
| 72 | + while (file.read(data, frameSize), file.gcount() == frameSize) { | |
| 73 | + rv = encoder_->EncodeFrame(buf.data(), &info); | |
| 74 | + ASSERT_TRUE(rv != videoFrameTypeInvalid); | |
| 75 | + if (rv != videoFrameTypeSkip && cbk != NULL) { | |
| 76 | + cbk->onEncodeFrame(info); | |
| 77 | + } | |
| 78 | + } | |
| 79 | +} | |