1/*
2 *  Copyright (c) 2016 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 "test/codec_factory.h"
11#include "test/encode_test_driver.h"
12#include "test/util.h"
13#include "test/video_source.h"
14#include "third_party/googletest/src/include/gtest/gtest.h"
15
16namespace {
17
18const int kVideoSourceWidth = 320;
19const int kVideoSourceHeight = 240;
20const int kFramesToEncode = 2;
21
22class RealtimeTest
23    : public ::libvpx_test::EncoderTest,
24      public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
25 protected:
26  RealtimeTest() : EncoderTest(GET_PARAM(0)), frame_packets_(0) {}
27  virtual ~RealtimeTest() {}
28
29  virtual void SetUp() {
30    InitializeConfig();
31    cfg_.g_lag_in_frames = 0;
32    SetMode(::libvpx_test::kRealTime);
33  }
34
35  virtual void BeginPassHook(unsigned int /*pass*/) {
36    // TODO(tomfinegan): We're changing the pass value here to make sure
37    // we get frames when real time mode is combined with |g_pass| set to
38    // VPX_RC_FIRST_PASS. This is necessary because EncoderTest::RunLoop() sets
39    // the pass value based on the mode passed into EncoderTest::SetMode(),
40    // which overrides the one specified in SetUp() above.
41    cfg_.g_pass = VPX_RC_FIRST_PASS;
42  }
43  virtual void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) {
44    frame_packets_++;
45  }
46
47  int frame_packets_;
48};
49
50TEST_P(RealtimeTest, RealtimeFirstPassProducesFrames) {
51  ::libvpx_test::RandomVideoSource video;
52  video.SetSize(kVideoSourceWidth, kVideoSourceHeight);
53  video.set_limit(kFramesToEncode);
54  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
55  EXPECT_EQ(kFramesToEncode, frame_packets_);
56}
57
58VP8_INSTANTIATE_TEST_CASE(RealtimeTest,
59                          ::testing::Values(::libvpx_test::kRealTime));
60VP9_INSTANTIATE_TEST_CASE(RealtimeTest,
61                          ::testing::Values(::libvpx_test::kRealTime));
62
63}  // namespace
64