Adrian Grange | cc017ca | 2012-10-02 12:16: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 |
Frank Galligan | 38536f6 | 2013-12-12 08:36:34 -0800 | [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 | */ |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 11 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 13 | #include "test/codec_factory.h" |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 14 | #include "test/encode_test_driver.h" |
| 15 | #include "test/i420_video_source.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 16 | #include "test/util.h" |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 17 | |
| 18 | namespace { |
| 19 | |
Marco Paniconi | f61b962 | 2014-02-24 18:14:50 -0800 | [diff] [blame] | 20 | const int kMaxErrorFrames = 12; |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 21 | const int kMaxInvisibleErrorFrames = 12; |
Marco Paniconi | f61b962 | 2014-02-24 18:14:50 -0800 | [diff] [blame] | 22 | const int kMaxDroppableFrames = 12; |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 23 | const int kMaxErrorResilientFrames = 12; |
Debargha Mukherjee | 93b047e | 2018-03-29 11:27:42 -0700 | [diff] [blame] | 24 | const int kMaxNoMFMVFrames = 12; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 25 | const int kMaxPrimRefNoneFrames = 12; |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 26 | const int kMaxSFrames = 12; |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 27 | const int kCpuUsed = 1; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 28 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 29 | class ErrorResilienceTestLarge |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 30 | : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>, |
| 31 | public ::libaom_test::EncoderTest { |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 32 | protected: |
Jim Bankoski | a0b5ed6 | 2014-03-12 08:13:16 -0700 | [diff] [blame] | 33 | ErrorResilienceTestLarge() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 34 | : EncoderTest(GET_PARAM(0)), psnr_(0.0), nframes_(0), mismatch_psnr_(0.0), |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 35 | mismatch_nframes_(0), encoding_mode_(GET_PARAM(1)), allow_mismatch_(0) { |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 36 | Reset(); |
| 37 | } |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 38 | |
Jim Bankoski | a0b5ed6 | 2014-03-12 08:13:16 -0700 | [diff] [blame] | 39 | virtual ~ErrorResilienceTestLarge() {} |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 40 | |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 41 | void Reset() { |
| 42 | error_nframes_ = 0; |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 43 | invisible_error_nframes_ = 0; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 44 | droppable_nframes_ = 0; |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 45 | error_resilient_nframes_ = 0; |
Debargha Mukherjee | 93b047e | 2018-03-29 11:27:42 -0700 | [diff] [blame] | 46 | nomfmv_nframes_ = 0; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 47 | prim_ref_none_nframes_ = 0; |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 48 | s_nframes_ = 0; |
| 49 | } |
| 50 | |
| 51 | void SetupEncoder(int bitrate, int lag) { |
| 52 | const aom_rational timebase = { 33333333, 1000000000 }; |
| 53 | cfg_.g_timebase = timebase; |
| 54 | cfg_.rc_target_bitrate = bitrate; |
| 55 | cfg_.kf_mode = AOM_KF_DISABLED; |
| 56 | cfg_.g_lag_in_frames = lag; |
| 57 | init_flags_ = AOM_CODEC_USE_PSNR; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 60 | virtual void SetUp() { |
| 61 | InitializeConfig(); |
| 62 | SetMode(encoding_mode_); |
| 63 | } |
| 64 | |
| 65 | virtual void BeginPassHook(unsigned int /*pass*/) { |
| 66 | psnr_ = 0.0; |
| 67 | nframes_ = 0; |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 68 | decoded_nframes_ = 0; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 69 | mismatch_psnr_ = 0.0; |
| 70 | mismatch_nframes_ = 0; |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 73 | virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) { |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 74 | psnr_ += pkt->data.psnr.psnr[0]; |
| 75 | nframes_++; |
| 76 | } |
| 77 | |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 78 | virtual void PreEncodeFrameHook(libaom_test::VideoSource *video, |
| 79 | libaom_test::Encoder *encoder) { |
| 80 | if (video->frame() == 0) encoder->Control(AOME_SET_CPUUSED, kCpuUsed); |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 81 | frame_flags_ &= |
| 82 | ~(AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF | |
| 83 | AOM_EFLAG_NO_REF_FRAME_MVS | AOM_EFLAG_ERROR_RESILIENT | |
| 84 | AOM_EFLAG_SET_S_FRAME | AOM_EFLAG_SET_PRIMARY_REF_NONE); |
James Zern | cc73e1f | 2016-08-08 15:09:30 -0700 | [diff] [blame] | 85 | if (droppable_nframes_ > 0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 86 | (cfg_.g_pass == AOM_RC_LAST_PASS || cfg_.g_pass == AOM_RC_ONE_PASS)) { |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 87 | for (unsigned int i = 0; i < droppable_nframes_; ++i) { |
Deb Mukherjee | 0d8723f | 2013-08-19 14:16:26 -0700 | [diff] [blame] | 88 | if (droppable_frames_[i] == video->frame()) { |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 89 | std::cout << " Encoding droppable frame: " |
| 90 | << droppable_frames_[i] << "\n"; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 91 | frame_flags_ |= (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | |
| 92 | AOM_EFLAG_NO_UPD_ARF); |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 93 | break; |
| 94 | } |
| 95 | } |
| 96 | } |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 97 | |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 98 | if (error_resilient_nframes_ > 0 && |
| 99 | (cfg_.g_pass == AOM_RC_LAST_PASS || cfg_.g_pass == AOM_RC_ONE_PASS)) { |
| 100 | for (unsigned int i = 0; i < error_resilient_nframes_; ++i) { |
| 101 | if (error_resilient_frames_[i] == video->frame()) { |
| 102 | std::cout << " Encoding error_resilient frame: " |
| 103 | << error_resilient_frames_[i] << "\n"; |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 104 | frame_flags_ |= AOM_EFLAG_ERROR_RESILIENT; |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 105 | break; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | } |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 109 | |
Debargha Mukherjee | 93b047e | 2018-03-29 11:27:42 -0700 | [diff] [blame] | 110 | if (nomfmv_nframes_ > 0 && |
| 111 | (cfg_.g_pass == AOM_RC_LAST_PASS || cfg_.g_pass == AOM_RC_ONE_PASS)) { |
| 112 | for (unsigned int i = 0; i < nomfmv_nframes_; ++i) { |
| 113 | if (nomfmv_frames_[i] == video->frame()) { |
| 114 | std::cout << " Encoding no mfmv frame: " |
| 115 | << nomfmv_frames_[i] << "\n"; |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 116 | frame_flags_ |= AOM_EFLAG_NO_REF_FRAME_MVS; |
Debargha Mukherjee | 93b047e | 2018-03-29 11:27:42 -0700 | [diff] [blame] | 117 | break; |
| 118 | } |
| 119 | } |
| 120 | } |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 121 | |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 122 | if (prim_ref_none_nframes_ > 0 && |
| 123 | (cfg_.g_pass == AOM_RC_LAST_PASS || cfg_.g_pass == AOM_RC_ONE_PASS)) { |
| 124 | for (unsigned int i = 0; i < prim_ref_none_nframes_; ++i) { |
| 125 | if (prim_ref_none_frames_[i] == video->frame()) { |
| 126 | std::cout << " Encoding no PRIMARY_REF_NONE frame: " |
| 127 | << prim_ref_none_frames_[i] << "\n"; |
| 128 | frame_flags_ |= AOM_EFLAG_SET_PRIMARY_REF_NONE; |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 134 | encoder->Control(AV1E_SET_S_FRAME_MODE, 0); |
| 135 | if (s_nframes_ > 0 && |
| 136 | (cfg_.g_pass == AOM_RC_LAST_PASS || cfg_.g_pass == AOM_RC_ONE_PASS)) { |
| 137 | for (unsigned int i = 0; i < s_nframes_; ++i) { |
| 138 | if (s_frames_[i] == video->frame()) { |
| 139 | std::cout << " Encoding S frame: " << s_frames_[i] |
| 140 | << "\n"; |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 141 | frame_flags_ |= AOM_EFLAG_SET_S_FRAME; |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | } |
| 145 | } |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 148 | double GetAveragePsnr() const { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 149 | if (nframes_) return psnr_ / nframes_; |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 150 | return 0.0; |
| 151 | } |
| 152 | |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 153 | double GetAverageMismatchPsnr() const { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 154 | if (mismatch_nframes_) return mismatch_psnr_ / mismatch_nframes_; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 155 | return 0.0; |
| 156 | } |
| 157 | |
| 158 | virtual bool DoDecode() const { |
| 159 | if (error_nframes_ > 0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 160 | (cfg_.g_pass == AOM_RC_LAST_PASS || cfg_.g_pass == AOM_RC_ONE_PASS)) { |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 161 | for (unsigned int i = 0; i < error_nframes_; ++i) { |
| 162 | if (error_frames_[i] == nframes_ - 1) { |
| 163 | std::cout << " Skipping decoding frame: " |
| 164 | << error_frames_[i] << "\n"; |
| 165 | return 0; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | return 1; |
| 170 | } |
| 171 | |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 172 | virtual bool DoDecodeInvisible() const { |
| 173 | if (invisible_error_nframes_ > 0 && |
| 174 | (cfg_.g_pass == AOM_RC_LAST_PASS || cfg_.g_pass == AOM_RC_ONE_PASS)) { |
| 175 | for (unsigned int i = 0; i < invisible_error_nframes_; ++i) { |
| 176 | if (invisible_error_frames_[i] == nframes_ - 1) { |
| 177 | std::cout << " Skipping decoding all invisible frames in " |
| 178 | "frame pkt: " |
| 179 | << invisible_error_frames_[i] << "\n"; |
| 180 | return 0; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | return 1; |
| 185 | } |
| 186 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 187 | virtual void MismatchHook(const aom_image_t *img1, const aom_image_t *img2) { |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 188 | if (allow_mismatch_) { |
| 189 | double mismatch_psnr = compute_psnr(img1, img2); |
| 190 | mismatch_psnr_ += mismatch_psnr; |
| 191 | ++mismatch_nframes_; |
| 192 | // std::cout << "Mismatch frame psnr: " << mismatch_psnr << "\n"; |
| 193 | } else { |
| 194 | ::libaom_test::EncoderTest::MismatchHook(img1, img2); |
| 195 | } |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 198 | virtual void DecompressedFrameHook(const aom_image_t &img, |
| 199 | aom_codec_pts_t pts) { |
| 200 | (void)img; |
| 201 | (void)pts; |
| 202 | ++decoded_nframes_; |
| 203 | } |
| 204 | |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 205 | void SetErrorFrames(int num, unsigned int *list) { |
| 206 | if (num > kMaxErrorFrames) |
| 207 | num = kMaxErrorFrames; |
| 208 | else if (num < 0) |
| 209 | num = 0; |
| 210 | error_nframes_ = num; |
| 211 | for (unsigned int i = 0; i < error_nframes_; ++i) |
| 212 | error_frames_[i] = list[i]; |
| 213 | } |
| 214 | |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 215 | void SetInvisibleErrorFrames(int num, unsigned int *list) { |
| 216 | if (num > kMaxInvisibleErrorFrames) |
| 217 | num = kMaxInvisibleErrorFrames; |
| 218 | else if (num < 0) |
| 219 | num = 0; |
| 220 | invisible_error_nframes_ = num; |
| 221 | for (unsigned int i = 0; i < invisible_error_nframes_; ++i) |
| 222 | invisible_error_frames_[i] = list[i]; |
| 223 | } |
| 224 | |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 225 | void SetDroppableFrames(int num, unsigned int *list) { |
| 226 | if (num > kMaxDroppableFrames) |
| 227 | num = kMaxDroppableFrames; |
| 228 | else if (num < 0) |
| 229 | num = 0; |
| 230 | droppable_nframes_ = num; |
| 231 | for (unsigned int i = 0; i < droppable_nframes_; ++i) |
| 232 | droppable_frames_[i] = list[i]; |
| 233 | } |
| 234 | |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 235 | void SetErrorResilientFrames(int num, unsigned int *list) { |
| 236 | if (num > kMaxErrorResilientFrames) |
| 237 | num = kMaxErrorResilientFrames; |
| 238 | else if (num < 0) |
| 239 | num = 0; |
| 240 | error_resilient_nframes_ = num; |
| 241 | for (unsigned int i = 0; i < error_resilient_nframes_; ++i) |
| 242 | error_resilient_frames_[i] = list[i]; |
| 243 | } |
| 244 | |
Debargha Mukherjee | 93b047e | 2018-03-29 11:27:42 -0700 | [diff] [blame] | 245 | void SetNoMFMVFrames(int num, unsigned int *list) { |
| 246 | if (num > kMaxNoMFMVFrames) |
| 247 | num = kMaxNoMFMVFrames; |
| 248 | else if (num < 0) |
| 249 | num = 0; |
| 250 | nomfmv_nframes_ = num; |
| 251 | for (unsigned int i = 0; i < nomfmv_nframes_; ++i) |
| 252 | nomfmv_frames_[i] = list[i]; |
| 253 | } |
| 254 | |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 255 | void SetPrimaryRefNoneFrames(int num, unsigned int *list) { |
| 256 | if (num > kMaxPrimRefNoneFrames) |
| 257 | num = kMaxPrimRefNoneFrames; |
| 258 | else if (num < 0) |
| 259 | num = 0; |
| 260 | prim_ref_none_nframes_ = num; |
| 261 | for (unsigned int i = 0; i < prim_ref_none_nframes_; ++i) |
| 262 | prim_ref_none_frames_[i] = list[i]; |
| 263 | } |
| 264 | |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 265 | void SetSFrames(int num, unsigned int *list) { |
| 266 | if (num > kMaxSFrames) |
| 267 | num = kMaxSFrames; |
| 268 | else if (num < 0) |
| 269 | num = 0; |
| 270 | s_nframes_ = num; |
| 271 | for (unsigned int i = 0; i < s_nframes_; ++i) s_frames_[i] = list[i]; |
| 272 | } |
| 273 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 274 | unsigned int GetMismatchFrames() { return mismatch_nframes_; } |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 275 | unsigned int GetEncodedFrames() { return nframes_; } |
| 276 | unsigned int GetDecodedFrames() { return decoded_nframes_; } |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 277 | |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 278 | void SetAllowMismatch(int allow) { allow_mismatch_ = allow; } |
Marco | 2c6d9c5 | 2015-01-11 15:26:44 -0800 | [diff] [blame] | 279 | |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 280 | private: |
| 281 | double psnr_; |
| 282 | unsigned int nframes_; |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 283 | unsigned int decoded_nframes_; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 284 | unsigned int error_nframes_; |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 285 | unsigned int invisible_error_nframes_; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 286 | unsigned int droppable_nframes_; |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 287 | unsigned int error_resilient_nframes_; |
Debargha Mukherjee | 93b047e | 2018-03-29 11:27:42 -0700 | [diff] [blame] | 288 | unsigned int nomfmv_nframes_; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 289 | unsigned int prim_ref_none_nframes_; |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 290 | unsigned int s_nframes_; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 291 | double mismatch_psnr_; |
| 292 | unsigned int mismatch_nframes_; |
| 293 | unsigned int error_frames_[kMaxErrorFrames]; |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 294 | unsigned int invisible_error_frames_[kMaxInvisibleErrorFrames]; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 295 | unsigned int droppable_frames_[kMaxDroppableFrames]; |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 296 | unsigned int error_resilient_frames_[kMaxErrorResilientFrames]; |
Debargha Mukherjee | 93b047e | 2018-03-29 11:27:42 -0700 | [diff] [blame] | 297 | unsigned int nomfmv_frames_[kMaxNoMFMVFrames]; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 298 | unsigned int prim_ref_none_frames_[kMaxPrimRefNoneFrames]; |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 299 | unsigned int s_frames_[kMaxSFrames]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 300 | libaom_test::TestMode encoding_mode_; |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 301 | int allow_mismatch_; |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
Jim Bankoski | a0b5ed6 | 2014-03-12 08:13:16 -0700 | [diff] [blame] | 304 | TEST_P(ErrorResilienceTestLarge, OnVersusOff) { |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 305 | SetupEncoder(2000, 10); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 306 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 307 | cfg_.g_timebase.den, cfg_.g_timebase.num, |
| 308 | 0, 12); |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 309 | |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 310 | // Global error resilient mode OFF. |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 311 | cfg_.g_error_resilient = 0; |
| 312 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 313 | const double psnr_resilience_off = GetAveragePsnr(); |
| 314 | EXPECT_GT(psnr_resilience_off, 25.0); |
| 315 | |
Debargha Mukherjee | 9dec0c5 | 2018-03-25 09:09:36 -0700 | [diff] [blame] | 316 | Reset(); |
| 317 | // Error resilient mode ON for certain frames |
| 318 | unsigned int num_error_resilient_frames = 5; |
| 319 | unsigned int error_resilient_frame_list[] = { 3, 5, 6, 9, 11 }; |
| 320 | SetErrorResilientFrames(num_error_resilient_frames, |
| 321 | error_resilient_frame_list); |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 322 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 323 | const double psnr_resilience_on = GetAveragePsnr(); |
| 324 | EXPECT_GT(psnr_resilience_on, 25.0); |
| 325 | |
| 326 | // Test that turning on error resilient mode hurts by 10% at most. |
| 327 | if (psnr_resilience_off > 0.0) { |
| 328 | const double psnr_ratio = psnr_resilience_on / psnr_resilience_off; |
| 329 | EXPECT_GE(psnr_ratio, 0.9); |
| 330 | EXPECT_LE(psnr_ratio, 1.1); |
| 331 | } |
| 332 | } |
| 333 | |
Marco Paniconi | f61b962 | 2014-02-24 18:14:50 -0800 | [diff] [blame] | 334 | // Check for successful decoding and no encoder/decoder mismatch |
| 335 | // if we lose (i.e., drop before decoding) a set of droppable |
| 336 | // frames (i.e., frames that don't update any reference buffers). |
Jim Bankoski | a0b5ed6 | 2014-03-12 08:13:16 -0700 | [diff] [blame] | 337 | TEST_P(ErrorResilienceTestLarge, DropFramesWithoutRecovery) { |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 338 | SetupEncoder(500, 10); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 339 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 340 | cfg_.g_timebase.den, cfg_.g_timebase.num, |
| 341 | 0, 20); |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 342 | |
Marco Paniconi | f61b962 | 2014-02-24 18:14:50 -0800 | [diff] [blame] | 343 | // Set an arbitrary set of error frames same as droppable frames. |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 344 | unsigned int num_droppable_frames = 3; |
| 345 | unsigned int droppable_frame_list[] = { 5, 10, 13 }; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 346 | SetDroppableFrames(num_droppable_frames, droppable_frame_list); |
| 347 | SetErrorFrames(num_droppable_frames, droppable_frame_list); |
| 348 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 349 | // Test that no mismatches have been found |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 350 | std::cout << " Encoded frames: " << GetEncodedFrames() << "\n"; |
| 351 | std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 352 | std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 353 | EXPECT_EQ(GetEncodedFrames() - GetDecodedFrames(), num_droppable_frames); |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | // Check for ParseAbility property of an error-resilient frame. |
| 357 | // Encode a frame in error-resilient mode (E-frame), and disallow all |
| 358 | // subsequent frames from using MFMV. If frames are dropped before the |
| 359 | // E frame, all frames starting from the E frame should be parse-able. |
| 360 | TEST_P(ErrorResilienceTestLarge, ParseAbilityTest) { |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 361 | SetupEncoder(500, 10); |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 362 | |
| 363 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
Debargha Mukherjee | e09b391 | 2018-03-29 20:01:35 -0700 | [diff] [blame] | 364 | cfg_.g_timebase.den, cfg_.g_timebase.num, |
| 365 | 0, 15); |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 366 | |
| 367 | SetAllowMismatch(1); |
| 368 | |
sarahparker | d000125 | 2018-04-05 18:44:47 -0700 | [diff] [blame] | 369 | // Note that an E-frame cannot be forced on a frame that is a |
| 370 | // show_existing_frame, or a frame that comes directly after an invisible |
| 371 | // frame. Currently, this will cause an assertion failure. |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 372 | // Set an arbitrary error resilient (E) frame |
| 373 | unsigned int num_error_resilient_frames = 1; |
sarahparker | d000125 | 2018-04-05 18:44:47 -0700 | [diff] [blame] | 374 | unsigned int error_resilient_frame_list[] = { 8 }; |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 375 | SetErrorResilientFrames(num_error_resilient_frames, |
| 376 | error_resilient_frame_list); |
Sarah Parker | 52100eb | 2018-04-11 15:11:15 -0700 | [diff] [blame] | 377 | // Ensure that any invisible frames before the E frame are dropped |
| 378 | SetInvisibleErrorFrames(num_error_resilient_frames, |
| 379 | error_resilient_frame_list); |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 380 | // Set all frames after the error resilient frame to not allow MFMV and to |
| 381 | // use PRIMARY_REF_NONE for their primary_ref_frame. |
| 382 | unsigned int num_post_error_resilient_frames = 6; |
| 383 | unsigned int post_error_resilient_frame_list[] = { 9, 10, 11, 12, 13, 14 }; |
| 384 | SetNoMFMVFrames(num_post_error_resilient_frames, |
| 385 | post_error_resilient_frame_list); |
Sarah Parker | 5b1914d | 2018-04-13 16:05:52 -0700 | [diff] [blame] | 386 | // SetPrimaryRefNoneFrames(num_post_error_resilient_frames, |
| 387 | // post_error_resilient_frame_list); |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 388 | |
| 389 | // Set a few frames before the E frame that are lost (not decoded) |
sarahparker | d000125 | 2018-04-05 18:44:47 -0700 | [diff] [blame] | 390 | unsigned int num_error_frames = 5; |
| 391 | unsigned int error_frame_list[] = { 3, 4, 5, 6, 7 }; |
Debargha Mukherjee | 5729d17 | 2018-03-29 12:31:21 -0700 | [diff] [blame] | 392 | SetErrorFrames(num_error_frames, error_frame_list); |
| 393 | |
| 394 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 395 | std::cout << " Encoded frames: " << GetEncodedFrames() << "\n"; |
| 396 | std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; |
| 397 | std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; |
| 398 | EXPECT_EQ(GetEncodedFrames() - GetDecodedFrames(), num_error_frames); |
| 399 | // All frames following the E-frame and the E-frame are expected to have |
| 400 | // mismatches, but still be parse-able. |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 401 | EXPECT_LE(GetMismatchFrames(), num_post_error_resilient_frames + 1); |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 402 | } |
| 403 | |
Debargha Mukherjee | 1c7eec8 | 2018-03-29 20:02:44 -0700 | [diff] [blame] | 404 | // Check for ParseAbility property of an S frame. |
| 405 | // Encode an S-frame. If frames are dropped before the S-frame, all frames |
| 406 | // starting from the S frame should be parse-able. |
| 407 | TEST_P(ErrorResilienceTestLarge, SFrameTest) { |
sarahparker | d000125 | 2018-04-05 18:44:47 -0700 | [diff] [blame] | 408 | SetupEncoder(500, 10); |
Debargha Mukherjee | 1c7eec8 | 2018-03-29 20:02:44 -0700 | [diff] [blame] | 409 | |
| 410 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 411 | cfg_.g_timebase.den, cfg_.g_timebase.num, |
| 412 | 0, 15); |
| 413 | |
| 414 | SetAllowMismatch(1); |
| 415 | |
sarahparker | d000125 | 2018-04-05 18:44:47 -0700 | [diff] [blame] | 416 | // Note that an S-frame cannot be forced on a frame that is a |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 417 | // show_existing_frame. This issue still needs to be addressed. |
Debargha Mukherjee | 1c7eec8 | 2018-03-29 20:02:44 -0700 | [diff] [blame] | 418 | // Set an arbitrary S-frame |
| 419 | unsigned int num_s_frames = 1; |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 420 | unsigned int s_frame_list[] = { 7 }; |
Debargha Mukherjee | 1c7eec8 | 2018-03-29 20:02:44 -0700 | [diff] [blame] | 421 | SetSFrames(num_s_frames, s_frame_list); |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 422 | // Ensure that any invisible frames before the S frame are dropped |
| 423 | SetInvisibleErrorFrames(num_s_frames, s_frame_list); |
Debargha Mukherjee | 1c7eec8 | 2018-03-29 20:02:44 -0700 | [diff] [blame] | 424 | |
| 425 | // Set a few frames before the S frame that are lost (not decoded) |
sarahparker | 48065fc | 2018-04-06 17:12:54 -0700 | [diff] [blame] | 426 | unsigned int num_error_frames = 4; |
| 427 | unsigned int error_frame_list[] = { 3, 4, 5, 6 }; |
Debargha Mukherjee | 1c7eec8 | 2018-03-29 20:02:44 -0700 | [diff] [blame] | 428 | SetErrorFrames(num_error_frames, error_frame_list); |
| 429 | |
| 430 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 431 | std::cout << " Encoded frames: " << GetEncodedFrames() << "\n"; |
| 432 | std::cout << " Decoded frames: " << GetDecodedFrames() << "\n"; |
| 433 | std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; |
| 434 | EXPECT_EQ(GetEncodedFrames() - GetDecodedFrames(), num_error_frames); |
| 435 | // All frames following the S-frame and the S-frame are expected to have |
| 436 | // mismatches, but still be parse-able. |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 437 | EXPECT_LE(GetMismatchFrames(), GetEncodedFrames() - s_frame_list[0]); |
Debargha Mukherjee | 1c7eec8 | 2018-03-29 20:02:44 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Debargha Mukherjee | 776b641 | 2018-03-23 17:25:06 -0700 | [diff] [blame] | 440 | AV1_INSTANTIATE_TEST_CASE(ErrorResilienceTestLarge, NONREALTIME_TEST_MODES); |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 441 | } // namespace |