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