2014-01-14 08:48:20 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "codec_def.h"
|
|
|
|
#include "utils/HashFunctions.h"
|
2014-01-18 12:31:54 +01:00
|
|
|
#include "utils/BufferedData.h"
|
|
|
|
#include "utils/InputStream.h"
|
2014-01-14 08:48:20 +01:00
|
|
|
#include "BaseDecoderTest.h"
|
|
|
|
#include "BaseEncoderTest.h"
|
|
|
|
|
2014-01-17 09:43:26 +01:00
|
|
|
static void UpdateHashFromFrame(const SFrameBSInfo& info, SHA1Context* ctx) {
|
2014-01-14 08:48:20 +01:00
|
|
|
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];
|
|
|
|
}
|
2014-01-17 09:43:26 +01:00
|
|
|
SHA1Input(ctx, layerInfo.pBsBuf, layerSize);
|
2014-01-14 08:48:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-18 12:31:54 +01:00
|
|
|
static void WritePlaneBuffer(BufferedData* buf, const uint8_t* plane,
|
2014-01-14 08:48:20 +01:00
|
|
|
int width, int height, int stride) {
|
|
|
|
for (int i = 0; i < height; i++) {
|
2014-02-05 11:04:32 +01:00
|
|
|
if (!buf->PushBack(plane, width)) {
|
2014-01-18 12:31:54 +01:00
|
|
|
FAIL() << "unable to allocate memory";
|
|
|
|
}
|
2014-01-14 08:48:20 +01:00
|
|
|
plane += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DecodeEncodeFileParam {
|
|
|
|
const char* fileName;
|
|
|
|
const char* hashStr;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
float frameRate;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DecodeEncodeTest : public ::testing::TestWithParam<DecodeEncodeFileParam>,
|
|
|
|
public BaseDecoderTest, public BaseDecoderTest::Callback,
|
2014-01-18 12:31:54 +01:00
|
|
|
public BaseEncoderTest , public BaseEncoderTest::Callback,
|
|
|
|
public InputStream {
|
2014-01-14 08:48:20 +01:00
|
|
|
public:
|
|
|
|
virtual void SetUp() {
|
|
|
|
BaseDecoderTest::SetUp();
|
|
|
|
if (HasFatalFailure()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BaseEncoderTest::SetUp();
|
|
|
|
if (HasFatalFailure()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-01-17 09:43:26 +01:00
|
|
|
SHA1Reset(&ctx_);
|
2014-01-14 08:48:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
|
|
|
BaseDecoderTest::TearDown();
|
|
|
|
BaseEncoderTest::TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDecodeFrame(const Frame& frame) {
|
|
|
|
const Plane& y = frame.y;
|
|
|
|
const Plane& u = frame.u;
|
|
|
|
const Plane& v = frame.v;
|
2014-01-18 12:31:54 +01:00
|
|
|
WritePlaneBuffer(&buf_, y.data, y.width, y.height, y.stride);
|
|
|
|
WritePlaneBuffer(&buf_, u.data, u.width, u.height, u.stride);
|
|
|
|
WritePlaneBuffer(&buf_, v.data, v.width, v.height, v.stride);
|
2014-01-14 08:48:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onEncodeFrame(const SFrameBSInfo& frameInfo) {
|
|
|
|
UpdateHashFromFrame(frameInfo, &ctx_);
|
|
|
|
}
|
|
|
|
|
2014-01-18 12:31:54 +01:00
|
|
|
virtual int read(void* ptr, size_t len) {
|
|
|
|
while (buf_.Length() < len) {
|
|
|
|
bool hasNext = DecodeNextFrame(this);
|
|
|
|
if (HasFatalFailure()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!hasNext) {
|
|
|
|
if (buf_.Length() == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-05 11:04:32 +01:00
|
|
|
return buf_.PopFront(static_cast<uint8_t*>(ptr), len);
|
2014-01-18 12:31:54 +01:00
|
|
|
}
|
|
|
|
|
2014-01-14 08:48:20 +01:00
|
|
|
protected:
|
2014-01-17 09:43:26 +01:00
|
|
|
SHA1Context ctx_;
|
2014-01-18 12:31:54 +01:00
|
|
|
BufferedData buf_;
|
2014-01-14 08:48:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(DecodeEncodeTest, CompareOutput) {
|
|
|
|
DecodeEncodeFileParam p = GetParam();
|
|
|
|
|
2014-01-18 12:31:54 +01:00
|
|
|
ASSERT_TRUE(Open(p.fileName));
|
2014-03-10 09:57:19 +01:00
|
|
|
EncodeStream(this, p.width, p.height, p.frameRate, SM_SINGLE_SLICE, this);
|
2014-01-14 08:48:20 +01:00
|
|
|
unsigned char digest[SHA_DIGEST_LENGTH];
|
2014-01-17 09:43:26 +01:00
|
|
|
SHA1Result(&ctx_, digest);
|
2014-01-14 08:48:20 +01:00
|
|
|
if (!HasFatalFailure()) {
|
2014-03-03 09:45:03 +01:00
|
|
|
CompareHash(digest, p.hashStr);
|
2014-01-14 08:48:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const DecodeEncodeFileParam kFileParamArray[] = {
|
2014-02-18 02:32:05 +01:00
|
|
|
{"res/test_vd_1d.264", "c04a5978eb715837c29463e79b6598a05136829f", 320, 192, 12.0f},
|
|
|
|
{"res/test_vd_rc.264", "40d8eb5a54d358c663f836c689a158c326de4b1c", 320, 192, 12.0f},
|
2014-01-14 08:48:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(DecodeEncodeFile, DecodeEncodeTest,
|
|
|
|
::testing::ValuesIn(kFileParamArray));
|