brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_RTP_RTCP_INCLUDE_FLEXFEC_SENDER_H_ |
| 12 | #define MODULES_RTP_RTCP_INCLUDE_FLEXFEC_SENDER_H_ |
brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #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" |
brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
| 31 | class RtpPacketToSend; |
| 32 | |
brandtr | fe793eb | 2016-12-12 07:13:56 -0800 | [diff] [blame] | 33 | // Note that this class is not thread safe, and thus requires external |
brandtr | 3b941be | 2017-03-17 07:02:46 -0700 | [diff] [blame] | 34 | // synchronization. Currently, this is done using the lock in PayloadRouter. |
brandtr | fe793eb | 2016-12-12 07:13:56 -0800 | [diff] [blame] | 35 | |
brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 36 | class 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, |
erikvarga | 2788373 | 2017-05-17 05:08:38 -0700 | [diff] [blame] | 42 | rtc::ArrayView<const RtpExtensionSize> extension_sizes, |
brandtr | 48d21a2 | 2017-05-30 02:32:12 -0700 | [diff] [blame] | 43 | const RtpState* rtp_state, |
brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 44 | Clock* clock); |
| 45 | ~FlexfecSender(); |
| 46 | |
brandtr | 9dfff29 | 2016-11-14 05:14:50 -0800 | [diff] [blame] | 47 | uint32_t ssrc() const { return ssrc_; } |
| 48 | |
brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 49 | // 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 | |
brandtr | 48d21a2 | 2017-05-30 02:32:12 -0700 | [diff] [blame] | 68 | // Only called on the VideoSendStream queue, after operation has shut down. |
| 69 | RtpState GetRtpState(); |
| 70 | |
brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 71 | private: |
| 72 | // Utility. |
| 73 | Clock* const clock_; |
brandtr | fe793eb | 2016-12-12 07:13:56 -0800 | [diff] [blame] | 74 | Random random_; |
| 75 | int64_t last_generated_packet_ms_; |
brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 76 | |
| 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. |
brandtr | fe793eb | 2016-12-12 07:13:56 -0800 | [diff] [blame] | 83 | uint16_t seq_num_; |
brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 84 | |
| 85 | // Implementation. |
brandtr | fe793eb | 2016-12-12 07:13:56 -0800 | [diff] [blame] | 86 | UlpfecGenerator ulpfec_generator_; |
brandtr | 131bc49 | 2016-11-10 05:01:11 -0800 | [diff] [blame] | 87 | const RtpHeaderExtensionMap rtp_header_extension_map_; |
erikvarga | 2788373 | 2017-05-17 05:08:38 -0700 | [diff] [blame] | 88 | const size_t header_extensions_size_; |
brandtr | c295e00 | 2016-11-03 09:22:33 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace webrtc |
| 92 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 93 | #endif // MODULES_RTP_RTCP_INCLUDE_FLEXFEC_SENDER_H_ |