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 // Accumulates frames for the next packet until more frames no longer fit or | 5 // Accumulates frames for the next packet until more frames no longer fit or |
6 // it's time to create a packet from them. Also provides packet creation of | 6 // it's time to create a packet from them. Also provides packet creation of |
7 // FEC packets based on previously created packets. | 7 // FEC packets based on previously created packets. |
8 | 8 |
9 #ifndef NET_QUIC_QUIC_PACKET_CREATOR_H_ | 9 #ifndef NET_QUIC_QUIC_PACKET_CREATOR_H_ |
10 #define NET_QUIC_QUIC_PACKET_CREATOR_H_ | 10 #define NET_QUIC_QUIC_PACKET_CREATOR_H_ |
(...skipping 15 matching lines...) Expand all Loading... |
26 class QuicRandom; | 26 class QuicRandom; |
27 | 27 |
28 class NET_EXPORT_PRIVATE QuicPacketCreator : public QuicFecBuilderInterface { | 28 class NET_EXPORT_PRIVATE QuicPacketCreator : public QuicFecBuilderInterface { |
29 public: | 29 public: |
30 // Options for controlling how packets are created. | 30 // Options for controlling how packets are created. |
31 struct Options { | 31 struct Options { |
32 Options() | 32 Options() |
33 : max_packet_length(kMaxPacketSize), | 33 : max_packet_length(kMaxPacketSize), |
34 random_reorder(false), | 34 random_reorder(false), |
35 max_packets_per_fec_group(0), | 35 max_packets_per_fec_group(0), |
36 send_guid_length(PACKET_8BYTE_GUID) { | 36 send_guid_length(PACKET_8BYTE_GUID), |
| 37 send_sequence_number_length(PACKET_6BYTE_SEQUENCE_NUMBER) { |
37 } | 38 } |
38 | 39 |
39 size_t max_packet_length; | 40 size_t max_packet_length; |
40 bool random_reorder; // Inefficient: rewrite if used at scale. | 41 bool random_reorder; // Inefficient: rewrite if used at scale. |
41 // 0 indicates fec is disabled. | 42 // 0 indicates fec is disabled. |
42 size_t max_packets_per_fec_group; | 43 size_t max_packets_per_fec_group; |
43 // Length of guid to send over the wire. | 44 // Length of guid to send over the wire. |
44 QuicGuidLength send_guid_length; | 45 QuicGuidLength send_guid_length; |
| 46 QuicSequenceNumberLength send_sequence_number_length; |
45 }; | 47 }; |
46 | 48 |
47 // QuicRandom* required for packet entropy. | 49 // QuicRandom* required for packet entropy. |
48 QuicPacketCreator(QuicGuid guid, | 50 QuicPacketCreator(QuicGuid guid, |
49 QuicFramer* framer, | 51 QuicFramer* framer, |
50 QuicRandom* random_generator, | 52 QuicRandom* random_generator, |
51 bool is_server); | 53 bool is_server); |
52 | 54 |
53 virtual ~QuicPacketCreator(); | 55 virtual ~QuicPacketCreator(); |
54 | 56 |
55 // QuicFecBuilderInterface | 57 // QuicFecBuilderInterface |
56 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header, | 58 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header, |
57 base::StringPiece payload) OVERRIDE; | 59 base::StringPiece payload) OVERRIDE; |
58 | 60 |
59 // Checks if it's time to send an FEC packet. |force_close| forces this to | 61 // Checks if it's time to send an FEC packet. |force_close| forces this to |
60 // return true if an fec group is open. | 62 // return true if an fec group is open. |
61 bool ShouldSendFec(bool force_close) const; | 63 bool ShouldSendFec(bool force_close) const; |
62 | 64 |
63 // Starts a new FEC group with the next serialized packet, if FEC is enabled | 65 // Starts a new FEC group with the next serialized packet, if FEC is enabled |
64 // and there is not already an FEC group open. | 66 // and there is not already an FEC group open. |
65 void MaybeStartFEC(); | 67 void MaybeStartFEC(); |
66 | 68 |
67 // Makes the framer not serialize the protocol version in sent packets. | 69 // Makes the framer not serialize the protocol version in sent packets. |
68 void StopSendingVersion(); | 70 void StopSendingVersion(); |
69 | 71 |
70 // The overhead the framing will add for a packet with num_frames frames. | 72 // The overhead the framing will add for a packet with num_frames frames. |
71 static size_t StreamFramePacketOverhead(int num_frames, | 73 static size_t StreamFramePacketOverhead( |
72 QuicGuidLength guid_length, | 74 int num_frames, |
73 bool include_version, | 75 QuicGuidLength guid_length, |
74 InFecGroup is_in_fec_group); | 76 bool include_version, |
| 77 QuicSequenceNumberLength sequence_number_length, |
| 78 InFecGroup is_in_fec_group); |
75 | 79 |
76 bool HasRoomForStreamFrame() const; | 80 bool HasRoomForStreamFrame() const; |
77 | 81 |
78 // Converts a raw payload to a frame which fits into the currently open | 82 // Converts a raw payload to a frame which fits into the currently open |
79 // packet if there is one. Returns the number of bytes consumed from data. | 83 // packet if there is one. Returns the number of bytes consumed from data. |
80 // If data is empty and fin is true, the expected behavior is to consume the | 84 // If data is empty and fin is true, the expected behavior is to consume the |
81 // fin but return 0. | 85 // fin but return 0. |
82 size_t CreateStreamFrame(QuicStreamId id, | 86 size_t CreateStreamFrame(QuicStreamId id, |
83 base::StringPiece data, | 87 base::StringPiece data, |
84 QuicStreamOffset offset, | 88 QuicStreamOffset offset, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 size_t packet_size_; | 173 size_t packet_size_; |
170 QuicFrames queued_frames_; | 174 QuicFrames queued_frames_; |
171 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_; | 175 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_; |
172 | 176 |
173 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); | 177 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); |
174 }; | 178 }; |
175 | 179 |
176 } // namespace net | 180 } // namespace net |
177 | 181 |
178 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_ | 182 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_ |
OLD | NEW |