| @@ -0,0 +1,90 @@ |
| 1 | +/* |
| 2 | + Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
| 3 | + |
| 4 | + Use of this source code is governed by a BSD-style license |
| 5 | + that can be found in the LICENSE file in the root of the source |
| 6 | + tree. An additional intellectual property rights grant can be found |
| 7 | + in the file PATENTS. All contributing project authors may |
| 8 | + be found in the AUTHORS file in the root of the source tree. |
| 9 | +*/ |
| 10 | +#include "third_party/googletest/src/include/gtest/gtest.h" |
| 11 | +#include "test/encode_test_driver.h" |
| 12 | +#include "test/i420_video_source.h" |
| 13 | + |
| 14 | +namespace { |
| 15 | + |
| 16 | +class ErrorResilienceTest : public libvpx_test::EncoderTest, |
| 17 | + public ::testing::TestWithParam<int> { |
| 18 | + protected: |
| 19 | + ErrorResilienceTest() { |
| 20 | + psnr_ = 0.0; |
| 21 | + nframes_ = 0; |
| 22 | + encoding_mode_ = static_cast<libvpx_test::TestMode>(GetParam()); |
| 23 | + } |
| 24 | + virtual ~ErrorResilienceTest() {} |
| 25 | + |
| 26 | + virtual void SetUp() { |
| 27 | + InitializeConfig(); |
| 28 | + SetMode(encoding_mode_); |
| 29 | + } |
| 30 | + |
| 31 | + virtual void BeginPassHook(unsigned int /*pass*/) { |
| 32 | + psnr_ = 0.0; |
| 33 | + nframes_ = 0; |
| 34 | + } |
| 35 | + |
| 36 | + virtual bool Continue() const { |
| 37 | + return !HasFatalFailure() && !abort_; |
| 38 | + } |
| 39 | + |
| 40 | + virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { |
| 41 | + psnr_ += pkt->data.psnr.psnr[0]; |
| 42 | + nframes_++; |
| 43 | + } |
| 44 | + |
| 45 | + double GetAveragePsnr() const { |
| 46 | + if (nframes_) |
| 47 | + return psnr_ / nframes_; |
| 48 | + return 0.0; |
| 49 | + } |
| 50 | + |
| 51 | + private: |
| 52 | + double psnr_; |
| 53 | + unsigned int nframes_; |
| 54 | + libvpx_test::TestMode encoding_mode_; |
| 55 | +}; |
| 56 | + |
| 57 | +TEST_P(ErrorResilienceTest, OnVersusOff) { |
| 58 | + const vpx_rational timebase = { 33333333, 1000000000 }; |
| 59 | + cfg_.g_timebase = timebase; |
| 60 | + cfg_.rc_target_bitrate = 2000; |
| 61 | + cfg_.g_lag_in_frames = 25; |
| 62 | + |
| 63 | + init_flags_ = VPX_CODEC_USE_PSNR; |
| 64 | + |
| 65 | + libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 66 | + timebase.den, timebase.num, 0, 30); |
| 67 | + |
| 68 | + // Error resilient mode OFF. |
| 69 | + cfg_.g_error_resilient = 0; |
| 70 | + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 71 | + const double psnr_resilience_off = GetAveragePsnr(); |
| 72 | + EXPECT_GT(psnr_resilience_off, 25.0); |
| 73 | + |
| 74 | + // Error resilient mode ON. |
| 75 | + cfg_.g_error_resilient = 1; |
| 76 | + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 77 | + const double psnr_resilience_on = GetAveragePsnr(); |
| 78 | + EXPECT_GT(psnr_resilience_on, 25.0); |
| 79 | + |
| 80 | + // Test that turning on error resilient mode hurts by 10% at most. |
| 81 | + if (psnr_resilience_off > 0.0) { |
| 82 | + const double psnr_ratio = psnr_resilience_on / psnr_resilience_off; |
| 83 | + EXPECT_GE(psnr_ratio, 0.9); |
| 84 | + EXPECT_LE(psnr_ratio, 1.1); |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +INSTANTIATE_TEST_CASE_P(OnOffTest, ErrorResilienceTest, |
| 89 | + ONE_PASS_TEST_MODES); |
| 90 | +} // namespace |