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