ref: 1a6c396330c3d7162470ed42b3850ff5e97e8f89
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", {"eb6cd4d17368be148de36af04d419c4c8cdb238f"}, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/CiscoVT2people_160x96_6fps.yuv", {"4e6e6dd3c9ef9c9f2ea19c90006b7e1561c2554f"}, CAMERA_VIDEO_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/Static_152_100.yuv", {"9b1eea9e9c4d58b02644a3b9d6cac32ad7174ce8"}, CAMERA_VIDEO_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/CiscoVT2people_320x192_12fps.yuv", {"b608de962bd4eb127f96fe91cb4a15435aff35c8"}, 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", {"8d2ed78f0ebb54fece701403675dcd36e9222fc2"}, 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. { "24177466a3433d73f0110e72ee0fcaf731e80e88", "1867a20126d80ae8d4812bd5a9cc172945e4785a" }, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 2, false, false, false }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"ce0cbb3d13af5b6e0932ae6393415700d751b374"}, 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. { "093eac26331dc016cef1ea22214904d32344ad76", "e1d01d767e2c9f3b0fb761e1572539121a2d13b9" }, 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", {"21eb4a21bb6b2974ffe078b00a574c6f7269e5eb"}, SCREEN_CONTENT_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/CiscoVT2people_160x96_6fps.yuv", {"962fe7aca514e409106b517149cbd332b9784ed3"}, SCREEN_CONTENT_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/Static_152_100.yuv", {"e69b7dc98c5c0934700517ef79e8377f3f683998"}, SCREEN_CONTENT_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"8bb3041ef447a9171ee0f016b64908119804bd31"}, 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", {"e62d5f1cce92633203bf65984089f471b530652b"}, SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, true, true, false }, { "res/CiscoVT2people_320x192_12fps.yuv", {"f006aa3569829d8ebebdd4a8a1f7cd6d31628a45"}, 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", {"08e03852d6354a5b852f3c350dd5a844ffc60b33"}, CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, true }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"752aa204be96efbf5f838e35164fa5341a464420"}, 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));