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 #include "webrtc/video/send_statistics_proxy.h" | 11 #include "webrtc/video/send_statistics_proxy.h" |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/system_wrappers/include/metrics.h" | 18 #include "webrtc/system_wrappers/include/metrics.h" |
19 #include "webrtc/system_wrappers/include/metrics_default.h" | 19 #include "webrtc/system_wrappers/include/metrics_default.h" |
20 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 namespace { | 23 namespace { |
24 const uint32_t kFirstSsrc = 17; | 24 const uint32_t kFirstSsrc = 17; |
25 const uint32_t kSecondSsrc = 42; | 25 const uint32_t kSecondSsrc = 42; |
26 const uint32_t kFirstRtxSsrc = 18; | 26 const uint32_t kFirstRtxSsrc = 18; |
27 const uint32_t kSecondRtxSsrc = 43; | 27 const uint32_t kSecondRtxSsrc = 43; |
28 const uint32_t kFlexFecSsrc = 55; | 28 const uint32_t kFlexFecSsrc = 55; |
29 | 29 const int kFpsPeriodicIntervalMs = 2000; |
| 30 const int kWidth = 640; |
| 31 const int kHeight = 480; |
30 const int kQpIdx0 = 21; | 32 const int kQpIdx0 = 21; |
31 const int kQpIdx1 = 39; | 33 const int kQpIdx1 = 39; |
32 } // namespace | 34 } // namespace |
33 | 35 |
34 class SendStatisticsProxyTest : public ::testing::Test { | 36 class SendStatisticsProxyTest : public ::testing::Test { |
35 public: | 37 public: |
36 SendStatisticsProxyTest() | 38 SendStatisticsProxyTest() |
37 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), | 39 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), |
38 max_delay_ms_(0) {} | 40 max_delay_ms_(0) {} |
39 virtual ~SendStatisticsProxyTest() {} | 41 virtual ~SendStatisticsProxyTest() {} |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 TEST_F(SendStatisticsProxyTest, OnSendEncodedImageWithoutQpQpSumWontExist) { | 348 TEST_F(SendStatisticsProxyTest, OnSendEncodedImageWithoutQpQpSumWontExist) { |
347 EncodedImage encoded_image; | 349 EncodedImage encoded_image; |
348 CodecSpecificInfo codec_info; | 350 CodecSpecificInfo codec_info; |
349 encoded_image.qp_ = -1; | 351 encoded_image.qp_ = -1; |
350 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum); | 352 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum); |
351 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); | 353 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); |
352 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum); | 354 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum); |
353 } | 355 } |
354 | 356 |
355 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { | 357 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { |
356 const int kWidth = 640; | |
357 const int kHeight = 480; | |
358 | |
359 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) | 358 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) |
360 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); | 359 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
361 | 360 |
362 // No switch, stats should not be updated. | 361 // No switch, stats should not be updated. |
363 VideoEncoderConfig config; | 362 VideoEncoderConfig config; |
364 config.content_type = VideoEncoderConfig::ContentType::kRealtimeVideo; | 363 config.content_type = VideoEncoderConfig::ContentType::kRealtimeVideo; |
365 statistics_proxy_->OnEncoderReconfigured(config, 50); | 364 statistics_proxy_->OnEncoderReconfigured(config, 50); |
366 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); | 365 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); |
367 | 366 |
368 // Switch to screenshare, real-time stats should be updated. | 367 // Switch to screenshare, real-time stats should be updated. |
369 config.content_type = VideoEncoderConfig::ContentType::kScreen; | 368 config.content_type = VideoEncoderConfig::ContentType::kScreen; |
370 statistics_proxy_->OnEncoderReconfigured(config, 50); | 369 statistics_proxy_->OnEncoderReconfigured(config, 50); |
371 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); | 370 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); |
372 } | 371 } |
373 | 372 |
374 TEST_F(SendStatisticsProxyTest, CpuLimitedResolutionUpdated) { | 373 TEST_F(SendStatisticsProxyTest, InputResolutionHistogramsAreUpdated) { |
375 const int kWidth = 640; | |
376 const int kHeight = 480; | |
377 | |
378 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) | 374 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) |
379 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); | 375 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
380 | 376 |
| 377 statistics_proxy_.reset(); |
| 378 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); |
| 379 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.InputWidthInPixels", kWidth)); |
| 380 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputHeightInPixels")); |
| 381 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.InputHeightInPixels", kHeight)); |
| 382 } |
| 383 |
| 384 TEST_F(SendStatisticsProxyTest, SentResolutionHistogramsAreUpdated) { |
| 385 EncodedImage encoded_image; |
| 386 encoded_image._encodedWidth = kWidth; |
| 387 encoded_image._encodedHeight = kHeight; |
| 388 for (int i = 0; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
| 389 encoded_image._timeStamp = i + 1; |
| 390 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); |
| 391 } |
| 392 statistics_proxy_.reset(); |
| 393 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SentWidthInPixels")); |
| 394 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SentWidthInPixels", kWidth)); |
| 395 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SentHeightInPixels")); |
| 396 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SentHeightInPixels", kHeight)); |
| 397 } |
| 398 |
| 399 TEST_F(SendStatisticsProxyTest, InputFpsHistogramIsUpdated) { |
| 400 const int kFps = 20; |
| 401 const int kMinPeriodicSamples = 6; |
| 402 int frames = kMinPeriodicSamples * kFpsPeriodicIntervalMs * kFps / 1000; |
| 403 for (int i = 0; i <= frames; ++i) { |
| 404 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps); |
| 405 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
| 406 } |
| 407 statistics_proxy_.reset(); |
| 408 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputFramesPerSecond")); |
| 409 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.InputFramesPerSecond", kFps)); |
| 410 } |
| 411 |
| 412 TEST_F(SendStatisticsProxyTest, SentFpsHistogramIsUpdated) { |
| 413 EncodedImage encoded_image; |
| 414 const int kFps = 20; |
| 415 const int kMinPeriodicSamples = 6; |
| 416 int frames = kMinPeriodicSamples * kFpsPeriodicIntervalMs * kFps / 1000 + 1; |
| 417 for (int i = 0; i <= frames; ++i) { |
| 418 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps); |
| 419 encoded_image._timeStamp = i + 1; |
| 420 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); |
| 421 } |
| 422 statistics_proxy_.reset(); |
| 423 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SentFramesPerSecond")); |
| 424 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SentFramesPerSecond", kFps)); |
| 425 } |
| 426 |
| 427 TEST_F(SendStatisticsProxyTest, InputFpsHistogramExcludesSuspendedTime) { |
| 428 const int kFps = 20; |
| 429 const int kSuspendTimeMs = 10000; |
| 430 const int kMinPeriodicSamples = 6; |
| 431 int frames = kMinPeriodicSamples * kFpsPeriodicIntervalMs * kFps / 1000; |
| 432 for (int i = 0; i < frames; ++i) { |
| 433 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps); |
| 434 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
| 435 } |
| 436 // Suspend. |
| 437 statistics_proxy_->OnSuspendChange(true); |
| 438 fake_clock_.AdvanceTimeMilliseconds(kSuspendTimeMs); |
| 439 |
| 440 for (int i = 0; i < frames; ++i) { |
| 441 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps); |
| 442 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
| 443 } |
| 444 // Suspended time interval should not affect the framerate. |
| 445 statistics_proxy_.reset(); |
| 446 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputFramesPerSecond")); |
| 447 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.InputFramesPerSecond", kFps)); |
| 448 } |
| 449 |
| 450 TEST_F(SendStatisticsProxyTest, SentFpsHistogramExcludesSuspendedTime) { |
| 451 EncodedImage encoded_image; |
| 452 const int kFps = 20; |
| 453 const int kSuspendTimeMs = 10000; |
| 454 const int kMinPeriodicSamples = 6; |
| 455 int frames = kMinPeriodicSamples * kFpsPeriodicIntervalMs * kFps / 1000; |
| 456 for (int i = 0; i <= frames; ++i) { |
| 457 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps); |
| 458 encoded_image._timeStamp = i + 1; |
| 459 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); |
| 460 } |
| 461 // Suspend. |
| 462 statistics_proxy_->OnSuspendChange(true); |
| 463 fake_clock_.AdvanceTimeMilliseconds(kSuspendTimeMs); |
| 464 |
| 465 for (int i = 0; i <= frames; ++i) { |
| 466 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps); |
| 467 encoded_image._timeStamp = i + 1; |
| 468 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr); |
| 469 } |
| 470 // Suspended time interval should not affect the framerate. |
| 471 statistics_proxy_.reset(); |
| 472 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SentFramesPerSecond")); |
| 473 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SentFramesPerSecond", kFps)); |
| 474 } |
| 475 |
| 476 TEST_F(SendStatisticsProxyTest, CpuLimitedResolutionUpdated) { |
| 477 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) |
| 478 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
| 479 |
381 statistics_proxy_->OnCpuRestrictedResolutionChanged(true); | 480 statistics_proxy_->OnCpuRestrictedResolutionChanged(true); |
382 | 481 |
383 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) | 482 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) |
384 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); | 483 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
385 | 484 |
386 statistics_proxy_.reset(); | 485 statistics_proxy_.reset(); |
387 EXPECT_EQ(1, | 486 EXPECT_EQ(1, |
388 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 487 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
389 EXPECT_EQ( | 488 EXPECT_EQ( |
390 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); | 489 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 | 1175 |
1077 EXPECT_EQ( | 1176 EXPECT_EQ( |
1078 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); | 1177 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); |
1079 EXPECT_EQ(1, metrics::NumEvents( | 1178 EXPECT_EQ(1, metrics::NumEvents( |
1080 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", | 1179 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", |
1081 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) / | 1180 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) / |
1082 metrics::kMinRunTimeInSeconds / 1000))); | 1181 metrics::kMinRunTimeInSeconds / 1000))); |
1083 } | 1182 } |
1084 | 1183 |
1085 } // namespace webrtc | 1184 } // namespace webrtc |
OLD | NEW |