Chromium Code Reviews| 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(); |
|
michaelt
2017/02/27 12:44:21
Calling a function called "Reset" in the ctor soun
elad.alon_webrtc.org
2017/02/27 13:18:05
You voice legitimate concerns which were discussed
michaelt
2017/02/27 15:46:18
Hmm I think i would go for the std::unique_ptr sol
elad.alon_webrtc.org
2017/02/27 15:53:32
That would require the tracker informing its owner
michaelt
2017/02/27 16:04:31
:) no not for the tracker :)
For plr and rplr sta
elad.alon_webrtc.org
2017/02/27 16:29:19
It's possible for the plr_state_ and rplr_state_,
minyue-webrtc
2017/03/03 14:14:31
Hi, I hoped to get rid of Reset() everywhere, but
| |
| 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. |
| 111 webrtc::rtcp::TransportFeedback::StatusSymbol::kNotReceived; | 105 if (it != packet_status_window_.end()) { |
| 112 InsertPacketStatus(seq_num, received); | 106 const bool received = fb_vector[i] != |
| 113 | 107 webrtc::rtcp::TransportFeedback::StatusSymbol::kNotReceived; |
| 114 while (packet_status_window_.size() > max_window_size_) { | 108 RecordFeedback(it, received); |
| 115 // Make sure that the window holds at most |max_window_size_| items. | |
| 116 RemoveOldestPacketStatus(); | |
| 117 } | 109 } |
| 118 } | 110 } |
| 119 } | 111 } |
| 120 | 112 |
| 121 rtc::Optional<float> | 113 rtc::Optional<float> |
| 122 TransportFeedbackPacketLossTracker::GetPacketLossRate() const { | 114 TransportFeedbackPacketLossTracker::GetPacketLossRate() const { |
| 123 return plr_state_.GetMetric(); | 115 return plr_state_.GetMetric(); |
| 124 } | 116 } |
| 125 | 117 |
| 126 rtc::Optional<float> | 118 rtc::Optional<float> |
| 127 TransportFeedbackPacketLossTracker::GetRecoverablePacketLossRate() const { | 119 TransportFeedbackPacketLossTracker::GetRecoverablePacketLossRate() const { |
| 128 return rplr_state_.GetMetric(); | 120 return rplr_state_.GetMetric(); |
| 129 } | 121 } |
| 130 | 122 |
| 131 void TransportFeedbackPacketLossTracker::InsertPacketStatus(uint16_t seq_num, | 123 void TransportFeedbackPacketLossTracker::RecordFeedback( |
| 132 bool received) { | 124 PacketStatusMap::iterator it, |
| 133 const auto& ret = | 125 bool received) { |
| 134 packet_status_window_.insert(std::make_pair(seq_num, received)); | 126 if (it->second != PacketStatus::Unacked) { |
| 135 if (!ret.second) { | 127 // Normally, packets are sent (inserted into window as "unacked"), then we |
| 136 if (!ret.first->second && received) { | 128 // receive one feedback for them. |
| 129 // But it is possible that a packet would receive two feedbacks. Then: | |
| 130 if (it->second == PacketStatus::Lost && received) { | |
| 137 // If older status said that the packet was lost but newer one says it | 131 // If older status said that the packet was lost but newer one says it |
| 138 // is received, we take the newer one. | 132 // is received, we take the newer one. |
| 139 UpdateMetrics(ret.first, false); | 133 UpdateMetrics(it, false); |
| 140 ret.first->second = received; | 134 it->second = PacketStatus::Unacked; // For clarity; overwritten shortly. |
| 141 } else { | 135 } else { |
| 142 // If the value is unchanged or if older status said that the packet was | 136 // 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. | 137 // received but the newer one says it is lost, we ignore it. |
| 138 // The standard allows for previously-reported packets to carry | |
| 139 // no report when the reports overlap, which also looks like the | |
| 140 // packet is being reported as lost. | |
| 144 return; | 141 return; |
| 145 } | 142 } |
| 146 } | 143 } |
| 147 UpdateMetrics(ret.first, true); | 144 |
| 148 if (packet_status_window_.size() == 1) | 145 // Change from UNACKED to RECEIVED/LOST. |
| 149 ref_packet_status_ = ret.first; | 146 it->second = received ? PacketStatus::Received : PacketStatus::Lost; |
| 147 UpdateMetrics(it, true); | |
| 148 | |
| 149 // Remove packets from the beginning of the window until maximum-acked | |
| 150 // is observed again. Note that multiple sent-but-unacked packets might | |
| 151 // be removed before we reach the first acked (whether as received or as | |
| 152 // lost) packet. | |
| 153 while (acked_packets_ > max_acked_packets_) | |
| 154 RemoveOldestPacketStatus(); | |
| 150 } | 155 } |
| 151 | 156 |
| 152 void TransportFeedbackPacketLossTracker::RemoveOldestPacketStatus() { | 157 void TransportFeedbackPacketLossTracker::RemoveOldestPacketStatus() { |
| 153 UpdateMetrics(ref_packet_status_, false); | 158 UpdateMetrics(ref_packet_status_, false); |
| 154 const auto it = ref_packet_status_; | 159 const auto it = ref_packet_status_; |
| 155 ref_packet_status_ = NextPacketStatus(it); | 160 ref_packet_status_ = NextPacketStatus(it); |
| 156 packet_status_window_.erase(it); | 161 packet_status_window_.erase(it); |
| 157 } | 162 } |
| 158 | 163 |
| 159 void TransportFeedbackPacketLossTracker::UpdateMetrics( | 164 void TransportFeedbackPacketLossTracker::UpdateMetrics( |
| 160 PacketStatusIterator it, | 165 ConstPacketStatusIterator it, |
| 161 bool apply /* false = undo */) { | 166 bool apply /* false = undo */) { |
| 162 RTC_DCHECK(it != packet_status_window_.end()); | 167 RTC_DCHECK(it != packet_status_window_.end()); |
| 168 // Metrics are dependent on feedbacks from the other side. We don't want | |
| 169 // to update the metrics each time a packet is sent, except for the case | |
| 170 // when it shifts old sent-but-unacked-packets out of window. | |
| 171 RTC_DCHECK(!apply || it->second != PacketStatus::Unacked); | |
| 172 | |
| 173 if (it->second != PacketStatus::Unacked) { | |
| 174 UpdateCounter(&acked_packets_, apply); | |
| 175 } | |
| 176 | |
| 163 UpdatePlr(it, apply); | 177 UpdatePlr(it, apply); |
| 164 UpdateRplr(it, apply); | 178 UpdateRplr(it, apply); |
| 165 } | 179 } |
| 166 | 180 |
| 167 void TransportFeedbackPacketLossTracker::UpdatePlr( | 181 void TransportFeedbackPacketLossTracker::UpdatePlr( |
|
michaelt
2017/02/27 12:44:21
Would be nice to move this function to PlrState.
elad.alon_webrtc.org
2017/02/27 13:18:05
I agree in principle. Let's keep the discussion ar
| |
| 168 PacketStatusIterator it, | 182 ConstPacketStatusIterator it, |
| 169 bool apply /* false = undo */) { | 183 bool apply /* false = undo */) { |
| 170 // Record or undo reception status of currently handled packet. | 184 switch (it->second) { |
| 171 if (it->second) { | 185 case PacketStatus::Unacked: |
| 172 UpdateCounter(&plr_state_.num_received_packets_, apply); | 186 return; |
| 173 } else { | 187 case PacketStatus::Received: |
| 174 UpdateCounter(&plr_state_.num_lost_packets_, apply); | 188 UpdateCounter(&plr_state_.num_received_packets_, apply); |
| 189 break; | |
| 190 case PacketStatus::Lost: | |
| 191 UpdateCounter(&plr_state_.num_lost_packets_, apply); | |
| 192 break; | |
| 193 default: | |
|
michaelt
2017/02/27 12:44:21
A question to all:
In my opinion its not necessary
elad.alon_webrtc.org
2017/02/27 13:18:05
+1 question
(I think checking that is generally sa
minyue-webrtc
2017/03/03 14:14:31
Agree. compiling warnings should be enough. Please
elad.alon_webrtc.org
2017/03/03 14:54:22
Discussed this with Minyue offline, and he'd like
| |
| 194 RTC_NOTREACHED(); | |
| 175 } | 195 } |
| 176 } | 196 } |
| 177 | 197 |
| 178 void TransportFeedbackPacketLossTracker::UpdateRplr( | 198 void TransportFeedbackPacketLossTracker::UpdateRplr( |
| 179 PacketStatusIterator it, | 199 ConstPacketStatusIterator it, |
|
michaelt
2017/02/27 12:44:21
Would be nice to move this function to RplrState.
elad.alon_webrtc.org
2017/02/27 13:18:05
As you've noticed, this is the problematic case. W
michaelt
2017/02/27 15:46:18
I think i would go for the "rtc::Optional" solutio
elad.alon_webrtc.org
2017/02/27 15:53:32
Okay. I'll wait for feedback from Erik and/or Stef
minyue-webrtc
2017/03/03 14:14:31
I would also like to make PlrState and RplrState e
minyue-webrtc
2017/03/03 14:50:01
That links is not publicly assessible, see this in
elad.alon_webrtc.org
2017/03/03 14:54:22
So no action for now?
| |
| 180 bool apply /* false = undo */) { | 200 bool apply /* false = undo */) { |
| 181 // Previous packet and current packet might compose a known pair. | 201 if (it->second == PacketStatus::Unacked) { |
| 182 // If so, the RPLR state needs to be updated accordingly. | 202 // Unacked packets cannot compose a pair. |
| 203 return; | |
| 204 } | |
| 205 | |
| 206 // Previous packet and current packet might compose a pair. | |
| 183 if (it != ref_packet_status_) { | 207 if (it != ref_packet_status_) { |
| 184 const auto& prev = PreviousPacketStatus(it); | 208 const auto& prev = PreviousPacketStatus(it); |
| 185 if (prev->first == static_cast<uint16_t>(it->first - 1)) { | 209 if (prev->second != PacketStatus::Unacked) { |
| 186 UpdateCounter(&rplr_state_.num_known_pairs_, apply); | 210 UpdateCounter(&rplr_state_.num_acked_pairs_, apply); |
| 187 if (!prev->second && it->second) { | 211 if (prev->second == PacketStatus::Lost && |
| 212 it->second == PacketStatus::Received) { | |
| 188 UpdateCounter( | 213 UpdateCounter( |
| 189 &rplr_state_.num_recoverable_losses_, apply); | 214 &rplr_state_.num_recoverable_losses_, apply); |
| 190 } | 215 } |
| 191 } | 216 } |
| 192 } | 217 } |
| 193 | 218 |
| 194 // Current packet and next packet might compose a pair. | 219 // 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); | 220 const auto& next = NextPacketStatus(it); |
| 197 if (next != packet_status_window_.end() && | 221 if (next != packet_status_window_.end() && |
| 198 next->first == static_cast<uint16_t>(it->first + 1)) { | 222 next->second != PacketStatus::Unacked) { |
| 199 UpdateCounter(&rplr_state_.num_known_pairs_, apply); | 223 UpdateCounter(&rplr_state_.num_acked_pairs_, apply); |
| 200 if (!it->second && next->second) { | 224 if (it->second == PacketStatus::Lost && |
| 225 next->second == PacketStatus::Received) { | |
| 201 UpdateCounter(&rplr_state_.num_recoverable_losses_, apply); | 226 UpdateCounter(&rplr_state_.num_recoverable_losses_, apply); |
| 202 } | 227 } |
| 203 } | 228 } |
| 204 } | 229 } |
| 205 | 230 |
| 206 TransportFeedbackPacketLossTracker::PacketStatusIterator | 231 TransportFeedbackPacketLossTracker::ConstPacketStatusIterator |
| 207 TransportFeedbackPacketLossTracker::PreviousPacketStatus( | 232 TransportFeedbackPacketLossTracker::PreviousPacketStatus( |
| 208 PacketStatusIterator it) { | 233 ConstPacketStatusIterator it) const { |
| 209 RTC_DCHECK(it != ref_packet_status_); | 234 RTC_DCHECK(it != ref_packet_status_); |
| 210 if (it == packet_status_window_.end()) { | 235 if (it == packet_status_window_.end()) { |
| 211 // This is to make PreviousPacketStatus(packet_status_window_.end()) point | 236 // This is to make PreviousPacketStatus(packet_status_window_.end()) point |
| 212 // to the last element. | 237 // to the last element. |
| 213 it = ref_packet_status_; | 238 it = ref_packet_status_; |
| 214 } | 239 } |
| 215 | 240 |
| 216 if (it == packet_status_window_.begin()) { | 241 if (it == packet_status_window_.begin()) { |
| 217 // Due to the circular nature of sequence numbers, we let the iterator | 242 // Due to the circular nature of sequence numbers, we let the iterator |
| 218 // go to the end. | 243 // go to the end. |
| 219 it = packet_status_window_.end(); | 244 it = packet_status_window_.end(); |
| 220 } | 245 } |
| 221 return --it; | 246 return --it; |
| 222 } | 247 } |
| 223 | 248 |
| 224 TransportFeedbackPacketLossTracker::PacketStatusIterator | 249 TransportFeedbackPacketLossTracker::ConstPacketStatusIterator |
| 225 TransportFeedbackPacketLossTracker::NextPacketStatus(PacketStatusIterator it) { | 250 TransportFeedbackPacketLossTracker::NextPacketStatus( |
| 251 ConstPacketStatusIterator it) const { | |
| 226 RTC_DCHECK(it != packet_status_window_.end()); | 252 RTC_DCHECK(it != packet_status_window_.end()); |
| 227 ++it; | 253 ++it; |
| 228 if (it == packet_status_window_.end()) { | 254 if (it == packet_status_window_.end()) { |
| 229 // Due to the circular nature of sequence numbers, we let the iterator | 255 // Due to the circular nature of sequence numbers, we let the iterator |
| 230 // goes back to the beginning. | 256 // goes back to the beginning. |
| 231 it = packet_status_window_.begin(); | 257 it = packet_status_window_.begin(); |
| 232 } | 258 } |
| 233 if (it == ref_packet_status_) { | 259 if (it == ref_packet_status_) { |
| 234 // This is to make the NextPacketStatus of the last element to return the | 260 // This is to make the NextPacketStatus of the last element to return the |
| 235 // beyond-the-end iterator. | 261 // beyond-the-end iterator. |
| 236 it = packet_status_window_.end(); | 262 it = packet_status_window_.end(); |
| 237 } | 263 } |
| 238 return it; | 264 return it; |
| 239 } | 265 } |
| 240 | 266 |
| 241 // TODO(minyue): This method checks the states of this class do not misbehave. | 267 // 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 | 268 // 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 | 269 // 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 | 270 // error after long period, we can remove the fuzzer test, and move this method |
| 245 // to unit test. | 271 // to unit test. |
| 246 void TransportFeedbackPacketLossTracker::Validate() const { // Testing only! | 272 void TransportFeedbackPacketLossTracker::Validate() const { // Testing only! |
|
michaelt
2017/02/27 12:44:21
Do we have any concrete conditions when we will re
elad.alon_webrtc.org
2017/02/27 13:18:05
The fuzzer relies heavily on this, so I don't see
michaelt
2017/02/27 15:46:18
I just asked because minyue wrote in the comment "
elad.alon_webrtc.org
2017/02/27 15:53:32
Ah. Well, if he wants to remove this, of course. :
minyue-webrtc
2017/03/03 14:14:31
Let's keep it until the feature has been fully lan
| |
| 247 RTC_CHECK_LE(packet_status_window_.size(), max_window_size_); | 273 RTC_CHECK_EQ(plr_state_.num_received_packets_ + plr_state_.num_lost_packets_, |
| 248 RTC_CHECK_EQ(packet_status_window_.size(), | 274 acked_packets_); |
| 249 plr_state_.num_lost_packets_ + plr_state_.num_received_packets_); | 275 RTC_CHECK_LE(acked_packets_, packet_status_window_.size()); |
| 276 RTC_CHECK_LE(acked_packets_, max_acked_packets_); | |
| 250 RTC_CHECK_LE(rplr_state_.num_recoverable_losses_, | 277 RTC_CHECK_LE(rplr_state_.num_recoverable_losses_, |
| 251 rplr_state_.num_known_pairs_); | 278 rplr_state_.num_acked_pairs_); |
| 252 RTC_CHECK_LE(rplr_state_.num_known_pairs_, | 279 RTC_CHECK_LE(rplr_state_.num_acked_pairs_, acked_packets_ - 1); |
| 253 packet_status_window_.size() - 1); | |
| 254 | 280 |
| 281 size_t unacked_packets = 0; | |
| 255 size_t received_packets = 0; | 282 size_t received_packets = 0; |
| 256 size_t lost_packets = 0; | 283 size_t lost_packets = 0; |
| 257 size_t known_status_pairs = 0; | 284 size_t acked_pairs = 0; |
| 258 size_t recoverable_losses = 0; | 285 size_t recoverable_losses = 0; |
| 259 | 286 |
| 260 if (!packet_status_window_.empty()) { | 287 if (!packet_status_window_.empty()) { |
| 261 PacketStatusIterator it = ref_packet_status_; | 288 ConstPacketStatusIterator it = ref_packet_status_; |
| 262 do { | 289 do { |
| 263 if (it->second) { | 290 switch (it->second) { |
| 264 ++received_packets; | 291 case PacketStatus::Unacked: |
| 265 } else { | 292 ++unacked_packets; |
| 266 ++lost_packets; | 293 break; |
| 294 case PacketStatus::Received: | |
| 295 ++received_packets; | |
| 296 break; | |
| 297 case PacketStatus::Lost: | |
| 298 ++lost_packets; | |
| 299 break; | |
| 300 default: | |
| 301 RTC_NOTREACHED(); | |
| 267 } | 302 } |
| 268 | 303 |
| 269 auto next = std::next(it); | 304 auto next = std::next(it); |
| 270 if (next == packet_status_window_.end()) | 305 if (next == packet_status_window_.end()) |
| 271 next = packet_status_window_.begin(); | 306 next = packet_status_window_.begin(); |
| 272 | 307 |
| 273 if (next != ref_packet_status_ && | 308 if (next != ref_packet_status_ && |
| 274 next->first == static_cast<uint16_t>(it->first + 1)) { | 309 it->second != PacketStatus::Unacked && |
| 275 ++known_status_pairs; | 310 next->second != PacketStatus::Unacked) { |
| 276 if (!it->second && next->second) | 311 ++acked_pairs; |
| 312 if (it->second == PacketStatus::Lost && | |
| 313 next->second == PacketStatus::Received) | |
| 277 ++recoverable_losses; | 314 ++recoverable_losses; |
| 278 } | 315 } |
| 279 | 316 |
| 280 RTC_CHECK_LT(ForwardDiff(ReferenceSequenceNumber(), it->first), | 317 RTC_CHECK_LT(ForwardDiff(ReferenceSequenceNumber(), it->first), |
| 281 kSeqNumHalf); | 318 kSeqNumHalf); |
| 282 | 319 |
| 283 it = next; | 320 it = next; |
| 284 } while (it != ref_packet_status_); | 321 } while (it != ref_packet_status_); |
| 285 } | 322 } |
| 286 | 323 |
| 287 RTC_CHECK_EQ(plr_state_.num_received_packets_, received_packets); | 324 RTC_CHECK_EQ(plr_state_.num_received_packets_, received_packets); |
| 288 RTC_CHECK_EQ(plr_state_.num_lost_packets_, lost_packets); | 325 RTC_CHECK_EQ(plr_state_.num_lost_packets_, lost_packets); |
| 289 RTC_CHECK_EQ(rplr_state_.num_known_pairs_, known_status_pairs); | 326 RTC_CHECK_EQ(packet_status_window_.size(), |
| 327 unacked_packets + received_packets + lost_packets); | |
| 328 RTC_CHECK_EQ(rplr_state_.num_acked_pairs_, acked_pairs); | |
| 290 RTC_CHECK_EQ(rplr_state_.num_recoverable_losses_, recoverable_losses); | 329 RTC_CHECK_EQ(rplr_state_.num_recoverable_losses_, recoverable_losses); |
| 291 } | 330 } |
| 292 | 331 |
| 293 rtc::Optional<float> | 332 rtc::Optional<float> |
| 294 TransportFeedbackPacketLossTracker::PlrState::GetMetric() const { | 333 TransportFeedbackPacketLossTracker::PlrState::GetMetric() const { |
| 295 const size_t total = num_lost_packets_ + num_received_packets_; | 334 const size_t total = num_lost_packets_ + num_received_packets_; |
| 296 if (total < min_num_packets_) { | 335 if (total < min_num_acked_packets_) { |
| 297 return rtc::Optional<float>(); | 336 return rtc::Optional<float>(); |
| 298 } else { | 337 } else { |
| 299 return rtc::Optional<float>( | 338 return rtc::Optional<float>( |
| 300 static_cast<float>(num_lost_packets_) / total); | 339 static_cast<float>(num_lost_packets_) / total); |
| 301 } | 340 } |
| 302 } | 341 } |
| 303 | 342 |
| 304 rtc::Optional<float> | 343 rtc::Optional<float> |
| 305 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const { | 344 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const { |
| 306 if (num_known_pairs_ < min_num_pairs_) { | 345 if (num_acked_pairs_ < min_num_acked_pairs_) { |
| 307 return rtc::Optional<float>(); | 346 return rtc::Optional<float>(); |
| 308 } else { | 347 } else { |
| 309 return rtc::Optional<float>( | 348 return rtc::Optional<float>( |
| 310 static_cast<float>(num_recoverable_losses_) / num_known_pairs_); | 349 static_cast<float>(num_recoverable_losses_) / num_acked_pairs_); |
| 311 } | 350 } |
| 312 } | 351 } |
| 313 | 352 |
| 314 } // namespace webrtc | 353 } // namespace webrtc |
| OLD | NEW |