Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: webrtc/voice_engine/transport_feedback_packet_loss_tracker.cc

Issue 2632203002: Packet Loss Tracker - Stream Separation (Closed)
Patch Set: hint Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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) {
minyue-webrtc 2017/02/14 16:46:59 The name should be OnSentPacket or something like
elad.alon_webrtc.org 2017/02/15 16:47:36 This is triggered from the pre-existing TransportF
minyue-webrtc 2017/02/16 09:51:44 Should it hook to OnSentPacket instead: see https
elad.alon_webrtc.org 2017/02/16 15:51:40 That one seems to be called after the packet is se
minyue-webrtc 2017/02/17 11:09:14 I am not seeing this as a problem. Please refer to
elad.alon_webrtc.org 2017/02/17 12:24:42 (Replied there.)
minyue-webrtc 2017/02/20 12:49:06 Per offline discussion, I think AddPacket is the r
71 // The only way for these two to is when the stream lies dormant for long
minyue-webrtc 2017/02/14 16:46:59 .. to ?? is ... and looks like that this comment
elad.alon_webrtc.org 2017/02/15 16:47:36 Missing "happen"; thanks for catching.
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()) {
75 Reset();
76 } else if (!packet_status_window_.empty() &&
77 ForwardDiff(seq_num, NewestSequenceNumber()) <= kSeqNumHalf) {
minyue-webrtc 2017/02/14 16:46:59 how can this happen?
elad.alon_webrtc.org 2017/02/15 16:47:36 DTX, for instance. Or anything else that might cau
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 packet_status_window_.insert(packet_status_window_.end(),
88 std::make_pair(seq_num, PacketStatus::Unacked));
89
90 if (packet_status_window_.size() == 1) {
91 ref_packet_status_ = packet_status_window_.cbegin();
92 }
75 } 93 }
76 94
77 void TransportFeedbackPacketLossTracker::OnReceivedTransportFeedback( 95 void TransportFeedbackPacketLossTracker::OnReceivedTransportFeedback(
78 const rtcp::TransportFeedback& feedback) { 96 const rtcp::TransportFeedback& feedback) {
79 const auto& fb_vector = feedback.GetStatusVector(); 97 const auto& fb_vector = feedback.GetStatusVector();
80 const uint16_t base_seq_num = feedback.GetBaseSequence(); 98 const uint16_t base_seq_num = feedback.GetBaseSequence();
81 99
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; 100 uint16_t seq_num = base_seq_num;
100 for (size_t i = 0; i < fb_vector.size(); ++i, ++seq_num) { 101 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 102 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 103
109 const bool received = 104 // Packets which aren't at least marked as unacked either do not belong to
110 fb_vector[i] != 105 // this media stream, or have been shifted out of window.
106 if (it == packet_status_window_.end())
107 continue;
108
109 const bool lost = fb_vector[i] ==
111 webrtc::rtcp::TransportFeedback::StatusSymbol::kNotReceived; 110 webrtc::rtcp::TransportFeedback::StatusSymbol::kNotReceived;
112 InsertPacketStatus(seq_num, received); 111 const PacketStatus new_packet_status =
112 lost ? PacketStatus::Lost : PacketStatus::Received;
113 113
114 while (packet_status_window_.size() > max_window_size_) { 114 RecordPacketStatus(it, new_packet_status);
115 // Make sure that the window holds at most |max_window_size_| items.
116 RemoveOldestPacketStatus();
117 }
118 } 115 }
119 } 116 }
120 117
121 rtc::Optional<float> 118 rtc::Optional<float>
122 TransportFeedbackPacketLossTracker::GetPacketLossRate() const { 119 TransportFeedbackPacketLossTracker::GetPacketLossRate() const {
123 return plr_state_.GetMetric(); 120 return plr_state_.GetMetric();
124 } 121 }
125 122
126 rtc::Optional<float> 123 rtc::Optional<float>
127 TransportFeedbackPacketLossTracker::GetRecoverablePacketLossRate() const { 124 TransportFeedbackPacketLossTracker::GetRecoverablePacketLossRate() const {
128 return rplr_state_.GetMetric(); 125 return rplr_state_.GetMetric();
129 } 126 }
130 127
131 void TransportFeedbackPacketLossTracker::InsertPacketStatus(uint16_t seq_num, 128 void TransportFeedbackPacketLossTracker::RecordPacketStatus(
132 bool received) { 129 PacketStatusIterator it,
minyue-webrtc 2017/02/14 16:46:59 if we make "it" into seq_num instead, we may avoid
elad.alon_webrtc.org 2017/02/15 16:47:36 I feel that calling RecordPacketStatus() when it m
minyue-webrtc 2017/02/16 09:51:44 I feel typedef a non-const iterator just for this
elad.alon_webrtc.org 2017/02/16 15:51:40 I feel like RecordPacketStatus() makes the code cl
minyue-webrtc 2017/02/17 11:09:14 ConstPacketStatusIterator was introduced to avoid
elad.alon_webrtc.org 2017/02/17 12:24:42 Do you want the name to be reverted to PacketStatu
minyue-webrtc 2017/02/20 12:49:06 No ConstPacketStatusIterator is fine
133 const auto& ret = 130 PacketStatus new_packet_status) {
minyue-webrtc 2017/02/17 11:09:14 I see another issue. RecordPacketStatus sounds mor
elad.alon_webrtc.org 2017/02/17 12:24:42 I'll go with #1.
elad.alon_webrtc.org 2017/02/17 12:27:03 By the way, I find the new code to be slightly les
minyue-webrtc 2017/02/20 12:49:06 I like the boolean ssince it is more important for
134 packet_status_window_.insert(std::make_pair(seq_num, received)); 131 if (it->second != PacketStatus::Unacked) {
135 if (!ret.second) { 132 // Normally, packets are sent (inserted into window as "unacked"), then we
136 if (!ret.first->second && received) { 133 // receive one feedback for them.
134 // But it is possible that a packet would receive two feedbacks. Then:
135 if (it->second == PacketStatus::Lost &&
136 new_packet_status == PacketStatus::Received) {
137 // If older status said that the packet was lost but newer one says it 137 // If older status said that the packet was lost but newer one says it
138 // is received, we take the newer one. 138 // is received, we take the newer one.
139 UpdateMetrics(ret.first, false); 139 UpdateMetrics(it, false);
140 ret.first->second = received; 140 it->second = PacketStatus::Unacked; // For clarity; overwritten shortly.
141 } else { 141 } else {
142 // If the value is unchanged or if older status said that the packet was 142 // 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. 143 // received but the newer one says it is lost, we ignore it.
144 // The standard allows for previously-reported packets to carry
145 // no report when the reports overlap, which also looks like the
146 // packet is being reported as lost.
144 return; 147 return;
145 } 148 }
146 } 149 }
147 UpdateMetrics(ret.first, true); 150
148 if (packet_status_window_.size() == 1) 151 // Change from UNACKED to RECEIVED/LOST.
149 ref_packet_status_ = ret.first; 152 it->second = new_packet_status;
153 UpdateMetrics(it, true);
154
155 // Remove packets from the beginning of the window until maximum-acked
156 // is observed again. Note that multiple sent-but-unacked packets might
157 // be removed before we reach the first acked (whether as received or as
158 // lost) packet.
159 while (acked_packets_ > max_acked_packets_)
160 RemoveOldestPacketStatus();
150 } 161 }
151 162
152 void TransportFeedbackPacketLossTracker::RemoveOldestPacketStatus() { 163 void TransportFeedbackPacketLossTracker::RemoveOldestPacketStatus() {
153 UpdateMetrics(ref_packet_status_, false); 164 UpdateMetrics(ref_packet_status_, false);
154 const auto it = ref_packet_status_; 165 const auto it = ref_packet_status_;
155 ref_packet_status_ = NextPacketStatus(it); 166 ref_packet_status_ = NextPacketStatus(it);
156 packet_status_window_.erase(it); 167 packet_status_window_.erase(it);
157 } 168 }
158 169
159 void TransportFeedbackPacketLossTracker::UpdateMetrics( 170 void TransportFeedbackPacketLossTracker::UpdateMetrics(
160 PacketStatusIterator it, 171 ConstPacketStatusIterator it,
161 bool apply /* false = undo */) { 172 bool apply /* false = undo */) {
162 RTC_DCHECK(it != packet_status_window_.end()); 173 RTC_DCHECK(it != packet_status_window_.end());
174 // Metrics are dependent on feedbacks from the other side. We don't want
175 // to update the metrics each time a packet is sent, except for the case
176 // when it shifts old sent-but-unacked-packets out of window.
177 RTC_DCHECK(!apply || it->second != PacketStatus::Unacked);
178
179 if (it->second != PacketStatus::Unacked) {
180 UpdateCounter(&acked_packets_, apply);
181 }
182
163 UpdatePlr(it, apply); 183 UpdatePlr(it, apply);
164 UpdateRplr(it, apply); 184 UpdateRplr(it, apply);
165 } 185 }
166 186
167 void TransportFeedbackPacketLossTracker::UpdatePlr( 187 void TransportFeedbackPacketLossTracker::UpdatePlr(
168 PacketStatusIterator it, 188 ConstPacketStatusIterator it,
169 bool apply /* false = undo */) { 189 bool apply /* false = undo */) {
170 // Record or undo reception status of currently handled packet. 190 switch (it->second) {
171 if (it->second) { 191 case PacketStatus::Unacked:
172 UpdateCounter(&plr_state_.num_received_packets_, apply); 192 return;
173 } else { 193 case PacketStatus::Received:
174 UpdateCounter(&plr_state_.num_lost_packets_, apply); 194 UpdateCounter(&plr_state_.num_received_packets_, apply);
195 break;
196 case PacketStatus::Lost:
197 UpdateCounter(&plr_state_.num_lost_packets_, apply);
198 break;
199 default:
200 RTC_NOTREACHED();
175 } 201 }
176 } 202 }
177 203
178 void TransportFeedbackPacketLossTracker::UpdateRplr( 204 void TransportFeedbackPacketLossTracker::UpdateRplr(
179 PacketStatusIterator it, 205 ConstPacketStatusIterator it,
180 bool apply /* false = undo */) { 206 bool apply /* false = undo */) {
181 // Previous packet and current packet might compose a known pair. 207 if (it->second == PacketStatus::Unacked) {
182 // If so, the RPLR state needs to be updated accordingly. 208 // Unacked packets cannot compose a pair.
209 return;
210 }
211
212 // Previous packet and current packet might compose a pair.
183 if (it != ref_packet_status_) { 213 if (it != ref_packet_status_) {
184 const auto& prev = PreviousPacketStatus(it); 214 const auto& prev = PreviousPacketStatus(it);
185 if (prev->first == static_cast<uint16_t>(it->first - 1)) { 215 if (prev->second != PacketStatus::Unacked) {
186 UpdateCounter(&rplr_state_.num_known_pairs_, apply); 216 UpdateCounter(&rplr_state_.num_acked_pairs_, apply);
187 if (!prev->second && it->second) { 217 if (prev->second == PacketStatus::Lost &&
218 it->second == PacketStatus::Received) {
188 UpdateCounter( 219 UpdateCounter(
189 &rplr_state_.num_recoverable_losses_, apply); 220 &rplr_state_.num_recoverable_losses_, apply);
190 } 221 }
191 } 222 }
192 } 223 }
193 224
194 // Current packet and next packet might compose a pair. 225 // 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); 226 const auto& next = NextPacketStatus(it);
197 if (next != packet_status_window_.end() && 227 if (next != packet_status_window_.end() &&
198 next->first == static_cast<uint16_t>(it->first + 1)) { 228 next->second != PacketStatus::Unacked) {
199 UpdateCounter(&rplr_state_.num_known_pairs_, apply); 229 UpdateCounter(&rplr_state_.num_acked_pairs_, apply);
200 if (!it->second && next->second) { 230 if (it->second == PacketStatus::Lost &&
231 next->second == PacketStatus::Received) {
201 UpdateCounter(&rplr_state_.num_recoverable_losses_, apply); 232 UpdateCounter(&rplr_state_.num_recoverable_losses_, apply);
202 } 233 }
203 } 234 }
204 } 235 }
205 236
206 TransportFeedbackPacketLossTracker::PacketStatusIterator 237 TransportFeedbackPacketLossTracker::ConstPacketStatusIterator
207 TransportFeedbackPacketLossTracker::PreviousPacketStatus( 238 TransportFeedbackPacketLossTracker::PreviousPacketStatus(
208 PacketStatusIterator it) { 239 ConstPacketStatusIterator it) const {
209 RTC_DCHECK(it != ref_packet_status_); 240 RTC_DCHECK(it != ref_packet_status_);
210 if (it == packet_status_window_.end()) { 241 if (it == packet_status_window_.end()) {
211 // This is to make PreviousPacketStatus(packet_status_window_.end()) point 242 // This is to make PreviousPacketStatus(packet_status_window_.end()) point
212 // to the last element. 243 // to the last element.
213 it = ref_packet_status_; 244 it = ref_packet_status_;
214 } 245 }
215 246
216 if (it == packet_status_window_.begin()) { 247 if (it == packet_status_window_.begin()) {
217 // Due to the circular nature of sequence numbers, we let the iterator 248 // Due to the circular nature of sequence numbers, we let the iterator
218 // go to the end. 249 // go to the end.
219 it = packet_status_window_.end(); 250 it = packet_status_window_.end();
220 } 251 }
221 return --it; 252 return --it;
222 } 253 }
223 254
224 TransportFeedbackPacketLossTracker::PacketStatusIterator 255 TransportFeedbackPacketLossTracker::ConstPacketStatusIterator
225 TransportFeedbackPacketLossTracker::NextPacketStatus(PacketStatusIterator it) { 256 TransportFeedbackPacketLossTracker::NextPacketStatus(
257 ConstPacketStatusIterator it) const {
226 RTC_DCHECK(it != packet_status_window_.end()); 258 RTC_DCHECK(it != packet_status_window_.end());
227 ++it; 259 ++it;
228 if (it == packet_status_window_.end()) { 260 if (it == packet_status_window_.end()) {
229 // Due to the circular nature of sequence numbers, we let the iterator 261 // Due to the circular nature of sequence numbers, we let the iterator
230 // goes back to the beginning. 262 // goes back to the beginning.
231 it = packet_status_window_.begin(); 263 it = packet_status_window_.begin();
232 } 264 }
233 if (it == ref_packet_status_) { 265 if (it == ref_packet_status_) {
234 // This is to make the NextPacketStatus of the last element to return the 266 // This is to make the NextPacketStatus of the last element to return the
235 // beyond-the-end iterator. 267 // beyond-the-end iterator.
236 it = packet_status_window_.end(); 268 it = packet_status_window_.end();
237 } 269 }
238 return it; 270 return it;
239 } 271 }
240 272
241 // TODO(minyue): This method checks the states of this class do not misbehave. 273 // 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 274 // 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 275 // 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 276 // error after long period, we can remove the fuzzer test, and move this method
245 // to unit test. 277 // to unit test.
246 void TransportFeedbackPacketLossTracker::Validate() const { // Testing only! 278 void TransportFeedbackPacketLossTracker::Validate() const { // Testing only!
247 RTC_CHECK_LE(packet_status_window_.size(), max_window_size_); 279 RTC_CHECK_EQ(plr_state_.num_received_packets_ + plr_state_.num_lost_packets_,
248 RTC_CHECK_EQ(packet_status_window_.size(), 280 acked_packets_);
249 plr_state_.num_lost_packets_ + plr_state_.num_received_packets_); 281 RTC_CHECK_LE(acked_packets_, packet_status_window_.size());
282 RTC_CHECK_LE(acked_packets_, max_acked_packets_);
250 RTC_CHECK_LE(rplr_state_.num_recoverable_losses_, 283 RTC_CHECK_LE(rplr_state_.num_recoverable_losses_,
251 rplr_state_.num_known_pairs_); 284 rplr_state_.num_acked_pairs_);
252 RTC_CHECK_LE(rplr_state_.num_known_pairs_, 285 RTC_CHECK_LE(rplr_state_.num_acked_pairs_, acked_packets_ - 1);
253 packet_status_window_.size() - 1);
254 286
287 size_t unacked_packets = 0;
255 size_t received_packets = 0; 288 size_t received_packets = 0;
256 size_t lost_packets = 0; 289 size_t lost_packets = 0;
257 size_t known_status_pairs = 0; 290 size_t acked_pairs = 0;
258 size_t recoverable_losses = 0; 291 size_t recoverable_losses = 0;
259 292
260 if (!packet_status_window_.empty()) { 293 if (!packet_status_window_.empty()) {
261 PacketStatusIterator it = ref_packet_status_; 294 ConstPacketStatusIterator it = ref_packet_status_;
262 do { 295 do {
263 if (it->second) { 296 switch (it->second) {
264 ++received_packets; 297 case PacketStatus::Unacked:
265 } else { 298 ++unacked_packets;
266 ++lost_packets; 299 break;
300 case PacketStatus::Received:
301 ++received_packets;
302 break;
303 case PacketStatus::Lost:
304 ++lost_packets;
305 break;
306 default:
307 RTC_NOTREACHED();
267 } 308 }
268 309
269 auto next = std::next(it); 310 auto next = std::next(it);
270 if (next == packet_status_window_.end()) 311 if (next == packet_status_window_.end())
271 next = packet_status_window_.begin(); 312 next = packet_status_window_.begin();
272 313
273 if (next != ref_packet_status_ && 314 if (next != ref_packet_status_ &&
274 next->first == static_cast<uint16_t>(it->first + 1)) { 315 it->second != PacketStatus::Unacked &&
275 ++known_status_pairs; 316 next->second != PacketStatus::Unacked) {
276 if (!it->second && next->second) 317 ++acked_pairs;
318 if (it->second == PacketStatus::Lost &&
319 next->second == PacketStatus::Received)
277 ++recoverable_losses; 320 ++recoverable_losses;
278 } 321 }
279 322
280 RTC_CHECK_LT(ForwardDiff(ReferenceSequenceNumber(), it->first), 323 RTC_CHECK_LT(ForwardDiff(ReferenceSequenceNumber(), it->first),
281 kSeqNumHalf); 324 kSeqNumHalf);
282 325
283 it = next; 326 it = next;
284 } while (it != ref_packet_status_); 327 } while (it != ref_packet_status_);
285 } 328 }
286 329
287 RTC_CHECK_EQ(plr_state_.num_received_packets_, received_packets); 330 RTC_CHECK_EQ(plr_state_.num_received_packets_, received_packets);
288 RTC_CHECK_EQ(plr_state_.num_lost_packets_, lost_packets); 331 RTC_CHECK_EQ(plr_state_.num_lost_packets_, lost_packets);
289 RTC_CHECK_EQ(rplr_state_.num_known_pairs_, known_status_pairs); 332 RTC_CHECK_EQ(packet_status_window_.size(),
333 unacked_packets + received_packets + lost_packets);
334 RTC_CHECK_EQ(rplr_state_.num_acked_pairs_, acked_pairs);
290 RTC_CHECK_EQ(rplr_state_.num_recoverable_losses_, recoverable_losses); 335 RTC_CHECK_EQ(rplr_state_.num_recoverable_losses_, recoverable_losses);
291 } 336 }
292 337
293 rtc::Optional<float> 338 rtc::Optional<float>
294 TransportFeedbackPacketLossTracker::PlrState::GetMetric() const { 339 TransportFeedbackPacketLossTracker::PlrState::GetMetric() const {
295 const size_t total = num_lost_packets_ + num_received_packets_; 340 const size_t total = num_lost_packets_ + num_received_packets_;
296 if (total < min_num_packets_) { 341 if (total < min_num_acked_packets_) {
297 return rtc::Optional<float>(); 342 return rtc::Optional<float>();
298 } else { 343 } else {
299 return rtc::Optional<float>( 344 return rtc::Optional<float>(
300 static_cast<float>(num_lost_packets_) / total); 345 static_cast<float>(num_lost_packets_) / total);
301 } 346 }
302 } 347 }
303 348
304 rtc::Optional<float> 349 rtc::Optional<float>
305 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const { 350 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const {
306 if (num_known_pairs_ < min_num_pairs_) { 351 if (num_acked_pairs_ < min_num_acked_pairs_) {
307 return rtc::Optional<float>(); 352 return rtc::Optional<float>();
308 } else { 353 } else {
309 return rtc::Optional<float>( 354 return rtc::Optional<float>(
310 static_cast<float>(num_recoverable_losses_) / num_known_pairs_); 355 static_cast<float>(num_recoverable_losses_) / num_acked_pairs_);
311 } 356 }
312 } 357 }
313 358
314 } // namespace webrtc 359 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698