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 | |
perkj | c11b184 | 2016-03-07 17:34:13 -0800 | [diff] [blame] | 11 | #ifndef WEBRTC_PC_CHANNEL_H_ |
| 12 | #define WEBRTC_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> |
| 15 | #include <set> |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 16 | #include <string> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 17 | #include <utility> |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 18 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | |
kjellander@webrtc.org | 7ffeab5 | 2016-02-26 22:46:09 +0100 | [diff] [blame] | 20 | #include "webrtc/audio_sink.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 21 | #include "webrtc/base/asyncudpsocket.h" |
| 22 | #include "webrtc/base/criticalsection.h" |
| 23 | #include "webrtc/base/network.h" |
| 24 | #include "webrtc/base/sigslot.h" |
| 25 | #include "webrtc/base/window.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 26 | #include "webrtc/media/base/mediachannel.h" |
| 27 | #include "webrtc/media/base/mediaengine.h" |
| 28 | #include "webrtc/media/base/streamparams.h" |
| 29 | #include "webrtc/media/base/videocapturer.h" |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 30 | #include "webrtc/media/base/videosinkinterface.h" |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 31 | #include "webrtc/p2p/base/transportcontroller.h" |
| 32 | #include "webrtc/p2p/client/socketmonitor.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 33 | #include "webrtc/pc/audiomonitor.h" |
| 34 | #include "webrtc/pc/bundlefilter.h" |
| 35 | #include "webrtc/pc/mediamonitor.h" |
| 36 | #include "webrtc/pc/mediasession.h" |
| 37 | #include "webrtc/pc/rtcpmuxfilter.h" |
| 38 | #include "webrtc/pc/srtpfilter.h" |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 39 | |
| 40 | namespace webrtc { |
| 41 | class AudioSinkInterface; |
| 42 | } // namespace webrtc |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | |
| 44 | namespace cricket { |
| 45 | |
| 46 | struct CryptoParams; |
| 47 | class MediaContentDescription; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | |
| 49 | enum SinkType { |
| 50 | SINK_PRE_CRYPTO, // Sink packets before encryption or after decryption. |
| 51 | SINK_POST_CRYPTO // Sink packets after encryption or before decryption. |
| 52 | }; |
| 53 | |
| 54 | // BaseChannel contains logic common to voice and video, including |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 55 | // enable, marshaling calls to a worker thread, and |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | // connection and media monitors. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 57 | // |
| 58 | // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS! |
| 59 | // This is required to avoid a data race between the destructor modifying the |
| 60 | // vtable, and the media channel's thread using BaseChannel as the |
| 61 | // NetworkInterface. |
| 62 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | class BaseChannel |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 64 | : public rtc::MessageHandler, public sigslot::has_slots<>, |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 65 | public MediaChannel::NetworkInterface, |
| 66 | public ConnectionStatsGetter { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | public: |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 68 | BaseChannel(rtc::Thread* thread, |
| 69 | MediaChannel* channel, |
| 70 | TransportController* transport_controller, |
| 71 | const std::string& content_name, |
| 72 | bool rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | virtual ~BaseChannel(); |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 74 | bool Init(); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 75 | // Deinit may be called multiple times and is simply ignored if it's alreay |
| 76 | // done. |
| 77 | void Deinit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 79 | rtc::Thread* worker_thread() const { return worker_thread_; } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 80 | const std::string& content_name() const { return content_name_; } |
| 81 | const std::string& transport_name() const { return transport_name_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | TransportChannel* transport_channel() const { |
| 83 | return transport_channel_; |
| 84 | } |
| 85 | TransportChannel* rtcp_transport_channel() const { |
| 86 | return rtcp_transport_channel_; |
| 87 | } |
| 88 | bool enabled() const { return enabled_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | |
| 90 | // This function returns true if we are using SRTP. |
| 91 | bool secure() const { return srtp_filter_.IsActive(); } |
| 92 | // The following function returns true if we are using |
| 93 | // DTLS-based keying. If you turned off SRTP later, however |
| 94 | // you could have secure() == false and dtls_secure() == true. |
| 95 | bool secure_dtls() const { return dtls_keyed_; } |
| 96 | // This function returns true if we require secure channel for call setup. |
| 97 | bool secure_required() const { return secure_required_; } |
| 98 | |
| 99 | bool writable() const { return writable_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 101 | // Activate RTCP mux, regardless of the state so far. Once |
| 102 | // activated, it can not be deactivated, and if the remote |
| 103 | // description doesn't support RTCP mux, setting the remote |
| 104 | // description will fail. |
| 105 | void ActivateRtcpMux(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 106 | bool SetTransport(const std::string& transport_name); |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 107 | bool PushdownLocalDescription(const SessionDescription* local_desc, |
| 108 | ContentAction action, |
| 109 | std::string* error_desc); |
| 110 | bool PushdownRemoteDescription(const SessionDescription* remote_desc, |
| 111 | ContentAction action, |
| 112 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | // Channel control |
| 114 | bool SetLocalContent(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 115 | ContentAction action, |
| 116 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | bool SetRemoteContent(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 118 | ContentAction action, |
| 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 | |
| 123 | // Multiplexing |
| 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 | |
| 129 | // Monitoring |
| 130 | void StartConnectionMonitor(int cms); |
| 131 | void StopConnectionMonitor(); |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 132 | // For ConnectionStatsGetter, used by ConnectionMonitor |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 133 | bool GetConnectionStats(ConnectionInfos* infos) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 134 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 135 | BundleFilter* bundle_filter() { return &bundle_filter_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 136 | |
| 137 | const std::vector<StreamParams>& local_streams() const { |
| 138 | return local_streams_; |
| 139 | } |
| 140 | const std::vector<StreamParams>& remote_streams() const { |
| 141 | return remote_streams_; |
| 142 | } |
| 143 | |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 144 | sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure; |
| 145 | void SignalDtlsSetupFailure_w(bool rtcp); |
| 146 | void SignalDtlsSetupFailure_s(bool rtcp); |
| 147 | |
buildbot@webrtc.org | 6bfd619 | 2014-05-15 16:15:59 +0000 | [diff] [blame] | 148 | // Used for latency measurements. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 149 | sigslot::signal1<BaseChannel*> SignalFirstPacketReceived; |
| 150 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 151 | // Made public for easier testing. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 152 | void SetReadyToSend(bool rtcp, bool ready); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 153 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 154 | // Only public for unit tests. Otherwise, consider protected. |
rlester | ec9d187 | 2015-10-27 14:22:16 -0700 | [diff] [blame] | 155 | int SetOption(SocketType type, rtc::Socket::Option o, int val) |
| 156 | override; |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 157 | |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 158 | SrtpFilter* srtp_filter() { return &srtp_filter_; } |
| 159 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 160 | protected: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | virtual MediaChannel* media_channel() const { return media_channel_; } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 162 | // Sets the |transport_channel_| (and |rtcp_transport_channel_|, if |rtcp_| is |
| 163 | // true). Gets the transport channels from |transport_controller_|. |
| 164 | bool SetTransport_w(const std::string& transport_name); |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame] | 165 | |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 166 | void set_transport_channel(TransportChannel* transport); |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame] | 167 | void set_rtcp_transport_channel(TransportChannel* transport, |
| 168 | bool update_writablity); |
| 169 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 170 | bool was_ever_writable() const { return was_ever_writable_; } |
| 171 | void set_local_content_direction(MediaContentDirection direction) { |
| 172 | local_content_direction_ = direction; |
| 173 | } |
| 174 | void set_remote_content_direction(MediaContentDirection direction) { |
| 175 | remote_content_direction_ = direction; |
| 176 | } |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 177 | void set_secure_required(bool secure_required) { |
| 178 | secure_required_ = secure_required; |
| 179 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | bool IsReadyToReceive() const; |
| 181 | bool IsReadyToSend() const; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 182 | rtc::Thread* signaling_thread() { |
| 183 | return transport_controller_->signaling_thread(); |
| 184 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 185 | bool rtcp_transport_enabled() const { return rtcp_transport_enabled_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 186 | |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 187 | void ConnectToTransportChannel(TransportChannel* tc); |
| 188 | void DisconnectFromTransportChannel(TransportChannel* tc); |
| 189 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 190 | void FlushRtcpMessages(); |
| 191 | |
| 192 | // NetworkInterface implementation, called by MediaEngine |
rlester | ec9d187 | 2015-10-27 14:22:16 -0700 | [diff] [blame] | 193 | bool SendPacket(rtc::Buffer* packet, |
| 194 | const rtc::PacketOptions& options) override; |
| 195 | bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options) |
| 196 | override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 197 | |
| 198 | // From TransportChannel |
| 199 | void OnWritableState(TransportChannel* channel); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 200 | virtual void OnChannelRead(TransportChannel* channel, |
| 201 | const char* data, |
| 202 | size_t len, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 203 | const rtc::PacketTime& packet_time, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 204 | int flags); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 205 | void OnReadyToSend(TransportChannel* channel); |
| 206 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 207 | void OnDtlsState(TransportChannel* channel, DtlsTransportState state); |
| 208 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 209 | bool PacketIsRtcp(const TransportChannel* channel, const char* data, |
| 210 | size_t len); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 211 | bool SendPacket(bool rtcp, |
| 212 | rtc::Buffer* packet, |
| 213 | const rtc::PacketOptions& options); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 214 | virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet); |
| 215 | void HandlePacket(bool rtcp, rtc::Buffer* packet, |
| 216 | const rtc::PacketTime& packet_time); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 217 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 218 | void EnableMedia_w(); |
| 219 | void DisableMedia_w(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 220 | void UpdateWritableState_w(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | void ChannelWritable_w(); |
| 222 | void ChannelNotWritable_w(); |
| 223 | bool AddRecvStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 224 | bool RemoveRecvStream_w(uint32_t ssrc); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 225 | bool AddSendStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 226 | bool RemoveSendStream_w(uint32_t ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | virtual bool ShouldSetupDtlsSrtp() const; |
| 228 | // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters. |
| 229 | // |rtcp_channel| indicates whether to set up the RTP or RTCP filter. |
| 230 | bool SetupDtlsSrtp(bool rtcp_channel); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 231 | void MaybeSetupDtlsSrtp_w(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | // Set the DTLS-SRTP cipher policy on this channel as appropriate. |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 233 | bool SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | |
| 235 | virtual void ChangeState() = 0; |
| 236 | |
| 237 | // Gets the content info appropriate to the channel (audio or video). |
| 238 | virtual const ContentInfo* GetFirstContent( |
| 239 | const SessionDescription* sdesc) = 0; |
| 240 | bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 241 | ContentAction action, |
| 242 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 243 | bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 244 | ContentAction action, |
| 245 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 246 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 247 | ContentAction action, |
| 248 | std::string* error_desc) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 249 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 250 | ContentAction action, |
| 251 | std::string* error_desc) = 0; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 252 | bool SetRtpTransportParameters_w(const MediaContentDescription* content, |
| 253 | ContentAction action, |
| 254 | ContentSource src, |
| 255 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 256 | |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 257 | // Helper method to get RTP Absoulute SendTime extension header id if |
| 258 | // present in remote supported extensions list. |
| 259 | void MaybeCacheRtpAbsSendTimeHeaderExtension( |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 260 | const std::vector<RtpHeaderExtension>& extensions); |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 261 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 262 | bool CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, |
| 263 | bool* dtls, |
| 264 | std::string* error_desc); |
| 265 | bool SetSrtp_w(const std::vector<CryptoParams>& params, |
| 266 | ContentAction action, |
| 267 | ContentSource src, |
| 268 | std::string* error_desc); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 269 | void ActivateRtcpMux_w(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 270 | bool SetRtcpMux_w(bool enable, |
| 271 | ContentAction action, |
| 272 | ContentSource src, |
| 273 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | |
| 275 | // From MessageHandler |
rlester | ec9d187 | 2015-10-27 14:22:16 -0700 | [diff] [blame] | 276 | void OnMessage(rtc::Message* pmsg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 277 | |
| 278 | // Handled in derived classes |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 279 | // Get the SRTP crypto suites to use for RTP media |
| 280 | virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const = 0; |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 281 | virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 282 | const std::vector<ConnectionInfo>& infos) = 0; |
| 283 | |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 284 | // Helper function for invoking bool-returning methods on the worker thread. |
| 285 | template <class FunctorT> |
| 286 | bool InvokeOnWorker(const FunctorT& functor) { |
| 287 | return worker_thread_->Invoke<bool>(functor); |
| 288 | } |
| 289 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 290 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 291 | rtc::Thread* worker_thread_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 292 | TransportController* transport_controller_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 293 | MediaChannel* media_channel_; |
| 294 | std::vector<StreamParams> local_streams_; |
| 295 | std::vector<StreamParams> remote_streams_; |
| 296 | |
pthatcher@webrtc.org | 990a00c | 2015-03-13 18:20:33 +0000 | [diff] [blame] | 297 | const std::string content_name_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 298 | std::string transport_name_; |
| 299 | bool rtcp_transport_enabled_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 300 | TransportChannel* transport_channel_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 301 | std::vector<std::pair<rtc::Socket::Option, int> > socket_options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 302 | TransportChannel* rtcp_transport_channel_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 303 | std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | SrtpFilter srtp_filter_; |
| 305 | RtcpMuxFilter rtcp_mux_filter_; |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 306 | BundleFilter bundle_filter_; |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 307 | rtc::scoped_ptr<ConnectionMonitor> connection_monitor_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 308 | bool enabled_; |
| 309 | bool writable_; |
| 310 | bool rtp_ready_to_send_; |
| 311 | bool rtcp_ready_to_send_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 312 | bool was_ever_writable_; |
| 313 | MediaContentDirection local_content_direction_; |
| 314 | MediaContentDirection remote_content_direction_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 315 | bool has_received_packet_; |
| 316 | bool dtls_keyed_; |
| 317 | bool secure_required_; |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 318 | int rtp_abs_sendtime_extn_id_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | // VoiceChannel is a specialization that adds support for early media, DTMF, |
| 322 | // and input/output level monitoring. |
| 323 | class VoiceChannel : public BaseChannel { |
| 324 | public: |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 325 | VoiceChannel(rtc::Thread* thread, |
| 326 | MediaEngineInterface* media_engine, |
| 327 | VoiceMediaChannel* channel, |
| 328 | TransportController* transport_controller, |
| 329 | const std::string& content_name, |
| 330 | bool rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 331 | ~VoiceChannel(); |
| 332 | bool Init(); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 333 | |
| 334 | // Configure sending media on the stream with SSRC |ssrc| |
| 335 | // If there is only one sending stream SSRC 0 can be used. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 336 | bool SetAudioSend(uint32_t ssrc, |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 337 | bool enable, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 338 | const AudioOptions* options, |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame^] | 339 | AudioSource* source); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 340 | |
| 341 | // downcasts a MediaChannel |
| 342 | virtual VoiceMediaChannel* media_channel() const { |
| 343 | return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel()); |
| 344 | } |
| 345 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 346 | void SetEarlyMedia(bool enable); |
| 347 | // This signal is emitted when we have gone a period of time without |
| 348 | // receiving early media. When received, a UI should start playing its |
| 349 | // own ringing sound |
| 350 | sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout; |
| 351 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 352 | // Returns if the telephone-event has been negotiated. |
| 353 | bool CanInsertDtmf(); |
| 354 | // Send and/or play a DTMF |event| according to the |flags|. |
| 355 | // The DTMF out-of-band signal will be used on sending. |
| 356 | // The |ssrc| should be either 0 or a valid send stream ssrc. |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 +0000 | [diff] [blame] | 357 | // The valid value for the |event| are 0 which corresponding to DTMF |
| 358 | // event 0-9, *, #, A-D. |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 359 | bool InsertDtmf(uint32_t ssrc, int event_code, int duration); |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 360 | bool SetOutputVolume(uint32_t ssrc, double volume); |
deadbeef | 2d110be | 2016-01-13 12:00:26 -0800 | [diff] [blame] | 361 | void SetRawAudioSink(uint32_t ssrc, |
| 362 | rtc::scoped_ptr<webrtc::AudioSinkInterface> sink); |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 363 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 364 | // Get statistics about the current media session. |
| 365 | bool GetStats(VoiceMediaInfo* stats); |
| 366 | |
| 367 | // Monitoring functions |
| 368 | sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&> |
| 369 | SignalConnectionMonitor; |
| 370 | |
| 371 | void StartMediaMonitor(int cms); |
| 372 | void StopMediaMonitor(); |
| 373 | sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor; |
| 374 | |
| 375 | void StartAudioMonitor(int cms); |
| 376 | void StopAudioMonitor(); |
| 377 | bool IsAudioMonitorRunning() const; |
| 378 | sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor; |
| 379 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 380 | int GetInputLevel_w(); |
| 381 | int GetOutputLevel_w(); |
| 382 | void GetActiveStreams_w(AudioInfo::StreamList* actives); |
| 383 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 384 | private: |
| 385 | // overrides from BaseChannel |
| 386 | virtual void OnChannelRead(TransportChannel* channel, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 387 | const char* data, size_t len, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 388 | const rtc::PacketTime& packet_time, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 389 | int flags); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 390 | virtual void ChangeState(); |
| 391 | virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); |
| 392 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 393 | ContentAction action, |
| 394 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 395 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 396 | ContentAction action, |
| 397 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 398 | void HandleEarlyMediaTimeout(); |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 399 | bool InsertDtmf_w(uint32_t ssrc, int event, int duration); |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 400 | bool SetOutputVolume_w(uint32_t ssrc, double volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 401 | bool GetStats_w(VoiceMediaInfo* stats); |
| 402 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 403 | virtual void OnMessage(rtc::Message* pmsg); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 404 | virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 405 | virtual void OnConnectionMonitorUpdate( |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 406 | ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 407 | virtual void OnMediaMonitorUpdate( |
| 408 | VoiceMediaChannel* media_channel, const VoiceMediaInfo& info); |
| 409 | void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 410 | |
| 411 | static const int kEarlyMediaTimeout = 1000; |
Fredrik Solenberg | 0c02264 | 2015-08-05 12:25:22 +0200 | [diff] [blame] | 412 | MediaEngineInterface* media_engine_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 413 | bool received_media_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 414 | rtc::scoped_ptr<VoiceMediaMonitor> media_monitor_; |
| 415 | rtc::scoped_ptr<AudioMonitor> audio_monitor_; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 416 | |
| 417 | // Last AudioSendParameters sent down to the media_channel() via |
| 418 | // SetSendParameters. |
| 419 | AudioSendParameters last_send_params_; |
| 420 | // Last AudioRecvParameters sent down to the media_channel() via |
| 421 | // SetRecvParameters. |
| 422 | AudioRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | // VideoChannel is a specialization for video. |
| 426 | class VideoChannel : public BaseChannel { |
| 427 | public: |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 428 | VideoChannel(rtc::Thread* thread, |
| 429 | VideoMediaChannel* channel, |
| 430 | TransportController* transport_controller, |
| 431 | const std::string& content_name, |
Fredrik Solenberg | 0c02264 | 2015-08-05 12:25:22 +0200 | [diff] [blame] | 432 | bool rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 433 | ~VideoChannel(); |
| 434 | bool Init(); |
| 435 | |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 436 | // downcasts a MediaChannel |
| 437 | virtual VideoMediaChannel* media_channel() const { |
| 438 | return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); |
| 439 | } |
| 440 | |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 441 | bool SetSink(uint32_t ssrc, rtc::VideoSinkInterface<VideoFrame>* sink); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 442 | bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 443 | // Get statistics about the current media session. |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 444 | bool GetStats(VideoMediaInfo* stats); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 445 | |
| 446 | sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&> |
| 447 | SignalConnectionMonitor; |
| 448 | |
| 449 | void StartMediaMonitor(int cms); |
| 450 | void StopMediaMonitor(); |
| 451 | sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 452 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 453 | bool SetVideoSend(uint32_t ssrc, bool enable, const VideoOptions* options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 454 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 455 | private: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 456 | // overrides from BaseChannel |
| 457 | virtual void ChangeState(); |
| 458 | virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); |
| 459 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 460 | ContentAction action, |
| 461 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 462 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 463 | ContentAction action, |
| 464 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 465 | bool GetStats_w(VideoMediaInfo* stats); |
| 466 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 467 | virtual void OnMessage(rtc::Message* pmsg); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 468 | virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 469 | virtual void OnConnectionMonitorUpdate( |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 470 | ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 471 | virtual void OnMediaMonitorUpdate( |
| 472 | VideoMediaChannel* media_channel, const VideoMediaInfo& info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 473 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 474 | rtc::scoped_ptr<VideoMediaMonitor> media_monitor_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 475 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 476 | // Last VideoSendParameters sent down to the media_channel() via |
| 477 | // SetSendParameters. |
| 478 | VideoSendParameters last_send_params_; |
| 479 | // Last VideoRecvParameters sent down to the media_channel() via |
| 480 | // SetRecvParameters. |
| 481 | VideoRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 482 | }; |
| 483 | |
| 484 | // DataChannel is a specialization for data. |
| 485 | class DataChannel : public BaseChannel { |
| 486 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 487 | DataChannel(rtc::Thread* thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 488 | DataMediaChannel* media_channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 489 | TransportController* transport_controller, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 490 | const std::string& content_name, |
| 491 | bool rtcp); |
| 492 | ~DataChannel(); |
| 493 | bool Init(); |
| 494 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 495 | virtual bool SendData(const SendDataParams& params, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 496 | const rtc::Buffer& payload, |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 497 | SendDataResult* result); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 498 | |
| 499 | void StartMediaMonitor(int cms); |
| 500 | void StopMediaMonitor(); |
| 501 | |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 502 | // Should be called on the signaling thread only. |
| 503 | bool ready_to_send_data() const { |
| 504 | return ready_to_send_data_; |
| 505 | } |
| 506 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 507 | sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor; |
| 508 | sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&> |
| 509 | SignalConnectionMonitor; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 510 | sigslot::signal3<DataChannel*, const ReceiveDataParams&, const rtc::Buffer&> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 511 | SignalDataReceived; |
| 512 | // Signal for notifying when the channel becomes ready to send data. |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 513 | // That occurs when the channel is enabled, the transport is writable, |
| 514 | // 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] | 515 | sigslot::signal1<bool> SignalReadyToSendData; |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 +0000 | [diff] [blame] | 516 | // Signal for notifying that the remote side has closed the DataChannel. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 517 | sigslot::signal1<uint32_t> SignalStreamClosedRemotely; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 518 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 519 | protected: |
| 520 | // downcasts a MediaChannel. |
| 521 | virtual DataMediaChannel* media_channel() const { |
| 522 | return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); |
| 523 | } |
| 524 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 525 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 526 | struct SendDataMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 527 | SendDataMessageData(const SendDataParams& params, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 528 | const rtc::Buffer* payload, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 529 | SendDataResult* result) |
| 530 | : params(params), |
| 531 | payload(payload), |
| 532 | result(result), |
| 533 | succeeded(false) { |
| 534 | } |
| 535 | |
| 536 | const SendDataParams& params; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 537 | const rtc::Buffer* payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 538 | SendDataResult* result; |
| 539 | bool succeeded; |
| 540 | }; |
| 541 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 542 | struct DataReceivedMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 543 | // We copy the data because the data will become invalid after we |
| 544 | // handle DataMediaChannel::SignalDataReceived but before we fire |
| 545 | // SignalDataReceived. |
| 546 | DataReceivedMessageData( |
| 547 | const ReceiveDataParams& params, const char* data, size_t len) |
| 548 | : params(params), |
| 549 | payload(data, len) { |
| 550 | } |
| 551 | const ReceiveDataParams params; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 552 | const rtc::Buffer payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 553 | }; |
| 554 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 555 | typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 556 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 557 | // overrides from BaseChannel |
| 558 | virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); |
| 559 | // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that |
| 560 | // it's the same as what was set previously. Returns false if it's |
| 561 | // set to one type one type and changed to another type later. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 562 | bool SetDataChannelType(DataChannelType new_data_channel_type, |
| 563 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 564 | // Same as SetDataChannelType, but extracts the type from the |
| 565 | // DataContentDescription. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 566 | bool SetDataChannelTypeFromContent(const DataContentDescription* content, |
| 567 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 568 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 569 | ContentAction action, |
| 570 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 571 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 572 | ContentAction action, |
| 573 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 574 | virtual void ChangeState(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 575 | virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 576 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 577 | virtual void OnMessage(rtc::Message* pmsg); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 578 | virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 579 | virtual void OnConnectionMonitorUpdate( |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 580 | ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 581 | virtual void OnMediaMonitorUpdate( |
| 582 | DataMediaChannel* media_channel, const DataMediaInfo& info); |
| 583 | virtual bool ShouldSetupDtlsSrtp() const; |
| 584 | void OnDataReceived( |
| 585 | const ReceiveDataParams& params, const char* data, size_t len); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 586 | void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 587 | void OnDataChannelReadyToSend(bool writable); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 588 | void OnStreamClosedRemotely(uint32_t sid); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 589 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 590 | rtc::scoped_ptr<DataMediaMonitor> media_monitor_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 591 | // TODO(pthatcher): Make a separate SctpDataChannel and |
| 592 | // RtpDataChannel instead of using this. |
| 593 | DataChannelType data_channel_type_; |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 594 | bool ready_to_send_data_; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 595 | |
| 596 | // Last DataSendParameters sent down to the media_channel() via |
| 597 | // SetSendParameters. |
| 598 | DataSendParameters last_send_params_; |
| 599 | // Last DataRecvParameters sent down to the media_channel() via |
| 600 | // SetRecvParameters. |
| 601 | DataRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 602 | }; |
| 603 | |
| 604 | } // namespace cricket |
| 605 | |
perkj | c11b184 | 2016-03-07 17:34:13 -0800 | [diff] [blame] | 606 | #endif // WEBRTC_PC_CHANNEL_H_ |