Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Frank Galligan | 38536f6 | 2013-12-12 08:36:34 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
| 10 | */ |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 11 | |
| 12 | #include <cstdio> |
| 13 | #include <cstdlib> |
| 14 | #include <string> |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 15 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 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" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 21 | #include "aom_mem/aom_mem.h" |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 22 | |
| 23 | namespace { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 24 | class TileIndependenceTest |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 25 | : public ::libaom_test::CodecTestWith2Params<int, int>, |
| 26 | public ::libaom_test::EncoderTest { |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 27 | protected: |
James Zern | bae3117 | 2013-07-18 14:37:53 -0700 | [diff] [blame] | 28 | TileIndependenceTest() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 29 | : EncoderTest(GET_PARAM(0)), md5_fw_order_(), md5_inv_order_(), |
| 30 | n_tile_cols_(GET_PARAM(1)), n_tile_rows_(GET_PARAM(2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 31 | init_flags_ = AOM_CODEC_USE_PSNR; |
| 32 | aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t(); |
Ronald S. Bultje | f496f60 | 2013-02-06 15:30:21 -0800 | [diff] [blame] | 33 | cfg.w = 704; |
| 34 | cfg.h = 144; |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 35 | cfg.threads = 1; |
Sebastien Alaiwan | 8a65f9f | 2017-06-23 07:28:44 +0200 | [diff] [blame] | 36 | cfg.allow_lowbitdepth = 1; |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 37 | fw_dec_ = codec_->CreateDecoder(cfg, 0); |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 38 | inv_dec_ = codec_->CreateDecoder(cfg, 0); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 39 | inv_dec_->Control(AV1_INVERT_TILE_DECODE_ORDER, 1); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 40 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 41 | #if CONFIG_AV1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 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); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 47 | } |
| 48 | #endif |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | virtual ~TileIndependenceTest() { |
| 52 | delete fw_dec_; |
| 53 | delete inv_dec_; |
| 54 | } |
| 55 | |
| 56 | virtual void SetUp() { |
| 57 | InitializeConfig(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | SetMode(libaom_test::kTwoPassGood); |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 61 | virtual void PreEncodeFrameHook(libaom_test::VideoSource *video, |
| 62 | libaom_test::Encoder *encoder) { |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 63 | if (video->frame() == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 64 | encoder->Control(AV1E_SET_TILE_COLUMNS, n_tile_cols_); |
| 65 | encoder->Control(AV1E_SET_TILE_ROWS, n_tile_rows_); |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 66 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 67 | encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0); |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 68 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 69 | SetCpuUsed(encoder); |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | virtual void SetCpuUsed(libaom_test::Encoder *encoder) { |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 74 | static const int kCpuUsed = 3; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 75 | encoder->Control(AOME_SET_CPUUSED, kCpuUsed); |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 78 | void UpdateMD5(::libaom_test::Decoder *dec, const aom_codec_cx_pkt_t *pkt, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 79 | ::libaom_test::MD5 *md5) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 80 | const aom_codec_err_t res = dec->DecodeFrame( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 81 | reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 82 | if (res != AOM_CODEC_OK) { |
James Zern | 2b1a0b6 | 2013-05-06 11:45:03 -0700 | [diff] [blame] | 83 | abort_ = true; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 84 | ASSERT_EQ(AOM_CODEC_OK, res); |
James Zern | 2b1a0b6 | 2013-05-06 11:45:03 -0700 | [diff] [blame] | 85 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 86 | const aom_image_t *img = dec->GetDxData().Next(); |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 87 | md5->Add(img); |
| 88 | } |
| 89 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 90 | virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) { |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 91 | UpdateMD5(fw_dec_, pkt, &md5_fw_order_); |
| 92 | UpdateMD5(inv_dec_, pkt, &md5_inv_order_); |
| 93 | } |
| 94 | |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 95 | void DoTest() { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | const aom_rational timebase = { 33333333, 1000000000 }; |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 97 | cfg_.g_timebase = timebase; |
| 98 | cfg_.rc_target_bitrate = 500; |
| 99 | cfg_.g_lag_in_frames = 12; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 100 | cfg_.rc_end_usage = AOM_VBR; |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 101 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 102 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 576, |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 103 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 111 | ::libaom_test::MD5 md5_fw_order_, md5_inv_order_; |
| 112 | ::libaom_test::Decoder *fw_dec_, *inv_dec_; |
James Zern | bae3117 | 2013-07-18 14:37:53 -0700 | [diff] [blame] | 113 | |
| 114 | private: |
Geza Lore | 1982d67 | 2016-05-03 13:55:25 +0100 | [diff] [blame] | 115 | int n_tile_cols_; |
| 116 | int n_tile_rows_; |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 117 | }; |
| 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 Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 122 | TEST_P(TileIndependenceTest, MD5Match) { |
| 123 | #if CONFIG_EXT_TILE |
| 124 | cfg_.large_scale_tile = 0; |
| 125 | #endif // CONFIG_EXT_TILE |
| 126 | DoTest(); |
| 127 | } |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 128 | |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 129 | class TileIndependenceTestLarge : public TileIndependenceTest { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 130 | virtual void SetCpuUsed(libaom_test::Encoder *encoder) { |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 131 | static const int kCpuUsed = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 132 | encoder->Control(AOME_SET_CPUUSED, kCpuUsed); |
Debargha Mukherjee | 6abddf3 | 2016-06-14 14:50:30 -0700 | [diff] [blame] | 133 | } |
| 134 | }; |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 135 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 136 | TEST_P(TileIndependenceTestLarge, MD5Match) { |
Geza Lore | 67a2ff7 | 2016-05-03 11:53:55 +0100 | [diff] [blame] | 137 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 138 | cfg_.large_scale_tile = 0; |
| 139 | #endif // CONFIG_EXT_TILE |
| 140 | DoTest(); |
| 141 | } |
| 142 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 143 | AV1_INSTANTIATE_TEST_CASE(TileIndependenceTest, ::testing::Values(0, 1), |
| 144 | ::testing::Values(0, 1)); |
| 145 | AV1_INSTANTIATE_TEST_CASE(TileIndependenceTestLarge, ::testing::Values(0, 1), |
| 146 | ::testing::Values(0, 1)); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 147 | |
| 148 | #if CONFIG_EXT_TILE |
| 149 | class TileIndependenceLSTest : public TileIndependenceTest {}; |
| 150 | |
| 151 | TEST_P(TileIndependenceLSTest, MD5Match) { |
| 152 | cfg_.large_scale_tile = 1; |
| 153 | DoTest(); |
| 154 | } |
| 155 | |
| 156 | class TileIndependenceLSTestLarge : public TileIndependenceTestLarge {}; |
| 157 | |
| 158 | TEST_P(TileIndependenceLSTestLarge, MD5Match) { |
| 159 | cfg_.large_scale_tile = 1; |
| 160 | DoTest(); |
| 161 | } |
| 162 | |
| 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)); |
Geza Lore | 67a2ff7 | 2016-05-03 11:53:55 +0100 | [diff] [blame] | 168 | #endif // CONFIG_EXT_TILE |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 169 | } // namespace |