blob: a42493a5634cd4328529fcb6f6ab55211edce4cc [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_RTPTRANSPORT_H_
12#define PC_RTPTRANSPORT_H_
zsteind48dbda2017-04-04 19:45:57 -070013
Zhi Huang942bc2e2017-11-13 13:26:07 -080014#include <string>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "pc/bundlefilter.h"
17#include "pc/rtptransportinternal.h"
18#include "rtc_base/sigslot.h"
zsteind9ce7642017-04-10 16:17:57 -070019
zsteind48dbda2017-04-04 19:45:57 -070020namespace rtc {
21
zstein56162b92017-04-24 16:54:35 -070022class CopyOnWriteBuffer;
23struct PacketOptions;
zstein3dcf0e92017-06-01 13:22:42 -070024struct PacketTime;
zsteind48dbda2017-04-04 19:45:57 -070025class PacketTransportInternal;
26
27} // namespace rtc
28
29namespace webrtc {
30
zstein398c3fd2017-07-19 13:38:02 -070031class RtpTransport : public RtpTransportInternal {
zsteind48dbda2017-04-04 19:45:57 -070032 public:
33 RtpTransport(const RtpTransport&) = delete;
34 RtpTransport& operator=(const RtpTransport&) = delete;
35
zstein56162b92017-04-24 16:54:35 -070036 explicit RtpTransport(bool rtcp_mux_enabled)
37 : rtcp_mux_enabled_(rtcp_mux_enabled) {}
zsteind48dbda2017-04-04 19:45:57 -070038
Zhi Huangf2d7beb2017-11-20 14:35:11 -080039 bool rtcp_mux_enabled() const override { return rtcp_mux_enabled_; }
zstein398c3fd2017-07-19 13:38:02 -070040 void SetRtcpMuxEnabled(bool enable) override;
zsteind48dbda2017-04-04 19:45:57 -070041
zstein398c3fd2017-07-19 13:38:02 -070042 rtc::PacketTransportInternal* rtp_packet_transport() const override {
zsteind48dbda2017-04-04 19:45:57 -070043 return rtp_packet_transport_;
44 }
zstein398c3fd2017-07-19 13:38:02 -070045 void SetRtpPacketTransport(rtc::PacketTransportInternal* rtp) override;
zsteind48dbda2017-04-04 19:45:57 -070046
zstein398c3fd2017-07-19 13:38:02 -070047 rtc::PacketTransportInternal* rtcp_packet_transport() const override {
zsteind48dbda2017-04-04 19:45:57 -070048 return rtcp_packet_transport_;
49 }
zstein398c3fd2017-07-19 13:38:02 -070050 void SetRtcpPacketTransport(rtc::PacketTransportInternal* rtcp) override;
zsteind48dbda2017-04-04 19:45:57 -070051
zsteind9ce7642017-04-10 16:17:57 -070052 PacketTransportInterface* GetRtpPacketTransport() const override;
53 PacketTransportInterface* GetRtcpPacketTransport() const override;
54
55 // TODO(zstein): Use these RtcpParameters for configuration elsewhere.
sprangdb2a9fc2017-08-09 06:42:32 -070056 RTCError SetParameters(const RtpTransportParameters& parameters) override;
57 RtpTransportParameters GetParameters() const override;
zsteind9ce7642017-04-10 16:17:57 -070058
zstein398c3fd2017-07-19 13:38:02 -070059 bool IsWritable(bool rtcp) const override;
zstein56162b92017-04-24 16:54:35 -070060
Zhi Huangcf990f52017-09-22 12:12:30 -070061 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;
zstein56162b92017-04-24 16:54:35 -070068
zstein398c3fd2017-07-19 13:38:02 -070069 bool HandlesPayloadType(int payload_type) const override;
zstein3dcf0e92017-06-01 13:22:42 -070070
zstein398c3fd2017-07-19 13:38:02 -070071 void AddHandledPayloadType(int payload_type) override;
zstein3dcf0e92017-06-01 13:22:42 -070072
zsteind9ce7642017-04-10 16:17:57 -070073 protected:
74 // TODO(zstein): Remove this when we remove RtpTransportAdapter.
75 RtpTransportAdapter* GetInternal() override;
76
zsteind48dbda2017-04-04 19:45:57 -070077 private:
zstein3dcf0e92017-06-01 13:22:42 -070078 bool HandlesPacket(const uint8_t* data, size_t len);
79
zstein56162b92017-04-24 16:54:35 -070080 void OnReadyToSend(rtc::PacketTransportInternal* transport);
Zhi Huang942bc2e2017-11-13 13:26:07 -080081 void OnNetworkRouteChange(rtc::Optional<rtc::NetworkRoute> network_route);
zstein56162b92017-04-24 16:54:35 -070082
83 // Updates "ready to send" for an individual channel and fires
84 // SignalReadyToSend.
85 void SetReadyToSend(bool rtcp, bool ready);
86
87 void MaybeSignalReadyToSend();
88
Zhi Huangcf990f52017-09-22 12:12:30 -070089 bool SendPacket(bool rtcp,
90 rtc::CopyOnWriteBuffer* packet,
91 const rtc::PacketOptions& options,
92 int flags);
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
sprangdb2a9fc2017-08-09 06:42:32 -0700111 RtpTransportParameters 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200118#endif // PC_RTPTRANSPORT_H_