refactor --for BaseEncoderTest
This commit is contained in:
@@ -14,10 +14,8 @@ class BaseEncoderTest {
|
|||||||
BaseEncoderTest();
|
BaseEncoderTest();
|
||||||
void SetUp();
|
void SetUp();
|
||||||
void TearDown();
|
void TearDown();
|
||||||
void EncodeFile (const char* fileName, EUsageType usageType, int width, int height, float frameRate,
|
void EncodeFile (const char* fileName, SEncParamExt* pEncParamExt, Callback* cbk);
|
||||||
SliceModeEnum slices, bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac, Callback* cbk);
|
void EncodeStream (InputStream* in, SEncParamExt* pEncParamExt, Callback* cbk);
|
||||||
void EncodeStream (InputStream* in, EUsageType usageType, int width, int height, float frameRate, SliceModeEnum slices,
|
|
||||||
bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac, Callback* cbk);
|
|
||||||
|
|
||||||
ISVCEncoder* encoder_;
|
ISVCEncoder* encoder_;
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -5,16 +5,20 @@
|
|||||||
#include "utils/FileInputStream.h"
|
#include "utils/FileInputStream.h"
|
||||||
#include "BaseEncoderTest.h"
|
#include "BaseEncoderTest.h"
|
||||||
|
|
||||||
static int InitWithParam (ISVCEncoder* encoder, EUsageType usageType, int width,
|
static int InitWithParam (ISVCEncoder* encoder, SEncParamExt* pEncParamExt) {
|
||||||
int height, float frameRate, SliceModeEnum sliceMode, bool denoise, int layers, bool losslessLink, bool enableLtr,bool cabac) {
|
|
||||||
if (SM_SINGLE_SLICE == sliceMode && !denoise && layers == 1 && !losslessLink && !enableLtr &&!cabac) {
|
SliceModeEnum eSliceMode = pEncParamExt->sSpatialLayers[0].sSliceCfg.uiSliceMode;
|
||||||
|
bool bBaseParamFlag = (SM_SINGLE_SLICE == eSliceMode && !pEncParamExt->bEnableDenoise
|
||||||
|
&& pEncParamExt->iSpatialLayerNum == 1 && !pEncParamExt->bIsLosslessLink
|
||||||
|
&& !pEncParamExt->bEnableLongTermReference && !pEncParamExt->iEntropyCodingModeFlag) ? true : false;
|
||||||
|
if (bBaseParamFlag) {
|
||||||
SEncParamBase param;
|
SEncParamBase param;
|
||||||
memset (¶m, 0, sizeof (SEncParamBase));
|
memset (¶m, 0, sizeof (SEncParamBase));
|
||||||
|
|
||||||
param.iUsageType = usageType;
|
param.iUsageType = pEncParamExt->iUsageType;
|
||||||
param.fMaxFrameRate = frameRate;
|
param.fMaxFrameRate = pEncParamExt->fMaxFrameRate;
|
||||||
param.iPicWidth = width;
|
param.iPicWidth = pEncParamExt->iPicWidth;
|
||||||
param.iPicHeight = height;
|
param.iPicHeight = pEncParamExt->iPicHeight;
|
||||||
param.iTargetBitrate = 5000000;
|
param.iTargetBitrate = 5000000;
|
||||||
|
|
||||||
return encoder->Initialize (¶m);
|
return encoder->Initialize (¶m);
|
||||||
@@ -22,27 +26,27 @@ static int InitWithParam (ISVCEncoder* encoder, EUsageType usageType, int width,
|
|||||||
SEncParamExt param;
|
SEncParamExt param;
|
||||||
encoder->GetDefaultParams (¶m);
|
encoder->GetDefaultParams (¶m);
|
||||||
|
|
||||||
param.iUsageType = usageType;
|
param.iUsageType = pEncParamExt->iUsageType;
|
||||||
param.fMaxFrameRate = frameRate;
|
param.fMaxFrameRate = pEncParamExt->fMaxFrameRate;
|
||||||
param.iPicWidth = width;
|
param.iPicWidth = pEncParamExt->iPicWidth;
|
||||||
param.iPicHeight = height;
|
param.iPicHeight = pEncParamExt->iPicHeight;
|
||||||
param.iTargetBitrate = 5000000;
|
param.iTargetBitrate = 5000000;
|
||||||
param.bEnableDenoise = denoise;
|
param.bEnableDenoise = pEncParamExt->bEnableDenoise;
|
||||||
param.iSpatialLayerNum = layers;
|
param.iSpatialLayerNum = pEncParamExt->iSpatialLayerNum;
|
||||||
param.bIsLosslessLink = losslessLink;
|
param.bIsLosslessLink = pEncParamExt->bIsLosslessLink;
|
||||||
param.bEnableLongTermReference = enableLtr;
|
param.bEnableLongTermReference = pEncParamExt->bEnableLongTermReference;
|
||||||
param.iEntropyCodingModeFlag = cabac?1:0;
|
param.iEntropyCodingModeFlag = pEncParamExt->iEntropyCodingModeFlag ? 1 : 0;
|
||||||
if (sliceMode != SM_SINGLE_SLICE && sliceMode != SM_DYN_SLICE) //SM_DYN_SLICE don't support multi-thread now
|
if (eSliceMode != SM_SINGLE_SLICE && eSliceMode != SM_DYN_SLICE) //SM_DYN_SLICE don't support multi-thread now
|
||||||
param.iMultipleThreadIdc = 2;
|
param.iMultipleThreadIdc = 2;
|
||||||
|
|
||||||
for (int i = 0; i < param.iSpatialLayerNum; i++) {
|
for (int i = 0; i < param.iSpatialLayerNum; i++) {
|
||||||
param.sSpatialLayers[i].iVideoWidth = width >> (param.iSpatialLayerNum - 1 - i);
|
param.sSpatialLayers[i].iVideoWidth = pEncParamExt->iPicWidth >> (param.iSpatialLayerNum - 1 - i);
|
||||||
param.sSpatialLayers[i].iVideoHeight = height >> (param.iSpatialLayerNum - 1 - i);
|
param.sSpatialLayers[i].iVideoHeight = pEncParamExt->iPicHeight >> (param.iSpatialLayerNum - 1 - i);
|
||||||
param.sSpatialLayers[i].fFrameRate = frameRate;
|
param.sSpatialLayers[i].fFrameRate = pEncParamExt->fMaxFrameRate;
|
||||||
param.sSpatialLayers[i].iSpatialBitrate = param.iTargetBitrate;
|
param.sSpatialLayers[i].iSpatialBitrate = param.iTargetBitrate;
|
||||||
|
|
||||||
param.sSpatialLayers[i].sSliceCfg.uiSliceMode = sliceMode;
|
param.sSpatialLayers[i].sSliceCfg.uiSliceMode = eSliceMode;
|
||||||
if (sliceMode == SM_DYN_SLICE) {
|
if (eSliceMode == SM_DYN_SLICE) {
|
||||||
param.sSpatialLayers[i].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 600;
|
param.sSpatialLayers[i].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 600;
|
||||||
param.uiMaxNalSize = 1500;
|
param.uiMaxNalSize = 1500;
|
||||||
}
|
}
|
||||||
@@ -68,13 +72,15 @@ void BaseEncoderTest::TearDown() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEncoderTest::EncodeStream (InputStream* in, EUsageType usageType, int width, int height,
|
void BaseEncoderTest::EncodeStream (InputStream* in, SEncParamExt* pEncParamExt, Callback* cbk) {
|
||||||
float frameRate, SliceModeEnum slices, bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac,Callback* cbk) {
|
|
||||||
int rv = InitWithParam (encoder_, usageType, width, height, frameRate, slices, denoise, layers, losslessLink, enableLtr,cabac);
|
ASSERT_TRUE (NULL != pEncParamExt);
|
||||||
|
|
||||||
|
int rv = InitWithParam (encoder_, pEncParamExt);
|
||||||
ASSERT_TRUE (rv == cmResultSuccess);
|
ASSERT_TRUE (rv == cmResultSuccess);
|
||||||
|
|
||||||
// I420: 1(Y) + 1/4(U) + 1/4(V)
|
// I420: 1(Y) + 1/4(U) + 1/4(V)
|
||||||
int frameSize = width * height * 3 / 2;
|
int frameSize = pEncParamExt->iPicWidth * pEncParamExt->iPicHeight * 3 / 2;
|
||||||
|
|
||||||
BufferedData buf;
|
BufferedData buf;
|
||||||
buf.SetLength (frameSize);
|
buf.SetLength (frameSize);
|
||||||
@@ -85,14 +91,14 @@ void BaseEncoderTest::EncodeStream (InputStream* in, EUsageType usageType, int w
|
|||||||
|
|
||||||
SSourcePicture pic;
|
SSourcePicture pic;
|
||||||
memset (&pic, 0, sizeof (SSourcePicture));
|
memset (&pic, 0, sizeof (SSourcePicture));
|
||||||
pic.iPicWidth = width;
|
pic.iPicWidth = pEncParamExt->iPicWidth;
|
||||||
pic.iPicHeight = height;
|
pic.iPicHeight = pEncParamExt->iPicHeight;
|
||||||
pic.iColorFormat = videoFormatI420;
|
pic.iColorFormat = videoFormatI420;
|
||||||
pic.iStride[0] = pic.iPicWidth;
|
pic.iStride[0] = pic.iPicWidth;
|
||||||
pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
|
pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
|
||||||
pic.pData[0] = buf.data();
|
pic.pData[0] = buf.data();
|
||||||
pic.pData[1] = pic.pData[0] + width * height;
|
pic.pData[1] = pic.pData[0] + pEncParamExt->iPicWidth * pEncParamExt->iPicHeight;
|
||||||
pic.pData[2] = pic.pData[1] + (width * height >> 2);
|
pic.pData[2] = pic.pData[1] + (pEncParamExt->iPicWidth * pEncParamExt->iPicHeight >> 2);
|
||||||
while (in->read (buf.data(), frameSize) == frameSize) {
|
while (in->read (buf.data(), frameSize) == frameSize) {
|
||||||
rv = encoder_->EncodeFrame (&pic, &info);
|
rv = encoder_->EncodeFrame (&pic, &info);
|
||||||
ASSERT_TRUE (rv == cmResultSuccess);
|
ASSERT_TRUE (rv == cmResultSuccess);
|
||||||
@@ -102,9 +108,9 @@ void BaseEncoderTest::EncodeStream (InputStream* in, EUsageType usageType, int w
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEncoderTest::EncodeFile (const char* fileName, EUsageType usageType, int width, int height,
|
void BaseEncoderTest::EncodeFile (const char* fileName, SEncParamExt* pEncParamExt, Callback* cbk) {
|
||||||
float frameRate, SliceModeEnum slices, bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac,Callback* cbk) {
|
|
||||||
FileInputStream fileStream;
|
FileInputStream fileStream;
|
||||||
ASSERT_TRUE (fileStream.Open (fileName));
|
ASSERT_TRUE (fileStream.Open (fileName));
|
||||||
EncodeStream (&fileStream, usageType, width, height, frameRate, slices, denoise, layers, losslessLink, enableLtr, cabac,cbk);
|
ASSERT_TRUE (NULL != pEncParamExt);
|
||||||
|
EncodeStream (&fileStream, pEncParamExt, cbk);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,15 +91,38 @@ class DecodeEncodeTest : public ::testing::TestWithParam<DecodeEncodeFileParam>,
|
|||||||
BufferedData buf_;
|
BufferedData buf_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void DecEncFileParamToParamExt (DecodeEncodeFileParam * pDecEncFileParam, SEncParamExt* pEnxParamExt) {
|
||||||
|
ASSERT_TRUE (NULL != pDecEncFileParam && NULL != pEnxParamExt);
|
||||||
|
|
||||||
|
pEnxParamExt->iPicWidth = pDecEncFileParam->width;
|
||||||
|
pEnxParamExt->iPicHeight = pDecEncFileParam->height;
|
||||||
|
pEnxParamExt->fMaxFrameRate = pDecEncFileParam->frameRate;
|
||||||
|
|
||||||
|
//default value
|
||||||
|
pEnxParamExt->iUsageType = CAMERA_VIDEO_REAL_TIME;
|
||||||
|
pEnxParamExt->iSpatialLayerNum = 1;
|
||||||
|
pEnxParamExt->bEnableDenoise = false;
|
||||||
|
pEnxParamExt->bIsLosslessLink = false;
|
||||||
|
pEnxParamExt->bEnableLongTermReference = false;
|
||||||
|
pEnxParamExt->iEntropyCodingModeFlag = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < pEnxParamExt->iSpatialLayerNum; i++) {
|
||||||
|
pEnxParamExt->sSpatialLayers[i].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
TEST_P (DecodeEncodeTest, CompareOutput) {
|
TEST_P (DecodeEncodeTest, CompareOutput) {
|
||||||
DecodeEncodeFileParam p = GetParam();
|
DecodeEncodeFileParam p = GetParam();
|
||||||
|
SEncParamExt EnxParamExt;
|
||||||
|
DecEncFileParamToParamExt(&p,&EnxParamExt);
|
||||||
|
|
||||||
#if defined(ANDROID_NDK)
|
#if defined(ANDROID_NDK)
|
||||||
std::string filename = std::string ("/sdcard/") + p.fileName;
|
std::string filename = std::string ("/sdcard/") + p.fileName;
|
||||||
ASSERT_TRUE (Open (filename.c_str()));
|
ASSERT_TRUE (Open (filename.c_str()));
|
||||||
#else
|
#else
|
||||||
ASSERT_TRUE (Open (p.fileName));
|
ASSERT_TRUE (Open (p.fileName));
|
||||||
#endif
|
#endif
|
||||||
EncodeStream (this, CAMERA_VIDEO_REAL_TIME, p.width, p.height, p.frameRate, SM_SINGLE_SLICE, false, 1, false, false,false, this);
|
EncodeStream (this, &EnxParamExt, this);
|
||||||
unsigned char digest[SHA_DIGEST_LENGTH];
|
unsigned char digest[SHA_DIGEST_LENGTH];
|
||||||
SHA1Result (&ctx_, digest);
|
SHA1Result (&ctx_, digest);
|
||||||
if (!HasFatalFailure()) {
|
if (!HasFatalFailure()) {
|
||||||
|
|||||||
@@ -2003,7 +2003,6 @@ TEST_F (EncodeDecodeTestAPI, SetOptionEncParamExt) {
|
|||||||
ASSERT_TRUE (rv == cmResultSuccess);
|
ASSERT_TRUE (rv == cmResultSuccess);
|
||||||
|
|
||||||
for (int i = 0; i < iEncFrameNum; i++) {
|
for (int i = 0; i < iEncFrameNum; i++) {
|
||||||
//for (int i = 0; i < 9; i++) {
|
|
||||||
int iResult;
|
int iResult;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
unsigned char* pData[3] = { NULL };
|
unsigned char* pData[3] = { NULL };
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "utils/HashFunctions.h"
|
#include "utils/HashFunctions.h"
|
||||||
#include "BaseEncoderTest.h"
|
#include "BaseEncoderTest.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
static void UpdateHashFromFrame (const SFrameBSInfo& info, SHA1Context* ctx) {
|
static void UpdateHashFromFrame (const SFrameBSInfo& info, SHA1Context* ctx) {
|
||||||
for (int i = 0; i < info.iLayerNum; ++i) {
|
for (int i = 0; i < info.iLayerNum; ++i) {
|
||||||
const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
|
const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
|
||||||
@@ -26,20 +27,40 @@ class EncoderInitTest : public ::testing::Test, public BaseEncoderTest {
|
|||||||
TEST_F (EncoderInitTest, JustInit) {}
|
TEST_F (EncoderInitTest, JustInit) {}
|
||||||
|
|
||||||
struct EncodeFileParam {
|
struct EncodeFileParam {
|
||||||
const char* fileName;
|
const char* pkcFileName;
|
||||||
const char* hashStr;
|
const char* pkcHashStr;
|
||||||
EUsageType usageType;
|
EUsageType eUsageType;
|
||||||
int width;
|
int iWidth;
|
||||||
int height;
|
int iHeight;
|
||||||
float frameRate;
|
float fFrameRate;
|
||||||
SliceModeEnum slices;
|
SliceModeEnum eSliceMode;
|
||||||
bool denoise;
|
bool bDenoise;
|
||||||
int layers;
|
int iLayerNum;
|
||||||
bool isLossless;
|
bool bLossless;
|
||||||
bool enableLtr;
|
bool bEnableLtr;
|
||||||
bool cabac;
|
bool bCabac;
|
||||||
|
// unsigned short iMultipleThreadIdc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void EncFileParamToParamExt (EncodeFileParam* pEncFileParam, SEncParamExt* pEnxParamExt) {
|
||||||
|
ASSERT_TRUE (NULL != pEncFileParam && NULL != pEnxParamExt);
|
||||||
|
pEnxParamExt->iUsageType = pEncFileParam->eUsageType;
|
||||||
|
pEnxParamExt->iPicWidth = pEncFileParam->iWidth;
|
||||||
|
pEnxParamExt->iPicHeight = pEncFileParam->iHeight;
|
||||||
|
pEnxParamExt->fMaxFrameRate = pEncFileParam->fFrameRate;
|
||||||
|
pEnxParamExt->iSpatialLayerNum = pEncFileParam->iLayerNum;
|
||||||
|
|
||||||
|
pEnxParamExt->bEnableDenoise = pEncFileParam->bDenoise;
|
||||||
|
pEnxParamExt->bIsLosslessLink = pEncFileParam->bLossless;
|
||||||
|
pEnxParamExt->bEnableLongTermReference = pEncFileParam->bEnableLtr;
|
||||||
|
pEnxParamExt->iEntropyCodingModeFlag = pEncFileParam->bCabac ? 1 : 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < pEnxParamExt->iSpatialLayerNum; i++) {
|
||||||
|
pEnxParamExt->sSpatialLayers[i].sSliceCfg.uiSliceMode = pEncFileParam->eSliceMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>,
|
class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>,
|
||||||
public EncoderInitTest , public BaseEncoderTest::Callback {
|
public EncoderInitTest , public BaseEncoderTest::Callback {
|
||||||
public:
|
public:
|
||||||
@@ -53,6 +74,7 @@ class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>,
|
|||||||
virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) {
|
virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) {
|
||||||
UpdateHashFromFrame (frameInfo, &ctx_);
|
UpdateHashFromFrame (frameInfo, &ctx_);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SHA1Context ctx_;
|
SHA1Context ctx_;
|
||||||
};
|
};
|
||||||
@@ -60,20 +82,22 @@ class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>,
|
|||||||
|
|
||||||
TEST_P (EncoderOutputTest, CompareOutput) {
|
TEST_P (EncoderOutputTest, CompareOutput) {
|
||||||
EncodeFileParam p = GetParam();
|
EncodeFileParam p = GetParam();
|
||||||
|
SEncParamExt EnxParamExt;
|
||||||
|
|
||||||
|
EncFileParamToParamExt (&p, &EnxParamExt);
|
||||||
|
|
||||||
#if defined(ANDROID_NDK)
|
#if defined(ANDROID_NDK)
|
||||||
std::string filename = std::string ("/sdcard/") + p.fileName;
|
std::string filename = std::string ("/sdcard/") + p.pkcFileName;
|
||||||
EncodeFile (filename.c_str(), p.usageType , p.width, p.height, p.frameRate, p.slices, p.denoise, p.layers, p.isLossless,
|
EncodeFile (p.pkcFileName, &EnxParamExt, this);
|
||||||
p.enableLtr,p.cabac, this);
|
|
||||||
#else
|
#else
|
||||||
EncodeFile (p.fileName, p.usageType , p.width, p.height, p.frameRate, p.slices, p.denoise, p.layers, p.isLossless,
|
EncodeFile (p.pkcFileName, &EnxParamExt, this);
|
||||||
p.enableLtr, p.cabac, this);
|
|
||||||
#endif
|
#endif
|
||||||
//will remove this after screen content algorithms are ready,
|
//will remove this after screen content algorithms are ready,
|
||||||
//because the bitstream output will vary when the different algorithms are added.
|
//because the bitstream output will vary when the different algorithms are added.
|
||||||
unsigned char digest[SHA_DIGEST_LENGTH];
|
unsigned char digest[SHA_DIGEST_LENGTH];
|
||||||
SHA1Result (&ctx_, digest);
|
SHA1Result (&ctx_, digest);
|
||||||
if (!HasFatalFailure()) {
|
if (!HasFatalFailure()) {
|
||||||
CompareHash (digest, p.hashStr);
|
CompareHash (digest, p.pkcHashStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static const EncodeFileParam kFileParamArray[] = {
|
static const EncodeFileParam kFileParamArray[] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user