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