blob: 9563fd5865df27bff9b4c76bebab527a4a11abc6 [file] [log] [blame]
Yunqing Wang8e5e3382016-05-05 16:42:57 -07001/*
2 * Copyright (c) 2016 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <assert.h>
12#include <string>
13#include <vector>
14#include "third_party/googletest/src/include/gtest/gtest.h"
15#include "test/codec_factory.h"
16#include "test/encode_test_driver.h"
17#include "test/i420_video_source.h"
18#include "test/md5_helper.h"
19#include "test/util.h"
20
21namespace {
22// The number of frames to be encoded/decoded
23const int kLimit = 8;
24// Skip 1 frame to check the frame decoding independency.
25const int kSkip = 5;
26const int kTileSize = 1;
27const int kTIleSizeInPixels = (kTileSize << 6);
28// Fake width and height so that they can be multiples of the tile size.
29const int kImgWidth = 704;
30const int kImgHeight = 576;
31
Yaowu Xuf883b422016-08-30 14:01:10 -070032class AV1ExtTileTest
Yaowu Xuc27fc142016-08-22 16:08:15 -070033 : public ::libaom_test::EncoderTest,
34 public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> {
Yunqing Wang8e5e3382016-05-05 16:42:57 -070035 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070036 AV1ExtTileTest()
clang-format3a826f12016-08-11 17:46:05 -070037 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
Yunqing Wang8e5e3382016-05-05 16:42:57 -070038 set_cpu_used_(GET_PARAM(2)) {
Yaowu Xuf883b422016-08-30 14:01:10 -070039 init_flags_ = AOM_CODEC_USE_PSNR;
40 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
Yunqing Wang8e5e3382016-05-05 16:42:57 -070041 cfg.w = kImgWidth;
42 cfg.h = kImgHeight;
43
44 decoder_ = codec_->CreateDecoder(cfg, 0);
Yaowu Xuf883b422016-08-30 14:01:10 -070045 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
46 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070047
48 // Allocate buffer to store tile image.
Yaowu Xuf883b422016-08-30 14:01:10 -070049 aom_img_alloc(&tile_img_, AOM_IMG_FMT_I420, kImgWidth, kImgHeight, 32);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070050
51 md5_.clear();
52 tile_md5_.clear();
53 }
54
Yaowu Xuf883b422016-08-30 14:01:10 -070055 virtual ~AV1ExtTileTest() {
56 aom_img_free(&tile_img_);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070057 delete decoder_;
58 }
59
60 virtual void SetUp() {
61 InitializeConfig();
62 SetMode(encoding_mode_);
63
64 cfg_.g_lag_in_frames = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -070065 cfg_.rc_end_usage = AOM_VBR;
Yunqing Wang8e5e3382016-05-05 16:42:57 -070066 cfg_.g_error_resilient = 1;
67
68 cfg_.rc_max_quantizer = 56;
69 cfg_.rc_min_quantizer = 0;
70 }
71
Yaowu Xuc27fc142016-08-22 16:08:15 -070072 virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
73 ::libaom_test::Encoder *encoder) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -070074 if (video->frame() == 0) {
75 // Encode setting
Yaowu Xuf883b422016-08-30 14:01:10 -070076 encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
77 encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
78 encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070079
80 // The tile size is 64x64.
Yaowu Xuf883b422016-08-30 14:01:10 -070081 encoder->Control(AV1E_SET_TILE_COLUMNS, kTileSize);
82 encoder->Control(AV1E_SET_TILE_ROWS, kTileSize);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070083#if CONFIG_EXT_PARTITION
84 // Always use 64x64 max partition.
Yaowu Xuf883b422016-08-30 14:01:10 -070085 encoder->Control(AV1E_SET_SUPERBLOCK_SIZE, AOM_SUPERBLOCK_SIZE_64X64);
Yunqing Wang8e5e3382016-05-05 16:42:57 -070086#endif
87 }
88
89 if (video->frame() == 1) {
clang-format3a826f12016-08-11 17:46:05 -070090 frame_flags_ =
Yaowu Xuf883b422016-08-30 14:01:10 -070091 AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF;
Yunqing Wang8e5e3382016-05-05 16:42:57 -070092 }
93 }
94
Yaowu Xuf883b422016-08-30 14:01:10 -070095 virtual void DecompressedFrameHook(const aom_image_t &img,
96 aom_codec_pts_t pts) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -070097 // Skip 1 already decoded frame to be consistent with the decoder in this
98 // test.
Yaowu Xuf883b422016-08-30 14:01:10 -070099 if (pts == (aom_codec_pts_t)kSkip) return;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700100
101 // Calculate MD5 as the reference.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700102 ::libaom_test::MD5 md5_res;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700103 md5_res.Add(&img);
104 md5_.push_back(md5_res.Get());
105 }
106
Yaowu Xuf883b422016-08-30 14:01:10 -0700107 virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700108 // Skip decoding 1 frame.
Yaowu Xuf883b422016-08-30 14:01:10 -0700109 if (pkt->data.frame.pts == (aom_codec_pts_t)kSkip) return;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700110
Yaowu Xuf883b422016-08-30 14:01:10 -0700111 bool IsLastFrame = (pkt->data.frame.pts == (aom_codec_pts_t)(kLimit - 1));
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700112
113 // Decode the first (kLimit - 1) frames as whole frame, and decode the last
114 // frame in single tiles.
115 for (int r = 0; r < kImgHeight / kTIleSizeInPixels; ++r) {
116 for (int c = 0; c < kImgWidth / kTIleSizeInPixels; ++c) {
117 if (!IsLastFrame) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700118 decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
119 decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700120 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700121 decoder_->Control(AV1_SET_DECODE_TILE_ROW, r);
122 decoder_->Control(AV1_SET_DECODE_TILE_COL, c);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700123 }
124
Yaowu Xuf883b422016-08-30 14:01:10 -0700125 const aom_codec_err_t res = decoder_->DecodeFrame(
clang-format3a826f12016-08-11 17:46:05 -0700126 reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700127 pkt->data.frame.sz);
Yaowu Xuf883b422016-08-30 14:01:10 -0700128 if (res != AOM_CODEC_OK) {
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700129 abort_ = true;
Yaowu Xuf883b422016-08-30 14:01:10 -0700130 ASSERT_EQ(AOM_CODEC_OK, res);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700131 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700132 const aom_image_t *img = decoder_->GetDxData().Next();
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700133
134 if (!IsLastFrame) {
135 if (img) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700136 ::libaom_test::MD5 md5_res;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700137 md5_res.Add(img);
138 tile_md5_.push_back(md5_res.Get());
139 }
140 break;
141 }
142
143 const int kMaxMBPlane = 3;
144 for (int plane = 0; plane < kMaxMBPlane; ++plane) {
145 const int shift = (plane == 0) ? 0 : 1;
146 int tile_height = kTIleSizeInPixels >> shift;
147 int tile_width = kTIleSizeInPixels >> shift;
148
149 for (int tr = 0; tr < tile_height; ++tr) {
150 memcpy(tile_img_.planes[plane] +
clang-format3a826f12016-08-11 17:46:05 -0700151 tile_img_.stride[plane] * (r * tile_height + tr) +
152 c * tile_width,
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700153 img->planes[plane] + img->stride[plane] * tr, tile_width);
154 }
155 }
156 }
157
clang-format3a826f12016-08-11 17:46:05 -0700158 if (!IsLastFrame) break;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700159 }
160
Jingning Hane8164012016-05-19 09:25:38 -0700161 if (IsLastFrame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700162 ::libaom_test::MD5 md5_res;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700163 md5_res.Add(&tile_img_);
164 tile_md5_.push_back(md5_res.Get());
165 }
166 }
167
Yaowu Xuc27fc142016-08-22 16:08:15 -0700168 ::libaom_test::TestMode encoding_mode_;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700169 int set_cpu_used_;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700170 ::libaom_test::Decoder *decoder_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700171 aom_image_t tile_img_;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700172 std::vector<std::string> md5_;
173 std::vector<std::string> tile_md5_;
174};
175
Yaowu Xuf883b422016-08-30 14:01:10 -0700176TEST_P(AV1ExtTileTest, DecoderResultTest) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700177 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", kImgWidth,
clang-format3a826f12016-08-11 17:46:05 -0700178 kImgHeight, 30, 1, 0, kLimit);
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700179 cfg_.rc_target_bitrate = 500;
Yaowu Xuf883b422016-08-30 14:01:10 -0700180 cfg_.g_error_resilient = AOM_ERROR_RESILIENT_DEFAULT;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700181 cfg_.g_lag_in_frames = 0;
182 cfg_.g_threads = 1;
183
184 // Tile encoding
Yaowu Xuf883b422016-08-30 14:01:10 -0700185 init_flags_ = AOM_CODEC_USE_PSNR;
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700186 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 Xuf883b422016-08-30 14:01:10 -0700192AV1_INSTANTIATE_TEST_CASE(
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700193 // Now only test 2-pass mode.
Yaowu Xuf883b422016-08-30 14:01:10 -0700194 AV1ExtTileTest, ::testing::Values(::libaom_test::kTwoPassGood),
Yunqing Wang8e5e3382016-05-05 16:42:57 -0700195 ::testing::Range(0, 4));
196} // namespace