blob: 679a6ed917d6e9a864a272db938b276e2964afa7 [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>
15#include "third_party/googletest/src/include/gtest/gtest.h"
16#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
Yaowu Xuf883b422016-08-30 14:01:10 -070033class AV1ExtTileTest
Yaowu Xuc27fc142016-08-22 16:08:15 -070034 : public ::libaom_test::EncoderTest,
35 public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> {
Yunqing Wang8e5e3382016-05-05 16:42:57 -070036 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070037 AV1ExtTileTest()
clang-format3a826f12016-08-11 17:46:05 -070038 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
Yunqing Wang8e5e3382016-05-05 16:42:57 -070039 set_cpu_used_(GET_PARAM(2)) {
Yaowu Xuf883b422016-08-30 14:01:10 -070040 init_flags_ = AOM_CODEC_USE_PSNR;
41 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
Yunqing Wang8e5e3382016-05-05 16:42:57 -070042 cfg.w = kImgWidth;
43 cfg.h = kImgHeight;
44
45 decoder_ = codec_->CreateDecoder(cfg, 0);
Yaowu Xuf883b422016-08-30 14:01:10 -070046 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
47 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070048
49 // Allocate buffer to store tile image.
Yaowu Xuf883b422016-08-30 14:01:10 -070050 aom_img_alloc(&tile_img_, AOM_IMG_FMT_I420, kImgWidth, kImgHeight, 32);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070051
52 md5_.clear();
53 tile_md5_.clear();
54 }
55
Yaowu Xuf883b422016-08-30 14:01:10 -070056 virtual ~AV1ExtTileTest() {
57 aom_img_free(&tile_img_);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070058 delete decoder_;
59 }
60
61 virtual void SetUp() {
62 InitializeConfig();
63 SetMode(encoding_mode_);
64
65 cfg_.g_lag_in_frames = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070066 cfg_.rc_end_usage = AOM_VBR;
Yunqing Wang8e5e3382016-05-05 16:42:57 -070067 cfg_.g_error_resilient = 1;
68
69 cfg_.rc_max_quantizer = 56;
70 cfg_.rc_min_quantizer = 0;
71 }
72
Yaowu Xuc27fc142016-08-22 16:08:15 -070073 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
74 ::libaom_test::Encoder *encoder) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -070075 if (video->frame() == 0) {
76 // Encode setting
Yaowu Xuf883b422016-08-30 14:01:10 -070077 encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
78 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
79 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070080
81 // The tile size is 64x64.
Yaowu Xuf883b422016-08-30 14:01:10 -070082 encoder->Control(AV1E_SET_TILE_COLUMNS, kTileSize);
83 encoder->Control(AV1E_SET_TILE_ROWS, kTileSize);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070084#if CONFIG_EXT_PARTITION
85 // Always use 64x64 max partition.
Yaowu Xuf883b422016-08-30 14:01:10 -070086 encoder->Control(AV1E_SET_SUPERBLOCK_SIZE, AOM_SUPERBLOCK_SIZE_64X64);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070087#endif
88 }
89
90 if (video->frame() == 1) {
clang-format3a826f12016-08-11 17:46:05 -070091 frame_flags_ =
Yaowu Xuf883b422016-08-30 14:01:10 -070092 AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF;
Yunqing Wang8e5e3382016-05-05 16:42:57 -070093 }
94 }
95
Yaowu Xuf883b422016-08-30 14:01:10 -070096 virtual void DecompressedFrameHook(const aom_image_t &img,
97 aom_codec_pts_t pts) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -070098 // Skip 1 already decoded frame to be consistent with the decoder in this
99 // test.
Yaowu Xuf883b422016-08-30 14:01:10 -0700100 if (pts == (aom_codec_pts_t)kSkip) return;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700101
102 // Calculate MD5 as the reference.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700103 ::libaom_test::MD5 md5_res;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700104 md5_res.Add(&img);
105 md5_.push_back(md5_res.Get());
106 }
107
Yaowu Xuf883b422016-08-30 14:01:10 -0700108 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700109 // Skip decoding 1 frame.
Yaowu Xuf883b422016-08-30 14:01:10 -0700110 if (pkt->data.frame.pts == (aom_codec_pts_t)kSkip) return;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700111
Yaowu Xuf883b422016-08-30 14:01:10 -0700112 bool IsLastFrame = (pkt->data.frame.pts == (aom_codec_pts_t)(kLimit - 1));
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700113
114 // Decode the first (kLimit - 1) frames as whole frame, and decode the last
115 // frame in single tiles.
116 for (int r = 0; r < kImgHeight / kTIleSizeInPixels; ++r) {
117 for (int c = 0; c < kImgWidth / kTIleSizeInPixels; ++c) {
118 if (!IsLastFrame) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700119 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
120 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700121 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700122 decoder_->Control(AV1_SET_DECODE_TILE_ROW, r);
123 decoder_->Control(AV1_SET_DECODE_TILE_COL, c);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700124 }
125
Yaowu Xuf883b422016-08-30 14:01:10 -0700126 const aom_codec_err_t res = decoder_->DecodeFrame(
clang-format3a826f12016-08-11 17:46:05 -0700127 reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700128 pkt->data.frame.sz);
Yaowu Xuf883b422016-08-30 14:01:10 -0700129 if (res != AOM_CODEC_OK) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700130 abort_ = true;
Yaowu Xuf883b422016-08-30 14:01:10 -0700131 ASSERT_EQ(AOM_CODEC_OK, res);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700132 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700133 const aom_image_t *img = decoder_->GetDxData().Next();
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700134
135 if (!IsLastFrame) {
136 if (img) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700137 ::libaom_test::MD5 md5_res;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700138 md5_res.Add(img);
139 tile_md5_.push_back(md5_res.Get());
140 }
141 break;
142 }
143
144 const int kMaxMBPlane = 3;
145 for (int plane = 0; plane < kMaxMBPlane; ++plane) {
146 const int shift = (plane == 0) ? 0 : 1;
147 int tile_height = kTIleSizeInPixels >> shift;
148 int tile_width = kTIleSizeInPixels >> shift;
149
150 for (int tr = 0; tr < tile_height; ++tr) {
151 memcpy(tile_img_.planes[plane] +
clang-format3a826f12016-08-11 17:46:05 -0700152 tile_img_.stride[plane] * (r * tile_height + tr) +
153 c * tile_width,
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700154 img->planes[plane] + img->stride[plane] * tr, tile_width);
155 }
156 }
157 }
158
clang-format3a826f12016-08-11 17:46:05 -0700159 if (!IsLastFrame) break;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700160 }
161
Jingning Hane8164012016-05-19 09:25:38 -0700162 if (IsLastFrame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700163 ::libaom_test::MD5 md5_res;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700164 md5_res.Add(&tile_img_);
165 tile_md5_.push_back(md5_res.Get());
166 }
167 }
168
Yaowu Xuc27fc142016-08-22 16:08:15 -0700169 ::libaom_test::TestMode encoding_mode_;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700170 int set_cpu_used_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700171 ::libaom_test::Decoder *decoder_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700172 aom_image_t tile_img_;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700173 std::vector<std::string> md5_;
174 std::vector<std::string> tile_md5_;
175};
176
Yaowu Xuf883b422016-08-30 14:01:10 -0700177TEST_P(AV1ExtTileTest, DecoderResultTest) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700178 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", kImgWidth,
clang-format3a826f12016-08-11 17:46:05 -0700179 kImgHeight, 30, 1, 0, kLimit);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700180 cfg_.rc_target_bitrate = 500;
Yaowu Xuf883b422016-08-30 14:01:10 -0700181 cfg_.g_error_resilient = AOM_ERROR_RESILIENT_DEFAULT;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700182 cfg_.g_lag_in_frames = 0;
183 cfg_.g_threads = 1;
184
185 // Tile encoding
Yaowu Xuf883b422016-08-30 14:01:10 -0700186 init_flags_ = AOM_CODEC_USE_PSNR;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700187 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
188
189 // Compare to check if two vectors are equal.
190 ASSERT_EQ(md5_, tile_md5_);
191}
192
Yaowu Xuf883b422016-08-30 14:01:10 -0700193AV1_INSTANTIATE_TEST_CASE(
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700194 // Now only test 2-pass mode.
Yaowu Xuf883b422016-08-30 14:01:10 -0700195 AV1ExtTileTest, ::testing::Values(::libaom_test::kTwoPassGood),
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700196 ::testing::Range(0, 4));
197} // namespace