Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Frank Galligan | 38536f6 | 2013-12-12 08:36:34 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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 | */ |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 11 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 13 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 14 | #include "./aom_config.h" |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 15 | #include "test/codec_factory.h" |
| 16 | #include "test/encode_test_driver.h" |
| 17 | #include "test/i420_video_source.h" |
| 18 | #include "test/util.h" |
Alex Converse | f5949fa | 2014-01-17 13:52:23 -0800 | [diff] [blame] | 19 | #include "test/y4m_video_source.h" |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 20 | |
| 21 | namespace { |
| 22 | |
| 23 | const int kMaxPsnr = 100; |
| 24 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 25 | class LosslessTestLarge |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 26 | : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>, |
| 27 | public ::libaom_test::EncoderTest { |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 28 | protected: |
James Zern | 239bb16 | 2016-08-09 20:39:44 -0700 | [diff] [blame] | 29 | LosslessTestLarge() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 30 | : EncoderTest(GET_PARAM(0)), psnr_(kMaxPsnr), nframes_(0), |
| 31 | encoding_mode_(GET_PARAM(1)) {} |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 32 | |
James Zern | 239bb16 | 2016-08-09 20:39:44 -0700 | [diff] [blame] | 33 | virtual ~LosslessTestLarge() {} |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 34 | |
| 35 | virtual void SetUp() { |
| 36 | InitializeConfig(); |
| 37 | SetMode(encoding_mode_); |
| 38 | } |
| 39 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 40 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 41 | ::libaom_test::Encoder *encoder) { |
Alex Converse | 4bf2448 | 2014-06-27 16:09:06 -0700 | [diff] [blame] | 42 | if (video->frame() == 1) { |
| 43 | // Only call Control if quantizer > 0 to verify that using quantizer |
| 44 | // alone will activate lossless |
| 45 | if (cfg_.rc_max_quantizer > 0 || cfg_.rc_min_quantizer > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 46 | encoder->Control(AV1E_SET_LOSSLESS, 1); |
Alex Converse | 4bf2448 | 2014-06-27 16:09:06 -0700 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 51 | virtual void BeginPassHook(unsigned int /*pass*/) { |
Yaowu Xu | a4a5a21 | 2013-11-08 09:49:08 -0800 | [diff] [blame] | 52 | psnr_ = kMaxPsnr; |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 53 | nframes_ = 0; |
| 54 | } |
| 55 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 56 | virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 57 | if (pkt->data.psnr.psnr[0] < psnr_) psnr_ = pkt->data.psnr.psnr[0]; |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 58 | } |
| 59 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 60 | double GetMinPsnr() const { return psnr_; } |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | double psnr_; |
| 64 | unsigned int nframes_; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 65 | libaom_test::TestMode encoding_mode_; |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
James Zern | 239bb16 | 2016-08-09 20:39:44 -0700 | [diff] [blame] | 68 | TEST_P(LosslessTestLarge, TestLossLessEncoding) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 69 | const aom_rational timebase = { 33333333, 1000000000 }; |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 70 | cfg_.g_timebase = timebase; |
| 71 | cfg_.rc_target_bitrate = 2000; |
| 72 | cfg_.g_lag_in_frames = 25; |
| 73 | cfg_.rc_min_quantizer = 0; |
| 74 | cfg_.rc_max_quantizer = 0; |
| 75 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 76 | init_flags_ = AOM_CODEC_USE_PSNR; |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 77 | |
| 78 | // intentionally changed the dimension for better testing coverage |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 79 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
Yaowu Xu | a1b6507 | 2016-08-04 14:36:29 -0700 | [diff] [blame] | 80 | timebase.den, timebase.num, 0, 5); |
Yaowu Xu | a4a5a21 | 2013-11-08 09:49:08 -0800 | [diff] [blame] | 81 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 82 | const double psnr_lossless = GetMinPsnr(); |
| 83 | EXPECT_GE(psnr_lossless, kMaxPsnr); |
| 84 | } |
Alex Converse | f5949fa | 2014-01-17 13:52:23 -0800 | [diff] [blame] | 85 | |
James Zern | 239bb16 | 2016-08-09 20:39:44 -0700 | [diff] [blame] | 86 | TEST_P(LosslessTestLarge, TestLossLessEncoding444) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 87 | libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 5); |
Alex Converse | f5949fa | 2014-01-17 13:52:23 -0800 | [diff] [blame] | 88 | |
| 89 | cfg_.g_profile = 1; |
| 90 | cfg_.g_timebase = video.timebase(); |
| 91 | cfg_.rc_target_bitrate = 2000; |
| 92 | cfg_.g_lag_in_frames = 25; |
| 93 | cfg_.rc_min_quantizer = 0; |
| 94 | cfg_.rc_max_quantizer = 0; |
| 95 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | init_flags_ = AOM_CODEC_USE_PSNR; |
Alex Converse | f5949fa | 2014-01-17 13:52:23 -0800 | [diff] [blame] | 97 | |
| 98 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 99 | const double psnr_lossless = GetMinPsnr(); |
| 100 | EXPECT_GE(psnr_lossless, kMaxPsnr); |
| 101 | } |
Alex Converse | f5949fa | 2014-01-17 13:52:23 -0800 | [diff] [blame] | 102 | |
James Zern | 239bb16 | 2016-08-09 20:39:44 -0700 | [diff] [blame] | 103 | TEST_P(LosslessTestLarge, TestLossLessEncodingCtrl) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 104 | const aom_rational timebase = { 33333333, 1000000000 }; |
Alex Converse | 4bf2448 | 2014-06-27 16:09:06 -0700 | [diff] [blame] | 105 | cfg_.g_timebase = timebase; |
| 106 | cfg_.rc_target_bitrate = 2000; |
| 107 | cfg_.g_lag_in_frames = 25; |
| 108 | // Intentionally set Q > 0, to make sure control can be used to activate |
| 109 | // lossless |
| 110 | cfg_.rc_min_quantizer = 10; |
| 111 | cfg_.rc_max_quantizer = 20; |
| 112 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 113 | init_flags_ = AOM_CODEC_USE_PSNR; |
Alex Converse | 4bf2448 | 2014-06-27 16:09:06 -0700 | [diff] [blame] | 114 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 115 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
Yaowu Xu | a1b6507 | 2016-08-04 14:36:29 -0700 | [diff] [blame] | 116 | timebase.den, timebase.num, 0, 5); |
Alex Converse | 4bf2448 | 2014-06-27 16:09:06 -0700 | [diff] [blame] | 117 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 118 | const double psnr_lossless = GetMinPsnr(); |
| 119 | EXPECT_GE(psnr_lossless, kMaxPsnr); |
| 120 | } |
| 121 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 122 | AV1_INSTANTIATE_TEST_CASE(LosslessTestLarge, |
| 123 | ::testing::Values(::libaom_test::kOnePassGood, |
| 124 | ::libaom_test::kTwoPassGood)); |
Yaowu Xu | 9ce6de1 | 2013-07-09 10:54:36 -0700 | [diff] [blame] | 125 | } // namespace |