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