2014-01-07 03:23:44 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "utils/HashFunctions.h"
|
2014-01-14 08:48:20 +01:00
|
|
|
#include "BaseEncoderTest.h"
|
2014-01-07 03:23:44 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-14 08:48:20 +01:00
|
|
|
class EncoderInitTest : public ::testing::Test, public BaseEncoderTest {
|
2014-01-08 04:42:58 +01:00
|
|
|
public:
|
2014-01-07 03:23:44 +01:00
|
|
|
virtual void SetUp() {
|
2014-01-14 08:48:20 +01:00
|
|
|
BaseEncoderTest::SetUp();
|
2014-01-07 03:23:44 +01:00
|
|
|
}
|
|
|
|
virtual void TearDown() {
|
2014-01-14 08:48:20 +01:00
|
|
|
BaseEncoderTest::TearDown();
|
2014-01-07 03:23:44 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-14 08:48:20 +01:00
|
|
|
TEST_F(EncoderInitTest, JustInit) {}
|
2014-01-07 03:23:44 +01:00
|
|
|
|
|
|
|
struct EncodeFileParam {
|
|
|
|
const char* fileName;
|
|
|
|
const char* hashStr;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
float frameRate;
|
|
|
|
};
|
|
|
|
|
2014-01-14 08:48:20 +01:00
|
|
|
class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>,
|
|
|
|
public EncoderInitTest , public BaseEncoderTest::Callback {
|
|
|
|
public:
|
|
|
|
virtual void SetUp() {
|
|
|
|
EncoderInitTest::SetUp();
|
|
|
|
if (HasFatalFailure()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SHA1_Init(&ctx_);
|
|
|
|
}
|
|
|
|
virtual void onEncodeFrame(const SFrameBSInfo& frameInfo) {
|
|
|
|
UpdateHashFromFrame(frameInfo, &ctx_);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
SHA_CTX ctx_;
|
2014-01-07 03:23:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(EncoderOutputTest, CompareOutput) {
|
|
|
|
EncodeFileParam p = GetParam();
|
2014-01-14 08:48:20 +01:00
|
|
|
EncodeFile(p.fileName, p.width, p.height, p.frameRate, this);
|
|
|
|
|
|
|
|
unsigned char digest[SHA_DIGEST_LENGTH];
|
|
|
|
SHA1_Final(digest, &ctx_);
|
|
|
|
if (!HasFatalFailure()) {
|
|
|
|
ASSERT_TRUE(CompareHash(digest, p.hashStr));
|
|
|
|
}
|
2014-01-07 03:23:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const EncodeFileParam kFileParamArray[] = {
|
|
|
|
{
|
|
|
|
"res/CiscoVT2people_320x192_12fps.yuv",
|
|
|
|
"4df5751a59eb02153e086ade9b3ecfcb8845c30b", 320, 192, 12.0f
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"res/CiscoVT2people_160x96_6fps.yuv",
|
|
|
|
"6eb53b6bfdb95dfca0575bd3efe81aa58163951c", 160, 96, 6.0f
|
|
|
|
},
|
2014-01-12 14:55:37 +01:00
|
|
|
{
|
|
|
|
"res/Static_152_100.yuv",
|
|
|
|
"c5af55647a5ead570bd5d96651e05ea699762b8e", 152, 100, 6.0f
|
|
|
|
},
|
2014-01-07 03:23:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(EncodeFile, EncoderOutputTest,
|
|
|
|
::testing::ValuesIn(kFileParamArray));
|