1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include <cstdio>
13*77c1e3ccSAndroid Build Coastguard Worker #include <cstdlib>
14*77c1e3ccSAndroid Build Coastguard Worker #include <string>
15*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "test/i420_video_source.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/md5_helper.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "aom_mem/aom_mem.h"
22*77c1e3ccSAndroid Build Coastguard Worker
23*77c1e3ccSAndroid Build Coastguard Worker namespace {
24*77c1e3ccSAndroid Build Coastguard Worker class TileIndependenceTest
25*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWith3Params<int, int, int>,
26*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
27*77c1e3ccSAndroid Build Coastguard Worker protected:
TileIndependenceTest()28*77c1e3ccSAndroid Build Coastguard Worker TileIndependenceTest()
29*77c1e3ccSAndroid Build Coastguard Worker : EncoderTest(GET_PARAM(0)), md5_fw_order_(), md5_inv_order_(),
30*77c1e3ccSAndroid Build Coastguard Worker n_tile_cols_(GET_PARAM(1)), n_tile_rows_(GET_PARAM(2)),
31*77c1e3ccSAndroid Build Coastguard Worker n_tile_groups_(GET_PARAM(3)) {
32*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
33*77c1e3ccSAndroid Build Coastguard Worker aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
34*77c1e3ccSAndroid Build Coastguard Worker cfg.w = 704;
35*77c1e3ccSAndroid Build Coastguard Worker cfg.h = 576;
36*77c1e3ccSAndroid Build Coastguard Worker cfg.threads = 1;
37*77c1e3ccSAndroid Build Coastguard Worker cfg.allow_lowbitdepth = 1;
38*77c1e3ccSAndroid Build Coastguard Worker fw_dec_ = codec_->CreateDecoder(cfg, 0);
39*77c1e3ccSAndroid Build Coastguard Worker inv_dec_ = codec_->CreateDecoder(cfg, 0);
40*77c1e3ccSAndroid Build Coastguard Worker inv_dec_->Control(AV1_INVERT_TILE_DECODE_ORDER, 1);
41*77c1e3ccSAndroid Build Coastguard Worker
42*77c1e3ccSAndroid Build Coastguard Worker if (fw_dec_->IsAV1() && inv_dec_->IsAV1()) {
43*77c1e3ccSAndroid Build Coastguard Worker fw_dec_->Control(AV1_SET_DECODE_TILE_ROW, -1);
44*77c1e3ccSAndroid Build Coastguard Worker fw_dec_->Control(AV1_SET_DECODE_TILE_COL, -1);
45*77c1e3ccSAndroid Build Coastguard Worker inv_dec_->Control(AV1_SET_DECODE_TILE_ROW, -1);
46*77c1e3ccSAndroid Build Coastguard Worker inv_dec_->Control(AV1_SET_DECODE_TILE_COL, -1);
47*77c1e3ccSAndroid Build Coastguard Worker }
48*77c1e3ccSAndroid Build Coastguard Worker }
49*77c1e3ccSAndroid Build Coastguard Worker
~TileIndependenceTest()50*77c1e3ccSAndroid Build Coastguard Worker ~TileIndependenceTest() override {
51*77c1e3ccSAndroid Build Coastguard Worker delete fw_dec_;
52*77c1e3ccSAndroid Build Coastguard Worker delete inv_dec_;
53*77c1e3ccSAndroid Build Coastguard Worker }
54*77c1e3ccSAndroid Build Coastguard Worker
SetUp()55*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override { InitializeConfig(libaom_test::kTwoPassGood); }
56*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(libaom_test::VideoSource * video,libaom_test::Encoder * encoder)57*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(libaom_test::VideoSource *video,
58*77c1e3ccSAndroid Build Coastguard Worker libaom_test::Encoder *encoder) override {
59*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
60*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TILE_COLUMNS, n_tile_cols_);
61*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TILE_ROWS, n_tile_rows_);
62*77c1e3ccSAndroid Build Coastguard Worker SetCpuUsed(encoder);
63*77c1e3ccSAndroid Build Coastguard Worker } else if (video->frame() == 3) {
64*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_NUM_TG, n_tile_groups_);
65*77c1e3ccSAndroid Build Coastguard Worker }
66*77c1e3ccSAndroid Build Coastguard Worker }
67*77c1e3ccSAndroid Build Coastguard Worker
SetCpuUsed(libaom_test::Encoder * encoder)68*77c1e3ccSAndroid Build Coastguard Worker virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
69*77c1e3ccSAndroid Build Coastguard Worker static const int kCpuUsed = 3;
70*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
71*77c1e3ccSAndroid Build Coastguard Worker }
72*77c1e3ccSAndroid Build Coastguard Worker
UpdateMD5(::libaom_test::Decoder * dec,const aom_codec_cx_pkt_t * pkt,::libaom_test::MD5 * md5)73*77c1e3ccSAndroid Build Coastguard Worker void UpdateMD5(::libaom_test::Decoder *dec, const aom_codec_cx_pkt_t *pkt,
74*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::MD5 *md5) {
75*77c1e3ccSAndroid Build Coastguard Worker const aom_codec_err_t res = dec->DecodeFrame(
76*77c1e3ccSAndroid Build Coastguard Worker reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
77*77c1e3ccSAndroid Build Coastguard Worker if (res != AOM_CODEC_OK) {
78*77c1e3ccSAndroid Build Coastguard Worker abort_ = true;
79*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(AOM_CODEC_OK, res);
80*77c1e3ccSAndroid Build Coastguard Worker }
81*77c1e3ccSAndroid Build Coastguard Worker const aom_image_t *img = dec->GetDxData().Next();
82*77c1e3ccSAndroid Build Coastguard Worker md5->Add(img);
83*77c1e3ccSAndroid Build Coastguard Worker }
84*77c1e3ccSAndroid Build Coastguard Worker
FramePktHook(const aom_codec_cx_pkt_t * pkt)85*77c1e3ccSAndroid Build Coastguard Worker void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
86*77c1e3ccSAndroid Build Coastguard Worker UpdateMD5(fw_dec_, pkt, &md5_fw_order_);
87*77c1e3ccSAndroid Build Coastguard Worker UpdateMD5(inv_dec_, pkt, &md5_inv_order_);
88*77c1e3ccSAndroid Build Coastguard Worker }
89*77c1e3ccSAndroid Build Coastguard Worker
DoTest()90*77c1e3ccSAndroid Build Coastguard Worker void DoTest() {
91*77c1e3ccSAndroid Build Coastguard Worker const aom_rational timebase = { 33333333, 1000000000 };
92*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_timebase = timebase;
93*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 500;
94*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 12;
95*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_VBR;
96*77c1e3ccSAndroid Build Coastguard Worker
97*77c1e3ccSAndroid Build Coastguard Worker libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 576,
98*77c1e3ccSAndroid Build Coastguard Worker timebase.den, timebase.num, 0, 5);
99*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
100*77c1e3ccSAndroid Build Coastguard Worker
101*77c1e3ccSAndroid Build Coastguard Worker const char *md5_fw_str = md5_fw_order_.Get();
102*77c1e3ccSAndroid Build Coastguard Worker const char *md5_inv_str = md5_inv_order_.Get();
103*77c1e3ccSAndroid Build Coastguard Worker ASSERT_STREQ(md5_fw_str, md5_inv_str);
104*77c1e3ccSAndroid Build Coastguard Worker }
105*77c1e3ccSAndroid Build Coastguard Worker
106*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::MD5 md5_fw_order_, md5_inv_order_;
107*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Decoder *fw_dec_, *inv_dec_;
108*77c1e3ccSAndroid Build Coastguard Worker
109*77c1e3ccSAndroid Build Coastguard Worker private:
110*77c1e3ccSAndroid Build Coastguard Worker int n_tile_cols_;
111*77c1e3ccSAndroid Build Coastguard Worker int n_tile_rows_;
112*77c1e3ccSAndroid Build Coastguard Worker int n_tile_groups_;
113*77c1e3ccSAndroid Build Coastguard Worker };
114*77c1e3ccSAndroid Build Coastguard Worker
115*77c1e3ccSAndroid Build Coastguard Worker // run an encode with 2 or 4 tiles, and do the decode both in normal and
116*77c1e3ccSAndroid Build Coastguard Worker // inverted tile ordering. Ensure that the MD5 of the output in both cases
117*77c1e3ccSAndroid Build Coastguard Worker // is identical. If so, tiles are considered independent and the test passes.
TEST_P(TileIndependenceTest,MD5Match)118*77c1e3ccSAndroid Build Coastguard Worker TEST_P(TileIndependenceTest, MD5Match) {
119*77c1e3ccSAndroid Build Coastguard Worker cfg_.large_scale_tile = 0;
120*77c1e3ccSAndroid Build Coastguard Worker fw_dec_->Control(AV1_SET_TILE_MODE, 0);
121*77c1e3ccSAndroid Build Coastguard Worker inv_dec_->Control(AV1_SET_TILE_MODE, 0);
122*77c1e3ccSAndroid Build Coastguard Worker DoTest();
123*77c1e3ccSAndroid Build Coastguard Worker }
124*77c1e3ccSAndroid Build Coastguard Worker
125*77c1e3ccSAndroid Build Coastguard Worker class TileIndependenceTestLarge : public TileIndependenceTest {
SetCpuUsed(libaom_test::Encoder * encoder)126*77c1e3ccSAndroid Build Coastguard Worker void SetCpuUsed(libaom_test::Encoder *encoder) override {
127*77c1e3ccSAndroid Build Coastguard Worker static const int kCpuUsed = 0;
128*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
129*77c1e3ccSAndroid Build Coastguard Worker }
130*77c1e3ccSAndroid Build Coastguard Worker };
131*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(TileIndependenceTestLarge,MD5Match)132*77c1e3ccSAndroid Build Coastguard Worker TEST_P(TileIndependenceTestLarge, MD5Match) {
133*77c1e3ccSAndroid Build Coastguard Worker cfg_.large_scale_tile = 0;
134*77c1e3ccSAndroid Build Coastguard Worker fw_dec_->Control(AV1_SET_TILE_MODE, 0);
135*77c1e3ccSAndroid Build Coastguard Worker inv_dec_->Control(AV1_SET_TILE_MODE, 0);
136*77c1e3ccSAndroid Build Coastguard Worker DoTest();
137*77c1e3ccSAndroid Build Coastguard Worker }
138*77c1e3ccSAndroid Build Coastguard Worker
139*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(TileIndependenceTest, ::testing::Values(0, 1),
140*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(0, 1), ::testing::Values(1, 2, 4));
141*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(TileIndependenceTestLarge, ::testing::Values(0, 1),
142*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(0, 1), ::testing::Values(1, 2, 4));
143*77c1e3ccSAndroid Build Coastguard Worker
144*77c1e3ccSAndroid Build Coastguard Worker class TileIndependenceLSTest : public TileIndependenceTest {};
145*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(TileIndependenceLSTest,MD5Match)146*77c1e3ccSAndroid Build Coastguard Worker TEST_P(TileIndependenceLSTest, MD5Match) {
147*77c1e3ccSAndroid Build Coastguard Worker cfg_.large_scale_tile = 1;
148*77c1e3ccSAndroid Build Coastguard Worker fw_dec_->Control(AV1_SET_TILE_MODE, 1);
149*77c1e3ccSAndroid Build Coastguard Worker fw_dec_->Control(AV1D_EXT_TILE_DEBUG, 1);
150*77c1e3ccSAndroid Build Coastguard Worker inv_dec_->Control(AV1_SET_TILE_MODE, 1);
151*77c1e3ccSAndroid Build Coastguard Worker inv_dec_->Control(AV1D_EXT_TILE_DEBUG, 1);
152*77c1e3ccSAndroid Build Coastguard Worker DoTest();
153*77c1e3ccSAndroid Build Coastguard Worker }
154*77c1e3ccSAndroid Build Coastguard Worker
155*77c1e3ccSAndroid Build Coastguard Worker class TileIndependenceLSTestLarge : public TileIndependenceTestLarge {};
156*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(TileIndependenceLSTestLarge,MD5Match)157*77c1e3ccSAndroid Build Coastguard Worker TEST_P(TileIndependenceLSTestLarge, MD5Match) {
158*77c1e3ccSAndroid Build Coastguard Worker cfg_.large_scale_tile = 1;
159*77c1e3ccSAndroid Build Coastguard Worker fw_dec_->Control(AV1_SET_TILE_MODE, 1);
160*77c1e3ccSAndroid Build Coastguard Worker fw_dec_->Control(AV1D_EXT_TILE_DEBUG, 1);
161*77c1e3ccSAndroid Build Coastguard Worker inv_dec_->Control(AV1_SET_TILE_MODE, 1);
162*77c1e3ccSAndroid Build Coastguard Worker inv_dec_->Control(AV1D_EXT_TILE_DEBUG, 1);
163*77c1e3ccSAndroid Build Coastguard Worker DoTest();
164*77c1e3ccSAndroid Build Coastguard Worker }
165*77c1e3ccSAndroid Build Coastguard Worker
166*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(TileIndependenceLSTest, ::testing::Values(6),
167*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(6), ::testing::Values(1));
168*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(TileIndependenceLSTestLarge, ::testing::Values(6),
169*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(6), ::testing::Values(1));
170*77c1e3ccSAndroid Build Coastguard Worker } // namespace
171