OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 } // namespace | |
22 | |
23 class TestRtcpTransport : public PacedPacketSender { | |
24 public: | |
25 TestRtcpTransport() | |
26 : expected_packet_length_(0), | |
27 packet_count_(0) { | |
28 } | |
29 | |
30 virtual bool SendRtcpPacket(const Packet& packet) OVERRIDE { | |
31 EXPECT_EQ(expected_packet_length_, packet.size()); | |
32 EXPECT_EQ(0, memcmp(expected_packet_, &(packet[0]), packet.size())); | |
33 packet_count_++; | |
34 return true; | |
35 } | |
36 | |
37 virtual bool SendPackets(const PacketList& packets) OVERRIDE { | |
38 return false; | |
39 } | |
40 | |
41 virtual bool ResendPackets(const PacketList& packets) OVERRIDE { | |
42 return false; | |
43 } | |
44 | |
45 void SetExpectedRtcpPacket(const uint8* rtcp_buffer, size_t length) { | |
46 expected_packet_length_ = length; | |
47 memcpy(expected_packet_, rtcp_buffer, length); | |
48 } | |
49 | |
50 int packet_count() const { return packet_count_; } | |
51 | |
52 private: | |
53 uint8 expected_packet_[kMaxIpPacketSize]; | |
54 size_t expected_packet_length_; | |
55 int packet_count_; | |
56 }; | |
57 | |
58 class RtcpBuilderTest : public ::testing::Test { | |
59 protected: | |
60 RtcpBuilderTest() | |
61 : task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)), | |
62 cast_environment_(new CastEnvironment(&testing_clock_, task_runner_, | |
63 task_runner_, task_runner_, task_runner_, task_runner_, | |
64 GetDefaultCastSenderLoggingConfig())), | |
65 rtcp_builder_(new RtcpBuilder(&test_transport_, kSendingSsrc)) { | |
66 } | |
67 | |
68 base::SimpleTestTickClock testing_clock_; | |
69 TestRtcpTransport test_transport_; | |
70 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | |
71 scoped_refptr<CastEnvironment> cast_environment_; | |
72 scoped_ptr<RtcpBuilder> rtcp_builder_; | |
73 }; | |
74 | |
75 TEST_F(RtcpBuilderTest, RtcpSenderReport) { | |
76 RtcpSenderInfo sender_info; | |
77 sender_info.ntp_seconds = kNtpHigh; | |
78 sender_info.ntp_fraction = kNtpLow; | |
79 sender_info.rtp_timestamp = kRtpTimestamp; | |
80 sender_info.send_packet_count = kSendPacketCount; | |
81 sender_info.send_octet_count = kSendOctetCount; | |
82 | |
83 // Sender report. | |
84 TestRtcpPacketBuilder p; | |
85 p.AddSr(kSendingSsrc, 0); | |
86 test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length()); | |
87 | |
88 rtcp_builder_->SendRtcpFromRtpSender(RtcpBuilder::kRtcpSr, | |
89 &sender_info, | |
90 NULL, | |
91 NULL, | |
92 kSendingSsrc); | |
93 | |
94 EXPECT_EQ(1, test_transport_.packet_count()); | |
95 } | |
96 | |
97 TEST_F(RtcpBuilderTest, RtcpSenderReportWithDlrr) { | |
98 RtcpSenderInfo sender_info; | |
99 sender_info.ntp_seconds = kNtpHigh; | |
100 sender_info.ntp_fraction = kNtpLow; | |
101 sender_info.rtp_timestamp = kRtpTimestamp; | |
102 sender_info.send_packet_count = kSendPacketCount; | |
103 sender_info.send_octet_count = kSendOctetCount; | |
104 | |
105 // Sender report + dlrr. | |
106 TestRtcpPacketBuilder p1; | |
107 p1.AddSr(kSendingSsrc, 0); | |
108 p1.AddSdesCname(kSendingSsrc); | |
109 p1.AddXrHeader(kSendingSsrc); | |
110 p1.AddXrDlrrBlock(kSendingSsrc); | |
111 test_transport_.SetExpectedRtcpPacket(p1.Packet(), p1.Length()); | |
112 | |
113 RtcpDlrrReportBlock dlrr_rb; | |
114 dlrr_rb.last_rr = kLastRr; | |
115 dlrr_rb.delay_since_last_rr = kDelayLastRr; | |
116 | |
117 rtcp_builder_->SendRtcpFromRtpSender( | |
118 RtcpBuilder::kRtcpSr | RtcpBuilder::kRtcpDlrr, | |
119 &sender_info, | |
120 &dlrr_rb, | |
121 NULL, | |
122 kSendingSsrc); | |
123 | |
124 EXPECT_EQ(1, test_transport_.packet_count()); | |
125 } | |
126 | |
127 TEST_F(RtcpBuilderTest, RtcpSenderReportWithDlrr) { | |
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 + + dlrr + sender log. | |
136 TestRtcpPacketBuilder p; | |
137 p.AddSr(kSendingSsrc, 0); | |
138 p.AddSdesCname(kSendingSsrc); | |
139 p.AddXrHeader(kSendingSsrc); | |
140 p.AddXrDlrrBlock(kSendingSsrc); | |
141 | |
142 test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length()); | |
143 | |
144 RtcpDlrrReportBlock dlrr_rb; | |
145 dlrr_rb.last_rr = kLastRr; | |
146 dlrr_rb.delay_since_last_rr = kDelayLastRr; | |
147 | |
148 rtcp_builder_->SendRtcpFromRtpSender( | |
149 RtcpBuilder::kRtcpSr | RtcpBuilder::kRtcpDlrr | | |
150 RtcpBuilder::kRtcpSenderLog, | |
151 &sender_info, | |
152 &dlrr_rb, | |
153 kSendingSsrc); | |
154 | |
155 EXPECT_EQ(1, test_transport_.packet_count()); | |
156 } | |
157 | |
158 } // namespace cast | |
159 } // namespace media | |
OLD | NEW |