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