Index: talk/app/webrtc/webrtcsession.h |
diff --git a/talk/app/webrtc/webrtcsession.h b/talk/app/webrtc/webrtcsession.h |
index 8dcc85fabf718ba86cb31a8fb14f443f192729b1..f3dd602ebaebd8b4333ffe9c46ea0c7e616ddbc7 100644 |
--- a/talk/app/webrtc/webrtcsession.h |
+++ b/talk/app/webrtc/webrtcsession.h |
@@ -38,7 +38,7 @@ |
#include "talk/app/webrtc/peerconnectioninterface.h" |
#include "talk/app/webrtc/statstypes.h" |
#include "talk/media/base/mediachannel.h" |
-#include "webrtc/p2p/base/session.h" |
+#include "webrtc/p2p/base/transportcontroller.h" |
#include "talk/session/media/mediasession.h" |
#include "webrtc/base/sigslot.h" |
#include "webrtc/base/sslidentity.h" |
@@ -46,7 +46,6 @@ |
namespace cricket { |
-class BaseChannel; |
class ChannelManager; |
class DataChannel; |
class StatsReport; |
@@ -112,26 +111,80 @@ class IceObserver { |
RTC_DISALLOW_COPY_AND_ASSIGN(IceObserver); |
}; |
-class WebRtcSession : public cricket::BaseSession, |
- public AudioProviderInterface, |
+// Statistics for all the transports of the session. |
+typedef std::map<std::string, cricket::TransportStats> TransportStatsMap; |
+typedef std::map<std::string, std::string> ProxyTransportMap; |
+ |
+// TODO(pthatcher): Think of a better name for this. We already have |
+// a TransportStats in transport.h. Perhaps TransportsStats? |
+struct SessionStats { |
+ ProxyTransportMap proxy_to_transport; |
+ TransportStatsMap transport_stats; |
+}; |
+ |
+// A WebRtcSession manages general session state. This includes negotiation |
+// of both the application-level and network-level protocols: the former |
+// defines what will be sent and the latter defines how it will be sent. Each |
+// network-level protocol is represented by a Transport object. Each Transport |
+// participates in the network-level negotiation. The individual streams of |
+// packets are represented by TransportChannels. The application-level protocol |
+// is represented by SessionDecription objects. |
+class WebRtcSession : public AudioProviderInterface, |
public VideoProviderInterface, |
public DtmfProviderInterface, |
- public DataChannelProviderInterface { |
+ public DataChannelProviderInterface, |
+ public sigslot::has_slots<> { |
public: |
+ enum State { |
+ STATE_INIT = 0, |
+ STATE_SENTOFFER, // Sent offer, waiting for answer. |
+ STATE_RECEIVEDOFFER, // Received an offer. Need to send answer. |
+ STATE_SENTPRANSWER, // Sent provisional answer. Need to send answer. |
+ STATE_RECEIVEDPRANSWER, // Received provisional answer, waiting for answer. |
+ STATE_INPROGRESS, // Offer/answer exchange completed. |
+ STATE_CLOSED, // Close() was called. |
+ }; |
+ |
+ enum Error { |
+ ERROR_NONE = 0, // no error |
+ ERROR_CONTENT = 1, // channel errors in SetLocalContent/SetRemoteContent |
+ ERROR_TRANSPORT = 2, // transport error of some kind |
+ }; |
+ |
WebRtcSession(cricket::ChannelManager* channel_manager, |
rtc::Thread* signaling_thread, |
rtc::Thread* worker_thread, |
cricket::PortAllocator* port_allocator); |
virtual ~WebRtcSession(); |
+ // These are const to allow them to be called from const methods. |
+ rtc::Thread* signaling_thread() const { return signaling_thread_; } |
+ rtc::Thread* worker_thread() const { return worker_thread_; } |
+ cricket::PortAllocator* port_allocator() const { return port_allocator_; } |
+ |
+ // The ID of this session. |
+ const std::string& id() const { return sid_; } |
+ |
bool Initialize( |
const PeerConnectionFactoryInterface::Options& options, |
const MediaConstraintsInterface* constraints, |
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
const PeerConnectionInterface::RTCConfiguration& rtc_configuration); |
// Deletes the voice, video and data channel and changes the session state |
- // to STATE_RECEIVEDTERMINATE. |
- void Terminate(); |
+ // to STATE_CLOSED. |
+ void Close(); |
+ |
+ // Returns true if we were the initial offerer. |
+ bool initial_offerer() const { return initial_offerer_; } |
+ |
+ // Returns the current state of the session. See the enum above for details. |
+ // Each time the state changes, we will fire this signal. |
+ State state() const { return state_; } |
+ sigslot::signal2<WebRtcSession*, State> SignalState; |
+ |
+ // Returns the last error in the session. See the enum above for details. |
+ Error error() const { return error_; } |
+ const std::string& error_desc() const { return error_desc_; } |
void RegisterIceObserver(IceObserver* observer) { |
ice_observer_ = observer; |
@@ -153,10 +206,6 @@ class WebRtcSession : public cricket::BaseSession, |
// Get current ssl role from transport. |
bool GetSslRole(rtc::SSLRole* role); |
- // Generic error message callback from WebRtcSession. |
- // TODO - It may be necessary to supply error code as well. |
- sigslot::signal0<> SignalError; |
- |
void CreateOffer( |
CreateSessionDescriptionObserver* observer, |
const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
@@ -177,21 +226,18 @@ class WebRtcSession : public cricket::BaseSession, |
cricket::IceConfig ParseIceConfig( |
const PeerConnectionInterface::RTCConfiguration& config) const; |
+ void SetIceConfig(const cricket::IceConfig& ice_config); |
+ |
+ // Start gathering candidates for any new transports, or transports doing an |
+ // ICE restart. |
+ void MaybeStartGathering(); |
+ |
const SessionDescriptionInterface* local_description() const { |
return local_desc_.get(); |
} |
const SessionDescriptionInterface* remote_description() const { |
return remote_desc_.get(); |
} |
- // TODO(pthatcher): Cleanup the distinction between |
- // SessionDescription and SessionDescriptionInterface and remove |
- // these if possible. |
- const cricket::SessionDescription* base_local_description() const { |
- return BaseSession::local_description(); |
- } |
- const cricket::SessionDescription* base_remote_description() const { |
- return BaseSession::remote_description(); |
- } |
// Get the id used as a media stream track's "id" field from ssrc. |
virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id); |
@@ -232,11 +278,10 @@ class WebRtcSession : public cricket::BaseSession, |
// Returns stats for all channels of all transports. |
// This avoids exposing the internal structures used to track them. |
- virtual bool GetTransportStats(cricket::SessionStats* stats); |
+ virtual bool GetTransportStats(SessionStats* stats); |
// Get stats for a specific channel |
- bool GetChannelTransportStats(cricket::BaseChannel* ch, |
- cricket::SessionStats* stats); |
+ bool GetChannelTransportStats(cricket::BaseChannel* ch, SessionStats* stats); |
// virtual so it can be mocked in unit tests |
virtual bool GetLocalCertificate( |
@@ -291,6 +336,16 @@ class WebRtcSession : public cricket::BaseSession, |
kAnswer, |
}; |
+ // Log session state. |
+ void LogState(State old_state, State new_state); |
+ |
+ // Updates the state, signaling if necessary. |
+ virtual void SetState(State state); |
+ |
+ // Updates the error state, signaling if necessary. |
+ // TODO(ronghuawu): remove the SetError method that doesn't take |error_desc|. |
+ virtual void SetError(Error error, const std::string& error_desc); |
+ |
bool UpdateSessionState(Action action, cricket::ContentSource source, |
std::string* err_desc); |
static Action GetAction(const std::string& type); |
@@ -300,6 +355,27 @@ class WebRtcSession : public cricket::BaseSession, |
cricket::ContentSource source, |
std::string* error_desc); |
+ bool PushdownTransportDescription(cricket::ContentSource source, |
+ cricket::ContentAction action, |
+ std::string* error_desc); |
+ |
+ // Helper methods to push local and remote transport descriptions. |
+ bool PushdownLocalTransportDescription( |
+ const cricket::SessionDescription* sdesc, |
+ cricket::ContentAction action, |
+ std::string* error_desc); |
+ bool PushdownRemoteTransportDescription( |
+ const cricket::SessionDescription* sdesc, |
+ cricket::ContentAction action, |
+ std::string* error_desc); |
+ |
+ // Returns true and the TransportInfo of the given |content_name| |
+ // from |description|. Returns false if it's not available. |
+ static bool GetTransportDescription( |
+ const cricket::SessionDescription* description, |
+ const std::string& content_name, |
+ cricket::TransportDescription* info); |
+ |
cricket::BaseChannel* GetChannel(const std::string& content_name); |
// Cause all the BaseChannels in the bundle group to have the same |
// transport channel. |
@@ -331,10 +407,6 @@ class WebRtcSession : public cricket::BaseSession, |
bool CreateVideoChannel(const cricket::ContentInfo* content); |
bool CreateDataChannel(const cricket::ContentInfo* content); |
- // Copy the candidates from |saved_candidates_| to |dest_desc|. |
- // The |saved_candidates_| will be cleared after this function call. |
- void CopySavedCandidates(SessionDescriptionInterface* dest_desc); |
- |
// Listens to SCTP CONTROL messages on unused SIDs and process them as OPEN |
// messages. |
void OnDataChannelMessageReceived(cricket::DataChannel* channel, |
@@ -386,6 +458,18 @@ class WebRtcSession : public cricket::BaseSession, |
void ReportNegotiatedCiphers(const cricket::TransportStats& stats); |
+ rtc::Thread* const signaling_thread_; |
+ rtc::Thread* const worker_thread_; |
+ cricket::PortAllocator* const port_allocator_; |
+ |
+ State state_ = STATE_INIT; |
+ Error error_ = ERROR_NONE; |
+ std::string error_desc_; |
+ |
+ const std::string sid_; |
+ bool initial_offerer_ = false; |
+ |
+ rtc::scoped_ptr<cricket::TransportController> transport_controller_; |
rtc::scoped_ptr<MediaControllerInterface> media_controller_; |
rtc::scoped_ptr<cricket::VoiceChannel> voice_channel_; |
rtc::scoped_ptr<cricket::VideoChannel> video_channel_; |
@@ -396,8 +480,6 @@ class WebRtcSession : public cricket::BaseSession, |
bool ice_connection_receiving_; |
rtc::scoped_ptr<SessionDescriptionInterface> local_desc_; |
rtc::scoped_ptr<SessionDescriptionInterface> remote_desc_; |
- // Candidates that arrived before the remote description was set. |
- std::vector<IceCandidateInterface*> saved_candidates_; |
// If the remote peer is using a older version of implementation. |
bool older_version_remote_peer_; |
bool dtls_enabled_; |