OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 | 76 |
77 VideoSendStream::StreamStats GetStreamStats(uint32_t ssrc) { | 77 VideoSendStream::StreamStats GetStreamStats(uint32_t ssrc) { |
78 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 78 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
79 std::map<uint32_t, VideoSendStream::StreamStats>::iterator it = | 79 std::map<uint32_t, VideoSendStream::StreamStats>::iterator it = |
80 stats.substreams.find(ssrc); | 80 stats.substreams.find(ssrc); |
81 EXPECT_NE(it, stats.substreams.end()); | 81 EXPECT_NE(it, stats.substreams.end()); |
82 return it->second; | 82 return it->second; |
83 } | 83 } |
84 | 84 |
| 85 void UpdateDataCounters(uint32_t ssrc) { |
| 86 StreamDataCountersCallback* proxy = |
| 87 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get()); |
| 88 StreamDataCounters counters; |
| 89 proxy->DataCountersUpdated(counters, ssrc); |
| 90 } |
| 91 |
85 void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) { | 92 void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) { |
86 EXPECT_EQ(one.input_frame_rate, other.input_frame_rate); | 93 EXPECT_EQ(one.input_frame_rate, other.input_frame_rate); |
87 EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate); | 94 EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate); |
88 EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps); | 95 EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps); |
89 EXPECT_EQ(one.preferred_media_bitrate_bps, | 96 EXPECT_EQ(one.preferred_media_bitrate_bps, |
90 other.preferred_media_bitrate_bps); | 97 other.preferred_media_bitrate_bps); |
91 EXPECT_EQ(one.suspended, other.suspended); | 98 EXPECT_EQ(one.suspended, other.suspended); |
92 | 99 |
93 EXPECT_EQ(one.substreams.size(), other.substreams.size()); | 100 EXPECT_EQ(one.substreams.size(), other.substreams.size()); |
94 for (std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator it = | 101 for (std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator it = |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendStreamLifetimeInSeconds", | 504 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendStreamLifetimeInSeconds", |
498 kTimeSec)); | 505 kTimeSec)); |
499 } | 506 } |
500 | 507 |
501 TEST_F(SendStatisticsProxyTest, CodecTypeHistogramIsUpdated) { | 508 TEST_F(SendStatisticsProxyTest, CodecTypeHistogramIsUpdated) { |
502 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); | 509 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
503 statistics_proxy_.reset(); | 510 statistics_proxy_.reset(); |
504 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoder.CodecType")); | 511 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoder.CodecType")); |
505 } | 512 } |
506 | 513 |
| 514 TEST_F(SendStatisticsProxyTest, PauseEventHistogramIsUpdated) { |
| 515 // First RTP packet sent. |
| 516 UpdateDataCounters(kFirstSsrc); |
| 517 |
| 518 // Min runtime has passed. |
| 519 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 520 statistics_proxy_.reset(); |
| 521 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents")); |
| 522 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 0)); |
| 523 } |
| 524 |
| 525 TEST_F(SendStatisticsProxyTest, |
| 526 PauseEventHistogramIsNotUpdatedIfMinRuntimeHasNotPassed) { |
| 527 // First RTP packet sent. |
| 528 UpdateDataCounters(kFirstSsrc); |
| 529 |
| 530 // Min runtime has not passed. |
| 531 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1); |
| 532 statistics_proxy_.reset(); |
| 533 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents")); |
| 534 } |
| 535 |
| 536 TEST_F(SendStatisticsProxyTest, |
| 537 PauseEventHistogramIsNotUpdatedIfNoMediaIsSent) { |
| 538 // First RTP packet not sent. |
| 539 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 540 statistics_proxy_.reset(); |
| 541 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents")); |
| 542 } |
| 543 |
| 544 TEST_F(SendStatisticsProxyTest, NoPauseEvent) { |
| 545 // First RTP packet sent and min runtime passed. |
| 546 UpdateDataCounters(kFirstSsrc); |
| 547 |
| 548 // No change. Video: 10000 ms, paused: 0 ms (0%). |
| 549 statistics_proxy_->OnSetEncoderTargetRate(50000); |
| 550 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 551 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop |
| 552 |
| 553 statistics_proxy_.reset(); |
| 554 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents")); |
| 555 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 0)); |
| 556 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent")); |
| 557 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PausedTimeInPercent", 0)); |
| 558 } |
| 559 |
| 560 TEST_F(SendStatisticsProxyTest, OnePauseEvent) { |
| 561 // First RTP packet sent and min runtime passed. |
| 562 UpdateDataCounters(kFirstSsrc); |
| 563 |
| 564 // One change. Video: 7000 ms, paused: 3000 ms (30%). |
| 565 statistics_proxy_->OnSetEncoderTargetRate(50000); |
| 566 fake_clock_.AdvanceTimeMilliseconds(7000); |
| 567 statistics_proxy_->OnSetEncoderTargetRate(0); |
| 568 fake_clock_.AdvanceTimeMilliseconds(3000); |
| 569 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop |
| 570 |
| 571 statistics_proxy_.reset(); |
| 572 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents")); |
| 573 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 1)); |
| 574 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent")); |
| 575 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PausedTimeInPercent", 30)); |
| 576 } |
| 577 |
| 578 TEST_F(SendStatisticsProxyTest, TwoPauseEvents) { |
| 579 // First RTP packet sent. |
| 580 UpdateDataCounters(kFirstSsrc); |
| 581 |
| 582 // Three changes. Video: 20000 ms, paused: 1000 ms (5%). |
| 583 statistics_proxy_->OnSetEncoderTargetRate(0); |
| 584 fake_clock_.AdvanceTimeMilliseconds(1000); |
| 585 statistics_proxy_->OnSetEncoderTargetRate(50000); // Starts on bitrate > 0. |
| 586 fake_clock_.AdvanceTimeMilliseconds(7000); |
| 587 statistics_proxy_->OnSetEncoderTargetRate(60000); |
| 588 fake_clock_.AdvanceTimeMilliseconds(3000); |
| 589 statistics_proxy_->OnSetEncoderTargetRate(0); |
| 590 fake_clock_.AdvanceTimeMilliseconds(250); |
| 591 statistics_proxy_->OnSetEncoderTargetRate(0); |
| 592 fake_clock_.AdvanceTimeMilliseconds(750); |
| 593 statistics_proxy_->OnSetEncoderTargetRate(60000); |
| 594 fake_clock_.AdvanceTimeMilliseconds(5000); |
| 595 statistics_proxy_->OnSetEncoderTargetRate(50000); |
| 596 fake_clock_.AdvanceTimeMilliseconds(4000); |
| 597 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop |
| 598 |
| 599 statistics_proxy_.reset(); |
| 600 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents")); |
| 601 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 2)); |
| 602 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent")); |
| 603 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PausedTimeInPercent", 5)); |
| 604 } |
| 605 |
| 606 TEST_F(SendStatisticsProxyTest, |
| 607 PausedTimeHistogramIsNotUpdatedIfMinRuntimeHasNotPassed) { |
| 608 // First RTP packet sent. |
| 609 UpdateDataCounters(kFirstSsrc); |
| 610 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 611 |
| 612 // Min runtime has not passed. |
| 613 statistics_proxy_->OnSetEncoderTargetRate(50000); |
| 614 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1); |
| 615 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop |
| 616 |
| 617 statistics_proxy_.reset(); |
| 618 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent")); |
| 619 } |
| 620 |
507 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) { | 621 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) { |
508 EncodedImage encoded_image; | 622 EncodedImage encoded_image; |
509 CodecSpecificInfo codec_info; | 623 CodecSpecificInfo codec_info; |
510 codec_info.codecType = kVideoCodecVP8; | 624 codec_info.codecType = kVideoCodecVP8; |
511 | 625 |
512 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 626 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
513 codec_info.codecSpecific.VP8.simulcastIdx = 0; | 627 codec_info.codecSpecific.VP8.simulcastIdx = 0; |
514 encoded_image.qp_ = kQpIdx0; | 628 encoded_image.qp_ = kQpIdx0; |
515 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); | 629 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); |
516 codec_info.codecSpecific.VP8.simulcastIdx = 1; | 630 codec_info.codecSpecific.VP8.simulcastIdx = 1; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 // Resolution not scaled. | 837 // Resolution not scaled. |
724 encoded_image.adapt_reason_.bw_resolutions_disabled = 0; | 838 encoded_image.adapt_reason_.bw_resolutions_disabled = 0; |
725 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); | 839 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); |
726 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution); | 840 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution); |
727 // Resolution scaled due to bandwidth. | 841 // Resolution scaled due to bandwidth. |
728 encoded_image.adapt_reason_.bw_resolutions_disabled = 1; | 842 encoded_image.adapt_reason_.bw_resolutions_disabled = 1; |
729 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); | 843 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); |
730 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution); | 844 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution); |
731 } | 845 } |
732 | 846 |
| 847 TEST_F(SendStatisticsProxyTest, GetStatsReportsTargetMediaBitrate) { |
| 848 // Initially zero. |
| 849 EXPECT_EQ(0, statistics_proxy_->GetStats().target_media_bitrate_bps); |
| 850 |
| 851 const int kBitrate = 100000; |
| 852 statistics_proxy_->OnSetEncoderTargetRate(kBitrate); |
| 853 EXPECT_EQ(kBitrate, statistics_proxy_->GetStats().target_media_bitrate_bps); |
| 854 |
| 855 statistics_proxy_->OnSetEncoderTargetRate(0); |
| 856 EXPECT_EQ(0, statistics_proxy_->GetStats().target_media_bitrate_bps); |
| 857 } |
| 858 |
733 TEST_F(SendStatisticsProxyTest, NoSubstreams) { | 859 TEST_F(SendStatisticsProxyTest, NoSubstreams) { |
734 uint32_t excluded_ssrc = | 860 uint32_t excluded_ssrc = |
735 std::max( | 861 std::max( |
736 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), | 862 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), |
737 *std::max_element(config_.rtp.rtx.ssrcs.begin(), | 863 *std::max_element(config_.rtp.rtx.ssrcs.begin(), |
738 config_.rtp.rtx.ssrcs.end())) + | 864 config_.rtp.rtx.ssrcs.end())) + |
739 1; | 865 1; |
740 // From RtcpStatisticsCallback. | 866 // From RtcpStatisticsCallback. |
741 RtcpStatistics rtcp_stats; | 867 RtcpStatistics rtcp_stats; |
742 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); | 868 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 | 1289 |
1164 EXPECT_EQ( | 1290 EXPECT_EQ( |
1165 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); | 1291 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); |
1166 EXPECT_EQ(1, metrics::NumEvents( | 1292 EXPECT_EQ(1, metrics::NumEvents( |
1167 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", | 1293 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", |
1168 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) / | 1294 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) / |
1169 metrics::kMinRunTimeInSeconds / 1000))); | 1295 metrics::kMinRunTimeInSeconds / 1000))); |
1170 } | 1296 } |
1171 | 1297 |
1172 } // namespace webrtc | 1298 } // namespace webrtc |
OLD | NEW |