Add encoder test
This commit is contained in:
parent
cb0053f860
commit
6f58a0c1f7
2
Makefile
2
Makefile
@ -70,7 +70,7 @@ H264ENC_INCLUDES = $(ENCODER_INCLUDES) -Icodec/console/enc/inc
|
|||||||
H264ENC_LDFLAGS = -L. -lencoder -lprocessing -lcommon
|
H264ENC_LDFLAGS = -L. -lencoder -lprocessing -lcommon
|
||||||
H264ENC_DEPS = $(LIBPREFIX)encoder.$(LIBSUFFIX) $(LIBPREFIX)processing.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX)
|
H264ENC_DEPS = $(LIBPREFIX)encoder.$(LIBSUFFIX) $(LIBPREFIX)processing.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX)
|
||||||
|
|
||||||
CODEC_UNITTEST_LDFLAGS = -L. -lgtest -ldecoder -lcommon -lcrypto
|
CODEC_UNITTEST_LDFLAGS = -L. -lgtest -ldecoder -lcrypto -lencoder -lprocessing -lcommon
|
||||||
CODEC_UNITTEST_DEPS = $(LIBPREFIX)gtest.$(LIBSUFFIX) $(LIBPREFIX)decoder.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX)
|
CODEC_UNITTEST_DEPS = $(LIBPREFIX)gtest.$(LIBSUFFIX) $(LIBPREFIX)decoder.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX)
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
1
res/CiscoVT2people_160x96_6fps.yuv
Normal file
1
res/CiscoVT2people_160x96_6fps.yuv
Normal file
File diff suppressed because one or more lines are too long
1
res/CiscoVT2people_320x192_12fps.yuv
Normal file
1
res/CiscoVT2people_320x192_12fps.yuv
Normal file
File diff suppressed because one or more lines are too long
@ -11,17 +11,7 @@
|
|||||||
#include "codec_api.h"
|
#include "codec_api.h"
|
||||||
|
|
||||||
#include "utils/BufferedData.h"
|
#include "utils/BufferedData.h"
|
||||||
|
#include "utils/HashFunctions.h"
|
||||||
static bool CompareHash(unsigned char(&digest)[SHA_DIGEST_LENGTH],
|
|
||||||
const char* hashStr) {
|
|
||||||
|
|
||||||
char hashStrCmp[SHA_DIGEST_LENGTH * 2 + 1];
|
|
||||||
for (int i = 0; i < SHA_DIGEST_LENGTH; ++i) {
|
|
||||||
sprintf(&hashStrCmp[i*2], "%.2x", digest[i]);
|
|
||||||
}
|
|
||||||
hashStrCmp[SHA_DIGEST_LENGTH * 2] = '\0';
|
|
||||||
return strncmp(hashStr, hashStrCmp, SHA_DIGEST_LENGTH * 2) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void UpdateHashFromPlane(SHA_CTX* ctx, const uint8_t* plane,
|
static void UpdateHashFromPlane(SHA_CTX* ctx, const uint8_t* plane,
|
||||||
int width, int height, int stride) {
|
int width, int height, int stride) {
|
||||||
|
151
test/encoder_test.cpp
Normal file
151
test/encoder_test.cpp
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "codec_def.h"
|
||||||
|
#include "codec_app_def.h"
|
||||||
|
#include "codec_api.h"
|
||||||
|
|
||||||
|
#include "utils/BufferedData.h"
|
||||||
|
#include "utils/HashFunctions.h"
|
||||||
|
|
||||||
|
static int InitWithParam(ISVCEncoder* encoder, int width,
|
||||||
|
int height, float frameRate) {
|
||||||
|
SVCEncodingParam param;
|
||||||
|
memset (¶m, 0, sizeof(SVCEncodingParam));
|
||||||
|
|
||||||
|
param.sSpatialLayers[0].iVideoWidth = width;
|
||||||
|
param.sSpatialLayers[0].iVideoHeight = height;
|
||||||
|
param.sSpatialLayers[0].fFrameRate = frameRate;
|
||||||
|
param.sSpatialLayers[0].iQualityLayerNum = 1;
|
||||||
|
param.sSpatialLayers[0].iSpatialBitrate = 600000;
|
||||||
|
|
||||||
|
SSliceConfig* sliceCfg = ¶m.sSpatialLayers[0].sSliceCfg;
|
||||||
|
sliceCfg->sSliceArgument.uiSliceNum = 1;
|
||||||
|
sliceCfg->sSliceArgument.uiSliceSizeConstraint = 1500;
|
||||||
|
sliceCfg->sSliceArgument.uiSliceMbNum[0] = 960;
|
||||||
|
|
||||||
|
param.fFrameRate = param.sSpatialLayers[0].fFrameRate;
|
||||||
|
param.iPicWidth = param.sSpatialLayers[0].iVideoWidth;
|
||||||
|
param.iPicHeight = param.sSpatialLayers[0].iVideoHeight;
|
||||||
|
param.iTargetBitrate = 5000000;
|
||||||
|
param.iTemporalLayerNum = 3;
|
||||||
|
param.iSpatialLayerNum = 1;
|
||||||
|
param.bEnableBackgroundDetection = true;
|
||||||
|
param.bEnableLongTermReference = true;
|
||||||
|
param.iLtrMarkPeriod = 30;
|
||||||
|
param.iInputCsp = videoFormatI420;
|
||||||
|
param.bEnableSpsPpsIdAddition = true;
|
||||||
|
|
||||||
|
return encoder->Initialize(¶m, INIT_TYPE_PARAMETER_BASED);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateHashFromFrame(const SFrameBSInfo& info, SHA_CTX* ctx) {
|
||||||
|
for (int i = 0; i < info.iLayerNum; ++i) {
|
||||||
|
const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
|
||||||
|
int layerSize = 0;
|
||||||
|
for (int j = 0; j < layerInfo.iNalCount; ++j) {
|
||||||
|
layerSize += layerInfo.iNalLengthInByte[j];
|
||||||
|
}
|
||||||
|
SHA1_Update(ctx, layerInfo.pBsBuf, layerSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CompareFileToHash(ISVCEncoder* encoder,
|
||||||
|
const char* fileName, const char* hashStr,
|
||||||
|
int width, int height, float frameRate) {
|
||||||
|
|
||||||
|
std::ifstream file(fileName, std::ios::in | std::ios::binary);
|
||||||
|
ASSERT_TRUE(file.is_open());
|
||||||
|
|
||||||
|
int rv = InitWithParam(encoder, width, height, frameRate);
|
||||||
|
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);
|
||||||
|
char* data = reinterpret_cast<char*>(buf.data());
|
||||||
|
|
||||||
|
SFrameBSInfo info;
|
||||||
|
memset(&info, 0, sizeof(SFrameBSInfo));
|
||||||
|
|
||||||
|
unsigned char digest[SHA_DIGEST_LENGTH];
|
||||||
|
SHA_CTX ctx;
|
||||||
|
SHA1_Init(&ctx);
|
||||||
|
|
||||||
|
while (file.read(data, frameSize), file.gcount() == frameSize) {
|
||||||
|
rv = encoder->EncodeFrame(buf.data(), &info);
|
||||||
|
if (rv == videoFrameTypeInvalid) {
|
||||||
|
SHA1_Final(digest, &ctx);
|
||||||
|
FAIL() << "unable to encode frame";
|
||||||
|
}
|
||||||
|
if (rv != videoFrameTypeSkip) {
|
||||||
|
UpdateHashFromFrame(info, &ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SHA1_Final(digest, &ctx);
|
||||||
|
ASSERT_TRUE(CompareHash(digest, hashStr));
|
||||||
|
}
|
||||||
|
|
||||||
|
class EncoderInitTest : public ::testing::Test {
|
||||||
|
public:
|
||||||
|
EncoderInitTest() : encoder_(NULL) {}
|
||||||
|
|
||||||
|
virtual void SetUp() {
|
||||||
|
int rv = CreateSVCEncoder(&encoder_);
|
||||||
|
ASSERT_EQ(0, rv);
|
||||||
|
ASSERT_TRUE(encoder_ != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void TearDown() {
|
||||||
|
if (encoder_ != NULL) {
|
||||||
|
encoder_->Uninitialize();
|
||||||
|
DestroySVCEncoder(encoder_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ISVCEncoder* encoder_;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(EncoderInitTest, JustInit) {
|
||||||
|
}
|
||||||
|
|
||||||
|
struct EncodeFileParam {
|
||||||
|
const char* fileName;
|
||||||
|
const char* hashStr;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
float frameRate;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EncoderOutputTest : public EncoderInitTest ,
|
||||||
|
public ::testing::WithParamInterface<EncodeFileParam> {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
TEST_P(EncoderOutputTest, CompareOutput) {
|
||||||
|
EncodeFileParam p = GetParam();
|
||||||
|
CompareFileToHash(encoder_, p.fileName, p.hashStr, p.width, p.height, p.frameRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const EncodeFileParam kFileParamArray[] = {
|
||||||
|
{
|
||||||
|
"res/CiscoVT2people_320x192_12fps.yuv",
|
||||||
|
"4df5751a59eb02153e086ade9b3ecfcb8845c30b", 320, 192, 12.0f
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"res/CiscoVT2people_160x96_6fps.yuv",
|
||||||
|
"6eb53b6bfdb95dfca0575bd3efe81aa58163951c", 160, 96, 6.0f
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(EncodeFile, EncoderOutputTest,
|
||||||
|
::testing::ValuesIn(kFileParamArray));
|
15
test/utils/HashFunctions.h
Normal file
15
test/utils/HashFunctions.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef __HASHFUNCTIONS_H__
|
||||||
|
#define __HASHFUNCTIONS_H__
|
||||||
|
|
||||||
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
|
static bool CompareHash(const unsigned char* digest, const char* hashStr) {
|
||||||
|
char hashStrCmp[SHA_DIGEST_LENGTH * 2 + 1];
|
||||||
|
for (int i = 0; i < SHA_DIGEST_LENGTH; ++i) {
|
||||||
|
sprintf(&hashStrCmp[i*2], "%.2x", digest[i]);
|
||||||
|
}
|
||||||
|
hashStrCmp[SHA_DIGEST_LENGTH * 2] = '\0';
|
||||||
|
return strncmp(hashStr, hashStrCmp, SHA_DIGEST_LENGTH * 2) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //__HASHFUNCTIONS_H__
|
Loading…
x
Reference in New Issue
Block a user