OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 | 11 |
12 /* | 12 /* |
13 * This file includes unit tests for the RTCPSender. | 13 * This file includes unit tests for the RTCPSender. |
14 */ | 14 */ |
15 | 15 |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 #include "webrtc/common_types.h" | 19 #include "webrtc/common_types.h" |
20 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" |
21 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | |
danilchap
2016/02/11 13:35:30
Alphabetical order.
| |
22 #include "webrtc/test/rtcp_packet_parser.h" | 23 #include "webrtc/test/rtcp_packet_parser.h" |
23 | 24 |
24 using ::testing::ElementsAre; | 25 using ::testing::ElementsAre; |
26 using webrtc::RTCPUtility::RtcpCommonHeader; | |
25 | 27 |
26 namespace webrtc { | 28 namespace webrtc { |
27 | 29 |
28 TEST(NACKStringBuilderTest, TestCase1) { | 30 TEST(NACKStringBuilderTest, TestCase1) { |
29 NACKStringBuilder builder; | 31 NACKStringBuilder builder; |
30 builder.PushNACK(5); | 32 builder.PushNACK(5); |
31 builder.PushNACK(7); | 33 builder.PushNACK(7); |
32 builder.PushNACK(9); | 34 builder.PushNACK(9); |
33 builder.PushNACK(10); | 35 builder.PushNACK(10); |
34 builder.PushNACK(11); | 36 builder.PushNACK(11); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 return true; | 211 return true; |
210 } | 212 } |
211 int OnReceivedPayloadData(const uint8_t* payload_data, | 213 int OnReceivedPayloadData(const uint8_t* payload_data, |
212 const size_t payload_size, | 214 const size_t payload_size, |
213 const WebRtcRTPHeader* rtp_header) override { | 215 const WebRtcRTPHeader* rtp_header) override { |
214 return 0; | 216 return 0; |
215 } | 217 } |
216 test::RtcpPacketParser parser_; | 218 test::RtcpPacketParser parser_; |
217 }; | 219 }; |
218 | 220 |
221 // This is a mock transport class which is solely used | |
danilchap
2016/02/11 13:35:30
This mock is used in one test only, may be move it
| |
222 // by the ByeMustBeLast test to validate that BYE must | |
223 // be the last packet type in a RTCP compound packet. | |
224 class MockTransportByeIsLastInCompoundRtcpPacket : public Transport, | |
225 public NullRtpData { | |
danilchap
2016/02/11 13:35:30
any reason to derive it from NullRtpData?
| |
226 public: | |
227 MockTransportByeIsLastInCompoundRtcpPacket() {} | |
228 | |
229 bool SendRtp(const uint8_t* /*data*/, | |
230 size_t /*len*/, | |
231 const PacketOptions& options) override { | |
danilchap
2016/02/11 13:35:30
for consistency comment /*options*/ parameter too.
| |
232 return false; | |
233 } | |
234 bool SendRtcp(const uint8_t* data, size_t len) override { | |
235 const uint8_t* next_packet = data; | |
236 | |
237 while (next_packet < data + len) { | |
238 RtcpCommonHeader header; | |
239 RtcpParseCommonHeader(next_packet, len - (next_packet - data), &header); | |
240 next_packet = next_packet + | |
241 header.payload_size_bytes + | |
242 RtcpCommonHeader::kHeaderSizeBytes; | |
243 if (header.packet_type == RTCPUtility::PT_BYE) { | |
244 bool is_last_packet = (data + len == next_packet); | |
245 EXPECT_TRUE(is_last_packet) << | |
246 "Bye packet should be last in a compound RTCP packet."; | |
247 } | |
248 } | |
249 return true; | |
250 } | |
251 int OnReceivedPayloadData(const uint8_t* payload_data, | |
252 const size_t payload_size, | |
253 const WebRtcRTPHeader* rtp_header) override { | |
254 return 0; | |
255 } | |
256 }; | |
257 | |
219 namespace { | 258 namespace { |
220 static const uint32_t kSenderSsrc = 0x11111111; | 259 static const uint32_t kSenderSsrc = 0x11111111; |
221 static const uint32_t kRemoteSsrc = 0x22222222; | 260 static const uint32_t kRemoteSsrc = 0x22222222; |
222 } | 261 } |
223 | 262 |
224 class RtcpSenderTest : public ::testing::Test { | 263 class RtcpSenderTest : public ::testing::Test { |
225 protected: | 264 protected: |
226 RtcpSenderTest() | 265 RtcpSenderTest() |
227 : clock_(1335900000), | 266 : clock_(1335900000), |
228 receive_statistics_(ReceiveStatistics::Create(&clock_)) { | 267 receive_statistics_(ReceiveStatistics::Create(&clock_)) { |
(...skipping 20 matching lines...) Expand all Loading... | |
249 } | 288 } |
250 | 289 |
251 test::RtcpPacketParser* parser() { return &test_transport_.parser_; } | 290 test::RtcpPacketParser* parser() { return &test_transport_.parser_; } |
252 | 291 |
253 RTCPSender::FeedbackState feedback_state() { | 292 RTCPSender::FeedbackState feedback_state() { |
254 return rtp_rtcp_impl_->GetFeedbackState(); | 293 return rtp_rtcp_impl_->GetFeedbackState(); |
255 } | 294 } |
256 | 295 |
257 SimulatedClock clock_; | 296 SimulatedClock clock_; |
258 TestTransport test_transport_; | 297 TestTransport test_transport_; |
298 MockTransportByeIsLastInCompoundRtcpPacket mock_transport_; | |
259 rtc::scoped_ptr<ReceiveStatistics> receive_statistics_; | 299 rtc::scoped_ptr<ReceiveStatistics> receive_statistics_; |
260 rtc::scoped_ptr<ModuleRtpRtcpImpl> rtp_rtcp_impl_; | 300 rtc::scoped_ptr<ModuleRtpRtcpImpl> rtp_rtcp_impl_; |
261 rtc::scoped_ptr<RTCPSender> rtcp_sender_; | 301 rtc::scoped_ptr<RTCPSender> rtcp_sender_; |
262 }; | 302 }; |
263 | 303 |
264 TEST_F(RtcpSenderTest, SetRtcpStatus) { | 304 TEST_F(RtcpSenderTest, SetRtcpStatus) { |
265 EXPECT_EQ(RtcpMode::kOff, rtcp_sender_->Status()); | 305 EXPECT_EQ(RtcpMode::kOff, rtcp_sender_->Status()); |
266 rtcp_sender_->SetRTCPStatus(RtcpMode::kReducedSize); | 306 rtcp_sender_->SetRTCPStatus(RtcpMode::kReducedSize); |
267 EXPECT_EQ(RtcpMode::kReducedSize, rtcp_sender_->Status()); | 307 EXPECT_EQ(RtcpMode::kReducedSize, rtcp_sender_->Status()); |
268 } | 308 } |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 rtcp_sender_->SetRTCPStatus(RtcpMode::kCompound); | 794 rtcp_sender_->SetRTCPStatus(RtcpMode::kCompound); |
755 rtcp_sender_->SetREMBData(kBitrate, ssrcs); | 795 rtcp_sender_->SetREMBData(kBitrate, ssrcs); |
756 std::set<RTCPPacketType> packet_types; | 796 std::set<RTCPPacketType> packet_types; |
757 packet_types.insert(kRtcpRemb); | 797 packet_types.insert(kRtcpRemb); |
758 packet_types.insert(kRtcpPli); | 798 packet_types.insert(kRtcpPli); |
759 EXPECT_EQ(0, rtcp_sender_->SendCompoundRTCP(feedback_state(), packet_types)); | 799 EXPECT_EQ(0, rtcp_sender_->SendCompoundRTCP(feedback_state(), packet_types)); |
760 EXPECT_EQ(1, parser()->remb_item()->num_packets()); | 800 EXPECT_EQ(1, parser()->remb_item()->num_packets()); |
761 EXPECT_EQ(1, parser()->pli()->num_packets()); | 801 EXPECT_EQ(1, parser()->pli()->num_packets()); |
762 } | 802 } |
763 | 803 |
804 | |
805 // This test is written to verify that BYE is always the last packet | |
806 // type in a RTCP compoud packet. The rtcp_sender_ is recreated with | |
807 // mock_transport_, which is used to check for whether BYE at the end | |
808 // of a RTCP compound packet. | |
809 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=5498 for | |
810 // details. | |
811 TEST_F(RtcpSenderTest, ByeMustBeLast) { | |
812 // Re-configure rtcp_sender_ with mock_transport_ | |
813 rtcp_sender_.reset(new RTCPSender(false, &clock_, receive_statistics_.get(), | |
814 nullptr, nullptr, &mock_transport_)); | |
815 rtcp_sender_->SetSSRC(kSenderSsrc); | |
816 rtcp_sender_->SetRemoteSSRC(kRemoteSsrc); | |
817 | |
818 // Set up XR VoIP metric to be included with BYE | |
819 rtcp_sender_->SetRTCPStatus(RtcpMode::kCompound); | |
820 RTCPVoIPMetric metric; | |
821 metric.lossRate = 1; | |
danilchap
2016/02/11 13:35:30
Are VoIPMetric values have any meaning for this te
| |
822 metric.discardRate = 2; | |
823 metric.burstDensity = 3; | |
824 metric.gapDensity = 4; | |
825 metric.burstDuration = 0x1111; | |
826 metric.gapDuration = 0x2222; | |
827 metric.roundTripDelay = 0x3333; | |
828 metric.endSystemDelay = 0x4444; | |
829 metric.signalLevel = 5; | |
830 metric.noiseLevel = 6; | |
831 metric.RERL = 7; | |
832 metric.Gmin = 8; | |
833 metric.Rfactor = 9; | |
834 metric.extRfactor = 10; | |
835 metric.MOSLQ = 11; | |
836 metric.MOSCQ = 12; | |
837 metric.RXconfig = 13; | |
838 metric.JBnominal = 0x5555; | |
839 metric.JBmax = 0x6666; | |
840 metric.JBabsMax = 0x7777; | |
841 EXPECT_EQ(0, rtcp_sender_->SetRTCPVoIPMetrics(&metric)); | |
842 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state(), kRtcpBye)); | |
843 } | |
844 | |
764 } // namespace webrtc | 845 } // namespace webrtc |
OLD | NEW |