| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_fec_group.h" | 5 #include "net/quic/quic_fec_group.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 decrypted_payload[i] = payload_parity_[i]; | 111 decrypted_payload[i] = payload_parity_[i]; |
| 112 } | 112 } |
| 113 | 113 |
| 114 header->packet_number = missing; | 114 header->packet_number = missing; |
| 115 header->entropy_flag = false; // Unknown entropy. | 115 header->entropy_flag = false; // Unknown entropy. |
| 116 | 116 |
| 117 received_packets_.insert(missing); | 117 received_packets_.insert(missing); |
| 118 return payload_parity_len_; | 118 return payload_parity_len_; |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool QuicFecGroup::ProtectsPacketsBefore(QuicPacketNumber num) const { | 121 bool QuicFecGroup::IsWaitingForPacketBefore(QuicPacketNumber num) const { |
| 122 if (has_received_fec_packet()) { | 122 // Entire range is larger than the threshold. |
| 123 return max_protected_packet_ < num; | 123 if (min_protected_packet_ >= num) { |
| 124 return false; |
| 124 } | 125 } |
| 125 // Since we might not yet have received the FEC packet, we must check | 126 |
| 126 // the packets we have received. | 127 // Entire range is smaller than the threshold. |
| 127 return *received_packets_.begin() < num; | 128 if (received_packets_.size() > 0 ? *received_packets_.rbegin() + 1 < num |
| 129 : min_protected_packet_ < num) { |
| 130 return true; |
| 131 } |
| 132 |
| 133 // Range spans the threshold so look for a missing packet below the threshold. |
| 134 QuicPacketNumber target = min_protected_packet_; |
| 135 for (QuicPacketNumber packet : received_packets_) { |
| 136 if (target++ != packet) { |
| 137 return true; |
| 138 } |
| 139 if (target >= num) { |
| 140 return false; |
| 141 } |
| 142 } |
| 143 |
| 144 // No missing packets below the threshold. |
| 145 return false; |
| 128 } | 146 } |
| 129 | 147 |
| 130 bool QuicFecGroup::UpdateParity(StringPiece payload) { | 148 bool QuicFecGroup::UpdateParity(StringPiece payload) { |
| 131 DCHECK_GE(kMaxPacketSize, payload.size()); | 149 DCHECK_GE(kMaxPacketSize, payload.size()); |
| 132 if (payload.size() > kMaxPacketSize) { | 150 if (payload.size() > kMaxPacketSize) { |
| 133 DLOG(ERROR) << "Illegal payload size: " << payload.size(); | 151 DLOG(ERROR) << "Illegal payload size: " << payload.size(); |
| 134 return false; | 152 return false; |
| 135 } | 153 } |
| 136 if (payload_parity_len_ < payload.size()) { | 154 if (payload_parity_len_ < payload.size()) { |
| 137 payload_parity_len_ = payload.size(); | 155 payload_parity_len_ = payload.size(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 188 |
| 171 QuicPacketCount QuicFecGroup::NumReceivedPackets() const { | 189 QuicPacketCount QuicFecGroup::NumReceivedPackets() const { |
| 172 return received_packets_.size(); | 190 return received_packets_.size(); |
| 173 } | 191 } |
| 174 | 192 |
| 175 EncryptionLevel QuicFecGroup::EffectiveEncryptionLevel() const { | 193 EncryptionLevel QuicFecGroup::EffectiveEncryptionLevel() const { |
| 176 return effective_encryption_level_; | 194 return effective_encryption_level_; |
| 177 } | 195 } |
| 178 | 196 |
| 179 } // namespace net | 197 } // namespace net |
| OLD | NEW |