blob: 7d3bc946f6a9d6594a7733a3a0a22d73b5f654ca [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
deadbeef062ce9f2016-08-26 21:42:15 -070051// BaseChannel contains logic common to voice and video, including enable,
52// marshaling calls to a worker and network threads, and connection and media
53// monitors.
54//
Danil Chapovalov33b01f22016-05-11 19:55:27 +020055// BaseChannel assumes signaling and other threads are allowed to make
56// synchronous calls to the worker thread, the worker thread makes synchronous
57// calls only to the network thread, and the network thread can't be blocked by
58// other threads.
59// All methods with _n suffix must be called on network thread,
deadbeef062ce9f2016-08-26 21:42:15 -070060// methods with _w suffix on worker thread
Danil Chapovalov33b01f22016-05-11 19:55:27 +020061// and methods with _s suffix on signaling thread.
62// Network and worker threads may be the same thread.
wu@webrtc.org78187522013-10-07 23:32:02 +000063//
64// WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS!
65// This is required to avoid a data race between the destructor modifying the
66// vtable, and the media channel's thread using BaseChannel as the
67// NetworkInterface.
68
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069class BaseChannel
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000070 : public rtc::MessageHandler, public sigslot::has_slots<>,
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000071 public MediaChannel::NetworkInterface,
72 public ConnectionStatsGetter {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 public:
deadbeef23d947d2016-08-22 16:00:30 -070074 // |rtcp| represents whether or not this channel uses RTCP.
Danil Chapovalov33b01f22016-05-11 19:55:27 +020075 BaseChannel(rtc::Thread* worker_thread,
76 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -070077 MediaChannel* channel,
78 TransportController* transport_controller,
79 const std::string& content_name,
80 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081 virtual ~BaseChannel();
skvlad6c87a672016-05-17 17:49:52 -070082 bool Init_w(const std::string* bundle_transport_name);
Danil Chapovalov33b01f22016-05-11 19:55:27 +020083 // Deinit may be called multiple times and is simply ignored if it's already
wu@webrtc.org78187522013-10-07 23:32:02 +000084 // done.
85 void Deinit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000087 rtc::Thread* worker_thread() const { return worker_thread_; }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020088 rtc::Thread* network_thread() const { return network_thread_; }
deadbeefcbecd352015-09-23 11:50:27 -070089 const std::string& content_name() const { return content_name_; }
90 const std::string& transport_name() const { return transport_name_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 bool enabled() const { return enabled_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
93 // This function returns true if we are using SRTP.
94 bool secure() const { return srtp_filter_.IsActive(); }
95 // The following function returns true if we are using
96 // DTLS-based keying. If you turned off SRTP later, however
97 // you could have secure() == false and dtls_secure() == true.
98 bool secure_dtls() const { return dtls_keyed_; }
99 // This function returns true if we require secure channel for call setup.
100 bool secure_required() const { return secure_required_; }
101
102 bool writable() const { return writable_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700104 // Activate RTCP mux, regardless of the state so far. Once
105 // activated, it can not be deactivated, and if the remote
106 // description doesn't support RTCP mux, setting the remote
107 // description will fail.
108 void ActivateRtcpMux();
deadbeefcbecd352015-09-23 11:50:27 -0700109 bool SetTransport(const std::string& transport_name);
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +0000110 bool PushdownLocalDescription(const SessionDescription* local_desc,
111 ContentAction action,
112 std::string* error_desc);
113 bool PushdownRemoteDescription(const SessionDescription* remote_desc,
114 ContentAction action,
115 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 // Channel control
117 bool SetLocalContent(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000118 ContentAction action,
119 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 bool SetRemoteContent(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000121 ContentAction action,
122 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123
124 bool Enable(bool enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125
126 // Multiplexing
127 bool AddRecvStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200128 bool RemoveRecvStream(uint32_t ssrc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000129 bool AddSendStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200130 bool RemoveSendStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131
132 // Monitoring
133 void StartConnectionMonitor(int cms);
134 void StopConnectionMonitor();
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000135 // For ConnectionStatsGetter, used by ConnectionMonitor
deadbeefcbecd352015-09-23 11:50:27 -0700136 bool GetConnectionStats(ConnectionInfos* infos) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000138 BundleFilter* bundle_filter() { return &bundle_filter_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139
140 const std::vector<StreamParams>& local_streams() const {
141 return local_streams_;
142 }
143 const std::vector<StreamParams>& remote_streams() const {
144 return remote_streams_;
145 }
146
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000147 sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200148 void SignalDtlsSetupFailure_n(bool rtcp);
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000149 void SignalDtlsSetupFailure_s(bool rtcp);
150
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +0000151 // Used for latency measurements.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
153
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200154 // Forward TransportChannel SignalSentPacket to worker thread.
155 sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
156
157 // Only public for unit tests. Otherwise, consider private.
158 TransportChannel* transport_channel() const { return transport_channel_; }
159 TransportChannel* rtcp_transport_channel() const {
160 return rtcp_transport_channel_;
161 }
162
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 // Made public for easier testing.
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700164 //
165 // Updates "ready to send" for an individual channel, and informs the media
166 // channel that the transport is ready to send if each channel (in use) is
167 // ready to send. This is more specific than just "writable"; it means the
168 // last send didn't return ENOTCONN.
169 //
170 // This should be called whenever a channel's ready-to-send state changes,
171 // or when RTCP muxing becomes active/inactive.
172 void SetTransportChannelReadyToSend(bool rtcp, bool ready);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000174 // Only public for unit tests. Otherwise, consider protected.
rlesterec9d1872015-10-27 14:22:16 -0700175 int SetOption(SocketType type, rtc::Socket::Option o, int val)
176 override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200177 int SetOption_n(SocketType type, rtc::Socket::Option o, int val);
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000178
solenberg5b14b422015-10-01 04:10:31 -0700179 SrtpFilter* srtp_filter() { return &srtp_filter_; }
180
zhihuang184a3fd2016-06-14 11:47:14 -0700181 virtual cricket::MediaType media_type() = 0;
182
jbauchcb560652016-08-04 05:20:32 -0700183 bool SetCryptoOptions(const rtc::CryptoOptions& crypto_options);
184
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 protected:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 virtual MediaChannel* media_channel() const { return media_channel_; }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700187
188 // Sets the |transport_channel_| (and |rtcp_transport_channel_|, if
189 // |rtcp_enabled_| is true). Gets the transport channels from
190 // |transport_controller_|.
deadbeef062ce9f2016-08-26 21:42:15 -0700191 // This method also updates writability and "ready-to-send" state.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200192 bool SetTransport_n(const std::string& transport_name);
guoweis46383312015-12-17 16:45:59 -0800193
deadbeef062ce9f2016-08-26 21:42:15 -0700194 // This does not update writability or "ready-to-send" state; it just
195 // disconnects from the old channel and connects to the new one.
196 void SetTransportChannel_n(bool rtcp, TransportChannel* new_channel);
guoweis46383312015-12-17 16:45:59 -0800197
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 bool was_ever_writable() const { return was_ever_writable_; }
199 void set_local_content_direction(MediaContentDirection direction) {
200 local_content_direction_ = direction;
201 }
202 void set_remote_content_direction(MediaContentDirection direction) {
203 remote_content_direction_ = direction;
204 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700205 void set_secure_required(bool secure_required) {
206 secure_required_ = secure_required;
207 }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700208 // These methods verify that:
209 // * The required content description directions have been set.
210 // * The channel is enabled.
211 // * And for sending:
212 // - The SRTP filter is active if it's needed.
213 // - The transport has been writable before, meaning it should be at least
214 // possible to succeed in sending a packet.
215 //
216 // When any of these properties change, UpdateMediaSendRecvState_w should be
217 // called.
218 bool IsReadyToReceiveMedia_w() const;
219 bool IsReadyToSendMedia_w() const;
deadbeefcbecd352015-09-23 11:50:27 -0700220 rtc::Thread* signaling_thread() {
221 return transport_controller_->signaling_thread();
222 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223
pthatcher@webrtc.org6ad507a2015-03-16 20:19:12 +0000224 void ConnectToTransportChannel(TransportChannel* tc);
225 void DisconnectFromTransportChannel(TransportChannel* tc);
226
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200227 void FlushRtcpMessages_n();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228
229 // NetworkInterface implementation, called by MediaEngine
jbaucheec21bd2016-03-20 06:15:43 -0700230 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
231 const rtc::PacketOptions& options) override;
232 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
233 const rtc::PacketOptions& options) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234
235 // From TransportChannel
236 void OnWritableState(TransportChannel* channel);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000237 virtual void OnChannelRead(TransportChannel* channel,
238 const char* data,
239 size_t len,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000240 const rtc::PacketTime& packet_time,
wu@webrtc.orga9890802013-12-13 00:21:03 +0000241 int flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 void OnReadyToSend(TransportChannel* channel);
243
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800244 void OnDtlsState(TransportChannel* channel, DtlsTransportState state);
245
Honghai Zhangcc411c02016-03-29 17:27:21 -0700246 void OnSelectedCandidatePairChanged(
247 TransportChannel* channel,
Honghai Zhang52dce732016-03-31 12:37:31 -0700248 CandidatePairInterface* selected_candidate_pair,
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700249 int last_sent_packet_id,
250 bool ready_to_send);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700251
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 bool PacketIsRtcp(const TransportChannel* channel, const char* data,
253 size_t len);
stefanc1aeaf02015-10-15 07:26:07 -0700254 bool SendPacket(bool rtcp,
jbaucheec21bd2016-03-20 06:15:43 -0700255 rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700256 const rtc::PacketOptions& options);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200257
jbaucheec21bd2016-03-20 06:15:43 -0700258 virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
259 void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000260 const rtc::PacketTime& packet_time);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200261 void OnPacketReceived(bool rtcp,
262 const rtc::CopyOnWriteBuffer& packet,
263 const rtc::PacketTime& packet_time);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 void EnableMedia_w();
266 void DisableMedia_w();
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700267
268 // Performs actions if the RTP/RTCP writable state changed. This should
269 // be called whenever a channel's writable state changes or when RTCP muxing
270 // becomes active/inactive.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200271 void UpdateWritableState_n();
272 void ChannelWritable_n();
273 void ChannelNotWritable_n();
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700274
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 bool AddRecvStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200276 bool RemoveRecvStream_w(uint32_t ssrc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000277 bool AddSendStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200278 bool RemoveSendStream_w(uint32_t ssrc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200279 virtual bool ShouldSetupDtlsSrtp_n() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters.
281 // |rtcp_channel| indicates whether to set up the RTP or RTCP filter.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200282 bool SetupDtlsSrtp_n(bool rtcp_channel);
283 void MaybeSetupDtlsSrtp_n();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284 // Set the DTLS-SRTP cipher policy on this channel as appropriate.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200285 bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700287 // Should be called whenever the conditions for
288 // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied).
289 // Updates the send/recv state of the media channel.
290 void UpdateMediaSendRecvState();
291 virtual void UpdateMediaSendRecvState_w() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292
293 // Gets the content info appropriate to the channel (audio or video).
294 virtual const ContentInfo* GetFirstContent(
295 const SessionDescription* sdesc) = 0;
296 bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000297 ContentAction action,
298 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000300 ContentAction action,
301 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 virtual bool SetLocalContent_w(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000303 ContentAction action,
304 std::string* error_desc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000306 ContentAction action,
307 std::string* error_desc) = 0;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200308 bool SetRtpTransportParameters(const MediaContentDescription* content,
309 ContentAction action,
310 ContentSource src,
311 std::string* error_desc);
312 bool SetRtpTransportParameters_n(const MediaContentDescription* content,
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700313 ContentAction action,
314 ContentSource src,
315 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316
henrike@webrtc.orgd43aa9d2014-02-21 23:43:24 +0000317 // Helper method to get RTP Absoulute SendTime extension header id if
318 // present in remote supported extensions list.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200319 void MaybeCacheRtpAbsSendTimeHeaderExtension_w(
isheriff6f8d6862016-05-26 11:24:55 -0700320 const std::vector<webrtc::RtpExtension>& extensions);
henrike@webrtc.orgd43aa9d2014-02-21 23:43:24 +0000321
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200322 bool CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
323 bool* dtls,
324 std::string* error_desc);
325 bool SetSrtp_n(const std::vector<CryptoParams>& params,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000326 ContentAction action,
327 ContentSource src,
328 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200329 void ActivateRtcpMux_n();
330 bool SetRtcpMux_n(bool enable,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000331 ContentAction action,
332 ContentSource src,
333 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334
335 // From MessageHandler
rlesterec9d1872015-10-27 14:22:16 -0700336 void OnMessage(rtc::Message* pmsg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337
jbauchcb560652016-08-04 05:20:32 -0700338 const rtc::CryptoOptions& crypto_options() const {
339 return crypto_options_;
340 }
341
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 // Handled in derived classes
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800343 // Get the SRTP crypto suites to use for RTP media
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200344 virtual void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const = 0;
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000345 virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 const std::vector<ConnectionInfo>& infos) = 0;
347
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000348 // Helper function for invoking bool-returning methods on the worker thread.
349 template <class FunctorT>
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700350 bool InvokeOnWorker(const rtc::Location& posted_from,
351 const FunctorT& functor) {
352 return worker_thread_->Invoke<bool>(posted_from, functor);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000353 }
354
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 private:
skvlad6c87a672016-05-17 17:49:52 -0700356 bool InitNetwork_n(const std::string* bundle_transport_name);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +0200357 void DisconnectTransportChannels_n();
358 void DestroyTransportChannels_n();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200359 void SignalSentPacket_n(TransportChannel* channel,
360 const rtc::SentPacket& sent_packet);
361 void SignalSentPacket_w(const rtc::SentPacket& sent_packet);
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700362 bool IsReadyToSendMedia_n() const;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200363 void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id);
364
365 rtc::Thread* const worker_thread_;
366 rtc::Thread* const network_thread_;
367 rtc::AsyncInvoker invoker_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368
pthatcher@webrtc.org990a00c2015-03-13 18:20:33 +0000369 const std::string content_name_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200370 std::unique_ptr<ConnectionMonitor> connection_monitor_;
371
372 // Transport related members that should be accessed from network thread.
373 TransportController* const transport_controller_;
deadbeefcbecd352015-09-23 11:50:27 -0700374 std::string transport_name_;
deadbeef23d947d2016-08-22 16:00:30 -0700375 // Is RTCP used at all by this type of channel?
376 // Expected to be true (as of typing this) for everything except data
377 // channels.
378 const bool rtcp_enabled_;
379 TransportChannel* transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700380 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700381 TransportChannel* rtcp_transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700382 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 SrtpFilter srtp_filter_;
384 RtcpMuxFilter rtcp_mux_filter_;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000385 BundleFilter bundle_filter_;
deadbeef23d947d2016-08-22 16:00:30 -0700386 bool rtp_ready_to_send_ = false;
387 bool rtcp_ready_to_send_ = false;
388 bool writable_ = false;
389 bool was_ever_writable_ = false;
390 bool has_received_packet_ = false;
391 bool dtls_keyed_ = false;
392 bool secure_required_ = false;
jbauchcb560652016-08-04 05:20:32 -0700393 rtc::CryptoOptions crypto_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700394 int rtp_abs_sendtime_extn_id_ = -1;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200395
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700396 // MediaChannel related members that should be accessed from the worker
397 // thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200398 MediaChannel* const media_channel_;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700399 // Currently the |enabled_| flag is accessed from the signaling thread as
400 // well, but it can be changed only when signaling thread does a synchronous
401 // call to the worker thread, so it should be safe.
deadbeef23d947d2016-08-22 16:00:30 -0700402 bool enabled_ = false;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200403 std::vector<StreamParams> local_streams_;
404 std::vector<StreamParams> remote_streams_;
deadbeef23d947d2016-08-22 16:00:30 -0700405 MediaContentDirection local_content_direction_ = MD_INACTIVE;
406 MediaContentDirection remote_content_direction_ = MD_INACTIVE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407};
408
409// VoiceChannel is a specialization that adds support for early media, DTMF,
410// and input/output level monitoring.
411class VoiceChannel : public BaseChannel {
412 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200413 VoiceChannel(rtc::Thread* worker_thread,
414 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700415 MediaEngineInterface* media_engine,
416 VoiceMediaChannel* channel,
417 TransportController* transport_controller,
418 const std::string& content_name,
419 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420 ~VoiceChannel();
skvlad6c87a672016-05-17 17:49:52 -0700421 bool Init_w(const std::string* bundle_transport_name);
solenberg1dd98f32015-09-10 01:57:14 -0700422
423 // Configure sending media on the stream with SSRC |ssrc|
424 // If there is only one sending stream SSRC 0 can be used.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200425 bool SetAudioSend(uint32_t ssrc,
solenbergdfc8f4f2015-10-01 02:31:10 -0700426 bool enable,
deadbeefcbecd352015-09-23 11:50:27 -0700427 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800428 AudioSource* source);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429
430 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200431 VoiceMediaChannel* media_channel() const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
433 }
434
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435 void SetEarlyMedia(bool enable);
436 // This signal is emitted when we have gone a period of time without
437 // receiving early media. When received, a UI should start playing its
438 // own ringing sound
439 sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout;
440
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 // Returns if the telephone-event has been negotiated.
442 bool CanInsertDtmf();
443 // Send and/or play a DTMF |event| according to the |flags|.
444 // The DTMF out-of-band signal will be used on sending.
445 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000446 // The valid value for the |event| are 0 which corresponding to DTMF
447 // event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800448 bool InsertDtmf(uint32_t ssrc, int event_code, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700449 bool SetOutputVolume(uint32_t ssrc, double volume);
deadbeef2d110be2016-01-13 12:00:26 -0800450 void SetRawAudioSink(uint32_t ssrc,
kwiberg31022942016-03-11 14:18:21 -0800451 std::unique_ptr<webrtc::AudioSinkInterface> sink);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700452 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
453 bool SetRtpSendParameters(uint32_t ssrc,
454 const webrtc::RtpParameters& parameters);
455 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
456 bool SetRtpReceiveParameters(uint32_t ssrc,
457 const webrtc::RtpParameters& parameters);
Tommif888bb52015-12-12 01:37:01 +0100458
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 // Get statistics about the current media session.
460 bool GetStats(VoiceMediaInfo* stats);
461
462 // Monitoring functions
463 sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&>
464 SignalConnectionMonitor;
465
466 void StartMediaMonitor(int cms);
467 void StopMediaMonitor();
468 sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor;
469
470 void StartAudioMonitor(int cms);
471 void StopAudioMonitor();
472 bool IsAudioMonitorRunning() const;
473 sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor;
474
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 int GetInputLevel_w();
476 int GetOutputLevel_w();
477 void GetActiveStreams_w(AudioInfo::StreamList* actives);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700478 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
479 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
480 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
481 bool SetRtpReceiveParameters_w(uint32_t ssrc,
482 webrtc::RtpParameters parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700483 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_AUDIO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000485 private:
486 // overrides from BaseChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200487 void OnChannelRead(TransportChannel* channel,
488 const char* data,
489 size_t len,
490 const rtc::PacketTime& packet_time,
491 int flags) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700492 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200493 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
494 bool SetLocalContent_w(const MediaContentDescription* content,
495 ContentAction action,
496 std::string* error_desc) override;
497 bool SetRemoteContent_w(const MediaContentDescription* content,
498 ContentAction action,
499 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500 void HandleEarlyMediaTimeout();
solenberg1d63dd02015-12-02 12:35:09 -0800501 bool InsertDtmf_w(uint32_t ssrc, int event, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700502 bool SetOutputVolume_w(uint32_t ssrc, double volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000503 bool GetStats_w(VoiceMediaInfo* stats);
504
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200505 void OnMessage(rtc::Message* pmsg) override;
506 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
507 void OnConnectionMonitorUpdate(
508 ConnectionMonitor* monitor,
509 const std::vector<ConnectionInfo>& infos) override;
510 void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
511 const VoiceMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513
514 static const int kEarlyMediaTimeout = 1000;
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200515 MediaEngineInterface* media_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000516 bool received_media_;
kwiberg31022942016-03-11 14:18:21 -0800517 std::unique_ptr<VoiceMediaMonitor> media_monitor_;
518 std::unique_ptr<AudioMonitor> audio_monitor_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700519
520 // Last AudioSendParameters sent down to the media_channel() via
521 // SetSendParameters.
522 AudioSendParameters last_send_params_;
523 // Last AudioRecvParameters sent down to the media_channel() via
524 // SetRecvParameters.
525 AudioRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526};
527
528// VideoChannel is a specialization for video.
529class VideoChannel : public BaseChannel {
530 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200531 VideoChannel(rtc::Thread* worker_thread,
532 rtc::Thread* netwokr_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700533 VideoMediaChannel* channel,
534 TransportController* transport_controller,
535 const std::string& content_name,
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200536 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 ~VideoChannel();
skvlad6c87a672016-05-17 17:49:52 -0700538 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200540 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200541 VideoMediaChannel* media_channel() const override {
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200542 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
543 }
544
nisse08582ff2016-02-04 01:24:52 -0800545 bool SetSink(uint32_t ssrc, rtc::VideoSinkInterface<VideoFrame>* sink);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 // Get statistics about the current media session.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000547 bool GetStats(VideoMediaInfo* stats);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548
549 sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&>
550 SignalConnectionMonitor;
551
552 void StartMediaMonitor(int cms);
553 void StopMediaMonitor();
554 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555
deadbeef5a4a75a2016-06-02 16:23:38 -0700556 // Register a source and set options.
557 // The |ssrc| must correspond to a registered send stream.
558 bool SetVideoSend(uint32_t ssrc,
559 bool enable,
560 const VideoOptions* options,
561 rtc::VideoSourceInterface<cricket::VideoFrame>* source);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700562 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
563 bool SetRtpSendParameters(uint32_t ssrc,
564 const webrtc::RtpParameters& parameters);
565 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
566 bool SetRtpReceiveParameters(uint32_t ssrc,
567 const webrtc::RtpParameters& parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700568 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 private:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 // overrides from BaseChannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700572 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200573 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
574 bool SetLocalContent_w(const MediaContentDescription* content,
575 ContentAction action,
576 std::string* error_desc) override;
577 bool SetRemoteContent_w(const MediaContentDescription* content,
578 ContentAction action,
579 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 bool GetStats_w(VideoMediaInfo* stats);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700581 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
582 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
583 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
584 bool SetRtpReceiveParameters_w(uint32_t ssrc,
585 webrtc::RtpParameters parameters);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200587 void OnMessage(rtc::Message* pmsg) override;
588 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
589 void OnConnectionMonitorUpdate(
590 ConnectionMonitor* monitor,
591 const std::vector<ConnectionInfo>& infos) override;
592 void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
593 const VideoMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594
kwiberg31022942016-03-11 14:18:21 -0800595 std::unique_ptr<VideoMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700597 // Last VideoSendParameters sent down to the media_channel() via
598 // SetSendParameters.
599 VideoSendParameters last_send_params_;
600 // Last VideoRecvParameters sent down to the media_channel() via
601 // SetRecvParameters.
602 VideoRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603};
604
605// DataChannel is a specialization for data.
606class DataChannel : public BaseChannel {
607 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200608 DataChannel(rtc::Thread* worker_thread,
609 rtc::Thread* network_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 DataMediaChannel* media_channel,
deadbeefcbecd352015-09-23 11:50:27 -0700611 TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 const std::string& content_name,
613 bool rtcp);
614 ~DataChannel();
skvlad6c87a672016-05-17 17:49:52 -0700615 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000617 virtual bool SendData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700618 const rtc::CopyOnWriteBuffer& payload,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000619 SendDataResult* result);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620
621 void StartMediaMonitor(int cms);
622 void StopMediaMonitor();
623
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000624 // Should be called on the signaling thread only.
625 bool ready_to_send_data() const {
626 return ready_to_send_data_;
627 }
628
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor;
630 sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&>
631 SignalConnectionMonitor;
jbaucheec21bd2016-03-20 06:15:43 -0700632 sigslot::signal3<DataChannel*, const ReceiveDataParams&,
633 const rtc::CopyOnWriteBuffer&> SignalDataReceived;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634 // Signal for notifying when the channel becomes ready to send data.
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000635 // That occurs when the channel is enabled, the transport is writable,
636 // both local and remote descriptions are set, and the channel is unblocked.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637 sigslot::signal1<bool> SignalReadyToSendData;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +0000638 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200639 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
zhihuang184a3fd2016-06-14 11:47:14 -0700640 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000642 protected:
643 // downcasts a MediaChannel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200644 DataMediaChannel* media_channel() const override {
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000645 return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
646 }
647
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000649 struct SendDataMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650 SendDataMessageData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700651 const rtc::CopyOnWriteBuffer* payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652 SendDataResult* result)
653 : params(params),
654 payload(payload),
655 result(result),
656 succeeded(false) {
657 }
658
659 const SendDataParams& params;
jbaucheec21bd2016-03-20 06:15:43 -0700660 const rtc::CopyOnWriteBuffer* payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 SendDataResult* result;
662 bool succeeded;
663 };
664
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000665 struct DataReceivedMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 // We copy the data because the data will become invalid after we
667 // handle DataMediaChannel::SignalDataReceived but before we fire
668 // SignalDataReceived.
669 DataReceivedMessageData(
670 const ReceiveDataParams& params, const char* data, size_t len)
671 : params(params),
672 payload(data, len) {
673 }
674 const ReceiveDataParams params;
jbaucheec21bd2016-03-20 06:15:43 -0700675 const rtc::CopyOnWriteBuffer payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676 };
677
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000678 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000679
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 // overrides from BaseChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200681 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that
683 // it's the same as what was set previously. Returns false if it's
684 // set to one type one type and changed to another type later.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000685 bool SetDataChannelType(DataChannelType new_data_channel_type,
686 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 // Same as SetDataChannelType, but extracts the type from the
688 // DataContentDescription.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000689 bool SetDataChannelTypeFromContent(const DataContentDescription* content,
690 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200691 bool SetLocalContent_w(const MediaContentDescription* content,
692 ContentAction action,
693 std::string* error_desc) override;
694 bool SetRemoteContent_w(const MediaContentDescription* content,
695 ContentAction action,
696 std::string* error_desc) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700697 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200698 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200700 void OnMessage(rtc::Message* pmsg) override;
701 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
702 void OnConnectionMonitorUpdate(
703 ConnectionMonitor* monitor,
704 const std::vector<ConnectionInfo>& infos) override;
705 void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
706 const DataMediaInfo& info);
707 bool ShouldSetupDtlsSrtp_n() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 void OnDataReceived(
709 const ReceiveDataParams& params, const char* data, size_t len);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200710 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000711 void OnDataChannelReadyToSend(bool writable);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200712 void OnStreamClosedRemotely(uint32_t sid);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713
kwiberg31022942016-03-11 14:18:21 -0800714 std::unique_ptr<DataMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 // TODO(pthatcher): Make a separate SctpDataChannel and
716 // RtpDataChannel instead of using this.
717 DataChannelType data_channel_type_;
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000718 bool ready_to_send_data_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700719
720 // Last DataSendParameters sent down to the media_channel() via
721 // SetSendParameters.
722 DataSendParameters last_send_params_;
723 // Last DataRecvParameters sent down to the media_channel() via
724 // SetRecvParameters.
725 DataRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726};
727
728} // namespace cricket
729
perkjc11b1842016-03-07 17:34:13 -0800730#endif // WEBRTC_PC_CHANNEL_H_