blob: 308903c2db1cf9774c3b43bc14b13a96ebff014c [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);
michaelt79e05882016-11-08 02:50:09 -0800369 int GetTransportOverheadPerPacket() const;
370 void UpdateTransportOverhead();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200371
372 rtc::Thread* const worker_thread_;
373 rtc::Thread* const network_thread_;
374 rtc::AsyncInvoker invoker_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375
pthatcher@webrtc.org990a00c2015-03-13 18:20:33 +0000376 const std::string content_name_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200377 std::unique_ptr<ConnectionMonitor> connection_monitor_;
378
379 // Transport related members that should be accessed from network thread.
380 TransportController* const transport_controller_;
deadbeefcbecd352015-09-23 11:50:27 -0700381 std::string transport_name_;
deadbeef23d947d2016-08-22 16:00:30 -0700382 // Is RTCP used at all by this type of channel?
383 // Expected to be true (as of typing this) for everything except data
384 // channels.
385 const bool rtcp_enabled_;
johand89ab142016-10-25 10:50:32 -0700386 // TODO(johan): Replace TransportChannel* with rtc::PacketTransportInterface*.
deadbeef23d947d2016-08-22 16:00:30 -0700387 TransportChannel* transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700388 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700389 TransportChannel* rtcp_transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700390 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 SrtpFilter srtp_filter_;
392 RtcpMuxFilter rtcp_mux_filter_;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000393 BundleFilter bundle_filter_;
deadbeef23d947d2016-08-22 16:00:30 -0700394 bool rtp_ready_to_send_ = false;
395 bool rtcp_ready_to_send_ = false;
396 bool writable_ = false;
397 bool was_ever_writable_ = false;
398 bool has_received_packet_ = false;
399 bool dtls_keyed_ = false;
400 bool secure_required_ = false;
jbauchcb560652016-08-04 05:20:32 -0700401 rtc::CryptoOptions crypto_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700402 int rtp_abs_sendtime_extn_id_ = -1;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200403
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700404 // MediaChannel related members that should be accessed from the worker
405 // thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200406 MediaChannel* const media_channel_;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700407 // Currently the |enabled_| flag is accessed from the signaling thread as
408 // well, but it can be changed only when signaling thread does a synchronous
409 // call to the worker thread, so it should be safe.
deadbeef23d947d2016-08-22 16:00:30 -0700410 bool enabled_ = false;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200411 std::vector<StreamParams> local_streams_;
412 std::vector<StreamParams> remote_streams_;
deadbeef23d947d2016-08-22 16:00:30 -0700413 MediaContentDirection local_content_direction_ = MD_INACTIVE;
414 MediaContentDirection remote_content_direction_ = MD_INACTIVE;
michaelt79e05882016-11-08 02:50:09 -0800415 CandidatePairInterface* selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416};
417
418// VoiceChannel is a specialization that adds support for early media, DTMF,
419// and input/output level monitoring.
420class VoiceChannel : public BaseChannel {
421 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200422 VoiceChannel(rtc::Thread* worker_thread,
423 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700424 MediaEngineInterface* media_engine,
425 VoiceMediaChannel* channel,
426 TransportController* transport_controller,
427 const std::string& content_name,
428 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429 ~VoiceChannel();
skvlad6c87a672016-05-17 17:49:52 -0700430 bool Init_w(const std::string* bundle_transport_name);
solenberg1dd98f32015-09-10 01:57:14 -0700431
432 // Configure sending media on the stream with SSRC |ssrc|
433 // If there is only one sending stream SSRC 0 can be used.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200434 bool SetAudioSend(uint32_t ssrc,
solenbergdfc8f4f2015-10-01 02:31:10 -0700435 bool enable,
deadbeefcbecd352015-09-23 11:50:27 -0700436 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800437 AudioSource* source);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438
439 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200440 VoiceMediaChannel* media_channel() const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
442 }
443
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 void SetEarlyMedia(bool enable);
445 // This signal is emitted when we have gone a period of time without
446 // receiving early media. When received, a UI should start playing its
447 // own ringing sound
448 sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout;
449
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 // Returns if the telephone-event has been negotiated.
451 bool CanInsertDtmf();
452 // Send and/or play a DTMF |event| according to the |flags|.
453 // The DTMF out-of-band signal will be used on sending.
454 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000455 // The valid value for the |event| are 0 which corresponding to DTMF
456 // event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800457 bool InsertDtmf(uint32_t ssrc, int event_code, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700458 bool SetOutputVolume(uint32_t ssrc, double volume);
deadbeef2d110be2016-01-13 12:00:26 -0800459 void SetRawAudioSink(uint32_t ssrc,
kwiberg31022942016-03-11 14:18:21 -0800460 std::unique_ptr<webrtc::AudioSinkInterface> sink);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700461 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
462 bool SetRtpSendParameters(uint32_t ssrc,
463 const webrtc::RtpParameters& parameters);
464 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
465 bool SetRtpReceiveParameters(uint32_t ssrc,
466 const webrtc::RtpParameters& parameters);
Tommif888bb52015-12-12 01:37:01 +0100467
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 // Get statistics about the current media session.
469 bool GetStats(VoiceMediaInfo* stats);
470
471 // Monitoring functions
472 sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&>
473 SignalConnectionMonitor;
474
475 void StartMediaMonitor(int cms);
476 void StopMediaMonitor();
477 sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor;
478
479 void StartAudioMonitor(int cms);
480 void StopAudioMonitor();
481 bool IsAudioMonitorRunning() const;
482 sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor;
483
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 int GetInputLevel_w();
485 int GetOutputLevel_w();
486 void GetActiveStreams_w(AudioInfo::StreamList* actives);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700487 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
488 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
489 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
490 bool SetRtpReceiveParameters_w(uint32_t ssrc,
491 webrtc::RtpParameters parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700492 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_AUDIO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 private:
495 // overrides from BaseChannel
johand89ab142016-10-25 10:50:32 -0700496 void OnPacketRead(rtc::PacketTransportInterface* transport,
497 const char* data,
498 size_t len,
499 const rtc::PacketTime& packet_time,
500 int flags) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700501 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200502 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
503 bool SetLocalContent_w(const MediaContentDescription* content,
504 ContentAction action,
505 std::string* error_desc) override;
506 bool SetRemoteContent_w(const MediaContentDescription* content,
507 ContentAction action,
508 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509 void HandleEarlyMediaTimeout();
solenberg1d63dd02015-12-02 12:35:09 -0800510 bool InsertDtmf_w(uint32_t ssrc, int event, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700511 bool SetOutputVolume_w(uint32_t ssrc, double volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 bool GetStats_w(VoiceMediaInfo* stats);
513
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200514 void OnMessage(rtc::Message* pmsg) override;
515 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
516 void OnConnectionMonitorUpdate(
517 ConnectionMonitor* monitor,
518 const std::vector<ConnectionInfo>& infos) override;
519 void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
520 const VoiceMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522
523 static const int kEarlyMediaTimeout = 1000;
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200524 MediaEngineInterface* media_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000525 bool received_media_;
kwiberg31022942016-03-11 14:18:21 -0800526 std::unique_ptr<VoiceMediaMonitor> media_monitor_;
527 std::unique_ptr<AudioMonitor> audio_monitor_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700528
529 // Last AudioSendParameters sent down to the media_channel() via
530 // SetSendParameters.
531 AudioSendParameters last_send_params_;
532 // Last AudioRecvParameters sent down to the media_channel() via
533 // SetRecvParameters.
534 AudioRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535};
536
537// VideoChannel is a specialization for video.
538class VideoChannel : public BaseChannel {
539 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200540 VideoChannel(rtc::Thread* worker_thread,
541 rtc::Thread* netwokr_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700542 VideoMediaChannel* channel,
543 TransportController* transport_controller,
544 const std::string& content_name,
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200545 bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 ~VideoChannel();
skvlad6c87a672016-05-17 17:49:52 -0700547 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200549 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200550 VideoMediaChannel* media_channel() const override {
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200551 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
552 }
553
nisseacd935b2016-11-11 03:55:13 -0800554 bool SetSink(uint32_t ssrc,
555 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 // Get statistics about the current media session.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000557 bool GetStats(VideoMediaInfo* stats);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558
559 sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&>
560 SignalConnectionMonitor;
561
562 void StartMediaMonitor(int cms);
563 void StopMediaMonitor();
564 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565
deadbeef5a4a75a2016-06-02 16:23:38 -0700566 // Register a source and set options.
567 // The |ssrc| must correspond to a registered send stream.
568 bool SetVideoSend(uint32_t ssrc,
569 bool enable,
570 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800571 rtc::VideoSourceInterface<webrtc::VideoFrame>* source);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700572 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
573 bool SetRtpSendParameters(uint32_t ssrc,
574 const webrtc::RtpParameters& parameters);
575 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
576 bool SetRtpReceiveParameters(uint32_t ssrc,
577 const webrtc::RtpParameters& parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700578 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 private:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 // overrides from BaseChannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700582 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200583 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
584 bool SetLocalContent_w(const MediaContentDescription* content,
585 ContentAction action,
586 std::string* error_desc) override;
587 bool SetRemoteContent_w(const MediaContentDescription* content,
588 ContentAction action,
589 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 bool GetStats_w(VideoMediaInfo* stats);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700591 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
592 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
593 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
594 bool SetRtpReceiveParameters_w(uint32_t ssrc,
595 webrtc::RtpParameters parameters);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200597 void OnMessage(rtc::Message* pmsg) override;
598 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
599 void OnConnectionMonitorUpdate(
600 ConnectionMonitor* monitor,
601 const std::vector<ConnectionInfo>& infos) override;
602 void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
603 const VideoMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000604
kwiberg31022942016-03-11 14:18:21 -0800605 std::unique_ptr<VideoMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700607 // Last VideoSendParameters sent down to the media_channel() via
608 // SetSendParameters.
609 VideoSendParameters last_send_params_;
610 // Last VideoRecvParameters sent down to the media_channel() via
611 // SetRecvParameters.
612 VideoRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613};
614
615// DataChannel is a specialization for data.
616class DataChannel : public BaseChannel {
617 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200618 DataChannel(rtc::Thread* worker_thread,
619 rtc::Thread* network_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620 DataMediaChannel* media_channel,
deadbeefcbecd352015-09-23 11:50:27 -0700621 TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 const std::string& content_name,
623 bool rtcp);
624 ~DataChannel();
skvlad6c87a672016-05-17 17:49:52 -0700625 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000627 virtual bool SendData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700628 const rtc::CopyOnWriteBuffer& payload,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000629 SendDataResult* result);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630
631 void StartMediaMonitor(int cms);
632 void StopMediaMonitor();
633
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000634 // Should be called on the signaling thread only.
635 bool ready_to_send_data() const {
636 return ready_to_send_data_;
637 }
638
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor;
640 sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&>
641 SignalConnectionMonitor;
jbaucheec21bd2016-03-20 06:15:43 -0700642 sigslot::signal3<DataChannel*, const ReceiveDataParams&,
643 const rtc::CopyOnWriteBuffer&> SignalDataReceived;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644 // Signal for notifying when the channel becomes ready to send data.
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000645 // That occurs when the channel is enabled, the transport is writable,
646 // both local and remote descriptions are set, and the channel is unblocked.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647 sigslot::signal1<bool> SignalReadyToSendData;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +0000648 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200649 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
zhihuang184a3fd2016-06-14 11:47:14 -0700650 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000652 protected:
653 // downcasts a MediaChannel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200654 DataMediaChannel* media_channel() const override {
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000655 return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
656 }
657
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000659 struct SendDataMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660 SendDataMessageData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700661 const rtc::CopyOnWriteBuffer* payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000662 SendDataResult* result)
663 : params(params),
664 payload(payload),
665 result(result),
666 succeeded(false) {
667 }
668
669 const SendDataParams& params;
jbaucheec21bd2016-03-20 06:15:43 -0700670 const rtc::CopyOnWriteBuffer* payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671 SendDataResult* result;
672 bool succeeded;
673 };
674
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000675 struct DataReceivedMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676 // We copy the data because the data will become invalid after we
677 // handle DataMediaChannel::SignalDataReceived but before we fire
678 // SignalDataReceived.
679 DataReceivedMessageData(
680 const ReceiveDataParams& params, const char* data, size_t len)
681 : params(params),
682 payload(data, len) {
683 }
684 const ReceiveDataParams params;
jbaucheec21bd2016-03-20 06:15:43 -0700685 const rtc::CopyOnWriteBuffer payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 };
687
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000688 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000689
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 // overrides from BaseChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200691 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that
693 // it's the same as what was set previously. Returns false if it's
694 // set to one type one type and changed to another type later.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000695 bool SetDataChannelType(DataChannelType new_data_channel_type,
696 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 // Same as SetDataChannelType, but extracts the type from the
698 // DataContentDescription.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000699 bool SetDataChannelTypeFromContent(const DataContentDescription* content,
700 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200701 bool SetLocalContent_w(const MediaContentDescription* content,
702 ContentAction action,
703 std::string* error_desc) override;
704 bool SetRemoteContent_w(const MediaContentDescription* content,
705 ContentAction action,
706 std::string* error_desc) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700707 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200708 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200710 void OnMessage(rtc::Message* pmsg) override;
711 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
712 void OnConnectionMonitorUpdate(
713 ConnectionMonitor* monitor,
714 const std::vector<ConnectionInfo>& infos) override;
715 void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
716 const DataMediaInfo& info);
717 bool ShouldSetupDtlsSrtp_n() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 void OnDataReceived(
719 const ReceiveDataParams& params, const char* data, size_t len);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200720 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000721 void OnDataChannelReadyToSend(bool writable);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200722 void OnStreamClosedRemotely(uint32_t sid);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723
kwiberg31022942016-03-11 14:18:21 -0800724 std::unique_ptr<DataMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 // TODO(pthatcher): Make a separate SctpDataChannel and
726 // RtpDataChannel instead of using this.
727 DataChannelType data_channel_type_;
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000728 bool ready_to_send_data_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700729
730 // Last DataSendParameters sent down to the media_channel() via
731 // SetSendParameters.
732 DataSendParameters last_send_params_;
733 // Last DataRecvParameters sent down to the media_channel() via
734 // SetRecvParameters.
735 DataRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736};
737
738} // namespace cricket
739
perkjc11b1842016-03-07 17:34:13 -0800740#endif // WEBRTC_PC_CHANNEL_H_