| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" | 11 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" |
| 12 | 12 |
| 13 #include <limits> | 13 #include <limits> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/mod_ops.h" | 17 #include "webrtc/base/mod_ops.h" |
| 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 constexpr uint16_t kSeqNumHalf = 0x8000u; | 21 constexpr uint16_t kSeqNumHalf = 0x8000u; |
| 22 constexpr uint16_t kSeqNumQuarter = kSeqNumHalf / 2; | |
| 23 constexpr size_t kMaxConsecutiveOldReports = 4; | |
| 24 | |
| 25 void UpdateCounter(size_t* counter, bool increment) { | 22 void UpdateCounter(size_t* counter, bool increment) { |
| 26 if (increment) { | 23 if (increment) { |
| 27 RTC_DCHECK_LT(*counter, std::numeric_limits<std::size_t>::max()); | 24 RTC_DCHECK_LT(*counter, std::numeric_limits<std::size_t>::max()); |
| 28 ++(*counter); | 25 ++(*counter); |
| 29 } else { | 26 } else { |
| 30 RTC_DCHECK_GT(*counter, 0); | 27 RTC_DCHECK_GT(*counter, 0); |
| 31 --(*counter); | 28 --(*counter); |
| 32 } | 29 } |
| 33 } | 30 } |
| 34 | 31 |
| 35 } // namespace | 32 } // namespace |
| 36 | 33 |
| 37 namespace webrtc { | 34 namespace webrtc { |
| 38 | 35 |
| 39 TransportFeedbackPacketLossTracker::TransportFeedbackPacketLossTracker( | 36 TransportFeedbackPacketLossTracker::TransportFeedbackPacketLossTracker( |
| 40 size_t max_window_size, | 37 size_t max_acked_packets, |
| 41 size_t plr_min_num_packets, | 38 size_t plr_min_num_acked_packets, |
| 42 size_t rplr_min_num_pairs) | 39 size_t rplr_min_num_acked_pairs) |
| 43 : max_window_size_(max_window_size), | 40 : max_acked_packets_(max_acked_packets), |
| 44 ref_packet_status_(packet_status_window_.begin()), | 41 ref_packet_status_(packet_status_window_.begin()), |
| 45 plr_state_(plr_min_num_packets), | 42 plr_state_(plr_min_num_acked_packets), |
| 46 rplr_state_(rplr_min_num_pairs) { | 43 rplr_state_(rplr_min_num_acked_pairs) { |
| 47 RTC_DCHECK_GT(plr_min_num_packets, 0); | 44 RTC_DCHECK_GT(plr_min_num_acked_packets, 0); |
| 48 RTC_DCHECK_GE(max_window_size, plr_min_num_packets); | 45 RTC_DCHECK_GE(max_acked_packets, plr_min_num_acked_packets); |
| 49 RTC_DCHECK_LE(max_window_size, kSeqNumHalf); | 46 RTC_DCHECK_LE(max_acked_packets, kSeqNumHalf); |
| 50 RTC_DCHECK_GT(rplr_min_num_pairs, 0); | 47 RTC_DCHECK_GT(rplr_min_num_acked_pairs, 0); |
| 51 RTC_DCHECK_GT(max_window_size, rplr_min_num_pairs); | 48 RTC_DCHECK_GT(max_acked_packets, rplr_min_num_acked_pairs); |
| 52 Reset(); | 49 Reset(); |
| 53 } | 50 } |
| 54 | 51 |
| 55 void TransportFeedbackPacketLossTracker::Reset() { | 52 void TransportFeedbackPacketLossTracker::Reset() { |
| 53 acked_packets_ = 0; |
| 56 plr_state_.Reset(); | 54 plr_state_.Reset(); |
| 57 rplr_state_.Reset(); | 55 rplr_state_.Reset(); |
| 58 num_consecutive_old_reports_ = 0; | |
| 59 packet_status_window_.clear(); | 56 packet_status_window_.clear(); |
| 60 ref_packet_status_ = packet_status_window_.begin(); | 57 ref_packet_status_ = packet_status_window_.begin(); |
| 61 } | 58 } |
| 62 | 59 |
| 63 uint16_t TransportFeedbackPacketLossTracker::ReferenceSequenceNumber() const { | 60 uint16_t TransportFeedbackPacketLossTracker::ReferenceSequenceNumber() const { |
| 64 RTC_DCHECK(!packet_status_window_.empty()); | 61 RTC_DCHECK(!packet_status_window_.empty()); |
| 65 return ref_packet_status_->first; | 62 return ref_packet_status_->first; |
| 66 } | 63 } |
| 67 | 64 |
| 68 bool TransportFeedbackPacketLossTracker::IsOldSequenceNumber( | 65 uint16_t TransportFeedbackPacketLossTracker::NewestSequenceNumber() const { |
| 69 uint16_t seq_num) const { | 66 RTC_DCHECK(!packet_status_window_.empty()); |
| 70 if (packet_status_window_.empty()) { | 67 return PreviousPacketStatus(packet_status_window_.end())->first; |
| 71 return false; | 68 } |
| 69 |
| 70 void TransportFeedbackPacketLossTracker::OnPacketAdded(uint16_t seq_num) { |
| 71 if (packet_status_window_.find(seq_num) != packet_status_window_.end() || |
| 72 (!packet_status_window_.empty() && |
| 73 ForwardDiff(seq_num, NewestSequenceNumber()) <= kSeqNumHalf)) { |
| 74 // The only way for these two to happen is when the stream lies dormant for |
| 75 // long enough for the sequence numbers to wrap. Everything in the window in |
| 76 // such a case would be too old to use. |
| 77 Reset(); |
| 72 } | 78 } |
| 73 const uint16_t diff = ForwardDiff(ReferenceSequenceNumber(), seq_num); | 79 |
| 74 return diff >= 3 * kSeqNumQuarter; | 80 // Shift older packets out of window. |
| 81 while (!packet_status_window_.empty() && |
| 82 ForwardDiff(ref_packet_status_->first, seq_num) >= kSeqNumHalf) { |
| 83 RemoveOldestPacketStatus(); |
| 84 } |
| 85 |
| 86 packet_status_window_.insert(packet_status_window_.end(), |
| 87 std::make_pair(seq_num, PacketStatus::Unacked)); |
| 88 |
| 89 if (packet_status_window_.size() == 1) { |
| 90 ref_packet_status_ = packet_status_window_.cbegin(); |
| 91 } |
| 75 } | 92 } |
| 76 | 93 |
| 77 void TransportFeedbackPacketLossTracker::OnReceivedTransportFeedback( | 94 void TransportFeedbackPacketLossTracker::OnReceivedTransportFeedback( |
| 78 const rtcp::TransportFeedback& feedback) { | 95 const rtcp::TransportFeedback& feedback) { |
| 79 const auto& fb_vector = feedback.GetStatusVector(); | 96 const auto& fb_vector = feedback.GetStatusVector(); |
| 80 const uint16_t base_seq_num = feedback.GetBaseSequence(); | 97 const uint16_t base_seq_num = feedback.GetBaseSequence(); |
| 81 | 98 |
| 82 if (IsOldSequenceNumber(base_seq_num)) { | |
| 83 ++num_consecutive_old_reports_; | |
| 84 if (num_consecutive_old_reports_ <= kMaxConsecutiveOldReports) { | |
| 85 // If the number consecutive old reports have not exceed a threshold, we | |
| 86 // consider this packet as a late arrival. We could consider adding it to | |
| 87 // |packet_status_window_|, but in current implementation, we simply | |
| 88 // ignore it. | |
| 89 return; | |
| 90 } | |
| 91 // If we see several consecutive older reports, we assume that we've not | |
| 92 // received reports for an exceedingly long time, and do a reset. | |
| 93 Reset(); | |
| 94 RTC_DCHECK(!IsOldSequenceNumber(base_seq_num)); | |
| 95 } else { | |
| 96 num_consecutive_old_reports_ = 0; | |
| 97 } | |
| 98 | |
| 99 uint16_t seq_num = base_seq_num; | 99 uint16_t seq_num = base_seq_num; |
| 100 for (size_t i = 0; i < fb_vector.size(); ++i, ++seq_num) { | 100 for (size_t i = 0; i < fb_vector.size(); ++i, ++seq_num) { |
| 101 // Remove the oldest feedbacks so that the distance between the oldest and | 101 const auto& it = packet_status_window_.find(seq_num); |
| 102 // the packet to be added does not exceed or equal to half of total sequence | |
| 103 // numbers. | |
| 104 while (!packet_status_window_.empty() && | |
| 105 ForwardDiff(ReferenceSequenceNumber(), seq_num) >= kSeqNumHalf) { | |
| 106 RemoveOldestPacketStatus(); | |
| 107 } | |
| 108 | 102 |
| 109 const bool received = | 103 // Packets which aren't at least marked as unacked either do not belong to |
| 110 fb_vector[i] != | 104 // this media stream, or have been shifted out of window. |
| 105 if (it == packet_status_window_.end()) |
| 106 continue; |
| 107 |
| 108 const bool lost = fb_vector[i] == |
| 111 webrtc::rtcp::TransportFeedback::StatusSymbol::kNotReceived; | 109 webrtc::rtcp::TransportFeedback::StatusSymbol::kNotReceived; |
| 112 InsertPacketStatus(seq_num, received); | 110 const PacketStatus new_packet_status = |
| 111 lost ? PacketStatus::Lost : PacketStatus::Received; |
| 113 | 112 |
| 114 while (packet_status_window_.size() > max_window_size_) { | 113 RecordPacketStatus(it, new_packet_status); |
| 115 // Make sure that the window holds at most |max_window_size_| items. | |
| 116 RemoveOldestPacketStatus(); | |
| 117 } | |
| 118 } | 114 } |
| 119 } | 115 } |
| 120 | 116 |
| 121 rtc::Optional<float> | 117 rtc::Optional<float> |
| 122 TransportFeedbackPacketLossTracker::GetPacketLossRate() const { | 118 TransportFeedbackPacketLossTracker::GetPacketLossRate() const { |
| 123 return plr_state_.GetMetric(); | 119 return plr_state_.GetMetric(); |
| 124 } | 120 } |
| 125 | 121 |
| 126 rtc::Optional<float> | 122 rtc::Optional<float> |
| 127 TransportFeedbackPacketLossTracker::GetRecoverablePacketLossRate() const { | 123 TransportFeedbackPacketLossTracker::GetRecoverablePacketLossRate() const { |
| 128 return rplr_state_.GetMetric(); | 124 return rplr_state_.GetMetric(); |
| 129 } | 125 } |
| 130 | 126 |
| 131 void TransportFeedbackPacketLossTracker::InsertPacketStatus(uint16_t seq_num, | 127 void TransportFeedbackPacketLossTracker::RecordPacketStatus( |
| 132 bool received) { | 128 PacketStatusMap::iterator it, |
| 133 const auto& ret = | 129 PacketStatus new_packet_status) { |
| 134 packet_status_window_.insert(std::make_pair(seq_num, received)); | 130 if (it->second != PacketStatus::Unacked) { |
| 135 if (!ret.second) { | 131 // Normally, packets are sent (inserted into window as "unacked"), then we |
| 136 if (!ret.first->second && received) { | 132 // receive one feedback for them. |
| 133 // But it is possible that a packet would receive two feedbacks. Then: |
| 134 if (it->second == PacketStatus::Lost && |
| 135 new_packet_status == PacketStatus::Received) { |
| 137 // If older status said that the packet was lost but newer one says it | 136 // If older status said that the packet was lost but newer one says it |
| 138 // is received, we take the newer one. | 137 // is received, we take the newer one. |
| 139 UpdateMetrics(ret.first, false); | 138 UpdateMetrics(it, false); |
| 140 ret.first->second = received; | 139 it->second = PacketStatus::Unacked; // For clarity; overwritten shortly. |
| 141 } else { | 140 } else { |
| 142 // If the value is unchanged or if older status said that the packet was | 141 // If the value is unchanged or if older status said that the packet was |
| 143 // received but the newer one says it is lost, we ignore it. | 142 // received but the newer one says it is lost, we ignore it. |
| 143 // The standard allows for previously-reported packets to carry |
| 144 // no report when the reports overlap, which also looks like the |
| 145 // packet is being reported as lost. |
| 144 return; | 146 return; |
| 145 } | 147 } |
| 146 } | 148 } |
| 147 UpdateMetrics(ret.first, true); | 149 |
| 148 if (packet_status_window_.size() == 1) | 150 // Change from UNACKED to RECEIVED/LOST. |
| 149 ref_packet_status_ = ret.first; | 151 it->second = new_packet_status; |
| 152 UpdateMetrics(it, true); |
| 153 |
| 154 // Remove packets from the beginning of the window until maximum-acked |
| 155 // is observed again. Note that multiple sent-but-unacked packets might |
| 156 // be removed before we reach the first acked (whether as received or as |
| 157 // lost) packet. |
| 158 while (acked_packets_ > max_acked_packets_) |
| 159 RemoveOldestPacketStatus(); |
| 150 } | 160 } |
| 151 | 161 |
| 152 void TransportFeedbackPacketLossTracker::RemoveOldestPacketStatus() { | 162 void TransportFeedbackPacketLossTracker::RemoveOldestPacketStatus() { |
| 153 UpdateMetrics(ref_packet_status_, false); | 163 UpdateMetrics(ref_packet_status_, false); |
| 154 const auto it = ref_packet_status_; | 164 const auto it = ref_packet_status_; |
| 155 ref_packet_status_ = NextPacketStatus(it); | 165 ref_packet_status_ = NextPacketStatus(it); |
| 156 packet_status_window_.erase(it); | 166 packet_status_window_.erase(it); |
| 157 } | 167 } |
| 158 | 168 |
| 159 void TransportFeedbackPacketLossTracker::UpdateMetrics( | 169 void TransportFeedbackPacketLossTracker::UpdateMetrics( |
| 160 PacketStatusIterator it, | 170 ConstPacketStatusIterator it, |
| 161 bool apply /* false = undo */) { | 171 bool apply /* false = undo */) { |
| 162 RTC_DCHECK(it != packet_status_window_.end()); | 172 RTC_DCHECK(it != packet_status_window_.end()); |
| 173 // Metrics are dependent on feedbacks from the other side. We don't want |
| 174 // to update the metrics each time a packet is sent, except for the case |
| 175 // when it shifts old sent-but-unacked-packets out of window. |
| 176 RTC_DCHECK(!apply || it->second != PacketStatus::Unacked); |
| 177 |
| 178 if (it->second != PacketStatus::Unacked) { |
| 179 UpdateCounter(&acked_packets_, apply); |
| 180 } |
| 181 |
| 163 UpdatePlr(it, apply); | 182 UpdatePlr(it, apply); |
| 164 UpdateRplr(it, apply); | 183 UpdateRplr(it, apply); |
| 165 } | 184 } |
| 166 | 185 |
| 167 void TransportFeedbackPacketLossTracker::UpdatePlr( | 186 void TransportFeedbackPacketLossTracker::UpdatePlr( |
| 168 PacketStatusIterator it, | 187 ConstPacketStatusIterator it, |
| 169 bool apply /* false = undo */) { | 188 bool apply /* false = undo */) { |
| 170 // Record or undo reception status of currently handled packet. | 189 switch (it->second) { |
| 171 if (it->second) { | 190 case PacketStatus::Unacked: |
| 172 UpdateCounter(&plr_state_.num_received_packets_, apply); | 191 return; |
| 173 } else { | 192 case PacketStatus::Received: |
| 174 UpdateCounter(&plr_state_.num_lost_packets_, apply); | 193 UpdateCounter(&plr_state_.num_received_packets_, apply); |
| 194 break; |
| 195 case PacketStatus::Lost: |
| 196 UpdateCounter(&plr_state_.num_lost_packets_, apply); |
| 197 break; |
| 198 default: |
| 199 RTC_NOTREACHED(); |
| 175 } | 200 } |
| 176 } | 201 } |
| 177 | 202 |
| 178 void TransportFeedbackPacketLossTracker::UpdateRplr( | 203 void TransportFeedbackPacketLossTracker::UpdateRplr( |
| 179 PacketStatusIterator it, | 204 ConstPacketStatusIterator it, |
| 180 bool apply /* false = undo */) { | 205 bool apply /* false = undo */) { |
| 181 // Previous packet and current packet might compose a known pair. | 206 if (it->second == PacketStatus::Unacked) { |
| 182 // If so, the RPLR state needs to be updated accordingly. | 207 // Unacked packets cannot compose a pair. |
| 208 return; |
| 209 } |
| 210 |
| 211 // Previous packet and current packet might compose a pair. |
| 183 if (it != ref_packet_status_) { | 212 if (it != ref_packet_status_) { |
| 184 const auto& prev = PreviousPacketStatus(it); | 213 const auto& prev = PreviousPacketStatus(it); |
| 185 if (prev->first == static_cast<uint16_t>(it->first - 1)) { | 214 if (prev->second != PacketStatus::Unacked) { |
| 186 UpdateCounter(&rplr_state_.num_known_pairs_, apply); | 215 UpdateCounter(&rplr_state_.num_acked_pairs_, apply); |
| 187 if (!prev->second && it->second) { | 216 if (prev->second == PacketStatus::Lost && |
| 217 it->second == PacketStatus::Received) { |
| 188 UpdateCounter( | 218 UpdateCounter( |
| 189 &rplr_state_.num_recoverable_losses_, apply); | 219 &rplr_state_.num_recoverable_losses_, apply); |
| 190 } | 220 } |
| 191 } | 221 } |
| 192 } | 222 } |
| 193 | 223 |
| 194 // Current packet and next packet might compose a pair. | 224 // Current packet and next packet might compose a pair. |
| 195 // If so, the RPLR state needs to be updated accordingly. | |
| 196 const auto& next = NextPacketStatus(it); | 225 const auto& next = NextPacketStatus(it); |
| 197 if (next != packet_status_window_.end() && | 226 if (next != packet_status_window_.end() && |
| 198 next->first == static_cast<uint16_t>(it->first + 1)) { | 227 next->second != PacketStatus::Unacked) { |
| 199 UpdateCounter(&rplr_state_.num_known_pairs_, apply); | 228 UpdateCounter(&rplr_state_.num_acked_pairs_, apply); |
| 200 if (!it->second && next->second) { | 229 if (it->second == PacketStatus::Lost && |
| 230 next->second == PacketStatus::Received) { |
| 201 UpdateCounter(&rplr_state_.num_recoverable_losses_, apply); | 231 UpdateCounter(&rplr_state_.num_recoverable_losses_, apply); |
| 202 } | 232 } |
| 203 } | 233 } |
| 204 } | 234 } |
| 205 | 235 |
| 206 TransportFeedbackPacketLossTracker::PacketStatusIterator | 236 TransportFeedbackPacketLossTracker::ConstPacketStatusIterator |
| 207 TransportFeedbackPacketLossTracker::PreviousPacketStatus( | 237 TransportFeedbackPacketLossTracker::PreviousPacketStatus( |
| 208 PacketStatusIterator it) { | 238 ConstPacketStatusIterator it) const { |
| 209 RTC_DCHECK(it != ref_packet_status_); | 239 RTC_DCHECK(it != ref_packet_status_); |
| 210 if (it == packet_status_window_.end()) { | 240 if (it == packet_status_window_.end()) { |
| 211 // This is to make PreviousPacketStatus(packet_status_window_.end()) point | 241 // This is to make PreviousPacketStatus(packet_status_window_.end()) point |
| 212 // to the last element. | 242 // to the last element. |
| 213 it = ref_packet_status_; | 243 it = ref_packet_status_; |
| 214 } | 244 } |
| 215 | 245 |
| 216 if (it == packet_status_window_.begin()) { | 246 if (it == packet_status_window_.begin()) { |
| 217 // Due to the circular nature of sequence numbers, we let the iterator | 247 // Due to the circular nature of sequence numbers, we let the iterator |
| 218 // go to the end. | 248 // go to the end. |
| 219 it = packet_status_window_.end(); | 249 it = packet_status_window_.end(); |
| 220 } | 250 } |
| 221 return --it; | 251 return --it; |
| 222 } | 252 } |
| 223 | 253 |
| 224 TransportFeedbackPacketLossTracker::PacketStatusIterator | 254 TransportFeedbackPacketLossTracker::ConstPacketStatusIterator |
| 225 TransportFeedbackPacketLossTracker::NextPacketStatus(PacketStatusIterator it) { | 255 TransportFeedbackPacketLossTracker::NextPacketStatus( |
| 256 ConstPacketStatusIterator it) const { |
| 226 RTC_DCHECK(it != packet_status_window_.end()); | 257 RTC_DCHECK(it != packet_status_window_.end()); |
| 227 ++it; | 258 ++it; |
| 228 if (it == packet_status_window_.end()) { | 259 if (it == packet_status_window_.end()) { |
| 229 // Due to the circular nature of sequence numbers, we let the iterator | 260 // Due to the circular nature of sequence numbers, we let the iterator |
| 230 // goes back to the beginning. | 261 // goes back to the beginning. |
| 231 it = packet_status_window_.begin(); | 262 it = packet_status_window_.begin(); |
| 232 } | 263 } |
| 233 if (it == ref_packet_status_) { | 264 if (it == ref_packet_status_) { |
| 234 // This is to make the NextPacketStatus of the last element to return the | 265 // This is to make the NextPacketStatus of the last element to return the |
| 235 // beyond-the-end iterator. | 266 // beyond-the-end iterator. |
| 236 it = packet_status_window_.end(); | 267 it = packet_status_window_.end(); |
| 237 } | 268 } |
| 238 return it; | 269 return it; |
| 239 } | 270 } |
| 240 | 271 |
| 241 // TODO(minyue): This method checks the states of this class do not misbehave. | 272 // TODO(minyue): This method checks the states of this class do not misbehave. |
| 242 // The method is used both in unit tests and a fuzzer test. The fuzzer test | 273 // The method is used both in unit tests and a fuzzer test. The fuzzer test |
| 243 // is present to help finding potential errors. Once the fuzzer test shows no | 274 // is present to help finding potential errors. Once the fuzzer test shows no |
| 244 // error after long period, we can remove the fuzzer test, and move this method | 275 // error after long period, we can remove the fuzzer test, and move this method |
| 245 // to unit test. | 276 // to unit test. |
| 246 void TransportFeedbackPacketLossTracker::Validate() const { // Testing only! | 277 void TransportFeedbackPacketLossTracker::Validate() const { // Testing only! |
| 247 RTC_CHECK_LE(packet_status_window_.size(), max_window_size_); | 278 RTC_CHECK_EQ(plr_state_.num_received_packets_ + plr_state_.num_lost_packets_, |
| 248 RTC_CHECK_EQ(packet_status_window_.size(), | 279 acked_packets_); |
| 249 plr_state_.num_lost_packets_ + plr_state_.num_received_packets_); | 280 RTC_CHECK_LE(acked_packets_, packet_status_window_.size()); |
| 281 RTC_CHECK_LE(acked_packets_, max_acked_packets_); |
| 250 RTC_CHECK_LE(rplr_state_.num_recoverable_losses_, | 282 RTC_CHECK_LE(rplr_state_.num_recoverable_losses_, |
| 251 rplr_state_.num_known_pairs_); | 283 rplr_state_.num_acked_pairs_); |
| 252 RTC_CHECK_LE(rplr_state_.num_known_pairs_, | 284 RTC_CHECK_LE(rplr_state_.num_acked_pairs_, acked_packets_ - 1); |
| 253 packet_status_window_.size() - 1); | |
| 254 | 285 |
| 286 size_t unacked_packets = 0; |
| 255 size_t received_packets = 0; | 287 size_t received_packets = 0; |
| 256 size_t lost_packets = 0; | 288 size_t lost_packets = 0; |
| 257 size_t known_status_pairs = 0; | 289 size_t acked_pairs = 0; |
| 258 size_t recoverable_losses = 0; | 290 size_t recoverable_losses = 0; |
| 259 | 291 |
| 260 if (!packet_status_window_.empty()) { | 292 if (!packet_status_window_.empty()) { |
| 261 PacketStatusIterator it = ref_packet_status_; | 293 ConstPacketStatusIterator it = ref_packet_status_; |
| 262 do { | 294 do { |
| 263 if (it->second) { | 295 switch (it->second) { |
| 264 ++received_packets; | 296 case PacketStatus::Unacked: |
| 265 } else { | 297 ++unacked_packets; |
| 266 ++lost_packets; | 298 break; |
| 299 case PacketStatus::Received: |
| 300 ++received_packets; |
| 301 break; |
| 302 case PacketStatus::Lost: |
| 303 ++lost_packets; |
| 304 break; |
| 305 default: |
| 306 RTC_NOTREACHED(); |
| 267 } | 307 } |
| 268 | 308 |
| 269 auto next = std::next(it); | 309 auto next = std::next(it); |
| 270 if (next == packet_status_window_.end()) | 310 if (next == packet_status_window_.end()) |
| 271 next = packet_status_window_.begin(); | 311 next = packet_status_window_.begin(); |
| 272 | 312 |
| 273 if (next != ref_packet_status_ && | 313 if (next != ref_packet_status_ && |
| 274 next->first == static_cast<uint16_t>(it->first + 1)) { | 314 it->second != PacketStatus::Unacked && |
| 275 ++known_status_pairs; | 315 next->second != PacketStatus::Unacked) { |
| 276 if (!it->second && next->second) | 316 ++acked_pairs; |
| 317 if (it->second == PacketStatus::Lost && |
| 318 next->second == PacketStatus::Received) |
| 277 ++recoverable_losses; | 319 ++recoverable_losses; |
| 278 } | 320 } |
| 279 | 321 |
| 280 RTC_CHECK_LT(ForwardDiff(ReferenceSequenceNumber(), it->first), | 322 RTC_CHECK_LT(ForwardDiff(ReferenceSequenceNumber(), it->first), |
| 281 kSeqNumHalf); | 323 kSeqNumHalf); |
| 282 | 324 |
| 283 it = next; | 325 it = next; |
| 284 } while (it != ref_packet_status_); | 326 } while (it != ref_packet_status_); |
| 285 } | 327 } |
| 286 | 328 |
| 287 RTC_CHECK_EQ(plr_state_.num_received_packets_, received_packets); | 329 RTC_CHECK_EQ(plr_state_.num_received_packets_, received_packets); |
| 288 RTC_CHECK_EQ(plr_state_.num_lost_packets_, lost_packets); | 330 RTC_CHECK_EQ(plr_state_.num_lost_packets_, lost_packets); |
| 289 RTC_CHECK_EQ(rplr_state_.num_known_pairs_, known_status_pairs); | 331 RTC_CHECK_EQ(packet_status_window_.size(), |
| 332 unacked_packets + received_packets + lost_packets); |
| 333 RTC_CHECK_EQ(rplr_state_.num_acked_pairs_, acked_pairs); |
| 290 RTC_CHECK_EQ(rplr_state_.num_recoverable_losses_, recoverable_losses); | 334 RTC_CHECK_EQ(rplr_state_.num_recoverable_losses_, recoverable_losses); |
| 291 } | 335 } |
| 292 | 336 |
| 293 rtc::Optional<float> | 337 rtc::Optional<float> |
| 294 TransportFeedbackPacketLossTracker::PlrState::GetMetric() const { | 338 TransportFeedbackPacketLossTracker::PlrState::GetMetric() const { |
| 295 const size_t total = num_lost_packets_ + num_received_packets_; | 339 const size_t total = num_lost_packets_ + num_received_packets_; |
| 296 if (total < min_num_packets_) { | 340 if (total < min_num_acked_packets_) { |
| 297 return rtc::Optional<float>(); | 341 return rtc::Optional<float>(); |
| 298 } else { | 342 } else { |
| 299 return rtc::Optional<float>( | 343 return rtc::Optional<float>( |
| 300 static_cast<float>(num_lost_packets_) / total); | 344 static_cast<float>(num_lost_packets_) / total); |
| 301 } | 345 } |
| 302 } | 346 } |
| 303 | 347 |
| 304 rtc::Optional<float> | 348 rtc::Optional<float> |
| 305 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const { | 349 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const { |
| 306 if (num_known_pairs_ < min_num_pairs_) { | 350 if (num_acked_pairs_ < min_num_acked_pairs_) { |
| 307 return rtc::Optional<float>(); | 351 return rtc::Optional<float>(); |
| 308 } else { | 352 } else { |
| 309 return rtc::Optional<float>( | 353 return rtc::Optional<float>( |
| 310 static_cast<float>(num_recoverable_losses_) / num_known_pairs_); | 354 static_cast<float>(num_recoverable_losses_) / num_acked_pairs_); |
| 311 } | 355 } |
| 312 } | 356 } |
| 313 | 357 |
| 314 } // namespace webrtc | 358 } // namespace webrtc |
| OLD | NEW |