diff --git a/third_party_mods/libjingle/libjingle.gyp b/third_party_mods/libjingle/libjingle.gyp index 8ef849d0e7..fb3e1e7327 100644 --- a/third_party_mods/libjingle/libjingle.gyp +++ b/third_party_mods/libjingle/libjingle.gyp @@ -561,6 +561,8 @@ '<(libjingle_mods)/source/talk/app/webrtc/peerconnectionimpl_callbacks.h', '<(libjingle_mods)/source/talk/app/webrtc/peerconnection_impl.cc', '<(libjingle_mods)/source/talk/app/webrtc/peerconnection_impl.h', + '<(libjingle_mods)/source/talk/app/webrtc/peerconnection_proxy.cc', + '<(libjingle_mods)/source/talk/app/webrtc/peerconnection_proxy.h', '<(libjingle_mods)/source/talk/app/webrtc/webrtcsession.cc', '<(libjingle_mods)/source/talk/app/webrtc/webrtcsession.h', '<(libjingle_mods)/source/talk/app/webrtc/webrtc_json.cc', diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.cc b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.cc index 896c53224d..df4221e07c 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.cc @@ -25,7 +25,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "talk/app/webrtc/peerconnection_impl.h" +#include "talk/app/webrtc/peerconnection_proxy.h" namespace webrtc { @@ -35,14 +35,14 @@ PeerConnection* PeerConnection::Create(const std::string& config, talk_base::Thread* worker_thread, talk_base::Thread* signaling_thread, cricket::DeviceManager* device_manager) { - return new PeerConnectionImpl(config, port_allocator, media_engine, + return new PeerConnectionProxy(config, port_allocator, media_engine, worker_thread, signaling_thread, device_manager); } PeerConnection* PeerConnection::Create(const std::string& config, cricket::PortAllocator* port_allocator, talk_base::Thread* worker_thread) { - return new PeerConnectionImpl(config, port_allocator, worker_thread); + return new PeerConnectionProxy(config, port_allocator, worker_thread); } } // namespace webrtc 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 29a1d6a4d4..576f6e4aed 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection.h @@ -116,7 +116,7 @@ class PeerConnection { // TODO(ronghuawu): Add an event such as onclose, or onreadystatechanged // when the readystate reaches the closed state (no more streams in the // peerconnection object. - virtual void Close() = 0; + virtual bool Close() = 0; // Set the audio input & output devices based on the given device name. // An empty device name means to use the default audio device. diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl.cc b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl.cc index c931d5ae43..3a0e318b03 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl.cc @@ -25,19 +25,15 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include - #include "talk/app/webrtc/peerconnection_impl.h" +#include "talk/app/webrtc/webrtc_json.h" +#include "talk/app/webrtc/webrtcsession.h" #include "talk/base/basicpacketsocketfactory.h" #include "talk/base/helpers.h" -#include "talk/base/stringencode.h" #include "talk/base/logging.h" +#include "talk/base/stringencode.h" #include "talk/p2p/client/basicportallocator.h" -#include "talk/app/webrtc/webrtcsession.h" -#include "talk/app/webrtc/webrtc_json.h" - -using talk_base::ThreadManager; namespace webrtc { @@ -47,88 +43,6 @@ static const size_t kConfigTokens = 2; // The default stun port. static const int kDefaultStunPort = 3478; -enum { - MSG_WEBRTC_ADDSTREAM = 1, - MSG_WEBRTC_REMOVESTREAM, - MSG_WEBRTC_SIGNALINGMESSAGE, - MSG_WEBRTC_SETAUDIODEVICE, - MSG_WEBRTC_SETLOCALRENDERER, - MSG_WEBRTC_SETVIDEORENDERER, - MSG_WEBRTC_SETVIDEOCAPTURE, - MSG_WEBRTC_CONNECT, - MSG_WEBRTC_CLOSE, - MSG_WEBRTC_INIT_CHANNELMANAGER, - MSG_WEBRTC_RELEASE, -}; - -struct AddStreamParams : public talk_base::MessageData { - AddStreamParams(const std::string& stream_id, bool video) - : stream_id(stream_id), video(video) {} - - std::string stream_id; - bool video; - bool result; -}; - -struct RemoveStreamParams : public talk_base::MessageData { - explicit RemoveStreamParams(const std::string& stream_id) - : stream_id(stream_id) {} - - std::string stream_id; - bool result; -}; - -struct SignalingMsgParams : public talk_base::MessageData { - explicit SignalingMsgParams(const std::string& signaling_message) - : signaling_message(signaling_message) {} - - std::string signaling_message; - bool result; -}; - -struct SetAudioDeviceParams : public talk_base::MessageData { - SetAudioDeviceParams(const std::string& wave_in_device, - const std::string& wave_out_device, - int opts) - : wave_in_device(wave_in_device), wave_out_device(wave_out_device), - opts(opts) {} - - std::string wave_in_device; - std::string wave_out_device; - int opts; - bool result; -}; - -struct SetLocalRendererParams : public talk_base::MessageData { - explicit SetLocalRendererParams(cricket::VideoRenderer* renderer) - : renderer(renderer) {} - - cricket::VideoRenderer* renderer; - bool result; -}; - -struct SetVideoRendererParams : public talk_base::MessageData { - SetVideoRendererParams(const std::string& stream_id, - cricket::VideoRenderer* renderer) - : stream_id(stream_id), renderer(renderer) {} - - std::string stream_id; - cricket::VideoRenderer* renderer; - bool result; -}; - -struct SetVideoCaptureParams : public talk_base::MessageData { - explicit SetVideoCaptureParams(const std::string& cam_device) - : cam_device(cam_device) {} - - std::string cam_device; - bool result; -}; - -struct ConnectParams : public talk_base::MessageData { - bool result; -}; - PeerConnectionImpl::PeerConnectionImpl(const std::string& config, cricket::PortAllocator* port_allocator, cricket::MediaEngine* media_engine, @@ -165,12 +79,6 @@ PeerConnectionImpl::PeerConnectionImpl(const std::string& config, } PeerConnectionImpl::~PeerConnectionImpl() { - signaling_thread_->Send(this, MSG_WEBRTC_RELEASE); - // Signaling thread must be destroyed by the application. - signaling_thread_ = NULL; -} - -void PeerConnectionImpl::Release_s() { session_.reset(); channel_manager_.reset(); } @@ -195,8 +103,23 @@ bool PeerConnectionImpl::Init() { } } - signaling_thread_->Post(this, MSG_WEBRTC_INIT_CHANNELMANAGER); - return true; + // create cricket::ChannelManager object + ASSERT(worker_thread_ != NULL); + if (media_engine_ && device_manager_) { + channel_manager_.reset(new cricket::ChannelManager( + media_engine_, device_manager_, worker_thread_)); + } else { + channel_manager_.reset(new cricket::ChannelManager(worker_thread_)); + } + + initialized_ = channel_manager_->Init(); + + if (event_callback_) { + // TODO(ronghuawu): OnInitialized is no longer needed. + if (initialized_) + event_callback_->OnInitialized(); + } + return initialized_; } bool PeerConnectionImpl::ParseConfigString( @@ -255,18 +178,11 @@ void PeerConnectionImpl::RegisterObserver(PeerConnectionObserver* observer) { bool PeerConnectionImpl::SignalingMessage( const std::string& signaling_message) { - SignalingMsgParams* msg = new SignalingMsgParams(signaling_message); - signaling_thread_->Post(this, MSG_WEBRTC_SIGNALINGMESSAGE, msg); - return true; -} - -bool PeerConnectionImpl::SignalingMessage_s(const std::string& msg) { // Deserialize signaling message cricket::SessionDescription* incoming_sdp = NULL; std::vector candidates; - if (!ParseJSONSignalingMessage(msg, incoming_sdp, &candidates)) { - if (event_callback_) - event_callback_->OnError(); + if (!ParseJSONSignalingMessage(signaling_message, + incoming_sdp, &candidates)) { return false; } @@ -277,16 +193,16 @@ bool PeerConnectionImpl::SignalingMessage_s(const std::string& msg) { talk_base::CreateRandomString(8, &sid); std::string direction("r"); session_.reset(CreateMediaSession(sid, direction)); - ASSERT(session_.get() != NULL); + if (session_.get() == NULL) { + ASSERT(false && "failed to initialize a session"); + return false; + } incoming_ = true; ret = session_->OnInitiateMessage(incoming_sdp, candidates); } else { ret = session_->OnRemoteDescription(incoming_sdp, candidates); } - if (!ret && event_callback_) - event_callback_->OnError(); - return ret; } @@ -306,7 +222,7 @@ WebRtcSession* PeerConnectionImpl::CreateMediaSession( &PeerConnectionImpl::OnAddStream); session->SignalRemoveStream.connect( this, - &PeerConnectionImpl::OnRemoveStream2); + &PeerConnectionImpl::OnRemoveStream); session->SignalRtcMediaChannelCreated.connect( this, &PeerConnectionImpl::OnRtcMediaChannelCreated); @@ -324,10 +240,10 @@ WebRtcSession* PeerConnectionImpl::CreateMediaSession( } void PeerConnectionImpl::SendRemoveSignal(WebRtcSession* session) { - if (event_callback_) { - std::string message; - if (GetJSONSignalingMessage(session->remote_description(), - session->local_candidates(), &message)) { + std::string message; + if (GetJSONSignalingMessage(session->remote_description(), + session->local_candidates(), &message)) { + if (event_callback_) { event_callback_->OnSignalingMessage(message); // TODO(ronghuawu): Notify the client when the PeerConnection object // doesn't have any streams. Something like the onreadystatechanged @@ -337,12 +253,6 @@ void PeerConnectionImpl::SendRemoveSignal(WebRtcSession* session) { } bool PeerConnectionImpl::AddStream(const std::string& stream_id, bool video) { - AddStreamParams* params = new AddStreamParams(stream_id, video); - signaling_thread_->Post(this, MSG_WEBRTC_ADDSTREAM, params, true); - return true; -} - -bool PeerConnectionImpl::AddStream_s(const std::string& stream_id, bool video) { if (!session_.get()) { // if session doesn't exist then this should be an outgoing call std::string sid; @@ -370,16 +280,7 @@ bool PeerConnectionImpl::AddStream_s(const std::string& stream_id, bool video) { } bool PeerConnectionImpl::RemoveStream(const std::string& stream_id) { - RemoveStreamParams* params = new RemoveStreamParams(stream_id); - signaling_thread_->Post(this, MSG_WEBRTC_REMOVESTREAM, params); - return true; -} - -bool PeerConnectionImpl::RemoveStream_s(const std::string& stream_id) { if (!session_.get()) { - if (event_callback_) { - event_callback_->OnError(); - } return false; } return session_->RemoveStream(stream_id); @@ -408,15 +309,6 @@ void PeerConnectionImpl::OnFailedCall() { bool PeerConnectionImpl::SetAudioDevice(const std::string& wave_in_device, const std::string& wave_out_device, int opts) { - SetAudioDeviceParams* params = new SetAudioDeviceParams(wave_in_device, - wave_out_device, opts); - signaling_thread_->Post(this, MSG_WEBRTC_SETAUDIODEVICE, params); - return true; -} - -bool PeerConnectionImpl::SetAudioDevice_s(const std::string& wave_in_device, - const std::string& wave_out_device, - int opts) { return channel_manager_->SetAudioOptions(wave_in_device, wave_out_device, opts); @@ -424,59 +316,35 @@ bool PeerConnectionImpl::SetAudioDevice_s(const std::string& wave_in_device, bool PeerConnectionImpl::SetLocalVideoRenderer( cricket::VideoRenderer* renderer) { - SetLocalRendererParams* params = new SetLocalRendererParams(renderer); - signaling_thread_->Post(this, MSG_WEBRTC_SETLOCALRENDERER, params); - return true; -} - -bool PeerConnectionImpl::SetLocalVideoRenderer_s( - cricket::VideoRenderer* renderer) { return channel_manager_->SetLocalRenderer(renderer); } bool PeerConnectionImpl::SetVideoRenderer(const std::string& stream_id, cricket::VideoRenderer* renderer) { - SetVideoRendererParams* params = new SetVideoRendererParams(stream_id, - renderer); - signaling_thread_->Post(this, MSG_WEBRTC_SETVIDEORENDERER, params); - return true; -} - -bool PeerConnectionImpl::SetVideoRenderer_s(const std::string& stream_id, - cricket::VideoRenderer* renderer) { if (!session_.get()) { - if (event_callback_) { - event_callback_->OnError(); - } return false; } return session_->SetVideoRenderer(stream_id, renderer); } bool PeerConnectionImpl::SetVideoCapture(const std::string& cam_device) { - SetVideoCaptureParams* params = new SetVideoCaptureParams(cam_device); - signaling_thread_->Post(this, MSG_WEBRTC_SETVIDEOCAPTURE, params); - return true; -} - -bool PeerConnectionImpl::SetVideoCapture_s(const std::string& cam_device) { return channel_manager_->SetVideoOptions(cam_device); } bool PeerConnectionImpl::Connect() { - signaling_thread_->Post(this, MSG_WEBRTC_CONNECT); - return true; + if (!session_.get()) { + return false; + } + return session_->Connect(); } -bool PeerConnectionImpl::Connect_s() { +bool PeerConnectionImpl::Close() { if (!session_.get()) { - if (event_callback_) { - event_callback_->OnError(); - } return false; } - return session_->Connect(); + session_->RemoveAllStreams(); + return true; } void PeerConnectionImpl::OnAddStream(const std::string& stream_id, @@ -486,7 +354,7 @@ void PeerConnectionImpl::OnAddStream(const std::string& stream_id, } } -void PeerConnectionImpl::OnRemoveStream2(const std::string& stream_id, +void PeerConnectionImpl::OnRemoveStream(const std::string& stream_id, bool video) { if (event_callback_) { event_callback_->OnRemoveStream(stream_id, video); @@ -500,122 +368,4 @@ void PeerConnectionImpl::OnRtcMediaChannelCreated(const std::string& stream_id, } } -void PeerConnectionImpl::CreateChannelManager_s() { - // create cricket::ChannelManager object - ASSERT(worker_thread_ != NULL); - if (media_engine_ && device_manager_) { - channel_manager_.reset(new cricket::ChannelManager( - media_engine_, device_manager_, worker_thread_)); - } else { - channel_manager_.reset(new cricket::ChannelManager(worker_thread_)); - } - - initialized_ = channel_manager_->Init(); - - if (event_callback_) { - if (initialized_) - event_callback_->OnInitialized(); - else - event_callback_->OnError(); - } -} - -void PeerConnectionImpl::Close() { - signaling_thread_->Post(this, MSG_WEBRTC_CLOSE); -} - -void PeerConnectionImpl::Close_s() { - if (!session_.get()) { - if (event_callback_) - event_callback_->OnError(); - return; - } - - session_->RemoveAllStreams(); -} - -void PeerConnectionImpl::OnMessage(talk_base::Message* message) { - talk_base::MessageData* data = message->pdata; - switch (message->message_id) { - case MSG_WEBRTC_ADDSTREAM: { - AddStreamParams* params = reinterpret_cast(data); - params->result = AddStream_s(params->stream_id, params->video); - delete params; - break; - } - case MSG_WEBRTC_SIGNALINGMESSAGE: { - SignalingMsgParams* params = - reinterpret_cast(data); - params->result = SignalingMessage_s(params->signaling_message); - if (!params->result && event_callback_) - event_callback_->OnError(); - delete params; - break; - } - case MSG_WEBRTC_REMOVESTREAM: { - RemoveStreamParams* params = reinterpret_cast(data); - params->result = RemoveStream_s(params->stream_id); - delete params; - break; - } - case MSG_WEBRTC_SETAUDIODEVICE: { - SetAudioDeviceParams* params = - reinterpret_cast(data); - params->result = SetAudioDevice_s( - params->wave_in_device, params->wave_out_device, params->opts); - if (!params->result && event_callback_) - event_callback_->OnError(); - delete params; - break; - } - case MSG_WEBRTC_SETLOCALRENDERER: { - SetLocalRendererParams* params = - reinterpret_cast(data); - params->result = SetLocalVideoRenderer_s(params->renderer); - if (!params->result && event_callback_) - event_callback_->OnError(); - delete params; - break; - } - case MSG_WEBRTC_SETVIDEOCAPTURE: { - SetVideoCaptureParams* params = - reinterpret_cast(data); - params->result = SetVideoCapture_s(params->cam_device); - if (!params->result && event_callback_) - event_callback_->OnError(); - delete params; - break; - } - case MSG_WEBRTC_SETVIDEORENDERER: { - SetVideoRendererParams* params = - reinterpret_cast(data); - params->result = SetVideoRenderer_s(params->stream_id, params->renderer); - if (!params->result && event_callback_) - event_callback_->OnError(); - delete params; - break; - } - case MSG_WEBRTC_CONNECT: { - Connect_s(); - break; - } - case MSG_WEBRTC_CLOSE: { - Close_s(); - break; - } - case MSG_WEBRTC_INIT_CHANNELMANAGER: { - CreateChannelManager_s(); - break; - } - case MSG_WEBRTC_RELEASE: { - Release_s(); - break; - } - default: { - ASSERT(false); - break; - } - } -} - } // 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 0f0408fa53..3936ba8e28 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 @@ -34,29 +34,17 @@ #include "talk/app/webrtc/peerconnection.h" #include "talk/base/sigslot.h" #include "talk/base/scoped_ptr.h" -#include "talk/base/packetsocketfactory.h" -#include "talk/base/thread.h" #include "talk/session/phone/channelmanager.h" -namespace Json { -class Value; -} - namespace cricket { -class BasicPortAllocator; -class ChannelManager; class DeviceManager; class SessionDescription; } namespace webrtc { - -class AudioDeviceModule; -class ExternalRenderer; class WebRtcSession; class PeerConnectionImpl : public PeerConnection, - public talk_base::MessageHandler, public sigslot::has_slots<> { public: PeerConnectionImpl(const std::string& config, @@ -84,7 +72,7 @@ class PeerConnectionImpl : public PeerConnection, bool AddStream(const std::string& stream_id, bool video); bool RemoveStream(const std::string& stream_id); bool Connect(); - void Close(); + bool Close(); bool SetAudioDevice(const std::string& wave_in_device, const std::string& wave_out_device, int opts); bool SetLocalVideoRenderer(cricket::VideoRenderer* renderer); @@ -102,7 +90,7 @@ class PeerConnectionImpl : public PeerConnection, // Callbacks from PeerConnectionImplCallbacks void OnAddStream(const std::string& stream_id, bool video); - void OnRemoveStream2(const std::string& stream_id, bool video); + void OnRemoveStream(const std::string& stream_id, bool video); void OnLocalDescription( const cricket::SessionDescription* desc, const std::vector& candidates); @@ -113,28 +101,10 @@ class PeerConnectionImpl : public PeerConnection, private: bool ParseConfigString(const std::string& config, talk_base::SocketAddress* stun_addr); - void WrapChromiumThread(); void SendRemoveSignal(WebRtcSession* session); WebRtcSession* CreateMediaSession(const std::string& id, const std::string& dir); - virtual void OnMessage(talk_base::Message* message); - - // signaling thread methods - bool AddStream_s(const std::string& stream_id, bool video); - bool SignalingMessage_s(const std::string& signaling_message); - bool RemoveStream_s(const std::string& stream_id); - bool Connect_s(); - void Close_s(); - bool SetAudioDevice_s(const std::string& wave_in_device, - const std::string& wave_out_device, int opts); - bool SetLocalVideoRenderer_s(cricket::VideoRenderer* renderer); - bool SetVideoRenderer_s(const std::string& stream_id, - cricket::VideoRenderer* renderer); - bool SetVideoCapture_s(const std::string& cam_device); - void CreateChannelManager_s(); - void Release_s(); - std::string config_; talk_base::scoped_ptr channel_manager_; cricket::PortAllocator* port_allocator_; 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 new file mode 100644 index 0000000000..a231c4246d --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.cc @@ -0,0 +1,322 @@ +/* + * libjingle + * Copyright 2004--2011, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "talk/app/webrtc/peerconnection_proxy.h" + +#include "talk/app/webrtc/peerconnection_impl.h" +#include "talk/base/logging.h" + +namespace webrtc { + +enum { + MSG_WEBRTC_ADDSTREAM = 1, + MSG_WEBRTC_CLOSE, + MSG_WEBRTC_CONNECT, + MSG_WEBRTC_INIT, + MSG_WEBRTC_REGISTEROBSERVER, + MSG_WEBRTC_RELEASE, + MSG_WEBRTC_REMOVESTREAM, + MSG_WEBRTC_SETAUDIODEVICE, + MSG_WEBRTC_SETLOCALRENDERER, + MSG_WEBRTC_SETVIDEOCAPTURE, + MSG_WEBRTC_SETVIDEORENDERER, + MSG_WEBRTC_SIGNALINGMESSAGE, +}; + +struct AddStreamParams : public talk_base::MessageData { + AddStreamParams(const std::string& stream_id, bool video) + : stream_id(stream_id), + video(video), + result(false) {} + + std::string stream_id; + bool video; + bool result; +}; + +struct RemoveStreamParams : public talk_base::MessageData { + explicit RemoveStreamParams(const std::string& stream_id) + : stream_id(stream_id), + result(false) {} + + std::string stream_id; + bool result; +}; + +struct SignalingMsgParams : public talk_base::MessageData { + explicit SignalingMsgParams(const std::string& signaling_message) + : signaling_message(signaling_message), + result(false) {} + + std::string signaling_message; + bool result; +}; + +struct SetAudioDeviceParams : public talk_base::MessageData { + SetAudioDeviceParams(const std::string& wave_in_device, + const std::string& wave_out_device, + int opts) + : wave_in_device(wave_in_device), wave_out_device(wave_out_device), + opts(opts), result(false) {} + + std::string wave_in_device; + std::string wave_out_device; + int opts; + bool result; +}; + +struct SetLocalRendererParams : public talk_base::MessageData { + explicit SetLocalRendererParams(cricket::VideoRenderer* renderer) + : renderer(renderer), result(false) {} + + cricket::VideoRenderer* renderer; + bool result; +}; + +struct SetVideoRendererParams : public talk_base::MessageData { + SetVideoRendererParams(const std::string& stream_id, + cricket::VideoRenderer* renderer) + : stream_id(stream_id), renderer(renderer), result(false) {} + + std::string stream_id; + cricket::VideoRenderer* renderer; + bool result; +}; + +struct SetVideoCaptureParams : public talk_base::MessageData { + explicit SetVideoCaptureParams(const std::string& cam_device) + : cam_device(cam_device), result(false) {} + + std::string cam_device; + bool result; +}; + +struct RegisterObserverParams : public talk_base::MessageData { + explicit RegisterObserverParams(PeerConnectionObserver* observer) + : observer(observer), result(false) {} + + PeerConnectionObserver* observer; + bool result; +}; + +struct ResultParams : public talk_base::MessageData { + ResultParams() + : result(false) {} + + bool result; +}; + +PeerConnectionProxy::PeerConnectionProxy(const std::string& config, + cricket::PortAllocator* port_allocator, + cricket::MediaEngine* media_engine, + talk_base::Thread* worker_thread, + talk_base::Thread* signaling_thread, + cricket::DeviceManager* device_manager) + : peerconnection_impl_(new PeerConnectionImpl(config, port_allocator, + media_engine, worker_thread, signaling_thread, + device_manager)), + signaling_thread_(signaling_thread) { +} + +PeerConnectionProxy::PeerConnectionProxy(const std::string& config, + cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread) + : peerconnection_impl_(new PeerConnectionImpl(config, port_allocator, + worker_thread)), + signaling_thread_(NULL) { +} + +PeerConnectionProxy::~PeerConnectionProxy() { + ResultParams params; + Send(MSG_WEBRTC_RELEASE, ¶ms); +} + +bool PeerConnectionProxy::Init() { + // TODO(mallinath) - Changes are required to modify the stand alone + // constructor to get signaling thread as input. It should not be created + // here. + if (!signaling_thread_) { + signaling_thread_ = new talk_base::Thread(); + if (!signaling_thread_->SetName("signaling thread", this) || + !signaling_thread_->Start()) { + LOG(WARNING) << "Failed to start libjingle signaling thread"; + return false; + } + } + + ResultParams params; + return (Send(MSG_WEBRTC_INIT, ¶ms) && params.result); +} + +void PeerConnectionProxy::RegisterObserver(PeerConnectionObserver* observer) { + RegisterObserverParams params(observer); + Send(MSG_WEBRTC_REGISTEROBSERVER, ¶ms); +} + +bool PeerConnectionProxy::SignalingMessage( + const std::string& signaling_message) { + SignalingMsgParams params(signaling_message); + return (Send(MSG_WEBRTC_SIGNALINGMESSAGE, ¶ms) && params.result); +} + +bool PeerConnectionProxy::AddStream(const std::string& stream_id, bool video) { + AddStreamParams params(stream_id, video); + return (Send(MSG_WEBRTC_ADDSTREAM, ¶ms) && params.result); +} + +bool PeerConnectionProxy::RemoveStream(const std::string& stream_id) { + RemoveStreamParams params(stream_id); + return (Send(MSG_WEBRTC_REMOVESTREAM, ¶ms) && params.result); +} + +bool PeerConnectionProxy::SetAudioDevice(const std::string& wave_in_device, + const std::string& wave_out_device, + int opts) { + SetAudioDeviceParams params(wave_in_device, wave_out_device, opts); + return (Send(MSG_WEBRTC_SETAUDIODEVICE, ¶ms) && params.result); +} + +bool PeerConnectionProxy::SetLocalVideoRenderer( + cricket::VideoRenderer* renderer) { + SetLocalRendererParams params(renderer); + return (Send(MSG_WEBRTC_SETLOCALRENDERER, ¶ms) && params.result); +} + +bool PeerConnectionProxy::SetVideoRenderer(const std::string& stream_id, + cricket::VideoRenderer* renderer) { + SetVideoRendererParams params(stream_id, renderer); + return (Send(MSG_WEBRTC_SETVIDEORENDERER, ¶ms) && params.result); +} + +bool PeerConnectionProxy::SetVideoCapture(const std::string& cam_device) { + SetVideoCaptureParams params(cam_device); + return (Send(MSG_WEBRTC_SETVIDEOCAPTURE, ¶ms) && params.result); +} + +bool PeerConnectionProxy::Connect() { + ResultParams params; + return (Send(MSG_WEBRTC_CONNECT, ¶ms) && params.result); +} + +bool PeerConnectionProxy::Close() { + ResultParams params; + return (Send(MSG_WEBRTC_CLOSE, ¶ms) && params.result); +} + +bool PeerConnectionProxy::Send(uint32 id, talk_base::MessageData* data) { + if (!signaling_thread_) + return false; + signaling_thread_->Send(this, id, data); + return true; +} + +void PeerConnectionProxy::OnMessage(talk_base::Message* message) { + talk_base::MessageData* data = message->pdata; + switch (message->message_id) { + case MSG_WEBRTC_ADDSTREAM: { + AddStreamParams* params = reinterpret_cast(data); + params->result = peerconnection_impl_->AddStream( + params->stream_id, params->video); + break; + } + case MSG_WEBRTC_SIGNALINGMESSAGE: { + SignalingMsgParams* params = + reinterpret_cast(data); + params->result = peerconnection_impl_->SignalingMessage( + params->signaling_message); + break; + } + case MSG_WEBRTC_REMOVESTREAM: { + RemoveStreamParams* params = reinterpret_cast(data); + params->result = peerconnection_impl_->RemoveStream( + params->stream_id); + break; + } + case MSG_WEBRTC_SETAUDIODEVICE: { + SetAudioDeviceParams* params = + reinterpret_cast(data); + params->result = peerconnection_impl_->SetAudioDevice( + params->wave_in_device, params->wave_out_device, params->opts); + break; + } + case MSG_WEBRTC_SETLOCALRENDERER: { + SetLocalRendererParams* params = + reinterpret_cast(data); + params->result = peerconnection_impl_->SetLocalVideoRenderer( + params->renderer); + break; + } + case MSG_WEBRTC_SETVIDEOCAPTURE: { + SetVideoCaptureParams* params = + reinterpret_cast(data); + params->result = peerconnection_impl_->SetVideoCapture( + params->cam_device); + break; + } + case MSG_WEBRTC_SETVIDEORENDERER: { + SetVideoRendererParams* params = + reinterpret_cast(data); + params->result = peerconnection_impl_->SetVideoRenderer( + params->stream_id, params->renderer); + break; + } + case MSG_WEBRTC_CONNECT: { + ResultParams* params = + reinterpret_cast(data); + params->result = peerconnection_impl_->Connect(); + break; + } + case MSG_WEBRTC_CLOSE: { + ResultParams* params = + reinterpret_cast(data); + params->result = peerconnection_impl_->Close(); + break; + } + case MSG_WEBRTC_INIT: { + ResultParams* params = + reinterpret_cast(data); + params->result = peerconnection_impl_->Init(); + break; + } + case MSG_WEBRTC_REGISTEROBSERVER: { + RegisterObserverParams* params = + reinterpret_cast(data); + peerconnection_impl_->RegisterObserver(params->observer); + break; + } + case MSG_WEBRTC_RELEASE: { + peerconnection_impl_.reset(); + break; + } + default: { + ASSERT(false); + break; + } + } +} + +} // namespace webrtc 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 new file mode 100644 index 0000000000..87e9fea6d8 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_proxy.h @@ -0,0 +1,80 @@ +/* + * libjingle + * Copyright 2004--2011, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TALK_APP_WEBRTC_PEERCONNECTION_PROXY_H_ +#define TALK_APP_WEBRTC_PEERCONNECTION_PROXY_H_ + +#include + +#include "talk/app/webrtc/peerconnection.h" +#include "talk/base/scoped_ptr.h" +#include "talk/base/thread.h" + +namespace cricket { +class DeviceManager; +} + +namespace webrtc { +class PeerConnectionProxy : public PeerConnection, + public talk_base::MessageHandler { + public: + PeerConnectionProxy(const std::string& config, + cricket::PortAllocator* port_allocator, + cricket::MediaEngine* media_engine, + talk_base::Thread* worker_thread, + talk_base::Thread* signaling_thread, + cricket::DeviceManager* device_manager); + PeerConnectionProxy(const std::string& config, + cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread); + virtual ~PeerConnectionProxy(); + + // PeerConnection interfaces + bool Init(); + 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); + + private: + bool Send(uint32 id, talk_base::MessageData* data); + virtual void OnMessage(talk_base::Message* message); + + talk_base::scoped_ptr peerconnection_impl_; + talk_base::Thread* signaling_thread_; +}; +} + +#endif // TALK_APP_WEBRTC_PEERCONNECTION_PROXY_H_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/webrtc.scons b/third_party_mods/libjingle/source/talk/app/webrtc/webrtc.scons index 99cccc9712..611f24c805 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc/webrtc.scons +++ b/third_party_mods/libjingle/source/talk/app/webrtc/webrtc.scons @@ -10,6 +10,7 @@ talk.Library( srcs = [ 'peerconnection.cc', 'peerconnection_impl.cc', + 'peerconnection_proxy.cc', 'webrtc_json.cc', 'webrtcsession.cc', ],