• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022, 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 #include <ostream>
14 
15 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
16 
17 #include "test/codec_factory.h"
18 #include "test/encode_test_driver.h"
19 #include "test/util.h"
20 #include "test/y4m_video_source.h"
21 #include "test/yuv_video_source.h"
22 
23 namespace {
24 
25 const unsigned int kFrames = 20;
26 const int kBitrate = 500;
27 typedef struct {
28   const char *filename;
29   unsigned int input_bit_depth;
30   aom_img_fmt fmt;
31   aom_bit_depth_t bit_depth;
32   unsigned int profile;
33 } TestVideoParam;
34 
operator <<(std::ostream & os,const TestVideoParam & test_arg)35 std::ostream &operator<<(std::ostream &os, const TestVideoParam &test_arg) {
36   return os << "TestVideoParam { filename:" << test_arg.filename
37             << " input_bit_depth:" << test_arg.input_bit_depth
38             << " fmt:" << test_arg.fmt << " bit_depth:" << test_arg.bit_depth
39             << " profile:" << test_arg.profile << " }";
40 }
41 
42 const TestVideoParam kTestVectors[] = {
43   { "niklas_1280_720_30.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
44   { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420, AOM_BITS_8, 0 },
45 };
46 
47 // Params: test video, speed, aq mode, threads, tile columns.
48 class AllIntraEndToEndTest
49     : public ::libaom_test::CodecTestWith6Params<TestVideoParam, int, int, int,
50                                                  int, int>,
51       public ::libaom_test::EncoderTest {
52  protected:
AllIntraEndToEndTest()53   AllIntraEndToEndTest()
54       : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)),
55         cpu_used_(GET_PARAM(2)), psnr_(0.0), nframes_(0),
56         deltaq_mode_(GET_PARAM(3)), threads_(GET_PARAM(4)),
57         tile_columns_(GET_PARAM(5)), enable_tx_size_search_(GET_PARAM(6)) {}
58 
~AllIntraEndToEndTest()59   virtual ~AllIntraEndToEndTest() {}
60 
SetUp()61   virtual void SetUp() {
62     InitializeConfig(::libaom_test::kAllIntra);
63     cfg_.g_threads = threads_;
64   }
65 
BeginPassHook(unsigned int)66   virtual void BeginPassHook(unsigned int) {
67     psnr_ = 0.0;
68     nframes_ = 0;
69   }
70 
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)71   virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
72     psnr_ += pkt->data.psnr.psnr[0];
73     nframes_++;
74   }
75 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)76   virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
77                                   ::libaom_test::Encoder *encoder) {
78     if (video->frame() == 0) {
79       encoder->Control(AV1E_SET_ROW_MT, 1);
80       encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_DEFAULT);
81       encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
82       encoder->Control(AV1E_SET_TILE_COLUMNS, tile_columns_);
83       encoder->Control(AOME_SET_CPUUSED, cpu_used_);
84       encoder->Control(AV1E_SET_DELTAQ_MODE, deltaq_mode_);
85       encoder->Control(AV1E_SET_ENABLE_TX_SIZE_SEARCH, enable_tx_size_search_);
86     }
87   }
88 
GetAveragePsnr() const89   double GetAveragePsnr() const {
90     if (nframes_) return psnr_ / nframes_;
91     return 0.0;
92   }
93 
DoTest()94   void DoTest() {
95     cfg_.rc_target_bitrate = kBitrate;
96     cfg_.g_error_resilient = 0;
97     cfg_.g_profile = test_video_param_.profile;
98     cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
99     cfg_.g_bit_depth = test_video_param_.bit_depth;
100     init_flags_ = AOM_CODEC_USE_PSNR;
101     if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH;
102 
103     std::unique_ptr<libaom_test::VideoSource> video;
104     if (is_extension_y4m(test_video_param_.filename))
105       video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0,
106                                                   kFrames));
107     else
108       video.reset(new libaom_test::YUVVideoSource(test_video_param_.filename,
109                                                   test_video_param_.fmt, 352,
110                                                   288, 30, 1, 0, kFrames));
111     ASSERT_NE(video, nullptr);
112 
113     ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
114   }
115 
116   TestVideoParam test_video_param_;
117   int cpu_used_;
118 
119  private:
120   double psnr_;
121   unsigned int nframes_;
122   unsigned int deltaq_mode_;
123   int threads_;
124   int tile_columns_;
125   int enable_tx_size_search_;
126 };
127 
TEST_P(AllIntraEndToEndTest,EndToEndNoFailure)128 TEST_P(AllIntraEndToEndTest, EndToEndNoFailure) { DoTest(); }
129 
130 AV1_INSTANTIATE_TEST_SUITE(AllIntraEndToEndTest,
131                            ::testing::ValuesIn(kTestVectors),
132                            ::testing::Range(5, 9), ::testing::Range(0, 4),
133                            ::testing::Values(1), ::testing::Values(1),
134                            ::testing::Values(0, 1));
135 
136 INSTANTIATE_TEST_SUITE_P(
137     AV1MultiThreaded, AllIntraEndToEndTest,
138     ::testing::Combine(
139         ::testing::Values(
140             static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)),
141         ::testing::ValuesIn(kTestVectors), ::testing::Range(5, 9),
142         ::testing::Range(0, 4), ::testing::Values(6), ::testing::Values(1),
143         ::testing::Values(0, 1)));
144 
145 }  // namespace
146