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