From 137ece4ac300549691fe3dabd9ff28d730c47ec0 Mon Sep 17 00:00:00 2001 From: "tommi@webrtc.org" Date: Thu, 25 Aug 2011 14:18:25 +0000 Subject: [PATCH] * Make GetReadyState accessible via the PeerConnection interface. * Update PeerConnection implementations to include "virtual" in the method declarations. * Add a check for a valid signaling thread in webrtcsession.cc. Review URL: http://webrtc-codereview.appspot.com/137001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@445 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../source/talk/app/webrtc/peerconnection.h | 11 +++++++ .../talk/app/webrtc/peerconnection_impl.h | 33 ++++++++----------- .../talk/app/webrtc/peerconnection_proxy.cc | 14 ++++++++ .../talk/app/webrtc/peerconnection_proxy.h | 27 +++++++-------- .../source/talk/app/webrtc/webrtcsession.cc | 10 ++++-- 5 files changed, 59 insertions(+), 36 deletions(-) diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.h b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.h index ee37ad8c39..f4ce94835f 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.h @@ -71,6 +71,13 @@ class PeerConnectionObserver { class PeerConnection { public: + enum ReadyState { + NEW = 0, + NEGOTIATING, + ACTIVE, + CLOSED, + }; + virtual ~PeerConnection() {} // Register a listener @@ -121,6 +128,10 @@ class PeerConnection { // For standalone app, cam_device is the camera name. It will try to // set the default capture device when cam_device is "". virtual bool SetVideoCapture(const std::string& cam_device) = 0; + + // Returns the state of the PeerConnection object. See the ReadyState + // enum for valid values. + virtual ReadyState GetReadyState() = 0; }; } // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl.h b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl.h index 17a1771a26..02f6a4b549 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl.h @@ -54,26 +54,20 @@ class PeerConnectionImpl : public PeerConnection, talk_base::Thread* signaling_thread); virtual ~PeerConnectionImpl(); - enum ReadyState { - NEW = 0, - NEGOTIATING, - ACTIVE, - CLOSED, - }; - // PeerConnection interfaces - void RegisterObserver(PeerConnectionObserver* observer); - bool SignalingMessage(const std::string& msg); - bool AddStream(const std::string& stream_id, bool video); - bool RemoveStream(const std::string& stream_id); - bool Connect(); - bool Close(); - bool SetAudioDevice(const std::string& wave_in_device, - const std::string& wave_out_device, int opts); - bool SetLocalVideoRenderer(cricket::VideoRenderer* renderer); - bool SetVideoRenderer(const std::string& stream_id, - cricket::VideoRenderer* renderer); - bool SetVideoCapture(const std::string& cam_device); + virtual void RegisterObserver(PeerConnectionObserver* observer); + virtual bool SignalingMessage(const std::string& msg); + virtual bool AddStream(const std::string& stream_id, bool video); + virtual bool RemoveStream(const std::string& stream_id); + virtual bool Connect(); + virtual bool Close(); + virtual bool SetAudioDevice(const std::string& wave_in_device, + const std::string& wave_out_device, int opts); + virtual bool SetLocalVideoRenderer(cricket::VideoRenderer* renderer); + virtual bool SetVideoRenderer(const std::string& stream_id, + cricket::VideoRenderer* renderer); + virtual bool SetVideoCapture(const std::string& cam_device); + virtual ReadyState GetReadyState(); cricket::ChannelManager* channel_manager() { return channel_manager_; @@ -91,7 +85,6 @@ class PeerConnectionImpl : public PeerConnection, bool Init(); private: - ReadyState GetReadyState(); bool ParseConfigString(const std::string& config, talk_base::SocketAddress* stun_addr); void SendRemoveSignal(WebRtcSession* session); diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.cc b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.cc index ec0e8bf21c..072503b316 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.cc @@ -45,6 +45,7 @@ enum { MSG_WEBRTC_SETVIDEOCAPTURE, MSG_WEBRTC_SETVIDEORENDERER, MSG_WEBRTC_SIGNALINGMESSAGE, + MSG_WEBRTC_GETREADYSTATE, }; struct AddStreamParams : public talk_base::MessageData { @@ -194,6 +195,13 @@ bool PeerConnectionProxy::SetVideoCapture(const std::string& cam_device) { return (Send(MSG_WEBRTC_SETVIDEOCAPTURE, ¶ms) && params.result); } +PeerConnection::ReadyState PeerConnectionProxy::GetReadyState() { + PeerConnection::ReadyState ready_state = NEW; + Send(MSG_WEBRTC_GETREADYSTATE, + reinterpret_cast(&ready_state)); + return ready_state; +} + bool PeerConnectionProxy::Connect() { ResultParams params; return (Send(MSG_WEBRTC_CONNECT, ¶ms) && params.result); @@ -254,6 +262,12 @@ void PeerConnectionProxy::OnMessage(talk_base::Message* message) { params->cam_device); break; } + case MSG_WEBRTC_GETREADYSTATE: { + PeerConnection::ReadyState* ready_state = + reinterpret_cast(data); + *ready_state = peerconnection_impl_->GetReadyState(); + break; + } case MSG_WEBRTC_SETVIDEORENDERER: { SetVideoRendererParams* params = reinterpret_cast(data); diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.h b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.h index d8a14524a2..74a5776306 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.h @@ -51,19 +51,20 @@ class PeerConnectionProxy : public PeerConnection, talk_base::Thread* signaling_thread); virtual ~PeerConnectionProxy(); - // PeerConnection interfaces - void RegisterObserver(PeerConnectionObserver* observer); - bool SignalingMessage(const std::string& msg); - bool AddStream(const std::string& stream_id, bool video); - bool RemoveStream(const std::string& stream_id); - bool Connect(); - bool Close(); - bool SetAudioDevice(const std::string& wave_in_device, - const std::string& wave_out_device, int opts); - bool SetLocalVideoRenderer(cricket::VideoRenderer* renderer); - bool SetVideoRenderer(const std::string& stream_id, - cricket::VideoRenderer* renderer); - bool SetVideoCapture(const std::string& cam_device); + // PeerConnection interface implementation. + virtual void RegisterObserver(PeerConnectionObserver* observer); + virtual bool SignalingMessage(const std::string& msg); + virtual bool AddStream(const std::string& stream_id, bool video); + virtual bool RemoveStream(const std::string& stream_id); + virtual bool Connect(); + virtual bool Close(); + virtual bool SetAudioDevice(const std::string& wave_in_device, + const std::string& wave_out_device, int opts); + virtual bool SetLocalVideoRenderer(cricket::VideoRenderer* renderer); + virtual bool SetVideoRenderer(const std::string& stream_id, + cricket::VideoRenderer* renderer); + virtual bool SetVideoCapture(const std::string& cam_device); + virtual ReadyState GetReadyState(); private: diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/webrtcsession.cc b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcsession.cc index 7b86b52410..51df9270f0 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc/webrtcsession.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcsession.cc @@ -93,10 +93,14 @@ WebRtcSession::~WebRtcSession() { } bool WebRtcSession::Initiate() { - signaling_thread_->Send(this, MSG_WEBRTC_CREATE_TRANSPORT, NULL); - if (transport_ == NULL) { + if (signaling_thread_ == NULL) return false; - } + + signaling_thread_->Send(this, MSG_WEBRTC_CREATE_TRANSPORT, NULL); + + if (transport_ == NULL) + return false; + transport_->set_allow_local_ips(true); // start transports