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/system_wrappers/include/metrics.h" | 20 #include "webrtc/system_wrappers/include/metrics.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 namespace { | 23 namespace { |
24 const float kEncodeTimeWeigthFactor = 0.5f; | 24 const float kEncodeTimeWeigthFactor = 0.5f; |
25 | 25 |
26 // Packet with a larger delay are removed and excluded from the delay stats. | |
27 // Set to larger than max histogram delay which is 10000. | |
28 const int64_t kMaxSentPacketDelayMs = 11000; | |
29 const size_t kMaxSendPacketMapSize = 2000; | |
30 | |
26 // Used by histograms. Values of entries should not be changed. | 31 // Used by histograms. Values of entries should not be changed. |
27 enum HistogramCodecType { | 32 enum HistogramCodecType { |
28 kVideoUnknown = 0, | 33 kVideoUnknown = 0, |
29 kVideoVp8 = 1, | 34 kVideoVp8 = 1, |
30 kVideoVp9 = 2, | 35 kVideoVp9 = 2, |
31 kVideoH264 = 3, | 36 kVideoH264 = 3, |
32 kVideoMax = 64, | 37 kVideoMax = 64, |
33 }; | 38 }; |
34 | 39 |
35 const char* kRealtimePrefix = "WebRTC.Video."; | 40 const char* kRealtimePrefix = "WebRTC.Video."; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 | 76 |
72 SendStatisticsProxy::SendStatisticsProxy( | 77 SendStatisticsProxy::SendStatisticsProxy( |
73 Clock* clock, | 78 Clock* clock, |
74 const VideoSendStream::Config& config, | 79 const VideoSendStream::Config& config, |
75 VideoEncoderConfig::ContentType content_type) | 80 VideoEncoderConfig::ContentType content_type) |
76 : clock_(clock), | 81 : clock_(clock), |
77 config_(config), | 82 config_(config), |
78 content_type_(content_type), | 83 content_type_(content_type), |
79 last_sent_frame_timestamp_(0), | 84 last_sent_frame_timestamp_(0), |
80 encode_time_(kEncodeTimeWeigthFactor), | 85 encode_time_(kEncodeTimeWeigthFactor), |
86 num_old_packets_(0), | |
87 num_skipped_packets_(0), | |
81 uma_container_( | 88 uma_container_( |
82 new UmaSamplesContainer(GetUmaPrefix(content_type_), stats_, clock)) { | 89 new UmaSamplesContainer(GetUmaPrefix(content_type_), stats_, clock)) { |
83 UpdateCodecTypeHistogram(config_.encoder_settings.payload_name); | 90 UpdateCodecTypeHistogram(config_.encoder_settings.payload_name); |
84 } | 91 } |
85 | 92 |
86 SendStatisticsProxy::~SendStatisticsProxy() { | 93 SendStatisticsProxy::~SendStatisticsProxy() { |
94 if (num_old_packets_ > 0 || num_skipped_packets_ > 0) { | |
95 LOG(LS_WARNING) << "Delay stats: number of old packets " << num_old_packets_ | |
96 << ", skipped packets " << num_skipped_packets_; | |
97 } | |
87 rtc::CritScope lock(&crit_); | 98 rtc::CritScope lock(&crit_); |
88 uma_container_->UpdateHistograms(config_, stats_); | 99 uma_container_->UpdateHistograms(config_, stats_); |
89 } | 100 } |
90 | 101 |
91 SendStatisticsProxy::UmaSamplesContainer::UmaSamplesContainer( | 102 SendStatisticsProxy::UmaSamplesContainer::UmaSamplesContainer( |
92 const char* prefix, | 103 const char* prefix, |
93 const VideoSendStream::Stats& stats, | 104 const VideoSendStream::Stats& stats, |
94 Clock* const clock) | 105 Clock* const clock) |
95 : uma_prefix_(prefix), | 106 : uma_prefix_(prefix), |
96 clock_(clock), | 107 clock_(clock), |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 int delay_ms = delay_counter_.Avg(kMinRequiredSamples); | 196 int delay_ms = delay_counter_.Avg(kMinRequiredSamples); |
186 if (delay_ms != -1) | 197 if (delay_ms != -1) |
187 RTC_LOGGED_HISTOGRAMS_COUNTS_100000( | 198 RTC_LOGGED_HISTOGRAMS_COUNTS_100000( |
188 kIndex, uma_prefix_ + "SendSideDelayInMs", delay_ms); | 199 kIndex, uma_prefix_ + "SendSideDelayInMs", delay_ms); |
189 | 200 |
190 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples); | 201 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples); |
191 if (max_delay_ms != -1) { | 202 if (max_delay_ms != -1) { |
192 RTC_LOGGED_HISTOGRAMS_COUNTS_100000( | 203 RTC_LOGGED_HISTOGRAMS_COUNTS_100000( |
193 kIndex, uma_prefix_ + "SendSideDelayMaxInMs", max_delay_ms); | 204 kIndex, uma_prefix_ + "SendSideDelayMaxInMs", max_delay_ms); |
194 } | 205 } |
206 for (const auto& it : send_delay_counters_) { | |
207 int send_delay_ms = it.second.Avg(kMinRequiredSamples); | |
208 if (send_delay_ms != -1) | |
stefan-webrtc
2016/04/19 11:06:15
{}
åsapersson
2016/04/19 14:55:33
Done.
| |
209 RTC_LOGGED_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "SendDelayInMs", | |
210 send_delay_ms); | |
211 } | |
195 | 212 |
196 for (const auto& it : qp_counters_) { | 213 for (const auto& it : qp_counters_) { |
197 int qp = it.second.vp8.Avg(kMinRequiredSamples); | 214 int qp = it.second.vp8.Avg(kMinRequiredSamples); |
198 if (qp != -1) { | 215 if (qp != -1) { |
199 int spatial_idx = it.first; | 216 int spatial_idx = it.first; |
200 if (spatial_idx == -1) { | 217 if (spatial_idx == -1) { |
201 RTC_LOGGED_HISTOGRAMS_COUNTS_200(kIndex, uma_prefix_ + "Encoded.Qp.Vp8", | 218 RTC_LOGGED_HISTOGRAMS_COUNTS_200(kIndex, uma_prefix_ + "Encoded.Qp.Vp8", |
202 qp); | 219 qp); |
203 } else if (spatial_idx == 0) { | 220 } else if (spatial_idx == 0) { |
204 RTC_LOGGED_HISTOGRAMS_COUNTS_200(kIndex, | 221 RTC_LOGGED_HISTOGRAMS_COUNTS_200(kIndex, |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 571 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
555 if (stats == nullptr) | 572 if (stats == nullptr) |
556 return; | 573 return; |
557 stats->avg_delay_ms = avg_delay_ms; | 574 stats->avg_delay_ms = avg_delay_ms; |
558 stats->max_delay_ms = max_delay_ms; | 575 stats->max_delay_ms = max_delay_ms; |
559 | 576 |
560 uma_container_->delay_counter_.Add(avg_delay_ms); | 577 uma_container_->delay_counter_.Add(avg_delay_ms); |
561 uma_container_->max_delay_counter_.Add(max_delay_ms); | 578 uma_container_->max_delay_counter_.Add(max_delay_ms); |
562 } | 579 } |
563 | 580 |
581 void SendStatisticsProxy::OnSendPacket(uint16_t packet_id, | |
582 int64_t capture_time_ms, | |
583 uint32_t ssrc) { | |
584 // Packet sent to transport. | |
585 rtc::CritScope lock(&crit_); | |
586 if (GetStatsEntry(ssrc) == nullptr) | |
587 return; | |
588 | |
589 int64_t now = clock_->TimeInMilliseconds(); | |
590 RemoveOld(now, &packets_); | |
591 | |
592 if (packets_.size() > kMaxSendPacketMapSize) { | |
593 ++num_skipped_packets_; | |
594 return; | |
595 } | |
596 packets_.insert( | |
597 std::make_pair(packet_id, Packet(ssrc, capture_time_ms, now))); | |
598 } | |
599 | |
600 bool SendStatisticsProxy::OnSentPacket(int packet_id) { | |
601 // Packet leaving socket. | |
602 if (packet_id == -1) | |
603 return false; | |
604 | |
605 rtc::CritScope lock(&crit_); | |
606 auto it = packets_.find(packet_id); | |
607 if (it == packets_.end()) | |
608 return false; | |
609 | |
610 // TODO(asapersson): Remove SendSideDelayUpdated(), use capture -> sent. | |
611 // Elapsed time from send (to transport) -> sent (leaving socket). | |
612 int diff_ms = clock_->TimeInMilliseconds() - it->second.send_time_ms; | |
613 uma_container_->send_delay_counters_[it->second.ssrc].Add(diff_ms); | |
614 packets_.erase(it); | |
615 return true; | |
616 } | |
617 | |
618 void SendStatisticsProxy::RemoveOld(int64_t now, PacketMap* packets) { | |
619 while (!packets->empty()) { | |
620 auto it = packets->begin(); | |
621 if (now - it->second.capture_time_ms < kMaxSentPacketDelayMs) | |
622 break; | |
623 | |
624 packets->erase(it); | |
625 ++num_old_packets_; | |
626 } | |
627 } | |
628 | |
564 void SendStatisticsProxy::SampleCounter::Add(int sample) { | 629 void SendStatisticsProxy::SampleCounter::Add(int sample) { |
565 sum += sample; | 630 sum += sample; |
566 ++num_samples; | 631 ++num_samples; |
567 } | 632 } |
568 | 633 |
569 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { | 634 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { |
570 if (num_samples < min_required_samples || num_samples == 0) | 635 if (num_samples < min_required_samples || num_samples == 0) |
571 return -1; | 636 return -1; |
572 return (sum + (num_samples / 2)) / num_samples; | 637 return (sum + (num_samples / 2)) / num_samples; |
573 } | 638 } |
(...skipping 14 matching lines...) Expand all Loading... | |
588 return Fraction(min_required_samples, 1000.0f); | 653 return Fraction(min_required_samples, 1000.0f); |
589 } | 654 } |
590 | 655 |
591 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 656 int SendStatisticsProxy::BoolSampleCounter::Fraction( |
592 int min_required_samples, float multiplier) const { | 657 int min_required_samples, float multiplier) const { |
593 if (num_samples < min_required_samples || num_samples == 0) | 658 if (num_samples < min_required_samples || num_samples == 0) |
594 return -1; | 659 return -1; |
595 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 660 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
596 } | 661 } |
597 } // namespace webrtc | 662 } // namespace webrtc |
OLD | NEW |