ref: 52808550d8003f014df9814bc2ad504105a83675
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; 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].sSliceCfg.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()) { CompareHash (digest, p.pkcHashStr); } } static const EncodeFileParam kFileParamArray[] = { { "res/CiscoVT2people_320x192_12fps.yuv", "a3ad18c9973a0bb540d2faff5a6a20ba2afc8595", CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/CiscoVT2people_160x96_6fps.yuv", "522b18bbd733f193ab8ad6b9ee1020e5ea9c236f", CAMERA_VIDEO_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/Static_152_100.yuv", "923daa2b2437830e4afceef183842b71bb637a58", CAMERA_VIDEO_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/CiscoVT2people_320x192_12fps.yuv", "ca20a1a47b8c865e740570d7e43ef2c11b51eafb", CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_ROWMB_SLICE, false, 1, false, false, false // One slice per MB row }, { "res/CiscoVT2people_320x192_12fps.yuv", "c6c5c92b6c7d12a4a21701994d024f8c77c6a8a5", CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, true, 1, false, false, false }, { "res/CiscoVT2people_320x192_12fps.yuv", "a51aeb5313b24c75e05a96655066f6b2e19b6552", CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 2, false, false, false }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", "b25c942962e588395630ca9be1480221075f3e34", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_DYN_SLICE, false, 1, false, false, false }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", "9f6f4a819b4a304b491be74f349cb5b226e2b5ab", 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", "48f2a03d23541cc05056425374a74c63759f76c5", SCREEN_CONTENT_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/CiscoVT2people_160x96_6fps.yuv", "b98d33e3fc68fafd8d86ec22b23870ba1e5cf926", SCREEN_CONTENT_REAL_TIME, 160, 96, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/Static_152_100.yuv", "dc054763d3a4280e75c4864eba5004ca643202b5", SCREEN_CONTENT_REAL_TIME, 152, 100, 6.0f, SM_SINGLE_SLICE, false, 1, false, false, false }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", "46e2ea054fd1f48c9d803affa5e08c69bcf38eac", SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_DYN_SLICE, false, 1, false, false, false }, //for different strategy { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", "de239bc36915c6441dd4f4bf66d0474e4c520348", SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_DYN_SLICE, false, 1, true, true, false }, { "res/CiscoVT2people_320x192_12fps.yuv", "f6f87a961fb3280475d1a5f733200dcaa52111f1", 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", "44e2906594c5987dd24c7423752fe4e11e3d6296", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_DYN_SLICE, false, 1, false, false, true }, }; INSTANTIATE_TEST_CASE_P (EncodeFile, EncoderOutputTest, ::testing::ValuesIn (kFileParamArray));