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