blob: 0c992914e99cfdc36a2a4171e863d51aed62a9a5 [file] [log] [blame]
Tom Finegan5a9f21d2016-06-15 13:42:59 -07001/*
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
Yaowu Xuc27fc142016-08-22 16:08:15 -070023 : public ::libaom_test::EncoderTest,
24 public ::libaom_test::CodecTestWithParam<libaom_test::TestMode> {
Tom Finegan5a9f21d2016-06-15 13:42:59 -070025 protected:
clang-format3a826f12016-08-11 17:46:05 -070026 RealtimeTest() : EncoderTest(GET_PARAM(0)), frame_packets_(0) {}
Tom Finegan5a9f21d2016-06-15 13:42:59 -070027 virtual ~RealtimeTest() {}
28
29 virtual void SetUp() {
30 InitializeConfig();
31 cfg_.g_lag_in_frames = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -070032 SetMode(::libaom_test::kRealTime);
Tom Finegan5a9f21d2016-06-15 13:42:59 -070033 }
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
Yaowu Xuf883b422016-08-30 14:01:10 -070038 // AOM_RC_FIRST_PASS. This is necessary because EncoderTest::RunLoop() sets
Tom Finegan5a9f21d2016-06-15 13:42:59 -070039 // the pass value based on the mode passed into EncoderTest::SetMode(),
40 // which overrides the one specified in SetUp() above.
Yaowu Xuf883b422016-08-30 14:01:10 -070041 cfg_.g_pass = AOM_RC_FIRST_PASS;
Tom Finegan5a9f21d2016-06-15 13:42:59 -070042 }
Yaowu Xuf883b422016-08-30 14:01:10 -070043 virtual void FramePktHook(const aom_codec_cx_pkt_t * /*pkt*/) {
Tom Finegan5a9f21d2016-06-15 13:42:59 -070044 frame_packets_++;
45 }
Tom Finegan5a9f21d2016-06-15 13:42:59 -070046
Tom Finegan5a9f21d2016-06-15 13:42:59 -070047 int frame_packets_;
48};
49
50TEST_P(RealtimeTest, RealtimeFirstPassProducesFrames) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070051 ::libaom_test::RandomVideoSource video;
Tom Finegan5a9f21d2016-06-15 13:42:59 -070052 video.SetSize(kVideoSourceWidth, kVideoSourceHeight);
53 video.set_limit(kFramesToEncode);
54 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Tom Finegan5a9f21d2016-06-15 13:42:59 -070055 EXPECT_EQ(kFramesToEncode, frame_packets_);
56}
57
Yaowu Xuf883b422016-08-30 14:01:10 -070058AV1_INSTANTIATE_TEST_CASE(RealtimeTest,
Yaowu Xuc27fc142016-08-22 16:08:15 -070059 ::testing::Values(::libaom_test::kRealTime));
Tom Finegan5a9f21d2016-06-15 13:42:59 -070060
61} // namespace