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