diff --git a/third_party_mods/libjingle/libjingle.gyp b/third_party_mods/libjingle/libjingle.gyp index 43e7b32ab6..04af21fd40 100644 --- a/third_party_mods/libjingle/libjingle.gyp +++ b/third_party_mods/libjingle/libjingle.gyp @@ -596,7 +596,9 @@ ], } ], # inside_chromium_build ['peer_connection_dev==1', { - 'sources': [ + # sources= empties the list of source file and start new. + # peer_connection_dev is independent of the main branch. + 'sources=': [ '<(overrides)/talk/app/webrtc_dev/scoped_refptr.h', '<(libjingle_mods)/source/talk/app/webrtc_dev/audio_device_dev.cc', '<(libjingle_mods)/source/talk/app/webrtc_dev/local_audio_track_impl_dev.cc', @@ -608,8 +610,8 @@ '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnection_dev.h', '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnection_impl_dev.cc', '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnection_impl_dev.h', - '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnectionmanager.cc', - '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnectionmanager.h', + '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnectionmanager_impl.cc', + '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnectionmanager_impl.h', '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnectiontransport.cc', '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnectiontransport.h', '<(libjingle_mods)/source/talk/app/webrtc_dev/ref_count.h', @@ -618,6 +620,10 @@ '<(libjingle_mods)/source/talk/app/webrtc_dev/stream_dev.h', '<(libjingle_mods)/source/talk/app/webrtc_dev/video_device_dev.cc', '<(libjingle_mods)/source/talk/app/webrtc_dev/video_renderer_dev.cc', + '<(libjingle_mods)/source/talk/app/webrtc_dev/webrtc_devicemanager.h', + '<(libjingle_mods)/source/talk/app/webrtc_dev/webrtc_devicemanager.cc', + '<(libjingle_mods)/source/talk/app/webrtc_dev/webrtc_mediaengine.h', + '<(libjingle_mods)/source/talk/app/webrtc_dev/webrtc_mediaengine.cc', ], }], # peer_connection_dev ], # conditions @@ -653,7 +659,8 @@ 'dependencies': [ 'libjingle_app', '../../testing/gtest.gyp:gtest', - '../../testing/gtest.gyp:gtest_main', + '../../testing/gtest.gyp:gtest_main', + '../../src/modules/audio_device/main/source/audio_device.gyp:audio_device', ], 'conditions': [ ['peer_connection_dev==1', { @@ -663,10 +670,17 @@ '<(libjingle_mods)/source/talk/app/webrtc_dev/local_stream_dev_unittest.cc', '<(libjingle_mods)/source/talk/app/webrtc_dev/remote_stream_dev_unittest.cc', '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnection_impl_dev_unittest.cc', + '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnectionmanager_unittest.cc', ], }, { 'type': 'none', } ], # peer_connection_dev + ['peer_connection_dev==1 and OS=="linux"', { + 'libraries': [ + '-lXext', + '-lX11', + ], + } ], ], # conditions }, ], diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_dev.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_dev.h index 694cfc10e0..51365edcec 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_dev.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_dev.h @@ -32,17 +32,23 @@ #include "talk/app/webrtc_dev/stream_dev.h" -namespace cricket { -class PortAllocator; -class DeviceManager; -} - namespace talk_base { -class Thread; + class Thread; + class NetworkManager; + class PacketSocketFactory; } namespace webrtc { +class StreamCollection : public RefCount { + public: + virtual size_t count() = 0; + virtual MediaStream* at(size_t index) = 0; + protected: + // Dtor protected as objects shouldn't be deleted via this interface. + ~StreamCollection() {} +}; + ///////////////////////////////////////////// class PeerConnectionObserver { public: @@ -71,13 +77,8 @@ class PeerConnectionObserver { ~PeerConnectionObserver() {} }; -class StreamCollection : public RefCount { - public: - virtual size_t count() = 0; - virtual MediaStream* at(size_t index) = 0; -}; -class PeerConnection { +class PeerConnection : public RefCount { public: // Start Negotiation. Negotiation is based on if // SignalingMessage and AddStream have been called prior to this function. @@ -111,7 +112,58 @@ class PeerConnection { protected: // Dtor protected as objects shouldn't be deleted via this interface. - virtual ~PeerConnection() {} + ~PeerConnection() {} +}; + +// Reference counted wrapper for talk_base::NetworkManager. +class PcNetworkManager : public RefCount { + public: + static scoped_refptr Create( + talk_base::NetworkManager* network_manager); + virtual talk_base::NetworkManager* network_manager() const; + + protected: + explicit PcNetworkManager(talk_base::NetworkManager* network_manager); + virtual ~PcNetworkManager(); + + talk_base::NetworkManager* network_manager_; +}; + +// Reference counted wrapper for talk_base::PacketSocketFactory. +class PcPacketSocketFactory : public RefCount { + public: + static scoped_refptr Create( + talk_base::PacketSocketFactory* socket_factory); + virtual talk_base::PacketSocketFactory* socket_factory() const; + + protected: + explicit PcPacketSocketFactory( + talk_base::PacketSocketFactory* socket_factory); + virtual ~PcPacketSocketFactory(); + + talk_base::PacketSocketFactory* socket_factory_; +}; + +class PeerConnectionManager : public RefCount { + public: + // Create a new instance of PeerConnectionManager. + static scoped_refptr Create(); + + // Create a new instance of PeerConnectionManager. + // Ownership of the arguments are not transfered to this object and must + // remain in scope for the lifetime of the PeerConnectionManager. + static scoped_refptr Create( + talk_base::Thread* worker_thread, + PcNetworkManager* network_manager, + PcPacketSocketFactory* packet_socket_factory, + AudioDevice* default_adm); + + virtual scoped_refptr CreatePeerConnection( + const std::string& config) = 0; + + protected: + // Dtor protected as objects shouldn't be deleted via this interface. + ~PeerConnectionManager() {} }; } // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev.cc index 207441fd9b..3cb6ac4fca 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev.cc @@ -28,75 +28,129 @@ #include "talk/app/webrtc_dev/peerconnection_impl_dev.h" +#include + #include "talk/app/webrtc_dev/scoped_refptr_msg.h" #include "talk/base/logging.h" +#include "talk/p2p/client/basicportallocator.h" #include "talk/session/phone/channelmanager.h" -#include "talk/p2p/base/portallocator.h" - namespace webrtc { +// Implementation of StreamCollection intended for local streams. +class LocalStreamCollection : public StreamCollection { + public: + static scoped_refptr Create() { + RefCountImpl* implementation = + new RefCountImpl(); + return implementation; + } + + static scoped_refptr Create( + LocalStreamCollection* local_streams) { + RefCountImpl* implementation = + new RefCountImpl(local_streams); + return implementation; + } + + virtual size_t count() { + return local_media_streams_.size(); + } + + virtual MediaStream* at(size_t index) { + return local_media_streams_.at(index); + } + + void AddStream(LocalMediaStream* local_stream) { + for (LocalStreamVector::iterator it = local_media_streams_.begin(); + it != local_media_streams_.end(); ++it) { + if ((*it)->label().compare(local_stream->label()) == 0) + return; + } + local_media_streams_.push_back(local_stream); + } + + void RemoveStream(LocalMediaStream* remove_stream) { + for (LocalStreamVector::iterator it = local_media_streams_.begin(); + it != local_media_streams_.end(); ++it) { + if ((*it)->label().compare(remove_stream->label()) == 0) { + local_media_streams_.erase(it); + break; + } + } + } + + protected: + LocalStreamCollection() {} + explicit LocalStreamCollection(LocalStreamCollection* original) + : local_media_streams_(original->local_media_streams_) { + } + // Map of local media streams. + typedef std::vector > + LocalStreamVector; + LocalStreamVector local_media_streams_; +}; + PeerConnectionImpl::PeerConnectionImpl( cricket::ChannelManager* channel_manager, - cricket::PortAllocator* port_allocator, - talk_base::Thread* signal_thread) + talk_base::Thread* worker_thread, + PcNetworkManager* network_manager, + PcPacketSocketFactory* socket_factory) : observer_(NULL), - signal_thread_(signal_thread), + local_media_streams_(LocalStreamCollection::Create()), + worker_thread_(worker_thread), channel_manager_(channel_manager), - port_allocator_(port_allocator) { -// TODO(perkj): // ASSERT(port_allocator_ != NULL); + network_manager_(network_manager), + socket_factory_(socket_factory), + port_allocator_(new cricket::BasicPortAllocator( + network_manager->network_manager(), + socket_factory->socket_factory())) { } PeerConnectionImpl::~PeerConnectionImpl() { } +bool PeerConnectionImpl::Initialize(const std::string& configuration) { + // TODO(perkj): More initialization code? + return true; +} + void PeerConnectionImpl::RegisterObserver(PeerConnectionObserver* observer) { observer_ = observer; } +scoped_refptr PeerConnectionImpl::local_streams() { + return local_media_streams_; +} + void PeerConnectionImpl::AddStream(LocalMediaStream* local_stream) { - ScopedRefMessageData* msg = - new ScopedRefMessageData (local_stream); - signal_thread_->Post(this, MSG_ADDMEDIASTREAM, msg); + local_media_streams_->AddStream(local_stream); } void PeerConnectionImpl::RemoveStream(LocalMediaStream* remove_stream) { - ScopedRefMessageData* msg = - new ScopedRefMessageData (remove_stream); - signal_thread_->Post(this, MSG_REMOVEMEDIASTREAM, msg); + local_media_streams_->RemoveStream(remove_stream); } void PeerConnectionImpl::CommitStreamChanges() { - signal_thread_->Post(this, MSG_COMMITSTREAMCHANGES); + ScopedRefMessageData* msg = + new ScopedRefMessageData ( + LocalStreamCollection::Create(local_media_streams_)); + worker_thread_->Post(this, MSG_COMMITSTREAMCHANGES, msg); } void PeerConnectionImpl::OnMessage(talk_base::Message* msg) { talk_base::MessageData* data = msg->pdata; switch (msg->message_id) { - case MSG_ADDMEDIASTREAM: { - ScopedRefMessageData* s = - static_cast*> (data); - LocalStreamMap::iterator it = - local_media_streams_.find(s->data()->label()); - if (it != local_media_streams_.end()) - return; // Stream already exist. - const std::string& label = s->data()->label(); - local_media_streams_[label] = s->data(); - break; - } - case MSG_REMOVEMEDIASTREAM: { - ScopedRefMessageData* s = - static_cast*> (data); - local_media_streams_.erase(s->data()->label()); - break; - } case MSG_COMMITSTREAMCHANGES: { // TODO(perkj): Here is where necessary signaling // and creation of channels should happen. Also removing of channels. - // The media streams are in the local_media_streams_ array. + // The media streams are in the LocalStreamCollection in data. + // The collection is a copy of the local_media_streams_ and only + // accessible in this thread context. break; } } + delete data; // because it is Posted } } // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev.h index 533aefc354..6ccfda9b2f 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev.h @@ -28,55 +28,60 @@ #ifndef TALK_APP_WEBRTC_PEERCONNECTION_IMPL_H_ #define TALK_APP_WEBRTC_PEERCONNECTION_IMPL_H_ -#include #include #include #include "talk/app/webrtc_dev/peerconnection_dev.h" #include "talk/base/scoped_ptr.h" -#include "talk/base/messagequeue.h" +#include "talk/p2p/base/portallocator.h" namespace cricket { class ChannelManager; -class PortAllocator; } namespace webrtc { +class LocalStreamCollection; class PeerConnectionImpl : public PeerConnection, public talk_base::MessageHandler { public: 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 + 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, - talk_base::Thread* signal_thread); + talk_base::Thread* worker_thread, + PcNetworkManager* network_manager, + PcPacketSocketFactory* socket_factory); + + bool Initialize(const std::string& configuration); + virtual ~PeerConnectionImpl(); // Interfaces from PeerConnection virtual bool StartNegotiation() { - //TODO: implement + // TODO(perkj): implement + ASSERT(false); } virtual bool SignalingMessage(const std::string& msg) { - //TODO: implement + // TODO(perkj): implement + ASSERT(false); } virtual bool Send(const std::string& msg) { - //TODO: implement - } - virtual scoped_refptr local_streams() { - //TODO: implement + // TODO(perkj): implement + ASSERT(false); } + virtual scoped_refptr local_streams(); virtual scoped_refptr remote_streams() { - //TODO: implement + // TODO(perkj): implement + ASSERT(false); } virtual void AddStream(LocalMediaStream* stream); virtual void RemoveStream(LocalMediaStream* stream); @@ -89,22 +94,19 @@ class PeerConnectionImpl : public PeerConnection, private: enum { - MSG_ADDMEDIASTREAM = 1, - MSG_REMOVEMEDIASTREAM = 2, MSG_COMMITSTREAMCHANGES = 3 }; PeerConnectionObserver* observer_; + scoped_refptr local_media_streams_; - // Map of local media streams. - typedef std::map > LocalStreamMap; - LocalStreamMap local_media_streams_; - - talk_base::Thread* signal_thread_; + talk_base::Thread* worker_thread_; // Weak ref from PeerConnectionManager. cricket::ChannelManager* channel_manager_; - cricket::PortAllocator* port_allocator_; + scoped_refptr network_manager_; + scoped_refptr socket_factory_; + talk_base::scoped_ptr port_allocator_; }; -} // namespace webrtc +} // namespace webrtc -#endif // TALK_APP_WEBRTC_PEERCONNECTION_IMPL_H_ +#endif // TALK_APP_WEBRTC_PEERCONNECTION_IMPL_H_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev_unittest.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev_unittest.cc new file mode 100644 index 0000000000..6eb8369fe8 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection_impl_dev_unittest.cc @@ -0,0 +1,67 @@ +/* + * libjingle + * Copyright 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 + +#include "gtest/gtest.h" +#include "talk/app/webrtc_dev/local_stream_dev.h" +#include "talk/app/webrtc_dev/peerconnection_dev.h" +#include "talk/app/webrtc_dev/peerconnection_impl_dev.h" +#include "talk/base/scoped_ptr.h" +#include "talk/base/thread.h" + +static const char kStreamLabel1[] = "local_stream_1"; + +namespace webrtc { + +class PeerConnectionImplTest : public testing::Test { + public: + + protected: + virtual void SetUp() { + pc_factory_ = webrtc::PeerConnectionManager::Create(); + ASSERT_TRUE(pc_factory_.get() != NULL); + pc_ = pc_factory_->CreatePeerConnection(""); + ASSERT_TRUE(pc_.get() != NULL); + } + + scoped_refptr pc_factory_; + scoped_refptr pc_; +}; + +TEST_F(PeerConnectionImplTest, AddRemoveStream) { + // Create a local stream. + std::string label(kStreamLabel1); + scoped_refptr stream(LocalMediaStream::Create(label)); + + pc_->AddStream(stream); + pc_->CommitStreamChanges(); + EXPECT_EQ(pc_->local_streams()->count(), 1l); + EXPECT_EQ(pc_->local_streams()->at(0)->label().compare(kStreamLabel1), 0); +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager.cc deleted file mode 100644 index ef53779ba8..0000000000 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager.cc +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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_dev/peerconnectionmanager.h" - -#include "talk/app/webrtc_dev/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_; -} - -PeerConnectionManager::PeerConnectionManager() - : signal_thread_(new talk_base::Thread) { - -} - -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(), - signal_thread_.get()); -} - -void PeerConnectionManager::DestroyPeerConnection(PeerConnection* pc) { - delete static_cast (pc); -} - -} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager_impl.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager_impl.cc new file mode 100644 index 0000000000..932d4a742a --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager_impl.cc @@ -0,0 +1,166 @@ +/* + * 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_dev/peerconnection_impl_dev.h" +#include "talk/app/webrtc_dev/peerconnectionmanager_impl.h" +#include "talk/app/webrtc_dev/webrtc_devicemanager.h" +#include "talk/app/webrtc_dev/webrtc_mediaengine.h" +#include "talk/base/basicpacketsocketfactory.h" +#include "talk/base/thread.h" +#include "talk/session/phone/channelmanager.h" + +namespace webrtc { + +scoped_refptr PcNetworkManager::Create( + talk_base::NetworkManager* network_manager) { + RefCountImpl* implementation = + new RefCountImpl(network_manager); + return implementation; +} + +PcNetworkManager::PcNetworkManager(talk_base::NetworkManager* network_manager) + : network_manager_(network_manager) { +} + +talk_base::NetworkManager* PcNetworkManager::network_manager() const { + return network_manager_; +} + +PcNetworkManager::~PcNetworkManager() { + delete network_manager_; +} + +scoped_refptr PcPacketSocketFactory::Create( + talk_base::PacketSocketFactory* socket_factory) { + RefCountImpl* implementation = + new RefCountImpl(socket_factory); + return implementation; +} + +PcPacketSocketFactory::PcPacketSocketFactory( + talk_base::PacketSocketFactory* socket_factory) + : socket_factory_(socket_factory) { +} + +PcPacketSocketFactory::~PcPacketSocketFactory() { + delete socket_factory_; +} + +talk_base::PacketSocketFactory* PcPacketSocketFactory::socket_factory() const { + return socket_factory_; +} + +scoped_refptr PeerConnectionManager::Create() { + RefCountImpl* pc_manager = + new RefCountImpl(); + if (!pc_manager->Initialize()) { + delete pc_manager; + pc_manager = NULL; + } + return pc_manager; +} + +scoped_refptr PeerConnectionManager::Create( + talk_base::Thread* worker_thread, + PcNetworkManager* network_manager, + PcPacketSocketFactory* socket_factory, + AudioDevice* default_adm) { + RefCountImpl* pc_manager = + new RefCountImpl(worker_thread, + network_manager, + socket_factory, + default_adm); + if (!pc_manager->Initialize()) { + delete pc_manager; + pc_manager = NULL; + } + return pc_manager; +} + +PeerConnectionManagerImpl::PeerConnectionManagerImpl() + : worker_thread_(new talk_base::Thread), + network_manager_(PcNetworkManager::Create( + new talk_base::BasicNetworkManager())), + socket_factory_(PcPacketSocketFactory::Create( + new talk_base::BasicPacketSocketFactory)) { + worker_thread_ptr_ = worker_thread_.get(); +} + +PeerConnectionManagerImpl::PeerConnectionManagerImpl( + talk_base::Thread* worker_thread, + PcNetworkManager* network_manager, + PcPacketSocketFactory* socket_factory, + AudioDevice* default_adm) + : worker_thread_ptr_(worker_thread), + network_manager_(network_manager), + socket_factory_(socket_factory), + default_adm_(default_adm) { + ASSERT(worker_thread); + ASSERT(network_manager->network_manager()); + ASSERT(socket_factory->socket_factory()); + ASSERT(default_adm); +} + +PeerConnectionManagerImpl::~PeerConnectionManagerImpl() { +} + +bool PeerConnectionManagerImpl::Initialize() { + if (worker_thread_.get() && !worker_thread_->Start()) + return false; + cricket::DeviceManager* device_manager(new WebRtcDeviceManager()); + WebRtcMediaEngine* webrtc_media_engine = NULL; + if (default_adm_.get() != NULL) { + webrtc_media_engine = new WebRtcMediaEngine(default_adm_.get()->module(), + NULL, // No secondary adm. + NULL); // No vcm available. + } else { + webrtc_media_engine = new WebRtcMediaEngine(); + } + + channel_manager_.reset(new cricket::ChannelManager( + webrtc_media_engine, device_manager, worker_thread_ptr_)); + if (!channel_manager_->Init()) { + return false; + } + return true; +} + +scoped_refptr PeerConnectionManagerImpl::CreatePeerConnection( + const std::string& configuration) { + RefCountImpl* pc = + new RefCountImpl(channel_manager_.get(), + worker_thread_ptr_, + network_manager_, + socket_factory_); + if (!pc->Initialize(configuration)) { + delete pc; + pc = NULL; + } + return pc; +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager_impl.h similarity index 53% rename from third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager.h rename to third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager_impl.h index f51d38225b..d9a0914d09 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager_impl.h @@ -1,6 +1,6 @@ /* * libjingle - * Copyright 2004--2011, Google Inc. + * Copyright 2011, Google Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -24,61 +24,43 @@ * 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_ +#ifndef TALK_APP_WEBRTC_PEERCONNECTIONMANAGER_IMPL_H_ +#define TALK_APP_WEBRTC_PEERCONNECTIONMANAGER_IMPL_H_ + +#include #include "talk/base/scoped_ptr.h" +#include "talk/app/webrtc_dev/peerconnection_dev.h" +#include "talk/app/webrtc_dev/stream_dev.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 { +class PeerConnectionManagerImpl : public 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); + scoped_refptr CreatePeerConnection(const std::string& config); + bool Initialize(); protected: - PeerConnectionManager(); - virtual ~PeerConnectionManager() {}; + PeerConnectionManagerImpl(); + PeerConnectionManagerImpl(talk_base::Thread* worker_thread, + PcNetworkManager* network_manager, + PcPacketSocketFactory* socket_factory, + AudioDevice* default_adm); + virtual ~PeerConnectionManagerImpl(); 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 signal_thread_; - talk_base::scoped_ptr port_allocator_; + // Channel manager worker thread. Only used if the external thread is not set. + talk_base::scoped_ptr worker_thread_; + talk_base::Thread* worker_thread_ptr_; + scoped_refptr network_manager_; + scoped_refptr socket_factory_; talk_base::scoped_ptr channel_manager_; + + // External Audio device used for audio playback. + scoped_refptr default_adm_; }; -} // namespace webrtc +} // namespace webrtc -#endif // TALK_APP_WEBRTC_PEERCONNECTIONMANAGER_H_ +#endif // TALK_APP_WEBRTC_PEERCONNECTIONMANAGER_IMPL_H_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager_unittest.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager_unittest.cc new file mode 100644 index 0000000000..88b4d5508a --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanager_unittest.cc @@ -0,0 +1,82 @@ +/* + * libjingle + * Copyright 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 + +#include "gtest/gtest.h" +#include "talk/app/webrtc_dev/local_stream_dev.h" +#include "talk/app/webrtc_dev/peerconnectionmanager_impl.h" +#include "talk/base/basicpacketsocketfactory.h" +#include "talk/base/scoped_ptr.h" +#include "talk/base/thread.h" +#include "talk/session/phone/webrtccommon.h" +#include "talk/session/phone/webrtcvoe.h" + +static const char kAudioDeviceLabel[] = "dummy_audio_device"; + +namespace webrtc { + +TEST(PeerConnectionManager, CreatePCUsingInternalModules) { + scoped_refptr manager(PeerConnectionManager::Create()); + ASSERT_TRUE(manager.get() != NULL); + scoped_refptr pc1(manager->CreatePeerConnection("")); + EXPECT_TRUE(pc1.get() != NULL); + + scoped_refptr pc2(manager->CreatePeerConnection("")); + EXPECT_TRUE(pc2.get() != NULL); +} + +TEST(PeerConnectionManager, CreatePCUsingExternalModules) { + // Create an audio device. Use the default sound card. + AudioDeviceModule* module = AudioDeviceModule::Create(0); + scoped_refptr audio_device(AudioDevice::Create( + kAudioDeviceLabel, module)); + + // Creata a libjingle thread used as internal worker thread. + talk_base::scoped_ptr w_thread(new talk_base::Thread); + EXPECT_TRUE(w_thread->Start()); + + scoped_refptr network_manager(PcNetworkManager::Create( + new talk_base::BasicNetworkManager)); + scoped_refptr socket_factory( + PcPacketSocketFactory::Create(new talk_base::BasicPacketSocketFactory)); + + scoped_refptr manager = + PeerConnectionManager::Create(w_thread.get(), + network_manager, + socket_factory, + audio_device); + ASSERT_TRUE(manager.get() != NULL); + + scoped_refptr pc1(manager->CreatePeerConnection("")); + EXPECT_TRUE(pc1.get() != NULL); + + scoped_refptr pc2(manager->CreatePeerConnection("")); + EXPECT_TRUE(pc2.get() != NULL); +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/ref_count.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/ref_count.h index 6dca517d06..a4ba0d90f8 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/ref_count.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/ref_count.h @@ -1,3 +1,30 @@ +/* + * libjingle + * Copyright 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_REF_COUNT_H_ #define TALK_APP_WEBRTC_REF_COUNT_H_ @@ -12,18 +39,31 @@ class RefCount { template class RefCountImpl : public T { -public: + public: RefCountImpl() : ref_count_(0) { } template - RefCountImpl(P p) : ref_count_(0), T(p) { + explicit RefCountImpl(P p) : ref_count_(0), T(p) { } template RefCountImpl(P1 p1, P2 p2) : ref_count_(0), T(p1, p2) { } + template + RefCountImpl(P1 p1, P2 p2, P3 p3) : ref_count_(0), T(p1, p2, p3) { + } + + template + RefCountImpl(P1 p1, P2 p2, P3 p3, P4 p4) : ref_count_(0), T(p1, p2, p3, p4) { + } + + template + RefCountImpl(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) + : ref_count_(0), T(p1, p2, p3, p4, p5) { + } + virtual size_t AddRef() { ++ref_count_; return ref_count_; @@ -31,12 +71,13 @@ public: virtual size_t Release() { size_t ret = --ref_count_; - if(!ref_count_) { + if (!ref_count_) { delete this; } return ret; } -protected: + + protected: size_t ref_count_; }; diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_devicemanager.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_devicemanager.cc new file mode 100644 index 0000000000..a3d35b89c8 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_devicemanager.cc @@ -0,0 +1,76 @@ +/* + * libjingle + * Copyright 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_dev/webrtc_devicemanager.h" + +using cricket::Device; +using cricket::DeviceManager; + +const int WebRtcDeviceManager::kDefaultDeviceId = -1; + +WebRtcDeviceManager::WebRtcDeviceManager() + : DeviceManager(), + default_device_(DeviceManager::kDefaultDeviceName, kDefaultDeviceId) { +} + +WebRtcDeviceManager::~WebRtcDeviceManager() { + Terminate(); +} + +bool WebRtcDeviceManager::Init() { + return true; +} + +void WebRtcDeviceManager::Terminate() { +} + +bool WebRtcDeviceManager::GetAudioInputDevices(std::vector* devs) { + return GetDefaultDevices(devs); +} + +bool WebRtcDeviceManager::GetAudioOutputDevices(std::vector* devs) { + return GetDefaultDevices(devs); +} + +bool WebRtcDeviceManager::GetVideoCaptureDevices(std::vector* devs) { + return GetDefaultDevices(devs); +} + +bool WebRtcDeviceManager::GetDefaultVideoCaptureDevice(Device* device) { + *device = default_device_; + return true; +} + +bool WebRtcDeviceManager::GetDefaultDevices( + std::vector* devs) { + if (!devs) + return false; + devs->clear(); + devs->push_back(default_device_); + return true; +} diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_devicemanager.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_devicemanager.h new file mode 100644 index 0000000000..811dc9cf19 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_devicemanager.h @@ -0,0 +1,53 @@ +/* + * libjingle + * Copyright 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_DEVICEMANAGER_ +#define TALK_APP_WEBRTC_DEVICEMANAGER_ + +#include + +#include "talk/session/phone/devicemanager.h" + +class WebRtcDeviceManager : public cricket::DeviceManager { + public: + WebRtcDeviceManager(); + ~WebRtcDeviceManager(); + virtual bool Init(); + virtual void Terminate(); + virtual bool GetAudioInputDevices(std::vector* devs); + virtual bool GetAudioOutputDevices(std::vector* devs); + virtual bool GetVideoCaptureDevices(std::vector* devs); + virtual bool GetDefaultVideoCaptureDevice(cricket::Device* device); + + private: + static const int kDefaultDeviceId; + bool GetDefaultDevices(std::vector* devs); + + cricket::Device default_device_; +}; + +#endif // TALK_APP_WEBRTC_DEVICEMANAGER_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_mediaengine.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_mediaengine.cc new file mode 100644 index 0000000000..545b690baf --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_mediaengine.cc @@ -0,0 +1,153 @@ +/* + * libjingle + * Copyright 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_dev/webrtc_mediaengine.h" + +#include "talk/base/logging.h" +#include "talk/session/phone/webrtcvoiceengine.h" +#include "talk/session/phone/webrtcvideoengine.h" + +namespace webrtc { + +WebRtcMediaEngine::WebRtcMediaEngine() + : voice_(new cricket::WebRtcVoiceEngine()), + video_(new cricket::WebRtcVideoEngine()) { +} + +WebRtcMediaEngine::WebRtcMediaEngine(webrtc::AudioDeviceModule* adm, + webrtc::AudioDeviceModule* adm_sc, webrtc::VideoCaptureModule* vcm) + : voice_(new cricket::WebRtcVoiceEngine(adm, adm_sc)), + video_(new cricket::WebRtcVideoEngine(voice_, vcm)) { +} + +WebRtcMediaEngine::~WebRtcMediaEngine() { + delete video_; + delete voice_; +} + +bool WebRtcMediaEngine::Init() { + if (!voice_->Init()) + return false; + if (!video_->Init()) { + voice_->Terminate(); + return false; + } + SignalVideoCaptureResult.repeat(video_->SignalCaptureResult); + return true; +} + +void WebRtcMediaEngine::Terminate() { + video_->Terminate(); + voice_->Terminate(); +} + +int WebRtcMediaEngine::GetCapabilities() { + return (voice_->GetCapabilities() | video_->GetCapabilities()); +} + +cricket::VoiceMediaChannel* WebRtcMediaEngine::CreateChannel() { + return voice_->CreateChannel(); +} + +cricket::VideoMediaChannel* WebRtcMediaEngine::CreateVideoChannel( + cricket::VoiceMediaChannel* channel) { + return video_->CreateChannel(channel); +} + +cricket::SoundclipMedia* WebRtcMediaEngine::CreateSoundclip() { + return voice_->CreateSoundclip(); +} + +bool WebRtcMediaEngine::SetAudioOptions(int o) { + return voice_->SetOptions(o); +} + +bool WebRtcMediaEngine::SetVideoOptions(int o) { + return video_->SetOptions(o); +} + +bool WebRtcMediaEngine::SetDefaultVideoEncoderConfig( + const cricket::VideoEncoderConfig& config) { + return video_->SetDefaultEncoderConfig(config); +} + +bool WebRtcMediaEngine::SetSoundDevices(const cricket::Device* in_device, + const cricket::Device* out_device) { + return voice_->SetDevices(in_device, out_device); +} + +bool WebRtcMediaEngine::SetVideoCaptureDevice( + const cricket::Device* cam_device) { + return video_->SetCaptureDevice(cam_device); +} + +bool WebRtcMediaEngine::GetOutputVolume(int* level) { + return voice_->GetOutputVolume(level); +} + +bool WebRtcMediaEngine::SetOutputVolume(int level) { + return voice_->SetOutputVolume(level); +} + +int WebRtcMediaEngine::GetInputLevel() { + return voice_->GetInputLevel(); +} + +bool WebRtcMediaEngine::SetLocalMonitor(bool enable) { + return voice_->SetLocalMonitor(enable); +} + +bool WebRtcMediaEngine::SetLocalRenderer(cricket::VideoRenderer* renderer) { + return video_->SetLocalRenderer(renderer); +} + +cricket::CaptureResult WebRtcMediaEngine::SetVideoCapture(bool capture) { + return video_->SetCapture(capture); +} + +const std::vector& WebRtcMediaEngine::audio_codecs() { + return voice_->codecs(); +} + +const std::vector& WebRtcMediaEngine::video_codecs() { + return video_->codecs(); +} + +void WebRtcMediaEngine::SetVoiceLogging(int min_sev, const char* filter) { + return voice_->SetLogging(min_sev, filter); +} + +void WebRtcMediaEngine::SetVideoLogging(int min_sev, const char* filter) { + return video_->SetLogging(min_sev, filter); +} + +bool WebRtcMediaEngine::SetVideoCaptureModule( + webrtc::VideoCaptureModule* vcm) { + return video_->SetCaptureModule(vcm); +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_mediaengine.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_mediaengine.h new file mode 100644 index 0000000000..efe52fc80b --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/webrtc_mediaengine.h @@ -0,0 +1,86 @@ +/* + * libjingle + * Copyright 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_MEDIA_ENGINE_H_ +#define TALK_APP_WEBRTC_MEDIA_ENGINE_H_ + +#include + +#include "talk/session/phone/mediaengine.h" + +namespace cricket { +class WebRtcVideoEngine; +class WebRtcVoiceEngine; +} + +namespace webrtc { +class AudioDeviceModule; +class VideoCaptureModule; + +// TODO(perkj) Write comments. Why do we need to override cricket::MediaEngine. +class WebRtcMediaEngine : public cricket::MediaEngine { + public: + WebRtcMediaEngine(); + WebRtcMediaEngine(webrtc::AudioDeviceModule* adm, + webrtc::AudioDeviceModule* adm_sc, webrtc::VideoCaptureModule* vcm); + virtual ~WebRtcMediaEngine(); + virtual bool Init(); + virtual void Terminate(); + virtual int GetCapabilities(); + virtual cricket::VoiceMediaChannel *CreateChannel(); + virtual cricket::VideoMediaChannel *CreateVideoChannel( + cricket::VoiceMediaChannel* channel); + virtual cricket::SoundclipMedia *CreateSoundclip(); + virtual bool SetAudioOptions(int o); + virtual bool SetVideoOptions(int o); + virtual bool SetDefaultVideoEncoderConfig( + const cricket::VideoEncoderConfig& config); + virtual bool SetSoundDevices(const cricket::Device* in_device, + const cricket::Device* out_device); + virtual bool SetVideoCaptureDevice(const cricket::Device* cam_device); + virtual bool GetOutputVolume(int* level); + virtual bool SetOutputVolume(int level); + virtual int GetInputLevel(); + virtual bool SetLocalMonitor(bool enable); + virtual bool SetLocalRenderer(cricket::VideoRenderer* renderer); + virtual cricket::CaptureResult SetVideoCapture(bool capture); + virtual const std::vector& audio_codecs(); + virtual const std::vector& video_codecs(); + virtual void SetVoiceLogging(int min_sev, const char* filter); + virtual void SetVideoLogging(int min_sev, const char* filter); + + // Allow the VCM be set later if not ready during the construction time + bool SetVideoCaptureModule(webrtc::VideoCaptureModule* vcm); + + protected: + cricket::WebRtcVoiceEngine* voice_; + cricket::WebRtcVideoEngine* video_; +}; + +} // namespace WebRtcMediaEngine + +#endif // TALK_APP_WEBRTC_MEDIA_ENGINE_H_