blob: 6d5d4bff57377c2275f2f9ae1af260c47ee47fa0 [file] [log] [blame]
zsteind48dbda2017-04-05 02:45:571/*
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_H_
12#define PC_RTP_TRANSPORT_H_
zsteind48dbda2017-04-05 02:45:5713
Harald Alvestrand5761e7b2021-01-29 14:45:0814#include <stddef.h>
15#include <stdint.h>
16
Zhi Huang942bc2e2017-11-13 21:26:0717#include <string>
18
Harald Alvestrand5761e7b2021-01-29 14:45:0819#include "absl/types/optional.h"
Harald Alvestrand83894d32023-09-26 19:38:1920#include "api/task_queue/pending_task_safety_flag.h"
Zhi Huang365381f2018-04-13 23:44:3421#include "call/rtp_demuxer.h"
Harald Alvestrandc24a2182022-02-23 13:44:5922#include "call/video_receive_stream.h"
Zhi Huang365381f2018-04-13 23:44:3423#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0824#include "p2p/base/packet_transport_internal.h"
Steve Anton10542f22019-01-11 17:11:0025#include "pc/rtp_transport_internal.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0826#include "pc/session_description.h"
27#include "rtc_base/async_packet_socket.h"
28#include "rtc_base/copy_on_write_buffer.h"
29#include "rtc_base/network/sent_packet.h"
30#include "rtc_base/network_route.h"
31#include "rtc_base/socket.h"
zsteind9ce7642017-04-10 23:17:5732
zsteind48dbda2017-04-05 02:45:5733namespace rtc {
34
zstein56162b92017-04-24 23:54:3535class CopyOnWriteBuffer;
36struct PacketOptions;
zsteind48dbda2017-04-05 02:45:5737class PacketTransportInternal;
38
39} // namespace rtc
40
41namespace webrtc {
42
zstein398c3fd2017-07-19 20:38:0243class RtpTransport : public RtpTransportInternal {
zsteind48dbda2017-04-05 02:45:5744 public:
45 RtpTransport(const RtpTransport&) = delete;
46 RtpTransport& operator=(const RtpTransport&) = delete;
47
zstein56162b92017-04-24 23:54:3548 explicit RtpTransport(bool rtcp_mux_enabled)
49 : rtcp_mux_enabled_(rtcp_mux_enabled) {}
zsteind48dbda2017-04-05 02:45:5750
Zhi Huangf2d7beb2017-11-20 22:35:1151 bool rtcp_mux_enabled() const override { return rtcp_mux_enabled_; }
zstein398c3fd2017-07-19 20:38:0252 void SetRtcpMuxEnabled(bool enable) override;
zsteind48dbda2017-04-05 02:45:5753
Bjorn A Mellem3a1b9272019-05-24 23:13:0854 const std::string& transport_name() const override;
55
56 int SetRtpOption(rtc::Socket::Option opt, int value) override;
57 int SetRtcpOption(rtc::Socket::Option opt, int value) override;
58
59 rtc::PacketTransportInternal* rtp_packet_transport() const {
zsteind48dbda2017-04-05 02:45:5760 return rtp_packet_transport_;
61 }
Bjorn A Mellem3a1b9272019-05-24 23:13:0862 void SetRtpPacketTransport(rtc::PacketTransportInternal* rtp);
zsteind48dbda2017-04-05 02:45:5763
Bjorn A Mellem3a1b9272019-05-24 23:13:0864 rtc::PacketTransportInternal* rtcp_packet_transport() const {
zsteind48dbda2017-04-05 02:45:5765 return rtcp_packet_transport_;
66 }
Bjorn A Mellem3a1b9272019-05-24 23:13:0867 void SetRtcpPacketTransport(rtc::PacketTransportInternal* rtcp);
zsteind48dbda2017-04-05 02:45:5768
Zhi Huange830e682018-03-30 17:48:3569 bool IsReadyToSend() const override { return ready_to_send_; }
70
zstein398c3fd2017-07-19 20:38:0271 bool IsWritable(bool rtcp) const override;
zstein56162b92017-04-24 23:54:3572
Zhi Huangcf990f52017-09-22 19:12:3073 bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet,
74 const rtc::PacketOptions& options,
75 int flags) override;
76
77 bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet,
78 const rtc::PacketOptions& options,
79 int flags) override;
zstein56162b92017-04-24 23:54:3580
Zhi Huange830e682018-03-30 17:48:3581 bool IsSrtpActive() const override { return false; }
zstein3dcf0e92017-06-01 20:22:4282
Zhi Huang365381f2018-04-13 23:44:3483 void UpdateRtpHeaderExtensionMap(
84 const cricket::RtpHeaderExtensions& header_extensions) override;
85
86 bool RegisterRtpDemuxerSink(const RtpDemuxerCriteria& criteria,
87 RtpPacketSinkInterface* sink) override;
88
89 bool UnregisterRtpDemuxerSink(RtpPacketSinkInterface* sink) override;
90
zsteind9ce7642017-04-10 23:17:5791 protected:
Zhi Huang365381f2018-04-13 23:44:3492 // These methods will be used in the subclasses.
Amit Hilbuchedd20542019-03-18 19:33:4393 void DemuxPacket(rtc::CopyOnWriteBuffer packet, int64_t packet_time_us);
Zhi Huang95e7dbb2018-03-29 00:08:0394
Zhi Huang365381f2018-04-13 23:44:3495 bool SendPacket(bool rtcp,
96 rtc::CopyOnWriteBuffer* packet,
97 const rtc::PacketOptions& options,
98 int flags);
Philipp Hancke977b56c2023-11-08 09:20:5199 flat_set<uint32_t> GetSsrcsForSink(RtpPacketSinkInterface* sink);
Zhi Huang365381f2018-04-13 23:44:34100
101 // Overridden by SrtpTransport.
102 virtual void OnNetworkRouteChanged(
Danil Chapovalov66cadcc2018-06-19 14:47:43103 absl::optional<rtc::NetworkRoute> network_route);
Amit Hilbuchedd20542019-03-18 19:33:43104 virtual void OnRtpPacketReceived(rtc::CopyOnWriteBuffer packet,
Niels Möllere6933812018-11-05 12:01:41105 int64_t packet_time_us);
Amit Hilbuchedd20542019-03-18 19:33:43106 virtual void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer packet,
Niels Möllere6933812018-11-05 12:01:41107 int64_t packet_time_us);
Zhi Huang365381f2018-04-13 23:44:34108 // Overridden by SrtpTransport and DtlsSrtpTransport.
109 virtual void OnWritableState(rtc::PacketTransportInternal* packet_transport);
110
111 private:
zstein56162b92017-04-24 23:54:35112 void OnReadyToSend(rtc::PacketTransportInternal* transport);
Zhi Huangcd3fc5d2017-11-29 18:41:57113 void OnSentPacket(rtc::PacketTransportInternal* packet_transport,
114 const rtc::SentPacket& sent_packet);
Zhi Huang365381f2018-04-13 23:44:34115 void OnReadPacket(rtc::PacketTransportInternal* transport,
116 const char* data,
117 size_t len,
Niels Möllere6933812018-11-05 12:01:41118 const int64_t& packet_time_us,
Zhi Huang365381f2018-04-13 23:44:34119 int flags);
zstein56162b92017-04-24 23:54:35120
121 // Updates "ready to send" for an individual channel and fires
122 // SignalReadyToSend.
123 void SetReadyToSend(bool rtcp, bool ready);
124
125 void MaybeSignalReadyToSend();
126
Zhi Huang365381f2018-04-13 23:44:34127 bool IsTransportWritable();
Zhi Huang95e7dbb2018-03-29 00:08:03128
zstein56162b92017-04-24 23:54:35129 bool rtcp_mux_enabled_;
zsteind48dbda2017-04-05 02:45:57130
zsteind48dbda2017-04-05 02:45:57131 rtc::PacketTransportInternal* rtp_packet_transport_ = nullptr;
132 rtc::PacketTransportInternal* rtcp_packet_transport_ = nullptr;
zsteind9ce7642017-04-10 23:17:57133
zstein56162b92017-04-24 23:54:35134 bool ready_to_send_ = false;
135 bool rtp_ready_to_send_ = false;
136 bool rtcp_ready_to_send_ = false;
137
Zhi Huang365381f2018-04-13 23:44:34138 RtpDemuxer rtp_demuxer_;
139
140 // Used for identifying the MID for RtpDemuxer.
141 RtpHeaderExtensionMap header_extension_map_;
Harald Alvestrand83894d32023-09-26 19:38:19142 // Guard against recursive "ready to send" signals
143 bool processing_ready_to_send_ = false;
Harald Alvestrand2931ddd2023-11-03 15:30:17144 bool processing_sent_packet_ = false;
Harald Alvestrand83894d32023-09-26 19:38:19145 ScopedTaskSafety safety_;
zsteind48dbda2017-04-05 02:45:57146};
147
148} // namespace webrtc
149
Steve Anton10542f22019-01-11 17:11:00150#endif // PC_RTP_TRANSPORT_H_