2 * Copyright (c) 2020, 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.
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"
19 // This class is used to validate if screen_content_tools are turned on
21 class ScreenContentToolsTestLarge
22 : public ::libaom_test::CodecTestWith2Params
<libaom_test::TestMode
,
24 public ::libaom_test::EncoderTest
{
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
;
32 ~ScreenContentToolsTestLarge() override
= default;
34 void SetUp() override
{
35 InitializeConfig(encoding_mode_
);
36 const aom_rational timebase
= { 1, 30 };
37 cfg_
.g_timebase
= timebase
;
38 cfg_
.rc_end_usage
= rc_end_usage_
;
40 cfg_
.g_lag_in_frames
= 35;
41 cfg_
.rc_target_bitrate
= 1000;
45 bool DoDecode() const override
{ return true; }
47 void PreEncodeFrameHook(::libaom_test::VideoSource
*video
,
48 ::libaom_test::Encoder
*encoder
) override
{
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_
);
56 bool HandleDecodeResult(const aom_codec_err_t res_dec
,
57 libaom_test::Decoder
*decoder
) override
{
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
;
63 AOM_CODEC_CONTROL_TYPECHECKED(ctx_dec
, AOMD_GET_SCREEN_CONTENT_TOOLS_INFO
,
65 if (sc_info
.allow_screen_content_tools
== 1) {
66 is_screen_content_violated_
= false;
69 return AOM_CODEC_OK
== res_dec
;
72 ::libaom_test::TestMode encoding_mode_
;
73 bool is_screen_content_violated_
;
75 aom_rc_mode rc_end_usage_
;
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);
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";
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);
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";
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)";
109 AV1_INSTANTIATE_TEST_SUITE(ScreenContentToolsTestLarge
,
110 ::testing::Values(::libaom_test::kOnePassGood
,
111 ::libaom_test::kTwoPassGood
),
112 ::testing::Values(AOM_Q
));
114 class ScreenContentToolsMultiThreadTestLarge
115 : public ScreenContentToolsTestLarge
{};
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);
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";
131 AV1_INSTANTIATE_TEST_SUITE(ScreenContentToolsMultiThreadTestLarge
,
132 ::testing::Values(::libaom_test::kOnePassGood
,
133 ::libaom_test::kTwoPassGood
),
134 ::testing::Values(AOM_Q
));