ulpfec_receiver.h (2778B)
1 /* 2 * Copyright (c) 2012 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_SOURCE_ULPFEC_RECEIVER_H_ 12 #define MODULES_RTP_RTCP_SOURCE_ULPFEC_RECEIVER_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <memory> 18 #include <vector> 19 20 #include "api/sequence_checker.h" 21 #include "api/units/timestamp.h" 22 #include "modules/rtp_rtcp/include/recovered_packet_receiver.h" 23 #include "modules/rtp_rtcp/source/forward_error_correction.h" 24 #include "modules/rtp_rtcp/source/rtp_packet_received.h" 25 #include "rtc_base/system/no_unique_address.h" 26 #include "rtc_base/thread_annotations.h" 27 #include "system_wrappers/include/clock.h" 28 29 namespace webrtc { 30 31 struct FecPacketCounter { 32 FecPacketCounter() = default; 33 size_t num_packets = 0; // Number of received packets. 34 size_t num_bytes = 0; 35 size_t num_fec_packets = 0; // Number of received FEC packets. 36 size_t num_recovered_packets = 37 0; // Number of recovered media packets using FEC. 38 // Time when first packet is received. 39 Timestamp first_packet_time = Timestamp::MinusInfinity(); 40 }; 41 42 class UlpfecReceiver { 43 public: 44 UlpfecReceiver(uint32_t ssrc, 45 int ulpfec_payload_type, 46 RecoveredPacketReceiver* callback, 47 Clock* clock); 48 ~UlpfecReceiver(); 49 50 int ulpfec_payload_type() const { return ulpfec_payload_type_; } 51 52 bool AddReceivedRedPacket(const RtpPacketReceived& rtp_packet); 53 54 void ProcessReceivedFec(); 55 56 FecPacketCounter GetPacketCounter() const; 57 58 private: 59 const uint32_t ssrc_; 60 const int ulpfec_payload_type_; 61 Clock* const clock_; 62 63 RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_; 64 RecoveredPacketReceiver* const recovered_packet_callback_; 65 const std::unique_ptr<ForwardErrorCorrection> fec_; 66 // TODO(nisse): The AddReceivedRedPacket method adds one or two packets to 67 // this list at a time, after which it is emptied by ProcessReceivedFec. It 68 // will make things simpler to merge AddReceivedRedPacket and 69 // ProcessReceivedFec into a single method, and we can then delete this list. 70 std::vector<std::unique_ptr<ForwardErrorCorrection::ReceivedPacket>> 71 received_packets_ RTC_GUARDED_BY(&sequence_checker_); 72 ForwardErrorCorrection::RecoveredPacketList recovered_packets_ 73 RTC_GUARDED_BY(&sequence_checker_); 74 FecPacketCounter packet_counter_ RTC_GUARDED_BY(&sequence_checker_); 75 }; 76 77 } // namespace webrtc 78 79 #endif // MODULES_RTP_RTCP_SOURCE_ULPFEC_RECEIVER_H_