New Peerconnection manager implementation. Ready for review.
Review URL: http://webrtc-codereview.appspot.com/134004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@540 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
b44172dab9
commit
e5ea75254f
@ -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
|
||||
@ -654,6 +660,7 @@
|
||||
'libjingle_app',
|
||||
'../../testing/gtest.gyp:gtest',
|
||||
'../../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
|
||||
},
|
||||
],
|
||||
|
@ -32,17 +32,23 @@
|
||||
|
||||
#include "talk/app/webrtc_dev/stream_dev.h"
|
||||
|
||||
namespace cricket {
|
||||
class PortAllocator;
|
||||
class DeviceManager;
|
||||
}
|
||||
|
||||
namespace talk_base {
|
||||
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<PcNetworkManager> 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<PcPacketSocketFactory> 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<PeerConnectionManager> 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<PeerConnectionManager> Create(
|
||||
talk_base::Thread* worker_thread,
|
||||
PcNetworkManager* network_manager,
|
||||
PcPacketSocketFactory* packet_socket_factory,
|
||||
AudioDevice* default_adm);
|
||||
|
||||
virtual scoped_refptr<PeerConnection> CreatePeerConnection(
|
||||
const std::string& config) = 0;
|
||||
|
||||
protected:
|
||||
// Dtor protected as objects shouldn't be deleted via this interface.
|
||||
~PeerConnectionManager() {}
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -28,75 +28,129 @@
|
||||
|
||||
#include "talk/app/webrtc_dev/peerconnection_impl_dev.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#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<LocalStreamCollection> Create() {
|
||||
RefCountImpl<LocalStreamCollection>* implementation =
|
||||
new RefCountImpl<LocalStreamCollection>();
|
||||
return implementation;
|
||||
}
|
||||
|
||||
static scoped_refptr<LocalStreamCollection> Create(
|
||||
LocalStreamCollection* local_streams) {
|
||||
RefCountImpl<LocalStreamCollection>* implementation =
|
||||
new RefCountImpl<LocalStreamCollection>(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<scoped_refptr<LocalMediaStream> >
|
||||
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<StreamCollection> PeerConnectionImpl::local_streams() {
|
||||
return local_media_streams_;
|
||||
}
|
||||
|
||||
void PeerConnectionImpl::AddStream(LocalMediaStream* local_stream) {
|
||||
ScopedRefMessageData<LocalMediaStream>* msg =
|
||||
new ScopedRefMessageData<LocalMediaStream> (local_stream);
|
||||
signal_thread_->Post(this, MSG_ADDMEDIASTREAM, msg);
|
||||
local_media_streams_->AddStream(local_stream);
|
||||
}
|
||||
|
||||
void PeerConnectionImpl::RemoveStream(LocalMediaStream* remove_stream) {
|
||||
ScopedRefMessageData<LocalMediaStream>* msg =
|
||||
new ScopedRefMessageData<LocalMediaStream> (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<LocalStreamCollection>* msg =
|
||||
new ScopedRefMessageData<LocalStreamCollection> (
|
||||
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<LocalMediaStream>* s =
|
||||
static_cast<ScopedRefMessageData<LocalMediaStream>*> (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<LocalMediaStream>* s =
|
||||
static_cast<ScopedRefMessageData<LocalMediaStream>*> (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
|
||||
|
@ -28,20 +28,19 @@
|
||||
#ifndef TALK_APP_WEBRTC_PEERCONNECTION_IMPL_H_
|
||||
#define TALK_APP_WEBRTC_PEERCONNECTION_IMPL_H_
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#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 {
|
||||
@ -58,25 +57,31 @@ class PeerConnectionImpl : public PeerConnection,
|
||||
};
|
||||
|
||||
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<StreamCollection> local_streams() {
|
||||
//TODO: implement
|
||||
// TODO(perkj): implement
|
||||
ASSERT(false);
|
||||
}
|
||||
virtual scoped_refptr<StreamCollection> local_streams();
|
||||
virtual scoped_refptr<StreamCollection> remote_streams() {
|
||||
//TODO: implement
|
||||
// TODO(perkj): implement
|
||||
ASSERT(false);
|
||||
}
|
||||
virtual void AddStream(LocalMediaStream* stream);
|
||||
virtual void RemoveStream(LocalMediaStream* stream);
|
||||
@ -89,20 +94,17 @@ class PeerConnectionImpl : public PeerConnection,
|
||||
|
||||
private:
|
||||
enum {
|
||||
MSG_ADDMEDIASTREAM = 1,
|
||||
MSG_REMOVEMEDIASTREAM = 2,
|
||||
MSG_COMMITSTREAMCHANGES = 3
|
||||
};
|
||||
|
||||
PeerConnectionObserver* observer_;
|
||||
scoped_refptr<LocalStreamCollection> local_media_streams_;
|
||||
|
||||
// Map of local media streams.
|
||||
typedef std::map<std::string, scoped_refptr<LocalMediaStream> > 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<PcNetworkManager> network_manager_;
|
||||
scoped_refptr<PcPacketSocketFactory> socket_factory_;
|
||||
talk_base::scoped_ptr<cricket::PortAllocator> port_allocator_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -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 <string>
|
||||
|
||||
#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<webrtc::PeerConnectionManager> pc_factory_;
|
||||
scoped_refptr<PeerConnection> pc_;
|
||||
};
|
||||
|
||||
TEST_F(PeerConnectionImplTest, AddRemoveStream) {
|
||||
// Create a local stream.
|
||||
std::string label(kStreamLabel1);
|
||||
scoped_refptr<LocalMediaStream> 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
|
@ -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<PeerConnectionImpl*> (pc);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -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> PcNetworkManager::Create(
|
||||
talk_base::NetworkManager* network_manager) {
|
||||
RefCountImpl<PcNetworkManager>* implementation =
|
||||
new RefCountImpl<PcNetworkManager>(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> PcPacketSocketFactory::Create(
|
||||
talk_base::PacketSocketFactory* socket_factory) {
|
||||
RefCountImpl<PcPacketSocketFactory>* implementation =
|
||||
new RefCountImpl<PcPacketSocketFactory>(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> PeerConnectionManager::Create() {
|
||||
RefCountImpl<PeerConnectionManagerImpl>* pc_manager =
|
||||
new RefCountImpl<PeerConnectionManagerImpl>();
|
||||
if (!pc_manager->Initialize()) {
|
||||
delete pc_manager;
|
||||
pc_manager = NULL;
|
||||
}
|
||||
return pc_manager;
|
||||
}
|
||||
|
||||
scoped_refptr<PeerConnectionManager> PeerConnectionManager::Create(
|
||||
talk_base::Thread* worker_thread,
|
||||
PcNetworkManager* network_manager,
|
||||
PcPacketSocketFactory* socket_factory,
|
||||
AudioDevice* default_adm) {
|
||||
RefCountImpl<PeerConnectionManagerImpl>* pc_manager =
|
||||
new RefCountImpl<PeerConnectionManagerImpl>(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<PeerConnection> PeerConnectionManagerImpl::CreatePeerConnection(
|
||||
const std::string& configuration) {
|
||||
RefCountImpl<PeerConnectionImpl>* pc =
|
||||
new RefCountImpl<PeerConnectionImpl>(channel_manager_.get(),
|
||||
worker_thread_ptr_,
|
||||
network_manager_,
|
||||
socket_factory_);
|
||||
if (!pc->Initialize(configuration)) {
|
||||
delete pc;
|
||||
pc = NULL;
|
||||
}
|
||||
return pc;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -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 <string>
|
||||
|
||||
#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<PeerConnection> 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<talk_base::Thread> signal_thread_;
|
||||
talk_base::scoped_ptr<cricket::PortAllocator> port_allocator_;
|
||||
// Channel manager worker thread. Only used if the external thread is not set.
|
||||
talk_base::scoped_ptr<talk_base::Thread> worker_thread_;
|
||||
talk_base::Thread* worker_thread_ptr_;
|
||||
scoped_refptr<PcNetworkManager> network_manager_;
|
||||
scoped_refptr<PcPacketSocketFactory> socket_factory_;
|
||||
talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_;
|
||||
|
||||
// External Audio device used for audio playback.
|
||||
scoped_refptr<AudioDevice> default_adm_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // TALK_APP_WEBRTC_PEERCONNECTIONMANAGER_H_
|
||||
#endif // TALK_APP_WEBRTC_PEERCONNECTIONMANAGER_IMPL_H_
|
@ -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 <string>
|
||||
|
||||
#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<PeerConnectionManager> manager(PeerConnectionManager::Create());
|
||||
ASSERT_TRUE(manager.get() != NULL);
|
||||
scoped_refptr<PeerConnection> pc1(manager->CreatePeerConnection(""));
|
||||
EXPECT_TRUE(pc1.get() != NULL);
|
||||
|
||||
scoped_refptr<webrtc::PeerConnection> 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<AudioDevice> audio_device(AudioDevice::Create(
|
||||
kAudioDeviceLabel, module));
|
||||
|
||||
// Creata a libjingle thread used as internal worker thread.
|
||||
talk_base::scoped_ptr<talk_base::Thread> w_thread(new talk_base::Thread);
|
||||
EXPECT_TRUE(w_thread->Start());
|
||||
|
||||
scoped_refptr<PcNetworkManager> network_manager(PcNetworkManager::Create(
|
||||
new talk_base::BasicNetworkManager));
|
||||
scoped_refptr<PcPacketSocketFactory> socket_factory(
|
||||
PcPacketSocketFactory::Create(new talk_base::BasicPacketSocketFactory));
|
||||
|
||||
scoped_refptr<PeerConnectionManager> manager =
|
||||
PeerConnectionManager::Create(w_thread.get(),
|
||||
network_manager,
|
||||
socket_factory,
|
||||
audio_device);
|
||||
ASSERT_TRUE(manager.get() != NULL);
|
||||
|
||||
scoped_refptr<webrtc::PeerConnection> pc1(manager->CreatePeerConnection(""));
|
||||
EXPECT_TRUE(pc1.get() != NULL);
|
||||
|
||||
scoped_refptr<webrtc::PeerConnection> pc2(manager->CreatePeerConnection(""));
|
||||
EXPECT_TRUE(pc2.get() != NULL);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -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_
|
||||
|
||||
@ -17,13 +44,26 @@ public:
|
||||
}
|
||||
|
||||
template<typename P>
|
||||
RefCountImpl(P p) : ref_count_(0), T(p) {
|
||||
explicit RefCountImpl(P p) : ref_count_(0), T(p) {
|
||||
}
|
||||
|
||||
template<typename P1, typename P2>
|
||||
RefCountImpl(P1 p1, P2 p2) : ref_count_(0), T(p1, p2) {
|
||||
}
|
||||
|
||||
template<typename P1, typename P2, typename P3>
|
||||
RefCountImpl(P1 p1, P2 p2, P3 p3) : ref_count_(0), T(p1, p2, p3) {
|
||||
}
|
||||
|
||||
template<typename P1, typename P2, typename P3, typename P4>
|
||||
RefCountImpl(P1 p1, P2 p2, P3 p3, P4 p4) : ref_count_(0), T(p1, p2, p3, p4) {
|
||||
}
|
||||
|
||||
template<typename P1, typename P2, typename P3, typename P4, typename P5>
|
||||
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_;
|
||||
@ -36,6 +76,7 @@ public:
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t ref_count_;
|
||||
};
|
||||
|
@ -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<Device>* devs) {
|
||||
return GetDefaultDevices(devs);
|
||||
}
|
||||
|
||||
bool WebRtcDeviceManager::GetAudioOutputDevices(std::vector<Device>* devs) {
|
||||
return GetDefaultDevices(devs);
|
||||
}
|
||||
|
||||
bool WebRtcDeviceManager::GetVideoCaptureDevices(std::vector<Device>* devs) {
|
||||
return GetDefaultDevices(devs);
|
||||
}
|
||||
|
||||
bool WebRtcDeviceManager::GetDefaultVideoCaptureDevice(Device* device) {
|
||||
*device = default_device_;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WebRtcDeviceManager::GetDefaultDevices(
|
||||
std::vector<cricket::Device>* devs) {
|
||||
if (!devs)
|
||||
return false;
|
||||
devs->clear();
|
||||
devs->push_back(default_device_);
|
||||
return true;
|
||||
}
|
@ -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 <vector>
|
||||
|
||||
#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<cricket::Device>* devs);
|
||||
virtual bool GetAudioOutputDevices(std::vector<cricket::Device>* devs);
|
||||
virtual bool GetVideoCaptureDevices(std::vector<cricket::Device>* devs);
|
||||
virtual bool GetDefaultVideoCaptureDevice(cricket::Device* device);
|
||||
|
||||
private:
|
||||
static const int kDefaultDeviceId;
|
||||
bool GetDefaultDevices(std::vector<cricket::Device>* devs);
|
||||
|
||||
cricket::Device default_device_;
|
||||
};
|
||||
|
||||
#endif // TALK_APP_WEBRTC_DEVICEMANAGER_
|
@ -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<cricket::AudioCodec>& WebRtcMediaEngine::audio_codecs() {
|
||||
return voice_->codecs();
|
||||
}
|
||||
|
||||
const std::vector<cricket::VideoCodec>& 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
|
@ -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 <vector>
|
||||
|
||||
#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<cricket::AudioCodec>& audio_codecs();
|
||||
virtual const std::vector<cricket::VideoCodec>& 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_
|
Loading…
Reference in New Issue
Block a user