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/random.h" |
19 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
20 #include "webrtc/base/thread.h" | 21 #include "webrtc/base/thread.h" |
21 #include "webrtc/call.h" | 22 #include "webrtc/call.h" |
22 #include "webrtc/call/rtc_event_log.h" | 23 #include "webrtc/call/rtc_event_log.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" | 24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
24 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
25 #include "webrtc/system_wrappers/include/clock.h" | 26 #include "webrtc/system_wrappers/include/clock.h" |
26 #include "webrtc/test/random.h" | |
27 #include "webrtc/test/test_suite.h" | 27 #include "webrtc/test/test_suite.h" |
28 #include "webrtc/test/testsupport/fileutils.h" | 28 #include "webrtc/test/testsupport/fileutils.h" |
29 #include "webrtc/test/testsupport/gtest_disable.h" | 29 #include "webrtc/test/testsupport/gtest_disable.h" |
30 | 30 |
31 // Files generated at build-time by the protobuf compiler. | 31 // Files generated at build-time by the protobuf compiler. |
32 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 32 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
33 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" | 33 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" |
34 #else | 34 #else |
35 #include "webrtc/call/rtc_event_log.pb.h" | 35 #include "webrtc/call/rtc_event_log.pb.h" |
36 #endif | 36 #endif |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 293 |
294 /* | 294 /* |
295 * Bit number i of extension_bitvector is set to indicate the | 295 * Bit number i of extension_bitvector is set to indicate the |
296 * presence of extension number i from kExtensionTypes / kExtensionNames. | 296 * presence of extension number i from kExtensionTypes / kExtensionNames. |
297 * The least significant bit extension_bitvector has number 0. | 297 * The least significant bit extension_bitvector has number 0. |
298 */ | 298 */ |
299 size_t GenerateRtpPacket(uint32_t extensions_bitvector, | 299 size_t GenerateRtpPacket(uint32_t extensions_bitvector, |
300 uint32_t csrcs_count, | 300 uint32_t csrcs_count, |
301 uint8_t* packet, | 301 uint8_t* packet, |
302 size_t packet_size, | 302 size_t packet_size, |
303 test::Random* prng) { | 303 Random* prng) { |
304 RTC_CHECK_GE(packet_size, 16 + 4 * csrcs_count + 4 * kNumExtensions); | 304 RTC_CHECK_GE(packet_size, 16 + 4 * csrcs_count + 4 * kNumExtensions); |
305 Clock* clock = Clock::GetRealTimeClock(); | 305 Clock* clock = Clock::GetRealTimeClock(); |
306 | 306 |
307 RTPSender rtp_sender(false, // bool audio | 307 RTPSender rtp_sender(false, // bool audio |
308 clock, // Clock* clock | 308 clock, // Clock* clock |
309 nullptr, // Transport* | 309 nullptr, // Transport* |
310 nullptr, // RtpAudioFeedback* | 310 nullptr, // RtpAudioFeedback* |
311 nullptr, // PacedSender* | 311 nullptr, // PacedSender* |
312 nullptr, // PacketRouter* | 312 nullptr, // PacketRouter* |
313 nullptr, // SendTimeObserver* | 313 nullptr, // SendTimeObserver* |
(...skipping 27 matching lines...) Expand all Loading... |
341 packet, payload_type, marker_bit, capture_timestamp, capture_time_ms, | 341 packet, payload_type, marker_bit, capture_timestamp, capture_time_ms, |
342 timestamp_provided, inc_sequence_number); | 342 timestamp_provided, inc_sequence_number); |
343 | 343 |
344 for (size_t i = header_size; i < packet_size; i++) { | 344 for (size_t i = header_size; i < packet_size; i++) { |
345 packet[i] = prng->Rand<uint8_t>(); | 345 packet[i] = prng->Rand<uint8_t>(); |
346 } | 346 } |
347 | 347 |
348 return header_size; | 348 return header_size; |
349 } | 349 } |
350 | 350 |
351 rtc::scoped_ptr<rtcp::RawPacket> GenerateRtcpPacket(test::Random* prng) { | 351 rtc::scoped_ptr<rtcp::RawPacket> GenerateRtcpPacket(Random* prng) { |
352 rtcp::ReportBlock report_block; | 352 rtcp::ReportBlock report_block; |
353 report_block.To(prng->Rand<uint32_t>()); // Remote SSRC. | 353 report_block.To(prng->Rand<uint32_t>()); // Remote SSRC. |
354 report_block.WithFractionLost(prng->Rand(50)); | 354 report_block.WithFractionLost(prng->Rand(50)); |
355 | 355 |
356 rtcp::SenderReport sender_report; | 356 rtcp::SenderReport sender_report; |
357 sender_report.From(prng->Rand<uint32_t>()); // Sender SSRC. | 357 sender_report.From(prng->Rand<uint32_t>()); // Sender SSRC. |
358 sender_report.WithNtpSec(prng->Rand<uint32_t>()); | 358 sender_report.WithNtpSec(prng->Rand<uint32_t>()); |
359 sender_report.WithNtpFrac(prng->Rand<uint32_t>()); | 359 sender_report.WithNtpFrac(prng->Rand<uint32_t>()); |
360 sender_report.WithPacketCount(prng->Rand<uint32_t>()); | 360 sender_report.WithPacketCount(prng->Rand<uint32_t>()); |
361 sender_report.WithReportBlock(report_block); | 361 sender_report.WithReportBlock(report_block); |
362 | 362 |
363 return sender_report.Build(); | 363 return sender_report.Build(); |
364 } | 364 } |
365 | 365 |
366 void GenerateVideoReceiveConfig(uint32_t extensions_bitvector, | 366 void GenerateVideoReceiveConfig(uint32_t extensions_bitvector, |
367 VideoReceiveStream::Config* config, | 367 VideoReceiveStream::Config* config, |
368 test::Random* prng) { | 368 Random* prng) { |
369 // Create a map from a payload type to an encoder name. | 369 // Create a map from a payload type to an encoder name. |
370 VideoReceiveStream::Decoder decoder; | 370 VideoReceiveStream::Decoder decoder; |
371 decoder.payload_type = prng->Rand(0, 127); | 371 decoder.payload_type = prng->Rand(0, 127); |
372 decoder.payload_name = (prng->Rand<bool>() ? "VP8" : "H264"); | 372 decoder.payload_name = (prng->Rand<bool>() ? "VP8" : "H264"); |
373 config->decoders.push_back(decoder); | 373 config->decoders.push_back(decoder); |
374 // Add SSRCs for the stream. | 374 // Add SSRCs for the stream. |
375 config->rtp.remote_ssrc = prng->Rand<uint32_t>(); | 375 config->rtp.remote_ssrc = prng->Rand<uint32_t>(); |
376 config->rtp.local_ssrc = prng->Rand<uint32_t>(); | 376 config->rtp.local_ssrc = prng->Rand<uint32_t>(); |
377 // Add extensions and settings for RTCP. | 377 // Add extensions and settings for RTCP. |
378 config->rtp.rtcp_mode = | 378 config->rtp.rtcp_mode = |
379 prng->Rand<bool>() ? RtcpMode::kCompound : RtcpMode::kReducedSize; | 379 prng->Rand<bool>() ? RtcpMode::kCompound : RtcpMode::kReducedSize; |
380 config->rtp.remb = prng->Rand<bool>(); | 380 config->rtp.remb = prng->Rand<bool>(); |
381 // 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. |
382 VideoReceiveStream::Config::Rtp::Rtx rtx_pair; | 382 VideoReceiveStream::Config::Rtp::Rtx rtx_pair; |
383 rtx_pair.ssrc = prng->Rand<uint32_t>(); | 383 rtx_pair.ssrc = prng->Rand<uint32_t>(); |
384 rtx_pair.payload_type = prng->Rand(0, 127); | 384 rtx_pair.payload_type = prng->Rand(0, 127); |
385 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)); |
386 // Add header extensions. | 386 // Add header extensions. |
387 for (unsigned i = 0; i < kNumExtensions; i++) { | 387 for (unsigned i = 0; i < kNumExtensions; i++) { |
388 if (extensions_bitvector & (1u << i)) { | 388 if (extensions_bitvector & (1u << i)) { |
389 config->rtp.extensions.push_back( | 389 config->rtp.extensions.push_back( |
390 RtpExtension(kExtensionNames[i], prng->Rand<int>())); | 390 RtpExtension(kExtensionNames[i], prng->Rand<int>())); |
391 } | 391 } |
392 } | 392 } |
393 } | 393 } |
394 | 394 |
395 void GenerateVideoSendConfig(uint32_t extensions_bitvector, | 395 void GenerateVideoSendConfig(uint32_t extensions_bitvector, |
396 VideoSendStream::Config* config, | 396 VideoSendStream::Config* config, |
397 test::Random* prng) { | 397 Random* prng) { |
398 // Create a map from a payload type to an encoder name. | 398 // Create a map from a payload type to an encoder name. |
399 config->encoder_settings.payload_type = prng->Rand(0, 127); | 399 config->encoder_settings.payload_type = prng->Rand(0, 127); |
400 config->encoder_settings.payload_name = (prng->Rand<bool>() ? "VP8" : "H264"); | 400 config->encoder_settings.payload_name = (prng->Rand<bool>() ? "VP8" : "H264"); |
401 // Add SSRCs for the stream. | 401 // Add SSRCs for the stream. |
402 config->rtp.ssrcs.push_back(prng->Rand<uint32_t>()); | 402 config->rtp.ssrcs.push_back(prng->Rand<uint32_t>()); |
403 // 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. |
404 config->rtp.rtx.ssrcs.push_back(prng->Rand<uint32_t>()); | 404 config->rtp.rtx.ssrcs.push_back(prng->Rand<uint32_t>()); |
405 config->rtp.rtx.payload_type = prng->Rand(0, 127); | 405 config->rtp.rtx.payload_type = prng->Rand(0, 127); |
406 // Add header extensions. | 406 // Add header extensions. |
407 for (unsigned i = 0; i < kNumExtensions; i++) { | 407 for (unsigned i = 0; i < kNumExtensions; i++) { |
(...skipping 18 matching lines...) Expand all Loading... |
426 ASSERT_LE(bwe_loss_count, rtp_count); | 426 ASSERT_LE(bwe_loss_count, rtp_count); |
427 std::vector<rtc::Buffer> rtp_packets; | 427 std::vector<rtc::Buffer> rtp_packets; |
428 std::vector<rtc::scoped_ptr<rtcp::RawPacket> > rtcp_packets; | 428 std::vector<rtc::scoped_ptr<rtcp::RawPacket> > rtcp_packets; |
429 std::vector<size_t> rtp_header_sizes; | 429 std::vector<size_t> rtp_header_sizes; |
430 std::vector<uint32_t> playout_ssrcs; | 430 std::vector<uint32_t> playout_ssrcs; |
431 std::vector<std::pair<int32_t, uint8_t> > bwe_loss_updates; | 431 std::vector<std::pair<int32_t, uint8_t> > bwe_loss_updates; |
432 | 432 |
433 VideoReceiveStream::Config receiver_config(nullptr); | 433 VideoReceiveStream::Config receiver_config(nullptr); |
434 VideoSendStream::Config sender_config(nullptr); | 434 VideoSendStream::Config sender_config(nullptr); |
435 | 435 |
436 test::Random prng(random_seed); | 436 Random prng(random_seed); |
437 | 437 |
438 // Create rtp_count RTP packets containing random data. | 438 // Create rtp_count RTP packets containing random data. |
439 for (size_t i = 0; i < rtp_count; i++) { | 439 for (size_t i = 0; i < rtp_count; i++) { |
440 size_t packet_size = prng.Rand(1000, 1100); | 440 size_t packet_size = prng.Rand(1000, 1100); |
441 rtp_packets.push_back(rtc::Buffer(packet_size)); | 441 rtp_packets.push_back(rtc::Buffer(packet_size)); |
442 size_t header_size = | 442 size_t header_size = |
443 GenerateRtpPacket(extensions_bitvector, csrcs_count, | 443 GenerateRtpPacket(extensions_bitvector, csrcs_count, |
444 rtp_packets[i].data(), packet_size, &prng); | 444 rtp_packets[i].data(), packet_size, &prng); |
445 rtp_header_sizes.push_back(header_size); | 445 rtp_header_sizes.push_back(header_size); |
446 } | 446 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 583 |
584 // Try all combinations of header extensions and up to 2 CSRCS. | 584 // Try all combinations of header extensions and up to 2 CSRCS. |
585 for (extensions = 0; extensions < (1u << kNumExtensions); extensions++) { | 585 for (extensions = 0; extensions < (1u << kNumExtensions); extensions++) { |
586 for (uint32_t csrcs_count = 0; csrcs_count < 3; csrcs_count++) { | 586 for (uint32_t csrcs_count = 0; csrcs_count < 3; csrcs_count++) { |
587 LogSessionAndReadBack(5 + extensions, // Number of RTP packets. | 587 LogSessionAndReadBack(5 + extensions, // Number of RTP packets. |
588 2 + csrcs_count, // Number of RTCP packets. | 588 2 + csrcs_count, // Number of RTCP packets. |
589 3 + csrcs_count, // Number of playout events. | 589 3 + csrcs_count, // Number of playout events. |
590 1 + csrcs_count, // Number of BWE loss events. | 590 1 + csrcs_count, // Number of BWE loss events. |
591 extensions, // Bit vector choosing extensions. | 591 extensions, // Bit vector choosing extensions. |
592 csrcs_count, // Number of contributing sources. | 592 csrcs_count, // Number of contributing sources. |
593 extensions + csrcs_count); // Random seed. | 593 extensions * 3 + csrcs_count + 1); // Random seed. |
594 } | 594 } |
595 } | 595 } |
596 } | 596 } |
597 | 597 |
598 // 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 |
599 // 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. |
600 void DropOldEvents(uint32_t extensions_bitvector, | 600 void DropOldEvents(uint32_t extensions_bitvector, |
601 uint32_t csrcs_count, | 601 uint32_t csrcs_count, |
602 unsigned int random_seed) { | 602 unsigned int random_seed) { |
603 rtc::Buffer old_rtp_packet; | 603 rtc::Buffer old_rtp_packet; |
604 rtc::Buffer recent_rtp_packet; | 604 rtc::Buffer recent_rtp_packet; |
605 rtc::scoped_ptr<rtcp::RawPacket> old_rtcp_packet; | 605 rtc::scoped_ptr<rtcp::RawPacket> old_rtcp_packet; |
606 rtc::scoped_ptr<rtcp::RawPacket> recent_rtcp_packet; | 606 rtc::scoped_ptr<rtcp::RawPacket> recent_rtcp_packet; |
607 | 607 |
608 VideoReceiveStream::Config receiver_config(nullptr); | 608 VideoReceiveStream::Config receiver_config(nullptr); |
609 VideoSendStream::Config sender_config(nullptr); | 609 VideoSendStream::Config sender_config(nullptr); |
610 | 610 |
611 test::Random prng(random_seed); | 611 Random prng(random_seed); |
612 | 612 |
613 // Create two RTP packets containing random data. | 613 // Create two RTP packets containing random data. |
614 size_t packet_size = prng.Rand(1000, 1100); | 614 size_t packet_size = prng.Rand(1000, 1100); |
615 old_rtp_packet.SetSize(packet_size); | 615 old_rtp_packet.SetSize(packet_size); |
616 GenerateRtpPacket(extensions_bitvector, csrcs_count, old_rtp_packet.data(), | 616 GenerateRtpPacket(extensions_bitvector, csrcs_count, old_rtp_packet.data(), |
617 packet_size, &prng); | 617 packet_size, &prng); |
618 packet_size = prng.Rand(1000, 1100); | 618 packet_size = prng.Rand(1000, 1100); |
619 recent_rtp_packet.SetSize(packet_size); | 619 recent_rtp_packet.SetSize(packet_size); |
620 size_t recent_header_size = | 620 size_t recent_header_size = |
621 GenerateRtpPacket(extensions_bitvector, csrcs_count, | 621 GenerateRtpPacket(extensions_bitvector, csrcs_count, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 // Enable all header extensions | 681 // Enable all header extensions |
682 uint32_t extensions = (1u << kNumExtensions) - 1; | 682 uint32_t extensions = (1u << kNumExtensions) - 1; |
683 uint32_t csrcs_count = 2; | 683 uint32_t csrcs_count = 2; |
684 DropOldEvents(extensions, csrcs_count, 141421356); | 684 DropOldEvents(extensions, csrcs_count, 141421356); |
685 DropOldEvents(extensions, csrcs_count, 173205080); | 685 DropOldEvents(extensions, csrcs_count, 173205080); |
686 } | 686 } |
687 | 687 |
688 } // namespace webrtc | 688 } // namespace webrtc |
689 | 689 |
690 #endif // ENABLE_RTC_EVENT_LOG | 690 #endif // ENABLE_RTC_EVENT_LOG |
OLD | NEW |