blob: 832227fb8ad03056579b779f3c755126ac06e7b4 [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
Ryan Lei7386eda2016-12-08 21:08:31 -080067 encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0);
Ryan Lei9b02b0e2017-01-30 15:52:20 -080068#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Debargha Mukherjee6abddf32016-06-14 14:50:30 -070069 SetCpuUsed(encoder);
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080070 }
71 }
72
Yaowu Xuc27fc142016-08-22 16:08:15 -070073 virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
Debargha Mukherjee6abddf32016-06-14 14:50:30 -070074 static const int kCpuUsed = 3;
Yaowu Xuf883b422016-08-30 14:01:10 -070075 encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
Debargha Mukherjee6abddf32016-06-14 14:50:30 -070076 }
77
Yaowu Xuf883b422016-08-30 14:01:10 -070078 void UpdateMD5(::libaom_test::Decoder *dec, const aom_codec_cx_pkt_t *pkt,
Yaowu Xuc27fc142016-08-22 16:08:15 -070079 ::libaom_test::MD5 *md5) {
Yaowu Xuf883b422016-08-30 14:01:10 -070080 const aom_codec_err_t res = dec->DecodeFrame(
clang-format3a826f12016-08-11 17:46:05 -070081 reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
Yaowu Xuf883b422016-08-30 14:01:10 -070082 if (res != AOM_CODEC_OK) {
James Zern2b1a0b62013-05-06 11:45:03 -070083 abort_ = true;
Yaowu Xuf883b422016-08-30 14:01:10 -070084 ASSERT_EQ(AOM_CODEC_OK, res);
James Zern2b1a0b62013-05-06 11:45:03 -070085 }
Yaowu Xuf883b422016-08-30 14:01:10 -070086 const aom_image_t *img = dec->GetDxData().Next();
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080087 md5->Add(img);
88 }
89
Yaowu Xuf883b422016-08-30 14:01:10 -070090 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080091 UpdateMD5(fw_dec_, pkt, &md5_fw_order_);
92 UpdateMD5(inv_dec_, pkt, &md5_inv_order_);
93 }
94
Debargha Mukherjee6abddf32016-06-14 14:50:30 -070095 void DoTest() {
Yaowu Xuf883b422016-08-30 14:01:10 -070096 const aom_rational timebase = { 33333333, 1000000000 };
Debargha Mukherjee6abddf32016-06-14 14:50:30 -070097 cfg_.g_timebase = timebase;
98 cfg_.rc_target_bitrate = 500;
99 cfg_.g_lag_in_frames = 12;
Yaowu Xuf883b422016-08-30 14:01:10 -0700100 cfg_.rc_end_usage = AOM_VBR;
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700101
Yaowu Xuc27fc142016-08-22 16:08:15 -0700102 libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 576,
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700103 timebase.den, timebase.num, 0, 5);
104 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
105
106 const char *md5_fw_str = md5_fw_order_.Get();
107 const char *md5_inv_str = md5_inv_order_.Get();
108 ASSERT_STREQ(md5_fw_str, md5_inv_str);
109 }
110
Yaowu Xuc27fc142016-08-22 16:08:15 -0700111 ::libaom_test::MD5 md5_fw_order_, md5_inv_order_;
112 ::libaom_test::Decoder *fw_dec_, *inv_dec_;
James Zernbae31172013-07-18 14:37:53 -0700113
114 private:
Geza Lore1982d672016-05-03 13:55:25 +0100115 int n_tile_cols_;
116 int n_tile_rows_;
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800117};
118
119// run an encode with 2 or 4 tiles, and do the decode both in normal and
120// inverted tile ordering. Ensure that the MD5 of the output in both cases
121// is identical. If so, tiles are considered independent and the test passes.
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700122TEST_P(TileIndependenceTest, MD5Match) {
123#if CONFIG_EXT_TILE
124 cfg_.large_scale_tile = 0;
125#endif // CONFIG_EXT_TILE
126 DoTest();
127}
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800128
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700129class TileIndependenceTestLarge : public TileIndependenceTest {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700130 virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700131 static const int kCpuUsed = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -0700132 encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
Debargha Mukherjee6abddf32016-06-14 14:50:30 -0700133 }
134};
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800135
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700136TEST_P(TileIndependenceTestLarge, MD5Match) {
Geza Lore67a2ff72016-05-03 11:53:55 +0100137#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700138 cfg_.large_scale_tile = 0;
139#endif // CONFIG_EXT_TILE
140 DoTest();
141}
142
Yaowu Xuf883b422016-08-30 14:01:10 -0700143AV1_INSTANTIATE_TEST_CASE(TileIndependenceTest, ::testing::Values(0, 1),
144 ::testing::Values(0, 1));
145AV1_INSTANTIATE_TEST_CASE(TileIndependenceTestLarge, ::testing::Values(0, 1),
146 ::testing::Values(0, 1));
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700147
148#if CONFIG_EXT_TILE
149class TileIndependenceLSTest : public TileIndependenceTest {};
150
151TEST_P(TileIndependenceLSTest, MD5Match) {
152 cfg_.large_scale_tile = 1;
153 DoTest();
154}
155
156class TileIndependenceLSTestLarge : public TileIndependenceTestLarge {};
157
158TEST_P(TileIndependenceLSTestLarge, MD5Match) {
159 cfg_.large_scale_tile = 1;
160 DoTest();
161}
162
163AV1_INSTANTIATE_TEST_CASE(TileIndependenceLSTest, ::testing::Values(1, 2, 32),
164 ::testing::Values(1, 2, 32));
165AV1_INSTANTIATE_TEST_CASE(TileIndependenceLSTestLarge,
166 ::testing::Values(1, 2, 32),
167 ::testing::Values(1, 2, 32));
Geza Lore67a2ff72016-05-03 11:53:55 +0100168#endif // CONFIG_EXT_TILE
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800169} // namespace