• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2017 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 PC_RTP_TRANSPORT_H_
12 #define PC_RTP_TRANSPORT_H_
13 
14 #include <string>
15 
16 #include "call/rtp_demuxer.h"
17 #include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
18 #include "pc/rtp_transport_internal.h"
19 #include "rtc_base/third_party/sigslot/sigslot.h"
20 
21 namespace rtc {
22 
23 class CopyOnWriteBuffer;
24 struct PacketOptions;
25 class PacketTransportInternal;
26 
27 }  // namespace rtc
28 
29 namespace webrtc {
30 
31 class RtpTransport : public RtpTransportInternal {
32  public:
33   RtpTransport(const RtpTransport&) = delete;
34   RtpTransport& operator=(const RtpTransport&) = delete;
35 
RtpTransport(bool rtcp_mux_enabled)36   explicit RtpTransport(bool rtcp_mux_enabled)
37       : rtcp_mux_enabled_(rtcp_mux_enabled) {}
38 
rtcp_mux_enabled()39   bool rtcp_mux_enabled() const override { return rtcp_mux_enabled_; }
40   void SetRtcpMuxEnabled(bool enable) override;
41 
42   const std::string& transport_name() const override;
43 
44   int SetRtpOption(rtc::Socket::Option opt, int value) override;
45   int SetRtcpOption(rtc::Socket::Option opt, int value) override;
46 
rtp_packet_transport()47   rtc::PacketTransportInternal* rtp_packet_transport() const {
48     return rtp_packet_transport_;
49   }
50   void SetRtpPacketTransport(rtc::PacketTransportInternal* rtp);
51 
rtcp_packet_transport()52   rtc::PacketTransportInternal* rtcp_packet_transport() const {
53     return rtcp_packet_transport_;
54   }
55   void SetRtcpPacketTransport(rtc::PacketTransportInternal* rtcp);
56 
IsReadyToSend()57   bool IsReadyToSend() const override { return ready_to_send_; }
58 
59   bool IsWritable(bool rtcp) const override;
60 
61   bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet,
62                      const rtc::PacketOptions& options,
63                      int flags) override;
64 
65   bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet,
66                       const rtc::PacketOptions& options,
67                       int flags) override;
68 
IsSrtpActive()69   bool IsSrtpActive() const override { return false; }
70 
71   void UpdateRtpHeaderExtensionMap(
72       const cricket::RtpHeaderExtensions& header_extensions) override;
73 
74   bool RegisterRtpDemuxerSink(const RtpDemuxerCriteria& criteria,
75                               RtpPacketSinkInterface* sink) override;
76 
77   bool UnregisterRtpDemuxerSink(RtpPacketSinkInterface* sink) override;
78 
79  protected:
80   // These methods will be used in the subclasses.
81   void DemuxPacket(rtc::CopyOnWriteBuffer packet, int64_t packet_time_us);
82 
83   bool SendPacket(bool rtcp,
84                   rtc::CopyOnWriteBuffer* packet,
85                   const rtc::PacketOptions& options,
86                   int flags);
87 
88   // Overridden by SrtpTransport.
89   virtual void OnNetworkRouteChanged(
90       absl::optional<rtc::NetworkRoute> network_route);
91   virtual void OnRtpPacketReceived(rtc::CopyOnWriteBuffer packet,
92                                    int64_t packet_time_us);
93   virtual void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer packet,
94                                     int64_t packet_time_us);
95   // Overridden by SrtpTransport and DtlsSrtpTransport.
96   virtual void OnWritableState(rtc::PacketTransportInternal* packet_transport);
97 
98  private:
99   void OnReadyToSend(rtc::PacketTransportInternal* transport);
100   void OnSentPacket(rtc::PacketTransportInternal* packet_transport,
101                     const rtc::SentPacket& sent_packet);
102   void OnReadPacket(rtc::PacketTransportInternal* transport,
103                     const char* data,
104                     size_t len,
105                     const int64_t& packet_time_us,
106                     int flags);
107 
108   // Updates "ready to send" for an individual channel and fires
109   // SignalReadyToSend.
110   void SetReadyToSend(bool rtcp, bool ready);
111 
112   void MaybeSignalReadyToSend();
113 
114   bool IsTransportWritable();
115 
116   bool rtcp_mux_enabled_;
117 
118   rtc::PacketTransportInternal* rtp_packet_transport_ = nullptr;
119   rtc::PacketTransportInternal* rtcp_packet_transport_ = nullptr;
120 
121   bool ready_to_send_ = false;
122   bool rtp_ready_to_send_ = false;
123   bool rtcp_ready_to_send_ = false;
124 
125   RtpDemuxer rtp_demuxer_;
126 
127   // Used for identifying the MID for RtpDemuxer.
128   RtpHeaderExtensionMap header_extension_map_;
129 };
130 
131 }  // namespace webrtc
132 
133 #endif  // PC_RTP_TRANSPORT_H_
134