James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 1 | /* |
| 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 Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 11 | #include "test/codec_factory.h" |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 12 | #include "test/encode_test_driver.h" |
| 13 | #include "test/i420_video_source.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 14 | #include "test/util.h" |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 15 | namespace { |
| 16 | |
James Zern | 0dcd21f | 2016-03-17 18:46:10 -0700 | [diff] [blame] | 17 | class AltRefForcedKeyTestLarge |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | : public ::libaom_test::EncoderTest, |
| 19 | public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> { |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 20 | protected: |
James Zern | 0dcd21f | 2016-03-17 18:46:10 -0700 | [diff] [blame] | 21 | AltRefForcedKeyTestLarge() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 22 | : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), |
| 23 | cpu_used_(GET_PARAM(2)), forced_kf_frame_num_(1), frame_num_(0) {} |
James Zern | 0dcd21f | 2016-03-17 18:46:10 -0700 | [diff] [blame] | 24 | virtual ~AltRefForcedKeyTestLarge() {} |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 25 | |
| 26 | virtual void SetUp() { |
| 27 | InitializeConfig(); |
| 28 | SetMode(encoding_mode_); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 29 | cfg_.rc_end_usage = AOM_VBR; |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 30 | cfg_.g_threads = 0; |
| 31 | } |
| 32 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 33 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 34 | ::libaom_test::Encoder *encoder) { |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 35 | if (video->frame() == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 36 | encoder->Control(AOME_SET_CPUUSED, cpu_used_); |
| 37 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); |
| 38 | #if CONFIG_AV1_ENCODER |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 39 | // override test default for tile columns if necessary. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 40 | if (GET_PARAM(0) == &libaom_test::kAV1) { |
| 41 | encoder->Control(AV1E_SET_TILE_COLUMNS, 6); |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 42 | } |
| 43 | #endif |
| 44 | } |
| 45 | frame_flags_ = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 46 | (video->frame() == forced_kf_frame_num_) ? AOM_EFLAG_FORCE_KF : 0; |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 49 | virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) { |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 50 | if (frame_num_ == forced_kf_frame_num_) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 51 | ASSERT_TRUE(!!(pkt->data.frame.flags & AOM_FRAME_IS_KEY)) |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 52 | << "Frame #" << frame_num_ << " isn't a keyframe!"; |
| 53 | } |
| 54 | ++frame_num_; |
| 55 | } |
| 56 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | ::libaom_test::TestMode encoding_mode_; |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 58 | int cpu_used_; |
| 59 | unsigned int forced_kf_frame_num_; |
| 60 | unsigned int frame_num_; |
| 61 | }; |
| 62 | |
James Zern | 0dcd21f | 2016-03-17 18:46:10 -0700 | [diff] [blame] | 63 | TEST_P(AltRefForcedKeyTestLarge, Frame1IsKey) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 64 | const aom_rational timebase = { 1, 30 }; |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 65 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 71 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 72 | timebase.den, timebase.num, 0, 30); |
| 73 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 74 | } |
| 75 | } |
| 76 | |
James Zern | 0dcd21f | 2016-03-17 18:46:10 -0700 | [diff] [blame] | 77 | TEST_P(AltRefForcedKeyTestLarge, ForcedFrameIsKey) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 78 | const aom_rational timebase = { 1, 30 }; |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 79 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 85 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 86 | timebase.den, timebase.num, 0, 30); |
| 87 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 88 | } |
| 89 | } |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 90 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 91 | AV1_INSTANTIATE_TEST_CASE(AltRefForcedKeyTestLarge, |
| 92 | ::testing::Values(::libaom_test::kOnePassGood), |
| 93 | ::testing::Range(0, 9)); |
James Zern | ac4c37c | 2016-02-19 11:05:33 -0800 | [diff] [blame] | 94 | |
James Zern | 429743c | 2012-08-07 17:12:10 -0700 | [diff] [blame] | 95 | } // namespace |