lossless_test.cc 3.92 KB
Newer Older
Yaowu Xu's avatar
Yaowu Xu committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Frank Galligan's avatar
Frank Galligan committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
10
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
11

12
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
13

Yaowu Xu's avatar
Yaowu Xu committed
14
#include "./aom_config.h"
Yaowu Xu's avatar
Yaowu Xu committed
15
16
17
18
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/i420_video_source.h"
#include "test/util.h"
19
#include "test/y4m_video_source.h"
Yaowu Xu's avatar
Yaowu Xu committed
20
21
22
23
24

namespace {

const int kMaxPsnr = 100;

clang-format's avatar
clang-format committed
25
class LosslessTestLarge
26
27
    : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
      public ::libaom_test::EncoderTest {
Yaowu Xu's avatar
Yaowu Xu committed
28
 protected:
29
  LosslessTestLarge()
clang-format's avatar
clang-format committed
30
31
      : EncoderTest(GET_PARAM(0)), psnr_(kMaxPsnr), nframes_(0),
        encoding_mode_(GET_PARAM(1)) {}
Yaowu Xu's avatar
Yaowu Xu committed
32

33
  virtual ~LosslessTestLarge() {}
Yaowu Xu's avatar
Yaowu Xu committed
34
35
36
37
38
39

  virtual void SetUp() {
    InitializeConfig();
    SetMode(encoding_mode_);
  }

40
41
  virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
                                  ::libaom_test::Encoder *encoder) {
42
43
44
45
    if (video->frame() == 1) {
      // Only call Control if quantizer > 0 to verify that using quantizer
      // alone will activate lossless
      if (cfg_.rc_max_quantizer > 0 || cfg_.rc_min_quantizer > 0) {
Yaowu Xu's avatar
Yaowu Xu committed
46
        encoder->Control(AV1E_SET_LOSSLESS, 1);
47
48
49
50
      }
    }
  }

Yaowu Xu's avatar
Yaowu Xu committed
51
  virtual void BeginPassHook(unsigned int /*pass*/) {
52
    psnr_ = kMaxPsnr;
Yaowu Xu's avatar
Yaowu Xu committed
53
54
55
    nframes_ = 0;
  }

Yaowu Xu's avatar
Yaowu Xu committed
56
  virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
clang-format's avatar
clang-format committed
57
    if (pkt->data.psnr.psnr[0] < psnr_) psnr_ = pkt->data.psnr.psnr[0];
Yaowu Xu's avatar
Yaowu Xu committed
58
59
  }

clang-format's avatar
clang-format committed
60
  double GetMinPsnr() const { return psnr_; }
Yaowu Xu's avatar
Yaowu Xu committed
61
62
63
64

 private:
  double psnr_;
  unsigned int nframes_;
65
  libaom_test::TestMode encoding_mode_;
Yaowu Xu's avatar
Yaowu Xu committed
66
67
};

68
TEST_P(LosslessTestLarge, TestLossLessEncoding) {
Yaowu Xu's avatar
Yaowu Xu committed
69
  const aom_rational timebase = { 33333333, 1000000000 };
Yaowu Xu's avatar
Yaowu Xu committed
70
71
72
73
74
75
  cfg_.g_timebase = timebase;
  cfg_.rc_target_bitrate = 2000;
  cfg_.g_lag_in_frames = 25;
  cfg_.rc_min_quantizer = 0;
  cfg_.rc_max_quantizer = 0;

Yaowu Xu's avatar
Yaowu Xu committed
76
  init_flags_ = AOM_CODEC_USE_PSNR;
Yaowu Xu's avatar
Yaowu Xu committed
77
78

  // intentionally changed the dimension for better testing coverage
79
  libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
80
                                     timebase.den, timebase.num, 0, 5);
81
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Yaowu Xu's avatar
Yaowu Xu committed
82
83
84
  const double psnr_lossless = GetMinPsnr();
  EXPECT_GE(psnr_lossless, kMaxPsnr);
}
85

86
TEST_P(LosslessTestLarge, TestLossLessEncoding444) {
87
  libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 5);
88
89
90
91
92
93
94
95

  cfg_.g_profile = 1;
  cfg_.g_timebase = video.timebase();
  cfg_.rc_target_bitrate = 2000;
  cfg_.g_lag_in_frames = 25;
  cfg_.rc_min_quantizer = 0;
  cfg_.rc_max_quantizer = 0;

Yaowu Xu's avatar
Yaowu Xu committed
96
  init_flags_ = AOM_CODEC_USE_PSNR;
97
98
99
100
101
102

  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  const double psnr_lossless = GetMinPsnr();
  EXPECT_GE(psnr_lossless, kMaxPsnr);
}

103
TEST_P(LosslessTestLarge, TestLossLessEncodingCtrl) {
Yaowu Xu's avatar
Yaowu Xu committed
104
  const aom_rational timebase = { 33333333, 1000000000 };
105
106
107
108
109
110
111
112
  cfg_.g_timebase = timebase;
  cfg_.rc_target_bitrate = 2000;
  cfg_.g_lag_in_frames = 25;
  // Intentionally set Q > 0, to make sure control can be used to activate
  // lossless
  cfg_.rc_min_quantizer = 10;
  cfg_.rc_max_quantizer = 20;

Yaowu Xu's avatar
Yaowu Xu committed
113
  init_flags_ = AOM_CODEC_USE_PSNR;
114

115
  libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
116
                                     timebase.den, timebase.num, 0, 5);
117
118
119
120
121
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  const double psnr_lossless = GetMinPsnr();
  EXPECT_GE(psnr_lossless, kMaxPsnr);
}

Yaowu Xu's avatar
Yaowu Xu committed
122
123
124
AV1_INSTANTIATE_TEST_CASE(LosslessTestLarge,
                          ::testing::Values(::libaom_test::kOnePassGood,
                                            ::libaom_test::kTwoPassGood));
Yaowu Xu's avatar
Yaowu Xu committed
125
}  // namespace