OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_H_ | 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_H_ |
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_H_ | 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_H_ |
13 | 13 |
14 #include <stdint.h> | 14 #include <stdint.h> |
15 | 15 |
16 #include <list> | 16 #include <list> |
17 #include <memory> | 17 #include <memory> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
| 20 #include "webrtc/base/basictypes.h" |
| 21 #include "webrtc/base/constructormagic.h" |
20 #include "webrtc/base/refcount.h" | 22 #include "webrtc/base/refcount.h" |
21 #include "webrtc/base/scoped_ref_ptr.h" | 23 #include "webrtc/base/scoped_ref_ptr.h" |
22 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
23 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h" | 25 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h" |
24 #include "webrtc/typedefs.h" | |
25 | 26 |
26 namespace webrtc { | 27 namespace webrtc { |
27 | 28 |
| 29 class FecHeaderReader; |
| 30 class FecHeaderWriter; |
| 31 |
28 // Performs codec-independent forward error correction (FEC), based on RFC 5109. | 32 // Performs codec-independent forward error correction (FEC), based on RFC 5109. |
29 // Option exists to enable unequal protection (UEP) across packets. | 33 // Option exists to enable unequal protection (UEP) across packets. |
30 // This is not to be confused with protection within packets | 34 // This is not to be confused with protection within packets |
31 // (referred to as uneven level protection (ULP) in RFC 5109). | 35 // (referred to as uneven level protection (ULP) in RFC 5109). |
32 class ForwardErrorCorrection { | 36 class ForwardErrorCorrection { |
33 public: | 37 public: |
34 // Maximum number of media packets we can protect | |
35 static constexpr size_t kMaxMediaPackets = 48u; | |
36 | |
37 // TODO(holmer): As a next step all these struct-like packet classes should be | 38 // TODO(holmer): As a next step all these struct-like packet classes should be |
38 // refactored into proper classes, and their members should be made private. | 39 // refactored into proper classes, and their members should be made private. |
39 // This will require parts of the functionality in forward_error_correction.cc | 40 // This will require parts of the functionality in forward_error_correction.cc |
40 // and receiver_fec.cc to be refactored into the packet classes. | 41 // and receiver_fec.cc to be refactored into the packet classes. |
41 class Packet { | 42 class Packet { |
42 public: | 43 public: |
43 Packet() : length(0), data(), ref_count_(0) {} | 44 Packet(); |
44 virtual ~Packet() {} | 45 virtual ~Packet(); |
45 | 46 |
46 // Add a reference. | 47 // Add a reference. |
47 virtual int32_t AddRef(); | 48 virtual int32_t AddRef(); |
48 | 49 |
49 // Release a reference. Will delete the object if the reference count | 50 // Release a reference. Will delete the object if the reference count |
50 // reaches zero. | 51 // reaches zero. |
51 virtual int32_t Release(); | 52 virtual int32_t Release(); |
52 | 53 |
53 size_t length; // Length of packet in bytes. | 54 size_t length; // Length of packet in bytes. |
54 uint8_t data[IP_PACKET_SIZE]; // Packet data. | 55 uint8_t data[IP_PACKET_SIZE]; // Packet data. |
(...skipping 27 matching lines...) Expand all Loading... |
82 ReceivedPacket(); | 83 ReceivedPacket(); |
83 ~ReceivedPacket(); | 84 ~ReceivedPacket(); |
84 | 85 |
85 uint32_t ssrc; // SSRC of the current frame. Must be set for FEC | 86 uint32_t ssrc; // SSRC of the current frame. Must be set for FEC |
86 // packets, but not required for media packets. | 87 // packets, but not required for media packets. |
87 bool is_fec; // Set to true if this is an FEC packet and false | 88 bool is_fec; // Set to true if this is an FEC packet and false |
88 // otherwise. | 89 // otherwise. |
89 rtc::scoped_refptr<Packet> pkt; // Pointer to the packet storage. | 90 rtc::scoped_refptr<Packet> pkt; // Pointer to the packet storage. |
90 }; | 91 }; |
91 | 92 |
92 // The recovered list parameter of #DecodeFec() references structs of | 93 // The recovered list parameter of DecodeFec() references structs of |
93 // this type. | 94 // this type. |
94 // TODO(holmer): Refactor into a proper class. | 95 // TODO(holmer): Refactor into a proper class. |
95 class RecoveredPacket : public SortablePacket { | 96 class RecoveredPacket : public SortablePacket { |
96 public: | 97 public: |
97 RecoveredPacket(); | 98 RecoveredPacket(); |
98 ~RecoveredPacket(); | 99 ~RecoveredPacket(); |
99 | 100 |
100 bool was_recovered; // Will be true if this packet was recovered by | 101 bool was_recovered; // Will be true if this packet was recovered by |
101 // the FEC. Otherwise it was a media packet passed in | 102 // the FEC. Otherwise it was a media packet passed in |
102 // through the received packet list. | 103 // through the received packet list. |
103 bool returned; // True when the packet already has been returned to the | 104 bool returned; // True when the packet already has been returned to the |
104 // caller through the callback. | 105 // caller through the callback. |
105 uint8_t length_recovery[2]; // Two bytes used for recovering the packet | |
106 // length with XOR operations. | |
107 rtc::scoped_refptr<Packet> pkt; // Pointer to the packet storage. | 106 rtc::scoped_refptr<Packet> pkt; // Pointer to the packet storage. |
108 }; | 107 }; |
109 | 108 |
| 109 // Used to link media packets to their protecting FEC packets. |
| 110 // |
| 111 // TODO(holmer): Refactor into a proper class. |
| 112 class ProtectedPacket : public ForwardErrorCorrection::SortablePacket { |
| 113 public: |
| 114 ProtectedPacket(); |
| 115 ~ProtectedPacket(); |
| 116 |
| 117 rtc::scoped_refptr<ForwardErrorCorrection::Packet> pkt; |
| 118 }; |
| 119 |
| 120 using ProtectedPacketList = std::list<std::unique_ptr<ProtectedPacket>>; |
| 121 |
| 122 // Used for internal storage of received FEC packets in a list. |
| 123 // |
| 124 // TODO(holmer): Refactor into a proper class. |
| 125 class ReceivedFecPacket : public ForwardErrorCorrection::SortablePacket { |
| 126 public: |
| 127 ReceivedFecPacket(); |
| 128 ~ReceivedFecPacket(); |
| 129 |
| 130 // List of media packets that this FEC packet protects. |
| 131 ProtectedPacketList protected_packets; |
| 132 // RTP header fields. |
| 133 uint32_t ssrc; |
| 134 // FEC header fields. |
| 135 size_t fec_header_size; |
| 136 uint32_t protected_ssrc; |
| 137 uint16_t seq_num_base; |
| 138 size_t packet_mask_offset; // Relative start of FEC header. |
| 139 size_t packet_mask_size; |
| 140 size_t protection_length; |
| 141 // Raw data. |
| 142 rtc::scoped_refptr<ForwardErrorCorrection::Packet> pkt; |
| 143 }; |
| 144 |
110 using PacketList = std::list<std::unique_ptr<Packet>>; | 145 using PacketList = std::list<std::unique_ptr<Packet>>; |
111 using ReceivedPacketList = std::list<std::unique_ptr<ReceivedPacket>>; | 146 using ReceivedPacketList = std::list<std::unique_ptr<ReceivedPacket>>; |
112 using RecoveredPacketList = std::list<std::unique_ptr<RecoveredPacket>>; | 147 using RecoveredPacketList = std::list<std::unique_ptr<RecoveredPacket>>; |
| 148 using ReceivedFecPacketList = std::list<std::unique_ptr<ReceivedFecPacket>>; |
113 | 149 |
114 ForwardErrorCorrection(); | 150 ~ForwardErrorCorrection(); |
115 virtual ~ForwardErrorCorrection(); | |
116 | 151 |
117 // | 152 // Creates a ForwardErrorCorrection tailored for a specific FEC scheme. |
| 153 static std::unique_ptr<ForwardErrorCorrection> CreateUlpfec(); |
| 154 |
118 // Generates a list of FEC packets from supplied media packets. | 155 // Generates a list of FEC packets from supplied media packets. |
119 // | 156 // |
120 // Input: media_packets List of media packets to protect, of type | 157 // Input: media_packets List of media packets to protect, of type |
121 // Packet. All packets must belong to the | 158 // Packet. All packets must belong to the |
122 // same frame and the list must not be empty. | 159 // same frame and the list must not be empty. |
123 // Input: protection_factor FEC protection overhead in the [0, 255] | 160 // Input: protection_factor FEC protection overhead in the [0, 255] |
124 // domain. To obtain 100% overhead, or an | 161 // domain. To obtain 100% overhead, or an |
125 // equal number of FEC packets as | 162 // equal number of FEC packets as |
126 // media packets, use 255. | 163 // media packets, use 255. |
127 // Input: num_important_packets The number of "important" packets in the | 164 // Input: num_important_packets The number of "important" packets in the |
(...skipping 23 matching lines...) Expand all Loading... |
151 // | 188 // |
152 // Returns 0 on success, -1 on failure. | 189 // Returns 0 on success, -1 on failure. |
153 // | 190 // |
154 int EncodeFec(const PacketList& media_packets, | 191 int EncodeFec(const PacketList& media_packets, |
155 uint8_t protection_factor, | 192 uint8_t protection_factor, |
156 int num_important_packets, | 193 int num_important_packets, |
157 bool use_unequal_protection, | 194 bool use_unequal_protection, |
158 FecMaskType fec_mask_type, | 195 FecMaskType fec_mask_type, |
159 std::list<Packet*>* fec_packets); | 196 std::list<Packet*>* fec_packets); |
160 | 197 |
161 // | |
162 // Decodes a list of received media and FEC packets. It will parse the | 198 // Decodes a list of received media and FEC packets. It will parse the |
163 // |received_packets|, storing FEC packets internally, and move | 199 // |received_packets|, storing FEC packets internally, and move |
164 // media packets to |recovered_packets|. The recovered list will be | 200 // media packets to |recovered_packets|. The recovered list will be |
165 // sorted by ascending sequence number and have duplicates removed. | 201 // sorted by ascending sequence number and have duplicates removed. |
166 // The function should be called as new packets arrive, and | 202 // The function should be called as new packets arrive, and |
167 // |recovered_packets| will be progressively assembled with each call. | 203 // |recovered_packets| will be progressively assembled with each call. |
168 // When the function returns, |received_packets| will be empty. | 204 // When the function returns, |received_packets| will be empty. |
169 // | 205 // |
170 // The caller will allocate packets submitted through |received_packets|. | 206 // The caller will allocate packets submitted through |received_packets|. |
171 // The function will handle allocation of recovered packets. | 207 // The function will handle allocation of recovered packets. |
(...skipping 19 matching lines...) Expand all Loading... |
191 static int NumFecPackets(int num_media_packets, int protection_factor); | 227 static int NumFecPackets(int num_media_packets, int protection_factor); |
192 | 228 |
193 // Gets the maximum size of the FEC headers in bytes, which must be | 229 // Gets the maximum size of the FEC headers in bytes, which must be |
194 // accounted for as packet overhead. | 230 // accounted for as packet overhead. |
195 size_t MaxPacketOverhead() const; | 231 size_t MaxPacketOverhead() const; |
196 | 232 |
197 // Reset internal states from last frame and clear |recovered_packets|. | 233 // Reset internal states from last frame and clear |recovered_packets|. |
198 // Frees all memory allocated by this class. | 234 // Frees all memory allocated by this class. |
199 void ResetState(RecoveredPacketList* recovered_packets); | 235 void ResetState(RecoveredPacketList* recovered_packets); |
200 | 236 |
| 237 // TODO(brandtr): Remove these functions when the Packet classes |
| 238 // have been refactored. |
| 239 static uint16_t ParseSequenceNumber(uint8_t* packet); |
| 240 static uint32_t ParseSsrc(uint8_t* packet); |
| 241 |
| 242 protected: |
| 243 ForwardErrorCorrection(std::unique_ptr<FecHeaderReader> fec_header_reader, |
| 244 std::unique_ptr<FecHeaderWriter> fec_header_writer); |
| 245 |
201 private: | 246 private: |
202 // Used to link media packets to their protecting FEC packets. | |
203 // | |
204 // TODO(holmer): Refactor into a proper class. | |
205 class ProtectedPacket : public ForwardErrorCorrection::SortablePacket { | |
206 public: | |
207 rtc::scoped_refptr<ForwardErrorCorrection::Packet> pkt; | |
208 }; | |
209 | |
210 using ProtectedPacketList = std::list<std::unique_ptr<ProtectedPacket>>; | |
211 | |
212 // Used for internal storage of received FEC packets in a list. | |
213 // | |
214 // TODO(holmer): Refactor into a proper class. | |
215 class ReceivedFecPacket : public ForwardErrorCorrection::SortablePacket { | |
216 public: | |
217 ProtectedPacketList protected_packets; | |
218 uint32_t ssrc; // SSRC of the current frame. | |
219 rtc::scoped_refptr<ForwardErrorCorrection::Packet> pkt; | |
220 }; | |
221 | |
222 using ReceivedFecPacketList = std::list<std::unique_ptr<ReceivedFecPacket>>; | |
223 | |
224 // Analyzes |media_packets| for holes in the sequence and inserts zero columns | 247 // Analyzes |media_packets| for holes in the sequence and inserts zero columns |
225 // into the |packet_mask| where those holes are found. Zero columns means that | 248 // into the |packet_mask| where those holes are found. Zero columns means that |
226 // those packets will have no protection. | 249 // those packets will have no protection. |
227 // Returns the number of bits used for one row of the new packet mask. | 250 // Returns the number of bits used for one row of the new packet mask. |
228 // Requires that |packet_mask| has at least 6 * |num_fec_packets| bytes | 251 // Requires that |packet_mask| has at least 6 * |num_fec_packets| bytes |
229 // allocated. | 252 // allocated. |
230 int InsertZerosInBitMasks(const PacketList& media_packets, | 253 int InsertZerosInPacketMasks(const PacketList& media_packets, |
231 uint8_t* packet_mask, int num_mask_bytes, | 254 size_t num_fec_packets); |
232 int num_fec_packets); | |
233 | 255 |
| 256 // Writes FEC payloads and some recovery fields in the FEC headers. |
| 257 void GenerateFecPayloads(const PacketList& media_packets, |
| 258 size_t num_fec_packets); |
234 | 259 |
235 void GenerateFecUlpHeaders(const PacketList& media_packets, | 260 // Writes the FEC header fields that are not written by GenerateFecPayloads. |
236 uint8_t* packet_mask, int num_fec_packets, | 261 // This includes writing the packet masks. |
237 bool l_bit); | 262 void FinalizeFecHeaders(size_t num_fec_packets, uint16_t seq_num_base); |
238 | |
239 void GenerateFecBitStrings(const PacketList& media_packets, | |
240 uint8_t* packet_mask, int num_fec_packets, | |
241 bool l_bit); | |
242 | 263 |
243 // Inserts the |received_packets| into the internal received FEC packet list | 264 // Inserts the |received_packets| into the internal received FEC packet list |
244 // or into |recovered_packets|. | 265 // or into |recovered_packets|. |
245 void InsertPackets(ReceivedPacketList* received_packets, | 266 void InsertPackets(ReceivedPacketList* received_packets, |
246 RecoveredPacketList* recovered_packets); | 267 RecoveredPacketList* recovered_packets); |
247 | 268 |
248 // Inserts the |received_packet| into |recovered_packets|. Deletes duplicates. | 269 // Inserts the |received_packet| into |recovered_packets|. Deletes duplicates. |
249 void InsertMediaPacket(ReceivedPacket* received_packet, | 270 void InsertMediaPacket(RecoveredPacketList* recovered_packets, |
250 RecoveredPacketList* recovered_packets); | 271 ReceivedPacket* received_packet); |
251 | 272 |
252 // Assigns pointers to the recovered packet from all FEC packets which cover | 273 // Assigns pointers to the recovered packet from all FEC packets which cover |
253 // it. | 274 // it. |
254 // Note: This reduces the complexity when we want to try to recover a packet | 275 // Note: This reduces the complexity when we want to try to recover a packet |
255 // since we don't have to find the intersection between recovered packets and | 276 // since we don't have to find the intersection between recovered packets and |
256 // packets covered by the FEC packet. | 277 // packets covered by the FEC packet. |
257 void UpdateCoveringFecPackets(RecoveredPacket* packet); | 278 void UpdateCoveringFecPackets(const RecoveredPacket& packet); |
258 | 279 |
259 // Insert |received_packet| into internal FEC list. Deletes duplicates. | 280 // Insert |received_packet| into internal FEC list. Deletes duplicates. |
260 void InsertFecPacket(ReceivedPacket* received_packet, | 281 void InsertFecPacket(const RecoveredPacketList& recovered_packets, |
261 const RecoveredPacketList* recovered_packets); | 282 ReceivedPacket* received_packet); |
262 | 283 |
263 // Assigns pointers to already recovered packets covered by |fec_packet|. | 284 // Assigns pointers to already recovered packets covered by |fec_packet|. |
264 static void AssignRecoveredPackets( | 285 static void AssignRecoveredPackets( |
265 ReceivedFecPacket* fec_packet, | 286 const RecoveredPacketList& recovered_packets, |
266 const RecoveredPacketList* recovered_packets); | 287 ReceivedFecPacket* fec_packet); |
267 | |
268 // Insert |rec_packet_to_insert| into |recovered_packets| in correct position. | |
269 void InsertRecoveredPacket(RecoveredPacket* rec_packet_to_insert, | |
270 RecoveredPacketList* recovered_packets); | |
271 | 288 |
272 // Attempt to recover missing packets, using the internally stored | 289 // Attempt to recover missing packets, using the internally stored |
273 // received FEC packets. | 290 // received FEC packets. |
274 void AttemptRecover(RecoveredPacketList* recovered_packets); | 291 void AttemptRecovery(RecoveredPacketList* recovered_packets); |
275 | 292 |
276 // Initializes packet recovery using the received |fec_packet|. | 293 // Initializes headers and payload before the XOR operation |
277 static bool StartPacketRecovery(const ReceivedFecPacket* fec_packet, | 294 // that recovers a packet. |
| 295 static bool StartPacketRecovery(const ReceivedFecPacket& fec_packet, |
278 RecoveredPacket* recovered_packet); | 296 RecoveredPacket* recovered_packet); |
279 | 297 |
280 // Performs XOR between |src| and |dst| and stores the result in |dst|. | 298 // Performs XOR between the first 8 bytes of |src| and |dst| and stores |
281 static void XorPackets(const Packet* src, RecoveredPacket* dst); | 299 // the result in |dst|. The 3rd and 4th bytes are used for storing |
| 300 // the length recovery field. |
| 301 static void XorHeaders(const Packet& src, Packet* dst); |
282 | 302 |
283 // Finish up the recovery of a packet. | 303 // Performs XOR between the payloads of |src| and |dst| and stores the result |
284 static bool FinishPacketRecovery(RecoveredPacket* recovered_packet); | 304 // in |dst|. The parameter |dst_offset| determines at what byte the |
| 305 // XOR operation starts in |dst|. In total, |payload_length| bytes are XORed. |
| 306 static void XorPayloads(const Packet& src, |
| 307 size_t payload_length, |
| 308 size_t dst_offset, |
| 309 Packet* dst); |
| 310 |
| 311 // Finalizes recovery of packet by setting RTP header fields. |
| 312 // This is not specific to the FEC scheme used. |
| 313 static bool FinishPacketRecovery(const ReceivedFecPacket& fec_packet, |
| 314 RecoveredPacket* recovered_packet); |
285 | 315 |
286 // Recover a missing packet. | 316 // Recover a missing packet. |
287 bool RecoverPacket(const ReceivedFecPacket* fec_packet, | 317 static bool RecoverPacket(const ReceivedFecPacket& fec_packet, |
288 RecoveredPacket* rec_packet_to_insert); | 318 RecoveredPacket* recovered_packet); |
289 | 319 |
290 // Get the number of missing media packets which are covered by |fec_packet|. | 320 // Get the number of missing media packets which are covered by |fec_packet|. |
291 // An FEC packet can recover at most one packet, and if zero packets are | 321 // An FEC packet can recover at most one packet, and if zero packets are |
292 // missing the FEC packet can be discarded. This function returns 2 when two | 322 // missing the FEC packet can be discarded. This function returns 2 when two |
293 // or more packets are missing. | 323 // or more packets are missing. |
294 static int NumCoveredPacketsMissing(const ReceivedFecPacket* fec_packet); | 324 static int NumCoveredPacketsMissing(const ReceivedFecPacket& fec_packet); |
295 | 325 |
296 // Discards old packets in |recovered_packets|, which are no longer relevant | 326 // Discards old packets in |recovered_packets|, which are no longer relevant |
297 // for recovering lost packets. | 327 // for recovering lost packets. |
298 static void DiscardOldRecoveredPackets( | 328 void DiscardOldRecoveredPackets(RecoveredPacketList* recovered_packets); |
299 RecoveredPacketList* recovered_packets); | 329 |
300 static uint16_t ParseSequenceNumber(uint8_t* packet); | 330 std::unique_ptr<FecHeaderReader> fec_header_reader_; |
| 331 std::unique_ptr<FecHeaderWriter> fec_header_writer_; |
301 | 332 |
302 std::vector<Packet> generated_fec_packets_; | 333 std::vector<Packet> generated_fec_packets_; |
303 ReceivedFecPacketList received_fec_packets_; | 334 ReceivedFecPacketList received_fec_packets_; |
304 | 335 |
305 // Arrays used to avoid dynamically allocating memory when generating | 336 // Arrays used to avoid dynamically allocating memory when generating |
306 // the packet masks in the ULPFEC headers. | 337 // the packet masks. |
307 // (There are never more than |kMaxMediaPackets| FEC packets generated.) | 338 // (There are never more than |kUlpfecMaxMediaPackets| FEC packets generated.) |
308 uint8_t packet_mask_[kMaxMediaPackets * kMaskSizeLBitSet]; | 339 uint8_t packet_masks_[kUlpfecMaxMediaPackets * kUlpfecMaxPacketMaskSize]; |
309 uint8_t tmp_packet_mask_[kMaxMediaPackets * kMaskSizeLBitSet]; | 340 uint8_t tmp_packet_masks_[kUlpfecMaxMediaPackets * kUlpfecMaxPacketMaskSize]; |
| 341 size_t packet_mask_size_; |
310 }; | 342 }; |
| 343 |
| 344 // Classes derived from FecHeader{Reader,Writer} encapsulate the |
| 345 // specifics of reading and writing FEC header for, e.g., ULPFEC |
| 346 // and FlexFEC. |
| 347 class FecHeaderReader { |
| 348 public: |
| 349 virtual ~FecHeaderReader(); |
| 350 |
| 351 // The maximum number of media packets that can be covered by one FEC packet. |
| 352 size_t MaxMediaPackets() const; |
| 353 |
| 354 // The maximum number of FEC packets that is supported, per call |
| 355 // to ForwardErrorCorrection::EncodeFec(). |
| 356 size_t MaxFecPackets() const; |
| 357 |
| 358 // Parses FEC header and stores information in ReceivedFecPacket members. |
| 359 virtual bool ReadFecHeader( |
| 360 ForwardErrorCorrection::ReceivedFecPacket* fec_packet) const = 0; |
| 361 |
| 362 protected: |
| 363 FecHeaderReader(size_t max_media_packets, size_t max_fec_packets); |
| 364 |
| 365 const size_t max_media_packets_; |
| 366 const size_t max_fec_packets_; |
| 367 }; |
| 368 |
| 369 class FecHeaderWriter { |
| 370 public: |
| 371 virtual ~FecHeaderWriter(); |
| 372 |
| 373 // The maximum number of media packets that can be covered by one FEC packet. |
| 374 size_t MaxMediaPackets() const; |
| 375 |
| 376 // The maximum number of FEC packets that is supported, per call |
| 377 // to ForwardErrorCorrection::EncodeFec(). |
| 378 size_t MaxFecPackets() const; |
| 379 |
| 380 // The maximum overhead (in bytes) per packet, due to FEC headers. |
| 381 size_t MaxPacketOverhead() const; |
| 382 |
| 383 // Calculates the minimum packet mask size needed (in bytes), |
| 384 // given the discrete options of the ULPFEC masks and the bits |
| 385 // set in the current packet mask. |
| 386 virtual size_t MinPacketMaskSize(const uint8_t* packet_mask, |
| 387 size_t packet_mask_size) const = 0; |
| 388 |
| 389 // The header size (in bytes), given the packet mask size. |
| 390 virtual size_t FecHeaderSize(size_t packet_mask_size) const = 0; |
| 391 |
| 392 // Writes FEC header. |
| 393 virtual void FinalizeFecHeader( |
| 394 uint16_t seq_num_base, |
| 395 const uint8_t* packet_mask, |
| 396 size_t packet_mask_size, |
| 397 ForwardErrorCorrection::Packet* fec_packet) const = 0; |
| 398 |
| 399 protected: |
| 400 FecHeaderWriter(size_t max_media_packets, |
| 401 size_t max_fec_packets, |
| 402 size_t max_packet_overhead); |
| 403 |
| 404 const size_t max_media_packets_; |
| 405 const size_t max_fec_packets_; |
| 406 const size_t max_packet_overhead_; |
| 407 }; |
| 408 |
311 } // namespace webrtc | 409 } // namespace webrtc |
| 410 |
312 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_H_ | 411 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_H_ |
OLD | NEW |