9c55f9a8b178451e51e8efc859853681878be0e8
[platform/upstream/libvpx.git] / test / active_map_test.cc
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 "third_party/googletest/src/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::CodecTestWith2Params<libvpx_test::TestMode, int> {
23  protected:
24   static const int kWidth = 208;
25   static const int kHeight = 144;
26
27   ActiveMapTest() : EncoderTest(GET_PARAM(0)) {}
28   virtual ~ActiveMapTest() {}
29
30   virtual void SetUp() {
31     InitializeConfig();
32     SetMode(GET_PARAM(1));
33     cpu_used_ = GET_PARAM(2);
34   }
35
36   virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
37                                   ::libvpx_test::Encoder *encoder) {
38     if (video->frame() == 0) {
39       encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
40     } else if (video->frame() == 3) {
41       vpx_active_map_t map = vpx_active_map_t();
42       /* clang-format off */
43       uint8_t active_map[9 * 13] = {
44         1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
45         1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
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         0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1,
49         0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1,
50         0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1,
51         0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
52         1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0,
53       };
54       /* clang-format on */
55       map.cols = (kWidth + 15) / 16;
56       map.rows = (kHeight + 15) / 16;
57       ASSERT_EQ(map.cols, 13u);
58       ASSERT_EQ(map.rows, 9u);
59       map.active_map = active_map;
60       encoder->Control(VP8E_SET_ACTIVEMAP, &map);
61     } else if (video->frame() == 15) {
62       vpx_active_map_t map = vpx_active_map_t();
63       map.cols = (kWidth + 15) / 16;
64       map.rows = (kHeight + 15) / 16;
65       map.active_map = nullptr;
66       encoder->Control(VP8E_SET_ACTIVEMAP, &map);
67     }
68   }
69
70   int cpu_used_;
71 };
72
73 TEST_P(ActiveMapTest, Test) {
74   // Validate that this non multiple of 64 wide clip encodes
75   cfg_.g_lag_in_frames = 0;
76   cfg_.rc_target_bitrate = 400;
77   cfg_.rc_resize_allowed = 0;
78   cfg_.g_pass = VPX_RC_ONE_PASS;
79   cfg_.rc_end_usage = VPX_CBR;
80   cfg_.kf_max_dist = 90000;
81
82   ::libvpx_test::I420VideoSource video("hantro_odd.yuv", kWidth, kHeight, 30, 1,
83                                        0, 20);
84
85   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
86 }
87
88 VP9_INSTANTIATE_TEST_SUITE(ActiveMapTest,
89                            ::testing::Values(::libvpx_test::kRealTime),
90                            ::testing::Range(0, 9));
91 }  // namespace