191037db265ecdd914a26e056cf69207b4f50924ehkuang/*
2b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian *
4b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian *  Use of this source code is governed by a BSD-style license
5b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian *  that can be found in the LICENSE file in the root of the source
6b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian *  tree. An additional intellectual property rights grant can be found
7b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian *  in the file PATENTS.  All contributing project authors may
8b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian *  be found in the AUTHORS file in the root of the source tree.
9b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian */
10b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#include "./vpx_config.h"
1191037db265ecdd914a26e056cf69207b4f50924ehkuang#include "third_party/googletest/src/include/gtest/gtest.h"
1291037db265ecdd914a26e056cf69207b4f50924ehkuang#include "test/codec_factory.h"
1391037db265ecdd914a26e056cf69207b4f50924ehkuang#include "test/encode_test_driver.h"
1491037db265ecdd914a26e056cf69207b4f50924ehkuang#include "test/i420_video_source.h"
1591037db265ecdd914a26e056cf69207b4f50924ehkuang#include "test/util.h"
16b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#include "test/y4m_video_source.h"
1791037db265ecdd914a26e056cf69207b4f50924ehkuang
1891037db265ecdd914a26e056cf69207b4f50924ehkuangnamespace {
1991037db265ecdd914a26e056cf69207b4f50924ehkuang
2091037db265ecdd914a26e056cf69207b4f50924ehkuangconst int kMaxPsnr = 100;
2191037db265ecdd914a26e056cf69207b4f50924ehkuang
22a72801d7d92ababb50eecf27a36bd222d031d2feVignesh Venkatasubramanianclass LosslessTestLarge : public ::libvpx_test::EncoderTest,
2391037db265ecdd914a26e056cf69207b4f50924ehkuang    public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
2491037db265ecdd914a26e056cf69207b4f50924ehkuang protected:
25a72801d7d92ababb50eecf27a36bd222d031d2feVignesh Venkatasubramanian  LosslessTestLarge()
26a72801d7d92ababb50eecf27a36bd222d031d2feVignesh Venkatasubramanian      : EncoderTest(GET_PARAM(0)),
27a72801d7d92ababb50eecf27a36bd222d031d2feVignesh Venkatasubramanian        psnr_(kMaxPsnr),
28a72801d7d92ababb50eecf27a36bd222d031d2feVignesh Venkatasubramanian        nframes_(0),
29a72801d7d92ababb50eecf27a36bd222d031d2feVignesh Venkatasubramanian        encoding_mode_(GET_PARAM(1)) {
3091037db265ecdd914a26e056cf69207b4f50924ehkuang  }
3191037db265ecdd914a26e056cf69207b4f50924ehkuang
32a72801d7d92ababb50eecf27a36bd222d031d2feVignesh Venkatasubramanian  virtual ~LosslessTestLarge() {}
3391037db265ecdd914a26e056cf69207b4f50924ehkuang
3491037db265ecdd914a26e056cf69207b4f50924ehkuang  virtual void SetUp() {
3591037db265ecdd914a26e056cf69207b4f50924ehkuang    InitializeConfig();
3691037db265ecdd914a26e056cf69207b4f50924ehkuang    SetMode(encoding_mode_);
3791037db265ecdd914a26e056cf69207b4f50924ehkuang  }
3891037db265ecdd914a26e056cf69207b4f50924ehkuang
3991037db265ecdd914a26e056cf69207b4f50924ehkuang  virtual void BeginPassHook(unsigned int /*pass*/) {
409b35249446b07f40ac5fcc3205f2c048616efacchkuang    psnr_ = kMaxPsnr;
4191037db265ecdd914a26e056cf69207b4f50924ehkuang    nframes_ = 0;
4291037db265ecdd914a26e056cf69207b4f50924ehkuang  }
4391037db265ecdd914a26e056cf69207b4f50924ehkuang
4491037db265ecdd914a26e056cf69207b4f50924ehkuang  virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
4591037db265ecdd914a26e056cf69207b4f50924ehkuang    if (pkt->data.psnr.psnr[0] < psnr_)
4691037db265ecdd914a26e056cf69207b4f50924ehkuang      psnr_= pkt->data.psnr.psnr[0];
4791037db265ecdd914a26e056cf69207b4f50924ehkuang  }
4891037db265ecdd914a26e056cf69207b4f50924ehkuang
4991037db265ecdd914a26e056cf69207b4f50924ehkuang  double GetMinPsnr() const {
5091037db265ecdd914a26e056cf69207b4f50924ehkuang      return psnr_;
5191037db265ecdd914a26e056cf69207b4f50924ehkuang  }
5291037db265ecdd914a26e056cf69207b4f50924ehkuang
5391037db265ecdd914a26e056cf69207b4f50924ehkuang private:
5491037db265ecdd914a26e056cf69207b4f50924ehkuang  double psnr_;
5591037db265ecdd914a26e056cf69207b4f50924ehkuang  unsigned int nframes_;
5691037db265ecdd914a26e056cf69207b4f50924ehkuang  libvpx_test::TestMode encoding_mode_;
5791037db265ecdd914a26e056cf69207b4f50924ehkuang};
5891037db265ecdd914a26e056cf69207b4f50924ehkuang
59a72801d7d92ababb50eecf27a36bd222d031d2feVignesh VenkatasubramanianTEST_P(LosslessTestLarge, TestLossLessEncoding) {
6091037db265ecdd914a26e056cf69207b4f50924ehkuang  const vpx_rational timebase = { 33333333, 1000000000 };
6191037db265ecdd914a26e056cf69207b4f50924ehkuang  cfg_.g_timebase = timebase;
6291037db265ecdd914a26e056cf69207b4f50924ehkuang  cfg_.rc_target_bitrate = 2000;
6391037db265ecdd914a26e056cf69207b4f50924ehkuang  cfg_.g_lag_in_frames = 25;
6491037db265ecdd914a26e056cf69207b4f50924ehkuang  cfg_.rc_min_quantizer = 0;
6591037db265ecdd914a26e056cf69207b4f50924ehkuang  cfg_.rc_max_quantizer = 0;
6691037db265ecdd914a26e056cf69207b4f50924ehkuang
6791037db265ecdd914a26e056cf69207b4f50924ehkuang  init_flags_ = VPX_CODEC_USE_PSNR;
6891037db265ecdd914a26e056cf69207b4f50924ehkuang
6991037db265ecdd914a26e056cf69207b4f50924ehkuang  // intentionally changed the dimension for better testing coverage
709b35249446b07f40ac5fcc3205f2c048616efacchkuang  libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
71b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian                                     timebase.den, timebase.num, 0, 10);
72b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
73b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  const double psnr_lossless = GetMinPsnr();
74b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  EXPECT_GE(psnr_lossless, kMaxPsnr);
75b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian}
76b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
77a72801d7d92ababb50eecf27a36bd222d031d2feVignesh VenkatasubramanianTEST_P(LosslessTestLarge, TestLossLessEncoding444) {
78b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  libvpx_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 10);
79b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
80b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  cfg_.g_profile = 1;
81b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  cfg_.g_timebase = video.timebase();
82b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  cfg_.rc_target_bitrate = 2000;
83b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  cfg_.g_lag_in_frames = 25;
84b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  cfg_.rc_min_quantizer = 0;
85b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  cfg_.rc_max_quantizer = 0;
86b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
87b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  init_flags_ = VPX_CODEC_USE_PSNR;
88b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
899b35249446b07f40ac5fcc3205f2c048616efacchkuang  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
9091037db265ecdd914a26e056cf69207b4f50924ehkuang  const double psnr_lossless = GetMinPsnr();
9191037db265ecdd914a26e056cf69207b4f50924ehkuang  EXPECT_GE(psnr_lossless, kMaxPsnr);
9291037db265ecdd914a26e056cf69207b4f50924ehkuang}
93b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
94a72801d7d92ababb50eecf27a36bd222d031d2feVignesh VenkatasubramanianVP9_INSTANTIATE_TEST_CASE(LosslessTestLarge, ALL_TEST_MODES);
9591037db265ecdd914a26e056cf69207b4f50924ehkuang}  // namespace
96