OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 * This file includes unit tests for the RtcpPacket. | 10 * This file includes unit tests for the RtcpPacket. |
11 */ | 11 */ |
12 | 12 |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" | 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
16 #include "webrtc/test/rtcp_packet_parser.h" | 17 #include "webrtc/test/rtcp_packet_parser.h" |
17 | 18 |
| 19 using ::testing::ElementsAre; |
| 20 |
18 using webrtc::rtcp::App; | 21 using webrtc::rtcp::App; |
19 using webrtc::rtcp::Bye; | 22 using webrtc::rtcp::Bye; |
20 using webrtc::rtcp::Dlrr; | 23 using webrtc::rtcp::Dlrr; |
21 using webrtc::rtcp::Empty; | 24 using webrtc::rtcp::Empty; |
22 using webrtc::rtcp::Fir; | 25 using webrtc::rtcp::Fir; |
23 using webrtc::rtcp::Ij; | 26 using webrtc::rtcp::Ij; |
24 using webrtc::rtcp::Nack; | 27 using webrtc::rtcp::Nack; |
25 using webrtc::rtcp::Pli; | 28 using webrtc::rtcp::Pli; |
26 using webrtc::rtcp::Sdes; | 29 using webrtc::rtcp::Sdes; |
27 using webrtc::rtcp::SenderReport; | 30 using webrtc::rtcp::SenderReport; |
(...skipping 13 matching lines...) Expand all Loading... |
41 | 44 |
42 namespace webrtc { | 45 namespace webrtc { |
43 | 46 |
44 const uint32_t kSenderSsrc = 0x12345678; | 47 const uint32_t kSenderSsrc = 0x12345678; |
45 const uint32_t kRemoteSsrc = 0x23456789; | 48 const uint32_t kRemoteSsrc = 0x23456789; |
46 | 49 |
47 TEST(RtcpPacketTest, Rr) { | 50 TEST(RtcpPacketTest, Rr) { |
48 ReceiverReport rr; | 51 ReceiverReport rr; |
49 rr.From(kSenderSsrc); | 52 rr.From(kSenderSsrc); |
50 | 53 |
51 RawPacket packet = rr.Build(); | 54 rtc::scoped_ptr<RawPacket> packet(rr.Build()); |
52 RtcpPacketParser parser; | 55 RtcpPacketParser parser; |
53 parser.Parse(packet.buffer(), packet.buffer_length()); | 56 parser.Parse(packet->Buffer(), packet->Length()); |
54 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | 57 EXPECT_EQ(1, parser.receiver_report()->num_packets()); |
55 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); | 58 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); |
56 EXPECT_EQ(0, parser.report_block()->num_packets()); | 59 EXPECT_EQ(0, parser.report_block()->num_packets()); |
57 } | 60 } |
58 | 61 |
59 TEST(RtcpPacketTest, RrWithOneReportBlock) { | 62 TEST(RtcpPacketTest, RrWithOneReportBlock) { |
60 ReportBlock rb; | 63 ReportBlock rb; |
61 rb.To(kRemoteSsrc); | 64 rb.To(kRemoteSsrc); |
62 rb.WithFractionLost(55); | 65 rb.WithFractionLost(55); |
63 rb.WithCumulativeLost(0x111111); | 66 rb.WithCumulativeLost(0x111111); |
64 rb.WithExtHighestSeqNum(0x22222222); | 67 rb.WithExtHighestSeqNum(0x22222222); |
65 rb.WithJitter(0x33333333); | 68 rb.WithJitter(0x33333333); |
66 rb.WithLastSr(0x44444444); | 69 rb.WithLastSr(0x44444444); |
67 rb.WithDelayLastSr(0x55555555); | 70 rb.WithDelayLastSr(0x55555555); |
68 | 71 |
69 ReceiverReport rr; | 72 ReceiverReport rr; |
70 rr.From(kSenderSsrc); | 73 rr.From(kSenderSsrc); |
71 rr.WithReportBlock(&rb); | 74 EXPECT_TRUE(rr.WithReportBlock(&rb)); |
72 | 75 |
73 RawPacket packet = rr.Build(); | 76 rtc::scoped_ptr<RawPacket> packet(rr.Build()); |
74 RtcpPacketParser parser; | 77 RtcpPacketParser parser; |
75 parser.Parse(packet.buffer(), packet.buffer_length()); | 78 parser.Parse(packet->Buffer(), packet->Length()); |
76 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | 79 EXPECT_EQ(1, parser.receiver_report()->num_packets()); |
77 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); | 80 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); |
78 EXPECT_EQ(1, parser.report_block()->num_packets()); | 81 EXPECT_EQ(1, parser.report_block()->num_packets()); |
79 EXPECT_EQ(kRemoteSsrc, parser.report_block()->Ssrc()); | 82 EXPECT_EQ(kRemoteSsrc, parser.report_block()->Ssrc()); |
80 EXPECT_EQ(55U, parser.report_block()->FractionLost()); | 83 EXPECT_EQ(55U, parser.report_block()->FractionLost()); |
81 EXPECT_EQ(0x111111U, parser.report_block()->CumPacketLost()); | 84 EXPECT_EQ(0x111111U, parser.report_block()->CumPacketLost()); |
82 EXPECT_EQ(0x22222222U, parser.report_block()->ExtHighestSeqNum()); | 85 EXPECT_EQ(0x22222222U, parser.report_block()->ExtHighestSeqNum()); |
83 EXPECT_EQ(0x33333333U, parser.report_block()->Jitter()); | 86 EXPECT_EQ(0x33333333U, parser.report_block()->Jitter()); |
84 EXPECT_EQ(0x44444444U, parser.report_block()->LastSr()); | 87 EXPECT_EQ(0x44444444U, parser.report_block()->LastSr()); |
85 EXPECT_EQ(0x55555555U, parser.report_block()->DelayLastSr()); | 88 EXPECT_EQ(0x55555555U, parser.report_block()->DelayLastSr()); |
86 } | 89 } |
87 | 90 |
88 TEST(RtcpPacketTest, RrWithTwoReportBlocks) { | 91 TEST(RtcpPacketTest, RrWithTwoReportBlocks) { |
89 ReportBlock rb1; | 92 ReportBlock rb1; |
90 rb1.To(kRemoteSsrc); | 93 rb1.To(kRemoteSsrc); |
91 ReportBlock rb2; | 94 ReportBlock rb2; |
92 rb2.To(kRemoteSsrc + 1); | 95 rb2.To(kRemoteSsrc + 1); |
93 | 96 |
94 ReceiverReport rr; | 97 ReceiverReport rr; |
95 rr.From(kSenderSsrc); | 98 rr.From(kSenderSsrc); |
96 rr.WithReportBlock(&rb1); | 99 EXPECT_TRUE(rr.WithReportBlock(&rb1)); |
97 rr.WithReportBlock(&rb2); | 100 EXPECT_TRUE(rr.WithReportBlock(&rb2)); |
98 | 101 |
99 RawPacket packet = rr.Build(); | 102 rtc::scoped_ptr<RawPacket> packet(rr.Build()); |
100 RtcpPacketParser parser; | 103 RtcpPacketParser parser; |
101 parser.Parse(packet.buffer(), packet.buffer_length()); | 104 parser.Parse(packet->Buffer(), packet->Length()); |
102 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | 105 EXPECT_EQ(1, parser.receiver_report()->num_packets()); |
103 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); | 106 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); |
104 EXPECT_EQ(2, parser.report_block()->num_packets()); | 107 EXPECT_EQ(2, parser.report_block()->num_packets()); |
105 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc)); | 108 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc)); |
106 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc + 1)); | 109 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc + 1)); |
107 } | 110 } |
108 | 111 |
| 112 TEST(RtcpPacketTest, RrWithTooManyReportBlocks) { |
| 113 ReceiverReport rr; |
| 114 rr.From(kSenderSsrc); |
| 115 const int kMaxReportBlocks = (1 << 5) - 1; |
| 116 ReportBlock rb; |
| 117 for (int i = 0; i < kMaxReportBlocks; ++i) { |
| 118 rb.To(kRemoteSsrc + i); |
| 119 EXPECT_TRUE(rr.WithReportBlock(&rb)); |
| 120 } |
| 121 rb.To(kRemoteSsrc + kMaxReportBlocks); |
| 122 EXPECT_FALSE(rr.WithReportBlock(&rb)); |
| 123 } |
| 124 |
109 TEST(RtcpPacketTest, Sr) { | 125 TEST(RtcpPacketTest, Sr) { |
110 SenderReport sr; | 126 SenderReport sr; |
111 sr.From(kSenderSsrc); | 127 sr.From(kSenderSsrc); |
112 sr.WithNtpSec(0x11111111); | 128 sr.WithNtpSec(0x11111111); |
113 sr.WithNtpFrac(0x22222222); | 129 sr.WithNtpFrac(0x22222222); |
114 sr.WithRtpTimestamp(0x33333333); | 130 sr.WithRtpTimestamp(0x33333333); |
115 sr.WithPacketCount(0x44444444); | 131 sr.WithPacketCount(0x44444444); |
116 sr.WithOctetCount(0x55555555); | 132 sr.WithOctetCount(0x55555555); |
117 | 133 |
118 RawPacket packet = sr.Build(); | 134 rtc::scoped_ptr<RawPacket> packet(sr.Build()); |
119 RtcpPacketParser parser; | 135 RtcpPacketParser parser; |
120 parser.Parse(packet.buffer(), packet.buffer_length()); | 136 parser.Parse(packet->Buffer(), packet->Length()); |
121 | 137 |
122 EXPECT_EQ(1, parser.sender_report()->num_packets()); | 138 EXPECT_EQ(1, parser.sender_report()->num_packets()); |
123 EXPECT_EQ(kSenderSsrc, parser.sender_report()->Ssrc()); | 139 EXPECT_EQ(kSenderSsrc, parser.sender_report()->Ssrc()); |
124 EXPECT_EQ(0x11111111U, parser.sender_report()->NtpSec()); | 140 EXPECT_EQ(0x11111111U, parser.sender_report()->NtpSec()); |
125 EXPECT_EQ(0x22222222U, parser.sender_report()->NtpFrac()); | 141 EXPECT_EQ(0x22222222U, parser.sender_report()->NtpFrac()); |
126 EXPECT_EQ(0x33333333U, parser.sender_report()->RtpTimestamp()); | 142 EXPECT_EQ(0x33333333U, parser.sender_report()->RtpTimestamp()); |
127 EXPECT_EQ(0x44444444U, parser.sender_report()->PacketCount()); | 143 EXPECT_EQ(0x44444444U, parser.sender_report()->PacketCount()); |
128 EXPECT_EQ(0x55555555U, parser.sender_report()->OctetCount()); | 144 EXPECT_EQ(0x55555555U, parser.sender_report()->OctetCount()); |
129 EXPECT_EQ(0, parser.report_block()->num_packets()); | 145 EXPECT_EQ(0, parser.report_block()->num_packets()); |
130 } | 146 } |
131 | 147 |
132 TEST(RtcpPacketTest, SrWithOneReportBlock) { | 148 TEST(RtcpPacketTest, SrWithOneReportBlock) { |
133 ReportBlock rb; | 149 ReportBlock rb; |
134 rb.To(kRemoteSsrc); | 150 rb.To(kRemoteSsrc); |
135 | 151 |
136 SenderReport sr; | 152 SenderReport sr; |
137 sr.From(kSenderSsrc); | 153 sr.From(kSenderSsrc); |
138 sr.WithReportBlock(&rb); | 154 EXPECT_TRUE(sr.WithReportBlock(&rb)); |
139 | 155 |
140 RawPacket packet = sr.Build(); | 156 rtc::scoped_ptr<RawPacket> packet(sr.Build()); |
141 RtcpPacketParser parser; | 157 RtcpPacketParser parser; |
142 parser.Parse(packet.buffer(), packet.buffer_length()); | 158 parser.Parse(packet->Buffer(), packet->Length()); |
143 EXPECT_EQ(1, parser.sender_report()->num_packets()); | 159 EXPECT_EQ(1, parser.sender_report()->num_packets()); |
144 EXPECT_EQ(kSenderSsrc, parser.sender_report()->Ssrc()); | 160 EXPECT_EQ(kSenderSsrc, parser.sender_report()->Ssrc()); |
145 EXPECT_EQ(1, parser.report_block()->num_packets()); | 161 EXPECT_EQ(1, parser.report_block()->num_packets()); |
146 EXPECT_EQ(kRemoteSsrc, parser.report_block()->Ssrc()); | 162 EXPECT_EQ(kRemoteSsrc, parser.report_block()->Ssrc()); |
147 } | 163 } |
148 | 164 |
149 TEST(RtcpPacketTest, SrWithTwoReportBlocks) { | 165 TEST(RtcpPacketTest, SrWithTwoReportBlocks) { |
150 ReportBlock rb1; | 166 ReportBlock rb1; |
151 rb1.To(kRemoteSsrc); | 167 rb1.To(kRemoteSsrc); |
152 ReportBlock rb2; | 168 ReportBlock rb2; |
153 rb2.To(kRemoteSsrc + 1); | 169 rb2.To(kRemoteSsrc + 1); |
154 | 170 |
155 SenderReport sr; | 171 SenderReport sr; |
156 sr.From(kSenderSsrc); | 172 sr.From(kSenderSsrc); |
157 sr.WithReportBlock(&rb1); | 173 EXPECT_TRUE(sr.WithReportBlock(&rb1)); |
158 sr.WithReportBlock(&rb2); | 174 EXPECT_TRUE(sr.WithReportBlock(&rb2)); |
159 | 175 |
160 RawPacket packet = sr.Build(); | 176 rtc::scoped_ptr<RawPacket> packet(sr.Build()); |
161 RtcpPacketParser parser; | 177 RtcpPacketParser parser; |
162 parser.Parse(packet.buffer(), packet.buffer_length()); | 178 parser.Parse(packet->Buffer(), packet->Length()); |
163 EXPECT_EQ(1, parser.sender_report()->num_packets()); | 179 EXPECT_EQ(1, parser.sender_report()->num_packets()); |
164 EXPECT_EQ(kSenderSsrc, parser.sender_report()->Ssrc()); | 180 EXPECT_EQ(kSenderSsrc, parser.sender_report()->Ssrc()); |
165 EXPECT_EQ(2, parser.report_block()->num_packets()); | 181 EXPECT_EQ(2, parser.report_block()->num_packets()); |
166 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc)); | 182 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc)); |
167 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc + 1)); | 183 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc + 1)); |
168 } | 184 } |
169 | 185 |
| 186 TEST(RtcpPacketTest, SrWithTooManyReportBlocks) { |
| 187 SenderReport sr; |
| 188 sr.From(kSenderSsrc); |
| 189 const int kMaxReportBlocks = (1 << 5) - 1; |
| 190 ReportBlock rb; |
| 191 for (int i = 0; i < kMaxReportBlocks; ++i) { |
| 192 rb.To(kRemoteSsrc + i); |
| 193 EXPECT_TRUE(sr.WithReportBlock(&rb)); |
| 194 } |
| 195 rb.To(kRemoteSsrc + kMaxReportBlocks); |
| 196 EXPECT_FALSE(sr.WithReportBlock(&rb)); |
| 197 } |
| 198 |
170 TEST(RtcpPacketTest, IjNoItem) { | 199 TEST(RtcpPacketTest, IjNoItem) { |
171 Ij ij; | 200 Ij ij; |
172 | 201 |
173 RawPacket packet = ij.Build(); | 202 rtc::scoped_ptr<RawPacket> packet(ij.Build()); |
174 RtcpPacketParser parser; | 203 RtcpPacketParser parser; |
175 parser.Parse(packet.buffer(), packet.buffer_length()); | 204 parser.Parse(packet->Buffer(), packet->Length()); |
176 EXPECT_EQ(1, parser.ij()->num_packets()); | 205 EXPECT_EQ(1, parser.ij()->num_packets()); |
177 EXPECT_EQ(0, parser.ij_item()->num_packets()); | 206 EXPECT_EQ(0, parser.ij_item()->num_packets()); |
178 } | 207 } |
179 | 208 |
180 TEST(RtcpPacketTest, IjOneItem) { | 209 TEST(RtcpPacketTest, IjOneItem) { |
181 Ij ij; | 210 Ij ij; |
182 ij.WithJitterItem(0x11111111); | 211 EXPECT_TRUE(ij.WithJitterItem(0x11111111)); |
183 | 212 |
184 RawPacket packet = ij.Build(); | 213 rtc::scoped_ptr<RawPacket> packet(ij.Build()); |
185 RtcpPacketParser parser; | 214 RtcpPacketParser parser; |
186 parser.Parse(packet.buffer(), packet.buffer_length()); | 215 parser.Parse(packet->Buffer(), packet->Length()); |
187 EXPECT_EQ(1, parser.ij()->num_packets()); | 216 EXPECT_EQ(1, parser.ij()->num_packets()); |
188 EXPECT_EQ(1, parser.ij_item()->num_packets()); | 217 EXPECT_EQ(1, parser.ij_item()->num_packets()); |
189 EXPECT_EQ(0x11111111U, parser.ij_item()->Jitter()); | 218 EXPECT_EQ(0x11111111U, parser.ij_item()->Jitter()); |
190 } | 219 } |
191 | 220 |
192 TEST(RtcpPacketTest, IjTwoItems) { | 221 TEST(RtcpPacketTest, IjTwoItems) { |
193 Ij ij; | 222 Ij ij; |
194 ij.WithJitterItem(0x11111111); | 223 EXPECT_TRUE(ij.WithJitterItem(0x11111111)); |
195 ij.WithJitterItem(0x22222222); | 224 EXPECT_TRUE(ij.WithJitterItem(0x22222222)); |
196 | 225 |
197 RawPacket packet = ij.Build(); | 226 rtc::scoped_ptr<RawPacket> packet(ij.Build()); |
198 RtcpPacketParser parser; | 227 RtcpPacketParser parser; |
199 parser.Parse(packet.buffer(), packet.buffer_length()); | 228 parser.Parse(packet->Buffer(), packet->Length()); |
200 EXPECT_EQ(1, parser.ij()->num_packets()); | 229 EXPECT_EQ(1, parser.ij()->num_packets()); |
201 EXPECT_EQ(2, parser.ij_item()->num_packets()); | 230 EXPECT_EQ(2, parser.ij_item()->num_packets()); |
202 EXPECT_EQ(0x22222222U, parser.ij_item()->Jitter()); | 231 EXPECT_EQ(0x22222222U, parser.ij_item()->Jitter()); |
203 } | 232 } |
204 | 233 |
| 234 TEST(RtcpPacketTest, IjTooManyItems) { |
| 235 Ij ij; |
| 236 const int kMaxIjItems = (1 << 5) - 1; |
| 237 for (int i = 0; i < kMaxIjItems; ++i) { |
| 238 EXPECT_TRUE(ij.WithJitterItem(i)); |
| 239 } |
| 240 EXPECT_FALSE(ij.WithJitterItem(kMaxIjItems)); |
| 241 } |
| 242 |
205 TEST(RtcpPacketTest, AppWithNoData) { | 243 TEST(RtcpPacketTest, AppWithNoData) { |
206 App app; | 244 App app; |
207 app.WithSubType(30); | 245 app.WithSubType(30); |
208 uint32_t name = 'n' << 24; | 246 uint32_t name = 'n' << 24; |
209 name += 'a' << 16; | 247 name += 'a' << 16; |
210 name += 'm' << 8; | 248 name += 'm' << 8; |
211 name += 'e'; | 249 name += 'e'; |
212 app.WithName(name); | 250 app.WithName(name); |
213 | 251 |
214 RawPacket packet = app.Build(); | 252 rtc::scoped_ptr<RawPacket> packet(app.Build()); |
215 RtcpPacketParser parser; | 253 RtcpPacketParser parser; |
216 parser.Parse(packet.buffer(), packet.buffer_length()); | 254 parser.Parse(packet->Buffer(), packet->Length()); |
217 EXPECT_EQ(1, parser.app()->num_packets()); | 255 EXPECT_EQ(1, parser.app()->num_packets()); |
218 EXPECT_EQ(30U, parser.app()->SubType()); | 256 EXPECT_EQ(30U, parser.app()->SubType()); |
219 EXPECT_EQ(name, parser.app()->Name()); | 257 EXPECT_EQ(name, parser.app()->Name()); |
220 EXPECT_EQ(0, parser.app_item()->num_packets()); | 258 EXPECT_EQ(0, parser.app_item()->num_packets()); |
221 } | 259 } |
222 | 260 |
223 TEST(RtcpPacketTest, App) { | 261 TEST(RtcpPacketTest, App) { |
224 App app; | 262 App app; |
225 app.From(kSenderSsrc); | 263 app.From(kSenderSsrc); |
226 app.WithSubType(30); | 264 app.WithSubType(30); |
227 uint32_t name = 'n' << 24; | 265 uint32_t name = 'n' << 24; |
228 name += 'a' << 16; | 266 name += 'a' << 16; |
229 name += 'm' << 8; | 267 name += 'm' << 8; |
230 name += 'e'; | 268 name += 'e'; |
231 app.WithName(name); | 269 app.WithName(name); |
232 const char kData[] = {'t', 'e', 's', 't', 'd', 'a', 't', 'a'}; | 270 const char kData[] = {'t', 'e', 's', 't', 'd', 'a', 't', 'a'}; |
233 const size_t kDataLength = sizeof(kData) / sizeof(kData[0]); | 271 const size_t kDataLength = sizeof(kData) / sizeof(kData[0]); |
234 app.WithData((const uint8_t*)kData, kDataLength); | 272 app.WithData((const uint8_t*)kData, kDataLength); |
235 | 273 |
236 RawPacket packet = app.Build(); | 274 rtc::scoped_ptr<RawPacket> packet(app.Build()); |
237 RtcpPacketParser parser; | 275 RtcpPacketParser parser; |
238 parser.Parse(packet.buffer(), packet.buffer_length()); | 276 parser.Parse(packet->Buffer(), packet->Length()); |
239 EXPECT_EQ(1, parser.app()->num_packets()); | 277 EXPECT_EQ(1, parser.app()->num_packets()); |
240 EXPECT_EQ(30U, parser.app()->SubType()); | 278 EXPECT_EQ(30U, parser.app()->SubType()); |
241 EXPECT_EQ(name, parser.app()->Name()); | 279 EXPECT_EQ(name, parser.app()->Name()); |
242 EXPECT_EQ(1, parser.app_item()->num_packets()); | 280 EXPECT_EQ(1, parser.app_item()->num_packets()); |
243 EXPECT_EQ(kDataLength, parser.app_item()->DataLength()); | 281 EXPECT_EQ(kDataLength, parser.app_item()->DataLength()); |
244 EXPECT_EQ(0, strncmp(kData, (const char*)parser.app_item()->Data(), | 282 EXPECT_EQ(0, strncmp(kData, (const char*)parser.app_item()->Data(), |
245 parser.app_item()->DataLength())); | 283 parser.app_item()->DataLength())); |
246 } | 284 } |
247 | 285 |
248 TEST(RtcpPacketTest, SdesWithOneChunk) { | 286 TEST(RtcpPacketTest, SdesWithOneChunk) { |
249 Sdes sdes; | 287 Sdes sdes; |
250 sdes.WithCName(kSenderSsrc, "alice@host"); | 288 EXPECT_TRUE(sdes.WithCName(kSenderSsrc, "alice@host")); |
251 | 289 |
252 RawPacket packet = sdes.Build(); | 290 rtc::scoped_ptr<RawPacket> packet(sdes.Build()); |
253 RtcpPacketParser parser; | 291 RtcpPacketParser parser; |
254 parser.Parse(packet.buffer(), packet.buffer_length()); | 292 parser.Parse(packet->Buffer(), packet->Length()); |
255 EXPECT_EQ(1, parser.sdes()->num_packets()); | 293 EXPECT_EQ(1, parser.sdes()->num_packets()); |
256 EXPECT_EQ(1, parser.sdes_chunk()->num_packets()); | 294 EXPECT_EQ(1, parser.sdes_chunk()->num_packets()); |
257 EXPECT_EQ(kSenderSsrc, parser.sdes_chunk()->Ssrc()); | 295 EXPECT_EQ(kSenderSsrc, parser.sdes_chunk()->Ssrc()); |
258 EXPECT_EQ("alice@host", parser.sdes_chunk()->Cname()); | 296 EXPECT_EQ("alice@host", parser.sdes_chunk()->Cname()); |
259 } | 297 } |
260 | 298 |
261 TEST(RtcpPacketTest, SdesWithMultipleChunks) { | 299 TEST(RtcpPacketTest, SdesWithMultipleChunks) { |
262 Sdes sdes; | 300 Sdes sdes; |
263 sdes.WithCName(kSenderSsrc, "a"); | 301 EXPECT_TRUE(sdes.WithCName(kSenderSsrc, "a")); |
264 sdes.WithCName(kSenderSsrc + 1, "ab"); | 302 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 1, "ab")); |
265 sdes.WithCName(kSenderSsrc + 2, "abc"); | 303 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 2, "abc")); |
266 sdes.WithCName(kSenderSsrc + 3, "abcd"); | 304 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 3, "abcd")); |
267 sdes.WithCName(kSenderSsrc + 4, "abcde"); | 305 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 4, "abcde")); |
268 sdes.WithCName(kSenderSsrc + 5, "abcdef"); | 306 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 5, "abcdef")); |
269 | 307 |
270 RawPacket packet = sdes.Build(); | 308 rtc::scoped_ptr<RawPacket> packet(sdes.Build()); |
271 RtcpPacketParser parser; | 309 RtcpPacketParser parser; |
272 parser.Parse(packet.buffer(), packet.buffer_length()); | 310 parser.Parse(packet->Buffer(), packet->Length()); |
273 EXPECT_EQ(1, parser.sdes()->num_packets()); | 311 EXPECT_EQ(1, parser.sdes()->num_packets()); |
274 EXPECT_EQ(6, parser.sdes_chunk()->num_packets()); | 312 EXPECT_EQ(6, parser.sdes_chunk()->num_packets()); |
275 EXPECT_EQ(kSenderSsrc + 5, parser.sdes_chunk()->Ssrc()); | 313 EXPECT_EQ(kSenderSsrc + 5, parser.sdes_chunk()->Ssrc()); |
276 EXPECT_EQ("abcdef", parser.sdes_chunk()->Cname()); | 314 EXPECT_EQ("abcdef", parser.sdes_chunk()->Cname()); |
277 } | 315 } |
278 | 316 |
| 317 TEST(RtcpPacketTest, SdesWithTooManyChunks) { |
| 318 Sdes sdes; |
| 319 const int kMaxChunks = (1 << 5) - 1; |
| 320 for (int i = 0; i < kMaxChunks; ++i) { |
| 321 uint32_t ssrc = kSenderSsrc + i; |
| 322 std::ostringstream oss; |
| 323 oss << "cname" << i; |
| 324 EXPECT_TRUE(sdes.WithCName(ssrc, oss.str())); |
| 325 } |
| 326 EXPECT_FALSE(sdes.WithCName(kSenderSsrc + kMaxChunks, "foo")); |
| 327 } |
| 328 |
279 TEST(RtcpPacketTest, CnameItemWithEmptyString) { | 329 TEST(RtcpPacketTest, CnameItemWithEmptyString) { |
280 Sdes sdes; | 330 Sdes sdes; |
281 sdes.WithCName(kSenderSsrc, ""); | 331 EXPECT_TRUE(sdes.WithCName(kSenderSsrc, "")); |
282 | 332 |
283 RawPacket packet = sdes.Build(); | 333 rtc::scoped_ptr<RawPacket> packet(sdes.Build()); |
284 RtcpPacketParser parser; | 334 RtcpPacketParser parser; |
285 parser.Parse(packet.buffer(), packet.buffer_length()); | 335 parser.Parse(packet->Buffer(), packet->Length()); |
286 EXPECT_EQ(1, parser.sdes()->num_packets()); | 336 EXPECT_EQ(1, parser.sdes()->num_packets()); |
287 EXPECT_EQ(1, parser.sdes_chunk()->num_packets()); | 337 EXPECT_EQ(1, parser.sdes_chunk()->num_packets()); |
288 EXPECT_EQ(kSenderSsrc, parser.sdes_chunk()->Ssrc()); | 338 EXPECT_EQ(kSenderSsrc, parser.sdes_chunk()->Ssrc()); |
289 EXPECT_EQ("", parser.sdes_chunk()->Cname()); | 339 EXPECT_EQ("", parser.sdes_chunk()->Cname()); |
290 } | 340 } |
291 | 341 |
292 TEST(RtcpPacketTest, Pli) { | 342 TEST(RtcpPacketTest, Pli) { |
293 Pli pli; | 343 Pli pli; |
294 pli.From(kSenderSsrc); | 344 pli.From(kSenderSsrc); |
295 pli.To(kRemoteSsrc); | 345 pli.To(kRemoteSsrc); |
296 | 346 |
297 RawPacket packet = pli.Build(); | 347 rtc::scoped_ptr<RawPacket> packet(pli.Build()); |
298 RtcpPacketParser parser; | 348 RtcpPacketParser parser; |
299 parser.Parse(packet.buffer(), packet.buffer_length()); | 349 parser.Parse(packet->Buffer(), packet->Length()); |
300 EXPECT_EQ(1, parser.pli()->num_packets()); | 350 EXPECT_EQ(1, parser.pli()->num_packets()); |
301 EXPECT_EQ(kSenderSsrc, parser.pli()->Ssrc()); | 351 EXPECT_EQ(kSenderSsrc, parser.pli()->Ssrc()); |
302 EXPECT_EQ(kRemoteSsrc, parser.pli()->MediaSsrc()); | 352 EXPECT_EQ(kRemoteSsrc, parser.pli()->MediaSsrc()); |
303 } | 353 } |
304 | 354 |
305 TEST(RtcpPacketTest, Sli) { | 355 TEST(RtcpPacketTest, Sli) { |
306 const uint16_t kFirstMb = 7777; | 356 const uint16_t kFirstMb = 7777; |
307 const uint16_t kNumberOfMb = 6666; | 357 const uint16_t kNumberOfMb = 6666; |
308 const uint8_t kPictureId = 60; | 358 const uint8_t kPictureId = 60; |
309 Sli sli; | 359 Sli sli; |
310 sli.From(kSenderSsrc); | 360 sli.From(kSenderSsrc); |
311 sli.To(kRemoteSsrc); | 361 sli.To(kRemoteSsrc); |
312 sli.WithFirstMb(kFirstMb); | 362 sli.WithFirstMb(kFirstMb); |
313 sli.WithNumberOfMb(kNumberOfMb); | 363 sli.WithNumberOfMb(kNumberOfMb); |
314 sli.WithPictureId(kPictureId); | 364 sli.WithPictureId(kPictureId); |
315 | 365 |
316 RawPacket packet = sli.Build(); | 366 rtc::scoped_ptr<RawPacket> packet(sli.Build()); |
317 RtcpPacketParser parser; | 367 RtcpPacketParser parser; |
318 parser.Parse(packet.buffer(), packet.buffer_length()); | 368 parser.Parse(packet->Buffer(), packet->Length()); |
319 EXPECT_EQ(1, parser.sli()->num_packets()); | 369 EXPECT_EQ(1, parser.sli()->num_packets()); |
320 EXPECT_EQ(kSenderSsrc, parser.sli()->Ssrc()); | 370 EXPECT_EQ(kSenderSsrc, parser.sli()->Ssrc()); |
321 EXPECT_EQ(kRemoteSsrc, parser.sli()->MediaSsrc()); | 371 EXPECT_EQ(kRemoteSsrc, parser.sli()->MediaSsrc()); |
322 EXPECT_EQ(1, parser.sli_item()->num_packets()); | 372 EXPECT_EQ(1, parser.sli_item()->num_packets()); |
323 EXPECT_EQ(kFirstMb, parser.sli_item()->FirstMb()); | 373 EXPECT_EQ(kFirstMb, parser.sli_item()->FirstMb()); |
324 EXPECT_EQ(kNumberOfMb, parser.sli_item()->NumberOfMb()); | 374 EXPECT_EQ(kNumberOfMb, parser.sli_item()->NumberOfMb()); |
325 EXPECT_EQ(kPictureId, parser.sli_item()->PictureId()); | 375 EXPECT_EQ(kPictureId, parser.sli_item()->PictureId()); |
326 } | 376 } |
327 | 377 |
328 TEST(RtcpPacketTest, Nack) { | 378 TEST(RtcpPacketTest, Nack) { |
329 Nack nack; | 379 Nack nack; |
330 const uint16_t kList[] = {0, 1, 3, 8, 16}; | 380 const uint16_t kList[] = {0, 1, 3, 8, 16}; |
331 const uint16_t kListLength = sizeof(kList) / sizeof(kList[0]); | 381 const uint16_t kListLength = sizeof(kList) / sizeof(kList[0]); |
332 nack.From(kSenderSsrc); | 382 nack.From(kSenderSsrc); |
333 nack.To(kRemoteSsrc); | 383 nack.To(kRemoteSsrc); |
334 nack.WithList(kList, kListLength); | 384 nack.WithList(kList, kListLength); |
335 RawPacket packet = nack.Build(); | 385 rtc::scoped_ptr<RawPacket> packet(nack.Build()); |
336 RtcpPacketParser parser; | 386 RtcpPacketParser parser; |
337 parser.Parse(packet.buffer(), packet.buffer_length()); | 387 parser.Parse(packet->Buffer(), packet->Length()); |
338 EXPECT_EQ(1, parser.nack()->num_packets()); | 388 EXPECT_EQ(1, parser.nack()->num_packets()); |
339 EXPECT_EQ(kSenderSsrc, parser.nack()->Ssrc()); | 389 EXPECT_EQ(kSenderSsrc, parser.nack()->Ssrc()); |
340 EXPECT_EQ(kRemoteSsrc, parser.nack()->MediaSsrc()); | 390 EXPECT_EQ(kRemoteSsrc, parser.nack()->MediaSsrc()); |
341 EXPECT_EQ(1, parser.nack_item()->num_packets()); | 391 EXPECT_EQ(1, parser.nack_item()->num_packets()); |
342 std::vector<uint16_t> seqs = parser.nack_item()->last_nack_list(); | 392 std::vector<uint16_t> seqs = parser.nack_item()->last_nack_list(); |
343 EXPECT_EQ(kListLength, seqs.size()); | 393 EXPECT_EQ(kListLength, seqs.size()); |
344 for (size_t i = 0; i < kListLength; ++i) { | 394 for (size_t i = 0; i < kListLength; ++i) { |
345 EXPECT_EQ(kList[i], seqs[i]); | 395 EXPECT_EQ(kList[i], seqs[i]); |
346 } | 396 } |
347 } | 397 } |
348 | 398 |
349 TEST(RtcpPacketTest, NackWithWrap) { | 399 TEST(RtcpPacketTest, NackWithWrap) { |
350 Nack nack; | 400 Nack nack; |
351 const uint16_t kList[] = {65500, 65516, 65534, 65535, 0, 1, 3, 20, 100}; | 401 const uint16_t kList[] = {65500, 65516, 65534, 65535, 0, 1, 3, 20, 100}; |
352 const uint16_t kListLength = sizeof(kList) / sizeof(kList[0]); | 402 const uint16_t kListLength = sizeof(kList) / sizeof(kList[0]); |
353 nack.From(kSenderSsrc); | 403 nack.From(kSenderSsrc); |
354 nack.To(kRemoteSsrc); | 404 nack.To(kRemoteSsrc); |
355 nack.WithList(kList, kListLength); | 405 nack.WithList(kList, kListLength); |
356 RawPacket packet = nack.Build(); | 406 rtc::scoped_ptr<RawPacket> packet(nack.Build()); |
357 RtcpPacketParser parser; | 407 RtcpPacketParser parser; |
358 parser.Parse(packet.buffer(), packet.buffer_length()); | 408 parser.Parse(packet->Buffer(), packet->Length()); |
359 EXPECT_EQ(1, parser.nack()->num_packets()); | 409 EXPECT_EQ(1, parser.nack()->num_packets()); |
360 EXPECT_EQ(kSenderSsrc, parser.nack()->Ssrc()); | 410 EXPECT_EQ(kSenderSsrc, parser.nack()->Ssrc()); |
361 EXPECT_EQ(kRemoteSsrc, parser.nack()->MediaSsrc()); | 411 EXPECT_EQ(kRemoteSsrc, parser.nack()->MediaSsrc()); |
362 EXPECT_EQ(4, parser.nack_item()->num_packets()); | 412 EXPECT_EQ(4, parser.nack_item()->num_packets()); |
363 std::vector<uint16_t> seqs = parser.nack_item()->last_nack_list(); | 413 std::vector<uint16_t> seqs = parser.nack_item()->last_nack_list(); |
364 EXPECT_EQ(kListLength, seqs.size()); | 414 EXPECT_EQ(kListLength, seqs.size()); |
365 for (size_t i = 0; i < kListLength; ++i) { | 415 for (size_t i = 0; i < kListLength; ++i) { |
366 EXPECT_EQ(kList[i], seqs[i]); | 416 EXPECT_EQ(kList[i], seqs[i]); |
367 } | 417 } |
368 } | 418 } |
369 | 419 |
| 420 TEST(RtcpPacketTest, NackFragmented) { |
| 421 Nack nack; |
| 422 const uint16_t kList[] = {1, 100, 200, 300, 400}; |
| 423 const uint16_t kListLength = sizeof(kList) / sizeof(kList[0]); |
| 424 nack.From(kSenderSsrc); |
| 425 nack.To(kRemoteSsrc); |
| 426 nack.WithList(kList, kListLength); |
| 427 |
| 428 class Verifier : public rtcp::RtcpPacket::PacketReadyCallback { |
| 429 public: |
| 430 void OnPacketReady(uint8_t* data, size_t length) override { |
| 431 ++packets_created_; |
| 432 RtcpPacketParser parser; |
| 433 parser.Parse(data, length); |
| 434 EXPECT_EQ(1, parser.nack()->num_packets()); |
| 435 EXPECT_EQ(kSenderSsrc, parser.nack()->Ssrc()); |
| 436 EXPECT_EQ(kRemoteSsrc, parser.nack()->MediaSsrc()); |
| 437 switch (packets_created_) { |
| 438 case 1: |
| 439 EXPECT_THAT(parser.nack_item()->last_nack_list(), |
| 440 ElementsAre(1, 100, 200)); |
| 441 break; |
| 442 case 2: |
| 443 EXPECT_THAT(parser.nack_item()->last_nack_list(), |
| 444 ElementsAre(300, 400)); |
| 445 break; |
| 446 default: |
| 447 ADD_FAILURE() << "Unexpected packet count: " << packets_created_; |
| 448 } |
| 449 } |
| 450 int packets_created_ = 0; |
| 451 } verifier; |
| 452 const size_t kBufferSize = 12 + (3 * 4); // Fits common header + 3 nack items |
| 453 uint8_t buffer[kBufferSize]; |
| 454 EXPECT_TRUE(nack.BuildExternalBuffer(buffer, kBufferSize, &verifier)); |
| 455 EXPECT_EQ(2, verifier.packets_created_); |
| 456 } |
| 457 |
| 458 TEST(RtcpPacketTest, NackWithTooSmallBuffer) { |
| 459 const uint16_t kList[] = {1}; |
| 460 const size_t kMinNackBlockSize = 16; |
| 461 Nack nack; |
| 462 nack.From(kSenderSsrc); |
| 463 nack.To(kRemoteSsrc); |
| 464 nack.WithList(kList, 1); |
| 465 class Verifier : public rtcp::RtcpPacket::PacketReadyCallback { |
| 466 public: |
| 467 void OnPacketReady(uint8_t* data, size_t length) override { |
| 468 ADD_FAILURE() << "Buffer should be too small."; |
| 469 } |
| 470 } verifier; |
| 471 uint8_t buffer[kMinNackBlockSize - 1]; |
| 472 EXPECT_FALSE( |
| 473 nack.BuildExternalBuffer(buffer, kMinNackBlockSize - 1, &verifier)); |
| 474 } |
| 475 |
370 TEST(RtcpPacketTest, Rpsi) { | 476 TEST(RtcpPacketTest, Rpsi) { |
371 Rpsi rpsi; | 477 Rpsi rpsi; |
372 // 1000001 (7 bits = 1 byte in native string). | 478 // 1000001 (7 bits = 1 byte in native string). |
373 const uint64_t kPictureId = 0x41; | 479 const uint64_t kPictureId = 0x41; |
374 const uint16_t kNumberOfValidBytes = 1; | 480 const uint16_t kNumberOfValidBytes = 1; |
375 rpsi.WithPayloadType(100); | 481 rpsi.WithPayloadType(100); |
376 rpsi.WithPictureId(kPictureId); | 482 rpsi.WithPictureId(kPictureId); |
377 | 483 |
378 RawPacket packet = rpsi.Build(); | 484 rtc::scoped_ptr<RawPacket> packet(rpsi.Build()); |
379 RtcpPacketParser parser; | 485 RtcpPacketParser parser; |
380 parser.Parse(packet.buffer(), packet.buffer_length()); | 486 parser.Parse(packet->Buffer(), packet->Length()); |
381 EXPECT_EQ(100, parser.rpsi()->PayloadType()); | 487 EXPECT_EQ(100, parser.rpsi()->PayloadType()); |
382 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); | 488 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); |
383 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); | 489 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); |
384 } | 490 } |
385 | 491 |
386 TEST(RtcpPacketTest, RpsiWithTwoByteNativeString) { | 492 TEST(RtcpPacketTest, RpsiWithTwoByteNativeString) { |
387 Rpsi rpsi; | 493 Rpsi rpsi; |
388 // |1 0000001 (7 bits = 1 byte in native string). | 494 // |1 0000001 (7 bits = 1 byte in native string). |
389 const uint64_t kPictureId = 0x81; | 495 const uint64_t kPictureId = 0x81; |
390 const uint16_t kNumberOfValidBytes = 2; | 496 const uint16_t kNumberOfValidBytes = 2; |
391 rpsi.WithPictureId(kPictureId); | 497 rpsi.WithPictureId(kPictureId); |
392 | 498 |
393 RawPacket packet = rpsi.Build(); | 499 rtc::scoped_ptr<RawPacket> packet(rpsi.Build()); |
394 RtcpPacketParser parser; | 500 RtcpPacketParser parser; |
395 parser.Parse(packet.buffer(), packet.buffer_length()); | 501 parser.Parse(packet->Buffer(), packet->Length()); |
396 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); | 502 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); |
397 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); | 503 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); |
398 } | 504 } |
399 | 505 |
400 TEST(RtcpPacketTest, RpsiWithThreeByteNativeString) { | 506 TEST(RtcpPacketTest, RpsiWithThreeByteNativeString) { |
401 Rpsi rpsi; | 507 Rpsi rpsi; |
402 // 10000|00 100000|0 1000000 (7 bits = 1 byte in native string). | 508 // 10000|00 100000|0 1000000 (7 bits = 1 byte in native string). |
403 const uint64_t kPictureId = 0x102040; | 509 const uint64_t kPictureId = 0x102040; |
404 const uint16_t kNumberOfValidBytes = 3; | 510 const uint16_t kNumberOfValidBytes = 3; |
405 rpsi.WithPictureId(kPictureId); | 511 rpsi.WithPictureId(kPictureId); |
406 | 512 |
407 RawPacket packet = rpsi.Build(); | 513 rtc::scoped_ptr<RawPacket> packet(rpsi.Build()); |
408 RtcpPacketParser parser; | 514 RtcpPacketParser parser; |
409 parser.Parse(packet.buffer(), packet.buffer_length()); | 515 parser.Parse(packet->Buffer(), packet->Length()); |
410 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); | 516 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); |
411 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); | 517 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); |
412 } | 518 } |
413 | 519 |
414 TEST(RtcpPacketTest, RpsiWithFourByteNativeString) { | 520 TEST(RtcpPacketTest, RpsiWithFourByteNativeString) { |
415 Rpsi rpsi; | 521 Rpsi rpsi; |
416 // 1000|001 00001|01 100001|1 1000010 (7 bits = 1 byte in native string). | 522 // 1000|001 00001|01 100001|1 1000010 (7 bits = 1 byte in native string). |
417 const uint64_t kPictureId = 0x84161C2; | 523 const uint64_t kPictureId = 0x84161C2; |
418 const uint16_t kNumberOfValidBytes = 4; | 524 const uint16_t kNumberOfValidBytes = 4; |
419 rpsi.WithPictureId(kPictureId); | 525 rpsi.WithPictureId(kPictureId); |
420 | 526 |
421 RawPacket packet = rpsi.Build(); | 527 rtc::scoped_ptr<RawPacket> packet(rpsi.Build()); |
422 RtcpPacketParser parser; | 528 RtcpPacketParser parser; |
423 parser.Parse(packet.buffer(), packet.buffer_length()); | 529 parser.Parse(packet->Buffer(), packet->Length()); |
424 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); | 530 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); |
425 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); | 531 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); |
426 } | 532 } |
427 | 533 |
428 TEST(RtcpPacketTest, RpsiWithMaxPictureId) { | 534 TEST(RtcpPacketTest, RpsiWithMaxPictureId) { |
429 Rpsi rpsi; | 535 Rpsi rpsi; |
430 // 1 1111111| 1111111 1|111111 11|11111 111|1111 1111|111 11111| | 536 // 1 1111111| 1111111 1|111111 11|11111 111|1111 1111|111 11111| |
431 // 11 111111|1 1111111 (7 bits = 1 byte in native string). | 537 // 11 111111|1 1111111 (7 bits = 1 byte in native string). |
432 const uint64_t kPictureId = 0xffffffffffffffff; | 538 const uint64_t kPictureId = 0xffffffffffffffff; |
433 const uint16_t kNumberOfValidBytes = 10; | 539 const uint16_t kNumberOfValidBytes = 10; |
434 rpsi.WithPictureId(kPictureId); | 540 rpsi.WithPictureId(kPictureId); |
435 | 541 |
436 RawPacket packet = rpsi.Build(); | 542 rtc::scoped_ptr<RawPacket> packet(rpsi.Build()); |
437 RtcpPacketParser parser; | 543 RtcpPacketParser parser; |
438 parser.Parse(packet.buffer(), packet.buffer_length()); | 544 parser.Parse(packet->Buffer(), packet->Length()); |
439 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); | 545 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); |
440 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); | 546 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); |
441 } | 547 } |
442 | 548 |
443 TEST(RtcpPacketTest, Fir) { | 549 TEST(RtcpPacketTest, Fir) { |
444 Fir fir; | 550 Fir fir; |
445 fir.From(kSenderSsrc); | 551 fir.From(kSenderSsrc); |
446 fir.To(kRemoteSsrc); | 552 fir.To(kRemoteSsrc); |
447 fir.WithCommandSeqNum(123); | 553 fir.WithCommandSeqNum(123); |
448 | 554 |
449 RawPacket packet = fir.Build(); | 555 rtc::scoped_ptr<RawPacket> packet(fir.Build()); |
450 RtcpPacketParser parser; | 556 RtcpPacketParser parser; |
451 parser.Parse(packet.buffer(), packet.buffer_length()); | 557 parser.Parse(packet->Buffer(), packet->Length()); |
452 EXPECT_EQ(1, parser.fir()->num_packets()); | 558 EXPECT_EQ(1, parser.fir()->num_packets()); |
453 EXPECT_EQ(kSenderSsrc, parser.fir()->Ssrc()); | 559 EXPECT_EQ(kSenderSsrc, parser.fir()->Ssrc()); |
454 EXPECT_EQ(1, parser.fir_item()->num_packets()); | 560 EXPECT_EQ(1, parser.fir_item()->num_packets()); |
455 EXPECT_EQ(kRemoteSsrc, parser.fir_item()->Ssrc()); | 561 EXPECT_EQ(kRemoteSsrc, parser.fir_item()->Ssrc()); |
456 EXPECT_EQ(123U, parser.fir_item()->SeqNum()); | 562 EXPECT_EQ(123U, parser.fir_item()->SeqNum()); |
457 } | 563 } |
458 | 564 |
459 TEST(RtcpPacketTest, AppendPacket) { | 565 TEST(RtcpPacketTest, AppendPacket) { |
460 Fir fir; | 566 Fir fir; |
461 ReportBlock rb; | 567 ReportBlock rb; |
462 ReceiverReport rr; | 568 ReceiverReport rr; |
463 rr.From(kSenderSsrc); | 569 rr.From(kSenderSsrc); |
464 rr.WithReportBlock(&rb); | 570 EXPECT_TRUE(rr.WithReportBlock(&rb)); |
465 rr.Append(&fir); | 571 rr.Append(&fir); |
466 | 572 |
467 RawPacket packet = rr.Build(); | 573 rtc::scoped_ptr<RawPacket> packet(rr.Build()); |
468 RtcpPacketParser parser; | 574 RtcpPacketParser parser; |
469 parser.Parse(packet.buffer(), packet.buffer_length()); | 575 parser.Parse(packet->Buffer(), packet->Length()); |
470 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | 576 EXPECT_EQ(1, parser.receiver_report()->num_packets()); |
471 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); | 577 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); |
472 EXPECT_EQ(1, parser.report_block()->num_packets()); | 578 EXPECT_EQ(1, parser.report_block()->num_packets()); |
473 EXPECT_EQ(1, parser.fir()->num_packets()); | 579 EXPECT_EQ(1, parser.fir()->num_packets()); |
474 } | 580 } |
475 | 581 |
476 TEST(RtcpPacketTest, AppendPacketOnEmpty) { | 582 TEST(RtcpPacketTest, AppendPacketOnEmpty) { |
477 Empty empty; | 583 Empty empty; |
478 ReceiverReport rr; | 584 ReceiverReport rr; |
479 rr.From(kSenderSsrc); | 585 rr.From(kSenderSsrc); |
480 empty.Append(&rr); | 586 empty.Append(&rr); |
481 | 587 |
482 RawPacket packet = empty.Build(); | 588 rtc::scoped_ptr<RawPacket> packet(empty.Build()); |
483 RtcpPacketParser parser; | 589 RtcpPacketParser parser; |
484 parser.Parse(packet.buffer(), packet.buffer_length()); | 590 parser.Parse(packet->Buffer(), packet->Length()); |
485 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | 591 EXPECT_EQ(1, parser.receiver_report()->num_packets()); |
486 EXPECT_EQ(0, parser.report_block()->num_packets()); | 592 EXPECT_EQ(0, parser.report_block()->num_packets()); |
487 } | 593 } |
488 | 594 |
489 TEST(RtcpPacketTest, AppendPacketWithOwnAppendedPacket) { | 595 TEST(RtcpPacketTest, AppendPacketWithOwnAppendedPacket) { |
490 Fir fir; | 596 Fir fir; |
491 Bye bye; | 597 Bye bye; |
492 ReportBlock rb; | 598 ReportBlock rb; |
493 | 599 |
494 ReceiverReport rr; | 600 ReceiverReport rr; |
495 rr.WithReportBlock(&rb); | 601 EXPECT_TRUE(rr.WithReportBlock(&rb)); |
496 rr.Append(&fir); | 602 rr.Append(&fir); |
497 | 603 |
498 SenderReport sr; | 604 SenderReport sr; |
499 sr.Append(&bye); | 605 sr.Append(&bye); |
500 sr.Append(&rr); | 606 sr.Append(&rr); |
501 | 607 |
502 RawPacket packet = sr.Build(); | 608 rtc::scoped_ptr<RawPacket> packet(sr.Build()); |
503 RtcpPacketParser parser; | 609 RtcpPacketParser parser; |
504 parser.Parse(packet.buffer(), packet.buffer_length()); | 610 parser.Parse(packet->Buffer(), packet->Length()); |
505 EXPECT_EQ(1, parser.sender_report()->num_packets()); | 611 EXPECT_EQ(1, parser.sender_report()->num_packets()); |
506 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | 612 EXPECT_EQ(1, parser.receiver_report()->num_packets()); |
507 EXPECT_EQ(1, parser.report_block()->num_packets()); | 613 EXPECT_EQ(1, parser.report_block()->num_packets()); |
508 EXPECT_EQ(1, parser.bye()->num_packets()); | 614 EXPECT_EQ(1, parser.bye()->num_packets()); |
509 EXPECT_EQ(1, parser.fir()->num_packets()); | 615 EXPECT_EQ(1, parser.fir()->num_packets()); |
510 } | 616 } |
511 | 617 |
512 TEST(RtcpPacketTest, Bye) { | 618 TEST(RtcpPacketTest, Bye) { |
513 Bye bye; | 619 Bye bye; |
514 bye.From(kSenderSsrc); | 620 bye.From(kSenderSsrc); |
515 | 621 |
516 RawPacket packet = bye.Build(); | 622 rtc::scoped_ptr<RawPacket> packet(bye.Build()); |
517 RtcpPacketParser parser; | 623 RtcpPacketParser parser; |
518 parser.Parse(packet.buffer(), packet.buffer_length()); | 624 parser.Parse(packet->Buffer(), packet->Length()); |
519 EXPECT_EQ(1, parser.bye()->num_packets()); | 625 EXPECT_EQ(1, parser.bye()->num_packets()); |
520 EXPECT_EQ(kSenderSsrc, parser.bye()->Ssrc()); | 626 EXPECT_EQ(kSenderSsrc, parser.bye()->Ssrc()); |
521 } | 627 } |
522 | 628 |
523 TEST(RtcpPacketTest, ByeWithCsrcs) { | 629 TEST(RtcpPacketTest, ByeWithCsrcs) { |
524 Fir fir; | 630 Fir fir; |
525 Bye bye; | 631 Bye bye; |
526 bye.From(kSenderSsrc); | 632 bye.From(kSenderSsrc); |
527 bye.WithCsrc(0x22222222); | 633 EXPECT_TRUE(bye.WithCsrc(0x22222222)); |
528 bye.WithCsrc(0x33333333); | 634 EXPECT_TRUE(bye.WithCsrc(0x33333333)); |
529 bye.Append(&fir); | 635 bye.Append(&fir); |
530 | 636 |
531 RawPacket packet = bye.Build(); | 637 rtc::scoped_ptr<RawPacket> packet(bye.Build()); |
532 RtcpPacketParser parser; | 638 RtcpPacketParser parser; |
533 parser.Parse(packet.buffer(), packet.buffer_length()); | 639 parser.Parse(packet->Buffer(), packet->Length()); |
534 EXPECT_EQ(1, parser.bye()->num_packets()); | 640 EXPECT_EQ(1, parser.bye()->num_packets()); |
535 EXPECT_EQ(kSenderSsrc, parser.bye()->Ssrc()); | 641 EXPECT_EQ(kSenderSsrc, parser.bye()->Ssrc()); |
536 EXPECT_EQ(1, parser.fir()->num_packets()); | 642 EXPECT_EQ(1, parser.fir()->num_packets()); |
537 } | 643 } |
538 | 644 |
| 645 TEST(RtcpPacketTest, ByeWithTooManyCsrcs) { |
| 646 Bye bye; |
| 647 bye.From(kSenderSsrc); |
| 648 const int kMaxCsrcs = (1 << 5) - 2; // 5 bit len, first item is sender SSRC. |
| 649 for (int i = 0; i < kMaxCsrcs; ++i) { |
| 650 EXPECT_TRUE(bye.WithCsrc(i)); |
| 651 } |
| 652 EXPECT_FALSE(bye.WithCsrc(kMaxCsrcs)); |
| 653 } |
| 654 |
539 TEST(RtcpPacketTest, BuildWithInputBuffer) { | 655 TEST(RtcpPacketTest, BuildWithInputBuffer) { |
540 Fir fir; | 656 Fir fir; |
541 ReportBlock rb; | 657 ReportBlock rb; |
542 ReceiverReport rr; | 658 ReceiverReport rr; |
543 rr.From(kSenderSsrc); | 659 rr.From(kSenderSsrc); |
544 rr.WithReportBlock(&rb); | 660 EXPECT_TRUE(rr.WithReportBlock(&rb)); |
545 rr.Append(&fir); | 661 rr.Append(&fir); |
546 | 662 |
547 const size_t kRrLength = 8; | 663 const size_t kRrLength = 8; |
548 const size_t kReportBlockLength = 24; | 664 const size_t kReportBlockLength = 24; |
549 const size_t kFirLength = 20; | 665 const size_t kFirLength = 20; |
550 | 666 |
551 size_t len = 0; | 667 class Verifier : public rtcp::RtcpPacket::PacketReadyCallback { |
552 uint8_t packet[kRrLength + kReportBlockLength + kFirLength]; | 668 public: |
553 rr.Build(packet, &len, kRrLength + kReportBlockLength + kFirLength); | 669 void OnPacketReady(uint8_t* data, size_t length) override { |
| 670 RtcpPacketParser parser; |
| 671 parser.Parse(data, length); |
| 672 EXPECT_EQ(1, parser.receiver_report()->num_packets()); |
| 673 EXPECT_EQ(1, parser.report_block()->num_packets()); |
| 674 EXPECT_EQ(1, parser.fir()->num_packets()); |
| 675 ++packets_created_; |
| 676 } |
554 | 677 |
555 RtcpPacketParser parser; | 678 int packets_created_ = 0; |
556 parser.Parse(packet, len); | 679 } verifier; |
557 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | 680 const size_t kBufferSize = kRrLength + kReportBlockLength + kFirLength; |
558 EXPECT_EQ(1, parser.report_block()->num_packets()); | 681 uint8_t buffer[kBufferSize]; |
559 EXPECT_EQ(1, parser.fir()->num_packets()); | 682 EXPECT_TRUE(rr.BuildExternalBuffer(buffer, kBufferSize, &verifier)); |
| 683 EXPECT_EQ(1, verifier.packets_created_); |
560 } | 684 } |
561 | 685 |
562 TEST(RtcpPacketTest, BuildWithTooSmallBuffer) { | 686 TEST(RtcpPacketTest, BuildWithTooSmallBuffer) { |
563 ReportBlock rb; | 687 ReportBlock rb; |
564 ReceiverReport rr; | 688 ReceiverReport rr; |
565 rr.From(kSenderSsrc); | 689 rr.From(kSenderSsrc); |
566 rr.WithReportBlock(&rb); | 690 EXPECT_TRUE(rr.WithReportBlock(&rb)); |
567 | 691 |
568 const size_t kRrLength = 8; | 692 const size_t kRrLength = 8; |
569 const size_t kReportBlockLength = 24; | 693 const size_t kReportBlockLength = 24; |
570 | 694 |
571 // No packet. | 695 // No packet. |
572 size_t len = 0; | 696 class Verifier : public rtcp::RtcpPacket::PacketReadyCallback { |
573 uint8_t packet[kRrLength + kReportBlockLength - 1]; | 697 void OnPacketReady(uint8_t* data, size_t length) override { |
574 rr.Build(packet, &len, kRrLength + kReportBlockLength - 1); | 698 ADD_FAILURE() << "Packet should not fit within max size."; |
575 EXPECT_EQ(0U, len); | 699 } |
| 700 } verifier; |
| 701 const size_t kBufferSize = kRrLength + kReportBlockLength - 1; |
| 702 uint8_t buffer[kBufferSize]; |
| 703 EXPECT_FALSE(rr.BuildExternalBuffer(buffer, kBufferSize, &verifier)); |
576 } | 704 } |
577 | 705 |
578 TEST(RtcpPacketTest, BuildWithTooSmallBuffer_LastBlockFits) { | 706 TEST(RtcpPacketTest, BuildWithTooSmallBuffer_FragmentedSend) { |
579 Fir fir; | 707 Fir fir; |
580 ReportBlock rb; | 708 ReportBlock rb; |
581 ReceiverReport rr; | 709 ReceiverReport rr; |
582 rr.From(kSenderSsrc); | 710 rr.From(kSenderSsrc); |
583 rr.WithReportBlock(&rb); | 711 EXPECT_TRUE(rr.WithReportBlock(&rb)); |
584 rr.Append(&fir); | 712 rr.Append(&fir); |
585 | 713 |
586 const size_t kRrLength = 8; | 714 const size_t kRrLength = 8; |
587 const size_t kReportBlockLength = 24; | 715 const size_t kReportBlockLength = 24; |
588 | 716 |
589 size_t len = 0; | 717 class Verifier : public rtcp::RtcpPacket::PacketReadyCallback { |
590 uint8_t packet[kRrLength + kReportBlockLength - 1]; | 718 public: |
591 rr.Build(packet, &len, kRrLength + kReportBlockLength - 1); | 719 void OnPacketReady(uint8_t* data, size_t length) override { |
592 RtcpPacketParser parser; | 720 RtcpPacketParser parser; |
593 parser.Parse(packet, len); | 721 parser.Parse(data, length); |
594 EXPECT_EQ(0, parser.receiver_report()->num_packets()); | 722 switch (packets_created_++) { |
595 EXPECT_EQ(0, parser.report_block()->num_packets()); | 723 case 0: |
596 EXPECT_EQ(1, parser.fir()->num_packets()); | 724 EXPECT_EQ(1, parser.receiver_report()->num_packets()); |
| 725 EXPECT_EQ(1, parser.report_block()->num_packets()); |
| 726 EXPECT_EQ(0, parser.fir()->num_packets()); |
| 727 break; |
| 728 case 1: |
| 729 EXPECT_EQ(0, parser.receiver_report()->num_packets()); |
| 730 EXPECT_EQ(0, parser.report_block()->num_packets()); |
| 731 EXPECT_EQ(1, parser.fir()->num_packets()); |
| 732 break; |
| 733 default: |
| 734 ADD_FAILURE() << "OnPacketReady not expected to be called " |
| 735 << packets_created_ << " times."; |
| 736 } |
| 737 } |
| 738 |
| 739 int packets_created_ = 0; |
| 740 } verifier; |
| 741 const size_t kBufferSize = kRrLength + kReportBlockLength; |
| 742 uint8_t buffer[kBufferSize]; |
| 743 EXPECT_TRUE(rr.BuildExternalBuffer(buffer, kBufferSize, &verifier)); |
| 744 EXPECT_EQ(2, verifier.packets_created_); |
597 } | 745 } |
598 | 746 |
599 TEST(RtcpPacketTest, Remb) { | 747 TEST(RtcpPacketTest, Remb) { |
600 Remb remb; | 748 Remb remb; |
601 remb.From(kSenderSsrc); | 749 remb.From(kSenderSsrc); |
602 remb.AppliesTo(kRemoteSsrc); | 750 remb.AppliesTo(kRemoteSsrc); |
603 remb.AppliesTo(kRemoteSsrc + 1); | 751 remb.AppliesTo(kRemoteSsrc + 1); |
604 remb.AppliesTo(kRemoteSsrc + 2); | 752 remb.AppliesTo(kRemoteSsrc + 2); |
605 remb.WithBitrateBps(261011); | 753 remb.WithBitrateBps(261011); |
606 | 754 |
607 RawPacket packet = remb.Build(); | 755 rtc::scoped_ptr<RawPacket> packet(remb.Build()); |
608 RtcpPacketParser parser; | 756 RtcpPacketParser parser; |
609 parser.Parse(packet.buffer(), packet.buffer_length()); | 757 parser.Parse(packet->Buffer(), packet->Length()); |
610 EXPECT_EQ(1, parser.psfb_app()->num_packets()); | 758 EXPECT_EQ(1, parser.psfb_app()->num_packets()); |
611 EXPECT_EQ(kSenderSsrc, parser.psfb_app()->Ssrc()); | 759 EXPECT_EQ(kSenderSsrc, parser.psfb_app()->Ssrc()); |
612 EXPECT_EQ(1, parser.remb_item()->num_packets()); | 760 EXPECT_EQ(1, parser.remb_item()->num_packets()); |
613 EXPECT_EQ(261011, parser.remb_item()->last_bitrate_bps()); | 761 EXPECT_EQ(261011, parser.remb_item()->last_bitrate_bps()); |
614 std::vector<uint32_t> ssrcs = parser.remb_item()->last_ssrc_list(); | 762 std::vector<uint32_t> ssrcs = parser.remb_item()->last_ssrc_list(); |
615 EXPECT_EQ(kRemoteSsrc, ssrcs[0]); | 763 EXPECT_EQ(kRemoteSsrc, ssrcs[0]); |
616 EXPECT_EQ(kRemoteSsrc + 1, ssrcs[1]); | 764 EXPECT_EQ(kRemoteSsrc + 1, ssrcs[1]); |
617 EXPECT_EQ(kRemoteSsrc + 2, ssrcs[2]); | 765 EXPECT_EQ(kRemoteSsrc + 2, ssrcs[2]); |
618 } | 766 } |
619 | 767 |
620 TEST(RtcpPacketTest, Tmmbr) { | 768 TEST(RtcpPacketTest, Tmmbr) { |
621 Tmmbr tmmbr; | 769 Tmmbr tmmbr; |
622 tmmbr.From(kSenderSsrc); | 770 tmmbr.From(kSenderSsrc); |
623 tmmbr.To(kRemoteSsrc); | 771 tmmbr.To(kRemoteSsrc); |
624 tmmbr.WithBitrateKbps(312); | 772 tmmbr.WithBitrateKbps(312); |
625 tmmbr.WithOverhead(60); | 773 tmmbr.WithOverhead(60); |
626 | 774 |
627 RawPacket packet = tmmbr.Build(); | 775 rtc::scoped_ptr<RawPacket> packet(tmmbr.Build()); |
628 RtcpPacketParser parser; | 776 RtcpPacketParser parser; |
629 parser.Parse(packet.buffer(), packet.buffer_length()); | 777 parser.Parse(packet->Buffer(), packet->Length()); |
630 EXPECT_EQ(1, parser.tmmbr()->num_packets()); | 778 EXPECT_EQ(1, parser.tmmbr()->num_packets()); |
631 EXPECT_EQ(kSenderSsrc, parser.tmmbr()->Ssrc()); | 779 EXPECT_EQ(kSenderSsrc, parser.tmmbr()->Ssrc()); |
632 EXPECT_EQ(1, parser.tmmbr_item()->num_packets()); | 780 EXPECT_EQ(1, parser.tmmbr_item()->num_packets()); |
633 EXPECT_EQ(312U, parser.tmmbr_item()->BitrateKbps()); | 781 EXPECT_EQ(312U, parser.tmmbr_item()->BitrateKbps()); |
634 EXPECT_EQ(60U, parser.tmmbr_item()->Overhead()); | 782 EXPECT_EQ(60U, parser.tmmbr_item()->Overhead()); |
635 } | 783 } |
636 | 784 |
637 TEST(RtcpPacketTest, TmmbnWithNoItem) { | 785 TEST(RtcpPacketTest, TmmbnWithNoItem) { |
638 Tmmbn tmmbn; | 786 Tmmbn tmmbn; |
639 tmmbn.From(kSenderSsrc); | 787 tmmbn.From(kSenderSsrc); |
640 | 788 |
641 RawPacket packet = tmmbn.Build(); | 789 rtc::scoped_ptr<RawPacket> packet(tmmbn.Build()); |
642 RtcpPacketParser parser; | 790 RtcpPacketParser parser; |
643 parser.Parse(packet.buffer(), packet.buffer_length()); | 791 parser.Parse(packet->Buffer(), packet->Length()); |
644 EXPECT_EQ(1, parser.tmmbn()->num_packets()); | 792 EXPECT_EQ(1, parser.tmmbn()->num_packets()); |
645 EXPECT_EQ(kSenderSsrc, parser.tmmbn()->Ssrc()); | 793 EXPECT_EQ(kSenderSsrc, parser.tmmbn()->Ssrc()); |
646 EXPECT_EQ(0, parser.tmmbn_items()->num_packets()); | 794 EXPECT_EQ(0, parser.tmmbn_items()->num_packets()); |
647 } | 795 } |
648 | 796 |
649 TEST(RtcpPacketTest, TmmbnWithOneItem) { | 797 TEST(RtcpPacketTest, TmmbnWithOneItem) { |
650 Tmmbn tmmbn; | 798 Tmmbn tmmbn; |
651 tmmbn.From(kSenderSsrc); | 799 tmmbn.From(kSenderSsrc); |
652 tmmbn.WithTmmbr(kRemoteSsrc, 312, 60); | 800 EXPECT_TRUE(tmmbn.WithTmmbr(kRemoteSsrc, 312, 60)); |
653 | 801 |
654 RawPacket packet = tmmbn.Build(); | 802 rtc::scoped_ptr<RawPacket> packet(tmmbn.Build()); |
655 RtcpPacketParser parser; | 803 RtcpPacketParser parser; |
656 parser.Parse(packet.buffer(), packet.buffer_length()); | 804 parser.Parse(packet->Buffer(), packet->Length()); |
657 EXPECT_EQ(1, parser.tmmbn()->num_packets()); | 805 EXPECT_EQ(1, parser.tmmbn()->num_packets()); |
658 EXPECT_EQ(kSenderSsrc, parser.tmmbn()->Ssrc()); | 806 EXPECT_EQ(kSenderSsrc, parser.tmmbn()->Ssrc()); |
659 EXPECT_EQ(1, parser.tmmbn_items()->num_packets()); | 807 EXPECT_EQ(1, parser.tmmbn_items()->num_packets()); |
660 EXPECT_EQ(kRemoteSsrc, parser.tmmbn_items()->Ssrc(0)); | 808 EXPECT_EQ(kRemoteSsrc, parser.tmmbn_items()->Ssrc(0)); |
661 EXPECT_EQ(312U, parser.tmmbn_items()->BitrateKbps(0)); | 809 EXPECT_EQ(312U, parser.tmmbn_items()->BitrateKbps(0)); |
662 EXPECT_EQ(60U, parser.tmmbn_items()->Overhead(0)); | 810 EXPECT_EQ(60U, parser.tmmbn_items()->Overhead(0)); |
663 } | 811 } |
664 | 812 |
665 TEST(RtcpPacketTest, TmmbnWithTwoItems) { | 813 TEST(RtcpPacketTest, TmmbnWithTwoItems) { |
666 Tmmbn tmmbn; | 814 Tmmbn tmmbn; |
667 tmmbn.From(kSenderSsrc); | 815 tmmbn.From(kSenderSsrc); |
668 tmmbn.WithTmmbr(kRemoteSsrc, 312, 60); | 816 EXPECT_TRUE(tmmbn.WithTmmbr(kRemoteSsrc, 312, 60)); |
669 tmmbn.WithTmmbr(kRemoteSsrc + 1, 1288, 40); | 817 EXPECT_TRUE(tmmbn.WithTmmbr(kRemoteSsrc + 1, 1288, 40)); |
670 | 818 |
671 RawPacket packet = tmmbn.Build(); | 819 rtc::scoped_ptr<RawPacket> packet(tmmbn.Build()); |
672 RtcpPacketParser parser; | 820 RtcpPacketParser parser; |
673 parser.Parse(packet.buffer(), packet.buffer_length()); | 821 parser.Parse(packet->Buffer(), packet->Length()); |
674 EXPECT_EQ(1, parser.tmmbn()->num_packets()); | 822 EXPECT_EQ(1, parser.tmmbn()->num_packets()); |
675 EXPECT_EQ(kSenderSsrc, parser.tmmbn()->Ssrc()); | 823 EXPECT_EQ(kSenderSsrc, parser.tmmbn()->Ssrc()); |
676 EXPECT_EQ(2, parser.tmmbn_items()->num_packets()); | 824 EXPECT_EQ(2, parser.tmmbn_items()->num_packets()); |
677 EXPECT_EQ(kRemoteSsrc, parser.tmmbn_items()->Ssrc(0)); | 825 EXPECT_EQ(kRemoteSsrc, parser.tmmbn_items()->Ssrc(0)); |
678 EXPECT_EQ(312U, parser.tmmbn_items()->BitrateKbps(0)); | 826 EXPECT_EQ(312U, parser.tmmbn_items()->BitrateKbps(0)); |
679 EXPECT_EQ(60U, parser.tmmbn_items()->Overhead(0)); | 827 EXPECT_EQ(60U, parser.tmmbn_items()->Overhead(0)); |
680 EXPECT_EQ(kRemoteSsrc + 1, parser.tmmbn_items()->Ssrc(1)); | 828 EXPECT_EQ(kRemoteSsrc + 1, parser.tmmbn_items()->Ssrc(1)); |
681 EXPECT_EQ(1288U, parser.tmmbn_items()->BitrateKbps(1)); | 829 EXPECT_EQ(1288U, parser.tmmbn_items()->BitrateKbps(1)); |
682 EXPECT_EQ(40U, parser.tmmbn_items()->Overhead(1)); | 830 EXPECT_EQ(40U, parser.tmmbn_items()->Overhead(1)); |
683 } | 831 } |
684 | 832 |
| 833 TEST(RtcpPacketTest, TmmbnWithTooManyItems) { |
| 834 Tmmbn tmmbn; |
| 835 tmmbn.From(kSenderSsrc); |
| 836 const int kMaxTmmbrItems = 50; |
| 837 for (int i = 0; i < kMaxTmmbrItems; ++i) |
| 838 EXPECT_TRUE(tmmbn.WithTmmbr(kRemoteSsrc + i, 312, 60)); |
| 839 |
| 840 EXPECT_FALSE(tmmbn.WithTmmbr(kRemoteSsrc + kMaxTmmbrItems, 312, 60)); |
| 841 } |
| 842 |
685 TEST(RtcpPacketTest, XrWithNoReportBlocks) { | 843 TEST(RtcpPacketTest, XrWithNoReportBlocks) { |
686 Xr xr; | 844 Xr xr; |
687 xr.From(kSenderSsrc); | 845 xr.From(kSenderSsrc); |
688 | 846 |
689 RawPacket packet = xr.Build(); | 847 rtc::scoped_ptr<RawPacket> packet(xr.Build()); |
690 RtcpPacketParser parser; | 848 RtcpPacketParser parser; |
691 parser.Parse(packet.buffer(), packet.buffer_length()); | 849 parser.Parse(packet->Buffer(), packet->Length()); |
692 EXPECT_EQ(1, parser.xr_header()->num_packets()); | 850 EXPECT_EQ(1, parser.xr_header()->num_packets()); |
693 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); | 851 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); |
694 } | 852 } |
695 | 853 |
696 TEST(RtcpPacketTest, XrWithRrtr) { | 854 TEST(RtcpPacketTest, XrWithRrtr) { |
697 Rrtr rrtr; | 855 Rrtr rrtr; |
698 rrtr.WithNtpSec(0x11111111); | 856 rrtr.WithNtpSec(0x11111111); |
699 rrtr.WithNtpFrac(0x22222222); | 857 rrtr.WithNtpFrac(0x22222222); |
700 Xr xr; | 858 Xr xr; |
701 xr.From(kSenderSsrc); | 859 xr.From(kSenderSsrc); |
702 xr.WithRrtr(&rrtr); | 860 EXPECT_TRUE(xr.WithRrtr(&rrtr)); |
703 | 861 |
704 RawPacket packet = xr.Build(); | 862 rtc::scoped_ptr<RawPacket> packet(xr.Build()); |
705 RtcpPacketParser parser; | 863 RtcpPacketParser parser; |
706 parser.Parse(packet.buffer(), packet.buffer_length()); | 864 parser.Parse(packet->Buffer(), packet->Length()); |
707 EXPECT_EQ(1, parser.xr_header()->num_packets()); | 865 EXPECT_EQ(1, parser.xr_header()->num_packets()); |
708 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); | 866 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); |
709 EXPECT_EQ(1, parser.rrtr()->num_packets()); | 867 EXPECT_EQ(1, parser.rrtr()->num_packets()); |
710 EXPECT_EQ(0x11111111U, parser.rrtr()->NtpSec()); | 868 EXPECT_EQ(0x11111111U, parser.rrtr()->NtpSec()); |
711 EXPECT_EQ(0x22222222U, parser.rrtr()->NtpFrac()); | 869 EXPECT_EQ(0x22222222U, parser.rrtr()->NtpFrac()); |
712 } | 870 } |
713 | 871 |
714 TEST(RtcpPacketTest, XrWithTwoRrtrBlocks) { | 872 TEST(RtcpPacketTest, XrWithTwoRrtrBlocks) { |
715 Rrtr rrtr1; | 873 Rrtr rrtr1; |
716 rrtr1.WithNtpSec(0x11111111); | 874 rrtr1.WithNtpSec(0x11111111); |
717 rrtr1.WithNtpFrac(0x22222222); | 875 rrtr1.WithNtpFrac(0x22222222); |
718 Rrtr rrtr2; | 876 Rrtr rrtr2; |
719 rrtr2.WithNtpSec(0x33333333); | 877 rrtr2.WithNtpSec(0x33333333); |
720 rrtr2.WithNtpFrac(0x44444444); | 878 rrtr2.WithNtpFrac(0x44444444); |
721 Xr xr; | 879 Xr xr; |
722 xr.From(kSenderSsrc); | 880 xr.From(kSenderSsrc); |
723 xr.WithRrtr(&rrtr1); | 881 EXPECT_TRUE(xr.WithRrtr(&rrtr1)); |
724 xr.WithRrtr(&rrtr2); | 882 EXPECT_TRUE(xr.WithRrtr(&rrtr2)); |
725 | 883 |
726 RawPacket packet = xr.Build(); | 884 rtc::scoped_ptr<RawPacket> packet(xr.Build()); |
727 RtcpPacketParser parser; | 885 RtcpPacketParser parser; |
728 parser.Parse(packet.buffer(), packet.buffer_length()); | 886 parser.Parse(packet->Buffer(), packet->Length()); |
729 EXPECT_EQ(1, parser.xr_header()->num_packets()); | 887 EXPECT_EQ(1, parser.xr_header()->num_packets()); |
730 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); | 888 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); |
731 EXPECT_EQ(2, parser.rrtr()->num_packets()); | 889 EXPECT_EQ(2, parser.rrtr()->num_packets()); |
732 EXPECT_EQ(0x33333333U, parser.rrtr()->NtpSec()); | 890 EXPECT_EQ(0x33333333U, parser.rrtr()->NtpSec()); |
733 EXPECT_EQ(0x44444444U, parser.rrtr()->NtpFrac()); | 891 EXPECT_EQ(0x44444444U, parser.rrtr()->NtpFrac()); |
734 } | 892 } |
735 | 893 |
736 TEST(RtcpPacketTest, XrWithDlrrWithOneSubBlock) { | 894 TEST(RtcpPacketTest, XrWithDlrrWithOneSubBlock) { |
737 Dlrr dlrr; | 895 Dlrr dlrr; |
738 dlrr.WithDlrrItem(0x11111111, 0x22222222, 0x33333333); | 896 EXPECT_TRUE(dlrr.WithDlrrItem(0x11111111, 0x22222222, 0x33333333)); |
739 Xr xr; | 897 Xr xr; |
740 xr.From(kSenderSsrc); | 898 xr.From(kSenderSsrc); |
741 xr.WithDlrr(&dlrr); | 899 EXPECT_TRUE(xr.WithDlrr(&dlrr)); |
742 | 900 |
743 RawPacket packet = xr.Build(); | 901 rtc::scoped_ptr<RawPacket> packet(xr.Build()); |
744 RtcpPacketParser parser; | 902 RtcpPacketParser parser; |
745 parser.Parse(packet.buffer(), packet.buffer_length()); | 903 parser.Parse(packet->Buffer(), packet->Length()); |
746 EXPECT_EQ(1, parser.xr_header()->num_packets()); | 904 EXPECT_EQ(1, parser.xr_header()->num_packets()); |
747 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); | 905 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); |
748 EXPECT_EQ(1, parser.dlrr()->num_packets()); | 906 EXPECT_EQ(1, parser.dlrr()->num_packets()); |
749 EXPECT_EQ(1, parser.dlrr_items()->num_packets()); | 907 EXPECT_EQ(1, parser.dlrr_items()->num_packets()); |
750 EXPECT_EQ(0x11111111U, parser.dlrr_items()->Ssrc(0)); | 908 EXPECT_EQ(0x11111111U, parser.dlrr_items()->Ssrc(0)); |
751 EXPECT_EQ(0x22222222U, parser.dlrr_items()->LastRr(0)); | 909 EXPECT_EQ(0x22222222U, parser.dlrr_items()->LastRr(0)); |
752 EXPECT_EQ(0x33333333U, parser.dlrr_items()->DelayLastRr(0)); | 910 EXPECT_EQ(0x33333333U, parser.dlrr_items()->DelayLastRr(0)); |
753 } | 911 } |
754 | 912 |
755 TEST(RtcpPacketTest, XrWithDlrrWithTwoSubBlocks) { | 913 TEST(RtcpPacketTest, XrWithDlrrWithTwoSubBlocks) { |
756 Dlrr dlrr; | 914 Dlrr dlrr; |
757 dlrr.WithDlrrItem(0x11111111, 0x22222222, 0x33333333); | 915 EXPECT_TRUE(dlrr.WithDlrrItem(0x11111111, 0x22222222, 0x33333333)); |
758 dlrr.WithDlrrItem(0x44444444, 0x55555555, 0x66666666); | 916 EXPECT_TRUE(dlrr.WithDlrrItem(0x44444444, 0x55555555, 0x66666666)); |
759 Xr xr; | 917 Xr xr; |
760 xr.From(kSenderSsrc); | 918 xr.From(kSenderSsrc); |
761 xr.WithDlrr(&dlrr); | 919 EXPECT_TRUE(xr.WithDlrr(&dlrr)); |
762 | 920 |
763 RawPacket packet = xr.Build(); | 921 rtc::scoped_ptr<RawPacket> packet(xr.Build()); |
764 RtcpPacketParser parser; | 922 RtcpPacketParser parser; |
765 parser.Parse(packet.buffer(), packet.buffer_length()); | 923 parser.Parse(packet->Buffer(), packet->Length()); |
766 EXPECT_EQ(1, parser.xr_header()->num_packets()); | 924 EXPECT_EQ(1, parser.xr_header()->num_packets()); |
767 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); | 925 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); |
768 EXPECT_EQ(1, parser.dlrr()->num_packets()); | 926 EXPECT_EQ(1, parser.dlrr()->num_packets()); |
769 EXPECT_EQ(2, parser.dlrr_items()->num_packets()); | 927 EXPECT_EQ(2, parser.dlrr_items()->num_packets()); |
770 EXPECT_EQ(0x11111111U, parser.dlrr_items()->Ssrc(0)); | 928 EXPECT_EQ(0x11111111U, parser.dlrr_items()->Ssrc(0)); |
771 EXPECT_EQ(0x22222222U, parser.dlrr_items()->LastRr(0)); | 929 EXPECT_EQ(0x22222222U, parser.dlrr_items()->LastRr(0)); |
772 EXPECT_EQ(0x33333333U, parser.dlrr_items()->DelayLastRr(0)); | 930 EXPECT_EQ(0x33333333U, parser.dlrr_items()->DelayLastRr(0)); |
773 EXPECT_EQ(0x44444444U, parser.dlrr_items()->Ssrc(1)); | 931 EXPECT_EQ(0x44444444U, parser.dlrr_items()->Ssrc(1)); |
774 EXPECT_EQ(0x55555555U, parser.dlrr_items()->LastRr(1)); | 932 EXPECT_EQ(0x55555555U, parser.dlrr_items()->LastRr(1)); |
775 EXPECT_EQ(0x66666666U, parser.dlrr_items()->DelayLastRr(1)); | 933 EXPECT_EQ(0x66666666U, parser.dlrr_items()->DelayLastRr(1)); |
776 } | 934 } |
777 | 935 |
| 936 TEST(RtcpPacketTest, DlrrWithTooManySubBlocks) { |
| 937 const int kMaxItems = 100; |
| 938 Dlrr dlrr; |
| 939 for (int i = 0; i < kMaxItems; ++i) |
| 940 EXPECT_TRUE(dlrr.WithDlrrItem(i, i, i)); |
| 941 EXPECT_FALSE(dlrr.WithDlrrItem(kMaxItems, kMaxItems, kMaxItems)); |
| 942 } |
| 943 |
778 TEST(RtcpPacketTest, XrWithTwoDlrrBlocks) { | 944 TEST(RtcpPacketTest, XrWithTwoDlrrBlocks) { |
779 Dlrr dlrr1; | 945 Dlrr dlrr1; |
780 dlrr1.WithDlrrItem(0x11111111, 0x22222222, 0x33333333); | 946 EXPECT_TRUE(dlrr1.WithDlrrItem(0x11111111, 0x22222222, 0x33333333)); |
781 Dlrr dlrr2; | 947 Dlrr dlrr2; |
782 dlrr2.WithDlrrItem(0x44444444, 0x55555555, 0x66666666); | 948 EXPECT_TRUE(dlrr2.WithDlrrItem(0x44444444, 0x55555555, 0x66666666)); |
783 Xr xr; | 949 Xr xr; |
784 xr.From(kSenderSsrc); | 950 xr.From(kSenderSsrc); |
785 xr.WithDlrr(&dlrr1); | 951 EXPECT_TRUE(xr.WithDlrr(&dlrr1)); |
786 xr.WithDlrr(&dlrr2); | 952 EXPECT_TRUE(xr.WithDlrr(&dlrr2)); |
787 | 953 |
788 RawPacket packet = xr.Build(); | 954 rtc::scoped_ptr<RawPacket> packet(xr.Build()); |
789 RtcpPacketParser parser; | 955 RtcpPacketParser parser; |
790 parser.Parse(packet.buffer(), packet.buffer_length()); | 956 parser.Parse(packet->Buffer(), packet->Length()); |
791 EXPECT_EQ(1, parser.xr_header()->num_packets()); | 957 EXPECT_EQ(1, parser.xr_header()->num_packets()); |
792 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); | 958 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); |
793 EXPECT_EQ(2, parser.dlrr()->num_packets()); | 959 EXPECT_EQ(2, parser.dlrr()->num_packets()); |
794 EXPECT_EQ(2, parser.dlrr_items()->num_packets()); | 960 EXPECT_EQ(2, parser.dlrr_items()->num_packets()); |
795 EXPECT_EQ(0x11111111U, parser.dlrr_items()->Ssrc(0)); | 961 EXPECT_EQ(0x11111111U, parser.dlrr_items()->Ssrc(0)); |
796 EXPECT_EQ(0x22222222U, parser.dlrr_items()->LastRr(0)); | 962 EXPECT_EQ(0x22222222U, parser.dlrr_items()->LastRr(0)); |
797 EXPECT_EQ(0x33333333U, parser.dlrr_items()->DelayLastRr(0)); | 963 EXPECT_EQ(0x33333333U, parser.dlrr_items()->DelayLastRr(0)); |
798 EXPECT_EQ(0x44444444U, parser.dlrr_items()->Ssrc(1)); | 964 EXPECT_EQ(0x44444444U, parser.dlrr_items()->Ssrc(1)); |
799 EXPECT_EQ(0x55555555U, parser.dlrr_items()->LastRr(1)); | 965 EXPECT_EQ(0x55555555U, parser.dlrr_items()->LastRr(1)); |
800 EXPECT_EQ(0x66666666U, parser.dlrr_items()->DelayLastRr(1)); | 966 EXPECT_EQ(0x66666666U, parser.dlrr_items()->DelayLastRr(1)); |
(...skipping 18 matching lines...) Expand all Loading... |
819 metric.ExtRfactor(10); | 985 metric.ExtRfactor(10); |
820 metric.MosLq(11); | 986 metric.MosLq(11); |
821 metric.MosCq(12); | 987 metric.MosCq(12); |
822 metric.RxConfig(13); | 988 metric.RxConfig(13); |
823 metric.JbNominal(0x5555); | 989 metric.JbNominal(0x5555); |
824 metric.JbMax(0x6666); | 990 metric.JbMax(0x6666); |
825 metric.JbAbsMax(0x7777); | 991 metric.JbAbsMax(0x7777); |
826 | 992 |
827 Xr xr; | 993 Xr xr; |
828 xr.From(kSenderSsrc); | 994 xr.From(kSenderSsrc); |
829 xr.WithVoipMetric(&metric); | 995 EXPECT_TRUE(xr.WithVoipMetric(&metric)); |
830 | 996 |
831 RawPacket packet = xr.Build(); | 997 rtc::scoped_ptr<RawPacket> packet(xr.Build()); |
832 RtcpPacketParser parser; | 998 RtcpPacketParser parser; |
833 parser.Parse(packet.buffer(), packet.buffer_length()); | 999 parser.Parse(packet->Buffer(), packet->Length()); |
834 EXPECT_EQ(1, parser.xr_header()->num_packets()); | 1000 EXPECT_EQ(1, parser.xr_header()->num_packets()); |
835 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); | 1001 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); |
836 EXPECT_EQ(1, parser.voip_metric()->num_packets()); | 1002 EXPECT_EQ(1, parser.voip_metric()->num_packets()); |
837 EXPECT_EQ(kRemoteSsrc, parser.voip_metric()->Ssrc()); | 1003 EXPECT_EQ(kRemoteSsrc, parser.voip_metric()->Ssrc()); |
838 EXPECT_EQ(1, parser.voip_metric()->LossRate()); | 1004 EXPECT_EQ(1, parser.voip_metric()->LossRate()); |
839 EXPECT_EQ(2, parser.voip_metric()->DiscardRate()); | 1005 EXPECT_EQ(2, parser.voip_metric()->DiscardRate()); |
840 EXPECT_EQ(3, parser.voip_metric()->BurstDensity()); | 1006 EXPECT_EQ(3, parser.voip_metric()->BurstDensity()); |
841 EXPECT_EQ(4, parser.voip_metric()->GapDensity()); | 1007 EXPECT_EQ(4, parser.voip_metric()->GapDensity()); |
842 EXPECT_EQ(0x1111, parser.voip_metric()->BurstDuration()); | 1008 EXPECT_EQ(0x1111, parser.voip_metric()->BurstDuration()); |
843 EXPECT_EQ(0x2222, parser.voip_metric()->GapDuration()); | 1009 EXPECT_EQ(0x2222, parser.voip_metric()->GapDuration()); |
844 EXPECT_EQ(0x3333, parser.voip_metric()->RoundTripDelay()); | 1010 EXPECT_EQ(0x3333, parser.voip_metric()->RoundTripDelay()); |
845 EXPECT_EQ(0x4444, parser.voip_metric()->EndSystemDelay()); | 1011 EXPECT_EQ(0x4444, parser.voip_metric()->EndSystemDelay()); |
846 EXPECT_EQ(5, parser.voip_metric()->SignalLevel()); | 1012 EXPECT_EQ(5, parser.voip_metric()->SignalLevel()); |
847 EXPECT_EQ(6, parser.voip_metric()->NoiseLevel()); | 1013 EXPECT_EQ(6, parser.voip_metric()->NoiseLevel()); |
848 EXPECT_EQ(7, parser.voip_metric()->Rerl()); | 1014 EXPECT_EQ(7, parser.voip_metric()->Rerl()); |
849 EXPECT_EQ(8, parser.voip_metric()->Gmin()); | 1015 EXPECT_EQ(8, parser.voip_metric()->Gmin()); |
850 EXPECT_EQ(9, parser.voip_metric()->Rfactor()); | 1016 EXPECT_EQ(9, parser.voip_metric()->Rfactor()); |
851 EXPECT_EQ(10, parser.voip_metric()->ExtRfactor()); | 1017 EXPECT_EQ(10, parser.voip_metric()->ExtRfactor()); |
852 EXPECT_EQ(11, parser.voip_metric()->MosLq()); | 1018 EXPECT_EQ(11, parser.voip_metric()->MosLq()); |
853 EXPECT_EQ(12, parser.voip_metric()->MosCq()); | 1019 EXPECT_EQ(12, parser.voip_metric()->MosCq()); |
854 EXPECT_EQ(13, parser.voip_metric()->RxConfig()); | 1020 EXPECT_EQ(13, parser.voip_metric()->RxConfig()); |
855 EXPECT_EQ(0x5555, parser.voip_metric()->JbNominal()); | 1021 EXPECT_EQ(0x5555, parser.voip_metric()->JbNominal()); |
856 EXPECT_EQ(0x6666, parser.voip_metric()->JbMax()); | 1022 EXPECT_EQ(0x6666, parser.voip_metric()->JbMax()); |
857 EXPECT_EQ(0x7777, parser.voip_metric()->JbAbsMax()); | 1023 EXPECT_EQ(0x7777, parser.voip_metric()->JbAbsMax()); |
858 } | 1024 } |
859 | 1025 |
860 TEST(RtcpPacketTest, XrWithMultipleReportBlocks) { | 1026 TEST(RtcpPacketTest, XrWithMultipleReportBlocks) { |
861 Rrtr rrtr; | 1027 Rrtr rrtr; |
862 Dlrr dlrr; | 1028 Dlrr dlrr; |
863 dlrr.WithDlrrItem(1, 2, 3); | 1029 EXPECT_TRUE(dlrr.WithDlrrItem(1, 2, 3)); |
864 VoipMetric metric; | 1030 VoipMetric metric; |
865 Xr xr; | 1031 Xr xr; |
866 xr.From(kSenderSsrc); | 1032 xr.From(kSenderSsrc); |
867 xr.WithRrtr(&rrtr); | 1033 EXPECT_TRUE(xr.WithRrtr(&rrtr)); |
868 xr.WithDlrr(&dlrr); | 1034 EXPECT_TRUE(xr.WithDlrr(&dlrr)); |
869 xr.WithVoipMetric(&metric); | 1035 EXPECT_TRUE(xr.WithVoipMetric(&metric)); |
870 | 1036 |
871 RawPacket packet = xr.Build(); | 1037 rtc::scoped_ptr<RawPacket> packet(xr.Build()); |
872 RtcpPacketParser parser; | 1038 RtcpPacketParser parser; |
873 parser.Parse(packet.buffer(), packet.buffer_length()); | 1039 parser.Parse(packet->Buffer(), packet->Length()); |
874 EXPECT_EQ(1, parser.xr_header()->num_packets()); | 1040 EXPECT_EQ(1, parser.xr_header()->num_packets()); |
875 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); | 1041 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); |
876 EXPECT_EQ(1, parser.rrtr()->num_packets()); | 1042 EXPECT_EQ(1, parser.rrtr()->num_packets()); |
877 EXPECT_EQ(1, parser.dlrr()->num_packets()); | 1043 EXPECT_EQ(1, parser.dlrr()->num_packets()); |
878 EXPECT_EQ(1, parser.dlrr_items()->num_packets()); | 1044 EXPECT_EQ(1, parser.dlrr_items()->num_packets()); |
879 EXPECT_EQ(1, parser.voip_metric()->num_packets()); | 1045 EXPECT_EQ(1, parser.voip_metric()->num_packets()); |
880 } | 1046 } |
881 | 1047 |
882 TEST(RtcpPacketTest, DlrrWithoutItemNotIncludedInPacket) { | 1048 TEST(RtcpPacketTest, DlrrWithoutItemNotIncludedInPacket) { |
883 Rrtr rrtr; | 1049 Rrtr rrtr; |
884 Dlrr dlrr; | 1050 Dlrr dlrr; |
885 VoipMetric metric; | 1051 VoipMetric metric; |
886 Xr xr; | 1052 Xr xr; |
887 xr.From(kSenderSsrc); | 1053 xr.From(kSenderSsrc); |
888 xr.WithRrtr(&rrtr); | 1054 EXPECT_TRUE(xr.WithRrtr(&rrtr)); |
889 xr.WithDlrr(&dlrr); | 1055 EXPECT_TRUE(xr.WithDlrr(&dlrr)); |
890 xr.WithVoipMetric(&metric); | 1056 EXPECT_TRUE(xr.WithVoipMetric(&metric)); |
891 | 1057 |
892 RawPacket packet = xr.Build(); | 1058 rtc::scoped_ptr<RawPacket> packet(xr.Build()); |
893 RtcpPacketParser parser; | 1059 RtcpPacketParser parser; |
894 parser.Parse(packet.buffer(), packet.buffer_length()); | 1060 parser.Parse(packet->Buffer(), packet->Length()); |
895 EXPECT_EQ(1, parser.xr_header()->num_packets()); | 1061 EXPECT_EQ(1, parser.xr_header()->num_packets()); |
896 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); | 1062 EXPECT_EQ(kSenderSsrc, parser.xr_header()->Ssrc()); |
897 EXPECT_EQ(1, parser.rrtr()->num_packets()); | 1063 EXPECT_EQ(1, parser.rrtr()->num_packets()); |
898 EXPECT_EQ(0, parser.dlrr()->num_packets()); | 1064 EXPECT_EQ(0, parser.dlrr()->num_packets()); |
899 EXPECT_EQ(1, parser.voip_metric()->num_packets()); | 1065 EXPECT_EQ(1, parser.voip_metric()->num_packets()); |
900 } | 1066 } |
| 1067 |
| 1068 TEST(RtcpPacketTest, XrWithTooManyBlocks) { |
| 1069 const int kMaxBlocks = 50; |
| 1070 Xr xr; |
| 1071 |
| 1072 Rrtr rrtr; |
| 1073 for (int i = 0; i < kMaxBlocks; ++i) |
| 1074 EXPECT_TRUE(xr.WithRrtr(&rrtr)); |
| 1075 EXPECT_FALSE(xr.WithRrtr(&rrtr)); |
| 1076 |
| 1077 Dlrr dlrr; |
| 1078 for (int i = 0; i < kMaxBlocks; ++i) |
| 1079 EXPECT_TRUE(xr.WithDlrr(&dlrr)); |
| 1080 EXPECT_FALSE(xr.WithDlrr(&dlrr)); |
| 1081 |
| 1082 VoipMetric voip_metric; |
| 1083 for (int i = 0; i < kMaxBlocks; ++i) |
| 1084 EXPECT_TRUE(xr.WithVoipMetric(&voip_metric)); |
| 1085 EXPECT_FALSE(xr.WithVoipMetric(&voip_metric)); |
| 1086 } |
901 } // namespace webrtc | 1087 } // namespace webrtc |
OLD | NEW |