Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [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. |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <assert.h> |
| 13 | #include <string> |
| 14 | #include <vector> |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 15 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [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/md5_helper.h" |
| 20 | #include "test/util.h" |
| 21 | |
| 22 | namespace { |
| 23 | // The number of frames to be encoded/decoded |
| 24 | const int kLimit = 8; |
| 25 | // Skip 1 frame to check the frame decoding independency. |
| 26 | const int kSkip = 5; |
| 27 | const int kTileSize = 1; |
| 28 | const int kTIleSizeInPixels = (kTileSize << 6); |
| 29 | // Fake width and height so that they can be multiples of the tile size. |
| 30 | const int kImgWidth = 704; |
| 31 | const int kImgHeight = 576; |
| 32 | |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame^] | 33 | // This test tests "tile_encoding_mode = TILE_VR" case. The TILE_NORMAL case is |
| 34 | // tested by the tile_independence test. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 35 | class AV1ExtTileTest |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | : public ::libaom_test::EncoderTest, |
| 37 | public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> { |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 38 | protected: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 39 | AV1ExtTileTest() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 40 | : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 41 | set_cpu_used_(GET_PARAM(2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 42 | init_flags_ = AOM_CODEC_USE_PSNR; |
| 43 | aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t(); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 44 | cfg.w = kImgWidth; |
| 45 | cfg.h = kImgHeight; |
| 46 | |
| 47 | decoder_ = codec_->CreateDecoder(cfg, 0); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 48 | decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1); |
| 49 | decoder_->Control(AV1_SET_DECODE_TILE_COL, -1); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 50 | |
| 51 | // Allocate buffer to store tile image. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 52 | aom_img_alloc(&tile_img_, AOM_IMG_FMT_I420, kImgWidth, kImgHeight, 32); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 53 | |
| 54 | md5_.clear(); |
| 55 | tile_md5_.clear(); |
| 56 | } |
| 57 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 58 | virtual ~AV1ExtTileTest() { |
| 59 | aom_img_free(&tile_img_); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 60 | delete decoder_; |
| 61 | } |
| 62 | |
| 63 | virtual void SetUp() { |
| 64 | InitializeConfig(); |
| 65 | SetMode(encoding_mode_); |
| 66 | |
| 67 | cfg_.g_lag_in_frames = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 68 | cfg_.rc_end_usage = AOM_VBR; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 69 | cfg_.g_error_resilient = 1; |
| 70 | |
| 71 | cfg_.rc_max_quantizer = 56; |
| 72 | cfg_.rc_min_quantizer = 0; |
| 73 | } |
| 74 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 75 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 76 | ::libaom_test::Encoder *encoder) { |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 77 | if (video->frame() == 0) { |
| 78 | // Encode setting |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 79 | encoder->Control(AOME_SET_CPUUSED, set_cpu_used_); |
| 80 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0); |
| 81 | encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 82 | |
| 83 | // The tile size is 64x64. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 84 | encoder->Control(AV1E_SET_TILE_COLUMNS, kTileSize); |
| 85 | encoder->Control(AV1E_SET_TILE_ROWS, kTileSize); |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame^] | 86 | encoder->Control(AV1E_SET_TILE_ENCODING_MODE, 1); // TILE_VR |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 87 | #if CONFIG_EXT_PARTITION |
| 88 | // Always use 64x64 max partition. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 89 | encoder->Control(AV1E_SET_SUPERBLOCK_SIZE, AOM_SUPERBLOCK_SIZE_64X64); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 90 | #endif |
| 91 | } |
| 92 | |
| 93 | if (video->frame() == 1) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 94 | frame_flags_ = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 95 | AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 99 | virtual void DecompressedFrameHook(const aom_image_t &img, |
| 100 | aom_codec_pts_t pts) { |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 101 | // Skip 1 already decoded frame to be consistent with the decoder in this |
| 102 | // test. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 103 | if (pts == (aom_codec_pts_t)kSkip) return; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 104 | |
| 105 | // Calculate MD5 as the reference. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 106 | ::libaom_test::MD5 md5_res; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 107 | md5_res.Add(&img); |
| 108 | md5_.push_back(md5_res.Get()); |
| 109 | } |
| 110 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 111 | virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) { |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 112 | // Skip decoding 1 frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 113 | if (pkt->data.frame.pts == (aom_codec_pts_t)kSkip) return; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 114 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 115 | bool IsLastFrame = (pkt->data.frame.pts == (aom_codec_pts_t)(kLimit - 1)); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 116 | |
| 117 | // Decode the first (kLimit - 1) frames as whole frame, and decode the last |
| 118 | // frame in single tiles. |
| 119 | for (int r = 0; r < kImgHeight / kTIleSizeInPixels; ++r) { |
| 120 | for (int c = 0; c < kImgWidth / kTIleSizeInPixels; ++c) { |
| 121 | if (!IsLastFrame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 122 | decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1); |
| 123 | decoder_->Control(AV1_SET_DECODE_TILE_COL, -1); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 124 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 125 | decoder_->Control(AV1_SET_DECODE_TILE_ROW, r); |
| 126 | decoder_->Control(AV1_SET_DECODE_TILE_COL, c); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 129 | const aom_codec_err_t res = decoder_->DecodeFrame( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 130 | reinterpret_cast<uint8_t *>(pkt->data.frame.buf), |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 131 | pkt->data.frame.sz); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 132 | if (res != AOM_CODEC_OK) { |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 133 | abort_ = true; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 134 | ASSERT_EQ(AOM_CODEC_OK, res); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 135 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 136 | const aom_image_t *img = decoder_->GetDxData().Next(); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 137 | |
| 138 | if (!IsLastFrame) { |
| 139 | if (img) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 140 | ::libaom_test::MD5 md5_res; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 141 | md5_res.Add(img); |
| 142 | tile_md5_.push_back(md5_res.Get()); |
| 143 | } |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | const int kMaxMBPlane = 3; |
| 148 | for (int plane = 0; plane < kMaxMBPlane; ++plane) { |
| 149 | const int shift = (plane == 0) ? 0 : 1; |
| 150 | int tile_height = kTIleSizeInPixels >> shift; |
| 151 | int tile_width = kTIleSizeInPixels >> shift; |
| 152 | |
| 153 | for (int tr = 0; tr < tile_height; ++tr) { |
| 154 | memcpy(tile_img_.planes[plane] + |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 155 | tile_img_.stride[plane] * (r * tile_height + tr) + |
| 156 | c * tile_width, |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 157 | img->planes[plane] + img->stride[plane] * tr, tile_width); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 162 | if (!IsLastFrame) break; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Jingning Han | e816401 | 2016-05-19 09:25:38 -0700 | [diff] [blame] | 165 | if (IsLastFrame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 166 | ::libaom_test::MD5 md5_res; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 167 | md5_res.Add(&tile_img_); |
| 168 | tile_md5_.push_back(md5_res.Get()); |
| 169 | } |
| 170 | } |
| 171 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | ::libaom_test::TestMode encoding_mode_; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 173 | int set_cpu_used_; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 174 | ::libaom_test::Decoder *decoder_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 175 | aom_image_t tile_img_; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 176 | std::vector<std::string> md5_; |
| 177 | std::vector<std::string> tile_md5_; |
| 178 | }; |
| 179 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 180 | TEST_P(AV1ExtTileTest, DecoderResultTest) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 181 | ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", kImgWidth, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 182 | kImgHeight, 30, 1, 0, kLimit); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 183 | cfg_.rc_target_bitrate = 500; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 184 | cfg_.g_error_resilient = AOM_ERROR_RESILIENT_DEFAULT; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 185 | cfg_.g_lag_in_frames = 0; |
| 186 | cfg_.g_threads = 1; |
| 187 | |
| 188 | // Tile encoding |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 189 | init_flags_ = AOM_CODEC_USE_PSNR; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 190 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 191 | |
| 192 | // Compare to check if two vectors are equal. |
| 193 | ASSERT_EQ(md5_, tile_md5_); |
| 194 | } |
| 195 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 196 | AV1_INSTANTIATE_TEST_CASE( |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 197 | // Now only test 2-pass mode. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | AV1ExtTileTest, ::testing::Values(::libaom_test::kTwoPassGood), |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 199 | ::testing::Range(0, 4)); |
| 200 | } // namespace |