Bug 1797755 - Part 5: Use a single initial mark stack size regardless of whether...
[gecko.git] / third_party / aom / test / lossless_test.cc
blob3f8e89c815d49142a5bc8babbc44c901917d82c9
1 /*
2 * Copyright (c) 2016, 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.
12 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
14 #include "config/aom_config.h"
16 #include "test/codec_factory.h"
17 #include "test/encode_test_driver.h"
18 #include "test/i420_video_source.h"
19 #include "test/util.h"
20 #include "test/y4m_video_source.h"
22 namespace {
24 const int kMaxPsnr = 100;
26 class LosslessTestLarge
27 : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
28 public ::libaom_test::EncoderTest {
29 protected:
30 LosslessTestLarge()
31 : EncoderTest(GET_PARAM(0)), psnr_(kMaxPsnr), nframes_(0),
32 encoding_mode_(GET_PARAM(1)) {}
34 virtual ~LosslessTestLarge() {}
36 virtual void SetUp() {
37 InitializeConfig();
38 SetMode(encoding_mode_);
41 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
42 ::libaom_test::Encoder *encoder) {
43 if (video->frame() == 1) {
44 // Only call Control if quantizer > 0 to verify that using quantizer
45 // alone will activate lossless
46 if (cfg_.rc_max_quantizer > 0 || cfg_.rc_min_quantizer > 0) {
47 encoder->Control(AV1E_SET_LOSSLESS, 1);
52 virtual void BeginPassHook(unsigned int /*pass*/) {
53 psnr_ = kMaxPsnr;
54 nframes_ = 0;
57 virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
58 if (pkt->data.psnr.psnr[0] < psnr_) psnr_ = pkt->data.psnr.psnr[0];
61 double GetMinPsnr() const { return psnr_; }
63 private:
64 double psnr_;
65 unsigned int nframes_;
66 libaom_test::TestMode encoding_mode_;
69 TEST_P(LosslessTestLarge, TestLossLessEncoding) {
70 const aom_rational timebase = { 33333333, 1000000000 };
71 cfg_.g_timebase = timebase;
72 cfg_.rc_target_bitrate = 2000;
73 cfg_.g_lag_in_frames = 25;
74 cfg_.rc_min_quantizer = 0;
75 cfg_.rc_max_quantizer = 0;
77 init_flags_ = AOM_CODEC_USE_PSNR;
79 // intentionally changed the dimension for better testing coverage
80 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
81 timebase.den, timebase.num, 0, 5);
82 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
83 const double psnr_lossless = GetMinPsnr();
84 EXPECT_GE(psnr_lossless, kMaxPsnr);
87 TEST_P(LosslessTestLarge, TestLossLessEncoding444) {
88 libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 5);
90 cfg_.g_profile = 1;
91 cfg_.g_timebase = video.timebase();
92 cfg_.rc_target_bitrate = 2000;
93 cfg_.g_lag_in_frames = 25;
94 cfg_.rc_min_quantizer = 0;
95 cfg_.rc_max_quantizer = 0;
97 init_flags_ = AOM_CODEC_USE_PSNR;
99 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
100 const double psnr_lossless = GetMinPsnr();
101 EXPECT_GE(psnr_lossless, kMaxPsnr);
104 TEST_P(LosslessTestLarge, TestLossLessEncodingCtrl) {
105 const aom_rational timebase = { 33333333, 1000000000 };
106 cfg_.g_timebase = timebase;
107 cfg_.rc_target_bitrate = 2000;
108 cfg_.g_lag_in_frames = 25;
109 // Intentionally set Q > 0, to make sure control can be used to activate
110 // lossless
111 cfg_.rc_min_quantizer = 10;
112 cfg_.rc_max_quantizer = 20;
114 init_flags_ = AOM_CODEC_USE_PSNR;
116 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
117 timebase.den, timebase.num, 0, 5);
118 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
119 const double psnr_lossless = GetMinPsnr();
120 EXPECT_GE(psnr_lossless, kMaxPsnr);
123 AV1_INSTANTIATE_TEST_CASE(LosslessTestLarge,
124 ::testing::Values(::libaom_test::kOnePassGood,
125 ::libaom_test::kTwoPassGood));
126 } // namespace