blob: f4978fe21f0b39efe84f6c40be846fa7c1e9f93a [file] [log] [blame]
Yaowu Xu9ce6de12013-07-09 10:54:36 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Frank Galligan38536f62013-12-12 08:36:34 -08003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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 Han097d59c2015-07-29 14:51:36 -070011
Tom Finegan7a07ece2017-02-07 17:14:05 -080012#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Jingning Han097d59c2015-07-29 14:51:36 -070013
Yaowu Xuf883b422016-08-30 14:01:10 -070014#include "./aom_config.h"
Yaowu Xu9ce6de12013-07-09 10:54:36 -070015#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 Conversef5949fa2014-01-17 13:52:23 -080019#include "test/y4m_video_source.h"
Yaowu Xu9ce6de12013-07-09 10:54:36 -070020
21namespace {
22
23const int kMaxPsnr = 100;
24
clang-format3a826f12016-08-11 17:46:05 -070025class LosslessTestLarge
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020026 : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
27 public ::libaom_test::EncoderTest {
Yaowu Xu9ce6de12013-07-09 10:54:36 -070028 protected:
James Zern239bb162016-08-09 20:39:44 -070029 LosslessTestLarge()
clang-format3a826f12016-08-11 17:46:05 -070030 : EncoderTest(GET_PARAM(0)), psnr_(kMaxPsnr), nframes_(0),
31 encoding_mode_(GET_PARAM(1)) {}
Yaowu Xu9ce6de12013-07-09 10:54:36 -070032
James Zern239bb162016-08-09 20:39:44 -070033 virtual ~LosslessTestLarge() {}
Yaowu Xu9ce6de12013-07-09 10:54:36 -070034
35 virtual void SetUp() {
36 InitializeConfig();
37 SetMode(encoding_mode_);
38 }
39
Yaowu Xuc27fc142016-08-22 16:08:15 -070040 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
41 ::libaom_test::Encoder *encoder) {
Alex Converse4bf24482014-06-27 16:09:06 -070042 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 Xuf883b422016-08-30 14:01:10 -070046 encoder->Control(AV1E_SET_LOSSLESS, 1);
Alex Converse4bf24482014-06-27 16:09:06 -070047 }
48 }
49 }
50
Yaowu Xu9ce6de12013-07-09 10:54:36 -070051 virtual void BeginPassHook(unsigned int /*pass*/) {
Yaowu Xua4a5a212013-11-08 09:49:08 -080052 psnr_ = kMaxPsnr;
Yaowu Xu9ce6de12013-07-09 10:54:36 -070053 nframes_ = 0;
54 }
55
Yaowu Xuf883b422016-08-30 14:01:10 -070056 virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
clang-format3a826f12016-08-11 17:46:05 -070057 if (pkt->data.psnr.psnr[0] < psnr_) psnr_ = pkt->data.psnr.psnr[0];
Yaowu Xu9ce6de12013-07-09 10:54:36 -070058 }
59
clang-format3a826f12016-08-11 17:46:05 -070060 double GetMinPsnr() const { return psnr_; }
Yaowu Xu9ce6de12013-07-09 10:54:36 -070061
62 private:
63 double psnr_;
64 unsigned int nframes_;
Yaowu Xuc27fc142016-08-22 16:08:15 -070065 libaom_test::TestMode encoding_mode_;
Yaowu Xu9ce6de12013-07-09 10:54:36 -070066};
67
James Zern239bb162016-08-09 20:39:44 -070068TEST_P(LosslessTestLarge, TestLossLessEncoding) {
Yaowu Xuf883b422016-08-30 14:01:10 -070069 const aom_rational timebase = { 33333333, 1000000000 };
Yaowu Xu9ce6de12013-07-09 10:54:36 -070070 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 Xuf883b422016-08-30 14:01:10 -070076 init_flags_ = AOM_CODEC_USE_PSNR;
Yaowu Xu9ce6de12013-07-09 10:54:36 -070077
78 // intentionally changed the dimension for better testing coverage
Yaowu Xuc27fc142016-08-22 16:08:15 -070079 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
Yaowu Xua1b65072016-08-04 14:36:29 -070080 timebase.den, timebase.num, 0, 5);
Yaowu Xua4a5a212013-11-08 09:49:08 -080081 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Yaowu Xu9ce6de12013-07-09 10:54:36 -070082 const double psnr_lossless = GetMinPsnr();
83 EXPECT_GE(psnr_lossless, kMaxPsnr);
84}
Alex Conversef5949fa2014-01-17 13:52:23 -080085
James Zern239bb162016-08-09 20:39:44 -070086TEST_P(LosslessTestLarge, TestLossLessEncoding444) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070087 libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 5);
Alex Conversef5949fa2014-01-17 13:52:23 -080088
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 Xuf883b422016-08-30 14:01:10 -070096 init_flags_ = AOM_CODEC_USE_PSNR;
Alex Conversef5949fa2014-01-17 13:52:23 -080097
98 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
99 const double psnr_lossless = GetMinPsnr();
100 EXPECT_GE(psnr_lossless, kMaxPsnr);
101}
Alex Conversef5949fa2014-01-17 13:52:23 -0800102
James Zern239bb162016-08-09 20:39:44 -0700103TEST_P(LosslessTestLarge, TestLossLessEncodingCtrl) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700104 const aom_rational timebase = { 33333333, 1000000000 };
Alex Converse4bf24482014-06-27 16:09:06 -0700105 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 Xuf883b422016-08-30 14:01:10 -0700113 init_flags_ = AOM_CODEC_USE_PSNR;
Alex Converse4bf24482014-06-27 16:09:06 -0700114
Yaowu Xuc27fc142016-08-22 16:08:15 -0700115 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
Yaowu Xua1b65072016-08-04 14:36:29 -0700116 timebase.den, timebase.num, 0, 5);
Alex Converse4bf24482014-06-27 16:09:06 -0700117 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
118 const double psnr_lossless = GetMinPsnr();
119 EXPECT_GE(psnr_lossless, kMaxPsnr);
120}
121
Yaowu Xuf883b422016-08-30 14:01:10 -0700122AV1_INSTANTIATE_TEST_CASE(LosslessTestLarge,
123 ::testing::Values(::libaom_test::kOnePassGood,
124 ::libaom_test::kTwoPassGood));
Yaowu Xu9ce6de12013-07-09 10:54:36 -0700125} // namespace