| 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 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "webrtc/base/rate_limiter.h" | 13 #include "webrtc/base/rate_limiter.h" |
| 14 #include "webrtc/common_types.h" | 14 #include "webrtc/common_types.h" |
| 15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
| 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 15 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" | 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" |
| 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" | 18 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
| 18 #include "webrtc/test/gmock.h" | 19 #include "webrtc/test/gmock.h" |
| 19 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
| 20 #include "webrtc/test/mock_transport.h" | 21 #include "webrtc/test/mock_transport.h" |
| 21 #include "webrtc/test/rtcp_packet_parser.h" | 22 #include "webrtc/test/rtcp_packet_parser.h" |
| 22 | 23 |
| 23 using ::testing::_; | 24 using ::testing::_; |
| 24 using ::testing::ElementsAre; | 25 using ::testing::ElementsAre; |
| 25 using ::testing::Invoke; | 26 using ::testing::Invoke; |
| 26 using webrtc::RTCPUtility::RtcpCommonHeader; | |
| 27 | 27 |
| 28 namespace webrtc { | 28 namespace webrtc { |
| 29 | 29 |
| 30 TEST(NACKStringBuilderTest, TestCase1) { | 30 TEST(NACKStringBuilderTest, TestCase1) { |
| 31 NACKStringBuilder builder; | 31 NACKStringBuilder builder; |
| 32 builder.PushNACK(5); | 32 builder.PushNACK(5); |
| 33 builder.PushNACK(7); | 33 builder.PushNACK(7); |
| 34 builder.PushNACK(9); | 34 builder.PushNACK(9); |
| 35 builder.PushNACK(10); | 35 builder.PushNACK(10); |
| 36 builder.PushNACK(11); | 36 builder.PushNACK(11); |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 | 783 |
| 784 // This test is written to verify that BYE is always the last packet | 784 // This test is written to verify that BYE is always the last packet |
| 785 // type in a RTCP compoud packet. The rtcp_sender_ is recreated with | 785 // type in a RTCP compoud packet. The rtcp_sender_ is recreated with |
| 786 // mock_transport, which is used to check for whether BYE at the end | 786 // mock_transport, which is used to check for whether BYE at the end |
| 787 // of a RTCP compound packet. | 787 // of a RTCP compound packet. |
| 788 TEST_F(RtcpSenderTest, ByeMustBeLast) { | 788 TEST_F(RtcpSenderTest, ByeMustBeLast) { |
| 789 MockTransport mock_transport; | 789 MockTransport mock_transport; |
| 790 EXPECT_CALL(mock_transport, SendRtcp(_, _)) | 790 EXPECT_CALL(mock_transport, SendRtcp(_, _)) |
| 791 .WillOnce(Invoke([](const uint8_t* data, size_t len) { | 791 .WillOnce(Invoke([](const uint8_t* data, size_t len) { |
| 792 const uint8_t* next_packet = data; | 792 const uint8_t* next_packet = data; |
| 793 while (next_packet < data + len) { | 793 const uint8_t* const packet_end = data + len; |
| 794 RtcpCommonHeader header; | 794 rtcp::CommonHeader packet; |
| 795 RtcpParseCommonHeader(next_packet, len - (next_packet - data), &header); | 795 while (next_packet < packet_end) { |
| 796 next_packet = next_packet + | 796 EXPECT_TRUE(packet.Parse(next_packet, packet_end - next_packet)); |
| 797 header.payload_size_bytes + | 797 next_packet = packet.NextPacket(); |
| 798 RtcpCommonHeader::kHeaderSizeBytes; | 798 if (packet.type() == rtcp::Bye::kPacketType) // Main test expectation. |
| 799 if (header.packet_type == RTCPUtility::PT_BYE) { | 799 EXPECT_EQ(0, packet_end - next_packet) |
| 800 bool is_last_packet = (data + len == next_packet); | 800 << "Bye packet should be last in a compound RTCP packet."; |
| 801 EXPECT_TRUE(is_last_packet) << | 801 if (next_packet == packet_end) // Validate test was set correctly. |
| 802 "Bye packet should be last in a compound RTCP packet."; | 802 EXPECT_EQ(packet.type(), rtcp::Bye::kPacketType) |
| 803 } | 803 << "Last packet in this test expected to be Bye."; |
| 804 } | 804 } |
| 805 | 805 |
| 806 return true; | 806 return true; |
| 807 })); | 807 })); |
| 808 | 808 |
| 809 // Re-configure rtcp_sender_ with mock_transport_ | 809 // Re-configure rtcp_sender_ with mock_transport_ |
| 810 rtcp_sender_.reset(new RTCPSender(false, &clock_, receive_statistics_.get(), | 810 rtcp_sender_.reset(new RTCPSender(false, &clock_, receive_statistics_.get(), |
| 811 nullptr, nullptr, &mock_transport)); | 811 nullptr, nullptr, &mock_transport)); |
| 812 rtcp_sender_->SetSSRC(kSenderSsrc); | 812 rtcp_sender_->SetSSRC(kSenderSsrc); |
| 813 rtcp_sender_->SetRemoteSSRC(kRemoteSsrc); | 813 rtcp_sender_->SetRemoteSSRC(kRemoteSsrc); |
| 814 rtcp_sender_->SetTimestampOffset(kStartRtpTimestamp); | 814 rtcp_sender_->SetTimestampOffset(kStartRtpTimestamp); |
| 815 rtcp_sender_->SetLastRtpTime(kRtpTimestamp, clock_.TimeInMilliseconds()); | 815 rtcp_sender_->SetLastRtpTime(kRtpTimestamp, clock_.TimeInMilliseconds()); |
| 816 | 816 |
| 817 // Set up XR VoIP metric to be included with BYE | 817 // Set up XR VoIP metric to be included with BYE |
| 818 rtcp_sender_->SetRTCPStatus(RtcpMode::kCompound); | 818 rtcp_sender_->SetRTCPStatus(RtcpMode::kCompound); |
| 819 RTCPVoIPMetric metric; | 819 RTCPVoIPMetric metric; |
| 820 EXPECT_EQ(0, rtcp_sender_->SetRTCPVoIPMetrics(&metric)); | 820 EXPECT_EQ(0, rtcp_sender_->SetRTCPVoIPMetrics(&metric)); |
| 821 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state(), kRtcpBye)); | 821 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state(), kRtcpBye)); |
| 822 } | 822 } |
| 823 | 823 |
| 824 } // namespace webrtc | 824 } // namespace webrtc |
| OLD | NEW |