sharpness_test.cc (5216B)
1 /* 2 * Copyright (c) 2021, Alliance for Open Media. All rights reserved. 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 #include <unordered_map> 13 14 #include "gtest/gtest.h" 15 16 #include "test/codec_factory.h" 17 #include "test/encode_test_driver.h" 18 #include "test/util.h" 19 #include "test/y4m_video_source.h" 20 21 namespace { 22 const unsigned int kFrames = 10; 23 const int kBitrate = 500; 24 const unsigned int kCqLevel = 18; 25 26 // List of psnr thresholds for different test combinations 27 // keys: test-mode, cpu-used, sharpness. 28 const std::unordered_map< 29 int, std::unordered_map<int, std::unordered_map<int, double>>> 30 kPsnrThreshold = { { static_cast<int>(::libaom_test::kTwoPassGood), 31 { { 2, { { 2, 37.6 }, { 5, 37.6 } } }, 32 { 4, { { 2, 37.5 }, { 5, 37.5 } } }, 33 { 6, { { 2, 37.2 }, { 5, 37.2 } } } } }, 34 { static_cast<int>(::libaom_test::kAllIntra), 35 { { 3, { { 2, 42.2 }, { 5, 42.2 } } }, 36 { 6, { { 2, 41.7 }, { 4, 41.9 }, { 5, 41.9 } } }, 37 { 9, { { 2, 40.6 }, { 5, 40.6 } } } } } }; 38 39 // This class is used to test sharpness parameter configured through control 40 // call using AOME_SET_SHARPNESS for different encoder configurations. 41 class SharpnessTest 42 : public ::libaom_test::CodecTestWith3Params<libaom_test::TestMode, int, 43 int>, 44 public ::libaom_test::EncoderTest { 45 protected: 46 SharpnessTest() 47 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), 48 cpu_used_(GET_PARAM(2)), sharpness_level_(GET_PARAM(3)), psnr_(0.0), 49 nframes_(0) {} 50 51 ~SharpnessTest() override = default; 52 53 void SetUp() override { 54 InitializeConfig(encoding_mode_); 55 if (encoding_mode_ == ::libaom_test::kTwoPassGood) { 56 cfg_.rc_target_bitrate = kBitrate; 57 cfg_.g_lag_in_frames = 5; 58 } 59 } 60 61 void BeginPassHook(unsigned int) override { 62 psnr_ = 0.0; 63 nframes_ = 0; 64 } 65 66 void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override { 67 psnr_ += pkt->data.psnr.psnr[0]; 68 nframes_++; 69 } 70 71 void PreEncodeFrameHook(::libaom_test::VideoSource *video, 72 ::libaom_test::Encoder *encoder) override { 73 if (video->frame() == 0) { 74 encoder->Control(AOME_SET_CPUUSED, cpu_used_); 75 encoder->Control(AOME_SET_SHARPNESS, sharpness_level_); 76 if (encoding_mode_ == ::libaom_test::kTwoPassGood) { 77 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); 78 encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7); 79 encoder->Control(AOME_SET_ARNR_STRENGTH, 5); 80 } else if (encoding_mode_ == ::libaom_test::kAllIntra) { 81 encoder->Control(AOME_SET_CQ_LEVEL, kCqLevel); 82 } 83 } 84 } 85 86 double GetAveragePsnr() const { 87 if (nframes_) return psnr_ / nframes_; 88 return 0.0; 89 } 90 91 double GetPsnrThreshold() { 92 return kPsnrThreshold.at(encoding_mode_).at(cpu_used_).at(sharpness_level_); 93 } 94 95 void DoTest() { 96 init_flags_ = AOM_CODEC_USE_PSNR; 97 98 std::unique_ptr<libaom_test::VideoSource> video( 99 new libaom_test::Y4mVideoSource("paris_352_288_30.y4m", 0, kFrames)); 100 ASSERT_NE(video, nullptr); 101 102 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); 103 const double psnr = GetAveragePsnr(); 104 EXPECT_GT(psnr, GetPsnrThreshold()) 105 << "encoding mode = " << encoding_mode_ << ", cpu used = " << cpu_used_ 106 << ", sharpness level = " << sharpness_level_; 107 } 108 109 private: 110 const libaom_test::TestMode encoding_mode_; 111 const int cpu_used_; 112 const int sharpness_level_; 113 double psnr_; 114 unsigned int nframes_; 115 }; 116 117 class SharpnessTestLarge : public SharpnessTest {}; 118 119 class SharpnessAllIntraTest : public SharpnessTest {}; 120 121 class SharpnessAllIntraTestLarge : public SharpnessTest {}; 122 123 TEST_P(SharpnessTestLarge, SharpnessPSNRTest) { DoTest(); } 124 125 TEST_P(SharpnessAllIntraTest, SharpnessPSNRTest) { DoTest(); } 126 127 TEST_P(SharpnessAllIntraTestLarge, SharpnessPSNRTest) { DoTest(); } 128 129 AV1_INSTANTIATE_TEST_SUITE(SharpnessTestLarge, 130 ::testing::Values(::libaom_test::kTwoPassGood), 131 ::testing::Values(2, 4, 6), // cpu_used 132 ::testing::Values(2, 5)); // sharpness level 133 134 AV1_INSTANTIATE_TEST_SUITE(SharpnessAllIntraTest, 135 ::testing::Values(::libaom_test::kAllIntra), 136 ::testing::Values(6), // cpu_used 137 ::testing::Values(4)); // sharpness level 138 139 AV1_INSTANTIATE_TEST_SUITE(SharpnessAllIntraTestLarge, 140 ::testing::Values(::libaom_test::kAllIntra), 141 ::testing::Values(3, 6, 9), // cpu_used 142 ::testing::Values(2, 5)); // sharpness level 143 } // namespace