ref: 71566cdba463610e74e35b2ae9d5fbdc62ced611
dir: /test/api/encoder_test.cpp/
#include <gtest/gtest.h> #include "utils/HashFunctions.h" #include "BaseEncoderTest.h" #include <string> static void UpdateHashFromFrame (const SFrameBSInfo& info, SHA1Context* 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.pNalLengthInByte[j]; } SHA1Input (ctx, layerInfo.pBsBuf, layerSize); } } class EncoderInitTest : public ::testing::Test, public BaseEncoderTest { public: virtual void SetUp() { BaseEncoderTest::SetUp(); } virtual void TearDown() { BaseEncoderTest::TearDown(); } }; TEST_F (EncoderInitTest, JustInit) {} struct EncodeFileParam { const char* pkcFileName; const char* pkcHashStr[2]; EUsageType eUsageType; int iWidth; int iHeight; float fFrameRate; SliceModeEnum eSliceMode; bool bDenoise; int iLayerNum; bool bLossless; bool bEnableLtr; 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].sSliceArgument.uiSliceMode = pEncFileParam->eSliceMode; } } class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>, public EncoderInitTest , public BaseEncoderTest::Callback { public: virtual void SetUp() { EncoderInitTest::SetUp(); if (HasFatalFailure()) { return; } SHA1Reset (&ctx_); } virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) { UpdateHashFromFrame (frameInfo, &ctx_); } protected: SHA1Context ctx_; }; TEST_P (EncoderOutputTest, CompareOutput) { EncodeFileParam p = GetParam(); SEncParamExt EnxParamExt; EncFileParamToParamExt (&p, &EnxParamExt); #if defined(ANDROID_NDK) 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]; SHA1Result (&ctx_, digest); if (!HasFatalFailure()) { CompareHashAnyOf (digest, p.pkcHashStr, sizeof p.pkcHashStr / sizeof *p.pkcHashStr); } } static const EncodeFileParam kFileParamArray[] = { { "res/CiscoVT2people_320x192_12fps.yuv", {"913766b932176ff14943c0581f7c363e4fcb3e7a"}, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/CiscoVT2people_160x96_6fps.yuv", {"cfc6e738acdc3f8a3a6347d1d7a094ec18a95dcc"}, CAMERA_VIDEO_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/Static_152_100.yuv", {"6c735b2de8e40c5d58d104c3d59b816244dcae6f"}, CAMERA_VIDEO_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/CiscoVT2people_320x192_12fps.yuv", {"7cd6bc961433a6f0b3839aa31af0eee4cabf5f1f"}, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_RASTER_SLICE, false, 1, false, false, false // One slice per MB row }, { "res/CiscoVT2people_320x192_12fps.yuv", {"4b916fac735bede22b9596cf7a982913454c9cc4"}, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, true, 1, false, false, false }, { "res/CiscoVT2people_320x192_12fps.yuv", // Allow for different output depending on whether averaging is done // vertically or horizontally first when downsampling. { "8d289f3416db6f493d2ef9da2359a14f90c4af49", "37c5be6e6008823d3f9649ec0074735bcff7f052" }, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 2, false, false, false }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"9467df1227c6ef12e6014a3b340832f424ee1ec3"}, CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", // Allow for different output depending on whether averaging is done // vertically or horizontally first when downsampling. { "fd03be5581079e00541a944f848cfbc3886d3017", "ebcbb383478f5e31f5f8ef804c6e404ed7732664" }, 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 { "res/CiscoVT2people_320x192_12fps.yuv", {"d10ea8f062b4fd1bca401e8265aac061055e358c"}, SCREEN_CONTENT_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/CiscoVT2people_160x96_6fps.yuv", {"ae5114a1a5e32406e97807c454dd89c84d97cda4"}, SCREEN_CONTENT_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/Static_152_100.yuv", {"c02a960a710ad414737e8d879e7706804eeaa0e9"}, SCREEN_CONTENT_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"156d35b56e75a0c90bfcd2d58b652fe56d2d2dcd"}, SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false }, //for different strategy { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"a41b5877870f9e66294dcf58d56afdd2b1ff6aee"}, SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, true, true, false }, { "res/CiscoVT2people_320x192_12fps.yuv", {"dcdcadeb437607b50fc22a47753b9763f0f64796"}, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, true //turn on cabac }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"72d24512497921fdcd7e0330c256c8cea3e45ace"}, CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, true }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"1777abff44723470bb573ea4701cae1938d23ae5"}, CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_FIXEDSLCNUM_SLICE, false, 1, false, false, true }, }; INSTANTIATE_TEST_CASE_P (EncodeFile, EncoderOutputTest, ::testing::ValuesIn (kFileParamArray));