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
3 // found in the LICENSE file.
5 // Tracks information about an FEC group, including the packets
6 // that have been seen, and the running parity. Provided the ability
7 // to revive a dropped packet.
9 #ifndef NET_QUIC_QUIC_FEC_GROUP_H_
10 #define NET_QUIC_QUIC_FEC_GROUP_H_
14 #include "base/strings/string_piece.h"
15 #include "net/quic/quic_protocol.h"
19 class NET_EXPORT_PRIVATE QuicFecGroup
{
24 // Updates the FEC group based on the delivery of a data packet decrypted at
25 // |encryption_level|. Returns false if this packet has already been seen,
27 bool Update(EncryptionLevel encryption_level
,
28 const QuicPacketHeader
& header
,
29 base::StringPiece decrypted_payload
);
31 // Updates the FEC group based on the delivery of an FEC packet decrypted at
32 // |encryption_level|. Returns false if this packet has already been seen or
33 // if it does not claim to protect all the packets previously seen in this
35 bool UpdateFec(EncryptionLevel encryption_level
,
36 QuicPacketNumber fec_packet_packet_number
,
37 const QuicFecData
& fec
);
39 // Returns true if a packet can be revived from this FEC group.
40 bool CanRevive() const;
42 // Returns true if all packets (FEC and data) from this FEC group have been
44 bool IsFinished() const;
46 // Revives the missing packet from this FEC group. This may return a packet
47 // that is null padded to a greater length than the original packet, but
48 // the framer will handle it correctly. Returns the length of the data
49 // written to |decrypted_payload|, or 0 if the packet could not be revived.
50 size_t Revive(QuicPacketHeader
* header
,
51 char* decrypted_payload
,
52 size_t decrypted_payload_len
);
54 // Returns true of this FEC group protects any packets with sequence
55 // numbers less than |num|.
56 bool ProtectsPacketsBefore(QuicPacketNumber num
) const;
58 const base::StringPiece
payload_parity() const {
59 return base::StringPiece(payload_parity_
, payload_parity_len_
);
62 QuicPacketNumber
min_protected_packet() const {
63 return min_protected_packet_
;
66 QuicPacketCount
NumReceivedPackets() const {
67 return received_packets_
.size();
70 // Returns the effective encryption level of the FEC group.
71 EncryptionLevel
effective_encryption_level() const {
72 return effective_encryption_level_
;
75 // An optimized version of running |output| ^= |input|, where ^ is
76 // byte-by-byte XOR and both |output| and |input| are of size |size_in_bytes|.
77 static void XorBuffers(const char* input
, size_t size_in_bytes
, char* output
);
80 bool UpdateParity(base::StringPiece payload
);
81 // Returns the number of missing packets, or QuicPacketCount max
82 // if the number of missing packets is not known.
83 QuicPacketCount
NumMissingPackets() const;
85 // Set of packets that we have recevied.
86 PacketNumberSet received_packets_
;
87 // packet number of the first protected packet in this group (the one
88 // with the lowest packet number). Will only be set once the FEC
89 // packet has been seen.
90 QuicPacketNumber min_protected_packet_
;
91 // packet number of the last protected packet in this group (the one
92 // with the highest packet number). Will only be set once the FEC
93 // packet has been seen.
94 QuicPacketNumber max_protected_packet_
;
95 // The cumulative parity calculation of all received packets.
96 char payload_parity_
[kMaxPacketSize
];
97 size_t payload_parity_len_
;
98 // The effective encryption level, which is the lowest encryption level of
99 // the data and FEC in the group.
100 EncryptionLevel effective_encryption_level_
;
102 DISALLOW_COPY_AND_ASSIGN(QuicFecGroup
);
107 #endif // NET_QUIC_QUIC_FEC_GROUP_H_