1 /*
2 * Copyright (c) 2020, 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 #include "aom/aom_codec.h"
12 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/y4m_video_source.h"
16 #include "test/util.h"
17
18 namespace {
19 // This class is used to validate if screen_content_tools are turned on
20 // appropriately.
21 class ScreenContentToolsTestLarge
22 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode,
23 aom_rc_mode>,
24 public ::libaom_test::EncoderTest {
25 protected:
ScreenContentToolsTestLarge()26 ScreenContentToolsTestLarge()
27 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
28 rc_end_usage_(GET_PARAM(2)) {
29 is_screen_content_violated_ = true;
30 tune_content_ = AOM_CONTENT_DEFAULT;
31 }
~ScreenContentToolsTestLarge()32 virtual ~ScreenContentToolsTestLarge() {}
33
SetUp()34 virtual void SetUp() {
35 InitializeConfig(encoding_mode_);
36 const aom_rational timebase = { 1, 30 };
37 cfg_.g_timebase = timebase;
38 cfg_.rc_end_usage = rc_end_usage_;
39 cfg_.g_threads = 1;
40 cfg_.g_lag_in_frames = 35;
41 cfg_.rc_target_bitrate = 1000;
42 cfg_.g_profile = 0;
43 }
44
DoDecode() const45 virtual bool DoDecode() const { return 1; }
46
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)47 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
48 ::libaom_test::Encoder *encoder) {
49 if (video->frame() == 0) {
50 encoder->Control(AOME_SET_CPUUSED, 5);
51 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
52 encoder->Control(AV1E_SET_TUNE_CONTENT, tune_content_);
53 }
54 }
55
HandleDecodeResult(const aom_codec_err_t res_dec,libaom_test::Decoder * decoder)56 virtual bool HandleDecodeResult(const aom_codec_err_t res_dec,
57 libaom_test::Decoder *decoder) {
58 EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
59 if (AOM_CODEC_OK == res_dec) {
60 aom_codec_ctx_t *ctx_dec = decoder->GetDecoder();
61 aom_screen_content_tools_info sc_info;
62
63 AOM_CODEC_CONTROL_TYPECHECKED(ctx_dec, AOMD_GET_SCREEN_CONTENT_TOOLS_INFO,
64 &sc_info);
65 if (sc_info.allow_screen_content_tools == 1) {
66 is_screen_content_violated_ = false;
67 }
68 }
69 return AOM_CODEC_OK == res_dec;
70 }
71
72 ::libaom_test::TestMode encoding_mode_;
73 bool is_screen_content_violated_;
74 int tune_content_;
75 aom_rc_mode rc_end_usage_;
76 };
77
TEST_P(ScreenContentToolsTestLarge,ScreenContentToolsTest)78 TEST_P(ScreenContentToolsTestLarge, ScreenContentToolsTest) {
79 // force screen content tools on
80 ::libaom_test::Y4mVideoSource video_nonsc("park_joy_90p_8_444.y4m", 0, 1);
81 cfg_.g_profile = 1;
82 tune_content_ = AOM_CONTENT_SCREEN;
83 ASSERT_NO_FATAL_FAILURE(RunLoop(&video_nonsc));
84 ASSERT_EQ(is_screen_content_violated_, false)
85 << "Failed for tune_content_ = AOM_CONTENT_SCREEN";
86
87 // Don't force screen content, however as the input is screen content
88 // allow_screen_content_tools should still be turned on
89 ::libaom_test::Y4mVideoSource video_sc("desktop_credits.y4m", 0, 1);
90 cfg_.g_profile = 1;
91 is_screen_content_violated_ = true;
92 tune_content_ = AOM_CONTENT_DEFAULT;
93 ASSERT_NO_FATAL_FAILURE(RunLoop(&video_sc));
94 ASSERT_EQ(is_screen_content_violated_, false)
95 << "Failed detection of screen content";
96
97 // TODO(anyone): Enable below test once low resolution screen content
98 // detection issues are fixed.
99 // low resolution test
100 // ::libaom_test::Y4mVideoSource video_sc("screendata.y4m", 0, 1);
101 // cfg_.g_profile = 0;
102 // is_screen_content_violated_ = true;
103 // tune_content_ = AOM_CONTENT_DEFAULT;
104 // ASSERT_NO_FATAL_FAILURE(RunLoop(&video_sc));
105 // ASSERT_EQ(is_screen_content_violated_, false)
106 // << "Failed detection of screen content(lowres)";
107 }
108
109 AV1_INSTANTIATE_TEST_SUITE(ScreenContentToolsTestLarge,
110 ::testing::Values(::libaom_test::kOnePassGood,
111 ::libaom_test::kTwoPassGood),
112 ::testing::Values(AOM_Q));
113
114 class ScreenContentToolsMultiThreadTestLarge
115 : public ScreenContentToolsTestLarge {};
116
TEST_P(ScreenContentToolsMultiThreadTestLarge,ScreenContentToolsTest)117 TEST_P(ScreenContentToolsMultiThreadTestLarge, ScreenContentToolsTest) {
118 // Don't force screen content, however as the input is screen content
119 // allow_screen_content_tools should still be turned on even with
120 // multi-threaded encoding.
121 ::libaom_test::Y4mVideoSource video_sc("desktop_credits.y4m", 0, 10);
122 cfg_.g_profile = 1;
123 cfg_.g_threads = 4;
124 is_screen_content_violated_ = true;
125 tune_content_ = AOM_CONTENT_DEFAULT;
126 ASSERT_NO_FATAL_FAILURE(RunLoop(&video_sc));
127 ASSERT_EQ(is_screen_content_violated_, false)
128 << "Failed detection of screen content";
129 }
130
131 AV1_INSTANTIATE_TEST_SUITE(ScreenContentToolsMultiThreadTestLarge,
132 ::testing::Values(::libaom_test::kOnePassGood,
133 ::libaom_test::kTwoPassGood),
134 ::testing::Values(AOM_Q));
135 } // namespace
136