Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC 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 <cstring> | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | |
| 14 #include "webrtc/modules/video_coding/nack_module.h" | |
| 15 #include "webrtc/system_wrappers/include/clock.h" | |
| 16 | |
| 17 namespace webrtc { | |
| 18 class TestNackModule : public ::testing::Test, | |
| 19 public VCMNackSender, | |
| 20 public VCMKeyFrameRequestSender { | |
| 21 protected: | |
| 22 TestNackModule() | |
| 23 : clock_(new SimulatedClock(0)), | |
| 24 nack_module_(CriticalSectionWrapper::CreateCriticalSection(), | |
| 25 clock_.get(), | |
| 26 this, | |
| 27 this), | |
| 28 keyframes_requested_(0) {} | |
| 29 | |
| 30 int32_t SendNack(const uint16_t* sequence_numbers, uint16_t length) override { | |
| 31 for (int s = 0; s < length; ++s) { | |
| 32 sent_nacks_.push_back(sequence_numbers[s]); | |
| 33 } | |
| 34 return 0; | |
| 35 } | |
| 36 | |
| 37 int32_t RequestKeyFrame() override { | |
| 38 ++keyframes_requested_; | |
| 39 return 0; | |
| 40 } | |
| 41 | |
| 42 rtc::scoped_ptr<SimulatedClock> clock_; | |
| 43 NackModule nack_module_; | |
| 44 std::vector<uint16_t> sent_nacks_; | |
| 45 int keyframes_requested_; | |
| 46 }; | |
| 47 | |
| 48 TEST_F(TestNackModule, NackOnePacket) { | |
| 49 VCMPacket packet; | |
| 50 packet.seqNum = 1; | |
| 51 nack_module_.Notify(packet); | |
| 52 packet.seqNum = 3; | |
| 53 nack_module_.Notify(packet); | |
| 54 EXPECT_EQ(1u, sent_nacks_.size()); | |
| 55 EXPECT_EQ(2, sent_nacks_[0]); | |
| 56 } | |
| 57 | |
| 58 TEST_F(TestNackModule, ResendNack) { | |
| 59 VCMPacket packet; | |
| 60 packet.seqNum = 1; | |
| 61 nack_module_.Notify(packet); | |
| 62 packet.seqNum = 3; | |
| 63 nack_module_.Notify(packet); | |
| 64 EXPECT_EQ(1u, sent_nacks_.size()); | |
| 65 EXPECT_EQ(2, sent_nacks_[0]); | |
| 66 | |
| 67 // Default RTT is 100 | |
| 68 clock_->AdvanceTimeMilliseconds(99); | |
| 69 nack_module_.Process(); | |
| 70 EXPECT_EQ(1u, sent_nacks_.size()); | |
| 71 | |
| 72 clock_->AdvanceTimeMilliseconds(1); | |
| 73 nack_module_.Process(); | |
| 74 EXPECT_EQ(2u, sent_nacks_.size()); | |
| 75 | |
| 76 nack_module_.UpdateRtt(50); | |
| 77 clock_->AdvanceTimeMilliseconds(100); | |
| 78 nack_module_.Process(); | |
| 79 EXPECT_EQ(3u, sent_nacks_.size()); | |
| 80 | |
| 81 clock_->AdvanceTimeMilliseconds(50); | |
| 82 nack_module_.Process(); | |
| 83 EXPECT_EQ(4u, sent_nacks_.size()); | |
| 84 | |
| 85 packet.seqNum = 2; | |
| 86 nack_module_.Notify(packet); | |
| 87 clock_->AdvanceTimeMilliseconds(50); | |
| 88 nack_module_.Process(); | |
| 89 EXPECT_EQ(4u, sent_nacks_.size()); | |
| 90 } | |
| 91 | |
| 92 TEST_F(TestNackModule, ResendPacketMaxRetries) { | |
| 93 VCMPacket packet; | |
| 94 packet.seqNum = 1; | |
| 95 nack_module_.Notify(packet); | |
| 96 packet.seqNum = 3; | |
| 97 nack_module_.Notify(packet); | |
| 98 EXPECT_EQ(1u, sent_nacks_.size()); | |
| 99 EXPECT_EQ(2, sent_nacks_[0]); | |
| 100 | |
| 101 for (size_t retries = 1; retries < 10; ++retries) { | |
| 102 clock_->AdvanceTimeMilliseconds(100); | |
| 103 nack_module_.Process(); | |
| 104 EXPECT_EQ(retries+1, sent_nacks_.size()); | |
| 105 } | |
| 106 | |
| 107 clock_->AdvanceTimeMilliseconds(100); | |
| 108 nack_module_.Process(); | |
| 109 EXPECT_EQ(10u, sent_nacks_.size()); | |
| 110 } | |
| 111 | |
| 112 TEST_F(TestNackModule, TooLargeNackList) { | |
| 113 VCMPacket packet; | |
| 114 packet.seqNum = 0; | |
| 115 nack_module_.Notify(packet); | |
| 116 packet.seqNum = 1000; | |
| 117 nack_module_.Notify(packet); | |
| 118 EXPECT_EQ(999u, sent_nacks_.size()); | |
| 119 EXPECT_EQ(0, keyframes_requested_); | |
| 120 packet.seqNum = 1002; | |
| 121 nack_module_.Notify(packet); | |
| 122 EXPECT_EQ(999u, sent_nacks_.size()); | |
| 123 EXPECT_EQ(1, keyframes_requested_); | |
| 124 packet.seqNum = 1003; | |
| 125 nack_module_.Notify(packet); | |
| 126 EXPECT_EQ(999u, sent_nacks_.size()); | |
| 127 EXPECT_EQ(1, keyframes_requested_); | |
| 128 } | |
| 129 | |
| 130 TEST_F(TestNackModule, TooLargeNackListWithKeyFrame) { | |
| 131 VCMPacket packet; | |
| 132 packet.seqNum = 0; | |
| 133 nack_module_.Notify(packet); | |
| 134 packet.seqNum = 1; | |
| 135 packet.isFirstPacket = true; | |
| 136 packet.frameType = kVideoFrameKey; | |
| 137 nack_module_.Notify(packet); | |
| 138 packet.seqNum = 1000; | |
| 139 packet.isFirstPacket = false; | |
| 140 packet.frameType = kVideoFrameKey; | |
| 141 nack_module_.Notify(packet); | |
| 142 EXPECT_EQ(998u, sent_nacks_.size()); | |
| 143 EXPECT_EQ(0, keyframes_requested_); | |
| 144 packet.seqNum = 1002; | |
| 145 nack_module_.Notify(packet); | |
| 146 EXPECT_EQ(999u, sent_nacks_.size()); | |
| 147 EXPECT_EQ(0, keyframes_requested_); | |
| 148 packet.seqNum = 1004; | |
| 149 nack_module_.Notify(packet); | |
| 150 EXPECT_EQ(999u, sent_nacks_.size()); | |
| 151 EXPECT_EQ(1, keyframes_requested_); | |
| 152 } | |
| 153 | |
|
stefan-webrtc
2016/02/23 12:29:02
I think it would be good to add more tests where w
| |
| 154 } // namespace webrtc | |
| OLD | NEW |