OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 <algorithm> | 11 #include <algorithm> |
12 #include <iterator> | 12 #include <iterator> |
13 #include <list> | 13 #include <list> |
14 #include <set> | 14 #include <set> |
15 | 15 |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/common_types.h" | 18 #include "webrtc/common_types.h" |
19 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" | 19 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" |
20 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | 20 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
21 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" | 21 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" |
22 #include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h" | 22 #include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h" |
23 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" | 23 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" |
24 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" | 24 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
25 | 25 |
26 using namespace webrtc; | 26 using namespace webrtc; |
27 | 27 |
28 const int kVideoNackListSize = 30; | 28 const int kVideoNackListSize = 30; |
29 const int kTestId = 123; | |
30 const uint32_t kTestSsrc = 3456; | 29 const uint32_t kTestSsrc = 3456; |
31 const uint16_t kTestSequenceNumber = 2345; | 30 const uint16_t kTestSequenceNumber = 2345; |
32 const uint32_t kTestNumberOfPackets = 1350; | 31 const uint32_t kTestNumberOfPackets = 1350; |
33 const int kTestNumberOfRtxPackets = 149; | 32 const int kTestNumberOfRtxPackets = 149; |
34 const int kNumFrames = 30; | 33 const int kNumFrames = 30; |
35 const int kPayloadType = 123; | 34 const int kPayloadType = 123; |
36 const int kRtxPayloadType = 98; | 35 const int kRtxPayloadType = 98; |
37 | 36 |
38 class VerifyingRtxReceiver : public NullRtpData | 37 class VerifyingRtxReceiver : public NullRtpData |
39 { | 38 { |
(...skipping 10 matching lines...) Expand all Loading... |
50 return 0; | 49 return 0; |
51 } | 50 } |
52 std::list<uint16_t> sequence_numbers_; | 51 std::list<uint16_t> sequence_numbers_; |
53 }; | 52 }; |
54 | 53 |
55 class TestRtpFeedback : public NullRtpFeedback { | 54 class TestRtpFeedback : public NullRtpFeedback { |
56 public: | 55 public: |
57 TestRtpFeedback(RtpRtcp* rtp_rtcp) : rtp_rtcp_(rtp_rtcp) {} | 56 TestRtpFeedback(RtpRtcp* rtp_rtcp) : rtp_rtcp_(rtp_rtcp) {} |
58 virtual ~TestRtpFeedback() {} | 57 virtual ~TestRtpFeedback() {} |
59 | 58 |
60 void OnIncomingSSRCChanged(const int32_t id, const uint32_t ssrc) override { | 59 void OnIncomingSSRCChanged(const uint32_t ssrc) override { |
61 rtp_rtcp_->SetRemoteSSRC(ssrc); | 60 rtp_rtcp_->SetRemoteSSRC(ssrc); |
62 } | 61 } |
63 | 62 |
64 private: | 63 private: |
65 RtpRtcp* rtp_rtcp_; | 64 RtpRtcp* rtp_rtcp_; |
66 }; | 65 }; |
67 | 66 |
68 class RtxLoopBackTransport : public webrtc::Transport { | 67 class RtxLoopBackTransport : public webrtc::Transport { |
69 public: | 68 public: |
70 explicit RtxLoopBackTransport(uint32_t rtx_ssrc) | 69 explicit RtxLoopBackTransport(uint32_t rtx_ssrc) |
(...skipping 18 matching lines...) Expand all Loading... |
89 void DropEveryNthPacket(int n) { | 88 void DropEveryNthPacket(int n) { |
90 packet_loss_ = n; | 89 packet_loss_ = n; |
91 } | 90 } |
92 | 91 |
93 void DropConsecutivePackets(int start, int total) { | 92 void DropConsecutivePackets(int start, int total) { |
94 consecutive_drop_start_ = start; | 93 consecutive_drop_start_ = start; |
95 consecutive_drop_end_ = start + total; | 94 consecutive_drop_end_ = start + total; |
96 packet_loss_ = 0; | 95 packet_loss_ = 0; |
97 } | 96 } |
98 | 97 |
99 int SendPacket(int channel, const void* data, size_t len) override { | 98 int SendPacket(const void* data, size_t len) override { |
100 count_++; | 99 count_++; |
101 const unsigned char* ptr = static_cast<const unsigned char*>(data); | 100 const unsigned char* ptr = static_cast<const unsigned char*>(data); |
102 uint32_t ssrc = (ptr[8] << 24) + (ptr[9] << 16) + (ptr[10] << 8) + ptr[11]; | 101 uint32_t ssrc = (ptr[8] << 24) + (ptr[9] << 16) + (ptr[10] << 8) + ptr[11]; |
103 if (ssrc == rtx_ssrc_) count_rtx_ssrc_++; | 102 if (ssrc == rtx_ssrc_) count_rtx_ssrc_++; |
104 uint16_t sequence_number = (ptr[2] << 8) + ptr[3]; | 103 uint16_t sequence_number = (ptr[2] << 8) + ptr[3]; |
105 size_t packet_length = len; | 104 size_t packet_length = len; |
106 // TODO(pbos): Figure out why this needs to be initialized. Likely this | 105 // TODO(pbos): Figure out why this needs to be initialized. Likely this |
107 // is hiding a bug either in test setup or other code. | 106 // is hiding a bug either in test setup or other code. |
108 // https://code.google.com/p/webrtc/issues/detail?id=3183 | 107 // https://code.google.com/p/webrtc/issues/detail?id=3183 |
109 uint8_t restored_packet[1500] = {0}; | 108 uint8_t restored_packet[1500] = {0}; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 return -1; | 147 return -1; |
149 } | 148 } |
150 if (!rtp_receiver_->IncomingRtpPacket(header, restored_packet_ptr, | 149 if (!rtp_receiver_->IncomingRtpPacket(header, restored_packet_ptr, |
151 packet_length, payload_specific, | 150 packet_length, payload_specific, |
152 true)) { | 151 true)) { |
153 return -1; | 152 return -1; |
154 } | 153 } |
155 return static_cast<int>(len); | 154 return static_cast<int>(len); |
156 } | 155 } |
157 | 156 |
158 int SendRTCPPacket(int channel, const void* data, size_t len) override { | 157 int SendRTCPPacket(const void* data, size_t len) override { |
159 if (module_->IncomingRtcpPacket((const uint8_t*)data, len) == 0) { | 158 if (module_->IncomingRtcpPacket((const uint8_t*)data, len) == 0) { |
160 return static_cast<int>(len); | 159 return static_cast<int>(len); |
161 } | 160 } |
162 return -1; | 161 return -1; |
163 } | 162 } |
164 int count_; | 163 int count_; |
165 int packet_loss_; | 164 int packet_loss_; |
166 int consecutive_drop_start_; | 165 int consecutive_drop_start_; |
167 int consecutive_drop_end_; | 166 int consecutive_drop_end_; |
168 uint32_t rtx_ssrc_; | 167 uint32_t rtx_ssrc_; |
(...skipping 10 matching lines...) Expand all Loading... |
179 : rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)), | 178 : rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)), |
180 rtp_rtcp_module_(NULL), | 179 rtp_rtcp_module_(NULL), |
181 transport_(kTestSsrc + 1), | 180 transport_(kTestSsrc + 1), |
182 receiver_(), | 181 receiver_(), |
183 payload_data_length(sizeof(payload_data)), | 182 payload_data_length(sizeof(payload_data)), |
184 fake_clock(123456) {} | 183 fake_clock(123456) {} |
185 ~RtpRtcpRtxNackTest() {} | 184 ~RtpRtcpRtxNackTest() {} |
186 | 185 |
187 void SetUp() override { | 186 void SetUp() override { |
188 RtpRtcp::Configuration configuration; | 187 RtpRtcp::Configuration configuration; |
189 configuration.id = kTestId; | |
190 configuration.audio = false; | 188 configuration.audio = false; |
191 configuration.clock = &fake_clock; | 189 configuration.clock = &fake_clock; |
192 receive_statistics_.reset(ReceiveStatistics::Create(&fake_clock)); | 190 receive_statistics_.reset(ReceiveStatistics::Create(&fake_clock)); |
193 configuration.receive_statistics = receive_statistics_.get(); | 191 configuration.receive_statistics = receive_statistics_.get(); |
194 configuration.outgoing_transport = &transport_; | 192 configuration.outgoing_transport = &transport_; |
195 rtp_rtcp_module_ = RtpRtcp::CreateRtpRtcp(configuration); | 193 rtp_rtcp_module_ = RtpRtcp::CreateRtpRtcp(configuration); |
196 | 194 |
197 rtp_feedback_.reset(new TestRtpFeedback(rtp_rtcp_module_)); | 195 rtp_feedback_.reset(new TestRtpFeedback(rtp_rtcp_module_)); |
198 | 196 |
199 rtp_receiver_.reset(RtpReceiver::CreateVideoReceiver( | 197 rtp_receiver_.reset(RtpReceiver::CreateVideoReceiver( |
200 kTestId, &fake_clock, &receiver_, rtp_feedback_.get(), | 198 &fake_clock, &receiver_, rtp_feedback_.get(), |
201 &rtp_payload_registry_)); | 199 &rtp_payload_registry_)); |
202 | 200 |
203 rtp_rtcp_module_->SetSSRC(kTestSsrc); | 201 rtp_rtcp_module_->SetSSRC(kTestSsrc); |
204 rtp_rtcp_module_->SetRTCPStatus(kRtcpCompound); | 202 rtp_rtcp_module_->SetRTCPStatus(kRtcpCompound); |
205 rtp_receiver_->SetNACKStatus(kNackRtcp); | 203 rtp_receiver_->SetNACKStatus(kNackRtcp); |
206 rtp_rtcp_module_->SetStorePacketsStatus(true, 600); | 204 rtp_rtcp_module_->SetStorePacketsStatus(true, 600); |
207 EXPECT_EQ(0, rtp_rtcp_module_->SetSendingStatus(true)); | 205 EXPECT_EQ(0, rtp_rtcp_module_->SetSendingStatus(true)); |
208 rtp_rtcp_module_->SetSequenceNumber(kTestSequenceNumber); | 206 rtp_rtcp_module_->SetSequenceNumber(kTestSequenceNumber); |
209 rtp_rtcp_module_->SetStartTimestamp(111111); | 207 rtp_rtcp_module_->SetStartTimestamp(111111); |
210 | 208 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 344 |
347 TEST_F(RtpRtcpRtxNackTest, RtxNack) { | 345 TEST_F(RtpRtcpRtxNackTest, RtxNack) { |
348 RunRtxTest(kRtxRetransmitted, 10); | 346 RunRtxTest(kRtxRetransmitted, 10); |
349 EXPECT_EQ(kTestSequenceNumber, *(receiver_.sequence_numbers_.begin())); | 347 EXPECT_EQ(kTestSequenceNumber, *(receiver_.sequence_numbers_.begin())); |
350 EXPECT_EQ(kTestSequenceNumber + kTestNumberOfPackets - 1, | 348 EXPECT_EQ(kTestSequenceNumber + kTestNumberOfPackets - 1, |
351 *(receiver_.sequence_numbers_.rbegin())); | 349 *(receiver_.sequence_numbers_.rbegin())); |
352 EXPECT_EQ(kTestNumberOfPackets, receiver_.sequence_numbers_.size()); | 350 EXPECT_EQ(kTestNumberOfPackets, receiver_.sequence_numbers_.size()); |
353 EXPECT_EQ(kTestNumberOfRtxPackets, transport_.count_rtx_ssrc_); | 351 EXPECT_EQ(kTestNumberOfRtxPackets, transport_.count_rtx_ssrc_); |
354 EXPECT_TRUE(ExpectedPacketsReceived()); | 352 EXPECT_TRUE(ExpectedPacketsReceived()); |
355 } | 353 } |
OLD | NEW |