2014-01-14 08:48:20 +01:00
|
|
|
#include <fstream>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "codec_def.h"
|
|
|
|
#include "utils/BufferedData.h"
|
2014-01-18 12:31:54 +01:00
|
|
|
#include "utils/FileInputStream.h"
|
2014-01-14 08:48:20 +01:00
|
|
|
#include "BaseEncoderTest.h"
|
|
|
|
|
|
|
|
static int InitWithParam(ISVCEncoder* encoder, int width,
|
2014-03-14 18:01:37 +01:00
|
|
|
int height, float frameRate, SliceModeEnum sliceMode, bool denoise, int deblock, int layers) {
|
|
|
|
if (SM_SINGLE_SLICE == sliceMode && !denoise && deblock == 1 && layers == 1) {
|
2014-03-03 09:59:16 +01:00
|
|
|
SEncParamBase param;
|
|
|
|
memset (¶m, 0, sizeof(SEncParamBase));
|
|
|
|
|
|
|
|
param.fMaxFrameRate = frameRate;
|
|
|
|
param.iPicWidth = width;
|
|
|
|
param.iPicHeight = height;
|
|
|
|
param.iTargetBitrate = 5000000;
|
|
|
|
param.iInputCsp = videoFormatI420;
|
|
|
|
|
|
|
|
return encoder->Initialize(¶m);
|
|
|
|
} else {
|
|
|
|
SEncParamExt param;
|
|
|
|
encoder->GetDefaultParams(¶m);
|
|
|
|
|
|
|
|
param.fMaxFrameRate = frameRate;
|
|
|
|
param.iPicWidth = width;
|
|
|
|
param.iPicHeight = height;
|
|
|
|
param.iTargetBitrate = 5000000;
|
|
|
|
param.iInputCsp = videoFormatI420;
|
2014-03-14 17:40:40 +01:00
|
|
|
param.bEnableDenoise = denoise;
|
|
|
|
param.iLoopFilterDisableIdc = deblock;
|
2014-03-14 18:01:37 +01:00
|
|
|
param.iSpatialLayerNum = layers;
|
2014-03-03 09:59:16 +01:00
|
|
|
|
2014-03-14 18:01:37 +01:00
|
|
|
for (int i = 0; i < param.iSpatialLayerNum; i++) {
|
|
|
|
param.sSpatialLayers[i].iVideoWidth = width >> (param.iSpatialLayerNum - 1 - i);
|
|
|
|
param.sSpatialLayers[i].iVideoHeight = height >> (param.iSpatialLayerNum - 1 - i);
|
|
|
|
param.sSpatialLayers[i].fFrameRate = frameRate;
|
|
|
|
param.sSpatialLayers[i].iSpatialBitrate = param.iTargetBitrate;
|
2014-03-03 09:59:16 +01:00
|
|
|
|
2014-03-14 18:01:37 +01:00
|
|
|
param.sSpatialLayers[i].sSliceCfg.uiSliceMode = sliceMode;
|
|
|
|
}
|
2014-03-03 09:59:16 +01:00
|
|
|
|
|
|
|
return encoder->InitializeExt(¶m);
|
|
|
|
}
|
2014-01-14 08:48:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BaseEncoderTest::BaseEncoderTest() : encoder_(NULL) {}
|
|
|
|
|
|
|
|
void BaseEncoderTest::SetUp() {
|
|
|
|
int rv = CreateSVCEncoder(&encoder_);
|
|
|
|
ASSERT_EQ(0, rv);
|
|
|
|
ASSERT_TRUE(encoder_ != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseEncoderTest::TearDown() {
|
|
|
|
if (encoder_) {
|
|
|
|
encoder_->Uninitialize();
|
|
|
|
DestroySVCEncoder(encoder_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-18 12:31:54 +01:00
|
|
|
void BaseEncoderTest::EncodeStream(InputStream* in, int width, int height,
|
2014-03-14 18:01:37 +01:00
|
|
|
float frameRate, SliceModeEnum slices, bool denoise, int deblock, int layers, Callback* cbk) {
|
|
|
|
int rv = InitWithParam(encoder_, width, height, frameRate, slices, denoise, deblock, layers);
|
2014-01-14 08:48:20 +01:00
|
|
|
ASSERT_TRUE(rv == cmResultSuccess);
|
|
|
|
|
|
|
|
// I420: 1(Y) + 1/4(U) + 1/4(V)
|
|
|
|
int frameSize = width * height * 3 / 2;
|
|
|
|
|
|
|
|
BufferedData buf;
|
|
|
|
buf.SetLength(frameSize);
|
|
|
|
ASSERT_TRUE(buf.Length() == frameSize);
|
|
|
|
|
|
|
|
SFrameBSInfo info;
|
|
|
|
memset(&info, 0, sizeof(SFrameBSInfo));
|
|
|
|
|
2014-02-20 03:33:07 +01:00
|
|
|
SSourcePicture pic;
|
|
|
|
memset(&pic,0,sizeof(SSourcePicture));
|
|
|
|
pic.iPicWidth = width;
|
|
|
|
pic.iPicHeight = height;
|
|
|
|
pic.iColorFormat = videoFormatI420;
|
|
|
|
pic.iStride[0] = pic.iPicWidth;
|
|
|
|
pic.iStride[1] = pic.iStride[2] = pic.iPicWidth>>1;
|
|
|
|
pic.pData[0] = buf.data();
|
|
|
|
pic.pData[1] = pic.pData[0] + width *height;
|
|
|
|
pic.pData[2] = pic.pData[1] + (width*height>>2);
|
2014-01-18 12:31:54 +01:00
|
|
|
while (in->read(buf.data(), frameSize) == frameSize) {
|
2014-02-20 03:33:07 +01:00
|
|
|
rv = encoder_->EncodeFrame(&pic, &info);
|
2014-03-17 04:56:19 +01:00
|
|
|
ASSERT_TRUE(rv == cmResultSuccess);
|
|
|
|
if (info.eOutputFrameType != videoFrameTypeSkip && cbk != NULL) {
|
2014-01-14 08:48:20 +01:00
|
|
|
cbk->onEncodeFrame(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-18 12:31:54 +01:00
|
|
|
|
|
|
|
void BaseEncoderTest::EncodeFile(const char* fileName, int width, int height,
|
2014-03-14 18:01:37 +01:00
|
|
|
float frameRate, SliceModeEnum slices, bool denoise, int deblock, int layers, Callback* cbk) {
|
2014-01-18 12:31:54 +01:00
|
|
|
FileInputStream fileStream;
|
|
|
|
ASSERT_TRUE(fileStream.Open(fileName));
|
2014-03-14 18:01:37 +01:00
|
|
|
EncodeStream(&fileStream, width, height, frameRate, slices, denoise, deblock, layers, cbk);
|
2014-01-18 12:31:54 +01:00
|
|
|
}
|