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 // The only way for these two to is when the stream lies dormant for long | |
72 // enough for the sequence numbers to wrap. Everything in the window in | |
73 // such a case would be too old to use. | |
74 if (packet_status_window_.find(seq_num) != packet_status_window_.end()) { | |
michaelt
2017/02/09 10:52:02
The "else if" seams to be obsolete. Would go for:
elad.alon_webrtc.org
2017/02/09 12:27:53
I think it's easier to read like this, but if the
| |
75 Reset(); | |
76 } else if (!packet_status_window_.empty() && | |
77 ForwardDiff(seq_num, NewestSequenceNumber()) <= kSeqNumHalf) { | |
78 Reset(); | |
72 } | 79 } |
73 const uint16_t diff = ForwardDiff(ReferenceSequenceNumber(), seq_num); | 80 |
74 return diff >= 3 * kSeqNumQuarter; | 81 // Shift older packets out of window. |
82 while (!packet_status_window_.empty() && | |
83 ForwardDiff(ref_packet_status_->first, seq_num) >= kSeqNumHalf) { | |
84 RemoveOldestPacketStatus(); | |
85 } | |
86 | |
87 const auto& ret = packet_status_window_.insert( | |
michaelt
2017/02/09 10:52:02
1. "packet_status" would make more sene to me for
elad.alon_webrtc.org
2017/02/09 12:35:55
Good point about the hint.
| |
88 std::make_pair(seq_num, PacketStatus::Unacked)); | |
89 RTC_DCHECK(ret.second); | |
michaelt
2017/02/09 10:52:05
Seams obsolete since you checked already if the se
elad.alon_webrtc.org
2017/02/09 12:27:53
I think out-of-memory would be the only way for th
| |
90 | |
91 if (packet_status_window_.size() == 1) { | |
92 ref_packet_status_ = ret.first; | |
93 } | |
75 } | 94 } |
76 | 95 |
77 void TransportFeedbackPacketLossTracker::OnReceivedTransportFeedback( | 96 void TransportFeedbackPacketLossTracker::OnReceivedTransportFeedback( |
78 const rtcp::TransportFeedback& feedback) { | 97 const rtcp::TransportFeedback& feedback) { |
79 const auto& fb_vector = feedback.GetStatusVector(); | 98 const auto& fb_vector = feedback.GetStatusVector(); |
80 const uint16_t base_seq_num = feedback.GetBaseSequence(); | 99 const uint16_t base_seq_num = feedback.GetBaseSequence(); |
81 | 100 |
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; | 101 uint16_t seq_num = base_seq_num; |
100 for (size_t i = 0; i < fb_vector.size(); ++i, ++seq_num) { | 102 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 | 103 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 | 104 |
109 const bool received = | 105 // Packets which aren't at least marked as unacked either do not belong to |
110 fb_vector[i] != | 106 // this media stream, or have been shifted out of window. |
107 if (it == packet_status_window_.end()) | |
108 continue; | |
109 | |
110 const bool lost = fb_vector[i] == | |
111 webrtc::rtcp::TransportFeedback::StatusSymbol::kNotReceived; | 111 webrtc::rtcp::TransportFeedback::StatusSymbol::kNotReceived; |
112 InsertPacketStatus(seq_num, received); | 112 const PacketStatus new_packet_status = |
113 lost ? PacketStatus::Lost : PacketStatus::Received; | |
113 | 114 |
114 while (packet_status_window_.size() > max_window_size_) { | 115 RecordPacketStatus(it, new_packet_status); |
115 // Make sure that the window holds at most |max_window_size_| items. | |
116 RemoveOldestPacketStatus(); | |
117 } | |
118 } | 116 } |
119 } | 117 } |
120 | 118 |
121 rtc::Optional<float> | 119 rtc::Optional<float> |
122 TransportFeedbackPacketLossTracker::GetPacketLossRate() const { | 120 TransportFeedbackPacketLossTracker::GetPacketLossRate() const { |
123 return plr_state_.GetMetric(); | 121 return plr_state_.GetMetric(); |
124 } | 122 } |
125 | 123 |
126 rtc::Optional<float> | 124 rtc::Optional<float> |
127 TransportFeedbackPacketLossTracker::GetRecoverablePacketLossRate() const { | 125 TransportFeedbackPacketLossTracker::GetRecoverablePacketLossRate() const { |
128 return rplr_state_.GetMetric(); | 126 return rplr_state_.GetMetric(); |
129 } | 127 } |
130 | 128 |
131 void TransportFeedbackPacketLossTracker::InsertPacketStatus(uint16_t seq_num, | 129 void TransportFeedbackPacketLossTracker::RecordPacketStatus( |
132 bool received) { | 130 PacketStatusIterator it, |
133 const auto& ret = | 131 PacketStatus new_packet_status) { |
134 packet_status_window_.insert(std::make_pair(seq_num, received)); | 132 if (it->second != PacketStatus::Unacked) { |
135 if (!ret.second) { | 133 // Normally, packets are sent (inserted into window as "unacked"), then we |
136 if (!ret.first->second && received) { | 134 // receive one feedback for them. |
135 // But it is possible that a packet would receive two feedbacks. Then: | |
136 if (it->second == PacketStatus::Lost && | |
137 new_packet_status == PacketStatus::Received) { | |
137 // If older status said that the packet was lost but newer one says it | 138 // If older status said that the packet was lost but newer one says it |
138 // is received, we take the newer one. | 139 // is received, we take the newer one. |
139 UpdateMetrics(ret.first, false); | 140 UpdateMetrics(it, false); |
140 ret.first->second = received; | 141 it->second = PacketStatus::Unacked; // For clarity; overwritten shortly. |
141 } else { | 142 } else { |
142 // If the value is unchanged or if older status said that the packet was | 143 // 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. | 144 // received but the newer one says it is lost, we ignore it. |
145 // The standard allows for previously-reported packets to carry | |
146 // no report when the reports overlap, which also looks like the | |
147 // packet is being reported as lost. | |
144 return; | 148 return; |
145 } | 149 } |
146 } | 150 } |
147 UpdateMetrics(ret.first, true); | 151 |
148 if (packet_status_window_.size() == 1) | 152 // Change from UNACKED to RECEIVED/LOST. |
149 ref_packet_status_ = ret.first; | 153 it->second = new_packet_status; |
154 UpdateMetrics(it, true); | |
155 | |
156 // Remove packets from the beginning of the window until maximum-acked | |
157 // is observed again. Note that multiple sent-but-unacked packets might | |
158 // be removed before we reach the first acked (whether as received or as | |
159 // lost) packet. | |
160 while (acked_packets_ > max_acked_packets_) | |
161 RemoveOldestPacketStatus(); | |
150 } | 162 } |
151 | 163 |
152 void TransportFeedbackPacketLossTracker::RemoveOldestPacketStatus() { | 164 void TransportFeedbackPacketLossTracker::RemoveOldestPacketStatus() { |
153 UpdateMetrics(ref_packet_status_, false); | 165 UpdateMetrics(ref_packet_status_, false); |
michaelt
2017/02/09 10:52:04
Why do we UpdateMetrics before we remove the packe
elad.alon_webrtc.org
2017/02/09 12:27:53
The order is:
1. Update the statistics. This packe
| |
154 const auto it = ref_packet_status_; | 166 const auto it = ref_packet_status_; |
155 ref_packet_status_ = NextPacketStatus(it); | 167 ref_packet_status_ = NextPacketStatus(it); |
156 packet_status_window_.erase(it); | 168 packet_status_window_.erase(it); |
157 } | 169 } |
158 | 170 |
159 void TransportFeedbackPacketLossTracker::UpdateMetrics( | 171 void TransportFeedbackPacketLossTracker::UpdateMetrics( |
160 PacketStatusIterator it, | 172 ConstPacketStatusIterator it, |
161 bool apply /* false = undo */) { | 173 bool apply /* false = undo */) { |
162 RTC_DCHECK(it != packet_status_window_.end()); | 174 RTC_DCHECK(it != packet_status_window_.end()); |
175 // Metrics are dependent on feedbacks from the other side. We don't want | |
176 // to update the metrics each time a packet is sent, except for the case | |
177 // when it shifts old sent-but-unacked-packets out of window. | |
178 RTC_DCHECK(!apply || it->second != PacketStatus::Unacked); | |
179 | |
180 if (it->second != PacketStatus::Unacked) { | |
181 UpdateCounter(&acked_packets_, apply); | |
182 } | |
183 | |
163 UpdatePlr(it, apply); | 184 UpdatePlr(it, apply); |
164 UpdateRplr(it, apply); | 185 UpdateRplr(it, apply); |
165 } | 186 } |
166 | 187 |
167 void TransportFeedbackPacketLossTracker::UpdatePlr( | 188 void TransportFeedbackPacketLossTracker::UpdatePlr( |
168 PacketStatusIterator it, | 189 ConstPacketStatusIterator it, |
169 bool apply /* false = undo */) { | 190 bool apply /* false = undo */) { |
170 // Record or undo reception status of currently handled packet. | 191 switch (it->second) { |
171 if (it->second) { | 192 case PacketStatus::Unacked: |
172 UpdateCounter(&plr_state_.num_received_packets_, apply); | 193 return; |
173 } else { | 194 case PacketStatus::Received: |
174 UpdateCounter(&plr_state_.num_lost_packets_, apply); | 195 UpdateCounter(&plr_state_.num_received_packets_, apply); |
196 break; | |
197 case PacketStatus::Lost: | |
198 UpdateCounter(&plr_state_.num_lost_packets_, apply); | |
199 break; | |
200 default: | |
michaelt
2017/02/09 10:52:03
The default case seams useless to me, since the co
elad.alon_webrtc.org
2017/02/09 12:27:53
It protects against illegal enum values, such as 3
| |
201 RTC_NOTREACHED(); | |
175 } | 202 } |
176 } | 203 } |
177 | 204 |
178 void TransportFeedbackPacketLossTracker::UpdateRplr( | 205 void TransportFeedbackPacketLossTracker::UpdateRplr( |
179 PacketStatusIterator it, | 206 ConstPacketStatusIterator it, |
180 bool apply /* false = undo */) { | 207 bool apply /* false = undo */) { |
181 // Previous packet and current packet might compose a known pair. | 208 if (it->second == PacketStatus::Unacked) { |
182 // If so, the RPLR state needs to be updated accordingly. | 209 // Unacked packets cannot compose a pair. |
210 return; | |
211 } | |
212 | |
213 // Previous packet and current packet might compose a pair. | |
183 if (it != ref_packet_status_) { | 214 if (it != ref_packet_status_) { |
184 const auto& prev = PreviousPacketStatus(it); | 215 const auto& prev = PreviousPacketStatus(it); |
185 if (prev->first == static_cast<uint16_t>(it->first - 1)) { | 216 if (prev->second != PacketStatus::Unacked) { |
186 UpdateCounter(&rplr_state_.num_known_pairs_, apply); | 217 UpdateCounter(&rplr_state_.num_acked_pairs_, apply); |
187 if (!prev->second && it->second) { | 218 if (prev->second == PacketStatus::Lost && |
219 it->second == PacketStatus::Received) { | |
188 UpdateCounter( | 220 UpdateCounter( |
189 &rplr_state_.num_recoverable_losses_, apply); | 221 &rplr_state_.num_recoverable_losses_, apply); |
190 } | 222 } |
191 } | 223 } |
192 } | 224 } |
193 | 225 |
194 // Current packet and next packet might compose a pair. | 226 // 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); | 227 const auto& next = NextPacketStatus(it); |
197 if (next != packet_status_window_.end() && | 228 if (next != packet_status_window_.end() && |
198 next->first == static_cast<uint16_t>(it->first + 1)) { | 229 next->second != PacketStatus::Unacked) { |
199 UpdateCounter(&rplr_state_.num_known_pairs_, apply); | 230 UpdateCounter(&rplr_state_.num_acked_pairs_, apply); |
200 if (!it->second && next->second) { | 231 if (it->second == PacketStatus::Lost && |
232 next->second == PacketStatus::Received) { | |
201 UpdateCounter(&rplr_state_.num_recoverable_losses_, apply); | 233 UpdateCounter(&rplr_state_.num_recoverable_losses_, apply); |
202 } | 234 } |
203 } | 235 } |
204 } | 236 } |
205 | 237 |
206 TransportFeedbackPacketLossTracker::PacketStatusIterator | 238 TransportFeedbackPacketLossTracker::ConstPacketStatusIterator |
207 TransportFeedbackPacketLossTracker::PreviousPacketStatus( | 239 TransportFeedbackPacketLossTracker::PreviousPacketStatus( |
208 PacketStatusIterator it) { | 240 ConstPacketStatusIterator it) const { |
209 RTC_DCHECK(it != ref_packet_status_); | 241 RTC_DCHECK(it != ref_packet_status_); |
210 if (it == packet_status_window_.end()) { | 242 if (it == packet_status_window_.end()) { |
211 // This is to make PreviousPacketStatus(packet_status_window_.end()) point | 243 // This is to make PreviousPacketStatus(packet_status_window_.end()) point |
212 // to the last element. | 244 // to the last element. |
213 it = ref_packet_status_; | 245 it = ref_packet_status_; |
214 } | 246 } |
215 | 247 |
216 if (it == packet_status_window_.begin()) { | 248 if (it == packet_status_window_.begin()) { |
217 // Due to the circular nature of sequence numbers, we let the iterator | 249 // Due to the circular nature of sequence numbers, we let the iterator |
218 // go to the end. | 250 // go to the end. |
219 it = packet_status_window_.end(); | 251 it = packet_status_window_.end(); |
220 } | 252 } |
221 return --it; | 253 return --it; |
222 } | 254 } |
223 | 255 |
224 TransportFeedbackPacketLossTracker::PacketStatusIterator | 256 TransportFeedbackPacketLossTracker::ConstPacketStatusIterator |
225 TransportFeedbackPacketLossTracker::NextPacketStatus(PacketStatusIterator it) { | 257 TransportFeedbackPacketLossTracker::NextPacketStatus( |
258 ConstPacketStatusIterator it) const { | |
226 RTC_DCHECK(it != packet_status_window_.end()); | 259 RTC_DCHECK(it != packet_status_window_.end()); |
227 ++it; | 260 ++it; |
228 if (it == packet_status_window_.end()) { | 261 if (it == packet_status_window_.end()) { |
229 // Due to the circular nature of sequence numbers, we let the iterator | 262 // Due to the circular nature of sequence numbers, we let the iterator |
230 // goes back to the beginning. | 263 // goes back to the beginning. |
231 it = packet_status_window_.begin(); | 264 it = packet_status_window_.begin(); |
232 } | 265 } |
233 if (it == ref_packet_status_) { | 266 if (it == ref_packet_status_) { |
234 // This is to make the NextPacketStatus of the last element to return the | 267 // This is to make the NextPacketStatus of the last element to return the |
235 // beyond-the-end iterator. | 268 // beyond-the-end iterator. |
236 it = packet_status_window_.end(); | 269 it = packet_status_window_.end(); |
237 } | 270 } |
238 return it; | 271 return it; |
239 } | 272 } |
240 | 273 |
241 // TODO(minyue): This method checks the states of this class do not misbehave. | 274 // 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 | 275 // 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 | 276 // 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 | 277 // error after long period, we can remove the fuzzer test, and move this method |
245 // to unit test. | 278 // to unit test. |
246 void TransportFeedbackPacketLossTracker::Validate() const { // Testing only! | 279 void TransportFeedbackPacketLossTracker::Validate() const { // Testing only! |
247 RTC_CHECK_LE(packet_status_window_.size(), max_window_size_); | 280 RTC_CHECK_EQ(plr_state_.num_received_packets_ + plr_state_.num_lost_packets_, |
248 RTC_CHECK_EQ(packet_status_window_.size(), | 281 acked_packets_); |
249 plr_state_.num_lost_packets_ + plr_state_.num_received_packets_); | 282 RTC_CHECK_LE(acked_packets_, packet_status_window_.size()); |
283 RTC_CHECK_LE(acked_packets_, max_acked_packets_); | |
250 RTC_CHECK_LE(rplr_state_.num_recoverable_losses_, | 284 RTC_CHECK_LE(rplr_state_.num_recoverable_losses_, |
251 rplr_state_.num_known_pairs_); | 285 rplr_state_.num_acked_pairs_); |
252 RTC_CHECK_LE(rplr_state_.num_known_pairs_, | 286 RTC_CHECK_LE(rplr_state_.num_acked_pairs_, acked_packets_ - 1); |
253 packet_status_window_.size() - 1); | |
254 | 287 |
288 size_t unacked_packets = 0; | |
255 size_t received_packets = 0; | 289 size_t received_packets = 0; |
256 size_t lost_packets = 0; | 290 size_t lost_packets = 0; |
257 size_t known_status_pairs = 0; | 291 size_t acked_pairs = 0; |
258 size_t recoverable_losses = 0; | 292 size_t recoverable_losses = 0; |
259 | 293 |
260 if (!packet_status_window_.empty()) { | 294 if (!packet_status_window_.empty()) { |
261 PacketStatusIterator it = ref_packet_status_; | 295 ConstPacketStatusIterator it = ref_packet_status_; |
262 do { | 296 do { |
263 if (it->second) { | 297 switch (it->second) { |
264 ++received_packets; | 298 case PacketStatus::Unacked: |
265 } else { | 299 ++unacked_packets; |
266 ++lost_packets; | 300 break; |
301 case PacketStatus::Received: | |
302 ++received_packets; | |
303 break; | |
304 case PacketStatus::Lost: | |
305 ++lost_packets; | |
306 break; | |
307 default: | |
308 RTC_NOTREACHED(); | |
267 } | 309 } |
268 | 310 |
269 auto next = std::next(it); | 311 auto next = std::next(it); |
270 if (next == packet_status_window_.end()) | 312 if (next == packet_status_window_.end()) |
271 next = packet_status_window_.begin(); | 313 next = packet_status_window_.begin(); |
272 | 314 |
273 if (next != ref_packet_status_ && | 315 if (next != ref_packet_status_ && |
274 next->first == static_cast<uint16_t>(it->first + 1)) { | 316 it->second != PacketStatus::Unacked && |
275 ++known_status_pairs; | 317 next->second != PacketStatus::Unacked) { |
276 if (!it->second && next->second) | 318 ++acked_pairs; |
319 if (it->second == PacketStatus::Lost && | |
320 next->second == PacketStatus::Received) | |
277 ++recoverable_losses; | 321 ++recoverable_losses; |
278 } | 322 } |
279 | 323 |
280 RTC_CHECK_LT(ForwardDiff(ReferenceSequenceNumber(), it->first), | 324 RTC_CHECK_LT(ForwardDiff(ReferenceSequenceNumber(), it->first), |
281 kSeqNumHalf); | 325 kSeqNumHalf); |
282 | 326 |
283 it = next; | 327 it = next; |
284 } while (it != ref_packet_status_); | 328 } while (it != ref_packet_status_); |
285 } | 329 } |
286 | 330 |
287 RTC_CHECK_EQ(plr_state_.num_received_packets_, received_packets); | 331 RTC_CHECK_EQ(plr_state_.num_received_packets_, received_packets); |
288 RTC_CHECK_EQ(plr_state_.num_lost_packets_, lost_packets); | 332 RTC_CHECK_EQ(plr_state_.num_lost_packets_, lost_packets); |
289 RTC_CHECK_EQ(rplr_state_.num_known_pairs_, known_status_pairs); | 333 RTC_CHECK_EQ(packet_status_window_.size(), |
334 unacked_packets + received_packets + lost_packets); | |
335 RTC_CHECK_EQ(rplr_state_.num_acked_pairs_, acked_pairs); | |
290 RTC_CHECK_EQ(rplr_state_.num_recoverable_losses_, recoverable_losses); | 336 RTC_CHECK_EQ(rplr_state_.num_recoverable_losses_, recoverable_losses); |
291 } | 337 } |
292 | 338 |
293 rtc::Optional<float> | 339 rtc::Optional<float> |
294 TransportFeedbackPacketLossTracker::PlrState::GetMetric() const { | 340 TransportFeedbackPacketLossTracker::PlrState::GetMetric() const { |
295 const size_t total = num_lost_packets_ + num_received_packets_; | 341 const size_t total = num_lost_packets_ + num_received_packets_; |
296 if (total < min_num_packets_) { | 342 if (total < min_num_acked_packets_) { |
297 return rtc::Optional<float>(); | 343 return rtc::Optional<float>(); |
298 } else { | 344 } else { |
299 return rtc::Optional<float>( | 345 return rtc::Optional<float>( |
300 static_cast<float>(num_lost_packets_) / total); | 346 static_cast<float>(num_lost_packets_) / total); |
301 } | 347 } |
302 } | 348 } |
303 | 349 |
304 rtc::Optional<float> | 350 rtc::Optional<float> |
305 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const { | 351 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const { |
306 if (num_known_pairs_ < min_num_pairs_) { | 352 if (num_acked_pairs_ < min_num_acked_pairs_) { |
307 return rtc::Optional<float>(); | 353 return rtc::Optional<float>(); |
308 } else { | 354 } else { |
309 return rtc::Optional<float>( | 355 return rtc::Optional<float>( |
310 static_cast<float>(num_recoverable_losses_) / num_known_pairs_); | 356 static_cast<float>(num_recoverable_losses_) / num_acked_pairs_); |
311 } | 357 } |
312 } | 358 } |
313 | 359 |
314 } // namespace webrtc | 360 } // namespace webrtc |
OLD | NEW |