Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(871)

Side by Side Diff: talk/app/webrtc/webrtcsession.h

Issue 1397973002: Merging BaseSession code into WebRtcSession. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removing obsolete unit test. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 20 matching lines...) Expand all
31 #include <string> 31 #include <string>
32 #include <vector> 32 #include <vector>
33 33
34 #include "talk/app/webrtc/datachannel.h" 34 #include "talk/app/webrtc/datachannel.h"
35 #include "talk/app/webrtc/dtmfsender.h" 35 #include "talk/app/webrtc/dtmfsender.h"
36 #include "talk/app/webrtc/mediacontroller.h" 36 #include "talk/app/webrtc/mediacontroller.h"
37 #include "talk/app/webrtc/mediastreamprovider.h" 37 #include "talk/app/webrtc/mediastreamprovider.h"
38 #include "talk/app/webrtc/peerconnectioninterface.h" 38 #include "talk/app/webrtc/peerconnectioninterface.h"
39 #include "talk/app/webrtc/statstypes.h" 39 #include "talk/app/webrtc/statstypes.h"
40 #include "talk/media/base/mediachannel.h" 40 #include "talk/media/base/mediachannel.h"
41 #include "webrtc/p2p/base/session.h" 41 #include "webrtc/p2p/base/transportcontroller.h"
42 #include "talk/session/media/mediasession.h" 42 #include "talk/session/media/mediasession.h"
43 #include "webrtc/base/sigslot.h" 43 #include "webrtc/base/sigslot.h"
44 #include "webrtc/base/sslidentity.h" 44 #include "webrtc/base/sslidentity.h"
45 #include "webrtc/base/thread.h" 45 #include "webrtc/base/thread.h"
46 46
47 namespace cricket { 47 namespace cricket {
48 48
49 class BaseChannel;
50 class ChannelManager; 49 class ChannelManager;
51 class DataChannel; 50 class DataChannel;
52 class StatsReport; 51 class StatsReport;
53 class VideoCapturer; 52 class VideoCapturer;
54 class VideoChannel; 53 class VideoChannel;
55 class VoiceChannel; 54 class VoiceChannel;
56 55
57 } // namespace cricket 56 } // namespace cricket
58 57
59 namespace webrtc { 58 namespace webrtc {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Called whenever the state changes between receiving and not receiving. 104 // Called whenever the state changes between receiving and not receiving.
106 virtual void OnIceConnectionReceivingChange(bool receiving) {} 105 virtual void OnIceConnectionReceivingChange(bool receiving) {}
107 106
108 protected: 107 protected:
109 ~IceObserver() {} 108 ~IceObserver() {}
110 109
111 private: 110 private:
112 RTC_DISALLOW_COPY_AND_ASSIGN(IceObserver); 111 RTC_DISALLOW_COPY_AND_ASSIGN(IceObserver);
113 }; 112 };
114 113
115 class WebRtcSession : public cricket::BaseSession, 114 // Statistics for all the transports of the session.
116 public AudioProviderInterface, 115 typedef std::map<std::string, cricket::TransportStats> TransportStatsMap;
116 typedef std::map<std::string, std::string> ProxyTransportMap;
117
118 // TODO(pthatcher): Think of a better name for this. We already have
119 // a TransportStats in transport.h. Perhaps TransportsStats?
120 struct SessionStats {
121 ProxyTransportMap proxy_to_transport;
122 TransportStatsMap transport_stats;
123 };
124
125 // A WebRtcSession manages general session state. This includes negotiation
126 // of both the application-level and network-level protocols: the former
127 // defines what will be sent and the latter defines how it will be sent. Each
128 // network-level protocol is represented by a Transport object. Each Transport
129 // participates in the network-level negotiation. The individual streams of
130 // packets are represented by TransportChannels. The application-level protocol
131 // is represented by SessionDecription objects.
132 class WebRtcSession : public AudioProviderInterface,
117 public DataChannelFactory, 133 public DataChannelFactory,
118 public VideoProviderInterface, 134 public VideoProviderInterface,
119 public DtmfProviderInterface, 135 public DtmfProviderInterface,
120 public DataChannelProviderInterface { 136 public DataChannelProviderInterface,
137 public rtc::MessageHandler,
138 public sigslot::has_slots<> {
121 public: 139 public:
140 enum State {
141 STATE_INIT = 0,
142 STATE_SENTINITIATE, // sent initiate, waiting for Accept or Reject
143 STATE_RECEIVEDINITIATE, // received an initiate. Call Accept or Reject
144 STATE_SENTPRACCEPT, // sent provisional Accept
145 STATE_SENTACCEPT, // sent accept. begin connecting transport
146 STATE_RECEIVEDPRACCEPT, // received provisional Accept, waiting for Accept
147 STATE_RECEIVEDACCEPT, // received accept. begin connecting transport
148 STATE_SENTMODIFY, // sent modify, waiting for Accept or Reject
149 STATE_RECEIVEDMODIFY, // received modify, call Accept or Reject
150 STATE_SENTREJECT, // sent reject after receiving initiate
151 STATE_RECEIVEDREJECT, // received reject after sending initiate
152 STATE_SENTREDIRECT, // sent direct after receiving initiate
153 STATE_SENTTERMINATE, // sent terminate (any time / either side)
154 STATE_RECEIVEDTERMINATE, // received terminate (any time / either side)
155 STATE_INPROGRESS, // session accepted and in progress
156 STATE_DEINIT, // session is being destroyed
pthatcher1 2015/10/09 03:28:57 Not all of these are used any more, and almost all
Taylor Brandstetter 2015/10/09 23:02:07 Done.
157 };
158
159 enum Error {
160 ERROR_NONE = 0, // no error
161 ERROR_CONTENT = 1, // channel errors in SetLocalContent/SetRemoteContent
162 ERROR_TRANSPORT = 2, // transport error of some kind
163 };
164
122 WebRtcSession(cricket::ChannelManager* channel_manager, 165 WebRtcSession(cricket::ChannelManager* channel_manager,
123 rtc::Thread* signaling_thread, 166 rtc::Thread* signaling_thread,
124 rtc::Thread* worker_thread, 167 rtc::Thread* worker_thread,
125 cricket::PortAllocator* port_allocator, 168 cricket::PortAllocator* port_allocator,
126 MediaStreamSignaling* mediastream_signaling); 169 MediaStreamSignaling* mediastream_signaling);
127 virtual ~WebRtcSession(); 170 virtual ~WebRtcSession();
128 171
172 // These are const to allow them to be called from const methods.
173 rtc::Thread* signaling_thread() const { return signaling_thread_; }
174 rtc::Thread* worker_thread() const { return worker_thread_; }
175 cricket::PortAllocator* port_allocator() const { return port_allocator_; }
176
177 // The ID of this session.
178 const std::string& id() const { return sid_; }
179
129 bool Initialize( 180 bool Initialize(
130 const PeerConnectionFactoryInterface::Options& options, 181 const PeerConnectionFactoryInterface::Options& options,
131 const MediaConstraintsInterface* constraints, 182 const MediaConstraintsInterface* constraints,
132 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, 183 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
133 const PeerConnectionInterface::RTCConfiguration& rtc_configuration); 184 const PeerConnectionInterface::RTCConfiguration& rtc_configuration);
134 // Deletes the voice, video and data channel and changes the session state 185 // Deletes the voice, video and data channel and changes the session state
135 // to STATE_RECEIVEDTERMINATE. 186 // to STATE_RECEIVEDTERMINATE.
136 void Terminate(); 187 void Terminate();
137 188
189 // Returns true if we were the initial offerer.
190 bool initiator() const { return initiator_; }
pthatcher1 2015/10/09 03:28:57 Maybe call it offerer.
Taylor Brandstetter 2015/10/09 23:02:06 Since there can be multiple offer/answer pairs, I'
191
192 // Returns the current state of the session. See the enum above for details.
193 // Each time the state changes, we will fire this signal.
194 State state() const { return state_; }
195 sigslot::signal2<WebRtcSession*, State> SignalState;
196
197 // Returns the last error in the session. See the enum above for details.
198 // Each time the an error occurs, we will fire this signal.
199 Error error() const { return error_; }
200 const std::string& error_desc() const { return error_desc_; }
201 sigslot::signal2<WebRtcSession*, Error> SignalError;
pthatcher1 2015/10/09 03:28:57 Is this still used? I think we can just remove it
Taylor Brandstetter 2015/10/09 23:02:07 Done.
202
138 void RegisterIceObserver(IceObserver* observer) { 203 void RegisterIceObserver(IceObserver* observer) {
139 ice_observer_ = observer; 204 ice_observer_ = observer;
140 } 205 }
141 206
142 virtual cricket::VoiceChannel* voice_channel() { 207 virtual cricket::VoiceChannel* voice_channel() {
143 return voice_channel_.get(); 208 return voice_channel_.get();
144 } 209 }
145 virtual cricket::VideoChannel* video_channel() { 210 virtual cricket::VideoChannel* video_channel() {
146 return video_channel_.get(); 211 return video_channel_.get();
147 } 212 }
148 virtual cricket::DataChannel* data_channel() { 213 virtual cricket::DataChannel* data_channel() {
149 return data_channel_.get(); 214 return data_channel_.get();
150 } 215 }
151 216
152 virtual const MediaStreamSignaling* mediastream_signaling() const { 217 virtual const MediaStreamSignaling* mediastream_signaling() const {
153 return mediastream_signaling_; 218 return mediastream_signaling_;
154 } 219 }
155 220
156 void SetSdesPolicy(cricket::SecurePolicy secure_policy); 221 void SetSdesPolicy(cricket::SecurePolicy secure_policy);
157 cricket::SecurePolicy SdesPolicy() const; 222 cricket::SecurePolicy SdesPolicy() const;
158 223
159 // Get current ssl role from transport. 224 // Get current ssl role from transport.
160 bool GetSslRole(rtc::SSLRole* role); 225 bool GetSslRole(rtc::SSLRole* role);
161 226
162 // Generic error message callback from WebRtcSession.
163 // TODO - It may be necessary to supply error code as well.
164 sigslot::signal0<> SignalError;
165
166 void CreateOffer( 227 void CreateOffer(
167 CreateSessionDescriptionObserver* observer, 228 CreateSessionDescriptionObserver* observer,
168 const PeerConnectionInterface::RTCOfferAnswerOptions& options); 229 const PeerConnectionInterface::RTCOfferAnswerOptions& options);
169 void CreateAnswer(CreateSessionDescriptionObserver* observer, 230 void CreateAnswer(CreateSessionDescriptionObserver* observer,
170 const MediaConstraintsInterface* constraints); 231 const MediaConstraintsInterface* constraints);
171 // The ownership of |desc| will be transferred after this call. 232 // The ownership of |desc| will be transferred after this call.
172 bool SetLocalDescription(SessionDescriptionInterface* desc, 233 bool SetLocalDescription(SessionDescriptionInterface* desc,
173 std::string* err_desc); 234 std::string* err_desc);
174 // The ownership of |desc| will be transferred after this call. 235 // The ownership of |desc| will be transferred after this call.
175 bool SetRemoteDescription(SessionDescriptionInterface* desc, 236 bool SetRemoteDescription(SessionDescriptionInterface* desc,
176 std::string* err_desc); 237 std::string* err_desc);
177 bool ProcessIceMessage(const IceCandidateInterface* ice_candidate); 238 bool ProcessIceMessage(const IceCandidateInterface* ice_candidate);
178 239
179 bool SetIceTransports(PeerConnectionInterface::IceTransportsType type); 240 bool SetIceTransports(PeerConnectionInterface::IceTransportsType type);
180 241
181 cricket::IceConfig ParseIceConfig( 242 cricket::IceConfig ParseIceConfig(
182 const PeerConnectionInterface::RTCConfiguration& config) const; 243 const PeerConnectionInterface::RTCConfiguration& config) const;
183 244
245 void SetIceConfig(const cricket::IceConfig& ice_config);
246
247 // Start gathering candidates for any new transports, or transports doing an
248 // ICE restart.
249 void MaybeStartGathering();
250
184 const SessionDescriptionInterface* local_description() const { 251 const SessionDescriptionInterface* local_description() const {
185 return local_desc_.get(); 252 return local_desc_.get();
186 } 253 }
187 const SessionDescriptionInterface* remote_description() const { 254 const SessionDescriptionInterface* remote_description() const {
188 return remote_desc_.get(); 255 return remote_desc_.get();
189 } 256 }
257
190 // TODO(pthatcher): Cleanup the distinction between 258 // TODO(pthatcher): Cleanup the distinction between
191 // SessionDescription and SessionDescriptionInterface and remove 259 // SessionDescription and SessionDescriptionInterface and remove
192 // these if possible. 260 // these if possible.
193 const cricket::SessionDescription* base_local_description() const { 261 const cricket::SessionDescription* base_local_description() const {
194 return BaseSession::local_description(); 262 return local_desc_ ? local_desc_->description() : nullptr;
pthatcher1 2015/10/09 03:28:57 base_ doesn't make sense as a prefix any more. Bu
Taylor Brandstetter 2015/10/09 23:02:06 Actually, the only reason I even kept these around
195 } 263 }
196 const cricket::SessionDescription* base_remote_description() const { 264 const cricket::SessionDescription* base_remote_description() const {
197 return BaseSession::remote_description(); 265 return remote_desc_ ? remote_desc_->description() : nullptr;
198 } 266 }
199 267
200 // Get the id used as a media stream track's "id" field from ssrc. 268 // Get the id used as a media stream track's "id" field from ssrc.
201 virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id); 269 virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
202 virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id); 270 virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
203 271
204 // AudioMediaProviderInterface implementation. 272 // AudioMediaProviderInterface implementation.
205 void SetAudioPlayout(uint32_t ssrc, 273 void SetAudioPlayout(uint32_t ssrc,
206 bool enable, 274 bool enable,
207 cricket::AudioRenderer* renderer) override; 275 cricket::AudioRenderer* renderer) override;
(...skipping 23 matching lines...) Expand all
231 const rtc::Buffer& payload, 299 const rtc::Buffer& payload,
232 cricket::SendDataResult* result) override; 300 cricket::SendDataResult* result) override;
233 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override; 301 bool ConnectDataChannel(DataChannel* webrtc_data_channel) override;
234 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override; 302 void DisconnectDataChannel(DataChannel* webrtc_data_channel) override;
235 void AddSctpDataStream(int sid) override; 303 void AddSctpDataStream(int sid) override;
236 void RemoveSctpDataStream(int sid) override; 304 void RemoveSctpDataStream(int sid) override;
237 bool ReadyToSendData() const override; 305 bool ReadyToSendData() const override;
238 306
239 // Returns stats for all channels of all transports. 307 // Returns stats for all channels of all transports.
240 // This avoids exposing the internal structures used to track them. 308 // This avoids exposing the internal structures used to track them.
241 virtual bool GetTransportStats(cricket::SessionStats* stats); 309 virtual bool GetTransportStats(SessionStats* stats);
242 310
243 // Get stats for a specific channel 311 // Get stats for a specific channel
244 bool GetChannelTransportStats(cricket::BaseChannel* ch, 312 bool GetChannelTransportStats(cricket::BaseChannel* ch, SessionStats* stats);
245 cricket::SessionStats* stats);
246 313
247 // virtual so it can be mocked in unit tests 314 // virtual so it can be mocked in unit tests
248 virtual bool GetLocalCertificate( 315 virtual bool GetLocalCertificate(
249 const std::string& transport_name, 316 const std::string& transport_name,
250 rtc::scoped_refptr<rtc::RTCCertificate>* certificate); 317 rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
251 318
252 // Caller owns returned certificate 319 // Caller owns returned certificate
253 virtual bool GetRemoteSSLCertificate(const std::string& transport_name, 320 virtual bool GetRemoteSSLCertificate(const std::string& transport_name,
254 rtc::SSLCertificate** cert); 321 rtc::SSLCertificate** cert);
255 322
(...skipping 25 matching lines...) Expand all
281 348
282 private: 349 private:
283 // Indicates the type of SessionDescription in a call to SetLocalDescription 350 // Indicates the type of SessionDescription in a call to SetLocalDescription
284 // and SetRemoteDescription. 351 // and SetRemoteDescription.
285 enum Action { 352 enum Action {
286 kOffer, 353 kOffer,
287 kPrAnswer, 354 kPrAnswer,
288 kAnswer, 355 kAnswer,
289 }; 356 };
290 357
358 // Handles messages posted to us.
359 void OnMessage(rtc::Message* pmsg) override;
360
361 // Log session state.
362 void LogState(State old_state, State new_state);
363
364 // Updates the state, signaling if necessary.
365 virtual void SetState(State state);
366
367 // Updates the error state, signaling if necessary.
368 // TODO(ronghuawu): remove the SetError method that doesn't take |error_desc|.
369 virtual void SetError(Error error, const std::string& error_desc);
370
291 bool UpdateSessionState(Action action, cricket::ContentSource source, 371 bool UpdateSessionState(Action action, cricket::ContentSource source,
292 std::string* err_desc); 372 std::string* err_desc);
293 static Action GetAction(const std::string& type); 373 static Action GetAction(const std::string& type);
294 // Push the media parts of the local or remote session description 374 // Push the media parts of the local or remote session description
295 // down to all of the channels. 375 // down to all of the channels.
296 bool PushdownMediaDescription(cricket::ContentAction action, 376 bool PushdownMediaDescription(cricket::ContentAction action,
297 cricket::ContentSource source, 377 cricket::ContentSource source,
298 std::string* error_desc); 378 std::string* error_desc);
299 379
380 bool PushdownTransportDescription(cricket::ContentSource source,
381 cricket::ContentAction action,
382 std::string* error_desc);
383
384 // Helper methods to push local and remote transport descriptions.
385 bool PushdownLocalTransportDescription(
386 const cricket::SessionDescription* sdesc,
387 cricket::ContentAction action,
388 std::string* error_desc);
389 bool PushdownRemoteTransportDescription(
390 const cricket::SessionDescription* sdesc,
391 cricket::ContentAction action,
392 std::string* error_desc);
393
394 // Returns true and the TransportInfo of the given |content_name|
395 // from |description|. Returns false if it's not available.
396 static bool GetTransportDescription(
397 const cricket::SessionDescription* description,
398 const std::string& content_name,
399 cricket::TransportDescription* info);
400
300 cricket::BaseChannel* GetChannel(const std::string& content_name); 401 cricket::BaseChannel* GetChannel(const std::string& content_name);
301 // Cause all the BaseChannels in the bundle group to have the same 402 // Cause all the BaseChannels in the bundle group to have the same
302 // transport channel. 403 // transport channel.
303 bool EnableBundle(const cricket::ContentGroup& bundle); 404 bool EnableBundle(const cricket::ContentGroup& bundle);
304 405
305 // Enables media channels to allow sending of media. 406 // Enables media channels to allow sending of media.
306 void EnableChannels(); 407 void EnableChannels();
307 // Returns the media index for a local ice candidate given the content name. 408 // Returns the media index for a local ice candidate given the content name.
308 // Returns false if the local session description does not have a media 409 // Returns false if the local session description does not have a media
309 // content called |content_name|. 410 // content called |content_name|.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 477
377 // Invoked when TransportController connection completion is signaled. 478 // Invoked when TransportController connection completion is signaled.
378 // Reports stats for all transports in use. 479 // Reports stats for all transports in use.
379 void ReportTransportStats(); 480 void ReportTransportStats();
380 481
381 // Gather the usage of IPv4/IPv6 as best connection. 482 // Gather the usage of IPv4/IPv6 as best connection.
382 void ReportBestConnectionState(const cricket::TransportStats& stats); 483 void ReportBestConnectionState(const cricket::TransportStats& stats);
383 484
384 void ReportNegotiatedCiphers(const cricket::TransportStats& stats); 485 void ReportNegotiatedCiphers(const cricket::TransportStats& stats);
385 486
487 rtc::Thread* const signaling_thread_;
488 rtc::Thread* const worker_thread_;
489 cricket::PortAllocator* const port_allocator_;
490
491 State state_ = STATE_INIT;
492 Error error_ = ERROR_NONE;
493 std::string error_desc_;
494
495 const std::string sid_;
496 bool initiator_ = false;
497
498 rtc::scoped_ptr<cricket::TransportController> transport_controller_;
386 rtc::scoped_ptr<MediaControllerInterface> media_controller_; 499 rtc::scoped_ptr<MediaControllerInterface> media_controller_;
387 rtc::scoped_ptr<cricket::VoiceChannel> voice_channel_; 500 rtc::scoped_ptr<cricket::VoiceChannel> voice_channel_;
388 rtc::scoped_ptr<cricket::VideoChannel> video_channel_; 501 rtc::scoped_ptr<cricket::VideoChannel> video_channel_;
389 rtc::scoped_ptr<cricket::DataChannel> data_channel_; 502 rtc::scoped_ptr<cricket::DataChannel> data_channel_;
390 cricket::ChannelManager* channel_manager_; 503 cricket::ChannelManager* channel_manager_;
391 MediaStreamSignaling* mediastream_signaling_; 504 MediaStreamSignaling* mediastream_signaling_;
392 IceObserver* ice_observer_; 505 IceObserver* ice_observer_;
393 PeerConnectionInterface::IceConnectionState ice_connection_state_; 506 PeerConnectionInterface::IceConnectionState ice_connection_state_;
394 bool ice_connection_receiving_; 507 bool ice_connection_receiving_;
395 rtc::scoped_ptr<SessionDescriptionInterface> local_desc_; 508 rtc::scoped_ptr<SessionDescriptionInterface> local_desc_;
(...skipping 29 matching lines...) Expand all
425 PeerConnectionInterface::BundlePolicy bundle_policy_; 538 PeerConnectionInterface::BundlePolicy bundle_policy_;
426 539
427 // Declares the RTCP mux policy for the WebRTCSession. 540 // Declares the RTCP mux policy for the WebRTCSession.
428 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy_; 541 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy_;
429 542
430 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSession); 543 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSession);
431 }; 544 };
432 } // namespace webrtc 545 } // namespace webrtc
433 546
434 #endif // TALK_APP_WEBRTC_WEBRTCSESSION_H_ 547 #endif // TALK_APP_WEBRTC_WEBRTCSESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698