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