zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef PC_RTPTRANSPORT_H_ |
| 12 | #define PC_RTPTRANSPORT_H_ |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 13 | |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "pc/bundlefilter.h" |
| 17 | #include "pc/rtptransportinternal.h" |
| 18 | #include "rtc_base/sigslot.h" |
zstein | d9ce764 | 2017-04-10 16:17:57 -0700 | [diff] [blame] | 19 | |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 20 | namespace rtc { |
| 21 | |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 22 | class CopyOnWriteBuffer; |
| 23 | struct PacketOptions; |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 24 | struct PacketTime; |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 25 | class PacketTransportInternal; |
| 26 | |
| 27 | } // namespace rtc |
| 28 | |
| 29 | namespace webrtc { |
| 30 | |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 31 | class RtpTransport : public RtpTransportInternal { |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 32 | public: |
| 33 | RtpTransport(const RtpTransport&) = delete; |
| 34 | RtpTransport& operator=(const RtpTransport&) = delete; |
| 35 | |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 36 | explicit RtpTransport(bool rtcp_mux_enabled) |
| 37 | : rtcp_mux_enabled_(rtcp_mux_enabled) {} |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 38 | |
Zhi Huang | f2d7beb | 2017-11-20 14:35:11 -0800 | [diff] [blame] | 39 | bool rtcp_mux_enabled() const override { return rtcp_mux_enabled_; } |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 40 | void SetRtcpMuxEnabled(bool enable) override; |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 41 | |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 42 | rtc::PacketTransportInternal* rtp_packet_transport() const override { |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 43 | return rtp_packet_transport_; |
| 44 | } |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 45 | void SetRtpPacketTransport(rtc::PacketTransportInternal* rtp) override; |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 46 | |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 47 | rtc::PacketTransportInternal* rtcp_packet_transport() const override { |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 48 | return rtcp_packet_transport_; |
| 49 | } |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 50 | void SetRtcpPacketTransport(rtc::PacketTransportInternal* rtcp) override; |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 51 | |
zstein | d9ce764 | 2017-04-10 16:17:57 -0700 | [diff] [blame] | 52 | PacketTransportInterface* GetRtpPacketTransport() const override; |
| 53 | PacketTransportInterface* GetRtcpPacketTransport() const override; |
| 54 | |
| 55 | // TODO(zstein): Use these RtcpParameters for configuration elsewhere. |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 56 | RTCError SetParameters(const RtpTransportParameters& parameters) override; |
| 57 | RtpTransportParameters GetParameters() const override; |
zstein | d9ce764 | 2017-04-10 16:17:57 -0700 | [diff] [blame] | 58 | |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 59 | bool IsWritable(bool rtcp) const override; |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 60 | |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 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; |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 68 | |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 69 | bool HandlesPayloadType(int payload_type) const override; |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 70 | |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 71 | void AddHandledPayloadType(int payload_type) override; |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 72 | |
zstein | d9ce764 | 2017-04-10 16:17:57 -0700 | [diff] [blame] | 73 | protected: |
| 74 | // TODO(zstein): Remove this when we remove RtpTransportAdapter. |
| 75 | RtpTransportAdapter* GetInternal() override; |
| 76 | |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 77 | private: |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 78 | bool IsRtpTransportWritable(); |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 79 | bool HandlesPacket(const uint8_t* data, size_t len); |
| 80 | |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 81 | void OnReadyToSend(rtc::PacketTransportInternal* transport); |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 82 | void OnNetworkRouteChange(rtc::Optional<rtc::NetworkRoute> network_route); |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 83 | void OnWritableState(rtc::PacketTransportInternal* packet_transport); |
| 84 | void OnSentPacket(rtc::PacketTransportInternal* packet_transport, |
| 85 | const rtc::SentPacket& sent_packet); |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 86 | |
| 87 | // Updates "ready to send" for an individual channel and fires |
| 88 | // SignalReadyToSend. |
| 89 | void SetReadyToSend(bool rtcp, bool ready); |
| 90 | |
| 91 | void MaybeSignalReadyToSend(); |
| 92 | |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 93 | bool SendPacket(bool rtcp, |
| 94 | rtc::CopyOnWriteBuffer* packet, |
| 95 | const rtc::PacketOptions& options, |
| 96 | int flags); |
| 97 | |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 98 | void OnReadPacket(rtc::PacketTransportInternal* transport, |
| 99 | const char* data, |
| 100 | size_t len, |
| 101 | const rtc::PacketTime& packet_time, |
| 102 | int flags); |
| 103 | |
| 104 | bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet); |
| 105 | |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 106 | bool rtcp_mux_enabled_; |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 107 | |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 108 | rtc::PacketTransportInternal* rtp_packet_transport_ = nullptr; |
| 109 | rtc::PacketTransportInternal* rtcp_packet_transport_ = nullptr; |
zstein | d9ce764 | 2017-04-10 16:17:57 -0700 | [diff] [blame] | 110 | |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 111 | bool ready_to_send_ = false; |
| 112 | bool rtp_ready_to_send_ = false; |
| 113 | bool rtcp_ready_to_send_ = false; |
| 114 | |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 115 | RtpTransportParameters parameters_; |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 116 | |
| 117 | cricket::BundleFilter bundle_filter_; |
zstein | d48dbda | 2017-04-04 19:45:57 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | } // namespace webrtc |
| 121 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 122 | #endif // PC_RTPTRANSPORT_H_ |