blob: 64c5f8253f7fed52f0f0b0e35125e244f0901e29 [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.
deadbeef7af91dd2016-12-13 11:29:11 -080079 // If |srtp_required| is true, the channel will not send or receive any
80 // RTP/RTCP packets without using SRTP (either using SDES or DTLS-SRTP).
Danil Chapovalov33b01f22016-05-11 19:55:27 +020081 BaseChannel(rtc::Thread* worker_thread,
82 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -070083 MediaChannel* channel,
84 TransportController* transport_controller,
85 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -080086 bool rtcp,
87 bool srtp_required);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 virtual ~BaseChannel();
skvlad6c87a672016-05-17 17:49:52 -070089 bool Init_w(const std::string* bundle_transport_name);
Danil Chapovalov33b01f22016-05-11 19:55:27 +020090 // Deinit may be called multiple times and is simply ignored if it's already
wu@webrtc.org78187522013-10-07 23:32:02 +000091 // done.
92 void Deinit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000094 rtc::Thread* worker_thread() const { return worker_thread_; }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020095 rtc::Thread* network_thread() const { return network_thread_; }
deadbeefcbecd352015-09-23 11:50:27 -070096 const std::string& content_name() const { return content_name_; }
97 const std::string& transport_name() const { return transport_name_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098 bool enabled() const { return enabled_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099
100 // This function returns true if we are using SRTP.
101 bool secure() const { return srtp_filter_.IsActive(); }
102 // The following function returns true if we are using
103 // DTLS-based keying. If you turned off SRTP later, however
104 // you could have secure() == false and dtls_secure() == true.
105 bool secure_dtls() const { return dtls_keyed_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106
107 bool writable() const { return writable_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700109 // Activate RTCP mux, regardless of the state so far. Once
110 // activated, it can not be deactivated, and if the remote
111 // description doesn't support RTCP mux, setting the remote
112 // description will fail.
113 void ActivateRtcpMux();
deadbeefcbecd352015-09-23 11:50:27 -0700114 bool SetTransport(const std::string& transport_name);
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +0000115 bool PushdownLocalDescription(const SessionDescription* local_desc,
116 ContentAction action,
117 std::string* error_desc);
118 bool PushdownRemoteDescription(const SessionDescription* remote_desc,
119 ContentAction action,
120 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 // Channel control
122 bool SetLocalContent(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000123 ContentAction action,
124 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 bool SetRemoteContent(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000126 ContentAction action,
127 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128
129 bool Enable(bool enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130
131 // Multiplexing
132 bool AddRecvStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200133 bool RemoveRecvStream(uint32_t ssrc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000134 bool AddSendStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200135 bool RemoveSendStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136
137 // Monitoring
138 void StartConnectionMonitor(int cms);
139 void StopConnectionMonitor();
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000140 // For ConnectionStatsGetter, used by ConnectionMonitor
deadbeefcbecd352015-09-23 11:50:27 -0700141 bool GetConnectionStats(ConnectionInfos* infos) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000143 BundleFilter* bundle_filter() { return &bundle_filter_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144
145 const std::vector<StreamParams>& local_streams() const {
146 return local_streams_;
147 }
148 const std::vector<StreamParams>& remote_streams() const {
149 return remote_streams_;
150 }
151
deadbeefc0dad892017-01-04 20:28:21 -0800152 sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure;
153 void SignalDtlsSetupFailure_n(bool rtcp);
154 void SignalDtlsSetupFailure_s(bool rtcp);
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000155
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +0000156 // Used for latency measurements.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
158
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200159 // Forward TransportChannel SignalSentPacket to worker thread.
160 sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
161
162 // Only public for unit tests. Otherwise, consider private.
163 TransportChannel* transport_channel() const { return transport_channel_; }
164 TransportChannel* rtcp_transport_channel() const {
165 return rtcp_transport_channel_;
166 }
167
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 // Made public for easier testing.
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700169 //
170 // Updates "ready to send" for an individual channel, and informs the media
171 // channel that the transport is ready to send if each channel (in use) is
172 // ready to send. This is more specific than just "writable"; it means the
173 // last send didn't return ENOTCONN.
174 //
175 // This should be called whenever a channel's ready-to-send state changes,
176 // or when RTCP muxing becomes active/inactive.
177 void SetTransportChannelReadyToSend(bool rtcp, bool ready);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000179 // Only public for unit tests. Otherwise, consider protected.
rlesterec9d1872015-10-27 14:22:16 -0700180 int SetOption(SocketType type, rtc::Socket::Option o, int val)
181 override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200182 int SetOption_n(SocketType type, rtc::Socket::Option o, int val);
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000183
solenberg5b14b422015-10-01 04:10:31 -0700184 SrtpFilter* srtp_filter() { return &srtp_filter_; }
185
zhihuang184a3fd2016-06-14 11:47:14 -0700186 virtual cricket::MediaType media_type() = 0;
187
jbauchcb560652016-08-04 05:20:32 -0700188 bool SetCryptoOptions(const rtc::CryptoOptions& crypto_options);
189
deadbeef7af91dd2016-12-13 11:29:11 -0800190 // This function returns true if we require SRTP for call setup.
191 bool srtp_required_for_testing() const { return srtp_required_; }
192
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 protected:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 virtual MediaChannel* media_channel() const { return media_channel_; }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700195
196 // Sets the |transport_channel_| (and |rtcp_transport_channel_|, if
197 // |rtcp_enabled_| is true). Gets the transport channels from
198 // |transport_controller_|.
deadbeef062ce9f2016-08-26 21:42:15 -0700199 // This method also updates writability and "ready-to-send" state.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200200 bool SetTransport_n(const std::string& transport_name);
guoweis46383312015-12-17 16:45:59 -0800201
deadbeef062ce9f2016-08-26 21:42:15 -0700202 // This does not update writability or "ready-to-send" state; it just
203 // disconnects from the old channel and connects to the new one.
204 void SetTransportChannel_n(bool rtcp, TransportChannel* new_channel);
guoweis46383312015-12-17 16:45:59 -0800205
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 bool was_ever_writable() const { return was_ever_writable_; }
207 void set_local_content_direction(MediaContentDirection direction) {
208 local_content_direction_ = direction;
209 }
210 void set_remote_content_direction(MediaContentDirection direction) {
211 remote_content_direction_ = direction;
212 }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700213 // These methods verify that:
214 // * The required content description directions have been set.
215 // * The channel is enabled.
216 // * And for sending:
217 // - The SRTP filter is active if it's needed.
218 // - The transport has been writable before, meaning it should be at least
219 // possible to succeed in sending a packet.
220 //
221 // When any of these properties change, UpdateMediaSendRecvState_w should be
222 // called.
223 bool IsReadyToReceiveMedia_w() const;
224 bool IsReadyToSendMedia_w() const;
deadbeefcbecd352015-09-23 11:50:27 -0700225 rtc::Thread* signaling_thread() {
226 return transport_controller_->signaling_thread();
227 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228
pthatcher@webrtc.org6ad507a2015-03-16 20:19:12 +0000229 void ConnectToTransportChannel(TransportChannel* tc);
230 void DisconnectFromTransportChannel(TransportChannel* tc);
231
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200232 void FlushRtcpMessages_n();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233
234 // NetworkInterface implementation, called by MediaEngine
jbaucheec21bd2016-03-20 06:15:43 -0700235 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
236 const rtc::PacketOptions& options) override;
237 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
238 const rtc::PacketOptions& options) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
240 // From TransportChannel
johand89ab142016-10-25 10:50:32 -0700241 void OnWritableState(rtc::PacketTransportInterface* transport);
242 virtual void OnPacketRead(rtc::PacketTransportInterface* transport,
243 const char* data,
244 size_t len,
245 const rtc::PacketTime& packet_time,
246 int flags);
247 void OnReadyToSend(rtc::PacketTransportInterface* transport);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248
Guo-wei Shieh1218d7a2015-12-05 09:59:56 -0800249 void OnDtlsState(TransportChannel* channel, DtlsTransportState state);
250
Honghai Zhangcc411c02016-03-29 17:27:21 -0700251 void OnSelectedCandidatePairChanged(
252 TransportChannel* channel,
Honghai Zhang52dce732016-03-31 12:37:31 -0700253 CandidatePairInterface* selected_candidate_pair,
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700254 int last_sent_packet_id,
255 bool ready_to_send);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700256
johand89ab142016-10-25 10:50:32 -0700257 bool PacketIsRtcp(const rtc::PacketTransportInterface* transport,
258 const char* data,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 size_t len);
stefanc1aeaf02015-10-15 07:26:07 -0700260 bool SendPacket(bool rtcp,
jbaucheec21bd2016-03-20 06:15:43 -0700261 rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700262 const rtc::PacketOptions& options);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200263
deadbeefc0dad892017-01-04 20:28:21 -0800264 virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
jbaucheec21bd2016-03-20 06:15:43 -0700265 void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000266 const rtc::PacketTime& packet_time);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200267 void OnPacketReceived(bool rtcp,
268 const rtc::CopyOnWriteBuffer& packet,
269 const rtc::PacketTime& packet_time);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 void EnableMedia_w();
272 void DisableMedia_w();
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700273
274 // Performs actions if the RTP/RTCP writable state changed. This should
275 // be called whenever a channel's writable state changes or when RTCP muxing
276 // becomes active/inactive.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200277 void UpdateWritableState_n();
278 void ChannelWritable_n();
279 void ChannelNotWritable_n();
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700280
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 bool AddRecvStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200282 bool RemoveRecvStream_w(uint32_t ssrc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000283 bool AddSendStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200284 bool RemoveSendStream_w(uint32_t ssrc);
deadbeefc0dad892017-01-04 20:28:21 -0800285 virtual bool ShouldSetupDtlsSrtp_n() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters.
287 // |rtcp_channel| indicates whether to set up the RTP or RTCP filter.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200288 bool SetupDtlsSrtp_n(bool rtcp_channel);
289 void MaybeSetupDtlsSrtp_n();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 // Set the DTLS-SRTP cipher policy on this channel as appropriate.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200291 bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700293 // Should be called whenever the conditions for
294 // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied).
295 // Updates the send/recv state of the media channel.
296 void UpdateMediaSendRecvState();
297 virtual void UpdateMediaSendRecvState_w() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298
299 // Gets the content info appropriate to the channel (audio or video).
300 virtual const ContentInfo* GetFirstContent(
301 const SessionDescription* sdesc) = 0;
302 bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000303 ContentAction action,
304 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000306 ContentAction action,
307 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 virtual bool SetLocalContent_w(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000309 ContentAction action,
310 std::string* error_desc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000312 ContentAction action,
313 std::string* error_desc) = 0;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200314 bool SetRtpTransportParameters(const MediaContentDescription* content,
315 ContentAction action,
316 ContentSource src,
317 std::string* error_desc);
318 bool SetRtpTransportParameters_n(const MediaContentDescription* content,
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700319 ContentAction action,
320 ContentSource src,
321 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322
henrike@webrtc.orgd43aa9d2014-02-21 23:43:24 +0000323 // Helper method to get RTP Absoulute SendTime extension header id if
324 // present in remote supported extensions list.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200325 void MaybeCacheRtpAbsSendTimeHeaderExtension_w(
isheriff6f8d6862016-05-26 11:24:55 -0700326 const std::vector<webrtc::RtpExtension>& extensions);
henrike@webrtc.orgd43aa9d2014-02-21 23:43:24 +0000327
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200328 bool CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
329 bool* dtls,
330 std::string* error_desc);
331 bool SetSrtp_n(const std::vector<CryptoParams>& params,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000332 ContentAction action,
333 ContentSource src,
334 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200335 void ActivateRtcpMux_n();
336 bool SetRtcpMux_n(bool enable,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000337 ContentAction action,
338 ContentSource src,
339 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340
341 // From MessageHandler
rlesterec9d1872015-10-27 14:22:16 -0700342 void OnMessage(rtc::Message* pmsg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343
jbauchcb560652016-08-04 05:20:32 -0700344 const rtc::CryptoOptions& crypto_options() const {
345 return crypto_options_;
346 }
347
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 // Handled in derived classes
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800349 // Get the SRTP crypto suites to use for RTP media
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200350 virtual void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const = 0;
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000351 virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 const std::vector<ConnectionInfo>& infos) = 0;
353
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000354 // Helper function for invoking bool-returning methods on the worker thread.
355 template <class FunctorT>
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700356 bool InvokeOnWorker(const rtc::Location& posted_from,
357 const FunctorT& functor) {
358 return worker_thread_->Invoke<bool>(posted_from, functor);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000359 }
360
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 private:
skvlad6c87a672016-05-17 17:49:52 -0700362 bool InitNetwork_n(const std::string* bundle_transport_name);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +0200363 void DisconnectTransportChannels_n();
364 void DestroyTransportChannels_n();
johand89ab142016-10-25 10:50:32 -0700365 void SignalSentPacket_n(rtc::PacketTransportInterface* transport,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200366 const rtc::SentPacket& sent_packet);
367 void SignalSentPacket_w(const rtc::SentPacket& sent_packet);
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700368 bool IsReadyToSendMedia_n() const;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200369 void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id);
michaelt79e05882016-11-08 02:50:09 -0800370 int GetTransportOverheadPerPacket() const;
371 void UpdateTransportOverhead();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200372
373 rtc::Thread* const worker_thread_;
374 rtc::Thread* const network_thread_;
375 rtc::AsyncInvoker invoker_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376
pthatcher@webrtc.org990a00c2015-03-13 18:20:33 +0000377 const std::string content_name_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200378 std::unique_ptr<ConnectionMonitor> connection_monitor_;
379
380 // Transport related members that should be accessed from network thread.
381 TransportController* const transport_controller_;
deadbeefcbecd352015-09-23 11:50:27 -0700382 std::string transport_name_;
deadbeef23d947d2016-08-22 16:00:30 -0700383 // Is RTCP used at all by this type of channel?
384 // Expected to be true (as of typing this) for everything except data
385 // channels.
386 const bool rtcp_enabled_;
johand89ab142016-10-25 10:50:32 -0700387 // TODO(johan): Replace TransportChannel* with rtc::PacketTransportInterface*.
deadbeef23d947d2016-08-22 16:00:30 -0700388 TransportChannel* transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700389 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700390 TransportChannel* rtcp_transport_channel_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700391 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 SrtpFilter srtp_filter_;
393 RtcpMuxFilter rtcp_mux_filter_;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000394 BundleFilter bundle_filter_;
deadbeef23d947d2016-08-22 16:00:30 -0700395 bool rtp_ready_to_send_ = false;
396 bool rtcp_ready_to_send_ = false;
397 bool writable_ = false;
398 bool was_ever_writable_ = false;
399 bool has_received_packet_ = false;
400 bool dtls_keyed_ = false;
deadbeef7af91dd2016-12-13 11:29:11 -0800401 const bool srtp_required_ = true;
jbauchcb560652016-08-04 05:20:32 -0700402 rtc::CryptoOptions crypto_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700403 int rtp_abs_sendtime_extn_id_ = -1;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200404
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700405 // MediaChannel related members that should be accessed from the worker
406 // thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200407 MediaChannel* const media_channel_;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700408 // Currently the |enabled_| flag is accessed from the signaling thread as
409 // well, but it can be changed only when signaling thread does a synchronous
410 // call to the worker thread, so it should be safe.
deadbeef23d947d2016-08-22 16:00:30 -0700411 bool enabled_ = false;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200412 std::vector<StreamParams> local_streams_;
413 std::vector<StreamParams> remote_streams_;
deadbeef23d947d2016-08-22 16:00:30 -0700414 MediaContentDirection local_content_direction_ = MD_INACTIVE;
415 MediaContentDirection remote_content_direction_ = MD_INACTIVE;
michaelt79e05882016-11-08 02:50:09 -0800416 CandidatePairInterface* selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417};
418
419// VoiceChannel is a specialization that adds support for early media, DTMF,
420// and input/output level monitoring.
421class VoiceChannel : public BaseChannel {
422 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200423 VoiceChannel(rtc::Thread* worker_thread,
424 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700425 MediaEngineInterface* media_engine,
426 VoiceMediaChannel* channel,
427 TransportController* transport_controller,
428 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800429 bool rtcp,
430 bool srtp_required);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 ~VoiceChannel();
skvlad6c87a672016-05-17 17:49:52 -0700432 bool Init_w(const std::string* bundle_transport_name);
solenberg1dd98f32015-09-10 01:57:14 -0700433
434 // Configure sending media on the stream with SSRC |ssrc|
435 // If there is only one sending stream SSRC 0 can be used.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200436 bool SetAudioSend(uint32_t ssrc,
solenbergdfc8f4f2015-10-01 02:31:10 -0700437 bool enable,
deadbeefcbecd352015-09-23 11:50:27 -0700438 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800439 AudioSource* source);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440
441 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200442 VoiceMediaChannel* media_channel() const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
444 }
445
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 void SetEarlyMedia(bool enable);
447 // This signal is emitted when we have gone a period of time without
448 // receiving early media. When received, a UI should start playing its
449 // own ringing sound
450 sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout;
451
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 // Returns if the telephone-event has been negotiated.
453 bool CanInsertDtmf();
454 // Send and/or play a DTMF |event| according to the |flags|.
455 // The DTMF out-of-band signal will be used on sending.
456 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000457 // The valid value for the |event| are 0 which corresponding to DTMF
458 // event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800459 bool InsertDtmf(uint32_t ssrc, int event_code, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700460 bool SetOutputVolume(uint32_t ssrc, double volume);
deadbeef2d110be2016-01-13 12:00:26 -0800461 void SetRawAudioSink(uint32_t ssrc,
kwiberg31022942016-03-11 14:18:21 -0800462 std::unique_ptr<webrtc::AudioSinkInterface> sink);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700463 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
464 bool SetRtpSendParameters(uint32_t ssrc,
465 const webrtc::RtpParameters& parameters);
466 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
467 bool SetRtpReceiveParameters(uint32_t ssrc,
468 const webrtc::RtpParameters& parameters);
Tommif888bb52015-12-12 01:37:01 +0100469
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 // Get statistics about the current media session.
471 bool GetStats(VoiceMediaInfo* stats);
472
473 // Monitoring functions
474 sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&>
475 SignalConnectionMonitor;
476
477 void StartMediaMonitor(int cms);
478 void StopMediaMonitor();
479 sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor;
480
481 void StartAudioMonitor(int cms);
482 void StopAudioMonitor();
483 bool IsAudioMonitorRunning() const;
484 sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor;
485
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486 int GetInputLevel_w();
487 int GetOutputLevel_w();
488 void GetActiveStreams_w(AudioInfo::StreamList* actives);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700489 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
490 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
491 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
492 bool SetRtpReceiveParameters_w(uint32_t ssrc,
493 webrtc::RtpParameters parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700494 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_AUDIO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496 private:
497 // overrides from BaseChannel
johand89ab142016-10-25 10:50:32 -0700498 void OnPacketRead(rtc::PacketTransportInterface* transport,
499 const char* data,
500 size_t len,
501 const rtc::PacketTime& packet_time,
502 int flags) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700503 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200504 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
505 bool SetLocalContent_w(const MediaContentDescription* content,
506 ContentAction action,
507 std::string* error_desc) override;
508 bool SetRemoteContent_w(const MediaContentDescription* content,
509 ContentAction action,
510 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000511 void HandleEarlyMediaTimeout();
solenberg1d63dd02015-12-02 12:35:09 -0800512 bool InsertDtmf_w(uint32_t ssrc, int event, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700513 bool SetOutputVolume_w(uint32_t ssrc, double volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 bool GetStats_w(VoiceMediaInfo* stats);
515
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200516 void OnMessage(rtc::Message* pmsg) override;
517 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
518 void OnConnectionMonitorUpdate(
519 ConnectionMonitor* monitor,
520 const std::vector<ConnectionInfo>& infos) override;
521 void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
522 const VoiceMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523 void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524
525 static const int kEarlyMediaTimeout = 1000;
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200526 MediaEngineInterface* media_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527 bool received_media_;
kwiberg31022942016-03-11 14:18:21 -0800528 std::unique_ptr<VoiceMediaMonitor> media_monitor_;
529 std::unique_ptr<AudioMonitor> audio_monitor_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700530
531 // Last AudioSendParameters sent down to the media_channel() via
532 // SetSendParameters.
533 AudioSendParameters last_send_params_;
534 // Last AudioRecvParameters sent down to the media_channel() via
535 // SetRecvParameters.
536 AudioRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537};
538
539// VideoChannel is a specialization for video.
540class VideoChannel : public BaseChannel {
541 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200542 VideoChannel(rtc::Thread* worker_thread,
543 rtc::Thread* netwokr_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700544 VideoMediaChannel* channel,
545 TransportController* transport_controller,
546 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800547 bool rtcp,
548 bool srtp_required);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 ~VideoChannel();
skvlad6c87a672016-05-17 17:49:52 -0700550 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200552 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200553 VideoMediaChannel* media_channel() const override {
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200554 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
555 }
556
nisseacd935b2016-11-11 03:55:13 -0800557 bool SetSink(uint32_t ssrc,
558 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 // Get statistics about the current media session.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000560 bool GetStats(VideoMediaInfo* stats);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561
562 sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&>
563 SignalConnectionMonitor;
564
565 void StartMediaMonitor(int cms);
566 void StopMediaMonitor();
567 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568
deadbeef5a4a75a2016-06-02 16:23:38 -0700569 // Register a source and set options.
570 // The |ssrc| must correspond to a registered send stream.
571 bool SetVideoSend(uint32_t ssrc,
572 bool enable,
573 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800574 rtc::VideoSourceInterface<webrtc::VideoFrame>* source);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700575 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
576 bool SetRtpSendParameters(uint32_t ssrc,
577 const webrtc::RtpParameters& parameters);
578 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
579 bool SetRtpReceiveParameters(uint32_t ssrc,
580 const webrtc::RtpParameters& parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700581 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 private:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 // overrides from BaseChannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700585 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200586 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
587 bool SetLocalContent_w(const MediaContentDescription* content,
588 ContentAction action,
589 std::string* error_desc) override;
590 bool SetRemoteContent_w(const MediaContentDescription* content,
591 ContentAction action,
592 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 bool GetStats_w(VideoMediaInfo* stats);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700594 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
595 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
596 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
597 bool SetRtpReceiveParameters_w(uint32_t ssrc,
598 webrtc::RtpParameters parameters);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200600 void OnMessage(rtc::Message* pmsg) override;
601 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
602 void OnConnectionMonitorUpdate(
603 ConnectionMonitor* monitor,
604 const std::vector<ConnectionInfo>& infos) override;
605 void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
606 const VideoMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607
kwiberg31022942016-03-11 14:18:21 -0800608 std::unique_ptr<VideoMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700610 // Last VideoSendParameters sent down to the media_channel() via
611 // SetSendParameters.
612 VideoSendParameters last_send_params_;
613 // Last VideoRecvParameters sent down to the media_channel() via
614 // SetRecvParameters.
615 VideoRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616};
617
deadbeefc0dad892017-01-04 20:28:21 -0800618// DataChannel is a specialization for data.
619class DataChannel : public BaseChannel {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620 public:
deadbeefc0dad892017-01-04 20:28:21 -0800621 DataChannel(rtc::Thread* worker_thread,
622 rtc::Thread* network_thread,
623 DataMediaChannel* media_channel,
624 TransportController* transport_controller,
625 const std::string& content_name,
626 bool rtcp,
627 bool srtp_required);
628 ~DataChannel();
skvlad6c87a672016-05-17 17:49:52 -0700629 bool Init_w(const std::string* bundle_transport_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000631 virtual bool SendData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700632 const rtc::CopyOnWriteBuffer& payload,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000633 SendDataResult* result);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634
635 void StartMediaMonitor(int cms);
636 void StopMediaMonitor();
637
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000638 // Should be called on the signaling thread only.
639 bool ready_to_send_data() const {
640 return ready_to_send_data_;
641 }
642
deadbeefc0dad892017-01-04 20:28:21 -0800643 sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor;
644 sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 SignalConnectionMonitor;
deadbeefc0dad892017-01-04 20:28:21 -0800646 sigslot::signal3<DataChannel*, const ReceiveDataParams&,
647 const rtc::CopyOnWriteBuffer&> SignalDataReceived;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 // Signal for notifying when the channel becomes ready to send data.
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000649 // That occurs when the channel is enabled, the transport is writable,
650 // both local and remote descriptions are set, and the channel is unblocked.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651 sigslot::signal1<bool> SignalReadyToSendData;
deadbeefc0dad892017-01-04 20:28:21 -0800652 // Signal for notifying that the remote side has closed the DataChannel.
653 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
zhihuang184a3fd2016-06-14 11:47:14 -0700654 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000656 protected:
657 // downcasts a MediaChannel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200658 DataMediaChannel* media_channel() const override {
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000659 return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
660 }
661
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000662 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000663 struct SendDataMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 SendDataMessageData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700665 const rtc::CopyOnWriteBuffer* payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 SendDataResult* result)
667 : params(params),
668 payload(payload),
669 result(result),
670 succeeded(false) {
671 }
672
673 const SendDataParams& params;
jbaucheec21bd2016-03-20 06:15:43 -0700674 const rtc::CopyOnWriteBuffer* payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 SendDataResult* result;
676 bool succeeded;
677 };
678
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000679 struct DataReceivedMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 // We copy the data because the data will become invalid after we
681 // handle DataMediaChannel::SignalDataReceived but before we fire
682 // SignalDataReceived.
683 DataReceivedMessageData(
684 const ReceiveDataParams& params, const char* data, size_t len)
685 : params(params),
686 payload(data, len) {
687 }
688 const ReceiveDataParams params;
jbaucheec21bd2016-03-20 06:15:43 -0700689 const rtc::CopyOnWriteBuffer payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 };
691
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000692 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000693
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 // overrides from BaseChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200695 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
deadbeefc0dad892017-01-04 20:28:21 -0800696 // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that
697 // it's the same as what was set previously. Returns false if it's
698 // set to one type one type and changed to another type later.
699 bool SetDataChannelType(DataChannelType new_data_channel_type,
700 std::string* error_desc);
701 // Same as SetDataChannelType, but extracts the type from the
702 // DataContentDescription.
703 bool SetDataChannelTypeFromContent(const DataContentDescription* content,
704 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200705 bool SetLocalContent_w(const MediaContentDescription* content,
706 ContentAction action,
707 std::string* error_desc) override;
708 bool SetRemoteContent_w(const MediaContentDescription* content,
709 ContentAction action,
710 std::string* error_desc) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700711 void UpdateMediaSendRecvState_w() override;
deadbeefc0dad892017-01-04 20:28:21 -0800712 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200714 void OnMessage(rtc::Message* pmsg) override;
715 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
716 void OnConnectionMonitorUpdate(
717 ConnectionMonitor* monitor,
718 const std::vector<ConnectionInfo>& infos) override;
719 void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
720 const DataMediaInfo& info);
deadbeefc0dad892017-01-04 20:28:21 -0800721 bool ShouldSetupDtlsSrtp_n() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 void OnDataReceived(
723 const ReceiveDataParams& params, const char* data, size_t len);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200724 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000725 void OnDataChannelReadyToSend(bool writable);
deadbeefc0dad892017-01-04 20:28:21 -0800726 void OnStreamClosedRemotely(uint32_t sid);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727
kwiberg31022942016-03-11 14:18:21 -0800728 std::unique_ptr<DataMediaMonitor> media_monitor_;
deadbeefc0dad892017-01-04 20:28:21 -0800729 // TODO(pthatcher): Make a separate SctpDataChannel and
730 // RtpDataChannel instead of using this.
731 DataChannelType data_channel_type_;
732 bool ready_to_send_data_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700733
734 // Last DataSendParameters sent down to the media_channel() via
735 // SetSendParameters.
736 DataSendParameters last_send_params_;
737 // Last DataRecvParameters sent down to the media_channel() via
738 // SetRecvParameters.
739 DataRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740};
741
742} // namespace cricket
743
perkjc11b1842016-03-07 17:34:13 -0800744#endif // WEBRTC_PC_CHANNEL_H_