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