blob: 424d2f065f60958ef2d4c71ecbe9f4fab9acc886 [file] [log] [blame]
Yunqing Wang8e5e3382016-05-05 16:42:57 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yunqing Wang8e5e3382016-05-05 16:42:57 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * 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.
Yunqing Wang8e5e3382016-05-05 16:42:57 -070010 */
11
12#include <assert.h>
13#include <string>
14#include <vector>
Tom Finegan7a07ece2017-02-07 17:14:05 -080015#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Yunqing Wang8e5e3382016-05-05 16:42:57 -070016#include "test/codec_factory.h"
17#include "test/encode_test_driver.h"
18#include "test/i420_video_source.h"
19#include "test/md5_helper.h"
20#include "test/util.h"
21
22namespace {
23// The number of frames to be encoded/decoded
24const int kLimit = 8;
25// Skip 1 frame to check the frame decoding independency.
26const int kSkip = 5;
27const int kTileSize = 1;
28const int kTIleSizeInPixels = (kTileSize << 6);
29// Fake width and height so that they can be multiples of the tile size.
30const int kImgWidth = 704;
31const int kImgHeight = 576;
32
Yunqing Wangeeb08a92017-07-07 21:25:18 -070033// This test tests large scale tile coding case. Non-large-scale tile coding
34// is tested by the tile_independence test.
Yaowu Xuf883b422016-08-30 14:01:10 -070035class AV1ExtTileTest
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020036 : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
37 public ::libaom_test::EncoderTest {
Yunqing Wang8e5e3382016-05-05 16:42:57 -070038 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070039 AV1ExtTileTest()
clang-format3a826f12016-08-11 17:46:05 -070040 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
Yunqing Wang8e5e3382016-05-05 16:42:57 -070041 set_cpu_used_(GET_PARAM(2)) {
Yaowu Xuf883b422016-08-30 14:01:10 -070042 init_flags_ = AOM_CODEC_USE_PSNR;
43 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
Yunqing Wang8e5e3382016-05-05 16:42:57 -070044 cfg.w = kImgWidth;
45 cfg.h = kImgHeight;
Sebastien Alaiwan8a65f9f2017-06-23 07:28:44 +020046 cfg.allow_lowbitdepth = 1;
Yunqing Wang8e5e3382016-05-05 16:42:57 -070047
48 decoder_ = codec_->CreateDecoder(cfg, 0);
Yunqing Wang8ae64a92018-01-12 12:26:44 -080049 decoder_->Control(AV1_SET_TILE_MODE, 1);
Yunqing Wangce8f4812018-06-25 15:17:44 -070050 decoder_->Control(AV1D_EXT_TILE_DEBUG, 1);
Yaowu Xuf883b422016-08-30 14:01:10 -070051 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
52 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070053
54 // Allocate buffer to store tile image.
Yaowu Xuf883b422016-08-30 14:01:10 -070055 aom_img_alloc(&tile_img_, AOM_IMG_FMT_I420, kImgWidth, kImgHeight, 32);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070056
57 md5_.clear();
58 tile_md5_.clear();
59 }
60
Yaowu Xuf883b422016-08-30 14:01:10 -070061 virtual ~AV1ExtTileTest() {
62 aom_img_free(&tile_img_);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070063 delete decoder_;
64 }
65
66 virtual void SetUp() {
67 InitializeConfig();
68 SetMode(encoding_mode_);
69
70 cfg_.g_lag_in_frames = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070071 cfg_.rc_end_usage = AOM_VBR;
Yunqing Wang8e5e3382016-05-05 16:42:57 -070072 cfg_.g_error_resilient = 1;
73
74 cfg_.rc_max_quantizer = 56;
75 cfg_.rc_min_quantizer = 0;
76 }
77
Yaowu Xuc27fc142016-08-22 16:08:15 -070078 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
79 ::libaom_test::Encoder *encoder) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -070080 if (video->frame() == 0) {
81 // Encode setting
Yaowu Xuf883b422016-08-30 14:01:10 -070082 encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
83 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
84 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070085
Yunqing Wangeeb08a92017-07-07 21:25:18 -070086 // TODO(yunqingwang): test single_tile_decoding = 0.
87 encoder->Control(AV1E_SET_SINGLE_TILE_DECODING, 1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070088 // Always use 64x64 max partition.
Yaowu Xuf883b422016-08-30 14:01:10 -070089 encoder->Control(AV1E_SET_SUPERBLOCK_SIZE, AOM_SUPERBLOCK_SIZE_64X64);
Yunqing Wangce8f4812018-06-25 15:17:44 -070090 // Set tile_columns and tile_rows to MAX values, which guarantees the tile
91 // size of 64 x 64 pixels(i.e. 1 SB) for <= 4k resolution.
92 encoder->Control(AV1E_SET_TILE_COLUMNS, 6);
93 encoder->Control(AV1E_SET_TILE_ROWS, 6);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070094 }
95
96 if (video->frame() == 1) {
clang-format3a826f12016-08-11 17:46:05 -070097 frame_flags_ =
Yaowu Xuf883b422016-08-30 14:01:10 -070098 AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF;
Yunqing Wang8e5e3382016-05-05 16:42:57 -070099 }
100 }
101
Yaowu Xuf883b422016-08-30 14:01:10 -0700102 virtual void DecompressedFrameHook(const aom_image_t &img,
103 aom_codec_pts_t pts) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700104 // Skip 1 already decoded frame to be consistent with the decoder in this
105 // test.
Yaowu Xuf883b422016-08-30 14:01:10 -0700106 if (pts == (aom_codec_pts_t)kSkip) return;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700107
108 // Calculate MD5 as the reference.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700109 ::libaom_test::MD5 md5_res;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700110 md5_res.Add(&img);
111 md5_.push_back(md5_res.Get());
112 }
113
Yaowu Xuf883b422016-08-30 14:01:10 -0700114 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700115 // Skip decoding 1 frame.
Yaowu Xuf883b422016-08-30 14:01:10 -0700116 if (pkt->data.frame.pts == (aom_codec_pts_t)kSkip) return;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700117
Yaowu Xuf883b422016-08-30 14:01:10 -0700118 bool IsLastFrame = (pkt->data.frame.pts == (aom_codec_pts_t)(kLimit - 1));
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700119
120 // Decode the first (kLimit - 1) frames as whole frame, and decode the last
121 // frame in single tiles.
122 for (int r = 0; r < kImgHeight / kTIleSizeInPixels; ++r) {
123 for (int c = 0; c < kImgWidth / kTIleSizeInPixels; ++c) {
124 if (!IsLastFrame) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700125 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
126 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700127 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700128 decoder_->Control(AV1_SET_DECODE_TILE_ROW, r);
129 decoder_->Control(AV1_SET_DECODE_TILE_COL, c);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700130 }
131
Yaowu Xuf883b422016-08-30 14:01:10 -0700132 const aom_codec_err_t res = decoder_->DecodeFrame(
clang-format3a826f12016-08-11 17:46:05 -0700133 reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700134 pkt->data.frame.sz);
Yaowu Xuf883b422016-08-30 14:01:10 -0700135 if (res != AOM_CODEC_OK) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700136 abort_ = true;
Yaowu Xuf883b422016-08-30 14:01:10 -0700137 ASSERT_EQ(AOM_CODEC_OK, res);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700138 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700139 const aom_image_t *img = decoder_->GetDxData().Next();
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700140
141 if (!IsLastFrame) {
142 if (img) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700143 ::libaom_test::MD5 md5_res;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700144 md5_res.Add(img);
145 tile_md5_.push_back(md5_res.Get());
146 }
147 break;
148 }
149
150 const int kMaxMBPlane = 3;
151 for (int plane = 0; plane < kMaxMBPlane; ++plane) {
152 const int shift = (plane == 0) ? 0 : 1;
153 int tile_height = kTIleSizeInPixels >> shift;
154 int tile_width = kTIleSizeInPixels >> shift;
155
156 for (int tr = 0; tr < tile_height; ++tr) {
157 memcpy(tile_img_.planes[plane] +
clang-format3a826f12016-08-11 17:46:05 -0700158 tile_img_.stride[plane] * (r * tile_height + tr) +
159 c * tile_width,
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700160 img->planes[plane] + img->stride[plane] * tr, tile_width);
161 }
162 }
163 }
164
clang-format3a826f12016-08-11 17:46:05 -0700165 if (!IsLastFrame) break;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700166 }
167
Jingning Hane8164012016-05-19 09:25:38 -0700168 if (IsLastFrame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700169 ::libaom_test::MD5 md5_res;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700170 md5_res.Add(&tile_img_);
171 tile_md5_.push_back(md5_res.Get());
172 }
173 }
174
James Zern502bf9c2018-03-12 20:14:00 -0700175 void TestRoundTrip() {
176 ::libaom_test::I420VideoSource video(
177 "hantro_collage_w352h288.yuv", kImgWidth, kImgHeight, 30, 1, 0, kLimit);
178 cfg_.rc_target_bitrate = 500;
179 cfg_.g_error_resilient = AOM_ERROR_RESILIENT_DEFAULT;
180 cfg_.large_scale_tile = 1;
181 cfg_.g_lag_in_frames = 0;
182 cfg_.g_threads = 1;
183
184 // Tile encoding
185 init_flags_ = AOM_CODEC_USE_PSNR;
186 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
187
188 // Compare to check if two vectors are equal.
189 ASSERT_EQ(md5_, tile_md5_);
190 }
191
Yaowu Xuc27fc142016-08-22 16:08:15 -0700192 ::libaom_test::TestMode encoding_mode_;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700193 int set_cpu_used_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700194 ::libaom_test::Decoder *decoder_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700195 aom_image_t tile_img_;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700196 std::vector<std::string> md5_;
197 std::vector<std::string> tile_md5_;
198};
199
Yunqing Wangce8f4812018-06-25 15:17:44 -0700200TEST_P(AV1ExtTileTest, DecoderResultTest) { TestRoundTrip(); }
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700201
Yaowu Xuf883b422016-08-30 14:01:10 -0700202AV1_INSTANTIATE_TEST_CASE(
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700203 // Now only test 2-pass mode.
Yaowu Xuf883b422016-08-30 14:01:10 -0700204 AV1ExtTileTest, ::testing::Values(::libaom_test::kTwoPassGood),
James Zern502bf9c2018-03-12 20:14:00 -0700205 ::testing::Range(1, 4));
206
207class AV1ExtTileTestLarge : public AV1ExtTileTest {};
208
Yunqing Wangce8f4812018-06-25 15:17:44 -0700209TEST_P(AV1ExtTileTestLarge, DecoderResultTest) { TestRoundTrip(); }
James Zern502bf9c2018-03-12 20:14:00 -0700210
211AV1_INSTANTIATE_TEST_CASE(
212 // Now only test 2-pass mode.
213 AV1ExtTileTestLarge, ::testing::Values(::libaom_test::kTwoPassGood),
214 ::testing::Range(0, 1));
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700215} // namespace