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