blob: deb315dcf6513d0842806be3b8da5cc914311cf2 [file] [log] [blame]
Bjorn A Mellem44bd71c2019-05-28 15:25:38 -07001/*
2 * Copyright 2019 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_COMPOSITE_RTP_TRANSPORT_H_
12#define PC_COMPOSITE_RTP_TRANSPORT_H_
13
14#include <memory>
15#include <string>
16#include <vector>
17
18#include "call/rtp_demuxer.h"
19#include "call/rtp_packet_sink_interface.h"
20#include "pc/rtp_transport_internal.h"
21#include "pc/session_description.h"
22#include "rtc_base/async_packet_socket.h"
23#include "rtc_base/copy_on_write_buffer.h"
24
25namespace webrtc {
26
27// Composite RTP transport capable of receiving from multiple sub-transports.
28//
29// CompositeRtpTransport is receive-only until the caller explicitly chooses
30// which transport will be used to send and calls |SetSendTransport|. This
31// choice must be made as part of the SDP negotiation process, based on receipt
32// of a provisional answer. |CompositeRtpTransport| does not become writable or
33// ready to send until |SetSendTransport| is called.
34//
35// When a full answer is received, the user should replace the composite
36// transport with the single, chosen RTP transport, then delete the composite
37// and all non-chosen transports.
38class CompositeRtpTransport : public RtpTransportInternal {
39 public:
40 // Constructs a composite out of the given |transports|. |transports| must
41 // not be empty. All |transports| must outlive the composite.
42 explicit CompositeRtpTransport(std::vector<RtpTransportInternal*> transports);
43
44 // Sets which transport will be used for sending packets. Once called,
45 // |IsReadyToSend|, |IsWritable|, and the associated signals will reflect the
46 // state of |send_tranpsort|.
47 void SetSendTransport(RtpTransportInternal* send_transport);
48
49 // All transports within a composite must have the same name.
50 const std::string& transport_name() const override;
51
52 int SetRtpOption(rtc::Socket::Option opt, int value) override;
53 int SetRtcpOption(rtc::Socket::Option opt, int value) override;
54
55 // All transports within a composite must either enable or disable RTCP mux.
56 bool rtcp_mux_enabled() const override;
57
58 // Enables or disables RTCP mux for all component transports.
59 void SetRtcpMuxEnabled(bool enabled) override;
60
61 // The composite is ready to send if |send_transport_| is set and ready to
62 // send.
63 bool IsReadyToSend() const override;
64
65 // The composite is writable if |send_transport_| is set and writable.
66 bool IsWritable(bool rtcp) const override;
67
68 // Sends an RTP packet. May only be called after |send_transport_| is set.
69 bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet,
70 const rtc::PacketOptions& options,
71 int flags) override;
72
73 // Sends an RTCP packet. May only be called after |send_transport_| is set.
74 bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet,
75 const rtc::PacketOptions& options,
76 int flags) override;
77
78 // Updates the mapping of RTP header extensions for all component transports.
79 void UpdateRtpHeaderExtensionMap(
80 const cricket::RtpHeaderExtensions& header_extensions) override;
81
82 // SRTP is only active for a composite if it is active for all component
83 // transports.
84 bool IsSrtpActive() const override;
85
86 // Registers an RTP demux sink with all component transports.
87 bool RegisterRtpDemuxerSink(const RtpDemuxerCriteria& criteria,
88 RtpPacketSinkInterface* sink) override;
89 bool UnregisterRtpDemuxerSink(RtpPacketSinkInterface* sink) override;
90
91 private:
92 // Receive-side signals.
93 void OnNetworkRouteChanged(absl::optional<rtc::NetworkRoute> route);
94 void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer* packet,
95 int64_t packet_time_us);
96
97 // Send-side signals.
98 void OnWritableState(bool writable);
99 void OnReadyToSend(bool ready_to_send);
100 void OnSentPacket(const rtc::SentPacket& packet);
101
102 std::vector<RtpTransportInternal*> transports_;
103 RtpTransportInternal* send_transport_ = nullptr;
Bjorn A Mellem44bd71c2019-05-28 15:25:38 -0700104};
105
106} // namespace webrtc
107
108#endif // PC_COMPOSITE_RTP_TRANSPORT_H_