blob: 2a5d3a55ec42f68111a3b79ca90d296b8eb2514e [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
kjellander@webrtc.org7ffeab52016-02-26 22:46:09 +010021#include "webrtc/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
42namespace webrtc {
43class AudioSinkInterface;
44} // namespace webrtc
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045
46namespace cricket {
47
48struct CryptoParams;
49class MediaContentDescription;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051// BaseChannel contains logic common to voice and video, including
Danil Chapovalov33b01f22016-05-11 19:55:27 +020052// enable, marshaling calls to a worker and network threads, and
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053// connection and media monitors.
Danil Chapovalov33b01f22016-05-11 19:55:27 +020054// BaseChannel assumes signaling and other threads are allowed to make
55// synchronous calls to the worker thread, the worker thread makes synchronous
56// calls only to the network thread, and the network thread can't be blocked by
57// other threads.
58// All methods with _n suffix must be called on network thread,
59// methods with _w suffix - on worker thread
60// and methods with _s suffix on signaling thread.
61// Network and worker threads may be the same thread.
wu@webrtc.org78187522013-10-07 23:32:02 +000062//
63// WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS!
64// This is required to avoid a data race between the destructor modifying the
65// vtable, and the media channel's thread using BaseChannel as the
66// NetworkInterface.
67
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068class BaseChannel
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000069 : public rtc::MessageHandler, public sigslot::has_slots<>,
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000070 public MediaChannel::NetworkInterface,
71 public ConnectionStatsGetter {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 public:
deadbeef23d947d2016-08-22 16:00:30 -070073 // |rtcp| represents whether or not this channel uses RTCP.
Danil Chapovalov33b01f22016-05-11 19:55:27 +020074 BaseChannel(rtc::Thread* worker_thread,
75 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -070076 MediaChannel* channel,
77 TransportController* transport_controller,
78 const std::string& content_name,
79 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080 virtual ~BaseChannel();
skvlad6c87a672016-05-17 17:49:52 -070081 bool Init_w(const std::string* bundle_transport_name);
Danil Chapovalov33b01f22016-05-11 19:55:27 +020082 // Deinit may be called multiple times and is simply ignored if it's already
wu@webrtc.org78187522013-10-07 23:32:02 +000083 // done.
84 void Deinit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000086 rtc::Thread* worker_thread() const { return worker_thread_; }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020087 rtc::Thread* network_thread() const { return network_thread_; }
deadbeefcbecd352015-09-23 11:50:27 -070088 const std::string& content_name() const { return content_name_; }
89 const std::string& transport_name() const { return transport_name_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090 bool enabled() const { return enabled_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091
92 // This function returns true if we are using SRTP.
93 bool secure() const { return srtp_filter_.IsActive(); }
94 // The following function returns true if we are using
95 // DTLS-based keying. If you turned off SRTP later, however
96 // you could have secure() == false and dtls_secure() == true.
97 bool secure_dtls() const { return dtls_keyed_; }
98 // This function returns true if we require secure channel for call setup.
99 bool secure_required() const { return secure_required_; }
100
101 bool writable() const { return writable_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700103 // Activate RTCP mux, regardless of the state so far. Once
104 // activated, it can not be deactivated, and if the remote
105 // description doesn't support RTCP mux, setting the remote
106 // description will fail.
107 void ActivateRtcpMux();
deadbeefcbecd352015-09-23 11:50:27 -0700108 bool SetTransport(const std::string& transport_name);
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +0000109 bool PushdownLocalDescription(const SessionDescription* local_desc,
110 ContentAction action,
111 std::string* error_desc);
112 bool PushdownRemoteDescription(const SessionDescription* remote_desc,
113 ContentAction action,
114 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 // Channel control
116 bool SetLocalContent(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000117 ContentAction action,
118 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 bool SetRemoteContent(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000120 ContentAction action,
121 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122
123 bool Enable(bool enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124
125 // Multiplexing
126 bool AddRecvStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200127 bool RemoveRecvStream(uint32_t ssrc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000128 bool AddSendStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200129 bool RemoveSendStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130
131 // Monitoring
132 void StartConnectionMonitor(int cms);
133 void StopConnectionMonitor();
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000134 // For ConnectionStatsGetter, used by ConnectionMonitor
deadbeefcbecd352015-09-23 11:50:27 -0700135 bool GetConnectionStats(ConnectionInfos* infos) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000137 BundleFilter* bundle_filter() { return &bundle_filter_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138
139 const std::vector<StreamParams>& local_streams() const {
140 return local_streams_;
141 }
142 const std::vector<StreamParams>& remote_streams() const {
143 return remote_streams_;
144 }
145
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000146 sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200147 void SignalDtlsSetupFailure_n(bool rtcp);
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000148 void SignalDtlsSetupFailure_s(bool rtcp);
149
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +0000150 // Used for latency measurements.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
152
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200153 // Forward TransportChannel SignalSentPacket to worker thread.
154 sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
155
156 // Only public for unit tests. Otherwise, consider private.
157 TransportChannel* transport_channel() const { return transport_channel_; }
158 TransportChannel* rtcp_transport_channel() const {
159 return rtcp_transport_channel_;
160 }
161
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 // Made public for easier testing.
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700163 //
164 // Updates "ready to send" for an individual channel, and informs the media
165 // channel that the transport is ready to send if each channel (in use) is
166 // ready to send. This is more specific than just "writable"; it means the
167 // last send didn't return ENOTCONN.
168 //
169 // This should be called whenever a channel's ready-to-send state changes,
170 // or when RTCP muxing becomes active/inactive.
171 void SetTransportChannelReadyToSend(bool rtcp, bool ready);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000173 // Only public for unit tests. Otherwise, consider protected.
rlesterec9d1872015-10-27 14:22:16 -0700174 int SetOption(SocketType type, rtc::Socket::Option o, int val)
175 override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200176 int SetOption_n(SocketType type, rtc::Socket::Option o, int val);
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000177
solenberg5b14b422015-10-01 04:10:31 -0700178 SrtpFilter* srtp_filter() { return &srtp_filter_; }
179
zhihuang184a3fd2016-06-14 11:47:14 -0700180 virtual cricket::MediaType media_type() = 0;
181
jbauchcb560652016-08-04 05:20:32 -0700182 bool SetCryptoOptions(const rtc::CryptoOptions& crypto_options);
183
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 protected:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 virtual MediaChannel* media_channel() const { return media_channel_; }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700186
187 // Sets the |transport_channel_| (and |rtcp_transport_channel_|, if
188 // |rtcp_enabled_| is true). Gets the transport channels from
189 // |transport_controller_|.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200190 bool SetTransport_n(const std::string& transport_name);
guoweis46383312015-12-17 16:45:59 -0800191
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200192 void SetTransportChannel_n(TransportChannel* transport);
193 void SetRtcpTransportChannel_n(TransportChannel* transport,
194 bool update_writablity);
guoweis46383312015-12-17 16:45:59 -0800195
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 bool was_ever_writable() const { return was_ever_writable_; }
197 void set_local_content_direction(MediaContentDirection direction) {
198 local_content_direction_ = direction;
199 }
200 void set_remote_content_direction(MediaContentDirection direction) {
201 remote_content_direction_ = direction;
202 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700203 void set_secure_required(bool secure_required) {
204 secure_required_ = secure_required;
205 }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700206 // These methods verify that:
207 // * The required content description directions have been set.
208 // * The channel is enabled.
209 // * And for sending:
210 // - The SRTP filter is active if it's needed.
211 // - The transport has been writable before, meaning it should be at least
212 // possible to succeed in sending a packet.
213 //
214 // When any of these properties change, UpdateMediaSendRecvState_w should be
215 // called.
216 bool IsReadyToReceiveMedia_w() const;
217 bool IsReadyToSendMedia_w() const;
deadbeefcbecd352015-09-23 11:50:27 -0700218 rtc::Thread* signaling_thread() {
219 return transport_controller_->signaling_thread();
220 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221
pthatcher@webrtc.org6ad507a2015-03-16 20:19:12 +0000222 void ConnectToTransportChannel(TransportChannel* tc);
223 void DisconnectFromTransportChannel(TransportChannel* tc);
224
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200225 void FlushRtcpMessages_n();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226
227 // NetworkInterface implementation, called by MediaEngine
jbaucheec21bd2016-03-20 06:15:43 -0700228 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
229 const rtc::PacketOptions& options) override;
230 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
231 const rtc::PacketOptions& options) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232
233 // From TransportChannel
234 void OnWritableState(TransportChannel* channel);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000235 virtual void OnChannelRead(TransportChannel* channel,
236 const char* data,
237 size_t len,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000238 const rtc::PacketTime& packet_time,
wu@webrtc.orga9890802013-12-13 00:21:03 +0000239 int flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 void OnReadyToSend(TransportChannel* channel);
241
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800242 void OnDtlsState(TransportChannel* channel, DtlsTransportState state);
243
Honghai Zhangcc411c02016-03-29 17:27:21 -0700244 void OnSelectedCandidatePairChanged(
245 TransportChannel* channel,
Honghai Zhang52dce732016-03-31 12:37:31 -0700246 CandidatePairInterface* selected_candidate_pair,
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700247 int last_sent_packet_id,
248 bool ready_to_send);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700249
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 bool PacketIsRtcp(const TransportChannel* channel, const char* data,
251 size_t len);
stefanc1aeaf02015-10-15 07:26:07 -0700252 bool SendPacket(bool rtcp,
jbaucheec21bd2016-03-20 06:15:43 -0700253 rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700254 const rtc::PacketOptions& options);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200255
jbaucheec21bd2016-03-20 06:15:43 -0700256 virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
257 void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000258 const rtc::PacketTime& packet_time);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200259 void OnPacketReceived(bool rtcp,
260 const rtc::CopyOnWriteBuffer& packet,
261 const rtc::PacketTime& packet_time);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 void EnableMedia_w();
264 void DisableMedia_w();
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700265
266 // Performs actions if the RTP/RTCP writable state changed. This should
267 // be called whenever a channel's writable state changes or when RTCP muxing
268 // becomes active/inactive.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200269 void UpdateWritableState_n();
270 void ChannelWritable_n();
271 void ChannelNotWritable_n();
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700272
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 bool AddRecvStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200274 bool RemoveRecvStream_w(uint32_t ssrc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000275 bool AddSendStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200276 bool RemoveSendStream_w(uint32_t ssrc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200277 virtual bool ShouldSetupDtlsSrtp_n() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters.
279 // |rtcp_channel| indicates whether to set up the RTP or RTCP filter.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200280 bool SetupDtlsSrtp_n(bool rtcp_channel);
281 void MaybeSetupDtlsSrtp_n();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 // Set the DTLS-SRTP cipher policy on this channel as appropriate.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200283 bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700285 // Should be called whenever the conditions for
286 // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied).
287 // Updates the send/recv state of the media channel.
288 void UpdateMediaSendRecvState();
289 virtual void UpdateMediaSendRecvState_w() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290
291 // Gets the content info appropriate to the channel (audio or video).
292 virtual const ContentInfo* GetFirstContent(
293 const SessionDescription* sdesc) = 0;
294 bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000295 ContentAction action,
296 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000298 ContentAction action,
299 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 virtual bool SetLocalContent_w(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000301 ContentAction action,
302 std::string* error_desc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000304 ContentAction action,
305 std::string* error_desc) = 0;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200306 bool SetRtpTransportParameters(const MediaContentDescription* content,
307 ContentAction action,
308 ContentSource src,
309 std::string* error_desc);
310 bool SetRtpTransportParameters_n(const MediaContentDescription* content,
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700311 ContentAction action,
312 ContentSource src,
313 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314
henrike@webrtc.orgd43aa9d2014-02-21 23:43:24 +0000315 // Helper method to get RTP Absoulute SendTime extension header id if
316 // present in remote supported extensions list.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200317 void MaybeCacheRtpAbsSendTimeHeaderExtension_w(
isheriff6f8d6862016-05-26 11:24:55 -0700318 const std::vector<webrtc::RtpExtension>& extensions);
henrike@webrtc.orgd43aa9d2014-02-21 23:43:24 +0000319
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200320 bool CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
321 bool* dtls,
322 std::string* error_desc);
323 bool SetSrtp_n(const std::vector<CryptoParams>& params,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000324 ContentAction action,
325 ContentSource src,
326 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200327 void ActivateRtcpMux_n();
328 bool SetRtcpMux_n(bool enable,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000329 ContentAction action,
330 ContentSource src,
331 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332
333 // From MessageHandler
rlesterec9d1872015-10-27 14:22:16 -0700334 void OnMessage(rtc::Message* pmsg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335
jbauchcb560652016-08-04 05:20:32 -0700336 const rtc::CryptoOptions& crypto_options() const {
337 return crypto_options_;
338 }
339
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 // Handled in derived classes
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800341 // Get the SRTP crypto suites to use for RTP media
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200342 virtual void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const = 0;
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000343 virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 const std::vector<ConnectionInfo>& infos) = 0;
345
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000346 // Helper function for invoking bool-returning methods on the worker thread.
347 template <class FunctorT>
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700348 bool InvokeOnWorker(const rtc::Location& posted_from,
349 const FunctorT& functor) {
350 return worker_thread_->Invoke<bool>(posted_from, functor);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000351 }
352
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 private:
skvlad6c87a672016-05-17 17:49:52 -0700354 bool InitNetwork_n(const std::string* bundle_transport_name);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +0200355 void DisconnectTransportChannels_n();
356 void DestroyTransportChannels_n();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200357 void SignalSentPacket_n(TransportChannel* channel,
358 const rtc::SentPacket& sent_packet);
359 void SignalSentPacket_w(const rtc::SentPacket& sent_packet);
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700360 bool IsReadyToSendMedia_n() const;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200361 void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id);
362
363 rtc::Thread* const worker_thread_;
364 rtc::Thread* const network_thread_;
365 rtc::AsyncInvoker invoker_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366
pthatcher@webrtc.org990a00c2015-03-13 18:20:33 +0000367 const std::string content_name_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200368 std::unique_ptr<ConnectionMonitor> connection_monitor_;
369
370 // Transport related members that should be accessed from network thread.
371 TransportController* const transport_controller_;
deadbeefcbecd352015-09-23 11:50:27 -0700372 std::string transport_name_;
deadbeef23d947d2016-08-22 16:00:30 -0700373 // Is RTCP used at all by this type of channel?
374 // Expected to be true (as of typing this) for everything except data
375 // channels.
376 const bool rtcp_enabled_;
377 TransportChannel* transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700378 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700379 TransportChannel* rtcp_transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700380 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 SrtpFilter srtp_filter_;
382 RtcpMuxFilter rtcp_mux_filter_;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000383 BundleFilter bundle_filter_;
deadbeef23d947d2016-08-22 16:00:30 -0700384 bool rtp_ready_to_send_ = false;
385 bool rtcp_ready_to_send_ = false;
386 bool writable_ = false;
387 bool was_ever_writable_ = false;
388 bool has_received_packet_ = false;
389 bool dtls_keyed_ = false;
390 bool secure_required_ = false;
jbauchcb560652016-08-04 05:20:32 -0700391 rtc::CryptoOptions crypto_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700392 int rtp_abs_sendtime_extn_id_ = -1;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200393
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700394 // MediaChannel related members that should be accessed from the worker
395 // thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200396 MediaChannel* const media_channel_;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700397 // Currently the |enabled_| flag is accessed from the signaling thread as
398 // well, but it can be changed only when signaling thread does a synchronous
399 // call to the worker thread, so it should be safe.
deadbeef23d947d2016-08-22 16:00:30 -0700400 bool enabled_ = false;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200401 std::vector<StreamParams> local_streams_;
402 std::vector<StreamParams> remote_streams_;
deadbeef23d947d2016-08-22 16:00:30 -0700403 MediaContentDirection local_content_direction_ = MD_INACTIVE;
404 MediaContentDirection remote_content_direction_ = MD_INACTIVE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405};
406
407// VoiceChannel is a specialization that adds support for early media, DTMF,
408// and input/output level monitoring.
409class VoiceChannel : public BaseChannel {
410 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200411 VoiceChannel(rtc::Thread* worker_thread,
412 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700413 MediaEngineInterface* media_engine,
414 VoiceMediaChannel* channel,
415 TransportController* transport_controller,
416 const std::string& content_name,
417 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 ~VoiceChannel();
skvlad6c87a672016-05-17 17:49:52 -0700419 bool Init_w(const std::string* bundle_transport_name);
solenberg1dd98f32015-09-10 01:57:14 -0700420
421 // Configure sending media on the stream with SSRC |ssrc|
422 // If there is only one sending stream SSRC 0 can be used.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200423 bool SetAudioSend(uint32_t ssrc,
solenbergdfc8f4f2015-10-01 02:31:10 -0700424 bool enable,
deadbeefcbecd352015-09-23 11:50:27 -0700425 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800426 AudioSource* source);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427
428 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200429 VoiceMediaChannel* media_channel() const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
431 }
432
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433 void SetEarlyMedia(bool enable);
434 // This signal is emitted when we have gone a period of time without
435 // receiving early media. When received, a UI should start playing its
436 // own ringing sound
437 sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout;
438
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 // Returns if the telephone-event has been negotiated.
440 bool CanInsertDtmf();
441 // Send and/or play a DTMF |event| according to the |flags|.
442 // The DTMF out-of-band signal will be used on sending.
443 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000444 // The valid value for the |event| are 0 which corresponding to DTMF
445 // event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800446 bool InsertDtmf(uint32_t ssrc, int event_code, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700447 bool SetOutputVolume(uint32_t ssrc, double volume);
deadbeef2d110be2016-01-13 12:00:26 -0800448 void SetRawAudioSink(uint32_t ssrc,
kwiberg31022942016-03-11 14:18:21 -0800449 std::unique_ptr<webrtc::AudioSinkInterface> sink);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700450 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
451 bool SetRtpSendParameters(uint32_t ssrc,
452 const webrtc::RtpParameters& parameters);
453 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
454 bool SetRtpReceiveParameters(uint32_t ssrc,
455 const webrtc::RtpParameters& parameters);
Tommif888bb52015-12-12 01:37:01 +0100456
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 // Get statistics about the current media session.
458 bool GetStats(VoiceMediaInfo* stats);
459
460 // Monitoring functions
461 sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&>
462 SignalConnectionMonitor;
463
464 void StartMediaMonitor(int cms);
465 void StopMediaMonitor();
466 sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor;
467
468 void StartAudioMonitor(int cms);
469 void StopAudioMonitor();
470 bool IsAudioMonitorRunning() const;
471 sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor;
472
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 int GetInputLevel_w();
474 int GetOutputLevel_w();
475 void GetActiveStreams_w(AudioInfo::StreamList* actives);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700476 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
477 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
478 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
479 bool SetRtpReceiveParameters_w(uint32_t ssrc,
480 webrtc::RtpParameters parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700481 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_AUDIO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 private:
484 // overrides from BaseChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200485 void OnChannelRead(TransportChannel* channel,
486 const char* data,
487 size_t len,
488 const rtc::PacketTime& packet_time,
489 int flags) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700490 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200491 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
492 bool SetLocalContent_w(const MediaContentDescription* content,
493 ContentAction action,
494 std::string* error_desc) override;
495 bool SetRemoteContent_w(const MediaContentDescription* content,
496 ContentAction action,
497 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498 void HandleEarlyMediaTimeout();
solenberg1d63dd02015-12-02 12:35:09 -0800499 bool InsertDtmf_w(uint32_t ssrc, int event, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700500 bool SetOutputVolume_w(uint32_t ssrc, double volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 bool GetStats_w(VoiceMediaInfo* stats);
502
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200503 void OnMessage(rtc::Message* pmsg) override;
504 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
505 void OnConnectionMonitorUpdate(
506 ConnectionMonitor* monitor,
507 const std::vector<ConnectionInfo>& infos) override;
508 void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
509 const VoiceMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000511
512 static const int kEarlyMediaTimeout = 1000;
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200513 MediaEngineInterface* media_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 bool received_media_;
kwiberg31022942016-03-11 14:18:21 -0800515 std::unique_ptr<VoiceMediaMonitor> media_monitor_;
516 std::unique_ptr<AudioMonitor> audio_monitor_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700517
518 // Last AudioSendParameters sent down to the media_channel() via
519 // SetSendParameters.
520 AudioSendParameters last_send_params_;
521 // Last AudioRecvParameters sent down to the media_channel() via
522 // SetRecvParameters.
523 AudioRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524};
525
526// VideoChannel is a specialization for video.
527class VideoChannel : public BaseChannel {
528 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200529 VideoChannel(rtc::Thread* worker_thread,
530 rtc::Thread* netwokr_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700531 VideoMediaChannel* channel,
532 TransportController* transport_controller,
533 const std::string& content_name,
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200534 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 ~VideoChannel();
skvlad6c87a672016-05-17 17:49:52 -0700536 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200538 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200539 VideoMediaChannel* media_channel() const override {
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200540 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
541 }
542
nisse08582ff2016-02-04 01:24:52 -0800543 bool SetSink(uint32_t ssrc, rtc::VideoSinkInterface<VideoFrame>* sink);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000544 // Get statistics about the current media session.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000545 bool GetStats(VideoMediaInfo* stats);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546
547 sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&>
548 SignalConnectionMonitor;
549
550 void StartMediaMonitor(int cms);
551 void StopMediaMonitor();
552 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553
deadbeef5a4a75a2016-06-02 16:23:38 -0700554 // Register a source and set options.
555 // The |ssrc| must correspond to a registered send stream.
556 bool SetVideoSend(uint32_t ssrc,
557 bool enable,
558 const VideoOptions* options,
559 rtc::VideoSourceInterface<cricket::VideoFrame>* source);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700560 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
561 bool SetRtpSendParameters(uint32_t ssrc,
562 const webrtc::RtpParameters& parameters);
563 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
564 bool SetRtpReceiveParameters(uint32_t ssrc,
565 const webrtc::RtpParameters& parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700566 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 private:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 // overrides from BaseChannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700570 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200571 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
572 bool SetLocalContent_w(const MediaContentDescription* content,
573 ContentAction action,
574 std::string* error_desc) override;
575 bool SetRemoteContent_w(const MediaContentDescription* content,
576 ContentAction action,
577 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 bool GetStats_w(VideoMediaInfo* stats);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700579 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
580 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
581 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
582 bool SetRtpReceiveParameters_w(uint32_t ssrc,
583 webrtc::RtpParameters parameters);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200585 void OnMessage(rtc::Message* pmsg) override;
586 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
587 void OnConnectionMonitorUpdate(
588 ConnectionMonitor* monitor,
589 const std::vector<ConnectionInfo>& infos) override;
590 void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
591 const VideoMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592
kwiberg31022942016-03-11 14:18:21 -0800593 std::unique_ptr<VideoMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700595 // Last VideoSendParameters sent down to the media_channel() via
596 // SetSendParameters.
597 VideoSendParameters last_send_params_;
598 // Last VideoRecvParameters sent down to the media_channel() via
599 // SetRecvParameters.
600 VideoRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000601};
602
603// DataChannel is a specialization for data.
604class DataChannel : public BaseChannel {
605 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200606 DataChannel(rtc::Thread* worker_thread,
607 rtc::Thread* network_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608 DataMediaChannel* media_channel,
deadbeefcbecd352015-09-23 11:50:27 -0700609 TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 const std::string& content_name,
611 bool rtcp);
612 ~DataChannel();
skvlad6c87a672016-05-17 17:49:52 -0700613 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000615 virtual bool SendData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700616 const rtc::CopyOnWriteBuffer& payload,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000617 SendDataResult* result);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618
619 void StartMediaMonitor(int cms);
620 void StopMediaMonitor();
621
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000622 // Should be called on the signaling thread only.
623 bool ready_to_send_data() const {
624 return ready_to_send_data_;
625 }
626
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor;
628 sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&>
629 SignalConnectionMonitor;
jbaucheec21bd2016-03-20 06:15:43 -0700630 sigslot::signal3<DataChannel*, const ReceiveDataParams&,
631 const rtc::CopyOnWriteBuffer&> SignalDataReceived;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 // Signal for notifying when the channel becomes ready to send data.
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000633 // That occurs when the channel is enabled, the transport is writable,
634 // both local and remote descriptions are set, and the channel is unblocked.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635 sigslot::signal1<bool> SignalReadyToSendData;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +0000636 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200637 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
zhihuang184a3fd2016-06-14 11:47:14 -0700638 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000640 protected:
641 // downcasts a MediaChannel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200642 DataMediaChannel* media_channel() const override {
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000643 return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
644 }
645
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000647 struct SendDataMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 SendDataMessageData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700649 const rtc::CopyOnWriteBuffer* payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650 SendDataResult* result)
651 : params(params),
652 payload(payload),
653 result(result),
654 succeeded(false) {
655 }
656
657 const SendDataParams& params;
jbaucheec21bd2016-03-20 06:15:43 -0700658 const rtc::CopyOnWriteBuffer* payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000659 SendDataResult* result;
660 bool succeeded;
661 };
662
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000663 struct DataReceivedMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 // We copy the data because the data will become invalid after we
665 // handle DataMediaChannel::SignalDataReceived but before we fire
666 // SignalDataReceived.
667 DataReceivedMessageData(
668 const ReceiveDataParams& params, const char* data, size_t len)
669 : params(params),
670 payload(data, len) {
671 }
672 const ReceiveDataParams params;
jbaucheec21bd2016-03-20 06:15:43 -0700673 const rtc::CopyOnWriteBuffer payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674 };
675
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000676 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000677
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678 // overrides from BaseChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200679 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that
681 // it's the same as what was set previously. Returns false if it's
682 // set to one type one type and changed to another type later.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000683 bool SetDataChannelType(DataChannelType new_data_channel_type,
684 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 // Same as SetDataChannelType, but extracts the type from the
686 // DataContentDescription.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000687 bool SetDataChannelTypeFromContent(const DataContentDescription* content,
688 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200689 bool SetLocalContent_w(const MediaContentDescription* content,
690 ContentAction action,
691 std::string* error_desc) override;
692 bool SetRemoteContent_w(const MediaContentDescription* content,
693 ContentAction action,
694 std::string* error_desc) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700695 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200696 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200698 void OnMessage(rtc::Message* pmsg) override;
699 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
700 void OnConnectionMonitorUpdate(
701 ConnectionMonitor* monitor,
702 const std::vector<ConnectionInfo>& infos) override;
703 void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
704 const DataMediaInfo& info);
705 bool ShouldSetupDtlsSrtp_n() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 void OnDataReceived(
707 const ReceiveDataParams& params, const char* data, size_t len);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200708 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000709 void OnDataChannelReadyToSend(bool writable);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200710 void OnStreamClosedRemotely(uint32_t sid);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711
kwiberg31022942016-03-11 14:18:21 -0800712 std::unique_ptr<DataMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 // TODO(pthatcher): Make a separate SctpDataChannel and
714 // RtpDataChannel instead of using this.
715 DataChannelType data_channel_type_;
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000716 bool ready_to_send_data_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700717
718 // Last DataSendParameters sent down to the media_channel() via
719 // SetSendParameters.
720 DataSendParameters last_send_params_;
721 // Last DataRecvParameters sent down to the media_channel() via
722 // SetRecvParameters.
723 DataRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724};
725
726} // namespace cricket
727
perkjc11b1842016-03-07 17:34:13 -0800728#endif // WEBRTC_PC_CHANNEL_H_