706cafe336
This commit starts to convert the tests to a system where the codec to be used is provided by a factory object. Currently no tests are instantiated for VP9 since they all fail for various reasons, but it was verified that they're called and the correct codec is instantiated. Change-Id: Ia7506df2ca3a7651218ba3ca560634f08c9fbdeb
90 lines
2.5 KiB
C++
90 lines
2.5 KiB
C++
/*
|
|
Copyright (c) 2012 The WebM project authors. All Rights Reserved.
|
|
|
|
Use of this source code is governed by a BSD-style license
|
|
that can be found in the LICENSE file in the root of the source
|
|
tree. An additional intellectual property rights grant can be found
|
|
in the file PATENTS. All contributing project authors may
|
|
be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
|
#include "test/codec_factory.h"
|
|
#include "test/encode_test_driver.h"
|
|
#include "test/i420_video_source.h"
|
|
#include "test/util.h"
|
|
|
|
namespace {
|
|
|
|
class ErrorResilienceTest : public ::libvpx_test::EncoderTest,
|
|
public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
|
|
protected:
|
|
ErrorResilienceTest() : EncoderTest(GET_PARAM(0)), psnr_(0.0), nframes_(0),
|
|
encoding_mode_(GET_PARAM(1)) {}
|
|
|
|
virtual ~ErrorResilienceTest() {}
|
|
|
|
virtual void SetUp() {
|
|
InitializeConfig();
|
|
SetMode(encoding_mode_);
|
|
}
|
|
|
|
virtual void BeginPassHook(unsigned int /*pass*/) {
|
|
psnr_ = 0.0;
|
|
nframes_ = 0;
|
|
}
|
|
|
|
virtual bool Continue() const {
|
|
return !HasFatalFailure() && !abort_;
|
|
}
|
|
|
|
virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
|
|
psnr_ += pkt->data.psnr.psnr[0];
|
|
nframes_++;
|
|
}
|
|
|
|
double GetAveragePsnr() const {
|
|
if (nframes_)
|
|
return psnr_ / nframes_;
|
|
return 0.0;
|
|
}
|
|
|
|
private:
|
|
double psnr_;
|
|
unsigned int nframes_;
|
|
libvpx_test::TestMode encoding_mode_;
|
|
};
|
|
|
|
TEST_P(ErrorResilienceTest, OnVersusOff) {
|
|
const vpx_rational timebase = { 33333333, 1000000000 };
|
|
cfg_.g_timebase = timebase;
|
|
cfg_.rc_target_bitrate = 2000;
|
|
cfg_.g_lag_in_frames = 25;
|
|
|
|
init_flags_ = VPX_CODEC_USE_PSNR;
|
|
|
|
libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
|
|
timebase.den, timebase.num, 0, 30);
|
|
|
|
// Error resilient mode OFF.
|
|
cfg_.g_error_resilient = 0;
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
const double psnr_resilience_off = GetAveragePsnr();
|
|
EXPECT_GT(psnr_resilience_off, 25.0);
|
|
|
|
// Error resilient mode ON.
|
|
cfg_.g_error_resilient = 1;
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
const double psnr_resilience_on = GetAveragePsnr();
|
|
EXPECT_GT(psnr_resilience_on, 25.0);
|
|
|
|
// Test that turning on error resilient mode hurts by 10% at most.
|
|
if (psnr_resilience_off > 0.0) {
|
|
const double psnr_ratio = psnr_resilience_on / psnr_resilience_off;
|
|
EXPECT_GE(psnr_ratio, 0.9);
|
|
EXPECT_LE(psnr_ratio, 1.1);
|
|
}
|
|
}
|
|
|
|
VP8_INSTANTIATE_TEST_CASE(ErrorResilienceTest, ONE_PASS_TEST_MODES);
|
|
} // namespace
|