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