mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 1 | /* |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2 | * Copyright (c) 2013 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 | */ |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 10 | |
| 11 | #include <algorithm> |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 12 | #include <iterator> |
| 13 | #include <list> |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 14 | #include <memory> |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 15 | #include <set> |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/call/transport.h" |
| 18 | #include "call/rtp_stream_receiver_controller.h" |
| 19 | #include "call/rtx_receive_stream.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 20 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "modules/rtp_rtcp/include/receive_statistics.h" |
| 22 | #include "modules/rtp_rtcp/include/rtp_rtcp.h" |
| 23 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 24 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
| 25 | #include "rtc_base/rate_limiter.h" |
| 26 | #include "test/gtest.h" |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 27 | |
danilchap | 6a6f089 | 2015-12-10 12:39:08 -0800 | [diff] [blame] | 28 | namespace webrtc { |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 29 | |
| 30 | const int kVideoNackListSize = 30; |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 31 | const uint32_t kTestSsrc = 3456; |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 32 | const uint32_t kTestRtxSsrc = kTestSsrc + 1; |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 33 | const uint16_t kTestSequenceNumber = 2345; |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 34 | const uint32_t kTestNumberOfPackets = 1350; |
| 35 | const int kTestNumberOfRtxPackets = 149; |
| 36 | const int kNumFrames = 30; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 37 | const int kPayloadType = 123; |
| 38 | const int kRtxPayloadType = 98; |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 39 | const int64_t kMaxRttMs = 1000; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 40 | |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 41 | class VerifyingMediaStream : public RtpPacketSinkInterface { |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 42 | public: |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 43 | VerifyingMediaStream() {} |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 44 | |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 45 | void OnRtpPacket(const RtpPacketReceived& packet) override { |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 46 | if (!sequence_numbers_.empty()) |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 47 | EXPECT_EQ(kTestSsrc, packet.Ssrc()); |
| 48 | |
| 49 | sequence_numbers_.push_back(packet.SequenceNumber()); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 50 | } |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 51 | std::list<uint16_t> sequence_numbers_; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | class RtxLoopBackTransport : public webrtc::Transport { |
| 55 | public: |
| 56 | explicit RtxLoopBackTransport(uint32_t rtx_ssrc) |
| 57 | : count_(0), |
| 58 | packet_loss_(0), |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 59 | consecutive_drop_start_(0), |
| 60 | consecutive_drop_end_(0), |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 61 | rtx_ssrc_(rtx_ssrc), |
| 62 | count_rtx_ssrc_(0), |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 63 | module_(NULL) {} |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 64 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 65 | void SetSendModule(RtpRtcp* rtpRtcpModule) { module_ = rtpRtcpModule; } |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 66 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 67 | void DropEveryNthPacket(int n) { packet_loss_ = n; } |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 68 | |
| 69 | void DropConsecutivePackets(int start, int total) { |
| 70 | consecutive_drop_start_ = start; |
| 71 | consecutive_drop_end_ = start + total; |
| 72 | packet_loss_ = 0; |
| 73 | } |
| 74 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 75 | bool SendRtp(const uint8_t* data, |
| 76 | size_t len, |
| 77 | const PacketOptions& options) override { |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 78 | count_++; |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 79 | RtpPacketReceived packet; |
| 80 | if (!packet.Parse(data, len)) |
nisse | a646853 | 2017-09-08 05:00:54 -0700 | [diff] [blame] | 81 | return false; |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 82 | if (packet.Ssrc() == rtx_ssrc_) { |
| 83 | count_rtx_ssrc_++; |
| 84 | } else { |
| 85 | // For non-RTX packets only. |
terelius | e64fbce | 2015-09-17 03:19:45 -0700 | [diff] [blame] | 86 | expected_sequence_numbers_.insert(expected_sequence_numbers_.end(), |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 87 | packet.SequenceNumber()); |
terelius | e64fbce | 2015-09-17 03:19:45 -0700 | [diff] [blame] | 88 | } |
| 89 | if (packet_loss_ > 0) { |
| 90 | if ((count_ % packet_loss_) == 0) { |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 91 | return true; |
terelius | e64fbce | 2015-09-17 03:19:45 -0700 | [diff] [blame] | 92 | } |
| 93 | } else if (count_ >= consecutive_drop_start_ && |
| 94 | count_ < consecutive_drop_end_) { |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 95 | return true; |
terelius | e64fbce | 2015-09-17 03:19:45 -0700 | [diff] [blame] | 96 | } |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 97 | EXPECT_TRUE(stream_receiver_controller_.OnRtpPacket(packet)); |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 98 | return true; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 99 | } |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 100 | |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 101 | bool SendRtcp(const uint8_t* data, size_t len) override { |
nisse | 479d3d7 | 2017-09-13 07:53:37 -0700 | [diff] [blame] | 102 | module_->IncomingRtcpPacket((const uint8_t*)data, len); |
| 103 | return true; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 104 | } |
| 105 | int count_; |
| 106 | int packet_loss_; |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 107 | int consecutive_drop_start_; |
| 108 | int consecutive_drop_end_; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 109 | uint32_t rtx_ssrc_; |
| 110 | int count_rtx_ssrc_; |
| 111 | RtpRtcp* module_; |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 112 | RtpStreamReceiverController stream_receiver_controller_; |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 113 | std::set<uint16_t> expected_sequence_numbers_; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
stefan@webrtc.org | 4121146 | 2013-03-18 15:00:50 +0000 | [diff] [blame] | 116 | class RtpRtcpRtxNackTest : public ::testing::Test { |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 117 | protected: |
stefan@webrtc.org | 4121146 | 2013-03-18 15:00:50 +0000 | [diff] [blame] | 118 | RtpRtcpRtxNackTest() |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 119 | : rtp_rtcp_module_(nullptr), |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 120 | transport_(kTestRtxSsrc), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 121 | rtx_stream_(&media_stream_, rtx_associated_payload_types_, kTestSsrc), |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 122 | payload_data_length(sizeof(payload_data)), |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 123 | fake_clock(123456), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 124 | retransmission_rate_limiter_(&fake_clock, kMaxRttMs) {} |
Danil Chapovalov | dd7e284 | 2018-03-09 15:37:03 +0000 | [diff] [blame] | 125 | ~RtpRtcpRtxNackTest() override {} |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 126 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 127 | void SetUp() override { |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 128 | RtpRtcp::Configuration configuration; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 129 | configuration.audio = false; |
| 130 | configuration.clock = &fake_clock; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 131 | receive_statistics_.reset(ReceiveStatistics::Create(&fake_clock)); |
| 132 | configuration.receive_statistics = receive_statistics_.get(); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 133 | configuration.outgoing_transport = &transport_; |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 134 | configuration.retransmission_rate_limiter = &retransmission_rate_limiter_; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 135 | rtp_rtcp_module_ = RtpRtcp::CreateRtpRtcp(configuration); |
| 136 | |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 137 | rtp_rtcp_module_->SetSSRC(kTestSsrc); |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 138 | rtp_rtcp_module_->SetRTCPStatus(RtcpMode::kCompound); |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 139 | rtp_rtcp_module_->SetStorePacketsStatus(true, 600); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 140 | EXPECT_EQ(0, rtp_rtcp_module_->SetSendingStatus(true)); |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 141 | rtp_rtcp_module_->SetSequenceNumber(kTestSequenceNumber); |
| 142 | rtp_rtcp_module_->SetStartTimestamp(111111); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 143 | |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 144 | // Used for NACK processing. |
| 145 | // TODO(nisse): Unclear on which side? It's confusing to use a |
| 146 | // single rtp_rtcp module for both send and receive side. |
| 147 | rtp_rtcp_module_->SetRemoteSSRC(kTestSsrc); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 148 | |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 149 | rtp_rtcp_module_->RegisterVideoSendPayload(kPayloadType, "video"); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 150 | rtp_rtcp_module_->SetRtxSendPayloadType(kRtxPayloadType, kPayloadType); |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 151 | transport_.SetSendModule(rtp_rtcp_module_); |
| 152 | media_receiver_ = transport_.stream_receiver_controller_.CreateReceiver( |
| 153 | kTestSsrc, &media_stream_); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 154 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 155 | for (size_t n = 0; n < payload_data_length; n++) { |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 156 | payload_data[n] = n % 10; |
| 157 | } |
| 158 | } |
| 159 | |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 160 | int BuildNackList(uint16_t* nack_list) { |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 161 | media_stream_.sequence_numbers_.sort(); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 162 | std::list<uint16_t> missing_sequence_numbers; |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 163 | std::list<uint16_t>::iterator it = media_stream_.sequence_numbers_.begin(); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 164 | |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 165 | while (it != media_stream_.sequence_numbers_.end()) { |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 166 | uint16_t sequence_number_1 = *it; |
| 167 | ++it; |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 168 | if (it != media_stream_.sequence_numbers_.end()) { |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 169 | uint16_t sequence_number_2 = *it; |
| 170 | // Add all missing sequence numbers to list |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 171 | for (uint16_t i = sequence_number_1 + 1; i < sequence_number_2; ++i) { |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 172 | missing_sequence_numbers.push_back(i); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | int n = 0; |
| 177 | for (it = missing_sequence_numbers.begin(); |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 178 | it != missing_sequence_numbers.end(); ++it) { |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 179 | nack_list[n++] = (*it); |
| 180 | } |
| 181 | return n; |
| 182 | } |
| 183 | |
| 184 | bool ExpectedPacketsReceived() { |
| 185 | std::list<uint16_t> received_sorted; |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 186 | std::copy(media_stream_.sequence_numbers_.begin(), |
| 187 | media_stream_.sequence_numbers_.end(), |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 188 | std::back_inserter(received_sorted)); |
| 189 | received_sorted.sort(); |
terelius | e64fbce | 2015-09-17 03:19:45 -0700 | [diff] [blame] | 190 | return received_sorted.size() == |
| 191 | transport_.expected_sequence_numbers_.size() && |
| 192 | std::equal(received_sorted.begin(), received_sorted.end(), |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 193 | transport_.expected_sequence_numbers_.begin()); |
| 194 | } |
| 195 | |
| 196 | void RunRtxTest(RtxMode rtx_method, int loss) { |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 197 | rtx_receiver_ = transport_.stream_receiver_controller_.CreateReceiver( |
| 198 | kTestRtxSsrc, &rtx_stream_); |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 +0000 | [diff] [blame] | 199 | rtp_rtcp_module_->SetRtxSendStatus(rtx_method); |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 200 | rtp_rtcp_module_->SetRtxSsrc(kTestRtxSsrc); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 201 | transport_.DropEveryNthPacket(loss); |
| 202 | uint32_t timestamp = 3000; |
| 203 | uint16_t nack_list[kVideoNackListSize]; |
| 204 | for (int frame = 0; frame < kNumFrames; ++frame) { |
Sami Kalliomäki | 426a80c | 2018-08-08 11:37:59 +0200 | [diff] [blame] | 205 | RTPVideoHeader video_header; |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 206 | EXPECT_TRUE(rtp_rtcp_module_->SendOutgoingData( |
| 207 | webrtc::kVideoFrameDelta, kPayloadType, timestamp, timestamp / 90, |
Sami Kalliomäki | 426a80c | 2018-08-08 11:37:59 +0200 | [diff] [blame] | 208 | payload_data, payload_data_length, nullptr, &video_header, nullptr)); |
sprang@webrtc.org | 43c8839 | 2015-01-29 09:09:17 +0000 | [diff] [blame] | 209 | // Min required delay until retransmit = 5 + RTT ms (RTT = 0). |
| 210 | fake_clock.AdvanceTimeMilliseconds(5); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 211 | int length = BuildNackList(nack_list); |
| 212 | if (length > 0) |
| 213 | rtp_rtcp_module_->SendNACK(nack_list, length); |
sprang@webrtc.org | 43c8839 | 2015-01-29 09:09:17 +0000 | [diff] [blame] | 214 | fake_clock.AdvanceTimeMilliseconds(28); // 33ms - 5ms delay. |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 215 | rtp_rtcp_module_->Process(); |
| 216 | // Prepare next frame. |
| 217 | timestamp += 3000; |
| 218 | } |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 219 | media_stream_.sequence_numbers_.sort(); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 220 | } |
| 221 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 222 | void TearDown() override { delete rtp_rtcp_module_; } |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 223 | |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 224 | std::unique_ptr<ReceiveStatistics> receive_statistics_; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 225 | RtpRtcp* rtp_rtcp_module_; |
| 226 | RtxLoopBackTransport transport_; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 227 | const std::map<int, int> rtx_associated_payload_types_ = { |
| 228 | {kRtxPayloadType, kPayloadType}}; |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 229 | VerifyingMediaStream media_stream_; |
| 230 | RtxReceiveStream rtx_stream_; |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 231 | uint8_t payload_data[65000]; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 232 | size_t payload_data_length; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 233 | SimulatedClock fake_clock; |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 234 | RateLimiter retransmission_rate_limiter_; |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 235 | std::unique_ptr<RtpStreamReceiverInterface> media_receiver_; |
| 236 | std::unique_ptr<RtpStreamReceiverInterface> rtx_receiver_; |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 239 | TEST_F(RtpRtcpRtxNackTest, LongNackList) { |
| 240 | const int kNumPacketsToDrop = 900; |
| 241 | const int kNumRequiredRtcp = 4; |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 242 | uint32_t timestamp = 3000; |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 243 | uint16_t nack_list[kNumPacketsToDrop]; |
| 244 | // Disable StorePackets to be able to set a larger packet history. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 245 | rtp_rtcp_module_->SetStorePacketsStatus(false, 0); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 246 | // Enable StorePackets with a packet history of 2000 packets. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 247 | rtp_rtcp_module_->SetStorePacketsStatus(true, 2000); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 248 | // Drop 900 packets from the second one so that we get a NACK list which is |
| 249 | // big enough to require 4 RTCP packets to be fully transmitted to the sender. |
| 250 | transport_.DropConsecutivePackets(2, kNumPacketsToDrop); |
| 251 | // Send 30 frames which at the default size is roughly what we need to get |
| 252 | // enough packets. |
| 253 | for (int frame = 0; frame < kNumFrames; ++frame) { |
Sami Kalliomäki | 426a80c | 2018-08-08 11:37:59 +0200 | [diff] [blame] | 254 | RTPVideoHeader video_header; |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 255 | EXPECT_TRUE(rtp_rtcp_module_->SendOutgoingData( |
| 256 | webrtc::kVideoFrameDelta, kPayloadType, timestamp, timestamp / 90, |
Sami Kalliomäki | 426a80c | 2018-08-08 11:37:59 +0200 | [diff] [blame] | 257 | payload_data, payload_data_length, nullptr, &video_header, nullptr)); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 258 | // Prepare next frame. |
| 259 | timestamp += 3000; |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 260 | fake_clock.AdvanceTimeMilliseconds(33); |
| 261 | rtp_rtcp_module_->Process(); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 262 | } |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 263 | EXPECT_FALSE(transport_.expected_sequence_numbers_.empty()); |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 264 | EXPECT_FALSE(media_stream_.sequence_numbers_.empty()); |
| 265 | size_t last_receive_count = media_stream_.sequence_numbers_.size(); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 266 | int length = BuildNackList(nack_list); |
| 267 | for (int i = 0; i < kNumRequiredRtcp - 1; ++i) { |
| 268 | rtp_rtcp_module_->SendNACK(nack_list, length); |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 269 | EXPECT_GT(media_stream_.sequence_numbers_.size(), last_receive_count); |
| 270 | last_receive_count = media_stream_.sequence_numbers_.size(); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 271 | EXPECT_FALSE(ExpectedPacketsReceived()); |
| 272 | } |
| 273 | rtp_rtcp_module_->SendNACK(nack_list, length); |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 274 | EXPECT_GT(media_stream_.sequence_numbers_.size(), last_receive_count); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 275 | EXPECT_TRUE(ExpectedPacketsReceived()); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 276 | } |
| 277 | |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 278 | TEST_F(RtpRtcpRtxNackTest, RtxNack) { |
| 279 | RunRtxTest(kRtxRetransmitted, 10); |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 280 | EXPECT_EQ(kTestSequenceNumber, *(media_stream_.sequence_numbers_.begin())); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 281 | EXPECT_EQ(kTestSequenceNumber + kTestNumberOfPackets - 1, |
nisse | f54573b | 2017-09-13 07:13:57 -0700 | [diff] [blame] | 282 | *(media_stream_.sequence_numbers_.rbegin())); |
| 283 | EXPECT_EQ(kTestNumberOfPackets, media_stream_.sequence_numbers_.size()); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 284 | EXPECT_EQ(kTestNumberOfRtxPackets, transport_.count_rtx_ssrc_); |
mikhal@webrtc.org | 6cfa390 | 2013-05-15 20:17:43 +0000 | [diff] [blame] | 285 | EXPECT_TRUE(ExpectedPacketsReceived()); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 286 | } |
danilchap | 6a6f089 | 2015-12-10 12:39:08 -0800 | [diff] [blame] | 287 | |
| 288 | } // namespace webrtc |