Showing the changes to test/encoder/EncUT_EncoderExt.cpp (1 of 8 files). Show all
Unified · Split
| @@ -661,3 +661,83 @@ TEST_F (EncoderInterfaceTest, EncodeParameterSets) { · 660 unmodified lines | ||
| 661 | 661 | TEST_F (EncoderInterfaceTest, BasicReturnTypeTest) { |
| 662 | 662 | //TODO |
| 663 | 663 | } |
| 664 | + | |
| 665 | +TEST_F (EncoderInterfaceTest, GetStatistics) { | |
| 666 | + SEncParamBase sEncParamBase; | |
| 667 | + GetValidEncParamBase (&sEncParamBase); | |
| 668 | + | |
| 669 | + int iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 670 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 671 | + if (iResult != cmResultSuccess) { | |
| 672 | + fprintf (stderr, "Unexpected ParamBase? \ | |
| 673 | + iUsageType=%d, Pic=%dx%d, TargetBitrate=%d, iRCMode=%d, fMaxFrameRate=%.1f\n", | |
| 674 | + sEncParamBase.iUsageType, sEncParamBase.iPicWidth, sEncParamBase.iPicHeight, | |
| 675 | + sEncParamBase.iTargetBitrate, sEncParamBase.iRCMode, sEncParamBase.fMaxFrameRate); | |
| 676 | + } | |
| 677 | + | |
| 678 | + PrepareOneSrcFrame(); | |
| 679 | + EncodeOneIDRandP (pPtrEnc); | |
| 680 | + | |
| 681 | + SEncoderStatistics sEncoderStatistics; | |
| 682 | + iResult = pPtrEnc->GetOption (ENCODER_OPTION_GET_STATISTICS, &sEncoderStatistics); | |
| 683 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 684 | + EXPECT_EQ (sEncoderStatistics.uiInputFrameCount, 2); | |
| 685 | + EXPECT_EQ (sEncoderStatistics.uIDRSentNum, 1); | |
| 686 | + EXPECT_EQ (sEncoderStatistics.uiResolutionChangeTimes, 0); | |
| 687 | + | |
| 688 | + EXPECT_EQ (sEncoderStatistics.uWidth, sEncParamBase.iPicWidth); | |
| 689 | + EXPECT_EQ (sEncoderStatistics.uHeight, sEncParamBase.iPicHeight); | |
| 690 | + | |
| 691 | + // try param change | |
| 692 | + // 1, get the existing | |
| 693 | + pPtrEnc->GetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, pParamExt); | |
| 694 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 695 | + | |
| 696 | + // 2, change the reoslution | |
| 697 | + GetValidEncParamBase (&sEncParamBase); | |
| 698 | + int32_t knownResolutionChangeTimes = 0; | |
| 699 | + if (pParamExt->iPicWidth != sEncParamBase.iPicWidth || pParamExt->iPicHeight != sEncParamBase.iPicHeight) { | |
| 700 | + knownResolutionChangeTimes = 1; | |
| 701 | + } | |
| 702 | + pParamExt->iPicWidth = pParamExt->sSpatialLayers[0].iVideoWidth = sEncParamBase.iPicWidth; | |
| 703 | + pParamExt->iPicHeight = pParamExt->sSpatialLayers[0].iVideoHeight = sEncParamBase.iPicHeight; | |
| 704 | + pPtrEnc->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, pParamExt); | |
| 705 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 706 | + | |
| 707 | + // 3, code one frame | |
| 708 | + PrepareOneSrcFrame(); | |
| 709 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 710 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 711 | + iResult = pPtrEnc->GetOption (ENCODER_OPTION_GET_STATISTICS, &sEncoderStatistics); | |
| 712 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 713 | + | |
| 714 | + EXPECT_EQ (sEncoderStatistics.uiInputFrameCount, 3); | |
| 715 | + EXPECT_EQ (sEncoderStatistics.uIDRSentNum, 2); | |
| 716 | + EXPECT_EQ (sEncoderStatistics.uiResolutionChangeTimes, knownResolutionChangeTimes); | |
| 717 | + | |
| 718 | + EXPECT_EQ (sEncoderStatistics.uWidth, sEncParamBase.iPicWidth); | |
| 719 | + EXPECT_EQ (sEncoderStatistics.uHeight, sEncParamBase.iPicHeight); | |
| 720 | + | |
| 721 | + // 4, change log interval | |
| 722 | + int32_t iInterval = 0; | |
| 723 | + iResult = pPtrEnc->GetOption (ENCODER_OPTION_STATISTICS_LOG_INTERVAL, &iInterval); | |
| 724 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 725 | + EXPECT_EQ (iInterval, 5000); | |
| 726 | + | |
| 727 | + int32_t iInterval2 = 2000; | |
| 728 | + iResult = pPtrEnc->SetOption (ENCODER_OPTION_STATISTICS_LOG_INTERVAL, &iInterval2); | |
| 729 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 730 | + iResult = pPtrEnc->GetOption (ENCODER_OPTION_STATISTICS_LOG_INTERVAL, &iInterval); | |
| 731 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 732 | + EXPECT_EQ (iInterval, iInterval2); | |
| 733 | + | |
| 734 | + iInterval2 = 0; | |
| 735 | + iResult = pPtrEnc->SetOption (ENCODER_OPTION_STATISTICS_LOG_INTERVAL, &iInterval2); | |
| 736 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 737 | + iResult = pPtrEnc->GetOption (ENCODER_OPTION_STATISTICS_LOG_INTERVAL, &iInterval); | |
| 738 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 739 | + EXPECT_EQ (iInterval, iInterval2); | |
| 740 | + | |
| 741 | + // finish | |
| 742 | + pPtrEnc->Uninitialize(); | |
| 743 | +} | |