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