Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: webrtc/video/send_statistics_proxy.cc

Issue 1478253002: Add histogram stats for send delay for a sent video stream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18
19 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
20 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
21 #include "webrtc/system_wrappers/include/metrics.h" 20 #include "webrtc/system_wrappers/include/metrics.h"
22 21
23 namespace webrtc { 22 namespace webrtc {
24 namespace { 23 namespace {
24 // Packet with a larger delay are removed and excluded from the delay stats.
25 // Set to larger than max histogram delay which is 10000.
26 const int64_t kMaxSentPacketDelayMs = 11000;
27 const size_t kMaxSendPacketMapSize = 2000;
28
25 // Used by histograms. Values of entries should not be changed. 29 // Used by histograms. Values of entries should not be changed.
26 enum HistogramCodecType { 30 enum HistogramCodecType {
27 kVideoUnknown = 0, 31 kVideoUnknown = 0,
28 kVideoVp8 = 1, 32 kVideoVp8 = 1,
29 kVideoVp9 = 2, 33 kVideoVp9 = 2,
30 kVideoH264 = 3, 34 kVideoH264 = 3,
31 kVideoMax = 64, 35 kVideoMax = 64,
32 }; 36 };
33 37
34 HistogramCodecType PayloadNameToHistogramCodecType( 38 HistogramCodecType PayloadNameToHistogramCodecType(
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 123 }
120 int delay_ms = delay_counter_.Avg(kMinRequiredSamples); 124 int delay_ms = delay_counter_.Avg(kMinRequiredSamples);
121 if (delay_ms != -1) 125 if (delay_ms != -1)
122 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Video.SendSideDelayInMs", delay_ms); 126 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Video.SendSideDelayInMs", delay_ms);
123 127
124 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples); 128 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples);
125 if (max_delay_ms != -1) { 129 if (max_delay_ms != -1) {
126 RTC_HISTOGRAM_COUNTS_100000( 130 RTC_HISTOGRAM_COUNTS_100000(
127 "WebRTC.Video.SendSideDelayMaxInMs", max_delay_ms); 131 "WebRTC.Video.SendSideDelayMaxInMs", max_delay_ms);
128 } 132 }
133 int send_delay_ms = send_delay_counter_.Avg(kMinRequiredSamples);
134 if (send_delay_ms != -1) {
135 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.SendDelayInMs", send_delay_ms);
136 }
129 } 137 }
130 138
131 void SendStatisticsProxy::OnOutgoingRate(uint32_t framerate, uint32_t bitrate) { 139 void SendStatisticsProxy::OnOutgoingRate(uint32_t framerate, uint32_t bitrate) {
132 rtc::CritScope lock(&crit_); 140 rtc::CritScope lock(&crit_);
133 stats_.encode_frame_rate = framerate; 141 stats_.encode_frame_rate = framerate;
134 stats_.media_bitrate_bps = bitrate; 142 stats_.media_bitrate_bps = bitrate;
135 } 143 }
136 144
137 void SendStatisticsProxy::CpuOveruseMetricsUpdated( 145 void SendStatisticsProxy::CpuOveruseMetricsUpdated(
138 const CpuOveruseMetrics& metrics) { 146 const CpuOveruseMetrics& metrics) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); 348 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
341 if (stats == nullptr) 349 if (stats == nullptr)
342 return; 350 return;
343 stats->avg_delay_ms = avg_delay_ms; 351 stats->avg_delay_ms = avg_delay_ms;
344 stats->max_delay_ms = max_delay_ms; 352 stats->max_delay_ms = max_delay_ms;
345 353
346 delay_counter_.Add(avg_delay_ms); 354 delay_counter_.Add(avg_delay_ms);
347 max_delay_counter_.Add(max_delay_ms); 355 max_delay_counter_.Add(max_delay_ms);
348 } 356 }
349 357
358 void SendStatisticsProxy::OnSendPacket(uint16_t packet_id,
359 int64_t capture_time_ms,
360 uint32_t ssrc) {
361 rtc::CritScope lock(&crit_);
362 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
363 if (stats == nullptr)
364 return;
365
366 int64_t now = clock_->TimeInMilliseconds();
367 RemoveOld(now, &packets_);
368
369 if (packets_.size() > kMaxSendPacketMapSize)
370 return;
371
372 Packet packet;
373 packet.cap_time_ms = capture_time_ms;
374 packet.send_time_ms = now;
375 packets_[packet_id] = packet;
376 }
377
378 bool SendStatisticsProxy::OnSentPacket(int packet_id) {
379 if (packet_id == -1)
380 return false;
381
382 rtc::CritScope lock(&crit_);
383 auto it = packets_.find(packet_id);
384 if (it == packets_.end())
385 return false;
386
387 // TODO(asapersson): Use diff to cap_time_ms to update delay_counter_.
388 int diff_send = clock_->TimeInMilliseconds() - it->second.send_time_ms;
389 send_delay_counter_.Add(diff_send);
390 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
391 return true;
392 }
393
394 void SendStatisticsProxy::RemoveOld(int64_t now, PacketMap* packets) {
395 while (!packets->empty()) {
396 auto it = packets->begin();
397 if (now - it->second.cap_time_ms < kMaxSentPacketDelayMs) {
398 break;
399 }
400 packets->erase(it);
401 }
402 }
403
350 void SendStatisticsProxy::SampleCounter::Add(int sample) { 404 void SendStatisticsProxy::SampleCounter::Add(int sample) {
351 sum += sample; 405 sum += sample;
352 ++num_samples; 406 ++num_samples;
353 } 407 }
354 408
355 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { 409 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const {
356 if (num_samples < min_required_samples || num_samples == 0) 410 if (num_samples < min_required_samples || num_samples == 0)
357 return -1; 411 return -1;
358 return (sum + (num_samples / 2)) / num_samples; 412 return (sum + (num_samples / 2)) / num_samples;
359 } 413 }
(...skipping 15 matching lines...) Expand all
375 } 429 }
376 430
377 int SendStatisticsProxy::BoolSampleCounter::Fraction( 431 int SendStatisticsProxy::BoolSampleCounter::Fraction(
378 int min_required_samples, float multiplier) const { 432 int min_required_samples, float multiplier) const {
379 if (num_samples < min_required_samples || num_samples == 0) 433 if (num_samples < min_required_samples || num_samples == 0)
380 return -1; 434 return -1;
381 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); 435 return static_cast<int>((sum * multiplier / num_samples) + 0.5f);
382 } 436 }
383 437
384 } // namespace webrtc 438 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698