xref: /aosp_15_r20/external/webrtc/modules/rtp_rtcp/source/ulpfec_receiver.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 "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/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 "system_wrappers/include/clock.h"
27 
28 namespace webrtc {
29 
30 struct FecPacketCounter {
31   FecPacketCounter() = default;
32   size_t num_packets = 0;  // Number of received packets.
33   size_t num_bytes = 0;
34   size_t num_fec_packets = 0;  // Number of received FEC packets.
35   size_t num_recovered_packets =
36       0;  // Number of recovered media packets using FEC.
37   // Time when first packet is received.
38   Timestamp first_packet_time = Timestamp::MinusInfinity();
39 };
40 
41 class UlpfecReceiver {
42  public:
43   UlpfecReceiver(uint32_t ssrc,
44                  int ulpfec_payload_type,
45                  RecoveredPacketReceiver* callback,
46                  rtc::ArrayView<const RtpExtension> extensions,
47                  Clock* clock);
48   ~UlpfecReceiver();
49 
ulpfec_payload_type()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   void SetRtpExtensions(rtc::ArrayView<const RtpExtension> extensions);
59 
60  private:
61   const uint32_t ssrc_;
62   const int ulpfec_payload_type_;
63   Clock* const clock_;
64   RtpHeaderExtensionMap extensions_ RTC_GUARDED_BY(&sequence_checker_);
65 
66   RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;
67   RecoveredPacketReceiver* const recovered_packet_callback_;
68   const std::unique_ptr<ForwardErrorCorrection> fec_;
69   // TODO(nisse): The AddReceivedRedPacket method adds one or two packets to
70   // this list at a time, after which it is emptied by ProcessReceivedFec. It
71   // will make things simpler to merge AddReceivedRedPacket and
72   // ProcessReceivedFec into a single method, and we can then delete this list.
73   std::vector<std::unique_ptr<ForwardErrorCorrection::ReceivedPacket>>
74       received_packets_ RTC_GUARDED_BY(&sequence_checker_);
75   ForwardErrorCorrection::RecoveredPacketList recovered_packets_
76       RTC_GUARDED_BY(&sequence_checker_);
77   FecPacketCounter packet_counter_ RTC_GUARDED_BY(&sequence_checker_);
78 };
79 
80 }  // namespace webrtc
81 
82 #endif  // MODULES_RTP_RTCP_SOURCE_ULPFEC_RECEIVER_H_
83