1 /*
2 * Copyright (c) 2014 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 <climits>
11 #include <vector>
12 #include "gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/i420_video_source.h"
16 #include "test/util.h"
17
18 namespace {
19
20 class ActiveMapTest
21 : public ::libvpx_test::EncoderTest,
22 public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode, int,
23 int> {
24 protected:
25 static const int kWidth = 208;
26 static const int kHeight = 144;
27
ActiveMapTest()28 ActiveMapTest() : EncoderTest(GET_PARAM(0)) {}
29 ~ActiveMapTest() override = default;
30
SetUp()31 void SetUp() override {
32 InitializeConfig();
33 SetMode(GET_PARAM(1));
34 cpu_used_ = GET_PARAM(2);
35 }
36
PreEncodeFrameHook(::libvpx_test::VideoSource * video,::libvpx_test::Encoder * encoder)37 void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
38 ::libvpx_test::Encoder *encoder) override {
39 if (video->frame() == 0) {
40 encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
41 encoder->Control(VP9E_SET_AQ_MODE, GET_PARAM(3));
42 } else if (video->frame() == 3) {
43 vpx_active_map_t map = vpx_active_map_t();
44 /* clang-format off */
45 uint8_t active_map[9 * 13] = {
46 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
47 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
48 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
49 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
50 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1,
51 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1,
52 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1,
53 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
54 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0,
55 };
56 /* clang-format on */
57 map.cols = (kWidth + 15) / 16;
58 map.rows = (kHeight + 15) / 16;
59 ASSERT_EQ(map.cols, 13u);
60 ASSERT_EQ(map.rows, 9u);
61 map.active_map = active_map;
62 encoder->Control(VP8E_SET_ACTIVEMAP, &map);
63 } else if (video->frame() == 15) {
64 vpx_active_map_t map = vpx_active_map_t();
65 map.cols = (kWidth + 15) / 16;
66 map.rows = (kHeight + 15) / 16;
67 map.active_map = nullptr;
68 encoder->Control(VP8E_SET_ACTIVEMAP, &map);
69 }
70 }
71
72 int cpu_used_;
73 };
74
TEST_P(ActiveMapTest,Test)75 TEST_P(ActiveMapTest, Test) {
76 // Validate that this non multiple of 64 wide clip encodes
77 cfg_.g_lag_in_frames = 0;
78 cfg_.rc_target_bitrate = 400;
79 cfg_.rc_resize_allowed = 0;
80 cfg_.g_pass = VPX_RC_ONE_PASS;
81 cfg_.rc_end_usage = VPX_CBR;
82 cfg_.kf_max_dist = 90000;
83
84 ::libvpx_test::I420VideoSource video("hantro_odd.yuv", kWidth, kHeight, 30, 1,
85 0, 20);
86
87 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
88 }
89
90 VP9_INSTANTIATE_TEST_SUITE(ActiveMapTest,
91 ::testing::Values(::libvpx_test::kRealTime),
92 ::testing::Range(5, 10), ::testing::Values(0, 3));
93 } // namespace
94