James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 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" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 11 | #include "test/codec_factory.h" |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 12 | #include "test/encode_test_driver.h" |
| 13 | #include "test/i420_video_source.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 14 | #include "test/util.h" |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 15 | namespace { |
| 16 | |
| 17 | // lookahead range: [kLookAheadMin, kLookAheadMax). |
| 18 | const int kLookAheadMin = 5; |
| 19 | const int kLookAheadMax = 26; |
| 20 | |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 21 | class AltRefTest : public ::libvpx_test::EncoderTest, |
| 22 | public ::libvpx_test::CodecTestWithParam<int> { |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 23 | protected: |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 24 | AltRefTest() : EncoderTest(GET_PARAM(0)), altref_count_(0) {} |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 25 | virtual ~AltRefTest() {} |
| 26 | |
| 27 | virtual void SetUp() { |
| 28 | InitializeConfig(); |
| 29 | SetMode(libvpx_test::kTwoPassGood); |
| 30 | } |
| 31 | |
| 32 | virtual void BeginPassHook(unsigned int pass) { |
| 33 | altref_count_ = 0; |
| 34 | } |
| 35 | |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 36 | virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, |
| 37 | libvpx_test::Encoder *encoder) { |
| 38 | if (video->frame() == 1) { |
| 39 | encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); |
| 40 | encoder->Control(VP8E_SET_CPUUSED, 3); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { |
| 45 | if (pkt->data.frame.flags & VPX_FRAME_IS_INVISIBLE) ++altref_count_; |
| 46 | } |
| 47 | |
| 48 | int altref_count() const { return altref_count_; } |
| 49 | |
| 50 | private: |
| 51 | int altref_count_; |
| 52 | }; |
| 53 | |
| 54 | TEST_P(AltRefTest, MonotonicTimestamps) { |
| 55 | const vpx_rational timebase = { 33333333, 1000000000 }; |
| 56 | cfg_.g_timebase = timebase; |
| 57 | cfg_.rc_target_bitrate = 1000; |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 58 | cfg_.g_lag_in_frames = GET_PARAM(1); |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 59 | |
| 60 | libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 61 | timebase.den, timebase.num, 0, 30); |
| 62 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 63 | EXPECT_GE(altref_count(), 1); |
| 64 | } |
| 65 | |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 66 | |
| 67 | VP8_INSTANTIATE_TEST_CASE(AltRefTest, |
| 68 | ::testing::Range(kLookAheadMin, kLookAheadMax)); |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 69 | } // namespace |