| 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 | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 95   EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 95   EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 
| 96   EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); | 96   EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); | 
| 97   EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _)).Times(0); | 97   EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _)).Times(0); | 
| 98   EXPECT_TRUE(packet_router_->TimeToSendPacket(kSsrc1, sequence_number, | 98   EXPECT_TRUE(packet_router_->TimeToSendPacket(kSsrc1, sequence_number, | 
| 99                                                timestamp, retransmission)); | 99                                                timestamp, retransmission)); | 
| 100 | 100 | 
| 101   packet_router_->RemoveRtpModule(&rtp_2); | 101   packet_router_->RemoveRtpModule(&rtp_2); | 
| 102 } | 102 } | 
| 103 | 103 | 
| 104 TEST_F(PacketRouterTest, TimeToSendPadding) { | 104 TEST_F(PacketRouterTest, TimeToSendPadding) { | 
|  | 105   const uint16_t kSsrc1 = 1234; | 
|  | 106   const uint16_t kSsrc2 = 4567; | 
|  | 107 | 
| 105   MockRtpRtcp rtp_1; | 108   MockRtpRtcp rtp_1; | 
|  | 109   EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1)); | 
| 106   MockRtpRtcp rtp_2; | 110   MockRtpRtcp rtp_2; | 
|  | 111   EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2)); | 
| 107   packet_router_->AddRtpModule(&rtp_1); | 112   packet_router_->AddRtpModule(&rtp_1); | 
| 108   packet_router_->AddRtpModule(&rtp_2); | 113   packet_router_->AddRtpModule(&rtp_2); | 
| 109 | 114 | 
| 110   // Default configuration, sending padding on the first sending module. | 115   // Default configuration, sending padding on all modules sending media, | 
|  | 116   // ordered by SSRC. | 
| 111   const size_t requested_padding_bytes = 1000; | 117   const size_t requested_padding_bytes = 1000; | 
| 112   const size_t sent_padding_bytes = 890; | 118   const size_t sent_padding_bytes = 890; | 
| 113   EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); | 119   EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); | 
| 114   EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)) | 120   EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)) | 
| 115       .Times(1) | 121       .Times(1) | 
| 116       .WillOnce(Return(sent_padding_bytes)); | 122       .WillOnce(Return(sent_padding_bytes)); | 
| 117   EXPECT_CALL(rtp_2, TimeToSendPadding(_)).Times(0); | 123   EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 
| 118   EXPECT_EQ(sent_padding_bytes, | 124   EXPECT_CALL(rtp_2, | 
|  | 125               TimeToSendPadding(requested_padding_bytes - sent_padding_bytes)) | 
|  | 126       .Times(1) | 
|  | 127       .WillOnce(Return(requested_padding_bytes - sent_padding_bytes)); | 
|  | 128   EXPECT_EQ(requested_padding_bytes, | 
| 119             packet_router_->TimeToSendPadding(requested_padding_bytes)); | 129             packet_router_->TimeToSendPadding(requested_padding_bytes)); | 
| 120 | 130 | 
| 121   // Let only the second module be sending and verify the padding request is | 131   // Let only the second module be sending and verify the padding request is | 
| 122   // routed there. | 132   // routed there. | 
| 123   EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); | 133   EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); | 
| 124   EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)).Times(0); | 134   EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)).Times(0); | 
| 125   EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 135   EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 
| 126   EXPECT_CALL(rtp_2, TimeToSendPadding(_)) | 136   EXPECT_CALL(rtp_2, TimeToSendPadding(_)) | 
| 127       .Times(1) | 137       .Times(1) | 
| 128       .WillOnce(Return(sent_padding_bytes)); | 138       .WillOnce(Return(sent_padding_bytes)); | 
| 129   EXPECT_EQ(sent_padding_bytes, | 139   EXPECT_EQ(sent_padding_bytes, | 
| 130             packet_router_->TimeToSendPadding(requested_padding_bytes)); | 140             packet_router_->TimeToSendPadding(requested_padding_bytes)); | 
| 131 | 141 | 
| 132   // No sending module at all. | 142   // No sending module at all. | 
| 133   EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); | 143   EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); | 
| 134   EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)).Times(0); | 144   EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes)).Times(0); | 
| 135   EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); | 145   EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); | 
| 136   EXPECT_CALL(rtp_2, TimeToSendPadding(_)).Times(0); | 146   EXPECT_CALL(rtp_2, TimeToSendPadding(_)).Times(0); | 
| 137   EXPECT_EQ(static_cast<size_t>(0), | 147   EXPECT_EQ(0u, packet_router_->TimeToSendPadding(requested_padding_bytes)); | 
| 138             packet_router_->TimeToSendPadding(requested_padding_bytes)); |  | 
| 139 | 148 | 
| 140   packet_router_->RemoveRtpModule(&rtp_1); | 149   packet_router_->RemoveRtpModule(&rtp_1); | 
| 141 | 150 | 
| 142   // rtp_1 has been removed, try sending padding and make sure rtp_1 isn't asked | 151   // rtp_1 has been removed, try sending padding and make sure rtp_1 isn't asked | 
| 143   // to send by not expecting any calls. Instead verify rtp_2 is called. | 152   // to send by not expecting any calls. Instead verify rtp_2 is called. | 
| 144   EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 153   EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 
| 145   EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes)).Times(1); | 154   EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes)).Times(1); | 
| 146   EXPECT_EQ(static_cast<size_t>(0), | 155   EXPECT_EQ(0u, packet_router_->TimeToSendPadding(requested_padding_bytes)); | 
| 147             packet_router_->TimeToSendPadding(requested_padding_bytes)); |  | 
| 148 | 156 | 
| 149   packet_router_->RemoveRtpModule(&rtp_2); | 157   packet_router_->RemoveRtpModule(&rtp_2); | 
| 150 } | 158 } | 
|  | 159 | 
|  | 160 TEST_F(PacketRouterTest, AllocateSequenceNumbers) { | 
|  | 161   const uint16_t kStartSeq = 0xFFF0; | 
|  | 162   const size_t kNumPackets = 32; | 
|  | 163 | 
|  | 164   packet_router_->SetTransportWideSequenceNumber(kStartSeq - 1); | 
|  | 165 | 
|  | 166   for (size_t i = 0; i < kNumPackets; ++i) { | 
|  | 167     uint16_t seq = packet_router_->AllocateSequenceNumber(); | 
|  | 168     uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i; | 
|  | 169     EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq); | 
|  | 170   } | 
|  | 171 } | 
| 151 }  // namespace webrtc | 172 }  // namespace webrtc | 
| OLD | NEW | 
|---|