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 | 28 |
29 const int kMinRequiredSamples = 200; | |
30 const int kQpIdx0 = 21; | 29 const int kQpIdx0 = 21; |
31 const int kQpIdx1 = 39; | 30 const int kQpIdx1 = 39; |
32 } // namespace | 31 } // namespace |
33 | 32 |
34 class SendStatisticsProxyTest : public ::testing::Test { | 33 class SendStatisticsProxyTest : public ::testing::Test { |
35 public: | 34 public: |
36 SendStatisticsProxyTest() | 35 SendStatisticsProxyTest() |
37 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), | 36 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), |
38 max_delay_ms_(0) {} | 37 max_delay_ms_(0) {} |
39 virtual ~SendStatisticsProxyTest() {} | 38 virtual ~SendStatisticsProxyTest() {} |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 VideoEncoderConfig config; | 297 VideoEncoderConfig config; |
299 statistics_proxy_->OnEncoderReconfigured(config, kPreferredMediaBitrateBps); | 298 statistics_proxy_->OnEncoderReconfigured(config, kPreferredMediaBitrateBps); |
300 stats = statistics_proxy_->GetStats(); | 299 stats = statistics_proxy_->GetStats(); |
301 EXPECT_EQ(kPreferredMediaBitrateBps, stats.preferred_media_bitrate_bps); | 300 EXPECT_EQ(kPreferredMediaBitrateBps, stats.preferred_media_bitrate_bps); |
302 } | 301 } |
303 | 302 |
304 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { | 303 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { |
305 const int kWidth = 640; | 304 const int kWidth = 640; |
306 const int kHeight = 480; | 305 const int kHeight = 480; |
307 | 306 |
308 for (int i = 0; i < kMinRequiredSamples; ++i) | 307 for (int i = 0; i < SendStatisticsProxy::kMinRequiredUMASamples; ++i) |
309 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); | 308 statistics_proxy_->OnIncomingFrame(kWidth, kHeight, false); |
310 | 309 |
311 // No switch, stats should not be updated. | 310 // No switch, stats should not be updated. |
312 VideoEncoderConfig config; | 311 VideoEncoderConfig config; |
313 config.content_type = VideoEncoderConfig::ContentType::kRealtimeVideo; | 312 config.content_type = VideoEncoderConfig::ContentType::kRealtimeVideo; |
314 statistics_proxy_->OnEncoderReconfigured(config, 50); | 313 statistics_proxy_->OnEncoderReconfigured(config, 50); |
315 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); | 314 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); |
316 | 315 |
317 // Switch to screenshare, real-time stats should be updated. | 316 // Switch to screenshare, real-time stats should be updated. |
318 config.content_type = VideoEncoderConfig::ContentType::kScreen; | 317 config.content_type = VideoEncoderConfig::ContentType::kScreen; |
319 statistics_proxy_->OnEncoderReconfigured(config, 50); | 318 statistics_proxy_->OnEncoderReconfigured(config, 50); |
320 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); | 319 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); |
321 } | 320 } |
322 | 321 |
| 322 TEST_F(SendStatisticsProxyTest, CpuLimitedResolutionUpdated) { |
| 323 const int kWidth = 640; |
| 324 const int kHeight = 480; |
| 325 |
| 326 for (int i = 0; i < SendStatisticsProxy::kMinRequiredUMASamples; ++i) |
| 327 statistics_proxy_->OnIncomingFrame(kWidth, kHeight, false); |
| 328 |
| 329 for (int i = 0; i < SendStatisticsProxy::kMinRequiredUMASamples; ++i) |
| 330 statistics_proxy_->OnIncomingFrame(kWidth, kHeight, true); |
| 331 |
| 332 statistics_proxy_.reset(); |
| 333 EXPECT_EQ(1, |
| 334 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
| 335 EXPECT_EQ( |
| 336 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
| 337 } |
| 338 |
323 TEST_F(SendStatisticsProxyTest, LifetimeHistogramIsUpdated) { | 339 TEST_F(SendStatisticsProxyTest, LifetimeHistogramIsUpdated) { |
324 const int64_t kTimeSec = 3; | 340 const int64_t kTimeSec = 3; |
325 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); | 341 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); |
326 statistics_proxy_.reset(); | 342 statistics_proxy_.reset(); |
327 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SendStreamLifetimeInSeconds")); | 343 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SendStreamLifetimeInSeconds")); |
328 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendStreamLifetimeInSeconds", | 344 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendStreamLifetimeInSeconds", |
329 kTimeSec)); | 345 kTimeSec)); |
330 } | 346 } |
331 | 347 |
332 TEST_F(SendStatisticsProxyTest, CodecTypeHistogramIsUpdated) { | 348 TEST_F(SendStatisticsProxyTest, CodecTypeHistogramIsUpdated) { |
333 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); | 349 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
334 statistics_proxy_.reset(); | 350 statistics_proxy_.reset(); |
335 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoder.CodecType")); | 351 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoder.CodecType")); |
336 } | 352 } |
337 | 353 |
338 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) { | 354 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) { |
339 EncodedImage encoded_image; | 355 EncodedImage encoded_image; |
340 CodecSpecificInfo codec_info; | 356 CodecSpecificInfo codec_info; |
341 codec_info.codecType = kVideoCodecVP8; | 357 codec_info.codecType = kVideoCodecVP8; |
342 | 358 |
343 for (int i = 0; i < kMinRequiredSamples; ++i) { | 359 for (int i = 0; i < SendStatisticsProxy::kMinRequiredUMASamples; ++i) { |
344 codec_info.codecSpecific.VP8.simulcastIdx = 0; | 360 codec_info.codecSpecific.VP8.simulcastIdx = 0; |
345 encoded_image.qp_ = kQpIdx0; | 361 encoded_image.qp_ = kQpIdx0; |
346 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); | 362 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); |
347 codec_info.codecSpecific.VP8.simulcastIdx = 1; | 363 codec_info.codecSpecific.VP8.simulcastIdx = 1; |
348 encoded_image.qp_ = kQpIdx1; | 364 encoded_image.qp_ = kQpIdx1; |
349 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); | 365 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); |
350 } | 366 } |
351 statistics_proxy_.reset(); | 367 statistics_proxy_.reset(); |
352 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8.S0")); | 368 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8.S0")); |
353 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8.S0", kQpIdx0)); | 369 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8.S0", kQpIdx0)); |
354 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8.S1")); | 370 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8.S1")); |
355 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8.S1", kQpIdx1)); | 371 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8.S1", kQpIdx1)); |
356 } | 372 } |
357 | 373 |
358 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8OneSsrc) { | 374 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8OneSsrc) { |
359 VideoSendStream::Config config(nullptr); | 375 VideoSendStream::Config config(nullptr); |
360 config.rtp.ssrcs.push_back(kFirstSsrc); | 376 config.rtp.ssrcs.push_back(kFirstSsrc); |
361 statistics_proxy_.reset(new SendStatisticsProxy( | 377 statistics_proxy_.reset(new SendStatisticsProxy( |
362 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo)); | 378 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo)); |
363 | 379 |
364 EncodedImage encoded_image; | 380 EncodedImage encoded_image; |
365 CodecSpecificInfo codec_info; | 381 CodecSpecificInfo codec_info; |
366 codec_info.codecType = kVideoCodecVP8; | 382 codec_info.codecType = kVideoCodecVP8; |
367 | 383 |
368 for (int i = 0; i < kMinRequiredSamples; ++i) { | 384 for (int i = 0; i < SendStatisticsProxy::kMinRequiredUMASamples; ++i) { |
369 codec_info.codecSpecific.VP8.simulcastIdx = 0; | 385 codec_info.codecSpecific.VP8.simulcastIdx = 0; |
370 encoded_image.qp_ = kQpIdx0; | 386 encoded_image.qp_ = kQpIdx0; |
371 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); | 387 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); |
372 } | 388 } |
373 statistics_proxy_.reset(); | 389 statistics_proxy_.reset(); |
374 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8")); | 390 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8")); |
375 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8", kQpIdx0)); | 391 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8", kQpIdx0)); |
376 } | 392 } |
377 | 393 |
378 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9) { | 394 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9) { |
379 EncodedImage encoded_image; | 395 EncodedImage encoded_image; |
380 CodecSpecificInfo codec_info; | 396 CodecSpecificInfo codec_info; |
381 codec_info.codecType = kVideoCodecVP9; | 397 codec_info.codecType = kVideoCodecVP9; |
382 codec_info.codecSpecific.VP9.num_spatial_layers = 2; | 398 codec_info.codecSpecific.VP9.num_spatial_layers = 2; |
383 | 399 |
384 for (int i = 0; i < kMinRequiredSamples; ++i) { | 400 for (int i = 0; i < SendStatisticsProxy::kMinRequiredUMASamples; ++i) { |
385 encoded_image.qp_ = kQpIdx0; | 401 encoded_image.qp_ = kQpIdx0; |
386 codec_info.codecSpecific.VP9.spatial_idx = 0; | 402 codec_info.codecSpecific.VP9.spatial_idx = 0; |
387 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); | 403 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); |
388 encoded_image.qp_ = kQpIdx1; | 404 encoded_image.qp_ = kQpIdx1; |
389 codec_info.codecSpecific.VP9.spatial_idx = 1; | 405 codec_info.codecSpecific.VP9.spatial_idx = 1; |
390 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); | 406 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); |
391 } | 407 } |
392 statistics_proxy_.reset(); | 408 statistics_proxy_.reset(); |
393 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9.S0")); | 409 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9.S0")); |
394 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9.S0", kQpIdx0)); | 410 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9.S0", kQpIdx0)); |
395 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9.S1")); | 411 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9.S1")); |
396 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9.S1", kQpIdx1)); | 412 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9.S1", kQpIdx1)); |
397 } | 413 } |
398 | 414 |
399 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9OneSpatialLayer) { | 415 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9OneSpatialLayer) { |
400 VideoSendStream::Config config(nullptr); | 416 VideoSendStream::Config config(nullptr); |
401 config.rtp.ssrcs.push_back(kFirstSsrc); | 417 config.rtp.ssrcs.push_back(kFirstSsrc); |
402 statistics_proxy_.reset(new SendStatisticsProxy( | 418 statistics_proxy_.reset(new SendStatisticsProxy( |
403 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo)); | 419 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo)); |
404 | 420 |
405 EncodedImage encoded_image; | 421 EncodedImage encoded_image; |
406 CodecSpecificInfo codec_info; | 422 CodecSpecificInfo codec_info; |
407 codec_info.codecType = kVideoCodecVP9; | 423 codec_info.codecType = kVideoCodecVP9; |
408 codec_info.codecSpecific.VP9.num_spatial_layers = 1; | 424 codec_info.codecSpecific.VP9.num_spatial_layers = 1; |
409 | 425 |
410 for (int i = 0; i < kMinRequiredSamples; ++i) { | 426 for (int i = 0; i < SendStatisticsProxy::kMinRequiredUMASamples; ++i) { |
411 encoded_image.qp_ = kQpIdx0; | 427 encoded_image.qp_ = kQpIdx0; |
412 codec_info.codecSpecific.VP9.spatial_idx = 0; | 428 codec_info.codecSpecific.VP9.spatial_idx = 0; |
413 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); | 429 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); |
414 } | 430 } |
415 statistics_proxy_.reset(); | 431 statistics_proxy_.reset(); |
416 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9")); | 432 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9")); |
417 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9", kQpIdx0)); | 433 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9", kQpIdx0)); |
418 } | 434 } |
419 | 435 |
420 TEST_F(SendStatisticsProxyTest, NoSubstreams) { | 436 TEST_F(SendStatisticsProxyTest, NoSubstreams) { |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 | 773 |
758 EXPECT_EQ( | 774 EXPECT_EQ( |
759 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); | 775 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); |
760 EXPECT_EQ(1, metrics::NumEvents( | 776 EXPECT_EQ(1, metrics::NumEvents( |
761 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", | 777 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", |
762 static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) / | 778 static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) / |
763 metrics::kMinRunTimeInSeconds / 1000))); | 779 metrics::kMinRunTimeInSeconds / 1000))); |
764 } | 780 } |
765 | 781 |
766 } // namespace webrtc | 782 } // namespace webrtc |
OLD | NEW |