henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2004 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef TALK_SESSION_MEDIA_CHANNEL_H_ |
| 29 | #define TALK_SESSION_MEDIA_CHANNEL_H_ |
| 30 | |
| 31 | #include <string> |
| 32 | #include <vector> |
| 33 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | #include "talk/media/base/mediachannel.h" |
| 35 | #include "talk/media/base/mediaengine.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | #include "talk/media/base/streamparams.h" |
| 37 | #include "talk/media/base/videocapturer.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 38 | #include "webrtc/p2p/base/session.h" |
| 39 | #include "webrtc/p2p/client/socketmonitor.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | #include "talk/session/media/audiomonitor.h" |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 41 | #include "talk/session/media/bundlefilter.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | #include "talk/session/media/mediamonitor.h" |
| 43 | #include "talk/session/media/mediasession.h" |
| 44 | #include "talk/session/media/rtcpmuxfilter.h" |
| 45 | #include "talk/session/media/srtpfilter.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 46 | #include "webrtc/base/asyncudpsocket.h" |
| 47 | #include "webrtc/base/criticalsection.h" |
| 48 | #include "webrtc/base/network.h" |
| 49 | #include "webrtc/base/sigslot.h" |
| 50 | #include "webrtc/base/window.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | |
| 52 | namespace cricket { |
| 53 | |
| 54 | struct CryptoParams; |
| 55 | class MediaContentDescription; |
| 56 | struct TypingMonitorOptions; |
| 57 | class TypingMonitor; |
| 58 | struct ViewRequest; |
| 59 | |
| 60 | enum SinkType { |
| 61 | SINK_PRE_CRYPTO, // Sink packets before encryption or after decryption. |
| 62 | SINK_POST_CRYPTO // Sink packets after encryption or before decryption. |
| 63 | }; |
| 64 | |
| 65 | // BaseChannel contains logic common to voice and video, including |
| 66 | // enable/mute, marshaling calls to a worker thread, and |
| 67 | // connection and media monitors. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 68 | // |
| 69 | // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS! |
| 70 | // This is required to avoid a data race between the destructor modifying the |
| 71 | // vtable, and the media channel's thread using BaseChannel as the |
| 72 | // NetworkInterface. |
| 73 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | class BaseChannel |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 75 | : public rtc::MessageHandler, public sigslot::has_slots<>, |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame^] | 76 | public MediaChannel::NetworkInterface, |
| 77 | public ConnectionStatsGetter { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 79 | BaseChannel(rtc::Thread* thread, MediaEngineInterface* media_engine, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | MediaChannel* channel, BaseSession* session, |
| 81 | const std::string& content_name, bool rtcp); |
| 82 | virtual ~BaseChannel(); |
| 83 | bool Init(TransportChannel* transport_channel, |
| 84 | TransportChannel* rtcp_transport_channel); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 85 | // Deinit may be called multiple times and is simply ignored if it's alreay |
| 86 | // done. |
| 87 | void Deinit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 88 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 89 | rtc::Thread* worker_thread() const { return worker_thread_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | BaseSession* session() const { return session_; } |
| 91 | const std::string& content_name() { return content_name_; } |
| 92 | TransportChannel* transport_channel() const { |
| 93 | return transport_channel_; |
| 94 | } |
| 95 | TransportChannel* rtcp_transport_channel() const { |
| 96 | return rtcp_transport_channel_; |
| 97 | } |
| 98 | bool enabled() const { return enabled_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | |
| 100 | // This function returns true if we are using SRTP. |
| 101 | bool secure() const { return srtp_filter_.IsActive(); } |
| 102 | // The following function returns true if we are using |
| 103 | // DTLS-based keying. If you turned off SRTP later, however |
| 104 | // you could have secure() == false and dtls_secure() == true. |
| 105 | bool secure_dtls() const { return dtls_keyed_; } |
| 106 | // This function returns true if we require secure channel for call setup. |
| 107 | bool secure_required() const { return secure_required_; } |
| 108 | |
| 109 | bool writable() const { return writable_; } |
| 110 | bool IsStreamMuted(uint32 ssrc); |
| 111 | |
| 112 | // Channel control |
| 113 | bool SetLocalContent(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 114 | ContentAction action, |
| 115 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | bool SetRemoteContent(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 117 | ContentAction action, |
| 118 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | |
| 120 | bool Enable(bool enable); |
| 121 | // Mute sending media on the stream with SSRC |ssrc| |
| 122 | // If there is only one sending stream SSRC 0 can be used. |
| 123 | bool MuteStream(uint32 ssrc, bool mute); |
| 124 | |
| 125 | // Multiplexing |
| 126 | bool AddRecvStream(const StreamParams& sp); |
| 127 | bool RemoveRecvStream(uint32 ssrc); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 128 | bool AddSendStream(const StreamParams& sp); |
| 129 | bool RemoveSendStream(uint32 ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | |
| 131 | // Monitoring |
| 132 | void StartConnectionMonitor(int cms); |
| 133 | void StopConnectionMonitor(); |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame^] | 134 | // For ConnectionStatsGetter, used by ConnectionMonitor |
| 135 | virtual bool GetConnectionStats(ConnectionInfos* infos) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 136 | |
| 137 | void set_srtp_signal_silent_time(uint32 silent_time) { |
| 138 | srtp_filter_.set_signal_silent_time(silent_time); |
| 139 | } |
| 140 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 141 | template <class T> |
| 142 | void RegisterSendSink(T* sink, |
| 143 | void (T::*OnPacket)(const void*, size_t, bool), |
| 144 | SinkType type) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 145 | rtc::CritScope cs(&signal_send_packet_cs_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | if (SINK_POST_CRYPTO == type) { |
| 147 | SignalSendPacketPostCrypto.disconnect(sink); |
| 148 | SignalSendPacketPostCrypto.connect(sink, OnPacket); |
| 149 | } else { |
| 150 | SignalSendPacketPreCrypto.disconnect(sink); |
| 151 | SignalSendPacketPreCrypto.connect(sink, OnPacket); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | void UnregisterSendSink(sigslot::has_slots<>* sink, |
| 156 | SinkType type) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 157 | rtc::CritScope cs(&signal_send_packet_cs_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 158 | if (SINK_POST_CRYPTO == type) { |
| 159 | SignalSendPacketPostCrypto.disconnect(sink); |
| 160 | } else { |
| 161 | SignalSendPacketPreCrypto.disconnect(sink); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | bool HasSendSinks(SinkType type) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 166 | rtc::CritScope cs(&signal_send_packet_cs_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 167 | if (SINK_POST_CRYPTO == type) { |
| 168 | return !SignalSendPacketPostCrypto.is_empty(); |
| 169 | } else { |
| 170 | return !SignalSendPacketPreCrypto.is_empty(); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | template <class T> |
| 175 | void RegisterRecvSink(T* sink, |
| 176 | void (T::*OnPacket)(const void*, size_t, bool), |
| 177 | SinkType type) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 178 | rtc::CritScope cs(&signal_recv_packet_cs_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 179 | if (SINK_POST_CRYPTO == type) { |
| 180 | SignalRecvPacketPostCrypto.disconnect(sink); |
| 181 | SignalRecvPacketPostCrypto.connect(sink, OnPacket); |
| 182 | } else { |
| 183 | SignalRecvPacketPreCrypto.disconnect(sink); |
| 184 | SignalRecvPacketPreCrypto.connect(sink, OnPacket); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | void UnregisterRecvSink(sigslot::has_slots<>* sink, |
| 189 | SinkType type) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 190 | rtc::CritScope cs(&signal_recv_packet_cs_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 191 | if (SINK_POST_CRYPTO == type) { |
| 192 | SignalRecvPacketPostCrypto.disconnect(sink); |
| 193 | } else { |
| 194 | SignalRecvPacketPreCrypto.disconnect(sink); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | bool HasRecvSinks(SinkType type) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 199 | rtc::CritScope cs(&signal_recv_packet_cs_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 200 | if (SINK_POST_CRYPTO == type) { |
| 201 | return !SignalRecvPacketPostCrypto.is_empty(); |
| 202 | } else { |
| 203 | return !SignalRecvPacketPreCrypto.is_empty(); |
| 204 | } |
| 205 | } |
| 206 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 207 | BundleFilter* bundle_filter() { return &bundle_filter_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | |
| 209 | const std::vector<StreamParams>& local_streams() const { |
| 210 | return local_streams_; |
| 211 | } |
| 212 | const std::vector<StreamParams>& remote_streams() const { |
| 213 | return remote_streams_; |
| 214 | } |
| 215 | |
buildbot@webrtc.org | 6bfd619 | 2014-05-15 16:15:59 +0000 | [diff] [blame] | 216 | // Used for latency measurements. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 217 | sigslot::signal1<BaseChannel*> SignalFirstPacketReceived; |
| 218 | |
| 219 | // Used to alert UI when the muted status changes, perhaps autonomously. |
| 220 | sigslot::repeater2<BaseChannel*, bool> SignalAutoMuted; |
| 221 | |
| 222 | // Made public for easier testing. |
| 223 | void SetReadyToSend(TransportChannel* channel, bool ready); |
| 224 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 225 | // Only public for unit tests. Otherwise, consider protected. |
| 226 | virtual int SetOption(SocketType type, rtc::Socket::Option o, int val); |
| 227 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 228 | protected: |
| 229 | MediaEngineInterface* media_engine() const { return media_engine_; } |
| 230 | virtual MediaChannel* media_channel() const { return media_channel_; } |
| 231 | void set_rtcp_transport_channel(TransportChannel* transport); |
| 232 | bool was_ever_writable() const { return was_ever_writable_; } |
| 233 | void set_local_content_direction(MediaContentDirection direction) { |
| 234 | local_content_direction_ = direction; |
| 235 | } |
| 236 | void set_remote_content_direction(MediaContentDirection direction) { |
| 237 | remote_content_direction_ = direction; |
| 238 | } |
| 239 | bool IsReadyToReceive() const; |
| 240 | bool IsReadyToSend() const; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 241 | rtc::Thread* signaling_thread() { return session_->signaling_thread(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 242 | SrtpFilter* srtp_filter() { return &srtp_filter_; } |
| 243 | bool rtcp() const { return rtcp_; } |
| 244 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | void FlushRtcpMessages(); |
| 246 | |
| 247 | // NetworkInterface implementation, called by MediaEngine |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 248 | virtual bool SendPacket(rtc::Buffer* packet, |
| 249 | rtc::DiffServCodePoint dscp); |
| 250 | virtual bool SendRtcp(rtc::Buffer* packet, |
| 251 | rtc::DiffServCodePoint dscp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 252 | |
| 253 | // From TransportChannel |
| 254 | void OnWritableState(TransportChannel* channel); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 255 | virtual void OnChannelRead(TransportChannel* channel, |
| 256 | const char* data, |
| 257 | size_t len, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 258 | const rtc::PacketTime& packet_time, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 259 | int flags); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 260 | void OnReadyToSend(TransportChannel* channel); |
| 261 | |
| 262 | bool PacketIsRtcp(const TransportChannel* channel, const char* data, |
| 263 | size_t len); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 264 | bool SendPacket(bool rtcp, rtc::Buffer* packet, |
| 265 | rtc::DiffServCodePoint dscp); |
| 266 | virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet); |
| 267 | void HandlePacket(bool rtcp, rtc::Buffer* packet, |
| 268 | const rtc::PacketTime& packet_time); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 269 | |
| 270 | // Apply the new local/remote session description. |
| 271 | void OnNewLocalDescription(BaseSession* session, ContentAction action); |
| 272 | void OnNewRemoteDescription(BaseSession* session, ContentAction action); |
| 273 | |
| 274 | void EnableMedia_w(); |
| 275 | void DisableMedia_w(); |
| 276 | virtual bool MuteStream_w(uint32 ssrc, bool mute); |
| 277 | bool IsStreamMuted_w(uint32 ssrc); |
| 278 | void ChannelWritable_w(); |
| 279 | void ChannelNotWritable_w(); |
| 280 | bool AddRecvStream_w(const StreamParams& sp); |
| 281 | bool RemoveRecvStream_w(uint32 ssrc); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 282 | bool AddSendStream_w(const StreamParams& sp); |
| 283 | bool RemoveSendStream_w(uint32 ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 284 | virtual bool ShouldSetupDtlsSrtp() const; |
| 285 | // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters. |
| 286 | // |rtcp_channel| indicates whether to set up the RTP or RTCP filter. |
| 287 | bool SetupDtlsSrtp(bool rtcp_channel); |
| 288 | // Set the DTLS-SRTP cipher policy on this channel as appropriate. |
| 289 | bool SetDtlsSrtpCiphers(TransportChannel *tc, bool rtcp); |
| 290 | |
| 291 | virtual void ChangeState() = 0; |
| 292 | |
| 293 | // Gets the content info appropriate to the channel (audio or video). |
| 294 | virtual const ContentInfo* GetFirstContent( |
| 295 | const SessionDescription* sdesc) = 0; |
| 296 | bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 297 | ContentAction action, |
| 298 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 299 | bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 300 | ContentAction action, |
| 301 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 302 | bool SetBaseLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 303 | ContentAction action, |
| 304 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 305 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 306 | ContentAction action, |
| 307 | std::string* error_desc) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 308 | bool SetBaseRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 309 | ContentAction action, |
| 310 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 311 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 312 | ContentAction action, |
| 313 | std::string* error_desc) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 314 | |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 315 | // Helper method to get RTP Absoulute SendTime extension header id if |
| 316 | // present in remote supported extensions list. |
| 317 | void MaybeCacheRtpAbsSendTimeHeaderExtension( |
| 318 | const std::vector<RtpHeaderExtension>& extensions); |
| 319 | |
buildbot@webrtc.org | 75ce920 | 2014-06-20 12:30:24 +0000 | [diff] [blame] | 320 | bool SetRecvRtpHeaderExtensions_w(const MediaContentDescription* content, |
| 321 | MediaChannel* media_channel, |
| 322 | std::string* error_desc); |
| 323 | bool SetSendRtpHeaderExtensions_w(const MediaContentDescription* content, |
| 324 | MediaChannel* media_channel, |
| 325 | std::string* error_desc); |
| 326 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 327 | bool CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, |
| 328 | bool* dtls, |
| 329 | std::string* error_desc); |
| 330 | bool SetSrtp_w(const std::vector<CryptoParams>& params, |
| 331 | ContentAction action, |
| 332 | ContentSource src, |
| 333 | std::string* error_desc); |
| 334 | bool SetRtcpMux_w(bool enable, |
| 335 | ContentAction action, |
| 336 | ContentSource src, |
| 337 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 338 | |
| 339 | // From MessageHandler |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 340 | virtual void OnMessage(rtc::Message* pmsg); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | |
| 342 | // Handled in derived classes |
| 343 | // Get the SRTP ciphers to use for RTP media |
| 344 | virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const = 0; |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame^] | 345 | virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 346 | const std::vector<ConnectionInfo>& infos) = 0; |
| 347 | |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 348 | // Helper function for invoking bool-returning methods on the worker thread. |
| 349 | template <class FunctorT> |
| 350 | bool InvokeOnWorker(const FunctorT& functor) { |
| 351 | return worker_thread_->Invoke<bool>(functor); |
| 352 | } |
| 353 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 354 | private: |
| 355 | sigslot::signal3<const void*, size_t, bool> SignalSendPacketPreCrypto; |
| 356 | sigslot::signal3<const void*, size_t, bool> SignalSendPacketPostCrypto; |
| 357 | sigslot::signal3<const void*, size_t, bool> SignalRecvPacketPreCrypto; |
| 358 | sigslot::signal3<const void*, size_t, bool> SignalRecvPacketPostCrypto; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 359 | rtc::CriticalSection signal_send_packet_cs_; |
| 360 | rtc::CriticalSection signal_recv_packet_cs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 361 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 362 | rtc::Thread* worker_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 363 | MediaEngineInterface* media_engine_; |
| 364 | BaseSession* session_; |
| 365 | MediaChannel* media_channel_; |
| 366 | std::vector<StreamParams> local_streams_; |
| 367 | std::vector<StreamParams> remote_streams_; |
| 368 | |
pthatcher@webrtc.org | 990a00c | 2015-03-13 18:20:33 +0000 | [diff] [blame] | 369 | const std::string content_name_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 370 | bool rtcp_; |
| 371 | TransportChannel* transport_channel_; |
| 372 | TransportChannel* rtcp_transport_channel_; |
| 373 | SrtpFilter srtp_filter_; |
| 374 | RtcpMuxFilter rtcp_mux_filter_; |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 375 | BundleFilter bundle_filter_; |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame^] | 376 | rtc::scoped_ptr<ConnectionMonitor> connection_monitor_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 377 | bool enabled_; |
| 378 | bool writable_; |
| 379 | bool rtp_ready_to_send_; |
| 380 | bool rtcp_ready_to_send_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 381 | bool was_ever_writable_; |
| 382 | MediaContentDirection local_content_direction_; |
| 383 | MediaContentDirection remote_content_direction_; |
| 384 | std::set<uint32> muted_streams_; |
| 385 | bool has_received_packet_; |
| 386 | bool dtls_keyed_; |
| 387 | bool secure_required_; |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 388 | int rtp_abs_sendtime_extn_id_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | // VoiceChannel is a specialization that adds support for early media, DTMF, |
| 392 | // and input/output level monitoring. |
| 393 | class VoiceChannel : public BaseChannel { |
| 394 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 395 | VoiceChannel(rtc::Thread* thread, MediaEngineInterface* media_engine, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 396 | VoiceMediaChannel* channel, BaseSession* session, |
| 397 | const std::string& content_name, bool rtcp); |
| 398 | ~VoiceChannel(); |
| 399 | bool Init(); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 400 | bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer); |
| 401 | bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 402 | |
| 403 | // downcasts a MediaChannel |
| 404 | virtual VoiceMediaChannel* media_channel() const { |
| 405 | return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel()); |
| 406 | } |
| 407 | |
| 408 | bool SetRingbackTone(const void* buf, int len); |
| 409 | void SetEarlyMedia(bool enable); |
| 410 | // This signal is emitted when we have gone a period of time without |
| 411 | // receiving early media. When received, a UI should start playing its |
| 412 | // own ringing sound |
| 413 | sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout; |
| 414 | |
| 415 | bool PlayRingbackTone(uint32 ssrc, bool play, bool loop); |
| 416 | // TODO(ronghuawu): Replace PressDTMF with InsertDtmf. |
| 417 | bool PressDTMF(int digit, bool playout); |
| 418 | // Returns if the telephone-event has been negotiated. |
| 419 | bool CanInsertDtmf(); |
| 420 | // Send and/or play a DTMF |event| according to the |flags|. |
| 421 | // The DTMF out-of-band signal will be used on sending. |
| 422 | // 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] | 423 | // The valid value for the |event| are 0 which corresponding to DTMF |
| 424 | // event 0-9, *, #, A-D. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 425 | bool InsertDtmf(uint32 ssrc, int event_code, int duration, int flags); |
| 426 | bool SetOutputScaling(uint32 ssrc, double left, double right); |
| 427 | // Get statistics about the current media session. |
| 428 | bool GetStats(VoiceMediaInfo* stats); |
| 429 | |
| 430 | // Monitoring functions |
| 431 | sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&> |
| 432 | SignalConnectionMonitor; |
| 433 | |
| 434 | void StartMediaMonitor(int cms); |
| 435 | void StopMediaMonitor(); |
| 436 | sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor; |
| 437 | |
| 438 | void StartAudioMonitor(int cms); |
| 439 | void StopAudioMonitor(); |
| 440 | bool IsAudioMonitorRunning() const; |
| 441 | sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor; |
| 442 | |
| 443 | void StartTypingMonitor(const TypingMonitorOptions& settings); |
| 444 | void StopTypingMonitor(); |
| 445 | bool IsTypingMonitorRunning() const; |
| 446 | |
| 447 | // Overrides BaseChannel::MuteStream_w. |
| 448 | virtual bool MuteStream_w(uint32 ssrc, bool mute); |
| 449 | |
| 450 | int GetInputLevel_w(); |
| 451 | int GetOutputLevel_w(); |
| 452 | void GetActiveStreams_w(AudioInfo::StreamList* actives); |
| 453 | |
| 454 | // Signal errors from VoiceMediaChannel. Arguments are: |
| 455 | // ssrc(uint32), and error(VoiceMediaChannel::Error). |
| 456 | sigslot::signal3<VoiceChannel*, uint32, VoiceMediaChannel::Error> |
| 457 | SignalMediaError; |
| 458 | |
| 459 | // Configuration and setting. |
| 460 | bool SetChannelOptions(const AudioOptions& options); |
| 461 | |
| 462 | private: |
| 463 | // overrides from BaseChannel |
| 464 | virtual void OnChannelRead(TransportChannel* channel, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 465 | const char* data, size_t len, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 466 | const rtc::PacketTime& packet_time, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 467 | int flags); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 468 | virtual void ChangeState(); |
| 469 | virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); |
| 470 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 471 | ContentAction action, |
| 472 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 473 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 474 | ContentAction action, |
| 475 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 476 | bool SetRingbackTone_w(const void* buf, int len); |
| 477 | bool PlayRingbackTone_w(uint32 ssrc, bool play, bool loop); |
| 478 | void HandleEarlyMediaTimeout(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 479 | bool InsertDtmf_w(uint32 ssrc, int event, int duration, int flags); |
| 480 | bool SetOutputScaling_w(uint32 ssrc, double left, double right); |
| 481 | bool GetStats_w(VoiceMediaInfo* stats); |
| 482 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 483 | virtual void OnMessage(rtc::Message* pmsg); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 484 | virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const; |
| 485 | virtual void OnConnectionMonitorUpdate( |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame^] | 486 | ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 487 | virtual void OnMediaMonitorUpdate( |
| 488 | VoiceMediaChannel* media_channel, const VoiceMediaInfo& info); |
| 489 | void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info); |
| 490 | void OnVoiceChannelError(uint32 ssrc, VoiceMediaChannel::Error error); |
| 491 | void SendLastMediaError(); |
| 492 | void OnSrtpError(uint32 ssrc, SrtpFilter::Mode mode, SrtpFilter::Error error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 493 | |
| 494 | static const int kEarlyMediaTimeout = 1000; |
| 495 | bool received_media_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 496 | rtc::scoped_ptr<VoiceMediaMonitor> media_monitor_; |
| 497 | rtc::scoped_ptr<AudioMonitor> audio_monitor_; |
| 498 | rtc::scoped_ptr<TypingMonitor> typing_monitor_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 499 | }; |
| 500 | |
| 501 | // VideoChannel is a specialization for video. |
| 502 | class VideoChannel : public BaseChannel { |
| 503 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 504 | VideoChannel(rtc::Thread* thread, MediaEngineInterface* media_engine, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 505 | VideoMediaChannel* channel, BaseSession* session, |
| 506 | const std::string& content_name, bool rtcp, |
| 507 | VoiceChannel* voice_channel); |
| 508 | ~VideoChannel(); |
| 509 | bool Init(); |
| 510 | |
| 511 | bool SetRenderer(uint32 ssrc, VideoRenderer* renderer); |
| 512 | bool ApplyViewRequest(const ViewRequest& request); |
| 513 | |
| 514 | // TODO(pthatcher): Refactor to use a "capture id" instead of an |
| 515 | // ssrc here as the "key". |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 516 | // Passes ownership of the capturer to the channel. |
| 517 | bool AddScreencast(uint32 ssrc, VideoCapturer* capturer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 518 | bool SetCapturer(uint32 ssrc, VideoCapturer* capturer); |
| 519 | bool RemoveScreencast(uint32 ssrc); |
| 520 | // True if we've added a screencast. Doesn't matter if the capturer |
| 521 | // has been started or not. |
| 522 | bool IsScreencasting(); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 523 | int GetScreencastFps(uint32 ssrc); |
| 524 | int GetScreencastMaxPixels(uint32 ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 525 | // Get statistics about the current media session. |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 526 | bool GetStats(VideoMediaInfo* stats); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 527 | |
| 528 | sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&> |
| 529 | SignalConnectionMonitor; |
| 530 | |
| 531 | void StartMediaMonitor(int cms); |
| 532 | void StopMediaMonitor(); |
| 533 | sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 534 | sigslot::signal2<uint32, rtc::WindowEvent> SignalScreencastWindowEvent; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 535 | |
| 536 | bool SendIntraFrame(); |
| 537 | bool RequestIntraFrame(); |
| 538 | sigslot::signal3<VideoChannel*, uint32, VideoMediaChannel::Error> |
| 539 | SignalMediaError; |
| 540 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 541 | // Configuration and setting. |
| 542 | bool SetChannelOptions(const VideoOptions& options); |
| 543 | |
| 544 | protected: |
| 545 | // downcasts a MediaChannel |
| 546 | virtual VideoMediaChannel* media_channel() const { |
| 547 | return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); |
| 548 | } |
| 549 | |
| 550 | private: |
| 551 | typedef std::map<uint32, VideoCapturer*> ScreencastMap; |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 552 | struct ScreencastDetailsData; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 553 | |
| 554 | // overrides from BaseChannel |
| 555 | virtual void ChangeState(); |
| 556 | virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); |
| 557 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 558 | ContentAction action, |
| 559 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 560 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 561 | ContentAction action, |
| 562 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 563 | bool ApplyViewRequest_w(const ViewRequest& request); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 564 | |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 565 | bool AddScreencast_w(uint32 ssrc, VideoCapturer* capturer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 566 | bool RemoveScreencast_w(uint32 ssrc); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 567 | void OnScreencastWindowEvent_s(uint32 ssrc, rtc::WindowEvent we); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 568 | bool IsScreencasting_w() const; |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 569 | void GetScreencastDetails_w(ScreencastDetailsData* d) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 570 | bool GetStats_w(VideoMediaInfo* stats); |
| 571 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 572 | virtual void OnMessage(rtc::Message* pmsg); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 573 | virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const; |
| 574 | virtual void OnConnectionMonitorUpdate( |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame^] | 575 | ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 576 | virtual void OnMediaMonitorUpdate( |
| 577 | VideoMediaChannel* media_channel, const VideoMediaInfo& info); |
| 578 | virtual void OnScreencastWindowEvent(uint32 ssrc, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 579 | rtc::WindowEvent event); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 580 | virtual void OnStateChange(VideoCapturer* capturer, CaptureState ev); |
| 581 | bool GetLocalSsrc(const VideoCapturer* capturer, uint32* ssrc); |
| 582 | |
| 583 | void OnVideoChannelError(uint32 ssrc, VideoMediaChannel::Error error); |
| 584 | void OnSrtpError(uint32 ssrc, SrtpFilter::Mode mode, SrtpFilter::Error error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 585 | |
| 586 | VoiceChannel* voice_channel_; |
| 587 | VideoRenderer* renderer_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 588 | ScreencastMap screencast_capturers_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 589 | rtc::scoped_ptr<VideoMediaMonitor> media_monitor_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 590 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 591 | rtc::WindowEvent previous_we_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 592 | }; |
| 593 | |
| 594 | // DataChannel is a specialization for data. |
| 595 | class DataChannel : public BaseChannel { |
| 596 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 597 | DataChannel(rtc::Thread* thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 598 | DataMediaChannel* media_channel, |
| 599 | BaseSession* session, |
| 600 | const std::string& content_name, |
| 601 | bool rtcp); |
| 602 | ~DataChannel(); |
| 603 | bool Init(); |
| 604 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 605 | virtual bool SendData(const SendDataParams& params, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 606 | const rtc::Buffer& payload, |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 607 | SendDataResult* result); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 608 | |
| 609 | void StartMediaMonitor(int cms); |
| 610 | void StopMediaMonitor(); |
| 611 | |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 612 | // Should be called on the signaling thread only. |
| 613 | bool ready_to_send_data() const { |
| 614 | return ready_to_send_data_; |
| 615 | } |
| 616 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 617 | sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor; |
| 618 | sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&> |
| 619 | SignalConnectionMonitor; |
| 620 | sigslot::signal3<DataChannel*, uint32, DataMediaChannel::Error> |
| 621 | SignalMediaError; |
| 622 | sigslot::signal3<DataChannel*, |
| 623 | const ReceiveDataParams&, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 624 | const rtc::Buffer&> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 625 | SignalDataReceived; |
| 626 | // Signal for notifying when the channel becomes ready to send data. |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 627 | // That occurs when the channel is enabled, the transport is writable, |
| 628 | // 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] | 629 | sigslot::signal1<bool> SignalReadyToSendData; |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 +0000 | [diff] [blame] | 630 | // Signal for notifying that the remote side has closed the DataChannel. |
| 631 | sigslot::signal1<uint32> SignalStreamClosedRemotely; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 632 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 633 | protected: |
| 634 | // downcasts a MediaChannel. |
| 635 | virtual DataMediaChannel* media_channel() const { |
| 636 | return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); |
| 637 | } |
| 638 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 639 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 640 | struct SendDataMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 641 | SendDataMessageData(const SendDataParams& params, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 642 | const rtc::Buffer* payload, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 643 | SendDataResult* result) |
| 644 | : params(params), |
| 645 | payload(payload), |
| 646 | result(result), |
| 647 | succeeded(false) { |
| 648 | } |
| 649 | |
| 650 | const SendDataParams& params; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 651 | const rtc::Buffer* payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 652 | SendDataResult* result; |
| 653 | bool succeeded; |
| 654 | }; |
| 655 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 656 | struct DataReceivedMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 657 | // We copy the data because the data will become invalid after we |
| 658 | // handle DataMediaChannel::SignalDataReceived but before we fire |
| 659 | // SignalDataReceived. |
| 660 | DataReceivedMessageData( |
| 661 | const ReceiveDataParams& params, const char* data, size_t len) |
| 662 | : params(params), |
| 663 | payload(data, len) { |
| 664 | } |
| 665 | const ReceiveDataParams params; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 666 | const rtc::Buffer payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 667 | }; |
| 668 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 669 | typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 670 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 671 | // overrides from BaseChannel |
| 672 | virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); |
| 673 | // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that |
| 674 | // it's the same as what was set previously. Returns false if it's |
| 675 | // 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] | 676 | bool SetDataChannelType(DataChannelType new_data_channel_type, |
| 677 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 678 | // Same as SetDataChannelType, but extracts the type from the |
| 679 | // DataContentDescription. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 680 | bool SetDataChannelTypeFromContent(const DataContentDescription* content, |
| 681 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 682 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 683 | ContentAction action, |
| 684 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 685 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 686 | ContentAction action, |
| 687 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 688 | virtual void ChangeState(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 689 | virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 690 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 691 | virtual void OnMessage(rtc::Message* pmsg); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 692 | virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const; |
| 693 | virtual void OnConnectionMonitorUpdate( |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame^] | 694 | ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 695 | virtual void OnMediaMonitorUpdate( |
| 696 | DataMediaChannel* media_channel, const DataMediaInfo& info); |
| 697 | virtual bool ShouldSetupDtlsSrtp() const; |
| 698 | void OnDataReceived( |
| 699 | const ReceiveDataParams& params, const char* data, size_t len); |
| 700 | void OnDataChannelError(uint32 ssrc, DataMediaChannel::Error error); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 701 | void OnDataChannelReadyToSend(bool writable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 702 | void OnSrtpError(uint32 ssrc, SrtpFilter::Mode mode, SrtpFilter::Error error); |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 +0000 | [diff] [blame] | 703 | void OnStreamClosedRemotely(uint32 sid); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 704 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 705 | rtc::scoped_ptr<DataMediaMonitor> media_monitor_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 706 | // TODO(pthatcher): Make a separate SctpDataChannel and |
| 707 | // RtpDataChannel instead of using this. |
| 708 | DataChannelType data_channel_type_; |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 709 | bool ready_to_send_data_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 710 | }; |
| 711 | |
| 712 | } // namespace cricket |
| 713 | |
| 714 | #endif // TALK_SESSION_MEDIA_CHANNEL_H_ |