diff --git a/webrtc/api/android/jni/peerconnection_jni.cc b/webrtc/api/android/jni/peerconnection_jni.cc index 5095b152ba..f47787f07d 100644 --- a/webrtc/api/android/jni/peerconnection_jni.cc +++ b/webrtc/api/android/jni/peerconnection_jni.cc @@ -1668,7 +1668,8 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnection)( reinterpret_cast( factoryFromJava(factory))); - PeerConnectionInterface::RTCConfiguration rtc_config; + PeerConnectionInterface::RTCConfiguration rtc_config = + PeerConnectionInterface::RTCConfiguration::AggressiveConfiguration(); JavaRTCConfigurationToJsepRTCConfiguration(jni, j_rtc_config, &rtc_config); jclass j_rtc_config_class = GetObjectClass(jni, j_rtc_config); @@ -1809,7 +1810,8 @@ JOW(void, PeerConnection_setRemoteDescription)( JOW(jboolean, PeerConnection_setConfiguration)( JNIEnv* jni, jobject j_pc, jobject j_rtc_config) { - PeerConnectionInterface::RTCConfiguration rtc_config; + PeerConnectionInterface::RTCConfiguration rtc_config = + PeerConnectionInterface::RTCConfiguration::AggressiveConfiguration(); JavaRTCConfigurationToJsepRTCConfiguration(jni, j_rtc_config, &rtc_config); return ExtractNativePC(jni, j_pc)->SetConfiguration(rtc_config); } diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc index c675015ac9..b13113aa3a 100644 --- a/webrtc/api/peerconnection.cc +++ b/webrtc/api/peerconnection.cc @@ -627,7 +627,9 @@ bool PeerConnection::Initialize( factory_->worker_thread(), factory_->signaling_thread(), port_allocator_.get(), std::unique_ptr( - factory_->CreateTransportController(port_allocator_.get())))); + factory_->CreateTransportController( + port_allocator_.get(), + configuration.redetermine_role_on_ice_restart)))); stats_.reset(new StatsCollector(this)); diff --git a/webrtc/api/peerconnectionfactory.cc b/webrtc/api/peerconnectionfactory.cc index 82cd5d4f4a..f49c291e49 100644 --- a/webrtc/api/peerconnectionfactory.cc +++ b/webrtc/api/peerconnectionfactory.cc @@ -309,10 +309,12 @@ webrtc::MediaControllerInterface* PeerConnectionFactory::CreateMediaController( } cricket::TransportController* PeerConnectionFactory::CreateTransportController( - cricket::PortAllocator* port_allocator) { + cricket::PortAllocator* port_allocator, + bool redetermine_role_on_ice_restart) { RTC_DCHECK(signaling_thread_->IsCurrent()); return new cricket::TransportController(signaling_thread_, network_thread_, - port_allocator); + port_allocator, + redetermine_role_on_ice_restart); } rtc::Thread* PeerConnectionFactory::signaling_thread() { diff --git a/webrtc/api/peerconnectionfactory.h b/webrtc/api/peerconnectionfactory.h index 377ad73ec8..7684b95362 100644 --- a/webrtc/api/peerconnectionfactory.h +++ b/webrtc/api/peerconnectionfactory.h @@ -91,7 +91,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { virtual webrtc::MediaControllerInterface* CreateMediaController( const cricket::MediaConfig& config) const; virtual cricket::TransportController* CreateTransportController( - cricket::PortAllocator* port_allocator); + cricket::PortAllocator* port_allocator, + bool redetermine_role_on_ice_restart); virtual rtc::Thread* signaling_thread(); virtual rtc::Thread* worker_thread(); virtual rtc::Thread* network_thread(); diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h index fdf9cef51e..1dba14c41a 100644 --- a/webrtc/api/peerconnectioninterface.h +++ b/webrtc/api/peerconnectioninterface.h @@ -240,6 +240,18 @@ class PeerConnectionInterface : public rtc::RefCountInterface { // methods for all settings which are of interest to applications, // Chrome in particular. + // A configuration that is safer to use, despite it may not have the best + // performance. + static RTCConfiguration SafeConfiguration() { return RTCConfiguration(); } + + // An aggressive configuration that has better performance, although it + // may be riskier and may need extra support in the application. + static RTCConfiguration AggressiveConfiguration() { + RTCConfiguration config; + config.redetermine_role_on_ice_restart = false; + return config; + } + bool dscp() { return media_config.enable_dscp; } void set_dscp(bool enable) { media_config.enable_dscp = enable; } @@ -305,6 +317,9 @@ class PeerConnectionInterface : public rtc::RefCountInterface { // If set to true, this means the ICE transport should presume TURN-to-TURN // candidate pairs will succeed, even before a binding response is received. bool presume_writable_when_fully_relayed = false; + // If true, ICE role is redetermined when peerconnection sets a local + // transport description that indicates an ICE restart. + bool redetermine_role_on_ice_restart = true; }; struct RTCOfferAnswerOptions { diff --git a/webrtc/api/peerconnectioninterface_unittest.cc b/webrtc/api/peerconnectioninterface_unittest.cc index 0b24fcb7cf..d9c8af0b4c 100644 --- a/webrtc/api/peerconnectioninterface_unittest.cc +++ b/webrtc/api/peerconnectioninterface_unittest.cc @@ -568,9 +568,11 @@ class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { } cricket::TransportController* CreateTransportController( - cricket::PortAllocator* port_allocator) override { + cricket::PortAllocator* port_allocator, + bool redetermine_role_on_ice_restart) override { transport_controller = new cricket::TransportController( - rtc::Thread::Current(), rtc::Thread::Current(), port_allocator); + rtc::Thread::Current(), rtc::Thread::Current(), port_allocator, + redetermine_role_on_ice_restart); return transport_controller; }