xref: /aosp_15_r20/external/webrtc/call/flexfec_receive_stream_impl.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 CALL_FLEXFEC_RECEIVE_STREAM_IMPL_H_
12 #define CALL_FLEXFEC_RECEIVE_STREAM_IMPL_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include "call/flexfec_receive_stream.h"
18 #include "call/rtp_packet_sink_interface.h"
19 #include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
20 #include "rtc_base/system/no_unique_address.h"
21 #include "system_wrappers/include/clock.h"
22 
23 namespace webrtc {
24 
25 class FlexfecReceiver;
26 class ReceiveStatistics;
27 class RecoveredPacketReceiver;
28 class RtcpRttStats;
29 class RtpPacketReceived;
30 class RtpRtcp;
31 class RtpStreamReceiverControllerInterface;
32 class RtpStreamReceiverInterface;
33 
34 class FlexfecReceiveStreamImpl : public FlexfecReceiveStream {
35  public:
36   FlexfecReceiveStreamImpl(Clock* clock,
37                            Config config,
38                            RecoveredPacketReceiver* recovered_packet_receiver,
39                            RtcpRttStats* rtt_stats);
40   // Destruction happens on the worker thread. Prior to destruction the caller
41   // must ensure that a registration with the transport has been cleared. See
42   // `RegisterWithTransport` for details.
43   // TODO(tommi): As a further improvement to this, performing the full
44   // destruction on the network thread could be made the default.
45   ~FlexfecReceiveStreamImpl() override;
46 
47   // Called on the network thread to register/unregister with the network
48   // transport.
49   void RegisterWithTransport(
50       RtpStreamReceiverControllerInterface* receiver_controller);
51   // If registration has previously been done (via `RegisterWithTransport`) then
52   // `UnregisterFromTransport` must be called prior to destruction, on the
53   // network thread.
54   void UnregisterFromTransport();
55 
56   // RtpPacketSinkInterface.
57   void OnRtpPacket(const RtpPacketReceived& packet) override;
58 
59   void SetPayloadType(int payload_type) override;
60   int payload_type() const override;
61 
62   // ReceiveStreamInterface impl.
63   void SetRtpExtensions(std::vector<RtpExtension> extensions) override;
64   RtpHeaderExtensionMap GetRtpExtensionMap() const override;
65 
66   // Updates the `rtp_video_stream_receiver_`'s `local_ssrc` when the default
67   // sender has been created, changed or removed.
68   void SetLocalSsrc(uint32_t local_ssrc);
69 
remote_ssrc()70   uint32_t remote_ssrc() const { return remote_ssrc_; }
71 
transport_cc()72   bool transport_cc() const override {
73     RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
74     return transport_cc_;
75   }
76 
SetTransportCc(bool transport_cc)77   void SetTransportCc(bool transport_cc) override {
78     RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
79     transport_cc_ = transport_cc;
80   }
81 
SetRtcpMode(RtcpMode mode)82   void SetRtcpMode(RtcpMode mode) override {
83     RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
84     rtp_rtcp_->SetRTCPStatus(mode);
85   }
86 
87  private:
88   RTC_NO_UNIQUE_ADDRESS SequenceChecker packet_sequence_checker_;
89 
90   RtpHeaderExtensionMap extension_map_;
91 
92   const uint32_t remote_ssrc_;
93   bool transport_cc_ RTC_GUARDED_BY(packet_sequence_checker_);
94 
95   // `payload_type_` is initially set to -1, indicating that FlexFec is
96   // disabled.
97   int payload_type_ RTC_GUARDED_BY(packet_sequence_checker_) = -1;
98 
99   // Erasure code interfacing.
100   const std::unique_ptr<FlexfecReceiver> receiver_;
101 
102   // RTCP reporting.
103   const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
104   const std::unique_ptr<ModuleRtpRtcpImpl2> rtp_rtcp_;
105 
106   std::unique_ptr<RtpStreamReceiverInterface> rtp_stream_receiver_
107       RTC_GUARDED_BY(packet_sequence_checker_);
108 };
109 
110 }  // namespace webrtc
111 
112 #endif  // CALL_FLEXFEC_RECEIVE_STREAM_IMPL_H_
113