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