Index: webrtc/video/send_statistics_proxy.cc |
diff --git a/webrtc/video/send_statistics_proxy.cc b/webrtc/video/send_statistics_proxy.cc |
index 6951fda01bbbd5520a622cd8fca3150c5be0570c..923a3f1029bb705eada0e42464a4a623d946b87e 100644 |
--- a/webrtc/video/send_statistics_proxy.cc |
+++ b/webrtc/video/send_statistics_proxy.cc |
@@ -23,6 +23,11 @@ namespace webrtc { |
namespace { |
const float kEncodeTimeWeigthFactor = 0.5f; |
+// Packet with a larger delay are removed and excluded from the delay stats. |
+// Set to larger than max histogram delay which is 10000. |
+const int64_t kMaxSentPacketDelayMs = 11000; |
+const size_t kMaxSendPacketMapSize = 2000; |
+ |
// Used by histograms. Values of entries should not be changed. |
enum HistogramCodecType { |
kVideoUnknown = 0, |
@@ -78,12 +83,18 @@ SendStatisticsProxy::SendStatisticsProxy( |
content_type_(content_type), |
last_sent_frame_timestamp_(0), |
encode_time_(kEncodeTimeWeigthFactor), |
+ num_old_packets_(0), |
+ num_skipped_packets_(0), |
uma_container_( |
new UmaSamplesContainer(GetUmaPrefix(content_type_), stats_, clock)) { |
UpdateCodecTypeHistogram(config_.encoder_settings.payload_name); |
} |
SendStatisticsProxy::~SendStatisticsProxy() { |
+ if (num_old_packets_ > 0 || num_skipped_packets_ > 0) { |
+ LOG(LS_WARNING) << "Delay stats: number of old packets " << num_old_packets_ |
+ << ", skipped packets " << num_skipped_packets_; |
+ } |
rtc::CritScope lock(&crit_); |
uma_container_->UpdateHistograms(config_, stats_); |
} |
@@ -192,6 +203,13 @@ void SendStatisticsProxy::UmaSamplesContainer::UpdateHistograms( |
RTC_LOGGED_HISTOGRAMS_COUNTS_100000( |
kIndex, uma_prefix_ + "SendSideDelayMaxInMs", max_delay_ms); |
} |
+ for (const auto& it : send_delay_counters_) { |
+ int send_delay_ms = it.second.Avg(kMinRequiredSamples); |
+ if (send_delay_ms != -1) { |
+ RTC_LOGGED_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "SendDelayInMs", |
+ send_delay_ms); |
+ } |
+ } |
for (const auto& it : qp_counters_) { |
int qp_vp8 = it.second.vp8.Avg(kMinRequiredSamples); |
@@ -588,6 +606,54 @@ void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms, |
uma_container_->max_delay_counter_.Add(max_delay_ms); |
} |
+void SendStatisticsProxy::OnSendPacket(uint16_t packet_id, |
+ int64_t capture_time_ms, |
+ uint32_t ssrc) { |
+ // Packet sent to transport. |
+ rtc::CritScope lock(&crit_); |
+ if (GetStatsEntry(ssrc) == nullptr) |
+ return; |
+ |
+ int64_t now = clock_->TimeInMilliseconds(); |
+ RemoveOld(now, &packets_); |
+ |
+ if (packets_.size() > kMaxSendPacketMapSize) { |
+ ++num_skipped_packets_; |
+ return; |
+ } |
+ packets_.insert( |
+ std::make_pair(packet_id, Packet(ssrc, capture_time_ms, now))); |
+} |
+ |
+bool SendStatisticsProxy::OnSentPacket(int packet_id) { |
+ // Packet leaving socket. |
+ if (packet_id == -1) |
+ return false; |
+ |
+ rtc::CritScope lock(&crit_); |
+ auto it = packets_.find(packet_id); |
+ if (it == packets_.end()) |
+ return false; |
+ |
+ // TODO(asapersson): Remove SendSideDelayUpdated(), use capture -> sent. |
+ // Elapsed time from send (to transport) -> sent (leaving socket). |
+ int diff_ms = clock_->TimeInMilliseconds() - it->second.send_time_ms; |
mflodman
2016/04/26 06:49:11
Is there some way we could get this time when actu
åsapersson
2016/04/28 12:26:19
Right, it is not working due to clock differences.
|
+ uma_container_->send_delay_counters_[it->second.ssrc].Add(diff_ms); |
+ packets_.erase(it); |
+ return true; |
+} |
+ |
+void SendStatisticsProxy::RemoveOld(int64_t now, PacketMap* packets) { |
+ while (!packets->empty()) { |
+ auto it = packets->begin(); |
+ if (now - it->second.capture_time_ms < kMaxSentPacketDelayMs) |
+ break; |
+ |
+ packets->erase(it); |
+ ++num_old_packets_; |
+ } |
+} |
+ |
void SendStatisticsProxy::SampleCounter::Add(int sample) { |
sum += sample; |
++num_samples; |