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 <assert.h>
13*77c1e3ccSAndroid Build Coastguard Worker #include <string>
14*77c1e3ccSAndroid Build Coastguard Worker #include <vector>
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/md5_helper.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
21*77c1e3ccSAndroid Build Coastguard Worker
22*77c1e3ccSAndroid Build Coastguard Worker namespace {
23*77c1e3ccSAndroid Build Coastguard Worker // The number of frames to be encoded/decoded
24*77c1e3ccSAndroid Build Coastguard Worker const int kLimit = 8;
25*77c1e3ccSAndroid Build Coastguard Worker // Skip 1 frame to check the frame decoding independency.
26*77c1e3ccSAndroid Build Coastguard Worker const int kSkip = 5;
27*77c1e3ccSAndroid Build Coastguard Worker const int kTileSize = 1;
28*77c1e3ccSAndroid Build Coastguard Worker const int kTIleSizeInPixels = (kTileSize << 6);
29*77c1e3ccSAndroid Build Coastguard Worker // Fake width and height so that they can be multiples of the tile size.
30*77c1e3ccSAndroid Build Coastguard Worker const int kImgWidth = 704;
31*77c1e3ccSAndroid Build Coastguard Worker const int kImgHeight = 576;
32*77c1e3ccSAndroid Build Coastguard Worker
33*77c1e3ccSAndroid Build Coastguard Worker // This test tests large scale tile coding case. Non-large-scale tile coding
34*77c1e3ccSAndroid Build Coastguard Worker // is tested by the tile_independence test.
35*77c1e3ccSAndroid Build Coastguard Worker class AV1ExtTileTest
36*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
37*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
38*77c1e3ccSAndroid Build Coastguard Worker protected:
AV1ExtTileTest()39*77c1e3ccSAndroid Build Coastguard Worker AV1ExtTileTest()
40*77c1e3ccSAndroid Build Coastguard Worker : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
41*77c1e3ccSAndroid Build Coastguard Worker set_cpu_used_(GET_PARAM(2)) {
42*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
43*77c1e3ccSAndroid Build Coastguard Worker aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
44*77c1e3ccSAndroid Build Coastguard Worker cfg.w = kImgWidth;
45*77c1e3ccSAndroid Build Coastguard Worker cfg.h = kImgHeight;
46*77c1e3ccSAndroid Build Coastguard Worker cfg.allow_lowbitdepth = 1;
47*77c1e3ccSAndroid Build Coastguard Worker
48*77c1e3ccSAndroid Build Coastguard Worker decoder_ = codec_->CreateDecoder(cfg, 0);
49*77c1e3ccSAndroid Build Coastguard Worker decoder_->Control(AV1_SET_TILE_MODE, 1);
50*77c1e3ccSAndroid Build Coastguard Worker decoder_->Control(AV1D_EXT_TILE_DEBUG, 1);
51*77c1e3ccSAndroid Build Coastguard Worker decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
52*77c1e3ccSAndroid Build Coastguard Worker decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
53*77c1e3ccSAndroid Build Coastguard Worker
54*77c1e3ccSAndroid Build Coastguard Worker // Allocate buffer to store tile image.
55*77c1e3ccSAndroid Build Coastguard Worker aom_img_alloc(&tile_img_, AOM_IMG_FMT_I420, kImgWidth, kImgHeight, 32);
56*77c1e3ccSAndroid Build Coastguard Worker
57*77c1e3ccSAndroid Build Coastguard Worker md5_.clear();
58*77c1e3ccSAndroid Build Coastguard Worker tile_md5_.clear();
59*77c1e3ccSAndroid Build Coastguard Worker }
60*77c1e3ccSAndroid Build Coastguard Worker
~AV1ExtTileTest()61*77c1e3ccSAndroid Build Coastguard Worker ~AV1ExtTileTest() override {
62*77c1e3ccSAndroid Build Coastguard Worker aom_img_free(&tile_img_);
63*77c1e3ccSAndroid Build Coastguard Worker delete decoder_;
64*77c1e3ccSAndroid Build Coastguard Worker }
65*77c1e3ccSAndroid Build Coastguard Worker
SetUp()66*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
67*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(encoding_mode_);
68*77c1e3ccSAndroid Build Coastguard Worker
69*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 0;
70*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_VBR;
71*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_error_resilient = 1;
72*77c1e3ccSAndroid Build Coastguard Worker
73*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 56;
74*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 0;
75*77c1e3ccSAndroid Build Coastguard Worker }
76*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)77*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource *video,
78*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder *encoder) override {
79*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
80*77c1e3ccSAndroid Build Coastguard Worker // Encode setting
81*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
82*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
83*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
84*77c1e3ccSAndroid Build Coastguard Worker
85*77c1e3ccSAndroid Build Coastguard Worker // TODO(yunqingwang): test single_tile_decoding = 0.
86*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_SINGLE_TILE_DECODING, 1);
87*77c1e3ccSAndroid Build Coastguard Worker // Always use 64x64 max partition.
88*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_SUPERBLOCK_SIZE, AOM_SUPERBLOCK_SIZE_64X64);
89*77c1e3ccSAndroid Build Coastguard Worker // Set tile_columns and tile_rows to MAX values, which guarantees the tile
90*77c1e3ccSAndroid Build Coastguard Worker // size of 64 x 64 pixels(i.e. 1 SB) for <= 4k resolution.
91*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TILE_COLUMNS, 6);
92*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TILE_ROWS, 6);
93*77c1e3ccSAndroid Build Coastguard Worker } else if (video->frame() == 1) {
94*77c1e3ccSAndroid Build Coastguard Worker frame_flags_ =
95*77c1e3ccSAndroid Build Coastguard Worker AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF;
96*77c1e3ccSAndroid Build Coastguard Worker }
97*77c1e3ccSAndroid Build Coastguard Worker }
98*77c1e3ccSAndroid Build Coastguard Worker
DecompressedFrameHook(const aom_image_t & img,aom_codec_pts_t pts)99*77c1e3ccSAndroid Build Coastguard Worker void DecompressedFrameHook(const aom_image_t &img,
100*77c1e3ccSAndroid Build Coastguard Worker aom_codec_pts_t pts) override {
101*77c1e3ccSAndroid Build Coastguard Worker // Skip 1 already decoded frame to be consistent with the decoder in this
102*77c1e3ccSAndroid Build Coastguard Worker // test.
103*77c1e3ccSAndroid Build Coastguard Worker if (pts == (aom_codec_pts_t)kSkip) return;
104*77c1e3ccSAndroid Build Coastguard Worker
105*77c1e3ccSAndroid Build Coastguard Worker // Calculate MD5 as the reference.
106*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::MD5 md5_res;
107*77c1e3ccSAndroid Build Coastguard Worker md5_res.Add(&img);
108*77c1e3ccSAndroid Build Coastguard Worker md5_.push_back(md5_res.Get());
109*77c1e3ccSAndroid Build Coastguard Worker }
110*77c1e3ccSAndroid Build Coastguard Worker
FramePktHook(const aom_codec_cx_pkt_t * pkt)111*77c1e3ccSAndroid Build Coastguard Worker void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
112*77c1e3ccSAndroid Build Coastguard Worker // Skip decoding 1 frame.
113*77c1e3ccSAndroid Build Coastguard Worker if (pkt->data.frame.pts == (aom_codec_pts_t)kSkip) return;
114*77c1e3ccSAndroid Build Coastguard Worker
115*77c1e3ccSAndroid Build Coastguard Worker bool IsLastFrame = (pkt->data.frame.pts == (aom_codec_pts_t)(kLimit - 1));
116*77c1e3ccSAndroid Build Coastguard Worker
117*77c1e3ccSAndroid Build Coastguard Worker // Decode the first (kLimit - 1) frames as whole frame, and decode the last
118*77c1e3ccSAndroid Build Coastguard Worker // frame in single tiles.
119*77c1e3ccSAndroid Build Coastguard Worker for (int r = 0; r < kImgHeight / kTIleSizeInPixels; ++r) {
120*77c1e3ccSAndroid Build Coastguard Worker for (int c = 0; c < kImgWidth / kTIleSizeInPixels; ++c) {
121*77c1e3ccSAndroid Build Coastguard Worker if (!IsLastFrame) {
122*77c1e3ccSAndroid Build Coastguard Worker decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
123*77c1e3ccSAndroid Build Coastguard Worker decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
124*77c1e3ccSAndroid Build Coastguard Worker } else {
125*77c1e3ccSAndroid Build Coastguard Worker decoder_->Control(AV1_SET_DECODE_TILE_ROW, r);
126*77c1e3ccSAndroid Build Coastguard Worker decoder_->Control(AV1_SET_DECODE_TILE_COL, c);
127*77c1e3ccSAndroid Build Coastguard Worker }
128*77c1e3ccSAndroid Build Coastguard Worker
129*77c1e3ccSAndroid Build Coastguard Worker const aom_codec_err_t res = decoder_->DecodeFrame(
130*77c1e3ccSAndroid Build Coastguard Worker reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
131*77c1e3ccSAndroid Build Coastguard Worker pkt->data.frame.sz);
132*77c1e3ccSAndroid Build Coastguard Worker if (res != AOM_CODEC_OK) {
133*77c1e3ccSAndroid Build Coastguard Worker abort_ = true;
134*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(AOM_CODEC_OK, res);
135*77c1e3ccSAndroid Build Coastguard Worker }
136*77c1e3ccSAndroid Build Coastguard Worker const aom_image_t *img = decoder_->GetDxData().Next();
137*77c1e3ccSAndroid Build Coastguard Worker
138*77c1e3ccSAndroid Build Coastguard Worker if (!IsLastFrame) {
139*77c1e3ccSAndroid Build Coastguard Worker if (img) {
140*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::MD5 md5_res;
141*77c1e3ccSAndroid Build Coastguard Worker md5_res.Add(img);
142*77c1e3ccSAndroid Build Coastguard Worker tile_md5_.push_back(md5_res.Get());
143*77c1e3ccSAndroid Build Coastguard Worker }
144*77c1e3ccSAndroid Build Coastguard Worker break;
145*77c1e3ccSAndroid Build Coastguard Worker }
146*77c1e3ccSAndroid Build Coastguard Worker
147*77c1e3ccSAndroid Build Coastguard Worker const int kMaxMBPlane = 3;
148*77c1e3ccSAndroid Build Coastguard Worker for (int plane = 0; plane < kMaxMBPlane; ++plane) {
149*77c1e3ccSAndroid Build Coastguard Worker const int shift = (plane == 0) ? 0 : 1;
150*77c1e3ccSAndroid Build Coastguard Worker int tile_height = kTIleSizeInPixels >> shift;
151*77c1e3ccSAndroid Build Coastguard Worker int tile_width = kTIleSizeInPixels >> shift;
152*77c1e3ccSAndroid Build Coastguard Worker
153*77c1e3ccSAndroid Build Coastguard Worker for (int tr = 0; tr < tile_height; ++tr) {
154*77c1e3ccSAndroid Build Coastguard Worker memcpy(tile_img_.planes[plane] +
155*77c1e3ccSAndroid Build Coastguard Worker tile_img_.stride[plane] * (r * tile_height + tr) +
156*77c1e3ccSAndroid Build Coastguard Worker c * tile_width,
157*77c1e3ccSAndroid Build Coastguard Worker img->planes[plane] + img->stride[plane] * tr, tile_width);
158*77c1e3ccSAndroid Build Coastguard Worker }
159*77c1e3ccSAndroid Build Coastguard Worker }
160*77c1e3ccSAndroid Build Coastguard Worker }
161*77c1e3ccSAndroid Build Coastguard Worker
162*77c1e3ccSAndroid Build Coastguard Worker if (!IsLastFrame) break;
163*77c1e3ccSAndroid Build Coastguard Worker }
164*77c1e3ccSAndroid Build Coastguard Worker
165*77c1e3ccSAndroid Build Coastguard Worker if (IsLastFrame) {
166*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::MD5 md5_res;
167*77c1e3ccSAndroid Build Coastguard Worker md5_res.Add(&tile_img_);
168*77c1e3ccSAndroid Build Coastguard Worker tile_md5_.push_back(md5_res.Get());
169*77c1e3ccSAndroid Build Coastguard Worker }
170*77c1e3ccSAndroid Build Coastguard Worker }
171*77c1e3ccSAndroid Build Coastguard Worker
TestRoundTrip()172*77c1e3ccSAndroid Build Coastguard Worker void TestRoundTrip() {
173*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video(
174*77c1e3ccSAndroid Build Coastguard Worker "hantro_collage_w352h288.yuv", kImgWidth, kImgHeight, 30, 1, 0, kLimit);
175*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 500;
176*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_error_resilient = AOM_ERROR_RESILIENT_DEFAULT;
177*77c1e3ccSAndroid Build Coastguard Worker cfg_.large_scale_tile = 1;
178*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 0;
179*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_threads = 1;
180*77c1e3ccSAndroid Build Coastguard Worker
181*77c1e3ccSAndroid Build Coastguard Worker // Tile encoding
182*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
183*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
184*77c1e3ccSAndroid Build Coastguard Worker
185*77c1e3ccSAndroid Build Coastguard Worker // Compare to check if two vectors are equal.
186*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(md5_, tile_md5_);
187*77c1e3ccSAndroid Build Coastguard Worker }
188*77c1e3ccSAndroid Build Coastguard Worker
189*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::TestMode encoding_mode_;
190*77c1e3ccSAndroid Build Coastguard Worker int set_cpu_used_;
191*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Decoder *decoder_;
192*77c1e3ccSAndroid Build Coastguard Worker aom_image_t tile_img_;
193*77c1e3ccSAndroid Build Coastguard Worker std::vector<std::string> md5_;
194*77c1e3ccSAndroid Build Coastguard Worker std::vector<std::string> tile_md5_;
195*77c1e3ccSAndroid Build Coastguard Worker };
196*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AV1ExtTileTest,DecoderResultTest)197*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1ExtTileTest, DecoderResultTest) { TestRoundTrip(); }
198*77c1e3ccSAndroid Build Coastguard Worker
199*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(
200*77c1e3ccSAndroid Build Coastguard Worker // Now only test 2-pass mode.
201*77c1e3ccSAndroid Build Coastguard Worker AV1ExtTileTest, ::testing::Values(::libaom_test::kTwoPassGood),
202*77c1e3ccSAndroid Build Coastguard Worker ::testing::Range(1, 4));
203*77c1e3ccSAndroid Build Coastguard Worker
204*77c1e3ccSAndroid Build Coastguard Worker class AV1ExtTileTestLarge : public AV1ExtTileTest {};
205*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AV1ExtTileTestLarge,DecoderResultTest)206*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1ExtTileTestLarge, DecoderResultTest) { TestRoundTrip(); }
207*77c1e3ccSAndroid Build Coastguard Worker
208*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(
209*77c1e3ccSAndroid Build Coastguard Worker // Now only test 2-pass mode.
210*77c1e3ccSAndroid Build Coastguard Worker AV1ExtTileTestLarge, ::testing::Values(::libaom_test::kTwoPassGood),
211*77c1e3ccSAndroid Build Coastguard Worker ::testing::Range(0, 1));
212*77c1e3ccSAndroid Build Coastguard Worker } // namespace
213