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 |
11 // This file includes unit tests for SendStatisticsProxy. | 11 // This file includes unit tests for SendStatisticsProxy. |
12 #include "webrtc/video/send_statistics_proxy.h" | 12 #include "webrtc/video/send_statistics_proxy.h" |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "webrtc/system_wrappers/include/metrics.h" |
19 #include "webrtc/test/histogram.h" | 20 #include "webrtc/test/histogram.h" |
20 | 21 |
21 namespace webrtc { | 22 namespace webrtc { |
22 | 23 |
| 24 static const uint32_t kFirstSsrc = 17; |
| 25 static const uint32_t kSecondSsrc = 42; |
| 26 static const uint32_t kFirstRtxSsrc = 18; |
| 27 static const uint32_t kSecondRtxSsrc = 43; |
| 28 |
23 class SendStatisticsProxyTest : public ::testing::Test { | 29 class SendStatisticsProxyTest : public ::testing::Test { |
24 public: | 30 public: |
25 SendStatisticsProxyTest() | 31 SendStatisticsProxyTest() |
26 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), | 32 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), |
27 max_delay_ms_(0) {} | 33 max_delay_ms_(0) {} |
28 virtual ~SendStatisticsProxyTest() {} | 34 virtual ~SendStatisticsProxyTest() {} |
29 | 35 |
30 protected: | 36 protected: |
31 virtual void SetUp() { | 37 virtual void SetUp() { |
32 statistics_proxy_.reset(new SendStatisticsProxy( | 38 statistics_proxy_.reset(new SendStatisticsProxy( |
33 &fake_clock_, GetTestConfig(), | 39 &fake_clock_, GetTestConfig(), |
34 VideoEncoderConfig::ContentType::kRealtimeVideo)); | 40 VideoEncoderConfig::ContentType::kRealtimeVideo)); |
35 expected_ = VideoSendStream::Stats(); | 41 expected_ = VideoSendStream::Stats(); |
36 } | 42 } |
37 | 43 |
38 VideoSendStream::Config GetTestConfig() { | 44 VideoSendStream::Config GetTestConfig() { |
39 VideoSendStream::Config config(nullptr); | 45 VideoSendStream::Config config(nullptr); |
40 config.rtp.ssrcs.push_back(17); | 46 config.rtp.ssrcs.push_back(kFirstSsrc); |
41 config.rtp.ssrcs.push_back(42); | 47 config.rtp.ssrcs.push_back(kSecondSsrc); |
42 config.rtp.rtx.ssrcs.push_back(18); | 48 config.rtp.rtx.ssrcs.push_back(kFirstRtxSsrc); |
43 config.rtp.rtx.ssrcs.push_back(43); | 49 config.rtp.rtx.ssrcs.push_back(kSecondRtxSsrc); |
44 return config; | 50 return config; |
45 } | 51 } |
46 | 52 |
47 void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) { | 53 void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) { |
48 EXPECT_EQ(one.input_frame_rate, other.input_frame_rate); | 54 EXPECT_EQ(one.input_frame_rate, other.input_frame_rate); |
49 EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate); | 55 EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate); |
50 EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps); | 56 EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps); |
51 EXPECT_EQ(one.suspended, other.suspended); | 57 EXPECT_EQ(one.suspended, other.suspended); |
52 | 58 |
53 EXPECT_EQ(one.substreams.size(), other.substreams.size()); | 59 EXPECT_EQ(one.substreams.size(), other.substreams.size()); |
(...skipping 25 matching lines...) Expand all Loading... |
79 EXPECT_EQ(a.rtp_stats.fec.packets, b.rtp_stats.fec.packets); | 85 EXPECT_EQ(a.rtp_stats.fec.packets, b.rtp_stats.fec.packets); |
80 | 86 |
81 EXPECT_EQ(a.rtcp_stats.fraction_lost, b.rtcp_stats.fraction_lost); | 87 EXPECT_EQ(a.rtcp_stats.fraction_lost, b.rtcp_stats.fraction_lost); |
82 EXPECT_EQ(a.rtcp_stats.cumulative_lost, b.rtcp_stats.cumulative_lost); | 88 EXPECT_EQ(a.rtcp_stats.cumulative_lost, b.rtcp_stats.cumulative_lost); |
83 EXPECT_EQ(a.rtcp_stats.extended_max_sequence_number, | 89 EXPECT_EQ(a.rtcp_stats.extended_max_sequence_number, |
84 b.rtcp_stats.extended_max_sequence_number); | 90 b.rtcp_stats.extended_max_sequence_number); |
85 EXPECT_EQ(a.rtcp_stats.jitter, b.rtcp_stats.jitter); | 91 EXPECT_EQ(a.rtcp_stats.jitter, b.rtcp_stats.jitter); |
86 } | 92 } |
87 } | 93 } |
88 | 94 |
| 95 SimulatedClock fake_clock_; |
89 rtc::scoped_ptr<SendStatisticsProxy> statistics_proxy_; | 96 rtc::scoped_ptr<SendStatisticsProxy> statistics_proxy_; |
90 SimulatedClock fake_clock_; | |
91 VideoSendStream::Config config_; | 97 VideoSendStream::Config config_; |
92 int avg_delay_ms_; | 98 int avg_delay_ms_; |
93 int max_delay_ms_; | 99 int max_delay_ms_; |
94 VideoSendStream::Stats expected_; | 100 VideoSendStream::Stats expected_; |
95 typedef std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator | 101 typedef std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator |
96 StreamIterator; | 102 StreamIterator; |
97 }; | 103 }; |
98 | 104 |
99 TEST_F(SendStatisticsProxyTest, RtcpStatistics) { | 105 TEST_F(SendStatisticsProxyTest, RtcpStatistics) { |
100 RtcpStatisticsCallback* callback = statistics_proxy_.get(); | 106 RtcpStatisticsCallback* callback = statistics_proxy_.get(); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 433 |
428 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 434 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
429 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 435 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
430 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); | 436 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); |
431 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 437 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
432 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); | 438 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); |
433 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); | 439 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); |
434 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); | 440 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); |
435 } | 441 } |
436 | 442 |
| 443 TEST_F(SendStatisticsProxyTest, ResetsRtcpCountersOnContentChange) { |
| 444 RtcpPacketTypeCounterObserver* proxy = |
| 445 static_cast<RtcpPacketTypeCounterObserver*>(statistics_proxy_.get()); |
| 446 RtcpPacketTypeCounter counters; |
| 447 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds(); |
| 448 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters); |
| 449 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters); |
| 450 |
| 451 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds); |
| 452 |
| 453 counters.nack_packets += 1 * metrics::kMinRunTimeInSeconds; |
| 454 counters.fir_packets += 2 * metrics::kMinRunTimeInSeconds; |
| 455 counters.pli_packets += 3 * metrics::kMinRunTimeInSeconds; |
| 456 counters.unique_nack_requests += 4 * metrics::kMinRunTimeInSeconds; |
| 457 counters.nack_requests += 5 * metrics::kMinRunTimeInSeconds; |
| 458 |
| 459 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters); |
| 460 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters); |
| 461 |
| 462 // Changing content type causes histograms to be reported. |
| 463 statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen); |
| 464 |
| 465 EXPECT_EQ(1, test::NumHistogramSamples( |
| 466 "WebRTC.Video.NackPacketsReceivedPerMinute")); |
| 467 EXPECT_EQ( |
| 468 1, test::NumHistogramSamples("WebRTC.Video.FirPacketsReceivedPerMinute")); |
| 469 EXPECT_EQ( |
| 470 1, test::NumHistogramSamples("WebRTC.Video.PliPacketsReceivedPerMinute")); |
| 471 EXPECT_EQ(1, test::NumHistogramSamples( |
| 472 "WebRTC.Video.UniqueNackRequestsReceivedInPercent")); |
| 473 |
| 474 const int kRate = 60 * 2; // Packets per minute with two streams. |
| 475 |
| 476 EXPECT_EQ(1 * kRate, test::LastHistogramSample( |
| 477 "WebRTC.Video.NackPacketsReceivedPerMinute")); |
| 478 EXPECT_EQ(2 * kRate, test::LastHistogramSample( |
| 479 "WebRTC.Video.FirPacketsReceivedPerMinute")); |
| 480 EXPECT_EQ(3 * kRate, test::LastHistogramSample( |
| 481 "WebRTC.Video.PliPacketsReceivedPerMinute")); |
| 482 EXPECT_EQ(4 * 100 / 5, |
| 483 test::LastHistogramSample( |
| 484 "WebRTC.Video.UniqueNackRequestsReceivedInPercent")); |
| 485 |
| 486 // New start time but same counter values. |
| 487 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters); |
| 488 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters); |
| 489 |
| 490 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds); |
| 491 |
| 492 counters.nack_packets += 1 * metrics::kMinRunTimeInSeconds; |
| 493 counters.fir_packets += 2 * metrics::kMinRunTimeInSeconds; |
| 494 counters.pli_packets += 3 * metrics::kMinRunTimeInSeconds; |
| 495 counters.unique_nack_requests += 4 * metrics::kMinRunTimeInSeconds; |
| 496 counters.nack_requests += 5 * metrics::kMinRunTimeInSeconds; |
| 497 |
| 498 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters); |
| 499 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters); |
| 500 |
| 501 SetUp(); // Reset stats proxy also causes histograms to be reported. |
| 502 |
| 503 EXPECT_EQ(1, test::NumHistogramSamples( |
| 504 "WebRTC.Video.Screenshare.NackPacketsReceivedPerMinute")); |
| 505 EXPECT_EQ(1, test::NumHistogramSamples( |
| 506 "WebRTC.Video.Screenshare.FirPacketsReceivedPerMinute")); |
| 507 EXPECT_EQ(1, test::NumHistogramSamples( |
| 508 "WebRTC.Video.Screenshare.PliPacketsReceivedPerMinute")); |
| 509 EXPECT_EQ( |
| 510 1, test::NumHistogramSamples( |
| 511 "WebRTC.Video.Screenshare.UniqueNackRequestsReceivedInPercent")); |
| 512 |
| 513 EXPECT_EQ(1 * kRate, |
| 514 test::LastHistogramSample( |
| 515 "WebRTC.Video.Screenshare.NackPacketsReceivedPerMinute")); |
| 516 EXPECT_EQ(2 * kRate, |
| 517 test::LastHistogramSample( |
| 518 "WebRTC.Video.Screenshare.FirPacketsReceivedPerMinute")); |
| 519 EXPECT_EQ(3 * kRate, |
| 520 test::LastHistogramSample( |
| 521 "WebRTC.Video.Screenshare.PliPacketsReceivedPerMinute")); |
| 522 EXPECT_EQ( |
| 523 4 * 100 / 5, |
| 524 test::LastHistogramSample( |
| 525 "WebRTC.Video.Screenshare.UniqueNackRequestsReceivedInPercent")); |
| 526 } |
| 527 |
437 } // namespace webrtc | 528 } // namespace webrtc |
OLD | NEW |