1 /*
2 * Copyright(c) 2019 Netflix, Inc.
3 *
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 https://www.aomedia.org/license/software-license. 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 https://www.aomedia.org/license/patent-license.
10 */
11 
12 /******************************************************************************
13  * @file IntraBcUtilTest.cc
14  *
15  * @brief Unit test of Intra BC utility:
16  * - av1_is_dv_valid
17  *
18  * @author Cidana-Edmond
19  *
20  ******************************************************************************/
21 
22 #include "gtest/gtest.h"
23 // workaround to eliminate the compiling warning on linux
24 // The macro will conflict with definition in gtest.h
25 #ifdef __USE_GNU
26 #undef __USE_GNU  // defined in EbThreads.h
27 #endif
28 #ifdef _GNU_SOURCE
29 #undef _GNU_SOURCE  // defined in EbThreads.h
30 #endif
31 #include "EbDefinitions.h"
32 #include "EbAdaptiveMotionVectorPrediction.h"
33 #include "util.h"
34 
35 namespace {
36 using std::make_tuple;
37 
38 typedef std::tuple<MV,            /**< DV */
39                    int,           /**< offset of MI row */
40                    int,           /**< offset of MI colum */
41                    BlockSize, int /**< the result of dv validation function */
42                    >
43     DvValidationParam;
44 
45 static const int kSubPelScale = 8;
46 static const int kTileMaxMibWidth = 8;
47 static const DvValidationParam dv_validation_params[] = {
48     DvValidationParam({0, 0}, 0, 0, BLOCK_128X128, 0),
49     DvValidationParam({0, 0}, 0, 0, BLOCK_64X64, 0),
50     DvValidationParam({0, 0}, 0, 0, BLOCK_32X32, 0),
51     DvValidationParam({0, 0}, 0, 0, BLOCK_16X16, 0),
52     DvValidationParam({0, 0}, 0, 0, BLOCK_8X8, 0),
53     DvValidationParam({0, 0}, 0, 0, BLOCK_4X4, 0),
54     DvValidationParam({-MAX_SB_SIZE * kSubPelScale, -MAX_SB_SIZE* kSubPelScale},
55                       MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_16X16,
56                       1),
57     DvValidationParam({0, -MAX_SB_SIZE* kSubPelScale}, MAX_SB_SIZE / MI_SIZE,
58                       MAX_SB_SIZE / MI_SIZE, BLOCK_16X16, 0),
59     DvValidationParam({-MAX_SB_SIZE * kSubPelScale, 0}, MAX_SB_SIZE / MI_SIZE,
60                       MAX_SB_SIZE / MI_SIZE, BLOCK_16X16, 1),
61     DvValidationParam({MAX_SB_SIZE * kSubPelScale, 0}, MAX_SB_SIZE / MI_SIZE,
62                       MAX_SB_SIZE / MI_SIZE, BLOCK_16X16, 0),
63     DvValidationParam({0, MAX_SB_SIZE* kSubPelScale}, MAX_SB_SIZE / MI_SIZE,
64                       MAX_SB_SIZE / MI_SIZE, BLOCK_16X16, 0),
65     DvValidationParam({-32 * kSubPelScale, -32 * kSubPelScale},
66                       MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_32X32,
67                       1),
68     DvValidationParam({-32 * kSubPelScale, -32 * kSubPelScale}, 32 / MI_SIZE,
69                       32 / MI_SIZE, BLOCK_32X32, 0),
70     DvValidationParam(
71         {-32 * kSubPelScale - kSubPelScale / 2, -32 * kSubPelScale},
72         MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_32X32, 0),
73     DvValidationParam({-33 * kSubPelScale, -32 * kSubPelScale},
74                       MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_32X32,
75                       1),
76     DvValidationParam(
77         {-32 * kSubPelScale, -32 * kSubPelScale - kSubPelScale / 2},
78         MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_32X32, 0),
79     DvValidationParam({-32 * kSubPelScale, -33 * kSubPelScale},
80                       MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_32X32,
81                       1),
82     DvValidationParam({-MAX_SB_SIZE * kSubPelScale, -MAX_SB_SIZE* kSubPelScale},
83                       MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE,
84                       BLOCK_LARGEST, 1),
85     DvValidationParam(
86         {-(MAX_SB_SIZE + 1) * kSubPelScale, -MAX_SB_SIZE* kSubPelScale},
87         MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_LARGEST, 0),
88     DvValidationParam(
89         {-MAX_SB_SIZE * kSubPelScale, -(MAX_SB_SIZE + 1) * kSubPelScale},
90         MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_LARGEST, 0),
91     DvValidationParam(
92         {-(MAX_SB_SIZE - 1) * kSubPelScale, -MAX_SB_SIZE* kSubPelScale},
93         MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_LARGEST, 0),
94     DvValidationParam(
95         {-MAX_SB_SIZE * kSubPelScale, -(MAX_SB_SIZE - 1) * kSubPelScale},
96         MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_LARGEST, 1),
97     DvValidationParam(
98         {-(MAX_SB_SIZE - 1) * kSubPelScale, -(MAX_SB_SIZE - 1) * kSubPelScale},
99         MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_LARGEST, 0),
100     DvValidationParam({-MAX_SB_SIZE * kSubPelScale, MAX_SB_SIZE* kSubPelScale},
101                       MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE,
102                       BLOCK_LARGEST, 0),
103     DvValidationParam({-MAX_SB_SIZE * kSubPelScale,
104                        (kTileMaxMibWidth - 2) * MAX_SB_SIZE* kSubPelScale},
105                       MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE,
106                       BLOCK_LARGEST, 0),
107     DvValidationParam(
108         {-MAX_SB_SIZE * kSubPelScale,
109          ((kTileMaxMibWidth - 2) * MAX_SB_SIZE + 1) * kSubPelScale},
110         MAX_SB_SIZE / MI_SIZE, MAX_SB_SIZE / MI_SIZE, BLOCK_LARGEST, 0),
111 };
112 
113 class DvValiationTest : public ::testing::TestWithParam<DvValidationParam> {
114   public:
is_dv_validate()115     void is_dv_validate() {
116         MacroBlockD xd;
117         memset(&xd, 0, sizeof(xd));
118         xd.tile.mi_row_start = 8 * MAX_MIB_SIZE;
119         xd.tile.mi_row_end = 16 * MAX_MIB_SIZE;
120         xd.tile.mi_col_start = 24 * MAX_MIB_SIZE;
121         xd.tile.mi_col_end =
122             xd.tile.mi_col_start + kTileMaxMibWidth * MAX_MIB_SIZE;
123         xd.plane[1].subsampling_x = 1;
124         xd.plane[1].subsampling_y = 1;
125         xd.plane[2].subsampling_x = 1;
126         xd.plane[2].subsampling_y = 1;
127 
128         ASSERT_EQ(TEST_GET_PARAM(4),
129                   av1_is_dv_valid(TEST_GET_PARAM(0),
130                                   &xd,
131                                   xd.tile.mi_row_start + TEST_GET_PARAM(1),
132                                   xd.tile.mi_col_start + TEST_GET_PARAM(2),
133                                   TEST_GET_PARAM(3),
134                                   MAX_MIB_SIZE_LOG2));
135     }
136 };
137 
TEST_P(DvValiationTest,IsDvValidate)138 TEST_P(DvValiationTest, IsDvValidate) {
139     is_dv_validate();
140 }
141 
142 INSTANTIATE_TEST_CASE_P(AV1, DvValiationTest,
143                         ::testing::ValuesIn(dv_validation_params));
144 
145 }  // namespace
146