2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
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.
12 #include "test/encode_test_driver.h"
13 #include "test/video_source.h"
14 #include "third_party/googletest/src/include/gtest/gtest.h"
18 class KeyframeTest : public ::libvpx_test::EncoderTest,
19 public ::testing::TestWithParam<enum libvpx_test::TestMode> {
21 virtual void SetUp() {
25 kf_count_max_ = INT_MAX;
26 kf_do_force_kf_ = false;
29 virtual bool Continue() {
30 return !HasFatalFailure() && !abort_;
33 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video) {
35 flags_ = (video->frame() % 3) ? 0 : VPX_EFLAG_FORCE_KF;
38 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
39 if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) {
40 kf_pts_list_.push_back(pkt->data.frame.pts);
42 abort_ |= kf_count_ > kf_count_max_;
49 std::vector< vpx_codec_pts_t > kf_pts_list_;
52 TEST_P(KeyframeTest, TestRandomVideoSource) {
53 // Validate that encoding the RandomVideoSource produces multiple keyframes.
54 // This validates the results of the TestDisableKeyframes test.
55 kf_count_max_ = 2; // early exit successful tests.
57 ::libvpx_test::RandomVideoSource video;
58 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
60 EXPECT_GT(kf_count_, 1);
63 TEST_P(KeyframeTest, TestDisableKeyframes) {
64 cfg_.kf_mode = VPX_KF_DISABLED;
65 kf_count_max_ = 1; // early exit failed tests.
67 ::libvpx_test::RandomVideoSource video;
68 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
70 EXPECT_EQ(1, kf_count_);
73 TEST_P(KeyframeTest, TestForceKeyframe) {
74 cfg_.kf_mode = VPX_KF_DISABLED;
75 kf_do_force_kf_ = true;
77 ::libvpx_test::DummyVideoSource video;
78 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
80 // verify that every third frame is a keyframe.
81 for (std::vector<vpx_codec_pts_t>::iterator iter = kf_pts_list_.begin();
82 iter != kf_pts_list_.end();
84 ASSERT_EQ(0, *iter % 3) << "Unexpected keyframe at frame " << *iter;
88 TEST_P(KeyframeTest, TestKeyframeMaxDistance) {
89 cfg_.kf_max_dist = 25;
91 ::libvpx_test::DummyVideoSource video;
92 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
94 // verify that keyframe interval matches kf_max_dist
95 for (std::vector<vpx_codec_pts_t>::iterator iter = kf_pts_list_.begin();
96 iter != kf_pts_list_.end();
98 ASSERT_EQ(0, *iter % 25) << "Unexpected keyframe at frame " << *iter;
102 INSTANTIATE_TEST_CASE_P(AllModes, KeyframeTest, ALL_TEST_MODES);