OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <list> | 11 #include <list> |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/modules/pacing/packet_router.h" | 16 #include "webrtc/modules/pacing/packet_router.h" |
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
18 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" | 18 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
| 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
19 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
20 | 21 |
21 using ::testing::_; | 22 using ::testing::_; |
22 using ::testing::AnyNumber; | 23 using ::testing::AnyNumber; |
23 using ::testing::NiceMock; | 24 using ::testing::NiceMock; |
24 using ::testing::Return; | 25 using ::testing::Return; |
25 | 26 |
26 namespace webrtc { | 27 namespace webrtc { |
27 | 28 |
28 class PacketRouterTest : public ::testing::Test { | 29 class PacketRouterTest : public ::testing::Test { |
29 public: | 30 public: |
30 PacketRouterTest() : packet_router_(new PacketRouter()) {} | 31 PacketRouterTest() : packet_router_(new PacketRouter()) {} |
31 protected: | 32 protected: |
32 const rtc::scoped_ptr<PacketRouter> packet_router_; | 33 const rtc::scoped_ptr<PacketRouter> packet_router_; |
33 }; | 34 }; |
34 | 35 |
35 TEST_F(PacketRouterTest, TimeToSendPacket) { | 36 TEST_F(PacketRouterTest, TimeToSendPacket) { |
36 MockRtpRtcp rtp_1; | 37 MockRtpRtcp rtp_1; |
37 MockRtpRtcp rtp_2; | 38 MockRtpRtcp rtp_2; |
38 packet_router_->AddRtpModule(&rtp_1); | 39 packet_router_->AddRtpModule(&rtp_1, true); |
39 packet_router_->AddRtpModule(&rtp_2); | 40 packet_router_->AddRtpModule(&rtp_2, true); |
40 | 41 |
41 const uint16_t kSsrc1 = 1234; | 42 const uint16_t kSsrc1 = 1234; |
42 uint16_t sequence_number = 17; | 43 uint16_t sequence_number = 17; |
43 uint64_t timestamp = 7890; | 44 uint64_t timestamp = 7890; |
44 bool retransmission = false; | 45 bool retransmission = false; |
45 | 46 |
46 // Send on the first module by letting rtp_1 be sending with correct ssrc. | 47 // Send on the first module by letting rtp_1 be sending with correct ssrc. |
47 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); | 48 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
48 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); | 49 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); |
49 EXPECT_CALL(rtp_1, TimeToSendPacket(kSsrc1, sequence_number, timestamp, | 50 EXPECT_CALL(rtp_1, TimeToSendPacket(kSsrc1, sequence_number, timestamp, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // Add a packet with incorrect ssrc and test it's dropped in the router. | 82 // Add a packet with incorrect ssrc and test it's dropped in the router. |
82 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); | 83 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
83 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); | 84 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); |
84 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 85 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
85 EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); | 86 EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); |
86 EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _)).Times(0); | 87 EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _)).Times(0); |
87 EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _)).Times(0); | 88 EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _)).Times(0); |
88 EXPECT_TRUE(packet_router_->TimeToSendPacket(kSsrc1 + kSsrc2, sequence_number, | 89 EXPECT_TRUE(packet_router_->TimeToSendPacket(kSsrc1 + kSsrc2, sequence_number, |
89 timestamp, retransmission)); | 90 timestamp, retransmission)); |
90 | 91 |
91 packet_router_->RemoveRtpModule(&rtp_1); | 92 packet_router_->RemoveRtpModule(&rtp_1, true); |
92 | 93 |
93 // rtp_1 has been removed, try sending a packet on that ssrc and make sure | 94 // rtp_1 has been removed, try sending a packet on that ssrc and make sure |
94 // it is dropped as expected by not expecting any calls to rtp_1. | 95 // it is dropped as expected by not expecting any calls to rtp_1. |
95 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 96 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
96 EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); | 97 EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); |
97 EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _)).Times(0); | 98 EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _)).Times(0); |
98 EXPECT_TRUE(packet_router_->TimeToSendPacket(kSsrc1, sequence_number, | 99 EXPECT_TRUE(packet_router_->TimeToSendPacket(kSsrc1, sequence_number, |
99 timestamp, retransmission)); | 100 timestamp, retransmission)); |
100 | 101 |
101 packet_router_->RemoveRtpModule(&rtp_2); | 102 packet_router_->RemoveRtpModule(&rtp_2, true); |
102 } | 103 } |
103 | 104 |
104 TEST_F(PacketRouterTest, TimeToSendPadding) { | 105 TEST_F(PacketRouterTest, TimeToSendPadding) { |
105 const uint16_t kSsrc1 = 1234; | 106 const uint16_t kSsrc1 = 1234; |
106 const uint16_t kSsrc2 = 4567; | 107 const uint16_t kSsrc2 = 4567; |
107 | 108 |
108 MockRtpRtcp rtp_1; | 109 MockRtpRtcp rtp_1; |
109 EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1)); | 110 EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1)); |
110 MockRtpRtcp rtp_2; | 111 MockRtpRtcp rtp_2; |
111 EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2)); | 112 EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2)); |
112 packet_router_->AddRtpModule(&rtp_1); | 113 packet_router_->AddRtpModule(&rtp_1, true); |
113 packet_router_->AddRtpModule(&rtp_2); | 114 packet_router_->AddRtpModule(&rtp_2, true); |
114 | 115 |
115 // Default configuration, sending padding on all modules sending media, | 116 // Default configuration, sending padding on all modules sending media, |
116 // ordered by SSRC. | 117 // ordered by SSRC. |
117 const size_t requested_padding_bytes = 1000; | 118 const size_t requested_padding_bytes = 1000; |
118 const size_t sent_padding_bytes = 890; | 119 const size_t sent_padding_bytes = 890; |
119 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); | 120 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
120 EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)) | 121 EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)) |
121 .Times(1) | 122 .Times(1) |
122 .WillOnce(Return(sent_padding_bytes)); | 123 .WillOnce(Return(sent_padding_bytes)); |
123 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 124 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
(...skipping 15 matching lines...) Expand all Loading... |
139 EXPECT_EQ(sent_padding_bytes, | 140 EXPECT_EQ(sent_padding_bytes, |
140 packet_router_->TimeToSendPadding(requested_padding_bytes)); | 141 packet_router_->TimeToSendPadding(requested_padding_bytes)); |
141 | 142 |
142 // No sending module at all. | 143 // No sending module at all. |
143 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); | 144 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); |
144 EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)).Times(0); | 145 EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)).Times(0); |
145 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); | 146 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); |
146 EXPECT_CALL(rtp_2, TimeToSendPadding(_)).Times(0); | 147 EXPECT_CALL(rtp_2, TimeToSendPadding(_)).Times(0); |
147 EXPECT_EQ(0u, packet_router_->TimeToSendPadding(requested_padding_bytes)); | 148 EXPECT_EQ(0u, packet_router_->TimeToSendPadding(requested_padding_bytes)); |
148 | 149 |
149 packet_router_->RemoveRtpModule(&rtp_1); | 150 packet_router_->RemoveRtpModule(&rtp_1, true); |
150 | 151 |
151 // rtp_1 has been removed, try sending padding and make sure rtp_1 isn't asked | 152 // rtp_1 has been removed, try sending padding and make sure rtp_1 isn't asked |
152 // to send by not expecting any calls. Instead verify rtp_2 is called. | 153 // to send by not expecting any calls. Instead verify rtp_2 is called. |
153 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 154 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
154 EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes)).Times(1); | 155 EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes)).Times(1); |
155 EXPECT_EQ(0u, packet_router_->TimeToSendPadding(requested_padding_bytes)); | 156 EXPECT_EQ(0u, packet_router_->TimeToSendPadding(requested_padding_bytes)); |
156 | 157 |
157 packet_router_->RemoveRtpModule(&rtp_2); | 158 packet_router_->RemoveRtpModule(&rtp_2, true); |
158 } | 159 } |
159 | 160 |
160 TEST_F(PacketRouterTest, AllocateSequenceNumbers) { | 161 TEST_F(PacketRouterTest, AllocateSequenceNumbers) { |
161 const uint16_t kStartSeq = 0xFFF0; | 162 const uint16_t kStartSeq = 0xFFF0; |
162 const size_t kNumPackets = 32; | 163 const size_t kNumPackets = 32; |
163 | 164 |
164 packet_router_->SetTransportWideSequenceNumber(kStartSeq - 1); | 165 packet_router_->SetTransportWideSequenceNumber(kStartSeq - 1); |
165 | 166 |
166 for (size_t i = 0; i < kNumPackets; ++i) { | 167 for (size_t i = 0; i < kNumPackets; ++i) { |
167 uint16_t seq = packet_router_->AllocateSequenceNumber(); | 168 uint16_t seq = packet_router_->AllocateSequenceNumber(); |
168 uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i; | 169 uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i; |
169 EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq); | 170 EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq); |
170 } | 171 } |
171 } | 172 } |
| 173 |
| 174 TEST_F(PacketRouterTest, SendFeedback) { |
| 175 MockRtpRtcp rtp_1; |
| 176 MockRtpRtcp rtp_2; |
| 177 packet_router_->AddRtpModule(&rtp_1, false); |
| 178 packet_router_->AddRtpModule(&rtp_2, true); |
| 179 |
| 180 rtcp::TransportFeedback feedback; |
| 181 EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1); |
| 182 packet_router_->SendFeedback(&feedback); |
| 183 packet_router_->RemoveRtpModule(&rtp_1, false); |
| 184 EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1); |
| 185 packet_router_->SendFeedback(&feedback); |
| 186 packet_router_->RemoveRtpModule(&rtp_2, true); |
| 187 } |
172 } // namespace webrtc | 188 } // namespace webrtc |
OLD | NEW |