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/test/histogram.h" | |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
22 namespace { | |
23 const int64_t kMaxPacketDelayMs = 11000; | |
24 } // namespace | |
21 | 25 |
22 class SendStatisticsProxyTest : public ::testing::Test { | 26 class SendStatisticsProxyTest : public ::testing::Test { |
23 public: | 27 public: |
24 SendStatisticsProxyTest() | 28 SendStatisticsProxyTest() |
25 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), | 29 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), |
26 max_delay_ms_(0) {} | 30 max_delay_ms_(0) {} |
27 virtual ~SendStatisticsProxyTest() {} | 31 virtual ~SendStatisticsProxyTest() {} |
28 | 32 |
29 protected: | 33 protected: |
30 virtual void SetUp() { | 34 virtual void SetUp() { |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 int avg_delay_ms = ssrc; | 284 int avg_delay_ms = ssrc; |
281 int max_delay_ms = ssrc + 1; | 285 int max_delay_ms = ssrc + 1; |
282 observer->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, ssrc); | 286 observer->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, ssrc); |
283 expected_.substreams[ssrc].avg_delay_ms = avg_delay_ms; | 287 expected_.substreams[ssrc].avg_delay_ms = avg_delay_ms; |
284 expected_.substreams[ssrc].max_delay_ms = max_delay_ms; | 288 expected_.substreams[ssrc].max_delay_ms = max_delay_ms; |
285 } | 289 } |
286 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 290 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
287 ExpectEqual(expected_, stats); | 291 ExpectEqual(expected_, stats); |
288 } | 292 } |
289 | 293 |
294 TEST_F(SendStatisticsProxyTest, VerifySendDelayStats) { | |
295 const int64_t kSendDelayInMs = 5; | |
296 const size_t kMinRequiredSamples = 200; | |
297 test::ClearHistograms(); | |
298 SendPacketObserver* observer = statistics_proxy_.get(); | |
299 const uint32_t ssrc = *config_.rtp.ssrcs.begin(); | |
300 | |
301 uint16_t packet_id = 0; | |
302 for (size_t i = 0; i < kMinRequiredSamples; ++i) { | |
303 observer->OnSendPacket(++packet_id, fake_clock_.TimeInMilliseconds(), ssrc); | |
304 // Packet sent. | |
305 fake_clock_.AdvanceTimeMilliseconds(kSendDelayInMs); | |
306 EXPECT_TRUE(statistics_proxy_->OnSentPacket(packet_id)); | |
307 } | |
308 statistics_proxy_.reset(); | |
309 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.SendDelayInMs")); | |
310 EXPECT_EQ(kSendDelayInMs, | |
311 test::LastHistogramSample("WebRTC.Video.SendDelayInMs")); | |
312 } | |
313 | |
314 TEST_F(SendStatisticsProxyTest, OnSendPacket) { | |
315 const uint16_t kPacketId = 2345; | |
316 SendPacketObserver* observer = statistics_proxy_.get(); | |
317 const uint32_t ssrc = *config_.rtp.ssrcs.begin(); | |
318 | |
319 observer->OnSendPacket(kPacketId, fake_clock_.TimeInMilliseconds(), ssrc); | |
320 fake_clock_.AdvanceTimeMilliseconds(kMaxPacketDelayMs - 1); | |
321 observer->OnSendPacket(kPacketId + 1, fake_clock_.TimeInMilliseconds(), ssrc); | |
322 | |
323 EXPECT_TRUE(statistics_proxy_->OnSentPacket(kPacketId)); | |
324 EXPECT_TRUE(statistics_proxy_->OnSentPacket(kPacketId + 1)); | |
325 // Packets removed. | |
326 EXPECT_FALSE(statistics_proxy_->OnSentPacket(kPacketId)); | |
pbos-webrtc
2015/12/07 06:05:52
This can be called more than once right? If this i
åsapersson
2015/12/08 12:50:15
OnSentPacket should only be called from talk.
| |
327 EXPECT_FALSE(statistics_proxy_->OnSentPacket(kPacketId + 1)); | |
328 } | |
329 | |
330 TEST_F(SendStatisticsProxyTest, OnSendPacket_RemoveOldWithWrap) { | |
331 SendPacketObserver* observer = statistics_proxy_.get(); | |
332 const uint32_t ssrc = *config_.rtp.ssrcs.begin(); | |
333 | |
334 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | |
335 observer->OnSendPacket(0xFFFFu, capture_time_ms, ssrc); | |
336 observer->OnSendPacket(0u, capture_time_ms, ssrc); | |
337 observer->OnSendPacket(1u, capture_time_ms + 1, ssrc); | |
338 fake_clock_.AdvanceTimeMilliseconds(kMaxPacketDelayMs); | |
339 observer->OnSendPacket(2u, capture_time_ms + 2, ssrc); | |
340 | |
341 EXPECT_FALSE(statistics_proxy_->OnSentPacket(0xFFFFu)); // Old removed. | |
342 EXPECT_FALSE(statistics_proxy_->OnSentPacket(0u)); // Old removed. | |
343 EXPECT_TRUE(statistics_proxy_->OnSentPacket(1u)); | |
344 EXPECT_TRUE(statistics_proxy_->OnSentPacket(2u)); | |
345 } | |
346 | |
290 TEST_F(SendStatisticsProxyTest, NoSubstreams) { | 347 TEST_F(SendStatisticsProxyTest, NoSubstreams) { |
291 uint32_t excluded_ssrc = | 348 uint32_t excluded_ssrc = |
292 std::max( | 349 std::max( |
293 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), | 350 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), |
294 *std::max_element(config_.rtp.rtx.ssrcs.begin(), | 351 *std::max_element(config_.rtp.rtx.ssrcs.begin(), |
295 config_.rtp.rtx.ssrcs.end())) + | 352 config_.rtp.rtx.ssrcs.end())) + |
296 1; | 353 1; |
297 // From RtcpStatisticsCallback. | 354 // From RtcpStatisticsCallback. |
298 RtcpStatistics rtcp_stats; | 355 RtcpStatistics rtcp_stats; |
299 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); | 356 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 453 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
397 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 454 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
398 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); | 455 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); |
399 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 456 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
400 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); | 457 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); |
401 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); | 458 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); |
402 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); | 459 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); |
403 } | 460 } |
404 | 461 |
405 } // namespace webrtc | 462 } // namespace webrtc |
OLD | NEW |