| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/memory/scoped_ptr.h" | |
| 6 #include "base/test/simple_test_tick_clock.h" | |
| 7 #include "media/cast/cast_defines.h" | |
| 8 #include "media/cast/cast_environment.h" | |
| 9 #include "media/cast/net/pacing/paced_sender.h" | |
| 10 #include "media/cast/net/rtcp/rtcp_builder.h" | |
| 11 #include "media/cast/rtcp/rtcp_utility.h" | |
| 12 #include "media/cast/rtcp/test_rtcp_packet_builder.h" | |
| 13 #include "media/cast/test/fake_task_runner.h" | |
| 14 #include "testing/gmock/include/gmock/gmock.h" | |
| 15 | |
| 16 namespace media { | |
| 17 namespace cast { | |
| 18 | |
| 19 namespace { | |
| 20 static const uint32 kSendingSsrc = 0x12345678; | |
| 21 static const std::string kCName("test@10.1.1.1"); | |
| 22 } // namespace | |
| 23 | |
| 24 class TestRtcpTransport : public PacedPacketSender { | |
| 25 public: | |
| 26 TestRtcpTransport() | |
| 27 : expected_packet_length_(0), | |
| 28 packet_count_(0) { | |
| 29 } | |
| 30 | |
| 31 virtual bool SendRtcpPacket(const Packet& packet) OVERRIDE { | |
| 32 EXPECT_EQ(expected_packet_length_, packet.size()); | |
| 33 EXPECT_EQ(0, memcmp(expected_packet_, &(packet[0]), packet.size())); | |
| 34 packet_count_++; | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 virtual bool SendPackets(const PacketList& packets) OVERRIDE { | |
| 39 return false; | |
| 40 } | |
| 41 | |
| 42 virtual bool ResendPackets(const PacketList& packets) OVERRIDE { | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 void SetExpectedRtcpPacket(const uint8* rtcp_buffer, size_t length) { | |
| 47 expected_packet_length_ = length; | |
| 48 memcpy(expected_packet_, rtcp_buffer, length); | |
| 49 } | |
| 50 | |
| 51 int packet_count() const { return packet_count_; } | |
| 52 | |
| 53 private: | |
| 54 uint8 expected_packet_[kIpPacketSize]; | |
| 55 size_t expected_packet_length_; | |
| 56 int packet_count_; | |
| 57 }; | |
| 58 | |
| 59 class RtcpBuilderTest : public ::testing::Test { | |
| 60 protected: | |
| 61 RtcpBuilderTest() | |
| 62 : task_runner_(new test::FakeTaskRunner(&testing_clock_)), | |
| 63 cast_environment_(new CastEnvironment(&testing_clock_, task_runner_, | |
| 64 task_runner_, task_runner_, task_runner_, task_runner_, | |
| 65 GetDefaultCastLoggingConfig())), | |
| 66 rtcp_builder_(new RtcpBuilder(&test_transport_, kSendingSsrc, kCName)) { | |
| 67 } | |
| 68 | |
| 69 base::SimpleTestTickClock testing_clock_; | |
| 70 TestRtcpTransport test_transport_; | |
| 71 scoped_refptr<test::FakeTaskRunner> task_runner_; | |
| 72 scoped_refptr<CastEnvironment> cast_environment_; | |
| 73 scoped_ptr<RtcpBuilder> rtcp_builder_; | |
| 74 }; | |
| 75 | |
| 76 TEST_F(RtcpBuilderTest, RtcpSenderReport) { | |
| 77 RtcpSenderInfo sender_info; | |
| 78 sender_info.ntp_seconds = kNtpHigh; | |
| 79 sender_info.ntp_fraction = kNtpLow; | |
| 80 sender_info.rtp_timestamp = kRtpTimestamp; | |
| 81 sender_info.send_packet_count = kSendPacketCount; | |
| 82 sender_info.send_octet_count = kSendOctetCount; | |
| 83 | |
| 84 // Sender report + c_name. | |
| 85 TestRtcpPacketBuilder p; | |
| 86 p.AddSr(kSendingSsrc, 0); | |
| 87 p.AddSdesCname(kSendingSsrc, kCName); | |
| 88 test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length()); | |
| 89 | |
| 90 rtcp_builder_->SendRtcpFromRtpSender(RtcpBuilder::kRtcpSr, | |
| 91 &sender_info, | |
| 92 NULL, | |
| 93 NULL); | |
| 94 | |
| 95 EXPECT_EQ(1, test_transport_.packet_count()); | |
| 96 } | |
| 97 | |
| 98 TEST_F(RtcpBuilderTest, RtcpSenderReportWithDlrr) { | |
| 99 RtcpSenderInfo sender_info; | |
| 100 sender_info.ntp_seconds = kNtpHigh; | |
| 101 sender_info.ntp_fraction = kNtpLow; | |
| 102 sender_info.rtp_timestamp = kRtpTimestamp; | |
| 103 sender_info.send_packet_count = kSendPacketCount; | |
| 104 sender_info.send_octet_count = kSendOctetCount; | |
| 105 | |
| 106 // Sender report + c_name + dlrr. | |
| 107 TestRtcpPacketBuilder p1; | |
| 108 p1.AddSr(kSendingSsrc, 0); | |
| 109 p1.AddSdesCname(kSendingSsrc, kCName); | |
| 110 p1.AddXrHeader(kSendingSsrc); | |
| 111 p1.AddXrDlrrBlock(kSendingSsrc); | |
| 112 test_transport_.SetExpectedRtcpPacket(p1.Packet(), p1.Length()); | |
| 113 | |
| 114 RtcpDlrrReportBlock dlrr_rb; | |
| 115 dlrr_rb.last_rr = kLastRr; | |
| 116 dlrr_rb.delay_since_last_rr = kDelayLastRr; | |
| 117 | |
| 118 rtcp_builder_->SendRtcpFromRtpSender( | |
| 119 RtcpBuilder::kRtcpSr | RtcpBuilder::kRtcpDlrr, | |
| 120 &sender_info, | |
| 121 &dlrr_rb, | |
| 122 NULL); | |
| 123 | |
| 124 EXPECT_EQ(1, test_transport_.packet_count()); | |
| 125 } | |
| 126 | |
| 127 TEST_F(RtcpBuilderTest, RtcpSenderReportWithDlrrAndLog) { | |
| 128 RtcpSenderInfo sender_info; | |
| 129 sender_info.ntp_seconds = kNtpHigh; | |
| 130 sender_info.ntp_fraction = kNtpLow; | |
| 131 sender_info.rtp_timestamp = kRtpTimestamp; | |
| 132 sender_info.send_packet_count = kSendPacketCount; | |
| 133 sender_info.send_octet_count = kSendOctetCount; | |
| 134 | |
| 135 // Sender report + c_name + dlrr + sender log. | |
| 136 TestRtcpPacketBuilder p; | |
| 137 p.AddSr(kSendingSsrc, 0); | |
| 138 p.AddSdesCname(kSendingSsrc, kCName); | |
| 139 p.AddXrHeader(kSendingSsrc); | |
| 140 p.AddXrDlrrBlock(kSendingSsrc); | |
| 141 p.AddSenderLog(kSendingSsrc); | |
| 142 p.AddSenderFrameLog(kRtcpSenderFrameStatusSentToNetwork, kRtpTimestamp); | |
| 143 | |
| 144 test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length()); | |
| 145 | |
| 146 RtcpDlrrReportBlock dlrr_rb; | |
| 147 dlrr_rb.last_rr = kLastRr; | |
| 148 dlrr_rb.delay_since_last_rr = kDelayLastRr; | |
| 149 | |
| 150 RtcpSenderFrameLogMessage sender_frame_log; | |
| 151 sender_frame_log.frame_status = kRtcpSenderFrameStatusSentToNetwork; | |
| 152 sender_frame_log.rtp_timestamp = kRtpTimestamp; | |
| 153 | |
| 154 RtcpSenderLogMessage sender_log; | |
| 155 sender_log.push_back(sender_frame_log); | |
| 156 | |
| 157 rtcp_builder_->SendRtcpFromRtpSender( | |
| 158 RtcpBuilder::kRtcpSr | RtcpBuilder::kRtcpDlrr | | |
| 159 RtcpBuilder::kRtcpSenderLog, | |
| 160 &sender_info, | |
| 161 &dlrr_rb, | |
| 162 &sender_log); | |
| 163 | |
| 164 EXPECT_EQ(1, test_transport_.packet_count()); | |
| 165 EXPECT_TRUE(sender_log.empty()); | |
| 166 } | |
| 167 | |
| 168 TEST_F(RtcpBuilderTest, RtcpSenderReporWithTooManyLogFrames) { | |
| 169 RtcpSenderInfo sender_info; | |
| 170 sender_info.ntp_seconds = kNtpHigh; | |
| 171 sender_info.ntp_fraction = kNtpLow; | |
| 172 sender_info.rtp_timestamp = kRtpTimestamp; | |
| 173 sender_info.send_packet_count = kSendPacketCount; | |
| 174 sender_info.send_octet_count = kSendOctetCount; | |
| 175 | |
| 176 // Sender report + c_name + sender log. | |
| 177 TestRtcpPacketBuilder p; | |
| 178 p.AddSr(kSendingSsrc, 0); | |
| 179 p.AddSdesCname(kSendingSsrc, kCName); | |
| 180 p.AddSenderLog(kSendingSsrc); | |
| 181 | |
| 182 for (int i = 0; i < 359; ++i) { | |
| 183 p.AddSenderFrameLog(kRtcpSenderFrameStatusSentToNetwork, | |
| 184 kRtpTimestamp + i * 90); | |
| 185 } | |
| 186 test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length()); | |
| 187 | |
| 188 | |
| 189 RtcpSenderLogMessage sender_log; | |
| 190 for (int j = 0; j < 400; ++j) { | |
| 191 RtcpSenderFrameLogMessage sender_frame_log; | |
| 192 sender_frame_log.frame_status = kRtcpSenderFrameStatusSentToNetwork; | |
| 193 sender_frame_log.rtp_timestamp = kRtpTimestamp + j * 90; | |
| 194 sender_log.push_back(sender_frame_log); | |
| 195 } | |
| 196 | |
| 197 rtcp_builder_->SendRtcpFromRtpSender( | |
| 198 RtcpBuilder::kRtcpSr | RtcpBuilder::kRtcpSenderLog, | |
| 199 &sender_info, | |
| 200 NULL, | |
| 201 &sender_log); | |
| 202 | |
| 203 EXPECT_EQ(1, test_transport_.packet_count()); | |
| 204 EXPECT_EQ(41u, sender_log.size()); | |
| 205 } | |
| 206 | |
| 207 } // namespace cast | |
| 208 } // namespace media | |
| OLD | NEW |