Prepare WebRtcSession to be merged into PeerConnection
This commit prepares WebRtcSession so that it can be cleanly
copy & pasted into PeerConnection in the next commit. To accomplish
this, the following was done:
1. Added a pointer to the owning PeerConnection to WebRtcSession.
2. Replace WebRtcSession state enum with signaling state.
3. All signals/observers only observed by PeerConnection were
replaced with direct calls to PeerConnection methods.
4. All duplicated fields were moved to PeerConnection.
5. The remaining tests that still use WebRtcSession for mocks were
updated to minimize dependence on WebRtcSession construction.
Bug: webrtc:8323
Change-Id: Ifc1a4ee819dcc9beca5363291012f7d5563ff7b1
Reviewed-on: https://webrtc-review.googlesource.com/9020
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Peter Thatcher <pthatcher@webrtc.org>
Reviewed-by: Zhi Huang <zhihuang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20573}
diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc
index 89452c0..3889222 100644
--- a/pc/peerconnection.cc
+++ b/pc/peerconnection.cc
@@ -45,6 +45,8 @@
#include "system_wrappers/include/clock.h"
#include "system_wrappers/include/field_trial.h"
+namespace webrtc {
+
namespace {
using webrtc::DataChannel;
@@ -241,7 +243,25 @@
} // namespace
-namespace webrtc {
+std::string GetSignalingStateString(
+ PeerConnectionInterface::SignalingState state) {
+ switch (state) {
+ case PeerConnectionInterface::kStable:
+ return "kStable";
+ case PeerConnectionInterface::kHaveLocalOffer:
+ return "kHaveLocalOffer";
+ case PeerConnectionInterface::kHaveLocalPrAnswer:
+ return "kHavePrAnswer";
+ case PeerConnectionInterface::kHaveRemoteOffer:
+ return "kHaveRemoteOffer";
+ case PeerConnectionInterface::kHaveRemotePrAnswer:
+ return "kHaveRemotePrAnswer";
+ case PeerConnectionInterface::kClosed:
+ return "kClosed";
+ }
+ RTC_NOTREACHED();
+ return "";
+}
bool PeerConnectionInterface::RTCConfiguration::operator==(
const PeerConnectionInterface::RTCConfiguration& o) const {
@@ -393,12 +413,7 @@
std::unique_ptr<RtcEventLog> event_log,
std::unique_ptr<Call> call)
: factory_(factory),
- observer_(NULL),
- uma_observer_(NULL),
event_log_(std::move(event_log)),
- signaling_state_(kStable),
- ice_connection_state_(kIceConnectionNew),
- ice_gathering_state_(kIceGatheringNew),
rtcp_cname_(GenerateRtcpCname()),
local_streams_(StreamCollection::Create()),
remote_streams_(StreamCollection::Create()),
@@ -472,44 +487,26 @@
return false;
}
- owned_session_.reset(new WebRtcSession(
- call_.get(), factory_->channel_manager(), configuration.media_config,
- event_log_.get(), network_thread(), worker_thread(), signaling_thread(),
- port_allocator_.get(),
- std::unique_ptr<cricket::TransportController>(
- factory_->CreateTransportController(
- port_allocator_.get(),
- configuration.redetermine_role_on_ice_restart)),
- factory_->CreateSctpTransportInternalFactory()));
+ owned_session_.reset(
+ new WebRtcSession(this,
+ std::unique_ptr<cricket::TransportController>(
+ factory_->CreateTransportController(
+ port_allocator_.get(),
+ configuration.redetermine_role_on_ice_restart)),
+ factory_->CreateSctpTransportInternalFactory()));
session_ = owned_session_.get();
stats_.reset(new StatsCollector(this));
stats_collector_ = RTCStatsCollector::Create(this);
+ // Need to set configuration before initializing WebRtcSession because it will
+ // reach back to fetch the media config.
+ configuration_ = configuration;
+
// Initialize the WebRtcSession. It creates transport channels etc.
session_->Initialize(factory_->options(), std::move(cert_generator),
configuration, this);
- // Register PeerConnection as receiver of local ice candidates.
- // All the callbacks will be posted to the application from PeerConnection.
- session_->RegisterIceObserver(this);
- session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange);
- session_->SignalVoiceChannelCreated.connect(
- this, &PeerConnection::OnVoiceChannelCreated);
- session_->SignalVoiceChannelDestroyed.connect(
- this, &PeerConnection::OnVoiceChannelDestroyed);
- session_->SignalVideoChannelCreated.connect(
- this, &PeerConnection::OnVideoChannelCreated);
- session_->SignalVideoChannelDestroyed.connect(
- this, &PeerConnection::OnVideoChannelDestroyed);
- session_->SignalDataChannelCreated.connect(
- this, &PeerConnection::OnDataChannelCreated);
- session_->SignalDataChannelDestroyed.connect(
- this, &PeerConnection::OnDataChannelDestroyed);
- session_->SignalDataChannelOpenMessage.connect(
- this, &PeerConnection::OnDataChannelOpenMessage);
-
- configuration_ = configuration;
return true;
}
@@ -1240,7 +1237,7 @@
uma_observer_ = observer;
if (session_) {
- session_->set_metrics_observer(uma_observer_);
+ session_->transport_controller()->SetMetricsObserver(uma_observer_);
}
// Send information about IPv4/IPv6 status.
@@ -1433,35 +1430,6 @@
});
}
-void PeerConnection::OnSessionStateChange(WebRtcSession* /*session*/,
- WebRtcSession::State state) {
- switch (state) {
- case WebRtcSession::STATE_INIT:
- ChangeSignalingState(PeerConnectionInterface::kStable);
- break;
- case WebRtcSession::STATE_SENTOFFER:
- ChangeSignalingState(PeerConnectionInterface::kHaveLocalOffer);
- break;
- case WebRtcSession::STATE_SENTPRANSWER:
- ChangeSignalingState(PeerConnectionInterface::kHaveLocalPrAnswer);
- break;
- case WebRtcSession::STATE_RECEIVEDOFFER:
- ChangeSignalingState(PeerConnectionInterface::kHaveRemoteOffer);
- break;
- case WebRtcSession::STATE_RECEIVEDPRANSWER:
- ChangeSignalingState(PeerConnectionInterface::kHaveRemotePrAnswer);
- break;
- case WebRtcSession::STATE_INPROGRESS:
- ChangeSignalingState(PeerConnectionInterface::kStable);
- break;
- case WebRtcSession::STATE_CLOSED:
- ChangeSignalingState(PeerConnectionInterface::kClosed);
- break;
- default:
- break;
- }
-}
-
void PeerConnection::OnMessage(rtc::Message* msg) {
switch (msg->message_id) {
case MSG_SET_SESSIONDESCRIPTION_SUCCESS: {
@@ -1633,14 +1601,23 @@
senders_.erase(sender);
}
-void PeerConnection::OnIceConnectionStateChange(
- PeerConnectionInterface::IceConnectionState new_state) {
+void PeerConnection::SetIceConnectionState(IceConnectionState new_state) {
RTC_DCHECK(signaling_thread()->IsCurrent());
+ if (ice_connection_state_ == new_state) {
+ return;
+ }
+
// After transitioning to "closed", ignore any additional states from
- // WebRtcSession (such as "disconnected").
+ // TransportController (such as "disconnected").
if (IsClosed()) {
return;
}
+
+ LOG(LS_INFO) << "Changing IceConnectionState " << ice_connection_state_
+ << " => " << new_state;
+ RTC_DCHECK(ice_connection_state_ !=
+ PeerConnectionInterface::kIceConnectionClosed);
+
ice_connection_state_ = new_state;
observer_->OnIceConnectionChange(ice_connection_state_);
}
@@ -1673,16 +1650,15 @@
observer_->OnIceCandidatesRemoved(candidates);
}
-void PeerConnection::OnIceConnectionReceivingChange(bool receiving) {
- RTC_DCHECK(signaling_thread()->IsCurrent());
- if (IsClosed()) {
- return;
- }
- observer_->OnIceConnectionReceivingChange(receiving);
-}
-
void PeerConnection::ChangeSignalingState(
PeerConnectionInterface::SignalingState signaling_state) {
+ RTC_DCHECK(signaling_thread()->IsCurrent());
+ if (signaling_state_ == signaling_state) {
+ return;
+ }
+ LOG(LS_INFO) << "Session: " << session_id()
+ << " Old state: " << GetSignalingStateString(signaling_state_)
+ << " New state: " << GetSignalingStateString(signaling_state);
signaling_state_ = signaling_state;
if (signaling_state == kClosed) {
ice_connection_state_ = kIceConnectionClosed;
@@ -2609,6 +2585,14 @@
turn_customizer);
}
+cricket::ChannelManager* PeerConnection::channel_manager() const {
+ return factory_->channel_manager();
+}
+
+MetricsObserverInterface* PeerConnection::metrics_observer() const {
+ return uma_observer_;
+}
+
bool PeerConnection::StartRtcEventLog_w(
std::unique_ptr<RtcEventLogOutput> output) {
if (!event_log_) {