wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/rtp_rtcp/source/receive_statistics_impl.h" |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 12 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 13 | #include <math.h> |
| 14 | |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 15 | #include <cstdlib> |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 16 | #include <vector> |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/remote_bitrate_estimator/test/bwe_test_logging.h" |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 19 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/rtp_rtcp/source/rtp_rtcp_config.h" |
| 21 | #include "modules/rtp_rtcp/source/time_util.h" |
| 22 | #include "rtc_base/logging.h" |
| 23 | #include "system_wrappers/include/clock.h" |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 27 | const int64_t kStatisticsTimeoutMs = 8000; |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 +0000 | [diff] [blame] | 28 | const int64_t kStatisticsProcessIntervalMs = 1000; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 29 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 30 | StreamStatistician::~StreamStatistician() {} |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 31 | |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 32 | StreamStatisticianImpl::StreamStatisticianImpl( |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 33 | uint32_t ssrc, |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 34 | Clock* clock, |
Niels Möller | 5304a32 | 2018-08-27 13:27:05 +0200 | [diff] [blame] | 35 | bool enable_retransmit_detection, |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 36 | RtcpStatisticsCallback* rtcp_callback, |
| 37 | StreamDataCountersCallback* rtp_callback) |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 38 | : ssrc_(ssrc), |
| 39 | clock_(clock), |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 40 | incoming_bitrate_(kStatisticsProcessIntervalMs, |
| 41 | RateStatistics::kBpsScale), |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 42 | max_reordering_threshold_(kDefaultMaxReorderingThreshold), |
Niels Möller | 5304a32 | 2018-08-27 13:27:05 +0200 | [diff] [blame] | 43 | enable_retransmit_detection_(enable_retransmit_detection), |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 44 | jitter_q4_(0), |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 45 | cumulative_loss_(0), |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 46 | last_receive_time_ms_(0), |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 47 | last_received_timestamp_(0), |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 48 | received_seq_first_(0), |
| 49 | received_seq_max_(0), |
| 50 | received_seq_wraps_(0), |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 51 | received_packet_overhead_(12), |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 52 | last_report_inorder_packets_(0), |
| 53 | last_report_old_packets_(0), |
| 54 | last_report_seq_max_(0), |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 55 | rtcp_callback_(rtcp_callback), |
| 56 | rtp_callback_(rtp_callback) {} |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 57 | |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 58 | StreamStatisticianImpl::~StreamStatisticianImpl() = default; |
| 59 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 60 | void StreamStatisticianImpl::IncomingPacket(const RTPHeader& header, |
Niels Möller | 5304a32 | 2018-08-27 13:27:05 +0200 | [diff] [blame] | 61 | size_t packet_length) { |
Niels Möller | b615d1a | 2018-08-27 12:32:21 +0200 | [diff] [blame] | 62 | StreamDataCounters counters; |
| 63 | { |
| 64 | rtc::CritScope cs(&stream_lock_); |
| 65 | |
Niels Möller | 5304a32 | 2018-08-27 13:27:05 +0200 | [diff] [blame] | 66 | bool retransmitted = |
| 67 | enable_retransmit_detection_ && IsRetransmitOfOldPacket(header); |
Niels Möller | b615d1a | 2018-08-27 12:32:21 +0200 | [diff] [blame] | 68 | counters = UpdateCounters(header, packet_length, retransmitted); |
| 69 | } |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 70 | rtp_callback_->DataCountersUpdated(counters, ssrc_); |
sprang@webrtc.org | a45cac0 | 2014-01-27 16:22:08 +0000 | [diff] [blame] | 71 | } |
| 72 | |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 73 | StreamDataCounters StreamStatisticianImpl::UpdateCounters( |
| 74 | const RTPHeader& header, |
| 75 | size_t packet_length, |
| 76 | bool retransmitted) { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 77 | bool in_order = InOrderPacketInternal(header.sequenceNumber); |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 78 | RTC_DCHECK_EQ(ssrc_, header.ssrc); |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 79 | incoming_bitrate_.Update(packet_length, clock_->TimeInMilliseconds()); |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 +0000 | [diff] [blame] | 80 | receive_counters_.transmitted.AddPacket(packet_length, header); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 81 | if (!in_order && retransmitted) { |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 +0000 | [diff] [blame] | 82 | receive_counters_.retransmitted.AddPacket(packet_length, header); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 83 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 84 | |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 85 | if (receive_counters_.transmitted.packets == 1) { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 86 | received_seq_first_ = header.sequenceNumber; |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 87 | receive_counters_.first_packet_time_ms = clock_->TimeInMilliseconds(); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | // Count only the new packets received. That is, if packets 1, 2, 3, 5, 4, 6 |
| 91 | // are received, 4 will be ignored. |
| 92 | if (in_order) { |
| 93 | // Current time in samples. |
danilchap | 3795376 | 2017-02-09 11:15:25 -0800 | [diff] [blame] | 94 | NtpTime receive_time = clock_->CurrentNtpTime(); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 95 | |
| 96 | // Wrong if we use RetransmitOfOldPacket. |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 97 | if (receive_counters_.transmitted.packets > 1 && |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 98 | received_seq_max_ > header.sequenceNumber) { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 99 | // Wrap around detected. |
| 100 | received_seq_wraps_++; |
| 101 | } |
| 102 | // New max. |
| 103 | received_seq_max_ = header.sequenceNumber; |
| 104 | |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 105 | // If new time stamp and more than one in-order packet received, calculate |
| 106 | // new jitter statistics. |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 107 | if (header.timestamp != last_received_timestamp_ && |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 108 | (receive_counters_.transmitted.packets - |
| 109 | receive_counters_.retransmitted.packets) > 1) { |
danilchap | 1227e8b | 2015-12-21 11:06:50 -0800 | [diff] [blame] | 110 | UpdateJitter(header, receive_time); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 111 | } |
| 112 | last_received_timestamp_ = header.timestamp; |
danilchap | 1227e8b | 2015-12-21 11:06:50 -0800 | [diff] [blame] | 113 | last_receive_time_ntp_ = receive_time; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 114 | last_receive_time_ms_ = clock_->TimeInMilliseconds(); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 115 | } |
| 116 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 117 | size_t packet_oh = header.headerLength + header.paddingLength; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 118 | |
| 119 | // Our measured overhead. Filter from RFC 5104 4.2.1.2: |
| 120 | // avg_OH (new) = 15/16*avg_OH (old) + 1/16*pckt_OH, |
| 121 | received_packet_overhead_ = (15 * received_packet_overhead_ + packet_oh) >> 4; |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 122 | return receive_counters_; |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void StreamStatisticianImpl::UpdateJitter(const RTPHeader& header, |
danilchap | 1227e8b | 2015-12-21 11:06:50 -0800 | [diff] [blame] | 126 | NtpTime receive_time) { |
| 127 | uint32_t receive_time_rtp = |
| 128 | NtpToRtp(receive_time, header.payload_type_frequency); |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 129 | uint32_t last_receive_time_rtp = |
danilchap | 1227e8b | 2015-12-21 11:06:50 -0800 | [diff] [blame] | 130 | NtpToRtp(last_receive_time_ntp_, header.payload_type_frequency); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 131 | int32_t time_diff_samples = (receive_time_rtp - last_receive_time_rtp) - |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 132 | (header.timestamp - last_received_timestamp_); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 133 | |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 134 | time_diff_samples = std::abs(time_diff_samples); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 135 | |
| 136 | // lib_jingle sometimes deliver crazy jumps in TS for the same stream. |
| 137 | // If this happens, don't update jitter value. Use 5 secs video frequency |
| 138 | // as the threshold. |
| 139 | if (time_diff_samples < 450000) { |
| 140 | // Note we calculate in Q4 to avoid using float. |
| 141 | int32_t jitter_diff_q4 = (time_diff_samples << 4) - jitter_q4_; |
| 142 | jitter_q4_ += ((jitter_diff_q4 + 8) >> 4); |
| 143 | } |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 144 | } |
| 145 | |
asapersson@webrtc.org | 273fbbb | 2015-01-27 12:17:29 +0000 | [diff] [blame] | 146 | void StreamStatisticianImpl::FecPacketReceived(const RTPHeader& header, |
| 147 | size_t packet_length) { |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 148 | StreamDataCounters counters; |
sprang@webrtc.org | a45cac0 | 2014-01-27 16:22:08 +0000 | [diff] [blame] | 149 | { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 150 | rtc::CritScope cs(&stream_lock_); |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 +0000 | [diff] [blame] | 151 | receive_counters_.fec.AddPacket(packet_length, header); |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 152 | counters = receive_counters_; |
sprang@webrtc.org | a45cac0 | 2014-01-27 16:22:08 +0000 | [diff] [blame] | 153 | } |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 154 | rtp_callback_->DataCountersUpdated(counters, ssrc_); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 155 | } |
| 156 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 157 | void StreamStatisticianImpl::SetMaxReorderingThreshold( |
| 158 | int max_reordering_threshold) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 159 | rtc::CritScope cs(&stream_lock_); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 160 | max_reordering_threshold_ = max_reordering_threshold; |
| 161 | } |
| 162 | |
Niels Möller | 5304a32 | 2018-08-27 13:27:05 +0200 | [diff] [blame] | 163 | void StreamStatisticianImpl::EnableRetransmitDetection(bool enable) { |
| 164 | rtc::CritScope cs(&stream_lock_); |
| 165 | enable_retransmit_detection_ = enable; |
| 166 | } |
| 167 | |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 168 | bool StreamStatisticianImpl::GetStatistics(RtcpStatistics* statistics, |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 169 | bool reset) { |
sprang@webrtc.org | 7dba27c | 2014-01-21 16:33:37 +0000 | [diff] [blame] | 170 | { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 171 | rtc::CritScope cs(&stream_lock_); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 172 | if (received_seq_first_ == 0 && |
| 173 | receive_counters_.transmitted.payload_bytes == 0) { |
sprang@webrtc.org | 7dba27c | 2014-01-21 16:33:37 +0000 | [diff] [blame] | 174 | // We have not received anything. |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 175 | return false; |
| 176 | } |
sprang@webrtc.org | 7dba27c | 2014-01-21 16:33:37 +0000 | [diff] [blame] | 177 | |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 178 | if (!reset) { |
| 179 | if (last_report_inorder_packets_ == 0) { |
| 180 | // No report. |
| 181 | return false; |
| 182 | } |
| 183 | // Just get last report. |
| 184 | *statistics = last_reported_statistics_; |
| 185 | return true; |
| 186 | } |
| 187 | |
| 188 | *statistics = CalculateRtcpStatistics(); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 191 | rtcp_callback_->StatisticsUpdated(*statistics, ssrc_); |
sprang@webrtc.org | 7dba27c | 2014-01-21 16:33:37 +0000 | [diff] [blame] | 192 | return true; |
| 193 | } |
| 194 | |
Danil Chapovalov | c5267d2 | 2017-09-18 13:57:19 +0200 | [diff] [blame] | 195 | bool StreamStatisticianImpl::GetActiveStatisticsAndReset( |
| 196 | RtcpStatistics* statistics) { |
| 197 | { |
| 198 | rtc::CritScope cs(&stream_lock_); |
| 199 | if (clock_->CurrentNtpInMilliseconds() - last_receive_time_ntp_.ToMs() >= |
| 200 | kStatisticsTimeoutMs) { |
| 201 | // Not active. |
| 202 | return false; |
| 203 | } |
| 204 | if (received_seq_first_ == 0 && |
| 205 | receive_counters_.transmitted.payload_bytes == 0) { |
| 206 | // We have not received anything. |
| 207 | return false; |
| 208 | } |
| 209 | |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 210 | *statistics = CalculateRtcpStatistics(); |
Danil Chapovalov | c5267d2 | 2017-09-18 13:57:19 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | rtcp_callback_->StatisticsUpdated(*statistics, ssrc_); |
| 214 | return true; |
| 215 | } |
| 216 | |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 217 | RtcpStatistics StreamStatisticianImpl::CalculateRtcpStatistics() { |
| 218 | RtcpStatistics stats; |
sprang@webrtc.org | 7dba27c | 2014-01-21 16:33:37 +0000 | [diff] [blame] | 219 | |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 220 | if (last_report_inorder_packets_ == 0) { |
| 221 | // First time we send a report. |
| 222 | last_report_seq_max_ = received_seq_first_ - 1; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 225 | // Calculate fraction lost. |
| 226 | uint16_t exp_since_last = (received_seq_max_ - last_report_seq_max_); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 227 | |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 228 | if (last_report_seq_max_ > received_seq_max_) { |
| 229 | // Can we assume that the seq_num can't go decrease over a full RTCP period? |
| 230 | exp_since_last = 0; |
| 231 | } |
| 232 | |
| 233 | // Number of received RTP packets since last report, counts all packets but |
| 234 | // not re-transmissions. |
| 235 | uint32_t rec_since_last = (receive_counters_.transmitted.packets - |
| 236 | receive_counters_.retransmitted.packets) - |
| 237 | last_report_inorder_packets_; |
| 238 | |
| 239 | // With NACK we don't know the expected retransmissions during the last |
| 240 | // second. We know how many "old" packets we have received. We just count |
| 241 | // the number of old received to estimate the loss, but it still does not |
| 242 | // guarantee an exact number since we run this based on time triggered by |
| 243 | // sending of an RTP packet. This should have a minimum effect. |
| 244 | |
| 245 | // With NACK we don't count old packets as received since they are |
| 246 | // re-transmitted. We use RTT to decide if a packet is re-ordered or |
| 247 | // re-transmitted. |
| 248 | uint32_t retransmitted_packets = |
| 249 | receive_counters_.retransmitted.packets - last_report_old_packets_; |
| 250 | rec_since_last += retransmitted_packets; |
| 251 | |
| 252 | int32_t missing = 0; |
| 253 | if (exp_since_last > rec_since_last) { |
| 254 | missing = (exp_since_last - rec_since_last); |
| 255 | } |
| 256 | uint8_t local_fraction_lost = 0; |
| 257 | if (exp_since_last) { |
| 258 | // Scale 0 to 255, where 255 is 100% loss. |
| 259 | local_fraction_lost = static_cast<uint8_t>(255 * missing / exp_since_last); |
| 260 | } |
| 261 | stats.fraction_lost = local_fraction_lost; |
| 262 | |
| 263 | // We need a counter for cumulative loss too. |
| 264 | // TODO(danilchap): Ensure cumulative loss is below maximum value of 2^24. |
| 265 | cumulative_loss_ += missing; |
| 266 | stats.packets_lost = cumulative_loss_; |
| 267 | stats.extended_highest_sequence_number = |
| 268 | (received_seq_wraps_ << 16) + received_seq_max_; |
| 269 | // Note: internal jitter value is in Q4 and needs to be scaled by 1/16. |
| 270 | stats.jitter = jitter_q4_ >> 4; |
| 271 | |
| 272 | // Store this report. |
| 273 | last_reported_statistics_ = stats; |
| 274 | |
| 275 | // Only for report blocks in RTCP SR and RR. |
| 276 | last_report_inorder_packets_ = receive_counters_.transmitted.packets - |
| 277 | receive_counters_.retransmitted.packets; |
| 278 | last_report_old_packets_ = receive_counters_.retransmitted.packets; |
| 279 | last_report_seq_max_ = received_seq_max_; |
gaetano.carlucci | 61050f6 | 2016-09-30 06:29:54 -0700 | [diff] [blame] | 280 | BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "cumulative_loss_pkts", |
gaetano.carlucci | 52a5703 | 2016-09-14 05:04:36 -0700 | [diff] [blame] | 281 | clock_->TimeInMilliseconds(), |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 282 | cumulative_loss_, ssrc_); |
gaetano.carlucci | 52a5703 | 2016-09-14 05:04:36 -0700 | [diff] [blame] | 283 | BWE_TEST_LOGGING_PLOT_WITH_SSRC( |
gaetano.carlucci | 61050f6 | 2016-09-30 06:29:54 -0700 | [diff] [blame] | 284 | 1, "received_seq_max_pkts", clock_->TimeInMilliseconds(), |
gaetano.carlucci | 52a5703 | 2016-09-14 05:04:36 -0700 | [diff] [blame] | 285 | (received_seq_max_ - received_seq_first_), ssrc_); |
sprang@webrtc.org | 7dba27c | 2014-01-21 16:33:37 +0000 | [diff] [blame] | 286 | |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 287 | return stats; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 290 | void StreamStatisticianImpl::GetDataCounters(size_t* bytes_received, |
| 291 | uint32_t* packets_received) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 292 | rtc::CritScope cs(&stream_lock_); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 293 | if (bytes_received) { |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 294 | *bytes_received = receive_counters_.transmitted.payload_bytes + |
| 295 | receive_counters_.transmitted.header_bytes + |
| 296 | receive_counters_.transmitted.padding_bytes; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 297 | } |
| 298 | if (packets_received) { |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 299 | *packets_received = receive_counters_.transmitted.packets; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
asapersson@webrtc.org | d952c40 | 2014-11-27 07:38:56 +0000 | [diff] [blame] | 303 | void StreamStatisticianImpl::GetReceiveStreamDataCounters( |
| 304 | StreamDataCounters* data_counters) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 305 | rtc::CritScope cs(&stream_lock_); |
asapersson@webrtc.org | d952c40 | 2014-11-27 07:38:56 +0000 | [diff] [blame] | 306 | *data_counters = receive_counters_; |
asapersson@webrtc.org | d952c40 | 2014-11-27 07:38:56 +0000 | [diff] [blame] | 307 | } |
| 308 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 309 | uint32_t StreamStatisticianImpl::BitrateReceived() const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 310 | rtc::CritScope cs(&stream_lock_); |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 311 | return incoming_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 312 | } |
| 313 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 314 | bool StreamStatisticianImpl::IsRetransmitOfOldPacket( |
Niels Möller | eda0087 | 2018-05-23 13:54:51 +0200 | [diff] [blame] | 315 | const RTPHeader& header) const { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 316 | if (InOrderPacketInternal(header.sequenceNumber)) { |
| 317 | return false; |
| 318 | } |
| 319 | uint32_t frequency_khz = header.payload_type_frequency / 1000; |
| 320 | assert(frequency_khz > 0); |
| 321 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 322 | int64_t time_diff_ms = clock_->TimeInMilliseconds() - last_receive_time_ms_; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 323 | |
| 324 | // Diff in time stamp since last received in order. |
| 325 | uint32_t timestamp_diff = header.timestamp - last_received_timestamp_; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 326 | uint32_t rtp_time_stamp_diff_ms = timestamp_diff / frequency_khz; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 327 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 328 | int64_t max_delay_ms = 0; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 329 | |
Niels Möller | eda0087 | 2018-05-23 13:54:51 +0200 | [diff] [blame] | 330 | // Jitter standard deviation in samples. |
| 331 | float jitter_std = sqrt(static_cast<float>(jitter_q4_ >> 4)); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 332 | |
Niels Möller | eda0087 | 2018-05-23 13:54:51 +0200 | [diff] [blame] | 333 | // 2 times the standard deviation => 95% confidence. |
| 334 | // And transform to milliseconds by dividing by the frequency in kHz. |
| 335 | max_delay_ms = static_cast<int64_t>((2 * jitter_std) / frequency_khz); |
| 336 | |
| 337 | // Min max_delay_ms is 1. |
| 338 | if (max_delay_ms == 0) { |
| 339 | max_delay_ms = 1; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 340 | } |
| 341 | return time_diff_ms > rtp_time_stamp_diff_ms + max_delay_ms; |
| 342 | } |
| 343 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 344 | bool StreamStatisticianImpl::InOrderPacketInternal( |
| 345 | uint16_t sequence_number) const { |
| 346 | // First packet is always in order. |
Qingsi Wang | 2370b08 | 2018-08-21 14:24:26 -0700 | [diff] [blame] | 347 | if (last_receive_time_ms_ == 0) |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 348 | return true; |
| 349 | |
| 350 | if (IsNewerSequenceNumber(sequence_number, received_seq_max_)) { |
| 351 | return true; |
| 352 | } else { |
| 353 | // If we have a restart of the remote side this packet is still in order. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 354 | return !IsNewerSequenceNumber( |
| 355 | sequence_number, received_seq_max_ - max_reordering_threshold_); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 359 | ReceiveStatistics* ReceiveStatistics::Create(Clock* clock) { |
| 360 | return new ReceiveStatisticsImpl(clock); |
| 361 | } |
| 362 | |
| 363 | ReceiveStatisticsImpl::ReceiveStatisticsImpl(Clock* clock) |
| 364 | : clock_(clock), |
Danil Chapovalov | d1996b7 | 2018-01-16 11:07:18 +0100 | [diff] [blame] | 365 | last_returned_ssrc_(0), |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 366 | rtcp_stats_callback_(NULL), |
| 367 | rtp_stats_callback_(NULL) {} |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 368 | |
| 369 | ReceiveStatisticsImpl::~ReceiveStatisticsImpl() { |
| 370 | while (!statisticians_.empty()) { |
| 371 | delete statisticians_.begin()->second; |
| 372 | statisticians_.erase(statisticians_.begin()); |
| 373 | } |
| 374 | } |
| 375 | |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 376 | void ReceiveStatisticsImpl::OnRtpPacket(const RtpPacketReceived& packet) { |
| 377 | RTPHeader header; |
| 378 | packet.GetHeader(&header); |
| 379 | IncomingPacket(header, packet.size()); |
| 380 | } |
| 381 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 382 | void ReceiveStatisticsImpl::IncomingPacket(const RTPHeader& header, |
Niels Möller | 5304a32 | 2018-08-27 13:27:05 +0200 | [diff] [blame] | 383 | size_t packet_length) { |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 384 | StreamStatisticianImpl* impl; |
sprang@webrtc.org | 7dba27c | 2014-01-21 16:33:37 +0000 | [diff] [blame] | 385 | { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 386 | rtc::CritScope cs(&receive_statistics_lock_); |
Danil Chapovalov | c5267d2 | 2017-09-18 13:57:19 +0200 | [diff] [blame] | 387 | auto it = statisticians_.find(header.ssrc); |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 388 | if (it != statisticians_.end()) { |
| 389 | impl = it->second; |
| 390 | } else { |
Niels Möller | 5304a32 | 2018-08-27 13:27:05 +0200 | [diff] [blame] | 391 | impl = new StreamStatisticianImpl( |
| 392 | header.ssrc, clock_, /* enable_retransmit_detection = */ false, this, |
| 393 | this); |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 394 | statisticians_[header.ssrc] = impl; |
sprang@webrtc.org | 7dba27c | 2014-01-21 16:33:37 +0000 | [diff] [blame] | 395 | } |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 396 | } |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 397 | // StreamStatisticianImpl instance is created once and only destroyed when |
| 398 | // this whole ReceiveStatisticsImpl is destroyed. StreamStatisticianImpl has |
| 399 | // it's own locking so don't hold receive_statistics_lock_ (potential |
| 400 | // deadlock). |
Niels Möller | 5304a32 | 2018-08-27 13:27:05 +0200 | [diff] [blame] | 401 | impl->IncomingPacket(header, packet_length); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 404 | void ReceiveStatisticsImpl::FecPacketReceived(const RtpPacketReceived& packet) { |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 405 | StreamStatisticianImpl* impl; |
| 406 | { |
| 407 | rtc::CritScope cs(&receive_statistics_lock_); |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 408 | auto it = statisticians_.find(packet.Ssrc()); |
danilchap | ec86be0 | 2017-08-14 05:51:02 -0700 | [diff] [blame] | 409 | // Ignore FEC if it is the first packet. |
| 410 | if (it == statisticians_.end()) |
| 411 | return; |
| 412 | impl = it->second; |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 413 | } |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 414 | RTPHeader header; |
| 415 | packet.GetHeader(&header); |
| 416 | impl->FecPacketReceived(header, packet.size()); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 417 | } |
| 418 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 419 | StreamStatistician* ReceiveStatisticsImpl::GetStatistician( |
| 420 | uint32_t ssrc) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 421 | rtc::CritScope cs(&receive_statistics_lock_); |
Danil Chapovalov | c5267d2 | 2017-09-18 13:57:19 +0200 | [diff] [blame] | 422 | auto it = statisticians_.find(ssrc); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 423 | if (it == statisticians_.end()) |
| 424 | return NULL; |
| 425 | return it->second; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 426 | } |
| 427 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 428 | void ReceiveStatisticsImpl::SetMaxReorderingThreshold( |
| 429 | int max_reordering_threshold) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 430 | rtc::CritScope cs(&receive_statistics_lock_); |
Danil Chapovalov | c5267d2 | 2017-09-18 13:57:19 +0200 | [diff] [blame] | 431 | for (auto& statistician : statisticians_) { |
| 432 | statistician.second->SetMaxReorderingThreshold(max_reordering_threshold); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
Niels Möller | 5304a32 | 2018-08-27 13:27:05 +0200 | [diff] [blame] | 436 | void ReceiveStatisticsImpl::EnableRetransmitDetection(uint32_t ssrc, |
| 437 | bool enable) { |
| 438 | StreamStatisticianImpl* impl; |
| 439 | { |
| 440 | rtc::CritScope cs(&receive_statistics_lock_); |
| 441 | StreamStatisticianImpl*& impl_ref = statisticians_[ssrc]; |
| 442 | if (impl_ref == nullptr) { // new element |
| 443 | impl_ref = new StreamStatisticianImpl(ssrc, clock_, enable, this, this); |
| 444 | return; |
| 445 | } |
| 446 | impl = impl_ref; |
| 447 | } |
| 448 | impl->EnableRetransmitDetection(enable); |
| 449 | } |
| 450 | |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 451 | void ReceiveStatisticsImpl::RegisterRtcpStatisticsCallback( |
| 452 | RtcpStatisticsCallback* callback) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 453 | rtc::CritScope cs(&receive_statistics_lock_); |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 454 | if (callback != NULL) |
| 455 | assert(rtcp_stats_callback_ == NULL); |
| 456 | rtcp_stats_callback_ = callback; |
| 457 | } |
| 458 | |
| 459 | void ReceiveStatisticsImpl::StatisticsUpdated(const RtcpStatistics& statistics, |
| 460 | uint32_t ssrc) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 461 | rtc::CritScope cs(&receive_statistics_lock_); |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 462 | if (rtcp_stats_callback_) |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 463 | rtcp_stats_callback_->StatisticsUpdated(statistics, ssrc); |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | void ReceiveStatisticsImpl::CNameChanged(const char* cname, uint32_t ssrc) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 467 | rtc::CritScope cs(&receive_statistics_lock_); |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 468 | if (rtcp_stats_callback_) |
| 469 | rtcp_stats_callback_->CNameChanged(cname, ssrc); |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 470 | } |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 471 | |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 472 | void ReceiveStatisticsImpl::RegisterRtpStatisticsCallback( |
| 473 | StreamDataCountersCallback* callback) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 474 | rtc::CritScope cs(&receive_statistics_lock_); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 475 | if (callback != NULL) |
| 476 | assert(rtp_stats_callback_ == NULL); |
| 477 | rtp_stats_callback_ = callback; |
| 478 | } |
| 479 | |
| 480 | void ReceiveStatisticsImpl::DataCountersUpdated(const StreamDataCounters& stats, |
| 481 | uint32_t ssrc) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 482 | rtc::CritScope cs(&receive_statistics_lock_); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 483 | if (rtp_stats_callback_) { |
| 484 | rtp_stats_callback_->DataCountersUpdated(stats, ssrc); |
| 485 | } |
| 486 | } |
| 487 | |
danilchap | 0bc8423 | 2017-08-11 08:12:54 -0700 | [diff] [blame] | 488 | std::vector<rtcp::ReportBlock> ReceiveStatisticsImpl::RtcpReportBlocks( |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 489 | size_t max_blocks) { |
Danil Chapovalov | c5267d2 | 2017-09-18 13:57:19 +0200 | [diff] [blame] | 490 | std::map<uint32_t, StreamStatisticianImpl*> statisticians; |
| 491 | { |
| 492 | rtc::CritScope cs(&receive_statistics_lock_); |
| 493 | statisticians = statisticians_; |
| 494 | } |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 495 | std::vector<rtcp::ReportBlock> result; |
| 496 | result.reserve(std::min(max_blocks, statisticians.size())); |
Danil Chapovalov | d1996b7 | 2018-01-16 11:07:18 +0100 | [diff] [blame] | 497 | auto add_report_block = [&result](uint32_t media_ssrc, |
| 498 | StreamStatisticianImpl* statistician) { |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 499 | // Do we have receive statistics to send? |
| 500 | RtcpStatistics stats; |
Danil Chapovalov | d1996b7 | 2018-01-16 11:07:18 +0100 | [diff] [blame] | 501 | if (!statistician->GetActiveStatisticsAndReset(&stats)) |
| 502 | return; |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 503 | result.emplace_back(); |
| 504 | rtcp::ReportBlock& block = result.back(); |
Danil Chapovalov | d1996b7 | 2018-01-16 11:07:18 +0100 | [diff] [blame] | 505 | block.SetMediaSsrc(media_ssrc); |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 506 | block.SetFractionLost(stats.fraction_lost); |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 507 | if (!block.SetCumulativeLost(stats.packets_lost)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 508 | RTC_LOG(LS_WARNING) << "Cumulative lost is oversized."; |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 509 | result.pop_back(); |
Danil Chapovalov | d1996b7 | 2018-01-16 11:07:18 +0100 | [diff] [blame] | 510 | return; |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 511 | } |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 512 | block.SetExtHighestSeqNum(stats.extended_highest_sequence_number); |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 513 | block.SetJitter(stats.jitter); |
Danil Chapovalov | d1996b7 | 2018-01-16 11:07:18 +0100 | [diff] [blame] | 514 | }; |
| 515 | |
| 516 | const auto start_it = statisticians.upper_bound(last_returned_ssrc_); |
| 517 | for (auto it = start_it; |
| 518 | result.size() < max_blocks && it != statisticians.end(); ++it) |
| 519 | add_report_block(it->first, it->second); |
| 520 | for (auto it = statisticians.begin(); |
| 521 | result.size() < max_blocks && it != start_it; ++it) |
| 522 | add_report_block(it->first, it->second); |
| 523 | |
| 524 | if (!result.empty()) |
| 525 | last_returned_ssrc_ = result.back().source_ssrc(); |
danilchap | f5f793c | 2017-07-27 04:44:18 -0700 | [diff] [blame] | 526 | return result; |
| 527 | } |
| 528 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 529 | } // namespace webrtc |