diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc index 43d2b51e88..67d51bd9cb 100644 --- a/talk/app/webrtc/java/jni/peerconnection_jni.cc +++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc @@ -1383,13 +1383,10 @@ static void JavaIceServersToJsepIceServers( CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; } -JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnection)( - JNIEnv *jni, jclass, jlong factory, jobject j_rtc_config, - jobject j_constraints, jlong observer_p) { - rtc::scoped_refptr f( - reinterpret_cast( - factoryFromJava(factory))); - +static void JavaRTCConfigurationToJsepRTCConfiguration( + JNIEnv* jni, + jobject j_rtc_config, + PeerConnectionInterface::RTCConfiguration* rtc_config) { jclass j_rtc_config_class = GetObjectClass(jni, j_rtc_config); jfieldID j_ice_transports_type_id = GetFieldID( @@ -1428,34 +1425,46 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnection)( jfieldID j_ice_connection_receiving_timeout_id = GetFieldID(jni, j_rtc_config_class, "iceConnectionReceivingTimeout", "I"); - jfieldID j_key_type_id = GetFieldID(jni, j_rtc_config_class, "keyType", - "Lorg/webrtc/PeerConnection$KeyType;"); - jobject j_key_type = GetObjectField(jni, j_rtc_config, j_key_type_id); - jfieldID j_continual_gathering_policy_id = GetFieldID(jni, j_rtc_config_class, "continualGatheringPolicy", "Lorg/webrtc/PeerConnection$ContinualGatheringPolicy;"); jobject j_continual_gathering_policy = GetObjectField(jni, j_rtc_config, j_continual_gathering_policy_id); - PeerConnectionInterface::RTCConfiguration rtc_config; - rtc_config.type = + rtc_config->type = JavaIceTransportsTypeToNativeType(jni, j_ice_transports_type); - rtc_config.bundle_policy = JavaBundlePolicyToNativeType(jni, j_bundle_policy); - rtc_config.rtcp_mux_policy = + rtc_config->bundle_policy = + JavaBundlePolicyToNativeType(jni, j_bundle_policy); + rtc_config->rtcp_mux_policy = JavaRtcpMuxPolicyToNativeType(jni, j_rtcp_mux_policy); - rtc_config.tcp_candidate_policy = + rtc_config->tcp_candidate_policy = JavaTcpCandidatePolicyToNativeType(jni, j_tcp_candidate_policy); - JavaIceServersToJsepIceServers(jni, j_ice_servers, &rtc_config.servers); - rtc_config.audio_jitter_buffer_max_packets = + JavaIceServersToJsepIceServers(jni, j_ice_servers, &rtc_config->servers); + rtc_config->audio_jitter_buffer_max_packets = GetIntField(jni, j_rtc_config, j_audio_jitter_buffer_max_packets_id); - rtc_config.audio_jitter_buffer_fast_accelerate = GetBooleanField( + rtc_config->audio_jitter_buffer_fast_accelerate = GetBooleanField( jni, j_rtc_config, j_audio_jitter_buffer_fast_accelerate_id); - rtc_config.ice_connection_receiving_timeout = + rtc_config->ice_connection_receiving_timeout = GetIntField(jni, j_rtc_config, j_ice_connection_receiving_timeout_id); - rtc_config.continual_gathering_policy = + rtc_config->continual_gathering_policy = JavaContinualGatheringPolicyToNativeType( jni, j_continual_gathering_policy); +} + +JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnection)( + JNIEnv *jni, jclass, jlong factory, jobject j_rtc_config, + jobject j_constraints, jlong observer_p) { + rtc::scoped_refptr f( + reinterpret_cast( + factoryFromJava(factory))); + + PeerConnectionInterface::RTCConfiguration rtc_config; + JavaRTCConfigurationToJsepRTCConfiguration(jni, j_rtc_config, &rtc_config); + + jclass j_rtc_config_class = GetObjectClass(jni, j_rtc_config); + jfieldID j_key_type_id = GetFieldID(jni, j_rtc_config_class, "keyType", + "Lorg/webrtc/PeerConnection$KeyType;"); + jobject j_key_type = GetObjectField(jni, j_rtc_config, j_key_type_id); // Create ECDSA certificate. if (JavaKeyTypeToNativeType(jni, j_key_type) == rtc::KT_ECDSA) { @@ -1588,13 +1597,11 @@ JOW(void, PeerConnection_setRemoteDescription)( observer, JavaSdpToNativeSdp(jni, j_sdp)); } -JOW(jboolean, PeerConnection_updateIce)( - JNIEnv* jni, jobject j_pc, jobject j_ice_servers, jobject j_constraints) { - PeerConnectionInterface::IceServers ice_servers; - JavaIceServersToJsepIceServers(jni, j_ice_servers, &ice_servers); - scoped_ptr constraints( - new ConstraintsWrapper(jni, j_constraints)); - return ExtractNativePC(jni, j_pc)->UpdateIce(ice_servers, constraints.get()); +JOW(jboolean, PeerConnection_setConfiguration)( + JNIEnv* jni, jobject j_pc, jobject j_rtc_config) { + PeerConnectionInterface::RTCConfiguration rtc_config; + JavaRTCConfigurationToJsepRTCConfiguration(jni, j_rtc_config, &rtc_config); + return ExtractNativePC(jni, j_pc)->SetConfiguration(rtc_config); } JOW(jboolean, PeerConnection_nativeAddIceCandidate)( diff --git a/talk/app/webrtc/java/src/org/webrtc/PeerConnection.java b/talk/app/webrtc/java/src/org/webrtc/PeerConnection.java index f09c58fc1f..40ac615dcc 100644 --- a/talk/app/webrtc/java/src/org/webrtc/PeerConnection.java +++ b/talk/app/webrtc/java/src/org/webrtc/PeerConnection.java @@ -197,8 +197,7 @@ public class PeerConnection { public native void setRemoteDescription( SdpObserver observer, SessionDescription sdp); - public native boolean updateIce( - List iceServers, MediaConstraints constraints); + public native boolean setConfiguration(RTCConfiguration config); public boolean addIceCandidate(IceCandidate candidate) { return nativeAddIceCandidate( diff --git a/talk/app/webrtc/objc/RTCPeerConnection.mm b/talk/app/webrtc/objc/RTCPeerConnection.mm index 0d30acc0eb..44d39cb090 100644 --- a/talk/app/webrtc/objc/RTCPeerConnection.mm +++ b/talk/app/webrtc/objc/RTCPeerConnection.mm @@ -208,13 +208,9 @@ class RTCStatsObserver : public StatsObserver { self.peerConnection->SetRemoteDescription(observer, sdp.sessionDescription); } -- (BOOL)updateICEServers:(NSArray*)servers - constraints:(RTCMediaConstraints*)constraints { - webrtc::PeerConnectionInterface::IceServers iceServers; - for (RTCICEServer* server in servers) { - iceServers.push_back(server.iceServer); - } - return self.peerConnection->UpdateIce(iceServers, constraints.constraints); +- (BOOL)setConfiguration:(RTCConfiguration *)configuration { + return self.peerConnection->SetConfiguration( + configuration.nativeConfiguration); } - (RTCSessionDescription*)localDescription { diff --git a/talk/app/webrtc/objc/public/RTCPeerConnection.h b/talk/app/webrtc/objc/public/RTCPeerConnection.h index 7177fd6c21..a13ed3ecc3 100644 --- a/talk/app/webrtc/objc/public/RTCPeerConnection.h +++ b/talk/app/webrtc/objc/public/RTCPeerConnection.h @@ -27,6 +27,7 @@ #import "RTCPeerConnectionDelegate.h" +@class RTCConfiguration; @class RTCDataChannel; @class RTCDataChannelInit; @class RTCICECandidate; @@ -97,10 +98,12 @@ setRemoteDescriptionWithDelegate:(id)delegate sessionDescription:(RTCSessionDescription *)sdp; -// Restarts or updates the ICE Agent process of gathering local candidates -// and pinging remote candidates. -- (BOOL)updateICEServers:(NSArray *)servers - constraints:(RTCMediaConstraints *)constraints; +// Sets the PeerConnection's global configuration to |configuration|. +// 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 +// new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies +// cannot be changed with this method. +- (BOOL)setConfiguration:(RTCConfiguration *)configuration; // Provides a remote candidate to the ICE Agent. - (BOOL)addICECandidate:(RTCICECandidate *)candidate; diff --git a/talk/app/webrtc/peerconnection.cc b/talk/app/webrtc/peerconnection.cc index 961ba261a8..36875a6f93 100644 --- a/talk/app/webrtc/peerconnection.cc +++ b/talk/app/webrtc/peerconnection.cc @@ -680,12 +680,7 @@ void PeerConnection::PostSetSessionDescriptionFailure( signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_FAILED, msg); } -bool PeerConnection::UpdateIce(const IceServers& configuration, - const MediaConstraintsInterface* constraints) { - return false; -} - -bool PeerConnection::UpdateIce(const RTCConfiguration& config) { +bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { if (port_allocator_) { std::vector stuns; std::vector turns; @@ -702,7 +697,8 @@ bool PeerConnection::UpdateIce(const RTCConfiguration& config) { rtc::SocketAddress stun_addr; if (!stun_hosts.empty()) { stun_addr = stun_hosts.front(); - LOG(LS_INFO) << "UpdateIce: StunServer Address: " << stun_addr.ToString(); + LOG(LS_INFO) << "SetConfiguration: StunServer Address: " + << stun_addr.ToString(); } for (size_t i = 0; i < turns.size(); ++i) { @@ -714,7 +710,7 @@ bool PeerConnection::UpdateIce(const RTCConfiguration& config) { relay_server.ports.push_back(cricket::ProtocolAddress( turns[i].server, protocol, turns[i].secure)); relay_server.credentials = credentials; - LOG(LS_INFO) << "UpdateIce: TurnServer Address: " + LOG(LS_INFO) << "SetConfiguration: TurnServer Address: " << turns[i].server.ToString(); } else { LOG(LS_WARNING) << "Ignoring TURN server " << turns[i].server << ". " diff --git a/talk/app/webrtc/peerconnection.h b/talk/app/webrtc/peerconnection.h index 8caa821081..e996132df0 100644 --- a/talk/app/webrtc/peerconnection.h +++ b/talk/app/webrtc/peerconnection.h @@ -65,64 +65,61 @@ class PeerConnection : public PeerConnectionInterface, PortAllocatorFactoryInterface* allocator_factory, rtc::scoped_ptr dtls_identity_store, PeerConnectionObserver* observer); - virtual rtc::scoped_refptr local_streams(); - virtual rtc::scoped_refptr remote_streams(); - virtual bool AddStream(MediaStreamInterface* local_stream); - virtual void RemoveStream(MediaStreamInterface* local_stream); + rtc::scoped_refptr local_streams() override; + rtc::scoped_refptr remote_streams() override; + bool AddStream(MediaStreamInterface* local_stream) override; + void RemoveStream(MediaStreamInterface* local_stream) override; - virtual rtc::scoped_refptr CreateDtmfSender( - AudioTrackInterface* track); + rtc::scoped_refptr CreateDtmfSender( + AudioTrackInterface* track) override; std::vector> GetSenders() const override; std::vector> GetReceivers() const override; - virtual rtc::scoped_refptr CreateDataChannel( + rtc::scoped_refptr CreateDataChannel( const std::string& label, - const DataChannelInit* config); - virtual bool GetStats(StatsObserver* observer, - webrtc::MediaStreamTrackInterface* track, - StatsOutputLevel level); + const DataChannelInit* config) override; + bool GetStats(StatsObserver* observer, + webrtc::MediaStreamTrackInterface* track, + StatsOutputLevel level) override; - virtual SignalingState signaling_state(); + SignalingState signaling_state() override; // TODO(bemasc): Remove ice_state() when callers are removed. - virtual IceState ice_state(); - virtual IceConnectionState ice_connection_state(); - virtual IceGatheringState ice_gathering_state(); + IceState ice_state() override; + IceConnectionState ice_connection_state() override; + IceGatheringState ice_gathering_state() override; - virtual const SessionDescriptionInterface* local_description() const; - virtual const SessionDescriptionInterface* remote_description() const; + const SessionDescriptionInterface* local_description() const override; + const SessionDescriptionInterface* remote_description() const override; // JSEP01 - virtual void CreateOffer(CreateSessionDescriptionObserver* observer, - const MediaConstraintsInterface* constraints); - virtual void CreateOffer(CreateSessionDescriptionObserver* observer, - const RTCOfferAnswerOptions& options); - virtual void CreateAnswer(CreateSessionDescriptionObserver* observer, - const MediaConstraintsInterface* constraints); - virtual void SetLocalDescription(SetSessionDescriptionObserver* observer, - SessionDescriptionInterface* desc); - virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer, - SessionDescriptionInterface* desc); - // TODO(mallinath) : Deprecated version, remove after all clients are updated. - virtual bool UpdateIce(const IceServers& configuration, - const MediaConstraintsInterface* constraints); - virtual bool UpdateIce( - const PeerConnectionInterface::RTCConfiguration& config); - virtual bool AddIceCandidate(const IceCandidateInterface* candidate); + void CreateOffer(CreateSessionDescriptionObserver* observer, + const MediaConstraintsInterface* constraints) override; + void CreateOffer(CreateSessionDescriptionObserver* observer, + const RTCOfferAnswerOptions& options) override; + void CreateAnswer(CreateSessionDescriptionObserver* observer, + const MediaConstraintsInterface* constraints) override; + void SetLocalDescription(SetSessionDescriptionObserver* observer, + SessionDescriptionInterface* desc) override; + void SetRemoteDescription(SetSessionDescriptionObserver* observer, + SessionDescriptionInterface* desc) override; + bool SetConfiguration( + const PeerConnectionInterface::RTCConfiguration& config) override; + bool AddIceCandidate(const IceCandidateInterface* candidate) override; - virtual void RegisterUMAObserver(UMAObserver* observer); + void RegisterUMAObserver(UMAObserver* observer) override; - virtual void Close(); + void Close() override; protected: - virtual ~PeerConnection(); + ~PeerConnection() override; private: // Implements MessageHandler. - virtual void OnMessage(rtc::Message* msg); + void OnMessage(rtc::Message* msg) override; // Implements MediaStreamSignalingObserver. void OnAddRemoteStream(MediaStreamInterface* stream) override; diff --git a/talk/app/webrtc/peerconnectioninterface.h b/talk/app/webrtc/peerconnectioninterface.h index 734c2d09d3..f301bafdff 100644 --- a/talk/app/webrtc/peerconnectioninterface.h +++ b/talk/app/webrtc/peerconnectioninterface.h @@ -379,8 +379,22 @@ class PeerConnectionInterface : public rtc::RefCountInterface { SessionDescriptionInterface* desc) = 0; // Restarts or updates the ICE Agent process of gathering local candidates // and pinging remote candidates. + // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration. virtual bool UpdateIce(const IceServers& configuration, - const MediaConstraintsInterface* constraints) = 0; + const MediaConstraintsInterface* constraints) { + return false; + } + // 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 + // new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies + // cannot be changed with this method. + // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of + // PeerConnectionInterface implement it. + virtual bool SetConfiguration( + const PeerConnectionInterface::RTCConfiguration& config) { + return false; + } // Provides a remote candidate to the ICE Agent. // A copy of the |candidate| will be created and added to the remote // description. So the caller of this method still has the ownership of the diff --git a/talk/app/webrtc/peerconnectionproxy.h b/talk/app/webrtc/peerconnectionproxy.h index d9af8d9ab6..d207fbbdd8 100644 --- a/talk/app/webrtc/peerconnectionproxy.h +++ b/talk/app/webrtc/peerconnectionproxy.h @@ -62,8 +62,9 @@ BEGIN_PROXY_MAP(PeerConnection) SessionDescriptionInterface*) PROXY_METHOD2(void, SetRemoteDescription, SetSessionDescriptionObserver*, SessionDescriptionInterface*) - PROXY_METHOD2(bool, UpdateIce, const IceServers&, - const MediaConstraintsInterface*) + PROXY_METHOD1(bool, + SetConfiguration, + const PeerConnectionInterface::RTCConfiguration&); PROXY_METHOD1(bool, AddIceCandidate, const IceCandidateInterface*) PROXY_METHOD1(void, RegisterUMAObserver, UMAObserver*) PROXY_METHOD0(SignalingState, signaling_state)