ref: ce80db300c07d85e7a282704a039a31b5533b479
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. { "4001d718054e4f65d64f0a2bd32a99ba2033cd8a", "cd78b0dfee319d4460e9ab1509343ffe59593e45" }, CAMERA_VIDEO_REAL_TIME, 320, 192, 12.0f, SM_SINGLE_SLICE, false, 2, false, false, false }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"c04ff7e9d4317e7881ecd83012e31b073c96e295"}, 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. { "466028ee74639279eac329d5dcfa25f52e93323a", "26675f545566fa9603468fd04990fa7d0c28705e" }, 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", {"774efc987d3d43405500c1d7d47315fa1871e525"}, 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", {"e0367bfda7c1a7ab9a5e6c1661dc5d149c0bad3e"}, 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", {"e7b43e8c8dfd7c90981caec494b0f1beb95fadd7"}, 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", {"a8e429366ee8b591be156ab651c4b4b77dc1dfb4"}, CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, true }, { "res/Cisco_Absolute_Power_1280x720_30fps.yuv", {"3531e331d390a3a45ace24164c1b33a71ea9ba65"}, 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));