From 46c7389a63f71923d605d7851d956656ffbac4b3 Mon Sep 17 00:00:00 2001 From: deadbeef Date: Wed, 16 Nov 2016 19:42:04 -0800 Subject: [PATCH] Adding GetConfiguration to PeerConnection. Just returns the configuration the PC was constructed with, or the last one passed into SetConfiguration. BUG=chromium:587453 Review-Url: https://codereview.webrtc.org/2504103002 Cr-Commit-Position: refs/heads/master@{#15111} --- webrtc/api/peerconnection.cc | 18 +++++++++---- webrtc/api/peerconnection.h | 4 +-- webrtc/api/peerconnectioninterface.h | 5 ++++ .../api/peerconnectioninterface_unittest.cc | 26 +++++++++++++++++++ webrtc/api/peerconnectionproxy.h | 1 + 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc index 2f320d78ed..a1ce6ab05c 100644 --- a/webrtc/api/peerconnection.cc +++ b/webrtc/api/peerconnection.cc @@ -636,8 +636,6 @@ bool PeerConnection::Initialize( stats_.reset(new StatsCollector(this)); stats_collector_ = RTCStatsCollector::Create(this); - enable_ice_renomination_ = configuration.enable_ice_renomination; - // Initialize the WebRtcSession. It creates transport channels etc. if (!session_->Initialize(factory_->options(), std::move(cert_generator), configuration)) { @@ -662,6 +660,8 @@ bool PeerConnection::Initialize( this, &PeerConnection::OnDataChannelDestroyed); session_->SignalDataChannelOpenMessage.connect( this, &PeerConnection::OnDataChannelOpenMessage); + + configuration_ = configuration; return true; } @@ -1262,8 +1262,14 @@ void PeerConnection::SetRemoteDescription( MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); } +PeerConnectionInterface::RTCConfiguration PeerConnection::GetConfiguration() { + return configuration_; +} + bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) { TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); + // TODO(deadbeef): Return false and log an error if there are any unsupported + // modifications. if (port_allocator_) { if (!network_thread()->Invoke( RTC_FROM_HERE, @@ -1276,7 +1282,7 @@ bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) { // TODO(deadbeef): Shouldn't have to hop to the worker thread twice... session_->SetIceConfig(session_->ParseIceConfig(configuration)); - enable_ice_renomination_ = configuration.enable_ice_renomination; + configuration_ = configuration; return true; } @@ -1631,7 +1637,8 @@ bool PeerConnection::GetOptionsForOffer( cricket::TransportOptions(); } } - session_options->enable_ice_renomination = enable_ice_renomination_; + session_options->enable_ice_renomination = + configuration_.enable_ice_renomination; if (!ExtractMediaSessionOptions(rtc_options, true, session_options)) { return false; @@ -1674,7 +1681,8 @@ void PeerConnection::InitializeOptionsForAnswer( cricket::MediaSessionOptions* session_options) { session_options->recv_audio = false; session_options->recv_video = false; - session_options->enable_ice_renomination = enable_ice_renomination_; + session_options->enable_ice_renomination = + configuration_.enable_ice_renomination; } void PeerConnection::FinishOptionsForAnswer( diff --git a/webrtc/api/peerconnection.h b/webrtc/api/peerconnection.h index f444eb7294..70fd86779f 100644 --- a/webrtc/api/peerconnection.h +++ b/webrtc/api/peerconnection.h @@ -129,6 +129,7 @@ class PeerConnection : public PeerConnectionInterface, SessionDescriptionInterface* desc) override; void SetRemoteDescription(SetSessionDescriptionObserver* observer, SessionDescriptionInterface* desc) override; + PeerConnectionInterface::RTCConfiguration GetConfiguration() override; bool SetConfiguration( const PeerConnectionInterface::RTCConfiguration& configuration) override; bool AddIceCandidate(const IceCandidateInterface* candidate) override; @@ -389,6 +390,7 @@ class PeerConnection : public PeerConnectionInterface, SignalingState signaling_state_; IceConnectionState ice_connection_state_; IceGatheringState ice_gathering_state_; + PeerConnectionInterface::RTCConfiguration configuration_; std::unique_ptr port_allocator_; // The EventLog needs to outlive the media controller. @@ -420,8 +422,6 @@ class PeerConnection : public PeerConnectionInterface, bool remote_peer_supports_msid_ = false; - bool enable_ice_renomination_ = false; - std::vector>> senders_; std::vector< diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h index ea056bfc98..a597c986b1 100644 --- a/webrtc/api/peerconnectioninterface.h +++ b/webrtc/api/peerconnectioninterface.h @@ -480,6 +480,11 @@ class PeerConnectionInterface : public rtc::RefCountInterface { return false; } virtual bool UpdateIce(const IceServers& configuration) { return false; } + // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of + // PeerConnectionInterface implement it. + virtual PeerConnectionInterface::RTCConfiguration GetConfiguration() { + return PeerConnectionInterface::RTCConfiguration(); + } // Sets the PeerConnection's global configuration to |config|. // Any changes to STUN/TURN servers or ICE candidate policy will affect the // next gathering phase, and cause the next call to createOffer to generate diff --git a/webrtc/api/peerconnectioninterface_unittest.cc b/webrtc/api/peerconnectioninterface_unittest.cc index be4dc06acf..245e81c1c1 100644 --- a/webrtc/api/peerconnectioninterface_unittest.cc +++ b/webrtc/api/peerconnectioninterface_unittest.cc @@ -1173,6 +1173,32 @@ TEST_F(PeerConnectionInterfaceTest, EXPECT_TRUE(raw_port_allocator->initialized()); } +// Check that GetConfiguration returns the configuration the PeerConnection was +// constructed with, before SetConfiguration is called. +TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) { + PeerConnectionInterface::RTCConfiguration config; + config.type = PeerConnectionInterface::kRelay; + CreatePeerConnection(config, nullptr); + + PeerConnectionInterface::RTCConfiguration returned_config = + pc_->GetConfiguration(); + EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); +} + +// Check that GetConfiguration returns the last configuration passed into +// SetConfiguration. +TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) { + CreatePeerConnection(); + + PeerConnectionInterface::RTCConfiguration config; + config.type = PeerConnectionInterface::kRelay; + EXPECT_TRUE(pc_->SetConfiguration(config)); + + PeerConnectionInterface::RTCConfiguration returned_config = + pc_->GetConfiguration(); + EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); +} + TEST_F(PeerConnectionInterfaceTest, AddStreams) { CreatePeerConnection(); AddVideoStream(kStreamLabel1); diff --git a/webrtc/api/peerconnectionproxy.h b/webrtc/api/peerconnectionproxy.h index 8cd3a48e50..f002014846 100644 --- a/webrtc/api/peerconnectionproxy.h +++ b/webrtc/api/peerconnectionproxy.h @@ -63,6 +63,7 @@ BEGIN_SIGNALING_PROXY_MAP(PeerConnection) SessionDescriptionInterface*) PROXY_METHOD2(void, SetRemoteDescription, SetSessionDescriptionObserver*, SessionDescriptionInterface*) + PROXY_METHOD0(PeerConnectionInterface::RTCConfiguration, GetConfiguration); PROXY_METHOD1(bool, SetConfiguration, const PeerConnectionInterface::RTCConfiguration&);