blob: ae68cfca30b21da75e21195c8680d29e8e817b6a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -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
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#ifndef WEBRTC_API_WEBRTCSESSION_H_
12#define WEBRTC_API_WEBRTCSESSION_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <string>
deadbeefcbecd352015-09-23 11:50:27 -070015#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
henrike@webrtc.org28e20752013-07-10 00:45:36 +000017#include "talk/session/media/mediasession.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010018#include "webrtc/api/datachannel.h"
19#include "webrtc/api/dtmfsender.h"
20#include "webrtc/api/mediacontroller.h"
21#include "webrtc/api/mediastreamprovider.h"
22#include "webrtc/api/peerconnectioninterface.h"
23#include "webrtc/api/statstypes.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000024#include "webrtc/base/sigslot.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020025#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000026#include "webrtc/base/thread.h"
kjellandera96e2d72016-02-04 23:52:28 -080027#include "webrtc/media/base/mediachannel.h"
Tommif888bb52015-12-12 01:37:01 +010028#include "webrtc/p2p/base/transportcontroller.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
30namespace cricket {
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +000031
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032class ChannelManager;
33class DataChannel;
34class StatsReport;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035class VideoCapturer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036class VideoChannel;
37class VoiceChannel;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +000038
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039} // namespace cricket
40
41namespace webrtc {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000042
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043class IceRestartAnswerLatch;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000044class JsepIceCandidate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045class MediaStreamSignaling;
wu@webrtc.org91053e72013-08-10 07:18:04 +000046class WebRtcSessionDescriptionFactory;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
henrike@webrtc.org1e09a712013-07-26 19:17:59 +000048extern const char kBundleWithoutRtcpMux[];
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000049extern const char kCreateChannelFailed[];
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050extern const char kInvalidCandidates[];
51extern const char kInvalidSdp[];
52extern const char kMlineMismatch[];
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000053extern const char kPushDownTDFailed[];
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000054extern const char kSdpWithoutDtlsFingerprint[];
55extern const char kSdpWithoutSdesCrypto[];
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000056extern const char kSdpWithoutIceUfragPwd[];
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000057extern const char kSdpWithoutSdesAndDtlsDisabled[];
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058extern const char kSessionError[];
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000059extern const char kSessionErrorDesc[];
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +000060extern const char kDtlsSetupFailureRtp[];
61extern const char kDtlsSetupFailureRtcp[];
deadbeefcbecd352015-09-23 11:50:27 -070062extern const char kEnableBundleFailed[];
63
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000064// Maximum number of received video streams that will be processed by webrtc
65// even if they are not signalled beforehand.
66extern const int kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067
68// ICE state callback interface.
69class IceObserver {
70 public:
wu@webrtc.org364f2042013-11-20 21:49:41 +000071 IceObserver() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 // Called any time the IceConnectionState changes
Peter Thatcher54360512015-07-08 11:08:35 -070073 // TODO(honghaiz): Change the name to OnIceConnectionStateChange so as to
74 // conform to the w3c standard.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 virtual void OnIceConnectionChange(
76 PeerConnectionInterface::IceConnectionState new_state) {}
77 // Called any time the IceGatheringState changes
78 virtual void OnIceGatheringChange(
79 PeerConnectionInterface::IceGatheringState new_state) {}
80 // New Ice candidate have been found.
81 virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082
Peter Thatcher54360512015-07-08 11:08:35 -070083 // Called whenever the state changes between receiving and not receiving.
84 virtual void OnIceConnectionReceivingChange(bool receiving) {}
85
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 protected:
87 ~IceObserver() {}
wu@webrtc.org364f2042013-11-20 21:49:41 +000088
89 private:
henrikg3c089d72015-09-16 05:37:44 -070090 RTC_DISALLOW_COPY_AND_ASSIGN(IceObserver);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091};
92
deadbeefd59daf82015-10-14 15:02:44 -070093// Statistics for all the transports of the session.
94typedef std::map<std::string, cricket::TransportStats> TransportStatsMap;
95typedef std::map<std::string, std::string> ProxyTransportMap;
96
97// TODO(pthatcher): Think of a better name for this. We already have
98// a TransportStats in transport.h. Perhaps TransportsStats?
99struct SessionStats {
100 ProxyTransportMap proxy_to_transport;
101 TransportStatsMap transport_stats;
102};
103
104// A WebRtcSession manages general session state. This includes negotiation
105// of both the application-level and network-level protocols: the former
106// defines what will be sent and the latter defines how it will be sent. Each
107// network-level protocol is represented by a Transport object. Each Transport
108// participates in the network-level negotiation. The individual streams of
109// packets are represented by TransportChannels. The application-level protocol
110// is represented by SessionDecription objects.
111class WebRtcSession : public AudioProviderInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 public VideoProviderInterface,
wu@webrtc.org78187522013-10-07 23:32:02 +0000113 public DtmfProviderInterface,
deadbeefd59daf82015-10-14 15:02:44 -0700114 public DataChannelProviderInterface,
115 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 public:
deadbeefd59daf82015-10-14 15:02:44 -0700117 enum State {
118 STATE_INIT = 0,
119 STATE_SENTOFFER, // Sent offer, waiting for answer.
120 STATE_RECEIVEDOFFER, // Received an offer. Need to send answer.
121 STATE_SENTPRANSWER, // Sent provisional answer. Need to send answer.
122 STATE_RECEIVEDPRANSWER, // Received provisional answer, waiting for answer.
123 STATE_INPROGRESS, // Offer/answer exchange completed.
124 STATE_CLOSED, // Close() was called.
125 };
126
127 enum Error {
128 ERROR_NONE = 0, // no error
129 ERROR_CONTENT = 1, // channel errors in SetLocalContent/SetRemoteContent
130 ERROR_TRANSPORT = 2, // transport error of some kind
131 };
132
stefanc1aeaf02015-10-15 07:26:07 -0700133 WebRtcSession(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000134 rtc::Thread* signaling_thread,
135 rtc::Thread* worker_thread,
deadbeefab9b2d12015-10-14 11:33:11 -0700136 cricket::PortAllocator* port_allocator);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 virtual ~WebRtcSession();
138
deadbeefd59daf82015-10-14 15:02:44 -0700139 // These are const to allow them to be called from const methods.
140 rtc::Thread* signaling_thread() const { return signaling_thread_; }
141 rtc::Thread* worker_thread() const { return worker_thread_; }
142 cricket::PortAllocator* port_allocator() const { return port_allocator_; }
143
144 // The ID of this session.
145 const std::string& id() const { return sid_; }
146
Henrik Lundin64dad832015-05-11 12:44:23 +0200147 bool Initialize(
148 const PeerConnectionFactoryInterface::Options& options,
149 const MediaConstraintsInterface* constraints,
Henrik Boström5e56c592015-08-11 10:33:13 +0200150 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200151 const PeerConnectionInterface::RTCConfiguration& rtc_configuration);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 // Deletes the voice, video and data channel and changes the session state
deadbeefd59daf82015-10-14 15:02:44 -0700153 // to STATE_CLOSED.
154 void Close();
155
156 // Returns true if we were the initial offerer.
157 bool initial_offerer() const { return initial_offerer_; }
158
159 // Returns the current state of the session. See the enum above for details.
160 // Each time the state changes, we will fire this signal.
161 State state() const { return state_; }
162 sigslot::signal2<WebRtcSession*, State> SignalState;
163
164 // Returns the last error in the session. See the enum above for details.
165 Error error() const { return error_; }
166 const std::string& error_desc() const { return error_desc_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167
168 void RegisterIceObserver(IceObserver* observer) {
169 ice_observer_ = observer;
170 }
171
172 virtual cricket::VoiceChannel* voice_channel() {
173 return voice_channel_.get();
174 }
175 virtual cricket::VideoChannel* video_channel() {
176 return video_channel_.get();
177 }
178 virtual cricket::DataChannel* data_channel() {
179 return data_channel_.get();
180 }
181
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000182 void SetSdesPolicy(cricket::SecurePolicy secure_policy);
183 cricket::SecurePolicy SdesPolicy() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000185 // Get current ssl role from transport.
Taylor Brandstetterf475d362016-01-08 15:35:57 -0800186 bool GetSslRole(const std::string& transport_name, rtc::SSLRole* role);
187
188 // Get current SSL role for this channel's transport.
189 // If |transport| is null, returns false.
190 bool GetSslRole(const cricket::BaseChannel* channel, rtc::SSLRole* role);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000191
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000192 void CreateOffer(
193 CreateSessionDescriptionObserver* observer,
deadbeefab9b2d12015-10-14 11:33:11 -0700194 const PeerConnectionInterface::RTCOfferAnswerOptions& options,
195 const cricket::MediaSessionOptions& session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000196 void CreateAnswer(CreateSessionDescriptionObserver* observer,
deadbeefab9b2d12015-10-14 11:33:11 -0700197 const MediaConstraintsInterface* constraints,
198 const cricket::MediaSessionOptions& session_options);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000199 // The ownership of |desc| will be transferred after this call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 bool SetLocalDescription(SessionDescriptionInterface* desc,
201 std::string* err_desc);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000202 // The ownership of |desc| will be transferred after this call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 bool SetRemoteDescription(SessionDescriptionInterface* desc,
204 std::string* err_desc);
205 bool ProcessIceMessage(const IceCandidateInterface* ice_candidate);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000206
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000207 bool SetIceTransports(PeerConnectionInterface::IceTransportsType type);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000208
honghaiz1f429e32015-09-28 07:57:34 -0700209 cricket::IceConfig ParseIceConfig(
210 const PeerConnectionInterface::RTCConfiguration& config) const;
211
deadbeefd59daf82015-10-14 15:02:44 -0700212 void SetIceConfig(const cricket::IceConfig& ice_config);
213
214 // Start gathering candidates for any new transports, or transports doing an
215 // ICE restart.
216 void MaybeStartGathering();
217
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 const SessionDescriptionInterface* local_description() const {
219 return local_desc_.get();
220 }
221 const SessionDescriptionInterface* remote_description() const {
222 return remote_desc_.get();
223 }
224
225 // Get the id used as a media stream track's "id" field from ssrc.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200226 virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
227 virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000228
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 // AudioMediaProviderInterface implementation.
solenbergd4cec0d2015-10-09 08:55:48 -0700230 void SetAudioPlayout(uint32_t ssrc, bool enable) override;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200231 void SetAudioSend(uint32_t ssrc,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000232 bool enable,
233 const cricket::AudioOptions& options,
234 cricket::AudioRenderer* renderer) override;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200235 void SetAudioPlayoutVolume(uint32_t ssrc, double volume) override;
deadbeef2d110be2016-01-13 12:00:26 -0800236 void SetRawAudioSink(uint32_t ssrc,
237 rtc::scoped_ptr<AudioSinkInterface> sink) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238
239 // Implements VideoMediaProviderInterface.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200240 bool SetCaptureDevice(uint32_t ssrc, cricket::VideoCapturer* camera) override;
nisse08582ff2016-02-04 01:24:52 -0800241 void SetVideoPlayout(
242 uint32_t ssrc,
243 bool enable,
244 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200245 void SetVideoSend(uint32_t ssrc,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000246 bool enable,
247 const cricket::VideoOptions* options) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248
249 // Implements DtmfProviderInterface.
250 virtual bool CanInsertDtmf(const std::string& track_id);
251 virtual bool InsertDtmf(const std::string& track_id,
252 int code, int duration);
253 virtual sigslot::signal0<>* GetOnDestroyedSignal();
254
wu@webrtc.org78187522013-10-07 23:32:02 +0000255 // Implements DataChannelProviderInterface.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000256 bool SendData(const cricket::SendDataParams& params,
257 const rtc::Buffer& payload,
258 cricket::SendDataResult* result) override;
259 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override;
260 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override;
261 void AddSctpDataStream(int sid) override;
262 void RemoveSctpDataStream(int sid) override;
263 bool ReadyToSendData() const override;
wu@webrtc.org78187522013-10-07 23:32:02 +0000264
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000265 // Returns stats for all channels of all transports.
266 // This avoids exposing the internal structures used to track them.
deadbeefd59daf82015-10-14 15:02:44 -0700267 virtual bool GetTransportStats(SessionStats* stats);
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000268
deadbeefcbecd352015-09-23 11:50:27 -0700269 // Get stats for a specific channel
deadbeefd59daf82015-10-14 15:02:44 -0700270 bool GetChannelTransportStats(cricket::BaseChannel* ch, SessionStats* stats);
deadbeefcbecd352015-09-23 11:50:27 -0700271
272 // virtual so it can be mocked in unit tests
273 virtual bool GetLocalCertificate(
274 const std::string& transport_name,
275 rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
276
277 // Caller owns returned certificate
278 virtual bool GetRemoteSSLCertificate(const std::string& transport_name,
279 rtc::SSLCertificate** cert);
280
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 cricket::DataChannelType data_channel_type() const;
282
wu@webrtc.org91053e72013-08-10 07:18:04 +0000283 bool IceRestartPending() const;
284
285 void ResetIceRestartLatch();
286
Henrik Boströmd8281982015-08-27 10:12:24 +0200287 // Called when an RTCCertificate is generated or retrieved by
wu@webrtc.org91053e72013-08-10 07:18:04 +0000288 // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription.
Henrik Boströmd8281982015-08-27 10:12:24 +0200289 void OnCertificateReady(
290 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
pthatcher@webrtc.org4eeef582015-03-16 19:34:23 +0000291 void OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000292
293 // For unit test.
Henrik Boströmd8281982015-08-27 10:12:24 +0200294 bool waiting_for_certificate_for_testing() const;
deadbeefcbecd352015-09-23 11:50:27 -0700295 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000296
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000297 void set_metrics_observer(
298 webrtc::MetricsObserverInterface* metrics_observer) {
299 metrics_observer_ = metrics_observer;
300 }
301
deadbeefab9b2d12015-10-14 11:33:11 -0700302 // Called when voice_channel_, video_channel_ and data_channel_ are created
303 // and destroyed. As a result of, for example, setting a new description.
304 sigslot::signal0<> SignalVoiceChannelCreated;
305 sigslot::signal0<> SignalVoiceChannelDestroyed;
306 sigslot::signal0<> SignalVideoChannelCreated;
307 sigslot::signal0<> SignalVideoChannelDestroyed;
308 sigslot::signal0<> SignalDataChannelCreated;
309 sigslot::signal0<> SignalDataChannelDestroyed;
deadbeef057ecf02016-01-20 14:30:43 -0800310 // Called when the whole session is destroyed.
311 sigslot::signal0<> SignalDestroyed;
deadbeefab9b2d12015-10-14 11:33:11 -0700312
313 // Called when a valid data channel OPEN message is received.
314 // std::string represents the data channel label.
315 sigslot::signal2<const std::string&, const InternalDataChannelInit&>
316 SignalDataChannelOpenMessage;
317
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 private:
319 // Indicates the type of SessionDescription in a call to SetLocalDescription
320 // and SetRemoteDescription.
321 enum Action {
322 kOffer,
323 kPrAnswer,
324 kAnswer,
325 };
wu@webrtc.org91053e72013-08-10 07:18:04 +0000326
deadbeefd59daf82015-10-14 15:02:44 -0700327 // Log session state.
328 void LogState(State old_state, State new_state);
329
330 // Updates the state, signaling if necessary.
331 virtual void SetState(State state);
332
333 // Updates the error state, signaling if necessary.
334 // TODO(ronghuawu): remove the SetError method that doesn't take |error_desc|.
335 virtual void SetError(Error error, const std::string& error_desc);
336
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 bool UpdateSessionState(Action action, cricket::ContentSource source,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 std::string* err_desc);
339 static Action GetAction(const std::string& type);
pthatcher@webrtc.org592470b2015-03-16 21:15:37 +0000340 // Push the media parts of the local or remote session description
341 // down to all of the channels.
342 bool PushdownMediaDescription(cricket::ContentAction action,
343 cricket::ContentSource source,
344 std::string* error_desc);
345
deadbeefd59daf82015-10-14 15:02:44 -0700346 bool PushdownTransportDescription(cricket::ContentSource source,
347 cricket::ContentAction action,
348 std::string* error_desc);
349
350 // Helper methods to push local and remote transport descriptions.
351 bool PushdownLocalTransportDescription(
352 const cricket::SessionDescription* sdesc,
353 cricket::ContentAction action,
354 std::string* error_desc);
355 bool PushdownRemoteTransportDescription(
356 const cricket::SessionDescription* sdesc,
357 cricket::ContentAction action,
358 std::string* error_desc);
359
360 // Returns true and the TransportInfo of the given |content_name|
361 // from |description|. Returns false if it's not available.
362 static bool GetTransportDescription(
363 const cricket::SessionDescription* description,
364 const std::string& content_name,
365 cricket::TransportDescription* info);
366
deadbeefcbecd352015-09-23 11:50:27 -0700367 cricket::BaseChannel* GetChannel(const std::string& content_name);
368 // Cause all the BaseChannels in the bundle group to have the same
369 // transport channel.
370 bool EnableBundle(const cricket::ContentGroup& bundle);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 // Enables media channels to allow sending of media.
373 void EnableChannels();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 // Returns the media index for a local ice candidate given the content name.
375 // Returns false if the local session description does not have a media
376 // content called |content_name|.
377 bool GetLocalCandidateMediaIndex(const std::string& content_name,
378 int* sdp_mline_index);
379 // Uses all remote candidates in |remote_desc| in this session.
380 bool UseCandidatesInSessionDescription(
381 const SessionDescriptionInterface* remote_desc);
382 // Uses |candidate| in this session.
383 bool UseCandidate(const IceCandidateInterface* candidate);
384 // Deletes the corresponding channel of contents that don't exist in |desc|.
385 // |desc| can be null. This means that all channels are deleted.
deadbeefcbecd352015-09-23 11:50:27 -0700386 void RemoveUnusedChannels(const cricket::SessionDescription* desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387
388 // Allocates media channels based on the |desc|. If |desc| doesn't have
389 // the BUNDLE option, this method will disable BUNDLE in PortAllocator.
390 // This method will also delete any existing media channels before creating.
391 bool CreateChannels(const cricket::SessionDescription* desc);
392
393 // Helper methods to create media channels.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000394 bool CreateVoiceChannel(const cricket::ContentInfo* content);
395 bool CreateVideoChannel(const cricket::ContentInfo* content);
396 bool CreateDataChannel(const cricket::ContentInfo* content);
397
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000398 // Listens to SCTP CONTROL messages on unused SIDs and process them as OPEN
399 // messages.
400 void OnDataChannelMessageReceived(cricket::DataChannel* channel,
401 const cricket::ReceiveDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000402 const rtc::Buffer& payload);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000404 std::string BadStateErrMsg(State state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 void SetIceConnectionState(PeerConnectionInterface::IceConnectionState state);
Peter Thatcher54360512015-07-08 11:08:35 -0700406 void SetIceConnectionReceiving(bool receiving);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000408 bool ValidateBundleSettings(const cricket::SessionDescription* desc);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000409 bool HasRtcpMuxEnabled(const cricket::ContentInfo* content);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000410 // Below methods are helper methods which verifies SDP.
411 bool ValidateSessionDescription(const SessionDescriptionInterface* sdesc,
412 cricket::ContentSource source,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000413 std::string* err_desc);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000414
415 // Check if a call to SetLocalDescription is acceptable with |action|.
416 bool ExpectSetLocalDescription(Action action);
417 // Check if a call to SetRemoteDescription is acceptable with |action|.
418 bool ExpectSetRemoteDescription(Action action);
419 // Verifies a=setup attribute as per RFC 5763.
420 bool ValidateDtlsSetupAttribute(const cricket::SessionDescription* desc,
421 Action action);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000422
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +0000423 // Returns true if we are ready to push down the remote candidate.
424 // |remote_desc| is the new remote description, or NULL if the current remote
425 // description should be used. Output |valid| is true if the candidate media
426 // index is valid.
427 bool ReadyToUseRemoteCandidate(const IceCandidateInterface* candidate,
428 const SessionDescriptionInterface* remote_desc,
429 bool* valid);
430
deadbeefcbecd352015-09-23 11:50:27 -0700431 void OnTransportControllerConnectionState(cricket::IceConnectionState state);
432 void OnTransportControllerReceiving(bool receiving);
433 void OnTransportControllerGatheringState(cricket::IceGatheringState state);
434 void OnTransportControllerCandidatesGathered(
435 const std::string& transport_name,
436 const cricket::Candidates& candidates);
437
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000438 std::string GetSessionErrorMsg();
439
deadbeefcbecd352015-09-23 11:50:27 -0700440 // Invoked when TransportController connection completion is signaled.
441 // Reports stats for all transports in use.
442 void ReportTransportStats();
443
444 // Gather the usage of IPv4/IPv6 as best connection.
jbauchac8869e2015-07-03 01:36:14 -0700445 void ReportBestConnectionState(const cricket::TransportStats& stats);
446
447 void ReportNegotiatedCiphers(const cricket::TransportStats& stats);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000448
stefanc1aeaf02015-10-15 07:26:07 -0700449 void OnSentPacket_w(cricket::TransportChannel* channel,
450 const rtc::SentPacket& sent_packet);
451
deadbeefd59daf82015-10-14 15:02:44 -0700452 rtc::Thread* const signaling_thread_;
453 rtc::Thread* const worker_thread_;
454 cricket::PortAllocator* const port_allocator_;
455
456 State state_ = STATE_INIT;
457 Error error_ = ERROR_NONE;
458 std::string error_desc_;
459
460 const std::string sid_;
461 bool initial_offerer_ = false;
462
463 rtc::scoped_ptr<cricket::TransportController> transport_controller_;
stefanc1aeaf02015-10-15 07:26:07 -0700464 MediaControllerInterface* media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000465 rtc::scoped_ptr<cricket::VoiceChannel> voice_channel_;
466 rtc::scoped_ptr<cricket::VideoChannel> video_channel_;
467 rtc::scoped_ptr<cricket::DataChannel> data_channel_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 cricket::ChannelManager* channel_manager_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 IceObserver* ice_observer_;
470 PeerConnectionInterface::IceConnectionState ice_connection_state_;
Peter Thatcher54360512015-07-08 11:08:35 -0700471 bool ice_connection_receiving_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000472 rtc::scoped_ptr<SessionDescriptionInterface> local_desc_;
473 rtc::scoped_ptr<SessionDescriptionInterface> remote_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 // If the remote peer is using a older version of implementation.
475 bool older_version_remote_peer_;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000476 bool dtls_enabled_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477 // Specifies which kind of data channel is allowed. This is controlled
478 // by the chrome command-line flag and constraints:
479 // 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled,
480 // constraint kEnableDtlsSrtp is true, and constaint kEnableRtpDataChannels is
481 // not set or false, SCTP is allowed (DCT_SCTP);
482 // 2. If constraint kEnableRtpDataChannels is true, RTP is allowed (DCT_RTP);
483 // 3. If both 1&2 are false, data channel is not allowed (DCT_NONE).
484 cricket::DataChannelType data_channel_type_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000485 rtc::scoped_ptr<IceRestartAnswerLatch> ice_restart_latch_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000486
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000487 rtc::scoped_ptr<WebRtcSessionDescriptionFactory>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000488 webrtc_session_desc_factory_;
489
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000490 // Member variables for caching global options.
491 cricket::AudioOptions audio_options_;
492 cricket::VideoOptions video_options_;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000493 MetricsObserverInterface* metrics_observer_;
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000494
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000495 // Declares the bundle policy for the WebRTCSession.
496 PeerConnectionInterface::BundlePolicy bundle_policy_;
497
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700498 // Declares the RTCP mux policy for the WebRTCSession.
499 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy_;
500
henrikg3c089d72015-09-16 05:37:44 -0700501 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSession);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000502};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000503} // namespace webrtc
504
Henrik Kjellander15583c12016-02-10 10:53:12 +0100505#endif // WEBRTC_API_WEBRTCSESSION_H_