blob: 5b939d534baa1304980e24cf19b96a0706682b5c [file] [log] [blame]
brandtrc295e002016-11-03 09:22:33 -07001/*
2 * Copyright (c) 2016 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_RTP_RTCP_INCLUDE_FLEXFEC_SENDER_H_
12#define MODULES_RTP_RTCP_INCLUDE_FLEXFEC_SENDER_H_
brandtrc295e002016-11-03 09:22:33 -070013
14#include <memory>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/array_view.h"
18#include "api/rtpparameters.h"
19#include "modules/include/module_common_types.h"
20#include "modules/rtp_rtcp/include/flexfec_sender.h"
21#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
22#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
23#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
24#include "modules/rtp_rtcp/source/ulpfec_generator.h"
25#include "rtc_base/basictypes.h"
26#include "rtc_base/random.h"
27#include "system_wrappers/include/clock.h"
brandtrc295e002016-11-03 09:22:33 -070028
29namespace webrtc {
30
31class RtpPacketToSend;
32
brandtrfe793eb2016-12-12 07:13:56 -080033// Note that this class is not thread safe, and thus requires external
brandtr3b941be2017-03-17 07:02:46 -070034// synchronization. Currently, this is done using the lock in PayloadRouter.
brandtrfe793eb2016-12-12 07:13:56 -080035
brandtrc295e002016-11-03 09:22:33 -070036class FlexfecSender {
37 public:
38 FlexfecSender(int payload_type,
39 uint32_t ssrc,
40 uint32_t protected_media_ssrc,
41 const std::vector<RtpExtension>& rtp_header_extensions,
erikvarga27883732017-05-17 05:08:38 -070042 rtc::ArrayView<const RtpExtensionSize> extension_sizes,
brandtr48d21a22017-05-30 02:32:12 -070043 const RtpState* rtp_state,
brandtrc295e002016-11-03 09:22:33 -070044 Clock* clock);
45 ~FlexfecSender();
46
brandtr9dfff292016-11-14 05:14:50 -080047 uint32_t ssrc() const { return ssrc_; }
48
brandtrc295e002016-11-03 09:22:33 -070049 // Sets the FEC rate, max frames sent before FEC packets are sent,
50 // and what type of generator matrices are used.
51 void SetFecParameters(const FecProtectionParams& params);
52
53 // Adds a media packet to the internal buffer. When enough media packets
54 // have been added, the FEC packets are generated and stored internally.
55 // These FEC packets are then obtained by calling GetFecPackets().
56 // Returns true if the media packet was successfully added.
57 bool AddRtpPacketAndGenerateFec(const RtpPacketToSend& packet);
58
59 // Returns true if there are generated FEC packets available.
60 bool FecAvailable() const;
61
62 // Returns generated FlexFEC packets.
63 std::vector<std::unique_ptr<RtpPacketToSend>> GetFecPackets();
64
65 // Returns the overhead, per packet, for FlexFEC.
66 size_t MaxPacketOverhead() const;
67
brandtr48d21a22017-05-30 02:32:12 -070068 // Only called on the VideoSendStream queue, after operation has shut down.
69 RtpState GetRtpState();
70
brandtrc295e002016-11-03 09:22:33 -070071 private:
72 // Utility.
73 Clock* const clock_;
brandtrfe793eb2016-12-12 07:13:56 -080074 Random random_;
75 int64_t last_generated_packet_ms_;
brandtrc295e002016-11-03 09:22:33 -070076
77 // Config.
78 const int payload_type_;
79 const uint32_t timestamp_offset_;
80 const uint32_t ssrc_;
81 const uint32_t protected_media_ssrc_;
82 // Sequence number of next packet to generate.
brandtrfe793eb2016-12-12 07:13:56 -080083 uint16_t seq_num_;
brandtrc295e002016-11-03 09:22:33 -070084
85 // Implementation.
brandtrfe793eb2016-12-12 07:13:56 -080086 UlpfecGenerator ulpfec_generator_;
brandtr131bc492016-11-10 05:01:11 -080087 const RtpHeaderExtensionMap rtp_header_extension_map_;
erikvarga27883732017-05-17 05:08:38 -070088 const size_t header_extensions_size_;
brandtrc295e002016-11-03 09:22:33 -070089};
90
91} // namespace webrtc
92
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020093#endif // MODULES_RTP_RTCP_INCLUDE_FLEXFEC_SENDER_H_