Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | * 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. |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 10 | */ |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 11 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 13 | |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 14 | #include "test/codec_factory.h" |
| 15 | #include "test/encode_test_driver.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 16 | #include "test/util.h" |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 17 | #include "test/y4m_video_source.h" |
| 18 | #include "test/yuv_video_source.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | #include "av1/encoder/ratectrl.h" |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 20 | |
| 21 | namespace { |
| 22 | |
| 23 | const unsigned int kFrames = 100; |
| 24 | const int kBitrate = 500; |
| 25 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 26 | #define ARF_NOT_SEEN 1000001 |
| 27 | #define ARF_SEEN_ONCE 1000000 |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 28 | |
| 29 | typedef struct { |
| 30 | const char *filename; |
| 31 | unsigned int width; |
| 32 | unsigned int height; |
| 33 | unsigned int framerate_num; |
| 34 | unsigned int framerate_den; |
| 35 | unsigned int input_bit_depth; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 36 | aom_img_fmt fmt; |
| 37 | aom_bit_depth_t bit_depth; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 38 | unsigned int profile; |
| 39 | } TestVideoParam; |
| 40 | |
| 41 | typedef struct { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 42 | libaom_test::TestMode mode; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 43 | int cpu_used; |
| 44 | } TestEncodeParam; |
| 45 | |
| 46 | const TestVideoParam kTestVectors[] = { |
| 47 | // artificially increase framerate to trigger default check |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 48 | { "hantro_collage_w352h288.yuv", 352, 288, 5000, 1, 8, AOM_IMG_FMT_I420, |
| 49 | AOM_BITS_8, 0 }, |
| 50 | { "hantro_collage_w352h288.yuv", 352, 288, 30, 1, 8, AOM_IMG_FMT_I420, |
| 51 | AOM_BITS_8, 0 }, |
| 52 | { "rush_hour_444.y4m", 352, 288, 30, 1, 8, AOM_IMG_FMT_I444, AOM_BITS_8, 1 }, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 53 | // Add list of profile 2/3 test videos here ... |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | const TestEncodeParam kEncodeVectors[] = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | { ::libaom_test::kOnePassGood, 2 }, { ::libaom_test::kOnePassGood, 5 }, |
| 58 | { ::libaom_test::kTwoPassGood, 1 }, { ::libaom_test::kTwoPassGood, 2 }, |
| 59 | { ::libaom_test::kTwoPassGood, 5 }, { ::libaom_test::kRealTime, 5 }, |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | const int kMinArfVectors[] = { |
| 63 | // NOTE: 0 refers to the default built-in logic in: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 64 | // av1_rc_get_default_min_gf_interval(...) |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 65 | 0, 4, 8, 12, 15 |
| 66 | }; |
| 67 | |
| 68 | int is_extension_y4m(const char *filename) { |
| 69 | const char *dot = strrchr(filename, '.'); |
| 70 | if (!dot || dot == filename) |
| 71 | return 0; |
| 72 | else |
| 73 | return !strcmp(dot, ".y4m"); |
| 74 | } |
| 75 | |
hui su | a3a1b2d | 2015-11-02 15:47:55 -0800 | [diff] [blame] | 76 | class ArfFreqTestLarge |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 77 | : public ::libaom_test::CodecTestWith3Params<TestVideoParam, |
| 78 | TestEncodeParam, int>, |
| 79 | public ::libaom_test::EncoderTest { |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 80 | protected: |
hui su | a3a1b2d | 2015-11-02 15:47:55 -0800 | [diff] [blame] | 81 | ArfFreqTestLarge() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 82 | : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)), |
| 83 | test_encode_param_(GET_PARAM(2)), min_arf_requested_(GET_PARAM(3)) {} |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 84 | |
hui su | a3a1b2d | 2015-11-02 15:47:55 -0800 | [diff] [blame] | 85 | virtual ~ArfFreqTestLarge() {} |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 86 | |
| 87 | virtual void SetUp() { |
| 88 | InitializeConfig(); |
| 89 | SetMode(test_encode_param_.mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 90 | if (test_encode_param_.mode != ::libaom_test::kRealTime) { |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 91 | cfg_.g_lag_in_frames = 25; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 92 | cfg_.rc_end_usage = AOM_VBR; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 93 | } else { |
| 94 | cfg_.g_lag_in_frames = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 95 | cfg_.rc_end_usage = AOM_CBR; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 96 | cfg_.rc_buf_sz = 1000; |
| 97 | cfg_.rc_buf_initial_sz = 500; |
| 98 | cfg_.rc_buf_optimal_sz = 600; |
| 99 | } |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | virtual void BeginPassHook(unsigned int) { |
Debargha Mukherjee | 3c52448 | 2015-07-10 09:49:17 -0700 | [diff] [blame] | 103 | min_run_ = ARF_NOT_SEEN; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 104 | run_of_visible_frames_ = 0; |
| 105 | } |
| 106 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 107 | int GetNumFramesInPkt(const aom_codec_cx_pkt_t *pkt) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 108 | const uint8_t *buffer = reinterpret_cast<uint8_t *>(pkt->data.frame.buf); |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 109 | const uint8_t marker = buffer[pkt->data.frame.sz - 1]; |
| 110 | const int mag = ((marker >> 3) & 3) + 1; |
| 111 | int frames = (marker & 0x7) + 1; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 112 | const unsigned int index_sz = 2 + mag * frames; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 113 | // Check for superframe or not. |
| 114 | // Assume superframe has only one visible frame, the rest being |
| 115 | // invisible. If superframe index is not found, then there is only |
| 116 | // one frame. |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 117 | if (!((marker & 0xe0) == 0xc0 && pkt->data.frame.sz >= index_sz && |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 118 | buffer[pkt->data.frame.sz - index_sz] == marker)) { |
| 119 | frames = 1; |
| 120 | } |
| 121 | return frames; |
| 122 | } |
| 123 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 124 | virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) { |
| 125 | if (pkt->kind != AOM_CODEC_CX_FRAME_PKT) return; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 126 | const int frames = GetNumFramesInPkt(pkt); |
| 127 | if (frames == 1) { |
| 128 | run_of_visible_frames_++; |
| 129 | } else if (frames == 2) { |
Debargha Mukherjee | 3c52448 | 2015-07-10 09:49:17 -0700 | [diff] [blame] | 130 | if (min_run_ == ARF_NOT_SEEN) { |
| 131 | min_run_ = ARF_SEEN_ONCE; |
| 132 | } else if (min_run_ == ARF_SEEN_ONCE || |
| 133 | run_of_visible_frames_ < min_run_) { |
| 134 | min_run_ = run_of_visible_frames_; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 135 | } |
| 136 | run_of_visible_frames_ = 1; |
| 137 | } else { |
Debargha Mukherjee | 3c52448 | 2015-07-10 09:49:17 -0700 | [diff] [blame] | 138 | min_run_ = 0; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 139 | run_of_visible_frames_ = 1; |
| 140 | } |
| 141 | } |
| 142 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 143 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 144 | ::libaom_test::Encoder *encoder) { |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 145 | if (video->frame() == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 146 | encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1); |
| 147 | encoder->Control(AV1E_SET_TILE_COLUMNS, 4); |
| 148 | encoder->Control(AOME_SET_CPUUSED, test_encode_param_.cpu_used); |
| 149 | encoder->Control(AV1E_SET_MIN_GF_INTERVAL, min_arf_requested_); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 150 | if (test_encode_param_.mode != ::libaom_test::kRealTime) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 151 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); |
| 152 | encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7); |
| 153 | encoder->Control(AOME_SET_ARNR_STRENGTH, 5); |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 158 | int GetMinVisibleRun() const { return min_run_; } |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 159 | |
| 160 | int GetMinArfDistanceRequested() const { |
| 161 | if (min_arf_requested_) |
| 162 | return min_arf_requested_; |
| 163 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 164 | return av1_rc_get_default_min_gf_interval( |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 165 | test_video_param_.width, test_video_param_.height, |
| 166 | (double)test_video_param_.framerate_num / |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 167 | test_video_param_.framerate_den); |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | TestVideoParam test_video_param_; |
| 171 | TestEncodeParam test_encode_param_; |
| 172 | |
| 173 | private: |
| 174 | int min_arf_requested_; |
Debargha Mukherjee | 3c52448 | 2015-07-10 09:49:17 -0700 | [diff] [blame] | 175 | int min_run_; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 176 | int run_of_visible_frames_; |
| 177 | }; |
| 178 | |
hui su | a3a1b2d | 2015-11-02 15:47:55 -0800 | [diff] [blame] | 179 | TEST_P(ArfFreqTestLarge, MinArfFreqTest) { |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 180 | cfg_.rc_target_bitrate = kBitrate; |
| 181 | cfg_.g_error_resilient = 0; |
| 182 | cfg_.g_profile = test_video_param_.profile; |
| 183 | cfg_.g_input_bit_depth = test_video_param_.input_bit_depth; |
| 184 | cfg_.g_bit_depth = test_video_param_.bit_depth; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 185 | init_flags_ = AOM_CODEC_USE_PSNR; |
| 186 | if (cfg_.g_bit_depth > 8) init_flags_ |= AOM_CODEC_USE_HIGHBITDEPTH; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 187 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 188 | testing::internal::scoped_ptr<libaom_test::VideoSource> video; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 189 | if (is_extension_y4m(test_video_param_.filename)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 190 | video.reset(new libaom_test::Y4mVideoSource(test_video_param_.filename, 0, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 191 | kFrames)); |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 192 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 193 | video.reset(new libaom_test::YUVVideoSource( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 194 | test_video_param_.filename, test_video_param_.fmt, |
| 195 | test_video_param_.width, test_video_param_.height, |
| 196 | test_video_param_.framerate_num, test_video_param_.framerate_den, 0, |
| 197 | kFrames)); |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Alex Converse | 12ca90d | 2016-07-21 11:38:27 -0700 | [diff] [blame] | 200 | ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); |
Debargha Mukherjee | 3c52448 | 2015-07-10 09:49:17 -0700 | [diff] [blame] | 201 | const int min_run = GetMinVisibleRun(); |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 202 | const int min_arf_dist_requested = GetMinArfDistanceRequested(); |
Debargha Mukherjee | 3c52448 | 2015-07-10 09:49:17 -0700 | [diff] [blame] | 203 | if (min_run != ARF_NOT_SEEN && min_run != ARF_SEEN_ONCE) { |
| 204 | const int min_arf_dist = min_run + 1; |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 205 | EXPECT_GE(min_arf_dist, min_arf_dist_requested); |
| 206 | } |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 209 | #if CONFIG_AV1_ENCODER |
Yaowu Xu | 7c514e2 | 2015-09-28 15:55:46 -0700 | [diff] [blame] | 210 | // TODO(angiebird): 25-29 fail in high bitdepth mode. |
Zoe Liu | 5201280 | 2016-06-16 09:41:30 -0700 | [diff] [blame] | 211 | // TODO(zoeliu): This ArfFreqTest does not work with BWDREF_FRAME, as |
| 212 | // BWDREF_FRAME is also a non-show frame, and the minimum run between two |
| 213 | // consecutive BWDREF_FRAME's may vary between 1 and any arbitrary positive |
| 214 | // number as long as it does not exceed the gf_group interval. |
Yaowu Xu | 7c514e2 | 2015-09-28 15:55:46 -0700 | [diff] [blame] | 215 | INSTANTIATE_TEST_CASE_P( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 216 | DISABLED_AV1, ArfFreqTestLarge, |
Yaowu Xu | 7c514e2 | 2015-09-28 15:55:46 -0700 | [diff] [blame] | 217 | ::testing::Combine( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 218 | ::testing::Values( |
| 219 | static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)), |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 220 | ::testing::ValuesIn(kTestVectors), ::testing::ValuesIn(kEncodeVectors), |
Yaowu Xu | 7c514e2 | 2015-09-28 15:55:46 -0700 | [diff] [blame] | 221 | ::testing::ValuesIn(kMinArfVectors))); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 222 | #endif // CONFIG_AV1_ENCODER |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 223 | } // namespace |