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/net/rtcp/rtcp_utility.h" | |
12 #include "media/cast/net/rtcp/test_rtcp_packet_builder.h" | |
13 #include "media/cast/test/fake_single_thread_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_[kMaxIpPacketSize]; | |
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::FakeSingleThreadTaskRunner(&testing_clock_)), | |
63 cast_environment_(new CastEnvironment(&testing_clock_, task_runner_, | |
64 task_runner_, task_runner_, task_runner_, task_runner_, | |
65 GetDefaultCastSenderLoggingConfig())), | |
66 rtcp_builder_(new RtcpBuilder(&test_transport_, kSendingSsrc, kCName)) { | |
67 } | |
68 | |
69 base::SimpleTestTickClock testing_clock_; | |
70 TestRtcpTransport test_transport_; | |
71 scoped_refptr<test::FakeSingleThreadTaskRunner> 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 kSendingSsrc, | |
95 kCName); | |
96 | |
97 EXPECT_EQ(1, test_transport_.packet_count()); | |
98 } | |
99 | |
100 TEST_F(RtcpBuilderTest, RtcpSenderReportWithDlrr) { | |
101 RtcpSenderInfo sender_info; | |
102 sender_info.ntp_seconds = kNtpHigh; | |
103 sender_info.ntp_fraction = kNtpLow; | |
104 sender_info.rtp_timestamp = kRtpTimestamp; | |
105 sender_info.send_packet_count = kSendPacketCount; | |
106 sender_info.send_octet_count = kSendOctetCount; | |
107 | |
108 // Sender report + c_name + dlrr. | |
109 TestRtcpPacketBuilder p1; | |
110 p1.AddSr(kSendingSsrc, 0); | |
111 p1.AddSdesCname(kSendingSsrc, kCName); | |
112 p1.AddXrHeader(kSendingSsrc); | |
113 p1.AddXrDlrrBlock(kSendingSsrc); | |
114 test_transport_.SetExpectedRtcpPacket(p1.Packet(), p1.Length()); | |
115 | |
116 RtcpDlrrReportBlock dlrr_rb; | |
117 dlrr_rb.last_rr = kLastRr; | |
118 dlrr_rb.delay_since_last_rr = kDelayLastRr; | |
119 | |
120 rtcp_builder_->SendRtcpFromRtpSender( | |
121 RtcpBuilder::kRtcpSr | RtcpBuilder::kRtcpDlrr, | |
122 &sender_info, | |
123 &dlrr_rb, | |
124 NULL, | |
125 kSendingSsrc, | |
126 kCName); | |
127 | |
128 EXPECT_EQ(1, test_transport_.packet_count()); | |
129 } | |
130 | |
131 TEST_F(RtcpBuilderTest, RtcpSenderReportWithDlrr) { | |
132 RtcpSenderInfo sender_info; | |
133 sender_info.ntp_seconds = kNtpHigh; | |
134 sender_info.ntp_fraction = kNtpLow; | |
135 sender_info.rtp_timestamp = kRtpTimestamp; | |
136 sender_info.send_packet_count = kSendPacketCount; | |
137 sender_info.send_octet_count = kSendOctetCount; | |
138 | |
139 // Sender report + c_name + dlrr + sender log. | |
140 TestRtcpPacketBuilder p; | |
141 p.AddSr(kSendingSsrc, 0); | |
142 p.AddSdesCname(kSendingSsrc, kCName); | |
143 p.AddXrHeader(kSendingSsrc); | |
144 p.AddXrDlrrBlock(kSendingSsrc); | |
145 | |
146 test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length()); | |
147 | |
148 RtcpDlrrReportBlock dlrr_rb; | |
149 dlrr_rb.last_rr = kLastRr; | |
150 dlrr_rb.delay_since_last_rr = kDelayLastRr; | |
151 | |
152 rtcp_builder_->SendRtcpFromRtpSender( | |
153 RtcpBuilder::kRtcpSr | RtcpBuilder::kRtcpDlrr | | |
154 RtcpBuilder::kRtcpSenderLog, | |
155 &sender_info, | |
156 &dlrr_rb, | |
157 kSendingSsrc, | |
158 kCName); | |
159 | |
160 EXPECT_EQ(1, test_transport_.packet_count()); | |
161 } | |
162 | |
163 } // namespace cast | |
164 } // namespace media | |
OLD | NEW |