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 <algorithm> | 13 #include <algorithm> |
14 #include <cmath> | 14 #include <cmath> |
15 #include <map> | 15 #include <map> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/trace_event.h" | |
20 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 21 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
21 #include "webrtc/system_wrappers/include/metrics.h" | 22 #include "webrtc/system_wrappers/include/metrics.h" |
22 | 23 |
23 namespace webrtc { | 24 namespace webrtc { |
24 namespace { | 25 namespace { |
25 const float kEncodeTimeWeigthFactor = 0.5f; | 26 const float kEncodeTimeWeigthFactor = 0.5f; |
26 | 27 |
27 // Used by histograms. Values of entries should not be changed. | 28 // Used by histograms. Values of entries should not be changed. |
28 enum HistogramCodecType { | 29 enum HistogramCodecType { |
29 kVideoUnknown = 0, | 30 kVideoUnknown = 0, |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 GetUmaPrefix(config.content_type), stats_, clock_)); | 420 GetUmaPrefix(config.content_type), stats_, clock_)); |
420 content_type_ = config.content_type; | 421 content_type_ = config.content_type; |
421 } | 422 } |
422 } | 423 } |
423 | 424 |
424 void SendStatisticsProxy::OnEncoderStatsUpdate(uint32_t framerate, | 425 void SendStatisticsProxy::OnEncoderStatsUpdate(uint32_t framerate, |
425 uint32_t bitrate) { | 426 uint32_t bitrate) { |
426 rtc::CritScope lock(&crit_); | 427 rtc::CritScope lock(&crit_); |
427 stats_.encode_frame_rate = framerate; | 428 stats_.encode_frame_rate = framerate; |
428 stats_.media_bitrate_bps = bitrate; | 429 stats_.media_bitrate_bps = bitrate; |
430 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.FrameRateSent", | |
431 "frame_rate", framerate, "ssrc", rtp_config_.ssrcs[0]); | |
429 } | 432 } |
430 | 433 |
431 void SendStatisticsProxy::OnEncodedFrameTimeMeasured( | 434 void SendStatisticsProxy::OnEncodedFrameTimeMeasured( |
432 int encode_time_ms, | 435 int encode_time_ms, |
433 const CpuOveruseMetrics& metrics) { | 436 const CpuOveruseMetrics& metrics) { |
434 rtc::CritScope lock(&crit_); | 437 rtc::CritScope lock(&crit_); |
435 uma_container_->encode_time_counter_.Add(encode_time_ms); | 438 uma_container_->encode_time_counter_.Add(encode_time_ms); |
436 encode_time_.Apply(1.0f, encode_time_ms); | 439 encode_time_.Apply(1.0f, encode_time_ms); |
437 stats_.avg_encode_time_ms = round(encode_time_.filtered()); | 440 stats_.avg_encode_time_ms = round(encode_time_.filtered()); |
438 stats_.encode_usage_percent = metrics.encode_usage_percent; | 441 stats_.encode_usage_percent = metrics.encode_usage_percent; |
442 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.EncodeTimeInMs", | |
443 "encode_time_ms", stats_.avg_encode_time_ms, | |
444 "ssrc", rtp_config_.ssrcs[0]); | |
445 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.EncodeUsagePercent", | |
446 "encode_usage_percent", stats_.encode_usage_percent, | |
447 "ssrc", rtp_config_.ssrcs[0]); | |
439 } | 448 } |
440 | 449 |
441 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { | 450 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { |
442 rtc::CritScope lock(&crit_); | 451 rtc::CritScope lock(&crit_); |
443 stats_.suspended = is_suspended; | 452 stats_.suspended = is_suspended; |
444 if (is_suspended) { | 453 if (is_suspended) { |
445 // Pause framerate (add min pause time since there may be frames/packets | 454 // Pause framerate (add min pause time since there may be frames/packets |
446 // that are not yet sent). | 455 // that are not yet sent). |
447 const int64_t kMinMs = 500; | 456 const int64_t kMinMs = 500; |
448 uma_container_->input_fps_counter_.ProcessAndPauseForDuration(kMinMs); | 457 uma_container_->input_fps_counter_.ProcessAndPauseForDuration(kMinMs); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 uma_container_->max_sent_width_per_timestamp_ = 0; | 645 uma_container_->max_sent_width_per_timestamp_ = 0; |
637 uma_container_->max_sent_height_per_timestamp_ = 0; | 646 uma_container_->max_sent_height_per_timestamp_ = 0; |
638 } | 647 } |
639 last_sent_frame_timestamp_ = encoded_image._timeStamp; | 648 last_sent_frame_timestamp_ = encoded_image._timeStamp; |
640 uma_container_->max_sent_width_per_timestamp_ = | 649 uma_container_->max_sent_width_per_timestamp_ = |
641 std::max(uma_container_->max_sent_width_per_timestamp_, | 650 std::max(uma_container_->max_sent_width_per_timestamp_, |
642 static_cast<int>(encoded_image._encodedWidth)); | 651 static_cast<int>(encoded_image._encodedWidth)); |
643 uma_container_->max_sent_height_per_timestamp_ = | 652 uma_container_->max_sent_height_per_timestamp_ = |
644 std::max(uma_container_->max_sent_height_per_timestamp_, | 653 std::max(uma_container_->max_sent_height_per_timestamp_, |
645 static_cast<int>(encoded_image._encodedHeight)); | 654 static_cast<int>(encoded_image._encodedHeight)); |
655 | |
656 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.SentWidthInPixels", | |
657 "frame_height", uma_container_->max_sent_height_per_timestamp_, | |
åsapersson
2017/03/15 15:55:25
I think this should be encoded_image._encodedWidth
åsapersson
2017/03/15 15:55:25
"frame_height" -> "frame_width"
| |
658 "ssrc", ssrc); | |
659 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.SentHeightInPixels", | |
660 "frame_width", uma_container_->max_sent_width_per_timestamp_, | |
åsapersson
2017/03/15 15:55:25
"frame_height" -> "frame_width"
| |
661 "ssrc", ssrc); | |
646 } | 662 } |
647 | 663 |
648 int SendStatisticsProxy::GetSendFrameRate() const { | 664 int SendStatisticsProxy::GetSendFrameRate() const { |
649 rtc::CritScope lock(&crit_); | 665 rtc::CritScope lock(&crit_); |
650 return stats_.encode_frame_rate; | 666 return stats_.encode_frame_rate; |
651 } | 667 } |
652 | 668 |
653 void SendStatisticsProxy::OnIncomingFrame(int width, int height) { | 669 void SendStatisticsProxy::OnIncomingFrame(int width, int height) { |
654 rtc::CritScope lock(&crit_); | 670 rtc::CritScope lock(&crit_); |
655 uma_container_->input_frame_rate_tracker_.AddSamples(1); | 671 uma_container_->input_frame_rate_tracker_.AddSamples(1); |
656 uma_container_->input_fps_counter_.Add(1); | 672 uma_container_->input_fps_counter_.Add(1); |
657 uma_container_->input_width_counter_.Add(width); | 673 uma_container_->input_width_counter_.Add(width); |
658 uma_container_->input_height_counter_.Add(height); | 674 uma_container_->input_height_counter_.Add(height); |
659 uma_container_->cpu_limited_frame_counter_.Add(stats_.cpu_limited_resolution); | 675 uma_container_->cpu_limited_frame_counter_.Add(stats_.cpu_limited_resolution); |
676 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.InputFrameRate", | |
677 "frame_rate", round( | |
678 uma_container_->input_frame_rate_tracker_.ComputeRate()), | |
679 "ssrc", rtp_config_.ssrcs[0]); | |
660 } | 680 } |
661 | 681 |
662 void SendStatisticsProxy::SetResolutionRestrictionStats( | 682 void SendStatisticsProxy::SetResolutionRestrictionStats( |
663 bool scaling_enabled, | 683 bool scaling_enabled, |
664 bool cpu_restricted, | 684 bool cpu_restricted, |
665 int num_quality_downscales) { | 685 int num_quality_downscales) { |
666 rtc::CritScope lock(&crit_); | 686 rtc::CritScope lock(&crit_); |
667 if (scaling_enabled) { | 687 if (scaling_enabled) { |
668 quality_downscales_ = num_quality_downscales; | 688 quality_downscales_ = num_quality_downscales; |
669 stats_.bw_limited_resolution = quality_downscales_ > 0; | 689 stats_.bw_limited_resolution = quality_downscales_ > 0; |
670 stats_.cpu_limited_resolution = cpu_restricted; | 690 stats_.cpu_limited_resolution = cpu_restricted; |
671 } else { | 691 } else { |
672 stats_.bw_limited_resolution = false; | 692 stats_.bw_limited_resolution = false; |
673 stats_.cpu_limited_resolution = false; | 693 stats_.cpu_limited_resolution = false; |
674 quality_downscales_ = -1; | 694 quality_downscales_ = -1; |
675 } | 695 } |
676 } | 696 } |
677 | 697 |
678 void SendStatisticsProxy::OnCpuRestrictedResolutionChanged( | 698 void SendStatisticsProxy::OnCpuRestrictedResolutionChanged( |
679 bool cpu_restricted_resolution) { | 699 bool cpu_restricted_resolution) { |
680 rtc::CritScope lock(&crit_); | 700 rtc::CritScope lock(&crit_); |
681 stats_.cpu_limited_resolution = cpu_restricted_resolution; | 701 stats_.cpu_limited_resolution = cpu_restricted_resolution; |
682 ++stats_.number_of_cpu_adapt_changes; | 702 ++stats_.number_of_cpu_adapt_changes; |
703 TRACE_EVENT_INSTANT0("webrtc_stats", "WebRTC.Video.AdaptationChanges"); | |
683 } | 704 } |
684 | 705 |
685 void SendStatisticsProxy::OnQualityRestrictedResolutionChanged( | 706 void SendStatisticsProxy::OnQualityRestrictedResolutionChanged( |
686 int num_quality_downscales) { | 707 int num_quality_downscales) { |
687 rtc::CritScope lock(&crit_); | 708 rtc::CritScope lock(&crit_); |
688 quality_downscales_ = num_quality_downscales; | 709 quality_downscales_ = num_quality_downscales; |
689 stats_.bw_limited_resolution = quality_downscales_ > 0; | 710 stats_.bw_limited_resolution = quality_downscales_ > 0; |
690 } | 711 } |
691 | 712 |
692 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( | 713 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( |
693 uint32_t ssrc, | 714 uint32_t ssrc, |
694 const RtcpPacketTypeCounter& packet_counter) { | 715 const RtcpPacketTypeCounter& packet_counter) { |
695 rtc::CritScope lock(&crit_); | 716 rtc::CritScope lock(&crit_); |
696 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 717 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
697 if (!stats) | 718 if (!stats) |
698 return; | 719 return; |
699 | 720 |
700 stats->rtcp_packet_type_counts = packet_counter; | 721 stats->rtcp_packet_type_counts = packet_counter; |
701 if (uma_container_->first_rtcp_stats_time_ms_ == -1) | 722 if (uma_container_->first_rtcp_stats_time_ms_ == -1) |
702 uma_container_->first_rtcp_stats_time_ms_ = clock_->TimeInMilliseconds(); | 723 uma_container_->first_rtcp_stats_time_ms_ = clock_->TimeInMilliseconds(); |
724 | |
725 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.FirPacketsReceived", | |
726 "fir_packets_received", packet_counter.fir_packets, "ssrc", ssrc); | |
727 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.NackPacketsReceived", | |
728 "nack_packets_received", packet_counter.nack_packets, "ssrc", ssrc); | |
729 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.PliPacketsReceived", | |
730 "pli_packets_received", packet_counter.pli_packets, "ssrc", ssrc); | |
703 } | 731 } |
704 | 732 |
705 void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, | 733 void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, |
706 uint32_t ssrc) { | 734 uint32_t ssrc) { |
707 rtc::CritScope lock(&crit_); | 735 rtc::CritScope lock(&crit_); |
708 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 736 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
709 if (!stats) | 737 if (!stats) |
710 return; | 738 return; |
711 | 739 |
712 stats->rtcp_stats = statistics; | 740 stats->rtcp_stats = statistics; |
713 uma_container_->report_block_stats_.Store(statistics, 0, ssrc); | 741 uma_container_->report_block_stats_.Store(statistics, 0, ssrc); |
742 | |
743 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.SentPacketsLost", | |
744 "packets_lost", statistics.cumulative_lost, "ssrc", ssrc); | |
714 } | 745 } |
715 | 746 |
716 void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {} | 747 void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {} |
717 | 748 |
718 void SendStatisticsProxy::DataCountersUpdated( | 749 void SendStatisticsProxy::DataCountersUpdated( |
719 const StreamDataCounters& counters, | 750 const StreamDataCounters& counters, |
720 uint32_t ssrc) { | 751 uint32_t ssrc) { |
721 rtc::CritScope lock(&crit_); | 752 rtc::CritScope lock(&crit_); |
722 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 753 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
723 RTC_DCHECK(stats) << "DataCountersUpdated reported for unknown ssrc " << ssrc; | 754 RTC_DCHECK(stats) << "DataCountersUpdated reported for unknown ssrc " << ssrc; |
(...skipping 14 matching lines...) Expand all Loading... | |
738 ssrc); | 769 ssrc); |
739 uma_container_->retransmit_byte_counter_.Set( | 770 uma_container_->retransmit_byte_counter_.Set( |
740 counters.retransmitted.TotalBytes(), ssrc); | 771 counters.retransmitted.TotalBytes(), ssrc); |
741 uma_container_->fec_byte_counter_.Set(counters.fec.TotalBytes(), ssrc); | 772 uma_container_->fec_byte_counter_.Set(counters.fec.TotalBytes(), ssrc); |
742 if (stats->is_rtx) { | 773 if (stats->is_rtx) { |
743 uma_container_->rtx_byte_counter_.Set(counters.transmitted.TotalBytes(), | 774 uma_container_->rtx_byte_counter_.Set(counters.transmitted.TotalBytes(), |
744 ssrc); | 775 ssrc); |
745 } else { | 776 } else { |
746 uma_container_->media_byte_counter_.Set(counters.MediaPayloadBytes(), ssrc); | 777 uma_container_->media_byte_counter_.Set(counters.MediaPayloadBytes(), ssrc); |
747 } | 778 } |
779 | |
780 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.SentPackets", | |
781 "packets_sent", counters.transmitted.packets, "ssrc", ssrc); | |
748 } | 782 } |
749 | 783 |
750 void SendStatisticsProxy::Notify(uint32_t total_bitrate_bps, | 784 void SendStatisticsProxy::Notify(uint32_t total_bitrate_bps, |
751 uint32_t retransmit_bitrate_bps, | 785 uint32_t retransmit_bitrate_bps, |
752 uint32_t ssrc) { | 786 uint32_t ssrc) { |
753 rtc::CritScope lock(&crit_); | 787 rtc::CritScope lock(&crit_); |
754 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 788 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
755 if (!stats) | 789 if (!stats) |
756 return; | 790 return; |
757 | 791 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 } | 851 } |
818 | 852 |
819 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 853 int SendStatisticsProxy::BoolSampleCounter::Fraction( |
820 int64_t min_required_samples, | 854 int64_t min_required_samples, |
821 float multiplier) const { | 855 float multiplier) const { |
822 if (num_samples < min_required_samples || num_samples == 0) | 856 if (num_samples < min_required_samples || num_samples == 0) |
823 return -1; | 857 return -1; |
824 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 858 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
825 } | 859 } |
826 } // namespace webrtc | 860 } // namespace webrtc |
OLD | NEW |