Thanks to visit codestin.com
Credit goes to webrtc.googlesource.com

blob: a6df696f3162352f0857620eccdc821767a35f4a [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
Evan Shrubsoledaf96cf2025-03-31 12:34:0214#include <optional>
Zhi Huang942bc2e2017-11-13 21:26:0715#include <string>
Harald Alvestrandff281aa2023-09-05 09:49:3216#include <utility>
Zhi Huang942bc2e2017-11-13 21:26:0717
Evan Shrubsoledaf96cf2025-03-31 12:34:0218#include "absl/functional/any_invocable.h"
Harald Alvestrand4c450162025-10-09 15:22:5319#include "api/task_queue/pending_task_safety_flag.h"
Per K12103ce2025-11-12 16:04:4920#include "api/transport/ecn_marking.h"
21#include "api/units/timestamp.h"
Zhi Huang365381f2018-04-13 23:44:3422#include "call/rtp_demuxer.h"
Steve Anton10542f22019-01-11 17:11:0023#include "pc/session_description.h"
Philipp Hancke59927372025-08-01 16:43:3224#include "rtc_base/async_packet_socket.h"
Harald Alvestrandff281aa2023-09-05 09:49:3225#include "rtc_base/callback_list.h"
Evan Shrubsoledaf96cf2025-03-31 12:34:0226#include "rtc_base/copy_on_write_buffer.h"
27#include "rtc_base/network/sent_packet.h"
Steve Anton10542f22019-01-11 17:11:0028#include "rtc_base/network_route.h"
Evan Shrubsoledaf96cf2025-03-31 12:34:0229#include "rtc_base/socket.h"
zstein398c3fd2017-07-19 20:38:0230
zstein398c3fd2017-07-19 20:38:0231namespace webrtc {
32
Evan Shrubsolefe5bdd72025-02-07 13:24:0533class CopyOnWriteBuffer;
34
Yaowen Guofe911292022-06-01 10:57:0435// This class is an internal interface; it is not accessible to API consumers
36// but is accessible to internal classes in order to send and receive RTP and
37// RTCP packets belonging to a single RTP session. Additional convenience and
38// configuration methods are also provided.
Harald Alvestrandd9a01862025-11-03 23:05:2739class RtpTransportInternal {
zstein398c3fd2017-07-19 20:38:0240 public:
Bjorn A Mellem34cd4852019-05-24 17:13:1041 virtual ~RtpTransportInternal() = default;
42
zstein398c3fd2017-07-19 20:38:0243 virtual void SetRtcpMuxEnabled(bool enable) = 0;
44
Bjorn A Mellem3a1b9272019-05-24 23:13:0845 virtual const std::string& transport_name() const = 0;
46
47 // Sets socket options on the underlying RTP or RTCP transports.
Evan Shrubsole03b68802025-03-18 12:23:0548 virtual int SetRtpOption(Socket::Option opt, int value) = 0;
49 virtual int SetRtcpOption(Socket::Option opt, int value) = 0;
Bjorn A Mellem3a1b9272019-05-24 23:13:0850
Zhi Huangf2d7beb2017-11-20 22:35:1151 virtual bool rtcp_mux_enabled() const = 0;
zstein398c3fd2017-07-19 20:38:0252
Zhi Huange830e682018-03-30 17:48:3553 virtual bool IsReadyToSend() const = 0;
54
zstein398c3fd2017-07-19 20:38:0255 // Called whenever a transport's ready-to-send state changes. The argument
56 // is true if all used transports are ready to send. This is more specific
57 // than just "writable"; it means the last send didn't return ENOTCONN.
Harald Alvestrandff281aa2023-09-05 09:49:3258 void SubscribeReadyToSend(const void* tag,
59 absl::AnyInvocable<void(bool)> callback) {
60 callback_list_ready_to_send_.AddReceiver(tag, std::move(callback));
61 }
62 void UnsubscribeReadyToSend(const void* tag) {
63 callback_list_ready_to_send_.RemoveReceivers(tag);
64 }
zstein398c3fd2017-07-19 20:38:0265
Zhi Huang365381f2018-04-13 23:44:3466 // Called whenever an RTCP packet is received. There is no equivalent signal
Per Ke1e94ad2023-03-30 14:53:5967 // for demuxable RTP packets because they would be forwarded to the
68 // BaseChannel through the RtpDemuxer callback.
Harald Alvestrandff281aa2023-09-05 09:49:3269 void SubscribeRtcpPacketReceived(
70 const void* tag,
Per K12103ce2025-11-12 16:04:4971 absl::AnyInvocable<void(CopyOnWriteBuffer,
72 std::optional<Timestamp>,
73 EcnMarking)> callback) {
Harald Alvestrandff281aa2023-09-05 09:49:3274 callback_list_rtcp_packet_received_.AddReceiver(tag, std::move(callback));
75 }
76 // There doesn't seem to be a need to unsubscribe from this signal.
zstein398c3fd2017-07-19 20:38:0277
Per Ke1e94ad2023-03-30 14:53:5978 // Called whenever a RTP packet that can not be demuxed by the transport is
79 // received.
Harald Alvestrandff281aa2023-09-05 09:49:3280 void SetUnDemuxableRtpPacketReceivedHandler(
Harald Alvestranda6544372023-11-13 09:33:5681 absl::AnyInvocable<void(RtpPacketReceived&)> callback) {
Harald Alvestrandff281aa2023-09-05 09:49:3282 callback_undemuxable_rtp_packet_received_ = std::move(callback);
83 }
Per Ke1e94ad2023-03-30 14:53:5984
Zhi Huangcd3fc5d2017-11-29 18:41:5785 // Called whenever the network route of the P2P layer transport changes.
86 // The argument is an optional network route.
Harald Alvestrandff281aa2023-09-05 09:49:3287 void SubscribeNetworkRouteChanged(
88 const void* tag,
Evan Shrubsoledaf96cf2025-03-31 12:34:0289 absl::AnyInvocable<void(std::optional<webrtc::NetworkRoute>)> callback) {
Harald Alvestrandff281aa2023-09-05 09:49:3290 callback_list_network_route_changed_.AddReceiver(tag, std::move(callback));
91 }
92 void UnsubscribeNetworkRouteChanged(const void* tag) {
93 callback_list_network_route_changed_.RemoveReceivers(tag);
94 }
Zhi Huangcd3fc5d2017-11-29 18:41:5795
Zhi Huangf2d7beb2017-11-20 22:35:1196 // Called whenever a transport's writable state might change. The argument is
97 // true if the transport is writable, otherwise it is false.
Harald Alvestrandff281aa2023-09-05 09:49:3298 void SubscribeWritableState(const void* tag,
99 absl::AnyInvocable<void(bool)> callback) {
100 callback_list_writable_state_.AddReceiver(tag, std::move(callback));
101 }
102 void UnsubscribeWritableState(const void* tag) {
103 callback_list_writable_state_.RemoveReceivers(tag);
104 }
105 void SubscribeSentPacket(
106 const void* tag,
Evan Shrubsolee6a1f702025-04-15 14:55:42107 absl::AnyInvocable<void(const webrtc::SentPacketInfo&)> callback) {
Harald Alvestrandff281aa2023-09-05 09:49:32108 callback_list_sent_packet_.AddReceiver(tag, std::move(callback));
109 }
110 void UnsubscribeSentPacket(const void* tag) {
111 callback_list_sent_packet_.RemoveReceivers(tag);
112 }
Zhi Huang942bc2e2017-11-13 21:26:07113
zstein398c3fd2017-07-19 20:38:02114 virtual bool IsWritable(bool rtcp) const = 0;
115
Artem Titov880fa812021-07-30 20:30:23116 // TODO(zhihuang): Pass the `packet` by copy so that the original data
Zhi Huangf2d7beb2017-11-20 22:35:11117 // wouldn't be modified.
Evan Shrubsolee6a1f702025-04-15 14:55:42118 virtual bool SendRtpPacket(CopyOnWriteBuffer* packet,
119 const AsyncSocketPacketOptions& options,
Zhi Huangcf990f52017-09-22 19:12:30120 int flags) = 0;
121
Evan Shrubsolee6a1f702025-04-15 14:55:42122 virtual bool SendRtcpPacket(CopyOnWriteBuffer* packet,
123 const AsyncSocketPacketOptions& options,
Zhi Huangcf990f52017-09-22 19:12:30124 int flags) = 0;
zstein398c3fd2017-07-19 20:38:02125
Zhi Huang365381f2018-04-13 23:44:34126 // This method updates the RTP header extension map so that the RTP transport
127 // can parse the received packets and identify the MID. This is called by the
128 // BaseChannel when setting the content description.
129 //
130 // TODO(zhihuang): Merging and replacing following methods handling header
131 // extensions with SetParameters:
132 // UpdateRtpHeaderExtensionMap,
133 // UpdateSendEncryptedHeaderExtensionIds,
134 // UpdateRecvEncryptedHeaderExtensionIds,
135 // CacheRtpAbsSendTimeHeaderExtension,
136 virtual void UpdateRtpHeaderExtensionMap(
Evan Shrubsolee6a1f702025-04-15 14:55:42137 const RtpHeaderExtensions& header_extensions) = 0;
Zhi Huang365381f2018-04-13 23:44:34138
Zhi Huange830e682018-03-30 17:48:35139 virtual bool IsSrtpActive() const = 0;
Steve Antondb67ba12018-03-20 00:41:42140
Zhi Huang365381f2018-04-13 23:44:34141 virtual bool RegisterRtpDemuxerSink(const RtpDemuxerCriteria& criteria,
142 RtpPacketSinkInterface* sink) = 0;
143
144 virtual bool UnregisterRtpDemuxerSink(RtpPacketSinkInterface* sink) = 0;
Harald Alvestrandff281aa2023-09-05 09:49:32145
146 protected:
147 void SendReadyToSend(bool arg) { callback_list_ready_to_send_.Send(arg); }
Per K12103ce2025-11-12 16:04:49148 void SendRtcpPacketReceived(CopyOnWriteBuffer packet,
149 std::optional<Timestamp> arrival_time,
150 EcnMarking ecn) {
151 callback_list_rtcp_packet_received_.Send(packet, arrival_time, ecn);
Harald Alvestrandff281aa2023-09-05 09:49:32152 }
153 void NotifyUnDemuxableRtpPacketReceived(RtpPacketReceived& packet) {
154 callback_undemuxable_rtp_packet_received_(packet);
155 }
Evan Shrubsoledaf96cf2025-03-31 12:34:02156 void SendNetworkRouteChanged(std::optional<NetworkRoute> route) {
Harald Alvestrandff281aa2023-09-05 09:49:32157 callback_list_network_route_changed_.Send(route);
158 }
159 void SendWritableState(bool state) {
160 callback_list_writable_state_.Send(state);
161 }
Evan Shrubsolee6a1f702025-04-15 14:55:42162 void SendSentPacket(const SentPacketInfo& packet) {
Harald Alvestrandff281aa2023-09-05 09:49:32163 callback_list_sent_packet_.Send(packet);
164 }
165
166 private:
167 CallbackList<bool> callback_list_ready_to_send_;
Per K12103ce2025-11-12 16:04:49168 CallbackList<CopyOnWriteBuffer, std::optional<Timestamp>, EcnMarking>
169 callback_list_rtcp_packet_received_;
Harald Alvestranda6544372023-11-13 09:33:56170 absl::AnyInvocable<void(RtpPacketReceived&)>
Harald Alvestrandff281aa2023-09-05 09:49:32171 callback_undemuxable_rtp_packet_received_ =
172 [](RtpPacketReceived& packet) {};
Evan Shrubsoledaf96cf2025-03-31 12:34:02173 CallbackList<std::optional<NetworkRoute>>
Harald Alvestrandff281aa2023-09-05 09:49:32174 callback_list_network_route_changed_;
175 CallbackList<bool> callback_list_writable_state_;
Evan Shrubsolee6a1f702025-04-15 14:55:42176 CallbackList<const SentPacketInfo&> callback_list_sent_packet_;
Harald Alvestrand4c450162025-10-09 15:22:53177 ScopedTaskSafety safety_;
zstein398c3fd2017-07-19 20:38:02178};
179
180} // namespace webrtc
181
Steve Anton10542f22019-01-11 17:11:00182#endif // PC_RTP_TRANSPORT_INTERNAL_H_