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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 int avg_delay_ms = ssrc; | 285 int avg_delay_ms = ssrc; |
282 int max_delay_ms = ssrc + 1; | 286 int max_delay_ms = ssrc + 1; |
283 observer->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, ssrc); | 287 observer->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, ssrc); |
284 expected_.substreams[ssrc].avg_delay_ms = avg_delay_ms; | 288 expected_.substreams[ssrc].avg_delay_ms = avg_delay_ms; |
285 expected_.substreams[ssrc].max_delay_ms = max_delay_ms; | 289 expected_.substreams[ssrc].max_delay_ms = max_delay_ms; |
286 } | 290 } |
287 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 291 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
288 ExpectEqual(expected_, stats); | 292 ExpectEqual(expected_, stats); |
289 } | 293 } |
290 | 294 |
| 295 TEST_F(SendStatisticsProxyTest, VerifySendDelayStats) { |
| 296 const int64_t kSendDelayInMs = 5; |
| 297 const size_t kMinRequiredSamples = 200; |
| 298 test::ClearHistograms(); |
| 299 SendPacketObserver* observer = statistics_proxy_.get(); |
| 300 const uint32_t ssrc = *config_.rtp.ssrcs.begin(); |
| 301 |
| 302 uint16_t packet_id = 0; |
| 303 for (size_t i = 0; i < kMinRequiredSamples; ++i) { |
| 304 observer->OnSendPacket(++packet_id, fake_clock_.TimeInMilliseconds(), ssrc); |
| 305 // Packet sent. |
| 306 fake_clock_.AdvanceTimeMilliseconds(kSendDelayInMs); |
| 307 EXPECT_TRUE(statistics_proxy_->OnSentPacket(packet_id)); |
| 308 } |
| 309 statistics_proxy_.reset(); |
| 310 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.SendDelayInMs")); |
| 311 EXPECT_EQ(kSendDelayInMs, |
| 312 test::LastHistogramSample("WebRTC.Video.SendDelayInMs")); |
| 313 } |
| 314 |
| 315 TEST_F(SendStatisticsProxyTest, OnSendPacket) { |
| 316 const uint16_t kPacketId = 2345; |
| 317 SendPacketObserver* observer = statistics_proxy_.get(); |
| 318 const uint32_t ssrc = *config_.rtp.ssrcs.begin(); |
| 319 |
| 320 observer->OnSendPacket(kPacketId, fake_clock_.TimeInMilliseconds(), ssrc); |
| 321 fake_clock_.AdvanceTimeMilliseconds(kMaxPacketDelayMs - 1); |
| 322 observer->OnSendPacket(kPacketId + 1, fake_clock_.TimeInMilliseconds(), ssrc); |
| 323 |
| 324 EXPECT_TRUE(statistics_proxy_->OnSentPacket(kPacketId)); |
| 325 EXPECT_TRUE(statistics_proxy_->OnSentPacket(kPacketId + 1)); |
| 326 // Packets removed. |
| 327 EXPECT_FALSE(statistics_proxy_->OnSentPacket(kPacketId)); |
| 328 EXPECT_FALSE(statistics_proxy_->OnSentPacket(kPacketId + 1)); |
| 329 } |
| 330 |
| 331 TEST_F(SendStatisticsProxyTest, OnSendPacket_RemoveOldWithWrap) { |
| 332 SendPacketObserver* observer = statistics_proxy_.get(); |
| 333 const uint32_t ssrc = *config_.rtp.ssrcs.begin(); |
| 334 |
| 335 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 336 observer->OnSendPacket(0xFFFFu, capture_time_ms, ssrc); |
| 337 observer->OnSendPacket(0u, capture_time_ms, ssrc); |
| 338 observer->OnSendPacket(1u, capture_time_ms + 1, ssrc); |
| 339 fake_clock_.AdvanceTimeMilliseconds(kMaxPacketDelayMs); |
| 340 observer->OnSendPacket(2u, capture_time_ms + 2, ssrc); |
| 341 |
| 342 EXPECT_FALSE(statistics_proxy_->OnSentPacket(0xFFFFu)); // Old removed. |
| 343 EXPECT_FALSE(statistics_proxy_->OnSentPacket(0u)); // Old removed. |
| 344 EXPECT_TRUE(statistics_proxy_->OnSentPacket(1u)); |
| 345 EXPECT_TRUE(statistics_proxy_->OnSentPacket(2u)); |
| 346 } |
| 347 |
291 TEST_F(SendStatisticsProxyTest, OnEncodedFrame) { | 348 TEST_F(SendStatisticsProxyTest, OnEncodedFrame) { |
292 const int kEncodeTimeMs = 11; | 349 const int kEncodeTimeMs = 11; |
293 statistics_proxy_->OnEncodedFrame(kEncodeTimeMs); | 350 statistics_proxy_->OnEncodedFrame(kEncodeTimeMs); |
294 | 351 |
295 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 352 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
296 EXPECT_EQ(kEncodeTimeMs, stats.avg_encode_time_ms); | 353 EXPECT_EQ(kEncodeTimeMs, stats.avg_encode_time_ms); |
297 } | 354 } |
298 | 355 |
299 TEST_F(SendStatisticsProxyTest, NoSubstreams) { | 356 TEST_F(SendStatisticsProxyTest, NoSubstreams) { |
300 uint32_t excluded_ssrc = | 357 uint32_t excluded_ssrc = |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 462 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
406 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 463 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
407 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); | 464 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); |
408 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 465 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
409 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); | 466 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); |
410 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); | 467 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); |
411 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); | 468 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); |
412 } | 469 } |
413 | 470 |
414 } // namespace webrtc | 471 } // namespace webrtc |
OLD | NEW |