blob: be9b774545940d987184ed2545a54393fa3db6a8 [file] [log] [blame]
James Zern429743c2012-08-07 17:12:10 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
James Zern429743c2012-08-07 17:12:10 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
James Zern429743c2012-08-07 17:12:10 -070010 */
Yaowu Xubde4ac82016-11-28 15:26:06 -080011
James Zern429743c2012-08-07 17:12:10 -070012#include "third_party/googletest/src/include/gtest/gtest.h"
John Koleszar706cafe2013-01-18 11:51:12 -080013#include "test/codec_factory.h"
James Zern429743c2012-08-07 17:12:10 -070014#include "test/encode_test_driver.h"
15#include "test/i420_video_source.h"
John Koleszar706cafe2013-01-18 11:51:12 -080016#include "test/util.h"
James Zern429743c2012-08-07 17:12:10 -070017namespace {
18
James Zern0dcd21f2016-03-17 18:46:10 -070019class AltRefForcedKeyTestLarge
Yaowu Xuc27fc142016-08-22 16:08:15 -070020 : public ::libaom_test::EncoderTest,
21 public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> {
James Zernac4c37c2016-02-19 11:05:33 -080022 protected:
James Zern0dcd21f2016-03-17 18:46:10 -070023 AltRefForcedKeyTestLarge()
clang-format3a826f12016-08-11 17:46:05 -070024 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
25 cpu_used_(GET_PARAM(2)), forced_kf_frame_num_(1), frame_num_(0) {}
James Zern0dcd21f2016-03-17 18:46:10 -070026 virtual ~AltRefForcedKeyTestLarge() {}
James Zernac4c37c2016-02-19 11:05:33 -080027
28 virtual void SetUp() {
29 InitializeConfig();
30 SetMode(encoding_mode_);
Yaowu Xuf883b422016-08-30 14:01:10 -070031 cfg_.rc_end_usage = AOM_VBR;
James Zernac4c37c2016-02-19 11:05:33 -080032 cfg_.g_threads = 0;
33 }
34
Yaowu Xuc27fc142016-08-22 16:08:15 -070035 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
36 ::libaom_test::Encoder *encoder) {
James Zernac4c37c2016-02-19 11:05:33 -080037 if (video->frame() == 0) {
Yaowu Xuf883b422016-08-30 14:01:10 -070038 encoder->Control(AOME_SET_CPUUSED, cpu_used_);
39 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
40#if CONFIG_AV1_ENCODER
clang-format3a826f12016-08-11 17:46:05 -070041 // override test default for tile columns if necessary.
Yaowu Xuf883b422016-08-30 14:01:10 -070042 if (GET_PARAM(0) == &libaom_test::kAV1) {
43 encoder->Control(AV1E_SET_TILE_COLUMNS, 6);
James Zernac4c37c2016-02-19 11:05:33 -080044 }
45#endif
46 }
47 frame_flags_ =
Yaowu Xuf883b422016-08-30 14:01:10 -070048 (video->frame() == forced_kf_frame_num_) ? AOM_EFLAG_FORCE_KF : 0;
James Zernac4c37c2016-02-19 11:05:33 -080049 }
50
Yaowu Xuf883b422016-08-30 14:01:10 -070051 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
James Zernac4c37c2016-02-19 11:05:33 -080052 if (frame_num_ == forced_kf_frame_num_) {
Yaowu Xuf883b422016-08-30 14:01:10 -070053 ASSERT_TRUE(!!(pkt->data.frame.flags & AOM_FRAME_IS_KEY))
James Zernac4c37c2016-02-19 11:05:33 -080054 << "Frame #" << frame_num_ << " isn't a keyframe!";
55 }
56 ++frame_num_;
57 }
58
Yaowu Xuc27fc142016-08-22 16:08:15 -070059 ::libaom_test::TestMode encoding_mode_;
James Zernac4c37c2016-02-19 11:05:33 -080060 int cpu_used_;
61 unsigned int forced_kf_frame_num_;
62 unsigned int frame_num_;
63};
64
James Zern0dcd21f2016-03-17 18:46:10 -070065TEST_P(AltRefForcedKeyTestLarge, Frame1IsKey) {
Yaowu Xuf883b422016-08-30 14:01:10 -070066 const aom_rational timebase = { 1, 30 };
James Zernac4c37c2016-02-19 11:05:33 -080067 const int lag_values[] = { 3, 15, 25, -1 };
68
69 forced_kf_frame_num_ = 1;
70 for (int i = 0; lag_values[i] != -1; ++i) {
71 frame_num_ = 0;
72 cfg_.g_lag_in_frames = lag_values[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -070073 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
James Zernac4c37c2016-02-19 11:05:33 -080074 timebase.den, timebase.num, 0, 30);
75 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
76 }
77}
78
James Zern0dcd21f2016-03-17 18:46:10 -070079TEST_P(AltRefForcedKeyTestLarge, ForcedFrameIsKey) {
Yaowu Xuf883b422016-08-30 14:01:10 -070080 const aom_rational timebase = { 1, 30 };
James Zernac4c37c2016-02-19 11:05:33 -080081 const int lag_values[] = { 3, 15, 25, -1 };
82
83 for (int i = 0; lag_values[i] != -1; ++i) {
84 frame_num_ = 0;
85 forced_kf_frame_num_ = lag_values[i] - 1;
86 cfg_.g_lag_in_frames = lag_values[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -070087 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
James Zernac4c37c2016-02-19 11:05:33 -080088 timebase.den, timebase.num, 0, 30);
89 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
90 }
91}
John Koleszar706cafe2013-01-18 11:51:12 -080092
Yaowu Xuf883b422016-08-30 14:01:10 -070093AV1_INSTANTIATE_TEST_CASE(AltRefForcedKeyTestLarge,
94 ::testing::Values(::libaom_test::kOnePassGood),
95 ::testing::Range(0, 9));
James Zernac4c37c2016-02-19 11:05:33 -080096
James Zern429743c2012-08-07 17:12:10 -070097} // namespace