2013-07-09 21:54:36 +04:00
|
|
|
/*
|
2016-09-02 22:04:54 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2013-12-12 20:36:34 +04:00
|
|
|
*
|
2016-09-02 22:04:54 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
2015-07-30 00:51:36 +03:00
|
|
|
|
2017-02-08 04:14:05 +03:00
|
|
|
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
|
2015-07-30 00:51:36 +03:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "./aom_config.h"
|
2013-07-09 21:54:36 +04:00
|
|
|
#include "test/codec_factory.h"
|
|
|
|
#include "test/encode_test_driver.h"
|
|
|
|
#include "test/i420_video_source.h"
|
|
|
|
#include "test/util.h"
|
2014-01-18 01:52:23 +04:00
|
|
|
#include "test/y4m_video_source.h"
|
2013-07-09 21:54:36 +04:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const int kMaxPsnr = 100;
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
class LosslessTestLarge
|
2016-08-23 02:08:15 +03:00
|
|
|
: public ::libaom_test::EncoderTest,
|
|
|
|
public ::libaom_test::CodecTestWithParam<libaom_test::TestMode> {
|
2013-07-09 21:54:36 +04:00
|
|
|
protected:
|
2016-08-10 06:39:44 +03:00
|
|
|
LosslessTestLarge()
|
2016-08-12 03:46:05 +03:00
|
|
|
: EncoderTest(GET_PARAM(0)), psnr_(kMaxPsnr), nframes_(0),
|
|
|
|
encoding_mode_(GET_PARAM(1)) {}
|
2013-07-09 21:54:36 +04:00
|
|
|
|
2016-08-10 06:39:44 +03:00
|
|
|
virtual ~LosslessTestLarge() {}
|
2013-07-09 21:54:36 +04:00
|
|
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
InitializeConfig();
|
|
|
|
SetMode(encoding_mode_);
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
|
|
|
|
::libaom_test::Encoder *encoder) {
|
2014-06-28 03:09:06 +04:00
|
|
|
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) {
|
2016-08-31 00:01:10 +03:00
|
|
|
encoder->Control(AV1E_SET_LOSSLESS, 1);
|
2014-06-28 03:09:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 21:54:36 +04:00
|
|
|
virtual void BeginPassHook(unsigned int /*pass*/) {
|
2013-11-08 21:49:08 +04:00
|
|
|
psnr_ = kMaxPsnr;
|
2013-07-09 21:54:36 +04:00
|
|
|
nframes_ = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
|
2016-08-12 03:46:05 +03:00
|
|
|
if (pkt->data.psnr.psnr[0] < psnr_) psnr_ = pkt->data.psnr.psnr[0];
|
2013-07-09 21:54:36 +04:00
|
|
|
}
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
double GetMinPsnr() const { return psnr_; }
|
2013-07-09 21:54:36 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
double psnr_;
|
|
|
|
unsigned int nframes_;
|
2016-08-23 02:08:15 +03:00
|
|
|
libaom_test::TestMode encoding_mode_;
|
2013-07-09 21:54:36 +04:00
|
|
|
};
|
|
|
|
|
2016-08-10 06:39:44 +03:00
|
|
|
TEST_P(LosslessTestLarge, TestLossLessEncoding) {
|
2016-08-31 00:01:10 +03:00
|
|
|
const aom_rational timebase = { 33333333, 1000000000 };
|
2013-07-09 21:54:36 +04:00
|
|
|
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;
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
init_flags_ = AOM_CODEC_USE_PSNR;
|
2013-07-09 21:54:36 +04:00
|
|
|
|
|
|
|
// intentionally changed the dimension for better testing coverage
|
2016-08-23 02:08:15 +03:00
|
|
|
libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
|
2016-08-05 00:36:29 +03:00
|
|
|
timebase.den, timebase.num, 0, 5);
|
2013-11-08 21:49:08 +04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
2013-07-09 21:54:36 +04:00
|
|
|
const double psnr_lossless = GetMinPsnr();
|
|
|
|
EXPECT_GE(psnr_lossless, kMaxPsnr);
|
|
|
|
}
|
2014-01-18 01:52:23 +04:00
|
|
|
|
2016-08-10 06:39:44 +03:00
|
|
|
TEST_P(LosslessTestLarge, TestLossLessEncoding444) {
|
2016-08-23 02:08:15 +03:00
|
|
|
libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 5);
|
2014-01-18 01:52:23 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
init_flags_ = AOM_CODEC_USE_PSNR;
|
2014-01-18 01:52:23 +04:00
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
const double psnr_lossless = GetMinPsnr();
|
|
|
|
EXPECT_GE(psnr_lossless, kMaxPsnr);
|
|
|
|
}
|
|
|
|
|
2016-08-10 06:39:44 +03:00
|
|
|
TEST_P(LosslessTestLarge, TestLossLessEncodingCtrl) {
|
2016-08-31 00:01:10 +03:00
|
|
|
const aom_rational timebase = { 33333333, 1000000000 };
|
2014-06-28 03:09:06 +04:00
|
|
|
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;
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
init_flags_ = AOM_CODEC_USE_PSNR;
|
2014-06-28 03:09:06 +04:00
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
|
2016-08-05 00:36:29 +03:00
|
|
|
timebase.den, timebase.num, 0, 5);
|
2014-06-28 03:09:06 +04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
const double psnr_lossless = GetMinPsnr();
|
|
|
|
EXPECT_GE(psnr_lossless, kMaxPsnr);
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
AV1_INSTANTIATE_TEST_CASE(LosslessTestLarge,
|
|
|
|
::testing::Values(::libaom_test::kOnePassGood,
|
|
|
|
::libaom_test::kTwoPassGood));
|
2013-07-09 21:54:36 +04:00
|
|
|
} // namespace
|