flexfec_receiver.h (2858B)
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 11 #ifndef MODULES_RTP_RTCP_INCLUDE_FLEXFEC_RECEIVER_H_ 12 #define MODULES_RTP_RTCP_INCLUDE_FLEXFEC_RECEIVER_H_ 13 14 #include <stdint.h> 15 16 #include <memory> 17 18 #include "api/sequence_checker.h" 19 #include "api/units/timestamp.h" 20 #include "modules/rtp_rtcp/include/recovered_packet_receiver.h" 21 #include "modules/rtp_rtcp/source/forward_error_correction.h" 22 #include "modules/rtp_rtcp/source/rtp_packet_received.h" 23 #include "modules/rtp_rtcp/source/ulpfec_receiver.h" 24 #include "rtc_base/system/no_unique_address.h" 25 #include "rtc_base/thread_annotations.h" 26 27 namespace webrtc { 28 29 class Clock; 30 31 class FlexfecReceiver { 32 public: 33 /* Mozilla: Avoid this since it could use GetRealTimeClock(). 34 FlexfecReceiver(uint32_t ssrc, 35 uint32_t protected_media_ssrc, 36 RecoveredPacketReceiver* recovered_packet_receiver); 37 */ 38 FlexfecReceiver(Clock* clock, 39 uint32_t ssrc, 40 uint32_t protected_media_ssrc, 41 RecoveredPacketReceiver* recovered_packet_receiver); 42 ~FlexfecReceiver(); 43 44 // Inserts a received packet (can be either media or FlexFEC) into the 45 // internal buffer, and sends the received packets to the erasure code. 46 // All newly recovered packets are sent back through the callback. 47 void OnRtpPacket(const RtpPacketReceived& packet); 48 49 // Returns a counter describing the added and recovered packets. 50 FecPacketCounter GetPacketCounter() const; 51 52 // Protected to aid testing. 53 protected: 54 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> AddReceivedPacket( 55 const RtpPacketReceived& packet); 56 void ProcessReceivedPacket( 57 const ForwardErrorCorrection::ReceivedPacket& received_packet); 58 59 private: 60 // Config. 61 const uint32_t ssrc_; 62 const uint32_t protected_media_ssrc_; 63 64 // Erasure code interfacing and callback. 65 std::unique_ptr<ForwardErrorCorrection> erasure_code_ 66 RTC_GUARDED_BY(sequence_checker_); 67 ForwardErrorCorrection::RecoveredPacketList recovered_packets_ 68 RTC_GUARDED_BY(sequence_checker_); 69 RecoveredPacketReceiver* const recovered_packet_receiver_; 70 71 // Logging and stats. 72 Clock* const clock_; 73 Timestamp last_recovered_packet_ RTC_GUARDED_BY(sequence_checker_) = 74 Timestamp::MinusInfinity(); 75 FecPacketCounter packet_counter_ RTC_GUARDED_BY(sequence_checker_); 76 77 RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_; 78 }; 79 80 } // namespace webrtc 81 82 #endif // MODULES_RTP_RTCP_INCLUDE_FLEXFEC_RECEIVER_H_