blob: e3f9d1dfe2219f8e6611e127f25748ca4ad94a86 [file] [log] [blame]
stefan@webrtc.orge0d6fa42012-03-20 22:10:56 +00001/*
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
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000016#include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
stefan@webrtc.orge0d6fa42012-03-20 22:10:56 +000017
18namespace webrtc {
19
20struct RtpPacket;
21
22class RedPacket {
23 public:
24 explicit RedPacket(int length);
25 ~RedPacket();
26 void CreateHeader(const uint8_t* rtp_header, int header_length,
27 int red_pl_type, int pl_type);
28 void SetSeqNum(int seq_num);
29 void AssignPayload(const uint8_t* payload, int length);
30 void ClearMarkerBit();
31 uint8_t* data() const;
32 int length() const;
33
34 private:
35 uint8_t* data_;
36 int length_;
37 int header_length_;
38};
39
40class ProducerFec {
41 public:
42 explicit ProducerFec(ForwardErrorCorrection* fec);
43 ~ProducerFec();
44
45 void SetFecParameters(const FecProtectionParams* params,
46 int max_fec_frames);
47
48 RedPacket* BuildRedPacket(const uint8_t* data_buffer,
49 int payload_length,
50 int rtp_header_length,
51 int red_pl_type);
52
53 int AddRtpPacketAndGenerateFec(const uint8_t* data_buffer,
54 int payload_length,
55 int rtp_header_length);
56
marpan@webrtc.org747cd872012-05-22 16:50:00 +000057 bool ExcessOverheadBelowMax();
58
59 bool MinimumMediaPacketsReached();
60
stefan@webrtc.orge0d6fa42012-03-20 22:10:56 +000061 bool FecAvailable() const;
62
marpan@webrtc.org8639fd92012-07-30 18:17:02 +000063 RedPacket* GetFecPacket(int red_pl_type,
64 int fec_pl_type,
65 uint16_t seq_num,
66 int rtp_header_length);
stefan@webrtc.orge0d6fa42012-03-20 22:10:56 +000067
68 private:
69 void DeletePackets();
70 int Overhead() const;
71 ForwardErrorCorrection* fec_;
72 std::list<ForwardErrorCorrection::Packet*> media_packets_fec_;
73 std::list<ForwardErrorCorrection::Packet*> fec_packets_;
74 int num_frames_;
75 bool incomplete_frame_;
76 int num_first_partition_;
marpan@webrtc.org747cd872012-05-22 16:50:00 +000077 int minimum_media_packets_fec_;
stefan@webrtc.orge0d6fa42012-03-20 22:10:56 +000078 FecProtectionParams params_;
stefan@webrtc.orgc35f5ce2012-04-11 07:42:25 +000079 FecProtectionParams new_params_;
stefan@webrtc.orge0d6fa42012-03-20 22:10:56 +000080};
81
82} // namespace webrtc
83
84#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_PRODUCER_FEC_H_