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