blob: c7749a97156e2165a18a22d8217d199b28d580b9 [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,
zhihuangf5b251b2017-01-12 19:37:48 -080083 rtc::Thread* signaling_thread,
deadbeefcbecd352015-09-23 11:50:27 -070084 MediaChannel* channel,
deadbeefcbecd352015-09-23 11:50:27 -070085 const std::string& content_name,
deadbeefac22f702017-01-12 21:59:29 -080086 bool rtcp_mux_required,
deadbeef7af91dd2016-12-13 11:29:11 -080087 bool srtp_required);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 virtual ~BaseChannel();
zhihuangf5b251b2017-01-12 19:37:48 -080089 bool Init_w(TransportChannel* rtp_transport,
90 TransportChannel* rtcp_transport);
Danil Chapovalov33b01f22016-05-11 19:55:27 +020091 // Deinit may be called multiple times and is simply ignored if it's already
wu@webrtc.org78187522013-10-07 23:32:02 +000092 // done.
93 void Deinit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000095 rtc::Thread* worker_thread() const { return worker_thread_; }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020096 rtc::Thread* network_thread() const { return network_thread_; }
deadbeefcbecd352015-09-23 11:50:27 -070097 const std::string& content_name() const { return content_name_; }
98 const std::string& transport_name() const { return transport_name_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 bool enabled() const { return enabled_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101 // This function returns true if we are using SRTP.
102 bool secure() const { return srtp_filter_.IsActive(); }
103 // The following function returns true if we are using
104 // DTLS-based keying. If you turned off SRTP later, however
105 // you could have secure() == false and dtls_secure() == true.
106 bool secure_dtls() const { return dtls_keyed_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
108 bool writable() const { return writable_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
zhihuangf5b251b2017-01-12 19:37:48 -0800110 bool SetTransport(TransportChannel* rtp_transport,
111 TransportChannel* rtcp_transport);
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +0000112 bool PushdownLocalDescription(const SessionDescription* local_desc,
113 ContentAction action,
114 std::string* error_desc);
115 bool PushdownRemoteDescription(const SessionDescription* remote_desc,
116 ContentAction action,
117 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118 // Channel control
119 bool SetLocalContent(const MediaContentDescription* content,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000120 ContentAction action,
121 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122 bool SetRemoteContent(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
126 bool Enable(bool enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
128 // Multiplexing
129 bool AddRecvStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200130 bool RemoveRecvStream(uint32_t ssrc);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000131 bool AddSendStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200132 bool RemoveSendStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133
134 // Monitoring
135 void StartConnectionMonitor(int cms);
136 void StopConnectionMonitor();
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000137 // For ConnectionStatsGetter, used by ConnectionMonitor
deadbeefcbecd352015-09-23 11:50:27 -0700138 bool GetConnectionStats(ConnectionInfos* infos) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000140 BundleFilter* bundle_filter() { return &bundle_filter_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141
142 const std::vector<StreamParams>& local_streams() const {
143 return local_streams_;
144 }
145 const std::vector<StreamParams>& remote_streams() const {
146 return remote_streams_;
147 }
148
deadbeef953c2ce2017-01-09 14:53:41 -0800149 sigslot::signal2<BaseChannel*, bool> SignalDtlsSrtpSetupFailure;
150 void SignalDtlsSrtpSetupFailure_n(bool rtcp);
151 void SignalDtlsSrtpSetupFailure_s(bool rtcp);
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000152
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +0000153 // Used for latency measurements.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
155
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200156 // Forward TransportChannel SignalSentPacket to worker thread.
157 sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
158
deadbeefac22f702017-01-12 21:59:29 -0800159 // Emitted whenever rtcp-mux is fully negotiated and the rtcp-transport can
160 // be destroyed.
161 // Fired on the network thread.
162 sigslot::signal1<const std::string&> SignalRtcpMuxFullyActive;
zhihuangf5b251b2017-01-12 19:37:48 -0800163
164 TransportChannel* rtp_transport() const { return rtp_transport_; }
165 TransportChannel* rtcp_transport() const { return rtcp_transport_; }
166
167 bool NeedsRtcpTransport();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200168
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 // Made public for easier testing.
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700170 //
171 // Updates "ready to send" for an individual channel, and informs the media
172 // channel that the transport is ready to send if each channel (in use) is
173 // ready to send. This is more specific than just "writable"; it means the
174 // last send didn't return ENOTCONN.
175 //
176 // This should be called whenever a channel's ready-to-send state changes,
177 // or when RTCP muxing becomes active/inactive.
178 void SetTransportChannelReadyToSend(bool rtcp, bool ready);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000180 // Only public for unit tests. Otherwise, consider protected.
rlesterec9d1872015-10-27 14:22:16 -0700181 int SetOption(SocketType type, rtc::Socket::Option o, int val)
182 override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200183 int SetOption_n(SocketType type, rtc::Socket::Option o, int val);
guoweis@webrtc.org4f852882015-03-12 20:09:44 +0000184
solenberg5b14b422015-10-01 04:10:31 -0700185 SrtpFilter* srtp_filter() { return &srtp_filter_; }
186
zhihuang184a3fd2016-06-14 11:47:14 -0700187 virtual cricket::MediaType media_type() = 0;
188
jbauchcb560652016-08-04 05:20:32 -0700189 bool SetCryptoOptions(const rtc::CryptoOptions& crypto_options);
190
deadbeef7af91dd2016-12-13 11:29:11 -0800191 // This function returns true if we require SRTP for call setup.
192 bool srtp_required_for_testing() const { return srtp_required_; }
193
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 protected:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 virtual MediaChannel* media_channel() const { return media_channel_; }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700196
zhihuangf5b251b2017-01-12 19:37:48 -0800197 // Sets the |rtp_transport_| (and |rtcp_transport_|, if
198 // |rtcp_enabled_| is true).
deadbeef062ce9f2016-08-26 21:42:15 -0700199 // This method also updates writability and "ready-to-send" state.
zhihuangf5b251b2017-01-12 19:37:48 -0800200 bool SetTransport_n(TransportChannel* rtp_transport,
201 TransportChannel* rtcp_transport);
guoweis46383312015-12-17 16:45:59 -0800202
deadbeef062ce9f2016-08-26 21:42:15 -0700203 // This does not update writability or "ready-to-send" state; it just
204 // disconnects from the old channel and connects to the new one.
zhihuangf5b251b2017-01-12 19:37:48 -0800205 void SetTransportChannel_n(bool rtcp, TransportChannel* new_transport);
guoweis46383312015-12-17 16:45:59 -0800206
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 bool was_ever_writable() const { return was_ever_writable_; }
208 void set_local_content_direction(MediaContentDirection direction) {
209 local_content_direction_ = direction;
210 }
211 void set_remote_content_direction(MediaContentDirection direction) {
212 remote_content_direction_ = direction;
213 }
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700214 // These methods verify that:
215 // * The required content description directions have been set.
216 // * The channel is enabled.
217 // * And for sending:
218 // - The SRTP filter is active if it's needed.
219 // - The transport has been writable before, meaning it should be at least
220 // possible to succeed in sending a packet.
221 //
222 // When any of these properties change, UpdateMediaSendRecvState_w should be
223 // called.
224 bool IsReadyToReceiveMedia_w() const;
225 bool IsReadyToSendMedia_w() const;
zhihuangf5b251b2017-01-12 19:37:48 -0800226 rtc::Thread* signaling_thread() { return signaling_thread_; }
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
deadbeef953c2ce2017-01-09 14:53:41 -0800263 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
jbaucheec21bd2016-03-20 06:15:43 -0700264 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);
deadbeef953c2ce2017-01-09 14:53:41 -0800284 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 bool SetRtcpMux_n(bool enable,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000335 ContentAction action,
336 ContentSource src,
337 std::string* error_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338
339 // From MessageHandler
rlesterec9d1872015-10-27 14:22:16 -0700340 void OnMessage(rtc::Message* pmsg) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341
jbauchcb560652016-08-04 05:20:32 -0700342 const rtc::CryptoOptions& crypto_options() const {
343 return crypto_options_;
344 }
345
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 // Handled in derived classes
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800347 // Get the SRTP crypto suites to use for RTP media
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200348 virtual void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const = 0;
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +0000349 virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 const std::vector<ConnectionInfo>& infos) = 0;
351
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000352 // Helper function for invoking bool-returning methods on the worker thread.
353 template <class FunctorT>
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700354 bool InvokeOnWorker(const rtc::Location& posted_from,
355 const FunctorT& functor) {
356 return worker_thread_->Invoke<bool>(posted_from, functor);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000357 }
358
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 private:
zhihuangf5b251b2017-01-12 19:37:48 -0800360 bool InitNetwork_n(TransportChannel* rtp_transport,
361 TransportChannel* rtcp_transport);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +0200362 void DisconnectTransportChannels_n();
johand89ab142016-10-25 10:50:32 -0700363 void SignalSentPacket_n(rtc::PacketTransportInterface* transport,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200364 const rtc::SentPacket& sent_packet);
365 void SignalSentPacket_w(const rtc::SentPacket& sent_packet);
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700366 bool IsReadyToSendMedia_n() const;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200367 void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id);
michaelt79e05882016-11-08 02:50:09 -0800368 int GetTransportOverheadPerPacket() const;
369 void UpdateTransportOverhead();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200370
371 rtc::Thread* const worker_thread_;
372 rtc::Thread* const network_thread_;
zhihuangf5b251b2017-01-12 19:37:48 -0800373 rtc::Thread* const signaling_thread_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200374 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
deadbeefcbecd352015-09-23 11:50:27 -0700379 std::string transport_name_;
deadbeefac22f702017-01-12 21:59:29 -0800380 // True if RTCP-multiplexing is required. In other words, no standalone RTCP
381 // transport will ever be used for this channel.
382 const bool rtcp_mux_required_;
johand89ab142016-10-25 10:50:32 -0700383 // TODO(johan): Replace TransportChannel* with rtc::PacketTransportInterface*.
zhihuangf5b251b2017-01-12 19:37:48 -0800384 TransportChannel* rtp_transport_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700385 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_;
zhihuangf5b251b2017-01-12 19:37:48 -0800386 TransportChannel* rtcp_transport_ = nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700387 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 SrtpFilter srtp_filter_;
389 RtcpMuxFilter rtcp_mux_filter_;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000390 BundleFilter bundle_filter_;
deadbeef23d947d2016-08-22 16:00:30 -0700391 bool rtp_ready_to_send_ = false;
392 bool rtcp_ready_to_send_ = false;
393 bool writable_ = false;
394 bool was_ever_writable_ = false;
395 bool has_received_packet_ = false;
396 bool dtls_keyed_ = false;
deadbeef7af91dd2016-12-13 11:29:11 -0800397 const bool srtp_required_ = true;
jbauchcb560652016-08-04 05:20:32 -0700398 rtc::CryptoOptions crypto_options_;
deadbeef23d947d2016-08-22 16:00:30 -0700399 int rtp_abs_sendtime_extn_id_ = -1;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200400
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700401 // MediaChannel related members that should be accessed from the worker
402 // thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200403 MediaChannel* const media_channel_;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700404 // Currently the |enabled_| flag is accessed from the signaling thread as
405 // well, but it can be changed only when signaling thread does a synchronous
406 // call to the worker thread, so it should be safe.
deadbeef23d947d2016-08-22 16:00:30 -0700407 bool enabled_ = false;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200408 std::vector<StreamParams> local_streams_;
409 std::vector<StreamParams> remote_streams_;
deadbeef23d947d2016-08-22 16:00:30 -0700410 MediaContentDirection local_content_direction_ = MD_INACTIVE;
411 MediaContentDirection remote_content_direction_ = MD_INACTIVE;
michaelt79e05882016-11-08 02:50:09 -0800412 CandidatePairInterface* selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413};
414
415// VoiceChannel is a specialization that adds support for early media, DTMF,
416// and input/output level monitoring.
417class VoiceChannel : public BaseChannel {
418 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200419 VoiceChannel(rtc::Thread* worker_thread,
420 rtc::Thread* network_thread,
zhihuangf5b251b2017-01-12 19:37:48 -0800421 rtc::Thread* signaling_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700422 MediaEngineInterface* media_engine,
423 VoiceMediaChannel* channel,
deadbeefcbecd352015-09-23 11:50:27 -0700424 const std::string& content_name,
deadbeefac22f702017-01-12 21:59:29 -0800425 bool rtcp_mux_required,
deadbeef7af91dd2016-12-13 11:29:11 -0800426 bool srtp_required);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 ~VoiceChannel();
zhihuangf5b251b2017-01-12 19:37:48 -0800428 bool Init_w(TransportChannel* rtp_transport,
429 TransportChannel* rtcp_transport);
solenberg1dd98f32015-09-10 01:57:14 -0700430
431 // Configure sending media on the stream with SSRC |ssrc|
432 // If there is only one sending stream SSRC 0 can be used.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200433 bool SetAudioSend(uint32_t ssrc,
solenbergdfc8f4f2015-10-01 02:31:10 -0700434 bool enable,
deadbeefcbecd352015-09-23 11:50:27 -0700435 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800436 AudioSource* source);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437
438 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200439 VoiceMediaChannel* media_channel() const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
441 }
442
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 void SetEarlyMedia(bool enable);
444 // This signal is emitted when we have gone a period of time without
445 // receiving early media. When received, a UI should start playing its
446 // own ringing sound
447 sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout;
448
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 // Returns if the telephone-event has been negotiated.
450 bool CanInsertDtmf();
451 // Send and/or play a DTMF |event| according to the |flags|.
452 // The DTMF out-of-band signal will be used on sending.
453 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000454 // The valid value for the |event| are 0 which corresponding to DTMF
455 // event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800456 bool InsertDtmf(uint32_t ssrc, int event_code, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700457 bool SetOutputVolume(uint32_t ssrc, double volume);
deadbeef2d110be2016-01-13 12:00:26 -0800458 void SetRawAudioSink(uint32_t ssrc,
kwiberg31022942016-03-11 14:18:21 -0800459 std::unique_ptr<webrtc::AudioSinkInterface> sink);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700460 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
461 bool SetRtpSendParameters(uint32_t ssrc,
462 const webrtc::RtpParameters& parameters);
463 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
464 bool SetRtpReceiveParameters(uint32_t ssrc,
465 const webrtc::RtpParameters& parameters);
Tommif888bb52015-12-12 01:37:01 +0100466
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467 // Get statistics about the current media session.
468 bool GetStats(VoiceMediaInfo* stats);
469
470 // Monitoring functions
471 sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&>
472 SignalConnectionMonitor;
473
474 void StartMediaMonitor(int cms);
475 void StopMediaMonitor();
476 sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor;
477
478 void StartAudioMonitor(int cms);
479 void StopAudioMonitor();
480 bool IsAudioMonitorRunning() const;
481 sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor;
482
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 int GetInputLevel_w();
484 int GetOutputLevel_w();
485 void GetActiveStreams_w(AudioInfo::StreamList* actives);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700486 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
487 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
488 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
489 bool SetRtpReceiveParameters_w(uint32_t ssrc,
490 webrtc::RtpParameters parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700491 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_AUDIO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493 private:
494 // overrides from BaseChannel
johand89ab142016-10-25 10:50:32 -0700495 void OnPacketRead(rtc::PacketTransportInterface* transport,
496 const char* data,
497 size_t len,
498 const rtc::PacketTime& packet_time,
499 int flags) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700500 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200501 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
502 bool SetLocalContent_w(const MediaContentDescription* content,
503 ContentAction action,
504 std::string* error_desc) override;
505 bool SetRemoteContent_w(const MediaContentDescription* content,
506 ContentAction action,
507 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000508 void HandleEarlyMediaTimeout();
solenberg1d63dd02015-12-02 12:35:09 -0800509 bool InsertDtmf_w(uint32_t ssrc, int event, int duration);
solenberg4bac9c52015-10-09 02:32:53 -0700510 bool SetOutputVolume_w(uint32_t ssrc, double volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000511 bool GetStats_w(VoiceMediaInfo* stats);
512
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200513 void OnMessage(rtc::Message* pmsg) override;
514 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
515 void OnConnectionMonitorUpdate(
516 ConnectionMonitor* monitor,
517 const std::vector<ConnectionInfo>& infos) override;
518 void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
519 const VoiceMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521
522 static const int kEarlyMediaTimeout = 1000;
Fredrik Solenberg0c022642015-08-05 12:25:22 +0200523 MediaEngineInterface* media_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 bool received_media_;
kwiberg31022942016-03-11 14:18:21 -0800525 std::unique_ptr<VoiceMediaMonitor> media_monitor_;
526 std::unique_ptr<AudioMonitor> audio_monitor_;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700527
528 // Last AudioSendParameters sent down to the media_channel() via
529 // SetSendParameters.
530 AudioSendParameters last_send_params_;
531 // Last AudioRecvParameters sent down to the media_channel() via
532 // SetRecvParameters.
533 AudioRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534};
535
536// VideoChannel is a specialization for video.
537class VideoChannel : public BaseChannel {
538 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200539 VideoChannel(rtc::Thread* worker_thread,
zhihuangf5b251b2017-01-12 19:37:48 -0800540 rtc::Thread* network_thread,
541 rtc::Thread* signaling_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700542 VideoMediaChannel* channel,
deadbeefcbecd352015-09-23 11:50:27 -0700543 const std::string& content_name,
deadbeefac22f702017-01-12 21:59:29 -0800544 bool rtcp_mux_required,
deadbeef7af91dd2016-12-13 11:29:11 -0800545 bool srtp_required);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 ~VideoChannel();
zhihuangf5b251b2017-01-12 19:37:48 -0800547 bool Init_w(TransportChannel* rtp_transport,
548 TransportChannel* rtcp_transport);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200550 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200551 VideoMediaChannel* media_channel() const override {
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200552 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
553 }
554
nisseacd935b2016-11-11 03:55:13 -0800555 bool SetSink(uint32_t ssrc,
556 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 // Get statistics about the current media session.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000558 bool GetStats(VideoMediaInfo* stats);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559
560 sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&>
561 SignalConnectionMonitor;
562
563 void StartMediaMonitor(int cms);
564 void StopMediaMonitor();
565 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566
deadbeef5a4a75a2016-06-02 16:23:38 -0700567 // Register a source and set options.
568 // The |ssrc| must correspond to a registered send stream.
569 bool SetVideoSend(uint32_t ssrc,
570 bool enable,
571 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800572 rtc::VideoSourceInterface<webrtc::VideoFrame>* source);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700573 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const;
574 bool SetRtpSendParameters(uint32_t ssrc,
575 const webrtc::RtpParameters& parameters);
576 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const;
577 bool SetRtpReceiveParameters(uint32_t ssrc,
578 const webrtc::RtpParameters& parameters);
zhihuang184a3fd2016-06-14 11:47:14 -0700579 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 private:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 // overrides from BaseChannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700583 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200584 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
585 bool SetLocalContent_w(const MediaContentDescription* content,
586 ContentAction action,
587 std::string* error_desc) override;
588 bool SetRemoteContent_w(const MediaContentDescription* content,
589 ContentAction action,
590 std::string* error_desc) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 bool GetStats_w(VideoMediaInfo* stats);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700592 webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const;
593 bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
594 webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const;
595 bool SetRtpReceiveParameters_w(uint32_t ssrc,
596 webrtc::RtpParameters parameters);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200598 void OnMessage(rtc::Message* pmsg) override;
599 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
600 void OnConnectionMonitorUpdate(
601 ConnectionMonitor* monitor,
602 const std::vector<ConnectionInfo>& infos) override;
603 void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
604 const VideoMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605
kwiberg31022942016-03-11 14:18:21 -0800606 std::unique_ptr<VideoMediaMonitor> media_monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700608 // Last VideoSendParameters sent down to the media_channel() via
609 // SetSendParameters.
610 VideoSendParameters last_send_params_;
611 // Last VideoRecvParameters sent down to the media_channel() via
612 // SetRecvParameters.
613 VideoRecvParameters last_recv_params_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614};
615
deadbeef953c2ce2017-01-09 14:53:41 -0800616// RtpDataChannel is a specialization for data.
617class RtpDataChannel : public BaseChannel {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 public:
deadbeef953c2ce2017-01-09 14:53:41 -0800619 RtpDataChannel(rtc::Thread* worker_thread,
620 rtc::Thread* network_thread,
zhihuangf5b251b2017-01-12 19:37:48 -0800621 rtc::Thread* signaling_thread,
622 DataMediaChannel* channel,
deadbeef953c2ce2017-01-09 14:53:41 -0800623 const std::string& content_name,
deadbeefac22f702017-01-12 21:59:29 -0800624 bool rtcp_mux_required,
deadbeef953c2ce2017-01-09 14:53:41 -0800625 bool srtp_required);
626 ~RtpDataChannel();
zhihuangf5b251b2017-01-12 19:37:48 -0800627 bool Init_w(TransportChannel* rtp_transport,
628 TransportChannel* rtcp_transport);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000630 virtual bool SendData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700631 const rtc::CopyOnWriteBuffer& payload,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000632 SendDataResult* result);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633
634 void StartMediaMonitor(int cms);
635 void StopMediaMonitor();
636
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000637 // Should be called on the signaling thread only.
638 bool ready_to_send_data() const {
639 return ready_to_send_data_;
640 }
641
deadbeef953c2ce2017-01-09 14:53:41 -0800642 sigslot::signal2<RtpDataChannel*, const DataMediaInfo&> SignalMediaMonitor;
643 sigslot::signal2<RtpDataChannel*, const std::vector<ConnectionInfo>&>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644 SignalConnectionMonitor;
deadbeef953c2ce2017-01-09 14:53:41 -0800645
646 sigslot::signal2<const ReceiveDataParams&, const rtc::CopyOnWriteBuffer&>
647 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;
zhihuang184a3fd2016-06-14 11:47:14 -0700652 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000654 protected:
655 // downcasts a MediaChannel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200656 DataMediaChannel* media_channel() const override {
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000657 return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
658 }
659
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000661 struct SendDataMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000662 SendDataMessageData(const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700663 const rtc::CopyOnWriteBuffer* payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 SendDataResult* result)
665 : params(params),
666 payload(payload),
667 result(result),
668 succeeded(false) {
669 }
670
671 const SendDataParams& params;
jbaucheec21bd2016-03-20 06:15:43 -0700672 const rtc::CopyOnWriteBuffer* payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 SendDataResult* result;
674 bool succeeded;
675 };
676
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000677 struct DataReceivedMessageData : public rtc::MessageData {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678 // We copy the data because the data will become invalid after we
679 // handle DataMediaChannel::SignalDataReceived but before we fire
680 // SignalDataReceived.
681 DataReceivedMessageData(
682 const ReceiveDataParams& params, const char* data, size_t len)
683 : params(params),
684 payload(data, len) {
685 }
686 const ReceiveDataParams params;
jbaucheec21bd2016-03-20 06:15:43 -0700687 const rtc::CopyOnWriteBuffer payload;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688 };
689
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000690 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000691
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 // overrides from BaseChannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200693 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
deadbeef953c2ce2017-01-09 14:53:41 -0800694 // Checks that data channel type is RTP.
695 bool CheckDataChannelTypeFromContent(const DataContentDescription* content,
696 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200697 bool SetLocalContent_w(const MediaContentDescription* content,
698 ContentAction action,
699 std::string* error_desc) override;
700 bool SetRemoteContent_w(const MediaContentDescription* content,
701 ContentAction action,
702 std::string* error_desc) override;
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -0700703 void UpdateMediaSendRecvState_w() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200705 void OnMessage(rtc::Message* pmsg) override;
706 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
707 void OnConnectionMonitorUpdate(
708 ConnectionMonitor* monitor,
709 const std::vector<ConnectionInfo>& infos) override;
710 void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
711 const DataMediaInfo& info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 void OnDataReceived(
713 const ReceiveDataParams& params, const char* data, size_t len);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200714 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000715 void OnDataChannelReadyToSend(bool writable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716
kwiberg31022942016-03-11 14:18:21 -0800717 std::unique_ptr<DataMediaMonitor> media_monitor_;
deadbeef953c2ce2017-01-09 14:53:41 -0800718 bool ready_to_send_data_ = false;
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_