openh264/test/api/encoder_test.cpp

174 lines
6.2 KiB
C++
Raw Normal View History

2014-01-07 10:23:44 +08:00
#include <gtest/gtest.h>
#include "utils/HashFunctions.h"
#include "BaseEncoderTest.h"
#include <string>
2014-10-29 13:50:18 +08:00
2014-06-25 18:50:41 -07:00
static void UpdateHashFromFrame (const SFrameBSInfo& info, SHA1Context* ctx) {
2014-01-07 10:23:44 +08: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.pNalLengthInByte[j];
2014-01-07 10:23:44 +08:00
}
2014-06-25 18:50:41 -07:00
SHA1Input (ctx, layerInfo.pBsBuf, layerSize);
2014-01-07 10:23:44 +08:00
}
}
class EncoderInitTest : public ::testing::Test, public BaseEncoderTest {
2014-01-08 11:42:58 +08:00
public:
2014-01-07 10:23:44 +08:00
virtual void SetUp() {
BaseEncoderTest::SetUp();
2014-01-07 10:23:44 +08:00
}
virtual void TearDown() {
BaseEncoderTest::TearDown();
2014-01-07 10:23:44 +08:00
}
};
2014-06-25 18:50:41 -07:00
TEST_F (EncoderInitTest, JustInit) {}
2014-01-07 10:23:44 +08:00
struct EncodeFileParam {
2014-10-29 13:50:18 +08:00
const char* pkcFileName;
const char* pkcHashStr;
EUsageType eUsageType;
int iWidth;
int iHeight;
float fFrameRate;
SliceModeEnum eSliceMode;
bool bDenoise;
int iLayerNum;
bool bLossless;
bool bEnableLtr;
bool bCabac;
// unsigned short iMultipleThreadIdc;
2014-01-07 10:23:44 +08:00
};
2014-10-29 13:50:18 +08:00
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].sSliceArgument.uiSliceMode = pEncFileParam->eSliceMode;
2014-10-29 13:50:18 +08:00
}
}
class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>,
2014-06-25 18:50:41 -07:00
public EncoderInitTest , public BaseEncoderTest::Callback {
public:
virtual void SetUp() {
EncoderInitTest::SetUp();
if (HasFatalFailure()) {
return;
}
2014-06-25 18:50:41 -07:00
SHA1Reset (&ctx_);
}
2014-06-25 18:50:41 -07:00
virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) {
UpdateHashFromFrame (frameInfo, &ctx_);
}
2014-10-29 13:50:18 +08:00
protected:
SHA1Context ctx_;
2014-01-07 10:23:44 +08:00
};
2014-06-25 18:50:41 -07:00
TEST_P (EncoderOutputTest, CompareOutput) {
2014-01-07 10:23:44 +08:00
EncodeFileParam p = GetParam();
2014-10-29 13:50:18 +08:00
SEncParamExt EnxParamExt;
EncFileParamToParamExt (&p, &EnxParamExt);
#if defined(ANDROID_NDK)
2014-10-29 13:50:18 +08:00
std::string filename = std::string ("/sdcard/") + p.pkcFileName;
EncodeFile (p.pkcFileName, &EnxParamExt, this);
#else
EncodeFile (p.pkcFileName, &EnxParamExt, this);
#endif
//will remove this after screen content algorithms are ready,
//because the bitstream output will vary when the different algorithms are added.
unsigned char digest[SHA_DIGEST_LENGTH];
2014-06-25 18:50:41 -07:00
SHA1Result (&ctx_, digest);
if (!HasFatalFailure()) {
2014-10-29 13:50:18 +08:00
CompareHash (digest, p.pkcHashStr);
}
2014-01-07 10:23:44 +08:00
}
static const EncodeFileParam kFileParamArray[] = {
{
2014-06-25 18:50:41 -07:00
"res/CiscoVT2people_320x192_12fps.yuv",
2015-11-13 17:16:26 +08:00
"ee97bab09041362fbe8aed16f69a55f16b106f92", CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false
2014-01-07 10:23:44 +08:00
},
{
2014-06-25 18:50:41 -07:00
"res/CiscoVT2people_160x96_6fps.yuv",
2015-11-13 17:16:26 +08:00
"37b4f5b7b77b362dee9a74ac4b2bc043537f2dd0", CAMERA_VIDEO_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false
2014-01-07 10:23:44 +08:00
},
{
2014-06-25 18:50:41 -07:00
"res/Static_152_100.yuv",
2015-11-13 17:16:26 +08:00
"b220be0163974e36fbd6662236d4e05566a21546", CAMERA_VIDEO_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false
},
{
2014-06-25 18:50:41 -07:00
"res/CiscoVT2people_320x192_12fps.yuv",
"21dbfaaf4f09af735298434c1f97cf95a464165b", CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_RASTER_SLICE, false, 1, false, false, false // One slice per MB row
},
{
2014-06-25 18:50:41 -07:00
"res/CiscoVT2people_320x192_12fps.yuv",
2015-11-13 17:16:26 +08:00
"409ced068a5a313cad7c654d27ab7a2edaed4630", CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, true, 1, false, false, false
},
{
2014-06-25 18:50:41 -07:00
"res/CiscoVT2people_320x192_12fps.yuv",
2015-11-13 17:16:26 +08:00
"73156dfc1dc45924349b5b79f8debcac13d7231d", CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 2, false, false, false
},
2014-05-22 19:39:43 +08:00
{
2014-06-25 18:50:41 -07:00
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"84f97cff898055aaf96a303960abb76e12bf24c1", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false
2014-05-22 19:39:43 +08:00
},
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"3943145545a2bd27a642b2045d4e3dbae55c6870", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SINGLE_SLICE, false, 4, false, false, false
},
// the following values may be adjusted for times since we start tuning the strategy
{
2014-06-25 18:50:41 -07:00
"res/CiscoVT2people_320x192_12fps.yuv",
2015-11-13 17:16:26 +08:00
"c384a0dafc46573d02a38d8323304c5e1309d9d0", SCREEN_CONTENT_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false
},
{
2014-06-25 18:50:41 -07:00
"res/CiscoVT2people_160x96_6fps.yuv",
2015-11-13 17:16:26 +08:00
"637d50652f9bb8750359c4b418f30a039908d56d", SCREEN_CONTENT_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false
},
{
2014-06-25 18:50:41 -07:00
"res/Static_152_100.yuv",
2015-11-13 17:16:26 +08:00
"77a140c6bd80a6479ee13aecd2a8dac0a17cf03d", SCREEN_CONTENT_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false
},
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"8027935ed347671cb2a181d09cd4380ce2c0da79", SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false
2014-09-19 14:46:02 +08:00
},
//for different strategy
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"0e1af98bd978e602cc15329ba70a2c4c2afe8016", SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, true, true, false
2014-10-27 13:06:33 +08:00
},
{
"res/CiscoVT2people_320x192_12fps.yuv",
2015-11-13 17:16:26 +08:00
"a0c97ec484e8a8cca8868c893e38a5a7312a70a8", CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, true //turn on cabac
2014-10-27 13:06:33 +08:00
},
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"c87ff55413efb14d95acd1de3be02bd601fcc3df", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, true
},
2015-11-23 11:54:43 -08:00
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"fbc231e3ec66b426561bc80b902106fc4b5d2ccb", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_FIXEDSLCNUM_SLICE, false, 1, false, false, true
},
2014-01-07 10:23:44 +08:00
};
2014-06-25 18:50:41 -07:00
INSTANTIATE_TEST_CASE_P (EncodeFile, EncoderOutputTest,
::testing::ValuesIn (kFileParamArray));