blob: 29d6a638554f07cdb40e1371063151269a0dc573 [file] [log] [blame]
James Zern429743c2012-08-07 17:12:10 -07001/*
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 Koleszar706cafe2013-01-18 11:51:12 -080011#include "test/codec_factory.h"
James Zern429743c2012-08-07 17:12:10 -070012#include "test/encode_test_driver.h"
13#include "test/i420_video_source.h"
John Koleszar706cafe2013-01-18 11:51:12 -080014#include "test/util.h"
James Zern429743c2012-08-07 17:12:10 -070015namespace {
16
James Zern0dcd21f2016-03-17 18:46:10 -070017class AltRefForcedKeyTestLarge
Yaowu Xuc27fc142016-08-22 16:08:15 -070018 : public ::libaom_test::EncoderTest,
19 public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> {
James Zernac4c37c2016-02-19 11:05:33 -080020 protected:
James Zern0dcd21f2016-03-17 18:46:10 -070021 AltRefForcedKeyTestLarge()
clang-format3a826f12016-08-11 17:46:05 -070022 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
23 cpu_used_(GET_PARAM(2)), forced_kf_frame_num_(1), frame_num_(0) {}
James Zern0dcd21f2016-03-17 18:46:10 -070024 virtual ~AltRefForcedKeyTestLarge() {}
James Zernac4c37c2016-02-19 11:05:33 -080025
26 virtual void SetUp() {
27 InitializeConfig();
28 SetMode(encoding_mode_);
Yaowu Xuf883b422016-08-30 14:01:10 -070029 cfg_.rc_end_usage = AOM_VBR;
James Zernac4c37c2016-02-19 11:05:33 -080030 cfg_.g_threads = 0;
31 }
32
Yaowu Xuc27fc142016-08-22 16:08:15 -070033 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
34 ::libaom_test::Encoder *encoder) {
James Zernac4c37c2016-02-19 11:05:33 -080035 if (video->frame() == 0) {
Yaowu Xuf883b422016-08-30 14:01:10 -070036 encoder->Control(AOME_SET_CPUUSED, cpu_used_);
37 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
38#if CONFIG_AV1_ENCODER
clang-format3a826f12016-08-11 17:46:05 -070039 // override test default for tile columns if necessary.
Yaowu Xuf883b422016-08-30 14:01:10 -070040 if (GET_PARAM(0) == &libaom_test::kAV1) {
41 encoder->Control(AV1E_SET_TILE_COLUMNS, 6);
James Zernac4c37c2016-02-19 11:05:33 -080042 }
43#endif
44 }
45 frame_flags_ =
Yaowu Xuf883b422016-08-30 14:01:10 -070046 (video->frame() == forced_kf_frame_num_) ? AOM_EFLAG_FORCE_KF : 0;
James Zernac4c37c2016-02-19 11:05:33 -080047 }
48
Yaowu Xuf883b422016-08-30 14:01:10 -070049 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
James Zernac4c37c2016-02-19 11:05:33 -080050 if (frame_num_ == forced_kf_frame_num_) {
Yaowu Xuf883b422016-08-30 14:01:10 -070051 ASSERT_TRUE(!!(pkt->data.frame.flags & AOM_FRAME_IS_KEY))
James Zernac4c37c2016-02-19 11:05:33 -080052 << "Frame #" << frame_num_ << " isn't a keyframe!";
53 }
54 ++frame_num_;
55 }
56
Yaowu Xuc27fc142016-08-22 16:08:15 -070057 ::libaom_test::TestMode encoding_mode_;
James Zernac4c37c2016-02-19 11:05:33 -080058 int cpu_used_;
59 unsigned int forced_kf_frame_num_;
60 unsigned int frame_num_;
61};
62
James Zern0dcd21f2016-03-17 18:46:10 -070063TEST_P(AltRefForcedKeyTestLarge, Frame1IsKey) {
Yaowu Xuf883b422016-08-30 14:01:10 -070064 const aom_rational timebase = { 1, 30 };
James Zernac4c37c2016-02-19 11:05:33 -080065 const int lag_values[] = { 3, 15, 25, -1 };
66
67 forced_kf_frame_num_ = 1;
68 for (int i = 0; lag_values[i] != -1; ++i) {
69 frame_num_ = 0;
70 cfg_.g_lag_in_frames = lag_values[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -070071 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
James Zernac4c37c2016-02-19 11:05:33 -080072 timebase.den, timebase.num, 0, 30);
73 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
74 }
75}
76
James Zern0dcd21f2016-03-17 18:46:10 -070077TEST_P(AltRefForcedKeyTestLarge, ForcedFrameIsKey) {
Yaowu Xuf883b422016-08-30 14:01:10 -070078 const aom_rational timebase = { 1, 30 };
James Zernac4c37c2016-02-19 11:05:33 -080079 const int lag_values[] = { 3, 15, 25, -1 };
80
81 for (int i = 0; lag_values[i] != -1; ++i) {
82 frame_num_ = 0;
83 forced_kf_frame_num_ = lag_values[i] - 1;
84 cfg_.g_lag_in_frames = lag_values[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -070085 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
James Zernac4c37c2016-02-19 11:05:33 -080086 timebase.den, timebase.num, 0, 30);
87 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
88 }
89}
John Koleszar706cafe2013-01-18 11:51:12 -080090
Yaowu Xuf883b422016-08-30 14:01:10 -070091AV1_INSTANTIATE_TEST_CASE(AltRefForcedKeyTestLarge,
92 ::testing::Values(::libaom_test::kOnePassGood),
93 ::testing::Range(0, 9));
James Zernac4c37c2016-02-19 11:05:33 -080094
James Zern429743c2012-08-07 17:12:10 -070095} // namespace