Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: webrtc/video/send_statistics_proxy_unittest.cc

Issue 2530393003: Move histogram for number of pause events to per stream. (Closed)
Patch Set: fix comment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/send_statistics_proxy.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
535 }
536
537 TEST_F(SendStatisticsProxyTest,
538 PauseEventHistogramIsNotUpdatedIfNoMediaIsSent) {
539 // First RTP packet not sent.
540 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
541 statistics_proxy_.reset();
542 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
543 }
544
545 TEST_F(SendStatisticsProxyTest, NoPauseEvent) {
546 // First RTP packet sent and min runtime passed.
547 UpdateDataCounters(kFirstSsrc);
548
549 // No change. Video: 10000 ms, paused: 0 ms (0%).
550 statistics_proxy_->OnSetEncoderTargetRate(50000);
551 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
552 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop
553
554 statistics_proxy_.reset();
555 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
556 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 0));
557 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
558 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PausedTimeInPercent", 0));
559 }
560
561 TEST_F(SendStatisticsProxyTest, OnePauseEvent) {
562 // First RTP packet sent and min runtime passed.
563 UpdateDataCounters(kFirstSsrc);
564
565 // One change. Video: 7000 ms, paused: 3000 ms (30%).
566 statistics_proxy_->OnSetEncoderTargetRate(50000);
567 fake_clock_.AdvanceTimeMilliseconds(7000);
568 statistics_proxy_->OnSetEncoderTargetRate(0);
569 fake_clock_.AdvanceTimeMilliseconds(3000);
570 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop
571
572 statistics_proxy_.reset();
573 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
574 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 1));
575 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
576 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PausedTimeInPercent", 30));
577 }
578
579 TEST_F(SendStatisticsProxyTest, TwoPauseEvents) {
580 // First RTP packet sent.
581 UpdateDataCounters(kFirstSsrc);
582
583 // Two changes. Video: 19000 ms, paused: 1000 ms (5%).
584 statistics_proxy_->OnSetEncoderTargetRate(0);
585 fake_clock_.AdvanceTimeMilliseconds(1000);
586 statistics_proxy_->OnSetEncoderTargetRate(50000); // Starts on bitrate > 0.
587 fake_clock_.AdvanceTimeMilliseconds(7000);
588 statistics_proxy_->OnSetEncoderTargetRate(60000);
589 fake_clock_.AdvanceTimeMilliseconds(3000);
590 statistics_proxy_->OnSetEncoderTargetRate(0);
591 fake_clock_.AdvanceTimeMilliseconds(250);
592 statistics_proxy_->OnSetEncoderTargetRate(0);
593 fake_clock_.AdvanceTimeMilliseconds(750);
594 statistics_proxy_->OnSetEncoderTargetRate(60000);
595 fake_clock_.AdvanceTimeMilliseconds(5000);
596 statistics_proxy_->OnSetEncoderTargetRate(50000);
597 fake_clock_.AdvanceTimeMilliseconds(4000);
598 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop
599
600 statistics_proxy_.reset();
601 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
602 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 2));
603 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
604 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PausedTimeInPercent", 5));
605 }
606
607 TEST_F(SendStatisticsProxyTest,
608 PausedTimeHistogramIsNotUpdatedIfMinRuntimeHasNotPassed) {
609 // First RTP packet sent.
610 UpdateDataCounters(kFirstSsrc);
611 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
612
613 // Min runtime has not passed.
614 statistics_proxy_->OnSetEncoderTargetRate(50000);
615 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1);
616 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop
617
618 statistics_proxy_.reset();
619 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
620 }
621
507 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) { 622 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) {
508 EncodedImage encoded_image; 623 EncodedImage encoded_image;
509 CodecSpecificInfo codec_info; 624 CodecSpecificInfo codec_info;
510 codec_info.codecType = kVideoCodecVP8; 625 codec_info.codecType = kVideoCodecVP8;
511 626
512 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { 627 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
513 codec_info.codecSpecific.VP8.simulcastIdx = 0; 628 codec_info.codecSpecific.VP8.simulcastIdx = 0;
514 encoded_image.qp_ = kQpIdx0; 629 encoded_image.qp_ = kQpIdx0;
515 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); 630 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
516 codec_info.codecSpecific.VP8.simulcastIdx = 1; 631 codec_info.codecSpecific.VP8.simulcastIdx = 1;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 // Resolution not scaled. 838 // Resolution not scaled.
724 encoded_image.adapt_reason_.bw_resolutions_disabled = 0; 839 encoded_image.adapt_reason_.bw_resolutions_disabled = 0;
725 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); 840 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
726 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution); 841 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution);
727 // Resolution scaled due to bandwidth. 842 // Resolution scaled due to bandwidth.
728 encoded_image.adapt_reason_.bw_resolutions_disabled = 1; 843 encoded_image.adapt_reason_.bw_resolutions_disabled = 1;
729 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); 844 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
730 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution); 845 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution);
731 } 846 }
732 847
848 TEST_F(SendStatisticsProxyTest, GetStatsReportsTargetMediaBitrate) {
849 // Initially zero.
850 EXPECT_EQ(0, statistics_proxy_->GetStats().target_media_bitrate_bps);
851
852 const int kBitrate = 100000;
853 statistics_proxy_->OnSetEncoderTargetRate(kBitrate);
854 EXPECT_EQ(kBitrate, statistics_proxy_->GetStats().target_media_bitrate_bps);
855
856 statistics_proxy_->OnSetEncoderTargetRate(0);
857 EXPECT_EQ(0, statistics_proxy_->GetStats().target_media_bitrate_bps);
858 }
859
733 TEST_F(SendStatisticsProxyTest, NoSubstreams) { 860 TEST_F(SendStatisticsProxyTest, NoSubstreams) {
734 uint32_t excluded_ssrc = 861 uint32_t excluded_ssrc =
735 std::max( 862 std::max(
736 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), 863 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()),
737 *std::max_element(config_.rtp.rtx.ssrcs.begin(), 864 *std::max_element(config_.rtp.rtx.ssrcs.begin(),
738 config_.rtp.rtx.ssrcs.end())) + 865 config_.rtp.rtx.ssrcs.end())) +
739 1; 866 1;
740 // From RtcpStatisticsCallback. 867 // From RtcpStatisticsCallback.
741 RtcpStatistics rtcp_stats; 868 RtcpStatistics rtcp_stats;
742 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); 869 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get();
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 1290
1164 EXPECT_EQ( 1291 EXPECT_EQ(
1165 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); 1292 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps"));
1166 EXPECT_EQ(1, metrics::NumEvents( 1293 EXPECT_EQ(1, metrics::NumEvents(
1167 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", 1294 "WebRTC.Video.Screenshare.FecBitrateSentInKbps",
1168 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) / 1295 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) /
1169 metrics::kMinRunTimeInSeconds / 1000))); 1296 metrics::kMinRunTimeInSeconds / 1000)));
1170 } 1297 }
1171 1298
1172 } // namespace webrtc 1299 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/send_statistics_proxy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698