diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/audio_device_dev.cc b/third_party_mods/libjingle/source/talk/app/webrtc/audio_device_dev.cc new file mode 100644 index 000000000..e8b3cd621 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/audio_device_dev.cc @@ -0,0 +1,51 @@ +/* + * 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/local_stream_dev.h" + +namespace webrtc { + +scoped_refptr AudioDevice::Create(const std::string& name, + webrtc::AudioDeviceModule* adm) { + RefCountImpl* device = new RefCountImpl(); + device->Initialize(name, adm); + return device; +} + +const std::string& AudioDevice::name(){ + return name_; +} + +AudioDeviceModule* AudioDevice::module() { + return adm_; +} + +void AudioDevice::Initialize(const std::string& name, AudioDeviceModule* adm) { + name_ = name; + adm_ = adm; +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/local_audio_track_impl_dev.cc b/third_party_mods/libjingle/source/talk/app/webrtc/local_audio_track_impl_dev.cc new file mode 100644 index 000000000..c5d3ec919 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/local_audio_track_impl_dev.cc @@ -0,0 +1,77 @@ +/* + * 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/local_stream_dev.h" + +namespace webrtc { + +class LocalAudioTrackImpl : public NotifierImpl { + public: + LocalAudioTrackImpl(){}; + LocalAudioTrackImpl(AudioDevice* audio_device) + : enabled_(true), + kind_(kAudioTrackKind), + audio_device_(audio_device) { + } + + // Get the AudioDevice associated with this track. + virtual scoped_refptr GetAudioDevice() { + return audio_device_.get(); + }; + + // Implement MediaStreamTrack + virtual const std::string& kind() { + return kind_; + } + + virtual const std::string& label() { + return audio_device_->name(); + } + + virtual bool enabled() { + return enabled_; + } + + virtual bool set_enabled(bool enable) { + bool fire_on_change = enable != enabled_; + enabled_ = enable; + if (fire_on_change) + NotifierImpl::FireOnChanged(); + } + + private: + bool enabled_; + std::string kind_; + scoped_refptr audio_device_; +}; + +scoped_refptr LocalAudioTrack::Create(AudioDevice* audio_device) { + RefCountImpl* lstream = + new RefCountImpl(audio_device); + return lstream; +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/local_video_track_impl_dev.cc b/third_party_mods/libjingle/source/talk/app/webrtc/local_video_track_impl_dev.cc new file mode 100644 index 000000000..784c7f49e --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/local_video_track_impl_dev.cc @@ -0,0 +1,86 @@ +/* + * 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/local_stream_dev.h" + +namespace webrtc { + +class LocalVideoTrackImpl : public NotifierImpl { + public: + LocalVideoTrackImpl(){}; + LocalVideoTrackImpl(VideoDevice* video_device) + : enabled_(true), + kind_(kVideoTrackKind), + video_device_(video_device) { + } + + virtual void SetRenderer(VideoRenderer* renderer) { + video_renderer_ = renderer; + } + + virtual scoped_refptr GetRenderer() { + return video_renderer_.get(); + } + + // Get the VideoCapture device associated with this track. + virtual scoped_refptr GetVideoCapture() { + return video_device_.get(); + } + + // Implement MediaStreamTrack + virtual const std::string& kind() { + return kind_; + } + + virtual const std::string& label() { + return video_device_->name(); + } + + virtual bool enabled() { + return enabled_; + } + + virtual bool set_enabled(bool enable) { + bool fire_on_change = enable != enabled_; + enabled_ = enable; + if (fire_on_change) + NotifierImpl::FireOnChanged(); + } + +private: + bool enabled_; + std::string kind_; + scoped_refptr video_device_; + scoped_refptr video_renderer_; +}; + +scoped_refptr LocalVideoTrack::Create(VideoDevice* video_device) { + RefCountImpl* track = + new RefCountImpl(video_device); + return track; +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_client_dev.cc b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_client_dev.cc new file mode 100644 index 000000000..c35921733 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_client_dev.cc @@ -0,0 +1,54 @@ +/* + * 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/peerconnectionmanager.h" +#include "talk/base/logging.h" +#include "talk/p2p/client/basicportallocator.h" + +int main() { + LOG(INFO) << "Create PeerConnectionManager."; + + talk_base::scoped_ptr port_allocator_; + talk_base::scoped_ptr worker_thread_; + + port_allocator_.reset(new cricket::BasicPortAllocator( + new talk_base::BasicNetworkManager(), + talk_base::SocketAddress("stun.l.google.com", 19302), + talk_base::SocketAddress(), + talk_base::SocketAddress(), talk_base::SocketAddress())); + + worker_thread_.reset(new talk_base::Thread()); + if (!worker_thread_->SetName("workder thread", NULL) || + !worker_thread_->Start()) { + LOG(WARNING) << "Failed to start libjingle workder thread"; + } + + webrtc::PeerConnectionManager* peerconnection_manager = + webrtc::PeerConnectionManager::Create(port_allocator_.get(), + worker_thread_.get()); + return 0; +} diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl_dev.cc b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl_dev.cc new file mode 100644 index 000000000..6fadca033 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl_dev.cc @@ -0,0 +1,73 @@ + +#include "talk/app/webrtc/peerconnection_impl_dev.h" + +#include "talk/app/webrtc/webrtcsession.h" +#include "talk/base/logging.h" +#include "talk/session/phone/channelmanager.h" +#include "talk/p2p/base/portallocator.h" + +namespace webrtc { + +PeerConnectionImpl::PeerConnectionImpl( + cricket::ChannelManager* channel_manager, + cricket::PortAllocator* port_allocator) + : initialized_(false), + ready_state_(NEW), + observer_(NULL), + session_(NULL), + signaling_thread_(new talk_base::Thread()), + channel_manager_(channel_manager), + port_allocator_(port_allocator) { +} + +PeerConnectionImpl::~PeerConnectionImpl() { +} + +bool PeerConnectionImpl::Init() { + ASSERT(port_allocator_ != NULL); + ASSERT(signaling_thread_.get()); + if (!signaling_thread_->SetName("signaling_thread", this) || + !signaling_thread_->Start()) { + LOG(LS_ERROR) << "Failed to start signalig thread"; + return false; + } + session_.reset(CreateSession()); + ASSERT(session_.get() != NULL); + return true; +} + +WebRTCSession* PeerConnectionImpl::CreateSession() { + // TODO(ronghuawu): when we have the new WebRTCSession we don't need these + std::string id = ""; + std::string direction = ""; + WebRTCSession* session = + new WebRTCSession(id, direction, port_allocator_, + channel_manager_, + // TODO(ronghuawu): implement PeerConnectionImplCallbacks + // this, + NULL, + signaling_thread_.get()); + if (!session->Initiate()) { + delete session; + session = NULL; + } + return session; +} + +void PeerConnectionImpl::RegisterObserver(PeerConnectionObserver* observer) { + observer_ = observer; +} + +void PeerConnectionImpl::AddStream(LocalStream* local_stream) { + +} + +void PeerConnectionImpl::RemoveStream(LocalStream* remove_stream) { + +} + +void PeerConnectionImpl::OnMessage(talk_base::Message* msg) { + +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl_dev.h b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl_dev.h new file mode 100644 index 000000000..d5ec22c46 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnection_impl_dev.h @@ -0,0 +1,121 @@ +/* + * 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_IMPL_H_ +#define TALK_APP_WEBRTC_PEERCONNECTION_IMPL_H_ + +#include "talk/app/webrtc/peerconnection_dev.h" +#include "talk/base/scoped_ptr.h" + +namespace cricket { +class ChannelManager; +class PortAllocator; +} + +namespace talk_base { +class Message; +} + +namespace webrtc { + +class WebRTCSession; + +class PeerConnectionImpl : public PeerConnection { + public: + enum ReadyState { + NEW = 0, + NEGOTIATING, + ACTIVE, + CLOSED, + }; + + enum Error { + ERROR_NONE = 0, // Good + ERROR_TIMEOUT = 1, // No Candidates generated for X amount of time + ERROR_AUDIO_DEVICE = 2, // DeviceManager audio device error + ERROR_VIDEO_DEVICE = 3, // DeviceManager video device error + ERROR_NETWORK = 4, // Transport errors + ERROR_MEDIADESCRIPTION = 5, // SignalingMessage error + ERROR_MEDIA = 6, // Related to Engines + ERROR_UNKNOWN = 10, // Everything else + }; + + PeerConnectionImpl(cricket::ChannelManager* channel_manager, + cricket::PortAllocator* port_allocator); + virtual ~PeerConnectionImpl(); + + // Interfaces from PeerConnection + virtual bool StartNegotiation() { + //TODO: implement + } + virtual bool SignalingMessage(const std::string& msg) { + //TODO: implement + } + virtual bool Send(const std::string& msg) { + //TODO: implement + } + virtual scoped_refptr local_streams() { + //TODO: implement + } + virtual scoped_refptr remote_streams() { + //TODO: implement + } + virtual void AddStream(LocalStream* stream); + virtual void RemoveStream(LocalStream* stream); + + bool Init(); + void RegisterObserver(PeerConnectionObserver* observer); + + bool ProcessSignalingMessage(const std::string& msg); + + bool initialized() { + return initialized_; + } + ReadyState ready_state() { + return ready_state_; + } + +private: + WebRTCSession* CreateSession(); + virtual void OnMessage(talk_base::Message* msg); + void AddStream_s(LocalStream* stream); + void RemoveStream_s(LocalStream* stream); + void ProcessSignalingMessage_s(const std::string& msg); + void StartNegotiation_s(); + + bool initialized_; + ReadyState ready_state_; + PeerConnectionObserver* observer_; + talk_base::scoped_ptr session_; + talk_base::scoped_ptr signaling_thread_; + cricket::ChannelManager* channel_manager_; + cricket::PortAllocator* port_allocator_; +}; + +} // namespace webrtc + +#endif // TALK_APP_WEBRTC_PEERCONNECTION_IMPL_H_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectionmanager.cc b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectionmanager.cc new file mode 100644 index 000000000..76229e289 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectionmanager.cc @@ -0,0 +1,95 @@ +/* + * 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/peerconnectionmanager.h" + +#include "talk/app/webrtc/peerconnection_impl_dev.h" +#include "talk/base/logging.h" +#include "talk/base/thread.h" +#include "talk/session/phone/channelmanager.h" + +namespace webrtc { + +PeerConnectionManager* PeerConnectionManager::Create( + cricket::MediaEngine* media_engine, + cricket::DeviceManager* device_manager, + cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread) { + PeerConnectionManager* pc_manager = new PeerConnectionManager(); + if (!pc_manager->Initialize(media_engine, device_manager, port_allocator, + worker_thread)) { + delete pc_manager; + pc_manager = NULL; + } + return pc_manager; +} + +PeerConnectionManager* PeerConnectionManager::Create( + cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread) { + PeerConnectionManager* pc_manager = new PeerConnectionManager(); + if (!pc_manager->Initialize(port_allocator, worker_thread)) { + delete pc_manager; + pc_manager = NULL; + } + return pc_manager; +} + +bool PeerConnectionManager::Initialize(cricket::MediaEngine* media_engine, + cricket::DeviceManager* device_manager, + cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread) { + channel_manager_.reset(new cricket::ChannelManager( + media_engine, device_manager, worker_thread)); + if (channel_manager_->Init()) { + initialized_ = true; + } + return initialized_; +} + +bool PeerConnectionManager::Initialize(cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread) { + port_allocator_.reset(port_allocator); + channel_manager_.reset(new cricket::ChannelManager(worker_thread)); + if (channel_manager_->Init()) { + initialized_ = true; + } + return initialized_; +} + +PeerConnection* PeerConnectionManager::CreatePeerConnection() { + // TODO(mallinath) - It may be necessary to store the created PeerConnection + // object in manager. + return new PeerConnectionImpl(channel_manager_.get(), + port_allocator_.get()); +} + +void PeerConnectionManager::DestroyPeerConnection(PeerConnection* pc) { + delete pc; +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectionmanager.h b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectionmanager.h new file mode 100644 index 000000000..6cbcc34c3 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectionmanager.h @@ -0,0 +1,83 @@ +/* + * 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_PEERCONNECTIONMANAGER_H_ +#define TALK_APP_WEBRTC_PEERCONNECTIONMANAGER_H_ + +#include "talk/base/scoped_ptr.h" +#include "talk/session/phone/channelmanager.h" + +namespace talk_base { +class Thread; +} + +namespace cricket { +class ChannelManager; +class DeviceManager; +class MediaEngine; +class PeerConnection; +class PortAllocator; +} + +namespace webrtc { + +class PeerConnection; + +class PeerConnectionManager { + public: + static PeerConnectionManager* Create( + cricket::MediaEngine* media_engine, + cricket::DeviceManager* device_manager, + cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread); + static PeerConnectionManager* Create( + cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread); + + PeerConnection* CreatePeerConnection(); + void DestroyPeerConnection(PeerConnection* pc); + + protected: + PeerConnectionManager() {}; + virtual ~PeerConnectionManager() {}; + + private: + bool Initialize(cricket::MediaEngine* media_engine, + cricket::DeviceManager* device_manager, + cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread); + + bool Initialize(cricket::PortAllocator* port_allocator, + talk_base::Thread* worker_thread); + + bool initialized_; + talk_base::scoped_ptr port_allocator_; + talk_base::scoped_ptr channel_manager_; +}; + +} // namespace webrtc + +#endif // TALK_APP_WEBRTC_PEERCONNECTIONMANAGER_H_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectiontransport.cc b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectiontransport.cc new file mode 100644 index 000000000..1fc61a333 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectiontransport.cc @@ -0,0 +1,148 @@ + +#include "talk/app/webrtc/peerconnectiontransport.h" + +#include "talk/base/common.h" +#include "talk/base/logging.h" +#include "talk/base/thread.h" +#include "talk/p2p/base/p2ptransport.h" +#include "talk/p2p/base/portallocator.h" +#include "talk/p2p/base/transportchannelimpl.h" + +namespace { +static const int MSG_TRANSPORT_TIMEOUT = 1; +// TODO(mallinath) - This value is not finalized yet. For now 30 seconds +// timeout value is taken from magicflute. +static const int kCallSetupTimeout = 30 * 1000; +} + + +namespace webrtc { + +PeerConnectionTransport::PeerConnectionTransport( + talk_base::Thread* signaling_thread, + talk_base::Thread* worker_thread, + cricket::PortAllocator* port_allocator) + : state_(INIT), + all_writable_(false), + signaling_thread_(signaling_thread), + transport_(new cricket::P2PTransport( + signaling_thread, worker_thread, port_allocator)) { +} + +PeerConnectionTransport::~PeerConnectionTransport() { +} + +bool PeerConnectionTransport::Initialize() { + ASSERT(transport_.get()); + transport_->SignalCandidatesReady.connect( + this, &PeerConnectionTransport::OnCandidatesReady); + transport_->SignalRequestSignaling.connect( + this, &PeerConnectionTransport::OnRequestSignaling); + transport_->SignalWritableState.connect( + this, &PeerConnectionTransport::OnWritableState); + transport_->SignalRouteChange.connect( + this, &PeerConnectionTransport::OnRouteChange); + transport_->SignalConnecting.connect( + this, &PeerConnectionTransport::OnConnecting); + return true; +} + +void PeerConnectionTransport::ConnectChannels() { + transport_->ConnectChannels(); + state_ = CONNECTING; +} + +cricket::TransportChannel* PeerConnectionTransport::CreateChannel( + const std::string& channel_name, + const std::string& content_type) { + cricket::TransportChannel* channel = FindChannel(channel_name); + if (channel) { + LOG(LS_INFO) << "Channel alreary exists"; + return channel; + } else { + channel = transport_->CreateChannel(channel_name, content_type); + channels_[channel_name] = channel; + return channel; + } +} + +cricket::TransportChannel* PeerConnectionTransport::FindChannel( + const std::string& name) const { + TransportChannelMap::const_iterator iter = channels_.find(name); + return (iter != channels_.end()) ? iter->second : NULL; +} + +cricket::TransportChannel* PeerConnectionTransport::GetChannel( + const std::string& channel_name, + const std::string& content_type) { + return FindChannel(channel_name); +} + +void PeerConnectionTransport::DestroyChannel(const std::string& channel_name, + const std::string& content_type) { + TransportChannelMap::iterator iter = channels_.find(channel_name); + if (iter != channels_.end()) { + channels_.erase(iter); + } + transport_->DestroyChannel(channel_name); + return; +} + +void PeerConnectionTransport::OnRequestSignaling( + cricket::Transport* transport) { + transport_->OnSignalingReady(); +} + +void PeerConnectionTransport::OnCandidatesReady( + cricket::Transport* transport, + const std::vector& candidates) { + std::vector::const_iterator iter; + for (iter = candidates.begin(); iter != candidates.end(); ++iter) { + local_candidates_.push_back(*iter); + } +} + +void PeerConnectionTransport::OnWritableState(cricket::Transport* transport) { + bool all_writable = transport->writable(); + if (all_writable != all_writable_) { + if (all_writable) { + signaling_thread_->Clear(this, MSG_TRANSPORT_TIMEOUT); + } else { + signaling_thread_->PostDelayed( + kCallSetupTimeout, this, MSG_TRANSPORT_TIMEOUT); + } + all_writable_ = all_writable; + } +} + +void PeerConnectionTransport::OnRouteChange( + cricket::Transport* transport, + const std::string& name, + const cricket::Candidate& remote_candidate) { + channel_best_remote_candidate_[name] = remote_candidate; +} + +void PeerConnectionTransport::OnConnecting(cricket::Transport* transport) { + ASSERT(signaling_thread_->IsCurrent()); + if (transport->HasChannels() && !transport->writable()) { + signaling_thread_->PostDelayed( + kCallSetupTimeout, this, MSG_TRANSPORT_TIMEOUT); + } +} + +void PeerConnectionTransport::OnRemoteCandidates(const Candidates candidates) { + transport_->OnRemoteCandidates(candidates); + state_ = CONNECTED; +} + +void PeerConnectionTransport::OnMessage(talk_base::Message* message) { + switch(message->message_id) { + case MSG_TRANSPORT_TIMEOUT: { + LOG(LS_ERROR) << "Transport Timeout"; + SignalTransportTimeout(); + break; + } + } +} + +} diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectiontransport.h b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectiontransport.h new file mode 100644 index 000000000..4afd804d7 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/peerconnectiontransport.h @@ -0,0 +1,94 @@ + + +#ifndef TALK_APP_WEBRTC_PEERCONNECTIONTRANSPORT_H_ +#define TALK_APP_WEBRTC_PEERCONNECTIONTRANSPORT_H_ + +#include +#include +#include + +#include "talk/base/messagequeue.h" +#include "talk/base/sigslot.h" +#include "talk/p2p/base/candidate.h" + +namespace talk_base { +class Thread; +class Message; +} + +namespace cricket { +class PortAllocator; +class Transport; +class TransportChannel; +} + +namespace webrtc { +typedef std::vector Candidates; + +class PeerConnectionTransport : public talk_base::MessageHandler, + public sigslot::has_slots<> { + public: + PeerConnectionTransport(talk_base::Thread* signaling_thread, + talk_base::Thread* worker_thread, + cricket::PortAllocator* port_allocator); + ~PeerConnectionTransport(); + + enum TransportState { + INIT, + CONNECTING, + CONNECTED, + }; + + bool Initialize(); + + // methods signaled by the cricket::Transport + void OnRequestSignaling(cricket::Transport* transport); + void OnCandidatesReady(cricket::Transport* transport, + const std::vector& candidates); + void OnWritableState(cricket::Transport* transport); + void OnRouteChange(cricket::Transport* transport, + const std::string& name, + const cricket::Candidate& remote_candidate); + void OnConnecting(cricket::Transport* transport); + void ConnectChannels(); + + // methods to handle transport channels. These methods are relayed from + // WebRTCSessionImpl which implements cricket::BaseSession methods + cricket::TransportChannel* CreateChannel(const std::string& channel_name, + const std::string& content_type); + cricket::TransportChannel* GetChannel(const std::string& channel_name, + const std::string& content_type); + void DestroyChannel(const std::string& channel_name, + const std::string& content_type); + + Candidates local_candidates() { + return local_candidates_; + } + Candidates remote_candidates() { + return remote_candidates_; + } + + void OnRemoteCandidates(const Candidates candidates); + sigslot::signal0<> SignalTransportTimeout; + + private: + typedef std::map TransportChannelMap; + + virtual void OnMessage(talk_base::Message* message); + void StartTransportTimeout(); + void ClearTransportTimeout(); + cricket::TransportChannel* FindChannel(const std::string& name) const; + + TransportState state_; + bool all_writable_; + TransportChannelMap channels_; + talk_base::scoped_ptr transport_; + talk_base::Thread* signaling_thread_; + Candidates local_candidates_; + Candidates remote_candidates_; + std::map channel_best_remote_candidate_; +}; + +} // namespace webrtc + +#endif // TALK_APP_WEBRTC_PEERCONNECTIONTRANSPORT_H_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/video_device_dev.cc b/third_party_mods/libjingle/source/talk/app/webrtc/video_device_dev.cc new file mode 100644 index 000000000..b871af5a0 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/video_device_dev.cc @@ -0,0 +1,51 @@ +/* + * 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/local_stream_dev.h" + +namespace webrtc { + +scoped_refptr VideoDevice::Create(const std::string& name, + VideoCaptureModule* vcm) { + RefCountImpl* device = new RefCountImpl(); + device->Initialize(name,vcm); + return device; +} + +const std::string& VideoDevice::name(){ + return name_; +} + +VideoCaptureModule* VideoDevice::module() { + return vcm_; +} + +void VideoDevice::Initialize(const std::string& name, VideoCaptureModule* vcm) { + name_ = name; + vcm_ = vcm; +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/video_renderer_dev.cc b/third_party_mods/libjingle/source/talk/app/webrtc/video_renderer_dev.cc new file mode 100644 index 000000000..23771a4bd --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/video_renderer_dev.cc @@ -0,0 +1,45 @@ +/* + * 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/local_stream_dev.h" + +namespace webrtc { + +scoped_refptr VideoRenderer::Create(cricket::VideoRenderer* renderer) { + RefCountImpl* r = new RefCountImpl(); + r->Initialize(renderer); + return r; +} + +cricket::VideoRenderer* VideoRenderer::module() { + return renderer_; +} + +void VideoRenderer::Initialize(cricket::VideoRenderer* renderer) { + renderer_ = renderer; +} + +} // namespace webrtc