henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef PC_CHANNEL_H_ |
| 12 | #define PC_CHANNEL_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 14 | #include <map> |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 15 | #include <memory> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 16 | #include <set> |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 17 | #include <string> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 18 | #include <utility> |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 19 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 20 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "api/call/audio_sink.h" |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 22 | #include "api/jsep.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "api/rtpreceiverinterface.h" |
Niels Möller | c6ce9c5 | 2018-05-11 11:15:30 +0200 | [diff] [blame] | 24 | #include "api/video/video_sink_interface.h" |
Niels Möller | 0327c2d | 2018-05-21 14:09:31 +0200 | [diff] [blame] | 25 | #include "api/video/video_source_interface.h" |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 26 | #include "call/rtp_packet_sink_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "media/base/mediachannel.h" |
| 28 | #include "media/base/mediaengine.h" |
| 29 | #include "media/base/streamparams.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "p2p/base/dtlstransportinternal.h" |
| 31 | #include "p2p/base/packettransportinternal.h" |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 32 | #include "pc/dtlssrtptransport.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "pc/mediasession.h" |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 34 | #include "pc/rtptransport.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 35 | #include "pc/srtpfilter.h" |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 36 | #include "pc/srtptransport.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 37 | #include "rtc_base/asyncinvoker.h" |
| 38 | #include "rtc_base/asyncudpsocket.h" |
| 39 | #include "rtc_base/criticalsection.h" |
| 40 | #include "rtc_base/network.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame] | 41 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 42 | |
| 43 | namespace webrtc { |
| 44 | class AudioSinkInterface; |
| 45 | } // namespace webrtc |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | |
| 47 | namespace cricket { |
| 48 | |
| 49 | struct CryptoParams; |
| 50 | class MediaContentDescription; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | |
deadbeef | 062ce9f | 2016-08-26 21:42:15 -0700 | [diff] [blame] | 52 | // BaseChannel contains logic common to voice and video, including enable, |
| 53 | // marshaling calls to a worker and network threads, and connection and media |
| 54 | // monitors. |
| 55 | // |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 56 | // BaseChannel assumes signaling and other threads are allowed to make |
| 57 | // synchronous calls to the worker thread, the worker thread makes synchronous |
| 58 | // calls only to the network thread, and the network thread can't be blocked by |
| 59 | // other threads. |
| 60 | // All methods with _n suffix must be called on network thread, |
deadbeef | 062ce9f | 2016-08-26 21:42:15 -0700 | [diff] [blame] | 61 | // methods with _w suffix on worker thread |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 62 | // and methods with _s suffix on signaling thread. |
| 63 | // Network and worker threads may be the same thread. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 64 | // |
| 65 | // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS! |
| 66 | // This is required to avoid a data race between the destructor modifying the |
| 67 | // vtable, and the media channel's thread using BaseChannel as the |
| 68 | // NetworkInterface. |
| 69 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 70 | class BaseChannel : public rtc::MessageHandler, |
| 71 | public sigslot::has_slots<>, |
| 72 | public MediaChannel::NetworkInterface, |
| 73 | public webrtc::RtpPacketSinkInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | public: |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 75 | // If |srtp_required| is true, the channel will not send or receive any |
| 76 | // RTP/RTCP packets without using SRTP (either using SDES or DTLS-SRTP). |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 77 | // TODO(zhihuang:) Create a BaseChannel::Config struct for the parameter lists |
| 78 | // which will make it easier to change the constructor. |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 79 | BaseChannel(rtc::Thread* worker_thread, |
| 80 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 81 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 82 | std::unique_ptr<MediaChannel> media_channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 83 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 84 | bool srtp_required, |
| 85 | rtc::CryptoOptions crypto_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | virtual ~BaseChannel(); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 87 | void Init_w(webrtc::RtpTransportInternal* rtp_transport); |
| 88 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 89 | // Deinit may be called multiple times and is simply ignored if it's already |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 90 | // done. |
| 91 | void Deinit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 93 | rtc::Thread* worker_thread() const { return worker_thread_; } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 94 | rtc::Thread* network_thread() const { return network_thread_; } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 95 | const std::string& content_name() const { return content_name_; } |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 96 | // TODO(deadbeef): This is redundant; remove this. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 97 | const std::string& transport_name() const { return transport_name_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | bool enabled() const { return enabled_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 100 | // This function returns true if using SRTP (DTLS-based keying or SDES). |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 101 | bool srtp_active() const { |
| 102 | return rtp_transport_ && rtp_transport_->IsSrtpActive(); |
| 103 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | |
| 105 | bool writable() const { return writable_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 106 | |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 107 | // Set an RTP level transport which could be an RtpTransport without |
| 108 | // encryption, an SrtpTransport for SDES or a DtlsSrtpTransport for DTLS-SRTP. |
| 109 | // This can be called from any thread and it hops to the network thread |
| 110 | // internally. It would replace the |SetTransports| and its variants. |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 111 | bool SetRtpTransport(webrtc::RtpTransportInternal* rtp_transport); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 112 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | // Channel control |
| 114 | bool SetLocalContent(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 115 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 116 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | bool SetRemoteContent(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 118 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 119 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | |
| 121 | bool Enable(bool enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 123 | // TODO(zhihuang): These methods are used for testing and can be removed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | bool AddRecvStream(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 125 | bool RemoveRecvStream(uint32_t ssrc); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 126 | bool AddSendStream(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 127 | bool RemoveSendStream(uint32_t ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | const std::vector<StreamParams>& local_streams() const { |
| 130 | return local_streams_; |
| 131 | } |
| 132 | const std::vector<StreamParams>& remote_streams() const { |
| 133 | return remote_streams_; |
| 134 | } |
| 135 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 136 | sigslot::signal2<BaseChannel*, bool> SignalDtlsSrtpSetupFailure; |
| 137 | void SignalDtlsSrtpSetupFailure_n(bool rtcp); |
| 138 | void SignalDtlsSrtpSetupFailure_s(bool rtcp); |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 139 | |
buildbot@webrtc.org | 6bfd619 | 2014-05-15 16:15:59 +0000 | [diff] [blame] | 140 | // Used for latency measurements. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 141 | sigslot::signal1<BaseChannel*> SignalFirstPacketReceived; |
| 142 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 143 | // Forward SignalSentPacket to worker thread. |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 144 | sigslot::signal1<const rtc::SentPacket&> SignalSentPacket; |
| 145 | |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 146 | // Emitted whenever rtcp-mux is fully negotiated and the rtcp-transport can |
| 147 | // be destroyed. |
| 148 | // Fired on the network thread. |
| 149 | sigslot::signal1<const std::string&> SignalRtcpMuxFullyActive; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 150 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 151 | rtc::PacketTransportInternal* rtp_packet_transport() { |
| 152 | if (rtp_transport_) { |
| 153 | return rtp_transport_->rtp_packet_transport(); |
| 154 | } |
| 155 | return nullptr; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 156 | } |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 157 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 158 | rtc::PacketTransportInternal* rtcp_packet_transport() { |
| 159 | if (rtp_transport_) { |
| 160 | return rtp_transport_->rtcp_packet_transport(); |
| 161 | } |
| 162 | return nullptr; |
| 163 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 164 | |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 165 | // From RtpTransport - public for testing only |
| 166 | void OnTransportReadyToSend(bool ready); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 167 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 168 | // Only public for unit tests. Otherwise, consider protected. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 169 | int SetOption(SocketType type, rtc::Socket::Option o, int val) override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 170 | int SetOption_n(SocketType type, rtc::Socket::Option o, int val); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 171 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 172 | virtual cricket::MediaType media_type() = 0; |
| 173 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 174 | // RtpPacketSinkInterface overrides. |
| 175 | void OnRtpPacket(const webrtc::RtpPacketReceived& packet) override; |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 176 | |
Steve Anton | 593e325 | 2017-12-15 11:44:48 -0800 | [diff] [blame] | 177 | // Used by the RTCStatsCollector tests to set the transport name without |
| 178 | // creating RtpTransports. |
| 179 | void set_transport_name_for_testing(const std::string& transport_name) { |
| 180 | transport_name_ = transport_name; |
| 181 | } |
| 182 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 183 | protected: |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 184 | virtual MediaChannel* media_channel() const { return media_channel_.get(); } |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 185 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 186 | bool was_ever_writable() const { return was_ever_writable_; } |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 187 | void set_local_content_direction(webrtc::RtpTransceiverDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 188 | local_content_direction_ = direction; |
| 189 | } |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 190 | void set_remote_content_direction(webrtc::RtpTransceiverDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 191 | remote_content_direction_ = direction; |
| 192 | } |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 193 | // These methods verify that: |
| 194 | // * The required content description directions have been set. |
| 195 | // * The channel is enabled. |
| 196 | // * And for sending: |
| 197 | // - The SRTP filter is active if it's needed. |
| 198 | // - The transport has been writable before, meaning it should be at least |
| 199 | // possible to succeed in sending a packet. |
| 200 | // |
| 201 | // When any of these properties change, UpdateMediaSendRecvState_w should be |
| 202 | // called. |
| 203 | bool IsReadyToReceiveMedia_w() const; |
| 204 | bool IsReadyToSendMedia_w() const; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 205 | rtc::Thread* signaling_thread() { return signaling_thread_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 206 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 207 | void FlushRtcpMessages_n(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | |
| 209 | // NetworkInterface implementation, called by MediaEngine |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 210 | bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
| 211 | const rtc::PacketOptions& options) override; |
| 212 | bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
| 213 | const rtc::PacketOptions& options) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 214 | |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 215 | // From RtpTransportInternal |
| 216 | void OnWritableState(bool writable); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 217 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 218 | void OnNetworkRouteChanged(absl::optional<rtc::NetworkRoute> network_route); |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 219 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 220 | bool PacketIsRtcp(const rtc::PacketTransportInternal* transport, |
johan | d89ab14 | 2016-10-25 10:50:32 -0700 | [diff] [blame] | 221 | const char* data, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 222 | size_t len); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 223 | bool SendPacket(bool rtcp, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 224 | rtc::CopyOnWriteBuffer* packet, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 225 | const rtc::PacketOptions& options); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 226 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 227 | void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer* packet, |
| 228 | const rtc::PacketTime& packet_time); |
| 229 | |
Steve Anton | 0807d15 | 2018-03-05 11:23:09 -0800 | [diff] [blame] | 230 | void OnPacketReceived(bool rtcp, |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 231 | const rtc::CopyOnWriteBuffer& packet, |
Steve Anton | 0807d15 | 2018-03-05 11:23:09 -0800 | [diff] [blame] | 232 | const rtc::PacketTime& packet_time); |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 233 | void ProcessPacket(bool rtcp, |
| 234 | const rtc::CopyOnWriteBuffer& packet, |
| 235 | const rtc::PacketTime& packet_time); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 236 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 237 | void EnableMedia_w(); |
| 238 | void DisableMedia_w(); |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 239 | |
| 240 | // Performs actions if the RTP/RTCP writable state changed. This should |
| 241 | // be called whenever a channel's writable state changes or when RTCP muxing |
| 242 | // becomes active/inactive. |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 243 | void UpdateWritableState_n(); |
| 244 | void ChannelWritable_n(); |
| 245 | void ChannelNotWritable_n(); |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 246 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 247 | bool AddRecvStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 248 | bool RemoveRecvStream_w(uint32_t ssrc); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 249 | bool AddSendStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 250 | bool RemoveSendStream_w(uint32_t ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 251 | |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 252 | // Should be called whenever the conditions for |
| 253 | // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied). |
| 254 | // Updates the send/recv state of the media channel. |
| 255 | void UpdateMediaSendRecvState(); |
| 256 | virtual void UpdateMediaSendRecvState_w() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 257 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 258 | bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 259 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 260 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 261 | bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 262 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 263 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 264 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 265 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 266 | std::string* error_desc) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 267 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 268 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 269 | std::string* error_desc) = 0; |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 270 | // Return a list of RTP header extensions with the non-encrypted extensions |
| 271 | // removed depending on the current crypto_options_ and only if both the |
| 272 | // non-encrypted and encrypted extension is present for the same URI. |
| 273 | RtpHeaderExtensions GetFilteredRtpHeaderExtensions( |
| 274 | const RtpHeaderExtensions& extensions); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 275 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 276 | // From MessageHandler |
rlester | ec9d187 | 2015-10-27 14:22:16 -0700 | [diff] [blame] | 277 | void OnMessage(rtc::Message* pmsg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 278 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 279 | // Helper function template for invoking methods on the worker thread. |
| 280 | template <class T, class FunctorT> |
| 281 | T InvokeOnWorker(const rtc::Location& posted_from, const FunctorT& functor) { |
| 282 | return worker_thread_->Invoke<T>(posted_from, functor); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 283 | } |
| 284 | |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 285 | void AddHandledPayloadType(int payload_type); |
| 286 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 287 | void UpdateRtpHeaderExtensionMap( |
| 288 | const RtpHeaderExtensions& header_extensions); |
| 289 | |
| 290 | bool RegisterRtpDemuxerSink(); |
| 291 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 292 | private: |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 293 | bool ConnectToRtpTransport(); |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 294 | void DisconnectFromRtpTransport(); |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 295 | void SignalSentPacket_n(const rtc::SentPacket& sent_packet); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 296 | void SignalSentPacket_w(const rtc::SentPacket& sent_packet); |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 297 | bool IsReadyToSendMedia_n() const; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 298 | rtc::Thread* const worker_thread_; |
| 299 | rtc::Thread* const network_thread_; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 300 | rtc::Thread* const signaling_thread_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 301 | rtc::AsyncInvoker invoker_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 302 | |
pthatcher@webrtc.org | 990a00c | 2015-03-13 18:20:33 +0000 | [diff] [blame] | 303 | const std::string content_name_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 304 | |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 305 | // Won't be set when using raw packet transports. SDP-specific thing. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 306 | std::string transport_name_; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 307 | |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 308 | webrtc::RtpTransportInternal* rtp_transport_ = nullptr; |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 309 | |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 310 | std::vector<std::pair<rtc::Socket::Option, int> > socket_options_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 311 | std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_; |
deadbeef | 23d947d | 2016-08-22 16:00:30 -0700 | [diff] [blame] | 312 | bool writable_ = false; |
| 313 | bool was_ever_writable_ = false; |
| 314 | bool has_received_packet_ = false; |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 315 | const bool srtp_required_ = true; |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 316 | rtc::CryptoOptions crypto_options_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 317 | |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 318 | // MediaChannel related members that should be accessed from the worker |
| 319 | // thread. |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 320 | std::unique_ptr<MediaChannel> media_channel_; |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 321 | // Currently the |enabled_| flag is accessed from the signaling thread as |
| 322 | // well, but it can be changed only when signaling thread does a synchronous |
| 323 | // call to the worker thread, so it should be safe. |
deadbeef | 23d947d | 2016-08-22 16:00:30 -0700 | [diff] [blame] | 324 | bool enabled_ = false; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 325 | std::vector<StreamParams> local_streams_; |
| 326 | std::vector<StreamParams> remote_streams_; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 327 | webrtc::RtpTransceiverDirection local_content_direction_ = |
| 328 | webrtc::RtpTransceiverDirection::kInactive; |
| 329 | webrtc::RtpTransceiverDirection remote_content_direction_ = |
| 330 | webrtc::RtpTransceiverDirection::kInactive; |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 331 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 332 | webrtc::RtpDemuxerCriteria demuxer_criteria_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | // VoiceChannel is a specialization that adds support for early media, DTMF, |
| 336 | // and input/output level monitoring. |
| 337 | class VoiceChannel : public BaseChannel { |
| 338 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 339 | VoiceChannel(rtc::Thread* worker_thread, |
| 340 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 341 | rtc::Thread* signaling_thread, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 342 | MediaEngineInterface* media_engine, |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 343 | std::unique_ptr<VoiceMediaChannel> channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 344 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 345 | bool srtp_required, |
| 346 | rtc::CryptoOptions crypto_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 347 | ~VoiceChannel(); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 348 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 349 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 350 | VoiceMediaChannel* media_channel() const override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 351 | return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel()); |
| 352 | } |
| 353 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 354 | webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 355 | webrtc::RTCError SetRtpSendParameters_w(uint32_t ssrc, |
| 356 | webrtc::RtpParameters parameters); |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 357 | cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_AUDIO; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 358 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 359 | private: |
| 360 | // overrides from BaseChannel |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 361 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 362 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 363 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 364 | std::string* error_desc) override; |
| 365 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 366 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 367 | std::string* error_desc) override; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [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_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 375 | }; |
| 376 | |
| 377 | // VideoChannel is a specialization for video. |
| 378 | class VideoChannel : public BaseChannel { |
| 379 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 380 | VideoChannel(rtc::Thread* worker_thread, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 381 | rtc::Thread* network_thread, |
| 382 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 383 | std::unique_ptr<VideoMediaChannel> media_channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 384 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 385 | bool srtp_required, |
| 386 | rtc::CryptoOptions crypto_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 387 | ~VideoChannel(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 388 | |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 389 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 390 | VideoMediaChannel* media_channel() const override { |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 391 | return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); |
| 392 | } |
| 393 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 394 | void FillBitrateInfo(BandwidthEstimationInfo* bwe_info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 395 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 396 | cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 397 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 398 | private: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 399 | // overrides from BaseChannel |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 400 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 401 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 402 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 403 | std::string* error_desc) override; |
| 404 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 405 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 406 | std::string* error_desc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 407 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 408 | // Last VideoSendParameters sent down to the media_channel() via |
| 409 | // SetSendParameters. |
| 410 | VideoSendParameters last_send_params_; |
| 411 | // Last VideoRecvParameters sent down to the media_channel() via |
| 412 | // SetRecvParameters. |
| 413 | VideoRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 414 | }; |
| 415 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 416 | // RtpDataChannel is a specialization for data. |
| 417 | class RtpDataChannel : public BaseChannel { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 418 | public: |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 419 | RtpDataChannel(rtc::Thread* worker_thread, |
| 420 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 421 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 422 | std::unique_ptr<DataMediaChannel> channel, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 423 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 424 | bool srtp_required, |
| 425 | rtc::CryptoOptions crypto_options); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 426 | ~RtpDataChannel(); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 427 | // TODO(zhihuang): Remove this once the RtpTransport can be shared between |
| 428 | // BaseChannels. |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 429 | void Init_w(DtlsTransportInternal* rtp_dtls_transport, |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 430 | DtlsTransportInternal* rtcp_dtls_transport, |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 431 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 432 | rtc::PacketTransportInternal* rtcp_packet_transport); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 433 | void Init_w(webrtc::RtpTransportInternal* rtp_transport); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 434 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 435 | virtual bool SendData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 436 | const rtc::CopyOnWriteBuffer& payload, |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 437 | SendDataResult* result); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 438 | |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 439 | // Should be called on the signaling thread only. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 440 | bool ready_to_send_data() const { return ready_to_send_data_; } |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 441 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 442 | sigslot::signal2<const ReceiveDataParams&, const rtc::CopyOnWriteBuffer&> |
| 443 | SignalDataReceived; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 444 | // Signal for notifying when the channel becomes ready to send data. |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 445 | // That occurs when the channel is enabled, the transport is writable, |
| 446 | // both local and remote descriptions are set, and the channel is unblocked. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 447 | sigslot::signal1<bool> SignalReadyToSendData; |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 448 | cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 449 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 450 | protected: |
| 451 | // downcasts a MediaChannel. |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 452 | DataMediaChannel* media_channel() const override { |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 453 | return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); |
| 454 | } |
| 455 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 456 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 457 | struct SendDataMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 458 | SendDataMessageData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 459 | const rtc::CopyOnWriteBuffer* payload, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 460 | SendDataResult* result) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 461 | : params(params), payload(payload), result(result), succeeded(false) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 462 | |
| 463 | const SendDataParams& params; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 464 | const rtc::CopyOnWriteBuffer* payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 465 | SendDataResult* result; |
| 466 | bool succeeded; |
| 467 | }; |
| 468 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 469 | struct DataReceivedMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 470 | // We copy the data because the data will become invalid after we |
| 471 | // handle DataMediaChannel::SignalDataReceived but before we fire |
| 472 | // SignalDataReceived. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 473 | DataReceivedMessageData(const ReceiveDataParams& params, |
| 474 | const char* data, |
| 475 | size_t len) |
| 476 | : params(params), payload(data, len) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 477 | const ReceiveDataParams params; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 478 | const rtc::CopyOnWriteBuffer payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 479 | }; |
| 480 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 481 | typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 482 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 483 | // overrides from BaseChannel |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 484 | // Checks that data channel type is RTP. |
| 485 | bool CheckDataChannelTypeFromContent(const DataContentDescription* content, |
| 486 | std::string* error_desc); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 487 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 488 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 489 | std::string* error_desc) override; |
| 490 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 491 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 492 | std::string* error_desc) override; |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 493 | void UpdateMediaSendRecvState_w() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 494 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 495 | void OnMessage(rtc::Message* pmsg) override; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 496 | void OnDataReceived(const ReceiveDataParams& params, |
| 497 | const char* data, |
| 498 | size_t len); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 499 | void OnDataChannelReadyToSend(bool writable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 500 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 501 | bool ready_to_send_data_ = false; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 502 | |
| 503 | // Last DataSendParameters sent down to the media_channel() via |
| 504 | // SetSendParameters. |
| 505 | DataSendParameters last_send_params_; |
| 506 | // Last DataRecvParameters sent down to the media_channel() via |
| 507 | // SetRecvParameters. |
| 508 | DataRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 509 | }; |
| 510 | |
| 511 | } // namespace cricket |
| 512 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 513 | #endif // PC_CHANNEL_H_ |