1/* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_PRODUCER_FEC_H_ 12#define WEBRTC_MODULES_RTP_RTCP_SOURCE_PRODUCER_FEC_H_ 13 14#include <list> 15#include <vector> 16 17#include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" 18 19namespace webrtc { 20 21struct RtpPacket; 22 23class RedPacket { 24 public: 25 explicit RedPacket(size_t length); 26 ~RedPacket(); 27 void CreateHeader(const uint8_t* rtp_header, size_t header_length, 28 int red_pl_type, int pl_type); 29 void SetSeqNum(int seq_num); 30 void AssignPayload(const uint8_t* payload, size_t length); 31 void ClearMarkerBit(); 32 uint8_t* data() const; 33 size_t length() const; 34 35 private: 36 uint8_t* data_; 37 size_t length_; 38 size_t header_length_; 39}; 40 41class ProducerFec { 42 public: 43 explicit ProducerFec(ForwardErrorCorrection* fec); 44 ~ProducerFec(); 45 46 void SetFecParameters(const FecProtectionParams* params, 47 int max_fec_frames); 48 49 // The caller is expected to delete the memory when done. 50 RedPacket* BuildRedPacket(const uint8_t* data_buffer, 51 size_t payload_length, 52 size_t rtp_header_length, 53 int red_pl_type); 54 55 int AddRtpPacketAndGenerateFec(const uint8_t* data_buffer, 56 size_t payload_length, 57 size_t rtp_header_length); 58 59 bool ExcessOverheadBelowMax(); 60 61 bool MinimumMediaPacketsReached(); 62 63 bool FecAvailable() const; 64 size_t NumAvailableFecPackets() const; 65 66 // GetFecPackets allocates memory and creates FEC packets, but the caller is 67 // assumed to delete the memory when done with the packets. 68 std::vector<RedPacket*> GetFecPackets(int red_pl_type, 69 int fec_pl_type, 70 uint16_t first_seq_num, 71 size_t rtp_header_length); 72 73 private: 74 void DeletePackets(); 75 int Overhead() const; 76 ForwardErrorCorrection* fec_; 77 std::list<ForwardErrorCorrection::Packet*> media_packets_fec_; 78 std::list<ForwardErrorCorrection::Packet*> fec_packets_; 79 int num_frames_; 80 int num_first_partition_; 81 int minimum_media_packets_fec_; 82 FecProtectionParams params_; 83 FecProtectionParams new_params_; 84}; 85 86} // namespace webrtc 87 88#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_PRODUCER_FEC_H_ 89