[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" |
| 39 | #include "rtc_base/async_invoker.h" |
| 40 | #include "rtc_base/async_udp_socket.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 41 | #include "rtc_base/network.h" |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 42 | #include "rtc_base/synchronization/sequence_checker.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 { |
| 109 | return rtp_transport_ && rtp_transport_->IsSrtpActive(); |
| 110 | } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 111 | |
| 112 | bool writable() const { return writable_; } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 113 | |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 114 | // Set an RTP level transport which could be an RtpTransport without |
| 115 | // encryption, an SrtpTransport for SDES or a DtlsSrtpTransport for DTLS-SRTP. |
| 116 | // This can be called from any thread and it hops to the network thread |
| 117 | // internally. It would replace the |SetTransports| and its variants. |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 118 | bool SetRtpTransport(webrtc::RtpTransportInternal* rtp_transport) override; |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 119 | |
Bjorn A Mellem | 3a1b927 | 2019-05-24 23:13:08 | [diff] [blame] | 120 | webrtc::RtpTransportInternal* rtp_transport() const { return rtp_transport_; } |
| 121 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 122 | // Channel control |
| 123 | bool SetLocalContent(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 124 | webrtc::SdpType type, |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 125 | std::string* error_desc) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 126 | bool SetRemoteContent(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 127 | webrtc::SdpType type, |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 128 | std::string* error_desc) override; |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 129 | // Controls whether this channel will receive packets on the basis of |
| 130 | // matching payload type alone. This is needed for legacy endpoints that |
| 131 | // don't signal SSRCs or use MID/RID, but doesn't make sense if there is |
| 132 | // more than channel of specific media type, As that creates an ambiguity. |
| 133 | // |
| 134 | // This method will also remove any existing streams that were bound to this |
| 135 | // channel on the basis of payload type, since one of these streams might |
| 136 | // actually belong to a new channel. See: crbug.com/webrtc/11477 |
Taylor Brandstetter | d3ef499 | 2020-10-16 01:22:57 | [diff] [blame^] | 137 | bool SetPayloadTypeDemuxingEnabled(bool enabled) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 138 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 139 | bool Enable(bool enable) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 140 | |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 141 | const std::vector<StreamParams>& local_streams() const override { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 142 | return local_streams_; |
| 143 | } |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 144 | const std::vector<StreamParams>& remote_streams() const override { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 145 | return remote_streams_; |
| 146 | } |
| 147 | |
[email protected] | 6bfd619 | 2014-05-15 16:15:59 | [diff] [blame] | 148 | // Used for latency measurements. |
Tomas Gunnarsson | b2995a1 | 2020-09-28 12:05:35 | [diff] [blame] | 149 | sigslot::signal1<ChannelInterface*>& SignalFirstPacketReceived() override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 150 | |
zhihuang | b2cdd93 | 2017-01-20 00:54:25 | [diff] [blame] | 151 | // Forward SignalSentPacket to worker thread. |
Tomas Gunnarsson | b2995a1 | 2020-09-28 12:05:35 | [diff] [blame] | 152 | sigslot::signal1<const rtc::SentPacket&>& SignalSentPacket(); |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 153 | |
zstein | 56162b9 | 2017-04-24 23:54:35 | [diff] [blame] | 154 | // From RtpTransport - public for testing only |
| 155 | void OnTransportReadyToSend(bool ready); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 156 | |
[email protected] | 4f85288 | 2015-03-12 20:09:44 | [diff] [blame] | 157 | // Only public for unit tests. Otherwise, consider protected. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 158 | int SetOption(SocketType type, rtc::Socket::Option o, int val) override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 159 | int SetOption_n(SocketType type, rtc::Socket::Option o, int val); |
[email protected] | 4f85288 | 2015-03-12 20:09:44 | [diff] [blame] | 160 | |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 161 | // RtpPacketSinkInterface overrides. |
| 162 | void OnRtpPacket(const webrtc::RtpPacketReceived& packet) override; |
zstein | 3dcf0e9 | 2017-06-01 20:22:42 | [diff] [blame] | 163 | |
Steve Anton | 593e325 | 2017-12-15 19:44:48 | [diff] [blame] | 164 | // Used by the RTCStatsCollector tests to set the transport name without |
| 165 | // creating RtpTransports. |
| 166 | void set_transport_name_for_testing(const std::string& transport_name) { |
| 167 | transport_name_ = transport_name; |
| 168 | } |
| 169 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 170 | MediaChannel* media_channel() const override { return media_channel_.get(); } |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 171 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 172 | protected: |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 173 | bool was_ever_writable() const { return was_ever_writable_; } |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 174 | void set_local_content_direction(webrtc::RtpTransceiverDirection direction) { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 175 | local_content_direction_ = direction; |
| 176 | } |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 177 | void set_remote_content_direction(webrtc::RtpTransceiverDirection direction) { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 178 | remote_content_direction_ = direction; |
| 179 | } |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 180 | // These methods verify that: |
| 181 | // * The required content description directions have been set. |
| 182 | // * The channel is enabled. |
| 183 | // * And for sending: |
| 184 | // - The SRTP filter is active if it's needed. |
| 185 | // - The transport has been writable before, meaning it should be at least |
| 186 | // possible to succeed in sending a packet. |
| 187 | // |
| 188 | // When any of these properties change, UpdateMediaSendRecvState_w should be |
| 189 | // called. |
| 190 | bool IsReadyToReceiveMedia_w() const; |
| 191 | bool IsReadyToSendMedia_w() const; |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 192 | rtc::Thread* signaling_thread() { return signaling_thread_; } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 193 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 194 | void FlushRtcpMessages_n(); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 195 | |
| 196 | // NetworkInterface implementation, called by MediaEngine |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 197 | bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
| 198 | const rtc::PacketOptions& options) override; |
| 199 | bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
| 200 | const rtc::PacketOptions& options) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 201 | |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 202 | // From RtpTransportInternal |
| 203 | void OnWritableState(bool writable); |
Guo-wei Shieh | 1218d7a | 2015-12-05 17:59:56 | [diff] [blame] | 204 | |
Danil Chapovalov | 66cadcc | 2018-06-19 14:47:43 | [diff] [blame] | 205 | void OnNetworkRouteChanged(absl::optional<rtc::NetworkRoute> network_route); |
Honghai Zhang | cc411c0 | 2016-03-30 00:27:21 | [diff] [blame] | 206 | |
deadbeef | 5bd5ca3 | 2017-02-10 19:31:50 | [diff] [blame] | 207 | bool PacketIsRtcp(const rtc::PacketTransportInternal* transport, |
johan | d89ab14 | 2016-10-25 17:50:32 | [diff] [blame] | 208 | const char* data, |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 209 | size_t len); |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 210 | bool SendPacket(bool rtcp, |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 211 | rtc::CopyOnWriteBuffer* packet, |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 212 | const rtc::PacketOptions& options); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 213 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 214 | void EnableMedia_w(); |
| 215 | void DisableMedia_w(); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 216 | |
| 217 | // Performs actions if the RTP/RTCP writable state changed. This should |
| 218 | // be called whenever a channel's writable state changes or when RTCP muxing |
| 219 | // becomes active/inactive. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 220 | void UpdateWritableState_n(); |
| 221 | void ChannelWritable_n(); |
| 222 | void ChannelNotWritable_n(); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 223 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 224 | bool AddRecvStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 225 | bool RemoveRecvStream_w(uint32_t ssrc); |
Saurav Das | ff27da5 | 2019-09-20 18:05:30 | [diff] [blame] | 226 | void ResetUnsignaledRecvStream_w(); |
Taylor Brandstetter | d3ef499 | 2020-10-16 01:22:57 | [diff] [blame^] | 227 | bool SetPayloadTypeDemuxingEnabled_w(bool enabled); |
[email protected] | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 228 | bool AddSendStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 229 | bool RemoveSendStream_w(uint32_t ssrc); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 230 | |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 231 | // Should be called whenever the conditions for |
| 232 | // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied). |
| 233 | // Updates the send/recv state of the media channel. |
| 234 | void UpdateMediaSendRecvState(); |
| 235 | virtual void UpdateMediaSendRecvState_w() = 0; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 236 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 237 | bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 238 | webrtc::SdpType type, |
[email protected] | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 239 | std::string* error_desc); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 240 | bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 241 | webrtc::SdpType type, |
[email protected] | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 242 | std::string* error_desc); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 243 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 244 | webrtc::SdpType type, |
[email protected] | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 245 | std::string* error_desc) = 0; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 246 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 247 | webrtc::SdpType type, |
[email protected] | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 248 | std::string* error_desc) = 0; |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 249 | // Return a list of RTP header extensions with the non-encrypted extensions |
| 250 | // removed depending on the current crypto_options_ and only if both the |
| 251 | // non-encrypted and encrypted extension is present for the same URI. |
| 252 | RtpHeaderExtensions GetFilteredRtpHeaderExtensions( |
| 253 | const RtpHeaderExtensions& extensions); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 254 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 255 | // From MessageHandler |
rlester | ec9d187 | 2015-10-27 21:22:16 | [diff] [blame] | 256 | void OnMessage(rtc::Message* pmsg) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 257 | |
stefan | f79ade1 | 2017-06-02 13:44:03 | [diff] [blame] | 258 | // Helper function template for invoking methods on the worker thread. |
Danil Chapovalov | 8931345 | 2019-11-29 11:56:43 | [diff] [blame] | 259 | template <class T> |
| 260 | T InvokeOnWorker(const rtc::Location& posted_from, |
| 261 | rtc::FunctionView<T()> functor) { |
stefan | f79ade1 | 2017-06-02 13:44:03 | [diff] [blame] | 262 | return worker_thread_->Invoke<T>(posted_from, functor); |
[email protected] | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 263 | } |
| 264 | |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 265 | // Add |payload_type| to |demuxer_criteria_| if payload type demuxing is |
| 266 | // enabled. |
| 267 | void MaybeAddHandledPayloadType(int payload_type) RTC_RUN_ON(worker_thread()); |
zstein | 3dcf0e9 | 2017-06-01 20:22:42 | [diff] [blame] | 268 | |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 269 | void ClearHandledPayloadTypes() RTC_RUN_ON(worker_thread()); |
Steve Anton | be2e5f7 | 2019-09-06 23:26:02 | [diff] [blame] | 270 | |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 271 | void UpdateRtpHeaderExtensionMap( |
| 272 | const RtpHeaderExtensions& header_extensions); |
| 273 | |
| 274 | bool RegisterRtpDemuxerSink(); |
| 275 | |
Yura Yaroshevich | c325246 | 2020-05-18 10:26:14 | [diff] [blame] | 276 | // Return description of media channel to facilitate logging |
| 277 | std::string ToString() const; |
| 278 | |
Piotr (Peter) Slatala | 309aafe | 2019-01-15 22:24:34 | [diff] [blame] | 279 | bool has_received_packet_ = false; |
| 280 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 281 | private: |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 282 | bool ConnectToRtpTransport(); |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 283 | void DisconnectFromRtpTransport(); |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 284 | void SignalSentPacket_n(const rtc::SentPacket& sent_packet); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 285 | bool IsReadyToSendMedia_n() const; |
Piotr (Peter) Slatala | 179a392 | 2018-11-16 17:57:58 | [diff] [blame] | 286 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 287 | rtc::Thread* const worker_thread_; |
| 288 | rtc::Thread* const network_thread_; |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 289 | rtc::Thread* const signaling_thread_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 290 | rtc::AsyncInvoker invoker_; |
Tomas Gunnarsson | b2995a1 | 2020-09-28 12:05:35 | [diff] [blame] | 291 | sigslot::signal1<ChannelInterface*> SignalFirstPacketReceived_ |
| 292 | RTC_GUARDED_BY(signaling_thread_); |
| 293 | sigslot::signal1<const rtc::SentPacket&> SignalSentPacket_ |
| 294 | RTC_GUARDED_BY(worker_thread_); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 295 | |
[email protected] | 990a00c | 2015-03-13 18:20:33 | [diff] [blame] | 296 | const std::string content_name_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 297 | |
deadbeef | f534659 | 2017-01-25 05:51:21 | [diff] [blame] | 298 | // Won't be set when using raw packet transports. SDP-specific thing. |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 299 | std::string transport_name_; |
zhihuang | b2cdd93 | 2017-01-20 00:54:25 | [diff] [blame] | 300 | |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 301 | webrtc::RtpTransportInternal* rtp_transport_ = nullptr; |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 302 | |
deadbeef | f534659 | 2017-01-25 05:51:21 | [diff] [blame] | 303 | std::vector<std::pair<rtc::Socket::Option, int> > socket_options_; |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 304 | std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_; |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 305 | bool writable_ = false; |
| 306 | bool was_ever_writable_ = false; |
deadbeef | 7af91dd | 2016-12-13 19:29:11 | [diff] [blame] | 307 | const bool srtp_required_ = true; |
Benjamin Wright | a54daf1 | 2018-10-11 22:33:17 | [diff] [blame] | 308 | webrtc::CryptoOptions crypto_options_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 309 | |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 310 | // MediaChannel related members that should be accessed from the worker |
| 311 | // thread. |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 312 | std::unique_ptr<MediaChannel> media_channel_; |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 313 | // Currently the |enabled_| flag is accessed from the signaling thread as |
| 314 | // well, but it can be changed only when signaling thread does a synchronous |
| 315 | // call to the worker thread, so it should be safe. |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 316 | bool enabled_ = false; |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 317 | bool payload_type_demuxing_enabled_ RTC_GUARDED_BY(worker_thread()) = true; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 318 | std::vector<StreamParams> local_streams_; |
| 319 | std::vector<StreamParams> remote_streams_; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 320 | webrtc::RtpTransceiverDirection local_content_direction_ = |
| 321 | webrtc::RtpTransceiverDirection::kInactive; |
| 322 | webrtc::RtpTransceiverDirection remote_content_direction_ = |
| 323 | webrtc::RtpTransceiverDirection::kInactive; |
Zhi Huang | c99b6c7 | 2017-11-11 00:44:46 | [diff] [blame] | 324 | |
Taylor Brandstetter | d3ef499 | 2020-10-16 01:22:57 | [diff] [blame^] | 325 | // Cached list of payload types, used if payload type demuxing is re-enabled. |
| 326 | std::set<uint8_t> payload_types_ RTC_GUARDED_BY(worker_thread()); |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 327 | webrtc::RtpDemuxerCriteria demuxer_criteria_; |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 328 | // This generator is used to generate SSRCs for local streams. |
| 329 | // This is needed in cases where SSRCs are not negotiated or set explicitly |
| 330 | // like in Simulcast. |
| 331 | // This object is not owned by the channel so it must outlive it. |
| 332 | rtc::UniqueRandomIdGenerator* const ssrc_generator_; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | // VoiceChannel is a specialization that adds support for early media, DTMF, |
| 336 | // and input/output level monitoring. |
Bjorn A Mellem | 7a9a092 | 2019-11-26 17:19:40 | [diff] [blame] | 337 | class VoiceChannel : public BaseChannel { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 338 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 339 | VoiceChannel(rtc::Thread* worker_thread, |
| 340 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 341 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 342 | std::unique_ptr<VoiceMediaChannel> channel, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 343 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 344 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 345 | webrtc::CryptoOptions crypto_options, |
| 346 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 347 | ~VoiceChannel(); |
solenberg | 1dd98f3 | 2015-09-10 08:57:14 | [diff] [blame] | 348 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 349 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 350 | VoiceMediaChannel* media_channel() const override { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 351 | return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel()); |
| 352 | } |
| 353 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 354 | cricket::MediaType media_type() const override { |
| 355 | return cricket::MEDIA_TYPE_AUDIO; |
| 356 | } |
Niels Möller | 2a70703 | 2020-06-16 14:39:13 | [diff] [blame] | 357 | void Init_w(webrtc::RtpTransportInternal* rtp_transport) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 358 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 359 | private: |
| 360 | // overrides from BaseChannel |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 361 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 362 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 363 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 364 | std::string* error_desc) override; |
| 365 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 366 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 367 | std::string* error_desc) override; |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 368 | |
| 369 | // Last AudioSendParameters sent down to the media_channel() via |
| 370 | // SetSendParameters. |
| 371 | AudioSendParameters last_send_params_; |
| 372 | // Last AudioRecvParameters sent down to the media_channel() via |
| 373 | // SetRecvParameters. |
| 374 | AudioRecvParameters last_recv_params_; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 375 | }; |
| 376 | |
| 377 | // VideoChannel is a specialization for video. |
| 378 | class VideoChannel : public BaseChannel { |
| 379 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 380 | VideoChannel(rtc::Thread* worker_thread, |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 381 | rtc::Thread* network_thread, |
| 382 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 383 | std::unique_ptr<VideoMediaChannel> media_channel, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 384 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 385 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 386 | webrtc::CryptoOptions crypto_options, |
| 387 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 388 | ~VideoChannel(); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 389 | |
Fredrik Solenberg | 4b60c73 | 2015-05-07 12:07:48 | [diff] [blame] | 390 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 391 | VideoMediaChannel* media_channel() const override { |
Fredrik Solenberg | 4b60c73 | 2015-05-07 12:07:48 | [diff] [blame] | 392 | return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); |
| 393 | } |
| 394 | |
stefan | f79ade1 | 2017-06-02 13:44:03 | [diff] [blame] | 395 | void FillBitrateInfo(BandwidthEstimationInfo* bwe_info); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 396 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 397 | cricket::MediaType media_type() const override { |
| 398 | return cricket::MEDIA_TYPE_VIDEO; |
| 399 | } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 400 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 401 | private: |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 402 | // overrides from BaseChannel |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 403 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 404 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 405 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 406 | std::string* error_desc) override; |
| 407 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 408 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 409 | std::string* error_desc) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 410 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 411 | // Last VideoSendParameters sent down to the media_channel() via |
| 412 | // SetSendParameters. |
| 413 | VideoSendParameters last_send_params_; |
| 414 | // Last VideoRecvParameters sent down to the media_channel() via |
| 415 | // SetRecvParameters. |
| 416 | VideoRecvParameters last_recv_params_; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 417 | }; |
| 418 | |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 419 | // RtpDataChannel is a specialization for data. |
| 420 | class RtpDataChannel : public BaseChannel { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 421 | public: |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 422 | RtpDataChannel(rtc::Thread* worker_thread, |
| 423 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-13 03:37:48 | [diff] [blame] | 424 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 425 | std::unique_ptr<DataMediaChannel> channel, |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 426 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 427 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 428 | webrtc::CryptoOptions crypto_options, |
| 429 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 430 | ~RtpDataChannel(); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 431 | // TODO(zhihuang): Remove this once the RtpTransport can be shared between |
| 432 | // BaseChannels. |
Steve Anton | 8699a32 | 2017-11-06 23:53:33 | [diff] [blame] | 433 | void Init_w(DtlsTransportInternal* rtp_dtls_transport, |
deadbeef | f534659 | 2017-01-25 05:51:21 | [diff] [blame] | 434 | DtlsTransportInternal* rtcp_dtls_transport, |
deadbeef | 5bd5ca3 | 2017-02-10 19:31:50 | [diff] [blame] | 435 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 436 | rtc::PacketTransportInternal* rtcp_packet_transport); |
Niels Möller | 2a70703 | 2020-06-16 14:39:13 | [diff] [blame] | 437 | void Init_w(webrtc::RtpTransportInternal* rtp_transport) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 438 | |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 439 | virtual bool SendData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 440 | const rtc::CopyOnWriteBuffer& payload, |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 441 | SendDataResult* result); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 442 | |
[email protected] | 07a6fbe | 2013-11-04 18:41:34 | [diff] [blame] | 443 | // Should be called on the signaling thread only. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 444 | bool ready_to_send_data() const { return ready_to_send_data_; } |
[email protected] | 07a6fbe | 2013-11-04 18:41:34 | [diff] [blame] | 445 | |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 446 | sigslot::signal2<const ReceiveDataParams&, const rtc::CopyOnWriteBuffer&> |
| 447 | SignalDataReceived; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 448 | // Signal for notifying when the channel becomes ready to send data. |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 449 | // That occurs when the channel is enabled, the transport is writable, |
| 450 | // both local and remote descriptions are set, and the channel is unblocked. |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 451 | sigslot::signal1<bool> SignalReadyToSendData; |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 452 | cricket::MediaType media_type() const override { |
| 453 | return cricket::MEDIA_TYPE_DATA; |
| 454 | } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 455 | |
[email protected] | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 456 | protected: |
| 457 | // downcasts a MediaChannel. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 458 | DataMediaChannel* media_channel() const override { |
[email protected] | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 459 | return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); |
| 460 | } |
| 461 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 462 | private: |
[email protected] | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 463 | struct SendDataMessageData : public rtc::MessageData { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 464 | SendDataMessageData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 465 | const rtc::CopyOnWriteBuffer* payload, |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 466 | SendDataResult* result) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 467 | : params(params), payload(payload), result(result), succeeded(false) {} |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 468 | |
| 469 | const SendDataParams& params; |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 470 | const rtc::CopyOnWriteBuffer* payload; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 471 | SendDataResult* result; |
| 472 | bool succeeded; |
| 473 | }; |
| 474 | |
[email protected] | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 475 | struct DataReceivedMessageData : public rtc::MessageData { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 476 | // We copy the data because the data will become invalid after we |
| 477 | // handle DataMediaChannel::SignalDataReceived but before we fire |
| 478 | // SignalDataReceived. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 479 | DataReceivedMessageData(const ReceiveDataParams& params, |
| 480 | const char* data, |
| 481 | size_t len) |
| 482 | : params(params), payload(data, len) {} |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 483 | const ReceiveDataParams params; |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 484 | const rtc::CopyOnWriteBuffer payload; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 485 | }; |
| 486 | |
[email protected] | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 487 | typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 488 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 489 | // overrides from BaseChannel |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 490 | // Checks that data channel type is RTP. |
Harald Alvestrand | 755187f | 2019-12-05 12:43:34 | [diff] [blame] | 491 | bool CheckDataChannelTypeFromContent(const MediaContentDescription* content, |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 492 | std::string* error_desc); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 493 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 494 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 495 | std::string* error_desc) override; |
| 496 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 497 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 498 | std::string* error_desc) override; |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 499 | void UpdateMediaSendRecvState_w() override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 500 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 501 | void OnMessage(rtc::Message* pmsg) override; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 502 | void OnDataReceived(const ReceiveDataParams& params, |
| 503 | const char* data, |
| 504 | size_t len); |
[email protected] | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 505 | void OnDataChannelReadyToSend(bool writable); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 506 | |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 507 | bool ready_to_send_data_ = false; |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 508 | |
| 509 | // Last DataSendParameters sent down to the media_channel() via |
| 510 | // SetSendParameters. |
| 511 | DataSendParameters last_send_params_; |
| 512 | // Last DataRecvParameters sent down to the media_channel() via |
| 513 | // SetRecvParameters. |
| 514 | DataRecvParameters last_recv_params_; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 515 | }; |
| 516 | |
| 517 | } // namespace cricket |
| 518 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 519 | #endif // PC_CHANNEL_H_ |