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. |
| 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; |
| 21 | const int kMaxDroppableFrames = 12; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 22 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 23 | class ErrorResilienceTestLarge |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 24 | : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>, |
| 25 | public ::libaom_test::EncoderTest { |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 26 | protected: |
Jim Bankoski | a0b5ed6 | 2014-03-12 08:13:16 -0700 | [diff] [blame] | 27 | ErrorResilienceTestLarge() |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 28 | : EncoderTest(GET_PARAM(0)), psnr_(0.0), nframes_(0), mismatch_psnr_(0.0), |
| 29 | mismatch_nframes_(0), encoding_mode_(GET_PARAM(1)) { |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 30 | Reset(); |
| 31 | } |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 32 | |
Jim Bankoski | a0b5ed6 | 2014-03-12 08:13:16 -0700 | [diff] [blame] | 33 | virtual ~ErrorResilienceTestLarge() {} |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 34 | |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 35 | void Reset() { |
| 36 | error_nframes_ = 0; |
| 37 | droppable_nframes_ = 0; |
Marco | 2c6d9c5 | 2015-01-11 15:26:44 -0800 | [diff] [blame] | 38 | pattern_switch_ = 0; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 41 | virtual void SetUp() { |
| 42 | InitializeConfig(); |
| 43 | SetMode(encoding_mode_); |
| 44 | } |
| 45 | |
| 46 | virtual void BeginPassHook(unsigned int /*pass*/) { |
| 47 | psnr_ = 0.0; |
| 48 | nframes_ = 0; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 49 | mismatch_psnr_ = 0.0; |
| 50 | mismatch_nframes_ = 0; |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 53 | virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) { |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 54 | psnr_ += pkt->data.psnr.psnr[0]; |
| 55 | nframes_++; |
| 56 | } |
| 57 | |
Urvang Joshi | d71a231 | 2016-07-14 12:33:48 -0700 | [diff] [blame] | 58 | virtual void PreEncodeFrameHook(libaom_test::VideoSource *video) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 59 | frame_flags_ &= |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 60 | ~(AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF); |
James Zern | cc73e1f | 2016-08-08 15:09:30 -0700 | [diff] [blame] | 61 | if (droppable_nframes_ > 0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 62 | (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] | 63 | for (unsigned int i = 0; i < droppable_nframes_; ++i) { |
Deb Mukherjee | 0d8723f | 2013-08-19 14:16:26 -0700 | [diff] [blame] | 64 | if (droppable_frames_[i] == video->frame()) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 65 | std::cout << "Encoding droppable frame: " << droppable_frames_[i] |
| 66 | << "\n"; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 67 | frame_flags_ |= (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | |
| 68 | AOM_EFLAG_NO_UPD_ARF); |
James Zern | cc73e1f | 2016-08-08 15:09:30 -0700 | [diff] [blame] | 69 | return; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 75 | double GetAveragePsnr() const { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 76 | if (nframes_) return psnr_ / nframes_; |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 77 | return 0.0; |
| 78 | } |
| 79 | |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 80 | double GetAverageMismatchPsnr() const { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 81 | if (mismatch_nframes_) return mismatch_psnr_ / mismatch_nframes_; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 82 | return 0.0; |
| 83 | } |
| 84 | |
| 85 | virtual bool DoDecode() const { |
| 86 | if (error_nframes_ > 0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 87 | (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] | 88 | for (unsigned int i = 0; i < error_nframes_; ++i) { |
| 89 | if (error_frames_[i] == nframes_ - 1) { |
| 90 | std::cout << " Skipping decoding frame: " |
| 91 | << error_frames_[i] << "\n"; |
| 92 | return 0; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | return 1; |
| 97 | } |
| 98 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 99 | virtual void MismatchHook(const aom_image_t *img1, const aom_image_t *img2) { |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 100 | double mismatch_psnr = compute_psnr(img1, img2); |
| 101 | mismatch_psnr_ += mismatch_psnr; |
| 102 | ++mismatch_nframes_; |
| 103 | // std::cout << "Mismatch frame psnr: " << mismatch_psnr << "\n"; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 104 | ::libaom_test::EncoderTest::MismatchHook(img1, img2); |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void SetErrorFrames(int num, unsigned int *list) { |
| 108 | if (num > kMaxErrorFrames) |
| 109 | num = kMaxErrorFrames; |
| 110 | else if (num < 0) |
| 111 | num = 0; |
| 112 | error_nframes_ = num; |
| 113 | for (unsigned int i = 0; i < error_nframes_; ++i) |
| 114 | error_frames_[i] = list[i]; |
| 115 | } |
| 116 | |
| 117 | void SetDroppableFrames(int num, unsigned int *list) { |
| 118 | if (num > kMaxDroppableFrames) |
| 119 | num = kMaxDroppableFrames; |
| 120 | else if (num < 0) |
| 121 | num = 0; |
| 122 | droppable_nframes_ = num; |
| 123 | for (unsigned int i = 0; i < droppable_nframes_; ++i) |
| 124 | droppable_frames_[i] = list[i]; |
| 125 | } |
| 126 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 127 | unsigned int GetMismatchFrames() { return mismatch_nframes_; } |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 128 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 129 | void SetPatternSwitch(int frame_switch) { pattern_switch_ = frame_switch; } |
Marco | 2c6d9c5 | 2015-01-11 15:26:44 -0800 | [diff] [blame] | 130 | |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 131 | private: |
| 132 | double psnr_; |
| 133 | unsigned int nframes_; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 134 | unsigned int error_nframes_; |
| 135 | unsigned int droppable_nframes_; |
Marco | 2c6d9c5 | 2015-01-11 15:26:44 -0800 | [diff] [blame] | 136 | unsigned int pattern_switch_; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 137 | double mismatch_psnr_; |
| 138 | unsigned int mismatch_nframes_; |
| 139 | unsigned int error_frames_[kMaxErrorFrames]; |
| 140 | unsigned int droppable_frames_[kMaxDroppableFrames]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 141 | libaom_test::TestMode encoding_mode_; |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
Jim Bankoski | a0b5ed6 | 2014-03-12 08:13:16 -0700 | [diff] [blame] | 144 | TEST_P(ErrorResilienceTestLarge, OnVersusOff) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 145 | const aom_rational timebase = { 33333333, 1000000000 }; |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 146 | cfg_.g_timebase = timebase; |
| 147 | cfg_.rc_target_bitrate = 2000; |
Deb Mukherjee | 0d8723f | 2013-08-19 14:16:26 -0700 | [diff] [blame] | 148 | cfg_.g_lag_in_frames = 10; |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 149 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 150 | init_flags_ = AOM_CODEC_USE_PSNR; |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 151 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 152 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
Yaowu Xu | 2e7da0a | 2017-05-08 15:30:08 -0700 | [diff] [blame] | 153 | timebase.den, timebase.num, 0, 12); |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 154 | |
| 155 | // Error resilient mode OFF. |
| 156 | cfg_.g_error_resilient = 0; |
| 157 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 158 | const double psnr_resilience_off = GetAveragePsnr(); |
| 159 | EXPECT_GT(psnr_resilience_off, 25.0); |
| 160 | |
| 161 | // Error resilient mode ON. |
| 162 | cfg_.g_error_resilient = 1; |
| 163 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 164 | const double psnr_resilience_on = GetAveragePsnr(); |
| 165 | EXPECT_GT(psnr_resilience_on, 25.0); |
| 166 | |
| 167 | // Test that turning on error resilient mode hurts by 10% at most. |
| 168 | if (psnr_resilience_off > 0.0) { |
| 169 | const double psnr_ratio = psnr_resilience_on / psnr_resilience_off; |
| 170 | EXPECT_GE(psnr_ratio, 0.9); |
| 171 | EXPECT_LE(psnr_ratio, 1.1); |
| 172 | } |
| 173 | } |
| 174 | |
Marco Paniconi | f61b962 | 2014-02-24 18:14:50 -0800 | [diff] [blame] | 175 | // Check for successful decoding and no encoder/decoder mismatch |
| 176 | // if we lose (i.e., drop before decoding) a set of droppable |
| 177 | // frames (i.e., frames that don't update any reference buffers). |
| 178 | // Check both isolated and consecutive loss. |
Jim Bankoski | a0b5ed6 | 2014-03-12 08:13:16 -0700 | [diff] [blame] | 179 | TEST_P(ErrorResilienceTestLarge, DropFramesWithoutRecovery) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 180 | const aom_rational timebase = { 33333333, 1000000000 }; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 181 | cfg_.g_timebase = timebase; |
John Koleszar | c0490a5 | 2013-05-07 12:58:32 -0700 | [diff] [blame] | 182 | cfg_.rc_target_bitrate = 500; |
Deb Mukherjee | 0d8723f | 2013-08-19 14:16:26 -0700 | [diff] [blame] | 183 | // FIXME(debargha): Fix this to work for any lag. |
| 184 | // Currently this test only works for lag = 0 |
| 185 | cfg_.g_lag_in_frames = 0; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 186 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 187 | init_flags_ = AOM_CODEC_USE_PSNR; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 188 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 189 | libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
Yaowu Xu | 2e7da0a | 2017-05-08 15:30:08 -0700 | [diff] [blame] | 190 | timebase.den, timebase.num, 0, 20); |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 191 | |
| 192 | // Error resilient mode ON. |
| 193 | cfg_.g_error_resilient = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 194 | cfg_.kf_mode = AOM_KF_DISABLED; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 195 | |
Marco Paniconi | f61b962 | 2014-02-24 18:14:50 -0800 | [diff] [blame] | 196 | // Set an arbitrary set of error frames same as droppable frames. |
| 197 | // In addition to isolated loss/drop, add a long consecutive series |
| 198 | // (of size 9) of dropped frames. |
Yaowu Xu | 2e7da0a | 2017-05-08 15:30:08 -0700 | [diff] [blame] | 199 | unsigned int num_droppable_frames = 5; |
| 200 | unsigned int droppable_frame_list[] = { 5, 10, 13, 16, 19 }; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 201 | SetDroppableFrames(num_droppable_frames, droppable_frame_list); |
| 202 | SetErrorFrames(num_droppable_frames, droppable_frame_list); |
| 203 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 204 | // Test that no mismatches have been found |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 205 | std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; |
| 206 | EXPECT_EQ(GetMismatchFrames(), (unsigned int)0); |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 207 | |
Marco Paniconi | f61b962 | 2014-02-24 18:14:50 -0800 | [diff] [blame] | 208 | // Reset previously set of error/droppable frames. |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 209 | Reset(); |
| 210 | |
John Koleszar | 9fba034 | 2013-05-07 13:02:45 -0700 | [diff] [blame] | 211 | #if 0 |
| 212 | // TODO(jkoleszar): This test is disabled for the time being as too |
| 213 | // sensitive. It's not clear how to set a reasonable threshold for |
| 214 | // this behavior. |
| 215 | |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 216 | // Now set an arbitrary set of error frames that are non-droppable |
| 217 | unsigned int num_error_frames = 3; |
| 218 | unsigned int error_frame_list[] = {3, 10, 20}; |
| 219 | SetErrorFrames(num_error_frames, error_frame_list); |
| 220 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
John Koleszar | 9fba034 | 2013-05-07 13:02:45 -0700 | [diff] [blame] | 221 | |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 222 | // Test that dropping an arbitrary set of inter frames does not hurt too much |
| 223 | // Note the Average Mismatch PSNR is the average of the PSNR between |
| 224 | // decoded frame and encoder's version of the same frame for all frames |
| 225 | // with mismatch. |
| 226 | const double psnr_resilience_mismatch = GetAverageMismatchPsnr(); |
| 227 | std::cout << " Mismatch PSNR: " |
| 228 | << psnr_resilience_mismatch << "\n"; |
| 229 | EXPECT_GT(psnr_resilience_mismatch, 20.0); |
John Koleszar | 9fba034 | 2013-05-07 13:02:45 -0700 | [diff] [blame] | 230 | #endif |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 233 | AV1_INSTANTIATE_TEST_CASE(ErrorResilienceTestLarge, ONE_PASS_TEST_MODES); |
Adrian Grange | cc017ca | 2012-10-02 12:16:27 -0700 | [diff] [blame] | 234 | } // namespace |