blob: 45918ffca05d43a050a16ea13bbe474af03ad04a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
perkjc11b1842016-03-07 17:34:13 -080011#ifndef WEBRTC_PC_CHANNEL_H_
12#define WEBRTC_PC_CHANNEL_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
deadbeefcbecd352015-09-23 11:50:27 -070014#include <map>
kwiberg31022942016-03-11 14:18:21 -080015#include <memory>
deadbeefcbecd352015-09-23 11:50:27 -070016#include <set>
kjellandera96e2d72016-02-04 23:52:28 -080017#include <string>
deadbeefcbecd352015-09-23 11:50:27 -070018#include <utility>
kjellandera96e2d72016-02-04 23:52:28 -080019#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020
kjellandera69d9732016-08-31 07:33:05 -070021#include "webrtc/api/call/audio_sink.h"
Danil Chapovalov33b01f22016-05-11 19:55:27 +020022#include "webrtc/base/asyncinvoker.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000023#include "webrtc/base/asyncudpsocket.h"
24#include "webrtc/base/criticalsection.h"
25#include "webrtc/base/network.h"
26#include "webrtc/base/sigslot.h"
27#include "webrtc/base/window.h"
kjellandera96e2d72016-02-04 23:52:28 -080028#include "webrtc/media/base/mediachannel.h"
29#include "webrtc/media/base/mediaengine.h"
30#include "webrtc/media/base/streamparams.h"
nisse08582ff2016-02-04 01:24:52 -080031#include "webrtc/media/base/videosinkinterface.h"
nisse2ded9b12016-04-08 02:23:55 -070032#include "webrtc/media/base/videosourceinterface.h"
Tommif888bb52015-12-12 01:37:01 +010033#include "webrtc/p2p/base/transportcontroller.h"
34#include "webrtc/p2p/client/socketmonitor.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010035#include "webrtc/pc/audiomonitor.h"
36#include "webrtc/pc/bundlefilter.h"
37#include "webrtc/pc/mediamonitor.h"
38#include "webrtc/pc/mediasession.h"
39#include "webrtc/pc/rtcpmuxfilter.h"
40#include "webrtc/pc/srtpfilter.h"
Tommif888bb52015-12-12 01:37:01 +010041
johand89ab142016-10-25 10:50:32 -070042namespace rtc {
43class PacketTransportInterface;
44}
45
Tommif888bb52015-12-12 01:37:01 +010046namespace webrtc {
47class AudioSinkInterface;
48} // namespace webrtc
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50namespace cricket {
51
52struct CryptoParams;
53class MediaContentDescription;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054
deadbeef062ce9f2016-08-26 21:42:15 -070055// BaseChannel contains logic common to voice and video, including enable,
56// marshaling calls to a worker and network threads, and connection and media
57// monitors.
58//
Danil Chapovalov33b01f22016-05-11 19:55:27 +020059// BaseChannel assumes signaling and other threads are allowed to make
60// synchronous calls to the worker thread, the worker thread makes synchronous
61// calls only to the network thread, and the network thread can't be blocked by
62// other threads.
63// All methods with _n suffix must be called on network thread,
deadbeef062ce9f2016-08-26 21:42:15 -070064// methods with _w suffix on worker thread
Danil Chapovalov33b01f22016-05-11 19:55:27 +020065// and methods with _s suffix on signaling thread.
66// Network and worker threads may be the same thread.
wu@webrtc.org78187522013-10-07 23:32:02 +000067//
68// WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS!
69// This is required to avoid a data race between the destructor modifying the
70// vtable, and the media channel's thread using BaseChannel as the
71// NetworkInterface.
72
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073class BaseChannel
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074 : public rtc::MessageHandler, public sigslot::has_slots<>,
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000075 public MediaChannel::NetworkInterface,
76 public ConnectionStatsGetter {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 public:
deadbeef23d947d2016-08-22 16:00:30 -070078 // |rtcp| represents whether or not this channel uses RTCP.
Danil Chapovalov33b01f22016-05-11 19:55:27 +020079 BaseChannel(rtc::Thread* worker_thread,
80 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -070081 MediaChannel* channel,
82 TransportController* transport_controller,
83 const std::string& content_name,
84 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085 virtual ~BaseChannel();
skvlad6c87a672016-05-17 17:49:52 -070086 bool Init_w(const std::string* bundle_transport_name);
Danil Chapovalov33b01f22016-05-11 19:55:27 +020087 // Deinit may be called multiple times and is simply ignored if it's already
wu@webrtc.org78187522013-10-07 23:32:02 +000088 // done.
89 void Deinit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000091 rtc::Thread* worker_thread() const { return worker_thread_; }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020092 rtc::Thread* network_thread() const { return network_thread_; }
deadbeefcbecd352015-09-23 11:50:27 -070093 const std::string& content_name() const { return content_name_; }
94 const std::string& transport_name() const { return transport_name_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095 bool enabled() const { return enabled_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
97 // This function returns true if we are using SRTP.
98 bool secure() const { return srtp_filter_.IsActive(); }
99 // The following function returns true if we are using
100 // DTLS-based keying. If you turned off SRTP later, however
101 // you could have secure() == false and dtls_secure() == true.
102 bool secure_dtls() const { return dtls_keyed_; }
103 // This function returns true if we require secure channel for call setup.
104 bool secure_required() const { return secure_required_; }
105
106 bool writable() const { return writable_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700108 // Activate RTCP mux, regardless of the state so far. Once
109 // activated, it can not be deactivated, and if the remote
110 // description doesn't support RTCP mux, setting the remote
111 // description will fail.
112 void ActivateRtcpMux();
deadbeefcbecd352015-09-23 11:50:27 -0700113 bool SetTransport(const std::string& transport_name);
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +0000114 bool PushdownLocalDescription(const SessionDescription* local_desc,
115 ContentAction action,
116 std::string* error_desc);
117 bool PushdownRemoteDescription(const SessionDescription* remote_desc,
118 ContentAction action,
119 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 // Channel control
121 bool SetLocalContent(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000122 ContentAction action,
123 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 bool SetRemoteContent(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000125 ContentAction action,
126 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
128 bool Enable(bool enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129
130 // Multiplexing
131 bool AddRecvStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200132 bool RemoveRecvStream(uint32_t ssrc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000133 bool AddSendStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200134 bool RemoveSendStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135
136 // Monitoring
137 void StartConnectionMonitor(int cms);
138 void StopConnectionMonitor();
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000139 // For ConnectionStatsGetter, used by ConnectionMonitor
deadbeefcbecd352015-09-23 11:50:27 -0700140 bool GetConnectionStats(ConnectionInfos* infos) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000142 BundleFilter* bundle_filter() { return &bundle_filter_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143
144 const std::vector<StreamParams>& local_streams() const {
145 return local_streams_;
146 }
147 const std::vector<StreamParams>& remote_streams() const {
148 return remote_streams_;
149 }
150
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000151 sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200152 void SignalDtlsSetupFailure_n(bool rtcp);
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000153 void SignalDtlsSetupFailure_s(bool rtcp);
154
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +0000155 // Used for latency measurements.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
157
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200158 // Forward TransportChannel SignalSentPacket to worker thread.
159 sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
160
161 // Only public for unit tests. Otherwise, consider private.
162 TransportChannel* transport_channel() const { return transport_channel_; }
163 TransportChannel* rtcp_transport_channel() const {
164 return rtcp_transport_channel_;
165 }
166
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 // Made public for easier testing.
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700168 //
169 // Updates "ready to send" for an individual channel, and informs the media
170 // channel that the transport is ready to send if each channel (in use) is
171 // ready to send. This is more specific than just "writable"; it means the
172 // last send didn't return ENOTCONN.
173 //
174 // This should be called whenever a channel's ready-to-send state changes,
175 // or when RTCP muxing becomes active/inactive.
176 void SetTransportChannelReadyToSend(bool rtcp, bool ready);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000178 // Only public for unit tests. Otherwise, consider protected.
rlesterec9d1872015-10-27 14:22:16 -0700179 int SetOption(SocketType type, rtc::Socket::Option o, int val)
180 override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200181 int SetOption_n(SocketType type, rtc::Socket::Option o, int val);
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000182
solenberg5b14b422015-10-01 04:10:31 -0700183 SrtpFilter* srtp_filter() { return &srtp_filter_; }
184
zhihuang184a3fd2016-06-14 11:47:14 -0700185 virtual cricket::MediaType media_type() = 0;
186
jbauchcb560652016-08-04 05:20:32 -0700187 bool SetCryptoOptions(const rtc::CryptoOptions& crypto_options);
188
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 protected:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 virtual MediaChannel* media_channel() const { return media_channel_; }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700191
192 // Sets the |transport_channel_| (and |rtcp_transport_channel_|, if
193 // |rtcp_enabled_| is true). Gets the transport channels from
194 // |transport_controller_|.
deadbeef062ce9f2016-08-26 21:42:15 -0700195 // This method also updates writability and "ready-to-send" state.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200196 bool SetTransport_n(const std::string& transport_name);
guoweis46383312015-12-17 16:45:59 -0800197
deadbeef062ce9f2016-08-26 21:42:15 -0700198 // This does not update writability or "ready-to-send" state; it just
199 // disconnects from the old channel and connects to the new one.
200 void SetTransportChannel_n(bool rtcp, TransportChannel* new_channel);
guoweis46383312015-12-17 16:45:59 -0800201
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 bool was_ever_writable() const { return was_ever_writable_; }
203 void set_local_content_direction(MediaContentDirection direction) {
204 local_content_direction_ = direction;
205 }
206 void set_remote_content_direction(MediaContentDirection direction) {
207 remote_content_direction_ = direction;
208 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700209 void set_secure_required(bool secure_required) {
210 secure_required_ = secure_required;
211 }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700212 // These methods verify that:
213 // * The required content description directions have been set.
214 // * The channel is enabled.
215 // * And for sending:
216 // - The SRTP filter is active if it's needed.
217 // - The transport has been writable before, meaning it should be at least
218 // possible to succeed in sending a packet.
219 //
220 // When any of these properties change, UpdateMediaSendRecvState_w should be
221 // called.
222 bool IsReadyToReceiveMedia_w() const;
223 bool IsReadyToSendMedia_w() const;
deadbeefcbecd352015-09-23 11:50:27 -0700224 rtc::Thread* signaling_thread() {
225 return transport_controller_->signaling_thread();
226 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227
pthatcher@webrtc.org6ad507a2015-03-16 20:19:12 +0000228 void ConnectToTransportChannel(TransportChannel* tc);
229 void DisconnectFromTransportChannel(TransportChannel* tc);
230
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200231 void FlushRtcpMessages_n();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232
233 // NetworkInterface implementation, called by MediaEngine
jbaucheec21bd2016-03-20 06:15:43 -0700234 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
235 const rtc::PacketOptions& options) override;
236 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
237 const rtc::PacketOptions& options) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238
239 // From TransportChannel
johand89ab142016-10-25 10:50:32 -0700240 void OnWritableState(rtc::PacketTransportInterface* transport);
241 virtual void OnPacketRead(rtc::PacketTransportInterface* transport,
242 const char* data,
243 size_t len,
244 const rtc::PacketTime& packet_time,
245 int flags);
246 void OnReadyToSend(rtc::PacketTransportInterface* transport);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800248 void OnDtlsState(TransportChannel* channel, DtlsTransportState state);
249
Honghai Zhangcc411c02016-03-29 17:27:21 -0700250 void OnSelectedCandidatePairChanged(
251 TransportChannel* channel,
Honghai Zhang52dce732016-03-31 12:37:31 -0700252 CandidatePairInterface* selected_candidate_pair,
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700253 int last_sent_packet_id,
254 bool ready_to_send);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700255
johand89ab142016-10-25 10:50:32 -0700256 bool PacketIsRtcp(const rtc::PacketTransportInterface* transport,
257 const char* data,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 size_t len);
stefanc1aeaf02015-10-15 07:26:07 -0700259 bool SendPacket(bool rtcp,
jbaucheec21bd2016-03-20 06:15:43 -0700260 rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700261 const rtc::PacketOptions& options);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200262
jbaucheec21bd2016-03-20 06:15:43 -0700263 virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
264 void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000265 const rtc::PacketTime& packet_time);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200266 void OnPacketReceived(bool rtcp,
267 const rtc::CopyOnWriteBuffer& packet,
268 const rtc::PacketTime& packet_time);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 void EnableMedia_w();
271 void DisableMedia_w();
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700272
273 // Performs actions if the RTP/RTCP writable state changed. This should
274 // be called whenever a channel's writable state changes or when RTCP muxing
275 // becomes active/inactive.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200276 void UpdateWritableState_n();
277 void ChannelWritable_n();
278 void ChannelNotWritable_n();
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700279
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 bool AddRecvStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200281 bool RemoveRecvStream_w(uint32_t ssrc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000282 bool AddSendStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200283 bool RemoveSendStream_w(uint32_t ssrc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200284 virtual bool ShouldSetupDtlsSrtp_n() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285 // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters.
286 // |rtcp_channel| indicates whether to set up the RTP or RTCP filter.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200287 bool SetupDtlsSrtp_n(bool rtcp_channel);
288 void MaybeSetupDtlsSrtp_n();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 // Set the DTLS-SRTP cipher policy on this channel as appropriate.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200290 bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700292 // Should be called whenever the conditions for
293 // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied).
294 // Updates the send/recv state of the media channel.
295 void UpdateMediaSendRecvState();
296 virtual void UpdateMediaSendRecvState_w() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297
298 // Gets the content info appropriate to the channel (audio or video).
299 virtual const ContentInfo* GetFirstContent(
300 const SessionDescription* sdesc) = 0;
301 bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000302 ContentAction action,
303 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000305 ContentAction action,
306 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 virtual bool SetLocalContent_w(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000308 ContentAction action,
309 std::string* error_desc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000311 ContentAction action,
312 std::string* error_desc) = 0;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200313 bool SetRtpTransportParameters(const MediaContentDescription* content,
314 ContentAction action,
315 ContentSource src,
316 std::string* error_desc);
317 bool SetRtpTransportParameters_n(const MediaContentDescription* content,
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700318 ContentAction action,
319 ContentSource src,
320 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321
henrike@webrtc.orgd43aa9d2014-02-21 23:43:24 +0000322 // Helper method to get RTP Absoulute SendTime extension header id if
323 // present in remote supported extensions list.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200324 void MaybeCacheRtpAbsSendTimeHeaderExtension_w(
isheriff6f8d6862016-05-26 11:24:55 -0700325 const std::vector<webrtc::RtpExtension>& extensions);
henrike@webrtc.orgd43aa9d2014-02-21 23:43:24 +0000326
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200327 bool CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
328 bool* dtls,
329 std::string* error_desc);
330 bool SetSrtp_n(const std::vector<CryptoParams>& params,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000331 ContentAction action,
332 ContentSource src,
333 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200334 void ActivateRtcpMux_n();
335 bool SetRtcpMux_n(bool enable,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000336 ContentAction action,
337 ContentSource src,
338 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339
340 // From MessageHandler
rlesterec9d1872015-10-27 14:22:16 -0700341 void OnMessage(rtc::Message* pmsg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342
jbauchcb560652016-08-04 05:20:32 -0700343 const rtc::CryptoOptions& crypto_options() const {
344 return crypto_options_;
345 }
346
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 // Handled in derived classes
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800348 // Get the SRTP crypto suites to use for RTP media
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200349 virtual void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const = 0;
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000350 virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 const std::vector<ConnectionInfo>& infos) = 0;
352
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000353 // Helper function for invoking bool-returning methods on the worker thread.
354 template <class FunctorT>
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700355 bool InvokeOnWorker(const rtc::Location& posted_from,
356 const FunctorT& functor) {
357 return worker_thread_->Invoke<bool>(posted_from, functor);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000358 }
359
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 private:
skvlad6c87a672016-05-17 17:49:52 -0700361 bool InitNetwork_n(const std::string* bundle_transport_name);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +0200362 void DisconnectTransportChannels_n();
363 void DestroyTransportChannels_n();
johand89ab142016-10-25 10:50:32 -0700364 void SignalSentPacket_n(rtc::PacketTransportInterface* transport,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200365 const rtc::SentPacket& sent_packet);
366 void SignalSentPacket_w(const rtc::SentPacket& sent_packet);
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700367 bool IsReadyToSendMedia_n() const;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200368 void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id);
369
370 rtc::Thread* const worker_thread_;
371 rtc::Thread* const network_thread_;
372 rtc::AsyncInvoker invoker_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373
pthatcher@webrtc.org990a00c2015-03-13 18:20:33 +0000374 const std::string content_name_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200375 std::unique_ptr<ConnectionMonitor> connection_monitor_;
376
377 // Transport related members that should be accessed from network thread.
378 TransportController* const transport_controller_;
deadbeefcbecd352015-09-23 11:50:27 -0700379 std::string transport_name_;
deadbeef23d947d2016-08-22 16:00:30 -0700380 // Is RTCP used at all by this type of channel?
381 // Expected to be true (as of typing this) for everything except data
382 // channels.
383 const bool rtcp_enabled_;
johand89ab142016-10-25 10:50:32 -0700384 // TODO(johan): Replace TransportChannel* with rtc::PacketTransportInterface*.
deadbeef23d947d2016-08-22 16:00:30 -0700385 TransportChannel* transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700386 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700387 TransportChannel* rtcp_transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700388 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 SrtpFilter srtp_filter_;
390 RtcpMuxFilter rtcp_mux_filter_;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000391 BundleFilter bundle_filter_;
deadbeef23d947d2016-08-22 16:00:30 -0700392 bool rtp_ready_to_send_ = false;
393 bool rtcp_ready_to_send_ = false;
394 bool writable_ = false;
395 bool was_ever_writable_ = false;
396 bool has_received_packet_ = false;
397 bool dtls_keyed_ = false;
398 bool secure_required_ = false;
jbauchcb560652016-08-04 05:20:32 -0700399 rtc::CryptoOptions crypto_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700400 int rtp_abs_sendtime_extn_id_ = -1;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200401
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700402 // MediaChannel related members that should be accessed from the worker
403 // thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200404 MediaChannel* const media_channel_;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700405 // Currently the |enabled_| flag is accessed from the signaling thread as
406 // well, but it can be changed only when signaling thread does a synchronous
407 // call to the worker thread, so it should be safe.
deadbeef23d947d2016-08-22 16:00:30 -0700408 bool enabled_ = false;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200409 std::vector<StreamParams> local_streams_;
410 std::vector<StreamParams> remote_streams_;
deadbeef23d947d2016-08-22 16:00:30 -0700411 MediaContentDirection local_content_direction_ = MD_INACTIVE;
412 MediaContentDirection remote_content_direction_ = MD_INACTIVE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413};
414
415// VoiceChannel is a specialization that adds support for early media, DTMF,
416// and input/output level monitoring.
417class VoiceChannel : public BaseChannel {
418 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200419 VoiceChannel(rtc::Thread* worker_thread,
420 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700421 MediaEngineInterface* media_engine,
422 VoiceMediaChannel* channel,
423 TransportController* transport_controller,
424 const std::string& content_name,
425 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 ~VoiceChannel();
skvlad6c87a672016-05-17 17:49:52 -0700427 bool Init_w(const std::string* bundle_transport_name);
solenberg1dd98f32015-09-10 01:57:14 -0700428
429 // Configure sending media on the stream with SSRC |ssrc|
430 // If there is only one sending stream SSRC 0 can be used.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200431 bool SetAudioSend(uint32_t ssrc,
solenbergdfc8f4f2015-10-01 02:31:10 -0700432 bool enable,
deadbeefcbecd352015-09-23 11:50:27 -0700433 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800434 AudioSource* source);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435
436 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200437 VoiceMediaChannel* media_channel() const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
439 }
440
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 void SetEarlyMedia(bool enable);
442 // This signal is emitted when we have gone a period of time without
443 // receiving early media. When received, a UI should start playing its
444 // own ringing sound
445 sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout;
446
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 // Returns if the telephone-event has been negotiated.
448 bool CanInsertDtmf();
449 // Send and/or play a DTMF |event| according to the |flags|.
450 // The DTMF out-of-band signal will be used on sending.
451 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000452 // The valid value for the |event| are 0 which corresponding to DTMF
453 // event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800454 bool InsertDtmf(uint32_t ssrc, int event_code, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700455 bool SetOutputVolume(uint32_t ssrc, double volume);
deadbeef2d110be2016-01-13 12:00:26 -0800456 void SetRawAudioSink(uint32_t ssrc,
kwiberg31022942016-03-11 14:18:21 -0800457 std::unique_ptr<webrtc::AudioSinkInterface> sink);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700458 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
459 bool SetRtpSendParameters(uint32_t ssrc,
460 const webrtc::RtpParameters& parameters);
461 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
462 bool SetRtpReceiveParameters(uint32_t ssrc,
463 const webrtc::RtpParameters& parameters);
Tommif888bb52015-12-12 01:37:01 +0100464
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 // Get statistics about the current media session.
466 bool GetStats(VoiceMediaInfo* stats);
467
468 // Monitoring functions
469 sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&>
470 SignalConnectionMonitor;
471
472 void StartMediaMonitor(int cms);
473 void StopMediaMonitor();
474 sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor;
475
476 void StartAudioMonitor(int cms);
477 void StopAudioMonitor();
478 bool IsAudioMonitorRunning() const;
479 sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor;
480
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481 int GetInputLevel_w();
482 int GetOutputLevel_w();
483 void GetActiveStreams_w(AudioInfo::StreamList* actives);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700484 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
485 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
486 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
487 bool SetRtpReceiveParameters_w(uint32_t ssrc,
488 webrtc::RtpParameters parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700489 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_AUDIO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000491 private:
492 // overrides from BaseChannel
johand89ab142016-10-25 10:50:32 -0700493 void OnPacketRead(rtc::PacketTransportInterface* transport,
494 const char* data,
495 size_t len,
496 const rtc::PacketTime& packet_time,
497 int flags) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700498 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200499 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
500 bool SetLocalContent_w(const MediaContentDescription* content,
501 ContentAction action,
502 std::string* error_desc) override;
503 bool SetRemoteContent_w(const MediaContentDescription* content,
504 ContentAction action,
505 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000506 void HandleEarlyMediaTimeout();
solenberg1d63dd02015-12-02 12:35:09 -0800507 bool InsertDtmf_w(uint32_t ssrc, int event, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700508 bool SetOutputVolume_w(uint32_t ssrc, double volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509 bool GetStats_w(VoiceMediaInfo* stats);
510
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200511 void OnMessage(rtc::Message* pmsg) override;
512 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
513 void OnConnectionMonitorUpdate(
514 ConnectionMonitor* monitor,
515 const std::vector<ConnectionInfo>& infos) override;
516 void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
517 const VoiceMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519
520 static const int kEarlyMediaTimeout = 1000;
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200521 MediaEngineInterface* media_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 bool received_media_;
kwiberg31022942016-03-11 14:18:21 -0800523 std::unique_ptr<VoiceMediaMonitor> media_monitor_;
524 std::unique_ptr<AudioMonitor> audio_monitor_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700525
526 // Last AudioSendParameters sent down to the media_channel() via
527 // SetSendParameters.
528 AudioSendParameters last_send_params_;
529 // Last AudioRecvParameters sent down to the media_channel() via
530 // SetRecvParameters.
531 AudioRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532};
533
534// VideoChannel is a specialization for video.
535class VideoChannel : public BaseChannel {
536 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200537 VideoChannel(rtc::Thread* worker_thread,
538 rtc::Thread* netwokr_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700539 VideoMediaChannel* channel,
540 TransportController* transport_controller,
541 const std::string& content_name,
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200542 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 ~VideoChannel();
skvlad6c87a672016-05-17 17:49:52 -0700544 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200546 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200547 VideoMediaChannel* media_channel() const override {
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200548 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
549 }
550
nisse08582ff2016-02-04 01:24:52 -0800551 bool SetSink(uint32_t ssrc, rtc::VideoSinkInterface<VideoFrame>* sink);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 // Get statistics about the current media session.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000553 bool GetStats(VideoMediaInfo* stats);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554
555 sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&>
556 SignalConnectionMonitor;
557
558 void StartMediaMonitor(int cms);
559 void StopMediaMonitor();
560 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561
deadbeef5a4a75a2016-06-02 16:23:38 -0700562 // Register a source and set options.
563 // The |ssrc| must correspond to a registered send stream.
564 bool SetVideoSend(uint32_t ssrc,
565 bool enable,
566 const VideoOptions* options,
567 rtc::VideoSourceInterface<cricket::VideoFrame>* source);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700568 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
569 bool SetRtpSendParameters(uint32_t ssrc,
570 const webrtc::RtpParameters& parameters);
571 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
572 bool SetRtpReceiveParameters(uint32_t ssrc,
573 const webrtc::RtpParameters& parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700574 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 private:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577 // overrides from BaseChannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700578 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200579 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
580 bool SetLocalContent_w(const MediaContentDescription* content,
581 ContentAction action,
582 std::string* error_desc) override;
583 bool SetRemoteContent_w(const MediaContentDescription* content,
584 ContentAction action,
585 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586 bool GetStats_w(VideoMediaInfo* stats);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700587 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
588 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
589 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
590 bool SetRtpReceiveParameters_w(uint32_t ssrc,
591 webrtc::RtpParameters parameters);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200593 void OnMessage(rtc::Message* pmsg) override;
594 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
595 void OnConnectionMonitorUpdate(
596 ConnectionMonitor* monitor,
597 const std::vector<ConnectionInfo>& infos) override;
598 void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
599 const VideoMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600
kwiberg31022942016-03-11 14:18:21 -0800601 std::unique_ptr<VideoMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700603 // Last VideoSendParameters sent down to the media_channel() via
604 // SetSendParameters.
605 VideoSendParameters last_send_params_;
606 // Last VideoRecvParameters sent down to the media_channel() via
607 // SetRecvParameters.
608 VideoRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609};
610
611// DataChannel is a specialization for data.
612class DataChannel : public BaseChannel {
613 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200614 DataChannel(rtc::Thread* worker_thread,
615 rtc::Thread* network_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 DataMediaChannel* media_channel,
deadbeefcbecd352015-09-23 11:50:27 -0700617 TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 const std::string& content_name,
619 bool rtcp);
620 ~DataChannel();
skvlad6c87a672016-05-17 17:49:52 -0700621 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000623 virtual bool SendData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700624 const rtc::CopyOnWriteBuffer& payload,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000625 SendDataResult* result);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626
627 void StartMediaMonitor(int cms);
628 void StopMediaMonitor();
629
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000630 // Should be called on the signaling thread only.
631 bool ready_to_send_data() const {
632 return ready_to_send_data_;
633 }
634
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635 sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor;
636 sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&>
637 SignalConnectionMonitor;
jbaucheec21bd2016-03-20 06:15:43 -0700638 sigslot::signal3<DataChannel*, const ReceiveDataParams&,
639 const rtc::CopyOnWriteBuffer&> SignalDataReceived;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640 // Signal for notifying when the channel becomes ready to send data.
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000641 // That occurs when the channel is enabled, the transport is writable,
642 // both local and remote descriptions are set, and the channel is unblocked.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 sigslot::signal1<bool> SignalReadyToSendData;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +0000644 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200645 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
zhihuang184a3fd2016-06-14 11:47:14 -0700646 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000648 protected:
649 // downcasts a MediaChannel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200650 DataMediaChannel* media_channel() const override {
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000651 return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
652 }
653
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000655 struct SendDataMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656 SendDataMessageData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700657 const rtc::CopyOnWriteBuffer* payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 SendDataResult* result)
659 : params(params),
660 payload(payload),
661 result(result),
662 succeeded(false) {
663 }
664
665 const SendDataParams& params;
jbaucheec21bd2016-03-20 06:15:43 -0700666 const rtc::CopyOnWriteBuffer* payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000667 SendDataResult* result;
668 bool succeeded;
669 };
670
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000671 struct DataReceivedMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 // We copy the data because the data will become invalid after we
673 // handle DataMediaChannel::SignalDataReceived but before we fire
674 // SignalDataReceived.
675 DataReceivedMessageData(
676 const ReceiveDataParams& params, const char* data, size_t len)
677 : params(params),
678 payload(data, len) {
679 }
680 const ReceiveDataParams params;
jbaucheec21bd2016-03-20 06:15:43 -0700681 const rtc::CopyOnWriteBuffer payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 };
683
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000684 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000685
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 // overrides from BaseChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200687 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688 // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that
689 // it's the same as what was set previously. Returns false if it's
690 // set to one type one type and changed to another type later.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000691 bool SetDataChannelType(DataChannelType new_data_channel_type,
692 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 // Same as SetDataChannelType, but extracts the type from the
694 // DataContentDescription.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000695 bool SetDataChannelTypeFromContent(const DataContentDescription* content,
696 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200697 bool SetLocalContent_w(const MediaContentDescription* content,
698 ContentAction action,
699 std::string* error_desc) override;
700 bool SetRemoteContent_w(const MediaContentDescription* content,
701 ContentAction action,
702 std::string* error_desc) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700703 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200704 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200706 void OnMessage(rtc::Message* pmsg) override;
707 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
708 void OnConnectionMonitorUpdate(
709 ConnectionMonitor* monitor,
710 const std::vector<ConnectionInfo>& infos) override;
711 void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
712 const DataMediaInfo& info);
713 bool ShouldSetupDtlsSrtp_n() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 void OnDataReceived(
715 const ReceiveDataParams& params, const char* data, size_t len);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200716 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000717 void OnDataChannelReadyToSend(bool writable);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200718 void OnStreamClosedRemotely(uint32_t sid);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719
kwiberg31022942016-03-11 14:18:21 -0800720 std::unique_ptr<DataMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 // TODO(pthatcher): Make a separate SctpDataChannel and
722 // RtpDataChannel instead of using this.
723 DataChannelType data_channel_type_;
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000724 bool ready_to_send_data_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700725
726 // Last DataSendParameters sent down to the media_channel() via
727 // SetSendParameters.
728 DataSendParameters last_send_params_;
729 // Last DataRecvParameters sent down to the media_channel() via
730 // SetRecvParameters.
731 DataRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732};
733
734} // namespace cricket
735
perkjc11b1842016-03-07 17:34:13 -0800736#endif // WEBRTC_PC_CHANNEL_H_