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 RTCPReceiver. | 13 * This file includes unit tests for the RTCPReceiver. |
14 */ | 14 */ |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 // Note: This file has no directory. Lint warning must be ignored. | 18 // Note: This file has no directory. Lint warning must be ignored. |
19 #include "webrtc/common_types.h" | 19 #include "webrtc/common_types.h" |
20 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_observer.h" | 20 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_observer.h" |
21 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" | 21 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" |
| 22 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" | 23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" | 24 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" |
24 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" |
25 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
26 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
| 28 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
27 | 29 |
28 namespace webrtc { | 30 namespace webrtc { |
29 | 31 |
30 namespace { // Anonymous namespace; hide utility functions and classes. | 32 namespace { // Anonymous namespace; hide utility functions and classes. |
31 | 33 |
32 // This test transport verifies that no functions get called. | 34 // This test transport verifies that no functions get called. |
33 class TestTransport : public Transport, | 35 class TestTransport : public Transport, |
34 public NullRtpData { | 36 public NullRtpData { |
35 public: | 37 public: |
36 explicit TestTransport() : rtcp_receiver_(nullptr) {} | 38 explicit TestTransport() : rtcp_receiver_(nullptr) {} |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 rtcp_packet_info_.interArrivalJitter = | 115 rtcp_packet_info_.interArrivalJitter = |
114 rtcpPacketInformation.interArrivalJitter; | 116 rtcpPacketInformation.interArrivalJitter; |
115 rtcp_packet_info_.sliPictureId = rtcpPacketInformation.sliPictureId; | 117 rtcp_packet_info_.sliPictureId = rtcpPacketInformation.sliPictureId; |
116 rtcp_packet_info_.rpsiPictureId = rtcpPacketInformation.rpsiPictureId; | 118 rtcp_packet_info_.rpsiPictureId = rtcpPacketInformation.rpsiPictureId; |
117 rtcp_packet_info_.receiverEstimatedMaxBitrate = | 119 rtcp_packet_info_.receiverEstimatedMaxBitrate = |
118 rtcpPacketInformation.receiverEstimatedMaxBitrate; | 120 rtcpPacketInformation.receiverEstimatedMaxBitrate; |
119 rtcp_packet_info_.ntp_secs = rtcpPacketInformation.ntp_secs; | 121 rtcp_packet_info_.ntp_secs = rtcpPacketInformation.ntp_secs; |
120 rtcp_packet_info_.ntp_frac = rtcpPacketInformation.ntp_frac; | 122 rtcp_packet_info_.ntp_frac = rtcpPacketInformation.ntp_frac; |
121 rtcp_packet_info_.rtp_timestamp = rtcpPacketInformation.rtp_timestamp; | 123 rtcp_packet_info_.rtp_timestamp = rtcpPacketInformation.rtp_timestamp; |
122 rtcp_packet_info_.xr_dlrr_item = rtcpPacketInformation.xr_dlrr_item; | 124 rtcp_packet_info_.xr_dlrr_item = rtcpPacketInformation.xr_dlrr_item; |
123 if (rtcpPacketInformation.VoIPMetric) { | 125 if (rtcpPacketInformation.VoIPMetric) |
124 rtcp_packet_info_.AddVoIPMetric(rtcpPacketInformation.VoIPMetric); | 126 rtcp_packet_info_.AddVoIPMetric(rtcpPacketInformation.VoIPMetric); |
125 } | 127 rtcp_packet_info_.transport_feedback_.reset( |
| 128 rtcpPacketInformation.transport_feedback_.release()); |
126 return 0; | 129 return 0; |
127 } | 130 } |
128 | 131 |
129 OverUseDetectorOptions over_use_detector_options_; | 132 OverUseDetectorOptions over_use_detector_options_; |
130 SimulatedClock system_clock_; | 133 SimulatedClock system_clock_; |
131 ModuleRtpRtcpImpl* rtp_rtcp_impl_; | 134 ModuleRtpRtcpImpl* rtp_rtcp_impl_; |
132 RTCPReceiver* rtcp_receiver_; | 135 RTCPReceiver* rtcp_receiver_; |
133 TestTransport* test_transport_; | 136 TestTransport* test_transport_; |
134 RTCPHelp::RTCPPacketInformation rtcp_packet_info_; | 137 RTCPHelp::RTCPPacketInformation rtcp_packet_info_; |
135 MockRemoteBitrateObserver remote_bitrate_observer_; | 138 MockRemoteBitrateObserver remote_bitrate_observer_; |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 | 1024 |
1022 rtcp::ReceiverReport rr2; | 1025 rtcp::ReceiverReport rr2; |
1023 rr2.From(kSenderSsrc); | 1026 rr2.From(kSenderSsrc); |
1024 rr2.WithReportBlock(rb2); | 1027 rr2.WithReportBlock(rb2); |
1025 rtc::scoped_ptr<rtcp::RawPacket> p2(rr2.Build()); | 1028 rtc::scoped_ptr<rtcp::RawPacket> p2(rr2.Build()); |
1026 EXPECT_EQ(0, InjectRtcpPacket(p2->Buffer(), p2->Length())); | 1029 EXPECT_EQ(0, InjectRtcpPacket(p2->Buffer(), p2->Length())); |
1027 EXPECT_TRUE(callback.Matches(kSourceSsrc, kSequenceNumber, kFractionLoss, | 1030 EXPECT_TRUE(callback.Matches(kSourceSsrc, kSequenceNumber, kFractionLoss, |
1028 kCumulativeLoss, kJitter)); | 1031 kCumulativeLoss, kJitter)); |
1029 } | 1032 } |
1030 | 1033 |
| 1034 TEST_F(RtcpReceiverTest, ReceivesTransportFeedback) { |
| 1035 const uint32_t kSenderSsrc = 0x10203; |
| 1036 const uint32_t kSourceSsrc = 0x123456; |
| 1037 |
| 1038 std::set<uint32_t> ssrcs; |
| 1039 ssrcs.insert(kSourceSsrc); |
| 1040 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); |
| 1041 |
| 1042 rtcp::TransportFeedback packet; |
| 1043 packet.WithMediaSourceSsrc(kSourceSsrc); |
| 1044 packet.WithPacketSenderSsrc(kSenderSsrc); |
| 1045 packet.WithBase(1, 1000); |
| 1046 packet.WithReceivedPacket(1, 1000); |
| 1047 |
| 1048 rtc::scoped_ptr<rtcp::RawPacket> built_packet = packet.Build(); |
| 1049 ASSERT_TRUE(built_packet.get() != nullptr); |
| 1050 |
| 1051 EXPECT_EQ(0, |
| 1052 InjectRtcpPacket(built_packet->Buffer(), built_packet->Length())); |
| 1053 |
| 1054 EXPECT_NE(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpTransportFeedback); |
| 1055 EXPECT_TRUE(rtcp_packet_info_.transport_feedback_.get() != nullptr); |
| 1056 } |
| 1057 |
| 1058 TEST_F(RtcpReceiverTest, HandlesInvalidTransportFeedback) { |
| 1059 const uint32_t kSenderSsrc = 0x10203; |
| 1060 const uint32_t kSourceSsrc = 0x123456; |
| 1061 |
| 1062 std::set<uint32_t> ssrcs; |
| 1063 ssrcs.insert(kSourceSsrc); |
| 1064 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); |
| 1065 |
| 1066 // Send a compound packet with a TransportFeedback followed by something else. |
| 1067 rtcp::TransportFeedback packet; |
| 1068 packet.WithMediaSourceSsrc(kSourceSsrc); |
| 1069 packet.WithPacketSenderSsrc(kSenderSsrc); |
| 1070 packet.WithBase(1, 1000); |
| 1071 packet.WithReceivedPacket(1, 1000); |
| 1072 |
| 1073 static uint32_t kBitrateBps = 50000; |
| 1074 rtcp::Remb remb; |
| 1075 remb.From(kSourceSsrc); |
| 1076 remb.WithBitrateBps(kBitrateBps); |
| 1077 packet.Append(&remb); |
| 1078 |
| 1079 rtc::scoped_ptr<rtcp::RawPacket> built_packet = packet.Build(); |
| 1080 ASSERT_TRUE(built_packet.get() != nullptr); |
| 1081 |
| 1082 // Modify the TransportFeedback packet so that it is invalid. |
| 1083 const size_t kStatusCountOffset = 14; |
| 1084 ByteWriter<uint16_t>::WriteBigEndian( |
| 1085 &built_packet->MutableBuffer()[kStatusCountOffset], 42); |
| 1086 |
| 1087 EXPECT_EQ(0, |
| 1088 InjectRtcpPacket(built_packet->Buffer(), built_packet->Length())); |
| 1089 |
| 1090 // Transport feedback should be ignored, but next packet should work. |
| 1091 EXPECT_EQ(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpTransportFeedback); |
| 1092 EXPECT_NE(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpRemb); |
| 1093 EXPECT_EQ(kBitrateBps, rtcp_packet_info_.receiverEstimatedMaxBitrate); |
| 1094 } |
| 1095 |
1031 } // Anonymous namespace | 1096 } // Anonymous namespace |
1032 | 1097 |
1033 } // namespace webrtc | 1098 } // namespace webrtc |
OLD | NEW |