Alex Converse | 35fb344 | 2015-09-15 21:18:32 -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 |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -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 | */ |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 11 | |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 12 | #include <algorithm> |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 13 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 14 | #include "test/codec_factory.h" |
| 15 | #include "test/encode_test_driver.h" |
| 16 | #include "test/util.h" |
| 17 | #include "test/y4m_video_source.h" |
| 18 | |
| 19 | namespace { |
| 20 | |
| 21 | // Check if any pixel in a 16x16 macroblock varies between frames. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 22 | int CheckMb(const aom_image_t ¤t, const aom_image_t &previous, int mb_r, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 23 | int mb_c) { |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 24 | for (int plane = 0; plane < 3; plane++) { |
| 25 | int r = 16 * mb_r; |
| 26 | int c0 = 16 * mb_c; |
| 27 | int r_top = std::min(r + 16, static_cast<int>(current.d_h)); |
| 28 | int c_top = std::min(c0 + 16, static_cast<int>(current.d_w)); |
| 29 | r = std::max(r, 0); |
| 30 | c0 = std::max(c0, 0); |
| 31 | if (plane > 0 && current.x_chroma_shift) { |
| 32 | c_top = (c_top + 1) >> 1; |
| 33 | c0 >>= 1; |
| 34 | } |
| 35 | if (plane > 0 && current.y_chroma_shift) { |
| 36 | r_top = (r_top + 1) >> 1; |
| 37 | r >>= 1; |
| 38 | } |
| 39 | for (; r < r_top; ++r) { |
| 40 | for (int c = c0; c < c_top; ++c) { |
| 41 | if (current.planes[plane][current.stride[plane] * r + c] != |
| 42 | previous.planes[plane][previous.stride[plane] * r + c]) |
| 43 | return 1; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | return 0; |
| 48 | } |
| 49 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 50 | void GenerateMap(int mb_rows, int mb_cols, const aom_image_t ¤t, |
| 51 | const aom_image_t &previous, uint8_t *map) { |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 52 | for (int mb_r = 0; mb_r < mb_rows; ++mb_r) { |
| 53 | for (int mb_c = 0; mb_c < mb_cols; ++mb_c) { |
| 54 | map[mb_r * mb_cols + mb_c] = CheckMb(current, previous, mb_r, mb_c); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | const int kAqModeCyclicRefresh = 3; |
| 60 | |
| 61 | class ActiveMapRefreshTest |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 62 | : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>, |
| 63 | public ::libaom_test::EncoderTest { |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 64 | protected: |
| 65 | ActiveMapRefreshTest() : EncoderTest(GET_PARAM(0)) {} |
| 66 | virtual ~ActiveMapRefreshTest() {} |
| 67 | |
| 68 | virtual void SetUp() { |
| 69 | InitializeConfig(); |
| 70 | SetMode(GET_PARAM(1)); |
| 71 | cpu_used_ = GET_PARAM(2); |
| 72 | } |
| 73 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 75 | ::libaom_test::Encoder *encoder) { |
| 76 | ::libaom_test::Y4mVideoSource *y4m_video = |
| 77 | static_cast<libaom_test::Y4mVideoSource *>(video); |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 78 | if (video->frame() == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 79 | encoder->Control(AOME_SET_CPUUSED, cpu_used_); |
| 80 | encoder->Control(AV1E_SET_AQ_MODE, kAqModeCyclicRefresh); |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 81 | } else if (video->frame() >= 2 && video->img()) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 82 | aom_image_t *current = video->img(); |
| 83 | aom_image_t *previous = y4m_holder_->img(); |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 84 | ASSERT_TRUE(previous != NULL); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 85 | aom_active_map_t map = aom_active_map_t(); |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 86 | const int width = static_cast<int>(current->d_w); |
| 87 | const int height = static_cast<int>(current->d_h); |
| 88 | const int mb_width = (width + 15) / 16; |
| 89 | const int mb_height = (height + 15) / 16; |
| 90 | uint8_t *active_map = new uint8_t[mb_width * mb_height]; |
| 91 | GenerateMap(mb_height, mb_width, *current, *previous, active_map); |
| 92 | map.cols = mb_width; |
| 93 | map.rows = mb_height; |
| 94 | map.active_map = active_map; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 95 | encoder->Control(AOME_SET_ACTIVEMAP, &map); |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 96 | delete[] active_map; |
| 97 | } |
| 98 | if (video->img()) { |
| 99 | y4m_video->SwapBuffers(y4m_holder_); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | int cpu_used_; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 104 | ::libaom_test::Y4mVideoSource *y4m_holder_; |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | TEST_P(ActiveMapRefreshTest, Test) { |
| 108 | cfg_.g_lag_in_frames = 0; |
| 109 | cfg_.g_profile = 1; |
| 110 | cfg_.rc_target_bitrate = 600; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 111 | cfg_.rc_resize_mode = 0; |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 112 | cfg_.rc_min_quantizer = 8; |
| 113 | cfg_.rc_max_quantizer = 30; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 114 | cfg_.g_pass = AOM_RC_ONE_PASS; |
| 115 | cfg_.rc_end_usage = AOM_CBR; |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 116 | cfg_.kf_max_dist = 90000; |
| 117 | |
Yaowu Xu | 81fb4cf | 2016-09-08 16:16:54 -0700 | [diff] [blame] | 118 | ::libaom_test::Y4mVideoSource video("desktop_credits.y4m", 0, 10); |
| 119 | ::libaom_test::Y4mVideoSource video_holder("desktop_credits.y4m", 0, 10); |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 120 | video_holder.Begin(); |
| 121 | y4m_holder_ = &video_holder; |
| 122 | |
| 123 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 124 | } |
| 125 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 126 | AV1_INSTANTIATE_TEST_CASE(ActiveMapRefreshTest, |
| 127 | ::testing::Values(::libaom_test::kRealTime), |
| 128 | ::testing::Range(5, 6)); |
Alex Converse | 35fb344 | 2015-09-15 21:18:32 -0700 | [diff] [blame] | 129 | } // namespace |