blob: 90537dd4ea6b07aa67519064634cfaf19e0a017c [file] [log] [blame]
zstein398c3fd2017-07-19 20:38:021/*
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
Steve Anton10542f22019-01-11 17:11:0011#ifndef PC_RTP_TRANSPORT_INTERNAL_H_
12#define PC_RTP_TRANSPORT_INTERNAL_H_
zstein398c3fd2017-07-19 20:38:0213
Zhi Huang942bc2e2017-11-13 21:26:0714#include <string>
Harald Alvestrandff281aa2023-09-05 09:49:3215#include <utility>
Zhi Huang942bc2e2017-11-13 21:26:0716
Zhi Huang365381f2018-04-13 23:44:3417#include "call/rtp_demuxer.h"
Steve Anton10542f22019-01-11 17:11:0018#include "p2p/base/ice_transport_internal.h"
19#include "pc/session_description.h"
Harald Alvestrandff281aa2023-09-05 09:49:3220#include "rtc_base/callback_list.h"
Steve Anton10542f22019-01-11 17:11:0021#include "rtc_base/network_route.h"
22#include "rtc_base/ssl_stream_adapter.h"
zstein398c3fd2017-07-19 20:38:0223
24namespace rtc {
25class CopyOnWriteBuffer;
26struct PacketOptions;
zstein398c3fd2017-07-19 20:38:0227} // namespace rtc
28
29namespace webrtc {
30
Yaowen Guofe911292022-06-01 10:57:0431// This class is an internal interface; it is not accessible to API consumers
32// but is accessible to internal classes in order to send and receive RTP and
33// RTCP packets belonging to a single RTP session. Additional convenience and
34// configuration methods are also provided.
Bjorn A Mellem34cd4852019-05-24 17:13:1035class RtpTransportInternal : public sigslot::has_slots<> {
zstein398c3fd2017-07-19 20:38:0236 public:
Bjorn A Mellem34cd4852019-05-24 17:13:1037 virtual ~RtpTransportInternal() = default;
38
zstein398c3fd2017-07-19 20:38:0239 virtual void SetRtcpMuxEnabled(bool enable) = 0;
40
Bjorn A Mellem3a1b9272019-05-24 23:13:0841 virtual const std::string& transport_name() const = 0;
42
43 // Sets socket options on the underlying RTP or RTCP transports.
44 virtual int SetRtpOption(rtc::Socket::Option opt, int value) = 0;
45 virtual int SetRtcpOption(rtc::Socket::Option opt, int value) = 0;
46
Zhi Huangf2d7beb2017-11-20 22:35:1147 virtual bool rtcp_mux_enabled() const = 0;
zstein398c3fd2017-07-19 20:38:0248
Zhi Huange830e682018-03-30 17:48:3549 virtual bool IsReadyToSend() const = 0;
50
zstein398c3fd2017-07-19 20:38:0251 // Called whenever a transport's ready-to-send state changes. The argument
52 // is true if all used transports are ready to send. This is more specific
53 // than just "writable"; it means the last send didn't return ENOTCONN.
Harald Alvestrandff281aa2023-09-05 09:49:3254 void SubscribeReadyToSend(const void* tag,
55 absl::AnyInvocable<void(bool)> callback) {
56 callback_list_ready_to_send_.AddReceiver(tag, std::move(callback));
57 }
58 void UnsubscribeReadyToSend(const void* tag) {
59 callback_list_ready_to_send_.RemoveReceivers(tag);
60 }
zstein398c3fd2017-07-19 20:38:0261
Zhi Huang365381f2018-04-13 23:44:3462 // Called whenever an RTCP packet is received. There is no equivalent signal
Per Ke1e94ad2023-03-30 14:53:5963 // for demuxable RTP packets because they would be forwarded to the
64 // BaseChannel through the RtpDemuxer callback.
Harald Alvestrandff281aa2023-09-05 09:49:3265 void SubscribeRtcpPacketReceived(
66 const void* tag,
67 absl::AnyInvocable<void(rtc::CopyOnWriteBuffer*, int64_t)> callback) {
68 callback_list_rtcp_packet_received_.AddReceiver(tag, std::move(callback));
69 }
70 // There doesn't seem to be a need to unsubscribe from this signal.
zstein398c3fd2017-07-19 20:38:0271
Per Ke1e94ad2023-03-30 14:53:5972 // Called whenever a RTP packet that can not be demuxed by the transport is
73 // received.
Harald Alvestrandff281aa2023-09-05 09:49:3274 void SetUnDemuxableRtpPacketReceivedHandler(
Harald Alvestranda6544372023-11-13 09:33:5675 absl::AnyInvocable<void(RtpPacketReceived&)> callback) {
Harald Alvestrandff281aa2023-09-05 09:49:3276 callback_undemuxable_rtp_packet_received_ = std::move(callback);
77 }
Per Ke1e94ad2023-03-30 14:53:5978
Zhi Huangcd3fc5d2017-11-29 18:41:5779 // Called whenever the network route of the P2P layer transport changes.
80 // The argument is an optional network route.
Harald Alvestrandff281aa2023-09-05 09:49:3281 void SubscribeNetworkRouteChanged(
82 const void* tag,
Florent Castelli8037fc62024-08-29 13:00:4083 absl::AnyInvocable<void(std::optional<rtc::NetworkRoute>)> callback) {
Harald Alvestrandff281aa2023-09-05 09:49:3284 callback_list_network_route_changed_.AddReceiver(tag, std::move(callback));
85 }
86 void UnsubscribeNetworkRouteChanged(const void* tag) {
87 callback_list_network_route_changed_.RemoveReceivers(tag);
88 }
Zhi Huangcd3fc5d2017-11-29 18:41:5789
Zhi Huangf2d7beb2017-11-20 22:35:1190 // Called whenever a transport's writable state might change. The argument is
91 // true if the transport is writable, otherwise it is false.
Harald Alvestrandff281aa2023-09-05 09:49:3292 void SubscribeWritableState(const void* tag,
93 absl::AnyInvocable<void(bool)> callback) {
94 callback_list_writable_state_.AddReceiver(tag, std::move(callback));
95 }
96 void UnsubscribeWritableState(const void* tag) {
97 callback_list_writable_state_.RemoveReceivers(tag);
98 }
99 void SubscribeSentPacket(
100 const void* tag,
101 absl::AnyInvocable<void(const rtc::SentPacket&)> callback) {
102 callback_list_sent_packet_.AddReceiver(tag, std::move(callback));
103 }
104 void UnsubscribeSentPacket(const void* tag) {
105 callback_list_sent_packet_.RemoveReceivers(tag);
106 }
Zhi Huang942bc2e2017-11-13 21:26:07107
zstein398c3fd2017-07-19 20:38:02108 virtual bool IsWritable(bool rtcp) const = 0;
109
Artem Titov880fa812021-07-30 20:30:23110 // TODO(zhihuang): Pass the `packet` by copy so that the original data
Zhi Huangf2d7beb2017-11-20 22:35:11111 // wouldn't be modified.
Zhi Huangcf990f52017-09-22 19:12:30112 virtual bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet,
113 const rtc::PacketOptions& options,
114 int flags) = 0;
115
116 virtual bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet,
117 const rtc::PacketOptions& options,
118 int flags) = 0;
zstein398c3fd2017-07-19 20:38:02119
Zhi Huang365381f2018-04-13 23:44:34120 // This method updates the RTP header extension map so that the RTP transport
121 // can parse the received packets and identify the MID. This is called by the
122 // BaseChannel when setting the content description.
123 //
124 // TODO(zhihuang): Merging and replacing following methods handling header
125 // extensions with SetParameters:
126 // UpdateRtpHeaderExtensionMap,
127 // UpdateSendEncryptedHeaderExtensionIds,
128 // UpdateRecvEncryptedHeaderExtensionIds,
129 // CacheRtpAbsSendTimeHeaderExtension,
130 virtual void UpdateRtpHeaderExtensionMap(
131 const cricket::RtpHeaderExtensions& header_extensions) = 0;
132
Zhi Huange830e682018-03-30 17:48:35133 virtual bool IsSrtpActive() const = 0;
Steve Antondb67ba12018-03-20 00:41:42134
Zhi Huang365381f2018-04-13 23:44:34135 virtual bool RegisterRtpDemuxerSink(const RtpDemuxerCriteria& criteria,
136 RtpPacketSinkInterface* sink) = 0;
137
138 virtual bool UnregisterRtpDemuxerSink(RtpPacketSinkInterface* sink) = 0;
Harald Alvestrandff281aa2023-09-05 09:49:32139
140 protected:
141 void SendReadyToSend(bool arg) { callback_list_ready_to_send_.Send(arg); }
142 void SendRtcpPacketReceived(rtc::CopyOnWriteBuffer* buffer,
143 int64_t packet_time_us) {
144 callback_list_rtcp_packet_received_.Send(buffer, packet_time_us);
145 }
146 void NotifyUnDemuxableRtpPacketReceived(RtpPacketReceived& packet) {
147 callback_undemuxable_rtp_packet_received_(packet);
148 }
Florent Castelli8037fc62024-08-29 13:00:40149 void SendNetworkRouteChanged(std::optional<rtc::NetworkRoute> route) {
Harald Alvestrandff281aa2023-09-05 09:49:32150 callback_list_network_route_changed_.Send(route);
151 }
152 void SendWritableState(bool state) {
153 callback_list_writable_state_.Send(state);
154 }
155 void SendSentPacket(const rtc::SentPacket& packet) {
156 callback_list_sent_packet_.Send(packet);
157 }
158
159 private:
160 CallbackList<bool> callback_list_ready_to_send_;
161 CallbackList<rtc::CopyOnWriteBuffer*, int64_t>
162 callback_list_rtcp_packet_received_;
Harald Alvestranda6544372023-11-13 09:33:56163 absl::AnyInvocable<void(RtpPacketReceived&)>
Harald Alvestrandff281aa2023-09-05 09:49:32164 callback_undemuxable_rtp_packet_received_ =
165 [](RtpPacketReceived& packet) {};
Florent Castelli8037fc62024-08-29 13:00:40166 CallbackList<std::optional<rtc::NetworkRoute>>
Harald Alvestrandff281aa2023-09-05 09:49:32167 callback_list_network_route_changed_;
168 CallbackList<bool> callback_list_writable_state_;
169 CallbackList<const rtc::SentPacket&> callback_list_sent_packet_;
zstein398c3fd2017-07-19 20:38:02170};
171
172} // namespace webrtc
173
Steve Anton10542f22019-01-11 17:11:00174#endif // PC_RTP_TRANSPORT_INTERNAL_H_