philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 11 | #include "modules/video_coding/deprecated/nack_module.h" |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 12 | |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | #include <limits> |
| 15 | |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 16 | #include "api/units/timestamp.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/utility/include/process_thread.h" |
| 18 | #include "rtc_base/checks.h" |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 19 | #include "rtc_base/experiments/field_trial_parser.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "rtc_base/logging.h" |
Ying Wang | 0367d1a | 2018-11-02 14:51:15 +0100 | [diff] [blame] | 21 | #include "system_wrappers/include/field_trial.h" |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | namespace { |
| 26 | const int kMaxPacketAge = 10000; |
| 27 | const int kMaxNackPackets = 1000; |
| 28 | const int kDefaultRttMs = 100; |
| 29 | const int kMaxNackRetries = 10; |
| 30 | const int kProcessFrequency = 50; |
| 31 | const int kProcessIntervalMs = 1000 / kProcessFrequency; |
| 32 | const int kMaxReorderedPackets = 128; |
| 33 | const int kNumReorderingBuckets = 10; |
Ying Wang | 0367d1a | 2018-11-02 14:51:15 +0100 | [diff] [blame] | 34 | const int kDefaultSendNackDelayMs = 0; |
| 35 | |
| 36 | int64_t GetSendNackDelay() { |
| 37 | int64_t delay_ms = strtol( |
| 38 | webrtc::field_trial::FindFullName("WebRTC-SendNackDelayMs").c_str(), |
| 39 | nullptr, 10); |
| 40 | if (delay_ms > 0 && delay_ms <= 20) { |
| 41 | RTC_LOG(LS_INFO) << "SendNackDelay is set to " << delay_ms; |
| 42 | return delay_ms; |
| 43 | } |
| 44 | return kDefaultSendNackDelayMs; |
| 45 | } |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 46 | } // namespace |
| 47 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 48 | DEPRECATED_NackModule::NackInfo::NackInfo() |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 49 | : seq_num(0), send_at_seq_num(0), sent_at_time(-1), retries(0) {} |
| 50 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 51 | DEPRECATED_NackModule::NackInfo::NackInfo(uint16_t seq_num, |
| 52 | uint16_t send_at_seq_num, |
| 53 | int64_t created_at_time) |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 54 | : seq_num(seq_num), |
| 55 | send_at_seq_num(send_at_seq_num), |
Ying Wang | 0367d1a | 2018-11-02 14:51:15 +0100 | [diff] [blame] | 56 | created_at_time(created_at_time), |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 57 | sent_at_time(-1), |
| 58 | retries(0) {} |
| 59 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 60 | DEPRECATED_NackModule::BackoffSettings::BackoffSettings(TimeDelta min_retry, |
| 61 | TimeDelta max_rtt, |
| 62 | double base) |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 63 | : min_retry_interval(min_retry), max_rtt(max_rtt), base(base) {} |
| 64 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 65 | absl::optional<DEPRECATED_NackModule::BackoffSettings> |
| 66 | DEPRECATED_NackModule::BackoffSettings::ParseFromFieldTrials() { |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 67 | // Matches magic number in RTPSender::OnReceivedNack(). |
Danil Chapovalov | 5528402 | 2020-02-07 14:53:52 +0100 | [diff] [blame] | 68 | const TimeDelta kDefaultMinRetryInterval = TimeDelta::Millis(5); |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 69 | // Upper bound on link-delay considered for exponential backoff. |
| 70 | // Selected so that cumulative delay with 1.25 base and 10 retries ends up |
| 71 | // below 3s, since above that there will be a FIR generated instead. |
Danil Chapovalov | 5528402 | 2020-02-07 14:53:52 +0100 | [diff] [blame] | 72 | const TimeDelta kDefaultMaxRtt = TimeDelta::Millis(160); |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 73 | // Default base for exponential backoff, adds 25% RTT delay for each retry. |
| 74 | const double kDefaultBase = 1.25; |
| 75 | |
| 76 | FieldTrialParameter<bool> enabled("enabled", false); |
| 77 | FieldTrialParameter<TimeDelta> min_retry("min_retry", |
| 78 | kDefaultMinRetryInterval); |
| 79 | FieldTrialParameter<TimeDelta> max_rtt("max_rtt", kDefaultMaxRtt); |
| 80 | FieldTrialParameter<double> base("base", kDefaultBase); |
| 81 | ParseFieldTrial({&enabled, &min_retry, &max_rtt, &base}, |
| 82 | field_trial::FindFullName("WebRTC-ExponentialNackBackoff")); |
| 83 | |
| 84 | if (enabled) { |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 85 | return DEPRECATED_NackModule::BackoffSettings(min_retry.Get(), |
| 86 | max_rtt.Get(), base.Get()); |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 87 | } |
| 88 | return absl::nullopt; |
| 89 | } |
| 90 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 91 | DEPRECATED_NackModule::DEPRECATED_NackModule( |
| 92 | Clock* clock, |
| 93 | NackSender* nack_sender, |
| 94 | KeyFrameRequestSender* keyframe_request_sender) |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 95 | : clock_(clock), |
| 96 | nack_sender_(nack_sender), |
| 97 | keyframe_request_sender_(keyframe_request_sender), |
| 98 | reordering_histogram_(kNumReorderingBuckets, kMaxReorderedPackets), |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 99 | initialized_(false), |
| 100 | rtt_ms_(kDefaultRttMs), |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 101 | newest_seq_num_(0), |
Ying Wang | 0367d1a | 2018-11-02 14:51:15 +0100 | [diff] [blame] | 102 | next_process_time_ms_(-1), |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 103 | send_nack_delay_ms_(GetSendNackDelay()), |
| 104 | backoff_settings_(BackoffSettings::ParseFromFieldTrials()) { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 105 | RTC_DCHECK(clock_); |
| 106 | RTC_DCHECK(nack_sender_); |
| 107 | RTC_DCHECK(keyframe_request_sender_); |
| 108 | } |
| 109 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 110 | int DEPRECATED_NackModule::OnReceivedPacket(uint16_t seq_num, |
| 111 | bool is_keyframe) { |
Ying Wang | b32bb95 | 2018-10-31 10:12:27 +0100 | [diff] [blame] | 112 | return OnReceivedPacket(seq_num, is_keyframe, false); |
| 113 | } |
| 114 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 115 | int DEPRECATED_NackModule::OnReceivedPacket(uint16_t seq_num, |
| 116 | bool is_keyframe, |
| 117 | bool is_recovered) { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 118 | rtc::CritScope lock(&crit_); |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 119 | // TODO(philipel): When the packet includes information whether it is |
| 120 | // retransmitted or not, use that value instead. For |
| 121 | // now set it to true, which will cause the reordering |
| 122 | // statistics to never be updated. |
| 123 | bool is_retransmitted = true; |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 124 | |
| 125 | if (!initialized_) { |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 126 | newest_seq_num_ = seq_num; |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 127 | if (is_keyframe) |
| 128 | keyframe_list_.insert(seq_num); |
| 129 | initialized_ = true; |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 130 | return 0; |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 131 | } |
| 132 | |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 133 | // Since the |newest_seq_num_| is a packet we have actually received we know |
| 134 | // that packet has never been Nacked. |
| 135 | if (seq_num == newest_seq_num_) |
| 136 | return 0; |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 137 | |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 138 | if (AheadOf(newest_seq_num_, seq_num)) { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 139 | // An out of order packet has been received. |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 140 | auto nack_list_it = nack_list_.find(seq_num); |
| 141 | int nacks_sent_for_packet = 0; |
| 142 | if (nack_list_it != nack_list_.end()) { |
| 143 | nacks_sent_for_packet = nack_list_it->second.retries; |
| 144 | nack_list_.erase(nack_list_it); |
| 145 | } |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 146 | if (!is_retransmitted) |
| 147 | UpdateReorderingStatistics(seq_num); |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 148 | return nacks_sent_for_packet; |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 149 | } |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 150 | |
| 151 | // Keep track of new keyframes. |
| 152 | if (is_keyframe) |
| 153 | keyframe_list_.insert(seq_num); |
| 154 | |
| 155 | // And remove old ones so we don't accumulate keyframes. |
| 156 | auto it = keyframe_list_.lower_bound(seq_num - kMaxPacketAge); |
| 157 | if (it != keyframe_list_.begin()) |
| 158 | keyframe_list_.erase(keyframe_list_.begin(), it); |
| 159 | |
Ying Wang | b32bb95 | 2018-10-31 10:12:27 +0100 | [diff] [blame] | 160 | if (is_recovered) { |
| 161 | recovered_list_.insert(seq_num); |
| 162 | |
| 163 | // Remove old ones so we don't accumulate recovered packets. |
| 164 | auto it = recovered_list_.lower_bound(seq_num - kMaxPacketAge); |
| 165 | if (it != recovered_list_.begin()) |
| 166 | recovered_list_.erase(recovered_list_.begin(), it); |
| 167 | |
| 168 | // Do not send nack for packets recovered by FEC or RTX. |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | AddPacketsToNack(newest_seq_num_ + 1, seq_num); |
| 173 | newest_seq_num_ = seq_num; |
| 174 | |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 175 | // Are there any nacks that are waiting for this seq_num. |
| 176 | std::vector<uint16_t> nack_batch = GetNackBatch(kSeqNumOnly); |
Elad Alon | ef09c5b | 2019-05-31 13:25:50 +0200 | [diff] [blame] | 177 | if (!nack_batch.empty()) { |
| 178 | // This batch of NACKs is triggered externally; the initiator can |
| 179 | // batch them with other feedback messages. |
| 180 | nack_sender_->SendNack(nack_batch, /*buffering_allowed=*/true); |
| 181 | } |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 182 | |
| 183 | return 0; |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 186 | void DEPRECATED_NackModule::ClearUpTo(uint16_t seq_num) { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 187 | rtc::CritScope lock(&crit_); |
| 188 | nack_list_.erase(nack_list_.begin(), nack_list_.lower_bound(seq_num)); |
| 189 | keyframe_list_.erase(keyframe_list_.begin(), |
| 190 | keyframe_list_.lower_bound(seq_num)); |
Ying Wang | b32bb95 | 2018-10-31 10:12:27 +0100 | [diff] [blame] | 191 | recovered_list_.erase(recovered_list_.begin(), |
| 192 | recovered_list_.lower_bound(seq_num)); |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 195 | void DEPRECATED_NackModule::UpdateRtt(int64_t rtt_ms) { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 196 | rtc::CritScope lock(&crit_); |
| 197 | rtt_ms_ = rtt_ms; |
| 198 | } |
| 199 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 200 | void DEPRECATED_NackModule::Clear() { |
philipel | 83f831a | 2016-03-12 03:30:23 -0800 | [diff] [blame] | 201 | rtc::CritScope lock(&crit_); |
| 202 | nack_list_.clear(); |
| 203 | keyframe_list_.clear(); |
Ying Wang | b32bb95 | 2018-10-31 10:12:27 +0100 | [diff] [blame] | 204 | recovered_list_.clear(); |
philipel | 83f831a | 2016-03-12 03:30:23 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 207 | int64_t DEPRECATED_NackModule::TimeUntilNextProcess() { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 208 | return std::max<int64_t>(next_process_time_ms_ - clock_->TimeInMilliseconds(), |
| 209 | 0); |
| 210 | } |
| 211 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 212 | void DEPRECATED_NackModule::Process() { |
tommi | f284b7f | 2017-02-27 01:59:36 -0800 | [diff] [blame] | 213 | if (nack_sender_) { |
| 214 | std::vector<uint16_t> nack_batch; |
| 215 | { |
| 216 | rtc::CritScope lock(&crit_); |
| 217 | nack_batch = GetNackBatch(kTimeOnly); |
| 218 | } |
| 219 | |
Elad Alon | ef09c5b | 2019-05-31 13:25:50 +0200 | [diff] [blame] | 220 | if (!nack_batch.empty()) { |
| 221 | // This batch of NACKs is triggered externally; there is no external |
| 222 | // initiator who can batch them with other feedback messages. |
| 223 | nack_sender_->SendNack(nack_batch, /*buffering_allowed=*/false); |
| 224 | } |
tommi | f284b7f | 2017-02-27 01:59:36 -0800 | [diff] [blame] | 225 | } |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 226 | |
| 227 | // Update the next_process_time_ms_ in intervals to achieve |
| 228 | // the targeted frequency over time. Also add multiple intervals |
| 229 | // in case of a skip in time as to not make uneccessary |
| 230 | // calls to Process in order to catch up. |
| 231 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 232 | if (next_process_time_ms_ == -1) { |
| 233 | next_process_time_ms_ = now_ms + kProcessIntervalMs; |
| 234 | } else { |
| 235 | next_process_time_ms_ = next_process_time_ms_ + kProcessIntervalMs + |
| 236 | (now_ms - next_process_time_ms_) / |
| 237 | kProcessIntervalMs * kProcessIntervalMs; |
| 238 | } |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 241 | bool DEPRECATED_NackModule::RemovePacketsUntilKeyFrame() { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 242 | while (!keyframe_list_.empty()) { |
| 243 | auto it = nack_list_.lower_bound(*keyframe_list_.begin()); |
| 244 | |
| 245 | if (it != nack_list_.begin()) { |
| 246 | // We have found a keyframe that actually is newer than at least one |
| 247 | // packet in the nack list. |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 248 | nack_list_.erase(nack_list_.begin(), it); |
| 249 | return true; |
| 250 | } |
| 251 | |
| 252 | // If this keyframe is so old it does not remove any packets from the list, |
| 253 | // remove it from the list of keyframes and try the next keyframe. |
| 254 | keyframe_list_.erase(keyframe_list_.begin()); |
| 255 | } |
| 256 | return false; |
| 257 | } |
| 258 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 259 | void DEPRECATED_NackModule::AddPacketsToNack(uint16_t seq_num_start, |
| 260 | uint16_t seq_num_end) { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 261 | // Remove old packets. |
| 262 | auto it = nack_list_.lower_bound(seq_num_end - kMaxPacketAge); |
| 263 | nack_list_.erase(nack_list_.begin(), it); |
| 264 | |
| 265 | // If the nack list is too large, remove packets from the nack list until |
| 266 | // the latest first packet of a keyframe. If the list is still too large, |
| 267 | // clear it and request a keyframe. |
| 268 | uint16_t num_new_nacks = ForwardDiff(seq_num_start, seq_num_end); |
| 269 | if (nack_list_.size() + num_new_nacks > kMaxNackPackets) { |
| 270 | while (RemovePacketsUntilKeyFrame() && |
| 271 | nack_list_.size() + num_new_nacks > kMaxNackPackets) { |
| 272 | } |
| 273 | |
| 274 | if (nack_list_.size() + num_new_nacks > kMaxNackPackets) { |
| 275 | nack_list_.clear(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 276 | RTC_LOG(LS_WARNING) << "NACK list full, clearing NACK" |
| 277 | " list and requesting keyframe."; |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 278 | keyframe_request_sender_->RequestKeyFrame(); |
| 279 | return; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | for (uint16_t seq_num = seq_num_start; seq_num != seq_num_end; ++seq_num) { |
Ying Wang | b32bb95 | 2018-10-31 10:12:27 +0100 | [diff] [blame] | 284 | // Do not send nack for packets that are already recovered by FEC or RTX |
| 285 | if (recovered_list_.find(seq_num) != recovered_list_.end()) |
| 286 | continue; |
Ying Wang | 0367d1a | 2018-11-02 14:51:15 +0100 | [diff] [blame] | 287 | NackInfo nack_info(seq_num, seq_num + WaitNumberOfPackets(0.5), |
| 288 | clock_->TimeInMilliseconds()); |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 289 | RTC_DCHECK(nack_list_.find(seq_num) == nack_list_.end()); |
| 290 | nack_list_[seq_num] = nack_info; |
| 291 | } |
| 292 | } |
| 293 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 294 | std::vector<uint16_t> DEPRECATED_NackModule::GetNackBatch( |
| 295 | NackFilterOptions options) { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 296 | bool consider_seq_num = options != kTimeOnly; |
| 297 | bool consider_timestamp = options != kSeqNumOnly; |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 298 | Timestamp now = clock_->CurrentTime(); |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 299 | std::vector<uint16_t> nack_batch; |
| 300 | auto it = nack_list_.begin(); |
| 301 | while (it != nack_list_.end()) { |
Danil Chapovalov | 5528402 | 2020-02-07 14:53:52 +0100 | [diff] [blame] | 302 | TimeDelta resend_delay = TimeDelta::Millis(rtt_ms_); |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 303 | if (backoff_settings_) { |
| 304 | resend_delay = |
| 305 | std::max(resend_delay, backoff_settings_->min_retry_interval); |
| 306 | if (it->second.retries > 1) { |
| 307 | TimeDelta exponential_backoff = |
Danil Chapovalov | 5528402 | 2020-02-07 14:53:52 +0100 | [diff] [blame] | 308 | std::min(TimeDelta::Millis(rtt_ms_), backoff_settings_->max_rtt) * |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 309 | std::pow(backoff_settings_->base, it->second.retries - 1); |
| 310 | resend_delay = std::max(resend_delay, exponential_backoff); |
| 311 | } |
| 312 | } |
| 313 | |
Ying Wang | 0367d1a | 2018-11-02 14:51:15 +0100 | [diff] [blame] | 314 | bool delay_timed_out = |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 315 | now.ms() - it->second.created_at_time >= send_nack_delay_ms_; |
| 316 | bool nack_on_rtt_passed = |
| 317 | now.ms() - it->second.sent_at_time >= resend_delay.ms(); |
Ying Wang | 0367d1a | 2018-11-02 14:51:15 +0100 | [diff] [blame] | 318 | bool nack_on_seq_num_passed = |
| 319 | it->second.sent_at_time == -1 && |
| 320 | AheadOrAt(newest_seq_num_, it->second.send_at_seq_num); |
| 321 | if (delay_timed_out && ((consider_seq_num && nack_on_seq_num_passed) || |
| 322 | (consider_timestamp && nack_on_rtt_passed))) { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 323 | nack_batch.emplace_back(it->second.seq_num); |
| 324 | ++it->second.retries; |
Erik Språng | 3eae7e4 | 2019-10-25 09:24:45 +0200 | [diff] [blame] | 325 | it->second.sent_at_time = now.ms(); |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 326 | if (it->second.retries >= kMaxNackRetries) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 327 | RTC_LOG(LS_WARNING) << "Sequence number " << it->second.seq_num |
| 328 | << " removed from NACK list due to max retries."; |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 329 | it = nack_list_.erase(it); |
| 330 | } else { |
| 331 | ++it; |
| 332 | } |
| 333 | continue; |
| 334 | } |
| 335 | ++it; |
| 336 | } |
| 337 | return nack_batch; |
| 338 | } |
| 339 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 340 | void DEPRECATED_NackModule::UpdateReorderingStatistics(uint16_t seq_num) { |
philipel | 1a830c2 | 2016-05-13 11:12:00 +0200 | [diff] [blame] | 341 | RTC_DCHECK(AheadOf(newest_seq_num_, seq_num)); |
| 342 | uint16_t diff = ReverseDiff(newest_seq_num_, seq_num); |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 343 | reordering_histogram_.Add(diff); |
| 344 | } |
| 345 | |
Mirko Bonadei | 9ca7365 | 2020-05-30 17:31:46 +0200 | [diff] [blame^] | 346 | int DEPRECATED_NackModule::WaitNumberOfPackets(float probability) const { |
philipel | 5ab4c6d | 2016-03-08 03:36:15 -0800 | [diff] [blame] | 347 | if (reordering_histogram_.NumValues() == 0) |
| 348 | return 0; |
| 349 | return reordering_histogram_.InverseCdf(probability); |
| 350 | } |
| 351 | |
| 352 | } // namespace webrtc |