2 * Copyright (c) 2018, Alliance for Open Media. All rights reserved
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.
12 #include "aom/aom_codec.h"
13 #include "av1/common/blockd.h"
14 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
15 #include "test/codec_factory.h"
16 #include "test/encode_test_driver.h"
17 #include "test/y4m_video_source.h"
18 #include "test/util.h"
20 // Verify the optimized implementation of get_partition_subsize() produces the
21 // same results as the Partition_Subsize lookup table in the spec.
22 TEST(BlockdTest
, GetPartitionSubsize
) {
23 // The Partition_Subsize table in the spec (Section 9.3. Conversion tables).
24 /* clang-format off */
25 static const BLOCK_SIZE kPartitionSubsize
[10][BLOCK_SIZES_ALL
] = {
28 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_8X8
,
29 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X16
,
30 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_32X32
,
31 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_64X64
,
32 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_128X128
,
33 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
34 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
37 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_8X4
,
38 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X8
,
39 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_32X16
,
40 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_64X32
,
41 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_128X64
,
42 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
43 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
46 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_4X8
,
47 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_8X16
,
48 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X32
,
49 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_32X64
,
50 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_64X128
,
51 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
52 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
55 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_4X4
,
56 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_8X8
,
57 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X16
,
58 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_32X32
,
59 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_64X64
,
60 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
61 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
64 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
65 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X8
,
66 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_32X16
,
67 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_64X32
,
68 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_128X64
,
69 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
70 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
73 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
74 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X8
,
75 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_32X16
,
76 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_64X32
,
77 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_128X64
,
78 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
79 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
82 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
83 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_8X16
,
84 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X32
,
85 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_32X64
,
86 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_64X128
,
87 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
88 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
91 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
92 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_8X16
,
93 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X32
,
94 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_32X64
,
95 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_64X128
,
96 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
97 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
100 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
101 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X4
,
102 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_32X8
,
103 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_64X16
,
104 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
105 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
106 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
109 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
110 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_4X16
,
111 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_8X32
,
112 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_16X64
,
113 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
114 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
,
115 BLOCK_INVALID
, BLOCK_INVALID
, BLOCK_INVALID
118 /* clang-format on */
120 for (int partition
= 0; partition
< 10; partition
++) {
121 for (int bsize
= BLOCK_4X4
; bsize
< BLOCK_SIZES_ALL
; bsize
++) {
122 EXPECT_EQ(kPartitionSubsize
[partition
][bsize
],
123 get_partition_subsize(static_cast<BLOCK_SIZE
>(bsize
),
124 static_cast<PARTITION_TYPE
>(partition
)));
129 #if CONFIG_AV1_DECODER && CONFIG_AV1_ENCODER
131 // This class is used to validate if sb_size configured is respected
133 class SuperBlockSizeTestLarge
134 : public ::libaom_test::CodecTestWith3Params
<
135 libaom_test::TestMode
, aom_superblock_size_t
, aom_rc_mode
>,
136 public ::libaom_test::EncoderTest
{
138 SuperBlockSizeTestLarge()
139 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
140 superblock_size_(GET_PARAM(2)), rc_end_usage_(GET_PARAM(3)) {
141 sb_size_violated_
= false;
143 virtual ~SuperBlockSizeTestLarge() {}
145 virtual void SetUp() {
146 InitializeConfig(encoding_mode_
);
147 const aom_rational timebase
= { 1, 30 };
148 cfg_
.g_timebase
= timebase
;
149 cfg_
.rc_end_usage
= rc_end_usage_
;
151 cfg_
.g_lag_in_frames
= 35;
152 cfg_
.rc_target_bitrate
= 1000;
155 virtual bool DoDecode() const { return 1; }
157 virtual void PreEncodeFrameHook(::libaom_test::VideoSource
*video
,
158 ::libaom_test::Encoder
*encoder
) {
159 if (video
->frame() == 0) {
160 encoder
->Control(AOME_SET_CPUUSED
, 5);
161 encoder
->Control(AOME_SET_ENABLEAUTOALTREF
, 1);
162 encoder
->Control(AV1E_SET_SUPERBLOCK_SIZE
, superblock_size_
);
166 virtual bool HandleDecodeResult(const aom_codec_err_t res_dec
,
167 libaom_test::Decoder
*decoder
) {
168 EXPECT_EQ(AOM_CODEC_OK
, res_dec
) << decoder
->DecodeError();
169 if (AOM_CODEC_OK
== res_dec
&&
170 superblock_size_
!= AOM_SUPERBLOCK_SIZE_DYNAMIC
) {
171 aom_codec_ctx_t
*ctx_dec
= decoder
->GetDecoder();
172 aom_superblock_size_t sb_size
;
173 AOM_CODEC_CONTROL_TYPECHECKED(ctx_dec
, AOMD_GET_SB_SIZE
, &sb_size
);
174 if (superblock_size_
!= sb_size
) {
175 sb_size_violated_
= true;
178 return AOM_CODEC_OK
== res_dec
;
181 ::libaom_test::TestMode encoding_mode_
;
182 aom_superblock_size_t superblock_size_
;
183 bool sb_size_violated_
;
184 aom_rc_mode rc_end_usage_
;
187 TEST_P(SuperBlockSizeTestLarge
, SuperBlockSizeTest
) {
188 ::libaom_test::Y4mVideoSource
video("niklas_1280_720_30.y4m", 0, 1);
189 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
190 ASSERT_EQ(sb_size_violated_
, false)
191 << "Failed for SB size " << superblock_size_
;
194 const ::libaom_test::TestMode kTestModes
[] = {
195 #if CONFIG_REALTIME_ONLY
196 ::libaom_test::kRealTime
198 ::libaom_test::kRealTime
, ::libaom_test::kOnePassGood
,
199 ::libaom_test::kTwoPassGood
203 AV1_INSTANTIATE_TEST_SUITE(SuperBlockSizeTestLarge
,
204 ::testing::ValuesIn(kTestModes
),
205 ::testing::Values(AOM_SUPERBLOCK_SIZE_64X64
,
206 AOM_SUPERBLOCK_SIZE_128X128
),
207 ::testing::Values(AOM_Q
, AOM_VBR
, AOM_CBR
, AOM_CQ
));