• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019, 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 <memory>
13 
14 #include "third_party/googletest/src/googletest/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 #include "test/yuv_video_source.h"
21 
22 namespace {
23 
24 const unsigned int kFrames = 10;
25 const int kBitrate = 500;
26 
27 // List of psnr thresholds for speed settings 0-8
28 const double kPsnrThreshold[9] = { 36.9, 36.9, 36.85, 36.8, 36.6,
29                                    36.4, 36.0, 35.5,  35.0 };
30 
31 typedef struct {
32   const char *filename;
33   unsigned int input_bit_depth;
34   aom_img_fmt fmt;
35   aom_bit_depth_t bit_depth;
36   unsigned int profile;
37 } TestVideoParam;
38 
operator <<(std::ostream & os,const TestVideoParam & test_arg)39 std::ostream &operator<<(std::ostream &os, const TestVideoParam &test_arg) {
40   return os << "TestVideoParam { filename:" << test_arg.filename
41             << " input_bit_depth:" << test_arg.input_bit_depth
42             << " fmt:" << test_arg.fmt << " bit_depth:" << test_arg.bit_depth
43             << " profile:" << test_arg.profile << "}";
44 }
45 
46 // TODO(kyslov): Add more test vectors
47 const TestVideoParam kTestVectors[] = {
48   { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
49 };
50 
51 // Speed settings tested
52 const int kCpuUsedVectors[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
53 
54 class RTEndToEndTest
55     : public ::libaom_test::CodecTestWith2Params<TestVideoParam, int>,
56       public ::libaom_test::EncoderTest {
57  protected:
RTEndToEndTest()58   RTEndToEndTest()
59       : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
60         cpu_used_(GET_PARAM(2)), psnr_(0.0), nframes_(0) {}
61 
~RTEndToEndTest()62   virtual ~RTEndToEndTest() {}
63 
SetUp()64   virtual void SetUp() {
65     InitializeConfig();
66     SetMode(::libaom_test::kRealTime);
67 
68     cfg_.g_usage = 1;  // TODO(kyslov): Move it to encode_test_driver.cc
69     cfg_.rc_end_usage = AOM_CBR;
70     cfg_.rc_buf_sz = 1000;
71     cfg_.rc_buf_initial_sz = 500;
72     cfg_.rc_buf_optimal_sz = 600;
73   }
74 
BeginPassHook(unsigned int)75   virtual void BeginPassHook(unsigned int) {
76     psnr_ = 0.0;
77     nframes_ = 0;
78   }
79 
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)80   virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
81     psnr_ += pkt->data.psnr.psnr[0];
82     nframes_++;
83   }
84 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)85   virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
86                                   ::libaom_test::Encoder *encoder) {
87     if (video->frame() == 0) {
88       encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
89       encoder->Control(AV1E_SET_TILE_COLUMNS, 1);
90       encoder->Control(AOME_SET_CPUUSED, cpu_used_);
91       encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
92     }
93   }
94 
GetAveragePsnr() const95   double GetAveragePsnr() const {
96     if (nframes_) return psnr_ / nframes_;
97     return 0.0;
98   }
99 
GetPsnrThreshold()100   double GetPsnrThreshold() { return kPsnrThreshold[cpu_used_]; }
101 
DoTest()102   void DoTest() {
103     cfg_.rc_target_bitrate = kBitrate;
104     cfg_.g_error_resilient = 0;
105     cfg_.g_profile = test_video_param_.profile;
106     cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
107     cfg_.g_bit_depth = test_video_param_.bit_depth;
108     init_flags_ = AOM_CODEC_USE_PSNR;
109     if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
110 
111     std::unique_ptr<libaom_test::VideoSource> video;
112     video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
113                                                 kFrames));
114     ASSERT_TRUE(video.get() != NULL);
115 
116     ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
117     const double psnr = GetAveragePsnr();
118     EXPECT_GT(psnr, GetPsnrThreshold()) << "cpu used = " << cpu_used_;
119   }
120 
121   TestVideoParam test_video_param_;
122   int cpu_used_;
123 
124  private:
125   double psnr_;
126   unsigned int nframes_;
127 };
128 
129 class RTEndToEndTestLarge : public RTEndToEndTest {};
130 
TEST_P(RTEndToEndTestLarge,EndtoEndPSNRTest)131 TEST_P(RTEndToEndTestLarge, EndtoEndPSNRTest) { DoTest(); }
132 
TEST_P(RTEndToEndTest,EndtoEndPSNRTest)133 TEST_P(RTEndToEndTest, EndtoEndPSNRTest) { DoTest(); }
134 
135 AV1_INSTANTIATE_TEST_CASE(RTEndToEndTestLarge,
136                           ::testing::ValuesIn(kTestVectors),
137                           ::testing::ValuesIn(kCpuUsedVectors));
138 
139 AV1_INSTANTIATE_TEST_CASE(RTEndToEndTest, ::testing::Values(kTestVectors[0]),
140                           ::testing::Values(kCpuUsedVectors[8]));
141 }  // namespace
142