| 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_PRODUCER_FEC_H_ |   11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_PRODUCER_FEC_H_ | 
|   12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_PRODUCER_FEC_H_ |   12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_PRODUCER_FEC_H_ | 
|   13  |   13  | 
 |   14 #include <list> | 
 |   15 #include <memory> | 
|   14 #include <vector> |   16 #include <vector> | 
|   15  |   17  | 
|   16 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |   18 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 
|   17  |   19  | 
|   18 namespace webrtc { |   20 namespace webrtc { | 
|   19  |   21  | 
|   20 class RedPacket { |   22 class RedPacket { | 
|   21  public: |   23  public: | 
|   22   explicit RedPacket(size_t length); |   24   explicit RedPacket(size_t length); | 
|   23   ~RedPacket(); |   25  | 
|   24   void CreateHeader(const uint8_t* rtp_header, size_t header_length, |   26   void CreateHeader(const uint8_t* rtp_header, size_t header_length, | 
|   25                     int red_pl_type, int pl_type); |   27                     int red_payload_type, int payload_type); | 
|   26   void SetSeqNum(int seq_num); |   28   void SetSeqNum(int seq_num); | 
|   27   void AssignPayload(const uint8_t* payload, size_t length); |   29   void AssignPayload(const uint8_t* payload, size_t length); | 
|   28   void ClearMarkerBit(); |   30   void ClearMarkerBit(); | 
|   29   uint8_t* data() const; |   31   uint8_t* data() const; | 
|   30   size_t length() const; |   32   size_t length() const; | 
|   31  |   33  | 
|   32  private: |   34  private: | 
|   33   uint8_t* data_; |   35   std::unique_ptr<uint8_t[]> data_; | 
|   34   size_t length_; |   36   size_t length_; | 
|   35   size_t header_length_; |   37   size_t header_length_; | 
|   36 }; |   38 }; | 
|   37  |   39  | 
|   38 class ProducerFec { |   40 class ProducerFec { | 
|   39  public: |   41  public: | 
|   40   explicit ProducerFec(ForwardErrorCorrection* fec); |   42   explicit ProducerFec(ForwardErrorCorrection* fec); | 
|   41   ~ProducerFec(); |   43   ~ProducerFec(); | 
|   42  |   44  | 
 |   45   static std::unique_ptr<RedPacket> BuildRedPacket(const uint8_t* data_buffer, | 
 |   46                                                    size_t payload_length, | 
 |   47                                                    size_t rtp_header_length, | 
 |   48                                                    int red_payload_type); | 
 |   49  | 
|   43   void SetFecParameters(const FecProtectionParams* params, |   50   void SetFecParameters(const FecProtectionParams* params, | 
|   44                         int max_fec_frames); |   51                         int num_first_partition); | 
|   45  |   52  | 
|   46   // The caller is expected to delete the memory when done. |   53   // Adds a media packet to the internal buffer. When enough media packets | 
|   47   RedPacket* BuildRedPacket(const uint8_t* data_buffer, |   54   // have been added, the FEC packets are generated and stored internally. | 
|   48                             size_t payload_length, |   55   // These FEC packets are then obtained by calling GetFecPacketsAsRed(). | 
|   49                             size_t rtp_header_length, |  | 
|   50                             int red_pl_type); |  | 
|   51  |  | 
|   52   int AddRtpPacketAndGenerateFec(const uint8_t* data_buffer, |   56   int AddRtpPacketAndGenerateFec(const uint8_t* data_buffer, | 
|   53                                  size_t payload_length, |   57                                  size_t payload_length, | 
|   54                                  size_t rtp_header_length); |   58                                  size_t rtp_header_length); | 
|   55  |   59  | 
|   56   bool ExcessOverheadBelowMax(); |   60   // Returns true if the excess overhead (actual - target) for the FEC is below | 
 |   61   // the amount |kMaxExcessOverhead|. This effects the lower protection level | 
 |   62   // cases and low number of media packets/frame. The target overhead is given | 
 |   63   // by |params_.fec_rate|, and is only achievable in the limit of large number | 
 |   64   // of media packets. | 
 |   65   bool ExcessOverheadBelowMax() const; | 
|   57  |   66  | 
|   58   bool MinimumMediaPacketsReached(); |   67   // Returns true if the number of added media packets is at least | 
 |   68   // |min_num_media_packets_|. This condition tries to capture the effect | 
 |   69   // that, for the same amount of protection/overhead, longer codes | 
 |   70   // (e.g. (2k,2m) vs (k,m)) are generally more effective at recovering losses. | 
 |   71   bool MinimumMediaPacketsReached() const; | 
|   59  |   72  | 
 |   73   // Returns true if there are generated FEC packets available. | 
|   60   bool FecAvailable() const; |   74   bool FecAvailable() const; | 
 |   75  | 
|   61   size_t NumAvailableFecPackets() const; |   76   size_t NumAvailableFecPackets() const; | 
|   62  |   77  | 
|   63   // GetFecPackets allocates memory and creates FEC packets, but the caller is |   78   // Returns generated FEC packets with RED headers added. | 
|   64   // assumed to delete the memory when done with the packets. |   79   std::vector<std::unique_ptr<RedPacket>> GetFecPacketsAsRed( | 
|   65   std::vector<RedPacket*> GetFecPackets(int red_pl_type, |   80       int red_payload_type, | 
|   66                                         int fec_pl_type, |   81       int ulpfec_payload_type, | 
|   67                                         uint16_t first_seq_num, |   82       uint16_t first_seq_num, | 
|   68                                         size_t rtp_header_length); |   83       size_t rtp_header_length); | 
|   69  |   84  | 
|   70  private: |   85  private: | 
|   71   void DeletePackets(); |   86   void DeleteMediaPackets(); | 
|   72   int Overhead() const; |   87   int Overhead() const; | 
|   73   ForwardErrorCorrection* fec_; |   88   ForwardErrorCorrection* fec_; | 
|   74   ForwardErrorCorrection::PacketList media_packets_fec_; |   89   ForwardErrorCorrection::PacketList media_packets_; | 
|   75   ForwardErrorCorrection::PacketList fec_packets_; |   90   std::list<ForwardErrorCorrection::Packet*> generated_fec_packets_; | 
|   76   int num_frames_; |   91   int num_protected_frames_; | 
|   77   int num_first_partition_; |   92   int num_important_packets_; | 
|   78   int minimum_media_packets_fec_; |   93   int min_num_media_packets_; | 
|   79   FecProtectionParams params_; |   94   FecProtectionParams params_; | 
|   80   FecProtectionParams new_params_; |   95   FecProtectionParams new_params_; | 
|   81 }; |   96 }; | 
|   82  |   97  | 
|   83 }  // namespace webrtc |   98 }  // namespace webrtc | 
|   84  |   99  | 
|   85 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_PRODUCER_FEC_H_ |  100 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_PRODUCER_FEC_H_ | 
| OLD | NEW |