blob: 954e3f2156c0aec7256c73fdead7e4144a65d7c1 [file] [log] [blame]
Alex Converse35fb3442015-09-15 21:18:32 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Alex Converse35fb3442015-09-15 21:18:32 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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.
Johann123e8a62017-12-28 14:40:49 -080010 */
Yaowu Xu9c01aa12016-09-01 14:32:49 -070011
Alex Converse35fb3442015-09-15 21:18:32 -070012#include <algorithm>
Tom Finegan7a07ece2017-02-07 17:14:05 -080013#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Alex Converse35fb3442015-09-15 21:18:32 -070014#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
19namespace {
20
21// Check if any pixel in a 16x16 macroblock varies between frames.
Yaowu Xuf883b422016-08-30 14:01:10 -070022int CheckMb(const aom_image_t &current, const aom_image_t &previous, int mb_r,
clang-format3a826f12016-08-11 17:46:05 -070023 int mb_c) {
Alex Converse35fb3442015-09-15 21:18:32 -070024 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 Xuf883b422016-08-30 14:01:10 -070050void GenerateMap(int mb_rows, int mb_cols, const aom_image_t &current,
51 const aom_image_t &previous, uint8_t *map) {
Alex Converse35fb3442015-09-15 21:18:32 -070052 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
59const int kAqModeCyclicRefresh = 3;
60
61class ActiveMapRefreshTest
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020062 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
63 public ::libaom_test::EncoderTest {
Alex Converse35fb3442015-09-15 21:18:32 -070064 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 Xuc27fc142016-08-22 16:08:15 -070074 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 Converse35fb3442015-09-15 21:18:32 -070078 if (video->frame() == 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -070079 encoder->Control(AOME_SET_CPUUSED, cpu_used_);
80 encoder->Control(AV1E_SET_AQ_MODE, kAqModeCyclicRefresh);
Alex Converse35fb3442015-09-15 21:18:32 -070081 } else if (video->frame() >= 2 && video->img()) {
Yaowu Xuf883b422016-08-30 14:01:10 -070082 aom_image_t *current = video->img();
83 aom_image_t *previous = y4m_holder_->img();
Alex Converse35fb3442015-09-15 21:18:32 -070084 ASSERT_TRUE(previous != NULL);
Yaowu Xuf883b422016-08-30 14:01:10 -070085 aom_active_map_t map = aom_active_map_t();
Alex Converse35fb3442015-09-15 21:18:32 -070086 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 Xuf883b422016-08-30 14:01:10 -070095 encoder->Control(AOME_SET_ACTIVEMAP, &map);
Alex Converse35fb3442015-09-15 21:18:32 -070096 delete[] active_map;
97 }
98 if (video->img()) {
99 y4m_video->SwapBuffers(y4m_holder_);
100 }
101 }
102
103 int cpu_used_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700104 ::libaom_test::Y4mVideoSource *y4m_holder_;
Alex Converse35fb3442015-09-15 21:18:32 -0700105};
106
107TEST_P(ActiveMapRefreshTest, Test) {
108 cfg_.g_lag_in_frames = 0;
109 cfg_.g_profile = 1;
110 cfg_.rc_target_bitrate = 600;
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700111 cfg_.rc_resize_mode = 0;
Alex Converse35fb3442015-09-15 21:18:32 -0700112 cfg_.rc_min_quantizer = 8;
113 cfg_.rc_max_quantizer = 30;
Yaowu Xuf883b422016-08-30 14:01:10 -0700114 cfg_.g_pass = AOM_RC_ONE_PASS;
115 cfg_.rc_end_usage = AOM_CBR;
Alex Converse35fb3442015-09-15 21:18:32 -0700116 cfg_.kf_max_dist = 90000;
117
Yaowu Xu81fb4cf2016-09-08 16:16:54 -0700118 ::libaom_test::Y4mVideoSource video("desktop_credits.y4m", 0, 10);
119 ::libaom_test::Y4mVideoSource video_holder("desktop_credits.y4m", 0, 10);
Alex Converse35fb3442015-09-15 21:18:32 -0700120 video_holder.Begin();
121 y4m_holder_ = &video_holder;
122
123 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
124}
125
Yaowu Xuf883b422016-08-30 14:01:10 -0700126AV1_INSTANTIATE_TEST_CASE(ActiveMapRefreshTest,
127 ::testing::Values(::libaom_test::kRealTime),
128 ::testing::Range(5, 6));
Alex Converse35fb3442015-09-15 21:18:32 -0700129} // namespace