Notifier and RefCount interface and implementation class name changed according to the naming convention.

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@781 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mallinath@webrtc.org 2011-10-20 06:24:24 +00:00
parent ae499a2ac8
commit f553ec70c7
35 changed files with 469 additions and 375 deletions

View File

@ -53,18 +53,19 @@ const char* AudioTrack::kind() const {
return kAudioTrackKind;
}
scoped_refptr<AudioTrack> AudioTrack::CreateRemote(const std::string& label,
uint32 ssrc) {
talk_base::RefCountImpl<AudioTrack>* track =
new talk_base::RefCountImpl<AudioTrack>(label, ssrc);
talk_base::scoped_refptr<AudioTrack> AudioTrack::CreateRemote(
const std::string& label,
uint32 ssrc) {
talk_base::RefCount<AudioTrack>* track =
new talk_base::RefCount<AudioTrack>(label, ssrc);
return track;
}
scoped_refptr<AudioTrack> AudioTrack::CreateLocal(
talk_base::scoped_refptr<AudioTrack> AudioTrack::CreateLocal(
const std::string& label,
AudioDeviceModule* audio_device) {
talk_base::RefCountImpl<AudioTrack>* track =
new talk_base::RefCountImpl<AudioTrack>(label, audio_device);
talk_base::RefCount<AudioTrack>* track =
new talk_base::RefCount<AudioTrack>(label, audio_device);
return track;
}

View File

@ -44,11 +44,13 @@ namespace webrtc {
class AudioTrack : public MediaTrack<LocalAudioTrackInterface> {
public:
// Creates a remote audio track.
static scoped_refptr<AudioTrack> CreateRemote(const std::string& label,
uint32 ssrc);
static talk_base::scoped_refptr<AudioTrack> CreateRemote(
const std::string& label,
uint32 ssrc);
// Creates a local audio track.
static scoped_refptr<AudioTrack> CreateLocal(const std::string& label,
AudioDeviceModule* audio_device);
static talk_base::scoped_refptr<AudioTrack> CreateLocal(
const std::string& label,
AudioDeviceModule* audio_device);
// Get the AudioDeviceModule associated with this track.
virtual AudioDeviceModule* GetAudioDevice();
@ -61,7 +63,7 @@ class AudioTrack : public MediaTrack<LocalAudioTrackInterface> {
AudioTrack(const std::string& label, AudioDeviceModule* audio_device);
private:
scoped_refptr<AudioDeviceModule> audio_device_;
talk_base::scoped_refptr<AudioDeviceModule> audio_device_;
};
} // namespace webrtc

View File

@ -25,6 +25,12 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// This file contains interfaces for MediaStream and MediaTrack. These
// interfaces are used for implementing MediaStream and MediaTrack as defined
// in http://dev.w3.org/2011/webrtc/editor/webrtc.html#stream-api. These
// interfaces must be used only with PeerConnection. PeerConnectionManager
// interface provides the factory methods to create MediaStream and MediaTracks.
#ifndef TALK_APP_WEBRTC_MEDIASTREAM_H_
#define TALK_APP_WEBRTC_MEDIASTREAM_H_
@ -45,25 +51,25 @@ class AudioDeviceModule;
class VideoCaptureModule;
// Generic observer interface.
class Observer {
class ObserverInterface {
public:
virtual void OnChanged() = 0;
protected:
virtual ~Observer() {}
virtual ~ObserverInterface() {}
};
class Notifier {
class NotifierInterface {
public:
virtual void RegisterObserver(Observer* observer) = 0;
virtual void UnregisterObserver(Observer* observer) = 0;
virtual void RegisterObserver(ObserverInterface* observer) = 0;
virtual void UnregisterObserver(ObserverInterface* observer) = 0;
virtual ~Notifier() {}
virtual ~NotifierInterface() {}
};
// Information about a track.
class MediaStreamTrackInterface : public talk_base::RefCount,
public Notifier {
class MediaStreamTrackInterface : public talk_base::RefCountInterface,
public NotifierInterface {
public:
enum TrackState {
kInitializing, // Track is beeing negotiated.
@ -78,13 +84,13 @@ class MediaStreamTrackInterface : public talk_base::RefCount,
virtual bool enabled() const = 0;
virtual TrackState state() const = 0;
virtual bool set_enabled(bool enable) = 0;
// Return false (or assert) if the ssrc is already set.
// These methods should be called by implementation only.
virtual bool set_ssrc(uint32 ssrc) = 0;
virtual bool set_state(TrackState new_state) = 0;
};
// Reference counted wrapper for a VideoRenderer.
class VideoRendererWrapperInterface : public talk_base::RefCount {
class VideoRendererWrapperInterface : public talk_base::RefCountInterface {
public:
virtual cricket::VideoRenderer* renderer() = 0;
@ -92,10 +98,10 @@ class VideoRendererWrapperInterface : public talk_base::RefCount {
virtual ~VideoRendererWrapperInterface() {}
};
// Creates a reference counted object of type webrtc::VideoRenderer.
// Creates a reference counted object of type cricket::VideoRenderer.
// webrtc::VideoRendererWrapperInterface take ownership of
// cricket::VideoRenderer.
scoped_refptr<VideoRendererWrapperInterface> CreateVideoRenderer(
talk_base::scoped_refptr<VideoRendererWrapperInterface> CreateVideoRenderer(
cricket::VideoRenderer* renderer);
class VideoTrackInterface : public MediaStreamTrackInterface {
@ -140,7 +146,7 @@ class LocalAudioTrackInterface : public AudioTrackInterface {
// List of of tracks.
template <class TrackType>
class MediaStreamTrackListInterface : public talk_base::RefCount {
class MediaStreamTrackListInterface : public talk_base::RefCountInterface {
public:
virtual size_t count() = 0;
virtual TrackType* at(size_t index) = 0;
@ -152,8 +158,8 @@ class MediaStreamTrackListInterface : public talk_base::RefCount {
typedef MediaStreamTrackListInterface<AudioTrackInterface> AudioTracks;
typedef MediaStreamTrackListInterface<VideoTrackInterface> VideoTracks;
class MediaStreamInterface : public talk_base::RefCount,
public Notifier {
class MediaStreamInterface : public talk_base::RefCountInterface,
public NotifierInterface {
public:
virtual std::string label() const = 0;
virtual AudioTracks* audio_tracks() = 0;
@ -167,7 +173,7 @@ class MediaStreamInterface : public talk_base::RefCount,
virtual ReadyState ready_state() = 0;
// Only to be used by the implementation.
// These methods should be called by implementation only.
virtual void set_ready_state(ReadyState state) = 0;
protected:

View File

@ -45,7 +45,7 @@ namespace webrtc {
// VideoTrackHandler listen to events on a VideoTrack instance and
// executes the requested change.
class VideoTrackHandler : public Observer {
class VideoTrackHandler : public ObserverInterface {
public:
VideoTrackHandler(VideoTrackInterface* track,
MediaProviderInterface* provider);
@ -63,7 +63,7 @@ class VideoTrackHandler : public Observer {
private:
MediaStreamTrackInterface::TrackState state_;
bool enabled_;
scoped_refptr<VideoRendererWrapperInterface> renderer_;
talk_base::scoped_refptr<VideoRendererWrapperInterface> renderer_;
};
class LocalVideoTrackHandler : public VideoTrackHandler {
@ -78,7 +78,7 @@ class LocalVideoTrackHandler : public VideoTrackHandler {
virtual void OnEnabledChanged();
private:
scoped_refptr<LocalVideoTrackInterface> local_video_track_;
talk_base::scoped_refptr<LocalVideoTrackInterface> local_video_track_;
};
class RemoteVideoTrackHandler : public VideoTrackHandler {
@ -93,10 +93,10 @@ class RemoteVideoTrackHandler : public VideoTrackHandler {
virtual void OnEnabledChanged();
private:
scoped_refptr<VideoTrackInterface> remote_video_track_;
talk_base::scoped_refptr<VideoTrackInterface> remote_video_track_;
};
class MediaStreamHandler : public Observer {
class MediaStreamHandler : public ObserverInterface {
public:
MediaStreamHandler(MediaStreamInterface* stream,
MediaProviderInterface* provider);
@ -108,7 +108,7 @@ class MediaStreamHandler : public Observer {
MediaProviderInterface* provider_;
typedef std::vector<VideoTrackHandler*> VideoTrackHandlers;
VideoTrackHandlers video_handlers_;
scoped_refptr<MediaStreamInterface> stream_;
talk_base::scoped_refptr<MediaStreamInterface> stream_;
};
class LocalMediaStreamHandler : public MediaStreamHandler {
@ -129,7 +129,7 @@ class MediaStreamHandlers {
~MediaStreamHandlers();
void AddRemoteStream(MediaStreamInterface* stream);
void RemoveRemoteStream(MediaStreamInterface* stream);
void CommitLocalStreams(StreamCollection* streams);
void CommitLocalStreams(StreamCollectionInterface* streams);
private:
typedef std::list<MediaStreamHandler*> StreamHandlerList;

View File

@ -68,25 +68,26 @@ class MockMediaProvier : public MediaProviderInterface {
TEST(MediaStreamHandlerTest, LocalStreams) {
// Create a local stream.
std::string label(kStreamLabel1);
scoped_refptr<LocalMediaStreamInterface> stream(
talk_base::scoped_refptr<LocalMediaStreamInterface> stream(
MediaStream::Create(label));
scoped_refptr<LocalVideoTrackInterface> video_track(VideoTrack::CreateLocal(
kVideoDeviceName, NULL));
talk_base::scoped_refptr<LocalVideoTrackInterface>
video_track(VideoTrack::CreateLocal(kVideoDeviceName, NULL));
video_track->set_ssrc(kVideoSsrc);
EXPECT_TRUE(stream->AddTrack(video_track));
scoped_refptr<VideoRendererWrapperInterface> renderer(
talk_base::scoped_refptr<VideoRendererWrapperInterface> renderer(
CreateVideoRenderer(NULL));
video_track->SetRenderer(renderer);
MockMediaProvier provider;
MediaStreamHandlers handlers(&provider);
scoped_refptr<StreamCollectionImpl> collection(
talk_base::scoped_refptr<StreamCollectionImpl> collection(
StreamCollectionImpl::Create());
collection->AddStream(stream);
EXPECT_CALL(provider, SetLocalRenderer(kVideoSsrc))
.Times(Exactly(1));
.Times(Exactly(2)); // SetLocalRender will also be called from dtor of
// LocalVideoTrackHandler
EXPECT_CALL(provider, SetCaptureDevice(kVideoSsrc))
.Times(Exactly(1));
handlers.CommitLocalStreams(collection);
@ -108,10 +109,10 @@ TEST(MediaStreamHandlerTest, RemoteStreams) {
// they are easier to create.
// LocalMediaStreams inherit from MediaStreams.
std::string label(kStreamLabel1);
scoped_refptr<LocalMediaStreamInterface> stream(
talk_base::scoped_refptr<LocalMediaStreamInterface> stream(
MediaStream::Create(label));
scoped_refptr<LocalVideoTrackInterface> video_track(VideoTrack::CreateLocal(
kVideoDeviceName, NULL));
talk_base::scoped_refptr<LocalVideoTrackInterface>
video_track(VideoTrack::CreateLocal(kVideoDeviceName, NULL));
video_track->set_ssrc(kVideoSsrc);
EXPECT_TRUE(stream->AddTrack(video_track));
@ -121,10 +122,11 @@ TEST(MediaStreamHandlerTest, RemoteStreams) {
handlers.AddRemoteStream(stream);
EXPECT_CALL(provider, SetRemoteRenderer(kVideoSsrc))
.Times(Exactly(2));
.Times(Exactly(3)); // SetRemoteRenderer is also called from dtor of
// RemoteVideoTrackHandler.
// Set the renderer once.
scoped_refptr<VideoRendererWrapperInterface> renderer(
talk_base::scoped_refptr<VideoRendererWrapperInterface> renderer(
CreateVideoRenderer(NULL));
video_track->SetRenderer(renderer);
talk_base::Thread::Current()->ProcessMessages(1);

View File

@ -30,15 +30,10 @@
namespace webrtc {
scoped_refptr<LocalMediaStreamInterface> CreateLocalMediaStream(
talk_base::scoped_refptr<MediaStream> MediaStream::Create(
const std::string& label) {
return MediaStream::Create(label);
}
scoped_refptr<MediaStream> MediaStream::Create(
const std::string& label) {
talk_base::RefCountImpl<MediaStream>* stream =
new talk_base::RefCountImpl<MediaStream>(label);
talk_base::RefCount<MediaStream>* stream =
new talk_base::RefCount<MediaStream>(label);
return stream;
}
@ -46,10 +41,10 @@ MediaStream::MediaStream(const std::string& label)
: label_(label),
ready_state_(MediaStreamInterface::kInitializing),
audio_track_list_(
new talk_base::RefCountImpl<
new talk_base::RefCount<
MediaStreamTrackList<AudioTrackInterface> >()),
video_track_list_(
new talk_base::RefCountImpl<
new talk_base::RefCount<
MediaStreamTrackList<VideoTrackInterface> >()) {
}
@ -57,7 +52,7 @@ void MediaStream::set_ready_state(
MediaStreamInterface::ReadyState new_state) {
if (ready_state_ != new_state) {
ready_state_ = new_state;
NotifierImpl<LocalMediaStreamInterface>::FireOnChanged();
Notifier<LocalMediaStreamInterface>::FireOnChanged();
}
}

View File

@ -25,6 +25,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// This file contains the implementation of MediaStreamInterface interface.
#ifndef TALK_APP_WEBRTC_MEDIASTREAMIMPL_H_
#define TALK_APP_WEBRTC_MEDIASTREAMIMPL_H_
@ -38,12 +40,10 @@ namespace webrtc {
class AudioTrack;
class VideoTrack;
class MediaStream
: public NotifierImpl<LocalMediaStreamInterface> {
class MediaStream : public Notifier<LocalMediaStreamInterface> {
public:
template<class T>
class MediaStreamTrackList :
public MediaStreamTrackListInterface<T> {
class MediaStreamTrackList : public MediaStreamTrackListInterface<T> {
public:
void AddTrack(T* track) {
tracks_.push_back(track);
@ -54,10 +54,10 @@ class MediaStream
}
private:
std::vector<scoped_refptr<T> > tracks_;
std::vector<talk_base::scoped_refptr<T> > tracks_;
};
static scoped_refptr<MediaStream> Create(const std::string& label);
static talk_base::scoped_refptr<MediaStream> Create(const std::string& label);
// Implement LocalMediaStreamInterface.
virtual bool AddTrack(AudioTrackInterface* track);
@ -79,9 +79,9 @@ class MediaStream
std::string label_;
MediaStreamInterface::ReadyState ready_state_;
scoped_refptr<MediaStreamTrackList<AudioTrackInterface> >
talk_base::scoped_refptr<MediaStreamTrackList<AudioTrackInterface> >
audio_track_list_;
scoped_refptr<MediaStreamTrackList<VideoTrackInterface> >
talk_base::scoped_refptr<MediaStreamTrackList<VideoTrackInterface> >
video_track_list_;
};

View File

@ -37,7 +37,7 @@ static const char kVideoDeviceName[] = "dummy_video_cam_1";
namespace webrtc {
// Helper class to test the Observer.
class TestObserver : public Observer {
class TestObserver : public ObserverInterface {
public:
TestObserver() : changed_(0) {}
void OnChanged() {
@ -57,7 +57,7 @@ class TestObserver : public Observer {
TEST(LocalStreamTest, Create) {
// Create a local stream.
std::string label(kStreamLabel1);
scoped_refptr<LocalMediaStreamInterface> stream(
talk_base::scoped_refptr<LocalMediaStreamInterface> stream(
MediaStream::Create(label));
EXPECT_EQ(label, stream->label());
@ -66,17 +66,17 @@ TEST(LocalStreamTest, Create) {
// Create a local Video track.
TestObserver tracklist_observer;
scoped_refptr<LocalVideoTrackInterface> video_track(VideoTrack::CreateLocal(
kVideoDeviceName, NULL));
talk_base::scoped_refptr<LocalVideoTrackInterface>
video_track(VideoTrack::CreateLocal(kVideoDeviceName, NULL));
// Add an observer to the track list.
scoped_refptr<MediaStreamTrackListInterface<VideoTrackInterface> > track_list(
stream->video_tracks());
talk_base::scoped_refptr<MediaStreamTrackListInterface<VideoTrackInterface> >
track_list(stream->video_tracks());
// Add the track to the local stream.
EXPECT_TRUE(stream->AddTrack(video_track));
EXPECT_EQ(1u, stream->video_tracks()->count());
// Verify the track.
scoped_refptr<webrtc::MediaStreamTrackInterface> track(
talk_base::scoped_refptr<webrtc::MediaStreamTrackInterface> track(
stream->video_tracks()->at(0));
EXPECT_EQ(0, track->label().compare(kVideoDeviceName));
EXPECT_TRUE(track->enabled());

View File

@ -45,7 +45,8 @@ enum {
typedef talk_base::TypedMessageData<std::string*> LabelMessageData;
typedef talk_base::TypedMessageData<size_t> SizeTMessageData;
typedef talk_base::TypedMessageData<webrtc::Observer*> ObserverMessageData;
typedef talk_base::TypedMessageData<webrtc::ObserverInterface*>
ObserverMessageData;
typedef talk_base::TypedMessageData<webrtc::MediaStreamInterface::ReadyState>
ReadyStateMessageData;
@ -57,7 +58,7 @@ class MediaStreamTrackMessageData : public talk_base::MessageData {
result_(false) {
}
scoped_refptr<T> track_;
talk_base::scoped_refptr<T> track_;
bool result_;
};
@ -74,19 +75,19 @@ class MediaStreamTrackAtMessageData : public talk_base::MessageData {
}
size_t index_;
scoped_refptr<TrackType> track_;
talk_base::scoped_refptr<TrackType> track_;
};
} // namespace anonymous
namespace webrtc {
scoped_refptr<MediaStreamProxy> MediaStreamProxy::Create(
talk_base::scoped_refptr<MediaStreamProxy> MediaStreamProxy::Create(
const std::string& label,
talk_base::Thread* signaling_thread) {
ASSERT(signaling_thread);
talk_base::RefCountImpl<MediaStreamProxy>* stream =
new talk_base::RefCountImpl<MediaStreamProxy>(label, signaling_thread);
talk_base::RefCount<MediaStreamProxy>* stream =
new talk_base::RefCount<MediaStreamProxy>(label, signaling_thread);
return stream;
}
@ -94,11 +95,11 @@ MediaStreamProxy::MediaStreamProxy(const std::string& label,
talk_base::Thread* signaling_thread)
: signaling_thread_(signaling_thread),
media_stream_impl_(MediaStream::Create(label)),
audio_tracks_(new talk_base::RefCountImpl<
audio_tracks_(new talk_base::RefCount<
MediaStreamTrackListProxy<AudioTrackInterface> >(
media_stream_impl_->audio_tracks(),
signaling_thread_)),
video_tracks_(new talk_base::RefCountImpl<
video_tracks_(new talk_base::RefCount<
MediaStreamTrackListProxy<VideoTrackInterface> >(
media_stream_impl_->video_tracks(),
signaling_thread_)) {
@ -151,7 +152,7 @@ bool MediaStreamProxy::AddTrack(VideoTrackInterface* track) {
return media_stream_impl_->AddTrack(track);
}
void MediaStreamProxy::RegisterObserver(Observer* observer) {
void MediaStreamProxy::RegisterObserver(ObserverInterface* observer) {
if (!signaling_thread_->IsCurrent()) {
ObserverMessageData msg(observer);
Send(MSG_REGISTER_OBSERVER, &msg);
@ -160,7 +161,7 @@ void MediaStreamProxy::RegisterObserver(Observer* observer) {
media_stream_impl_->RegisterObserver(observer);
}
void MediaStreamProxy::UnregisterObserver(Observer* observer) {
void MediaStreamProxy::UnregisterObserver(ObserverInterface* observer) {
if (!signaling_thread_->IsCurrent()) {
ObserverMessageData msg(observer);
Send(MSG_UNREGISTER_OBSERVER, &msg);

View File

@ -55,11 +55,11 @@ class MediaStreamProxy : public LocalMediaStreamInterface,
void Send(uint32 id, talk_base::MessageData* data) const;
void OnMessage(talk_base::Message* msg);
scoped_refptr<MediaStreamTrackListInterface<T> > track_list_;
talk_base::scoped_refptr<MediaStreamTrackListInterface<T> > track_list_;
mutable talk_base::Thread* signaling_thread_;
};
static scoped_refptr<MediaStreamProxy> Create(
static talk_base::scoped_refptr<MediaStreamProxy> Create(
const std::string& label,
talk_base::Thread* signaling_thread);
@ -72,18 +72,18 @@ class MediaStreamProxy : public LocalMediaStreamInterface,
// Implement MediaStream.
virtual std::string label() const;
virtual MediaStreamTrackListProxy<AudioTrackInterface>* audio_tracks() {
virtual AudioTracks* audio_tracks() {
return audio_tracks_;
}
virtual MediaStreamTrackListProxy<VideoTrackInterface>* video_tracks() {
virtual VideoTracks* video_tracks() {
return video_tracks_;
}
virtual ReadyState ready_state();
virtual void set_ready_state(ReadyState new_state);
// Implement Notifier
virtual void RegisterObserver(Observer* observer);
virtual void UnregisterObserver(Observer* observer);
virtual void RegisterObserver(ObserverInterface* observer);
virtual void UnregisterObserver(ObserverInterface* observer);
protected:
explicit MediaStreamProxy(const std::string& label,
@ -94,9 +94,9 @@ class MediaStreamProxy : public LocalMediaStreamInterface,
virtual void OnMessage(talk_base::Message* msg);
mutable talk_base::Thread* signaling_thread_;
scoped_refptr<MediaStream> media_stream_impl_;
scoped_refptr<MediaStreamTrackListProxy<AudioTrackInterface> > audio_tracks_;
scoped_refptr<MediaStreamTrackListProxy<VideoTrackInterface> > video_tracks_;
talk_base::scoped_refptr<MediaStream> media_stream_impl_;
talk_base::scoped_refptr<AudioTracks> audio_tracks_;
talk_base::scoped_refptr<VideoTracks> video_tracks_;
};
} // namespace webrtc

View File

@ -45,7 +45,8 @@ enum {
};
typedef talk_base::TypedMessageData<std::string*> LabelMessageData;
typedef talk_base::TypedMessageData<webrtc::Observer*> ObserverMessageData;
typedef talk_base::TypedMessageData<webrtc::ObserverInterface*>
ObserverMessageData;
typedef talk_base::TypedMessageData
<webrtc::MediaStreamTrackInterface::TrackState> TrackStateMessageData;
typedef talk_base::TypedMessageData<uint32> SsrcMessageData;
@ -54,17 +55,18 @@ typedef talk_base::TypedMessageData<bool> EnableMessageData;
class AudioDeviceMessageData : public talk_base::MessageData {
public:
scoped_refptr<webrtc::AudioDeviceModule> audio_device_;
talk_base::scoped_refptr<webrtc::AudioDeviceModule> audio_device_;
};
class VideoDeviceMessageData : public talk_base::MessageData {
public:
scoped_refptr<webrtc::VideoCaptureModule> video_device_;
talk_base::scoped_refptr<webrtc::VideoCaptureModule> video_device_;
};
class VideoRendererMessageData : public talk_base::MessageData {
public:
scoped_refptr<webrtc::VideoRendererWrapperInterface> video_renderer_;
talk_base::scoped_refptr<webrtc::VideoRendererWrapperInterface>
video_renderer_;
};
} // namespace anonymous
@ -160,7 +162,7 @@ bool MediaStreamTrackProxy<T>::set_ssrc(uint32 ssrc) {
}
template <class T>
void MediaStreamTrackProxy<T>::RegisterObserver(Observer* observer) {
void MediaStreamTrackProxy<T>::RegisterObserver(ObserverInterface* observer) {
if (!signaling_thread_->IsCurrent()) {
ObserverMessageData msg(observer);
Send(MSG_REGISTER_OBSERVER, &msg);
@ -170,7 +172,7 @@ void MediaStreamTrackProxy<T>::RegisterObserver(Observer* observer) {
}
template <class T>
void MediaStreamTrackProxy<T>::UnregisterObserver(Observer* observer) {
void MediaStreamTrackProxy<T>::UnregisterObserver(ObserverInterface* observer) {
if (!signaling_thread_->IsCurrent()) {
ObserverMessageData msg(observer);
Send(MSG_UNREGISTER_OBSERVER, &msg);
@ -254,26 +256,26 @@ AudioTrackProxy::AudioTrackProxy(
Init(audio_track_);
}
scoped_refptr<AudioTrackInterface> AudioTrackProxy::CreateRemote(
talk_base::scoped_refptr<AudioTrackInterface> AudioTrackProxy::CreateRemote(
const std::string& label,
uint32 ssrc,
talk_base::Thread* signaling_thread) {
ASSERT(signaling_thread);
talk_base::RefCountImpl<AudioTrackProxy>* track =
new talk_base::RefCountImpl<AudioTrackProxy>(label, ssrc,
signaling_thread);
talk_base::RefCount<AudioTrackProxy>* track =
new talk_base::RefCount<AudioTrackProxy>(label, ssrc,
signaling_thread);
return track;
}
scoped_refptr<LocalAudioTrackInterface> AudioTrackProxy::CreateLocal(
talk_base::scoped_refptr<LocalAudioTrackInterface> AudioTrackProxy::CreateLocal(
const std::string& label,
AudioDeviceModule* audio_device,
talk_base::Thread* signaling_thread) {
ASSERT(signaling_thread);
talk_base::RefCountImpl<AudioTrackProxy>* track =
new talk_base::RefCountImpl<AudioTrackProxy>(label,
audio_device,
signaling_thread);
talk_base::RefCount<AudioTrackProxy>* track =
new talk_base::RefCount<AudioTrackProxy>(label,
audio_device,
signaling_thread);
return track;
}
@ -316,25 +318,25 @@ VideoTrackProxy::VideoTrackProxy(
Init(video_track_);
}
scoped_refptr<VideoTrackInterface> VideoTrackProxy::CreateRemote(
talk_base::scoped_refptr<VideoTrackInterface> VideoTrackProxy::CreateRemote(
const std::string& label,
uint32 ssrc,
talk_base::Thread* signaling_thread) {
ASSERT(signaling_thread);
talk_base::RefCountImpl<VideoTrackProxy>* track =
new talk_base::RefCountImpl<VideoTrackProxy>(label, ssrc,
signaling_thread);
talk_base::RefCount<VideoTrackProxy>* track =
new talk_base::RefCount<VideoTrackProxy>(label, ssrc,
signaling_thread);
return track;
}
scoped_refptr<LocalVideoTrackInterface> VideoTrackProxy::CreateLocal(
talk_base::scoped_refptr<LocalVideoTrackInterface> VideoTrackProxy::CreateLocal(
const std::string& label,
VideoCaptureModule* video_device,
talk_base::Thread* signaling_thread) {
ASSERT(signaling_thread);
talk_base::RefCountImpl<VideoTrackProxy>* track =
new talk_base::RefCountImpl<VideoTrackProxy>(label, video_device,
signaling_thread);
talk_base::RefCount<VideoTrackProxy>* track =
new talk_base::RefCount<VideoTrackProxy>(label, video_device,
signaling_thread);
return track;
}

View File

@ -58,8 +58,8 @@ class MediaStreamTrackProxy : public T,
virtual bool set_state(MediaStreamTrackInterface::TrackState new_state);
// Implement Notifier
virtual void RegisterObserver(Observer* observer);
virtual void UnregisterObserver(Observer* observer);
virtual void RegisterObserver(ObserverInterface* observer);
virtual void UnregisterObserver(ObserverInterface* observer);
protected:
explicit MediaStreamTrackProxy(talk_base::Thread* signaling_thread);
@ -77,11 +77,11 @@ class MediaStreamTrackProxy : public T,
// It can be used as a proxy for both local and remote audio tracks.
class AudioTrackProxy : public MediaStreamTrackProxy<LocalAudioTrackInterface> {
public:
static scoped_refptr<AudioTrackInterface> CreateRemote(
static talk_base::scoped_refptr<AudioTrackInterface> CreateRemote(
const std::string& label,
uint32 ssrc,
talk_base::Thread* signaling_thread);
static scoped_refptr<LocalAudioTrackInterface> CreateLocal(
static talk_base::scoped_refptr<LocalAudioTrackInterface> CreateLocal(
const std::string& label,
AudioDeviceModule* audio_device,
talk_base::Thread* signaling_thread);
@ -93,12 +93,12 @@ class AudioTrackProxy : public MediaStreamTrackProxy<LocalAudioTrackInterface> {
uint32 ssrc,
talk_base::Thread* signaling_thread);
AudioTrackProxy(const std::string& label,
AudioDeviceModule* audio_device,
talk_base::Thread* signaling_thread);
AudioDeviceModule* audio_device,
talk_base::Thread* signaling_thread);
// Implement MessageHandler
virtual void OnMessage(talk_base::Message* msg);
scoped_refptr<AudioTrack> audio_track_;
talk_base::scoped_refptr<AudioTrack> audio_track_;
};
// VideoTrackProxy is a proxy for the VideoTrackInterface and
@ -107,11 +107,11 @@ class AudioTrackProxy : public MediaStreamTrackProxy<LocalAudioTrackInterface> {
// It can be used as a proxy for both local and remote video tracks.
class VideoTrackProxy : public MediaStreamTrackProxy<LocalVideoTrackInterface> {
public:
static scoped_refptr<VideoTrackInterface> CreateRemote(
static talk_base::scoped_refptr<VideoTrackInterface> CreateRemote(
const std::string& label,
uint32 ssrc,
talk_base::Thread* signaling_thread);
static scoped_refptr<LocalVideoTrackInterface> CreateLocal(
static talk_base::scoped_refptr<LocalVideoTrackInterface> CreateLocal(
const std::string& label,
VideoCaptureModule* video_device,
talk_base::Thread* signaling_thread);
@ -130,7 +130,7 @@ class VideoTrackProxy : public MediaStreamTrackProxy<LocalVideoTrackInterface> {
// Implement MessageHandler
virtual void OnMessage(talk_base::Message* msg);
scoped_refptr<VideoTrack> video_track_;
talk_base::scoped_refptr<VideoTrack> video_track_;
};
} // namespace webrtc

View File

@ -35,8 +35,10 @@
namespace webrtc {
// MediaTrack implements the interface common to AudioTrackInterface and
// VideoTrackInterface.
template <typename T>
class MediaTrack : public NotifierImpl<T> {
class MediaTrack : public Notifier<T> {
public:
typedef typename T::TrackState TypedTrackState;
@ -48,7 +50,7 @@ class MediaTrack : public NotifierImpl<T> {
bool fire_on_change = (enable != enabled_);
enabled_ = enable;
if (fire_on_change) {
NotifierImpl<T>::FireOnChanged();
Notifier<T>::FireOnChanged();
}
}
@ -58,7 +60,7 @@ class MediaTrack : public NotifierImpl<T> {
if (ssrc_ != 0)
return false;
ssrc_ = ssrc;
NotifierImpl<T>::FireOnChanged();
Notifier<T>::FireOnChanged();
return true;
}
@ -66,7 +68,7 @@ class MediaTrack : public NotifierImpl<T> {
bool fire_on_change = (state_ != new_state);
state_ = new_state;
if (fire_on_change)
NotifierImpl<T>::FireOnChanged();
Notifier<T>::FireOnChanged();
return true;
}

View File

@ -37,18 +37,18 @@ namespace webrtc {
// Implement a template version of a notifier.
template <class T>
class NotifierImpl : public T {
class Notifier : public T {
public:
NotifierImpl() {
Notifier() {
}
virtual void RegisterObserver(Observer* observer) {
virtual void RegisterObserver(ObserverInterface* observer) {
ASSERT(observer != NULL);
observers_.push_back(observer);
}
virtual void UnregisterObserver(Observer* observer) {
for (std::list<Observer*>::iterator it = observers_.begin();
virtual void UnregisterObserver(ObserverInterface* observer) {
for (std::list<ObserverInterface*>::iterator it = observers_.begin();
it != observers_.end(); it++) {
if (*it == observer) {
observers_.erase(it);
@ -58,14 +58,14 @@ class NotifierImpl : public T {
}
void FireOnChanged() {
for (std::list<Observer*>::iterator it = observers_.begin();
for (std::list<ObserverInterface*>::iterator it = observers_.begin();
it != observers_.end(); ++it) {
(*it)-> OnChanged();
}
}
protected:
std::list<Observer*> observers_;
std::list<ObserverInterface*> observers_;
};
} // namespace webrtc

View File

@ -25,6 +25,47 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// This file contains the PeerConnection interface as defined in
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#peer-to-peer-connections.
// Applications must use this interface to implement peerconnection.
// PeerConnectionFactory class provides factory methods to create
// peerconnection, mediastream and media tracks objects.
//
// The Following steps are needed to setup a typical call.
// 1. Create a PeerConnectionManager. Check constructors for more information
// about input parameters.
// 2. Create a PeerConnection object. Provide a configuration string which
// points either to stun or turn server to generate ICE candidates and provide
// an object that implements the PeerConnectionObserver interface.
// Now PeerConnection will startcollecting ICE candidates.
// 3. Create local MediaStream and MediaTracks using the PeerConnectionFactory
// and add it to PeerConnection by calling AddStream.
// 4. Once all mediastreams are added to peerconnection, call
// CommitStreamChanges. Now PeerConnection starts generating an offer based on
// the local mediastreams.
// 5. When PeerConnection have generated the ICE candidates it will call the
// observer OnSignalingMessage callback with the initial offer.
// 6. When an Answer from peer received it must be supplied to the
// PeerConnection by calling ProcessSignalingMessage.
// At this point PeerConnection knows remote capabilities and ICE candidates.
// Media will start flowing to the remote peer.
// The Receiver of a call can decide to accept or reject the call.
// This decision will be taken by the application not peerconnection.
// If application decides to accept the call
// 1. Create PeerConnectionManager if it doesn't exist.
// 2. Create new PeerConnection
// 3. Provide the remote offer to the new PeerConnection object by calling
// ProcessSignalingMessage.
// 4. PeerConnection will call the observer function OnAddStream with remote
// MediaStream and tracks information.
// 5. PeerConnection will call the observer function OnSignalingMessage with
// local ICE candidates in a answer message.
// 6. Application can add it's own MediaStreams by calling AddStream.
// When all streams have been added the application must call
// CommitStreamChanges. Streams can be added at any time after the
// PeerConnection object have been created.
#ifndef TALK_APP_WEBRTC_PEERCONNECTION_H_
#define TALK_APP_WEBRTC_PEERCONNECTION_H_
@ -39,18 +80,19 @@ namespace talk_base {
}
namespace webrtc {
class StreamCollection : public talk_base::RefCount {
// MediaStream container interface.
class StreamCollectionInterface : public talk_base::RefCountInterface {
public:
virtual size_t count() = 0;
virtual MediaStreamInterface* at(size_t index) = 0;
virtual MediaStreamInterface* find(const std::string& label) = 0;
protected:
// Dtor protected as objects shouldn't be deleted via this interface.
~StreamCollection() {}
~StreamCollectionInterface() {}
};
/////////////////////////////////////////////
// PeerConnection callback interface. Application should implement these
// methods.
class PeerConnectionObserver {
public:
enum Readiness {
@ -79,7 +121,7 @@ class PeerConnectionObserver {
};
class PeerConnection : public talk_base::RefCount {
class PeerConnectionInterface : public talk_base::RefCountInterface {
public:
// SignalingMessage in json format
virtual bool ProcessSignalingMessage(const std::string& msg) = 0;
@ -88,10 +130,12 @@ class PeerConnection : public talk_base::RefCount {
virtual bool Send(const std::string& msg) = 0;
// Accessor methods to active local streams.
virtual scoped_refptr<StreamCollection> local_streams() = 0;
virtual talk_base::scoped_refptr<StreamCollectionInterface>
local_streams() = 0;
// Accessor methods to remote streams.
virtual scoped_refptr<StreamCollection> remote_streams() = 0;
virtual talk_base::scoped_refptr<StreamCollectionInterface>
remote_streams() = 0;
// Add a new local stream.
// This function does not trigger any changes to the stream until
@ -109,13 +153,13 @@ class PeerConnection : public talk_base::RefCount {
protected:
// Dtor protected as objects shouldn't be deleted via this interface.
~PeerConnection() {}
~PeerConnectionInterface() {}
};
// Reference counted wrapper for talk_base::NetworkManager.
class PcNetworkManager : public talk_base::RefCount {
class PcNetworkManager : public talk_base::RefCountInterface {
public:
static scoped_refptr<PcNetworkManager> Create(
static talk_base::scoped_refptr<PcNetworkManager> Create(
talk_base::NetworkManager* network_manager);
virtual talk_base::NetworkManager* network_manager() const;
@ -127,9 +171,9 @@ class PcNetworkManager : public talk_base::RefCount {
};
// Reference counted wrapper for talk_base::PacketSocketFactory.
class PcPacketSocketFactory : public talk_base::RefCount {
class PcPacketSocketFactory : public talk_base::RefCountInterface {
public:
static scoped_refptr<PcPacketSocketFactory> Create(
static talk_base::scoped_refptr<PcPacketSocketFactory> Create(
talk_base::PacketSocketFactory* socket_factory);
virtual talk_base::PacketSocketFactory* socket_factory() const;
@ -141,36 +185,42 @@ class PcPacketSocketFactory : public talk_base::RefCount {
talk_base::PacketSocketFactory* socket_factory_;
};
class PeerConnectionManager : public talk_base::RefCount {
// PeerConnectionManager is the factory interface use for creating
// PeerConnection, MediaStream and media tracks.
// PeerConnectionManager will create required libjingle threads, socket and
// network manager factory classes for networking.
// If application decides to provide its own implementation of these classes
// it should use alternate create method which accepts these parameters
// as input.
class PeerConnectionManager : public talk_base::RefCountInterface {
public:
// Create a new instance of PeerConnectionManager.
static scoped_refptr<PeerConnectionManager> Create();
static talk_base::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(
static talk_base::scoped_refptr<PeerConnectionManager> Create(
talk_base::Thread* worker_thread,
talk_base::Thread* signaling_thread,
PcNetworkManager* network_manager,
PcPacketSocketFactory* packet_socket_factory,
AudioDeviceModule* default_adm);
virtual scoped_refptr<PeerConnection> CreatePeerConnection(
const std::string& config,
PeerConnectionObserver* observer) = 0;
virtual talk_base::scoped_refptr<PeerConnectionInterface>
CreatePeerConnection(const std::string& config,
PeerConnectionObserver* observer) = 0;
virtual scoped_refptr<LocalMediaStreamInterface> CreateLocalMediaStream(
const std::string& label) = 0;
virtual talk_base::scoped_refptr<LocalMediaStreamInterface>
CreateLocalMediaStream(const std::string& label) = 0;
virtual scoped_refptr<LocalVideoTrackInterface> CreateLocalVideoTrack(
const std::string& label,
VideoCaptureModule* video_device) = 0;
virtual scoped_refptr<LocalAudioTrackInterface> CreateLocalAudioTrack(
const std::string& label,
AudioDeviceModule* audio_device) = 0;
virtual talk_base::scoped_refptr<LocalVideoTrackInterface>
CreateLocalVideoTrack(const std::string& label,
VideoCaptureModule* video_device) = 0;
virtual talk_base::scoped_refptr<LocalAudioTrackInterface>
CreateLocalAudioTrack(const std::string& label,
AudioDeviceModule* audio_device) = 0;
protected:
// Dtor protected as objects shouldn't be deleted via this interface.

View File

@ -48,10 +48,10 @@ void GetAllVideoTracks(webrtc::MediaStreamInterface* media_stream,
}
// TODO(henrike): replace with a capture device that reads from a file/buffer.
scoped_refptr<webrtc::VideoCaptureModule> OpenVideoCaptureDevice() {
talk_base::scoped_refptr<webrtc::VideoCaptureModule> OpenVideoCaptureDevice() {
webrtc::VideoCaptureModule::DeviceInfo* device_info(
webrtc::VideoCaptureFactory::CreateDeviceInfo(0));
scoped_refptr<webrtc::VideoCaptureModule> video_device;
talk_base::scoped_refptr<webrtc::VideoCaptureModule> video_device;
const size_t kMaxDeviceNameLength = 128;
const size_t kMaxUniqueIdLength = 256;
@ -175,22 +175,22 @@ class PeerConnectionP2PTestClient
~PeerConnectionP2PTestClient() {
// Ensure that webrtc::PeerConnection is deleted before
// webrtc::PeerConnectionManager or crash will occur
webrtc::PeerConnection* temp = peer_connection_.release();
webrtc::PeerConnectionInterface* temp = peer_connection_.release();
temp->Release();
}
void StartSession() {
// Audio track doesn't seem to be implemented yet. No need to pass a device
// to it.
scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track(
talk_base::scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track(
peer_connection_factory_->CreateLocalAudioTrack("audio_track", NULL));
scoped_refptr<webrtc::LocalVideoTrackInterface> video_track(
talk_base::scoped_refptr<webrtc::LocalVideoTrackInterface> video_track(
peer_connection_factory_->CreateLocalVideoTrack(
"video_track",
OpenVideoCaptureDevice()));
scoped_refptr<webrtc::LocalMediaStreamInterface> stream =
talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> stream =
peer_connection_factory_->CreateLocalMediaStream("stream_label");
stream->AddTrack(audio_track);
@ -231,8 +231,8 @@ class PeerConnectionP2PTestClient
++iter) {
char file_name[256];
GenerateRecordingFileName(track_id, file_name);
scoped_refptr<webrtc::VideoRendererWrapperInterface> video_renderer =
webrtc::CreateVideoRenderer(
talk_base::scoped_refptr<webrtc::VideoRendererWrapperInterface>
video_renderer = webrtc::CreateVideoRenderer(
VideoRecorder::CreateVideoRecorder(file_name));
if (video_renderer == NULL) {
ADD_FAILURE();
@ -277,8 +277,9 @@ class PeerConnectionP2PTestClient
}
int id_;
scoped_refptr<webrtc::PeerConnection> peer_connection_;
scoped_refptr<webrtc::PeerConnectionManager> peer_connection_factory_;
talk_base::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
talk_base::scoped_refptr<webrtc::PeerConnectionManager>
peer_connection_factory_;
// Remote peer communication.
SignalingMessageReceiver* signaling_message_receiver_;

View File

@ -110,11 +110,11 @@ bool static ParseConfigString(const std::string& config,
struct SignalingParams : public talk_base::MessageData {
SignalingParams(const std::string& msg,
webrtc::StreamCollection* local_streams)
webrtc::StreamCollectionInterface* local_streams)
: msg(msg),
local_streams(local_streams) {}
const std::string msg;
scoped_refptr<webrtc::StreamCollection> local_streams;
talk_base::scoped_refptr<webrtc::StreamCollectionInterface> local_streams;
};
} // namespace
@ -199,13 +199,15 @@ bool PeerConnectionImpl::Initialize(const std::string& configuration,
return session_->Initialize();
}
scoped_refptr<StreamCollection> PeerConnectionImpl::local_streams() {
talk_base::scoped_refptr<StreamCollectionInterface>
PeerConnectionImpl::local_streams() {
return local_media_streams_;
}
scoped_refptr<StreamCollection> PeerConnectionImpl::remote_streams() {
ScopedRefMessageData<StreamCollection>* msg =
new ScopedRefMessageData<StreamCollection>(NULL);
talk_base::scoped_refptr<StreamCollectionInterface>
PeerConnectionImpl::remote_streams() {
ScopedRefMessageData<StreamCollectionInterface>* msg =
new ScopedRefMessageData<StreamCollectionInterface>(NULL);
signaling_thread_->Send(this, MSG_RETURNREMOTEMEDIASTREAMS, msg);
return msg->data();
}
@ -226,8 +228,8 @@ void PeerConnectionImpl::RemoveStream(
}
void PeerConnectionImpl::CommitStreamChanges() {
ScopedRefMessageData<StreamCollection>* msg =
new ScopedRefMessageData<StreamCollection> (
ScopedRefMessageData<StreamCollectionInterface>* msg =
new ScopedRefMessageData<StreamCollectionInterface> (
StreamCollectionImpl::Create(local_media_streams_));
signaling_thread_->Post(this, MSG_COMMITSTREAMCHANGES, msg);
}
@ -236,8 +238,8 @@ void PeerConnectionImpl::OnMessage(talk_base::Message* msg) {
talk_base::MessageData* data = msg->pdata;
switch (msg->message_id) {
case MSG_COMMITSTREAMCHANGES: {
ScopedRefMessageData<StreamCollection>* param(
static_cast<ScopedRefMessageData<StreamCollection>*> (data));
ScopedRefMessageData<StreamCollectionInterface>* param(
static_cast<ScopedRefMessageData<StreamCollectionInterface>*> (data));
signaling_->CreateOffer(param->data());
stream_handler_->CommitLocalStreams(param->data());
delete data; // Because it is Posted.
@ -250,8 +252,8 @@ void PeerConnectionImpl::OnMessage(talk_base::Message* msg) {
break;
}
case MSG_RETURNREMOTEMEDIASTREAMS: {
ScopedRefMessageData<StreamCollection>* param(
static_cast<ScopedRefMessageData<StreamCollection>*> (data));
ScopedRefMessageData<StreamCollectionInterface>* param(
static_cast<ScopedRefMessageData<StreamCollectionInterface>*> (data));
param->data() = StreamCollectionImpl::Create(remote_media_streams_);
break;
}

View File

@ -49,7 +49,7 @@ class StreamCollectionImpl;
// PeerConnectionImpl implements the PeerConnection interface.
// It uses PeerConnectionSignaling and WebRtcSession to implement
// the PeerConnection functionality.
class PeerConnectionImpl : public PeerConnection,
class PeerConnectionImpl : public PeerConnectionInterface,
public talk_base::MessageHandler,
public sigslot::has_slots<> {
public:
@ -69,8 +69,8 @@ class PeerConnectionImpl : public PeerConnection,
// TODO(perkj): implement
ASSERT(false);
}
virtual scoped_refptr<StreamCollection> local_streams();
virtual scoped_refptr<StreamCollection> remote_streams();
virtual talk_base::scoped_refptr<StreamCollectionInterface> local_streams();
virtual talk_base::scoped_refptr<StreamCollectionInterface> remote_streams();
virtual void AddStream(LocalMediaStreamInterface* stream);
virtual void RemoveStream(LocalMediaStreamInterface* stream);
virtual void CommitStreamChanges();
@ -87,13 +87,13 @@ class PeerConnectionImpl : public PeerConnection,
void Terminate_s();
PeerConnectionObserver* observer_;
scoped_refptr<StreamCollectionImpl> local_media_streams_;
scoped_refptr<StreamCollectionImpl> remote_media_streams_;
talk_base::scoped_refptr<StreamCollectionImpl> local_media_streams_;
talk_base::scoped_refptr<StreamCollectionImpl> remote_media_streams_;
talk_base::Thread* signaling_thread_; // Weak ref from PeerConnectionManager.
cricket::ChannelManager* channel_manager_;
scoped_refptr<PcNetworkManager> network_manager_;
scoped_refptr<PcPacketSocketFactory> socket_factory_;
talk_base::scoped_refptr<PcNetworkManager> network_manager_;
talk_base::scoped_refptr<PcPacketSocketFactory> socket_factory_;
talk_base::scoped_ptr<cricket::HttpPortAllocator> port_allocator_;
talk_base::scoped_ptr<WebRtcSession> session_;
talk_base::scoped_ptr<PeerConnectionSignaling> signaling_;

View File

@ -59,15 +59,15 @@ class PeerConnectionImplTest : public testing::Test {
ASSERT_TRUE(pc_.get() != NULL);
}
scoped_refptr<webrtc::PeerConnectionManager> pc_factory_;
scoped_refptr<PeerConnection> pc_;
talk_base::scoped_refptr<webrtc::PeerConnectionManager> pc_factory_;
talk_base::scoped_refptr<PeerConnectionInterface> pc_;
MockPeerConnectionObserver observer_;
};
TEST_F(PeerConnectionImplTest, AddRemoveStream) {
TEST_F(PeerConnectionImplTest, DISABLED_AddRemoveStream) {
// Create a local stream.
std::string label(kStreamLabel1);
scoped_refptr<LocalMediaStreamInterface> stream(
talk_base::scoped_refptr<LocalMediaStreamInterface> stream(
pc_factory_->CreateLocalMediaStream(label));
pc_->AddStream(stream);

View File

@ -58,33 +58,34 @@ class MockPeerConnectionObserver : public PeerConnectionObserver {
// TODO(mallinath) - Fix drash when components are created in factory.
TEST(PeerConnectionManager, DISABLED_CreatePCUsingInternalModules) {
MockPeerConnectionObserver observer;
scoped_refptr<PeerConnectionManager> manager(PeerConnectionManager::Create());
talk_base::scoped_refptr<PeerConnectionManager> manager(
PeerConnectionManager::Create());
ASSERT_TRUE(manager.get() != NULL);
scoped_refptr<PeerConnection> pc1(manager->CreatePeerConnection("",
&observer));
talk_base::scoped_refptr<PeerConnectionInterface> pc1(
manager->CreatePeerConnection("", &observer));
EXPECT_TRUE(pc1.get() == NULL);
scoped_refptr<PeerConnection> pc2(manager->CreatePeerConnection(
kStunConfiguration, &observer));
talk_base::scoped_refptr<PeerConnectionInterface> pc2(
manager->CreatePeerConnection(kStunConfiguration, &observer));
EXPECT_TRUE(pc2.get() != NULL);
}
TEST(PeerConnectionManager, CreatePCUsingExternalModules) {
// Create an audio device. Use the default sound card.
scoped_refptr<AudioDeviceModule> audio_device(
talk_base::scoped_refptr<AudioDeviceModule> audio_device(
AudioDeviceModuleImpl::Create(0));
// 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(
talk_base::scoped_refptr<PcNetworkManager> network_manager(
PcNetworkManager::Create(new talk_base::BasicNetworkManager));
talk_base::scoped_refptr<PcPacketSocketFactory> socket_factory(
PcPacketSocketFactory::Create(new talk_base::BasicPacketSocketFactory));
scoped_refptr<PeerConnectionManager> manager =
talk_base::scoped_refptr<PeerConnectionManager> manager =
PeerConnectionManager::Create(talk_base::Thread::Current(),
talk_base::Thread::Current(),
network_manager,
@ -93,13 +94,13 @@ TEST(PeerConnectionManager, CreatePCUsingExternalModules) {
ASSERT_TRUE(manager.get() != NULL);
MockPeerConnectionObserver observer;
scoped_refptr<webrtc::PeerConnection> pc1(manager->CreatePeerConnection(
"", &observer));
talk_base::scoped_refptr<webrtc::PeerConnectionInterface> pc1(
manager->CreatePeerConnection("", &observer));
EXPECT_TRUE(pc1.get() == NULL);
scoped_refptr<PeerConnection> pc2(manager->CreatePeerConnection(
kStunConfiguration, &observer));
talk_base::scoped_refptr<PeerConnectionInterface> pc2(
manager->CreatePeerConnection(kStunConfiguration, &observer));
EXPECT_TRUE(pc2.get() != NULL);
}

View File

@ -49,7 +49,7 @@ struct CreatePeerConnectionParams : public talk_base::MessageData {
webrtc::PeerConnectionObserver* observer)
: configuration(configuration), observer(observer) {
}
scoped_refptr<webrtc::PeerConnection> peerconnection;
talk_base::scoped_refptr<webrtc::PeerConnectionInterface> peerconnection;
const std::string& configuration;
webrtc::PeerConnectionObserver* observer;
};
@ -64,10 +64,10 @@ enum {
namespace webrtc {
scoped_refptr<PcNetworkManager> PcNetworkManager::Create(
talk_base::scoped_refptr<PcNetworkManager> PcNetworkManager::Create(
talk_base::NetworkManager* network_manager) {
talk_base::RefCountImpl<PcNetworkManager>* implementation =
new talk_base::RefCountImpl<PcNetworkManager>(network_manager);
talk_base::RefCount<PcNetworkManager>* implementation =
new talk_base::RefCount<PcNetworkManager>(network_manager);
return implementation;
}
@ -83,10 +83,10 @@ PcNetworkManager::~PcNetworkManager() {
delete network_manager_;
}
scoped_refptr<PcPacketSocketFactory> PcPacketSocketFactory::Create(
talk_base::scoped_refptr<PcPacketSocketFactory> PcPacketSocketFactory::Create(
talk_base::PacketSocketFactory* socket_factory) {
talk_base::RefCountImpl<PcPacketSocketFactory>* implementation =
new talk_base::RefCountImpl<PcPacketSocketFactory>(socket_factory);
talk_base::RefCount<PcPacketSocketFactory>* implementation =
new talk_base::RefCount<PcPacketSocketFactory>(socket_factory);
return implementation;
}
@ -103,9 +103,10 @@ talk_base::PacketSocketFactory* PcPacketSocketFactory::socket_factory() const {
return socket_factory_;
}
scoped_refptr<PeerConnectionManager> PeerConnectionManager::Create() {
talk_base::RefCountImpl<PeerConnectionManagerImpl>* pc_manager =
new talk_base::RefCountImpl<PeerConnectionManagerImpl>();
talk_base::scoped_refptr<PeerConnectionManager>
PeerConnectionManager::Create() {
talk_base::RefCount<PeerConnectionManagerImpl>* pc_manager =
new talk_base::RefCount<PeerConnectionManagerImpl>();
if (!pc_manager->Initialize()) {
delete pc_manager;
@ -114,18 +115,18 @@ scoped_refptr<PeerConnectionManager> PeerConnectionManager::Create() {
return pc_manager;
}
scoped_refptr<PeerConnectionManager> PeerConnectionManager::Create(
talk_base::scoped_refptr<PeerConnectionManager> PeerConnectionManager::Create(
talk_base::Thread* worker_thread,
talk_base::Thread* signaling_thread,
PcNetworkManager* network_manager,
PcPacketSocketFactory* socket_factory,
AudioDeviceModule* default_adm) {
talk_base::RefCountImpl<PeerConnectionManagerImpl>* pc_manager =
new talk_base::RefCountImpl<PeerConnectionManagerImpl>(worker_thread,
signaling_thread,
network_manager,
socket_factory,
default_adm);
talk_base::RefCount<PeerConnectionManagerImpl>* pc_manager =
new talk_base::RefCount<PeerConnectionManagerImpl>(worker_thread,
signaling_thread,
network_manager,
socket_factory,
default_adm);
if (!pc_manager->Initialize()) {
delete pc_manager;
pc_manager = NULL;
@ -212,7 +213,8 @@ bool PeerConnectionManagerImpl::Initialize_s() {
return true;
}
scoped_refptr<PeerConnection> PeerConnectionManagerImpl::CreatePeerConnection(
talk_base::scoped_refptr<PeerConnectionInterface>
PeerConnectionManagerImpl::CreatePeerConnection(
const std::string& configuration,
PeerConnectionObserver* observer) {
CreatePeerConnectionParams params(configuration, observer);
@ -220,15 +222,16 @@ scoped_refptr<PeerConnection> PeerConnectionManagerImpl::CreatePeerConnection(
return params.peerconnection;
}
scoped_refptr<PeerConnection> PeerConnectionManagerImpl::CreatePeerConnection_s(
talk_base::scoped_refptr<PeerConnectionInterface>
PeerConnectionManagerImpl::CreatePeerConnection_s(
const std::string& configuration,
PeerConnectionObserver* observer) {
talk_base::RefCountImpl<PeerConnectionImpl>* pc(
new talk_base::RefCountImpl<PeerConnectionImpl>(channel_manager_.get(),
signaling_thread_ptr_,
worker_thread_ptr_,
network_manager_,
socket_factory_));
talk_base::RefCount<PeerConnectionImpl>* pc(
new talk_base::RefCount<PeerConnectionImpl>(channel_manager_.get(),
signaling_thread_ptr_,
worker_thread_ptr_,
network_manager_,
socket_factory_));
if (!pc->Initialize(configuration, observer)) {
delete pc;
pc = NULL;
@ -236,13 +239,13 @@ scoped_refptr<PeerConnection> PeerConnectionManagerImpl::CreatePeerConnection_s(
return pc;
}
scoped_refptr<LocalMediaStreamInterface>
talk_base::scoped_refptr<LocalMediaStreamInterface>
PeerConnectionManagerImpl::CreateLocalMediaStream(
const std::string& label) {
return MediaStreamProxy::Create(label, signaling_thread_ptr_);
}
scoped_refptr<LocalVideoTrackInterface>
talk_base::scoped_refptr<LocalVideoTrackInterface>
PeerConnectionManagerImpl::CreateLocalVideoTrack(
const std::string& label,
VideoCaptureModule* video_device) {
@ -250,7 +253,7 @@ PeerConnectionManagerImpl::CreateLocalVideoTrack(
signaling_thread_ptr_);
}
scoped_refptr<LocalAudioTrackInterface>
talk_base::scoped_refptr<LocalAudioTrackInterface>
PeerConnectionManagerImpl::CreateLocalAudioTrack(
const std::string& label,
AudioDeviceModule* audio_device) {

View File

@ -40,21 +40,21 @@ namespace webrtc {
class PeerConnectionManagerImpl : public PeerConnectionManager,
public talk_base::MessageHandler {
public:
scoped_refptr<PeerConnection> CreatePeerConnection(
talk_base::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
const std::string& config,
PeerConnectionObserver* observer);
bool Initialize();
virtual scoped_refptr<LocalMediaStreamInterface> CreateLocalMediaStream(
const std::string& label);
virtual talk_base::scoped_refptr<LocalMediaStreamInterface>
CreateLocalMediaStream(const std::string& label);
virtual scoped_refptr<LocalVideoTrackInterface> CreateLocalVideoTrack(
const std::string& label,
VideoCaptureModule* video_device);
virtual talk_base::scoped_refptr<LocalVideoTrackInterface>
CreateLocalVideoTrack(const std::string& label,
VideoCaptureModule* video_device);
virtual scoped_refptr<LocalAudioTrackInterface> CreateLocalAudioTrack(
const std::string& label,
AudioDeviceModule* audio_device);
virtual talk_base::scoped_refptr<LocalAudioTrackInterface>
CreateLocalAudioTrack(const std::string& label,
AudioDeviceModule* audio_device);
protected:
PeerConnectionManagerImpl();
@ -68,22 +68,21 @@ class PeerConnectionManagerImpl : public PeerConnectionManager,
private:
bool Initialize_s();
scoped_refptr<PeerConnection> CreatePeerConnection_s(
talk_base::scoped_refptr<PeerConnectionInterface> CreatePeerConnection_s(
const std::string& configuration,
PeerConnectionObserver* observer);
// Implements talk_base::MessageHandler.
void OnMessage(talk_base::Message* msg);
talk_base::scoped_ptr<talk_base::Thread> worker_thread_;
talk_base::Thread* worker_thread_ptr_;
talk_base::scoped_ptr<talk_base::Thread> signaling_thread_;
talk_base::Thread* signaling_thread_ptr_;
scoped_refptr<PcNetworkManager> network_manager_;
scoped_refptr<PcPacketSocketFactory> socket_factory_;
talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_;
talk_base::scoped_ptr<talk_base::Thread> worker_thread_;
talk_base::Thread* worker_thread_ptr_;
talk_base::scoped_refptr<PcNetworkManager> network_manager_;
talk_base::scoped_refptr<PcPacketSocketFactory> socket_factory_;
// External Audio device used for audio playback.
scoped_refptr<AudioDeviceModule> default_adm_;
talk_base::scoped_refptr<AudioDeviceModule> default_adm_;
talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_;
};
} // namespace webrtc

View File

@ -117,7 +117,7 @@ void PeerConnectionSignaling::OnCandidatesReady(
void PeerConnectionSignaling::ProcessSignalingMessage(
const std::string& message,
StreamCollection* local_streams) {
StreamCollectionInterface* local_streams) {
ASSERT(talk_base::Thread::Current() == signaling_thread_);
talk_base::scoped_ptr<PeerConnectionMessage> signaling_message(
@ -169,7 +169,8 @@ void PeerConnectionSignaling::ProcessSignalingMessage(
signaling_message->candidates());
provider_->NegotiationDone();
UpdateRemoteStreams(remote_desc);
scoped_refptr<StreamCollection> streams(queued_offers_.front());
talk_base::scoped_refptr<StreamCollectionInterface> streams(
queued_offers_.front());
queued_offers_.pop_front();
UpdateSendingLocalStreams(remote_desc, streams);
// Check if we have more offers waiting in the queue.
@ -194,7 +195,8 @@ void PeerConnectionSignaling::ProcessSignalingMessage(
}
}
void PeerConnectionSignaling::CreateOffer(StreamCollection* local_streams) {
void PeerConnectionSignaling::CreateOffer(
StreamCollectionInterface* local_streams) {
ASSERT(talk_base::Thread::Current() == signaling_thread_);
queued_offers_.push_back(local_streams);
if (state_ == kIdle) {
@ -219,7 +221,8 @@ void PeerConnectionSignaling::OnMessage(talk_base::Message* msg) {
void PeerConnectionSignaling::CreateOffer_s() {
ASSERT(queued_offers_.size() > 0);
scoped_refptr<StreamCollection> local_streams(queued_offers_.front());
talk_base::scoped_refptr<StreamCollectionInterface>
local_streams(queued_offers_.front());
cricket::MediaSessionOptions options;
InitMediaSessionOptions(&options, local_streams);
@ -241,7 +244,7 @@ void PeerConnectionSignaling::CreateAnswer_s() {
talk_base::scoped_ptr<PeerConnectionMessage> message(
queued_received_offer_.first);
queued_received_offer_.first = NULL;
scoped_refptr<StreamCollection> local_streams(
talk_base::scoped_refptr<StreamCollectionInterface> local_streams(
queued_received_offer_.second.release());
// Reset all pending offers. Instead, send the new streams in the answer.
@ -291,18 +294,19 @@ void PeerConnectionSignaling::CreateAnswer_s() {
// corresponding to the MediaStream and a label of the track.
void PeerConnectionSignaling::InitMediaSessionOptions(
cricket::MediaSessionOptions* options,
StreamCollection* local_streams) {
StreamCollectionInterface* local_streams) {
// In order to be able to receive video,
// the is_video should always be true even if there are not video tracks.
options->is_video = true;
for (size_t i = 0; i < local_streams->count(); ++i) {
MediaStreamInterface* stream = local_streams->at(i);
scoped_refptr<MediaStreamTrackListInterface<AudioTrackInterface> >
talk_base::scoped_refptr<AudioTracks>
audio_tracks = stream->audio_tracks();
// For each audio track in the stream, add it to the MediaSessionOptions.
for (size_t j = 0; j < audio_tracks->count(); ++j) {
scoped_refptr<MediaStreamTrackInterface> track = audio_tracks->at(j);
talk_base::scoped_refptr<MediaStreamTrackInterface> track =
audio_tracks->at(j);
if (track->ssrc() == 0)
track->set_ssrc(++ssrc_counter_);
options->audio_sources.push_back(cricket::SourceParam(track->ssrc(),
@ -310,11 +314,12 @@ void PeerConnectionSignaling::InitMediaSessionOptions(
stream->label()));
}
scoped_refptr<MediaStreamTrackListInterface<VideoTrackInterface> >
talk_base::scoped_refptr<VideoTracks>
video_tracks = stream->video_tracks();
// For each video track in the stream, add it to the MediaSessionOptions.
for (size_t j = 0; j < video_tracks->count(); ++j) {
scoped_refptr<MediaStreamTrackInterface> track = video_tracks->at(j);
talk_base::scoped_refptr<MediaStreamTrackInterface> track =
video_tracks->at(j);
if (track->ssrc() == 0)
track->set_ssrc(++ssrc_counter_);
options->video_sources.push_back(cricket::SourceParam(track->ssrc(),
@ -332,7 +337,7 @@ void PeerConnectionSignaling::InitMediaSessionOptions(
void PeerConnectionSignaling::UpdateRemoteStreams(
const cricket::SessionDescription* remote_desc) {
RemoteStreamMap current_streams;
typedef std::pair<std::string, scoped_refptr<MediaStreamProxy> >
typedef std::pair<std::string, talk_base::scoped_refptr<MediaStreamProxy> >
MediaStreamPair;
const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc);
@ -352,19 +357,20 @@ void PeerConnectionSignaling::UpdateRemoteStreams(
if (old_streams_it == remote_streams_.end()) {
if (new_streams_it == current_streams.end()) {
// New stream
scoped_refptr<MediaStreamProxy> stream(
talk_base::scoped_refptr<MediaStreamProxy> stream(
MediaStreamProxy::Create(it->cname, signaling_thread_));
current_streams.insert(MediaStreamPair(stream->label(), stream));
new_streams_it = current_streams.find(it->cname);
}
scoped_refptr<AudioTrackInterface> track(
talk_base::scoped_refptr<AudioTrackInterface> track(
AudioTrackProxy::CreateRemote(it->description, it->ssrc,
signaling_thread_));
track->set_state(MediaStreamTrackInterface::kLive);
new_streams_it->second->AddTrack(track);
} else {
scoped_refptr<MediaStreamProxy> stream(old_streams_it->second);
talk_base::scoped_refptr<MediaStreamProxy> stream(
old_streams_it->second);
current_streams.insert(MediaStreamPair(stream->label(), stream));
}
}
@ -387,19 +393,20 @@ void PeerConnectionSignaling::UpdateRemoteStreams(
if (old_streams_it == remote_streams_.end()) {
if (new_streams_it == current_streams.end()) {
// New stream
scoped_refptr<MediaStreamProxy> stream(
talk_base::scoped_refptr<MediaStreamProxy> stream(
MediaStreamProxy::Create(it->cname, signaling_thread_));
current_streams.insert(MediaStreamPair(stream->label(), stream));
new_streams_it = current_streams.find(it->cname);
}
scoped_refptr<VideoTrackInterface> track(
talk_base::scoped_refptr<VideoTrackInterface> track(
VideoTrackProxy::CreateRemote(it->description, it->ssrc,
signaling_thread_));
new_streams_it->second->AddTrack(track);
track->set_state(MediaStreamTrackInterface::kLive);
} else {
scoped_refptr<MediaStreamProxy> stream(old_streams_it->second);
talk_base::scoped_refptr<MediaStreamProxy>
stream(old_streams_it->second);
current_streams.insert(MediaStreamPair(stream->label(), stream));
}
}
@ -410,7 +417,7 @@ void PeerConnectionSignaling::UpdateRemoteStreams(
for (RemoteStreamMap::iterator it = current_streams.begin();
it != current_streams.end();
++it) {
scoped_refptr<MediaStreamProxy> new_stream(it->second);
talk_base::scoped_refptr<MediaStreamProxy> new_stream(it->second);
RemoteStreamMap::iterator old_streams_it =
remote_streams_.find(new_stream->label());
if (old_streams_it == remote_streams_.end()) {
@ -425,17 +432,17 @@ void PeerConnectionSignaling::UpdateRemoteStreams(
for (RemoteStreamMap::iterator it = remote_streams_.begin();
it != remote_streams_.end();
++it) {
scoped_refptr<MediaStreamProxy> old_stream(it->second);
talk_base::scoped_refptr<MediaStreamProxy> old_stream(it->second);
RemoteStreamMap::iterator new_streams_it =
current_streams.find(old_stream->label());
if (new_streams_it == current_streams.end()) {
old_stream->set_ready_state(MediaStreamInterface::kEnded);
scoped_refptr<MediaStreamTrackListInterface<AudioTrackInterface> >
talk_base::scoped_refptr<AudioTracks>
audio_tracklist(old_stream->audio_tracks());
for (size_t j = 0; j < audio_tracklist->count(); ++j) {
audio_tracklist->at(j)->set_state(MediaStreamTrackInterface::kEnded);
}
scoped_refptr<MediaStreamTrackListInterface<VideoTrackInterface> >
talk_base::scoped_refptr<VideoTracks>
video_tracklist(old_stream->video_tracks());
for (size_t j = 0; j < video_tracklist->count(); ++j) {
video_tracklist->at(j)->set_state(MediaStreamTrackInterface::kEnded);
@ -453,22 +460,25 @@ void PeerConnectionSignaling::UpdateRemoteStreams(
// failed the state is changed to kEnded.
void PeerConnectionSignaling::UpdateSendingLocalStreams(
const cricket::SessionDescription* answer_desc,
StreamCollection* negotiated_streams) {
typedef std::pair<std::string, scoped_refptr<MediaStreamInterface> >
MediaStreamPair;
StreamCollectionInterface* negotiated_streams) {
typedef std::pair<std::string,
talk_base::scoped_refptr<MediaStreamInterface> >
MediaStreamPair;
LocalStreamMap current_local_streams;
for (size_t i = 0; i < negotiated_streams->count(); ++i) {
scoped_refptr<MediaStreamInterface> stream = negotiated_streams->at(i);
scoped_refptr<MediaStreamTrackListInterface<AudioTrackInterface> >
audiotracklist(stream->audio_tracks());
scoped_refptr<MediaStreamTrackListInterface<VideoTrackInterface> >
videotracklist(stream->video_tracks());
talk_base::scoped_refptr<MediaStreamInterface> stream =
negotiated_streams->at(i);
talk_base::scoped_refptr<AudioTracks> audiotracklist(
stream->audio_tracks());
talk_base::scoped_refptr<VideoTracks> videotracklist(
stream->video_tracks());
bool stream_ok = false; // A stream is ok if at least one track succeed.
// Update tracks based on its type.
for (size_t j = 0; j < audiotracklist->count(); ++j) {
scoped_refptr<MediaStreamTrackInterface> track = audiotracklist->at(j);
talk_base::scoped_refptr<MediaStreamTrackInterface> track =
audiotracklist->at(j);
const cricket::ContentInfo* audio_content =
GetFirstAudioContent(answer_desc);
if (!audio_content) { // The remote does not accept audio.
@ -489,7 +499,8 @@ void PeerConnectionSignaling::UpdateSendingLocalStreams(
}
for (size_t j = 0; j < videotracklist->count(); ++j) {
scoped_refptr<MediaStreamTrackInterface> track = videotracklist->at(j);
talk_base::scoped_refptr<MediaStreamTrackInterface> track =
videotracklist->at(j);
const cricket::ContentInfo* video_content =
GetFirstVideoContent(answer_desc);
if (!video_content) { // The remote does not accept video.
@ -525,18 +536,18 @@ void PeerConnectionSignaling::UpdateSendingLocalStreams(
for (LocalStreamMap::iterator it = local_streams_.begin();
it != local_streams_.end();
++it) {
scoped_refptr<MediaStreamInterface> old_stream(it->second);
talk_base::scoped_refptr<MediaStreamInterface> old_stream(it->second);
MediaStreamInterface* new_streams =
negotiated_streams->find(old_stream->label());
if (new_streams == NULL) {
old_stream->set_ready_state(MediaStreamInterface::kEnded);
scoped_refptr<MediaStreamTrackListInterface<AudioTrackInterface> >
audio_tracklist(old_stream->audio_tracks());
talk_base::scoped_refptr<AudioTracks> audio_tracklist(
old_stream->audio_tracks());
for (size_t j = 0; j < audio_tracklist->count(); ++j) {
audio_tracklist->at(j)->set_state(MediaStreamTrackInterface::kEnded);
}
scoped_refptr<MediaStreamTrackListInterface<VideoTrackInterface> >
video_tracklist(old_stream->video_tracks());
talk_base::scoped_refptr<VideoTracks> video_tracklist(
old_stream->video_tracks());
for (size_t j = 0; j < video_tracklist->count(); ++j) {
video_tracklist->at(j)->set_state(MediaStreamTrackInterface::kEnded);
}

View File

@ -94,13 +94,13 @@ class PeerConnectionSignaling : public WebRtcSessionObserver,
// Process a received offer/answer from the remote peer.
void ProcessSignalingMessage(const std::string& message,
StreamCollection* local_streams);
StreamCollectionInterface* local_streams);
// Creates an offer containing all tracks in local_streams.
// When the offer is ready it is signaled by SignalNewPeerConnectionMessage.
// When the remote peer is ready to receive media on a stream , the state of
// the local stream will change to kAlive.
void CreateOffer(StreamCollection* local_streams);
void CreateOffer(StreamCollectionInterface* local_streams);
// Returns the current state.
State GetState();
@ -129,18 +129,20 @@ class PeerConnectionSignaling : public WebRtcSessionObserver,
void CreateAnswer_s();
void InitMediaSessionOptions(cricket::MediaSessionOptions* options,
StreamCollection* local_streams);
StreamCollectionInterface* local_streams);
void UpdateRemoteStreams(const cricket::SessionDescription* remote_desc);
void UpdateSendingLocalStreams(
const cricket::SessionDescription* answer_desc,
StreamCollection* negotiated_streams);
StreamCollectionInterface* negotiated_streams);
typedef std::list<scoped_refptr<StreamCollection> > StreamCollectionList;
typedef std::list<talk_base::scoped_refptr<StreamCollectionInterface> >
StreamCollectionList;
StreamCollectionList queued_offers_;
typedef std::pair<PeerConnectionMessage*,
scoped_refptr<StreamCollection> > RemoteOfferPair;
talk_base::scoped_refptr<StreamCollectionInterface> >
RemoteOfferPair;
RemoteOfferPair queued_received_offer_;
talk_base::Thread* signaling_thread_;
@ -148,10 +150,10 @@ class PeerConnectionSignaling : public WebRtcSessionObserver,
State state_;
uint32 ssrc_counter_;
typedef std::map<std::string, scoped_refptr<MediaStreamProxy> >
typedef std::map<std::string, talk_base::scoped_refptr<MediaStreamProxy> >
RemoteStreamMap;
RemoteStreamMap remote_streams_;
typedef std::map<std::string, scoped_refptr<MediaStreamInterface> >
typedef std::map<std::string, talk_base::scoped_refptr<MediaStreamInterface> >
LocalStreamMap;
LocalStreamMap local_streams_;
cricket::Candidates candidates_;

View File

@ -46,11 +46,12 @@ static const int kWaitTime = 5000;
namespace webrtc {
typedef std::map<std::string,
scoped_refptr<MediaStreamInterface> > MediaStreamMap;
typedef std::pair<std::string, scoped_refptr<MediaStreamInterface> > RemotePair;
typedef std::map<std::string, talk_base::scoped_refptr<MediaStreamInterface> >
MediaStreamMap;
typedef std::pair<std::string, talk_base::scoped_refptr<MediaStreamInterface> >
RemotePair;
class MockMediaTrackObserver : public webrtc::Observer {
class MockMediaTrackObserver : public webrtc::ObserverInterface {
public:
explicit MockMediaTrackObserver(MediaStreamTrackInterface* track)
: track_(track) {
@ -64,10 +65,10 @@ class MockMediaTrackObserver : public webrtc::Observer {
webrtc::MediaStreamTrackInterface::TrackState track_state;
private:
scoped_refptr<MediaStreamTrackInterface> track_;
talk_base::scoped_refptr<MediaStreamTrackInterface> track_;
};
class MockMediaStreamObserver : public webrtc::Observer {
class MockMediaStreamObserver : public webrtc::ObserverInterface {
public:
explicit MockMediaStreamObserver(MediaStreamInterface* stream)
: stream_(stream) {
@ -81,7 +82,7 @@ class MockMediaStreamObserver : public webrtc::Observer {
webrtc::MediaStreamInterface::ReadyState ready_state;
private:
scoped_refptr<MediaStreamInterface> stream_;
talk_base::scoped_refptr<MediaStreamInterface> stream_;
};
class MockSignalingObserver : public sigslot::has_slots<> {
@ -147,7 +148,7 @@ class MockSignalingObserver : public sigslot::has_slots<> {
private:
MediaStreamMap remote_media_streams_;
scoped_refptr<StreamCollectionImpl> remote_local_collection_;
talk_base::scoped_refptr<StreamCollectionImpl> remote_local_collection_;
PeerConnectionSignaling* remote_peer_;
};
@ -239,18 +240,18 @@ class PeerConnectionSignalingTest: public testing::Test {
TEST_F(PeerConnectionSignalingTest, SimpleOneWayCall) {
// Create a local stream.
std::string label(kStreamLabel1);
scoped_refptr<LocalMediaStreamInterface> stream(
talk_base::scoped_refptr<LocalMediaStreamInterface> stream(
MediaStream::Create(label));
MockMediaStreamObserver stream_observer1(stream);
// Add a local audio track.
scoped_refptr<LocalAudioTrackInterface> audio_track(AudioTrack::CreateLocal(
kAudioTrackLabel1, NULL));
talk_base::scoped_refptr<LocalAudioTrackInterface>
audio_track(AudioTrack::CreateLocal(kAudioTrackLabel1, NULL));
stream->AddTrack(audio_track);
MockMediaTrackObserver track_observer1(audio_track);
// Peer 1 create an offer with only one audio track.
scoped_refptr<StreamCollectionImpl> local_collection1(
talk_base::scoped_refptr<StreamCollectionImpl> local_collection1(
StreamCollectionImpl::Create());
local_collection1->AddStream(stream);
// Verify that the local stream is now initializing.
@ -260,7 +261,7 @@ TEST_F(PeerConnectionSignalingTest, SimpleOneWayCall) {
track_observer1.track_state);
// Peer 2 only receive. Create an empty collection
scoped_refptr<StreamCollectionImpl> local_collection2(
talk_base::scoped_refptr<StreamCollectionImpl> local_collection2(
StreamCollectionImpl::Create());
// Connect all messages sent from Peer1 to be received on Peer2
@ -314,16 +315,16 @@ TEST_F(PeerConnectionSignalingTest, Glare) {
signaling2_->OnCandidatesReady(candidates_);
// Create a local stream.
std::string label(kStreamLabel1);
scoped_refptr<LocalMediaStreamInterface> stream(
talk_base::scoped_refptr<LocalMediaStreamInterface> stream(
MediaStream::Create(label));
// Add a local audio track.
scoped_refptr<LocalAudioTrackInterface> audio_track(AudioTrack::CreateLocal(
kAudioTrackLabel1, NULL));
talk_base::scoped_refptr<LocalAudioTrackInterface>
audio_track(AudioTrack::CreateLocal(kAudioTrackLabel1, NULL));
stream->AddTrack(audio_track);
// Peer 1 create an offer with only one audio track.
scoped_refptr<StreamCollectionImpl> local_collection1(
talk_base::scoped_refptr<StreamCollectionImpl> local_collection1(
StreamCollectionImpl::Create());
local_collection1->AddStream(stream);
signaling1_->CreateOffer(local_collection1);
@ -333,7 +334,7 @@ TEST_F(PeerConnectionSignalingTest, Glare) {
talk_base::Thread::Current()->ProcessMessages(1);
// Peer 2 only receive. Create an empty collection.
scoped_refptr<StreamCollectionImpl> local_collection2(
talk_base::scoped_refptr<StreamCollectionImpl> local_collection2(
StreamCollectionImpl::Create());
// Peer 2 create an empty offer.
signaling2_->CreateOffer(local_collection2);
@ -378,28 +379,28 @@ TEST_F(PeerConnectionSignalingTest, AddRemoveStream) {
signaling2_->OnCandidatesReady(candidates_);
// Create a local stream.
std::string label(kStreamLabel1);
scoped_refptr<LocalMediaStreamInterface> stream(
talk_base::scoped_refptr<LocalMediaStreamInterface> stream(
MediaStream::Create(label));
MockMediaStreamObserver stream_observer1(stream);
// Add a local audio track.
scoped_refptr<LocalAudioTrackInterface> audio_track(AudioTrack::CreateLocal(
kAudioTrackLabel1, NULL));
talk_base::scoped_refptr<LocalAudioTrackInterface>
audio_track(AudioTrack::CreateLocal(kAudioTrackLabel1, NULL));
stream->AddTrack(audio_track);
MockMediaTrackObserver track_observer1(audio_track);
audio_track->RegisterObserver(&track_observer1);
// Add a local video track.
scoped_refptr<LocalVideoTrackInterface> video_track(VideoTrack::CreateLocal(
kVideoTrackLabel1, NULL));
talk_base::scoped_refptr<LocalVideoTrackInterface>
video_track(VideoTrack::CreateLocal(kVideoTrackLabel1, NULL));
stream->AddTrack(video_track);
// Peer 1 create an empty collection
scoped_refptr<StreamCollectionImpl> local_collection1(
talk_base::scoped_refptr<StreamCollectionImpl> local_collection1(
StreamCollectionImpl::Create());
// Peer 2 create an empty collection
scoped_refptr<StreamCollectionImpl> local_collection2(
talk_base::scoped_refptr<StreamCollectionImpl> local_collection2(
StreamCollectionImpl::Create());
// Connect all messages sent from Peer1 to be received on Peer2

View File

@ -35,36 +35,36 @@
namespace talk_base {
// Reference count interface.
class RefCount {
class RefCountInterface {
public:
virtual int AddRef() = 0;
virtual int Release() = 0;
};
template <class T>
class RefCountImpl : public T {
class RefCount : public T {
public:
RefCountImpl() : ref_count_(0) {
RefCount() : ref_count_(0) {
}
template<typename P>
explicit RefCountImpl(P p) : ref_count_(0), T(p) {
explicit RefCount(P p) : ref_count_(0), T(p) {
}
template<typename P1, typename P2>
RefCountImpl(P1 p1, P2 p2) : ref_count_(0), T(p1, p2) {
RefCount(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) {
RefCount(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) {
RefCount(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)
RefCount(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
: ref_count_(0), T(p1, p2, p3, p4, p5) {
}
@ -84,6 +84,6 @@ class RefCountImpl : public T {
int ref_count_;
};
} // namespace talk_base
} // namespace talk_base
#endif // TALK_APP_WEBRTC_REF_COUNT_H_

View File

@ -50,6 +50,8 @@
// // now, |a| and |b| each own a reference to the same MyFoo object.
// }
//
namespace talk_base {
template <class T>
class scoped_refptr {
public:
@ -125,4 +127,6 @@ class scoped_refptr {
T* ptr_;
};
} // namespace talk_base
#endif // TALK_APP_WEBRTC_SCOPED_REFPTR_H_

View File

@ -36,17 +36,17 @@ template <class T>
class ScopedRefMessageData : public talk_base::MessageData {
public:
explicit ScopedRefMessageData(T* data) : data_(data) { }
const scoped_refptr<T>& data() const { return data_; }
scoped_refptr<T>& data() { return data_; }
const talk_base::scoped_refptr<T>& data() const { return data_; }
talk_base::scoped_refptr<T>& data() { return data_; }
private:
scoped_refptr<T> data_;
talk_base::scoped_refptr<T> data_;
};
/*
struct ScopedTypedMessageData : public talk_base::MessageData {
ScopedRefPtrMsgParams(scoped_refptr<T> ptr)
ScopedRefPtrMsgParams(talk_base::scoped_refptr<T> ptr)
: ptr_(ptr) {
}
scoped_refptr<T> ptr_;
talk_base::scoped_refptr<T> ptr_;
};*/
#endif // TALK_APP_WEBRTC_SCOPED_REF_PTR_MSG_H_

View File

@ -36,18 +36,18 @@
namespace webrtc {
// Implementation of StreamCollection.
class StreamCollectionImpl : public StreamCollection {
class StreamCollectionImpl : public StreamCollectionInterface {
public:
static scoped_refptr<StreamCollectionImpl> Create() {
talk_base::RefCountImpl<StreamCollectionImpl>* implementation =
new talk_base::RefCountImpl<StreamCollectionImpl>();
static talk_base::scoped_refptr<StreamCollectionImpl> Create() {
talk_base::RefCount<StreamCollectionImpl>* implementation =
new talk_base::RefCount<StreamCollectionImpl>();
return implementation;
}
static scoped_refptr<StreamCollectionImpl> Create(
static talk_base::scoped_refptr<StreamCollectionImpl> Create(
StreamCollectionImpl* streams) {
talk_base::RefCountImpl<StreamCollectionImpl>* implementation =
new talk_base::RefCountImpl<StreamCollectionImpl>(streams);
talk_base::RefCount<StreamCollectionImpl>* implementation =
new talk_base::RefCount<StreamCollectionImpl>(streams);
return implementation;
}
@ -93,7 +93,8 @@ class StreamCollectionImpl : public StreamCollection {
explicit StreamCollectionImpl(StreamCollectionImpl* original)
: media_streams_(original->media_streams_) {
}
typedef std::vector<scoped_refptr<MediaStreamInterface> > StreamVector;
typedef std::vector<talk_base::scoped_refptr<MediaStreamInterface> >
StreamVector;
StreamVector media_streams_;
};

View File

@ -48,10 +48,10 @@ class VideoRendererImpl : public VideoRendererWrapperInterface {
cricket::VideoRenderer* renderer_;
};
scoped_refptr<VideoRendererWrapperInterface> CreateVideoRenderer(
talk_base::scoped_refptr<VideoRendererWrapperInterface> CreateVideoRenderer(
cricket::VideoRenderer* renderer) {
talk_base::RefCountImpl<VideoRendererImpl>* r =
new talk_base::RefCountImpl<VideoRendererImpl>(renderer);
talk_base::RefCount<VideoRendererImpl>* r =
new talk_base::RefCount<VideoRendererImpl>(renderer);
return r;
}

View File

@ -45,7 +45,7 @@ VideoTrack::VideoTrack(const std::string& label,
void VideoTrack::SetRenderer(VideoRendererWrapperInterface* renderer) {
video_renderer_ = renderer;
NotifierImpl<LocalVideoTrackInterface>::FireOnChanged();
Notifier<LocalVideoTrackInterface>::FireOnChanged();
}
VideoRendererWrapperInterface* VideoTrack::GetRenderer() {
@ -61,19 +61,19 @@ const char* VideoTrack::kind() const {
return kVideoTrackKind;
}
scoped_refptr<VideoTrack> VideoTrack::CreateRemote(
talk_base::scoped_refptr<VideoTrack> VideoTrack::CreateRemote(
const std::string& label,
uint32 ssrc) {
talk_base::RefCountImpl<VideoTrack>* track =
new talk_base::RefCountImpl<VideoTrack>(label, ssrc);
talk_base::RefCount<VideoTrack>* track =
new talk_base::RefCount<VideoTrack>(label, ssrc);
return track;
}
scoped_refptr<VideoTrack> VideoTrack::CreateLocal(
talk_base::scoped_refptr<VideoTrack> VideoTrack::CreateLocal(
const std::string& label,
VideoCaptureModule* video_device) {
talk_base::RefCountImpl<VideoTrack>* track =
new talk_base::RefCountImpl<VideoTrack>(label, video_device);
talk_base::RefCount<VideoTrack>* track =
new talk_base::RefCount<VideoTrack>(label, video_device);
return track;
}

View File

@ -28,6 +28,8 @@
#ifndef TALK_APP_WEBRTC_VIDEOTRACKIMPL_H_
#define TALK_APP_WEBRTC_VIDEOTRACKIMPL_H_
#include <string>
#include "talk/app/webrtc_dev/mediastream.h"
#include "talk/app/webrtc_dev/mediatrackimpl.h"
#include "talk/app/webrtc_dev/notifierimpl.h"
@ -44,10 +46,11 @@ namespace webrtc {
class VideoTrack : public MediaTrack<LocalVideoTrackInterface> {
public:
// Create a video track used for remote video tracks.
static scoped_refptr<VideoTrack> CreateRemote(const std::string& label,
uint32 ssrc);
static talk_base::scoped_refptr<VideoTrack> CreateRemote(
const std::string& label,
uint32 ssrc);
// Create a video track used for local video tracks.
static scoped_refptr<VideoTrack> CreateLocal(
static talk_base::scoped_refptr<VideoTrack> CreateLocal(
const std::string& label,
VideoCaptureModule* video_device);
@ -62,8 +65,8 @@ class VideoTrack : public MediaTrack<LocalVideoTrackInterface> {
VideoTrack(const std::string& label, VideoCaptureModule* video_device);
private:
scoped_refptr<VideoCaptureModule> video_device_;
scoped_refptr<VideoRendererWrapperInterface> video_renderer_;
talk_base::scoped_refptr<VideoCaptureModule> video_device_;
talk_base::scoped_refptr<VideoRendererWrapperInterface> video_renderer_;
};
} // namespace webrtc

View File

@ -220,10 +220,11 @@ void Conductor::ConnectToPeer(int peer_id) {
}
}
scoped_refptr<webrtc::VideoCaptureModule> Conductor::OpenVideoCaptureDevice() {
talk_base::scoped_refptr<webrtc::VideoCaptureModule>
Conductor::OpenVideoCaptureDevice() {
webrtc::VideoCaptureModule::DeviceInfo* device_info(
webrtc::VideoCaptureFactory::CreateDeviceInfo(0));
scoped_refptr<webrtc::VideoCaptureModule> video_device;
talk_base::scoped_refptr<webrtc::VideoCaptureModule> video_device;
const size_t kMaxDeviceNameLength = 128;
const size_t kMaxUniqueIdLength = 256;
@ -249,23 +250,24 @@ void Conductor::AddStreams() {
if (active_streams_.find(kStreamLabel) != active_streams_.end())
return; // Already added.
scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track(
talk_base::scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track(
peer_connection_factory_->CreateLocalAudioTrack(kAudioLabel, NULL));
scoped_refptr<webrtc::LocalVideoTrackInterface> video_track(
talk_base::scoped_refptr<webrtc::LocalVideoTrackInterface> video_track(
peer_connection_factory_->CreateLocalVideoTrack(
kVideoLabel, OpenVideoCaptureDevice()));
video_track->SetRenderer(main_wnd_->local_renderer());
scoped_refptr<webrtc::LocalMediaStreamInterface> stream =
talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> stream =
peer_connection_factory_->CreateLocalMediaStream(kStreamLabel);
stream->AddTrack(audio_track);
stream->AddTrack(video_track);
peer_connection_->AddStream(stream);
peer_connection_->CommitStreamChanges();
typedef std::pair<std::string, scoped_refptr<webrtc::MediaStreamInterface> >
typedef std::pair<std::string,
talk_base::scoped_refptr<webrtc::MediaStreamInterface> >
MediaStreamPair;
active_streams_.insert(MediaStreamPair(stream->label(), stream));
main_wnd_->SwitchToStreamingUI();
@ -340,8 +342,8 @@ void Conductor::UIThreadCallback(int msg_id, void* data) {
webrtc::MediaStreamInterface* stream =
reinterpret_cast<webrtc::MediaStreamInterface*>(
data);
scoped_refptr<webrtc::MediaStreamTrackListInterface<
webrtc::VideoTrackInterface> > tracks = stream->video_tracks();
talk_base::scoped_refptr<webrtc::VideoTracks> tracks =
stream->video_tracks();
for (size_t i = 0; i < tracks->count(); ++i) {
webrtc::VideoTrackInterface* track = tracks->at(i);
LOG(INFO) << "Setting video renderer for track: " << track->label();

View File

@ -58,7 +58,7 @@ class Conductor
void DeletePeerConnection();
void EnsureStreamingUI();
void AddStreams();
scoped_refptr<webrtc::VideoCaptureModule> OpenVideoCaptureDevice();
talk_base::scoped_refptr<webrtc::VideoCaptureModule> OpenVideoCaptureDevice();
//
// PeerConnectionObserver implementation.
@ -103,13 +103,14 @@ class Conductor
protected:
int peer_id_;
scoped_refptr<webrtc::PeerConnection> peer_connection_;
scoped_refptr<webrtc::PeerConnectionManager> peer_connection_factory_;
talk_base::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
talk_base::scoped_refptr<webrtc::PeerConnectionManager>
peer_connection_factory_;
PeerConnectionClient* client_;
MainWindow* main_wnd_;
std::deque<std::string*> pending_messages_;
std::map<std::string,
scoped_refptr<webrtc::MediaStreamInterface> > active_streams_;
std::map<std::string, talk_base::scoped_refptr<webrtc::MediaStreamInterface> >
active_streams_;
};
#endif // PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_

View File

@ -107,8 +107,10 @@ class GtkMainWnd : public MainWindow {
MainWndCallback* callback_;
std::string server_;
std::string port_;
scoped_refptr<webrtc::VideoRendererWrapperInterface> local_renderer_wrapper_;
scoped_refptr<webrtc::VideoRendererWrapperInterface> remote_renderer_wrapper_;
talk_base::scoped_refptr<webrtc::VideoRendererWrapperInterface>
local_renderer_wrapper_;
talk_base::scoped_refptr<webrtc::VideoRendererWrapperInterface>
remote_renderer_wrapper_;
talk_base::scoped_ptr<uint8> draw_buffer_;
int draw_buffer_size_;
};