Chromium Code Reviews

Unified Diff: webrtc/modules/rtp_rtcp/source/forward_error_correction.h

Issue 2099243003: Use std::unique_ptr in ForwardErrorCorrection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@flexfec-pt1a_mini-fixes-in-ULPFEC
Patch Set: Response to PS4 feedback. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: webrtc/modules/rtp_rtcp/source/forward_error_correction.h
diff --git a/webrtc/modules/rtp_rtcp/source/forward_error_correction.h b/webrtc/modules/rtp_rtcp/source/forward_error_correction.h
index fb35374ac693d11cec0412ad36401b555c12b0f0..84c8912dee22cb94942c7fdf1e2410c51deea8ec 100644
--- a/webrtc/modules/rtp_rtcp/source/forward_error_correction.h
+++ b/webrtc/modules/rtp_rtcp/source/forward_error_correction.h
@@ -24,9 +24,6 @@
namespace webrtc {
-// Forward declaration.
-class FecPacket;
-
// Performs codec-independent forward error correction (FEC), based on RFC 5109.
// Option exists to enable unequal protection (UEP) across packets.
// This is not to be confused with protection within packets
@@ -62,9 +59,13 @@ class ForwardErrorCorrection {
// TODO(holmer): Refactor into a proper class.
class SortablePacket {
public:
- // True if first is <= than second.
- static bool LessThan(const SortablePacket* first,
- const SortablePacket* second);
+ // Functor which returns true if the sequence number of |first|
+ // is < the sequence number of |second|.
+ class LessThan {
+ public:
+ template <typename S, typename T>
+ bool operator() (const S& first, const T& second);
+ };
uint16_t seq_num;
};
@@ -116,9 +117,9 @@ class ForwardErrorCorrection {
rtc::scoped_refptr<Packet> pkt; // Pointer to the packet storage.
};
- typedef std::list<Packet*> PacketList;
- typedef std::list<ReceivedPacket*> ReceivedPacketList;
- typedef std::list<RecoveredPacket*> RecoveredPacketList;
+ using PacketList = std::list<std::unique_ptr<Packet>>;
+ using ReceivedPacketList = std::list<std::unique_ptr<ReceivedPacket>>;
+ using RecoveredPacketList = std::list<std::unique_ptr<RecoveredPacket>>;
ForwardErrorCorrection();
virtual ~ForwardErrorCorrection();
@@ -162,7 +163,7 @@ class ForwardErrorCorrection {
int GenerateFec(const PacketList& media_packet_list,
uint8_t protection_factor, int num_important_packets,
bool use_unequal_protection, FecMaskType fec_mask_type,
- PacketList* fec_packet_list);
+ std::list<Packet*>* fec_packet_list);
/**
* Decodes a list of media and FEC packets. It will parse the input received
@@ -209,7 +210,27 @@ class ForwardErrorCorrection {
void ResetState(RecoveredPacketList* recovered_packet_list);
private:
- typedef std::list<FecPacket*> FecPacketList;
+ // Used to link media packets to their protecting FEC packets.
+ //
+ // TODO(holmer): Refactor into a proper class.
+ class ProtectedPacket : public ForwardErrorCorrection::SortablePacket {
+ public:
+ rtc::scoped_refptr<ForwardErrorCorrection::Packet> pkt;
+ };
+
+ using ProtectedPacketList = std::list<std::unique_ptr<ProtectedPacket>>;
+
+ // Used for internal storage of received FEC packets in a list.
+ //
+ // TODO(holmer): Refactor into a proper class.
+ class ReceivedFecPacket : public ForwardErrorCorrection::SortablePacket {
+ public:
+ ProtectedPacketList protected_pkt_list;
+ uint32_t ssrc; // SSRC of the current frame.
+ rtc::scoped_refptr<ForwardErrorCorrection::Packet> pkt;
+ };
+
+ using ReceivedFecPacketList = std::list<std::unique_ptr<ReceivedFecPacket>>;
// Analyzes |media_packets| for holes in the sequence and inserts zero columns
// into the |packet_mask| where those holes are found. Zero columns means that
@@ -271,7 +292,8 @@ class ForwardErrorCorrection {
// Assigns pointers to already recovered packets covered by this FEC packet.
static void AssignRecoveredPackets(
- FecPacket* fec_packet, const RecoveredPacketList* recovered_packets);
+ ReceivedFecPacket* fec_packet,
+ const RecoveredPacketList* recovered_packets);
// Insert into recovered list in correct position.
void InsertRecoveredPacket(RecoveredPacket* rec_packet_to_insert,
@@ -281,7 +303,7 @@ class ForwardErrorCorrection {
void AttemptRecover(RecoveredPacketList* recovered_packet_list);
// Initializes the packet recovery using the FEC packet.
- static bool StartPacketRecovery(const FecPacket* fec_packet,
+ static bool StartPacketRecovery(const ReceivedFecPacket* fec_packet,
RecoveredPacket* recovered);
// Performs XOR between |src_packet| and |dst_packet| and stores the result
@@ -292,21 +314,21 @@ class ForwardErrorCorrection {
static bool FinishPacketRecovery(RecoveredPacket* recovered);
// Recover a missing packet.
- bool RecoverPacket(const FecPacket* fec_packet,
+ bool RecoverPacket(const ReceivedFecPacket* fec_packet,
RecoveredPacket* rec_packet_to_insert);
// Get the number of missing media packets which are covered by this
// FEC packet. An FEC packet can recover at most one packet, and if zero
// packets are missing the FEC packet can be discarded.
// This function returns 2 when two or more packets are missing.
- static int NumCoveredPacketsMissing(const FecPacket* fec_packet);
+ static int NumCoveredPacketsMissing(const ReceivedFecPacket* fec_packet);
- static void DiscardFecPacket(FecPacket* fec_packet);
- static void DiscardOldPackets(RecoveredPacketList* recovered_packet_list);
+ static void DiscardOldRecoveredPackets(
+ RecoveredPacketList* recovered_packet_list);
static uint16_t ParseSequenceNumber(uint8_t* packet);
std::vector<Packet> generated_fec_packets_;
- FecPacketList fec_packet_list_;
+ ReceivedFecPacketList received_fec_packets_;
// Arrays used to avoid dynamically allocating memory when generating
// the packet masks in the ULPFEC headers.

Powered by Google App Engine