| 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_packet_generator.h" | 5 #include "net/quic/quic_packet_generator.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "net/quic/quic_fec_group.h" | 9 #include "net/quic/quic_fec_group.h" |
| 10 #include "net/quic/quic_flags.h" | 10 #include "net/quic/quic_flags.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // generator to check if the resulting expansion still allows the incoming | 281 // generator to check if the resulting expansion still allows the incoming |
| 282 // frame to be added to the packet. | 282 // frame to be added to the packet. |
| 283 SendQueuedFrames(/*flush=*/true, /*is_fec_timeout=*/false); | 283 SendQueuedFrames(/*flush=*/true, /*is_fec_timeout=*/false); |
| 284 } | 284 } |
| 285 packet_creator_.StartFecProtectingPackets(); | 285 packet_creator_.StartFecProtectingPackets(); |
| 286 DCHECK(packet_creator_.IsFecProtected()); | 286 DCHECK(packet_creator_.IsFecProtected()); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void QuicPacketGenerator::MaybeSendFecPacketAndCloseGroup(bool force, | 289 void QuicPacketGenerator::MaybeSendFecPacketAndCloseGroup(bool force, |
| 290 bool is_fec_timeout) { | 290 bool is_fec_timeout) { |
| 291 if (!ShouldSendFecPacket(force)) { | 291 if (ShouldSendFecPacket(force)) { |
| 292 return; | 292 // If we want to send FEC packet only when FEC alaram goes off and if it is |
| 293 // not a FEC timeout then close the group and dont send FEC packet. |
| 294 if (fec_send_policy_ == FEC_ALARM_TRIGGER && !is_fec_timeout) { |
| 295 ResetFecGroup(); |
| 296 } else { |
| 297 // TODO(jri): SerializeFec can return a NULL packet, and this should cause |
| 298 // an early return, with a call to delegate_->OnPacketGenerationError. |
| 299 char buffer[kMaxPacketSize]; |
| 300 SerializedPacket serialized_fec = |
| 301 packet_creator_.SerializeFec(buffer, kMaxPacketSize); |
| 302 DCHECK(serialized_fec.packet); |
| 303 delegate_->OnSerializedPacket(serialized_fec); |
| 304 } |
| 293 } | 305 } |
| 294 | 306 |
| 295 // If we want to send FEC packet only when FEC alaram goes off and if it is | |
| 296 // not a FEC timeout then close the group and dont send FEC packet. | |
| 297 if (fec_send_policy_ == FEC_ALARM_TRIGGER && !is_fec_timeout) { | |
| 298 ResetFecGroup(); | |
| 299 } else { | |
| 300 // TODO(jri): SerializeFec can return a NULL packet, and this should | |
| 301 // cause an early return, with a call to delegate_->OnPacketGenerationError. | |
| 302 char buffer[kMaxPacketSize]; | |
| 303 SerializedPacket serialized_fec = | |
| 304 packet_creator_.SerializeFec(buffer, kMaxPacketSize); | |
| 305 DCHECK(serialized_fec.packet); | |
| 306 delegate_->OnSerializedPacket(serialized_fec); | |
| 307 } | |
| 308 // Turn FEC protection off if creator's protection is on and the creator | 307 // Turn FEC protection off if creator's protection is on and the creator |
| 309 // does not have an open FEC group. | 308 // does not have an open FEC group. |
| 310 // Note: We only wait until the frames queued in the creator are flushed; | 309 // Note: We only wait until the frames queued in the creator are flushed; |
| 311 // pending frames in the generator will not keep us from turning FEC off. | 310 // pending frames in the generator will not keep us from turning FEC off. |
| 312 if (!should_fec_protect_ && !packet_creator_.IsFecGroupOpen()) { | 311 if (!should_fec_protect_ && packet_creator_.IsFecProtected() && |
| 312 !packet_creator_.IsFecGroupOpen()) { |
| 313 packet_creator_.StopFecProtectingPackets(); | 313 packet_creator_.StopFecProtectingPackets(); |
| 314 DCHECK(!packet_creator_.IsFecProtected()); | 314 DCHECK(!packet_creator_.IsFecProtected()); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 bool QuicPacketGenerator::ShouldSendFecPacket(bool force) { | 318 bool QuicPacketGenerator::ShouldSendFecPacket(bool force) { |
| 319 return packet_creator_.IsFecProtected() && | 319 return packet_creator_.IsFecProtected() && |
| 320 !packet_creator_.HasPendingFrames() && | 320 !packet_creator_.HasPendingFrames() && |
| 321 packet_creator_.ShouldSendFec(force); | 321 packet_creator_.ShouldSendFec(force); |
| 322 } | 322 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 void QuicPacketGenerator::set_encryption_level(EncryptionLevel level) { | 526 void QuicPacketGenerator::set_encryption_level(EncryptionLevel level) { |
| 527 packet_creator_.set_encryption_level(level); | 527 packet_creator_.set_encryption_level(level); |
| 528 } | 528 } |
| 529 | 529 |
| 530 void QuicPacketGenerator::SetEncrypter(EncryptionLevel level, | 530 void QuicPacketGenerator::SetEncrypter(EncryptionLevel level, |
| 531 QuicEncrypter* encrypter) { | 531 QuicEncrypter* encrypter) { |
| 532 packet_creator_.SetEncrypter(level, encrypter); | 532 packet_creator_.SetEncrypter(level, encrypter); |
| 533 } | 533 } |
| 534 | 534 |
| 535 } // namespace net | 535 } // namespace net |
| OLD | NEW |