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 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 19 #include "webrtc/system_wrappers/include/critical_section_wrapper.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* GetUmaPrefix(VideoEncoderConfig::ContentType content_type) { | 40 const char* GetUmaPrefix(VideoEncoderConfig::ContentType content_type) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 } | 147 } |
143 int delay_ms = delay_counter_.Avg(kMinRequiredSamples); | 148 int delay_ms = delay_counter_.Avg(kMinRequiredSamples); |
144 if (delay_ms != -1) | 149 if (delay_ms != -1) |
145 RTC_HISTOGRAM_COUNTS_100000(uma_prefix_ + "SendSideDelayInMs", delay_ms); | 150 RTC_HISTOGRAM_COUNTS_100000(uma_prefix_ + "SendSideDelayInMs", delay_ms); |
146 | 151 |
147 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples); | 152 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples); |
148 if (max_delay_ms != -1) { | 153 if (max_delay_ms != -1) { |
149 RTC_HISTOGRAM_COUNTS_100000(uma_prefix_ + "SendSideDelayMaxInMs", | 154 RTC_HISTOGRAM_COUNTS_100000(uma_prefix_ + "SendSideDelayMaxInMs", |
150 max_delay_ms); | 155 max_delay_ms); |
151 } | 156 } |
157 for (const auto& it : send_delay_counters_) { | |
158 int send_delay_ms = it.second.Avg(kMinRequiredSamples); | |
159 if (send_delay_ms != -1) | |
160 RTC_HISTOGRAM_COUNTS_10000(uma_prefix_ + "SendDelayInMs", send_delay_ms); | |
161 } | |
152 } | 162 } |
153 | 163 |
154 void SendStatisticsProxy::SetContentType( | 164 void SendStatisticsProxy::SetContentType( |
155 VideoEncoderConfig::ContentType content_type) { | 165 VideoEncoderConfig::ContentType content_type) { |
156 rtc::CritScope lock(&crit_); | 166 rtc::CritScope lock(&crit_); |
157 if (content_type_ != content_type) { | 167 if (content_type_ != content_type) { |
158 uma_container_->UpdateHistograms(); | 168 uma_container_->UpdateHistograms(); |
159 uma_container_.reset(new UmaSamplesContainer(GetUmaPrefix(content_type))); | 169 uma_container_.reset(new UmaSamplesContainer(GetUmaPrefix(content_type))); |
160 content_type_ = content_type; | 170 content_type_ = content_type; |
161 } | 171 } |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 386 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
377 if (stats == nullptr) | 387 if (stats == nullptr) |
378 return; | 388 return; |
379 stats->avg_delay_ms = avg_delay_ms; | 389 stats->avg_delay_ms = avg_delay_ms; |
380 stats->max_delay_ms = max_delay_ms; | 390 stats->max_delay_ms = max_delay_ms; |
381 | 391 |
382 uma_container_->delay_counter_.Add(avg_delay_ms); | 392 uma_container_->delay_counter_.Add(avg_delay_ms); |
383 uma_container_->max_delay_counter_.Add(max_delay_ms); | 393 uma_container_->max_delay_counter_.Add(max_delay_ms); |
384 } | 394 } |
385 | 395 |
396 void SendStatisticsProxy::OnSendPacket(uint16_t packet_id, | |
397 int64_t capture_time_ms, | |
398 uint32_t ssrc) { | |
399 rtc::CritScope lock(&crit_); | |
400 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | |
401 if (stats == nullptr) | |
402 return; | |
403 | |
404 int64_t now = clock_->TimeInMilliseconds(); | |
405 RemoveOld(now, &packets_); | |
406 | |
407 if (packets_.size() > kMaxSendPacketMapSize) | |
408 return; | |
409 | |
410 Packet packet; | |
411 packet.ssrc = ssrc; | |
412 packet.cap_time_ms = capture_time_ms; | |
413 packet.send_time_ms = now; | |
414 packets_[packet_id] = packet; | |
stefan-webrtc
2015/12/10 08:37:50
Would be nice to use a constructor here instead.
åsapersson
2015/12/15 14:28:27
Done.
| |
415 } | |
416 | |
417 bool SendStatisticsProxy::OnSentPacket(int packet_id) { | |
418 if (packet_id == -1) | |
419 return false; | |
420 | |
421 rtc::CritScope lock(&crit_); | |
422 auto it = packets_.find(packet_id); | |
423 if (it == packets_.end()) | |
424 return false; | |
425 | |
426 // TODO(asapersson): Use diff to cap_time_ms to update delay_counter_. | |
stefan-webrtc
2015/12/10 08:37:50
I think we would like to track all of capture -> s
åsapersson
2015/12/15 14:28:27
Encode time stats is capture -> pacer.
I plan to a
stefan-webrtc
2016/01/18 19:48:25
Sounds great.
| |
427 int diff_send = clock_->TimeInMilliseconds() - it->second.send_time_ms; | |
428 uma_container_->send_delay_counters_[it->second.ssrc].Add(diff_send); | |
429 packets_.erase(it); | |
430 return true; | |
431 } | |
432 | |
433 void SendStatisticsProxy::RemoveOld(int64_t now, PacketMap* packets) { | |
434 while (!packets->empty()) { | |
435 auto it = packets->begin(); | |
436 if (now - it->second.cap_time_ms < kMaxSentPacketDelayMs) { | |
437 break; | |
438 } | |
439 packets->erase(it); | |
440 } | |
stefan-webrtc
2015/12/10 08:37:50
Maybe we should add some LOG here to catch if we h
stefan-webrtc
2016/01/18 19:48:25
Do you think this would be good to have? Especiall
åsapersson
2016/04/06 14:52:37
Added logs for number of old and skipped packets.
| |
441 } | |
442 | |
386 void SendStatisticsProxy::SampleCounter::Add(int sample) { | 443 void SendStatisticsProxy::SampleCounter::Add(int sample) { |
387 sum += sample; | 444 sum += sample; |
388 ++num_samples; | 445 ++num_samples; |
389 } | 446 } |
390 | 447 |
391 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { | 448 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { |
392 if (num_samples < min_required_samples || num_samples == 0) | 449 if (num_samples < min_required_samples || num_samples == 0) |
393 return -1; | 450 return -1; |
394 return (sum + (num_samples / 2)) / num_samples; | 451 return (sum + (num_samples / 2)) / num_samples; |
395 } | 452 } |
(...skipping 14 matching lines...) Expand all Loading... | |
410 return Fraction(min_required_samples, 1000.0f); | 467 return Fraction(min_required_samples, 1000.0f); |
411 } | 468 } |
412 | 469 |
413 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 470 int SendStatisticsProxy::BoolSampleCounter::Fraction( |
414 int min_required_samples, float multiplier) const { | 471 int min_required_samples, float multiplier) const { |
415 if (num_samples < min_required_samples || num_samples == 0) | 472 if (num_samples < min_required_samples || num_samples == 0) |
416 return -1; | 473 return -1; |
417 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 474 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
418 } | 475 } |
419 } // namespace webrtc | 476 } // namespace webrtc |
OLD | NEW |