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