2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
14 #include "test/codec_factory.h"
15 #include "test/encode_test_driver.h"
16 #include "test/util.h"
17 #include "test/y4m_video_source.h"
18 #include "test/yuv_video_source.h"
22 const unsigned int kWidth
= 160;
23 const unsigned int kHeight
= 90;
24 const unsigned int kFramerate
= 50;
25 const unsigned int kFrames
= 10;
26 const int kBitrate
= 500;
27 // List of psnr thresholds for speed settings 0-7 and 5 encoding modes
28 const double kPsnrThreshold
[][5] = {
30 // AV1 HBD average PSNR is slightly lower than AV1.
31 // We make two cases here to enable the testing and
32 // guard picture quality.
33 #if CONFIG_AV1_ENCODER
34 { 36.0, 37.0, 37.0, 37.0, 37.0 }, { 31.0, 36.0, 36.0, 36.0, 36.0 },
35 { 31.0, 35.0, 35.0, 35.0, 35.0 }, { 31.0, 34.0, 34.0, 34.0, 34.0 },
36 { 31.0, 33.0, 33.0, 33.0, 33.0 }, { 31.0, 32.0, 32.0, 32.0, 32.0 },
37 { 30.0, 31.0, 31.0, 31.0, 31.0 }, { 29.0, 30.0, 30.0, 30.0, 30.0 },
39 { 36.0, 37.0, 37.0, 37.0, 37.0 }, { 35.0, 36.0, 36.0, 36.0, 36.0 },
40 { 34.0, 35.0, 35.0, 35.0, 35.0 }, { 33.0, 34.0, 34.0, 34.0, 34.0 },
41 { 32.0, 33.0, 33.0, 33.0, 33.0 }, { 31.0, 32.0, 32.0, 32.0, 32.0 },
42 { 30.0, 31.0, 31.0, 31.0, 31.0 }, { 29.0, 30.0, 30.0, 30.0, 30.0 },
43 #endif // CONFIG_AV1_ENCODER
48 unsigned int input_bit_depth
;
50 aom_bit_depth_t bit_depth
;
54 const TestVideoParam kTestVectors
[] = {
55 { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420
, AOM_BITS_8
, 0 },
56 { "park_joy_90p_8_422.y4m", 8, AOM_IMG_FMT_I422
, AOM_BITS_8
, 2 },
57 { "park_joy_90p_8_444.y4m", 8, AOM_IMG_FMT_I444
, AOM_BITS_8
, 1 },
58 { "park_joy_90p_10_420.y4m", 10, AOM_IMG_FMT_I42016
, AOM_BITS_10
, 0 },
59 { "park_joy_90p_10_422.y4m", 10, AOM_IMG_FMT_I42216
, AOM_BITS_10
, 2 },
60 { "park_joy_90p_10_444.y4m", 10, AOM_IMG_FMT_I44416
, AOM_BITS_10
, 1 },
61 { "park_joy_90p_12_420.y4m", 12, AOM_IMG_FMT_I42016
, AOM_BITS_12
, 2 },
62 { "park_joy_90p_12_422.y4m", 12, AOM_IMG_FMT_I42216
, AOM_BITS_12
, 2 },
63 { "park_joy_90p_12_444.y4m", 12, AOM_IMG_FMT_I44416
, AOM_BITS_12
, 2 },
66 // Encoding modes tested
67 const libaom_test::TestMode kEncodingModeVectors
[] = {
68 ::libaom_test::kTwoPassGood
,
69 ::libaom_test::kOnePassGood
,
70 ::libaom_test::kRealTime
,
73 // Speed settings tested
74 const int kCpuUsedVectors
[] = { 1, 2, 3, 5, 6 };
76 int is_extension_y4m(const char *filename
) {
77 const char *dot
= strrchr(filename
, '.');
78 if (!dot
|| dot
== filename
)
81 return !strcmp(dot
, ".y4m");
85 : public ::libaom_test::CodecTestWith3Params
<libaom_test::TestMode
,
87 public ::libaom_test::EncoderTest
{
90 : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(2)),
91 cpu_used_(GET_PARAM(3)), psnr_(0.0), nframes_(0),
92 encoding_mode_(GET_PARAM(1)) {}
94 virtual ~EndToEndTest() {}
96 virtual void SetUp() {
98 SetMode(encoding_mode_
);
99 if (encoding_mode_
!= ::libaom_test::kRealTime
) {
100 cfg_
.g_lag_in_frames
= 5;
101 cfg_
.rc_end_usage
= AOM_VBR
;
103 cfg_
.g_lag_in_frames
= 0;
104 cfg_
.rc_end_usage
= AOM_CBR
;
105 cfg_
.rc_buf_sz
= 1000;
106 cfg_
.rc_buf_initial_sz
= 500;
107 cfg_
.rc_buf_optimal_sz
= 600;
111 virtual void BeginPassHook(unsigned int) {
116 virtual void PSNRPktHook(const aom_codec_cx_pkt_t
*pkt
) {
117 psnr_
+= pkt
->data
.psnr
.psnr
[0];
121 virtual void PreEncodeFrameHook(::libaom_test::VideoSource
*video
,
122 ::libaom_test::Encoder
*encoder
) {
123 if (video
->frame() == 1) {
124 encoder
->Control(AV1E_SET_FRAME_PARALLEL_DECODING
, 1);
125 encoder
->Control(AV1E_SET_TILE_COLUMNS
, 4);
126 encoder
->Control(AOME_SET_CPUUSED
, cpu_used_
);
127 // Test screen coding tools at cpu_used = 1 && encoding mode is two-pass.
128 if (cpu_used_
== 1 && encoding_mode_
== ::libaom_test::kTwoPassGood
)
129 encoder
->Control(AV1E_SET_TUNE_CONTENT
, AOM_CONTENT_SCREEN
);
131 encoder
->Control(AV1E_SET_TUNE_CONTENT
, AOM_CONTENT_DEFAULT
);
132 if (encoding_mode_
!= ::libaom_test::kRealTime
) {
133 encoder
->Control(AOME_SET_ENABLEAUTOALTREF
, 1);
134 encoder
->Control(AOME_SET_ARNR_MAXFRAMES
, 7);
135 encoder
->Control(AOME_SET_ARNR_STRENGTH
, 5);
140 double GetAveragePsnr() const {
141 if (nframes_
) return psnr_
/ nframes_
;
145 double GetPsnrThreshold() {
146 return kPsnrThreshold
[cpu_used_
][encoding_mode_
];
150 cfg_
.rc_target_bitrate
= kBitrate
;
151 cfg_
.g_error_resilient
= 0;
152 cfg_
.g_profile
= test_video_param_
.profile
;
153 cfg_
.g_input_bit_depth
= test_video_param_
.input_bit_depth
;
154 cfg_
.g_bit_depth
= test_video_param_
.bit_depth
;
155 init_flags_
= AOM_CODEC_USE_PSNR
;
156 if (cfg_
.g_bit_depth
> 8) init_flags_
|= AOM_CODEC_USE_HIGHBITDEPTH
;
158 testing::internal::scoped_ptr
<libaom_test::VideoSource
> video
;
159 if (is_extension_y4m(test_video_param_
.filename
)) {
160 video
.reset(new libaom_test::Y4mVideoSource(test_video_param_
.filename
, 0,
163 video
.reset(new libaom_test::YUVVideoSource(
164 test_video_param_
.filename
, test_video_param_
.fmt
, kWidth
, kHeight
,
165 kFramerate
, 1, 0, kFrames
));
167 ASSERT_TRUE(video
.get() != NULL
);
169 ASSERT_NO_FATAL_FAILURE(RunLoop(video
.get()));
170 const double psnr
= GetAveragePsnr();
171 EXPECT_GT(psnr
, GetPsnrThreshold())
172 << "cpu used = " << cpu_used_
<< ", encoding mode = " << encoding_mode_
;
175 TestVideoParam test_video_param_
;
180 unsigned int nframes_
;
181 libaom_test::TestMode encoding_mode_
;
184 class EndToEndTestLarge
: public EndToEndTest
{};
186 TEST_P(EndToEndTestLarge
, EndtoEndPSNRTest
) { DoTest(); }
188 TEST_P(EndToEndTest
, EndtoEndPSNRTest
) { DoTest(); }
190 AV1_INSTANTIATE_TEST_CASE(EndToEndTestLarge
,
191 ::testing::ValuesIn(kEncodingModeVectors
),
192 ::testing::ValuesIn(kTestVectors
),
193 ::testing::ValuesIn(kCpuUsedVectors
));
195 AV1_INSTANTIATE_TEST_CASE(EndToEndTest
,
196 ::testing::Values(kEncodingModeVectors
[0]),
197 ::testing::Values(kTestVectors
[2]), // 444
198 ::testing::Values(kCpuUsedVectors
[2]));