| 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 <memory> | 15 #include <memory> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "webrtc/system_wrappers/include/metrics.h" | 20 #include "webrtc/system_wrappers/include/metrics.h" |
| 21 #include "webrtc/test/histogram.h" | 21 #include "webrtc/test/histogram.h" |
| 22 | 22 |
| 23 namespace webrtc { | 23 namespace webrtc { |
| 24 namespace { |
| 25 const uint32_t kFirstSsrc = 17; |
| 26 const uint32_t kSecondSsrc = 42; |
| 27 const uint32_t kFirstRtxSsrc = 18; |
| 28 const uint32_t kSecondRtxSsrc = 43; |
| 24 | 29 |
| 25 static const uint32_t kFirstSsrc = 17; | 30 const int kMinRequiredSamples = 200; |
| 26 static const uint32_t kSecondSsrc = 42; | 31 const int kQpIdx0 = 21; |
| 27 static const uint32_t kFirstRtxSsrc = 18; | 32 const int kQpIdx1 = 39; |
| 28 static const uint32_t kSecondRtxSsrc = 43; | 33 } // namespace |
| 29 | 34 |
| 30 class SendStatisticsProxyTest : public ::testing::Test { | 35 class SendStatisticsProxyTest : public ::testing::Test { |
| 31 public: | 36 public: |
| 32 SendStatisticsProxyTest() | 37 SendStatisticsProxyTest() |
| 33 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), | 38 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), |
| 34 max_delay_ms_(0) {} | 39 max_delay_ms_(0) {} |
| 35 virtual ~SendStatisticsProxyTest() {} | 40 virtual ~SendStatisticsProxyTest() {} |
| 36 | 41 |
| 37 protected: | 42 protected: |
| 38 virtual void SetUp() { | 43 virtual void SetUp() { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 metrics.encode_usage_percent = 80; | 308 metrics.encode_usage_percent = 80; |
| 304 statistics_proxy_->OnEncodedFrameTimeMeasured(kEncodeTimeMs, metrics); | 309 statistics_proxy_->OnEncodedFrameTimeMeasured(kEncodeTimeMs, metrics); |
| 305 | 310 |
| 306 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 311 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
| 307 EXPECT_EQ(kEncodeTimeMs, stats.avg_encode_time_ms); | 312 EXPECT_EQ(kEncodeTimeMs, stats.avg_encode_time_ms); |
| 308 EXPECT_EQ(metrics.encode_usage_percent, stats.encode_usage_percent); | 313 EXPECT_EQ(metrics.encode_usage_percent, stats.encode_usage_percent); |
| 309 } | 314 } |
| 310 | 315 |
| 311 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { | 316 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { |
| 312 test::ClearHistograms(); | 317 test::ClearHistograms(); |
| 313 const int kMinRequiredSamples = 200; | |
| 314 const int kWidth = 640; | 318 const int kWidth = 640; |
| 315 const int kHeight = 480; | 319 const int kHeight = 480; |
| 316 | 320 |
| 317 for (int i = 0; i < kMinRequiredSamples; ++i) | 321 for (int i = 0; i < kMinRequiredSamples; ++i) |
| 318 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); | 322 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
| 319 | 323 |
| 320 // No switch, stats not should be updated. | 324 // No switch, stats not should be updated. |
| 321 statistics_proxy_->SetContentType( | 325 statistics_proxy_->SetContentType( |
| 322 VideoEncoderConfig::ContentType::kRealtimeVideo); | 326 VideoEncoderConfig::ContentType::kRealtimeVideo); |
| 323 EXPECT_EQ(0, test::NumHistogramSamples("WebRTC.Video.InputWidthInPixels")); | 327 EXPECT_EQ(0, test::NumHistogramSamples("WebRTC.Video.InputWidthInPixels")); |
| 324 | 328 |
| 325 // Switch to screenshare, real-time stats should be updated. | 329 // Switch to screenshare, real-time stats should be updated. |
| 326 statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen); | 330 statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen); |
| 327 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.InputWidthInPixels")); | 331 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.InputWidthInPixels")); |
| 328 } | 332 } |
| 329 | 333 |
| 330 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) { | 334 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) { |
| 331 test::ClearHistograms(); | 335 test::ClearHistograms(); |
| 332 const int kMinRequiredSamples = 200; | |
| 333 const int kQpIdx0 = 21; | |
| 334 const int kQpIdx1 = 39; | |
| 335 EncodedImage encoded_image; | 336 EncodedImage encoded_image; |
| 336 | |
| 337 RTPVideoHeader rtp_video_header; | 337 RTPVideoHeader rtp_video_header; |
| 338 rtp_video_header.codec = kRtpVideoVp8; | 338 rtp_video_header.codec = kRtpVideoVp8; |
| 339 | 339 |
| 340 for (int i = 0; i < kMinRequiredSamples; ++i) { | 340 for (int i = 0; i < kMinRequiredSamples; ++i) { |
| 341 rtp_video_header.simulcastIdx = 0; | 341 rtp_video_header.simulcastIdx = 0; |
| 342 encoded_image.qp_ = kQpIdx0; | 342 encoded_image.qp_ = kQpIdx0; |
| 343 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); | 343 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 344 rtp_video_header.simulcastIdx = 1; | 344 rtp_video_header.simulcastIdx = 1; |
| 345 encoded_image.qp_ = kQpIdx1; | 345 encoded_image.qp_ = kQpIdx1; |
| 346 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); | 346 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 347 } | 347 } |
| 348 statistics_proxy_.reset(); | 348 statistics_proxy_.reset(); |
| 349 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp8.S0")); | 349 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp8.S0")); |
| 350 EXPECT_EQ(kQpIdx0, | 350 EXPECT_EQ(kQpIdx0, |
| 351 test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp8.S0")); | 351 test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp8.S0")); |
| 352 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp8.S1")); | 352 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp8.S1")); |
| 353 EXPECT_EQ(kQpIdx1, | 353 EXPECT_EQ(kQpIdx1, |
| 354 test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp8.S1")); | 354 test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp8.S1")); |
| 355 } | 355 } |
| 356 | 356 |
| 357 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8OneSsrc) { | 357 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8OneSsrc) { |
| 358 VideoSendStream::Config config(nullptr); | 358 VideoSendStream::Config config(nullptr); |
| 359 config.rtp.ssrcs.push_back(kFirstSsrc); | 359 config.rtp.ssrcs.push_back(kFirstSsrc); |
| 360 statistics_proxy_.reset(new SendStatisticsProxy( | 360 statistics_proxy_.reset(new SendStatisticsProxy( |
| 361 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo)); | 361 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo)); |
| 362 | 362 |
| 363 test::ClearHistograms(); | 363 test::ClearHistograms(); |
| 364 const int kMinRequiredSamples = 200; | |
| 365 const int kQpIdx0 = 21; | |
| 366 EncodedImage encoded_image; | 364 EncodedImage encoded_image; |
| 367 | |
| 368 RTPVideoHeader rtp_video_header; | 365 RTPVideoHeader rtp_video_header; |
| 369 rtp_video_header.codec = kRtpVideoVp8; | 366 rtp_video_header.codec = kRtpVideoVp8; |
| 370 | 367 |
| 371 for (int i = 0; i < kMinRequiredSamples; ++i) { | 368 for (int i = 0; i < kMinRequiredSamples; ++i) { |
| 372 rtp_video_header.simulcastIdx = 0; | 369 rtp_video_header.simulcastIdx = 0; |
| 373 encoded_image.qp_ = kQpIdx0; | 370 encoded_image.qp_ = kQpIdx0; |
| 374 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); | 371 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 375 } | 372 } |
| 376 statistics_proxy_.reset(); | 373 statistics_proxy_.reset(); |
| 377 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp8")); | 374 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp8")); |
| 378 EXPECT_EQ(kQpIdx0, test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp8")); | 375 EXPECT_EQ(kQpIdx0, test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp8")); |
| 379 } | 376 } |
| 380 | 377 |
| 378 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9) { |
| 379 test::ClearHistograms(); |
| 380 EncodedImage encoded_image; |
| 381 RTPVideoHeader rtp_video_header; |
| 382 rtp_video_header.simulcastIdx = 0; |
| 383 rtp_video_header.codec = kRtpVideoVp9; |
| 384 rtp_video_header.codecHeader.VP9.num_spatial_layers = 2; |
| 385 |
| 386 for (int i = 0; i < kMinRequiredSamples; ++i) { |
| 387 encoded_image.qp_ = kQpIdx0; |
| 388 rtp_video_header.codecHeader.VP9.spatial_idx = 0; |
| 389 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 390 encoded_image.qp_ = kQpIdx1; |
| 391 rtp_video_header.codecHeader.VP9.spatial_idx = 1; |
| 392 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 393 } |
| 394 statistics_proxy_.reset(); |
| 395 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp9.S0")); |
| 396 EXPECT_EQ(kQpIdx0, |
| 397 test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp9.S0")); |
| 398 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp9.S1")); |
| 399 EXPECT_EQ(kQpIdx1, |
| 400 test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp9.S1")); |
| 401 } |
| 402 |
| 403 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9OneSpatialLayer) { |
| 404 VideoSendStream::Config config(nullptr); |
| 405 config.rtp.ssrcs.push_back(kFirstSsrc); |
| 406 statistics_proxy_.reset(new SendStatisticsProxy( |
| 407 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo)); |
| 408 |
| 409 test::ClearHistograms(); |
| 410 EncodedImage encoded_image; |
| 411 RTPVideoHeader rtp_video_header; |
| 412 rtp_video_header.simulcastIdx = 0; |
| 413 rtp_video_header.codec = kRtpVideoVp9; |
| 414 rtp_video_header.codecHeader.VP9.num_spatial_layers = 1; |
| 415 |
| 416 for (int i = 0; i < kMinRequiredSamples; ++i) { |
| 417 encoded_image.qp_ = kQpIdx0; |
| 418 rtp_video_header.codecHeader.VP9.spatial_idx = 0; |
| 419 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 420 } |
| 421 statistics_proxy_.reset(); |
| 422 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp9")); |
| 423 EXPECT_EQ(kQpIdx0, test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp9")); |
| 424 } |
| 425 |
| 381 TEST_F(SendStatisticsProxyTest, NoSubstreams) { | 426 TEST_F(SendStatisticsProxyTest, NoSubstreams) { |
| 382 uint32_t excluded_ssrc = | 427 uint32_t excluded_ssrc = |
| 383 std::max( | 428 std::max( |
| 384 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), | 429 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), |
| 385 *std::max_element(config_.rtp.rtx.ssrcs.begin(), | 430 *std::max_element(config_.rtp.rtx.ssrcs.begin(), |
| 386 config_.rtp.rtx.ssrcs.end())) + | 431 config_.rtp.rtx.ssrcs.end())) + |
| 387 1; | 432 1; |
| 388 // From RtcpStatisticsCallback. | 433 // From RtcpStatisticsCallback. |
| 389 RtcpStatistics rtcp_stats; | 434 RtcpStatistics rtcp_stats; |
| 390 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); | 435 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 | 749 |
| 705 EXPECT_EQ(1, test::NumHistogramSamples( | 750 EXPECT_EQ(1, test::NumHistogramSamples( |
| 706 "WebRTC.Video.Screenshare.FecBitrateSentInKbps")); | 751 "WebRTC.Video.Screenshare.FecBitrateSentInKbps")); |
| 707 EXPECT_EQ(static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) / | 752 EXPECT_EQ(static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) / |
| 708 metrics::kMinRunTimeInSeconds / 1000), | 753 metrics::kMinRunTimeInSeconds / 1000), |
| 709 test::LastHistogramSample( | 754 test::LastHistogramSample( |
| 710 "WebRTC.Video.Screenshare.FecBitrateSentInKbps")); | 755 "WebRTC.Video.Screenshare.FecBitrateSentInKbps")); |
| 711 } | 756 } |
| 712 | 757 |
| 713 } // namespace webrtc | 758 } // namespace webrtc |
| OLD | NEW |