[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 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. |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef PC_CHANNEL_H_ |
| 12 | #define PC_CHANNEL_H_ |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 14 | #include <map> |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 15 | #include <memory> |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 16 | #include <set> |
kjellander | a96e2d7 | 2016-02-05 07:52:28 | [diff] [blame] | 17 | #include <string> |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 18 | #include <utility> |
kjellander | a96e2d7 | 2016-02-05 07:52:28 | [diff] [blame] | 19 | #include <vector> |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 20 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 21 | #include "api/call/audio_sink.h" |
Danil Chapovalov | 8931345 | 2019-11-29 11:56:43 | [diff] [blame] | 22 | #include "api/function_view.h" |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 23 | #include "api/jsep.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 24 | #include "api/rtp_receiver_interface.h" |
Niels Möller | c6ce9c5 | 2018-05-11 09:15:30 | [diff] [blame] | 25 | #include "api/video/video_sink_interface.h" |
Niels Möller | 0327c2d | 2018-05-21 12:09:31 | [diff] [blame] | 26 | #include "api/video/video_source_interface.h" |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 27 | #include "call/rtp_packet_sink_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 28 | #include "media/base/media_channel.h" |
| 29 | #include "media/base/media_engine.h" |
| 30 | #include "media/base/stream_params.h" |
| 31 | #include "p2p/base/dtls_transport_internal.h" |
| 32 | #include "p2p/base/packet_transport_internal.h" |
| 33 | #include "pc/channel_interface.h" |
| 34 | #include "pc/dtls_srtp_transport.h" |
| 35 | #include "pc/media_session.h" |
| 36 | #include "pc/rtp_transport.h" |
| 37 | #include "pc/srtp_filter.h" |
| 38 | #include "pc/srtp_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 39 | #include "rtc_base/async_udp_socket.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 40 | #include "rtc_base/network.h" |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 41 | #include "rtc_base/synchronization/sequence_checker.h" |
Danil Chapovalov | fd9500e | 2021-01-15 16:29:53 | [diff] [blame] | 42 | #include "rtc_base/task_utils/pending_task_safety_flag.h" |
Artem Titov | e41c433 | 2018-07-25 13:04:28 | [diff] [blame] | 43 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 44 | #include "rtc_base/thread_annotations.h" |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 45 | #include "rtc_base/unique_id_generator.h" |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 46 | |
| 47 | namespace webrtc { |
| 48 | class AudioSinkInterface; |
| 49 | } // namespace webrtc |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 50 | |
| 51 | namespace cricket { |
| 52 | |
| 53 | struct CryptoParams; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 54 | |
deadbeef | 062ce9f | 2016-08-27 04:42:15 | [diff] [blame] | 55 | // BaseChannel contains logic common to voice and video, including enable, |
| 56 | // marshaling calls to a worker and network threads, and connection and media |
| 57 | // monitors. |
| 58 | // |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 59 | // BaseChannel assumes signaling and other threads are allowed to make |
| 60 | // synchronous calls to the worker thread, the worker thread makes synchronous |
| 61 | // calls only to the network thread, and the network thread can't be blocked by |
| 62 | // other threads. |
| 63 | // All methods with _n suffix must be called on network thread, |
deadbeef | 062ce9f | 2016-08-27 04:42:15 | [diff] [blame] | 64 | // methods with _w suffix on worker thread |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 65 | // and methods with _s suffix on signaling thread. |
| 66 | // Network and worker threads may be the same thread. |
[email protected] | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 67 | // |
| 68 | // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS! |
| 69 | // This is required to avoid a data race between the destructor modifying the |
| 70 | // vtable, and the media channel's thread using BaseChannel as the |
| 71 | // NetworkInterface. |
| 72 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 73 | class BaseChannel : public ChannelInterface, |
Tomas Gunnarsson | abdb470 | 2020-09-05 16:43:36 | [diff] [blame] | 74 | public rtc::MessageHandlerAutoCleanup, |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 75 | public sigslot::has_slots<>, |
| 76 | public MediaChannel::NetworkInterface, |
Bjorn A Mellem | 7a9a092 | 2019-11-26 17:19:40 | [diff] [blame] | 77 | public webrtc::RtpPacketSinkInterface { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 78 | public: |
deadbeef | 7af91dd | 2016-12-13 19:29:11 | [diff] [blame] | 79 | // If |srtp_required| is true, the channel will not send or receive any |
| 80 | // RTP/RTCP packets without using SRTP (either using SDES or DTLS-SRTP). |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 81 | // The BaseChannel does not own the UniqueRandomIdGenerator so it is the |
| 82 | // responsibility of the user to ensure it outlives this object. |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 83 | // TODO(zhihuang:) Create a BaseChannel::Config struct for the parameter lists |
| 84 | // which will make it easier to change the constructor. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 85 | BaseChannel(rtc::Thread* worker_thread, |
| 86 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 87 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 88 | std::unique_ptr<MediaChannel> media_channel, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 89 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 90 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 91 | webrtc::CryptoOptions crypto_options, |
| 92 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 93 | virtual ~BaseChannel(); |
Niels Möller | 2a70703 | 2020-06-16 14:39:13 | [diff] [blame] | 94 | virtual void Init_w(webrtc::RtpTransportInternal* rtp_transport); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 95 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 96 | // Deinit may be called multiple times and is simply ignored if it's already |
[email protected] | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 97 | // done. |
| 98 | void Deinit(); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 99 | |
[email protected] | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 100 | rtc::Thread* worker_thread() const { return worker_thread_; } |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 101 | rtc::Thread* network_thread() const { return network_thread_; } |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 102 | const std::string& content_name() const override { return content_name_; } |
deadbeef | f534659 | 2017-01-25 05:51:21 | [diff] [blame] | 103 | // TODO(deadbeef): This is redundant; remove this. |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 104 | const std::string& transport_name() const override { return transport_name_; } |
| 105 | bool enabled() const override { return enabled_; } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 106 | |
Zhi Huang | cf990f5 | 2017-09-22 19:12:30 | [diff] [blame] | 107 | // This function returns true if using SRTP (DTLS-based keying or SDES). |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 108 | bool srtp_active() const { |
Harald Alvestrand | 476859d | 2020-12-07 11:16:45 | [diff] [blame] | 109 | RTC_DCHECK_RUN_ON(network_thread()); |
| 110 | return rtp_transport_ && rtp_transport_->IsSrtpActive(); |
| 111 | } |
| 112 | |
| 113 | // Version of the above that can be called from any thread. |
| 114 | bool SrtpActiveForTesting() const { |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 115 | if (!network_thread_->IsCurrent()) { |
| 116 | return network_thread_->Invoke<bool>(RTC_FROM_HERE, |
| 117 | [this] { return srtp_active(); }); |
| 118 | } |
| 119 | RTC_DCHECK_RUN_ON(network_thread()); |
Harald Alvestrand | 476859d | 2020-12-07 11:16:45 | [diff] [blame] | 120 | return srtp_active(); |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 121 | } |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 122 | // Set an RTP level transport which could be an RtpTransport without |
| 123 | // encryption, an SrtpTransport for SDES or a DtlsSrtpTransport for DTLS-SRTP. |
| 124 | // This can be called from any thread and it hops to the network thread |
| 125 | // internally. It would replace the |SetTransports| and its variants. |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 126 | bool SetRtpTransport(webrtc::RtpTransportInternal* rtp_transport) override; |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 127 | |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 128 | webrtc::RtpTransportInternal* rtp_transport() const { |
Harald Alvestrand | 476859d | 2020-12-07 11:16:45 | [diff] [blame] | 129 | RTC_DCHECK_RUN_ON(network_thread()); |
| 130 | return rtp_transport_; |
| 131 | } |
| 132 | |
| 133 | // Version of the above that can be called from any thread. |
| 134 | webrtc::RtpTransportInternal* RtpTransportForTesting() const { |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 135 | if (!network_thread_->IsCurrent()) { |
| 136 | return network_thread_->Invoke<webrtc::RtpTransportInternal*>( |
| 137 | RTC_FROM_HERE, [this] { return rtp_transport(); }); |
| 138 | } |
| 139 | RTC_DCHECK_RUN_ON(network_thread()); |
Harald Alvestrand | 476859d | 2020-12-07 11:16:45 | [diff] [blame] | 140 | return rtp_transport(); |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 141 | } |
Bjorn A Mellem | 3a1b927 | 2019-05-24 23:13:08 | [diff] [blame] | 142 | |
Taylor Brandstetter | c1ad1ff | 2020-12-10 23:31:14 | [diff] [blame] | 143 | // Channel control. Must call UpdateRtpTransport afterwards to apply any |
| 144 | // changes to the RtpTransport on the network thread. |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 145 | bool SetLocalContent(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 146 | webrtc::SdpType type, |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 147 | std::string* error_desc) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 148 | bool SetRemoteContent(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 149 | webrtc::SdpType type, |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 150 | std::string* error_desc) override; |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 151 | // Controls whether this channel will receive packets on the basis of |
| 152 | // matching payload type alone. This is needed for legacy endpoints that |
| 153 | // don't signal SSRCs or use MID/RID, but doesn't make sense if there is |
| 154 | // more than channel of specific media type, As that creates an ambiguity. |
| 155 | // |
| 156 | // This method will also remove any existing streams that were bound to this |
| 157 | // channel on the basis of payload type, since one of these streams might |
| 158 | // actually belong to a new channel. See: crbug.com/webrtc/11477 |
Taylor Brandstetter | c1ad1ff | 2020-12-10 23:31:14 | [diff] [blame] | 159 | // |
| 160 | // As with SetLocalContent/SetRemoteContent, must call UpdateRtpTransport |
| 161 | // afterwards to apply changes to the RtpTransport on the network thread. |
| 162 | void SetPayloadTypeDemuxingEnabled(bool enabled) override; |
| 163 | bool UpdateRtpTransport(std::string* error_desc) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 164 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 165 | bool Enable(bool enable) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 166 | |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 167 | const std::vector<StreamParams>& local_streams() const override { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 168 | return local_streams_; |
| 169 | } |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 170 | const std::vector<StreamParams>& remote_streams() const override { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 171 | return remote_streams_; |
| 172 | } |
| 173 | |
[email protected] | 6bfd619 | 2014-05-15 16:15:59 | [diff] [blame] | 174 | // Used for latency measurements. |
Tomas Gunnarsson | b2995a1 | 2020-09-28 12:05:35 | [diff] [blame] | 175 | sigslot::signal1<ChannelInterface*>& SignalFirstPacketReceived() override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 176 | |
zhihuang | b2cdd93 | 2017-01-20 00:54:25 | [diff] [blame] | 177 | // Forward SignalSentPacket to worker thread. |
Tomas Gunnarsson | b2995a1 | 2020-09-28 12:05:35 | [diff] [blame] | 178 | sigslot::signal1<const rtc::SentPacket&>& SignalSentPacket(); |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 179 | |
zstein | 56162b9 | 2017-04-24 23:54:35 | [diff] [blame] | 180 | // From RtpTransport - public for testing only |
| 181 | void OnTransportReadyToSend(bool ready); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 182 | |
[email protected] | 4f85288 | 2015-03-12 20:09:44 | [diff] [blame] | 183 | // Only public for unit tests. Otherwise, consider protected. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 184 | int SetOption(SocketType type, rtc::Socket::Option o, int val) override; |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 185 | int SetOption_n(SocketType type, rtc::Socket::Option o, int val) |
| 186 | RTC_RUN_ON(network_thread()); |
[email protected] | 4f85288 | 2015-03-12 20:09:44 | [diff] [blame] | 187 | |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 188 | // RtpPacketSinkInterface overrides. |
| 189 | void OnRtpPacket(const webrtc::RtpPacketReceived& packet) override; |
zstein | 3dcf0e9 | 2017-06-01 20:22:42 | [diff] [blame] | 190 | |
Steve Anton | 593e325 | 2017-12-15 19:44:48 | [diff] [blame] | 191 | // Used by the RTCStatsCollector tests to set the transport name without |
| 192 | // creating RtpTransports. |
| 193 | void set_transport_name_for_testing(const std::string& transport_name) { |
| 194 | transport_name_ = transport_name; |
| 195 | } |
| 196 | |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 197 | MediaChannel* media_channel() const override { |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 198 | return media_channel_.get(); |
| 199 | } |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 200 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 201 | protected: |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 202 | bool was_ever_writable() const { |
Taylor Brandstetter | c1ad1ff | 2020-12-10 23:31:14 | [diff] [blame] | 203 | RTC_DCHECK_RUN_ON(worker_thread()); |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 204 | return was_ever_writable_; |
| 205 | } |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 206 | void set_local_content_direction(webrtc::RtpTransceiverDirection direction) { |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 207 | RTC_DCHECK_RUN_ON(worker_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 208 | local_content_direction_ = direction; |
| 209 | } |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 210 | void set_remote_content_direction(webrtc::RtpTransceiverDirection direction) { |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 211 | RTC_DCHECK_RUN_ON(worker_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 212 | remote_content_direction_ = direction; |
| 213 | } |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 214 | // These methods verify that: |
| 215 | // * The required content description directions have been set. |
| 216 | // * The channel is enabled. |
| 217 | // * And for sending: |
| 218 | // - The SRTP filter is active if it's needed. |
| 219 | // - The transport has been writable before, meaning it should be at least |
| 220 | // possible to succeed in sending a packet. |
| 221 | // |
| 222 | // When any of these properties change, UpdateMediaSendRecvState_w should be |
| 223 | // called. |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 224 | bool IsReadyToReceiveMedia_w() const RTC_RUN_ON(worker_thread()); |
| 225 | bool IsReadyToSendMedia_w() const RTC_RUN_ON(worker_thread()); |
Markus Handell | 5932fe1 | 2020-12-17 21:19:40 | [diff] [blame] | 226 | rtc::Thread* signaling_thread() const { return signaling_thread_; } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 227 | |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 228 | void FlushRtcpMessages_n() RTC_RUN_ON(network_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 229 | |
| 230 | // NetworkInterface implementation, called by MediaEngine |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 231 | bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
| 232 | const rtc::PacketOptions& options) override; |
| 233 | bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
| 234 | const rtc::PacketOptions& options) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 235 | |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 236 | // From RtpTransportInternal |
| 237 | void OnWritableState(bool writable); |
Guo-wei Shieh | 1218d7a | 2015-12-05 17:59:56 | [diff] [blame] | 238 | |
Danil Chapovalov | 66cadcc | 2018-06-19 14:47:43 | [diff] [blame] | 239 | void OnNetworkRouteChanged(absl::optional<rtc::NetworkRoute> network_route); |
Honghai Zhang | cc411c0 | 2016-03-30 00:27:21 | [diff] [blame] | 240 | |
deadbeef | 5bd5ca3 | 2017-02-10 19:31:50 | [diff] [blame] | 241 | bool PacketIsRtcp(const rtc::PacketTransportInternal* transport, |
johan | d89ab14 | 2016-10-25 17:50:32 | [diff] [blame] | 242 | const char* data, |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 243 | size_t len); |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 244 | bool SendPacket(bool rtcp, |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 245 | rtc::CopyOnWriteBuffer* packet, |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 246 | const rtc::PacketOptions& options); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 247 | |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 248 | void EnableMedia_w() RTC_RUN_ON(worker_thread()); |
| 249 | void DisableMedia_w() RTC_RUN_ON(worker_thread()); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 250 | |
| 251 | // Performs actions if the RTP/RTCP writable state changed. This should |
| 252 | // be called whenever a channel's writable state changes or when RTCP muxing |
| 253 | // becomes active/inactive. |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 254 | void UpdateWritableState_n() RTC_RUN_ON(network_thread()); |
| 255 | void ChannelWritable_n() RTC_RUN_ON(network_thread()); |
| 256 | void ChannelNotWritable_n() RTC_RUN_ON(network_thread()); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 257 | |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 258 | bool AddRecvStream_w(const StreamParams& sp) RTC_RUN_ON(worker_thread()); |
| 259 | bool RemoveRecvStream_w(uint32_t ssrc) RTC_RUN_ON(worker_thread()); |
| 260 | void ResetUnsignaledRecvStream_w() RTC_RUN_ON(worker_thread()); |
Taylor Brandstetter | c1ad1ff | 2020-12-10 23:31:14 | [diff] [blame] | 261 | void SetPayloadTypeDemuxingEnabled_w(bool enabled) |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 262 | RTC_RUN_ON(worker_thread()); |
| 263 | bool AddSendStream_w(const StreamParams& sp) RTC_RUN_ON(worker_thread()); |
| 264 | bool RemoveSendStream_w(uint32_t ssrc) RTC_RUN_ON(worker_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 265 | |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 266 | // Should be called whenever the conditions for |
| 267 | // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied). |
| 268 | // Updates the send/recv state of the media channel. |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 269 | virtual void UpdateMediaSendRecvState_w() = 0; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 270 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 271 | bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 272 | webrtc::SdpType type, |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 273 | std::string* error_desc) |
| 274 | RTC_RUN_ON(worker_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 275 | bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 276 | webrtc::SdpType type, |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 277 | std::string* error_desc) |
| 278 | RTC_RUN_ON(worker_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 279 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 280 | webrtc::SdpType type, |
[email protected] | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 281 | std::string* error_desc) = 0; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 282 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 283 | webrtc::SdpType type, |
[email protected] | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 284 | std::string* error_desc) = 0; |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 285 | // Return a list of RTP header extensions with the non-encrypted extensions |
| 286 | // removed depending on the current crypto_options_ and only if both the |
| 287 | // non-encrypted and encrypted extension is present for the same URI. |
| 288 | RtpHeaderExtensions GetFilteredRtpHeaderExtensions( |
| 289 | const RtpHeaderExtensions& extensions); |
Taylor Brandstetter | c1ad1ff | 2020-12-10 23:31:14 | [diff] [blame] | 290 | // Set a list of RTP extensions we should prepare to receive on the next |
| 291 | // UpdateRtpTransport call. |
| 292 | void SetReceiveExtensions(const RtpHeaderExtensions& extensions); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 293 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 294 | // From MessageHandler |
rlester | ec9d187 | 2015-10-27 21:22:16 | [diff] [blame] | 295 | void OnMessage(rtc::Message* pmsg) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 296 | |
stefan | f79ade1 | 2017-06-02 13:44:03 | [diff] [blame] | 297 | // Helper function template for invoking methods on the worker thread. |
Danil Chapovalov | 8931345 | 2019-11-29 11:56:43 | [diff] [blame] | 298 | template <class T> |
| 299 | T InvokeOnWorker(const rtc::Location& posted_from, |
| 300 | rtc::FunctionView<T()> functor) { |
stefan | f79ade1 | 2017-06-02 13:44:03 | [diff] [blame] | 301 | return worker_thread_->Invoke<T>(posted_from, functor); |
[email protected] | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 302 | } |
| 303 | |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 304 | // Add |payload_type| to |demuxer_criteria_| if payload type demuxing is |
| 305 | // enabled. |
| 306 | void MaybeAddHandledPayloadType(int payload_type) RTC_RUN_ON(worker_thread()); |
zstein | 3dcf0e9 | 2017-06-01 20:22:42 | [diff] [blame] | 307 | |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 308 | void ClearHandledPayloadTypes() RTC_RUN_ON(worker_thread()); |
Yura Yaroshevich | c325246 | 2020-05-18 10:26:14 | [diff] [blame] | 309 | // Return description of media channel to facilitate logging |
| 310 | std::string ToString() const; |
| 311 | |
Markus Handell | 5932fe1 | 2020-12-17 21:19:40 | [diff] [blame] | 312 | void SetNegotiatedHeaderExtensions_w(const RtpHeaderExtensions& extensions); |
| 313 | |
| 314 | // ChannelInterface overrides |
| 315 | RtpHeaderExtensions GetNegotiatedRtpHeaderExtensions() const override; |
| 316 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 317 | private: |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 318 | bool ConnectToRtpTransport(); |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 319 | void DisconnectFromRtpTransport(); |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 320 | void SignalSentPacket_n(const rtc::SentPacket& sent_packet) |
| 321 | RTC_RUN_ON(network_thread()); |
Piotr (Peter) Slatala | 179a392 | 2018-11-16 17:57:58 | [diff] [blame] | 322 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 323 | rtc::Thread* const worker_thread_; |
| 324 | rtc::Thread* const network_thread_; |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 325 | rtc::Thread* const signaling_thread_; |
Danil Chapovalov | fd9500e | 2021-01-15 16:29:53 | [diff] [blame] | 326 | rtc::scoped_refptr<webrtc::PendingTaskSafetyFlag> alive_; |
Tomas Gunnarsson | b2995a1 | 2020-09-28 12:05:35 | [diff] [blame] | 327 | sigslot::signal1<ChannelInterface*> SignalFirstPacketReceived_ |
| 328 | RTC_GUARDED_BY(signaling_thread_); |
| 329 | sigslot::signal1<const rtc::SentPacket&> SignalSentPacket_ |
| 330 | RTC_GUARDED_BY(worker_thread_); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 331 | |
[email protected] | 990a00c | 2015-03-13 18:20:33 | [diff] [blame] | 332 | const std::string content_name_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 333 | |
Tomas Gunnarsson | 33c0ab4 | 2021-01-18 09:49:05 | [diff] [blame^] | 334 | bool has_received_packet_ = false; |
| 335 | |
deadbeef | f534659 | 2017-01-25 05:51:21 | [diff] [blame] | 336 | // Won't be set when using raw packet transports. SDP-specific thing. |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 337 | // TODO(bugs.webrtc.org/12230): Written on network thread, read on |
| 338 | // worker thread (at least). |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 339 | std::string transport_name_; |
zhihuang | b2cdd93 | 2017-01-20 00:54:25 | [diff] [blame] | 340 | |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 341 | webrtc::RtpTransportInternal* rtp_transport_ |
| 342 | RTC_GUARDED_BY(network_thread()) = nullptr; |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 343 | |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 344 | std::vector<std::pair<rtc::Socket::Option, int> > socket_options_ |
| 345 | RTC_GUARDED_BY(network_thread()); |
| 346 | std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_ |
| 347 | RTC_GUARDED_BY(network_thread()); |
Taylor Brandstetter | c1ad1ff | 2020-12-10 23:31:14 | [diff] [blame] | 348 | bool writable_ RTC_GUARDED_BY(network_thread()) = false; |
| 349 | bool was_ever_writable_n_ RTC_GUARDED_BY(network_thread()) = false; |
| 350 | bool was_ever_writable_ RTC_GUARDED_BY(worker_thread()) = false; |
deadbeef | 7af91dd | 2016-12-13 19:29:11 | [diff] [blame] | 351 | const bool srtp_required_ = true; |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 352 | const webrtc::CryptoOptions crypto_options_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 353 | |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 354 | // MediaChannel related members that should be accessed from the worker |
| 355 | // thread. |
Harald Alvestrand | 0f0bcb3 | 2020-12-07 11:45:55 | [diff] [blame] | 356 | const std::unique_ptr<MediaChannel> media_channel_; |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 357 | // Currently the |enabled_| flag is accessed from the signaling thread as |
| 358 | // well, but it can be changed only when signaling thread does a synchronous |
| 359 | // call to the worker thread, so it should be safe. |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 360 | bool enabled_ = false; |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 361 | bool payload_type_demuxing_enabled_ RTC_GUARDED_BY(worker_thread()) = true; |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 362 | std::vector<StreamParams> local_streams_ RTC_GUARDED_BY(worker_thread()); |
| 363 | std::vector<StreamParams> remote_streams_ RTC_GUARDED_BY(worker_thread()); |
| 364 | // TODO(bugs.webrtc.org/12230): local_content_direction and |
| 365 | // remote_content_direction are set on the worker thread, but accessed on the |
| 366 | // network thread. |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 367 | webrtc::RtpTransceiverDirection local_content_direction_ = |
| 368 | webrtc::RtpTransceiverDirection::kInactive; |
| 369 | webrtc::RtpTransceiverDirection remote_content_direction_ = |
| 370 | webrtc::RtpTransceiverDirection::kInactive; |
Zhi Huang | c99b6c7 | 2017-11-11 00:44:46 | [diff] [blame] | 371 | |
Taylor Brandstetter | d3ef499 | 2020-10-16 01:22:57 | [diff] [blame] | 372 | // Cached list of payload types, used if payload type demuxing is re-enabled. |
| 373 | std::set<uint8_t> payload_types_ RTC_GUARDED_BY(worker_thread()); |
Taylor Brandstetter | c1ad1ff | 2020-12-10 23:31:14 | [diff] [blame] | 374 | // TODO(bugs.webrtc.org/12239): These two variables are modified on the worker |
| 375 | // thread, accessed on the network thread in UpdateRtpTransport. |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 376 | webrtc::RtpDemuxerCriteria demuxer_criteria_; |
Taylor Brandstetter | c1ad1ff | 2020-12-10 23:31:14 | [diff] [blame] | 377 | RtpHeaderExtensions receive_rtp_header_extensions_; |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 378 | // This generator is used to generate SSRCs for local streams. |
| 379 | // This is needed in cases where SSRCs are not negotiated or set explicitly |
| 380 | // like in Simulcast. |
| 381 | // This object is not owned by the channel so it must outlive it. |
| 382 | rtc::UniqueRandomIdGenerator* const ssrc_generator_; |
Markus Handell | 5932fe1 | 2020-12-17 21:19:40 | [diff] [blame] | 383 | |
Markus Handell | 1921708 | 2021-01-14 13:00:40 | [diff] [blame] | 384 | // |negotiated_header_extensions_| is read on the signaling thread, but |
| 385 | // written on the worker thread while being sync-invoked from the signal |
| 386 | // thread in SdpOfferAnswerHandler::PushdownMediaDescription(). Hence the lock |
| 387 | // isn't strictly needed, but it's anyway placed here for future safeness. |
| 388 | mutable webrtc::Mutex negotiated_header_extensions_lock_; |
Markus Handell | 5932fe1 | 2020-12-17 21:19:40 | [diff] [blame] | 389 | RtpHeaderExtensions negotiated_header_extensions_ |
Markus Handell | 1921708 | 2021-01-14 13:00:40 | [diff] [blame] | 390 | RTC_GUARDED_BY(negotiated_header_extensions_lock_); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | // VoiceChannel is a specialization that adds support for early media, DTMF, |
| 394 | // and input/output level monitoring. |
Bjorn A Mellem | 7a9a092 | 2019-11-26 17:19:40 | [diff] [blame] | 395 | class VoiceChannel : public BaseChannel { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 396 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 397 | VoiceChannel(rtc::Thread* worker_thread, |
| 398 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 399 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 400 | std::unique_ptr<VoiceMediaChannel> channel, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 401 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 402 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 403 | webrtc::CryptoOptions crypto_options, |
| 404 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 405 | ~VoiceChannel(); |
solenberg | 1dd98f3 | 2015-09-10 08:57:14 | [diff] [blame] | 406 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 407 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 408 | VoiceMediaChannel* media_channel() const override { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 409 | return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel()); |
| 410 | } |
| 411 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 412 | cricket::MediaType media_type() const override { |
| 413 | return cricket::MEDIA_TYPE_AUDIO; |
| 414 | } |
Niels Möller | 2a70703 | 2020-06-16 14:39:13 | [diff] [blame] | 415 | void Init_w(webrtc::RtpTransportInternal* rtp_transport) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 416 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 417 | private: |
| 418 | // overrides from BaseChannel |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 419 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 420 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 421 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 422 | std::string* error_desc) override; |
| 423 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 424 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 425 | std::string* error_desc) override; |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 426 | |
| 427 | // Last AudioSendParameters sent down to the media_channel() via |
| 428 | // SetSendParameters. |
| 429 | AudioSendParameters last_send_params_; |
| 430 | // Last AudioRecvParameters sent down to the media_channel() via |
| 431 | // SetRecvParameters. |
| 432 | AudioRecvParameters last_recv_params_; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 433 | }; |
| 434 | |
| 435 | // VideoChannel is a specialization for video. |
| 436 | class VideoChannel : public BaseChannel { |
| 437 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 438 | VideoChannel(rtc::Thread* worker_thread, |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 439 | rtc::Thread* network_thread, |
| 440 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 441 | std::unique_ptr<VideoMediaChannel> media_channel, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 442 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 443 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 444 | webrtc::CryptoOptions crypto_options, |
| 445 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 446 | ~VideoChannel(); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 447 | |
Fredrik Solenberg | 4b60c73 | 2015-05-07 12:07:48 | [diff] [blame] | 448 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 449 | VideoMediaChannel* media_channel() const override { |
Fredrik Solenberg | 4b60c73 | 2015-05-07 12:07:48 | [diff] [blame] | 450 | return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); |
| 451 | } |
| 452 | |
stefan | f79ade1 | 2017-06-02 13:44:03 | [diff] [blame] | 453 | void FillBitrateInfo(BandwidthEstimationInfo* bwe_info); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 454 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 455 | cricket::MediaType media_type() const override { |
| 456 | return cricket::MEDIA_TYPE_VIDEO; |
| 457 | } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 458 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 459 | private: |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 460 | // overrides from BaseChannel |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 461 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 462 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 463 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 464 | std::string* error_desc) override; |
| 465 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 466 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 467 | std::string* error_desc) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 468 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 469 | // Last VideoSendParameters sent down to the media_channel() via |
| 470 | // SetSendParameters. |
| 471 | VideoSendParameters last_send_params_; |
| 472 | // Last VideoRecvParameters sent down to the media_channel() via |
| 473 | // SetRecvParameters. |
| 474 | VideoRecvParameters last_recv_params_; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 475 | }; |
| 476 | |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 477 | // RtpDataChannel is a specialization for data. |
| 478 | class RtpDataChannel : public BaseChannel { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 479 | public: |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 480 | RtpDataChannel(rtc::Thread* worker_thread, |
| 481 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 482 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 483 | std::unique_ptr<DataMediaChannel> channel, |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 484 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 485 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 486 | webrtc::CryptoOptions crypto_options, |
| 487 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 488 | ~RtpDataChannel(); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 489 | // TODO(zhihuang): Remove this once the RtpTransport can be shared between |
| 490 | // BaseChannels. |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 491 | void Init_w(DtlsTransportInternal* rtp_dtls_transport, |
deadbeef | f534659 | 2017-01-25 05:51:21 | [diff] [blame] | 492 | DtlsTransportInternal* rtcp_dtls_transport, |
deadbeef | 5bd5ca3 | 2017-02-10 19:31:50 | [diff] [blame] | 493 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 494 | rtc::PacketTransportInternal* rtcp_packet_transport); |
Niels Möller | 2a70703 | 2020-06-16 14:39:13 | [diff] [blame] | 495 | void Init_w(webrtc::RtpTransportInternal* rtp_transport) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 496 | |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 497 | virtual bool SendData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 498 | const rtc::CopyOnWriteBuffer& payload, |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 499 | SendDataResult* result); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 500 | |
[email protected] | 07a6fbe | 2013-11-04 18:41:34 | [diff] [blame] | 501 | // Should be called on the signaling thread only. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 502 | bool ready_to_send_data() const { return ready_to_send_data_; } |
[email protected] | 07a6fbe | 2013-11-04 18:41:34 | [diff] [blame] | 503 | |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 504 | sigslot::signal2<const ReceiveDataParams&, const rtc::CopyOnWriteBuffer&> |
| 505 | SignalDataReceived; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 506 | // Signal for notifying when the channel becomes ready to send data. |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 507 | // That occurs when the channel is enabled, the transport is writable, |
| 508 | // both local and remote descriptions are set, and the channel is unblocked. |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 509 | sigslot::signal1<bool> SignalReadyToSendData; |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 510 | cricket::MediaType media_type() const override { |
| 511 | return cricket::MEDIA_TYPE_DATA; |
| 512 | } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 513 | |
[email protected] | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 514 | protected: |
| 515 | // downcasts a MediaChannel. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 516 | DataMediaChannel* media_channel() const override { |
[email protected] | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 517 | return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); |
| 518 | } |
| 519 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 520 | private: |
[email protected] | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 521 | struct SendDataMessageData : public rtc::MessageData { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 522 | SendDataMessageData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 523 | const rtc::CopyOnWriteBuffer* payload, |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 524 | SendDataResult* result) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 525 | : params(params), payload(payload), result(result), succeeded(false) {} |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 526 | |
| 527 | const SendDataParams& params; |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 528 | const rtc::CopyOnWriteBuffer* payload; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 529 | SendDataResult* result; |
| 530 | bool succeeded; |
| 531 | }; |
| 532 | |
[email protected] | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 533 | struct DataReceivedMessageData : public rtc::MessageData { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 534 | // We copy the data because the data will become invalid after we |
| 535 | // handle DataMediaChannel::SignalDataReceived but before we fire |
| 536 | // SignalDataReceived. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 537 | DataReceivedMessageData(const ReceiveDataParams& params, |
| 538 | const char* data, |
| 539 | size_t len) |
| 540 | : params(params), payload(data, len) {} |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 541 | const ReceiveDataParams params; |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 542 | const rtc::CopyOnWriteBuffer payload; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 543 | }; |
| 544 | |
[email protected] | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 545 | typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 546 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 547 | // overrides from BaseChannel |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 548 | // Checks that data channel type is RTP. |
Harald Alvestrand | 755187f | 2019-12-05 12:43:34 | [diff] [blame] | 549 | bool CheckDataChannelTypeFromContent(const MediaContentDescription* content, |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 550 | std::string* error_desc); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 551 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 552 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 553 | std::string* error_desc) override; |
| 554 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 555 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 556 | std::string* error_desc) override; |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 557 | void UpdateMediaSendRecvState_w() override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 558 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 559 | void OnMessage(rtc::Message* pmsg) override; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 560 | void OnDataReceived(const ReceiveDataParams& params, |
| 561 | const char* data, |
| 562 | size_t len); |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 563 | void OnDataChannelReadyToSend(bool writable); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 564 | |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 565 | bool ready_to_send_data_ = false; |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 566 | |
| 567 | // Last DataSendParameters sent down to the media_channel() via |
| 568 | // SetSendParameters. |
| 569 | DataSendParameters last_send_params_; |
| 570 | // Last DataRecvParameters sent down to the media_channel() via |
| 571 | // SetRecvParameters. |
| 572 | DataRecvParameters last_recv_params_; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 573 | }; |
| 574 | |
| 575 | } // namespace cricket |
| 576 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 577 | #endif // PC_CHANNEL_H_ |