OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/video/receive_statistics_proxy.h" |
| 12 |
| 13 #include <memory> |
| 14 |
| 15 #include "webrtc/system_wrappers/include/metrics_default.h" |
| 16 #include "webrtc/test/gtest.h" |
| 17 |
| 18 namespace webrtc { |
| 19 namespace { |
| 20 const uint32_t kLocalSsrc = 123; |
| 21 const uint32_t kRemoteSsrc = 456; |
| 22 const int kMinRequiredSamples = 200; |
| 23 const int64_t kFreqOffsetProcessIntervalInMs = 40000; |
| 24 } // namespace |
| 25 |
| 26 class ReceiveStatisticsProxyTest : public ::testing::Test { |
| 27 public: |
| 28 ReceiveStatisticsProxyTest() : clock_(1234), config_(GetTestConfig()) {} |
| 29 virtual ~ReceiveStatisticsProxyTest() {} |
| 30 |
| 31 protected: |
| 32 virtual void SetUp() { |
| 33 metrics::Reset(); |
| 34 statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &clock_)); |
| 35 } |
| 36 |
| 37 VideoReceiveStream::Config GetTestConfig() { |
| 38 VideoReceiveStream::Config config(nullptr); |
| 39 config.rtp.local_ssrc = kLocalSsrc; |
| 40 config.rtp.remote_ssrc = kRemoteSsrc; |
| 41 return config; |
| 42 } |
| 43 |
| 44 SimulatedClock clock_; |
| 45 const VideoReceiveStream::Config config_; |
| 46 std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_; |
| 47 }; |
| 48 |
| 49 TEST_F(ReceiveStatisticsProxyTest, GetStats_VerifySsrc) { |
| 50 EXPECT_EQ(kRemoteSsrc, statistics_proxy_->GetStats().ssrc); |
| 51 } |
| 52 |
| 53 TEST_F(ReceiveStatisticsProxyTest, GetStats_VerifyPayloadType) { |
| 54 const int kPayloadType = 111; |
| 55 statistics_proxy_->OnIncomingPayloadType(kPayloadType); |
| 56 EXPECT_EQ(kPayloadType, statistics_proxy_->GetStats().current_payload_type); |
| 57 } |
| 58 |
| 59 TEST_F(ReceiveStatisticsProxyTest, GetStats_VerifyDiscardedPackets) { |
| 60 const int kDiscardedPackets = 12; |
| 61 statistics_proxy_->OnDiscardedPacketsUpdated(kDiscardedPackets); |
| 62 EXPECT_EQ(kDiscardedPackets, statistics_proxy_->GetStats().discarded_packets); |
| 63 } |
| 64 |
| 65 TEST_F(ReceiveStatisticsProxyTest, GetStats_VerifyDecodeTimingStats) { |
| 66 const int kDecodeMs = 1; |
| 67 const int kMaxDecodeMs = 2; |
| 68 const int kCurrentDelayMs = 3; |
| 69 const int kTargetDelayMs = 4; |
| 70 const int kJitterBufferMs = 5; |
| 71 const int kMinPlayoutDelayMs = 6; |
| 72 const int kRenderDelayMs = 7; |
| 73 const int64_t kRttMs = 8; |
| 74 statistics_proxy_->OnDecoderTiming( |
| 75 kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs, kJitterBufferMs, |
| 76 kMinPlayoutDelayMs, kRenderDelayMs, kRttMs); |
| 77 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats(); |
| 78 EXPECT_EQ(kDecodeMs, stats.decode_ms); |
| 79 EXPECT_EQ(kMaxDecodeMs, stats.max_decode_ms); |
| 80 EXPECT_EQ(kCurrentDelayMs, stats.current_delay_ms); |
| 81 EXPECT_EQ(kTargetDelayMs, stats.target_delay_ms); |
| 82 EXPECT_EQ(kJitterBufferMs, stats.jitter_buffer_ms); |
| 83 EXPECT_EQ(kMinPlayoutDelayMs, stats.min_playout_delay_ms); |
| 84 EXPECT_EQ(kRenderDelayMs, stats.render_delay_ms); |
| 85 } |
| 86 |
| 87 TEST_F(ReceiveStatisticsProxyTest, LifetimeHistogramIsUpdated) { |
| 88 const int64_t kTimeSec = 3; |
| 89 clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); |
| 90 statistics_proxy_.reset(); |
| 91 EXPECT_EQ(1, |
| 92 metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds")); |
| 93 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds", |
| 94 kTimeSec)); |
| 95 } |
| 96 |
| 97 TEST_F(ReceiveStatisticsProxyTest, AvSyncOffsetHistogramIsUpdated) { |
| 98 const int64_t kSyncOffsetMs = 22; |
| 99 const double kFreqKhz = 90.0; |
| 100 for (int i = 0; i < kMinRequiredSamples; ++i) |
| 101 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 102 |
| 103 statistics_proxy_.reset(); |
| 104 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs")); |
| 105 EXPECT_EQ(1, |
| 106 metrics::NumEvents("WebRTC.Video.AVSyncOffsetInMs", kSyncOffsetMs)); |
| 107 } |
| 108 |
| 109 TEST_F(ReceiveStatisticsProxyTest, RtpToNtpFrequencyOffsetHistogramIsUpdated) { |
| 110 const int64_t kSyncOffsetMs = 22; |
| 111 const double kFreqKhz = 90.0; |
| 112 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 113 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 2.2); |
| 114 clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); |
| 115 // Process interval passed, max diff: 2. |
| 116 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 1.1); |
| 117 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 4.2); |
| 118 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 0.9); |
| 119 clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); |
| 120 // Process interval passed, max diff: 4. |
| 121 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 122 statistics_proxy_.reset(); |
| 123 // Average reported: (2 + 4) / 2 = 3. |
| 124 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz")); |
| 125 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3)); |
| 126 } |
| 127 |
| 128 } // namespace webrtc |
OLD | NEW |