blob: 260aa42ffd1d6d8aced079798923e4741fd54acf [file] [log] [blame]
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -08001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Frank Galligan38536f62013-12-12 08:36:34 -08003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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.
10*/
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080011
12#include <cstdio>
13#include <cstdlib>
14#include <string>
Tom Finegan7a07ece2017-02-07 17:14:05 -080015#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080016#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"
Yaowu Xuf883b422016-08-30 14:01:10 -070021#include "aom_mem/aom_mem.h"
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080022
23namespace {
clang-format3a826f12016-08-11 17:46:05 -070024class TileIndependenceTest
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020025 : public ::libaom_test::CodecTestWith2Params<int, int>,
26 public ::libaom_test::EncoderTest {
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080027 protected:
James Zernbae31172013-07-18 14:37:53 -070028 TileIndependenceTest()
clang-format3a826f12016-08-11 17:46:05 -070029 : EncoderTest(GET_PARAM(0)), md5_fw_order_(), md5_inv_order_(),
30 n_tile_cols_(GET_PARAM(1)), n_tile_rows_(GET_PARAM(2)) {
Yaowu Xuf883b422016-08-30 14:01:10 -070031 init_flags_ = AOM_CODEC_USE_PSNR;
32 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
Ronald S. Bultjef496f602013-02-06 15:30:21 -080033 cfg.w = 704;
34 cfg.h = 144;
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080035 cfg.threads = 1;
Sebastien Alaiwan8a65f9f2017-06-23 07:28:44 +020036 cfg.allow_lowbitdepth = 1;
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080037 fw_dec_ = codec_->CreateDecoder(cfg, 0);
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080038 inv_dec_ = codec_->CreateDecoder(cfg, 0);
Yaowu Xuf883b422016-08-30 14:01:10 -070039 inv_dec_->Control(AV1_INVERT_TILE_DECODE_ORDER, 1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070040
Yunqing Wangeeb08a92017-07-07 21:25:18 -070041#if CONFIG_AV1
Yaowu Xuf883b422016-08-30 14:01:10 -070042 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);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070047 }
48#endif
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080049 }
50
51 virtual ~TileIndependenceTest() {
52 delete fw_dec_;
53 delete inv_dec_;
54 }
55
56 virtual void SetUp() {
57 InitializeConfig();
Yaowu Xuc27fc142016-08-22 16:08:15 -070058 SetMode(libaom_test::kTwoPassGood);
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080059 }
60
Yaowu Xuc27fc142016-08-22 16:08:15 -070061 virtual void PreEncodeFrameHook(libaom_test::VideoSource *video,
62 libaom_test::Encoder *encoder) {
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080063 if (video->frame() == 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -070064 encoder->Control(AV1E_SET_TILE_COLUMNS, n_tile_cols_);
65 encoder->Control(AV1E_SET_TILE_ROWS, n_tile_rows_);
Ryan Lei9b02b0e2017-01-30 15:52:20 -080066#if CONFIG_LOOPFILTERING_ACROSS_TILES
Lei7bb501d2017-12-13 15:10:34 -080067#if CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
68 encoder->Control(AV1E_SET_TILE_LOOPFILTER_V, 0);
69 encoder->Control(AV1E_SET_TILE_LOOPFILTER_H, 0);
70#else
Ryan Lei7386eda2016-12-08 21:08:31 -080071 encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0);
Lei7bb501d2017-12-13 15:10:34 -080072#endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
Ryan Lei9b02b0e2017-01-30 15:52:20 -080073#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Debargha Mukherjee6abddf32016-06-14 14:50:30 -070074 SetCpuUsed(encoder);
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080075 }
76 }
77
Yaowu Xuc27fc142016-08-22 16:08:15 -070078 virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
Debargha Mukherjee6abddf32016-06-14 14:50:30 -070079 static const int kCpuUsed = 3;
Yaowu Xuf883b422016-08-30 14:01:10 -070080 encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
Debargha Mukherjee6abddf32016-06-14 14:50:30 -070081 }
82
Yaowu Xuf883b422016-08-30 14:01:10 -070083 void UpdateMD5(::libaom_test::Decoder *dec, const aom_codec_cx_pkt_t *pkt,
Yaowu Xuc27fc142016-08-22 16:08:15 -070084 ::libaom_test::MD5 *md5) {
Yaowu Xuf883b422016-08-30 14:01:10 -070085 const aom_codec_err_t res = dec->DecodeFrame(
clang-format3a826f12016-08-11 17:46:05 -070086 reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
Yaowu Xuf883b422016-08-30 14:01:10 -070087 if (res != AOM_CODEC_OK) {
James Zern2b1a0b62013-05-06 11:45:03 -070088 abort_ = true;
Yaowu Xuf883b422016-08-30 14:01:10 -070089 ASSERT_EQ(AOM_CODEC_OK, res);
James Zern2b1a0b62013-05-06 11:45:03 -070090 }
Yaowu Xuf883b422016-08-30 14:01:10 -070091 const aom_image_t *img = dec->GetDxData().Next();
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080092 md5->Add(img);
93 }
94
Yaowu Xuf883b422016-08-30 14:01:10 -070095 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080096 UpdateMD5(fw_dec_, pkt, &md5_fw_order_);
97 UpdateMD5(inv_dec_, pkt, &md5_inv_order_);
98 }
99
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700100 void DoTest() {
Yaowu Xuf883b422016-08-30 14:01:10 -0700101 const aom_rational timebase = { 33333333, 1000000000 };
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700102 cfg_.g_timebase = timebase;
103 cfg_.rc_target_bitrate = 500;
104 cfg_.g_lag_in_frames = 12;
Yaowu Xuf883b422016-08-30 14:01:10 -0700105 cfg_.rc_end_usage = AOM_VBR;
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700106
Yaowu Xuc27fc142016-08-22 16:08:15 -0700107 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 576,
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700108 timebase.den, timebase.num, 0, 5);
109 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
110
111 const char *md5_fw_str = md5_fw_order_.Get();
112 const char *md5_inv_str = md5_inv_order_.Get();
113 ASSERT_STREQ(md5_fw_str, md5_inv_str);
114 }
115
Yaowu Xuc27fc142016-08-22 16:08:15 -0700116 ::libaom_test::MD5 md5_fw_order_, md5_inv_order_;
117 ::libaom_test::Decoder *fw_dec_, *inv_dec_;
James Zernbae31172013-07-18 14:37:53 -0700118
119 private:
Geza Lore1982d672016-05-03 13:55:25 +0100120 int n_tile_cols_;
121 int n_tile_rows_;
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800122};
123
124// run an encode with 2 or 4 tiles, and do the decode both in normal and
125// inverted tile ordering. Ensure that the MD5 of the output in both cases
126// is identical. If so, tiles are considered independent and the test passes.
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700127TEST_P(TileIndependenceTest, MD5Match) {
128#if CONFIG_EXT_TILE
129 cfg_.large_scale_tile = 0;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800130 fw_dec_->Control(AV1_SET_TILE_MODE, 0);
131 inv_dec_->Control(AV1_SET_TILE_MODE, 0);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700132#endif // CONFIG_EXT_TILE
133 DoTest();
134}
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800135
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700136class TileIndependenceTestLarge : public TileIndependenceTest {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700137 virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700138 static const int kCpuUsed = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -0700139 encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700140 }
141};
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800142
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700143TEST_P(TileIndependenceTestLarge, MD5Match) {
Geza Lore67a2ff72016-05-03 11:53:55 +0100144#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700145 cfg_.large_scale_tile = 0;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800146 fw_dec_->Control(AV1_SET_TILE_MODE, 0);
147 inv_dec_->Control(AV1_SET_TILE_MODE, 0);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700148#endif // CONFIG_EXT_TILE
149 DoTest();
150}
151
Yaowu Xuf883b422016-08-30 14:01:10 -0700152AV1_INSTANTIATE_TEST_CASE(TileIndependenceTest, ::testing::Values(0, 1),
153 ::testing::Values(0, 1));
154AV1_INSTANTIATE_TEST_CASE(TileIndependenceTestLarge, ::testing::Values(0, 1),
155 ::testing::Values(0, 1));
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700156
157#if CONFIG_EXT_TILE
158class TileIndependenceLSTest : public TileIndependenceTest {};
159
Yunqing Wangce796ed2018-01-17 10:16:33 -0800160TEST_P(TileIndependenceLSTest, DISABLED_MD5Match) {
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700161 cfg_.large_scale_tile = 1;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800162 fw_dec_->Control(AV1_SET_TILE_MODE, 1);
163 inv_dec_->Control(AV1_SET_TILE_MODE, 1);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700164 DoTest();
165}
166
167class TileIndependenceLSTestLarge : public TileIndependenceTestLarge {};
168
Yunqing Wangce796ed2018-01-17 10:16:33 -0800169TEST_P(TileIndependenceLSTestLarge, DISABLED_MD5Match) {
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700170 cfg_.large_scale_tile = 1;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800171 fw_dec_->Control(AV1_SET_TILE_MODE, 1);
172 inv_dec_->Control(AV1_SET_TILE_MODE, 1);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700173 DoTest();
174}
175
176AV1_INSTANTIATE_TEST_CASE(TileIndependenceLSTest, ::testing::Values(1, 2, 32),
177 ::testing::Values(1, 2, 32));
178AV1_INSTANTIATE_TEST_CASE(TileIndependenceLSTestLarge,
179 ::testing::Values(1, 2, 32),
180 ::testing::Values(1, 2, 32));
Geza Lore67a2ff72016-05-03 11:53:55 +0100181#endif // CONFIG_EXT_TILE
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800182} // namespace