OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 | 10 |
11 #ifdef ENABLE_RTC_EVENT_LOG | 11 #ifdef ENABLE_RTC_EVENT_LOG |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webrtc/base/buffer.h" | 17 #include "webrtc/base/buffer.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
20 #include "webrtc/base/thread.h" | 20 #include "webrtc/base/thread.h" |
21 #include "webrtc/call.h" | 21 #include "webrtc/call.h" |
22 #include "webrtc/call/rtc_event_log.h" | 22 #include "webrtc/call/rtc_event_log.h" |
| 23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" | 24 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
24 #include "webrtc/system_wrappers/include/clock.h" | 25 #include "webrtc/system_wrappers/include/clock.h" |
25 #include "webrtc/test/random.h" | 26 #include "webrtc/test/random.h" |
26 #include "webrtc/test/test_suite.h" | 27 #include "webrtc/test/test_suite.h" |
27 #include "webrtc/test/testsupport/fileutils.h" | 28 #include "webrtc/test/testsupport/fileutils.h" |
28 #include "webrtc/test/testsupport/gtest_disable.h" | 29 #include "webrtc/test/testsupport/gtest_disable.h" |
29 | 30 |
30 // Files generated at build-time by the protobuf compiler. | 31 // Files generated at build-time by the protobuf compiler. |
31 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 32 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
32 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" | 33 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 ASSERT_TRUE(receiver_config.has_local_ssrc()); | 132 ASSERT_TRUE(receiver_config.has_local_ssrc()); |
132 EXPECT_EQ(config.rtp.local_ssrc, receiver_config.local_ssrc()); | 133 EXPECT_EQ(config.rtp.local_ssrc, receiver_config.local_ssrc()); |
133 // Check RTCP settings. | 134 // Check RTCP settings. |
134 ASSERT_TRUE(receiver_config.has_rtcp_mode()); | 135 ASSERT_TRUE(receiver_config.has_rtcp_mode()); |
135 if (config.rtp.rtcp_mode == RtcpMode::kCompound) | 136 if (config.rtp.rtcp_mode == RtcpMode::kCompound) |
136 EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_COMPOUND, | 137 EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_COMPOUND, |
137 receiver_config.rtcp_mode()); | 138 receiver_config.rtcp_mode()); |
138 else | 139 else |
139 EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE, | 140 EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE, |
140 receiver_config.rtcp_mode()); | 141 receiver_config.rtcp_mode()); |
141 ASSERT_TRUE(receiver_config.has_receiver_reference_time_report()); | |
142 EXPECT_EQ(config.rtp.rtcp_xr.receiver_reference_time_report, | |
143 receiver_config.receiver_reference_time_report()); | |
144 ASSERT_TRUE(receiver_config.has_remb()); | 142 ASSERT_TRUE(receiver_config.has_remb()); |
145 EXPECT_EQ(config.rtp.remb, receiver_config.remb()); | 143 EXPECT_EQ(config.rtp.remb, receiver_config.remb()); |
146 // Check RTX map. | 144 // Check RTX map. |
147 ASSERT_EQ(static_cast<int>(config.rtp.rtx.size()), | 145 ASSERT_EQ(static_cast<int>(config.rtp.rtx.size()), |
148 receiver_config.rtx_map_size()); | 146 receiver_config.rtx_map_size()); |
149 for (const rtclog::RtxMap& rtx_map : receiver_config.rtx_map()) { | 147 for (const rtclog::RtxMap& rtx_map : receiver_config.rtx_map()) { |
150 ASSERT_TRUE(rtx_map.has_payload_type()); | 148 ASSERT_TRUE(rtx_map.has_payload_type()); |
151 ASSERT_TRUE(rtx_map.has_config()); | 149 ASSERT_TRUE(rtx_map.has_config()); |
152 EXPECT_EQ(1u, config.rtp.rtx.count(rtx_map.payload_type())); | 150 EXPECT_EQ(1u, config.rtp.rtx.count(rtx_map.payload_type())); |
153 const rtclog::RtxConfig& rtx_config = rtx_map.config(); | 151 const rtclog::RtxConfig& rtx_config = rtx_map.config(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // Check RTX settings. | 205 // Check RTX settings. |
208 ASSERT_EQ(static_cast<int>(config.rtp.rtx.ssrcs.size()), | 206 ASSERT_EQ(static_cast<int>(config.rtp.rtx.ssrcs.size()), |
209 sender_config.rtx_ssrcs_size()); | 207 sender_config.rtx_ssrcs_size()); |
210 for (int i = 0; i < sender_config.rtx_ssrcs_size(); i++) { | 208 for (int i = 0; i < sender_config.rtx_ssrcs_size(); i++) { |
211 EXPECT_EQ(config.rtp.rtx.ssrcs[i], sender_config.rtx_ssrcs(i)); | 209 EXPECT_EQ(config.rtp.rtx.ssrcs[i], sender_config.rtx_ssrcs(i)); |
212 } | 210 } |
213 if (sender_config.rtx_ssrcs_size() > 0) { | 211 if (sender_config.rtx_ssrcs_size() > 0) { |
214 ASSERT_TRUE(sender_config.has_rtx_payload_type()); | 212 ASSERT_TRUE(sender_config.has_rtx_payload_type()); |
215 EXPECT_EQ(config.rtp.rtx.payload_type, sender_config.rtx_payload_type()); | 213 EXPECT_EQ(config.rtp.rtx.payload_type, sender_config.rtx_payload_type()); |
216 } | 214 } |
217 // Check CNAME. | |
218 ASSERT_TRUE(sender_config.has_c_name()); | |
219 EXPECT_EQ(config.rtp.c_name, sender_config.c_name()); | |
220 // Check encoder. | 215 // Check encoder. |
221 ASSERT_TRUE(sender_config.has_encoder()); | 216 ASSERT_TRUE(sender_config.has_encoder()); |
222 ASSERT_TRUE(sender_config.encoder().has_name()); | 217 ASSERT_TRUE(sender_config.encoder().has_name()); |
223 ASSERT_TRUE(sender_config.encoder().has_payload_type()); | 218 ASSERT_TRUE(sender_config.encoder().has_payload_type()); |
224 EXPECT_EQ(config.encoder_settings.payload_name, | 219 EXPECT_EQ(config.encoder_settings.payload_name, |
225 sender_config.encoder().name()); | 220 sender_config.encoder().name()); |
226 EXPECT_EQ(config.encoder_settings.payload_type, | 221 EXPECT_EQ(config.encoder_settings.payload_type, |
227 sender_config.encoder().payload_type()); | 222 sender_config.encoder().payload_type()); |
228 } | 223 } |
229 | 224 |
230 void VerifyRtpEvent(const rtclog::Event& event, | 225 void VerifyRtpEvent(const rtclog::Event& event, |
231 bool incoming, | 226 bool incoming, |
232 MediaType media_type, | 227 MediaType media_type, |
233 uint8_t* header, | 228 const uint8_t* header, |
234 size_t header_size, | 229 size_t header_size, |
235 size_t total_size) { | 230 size_t total_size) { |
236 ASSERT_TRUE(IsValidBasicEvent(event)); | 231 ASSERT_TRUE(IsValidBasicEvent(event)); |
237 ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type()); | 232 ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type()); |
238 const rtclog::RtpPacket& rtp_packet = event.rtp_packet(); | 233 const rtclog::RtpPacket& rtp_packet = event.rtp_packet(); |
239 ASSERT_TRUE(rtp_packet.has_incoming()); | 234 ASSERT_TRUE(rtp_packet.has_incoming()); |
240 EXPECT_EQ(incoming, rtp_packet.incoming()); | 235 EXPECT_EQ(incoming, rtp_packet.incoming()); |
241 ASSERT_TRUE(rtp_packet.has_type()); | 236 ASSERT_TRUE(rtp_packet.has_type()); |
242 EXPECT_EQ(media_type, GetRuntimeMediaType(rtp_packet.type())); | 237 EXPECT_EQ(media_type, GetRuntimeMediaType(rtp_packet.type())); |
243 ASSERT_TRUE(rtp_packet.has_packet_length()); | 238 ASSERT_TRUE(rtp_packet.has_packet_length()); |
244 EXPECT_EQ(total_size, rtp_packet.packet_length()); | 239 EXPECT_EQ(total_size, rtp_packet.packet_length()); |
245 ASSERT_TRUE(rtp_packet.has_header()); | 240 ASSERT_TRUE(rtp_packet.has_header()); |
246 ASSERT_EQ(header_size, rtp_packet.header().size()); | 241 ASSERT_EQ(header_size, rtp_packet.header().size()); |
247 for (size_t i = 0; i < header_size; i++) { | 242 for (size_t i = 0; i < header_size; i++) { |
248 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i])); | 243 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i])); |
249 } | 244 } |
250 } | 245 } |
251 | 246 |
252 void VerifyRtcpEvent(const rtclog::Event& event, | 247 void VerifyRtcpEvent(const rtclog::Event& event, |
253 bool incoming, | 248 bool incoming, |
254 MediaType media_type, | 249 MediaType media_type, |
255 uint8_t* packet, | 250 const uint8_t* packet, |
256 size_t total_size) { | 251 size_t total_size) { |
257 ASSERT_TRUE(IsValidBasicEvent(event)); | 252 ASSERT_TRUE(IsValidBasicEvent(event)); |
258 ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type()); | 253 ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type()); |
259 const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet(); | 254 const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet(); |
260 ASSERT_TRUE(rtcp_packet.has_incoming()); | 255 ASSERT_TRUE(rtcp_packet.has_incoming()); |
261 EXPECT_EQ(incoming, rtcp_packet.incoming()); | 256 EXPECT_EQ(incoming, rtcp_packet.incoming()); |
262 ASSERT_TRUE(rtcp_packet.has_type()); | 257 ASSERT_TRUE(rtcp_packet.has_type()); |
263 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); | 258 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); |
264 ASSERT_TRUE(rtcp_packet.has_packet_data()); | 259 ASSERT_TRUE(rtcp_packet.has_packet_data()); |
265 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); | 260 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 packet, payload_type, marker_bit, capture_timestamp, capture_time_ms, | 341 packet, payload_type, marker_bit, capture_timestamp, capture_time_ms, |
347 timestamp_provided, inc_sequence_number); | 342 timestamp_provided, inc_sequence_number); |
348 | 343 |
349 for (size_t i = header_size; i < packet_size; i++) { | 344 for (size_t i = header_size; i < packet_size; i++) { |
350 packet[i] = prng->Rand<uint8_t>(); | 345 packet[i] = prng->Rand<uint8_t>(); |
351 } | 346 } |
352 | 347 |
353 return header_size; | 348 return header_size; |
354 } | 349 } |
355 | 350 |
356 void GenerateRtcpPacket(uint8_t* packet, | 351 rtc::scoped_ptr<rtcp::RawPacket> GenerateRtcpPacket(test::Random* prng) { |
357 size_t packet_size, | 352 rtcp::ReportBlock report_block; |
358 test::Random* prng) { | 353 report_block.To(prng->Rand<uint32_t>()); // Remote SSRC. |
359 for (size_t i = 0; i < packet_size; i++) { | 354 report_block.WithFractionLost(prng->Rand(50)); |
360 packet[i] = prng->Rand<uint8_t>(); | 355 |
361 } | 356 rtcp::SenderReport sender_report; |
| 357 sender_report.From(prng->Rand<uint32_t>()); // Sender SSRC. |
| 358 sender_report.WithNtpSec(prng->Rand<uint32_t>()); |
| 359 sender_report.WithNtpFrac(prng->Rand<uint32_t>()); |
| 360 sender_report.WithPacketCount(prng->Rand<uint32_t>()); |
| 361 sender_report.WithReportBlock(report_block); |
| 362 |
| 363 return sender_report.Build(); |
362 } | 364 } |
363 | 365 |
364 void GenerateVideoReceiveConfig(uint32_t extensions_bitvector, | 366 void GenerateVideoReceiveConfig(uint32_t extensions_bitvector, |
365 VideoReceiveStream::Config* config, | 367 VideoReceiveStream::Config* config, |
366 test::Random* prng) { | 368 test::Random* prng) { |
367 // Create a map from a payload type to an encoder name. | 369 // Create a map from a payload type to an encoder name. |
368 VideoReceiveStream::Decoder decoder; | 370 VideoReceiveStream::Decoder decoder; |
369 decoder.payload_type = prng->Rand(0, 127); | 371 decoder.payload_type = prng->Rand(0, 127); |
370 decoder.payload_name = (prng->Rand<bool>() ? "VP8" : "H264"); | 372 decoder.payload_name = (prng->Rand<bool>() ? "VP8" : "H264"); |
371 config->decoders.push_back(decoder); | 373 config->decoders.push_back(decoder); |
372 // Add SSRCs for the stream. | 374 // Add SSRCs for the stream. |
373 config->rtp.remote_ssrc = prng->Rand<uint32_t>(); | 375 config->rtp.remote_ssrc = prng->Rand<uint32_t>(); |
374 config->rtp.local_ssrc = prng->Rand<uint32_t>(); | 376 config->rtp.local_ssrc = prng->Rand<uint32_t>(); |
375 // Add extensions and settings for RTCP. | 377 // Add extensions and settings for RTCP. |
376 config->rtp.rtcp_mode = | 378 config->rtp.rtcp_mode = |
377 prng->Rand<bool>() ? RtcpMode::kCompound : RtcpMode::kReducedSize; | 379 prng->Rand<bool>() ? RtcpMode::kCompound : RtcpMode::kReducedSize; |
378 config->rtp.rtcp_xr.receiver_reference_time_report = prng->Rand<bool>(); | |
379 config->rtp.remb = prng->Rand<bool>(); | 380 config->rtp.remb = prng->Rand<bool>(); |
380 // Add a map from a payload type to a new ssrc and a new payload type for RTX. | 381 // Add a map from a payload type to a new ssrc and a new payload type for RTX. |
381 VideoReceiveStream::Config::Rtp::Rtx rtx_pair; | 382 VideoReceiveStream::Config::Rtp::Rtx rtx_pair; |
382 rtx_pair.ssrc = prng->Rand<uint32_t>(); | 383 rtx_pair.ssrc = prng->Rand<uint32_t>(); |
383 rtx_pair.payload_type = prng->Rand(0, 127); | 384 rtx_pair.payload_type = prng->Rand(0, 127); |
384 config->rtp.rtx.insert(std::make_pair(prng->Rand(0, 127), rtx_pair)); | 385 config->rtp.rtx.insert(std::make_pair(prng->Rand(0, 127), rtx_pair)); |
385 // Add header extensions. | 386 // Add header extensions. |
386 for (unsigned i = 0; i < kNumExtensions; i++) { | 387 for (unsigned i = 0; i < kNumExtensions; i++) { |
387 if (extensions_bitvector & (1u << i)) { | 388 if (extensions_bitvector & (1u << i)) { |
388 config->rtp.extensions.push_back( | 389 config->rtp.extensions.push_back( |
389 RtpExtension(kExtensionNames[i], prng->Rand<int>())); | 390 RtpExtension(kExtensionNames[i], prng->Rand<int>())); |
390 } | 391 } |
391 } | 392 } |
392 } | 393 } |
393 | 394 |
394 void GenerateVideoSendConfig(uint32_t extensions_bitvector, | 395 void GenerateVideoSendConfig(uint32_t extensions_bitvector, |
395 VideoSendStream::Config* config, | 396 VideoSendStream::Config* config, |
396 test::Random* prng) { | 397 test::Random* prng) { |
397 // Create a map from a payload type to an encoder name. | 398 // Create a map from a payload type to an encoder name. |
398 config->encoder_settings.payload_type = prng->Rand(0, 127); | 399 config->encoder_settings.payload_type = prng->Rand(0, 127); |
399 config->encoder_settings.payload_name = (prng->Rand<bool>() ? "VP8" : "H264"); | 400 config->encoder_settings.payload_name = (prng->Rand<bool>() ? "VP8" : "H264"); |
400 // Add SSRCs for the stream. | 401 // Add SSRCs for the stream. |
401 config->rtp.ssrcs.push_back(prng->Rand<uint32_t>()); | 402 config->rtp.ssrcs.push_back(prng->Rand<uint32_t>()); |
402 // Add a map from a payload type to new ssrcs and a new payload type for RTX. | 403 // Add a map from a payload type to new ssrcs and a new payload type for RTX. |
403 config->rtp.rtx.ssrcs.push_back(prng->Rand<uint32_t>()); | 404 config->rtp.rtx.ssrcs.push_back(prng->Rand<uint32_t>()); |
404 config->rtp.rtx.payload_type = prng->Rand(0, 127); | 405 config->rtp.rtx.payload_type = prng->Rand(0, 127); |
405 // Add a CNAME. | |
406 config->rtp.c_name = "some.user@some.host"; | |
407 // Add header extensions. | 406 // Add header extensions. |
408 for (unsigned i = 0; i < kNumExtensions; i++) { | 407 for (unsigned i = 0; i < kNumExtensions; i++) { |
409 if (extensions_bitvector & (1u << i)) { | 408 if (extensions_bitvector & (1u << i)) { |
410 config->rtp.extensions.push_back( | 409 config->rtp.extensions.push_back( |
411 RtpExtension(kExtensionNames[i], prng->Rand<int>())); | 410 RtpExtension(kExtensionNames[i], prng->Rand<int>())); |
412 } | 411 } |
413 } | 412 } |
414 } | 413 } |
415 | 414 |
416 // Test for the RtcEventLog class. Dumps some RTP packets and other events | 415 // Test for the RtcEventLog class. Dumps some RTP packets and other events |
417 // to disk, then reads them back to see if they match. | 416 // to disk, then reads them back to see if they match. |
418 void LogSessionAndReadBack(size_t rtp_count, | 417 void LogSessionAndReadBack(size_t rtp_count, |
419 size_t rtcp_count, | 418 size_t rtcp_count, |
420 size_t playout_count, | 419 size_t playout_count, |
421 size_t bwe_loss_count, | 420 size_t bwe_loss_count, |
422 uint32_t extensions_bitvector, | 421 uint32_t extensions_bitvector, |
423 uint32_t csrcs_count, | 422 uint32_t csrcs_count, |
424 unsigned int random_seed) { | 423 unsigned int random_seed) { |
425 ASSERT_LE(rtcp_count, rtp_count); | 424 ASSERT_LE(rtcp_count, rtp_count); |
426 ASSERT_LE(playout_count, rtp_count); | 425 ASSERT_LE(playout_count, rtp_count); |
427 ASSERT_LE(bwe_loss_count, rtp_count); | 426 ASSERT_LE(bwe_loss_count, rtp_count); |
428 std::vector<rtc::Buffer> rtp_packets; | 427 std::vector<rtc::Buffer> rtp_packets; |
429 std::vector<rtc::Buffer> rtcp_packets; | 428 std::vector<rtc::scoped_ptr<rtcp::RawPacket> > rtcp_packets; |
430 std::vector<size_t> rtp_header_sizes; | 429 std::vector<size_t> rtp_header_sizes; |
431 std::vector<uint32_t> playout_ssrcs; | 430 std::vector<uint32_t> playout_ssrcs; |
432 std::vector<std::pair<int32_t, uint8_t> > bwe_loss_updates; | 431 std::vector<std::pair<int32_t, uint8_t> > bwe_loss_updates; |
433 | 432 |
434 VideoReceiveStream::Config receiver_config(nullptr); | 433 VideoReceiveStream::Config receiver_config(nullptr); |
435 VideoSendStream::Config sender_config(nullptr); | 434 VideoSendStream::Config sender_config(nullptr); |
436 | 435 |
437 test::Random prng(random_seed); | 436 test::Random prng(random_seed); |
438 | 437 |
439 // Create rtp_count RTP packets containing random data. | 438 // Create rtp_count RTP packets containing random data. |
440 for (size_t i = 0; i < rtp_count; i++) { | 439 for (size_t i = 0; i < rtp_count; i++) { |
441 size_t packet_size = prng.Rand(1000, 1100); | 440 size_t packet_size = prng.Rand(1000, 1100); |
442 rtp_packets.push_back(rtc::Buffer(packet_size)); | 441 rtp_packets.push_back(rtc::Buffer(packet_size)); |
443 size_t header_size = | 442 size_t header_size = |
444 GenerateRtpPacket(extensions_bitvector, csrcs_count, | 443 GenerateRtpPacket(extensions_bitvector, csrcs_count, |
445 rtp_packets[i].data(), packet_size, &prng); | 444 rtp_packets[i].data(), packet_size, &prng); |
446 rtp_header_sizes.push_back(header_size); | 445 rtp_header_sizes.push_back(header_size); |
447 } | 446 } |
448 // Create rtcp_count RTCP packets containing random data. | 447 // Create rtcp_count RTCP packets containing random data. |
449 for (size_t i = 0; i < rtcp_count; i++) { | 448 for (size_t i = 0; i < rtcp_count; i++) { |
450 size_t packet_size = prng.Rand(1000, 1100); | 449 rtcp_packets.push_back(GenerateRtcpPacket(&prng)); |
451 rtcp_packets.push_back(rtc::Buffer(packet_size)); | |
452 GenerateRtcpPacket(rtcp_packets[i].data(), packet_size, &prng); | |
453 } | 450 } |
454 // Create playout_count random SSRCs to use when logging AudioPlayout events. | 451 // Create playout_count random SSRCs to use when logging AudioPlayout events. |
455 for (size_t i = 0; i < playout_count; i++) { | 452 for (size_t i = 0; i < playout_count; i++) { |
456 playout_ssrcs.push_back(prng.Rand<uint32_t>()); | 453 playout_ssrcs.push_back(prng.Rand<uint32_t>()); |
457 } | 454 } |
458 // Create bwe_loss_count random bitrate updates for BwePacketLoss. | 455 // Create bwe_loss_count random bitrate updates for BwePacketLoss. |
459 for (size_t i = 0; i < bwe_loss_count; i++) { | 456 for (size_t i = 0; i < bwe_loss_count; i++) { |
460 bwe_loss_updates.push_back(std::pair<int32_t, uint8_t>(rand(), rand())); | 457 bwe_loss_updates.push_back( |
| 458 std::make_pair(prng.Rand<int32_t>(), prng.Rand<uint8_t>())); |
461 } | 459 } |
462 // Create configurations for the video streams. | 460 // Create configurations for the video streams. |
463 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config, &prng); | 461 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config, &prng); |
464 GenerateVideoSendConfig(extensions_bitvector, &sender_config, &prng); | 462 GenerateVideoSendConfig(extensions_bitvector, &sender_config, &prng); |
465 const int config_count = 2; | 463 const int config_count = 2; |
466 | 464 |
467 // Find the name of the current test, in order to use it as a temporary | 465 // Find the name of the current test, in order to use it as a temporary |
468 // filename. | 466 // filename. |
469 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 467 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
470 const std::string temp_filename = | 468 const std::string temp_filename = |
(...skipping 10 matching lines...) Expand all Loading... |
481 size_t bwe_loss_index = 1; | 479 size_t bwe_loss_index = 1; |
482 for (size_t i = 1; i <= rtp_count; i++) { | 480 for (size_t i = 1; i <= rtp_count; i++) { |
483 log_dumper->LogRtpHeader( | 481 log_dumper->LogRtpHeader( |
484 (i % 2 == 0), // Every second packet is incoming. | 482 (i % 2 == 0), // Every second packet is incoming. |
485 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 483 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
486 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); | 484 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); |
487 if (i * rtcp_count >= rtcp_index * rtp_count) { | 485 if (i * rtcp_count >= rtcp_index * rtp_count) { |
488 log_dumper->LogRtcpPacket( | 486 log_dumper->LogRtcpPacket( |
489 rtcp_index % 2 == 0, // Every second packet is incoming | 487 rtcp_index % 2 == 0, // Every second packet is incoming |
490 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | 488 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
491 rtcp_packets[rtcp_index - 1].data(), | 489 rtcp_packets[rtcp_index - 1]->Buffer(), |
492 rtcp_packets[rtcp_index - 1].size()); | 490 rtcp_packets[rtcp_index - 1]->Length()); |
493 rtcp_index++; | 491 rtcp_index++; |
494 } | 492 } |
495 if (i * playout_count >= playout_index * rtp_count) { | 493 if (i * playout_count >= playout_index * rtp_count) { |
496 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); | 494 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); |
497 playout_index++; | 495 playout_index++; |
498 } | 496 } |
499 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | 497 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
500 log_dumper->LogBwePacketLossEvent( | 498 log_dumper->LogBwePacketLossEvent( |
501 bwe_loss_updates[bwe_loss_index - 1].first, | 499 bwe_loss_updates[bwe_loss_index - 1].first, |
502 bwe_loss_updates[bwe_loss_index - 1].second, i); | 500 bwe_loss_updates[bwe_loss_index - 1].second, i); |
(...skipping 26 matching lines...) Expand all Loading... |
529 VerifyRtpEvent(parsed_stream.stream(event_index), | 527 VerifyRtpEvent(parsed_stream.stream(event_index), |
530 (i % 2 == 0), // Every second packet is incoming. | 528 (i % 2 == 0), // Every second packet is incoming. |
531 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 529 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
532 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], | 530 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], |
533 rtp_packets[i - 1].size()); | 531 rtp_packets[i - 1].size()); |
534 event_index++; | 532 event_index++; |
535 if (i * rtcp_count >= rtcp_index * rtp_count) { | 533 if (i * rtcp_count >= rtcp_index * rtp_count) { |
536 VerifyRtcpEvent(parsed_stream.stream(event_index), | 534 VerifyRtcpEvent(parsed_stream.stream(event_index), |
537 rtcp_index % 2 == 0, // Every second packet is incoming. | 535 rtcp_index % 2 == 0, // Every second packet is incoming. |
538 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | 536 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
539 rtcp_packets[rtcp_index - 1].data(), | 537 rtcp_packets[rtcp_index - 1]->Buffer(), |
540 rtcp_packets[rtcp_index - 1].size()); | 538 rtcp_packets[rtcp_index - 1]->Length()); |
541 event_index++; | 539 event_index++; |
542 rtcp_index++; | 540 rtcp_index++; |
543 } | 541 } |
544 if (i * playout_count >= playout_index * rtp_count) { | 542 if (i * playout_count >= playout_index * rtp_count) { |
545 VerifyPlayoutEvent(parsed_stream.stream(event_index), | 543 VerifyPlayoutEvent(parsed_stream.stream(event_index), |
546 playout_ssrcs[playout_index - 1]); | 544 playout_ssrcs[playout_index - 1]); |
547 event_index++; | 545 event_index++; |
548 playout_index++; | 546 playout_index++; |
549 } | 547 } |
550 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | 548 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 } | 595 } |
598 } | 596 } |
599 | 597 |
600 // Tests that the event queue works correctly, i.e. drops old RTP, RTCP and | 598 // Tests that the event queue works correctly, i.e. drops old RTP, RTCP and |
601 // debug events, but keeps config events even if they are older than the limit. | 599 // debug events, but keeps config events even if they are older than the limit. |
602 void DropOldEvents(uint32_t extensions_bitvector, | 600 void DropOldEvents(uint32_t extensions_bitvector, |
603 uint32_t csrcs_count, | 601 uint32_t csrcs_count, |
604 unsigned int random_seed) { | 602 unsigned int random_seed) { |
605 rtc::Buffer old_rtp_packet; | 603 rtc::Buffer old_rtp_packet; |
606 rtc::Buffer recent_rtp_packet; | 604 rtc::Buffer recent_rtp_packet; |
607 rtc::Buffer old_rtcp_packet; | 605 rtc::scoped_ptr<rtcp::RawPacket> old_rtcp_packet; |
608 rtc::Buffer recent_rtcp_packet; | 606 rtc::scoped_ptr<rtcp::RawPacket> recent_rtcp_packet; |
609 | 607 |
610 VideoReceiveStream::Config receiver_config(nullptr); | 608 VideoReceiveStream::Config receiver_config(nullptr); |
611 VideoSendStream::Config sender_config(nullptr); | 609 VideoSendStream::Config sender_config(nullptr); |
612 | 610 |
613 test::Random prng(random_seed); | 611 test::Random prng(random_seed); |
614 | 612 |
615 // Create two RTP packets containing random data. | 613 // Create two RTP packets containing random data. |
616 size_t packet_size = prng.Rand(1000, 1100); | 614 size_t packet_size = prng.Rand(1000, 1100); |
617 old_rtp_packet.SetSize(packet_size); | 615 old_rtp_packet.SetSize(packet_size); |
618 GenerateRtpPacket(extensions_bitvector, csrcs_count, old_rtp_packet.data(), | 616 GenerateRtpPacket(extensions_bitvector, csrcs_count, old_rtp_packet.data(), |
619 packet_size, &prng); | 617 packet_size, &prng); |
620 packet_size = prng.Rand(1000, 1100); | 618 packet_size = prng.Rand(1000, 1100); |
621 recent_rtp_packet.SetSize(packet_size); | 619 recent_rtp_packet.SetSize(packet_size); |
622 size_t recent_header_size = | 620 size_t recent_header_size = |
623 GenerateRtpPacket(extensions_bitvector, csrcs_count, | 621 GenerateRtpPacket(extensions_bitvector, csrcs_count, |
624 recent_rtp_packet.data(), packet_size, &prng); | 622 recent_rtp_packet.data(), packet_size, &prng); |
625 | 623 |
626 // Create two RTCP packets containing random data. | 624 // Create two RTCP packets containing random data. |
627 packet_size = prng.Rand(1000, 1100); | 625 old_rtcp_packet = GenerateRtcpPacket(&prng); |
628 old_rtcp_packet.SetSize(packet_size); | 626 recent_rtcp_packet = GenerateRtcpPacket(&prng); |
629 GenerateRtcpPacket(old_rtcp_packet.data(), packet_size, &prng); | |
630 packet_size = prng.Rand(1000, 1100); | |
631 recent_rtcp_packet.SetSize(packet_size); | |
632 GenerateRtcpPacket(recent_rtcp_packet.data(), packet_size, &prng); | |
633 | 627 |
634 // Create configurations for the video streams. | 628 // Create configurations for the video streams. |
635 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config, &prng); | 629 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config, &prng); |
636 GenerateVideoSendConfig(extensions_bitvector, &sender_config, &prng); | 630 GenerateVideoSendConfig(extensions_bitvector, &sender_config, &prng); |
637 | 631 |
638 // Find the name of the current test, in order to use it as a temporary | 632 // Find the name of the current test, in order to use it as a temporary |
639 // filename. | 633 // filename. |
640 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 634 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
641 const std::string temp_filename = | 635 const std::string temp_filename = |
642 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 636 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
643 | 637 |
644 // The log file will be flushed to disk when the log_dumper goes out of scope. | 638 // The log file will be flushed to disk when the log_dumper goes out of scope. |
645 { | 639 { |
646 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | 640 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); |
647 // Reduce the time old events are stored to 50 ms. | 641 // Reduce the time old events are stored to 50 ms. |
648 log_dumper->SetBufferDuration(50000); | 642 log_dumper->SetBufferDuration(50000); |
649 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | 643 log_dumper->LogVideoReceiveStreamConfig(receiver_config); |
650 log_dumper->LogVideoSendStreamConfig(sender_config); | 644 log_dumper->LogVideoSendStreamConfig(sender_config); |
651 log_dumper->LogRtpHeader(false, MediaType::AUDIO, old_rtp_packet.data(), | 645 log_dumper->LogRtpHeader(false, MediaType::AUDIO, old_rtp_packet.data(), |
652 old_rtp_packet.size()); | 646 old_rtp_packet.size()); |
653 log_dumper->LogRtcpPacket(true, MediaType::AUDIO, old_rtcp_packet.data(), | 647 log_dumper->LogRtcpPacket(true, MediaType::AUDIO, old_rtcp_packet->Buffer(), |
654 old_rtcp_packet.size()); | 648 old_rtcp_packet->Length()); |
655 // Sleep 55 ms to let old events be removed from the queue. | 649 // Sleep 55 ms to let old events be removed from the queue. |
656 rtc::Thread::SleepMs(55); | 650 rtc::Thread::SleepMs(55); |
657 log_dumper->StartLogging(temp_filename, 10000000); | 651 log_dumper->StartLogging(temp_filename, 10000000); |
658 log_dumper->LogRtpHeader(true, MediaType::VIDEO, recent_rtp_packet.data(), | 652 log_dumper->LogRtpHeader(true, MediaType::VIDEO, recent_rtp_packet.data(), |
659 recent_rtp_packet.size()); | 653 recent_rtp_packet.size()); |
660 log_dumper->LogRtcpPacket(false, MediaType::VIDEO, | 654 log_dumper->LogRtcpPacket(false, MediaType::VIDEO, |
661 recent_rtcp_packet.data(), | 655 recent_rtcp_packet->Buffer(), |
662 recent_rtcp_packet.size()); | 656 recent_rtcp_packet->Length()); |
663 } | 657 } |
664 | 658 |
665 // Read the generated file from disk. | 659 // Read the generated file from disk. |
666 rtclog::EventStream parsed_stream; | 660 rtclog::EventStream parsed_stream; |
667 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 661 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); |
668 | 662 |
669 // Verify that what we read back from the event log is the same as | 663 // Verify that what we read back from the event log is the same as |
670 // what we wrote. Old RTP and RTCP events should have been discarded, | 664 // what we wrote. Old RTP and RTCP events should have been discarded, |
671 // but old configuration events should still be available. | 665 // but old configuration events should still be available. |
672 EXPECT_EQ(5, parsed_stream.stream_size()); | 666 EXPECT_EQ(5, parsed_stream.stream_size()); |
673 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | 667 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); |
674 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | 668 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); |
675 VerifyLogStartEvent(parsed_stream.stream(2)); | 669 VerifyLogStartEvent(parsed_stream.stream(2)); |
676 VerifyRtpEvent(parsed_stream.stream(3), true, MediaType::VIDEO, | 670 VerifyRtpEvent(parsed_stream.stream(3), true, MediaType::VIDEO, |
677 recent_rtp_packet.data(), recent_header_size, | 671 recent_rtp_packet.data(), recent_header_size, |
678 recent_rtp_packet.size()); | 672 recent_rtp_packet.size()); |
679 VerifyRtcpEvent(parsed_stream.stream(4), false, MediaType::VIDEO, | 673 VerifyRtcpEvent(parsed_stream.stream(4), false, MediaType::VIDEO, |
680 recent_rtcp_packet.data(), recent_rtcp_packet.size()); | 674 recent_rtcp_packet->Buffer(), recent_rtcp_packet->Length()); |
681 | 675 |
682 // Clean up temporary file - can be pretty slow. | 676 // Clean up temporary file - can be pretty slow. |
683 remove(temp_filename.c_str()); | 677 remove(temp_filename.c_str()); |
684 } | 678 } |
685 | 679 |
686 TEST(RtcEventLogTest, DropOldEvents) { | 680 TEST(RtcEventLogTest, DropOldEvents) { |
687 // Enable all header extensions | 681 // Enable all header extensions |
688 uint32_t extensions = (1u << kNumExtensions) - 1; | 682 uint32_t extensions = (1u << kNumExtensions) - 1; |
689 uint32_t csrcs_count = 2; | 683 uint32_t csrcs_count = 2; |
690 DropOldEvents(extensions, csrcs_count, 141421356); | 684 DropOldEvents(extensions, csrcs_count, 141421356); |
691 DropOldEvents(extensions, csrcs_count, 173205080); | 685 DropOldEvents(extensions, csrcs_count, 173205080); |
692 } | 686 } |
693 | 687 |
694 } // namespace webrtc | 688 } // namespace webrtc |
695 | 689 |
696 #endif // ENABLE_RTC_EVENT_LOG | 690 #endif // ENABLE_RTC_EVENT_LOG |
OLD | NEW |