blob: 87f29bac2a1be173411e6c086c5a7e064f2f0ab1 [file] [log] [blame]
zsteind48dbda2017-04-04 19:45:57 -07001/*
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 WEBRTC_PC_RTPTRANSPORT_H_
12#define WEBRTC_PC_RTPTRANSPORT_H_
13
zsteind9ce7642017-04-10 16:17:57 -070014#include "webrtc/api/ortc/rtptransportinterface.h"
zstein3dcf0e92017-06-01 13:22:42 -070015#include "webrtc/pc/bundlefilter.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020016#include "webrtc/rtc_base/sigslot.h"
zsteind9ce7642017-04-10 16:17:57 -070017
zsteind48dbda2017-04-04 19:45:57 -070018namespace rtc {
19
zstein56162b92017-04-24 16:54:35 -070020class CopyOnWriteBuffer;
21struct PacketOptions;
zstein3dcf0e92017-06-01 13:22:42 -070022struct PacketTime;
zsteind48dbda2017-04-04 19:45:57 -070023class PacketTransportInternal;
24
25} // namespace rtc
26
27namespace webrtc {
28
zstein56162b92017-04-24 16:54:35 -070029class RtpTransport : public RtpTransportInterface, public sigslot::has_slots<> {
zsteind48dbda2017-04-04 19:45:57 -070030 public:
31 RtpTransport(const RtpTransport&) = delete;
32 RtpTransport& operator=(const RtpTransport&) = delete;
33
zstein56162b92017-04-24 16:54:35 -070034 explicit RtpTransport(bool rtcp_mux_enabled)
35 : rtcp_mux_enabled_(rtcp_mux_enabled) {}
zsteind48dbda2017-04-04 19:45:57 -070036
zstein56162b92017-04-24 16:54:35 -070037 bool rtcp_mux_enabled() const { return rtcp_mux_enabled_; }
38 void SetRtcpMuxEnabled(bool enable);
zsteind48dbda2017-04-04 19:45:57 -070039
40 rtc::PacketTransportInternal* rtp_packet_transport() const {
41 return rtp_packet_transport_;
42 }
zstein56162b92017-04-24 16:54:35 -070043 void SetRtpPacketTransport(rtc::PacketTransportInternal* rtp);
zsteind48dbda2017-04-04 19:45:57 -070044
45 rtc::PacketTransportInternal* rtcp_packet_transport() const {
46 return rtcp_packet_transport_;
47 }
zstein56162b92017-04-24 16:54:35 -070048 void SetRtcpPacketTransport(rtc::PacketTransportInternal* rtcp);
zsteind48dbda2017-04-04 19:45:57 -070049
zsteind9ce7642017-04-10 16:17:57 -070050 PacketTransportInterface* GetRtpPacketTransport() const override;
51 PacketTransportInterface* GetRtcpPacketTransport() const override;
52
53 // TODO(zstein): Use these RtcpParameters for configuration elsewhere.
54 RTCError SetRtcpParameters(const RtcpParameters& parameters) override;
55 RtcpParameters GetRtcpParameters() const override;
56
zstein56162b92017-04-24 16:54:35 -070057 // Called whenever a transport's ready-to-send state changes. The argument
58 // is true if all used transports are ready to send. This is more specific
59 // than just "writable"; it means the last send didn't return ENOTCONN.
60 sigslot::signal1<bool> SignalReadyToSend;
61
62 bool IsWritable(bool rtcp) const;
63
64 bool SendPacket(bool rtcp,
65 const rtc::CopyOnWriteBuffer* packet,
66 const rtc::PacketOptions& options,
67 int flags);
68
zstein3dcf0e92017-06-01 13:22:42 -070069 bool HandlesPayloadType(int payload_type) const;
70
71 void AddHandledPayloadType(int payload_type);
72
73 // TODO(zstein): Consider having two signals - RtcPacketReceived and
74 // RtcpPacketReceived.
75 // The first argument is true for RTCP packets and false for RTP packets.
76 sigslot::signal3<bool, rtc::CopyOnWriteBuffer&, const rtc::PacketTime&>
77 SignalPacketReceived;
78
zsteind9ce7642017-04-10 16:17:57 -070079 protected:
80 // TODO(zstein): Remove this when we remove RtpTransportAdapter.
81 RtpTransportAdapter* GetInternal() override;
82
zsteind48dbda2017-04-04 19:45:57 -070083 private:
zstein3dcf0e92017-06-01 13:22:42 -070084 bool HandlesPacket(const uint8_t* data, size_t len);
85
zstein56162b92017-04-24 16:54:35 -070086 void OnReadyToSend(rtc::PacketTransportInternal* transport);
87
88 // Updates "ready to send" for an individual channel and fires
89 // SignalReadyToSend.
90 void SetReadyToSend(bool rtcp, bool ready);
91
92 void MaybeSignalReadyToSend();
93
zstein3dcf0e92017-06-01 13:22:42 -070094 void OnReadPacket(rtc::PacketTransportInternal* transport,
95 const char* data,
96 size_t len,
97 const rtc::PacketTime& packet_time,
98 int flags);
99
100 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
101
zstein56162b92017-04-24 16:54:35 -0700102 bool rtcp_mux_enabled_;
zsteind48dbda2017-04-04 19:45:57 -0700103
zsteind48dbda2017-04-04 19:45:57 -0700104 rtc::PacketTransportInternal* rtp_packet_transport_ = nullptr;
105 rtc::PacketTransportInternal* rtcp_packet_transport_ = nullptr;
zsteind9ce7642017-04-10 16:17:57 -0700106
zstein56162b92017-04-24 16:54:35 -0700107 bool ready_to_send_ = false;
108 bool rtp_ready_to_send_ = false;
109 bool rtcp_ready_to_send_ = false;
110
zsteind9ce7642017-04-10 16:17:57 -0700111 RtcpParameters rtcp_parameters_;
zstein3dcf0e92017-06-01 13:22:42 -0700112
113 cricket::BundleFilter bundle_filter_;
zsteind48dbda2017-04-04 19:45:57 -0700114};
115
116} // namespace webrtc
117
118#endif // WEBRTC_PC_RTPTRANSPORT_H_