2 * Copyright (c) 2016, 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.
15 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
16 #include "test/codec_factory.h"
17 #include "test/encode_test_driver.h"
18 #include "test/i420_video_source.h"
19 #include "test/util.h"
20 #include "test/md5_helper.h"
21 #include "aom_mem/aom_mem.h"
24 class TileIndependenceTest
25 : public ::libaom_test::CodecTestWith2Params
<int, int>,
26 public ::libaom_test::EncoderTest
{
28 TileIndependenceTest()
29 : EncoderTest(GET_PARAM(0)), md5_fw_order_(), md5_inv_order_(),
30 n_tile_cols_(GET_PARAM(1)), n_tile_rows_(GET_PARAM(2)) {
31 init_flags_
= AOM_CODEC_USE_PSNR
;
32 aom_codec_dec_cfg_t cfg
= aom_codec_dec_cfg_t();
36 cfg
.allow_lowbitdepth
= 1;
37 fw_dec_
= codec_
->CreateDecoder(cfg
, 0);
38 inv_dec_
= codec_
->CreateDecoder(cfg
, 0);
39 inv_dec_
->Control(AV1_INVERT_TILE_DECODE_ORDER
, 1);
42 if (fw_dec_
->IsAV1() && inv_dec_
->IsAV1()) {
43 fw_dec_
->Control(AV1_SET_DECODE_TILE_ROW
, -1);
44 fw_dec_
->Control(AV1_SET_DECODE_TILE_COL
, -1);
45 inv_dec_
->Control(AV1_SET_DECODE_TILE_ROW
, -1);
46 inv_dec_
->Control(AV1_SET_DECODE_TILE_COL
, -1);
51 virtual ~TileIndependenceTest() {
56 virtual void SetUp() {
58 SetMode(libaom_test::kTwoPassGood
);
61 virtual void PreEncodeFrameHook(libaom_test::VideoSource
*video
,
62 libaom_test::Encoder
*encoder
) {
63 if (video
->frame() == 1) {
64 encoder
->Control(AV1E_SET_TILE_COLUMNS
, n_tile_cols_
);
65 encoder
->Control(AV1E_SET_TILE_ROWS
, n_tile_rows_
);
70 virtual void SetCpuUsed(libaom_test::Encoder
*encoder
) {
71 static const int kCpuUsed
= 3;
72 encoder
->Control(AOME_SET_CPUUSED
, kCpuUsed
);
75 void UpdateMD5(::libaom_test::Decoder
*dec
, const aom_codec_cx_pkt_t
*pkt
,
76 ::libaom_test::MD5
*md5
) {
77 const aom_codec_err_t res
= dec
->DecodeFrame(
78 reinterpret_cast<uint8_t *>(pkt
->data
.frame
.buf
), pkt
->data
.frame
.sz
);
79 if (res
!= AOM_CODEC_OK
) {
81 ASSERT_EQ(AOM_CODEC_OK
, res
);
83 const aom_image_t
*img
= dec
->GetDxData().Next();
87 virtual void FramePktHook(const aom_codec_cx_pkt_t
*pkt
) {
88 UpdateMD5(fw_dec_
, pkt
, &md5_fw_order_
);
89 UpdateMD5(inv_dec_
, pkt
, &md5_inv_order_
);
93 const aom_rational timebase
= { 33333333, 1000000000 };
94 cfg_
.g_timebase
= timebase
;
95 cfg_
.rc_target_bitrate
= 500;
96 cfg_
.g_lag_in_frames
= 12;
97 cfg_
.rc_end_usage
= AOM_VBR
;
99 libaom_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 704, 576,
100 timebase
.den
, timebase
.num
, 0, 5);
101 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
103 const char *md5_fw_str
= md5_fw_order_
.Get();
104 const char *md5_inv_str
= md5_inv_order_
.Get();
105 ASSERT_STREQ(md5_fw_str
, md5_inv_str
);
108 ::libaom_test::MD5 md5_fw_order_
, md5_inv_order_
;
109 ::libaom_test::Decoder
*fw_dec_
, *inv_dec_
;
116 // run an encode with 2 or 4 tiles, and do the decode both in normal and
117 // inverted tile ordering. Ensure that the MD5 of the output in both cases
118 // is identical. If so, tiles are considered independent and the test passes.
119 TEST_P(TileIndependenceTest
, MD5Match
) {
120 cfg_
.large_scale_tile
= 0;
121 fw_dec_
->Control(AV1_SET_TILE_MODE
, 0);
122 inv_dec_
->Control(AV1_SET_TILE_MODE
, 0);
126 class TileIndependenceTestLarge
: public TileIndependenceTest
{
127 virtual void SetCpuUsed(libaom_test::Encoder
*encoder
) {
128 static const int kCpuUsed
= 0;
129 encoder
->Control(AOME_SET_CPUUSED
, kCpuUsed
);
133 TEST_P(TileIndependenceTestLarge
, MD5Match
) {
134 cfg_
.large_scale_tile
= 0;
135 fw_dec_
->Control(AV1_SET_TILE_MODE
, 0);
136 inv_dec_
->Control(AV1_SET_TILE_MODE
, 0);
140 AV1_INSTANTIATE_TEST_CASE(TileIndependenceTest
, ::testing::Values(0, 1),
141 ::testing::Values(0, 1));
142 AV1_INSTANTIATE_TEST_CASE(TileIndependenceTestLarge
, ::testing::Values(0, 1),
143 ::testing::Values(0, 1));
145 class TileIndependenceLSTest
: public TileIndependenceTest
{};
147 TEST_P(TileIndependenceLSTest
, MD5Match
) {
148 cfg_
.large_scale_tile
= 1;
149 fw_dec_
->Control(AV1_SET_TILE_MODE
, 1);
150 inv_dec_
->Control(AV1_SET_TILE_MODE
, 1);
154 class TileIndependenceLSTestLarge
: public TileIndependenceTestLarge
{};
156 TEST_P(TileIndependenceLSTestLarge
, MD5Match
) {
157 cfg_
.large_scale_tile
= 1;
158 fw_dec_
->Control(AV1_SET_TILE_MODE
, 1);
159 inv_dec_
->Control(AV1_SET_TILE_MODE
, 1);
163 AV1_INSTANTIATE_TEST_CASE(TileIndependenceLSTest
, ::testing::Values(1, 2, 32),
164 ::testing::Values(1, 2, 32));
165 AV1_INSTANTIATE_TEST_CASE(TileIndependenceLSTestLarge
,
166 ::testing::Values(1, 2, 32),
167 ::testing::Values(1, 2, 32));