This CL adding a factory class which has the responsibility of creating peerconnection objects. This is very basic class doesn't do any reference count, user has the responsibility to delete the object externally.

Review URL: http://webrtc-codereview.appspot.com/122006

git-svn-id: http://webrtc.googlecode.com/svn/trunk@443 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mallinath@webrtc.org 2011-08-24 23:50:05 +00:00
parent d1015fe677
commit 1cdc6b5d79
12 changed files with 259 additions and 336 deletions

View File

@ -555,9 +555,10 @@
{
'target_name': 'libjingle_app',
'type': '<(library)',
'sources': [
'<(libjingle_mods)/source/talk/app/webrtc/peerconnection.cc',
'sources': [
'<(libjingle_mods)/source/talk/app/webrtc/peerconnection.h',
'<(libjingle_mods)/source/talk/app/webrtc/peerconnectionfactory.h',
'<(libjingle_mods)/source/talk/app/webrtc/peerconnectionfactory.cc',
'<(libjingle_mods)/source/talk/app/webrtc/peerconnectionimpl_callbacks.h',
'<(libjingle_mods)/source/talk/app/webrtc/peerconnection_impl.cc',
'<(libjingle_mods)/source/talk/app/webrtc/peerconnection_impl.h',

View File

@ -1,48 +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/peerconnection_proxy.h"
namespace webrtc {
PeerConnection* PeerConnection::Create(const std::string& config,
cricket::PortAllocator* port_allocator,
cricket::MediaEngine* media_engine,
talk_base::Thread* worker_thread,
talk_base::Thread* signaling_thread,
cricket::DeviceManager* device_manager) {
return new PeerConnectionProxy(config, port_allocator, media_engine,
worker_thread, signaling_thread, device_manager);
}
PeerConnection* PeerConnection::Create(const std::string& config,
cricket::PortAllocator* port_allocator,
talk_base::Thread* worker_thread) {
return new PeerConnectionProxy(config, port_allocator, worker_thread);
}
} // namespace webrtc

View File

@ -37,9 +37,6 @@
#include <string>
namespace cricket {
class DeviceManager;
class MediaEngine;
class PortAllocator;
class VideoRenderer;
}
@ -75,18 +72,6 @@ class PeerConnectionObserver {
class PeerConnection {
public:
virtual ~PeerConnection() {}
static PeerConnection* Create(const std::string& config,
cricket::PortAllocator* port_allocator,
cricket::MediaEngine* media_engine,
talk_base::Thread* worker_thread,
talk_base::Thread* signaling_thread,
cricket::DeviceManager* device_manager);
static PeerConnection* Create(const std::string& config,
cricket::PortAllocator* port_allocator,
talk_base::Thread* worker_thread);
// Initialize
virtual bool Init() = 0;
// Register a listener
virtual void RegisterObserver(PeerConnectionObserver* observer) = 0;

View File

@ -33,138 +33,35 @@
#include "talk/base/helpers.h"
#include "talk/base/logging.h"
#include "talk/base/stringencode.h"
#include "talk/p2p/base/session.h"
#include "talk/p2p/client/basicportallocator.h"
namespace webrtc {
// The number of the tokens in the config string.
static const size_t kConfigTokens = 2;
// The default stun port.
static const int kDefaultStunPort = 3478;
PeerConnectionImpl::PeerConnectionImpl(const std::string& config,
cricket::PortAllocator* port_allocator,
cricket::MediaEngine* media_engine,
talk_base::Thread* worker_thread,
talk_base::Thread* signaling_thread,
cricket::DeviceManager* device_manager)
: config_(config),
port_allocator_(port_allocator),
media_engine_(media_engine),
worker_thread_(worker_thread),
device_manager_(device_manager),
PeerConnectionImpl::PeerConnectionImpl(
cricket::PortAllocator* port_allocator,
cricket::ChannelManager* channel_manager,
talk_base::Thread* signaling_thread)
: port_allocator_(port_allocator),
channel_manager_(channel_manager),
signaling_thread_(signaling_thread),
initialized_(false),
service_type_(SERVICE_COUNT),
event_callback_(NULL),
session_(NULL),
incoming_(false) {
}
PeerConnectionImpl::PeerConnectionImpl(const std::string& config,
cricket::PortAllocator* port_allocator,
talk_base::Thread* worker_thread)
: config_(config),
port_allocator_(port_allocator),
media_engine_(NULL),
worker_thread_(worker_thread),
device_manager_(NULL),
signaling_thread_(NULL),
initialized_(false),
service_type_(SERVICE_COUNT),
event_callback_(NULL),
session_(NULL),
incoming_(false) {
session_(NULL) {
}
PeerConnectionImpl::~PeerConnectionImpl() {
session_.reset();
channel_manager_.reset();
}
bool PeerConnectionImpl::Init() {
ASSERT(!initialized_);
std::vector<talk_base::SocketAddress> stun_hosts;
talk_base::SocketAddress stun_addr;
if (!ParseConfigString(config_, &stun_addr))
return false;
stun_hosts.push_back(stun_addr);
// TODO(mallinath) - Changes are required to modify the stand alone
// constructor to get signaling thread as input. It should not be created
// here.
if (!signaling_thread_) {
signaling_thread_ = new talk_base::Thread();
if (!signaling_thread_->SetName("signaling thread", this) ||
!signaling_thread_->Start()) {
LOG(WARNING) << "Failed to start libjingle signaling thread";
return false;
}
}
// create cricket::ChannelManager object
ASSERT(worker_thread_ != NULL);
if (media_engine_ && device_manager_) {
channel_manager_.reset(new cricket::ChannelManager(
media_engine_, device_manager_, worker_thread_));
} else {
channel_manager_.reset(new cricket::ChannelManager(worker_thread_));
}
initialized_ = channel_manager_->Init();
if (event_callback_) {
// TODO(ronghuawu): OnInitialized is no longer needed.
if (initialized_)
event_callback_->OnInitialized();
}
return initialized_;
}
bool PeerConnectionImpl::ParseConfigString(
const std::string& config, talk_base::SocketAddress* stun_addr) {
std::vector<std::string> tokens;
talk_base::tokenize(config_, ' ', &tokens);
if (tokens.size() != kConfigTokens) {
LOG(WARNING) << "Invalid config string";
std::string sid;
talk_base::CreateRandomString(8, &sid);
const bool incoming = false;
session_.reset(CreateMediaSession(sid, incoming)); // default outgoing direction
if (session_.get() == NULL) {
ASSERT(false && "failed to initialize a session");
return false;
}
service_type_ = SERVICE_COUNT;
// NOTE: Must be in the same order as the enum.
static const char* kValidServiceTypes[SERVICE_COUNT] = {
"STUN", "STUNS", "TURN", "TURNS"
};
const std::string& type = tokens[0];
for (size_t i = 0; i < SERVICE_COUNT; ++i) {
if (type.compare(kValidServiceTypes[i]) == 0) {
service_type_ = static_cast<ServiceType>(i);
break;
}
}
if (service_type_ == SERVICE_COUNT) {
LOG(WARNING) << "Invalid service type: " << type;
return false;
}
std::string service_address = tokens[1];
int port;
tokens.clear();
talk_base::tokenize(service_address, ':', &tokens);
if (tokens.size() != kConfigTokens) {
port = kDefaultStunPort;
} else {
port = atoi(tokens[1].c_str());
if (port <= 0 || port > 0xffff) {
LOG(WARNING) << "Invalid port: " << tokens[1];
return false;
}
}
stun_addr->SetIP(service_address);
stun_addr->SetPort(port);
return true;
}
@ -187,36 +84,23 @@ bool PeerConnectionImpl::SignalingMessage(
}
bool ret = false;
if (!session_.get()) {
// this will be incoming call
std::string sid;
talk_base::CreateRandomString(8, &sid);
std::string direction("r");
session_.reset(CreateMediaSession(sid, direction));
if (session_.get() == NULL) {
ASSERT(false && "failed to initialize a session");
return false;
}
incoming_ = true;
if (GetReadyState() == NEW) {
// set direction to incoming, as message received first
session_->set_incoming(true);
ret = session_->OnInitiateMessage(incoming_sdp, candidates);
} else {
ret = session_->OnRemoteDescription(incoming_sdp, candidates);
}
return ret;
}
WebRtcSession* PeerConnectionImpl::CreateMediaSession(
const std::string& id, const std::string& dir) {
const std::string& id, bool incoming) {
ASSERT(port_allocator_ != NULL);
WebRtcSession* session = new WebRtcSession(id, dir,
port_allocator_, channel_manager_.get(),
signaling_thread_);
WebRtcSession* session = new WebRtcSession(id, incoming,
port_allocator_, channel_manager_, signaling_thread_);
if (session->Initiate()) {
session->SignalRemoveStreamMessage.connect(
this,
&PeerConnectionImpl::SendRemoveSignal);
session->SignalAddStream.connect(
this,
&PeerConnectionImpl::OnAddStream);
@ -239,31 +123,7 @@ WebRtcSession* PeerConnectionImpl::CreateMediaSession(
return session;
}
void PeerConnectionImpl::SendRemoveSignal(WebRtcSession* session) {
std::string message;
if (GetJSONSignalingMessage(session->remote_description(),
session->local_candidates(), &message)) {
if (event_callback_) {
event_callback_->OnSignalingMessage(message);
// TODO(ronghuawu): Notify the client when the PeerConnection object
// doesn't have any streams. Something like the onreadystatechanged
// + setting readyState to 'CLOSED'.
}
}
}
bool PeerConnectionImpl::AddStream(const std::string& stream_id, bool video) {
if (!session_.get()) {
// if session doesn't exist then this should be an outgoing call
std::string sid;
talk_base::CreateRandomString(8, &sid);
session_.reset(CreateMediaSession(sid, "s"));
if (session_.get() == NULL) {
ASSERT(false && "failed to initialize a session");
return false;
}
}
bool ret = false;
if (session_->HasStream(stream_id)) {
ASSERT(false && "A stream with this name already exists");
@ -280,9 +140,6 @@ bool PeerConnectionImpl::AddStream(const std::string& stream_id, bool video) {
}
bool PeerConnectionImpl::RemoveStream(const std::string& stream_id) {
if (!session_.get()) {
return false;
}
return session_->RemoveStream(stream_id);
}
@ -321,9 +178,6 @@ bool PeerConnectionImpl::SetLocalVideoRenderer(
bool PeerConnectionImpl::SetVideoRenderer(const std::string& stream_id,
cricket::VideoRenderer* renderer) {
if (!session_.get()) {
return false;
}
return session_->SetVideoRenderer(stream_id, renderer);
}
@ -332,17 +186,11 @@ bool PeerConnectionImpl::SetVideoCapture(const std::string& cam_device) {
}
bool PeerConnectionImpl::Connect() {
if (!session_.get()) {
return false;
}
return session_->Connect();
}
// TODO(mallinath) - Close is not used anymore, should be removed.
bool PeerConnectionImpl::Close() {
if (!session_.get()) {
return false;
}
session_->RemoveAllStreams();
return true;
}
@ -368,4 +216,19 @@ void PeerConnectionImpl::OnRtcMediaChannelCreated(const std::string& stream_id,
}
}
PeerConnectionImpl::ReadyState PeerConnectionImpl::GetReadyState() {
ReadyState ready_state;
cricket::BaseSession::State state = session_->state();
if (state == cricket::BaseSession::STATE_INIT) {
ready_state = NEW;
} else if (state == cricket::BaseSession::STATE_INPROGRESS) {
ready_state = ACTIVE;
} else if (state == cricket::BaseSession::STATE_DEINIT) {
ready_state = CLOSED;
} else {
ready_state = NEGOTIATING;
}
return ready_state;
}
} // namespace webrtc

View File

@ -34,10 +34,12 @@
#include "talk/app/webrtc/peerconnection.h"
#include "talk/base/sigslot.h"
#include "talk/base/scoped_ptr.h"
#include "talk/base/thread.h"
#include "talk/session/phone/channelmanager.h"
namespace cricket {
class DeviceManager;
class ChannelManager;
class PortAllocator;
class SessionDescription;
}
@ -47,15 +49,9 @@ class WebRtcSession;
class PeerConnectionImpl : public PeerConnection,
public sigslot::has_slots<> {
public:
PeerConnectionImpl(const std::string& config,
cricket::PortAllocator* port_allocator,
cricket::MediaEngine* media_engine,
talk_base::Thread* worker_thread,
talk_base::Thread* signaling_thread,
cricket::DeviceManager* device_manager);
PeerConnectionImpl(const std::string& config,
cricket::PortAllocator* port_allocator,
talk_base::Thread* worker_thread);
PeerConnectionImpl(cricket::PortAllocator* port_allocator,
cricket::ChannelManager* channel_manager,
talk_base::Thread* signaling_thread);
virtual ~PeerConnectionImpl();
enum ReadyState {
@ -66,7 +62,6 @@ class PeerConnectionImpl : public PeerConnection,
};
// PeerConnection interfaces
bool Init();
void RegisterObserver(PeerConnectionObserver* observer);
bool SignalingMessage(const std::string& msg);
bool AddStream(const std::string& stream_id, bool video);
@ -80,13 +75,9 @@ class PeerConnectionImpl : public PeerConnection,
cricket::VideoRenderer* renderer);
bool SetVideoCapture(const std::string& cam_device);
// Access to the members
const std::string& config() const { return config_; }
bool incoming() const { return incoming_; }
cricket::ChannelManager* channel_manager() {
return channel_manager_.get();
return channel_manager_;
}
ReadyState ready_state() const { return ready_state_; }
// Callbacks from PeerConnectionImplCallbacks
void OnAddStream(const std::string& stream_id, bool video);
@ -97,45 +88,22 @@ class PeerConnectionImpl : public PeerConnection,
void OnFailedCall();
void OnRtcMediaChannelCreated(const std::string& stream_id,
bool video);
bool Init();
private:
ReadyState GetReadyState();
bool ParseConfigString(const std::string& config,
talk_base::SocketAddress* stun_addr);
void SendRemoveSignal(WebRtcSession* session);
WebRtcSession* CreateMediaSession(const std::string& id,
const std::string& dir);
WebRtcSession* CreateMediaSession(const std::string& id, bool incoming);
std::string config_;
talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_;
cricket::PortAllocator* port_allocator_;
cricket::MediaEngine* media_engine_;
talk_base::Thread* worker_thread_;
cricket::DeviceManager* device_manager_;
cricket::ChannelManager* channel_manager_;
talk_base::Thread* signaling_thread_;
bool initialized_;
ReadyState ready_state_;
// TODO(ronghuawu/tommi): Replace the initialized_ with ready_state_.
// Fire notifications via the observer interface
// when ready_state_ changes (i.e. onReadyStateChanged()).
// NOTE: The order of the enum values must be in sync with the array
// in Init().
enum ServiceType {
STUN,
STUNS,
TURN,
TURNS,
SERVICE_COUNT, // Also means 'invalid'.
};
ServiceType service_type_;
PeerConnectionObserver* event_callback_;
talk_base::scoped_ptr<WebRtcSession> session_;
// TODO(ronghua): There's no such concept as "incoming" and "outgoing"
// according to the spec. This will be removed in the new PeerConnection.
bool incoming_;
};
}
} // namespace webrtc
#endif // TALK_APP_WEBRTC_PEERCONNECTION_IMPL_H_

View File

@ -130,44 +130,21 @@ struct ResultParams : public talk_base::MessageData {
bool result;
};
PeerConnectionProxy::PeerConnectionProxy(const std::string& config,
cricket::PortAllocator* port_allocator,
cricket::MediaEngine* media_engine,
talk_base::Thread* worker_thread,
talk_base::Thread* signaling_thread,
cricket::DeviceManager* device_manager)
: peerconnection_impl_(new PeerConnectionImpl(config, port_allocator,
media_engine, worker_thread, signaling_thread,
device_manager)),
PeerConnectionProxy::PeerConnectionProxy(
cricket::PortAllocator* port_allocator,
cricket::ChannelManager* channel_manager,
talk_base::Thread* signaling_thread)
: peerconnection_impl_(new PeerConnectionImpl(port_allocator,
channel_manager, signaling_thread)),
signaling_thread_(signaling_thread) {
}
PeerConnectionProxy::PeerConnectionProxy(const std::string& config,
cricket::PortAllocator* port_allocator,
talk_base::Thread* worker_thread)
: peerconnection_impl_(new PeerConnectionImpl(config, port_allocator,
worker_thread)),
signaling_thread_(NULL) {
}
PeerConnectionProxy::~PeerConnectionProxy() {
ResultParams params;
Send(MSG_WEBRTC_RELEASE, &params);
}
bool PeerConnectionProxy::Init() {
// TODO(mallinath) - Changes are required to modify the stand alone
// constructor to get signaling thread as input. It should not be created
// here.
if (!signaling_thread_) {
signaling_thread_ = new talk_base::Thread();
if (!signaling_thread_->SetName("signaling thread", this) ||
!signaling_thread_->Start()) {
LOG(WARNING) << "Failed to start libjingle signaling thread";
return false;
}
}
ResultParams params;
return (Send(MSG_WEBRTC_INIT, &params) && params.result);
}

View File

@ -35,26 +35,23 @@
#include "talk/base/thread.h"
namespace cricket {
class DeviceManager;
class ChannelManager;
class PortAllocator;
}
namespace webrtc {
class PeerConnectionImpl;
class PeerConnectionProxy : public PeerConnection,
public talk_base::MessageHandler {
public:
PeerConnectionProxy(const std::string& config,
cricket::PortAllocator* port_allocator,
cricket::MediaEngine* media_engine,
talk_base::Thread* worker_thread,
talk_base::Thread* signaling_thread,
cricket::DeviceManager* device_manager);
PeerConnectionProxy(const std::string& config,
cricket::PortAllocator* port_allocator,
talk_base::Thread* worker_thread);
PeerConnectionProxy(cricket::PortAllocator* port_allocator,
cricket::ChannelManager* channel_manager,
talk_base::Thread* signaling_thread);
virtual ~PeerConnectionProxy();
// PeerConnection interfaces
bool Init();
void RegisterObserver(PeerConnectionObserver* observer);
bool SignalingMessage(const std::string& msg);
bool AddStream(const std::string& stream_id, bool video);
@ -69,11 +66,15 @@ class PeerConnectionProxy : public PeerConnection,
bool SetVideoCapture(const std::string& cam_device);
private:
bool Init();
bool Send(uint32 id, talk_base::MessageData* data);
virtual void OnMessage(talk_base::Message* message);
talk_base::scoped_ptr<PeerConnection> peerconnection_impl_;
talk_base::scoped_ptr<PeerConnectionImpl> peerconnection_impl_;
talk_base::Thread* signaling_thread_;
friend class PeerConnectionFactory;
};
}

View File

@ -0,0 +1,119 @@
#include "talk/app/webrtc/peerconnectionfactory.h"
#include "talk/app/webrtc/peerconnection_proxy.h"
#include "talk/base/logging.h"
#include "talk/p2p/client/basicportallocator.h"
#include "talk/session/phone/channelmanager.h"
namespace {
// The number of the tokens in the config string.
static const size_t kConfigTokens = 2;
// The default stun port.
static const int kDefaultStunPort = 3478;
// NOTE: Must be in the same order as the enum.
static const char* kValidServiceTypes[
webrtc::PeerConnectionFactory::SERVICE_COUNT] = {
"STUN", "STUNS", "TURN", "TURNS" };
}
namespace webrtc {
PeerConnectionFactory::PeerConnectionFactory(
const std::string& config,
cricket::PortAllocator* port_allocator,
cricket::MediaEngine* media_engine,
cricket::DeviceManager* device_manager,
talk_base::Thread* worker_thread)
: config_(config),
initialized_(false),
port_allocator_(port_allocator),
channel_manager_(new cricket::ChannelManager(
media_engine, device_manager, worker_thread)) {
}
PeerConnectionFactory::PeerConnectionFactory(
const std::string& config,
cricket::PortAllocator* port_allocator,
talk_base::Thread* worker_thread)
: config_(config),
initialized_(false),
port_allocator_(port_allocator),
channel_manager_(new cricket::ChannelManager(worker_thread)) {
}
PeerConnectionFactory::~PeerConnectionFactory() {
}
bool PeerConnectionFactory::Initialize() {
ASSERT(channel_manager_.get());
std::vector<talk_base::SocketAddress> stun_hosts;
talk_base::SocketAddress stun_addr;
if (!ParseConfigString(config_, &stun_addr))
return false;
stun_hosts.push_back(stun_addr);
initialized_ = channel_manager_->Init();
return initialized_;
}
PeerConnection* PeerConnectionFactory::CreatePeerConnection(
talk_base::Thread* signaling_thread) {
PeerConnectionProxy* pc = NULL;
if (initialized_) {
pc = new PeerConnectionProxy(
port_allocator_.get(), channel_manager_.get(), signaling_thread);
if (!pc->Init()) {
LOG(LERROR) << "Error in initializing PeerConnection";
delete pc;
pc = NULL;
}
} else {
LOG(LERROR) << "PeerConnectionFactory is not initialize";
}
return pc;
}
bool PeerConnectionFactory::ParseConfigString(
const std::string& config, talk_base::SocketAddress* stun_addr) {
std::vector<std::string> tokens;
talk_base::tokenize(config_, ' ', &tokens);
if (tokens.size() != kConfigTokens) {
LOG(WARNING) << "Invalid config string";
return false;
}
service_type_ = INVALID;
const std::string& type = tokens[0];
for (size_t i = 0; i < SERVICE_COUNT; ++i) {
if (type.compare(kValidServiceTypes[i]) == 0) {
service_type_ = static_cast<ServiceType>(i);
break;
}
}
if (service_type_ == SERVICE_COUNT) {
LOG(WARNING) << "Invalid service type: " << type;
return false;
}
std::string service_address = tokens[1];
int port;
tokens.clear();
talk_base::tokenize(service_address, ':', &tokens);
if (tokens.size() != kConfigTokens) {
port = kDefaultStunPort;
} else {
port = atoi(tokens[1].c_str());
if (port <= 0 || port > 0xffff) {
LOG(WARNING) << "Invalid port: " << tokens[1];
return false;
}
}
stun_addr->SetIP(service_address);
stun_addr->SetPort(port);
return true;
}
} // namespace webrtc

View File

@ -0,0 +1,64 @@
#ifndef TALK_APP_WEBRTC_PEERCONNECTIONFACTORY_H_
#define TALK_APP_WEBRTC_PEERCONNECTIONFACTORY_H_
#include <string>
#include <vector>
#include "talk/base/scoped_ptr.h"
namespace cricket {
class ChannelManager;
class DeviceManager;
class MediaEngine;
class PortAllocator;
} // namespace cricket
namespace talk_base {
class SocketAddress;
class Thread;
} // namespace talk_base
namespace webrtc {
class PeerConnection;
class PeerConnectionFactory {
public:
// NOTE: The order of the enum values must be in sync with the array
// in Initialize().
enum ServiceType {
STUN = 0,
STUNS,
TURN,
TURNS,
SERVICE_COUNT,
INVALID
};
PeerConnectionFactory(const std::string& config,
cricket::PortAllocator* port_allocator,
cricket::MediaEngine* media_engine,
cricket::DeviceManager* device_manager,
talk_base::Thread* worker_thread);
PeerConnectionFactory(const std::string& config,
cricket::PortAllocator* port_allocator,
talk_base::Thread* worker_thread);
virtual ~PeerConnectionFactory();
bool Initialize();
PeerConnection* CreatePeerConnection(talk_base::Thread* signaling_thread);
private:
bool ParseConfigString(const std::string&, talk_base::SocketAddress*);
ServiceType service_type_;
std::string config_;
bool initialized_;
talk_base::scoped_ptr<cricket::PortAllocator> port_allocator_;
talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_;
};
} // namespace webrtc
#endif // TALK_APP_WEBRTC_PEERCONNECTIONFACTORY_H_

View File

@ -64,12 +64,9 @@ typedef std::vector<StreamInfo*> StreamMap; // not really a map (vector)
static const char kVideoStream[] = "video_rtp";
static const char kAudioStream[] = "rtp";
const char WebRtcSession::kOutgoingDirection[] = "s";
const char WebRtcSession::kIncomingDirection[] = "r";
WebRtcSession::WebRtcSession(
const std::string& id,
const std::string& direction,
bool incoming,
cricket::PortAllocator* allocator,
cricket::ChannelManager* channelmgr,
talk_base::Thread* signaling_thread)
@ -82,7 +79,7 @@ WebRtcSession::WebRtcSession(
setup_timeout_(kCallSetupTimeout),
signaling_thread_(signaling_thread),
id_(id),
incoming_(direction == kIncomingDirection),
incoming_(incoming),
port_allocator_(allocator) {
BaseSession::sid_ = id;
}

View File

@ -78,7 +78,7 @@ typedef std::vector<cricket::VideoCodec> VideoCodecs;
class WebRtcSession : public cricket::BaseSession {
public:
WebRtcSession(const std::string& id,
const std::string& direction,
bool incoming,
cricket::PortAllocator* allocator,
cricket::ChannelManager* channelmgr,
talk_base::Thread* signaling_thread);
@ -142,6 +142,7 @@ class WebRtcSession : public cricket::BaseSession {
return local_candidates_;
}
const std::string& id() const { return id_; }
void set_incoming(bool incoming) { incoming_ = incoming; }
bool incoming() const { return incoming_; }
cricket::PortAllocator* port_allocator() const { return port_allocator_; }
talk_base::Thread* signaling_thread() const { return signaling_thread_; }

View File

@ -280,11 +280,6 @@ class WebRtcSessionTest : public OnSignalImpl {
return return_value;
}
std::string DirectionAsString() {
// Direction is either "r"=incoming or "s"=outgoing.
return (receiving_) ? "r" : "s";
}
bool WaitForCallback(CallbackId id, int timeout_ms) {
bool success = false;
for (int ms = 0; ms < timeout_ms; ms++) {
@ -324,7 +319,7 @@ class WebRtcSessionTest : public OnSignalImpl {
talk_base::CreateRandomString(8, &id_);
session_ = new webrtc::WebRtcSession(
id_, DirectionAsString() , allocator_,
id_, receiving_ , allocator_,
channel_manager_,
signaling_thread_);
session_->SignalAddStream.connect(