| 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 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 config.rtp.rtx.ssrcs.push_back(kFirstRtxSsrc); | 58 config.rtp.rtx.ssrcs.push_back(kFirstRtxSsrc); |
| 59 config.rtp.rtx.ssrcs.push_back(kSecondRtxSsrc); | 59 config.rtp.rtx.ssrcs.push_back(kSecondRtxSsrc); |
| 60 config.rtp.fec.red_payload_type = 17; | 60 config.rtp.fec.red_payload_type = 17; |
| 61 return config; | 61 return config; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) { | 64 void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) { |
| 65 EXPECT_EQ(one.input_frame_rate, other.input_frame_rate); | 65 EXPECT_EQ(one.input_frame_rate, other.input_frame_rate); |
| 66 EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate); | 66 EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate); |
| 67 EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps); | 67 EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps); |
| 68 EXPECT_EQ(one.preferred_media_bitrate_bps, |
| 69 other.preferred_media_bitrate_bps); |
| 68 EXPECT_EQ(one.suspended, other.suspended); | 70 EXPECT_EQ(one.suspended, other.suspended); |
| 69 | 71 |
| 70 EXPECT_EQ(one.substreams.size(), other.substreams.size()); | 72 EXPECT_EQ(one.substreams.size(), other.substreams.size()); |
| 71 for (std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator it = | 73 for (std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator it = |
| 72 one.substreams.begin(); | 74 one.substreams.begin(); |
| 73 it != one.substreams.end(); ++it) { | 75 it != one.substreams.end(); ++it) { |
| 74 std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator | 76 std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator |
| 75 corresponding_it = other.substreams.find(it->first); | 77 corresponding_it = other.substreams.find(it->first); |
| 76 ASSERT_TRUE(corresponding_it != other.substreams.end()); | 78 ASSERT_TRUE(corresponding_it != other.substreams.end()); |
| 77 const VideoSendStream::StreamStats& a = it->second; | 79 const VideoSendStream::StreamStats& a = it->second; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 const int kEncodeTimeMs = 11; | 283 const int kEncodeTimeMs = 11; |
| 282 CpuOveruseMetrics metrics; | 284 CpuOveruseMetrics metrics; |
| 283 metrics.encode_usage_percent = 80; | 285 metrics.encode_usage_percent = 80; |
| 284 statistics_proxy_->OnEncodedFrameTimeMeasured(kEncodeTimeMs, metrics); | 286 statistics_proxy_->OnEncodedFrameTimeMeasured(kEncodeTimeMs, metrics); |
| 285 | 287 |
| 286 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 288 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
| 287 EXPECT_EQ(kEncodeTimeMs, stats.avg_encode_time_ms); | 289 EXPECT_EQ(kEncodeTimeMs, stats.avg_encode_time_ms); |
| 288 EXPECT_EQ(metrics.encode_usage_percent, stats.encode_usage_percent); | 290 EXPECT_EQ(metrics.encode_usage_percent, stats.encode_usage_percent); |
| 289 } | 291 } |
| 290 | 292 |
| 293 TEST_F(SendStatisticsProxyTest, OnEncoderReconfiguredChangePreferredBitrate) { |
| 294 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
| 295 EXPECT_EQ(0, stats.preferred_media_bitrate_bps); |
| 296 |
| 297 VideoEncoderConfig config; |
| 298 std::vector<VideoStream> streams; |
| 299 VideoStream stream1; |
| 300 stream1.target_bitrate_bps = 5; |
| 301 stream1.max_bitrate_bps = 6; |
| 302 streams.push_back(stream1); |
| 303 |
| 304 statistics_proxy_->OnEncoderReconfigured(config, streams); |
| 305 stats = statistics_proxy_->GetStats(); |
| 306 EXPECT_EQ(stream1.max_bitrate_bps, stats.preferred_media_bitrate_bps); |
| 307 |
| 308 VideoStream stream2; |
| 309 stream2.target_bitrate_bps = 10; |
| 310 stream2.max_bitrate_bps = 20; |
| 311 streams.push_back(stream2); |
| 312 |
| 313 statistics_proxy_->OnEncoderReconfigured(config, streams); |
| 314 stats = statistics_proxy_->GetStats(); |
| 315 EXPECT_EQ(stream2.max_bitrate_bps + stream1.target_bitrate_bps, |
| 316 stats.preferred_media_bitrate_bps); |
| 317 } |
| 318 |
| 291 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { | 319 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { |
| 292 const int kWidth = 640; | 320 const int kWidth = 640; |
| 293 const int kHeight = 480; | 321 const int kHeight = 480; |
| 294 | 322 |
| 295 for (int i = 0; i < kMinRequiredSamples; ++i) | 323 for (int i = 0; i < kMinRequiredSamples; ++i) |
| 296 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); | 324 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
| 297 | 325 |
| 298 // No switch, stats not should be updated. | 326 // No switch, stats should not be updated. |
| 299 statistics_proxy_->SetContentType( | 327 VideoEncoderConfig config; |
| 300 VideoEncoderConfig::ContentType::kRealtimeVideo); | 328 config.content_type = VideoEncoderConfig::ContentType::kRealtimeVideo; |
| 329 std::vector<VideoStream> video_streams; |
| 330 statistics_proxy_->OnEncoderReconfigured(config, video_streams); |
| 301 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); | 331 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); |
| 302 | 332 |
| 303 // Switch to screenshare, real-time stats should be updated. | 333 // Switch to screenshare, real-time stats should be updated. |
| 304 statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen); | 334 config.content_type = VideoEncoderConfig::ContentType::kScreen; |
| 335 statistics_proxy_->OnEncoderReconfigured(config, video_streams); |
| 305 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); | 336 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); |
| 306 } | 337 } |
| 307 | 338 |
| 308 TEST_F(SendStatisticsProxyTest, LifetimeHistogramIsUpdated) { | 339 TEST_F(SendStatisticsProxyTest, LifetimeHistogramIsUpdated) { |
| 309 const int64_t kTimeSec = 3; | 340 const int64_t kTimeSec = 3; |
| 310 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); | 341 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); |
| 311 statistics_proxy_.reset(); | 342 statistics_proxy_.reset(); |
| 312 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SendStreamLifetimeInSeconds")); | 343 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SendStreamLifetimeInSeconds")); |
| 313 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendStreamLifetimeInSeconds", | 344 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendStreamLifetimeInSeconds", |
| 314 kTimeSec)); | 345 kTimeSec)); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 counters.nack_packets += 1 * metrics::kMinRunTimeInSeconds; | 562 counters.nack_packets += 1 * metrics::kMinRunTimeInSeconds; |
| 532 counters.fir_packets += 2 * metrics::kMinRunTimeInSeconds; | 563 counters.fir_packets += 2 * metrics::kMinRunTimeInSeconds; |
| 533 counters.pli_packets += 3 * metrics::kMinRunTimeInSeconds; | 564 counters.pli_packets += 3 * metrics::kMinRunTimeInSeconds; |
| 534 counters.unique_nack_requests += 4 * metrics::kMinRunTimeInSeconds; | 565 counters.unique_nack_requests += 4 * metrics::kMinRunTimeInSeconds; |
| 535 counters.nack_requests += 5 * metrics::kMinRunTimeInSeconds; | 566 counters.nack_requests += 5 * metrics::kMinRunTimeInSeconds; |
| 536 | 567 |
| 537 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters); | 568 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters); |
| 538 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters); | 569 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters); |
| 539 | 570 |
| 540 // Changing content type causes histograms to be reported. | 571 // Changing content type causes histograms to be reported. |
| 541 statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen); | 572 VideoEncoderConfig config; |
| 573 config.content_type = VideoEncoderConfig::ContentType::kScreen; |
| 574 std::vector<VideoStream> video_streams; |
| 575 statistics_proxy_->OnEncoderReconfigured(config, video_streams); |
| 542 | 576 |
| 543 EXPECT_EQ(1, | 577 EXPECT_EQ(1, |
| 544 metrics::NumSamples("WebRTC.Video.NackPacketsReceivedPerMinute")); | 578 metrics::NumSamples("WebRTC.Video.NackPacketsReceivedPerMinute")); |
| 545 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FirPacketsReceivedPerMinute")); | 579 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FirPacketsReceivedPerMinute")); |
| 546 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PliPacketsReceivedPerMinute")); | 580 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PliPacketsReceivedPerMinute")); |
| 547 EXPECT_EQ(1, metrics::NumSamples( | 581 EXPECT_EQ(1, metrics::NumSamples( |
| 548 "WebRTC.Video.UniqueNackRequestsReceivedInPercent")); | 582 "WebRTC.Video.UniqueNackRequestsReceivedInPercent")); |
| 549 | 583 |
| 550 const int kRate = 60 * 2; // Packets per minute with two streams. | 584 const int kRate = 60 * 2; // Packets per minute with two streams. |
| 551 | 585 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 | 660 |
| 627 rtx_counters.transmitted = counters.transmitted; | 661 rtx_counters.transmitted = counters.transmitted; |
| 628 | 662 |
| 629 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds); | 663 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds); |
| 630 proxy->DataCountersUpdated(counters, kFirstSsrc); | 664 proxy->DataCountersUpdated(counters, kFirstSsrc); |
| 631 proxy->DataCountersUpdated(counters, kSecondSsrc); | 665 proxy->DataCountersUpdated(counters, kSecondSsrc); |
| 632 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc); | 666 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc); |
| 633 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc); | 667 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc); |
| 634 | 668 |
| 635 // Changing content type causes histograms to be reported. | 669 // Changing content type causes histograms to be reported. |
| 636 statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen); | 670 VideoEncoderConfig config; |
| 671 config.content_type = VideoEncoderConfig::ContentType::kScreen; |
| 672 std::vector<VideoStream> video_streams; |
| 673 statistics_proxy_->OnEncoderReconfigured(config, video_streams); |
| 637 | 674 |
| 638 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps")); | 675 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps")); |
| 639 EXPECT_EQ(1, | 676 EXPECT_EQ(1, |
| 640 metrics::NumEvents( | 677 metrics::NumEvents( |
| 641 "WebRTC.Video.BitrateSentInKbps", | 678 "WebRTC.Video.BitrateSentInKbps", |
| 642 static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) / | 679 static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) / |
| 643 metrics::kMinRunTimeInSeconds / 1000))); | 680 metrics::kMinRunTimeInSeconds / 1000))); |
| 644 | 681 |
| 645 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps")); | 682 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps")); |
| 646 EXPECT_EQ(1, metrics::NumEvents( | 683 EXPECT_EQ(1, metrics::NumEvents( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 775 |
| 739 EXPECT_EQ( | 776 EXPECT_EQ( |
| 740 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); | 777 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); |
| 741 EXPECT_EQ(1, metrics::NumEvents( | 778 EXPECT_EQ(1, metrics::NumEvents( |
| 742 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", | 779 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", |
| 743 static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) / | 780 static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) / |
| 744 metrics::kMinRunTimeInSeconds / 1000))); | 781 metrics::kMinRunTimeInSeconds / 1000))); |
| 745 } | 782 } |
| 746 | 783 |
| 747 } // namespace webrtc | 784 } // namespace webrtc |
| OLD | NEW |