Index: webrtc/video/send_statistics_proxy.cc |
diff --git a/webrtc/video/send_statistics_proxy.cc b/webrtc/video/send_statistics_proxy.cc |
index 5c2052a207868d9c6b2e5c7bd4e7edbb0a83d7e1..ff83d5f23e730d0e57e4c4bb1dc01a4f0548d3b6 100644 |
--- a/webrtc/video/send_statistics_proxy.cc |
+++ b/webrtc/video/send_statistics_proxy.cc |
@@ -15,13 +15,17 @@ |
#include <map> |
#include "webrtc/base/checks.h" |
- |
#include "webrtc/base/logging.h" |
#include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
#include "webrtc/system_wrappers/include/metrics.h" |
namespace webrtc { |
namespace { |
+// 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, |
@@ -126,6 +130,10 @@ void SendStatisticsProxy::UpdateHistograms() { |
RTC_HISTOGRAM_COUNTS_100000( |
"WebRTC.Video.SendSideDelayMaxInMs", max_delay_ms); |
} |
+ int send_delay_ms = send_delay_counter_.Avg(kMinRequiredSamples); |
+ if (send_delay_ms != -1) { |
+ RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.SendDelayInMs", send_delay_ms); |
+ } |
} |
void SendStatisticsProxy::OnOutgoingRate(uint32_t framerate, uint32_t bitrate) { |
@@ -347,6 +355,52 @@ void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms, |
max_delay_counter_.Add(max_delay_ms); |
} |
+void SendStatisticsProxy::OnSendPacket(uint16_t packet_id, |
+ int64_t capture_time_ms, |
+ uint32_t ssrc) { |
+ rtc::CritScope lock(&crit_); |
+ VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
+ if (stats == nullptr) |
+ return; |
+ |
+ int64_t now = clock_->TimeInMilliseconds(); |
+ RemoveOld(now, &packets_); |
+ |
+ if (packets_.size() > kMaxSendPacketMapSize) |
+ return; |
+ |
+ Packet packet; |
+ packet.cap_time_ms = capture_time_ms; |
+ packet.send_time_ms = now; |
+ packets_[packet_id] = packet; |
+} |
+ |
+bool SendStatisticsProxy::OnSentPacket(int packet_id) { |
+ if (packet_id == -1) |
+ return false; |
+ |
+ rtc::CritScope lock(&crit_); |
+ auto it = packets_.find(packet_id); |
+ if (it == packets_.end()) |
+ return false; |
+ |
+ // TODO(asapersson): Use diff to cap_time_ms to update delay_counter_. |
+ int diff_send = clock_->TimeInMilliseconds() - it->second.send_time_ms; |
+ send_delay_counter_.Add(diff_send); |
+ packets_.erase(it); |
pbos-webrtc
2015/12/07 06:05:52
This means that we can't update packets' send time
åsapersson
2015/12/08 12:50:15
OnSendPacket is called from webrtc
OnSentPacket is
|
+ return true; |
+} |
+ |
+void SendStatisticsProxy::RemoveOld(int64_t now, PacketMap* packets) { |
+ while (!packets->empty()) { |
+ auto it = packets->begin(); |
+ if (now - it->second.cap_time_ms < kMaxSentPacketDelayMs) { |
+ break; |
+ } |
+ packets->erase(it); |
+ } |
+} |
+ |
void SendStatisticsProxy::SampleCounter::Add(int sample) { |
sum += sample; |
++num_samples; |