John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [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. |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 10 | */ |
James Zern | 0616fa6 | 2016-04-26 19:56:44 -0700 | [diff] [blame] | 11 | |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 12 | #include <climits> |
| 13 | #include <vector> |
Imdad Sardharwalla | 102c865 | 2018-02-23 16:35:13 +0000 | [diff] [blame] | 14 | #include "aom_dsp/aom_dsp_common.h" |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 15 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 16 | #include "test/codec_factory.h" |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 17 | #include "test/encode_test_driver.h" |
John Koleszar | 88f99f4 | 2013-02-06 12:44:20 -0800 | [diff] [blame] | 18 | #include "test/i420_video_source.h" |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 19 | #include "test/video_source.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 20 | #include "test/util.h" |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 21 | |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 22 | // Enable(1) or Disable(0) writing of the compressed bitstream. |
| 23 | #define WRITE_COMPRESSED_STREAM 0 |
| 24 | |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 25 | namespace { |
| 26 | |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 27 | #if WRITE_COMPRESSED_STREAM |
Yaowu Xu | 032573d | 2017-04-24 15:04:17 -0700 | [diff] [blame] | 28 | static void mem_put_le16(char *const mem, unsigned int val) { |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 29 | mem[0] = val; |
| 30 | mem[1] = val >> 8; |
| 31 | } |
| 32 | |
Yaowu Xu | 032573d | 2017-04-24 15:04:17 -0700 | [diff] [blame] | 33 | static void mem_put_le32(char *const mem, unsigned int val) { |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 34 | mem[0] = val; |
| 35 | mem[1] = val >> 8; |
| 36 | mem[2] = val >> 16; |
| 37 | mem[3] = val >> 24; |
| 38 | } |
| 39 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 40 | static void write_ivf_file_header(const aom_codec_enc_cfg_t *const cfg, |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 41 | int frame_cnt, FILE *const outfile) { |
| 42 | char header[32]; |
| 43 | |
| 44 | header[0] = 'D'; |
| 45 | header[1] = 'K'; |
| 46 | header[2] = 'I'; |
| 47 | header[3] = 'F'; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 48 | mem_put_le16(header + 4, 0); /* version */ |
| 49 | mem_put_le16(header + 6, 32); /* headersize */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 50 | mem_put_le32(header + 8, 0x30395056); /* fourcc (av1) */ |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 51 | mem_put_le16(header + 12, cfg->g_w); /* width */ |
| 52 | mem_put_le16(header + 14, cfg->g_h); /* height */ |
| 53 | mem_put_le32(header + 16, cfg->g_timebase.den); /* rate */ |
| 54 | mem_put_le32(header + 20, cfg->g_timebase.num); /* scale */ |
| 55 | mem_put_le32(header + 24, frame_cnt); /* length */ |
| 56 | mem_put_le32(header + 28, 0); /* unused */ |
| 57 | |
| 58 | (void)fwrite(header, 1, 32, outfile); |
| 59 | } |
| 60 | |
| 61 | static void write_ivf_frame_size(FILE *const outfile, const size_t size) { |
| 62 | char header[4]; |
| 63 | mem_put_le32(header, static_cast<unsigned int>(size)); |
| 64 | (void)fwrite(header, 1, 4, outfile); |
| 65 | } |
| 66 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 67 | static void write_ivf_frame_header(const aom_codec_cx_pkt_t *const pkt, |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 68 | FILE *const outfile) { |
| 69 | char header[12]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 70 | aom_codec_pts_t pts; |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 71 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 72 | if (pkt->kind != AOM_CODEC_CX_FRAME_PKT) return; |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 73 | |
| 74 | pts = pkt->data.frame.pts; |
| 75 | mem_put_le32(header, static_cast<unsigned int>(pkt->data.frame.sz)); |
| 76 | mem_put_le32(header + 4, pts & 0xFFFFFFFF); |
| 77 | mem_put_le32(header + 8, pts >> 32); |
| 78 | |
| 79 | (void)fwrite(header, 1, 12, outfile); |
| 80 | } |
| 81 | #endif // WRITE_COMPRESSED_STREAM |
| 82 | |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 83 | const unsigned int kInitialWidth = 320; |
| 84 | const unsigned int kInitialHeight = 240; |
| 85 | |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 86 | struct FrameInfo { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 87 | FrameInfo(aom_codec_pts_t _pts, unsigned int _w, unsigned int _h) |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 88 | : pts(_pts), w(_w), h(_h) {} |
| 89 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 90 | aom_codec_pts_t pts; |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 91 | unsigned int w; |
| 92 | unsigned int h; |
| 93 | }; |
| 94 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 95 | void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, |
| 96 | unsigned int initial_h, unsigned int *w, |
| 97 | unsigned int *h, int flag_codec) { |
Marco | 3cbc26f | 2016-02-10 11:39:04 -0800 | [diff] [blame] | 98 | if (frame < 10) { |
| 99 | *w = initial_w; |
| 100 | *h = initial_h; |
| 101 | return; |
| 102 | } |
| 103 | if (frame < 20) { |
| 104 | *w = initial_w * 3 / 4; |
| 105 | *h = initial_h * 3 / 4; |
| 106 | return; |
| 107 | } |
| 108 | if (frame < 30) { |
| 109 | *w = initial_w / 2; |
| 110 | *h = initial_h / 2; |
| 111 | return; |
| 112 | } |
| 113 | if (frame < 40) { |
| 114 | *w = initial_w; |
| 115 | *h = initial_h; |
| 116 | return; |
| 117 | } |
| 118 | if (frame < 50) { |
| 119 | *w = initial_w * 3 / 4; |
| 120 | *h = initial_h * 3 / 4; |
| 121 | return; |
| 122 | } |
| 123 | if (frame < 60) { |
| 124 | *w = initial_w / 2; |
| 125 | *h = initial_h / 2; |
| 126 | return; |
| 127 | } |
| 128 | if (frame < 70) { |
| 129 | *w = initial_w; |
| 130 | *h = initial_h; |
| 131 | return; |
| 132 | } |
| 133 | if (frame < 80) { |
| 134 | *w = initial_w * 3 / 4; |
| 135 | *h = initial_h * 3 / 4; |
| 136 | return; |
| 137 | } |
| 138 | if (frame < 90) { |
| 139 | *w = initial_w / 2; |
| 140 | *h = initial_h / 2; |
| 141 | return; |
| 142 | } |
| 143 | if (frame < 100) { |
| 144 | *w = initial_w * 3 / 4; |
| 145 | *h = initial_h * 3 / 4; |
| 146 | return; |
| 147 | } |
| 148 | if (frame < 110) { |
| 149 | *w = initial_w; |
| 150 | *h = initial_h; |
| 151 | return; |
| 152 | } |
| 153 | if (frame < 120) { |
| 154 | *w = initial_w * 3 / 4; |
| 155 | *h = initial_h * 3 / 4; |
| 156 | return; |
| 157 | } |
| 158 | if (frame < 130) { |
| 159 | *w = initial_w / 2; |
| 160 | *h = initial_h / 2; |
| 161 | return; |
| 162 | } |
| 163 | if (frame < 140) { |
| 164 | *w = initial_w * 3 / 4; |
| 165 | *h = initial_h * 3 / 4; |
| 166 | return; |
| 167 | } |
| 168 | if (frame < 150) { |
| 169 | *w = initial_w; |
| 170 | *h = initial_h; |
| 171 | return; |
| 172 | } |
| 173 | if (frame < 160) { |
| 174 | *w = initial_w * 3 / 4; |
| 175 | *h = initial_h * 3 / 4; |
| 176 | return; |
| 177 | } |
| 178 | if (frame < 170) { |
| 179 | *w = initial_w / 2; |
| 180 | *h = initial_h / 2; |
| 181 | return; |
| 182 | } |
| 183 | if (frame < 180) { |
| 184 | *w = initial_w * 3 / 4; |
| 185 | *h = initial_h * 3 / 4; |
| 186 | return; |
| 187 | } |
| 188 | if (frame < 190) { |
| 189 | *w = initial_w; |
| 190 | *h = initial_h; |
| 191 | return; |
| 192 | } |
| 193 | if (frame < 200) { |
| 194 | *w = initial_w * 3 / 4; |
| 195 | *h = initial_h * 3 / 4; |
| 196 | return; |
| 197 | } |
| 198 | if (frame < 210) { |
| 199 | *w = initial_w / 2; |
| 200 | *h = initial_h / 2; |
| 201 | return; |
| 202 | } |
| 203 | if (frame < 220) { |
| 204 | *w = initial_w * 3 / 4; |
| 205 | *h = initial_h * 3 / 4; |
| 206 | return; |
| 207 | } |
| 208 | if (frame < 230) { |
| 209 | *w = initial_w; |
| 210 | *h = initial_h; |
| 211 | return; |
| 212 | } |
| 213 | if (frame < 240) { |
| 214 | *w = initial_w * 3 / 4; |
| 215 | *h = initial_h * 3 / 4; |
| 216 | return; |
| 217 | } |
| 218 | if (frame < 250) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 219 | *w = initial_w / 2; |
Marco | 3cbc26f | 2016-02-10 11:39:04 -0800 | [diff] [blame] | 220 | *h = initial_h / 2; |
| 221 | return; |
| 222 | } |
| 223 | if (frame < 260) { |
| 224 | *w = initial_w; |
| 225 | *h = initial_h; |
| 226 | return; |
| 227 | } |
| 228 | // Go down very low. |
| 229 | if (frame < 270) { |
| 230 | *w = initial_w / 4; |
| 231 | *h = initial_h / 4; |
| 232 | return; |
| 233 | } |
| 234 | if (flag_codec == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 235 | // Cases that only works for AV1. |
| 236 | // For AV1: Swap width and height of original. |
Marco | 3cbc26f | 2016-02-10 11:39:04 -0800 | [diff] [blame] | 237 | if (frame < 320) { |
| 238 | *w = initial_h; |
| 239 | *h = initial_w; |
| 240 | return; |
| 241 | } |
| 242 | } |
| 243 | *w = initial_w; |
| 244 | *h = initial_h; |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 247 | class ResizingVideoSource : public ::libaom_test::DummyVideoSource { |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 248 | public: |
| 249 | ResizingVideoSource() { |
| 250 | SetSize(kInitialWidth, kInitialHeight); |
Imdad Sardharwalla | 102c865 | 2018-02-23 16:35:13 +0000 | [diff] [blame] | 251 | limit_ = 350; |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 252 | } |
Marco | 3cbc26f | 2016-02-10 11:39:04 -0800 | [diff] [blame] | 253 | int flag_codec_; |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 254 | virtual ~ResizingVideoSource() {} |
| 255 | |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 256 | protected: |
| 257 | virtual void Next() { |
| 258 | ++frame_; |
Marco | 3cbc26f | 2016-02-10 11:39:04 -0800 | [diff] [blame] | 259 | unsigned int width; |
| 260 | unsigned int height; |
| 261 | ScaleForFrameNumber(frame_, kInitialWidth, kInitialHeight, &width, &height, |
| 262 | flag_codec_); |
| 263 | SetSize(width, height); |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 264 | FillFrame(); |
| 265 | } |
| 266 | }; |
| 267 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 268 | class ResizeTest |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 269 | : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>, |
| 270 | public ::libaom_test::EncoderTest { |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 271 | protected: |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 272 | ResizeTest() : EncoderTest(GET_PARAM(0)) {} |
| 273 | |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 274 | virtual ~ResizeTest() {} |
| 275 | |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 276 | virtual void SetUp() { |
| 277 | InitializeConfig(); |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 278 | SetMode(GET_PARAM(1)); |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 281 | virtual void DecompressedFrameHook(const aom_image_t &img, |
| 282 | aom_codec_pts_t pts) { |
John Koleszar | 88f99f4 | 2013-02-06 12:44:20 -0800 | [diff] [blame] | 283 | frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h)); |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 284 | } |
| 285 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 286 | std::vector<FrameInfo> frame_info_list_; |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | TEST_P(ResizeTest, TestExternalResizeWorks) { |
| 290 | ResizingVideoSource video; |
Marco | 3cbc26f | 2016-02-10 11:39:04 -0800 | [diff] [blame] | 291 | video.flag_codec_ = 0; |
Alex Converse | 910ca85 | 2015-01-12 16:26:05 -0800 | [diff] [blame] | 292 | cfg_.g_lag_in_frames = 0; |
Imdad Sardharwalla | 102c865 | 2018-02-23 16:35:13 +0000 | [diff] [blame] | 293 | // We use max(kInitialWidth, kInitialHeight) because during the test |
| 294 | // the width and height of the frame are swapped |
| 295 | cfg_.g_forced_max_frame_width = cfg_.g_forced_max_frame_height = |
| 296 | AOMMAX(kInitialWidth, kInitialHeight); |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 297 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 298 | |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 299 | // Check we decoded the same number of frames as we attempted to encode |
| 300 | ASSERT_EQ(frame_info_list_.size(), video.limit()); |
| 301 | |
James Zern | bb06138 | 2014-01-31 20:11:55 -0800 | [diff] [blame] | 302 | for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 303 | info != frame_info_list_.end(); ++info) { |
James Zern | 17b8993 | 2014-01-31 20:10:28 -0800 | [diff] [blame] | 304 | const unsigned int frame = static_cast<unsigned>(info->pts); |
Marco | 3cbc26f | 2016-02-10 11:39:04 -0800 | [diff] [blame] | 305 | unsigned int expected_w; |
| 306 | unsigned int expected_h; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 307 | ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight, &expected_w, |
| 308 | &expected_h, 0); |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 309 | EXPECT_EQ(expected_w, info->w) |
| 310 | << "Frame " << frame << " had unexpected width"; |
| 311 | EXPECT_EQ(expected_h, info->h) |
| 312 | << "Frame " << frame << " had unexpected height"; |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 316 | const unsigned int kStepDownFrame = 3; |
| 317 | const unsigned int kStepUpFrame = 6; |
| 318 | |
Debargha Mukherjee | 15b6ae0 | 2017-10-10 19:56:05 -0700 | [diff] [blame] | 319 | class ResizeInternalTestLarge : public ResizeTest { |
John Koleszar | 88f99f4 | 2013-02-06 12:44:20 -0800 | [diff] [blame] | 320 | protected: |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 321 | #if WRITE_COMPRESSED_STREAM |
Debargha Mukherjee | 15b6ae0 | 2017-10-10 19:56:05 -0700 | [diff] [blame] | 322 | ResizeInternalTestLarge() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 323 | : ResizeTest(), frame0_psnr_(0.0), outfile_(NULL), out_frames_(0) {} |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 324 | #else |
Debargha Mukherjee | 15b6ae0 | 2017-10-10 19:56:05 -0700 | [diff] [blame] | 325 | ResizeInternalTestLarge() : ResizeTest(), frame0_psnr_(0.0) {} |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 326 | #endif |
| 327 | |
Debargha Mukherjee | 15b6ae0 | 2017-10-10 19:56:05 -0700 | [diff] [blame] | 328 | virtual ~ResizeInternalTestLarge() {} |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 329 | |
| 330 | virtual void BeginPassHook(unsigned int /*pass*/) { |
| 331 | #if WRITE_COMPRESSED_STREAM |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 332 | outfile_ = fopen("av10-2-05-resize.ivf", "wb"); |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 333 | #endif |
| 334 | } |
| 335 | |
| 336 | virtual void EndPassHook() { |
| 337 | #if WRITE_COMPRESSED_STREAM |
| 338 | if (outfile_) { |
| 339 | if (!fseek(outfile_, 0, SEEK_SET)) |
| 340 | write_ivf_file_header(&cfg_, out_frames_, outfile_); |
| 341 | fclose(outfile_); |
| 342 | outfile_ = NULL; |
| 343 | } |
| 344 | #endif |
| 345 | } |
John Koleszar | 88f99f4 | 2013-02-06 12:44:20 -0800 | [diff] [blame] | 346 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 347 | virtual void PreEncodeFrameHook(libaom_test::VideoSource *video, |
| 348 | libaom_test::Encoder *encoder) { |
jackychen | 55f092d | 2015-09-21 09:37:46 -0700 | [diff] [blame] | 349 | if (change_config_) { |
| 350 | int new_q = 60; |
| 351 | if (video->frame() == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 352 | struct aom_scaling_mode mode = { AOME_ONETWO, AOME_ONETWO }; |
| 353 | encoder->Control(AOME_SET_SCALEMODE, &mode); |
jackychen | 55f092d | 2015-09-21 09:37:46 -0700 | [diff] [blame] | 354 | } |
| 355 | if (video->frame() == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 356 | struct aom_scaling_mode mode = { AOME_NORMAL, AOME_NORMAL }; |
| 357 | encoder->Control(AOME_SET_SCALEMODE, &mode); |
jackychen | 55f092d | 2015-09-21 09:37:46 -0700 | [diff] [blame] | 358 | cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = new_q; |
| 359 | encoder->Config(&cfg_); |
| 360 | } |
| 361 | } else { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 362 | if (video->frame() >= kStepDownFrame && video->frame() < kStepUpFrame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 363 | struct aom_scaling_mode mode = { AOME_FOURFIVE, AOME_THREEFIVE }; |
| 364 | encoder->Control(AOME_SET_SCALEMODE, &mode); |
jackychen | 55f092d | 2015-09-21 09:37:46 -0700 | [diff] [blame] | 365 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 366 | if (video->frame() >= kStepUpFrame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 367 | struct aom_scaling_mode mode = { AOME_NORMAL, AOME_NORMAL }; |
| 368 | encoder->Control(AOME_SET_SCALEMODE, &mode); |
jackychen | 55f092d | 2015-09-21 09:37:46 -0700 | [diff] [blame] | 369 | } |
John Koleszar | b683eec | 2013-02-21 10:38:27 -0800 | [diff] [blame] | 370 | } |
John Koleszar | 88f99f4 | 2013-02-06 12:44:20 -0800 | [diff] [blame] | 371 | } |
John Koleszar | b683eec | 2013-02-21 10:38:27 -0800 | [diff] [blame] | 372 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 373 | virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 374 | if (frame0_psnr_ == 0.) frame0_psnr_ = pkt->data.psnr.psnr[0]; |
Debargha Mukherjee | 34e3a14 | 2017-10-05 12:46:14 -0700 | [diff] [blame] | 375 | EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 2.5); |
John Koleszar | b683eec | 2013-02-21 10:38:27 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 378 | #if WRITE_COMPRESSED_STREAM |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 379 | virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) { |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 380 | ++out_frames_; |
| 381 | |
| 382 | // Write initial file header if first frame. |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 383 | if (pkt->data.frame.pts == 0) write_ivf_file_header(&cfg_, 0, outfile_); |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 384 | |
| 385 | // Write frame header and data. |
| 386 | write_ivf_frame_header(pkt, outfile_); |
| 387 | (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_); |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 388 | } |
James Zern | dbe6917 | 2014-08-22 12:11:42 -0700 | [diff] [blame] | 389 | #endif |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 390 | |
John Koleszar | b683eec | 2013-02-21 10:38:27 -0800 | [diff] [blame] | 391 | double frame0_psnr_; |
jackychen | 55f092d | 2015-09-21 09:37:46 -0700 | [diff] [blame] | 392 | bool change_config_; |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 393 | #if WRITE_COMPRESSED_STREAM |
| 394 | FILE *outfile_; |
| 395 | unsigned int out_frames_; |
| 396 | #endif |
John Koleszar | 88f99f4 | 2013-02-06 12:44:20 -0800 | [diff] [blame] | 397 | }; |
| 398 | |
Debargha Mukherjee | 15b6ae0 | 2017-10-10 19:56:05 -0700 | [diff] [blame] | 399 | TEST_P(ResizeInternalTestLarge, TestInternalResizeWorks) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 400 | ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
John Koleszar | b683eec | 2013-02-21 10:38:27 -0800 | [diff] [blame] | 401 | 30, 1, 0, 10); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 402 | init_flags_ = AOM_CODEC_USE_PSNR; |
jackychen | 55f092d | 2015-09-21 09:37:46 -0700 | [diff] [blame] | 403 | change_config_ = false; |
Adrian Grange | 93ffd37 | 2013-09-10 12:02:37 -0700 | [diff] [blame] | 404 | |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 405 | // q picked such that initial keyframe on this clip is ~30dB PSNR |
| 406 | cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = 48; |
| 407 | |
Adrian Grange | 93ffd37 | 2013-09-10 12:02:37 -0700 | [diff] [blame] | 408 | // If the number of frames being encoded is smaller than g_lag_in_frames |
| 409 | // the encoded frame is unavailable using the current API. Comparing |
| 410 | // frames to detect mismatch would then not be possible. Set |
| 411 | // g_lag_in_frames = 0 to get around this. |
| 412 | cfg_.g_lag_in_frames = 0; |
John Koleszar | 88f99f4 | 2013-02-06 12:44:20 -0800 | [diff] [blame] | 413 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 414 | |
James Zern | bb06138 | 2014-01-31 20:11:55 -0800 | [diff] [blame] | 415 | for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); |
John Koleszar | 88f99f4 | 2013-02-06 12:44:20 -0800 | [diff] [blame] | 416 | info != frame_info_list_.end(); ++info) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 417 | } |
| 418 | for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); |
| 419 | info != frame_info_list_.end(); ++info) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 420 | const aom_codec_pts_t pts = info->pts; |
Adrian Grange | 88c8ff2 | 2013-09-12 09:35:04 -0700 | [diff] [blame] | 421 | if (pts >= kStepDownFrame && pts < kStepUpFrame) { |
John Koleszar | 88f99f4 | 2013-02-06 12:44:20 -0800 | [diff] [blame] | 422 | ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width"; |
| 423 | ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height"; |
| 424 | } else { |
| 425 | EXPECT_EQ(352U, info->w) << "Frame " << pts << " had unexpected width"; |
| 426 | EXPECT_EQ(288U, info->h) << "Frame " << pts << " had unexpected height"; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
Debargha Mukherjee | 15b6ae0 | 2017-10-10 19:56:05 -0700 | [diff] [blame] | 431 | TEST_P(ResizeInternalTestLarge, TestInternalResizeChangeConfig) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 432 | ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
jackychen | 55f092d | 2015-09-21 09:37:46 -0700 | [diff] [blame] | 433 | 30, 1, 0, 10); |
| 434 | cfg_.g_w = 352; |
| 435 | cfg_.g_h = 288; |
| 436 | change_config_ = true; |
| 437 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 438 | } |
| 439 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 440 | class ResizeRealtimeTest |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 441 | : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>, |
| 442 | public ::libaom_test::EncoderTest { |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 443 | protected: |
jackychen | 55c8843 | 2015-11-09 14:58:14 -0800 | [diff] [blame] | 444 | ResizeRealtimeTest() : EncoderTest(GET_PARAM(0)) {} |
| 445 | virtual ~ResizeRealtimeTest() {} |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 446 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 447 | virtual void PreEncodeFrameHook(libaom_test::VideoSource *video, |
| 448 | libaom_test::Encoder *encoder) { |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 449 | if (video->frame() == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 450 | encoder->Control(AV1E_SET_AQ_MODE, 3); |
| 451 | encoder->Control(AOME_SET_CPUUSED, set_cpu_used_); |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 452 | } |
jackychen | ca8f8fd | 2015-09-15 15:47:11 -0700 | [diff] [blame] | 453 | |
| 454 | if (change_bitrate_ && video->frame() == 120) { |
| 455 | change_bitrate_ = false; |
| 456 | cfg_.rc_target_bitrate = 500; |
| 457 | encoder->Config(&cfg_); |
| 458 | } |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | virtual void SetUp() { |
| 462 | InitializeConfig(); |
| 463 | SetMode(GET_PARAM(1)); |
| 464 | set_cpu_used_ = GET_PARAM(2); |
| 465 | } |
| 466 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 467 | virtual void DecompressedFrameHook(const aom_image_t &img, |
| 468 | aom_codec_pts_t pts) { |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 469 | frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h)); |
| 470 | } |
| 471 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 472 | virtual void MismatchHook(const aom_image_t *img1, const aom_image_t *img2) { |
Marco | b9cb955 | 2016-03-07 16:58:06 -0800 | [diff] [blame] | 473 | double mismatch_psnr = compute_psnr(img1, img2); |
| 474 | mismatch_psnr_ += mismatch_psnr; |
| 475 | ++mismatch_nframes_; |
| 476 | } |
| 477 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 478 | unsigned int GetMismatchFrames() { return mismatch_nframes_; } |
Marco | b9cb955 | 2016-03-07 16:58:06 -0800 | [diff] [blame] | 479 | |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 480 | void DefaultConfig() { |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 481 | cfg_.rc_buf_initial_sz = 500; |
| 482 | cfg_.rc_buf_optimal_sz = 600; |
| 483 | cfg_.rc_buf_sz = 1000; |
| 484 | cfg_.rc_min_quantizer = 2; |
| 485 | cfg_.rc_max_quantizer = 56; |
| 486 | cfg_.rc_undershoot_pct = 50; |
| 487 | cfg_.rc_overshoot_pct = 50; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 488 | cfg_.rc_end_usage = AOM_CBR; |
| 489 | cfg_.kf_mode = AOM_KF_AUTO; |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 490 | cfg_.g_lag_in_frames = 0; |
| 491 | cfg_.kf_min_dist = cfg_.kf_max_dist = 3000; |
| 492 | // Enable dropped frames. |
| 493 | cfg_.rc_dropframe_thresh = 1; |
Soo-Chul Han | 2638cb5 | 2017-11-22 16:34:47 -0500 | [diff] [blame] | 494 | // Disable error_resilience mode. |
| 495 | cfg_.g_error_resilient = 0; |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 496 | // Run at low bitrate. |
| 497 | cfg_.rc_target_bitrate = 200; |
Imdad Sardharwalla | 102c865 | 2018-02-23 16:35:13 +0000 | [diff] [blame] | 498 | // We use max(kInitialWidth, kInitialHeight) because during the test |
| 499 | // the width and height of the frame are swapped |
| 500 | cfg_.g_forced_max_frame_width = cfg_.g_forced_max_frame_height = |
| 501 | AOMMAX(kInitialWidth, kInitialHeight); |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 502 | } |
| 503 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 504 | std::vector<FrameInfo> frame_info_list_; |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 505 | int set_cpu_used_; |
jackychen | ca8f8fd | 2015-09-15 15:47:11 -0700 | [diff] [blame] | 506 | bool change_bitrate_; |
Marco | b9cb955 | 2016-03-07 16:58:06 -0800 | [diff] [blame] | 507 | double mismatch_psnr_; |
| 508 | int mismatch_nframes_; |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 509 | }; |
| 510 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 511 | TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) { |
jackychen | 55c8843 | 2015-11-09 14:58:14 -0800 | [diff] [blame] | 512 | ResizingVideoSource video; |
Marco | 3cbc26f | 2016-02-10 11:39:04 -0800 | [diff] [blame] | 513 | video.flag_codec_ = 1; |
jackychen | 55c8843 | 2015-11-09 14:58:14 -0800 | [diff] [blame] | 514 | DefaultConfig(); |
| 515 | change_bitrate_ = false; |
Marco | b9cb955 | 2016-03-07 16:58:06 -0800 | [diff] [blame] | 516 | mismatch_psnr_ = 0.0; |
| 517 | mismatch_nframes_ = 0; |
jackychen | 55c8843 | 2015-11-09 14:58:14 -0800 | [diff] [blame] | 518 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 519 | |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 520 | // Check we decoded the same number of frames as we attempted to encode |
| 521 | ASSERT_EQ(frame_info_list_.size(), video.limit()); |
| 522 | |
jackychen | 55c8843 | 2015-11-09 14:58:14 -0800 | [diff] [blame] | 523 | for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); |
| 524 | info != frame_info_list_.end(); ++info) { |
| 525 | const unsigned int frame = static_cast<unsigned>(info->pts); |
Marco | 3cbc26f | 2016-02-10 11:39:04 -0800 | [diff] [blame] | 526 | unsigned int expected_w; |
| 527 | unsigned int expected_h; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 528 | ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight, &expected_w, |
| 529 | &expected_h, 1); |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 530 | EXPECT_EQ(expected_w, info->w) |
| 531 | << "Frame " << frame << " had unexpected width"; |
| 532 | EXPECT_EQ(expected_h, info->h) |
| 533 | << "Frame " << frame << " had unexpected height"; |
Marco | b9cb955 | 2016-03-07 16:58:06 -0800 | [diff] [blame] | 534 | EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames()); |
jackychen | 55c8843 | 2015-11-09 14:58:14 -0800 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 538 | // Verify the dynamic resizer behavior for real time, 1 pass CBR mode. |
| 539 | // Run at low bitrate, with resize_allowed = 1, and verify that we get |
| 540 | // one resize down event. |
Urvang Joshi | c9ac07f | 2017-08-15 12:21:35 -0700 | [diff] [blame] | 541 | TEST_P(ResizeRealtimeTest, DISABLED_TestInternalResizeDown) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 542 | ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 543 | 30, 1, 0, 299); |
| 544 | DefaultConfig(); |
jackychen | 55c8843 | 2015-11-09 14:58:14 -0800 | [diff] [blame] | 545 | cfg_.g_w = 352; |
| 546 | cfg_.g_h = 288; |
jackychen | ca8f8fd | 2015-09-15 15:47:11 -0700 | [diff] [blame] | 547 | change_bitrate_ = false; |
Marco | b9cb955 | 2016-03-07 16:58:06 -0800 | [diff] [blame] | 548 | mismatch_psnr_ = 0.0; |
| 549 | mismatch_nframes_ = 0; |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 550 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 551 | |
| 552 | unsigned int last_w = cfg_.g_w; |
| 553 | unsigned int last_h = cfg_.g_h; |
| 554 | int resize_count = 0; |
| 555 | for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); |
| 556 | info != frame_info_list_.end(); ++info) { |
| 557 | if (info->w != last_w || info->h != last_h) { |
| 558 | // Verify that resize down occurs. |
| 559 | ASSERT_LT(info->w, last_w); |
| 560 | ASSERT_LT(info->h, last_h); |
| 561 | last_w = info->w; |
| 562 | last_h = info->h; |
| 563 | resize_count++; |
| 564 | } |
| 565 | } |
| 566 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 567 | #if CONFIG_AV1_DECODER |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 568 | // Verify that we get 1 resize down event in this test. |
| 569 | ASSERT_EQ(1, resize_count) << "Resizing should occur."; |
Marco | b9cb955 | 2016-03-07 16:58:06 -0800 | [diff] [blame] | 570 | EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames()); |
James Zern | 0616fa6 | 2016-04-26 19:56:44 -0700 | [diff] [blame] | 571 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 572 | printf("Warning: AV1 decoder unavailable, unable to check resize count!\n"); |
James Zern | 0616fa6 | 2016-04-26 19:56:44 -0700 | [diff] [blame] | 573 | #endif |
jackychen | 9ac42bc | 2015-09-15 14:17:04 -0700 | [diff] [blame] | 574 | } |
| 575 | |
jackychen | ca8f8fd | 2015-09-15 15:47:11 -0700 | [diff] [blame] | 576 | // Verify the dynamic resizer behavior for real time, 1 pass CBR mode. |
| 577 | // Start at low target bitrate, raise the bitrate in the middle of the clip, |
| 578 | // scaling-up should occur after bitrate changed. |
Urvang Joshi | c9ac07f | 2017-08-15 12:21:35 -0700 | [diff] [blame] | 579 | TEST_P(ResizeRealtimeTest, DISABLED_TestInternalResizeDownUpChangeBitRate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 580 | ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
jackychen | 0465aa4 | 2015-11-09 14:04:58 -0800 | [diff] [blame] | 581 | 30, 1, 0, 359); |
jackychen | ca8f8fd | 2015-09-15 15:47:11 -0700 | [diff] [blame] | 582 | DefaultConfig(); |
jackychen | 55c8843 | 2015-11-09 14:58:14 -0800 | [diff] [blame] | 583 | cfg_.g_w = 352; |
| 584 | cfg_.g_h = 288; |
jackychen | ca8f8fd | 2015-09-15 15:47:11 -0700 | [diff] [blame] | 585 | change_bitrate_ = true; |
Marco | b9cb955 | 2016-03-07 16:58:06 -0800 | [diff] [blame] | 586 | mismatch_psnr_ = 0.0; |
| 587 | mismatch_nframes_ = 0; |
jackychen | ca8f8fd | 2015-09-15 15:47:11 -0700 | [diff] [blame] | 588 | // Disable dropped frames. |
| 589 | cfg_.rc_dropframe_thresh = 0; |
| 590 | // Starting bitrate low. |
jackychen | 204cde5 | 2015-11-13 16:02:43 -0800 | [diff] [blame] | 591 | cfg_.rc_target_bitrate = 80; |
jackychen | ca8f8fd | 2015-09-15 15:47:11 -0700 | [diff] [blame] | 592 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 593 | |
| 594 | unsigned int last_w = cfg_.g_w; |
| 595 | unsigned int last_h = cfg_.g_h; |
| 596 | int resize_count = 0; |
| 597 | for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); |
| 598 | info != frame_info_list_.end(); ++info) { |
| 599 | if (info->w != last_w || info->h != last_h) { |
| 600 | resize_count++; |
| 601 | if (resize_count == 1) { |
| 602 | // Verify that resize down occurs. |
| 603 | ASSERT_LT(info->w, last_w); |
| 604 | ASSERT_LT(info->h, last_h); |
| 605 | } else if (resize_count == 2) { |
| 606 | // Verify that resize up occurs. |
| 607 | ASSERT_GT(info->w, last_w); |
| 608 | ASSERT_GT(info->h, last_h); |
| 609 | } |
| 610 | last_w = info->w; |
| 611 | last_h = info->h; |
| 612 | } |
| 613 | } |
| 614 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 615 | #if CONFIG_AV1_DECODER |
jackychen | 204cde5 | 2015-11-13 16:02:43 -0800 | [diff] [blame] | 616 | // Verify that we get 2 resize events in this test. |
| 617 | ASSERT_EQ(resize_count, 2) << "Resizing should occur twice."; |
Marco | b9cb955 | 2016-03-07 16:58:06 -0800 | [diff] [blame] | 618 | EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames()); |
James Zern | 0616fa6 | 2016-04-26 19:56:44 -0700 | [diff] [blame] | 619 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 620 | printf("Warning: AV1 decoder unavailable, unable to check resize count!\n"); |
James Zern | 0616fa6 | 2016-04-26 19:56:44 -0700 | [diff] [blame] | 621 | #endif |
jackychen | ca8f8fd | 2015-09-15 15:47:11 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 624 | aom_img_fmt_t CspForFrameNumber(int frame) { |
| 625 | if (frame < 10) return AOM_IMG_FMT_I420; |
| 626 | if (frame < 20) return AOM_IMG_FMT_I444; |
| 627 | return AOM_IMG_FMT_I420; |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | class ResizeCspTest : public ResizeTest { |
| 631 | protected: |
| 632 | #if WRITE_COMPRESSED_STREAM |
| 633 | ResizeCspTest() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 634 | : ResizeTest(), frame0_psnr_(0.0), outfile_(NULL), out_frames_(0) {} |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 635 | #else |
| 636 | ResizeCspTest() : ResizeTest(), frame0_psnr_(0.0) {} |
| 637 | #endif |
| 638 | |
| 639 | virtual ~ResizeCspTest() {} |
| 640 | |
| 641 | virtual void BeginPassHook(unsigned int /*pass*/) { |
| 642 | #if WRITE_COMPRESSED_STREAM |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 643 | outfile_ = fopen("av11-2-05-cspchape.ivf", "wb"); |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 644 | #endif |
| 645 | } |
| 646 | |
| 647 | virtual void EndPassHook() { |
| 648 | #if WRITE_COMPRESSED_STREAM |
| 649 | if (outfile_) { |
| 650 | if (!fseek(outfile_, 0, SEEK_SET)) |
| 651 | write_ivf_file_header(&cfg_, out_frames_, outfile_); |
| 652 | fclose(outfile_); |
| 653 | outfile_ = NULL; |
| 654 | } |
| 655 | #endif |
| 656 | } |
| 657 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 658 | virtual void PreEncodeFrameHook(libaom_test::VideoSource *video, |
| 659 | libaom_test::Encoder *encoder) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 660 | if (CspForFrameNumber(video->frame()) != AOM_IMG_FMT_I420 && |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 661 | cfg_.g_profile != 1) { |
| 662 | cfg_.g_profile = 1; |
| 663 | encoder->Config(&cfg_); |
| 664 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 665 | if (CspForFrameNumber(video->frame()) == AOM_IMG_FMT_I420 && |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 666 | cfg_.g_profile != 0) { |
| 667 | cfg_.g_profile = 0; |
| 668 | encoder->Config(&cfg_); |
| 669 | } |
| 670 | } |
| 671 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 672 | virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 673 | if (frame0_psnr_ == 0.) frame0_psnr_ = pkt->data.psnr.psnr[0]; |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 674 | EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 2.0); |
| 675 | } |
| 676 | |
| 677 | #if WRITE_COMPRESSED_STREAM |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 678 | virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) { |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 679 | ++out_frames_; |
| 680 | |
| 681 | // Write initial file header if first frame. |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 682 | if (pkt->data.frame.pts == 0) write_ivf_file_header(&cfg_, 0, outfile_); |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 683 | |
| 684 | // Write frame header and data. |
| 685 | write_ivf_frame_header(pkt, outfile_); |
| 686 | (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_); |
| 687 | } |
| 688 | #endif |
| 689 | |
| 690 | double frame0_psnr_; |
| 691 | #if WRITE_COMPRESSED_STREAM |
| 692 | FILE *outfile_; |
| 693 | unsigned int out_frames_; |
| 694 | #endif |
| 695 | }; |
| 696 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 697 | class ResizingCspVideoSource : public ::libaom_test::DummyVideoSource { |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 698 | public: |
| 699 | ResizingCspVideoSource() { |
| 700 | SetSize(kInitialWidth, kInitialHeight); |
| 701 | limit_ = 30; |
| 702 | } |
| 703 | |
| 704 | virtual ~ResizingCspVideoSource() {} |
| 705 | |
| 706 | protected: |
| 707 | virtual void Next() { |
| 708 | ++frame_; |
| 709 | SetImageFormat(CspForFrameNumber(frame_)); |
| 710 | FillFrame(); |
| 711 | } |
| 712 | }; |
| 713 | |
Debargha Mukherjee | 34e3a14 | 2017-10-05 12:46:14 -0700 | [diff] [blame] | 714 | #if (defined(DISABLE_TRELLISQ_SEARCH) && DISABLE_TRELLISQ_SEARCH) |
Angie Chiang | a603488 | 2017-09-28 15:35:14 -0700 | [diff] [blame] | 715 | TEST_P(ResizeCspTest, DISABLED_TestResizeCspWorks) { |
| 716 | #else |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 717 | TEST_P(ResizeCspTest, TestResizeCspWorks) { |
Angie Chiang | a603488 | 2017-09-28 15:35:14 -0700 | [diff] [blame] | 718 | #endif |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 719 | ResizingCspVideoSource video; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 720 | init_flags_ = AOM_CODEC_USE_PSNR; |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 721 | cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = 48; |
| 722 | cfg_.g_lag_in_frames = 0; |
| 723 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 724 | |
| 725 | // Check we decoded the same number of frames as we attempted to encode |
| 726 | ASSERT_EQ(frame_info_list_.size(), video.limit()); |
Alex Converse | 797a255 | 2015-01-15 13:56:55 -0800 | [diff] [blame] | 727 | } |
| 728 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 729 | AV1_INSTANTIATE_TEST_CASE(ResizeTest, |
| 730 | ::testing::Values(::libaom_test::kRealTime)); |
Debargha Mukherjee | 15b6ae0 | 2017-10-10 19:56:05 -0700 | [diff] [blame] | 731 | AV1_INSTANTIATE_TEST_CASE(ResizeInternalTestLarge, |
Urvang Joshi | c9ac07f | 2017-08-15 12:21:35 -0700 | [diff] [blame] | 732 | ::testing::Values(::libaom_test::kOnePassGood)); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 733 | AV1_INSTANTIATE_TEST_CASE(ResizeRealtimeTest, |
| 734 | ::testing::Values(::libaom_test::kRealTime), |
| 735 | ::testing::Range(5, 9)); |
| 736 | AV1_INSTANTIATE_TEST_CASE(ResizeCspTest, |
| 737 | ::testing::Values(::libaom_test::kRealTime)); |
John Koleszar | 2fb29ff | 2012-05-23 12:55:27 -0700 | [diff] [blame] | 738 | } // namespace |