Changes after comments received from Justin and Harald. Few comments are not implemented like moving track implementation to base<> and then have child classes based on the type of track.
Review URL: http://webrtc-codereview.appspot.com/217004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@735 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
7951e819af
commit
103f33b734
@ -30,9 +30,10 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
static const char kAudioTrackKind[] = "audio";
|
||||
|
||||
AudioTrackImpl::AudioTrackImpl(const std::string& label, uint32 ssrc)
|
||||
: enabled_(true),
|
||||
kind_(kAudioTrackKind),
|
||||
label_(label),
|
||||
ssrc_(ssrc),
|
||||
state_(kInitializing),
|
||||
@ -42,7 +43,6 @@ AudioTrackImpl::AudioTrackImpl(const std::string& label, uint32 ssrc)
|
||||
AudioTrackImpl::AudioTrackImpl(const std::string& label,
|
||||
AudioDeviceModule* audio_device)
|
||||
: enabled_(true),
|
||||
kind_(kAudioTrackKind),
|
||||
label_(label),
|
||||
ssrc_(0),
|
||||
state_(kInitializing),
|
||||
@ -50,34 +50,22 @@ AudioTrackImpl::AudioTrackImpl(const std::string& label,
|
||||
}
|
||||
|
||||
// Get the AudioDeviceModule associated with this track.
|
||||
scoped_refptr<AudioDeviceModule> AudioTrackImpl::GetAudioDevice() {
|
||||
return audio_device_;
|
||||
AudioDeviceModule* AudioTrackImpl::GetAudioDevice() {
|
||||
return audio_device_.get();
|
||||
}
|
||||
|
||||
// Implement MediaStreamTrack
|
||||
const std::string& AudioTrackImpl::kind() {
|
||||
return kind_;
|
||||
}
|
||||
|
||||
const std::string& AudioTrackImpl::label() {
|
||||
return label_;
|
||||
}
|
||||
|
||||
bool AudioTrackImpl::enabled() {
|
||||
return enabled_;
|
||||
const char* AudioTrackImpl::kind() const {
|
||||
return kAudioTrackKind;
|
||||
}
|
||||
|
||||
bool AudioTrackImpl::set_enabled(bool enable) {
|
||||
bool fire_on_change = enable != enabled_;
|
||||
bool fire_on_change = (enable != enabled_);
|
||||
enabled_ = enable;
|
||||
if (fire_on_change)
|
||||
NotifierImpl<LocalAudioTrack>::FireOnChanged();
|
||||
}
|
||||
|
||||
uint32 AudioTrackImpl::ssrc() {
|
||||
return ssrc_;
|
||||
}
|
||||
|
||||
bool AudioTrackImpl::set_ssrc(uint32 ssrc) {
|
||||
ASSERT(ssrc_ == 0);
|
||||
ASSERT(ssrc != 0);
|
||||
@ -88,12 +76,8 @@ bool AudioTrackImpl::set_ssrc(uint32 ssrc) {
|
||||
return true;
|
||||
}
|
||||
|
||||
MediaStreamTrack::TrackState AudioTrackImpl::state() {
|
||||
return state_;
|
||||
}
|
||||
|
||||
bool AudioTrackImpl::set_state(TrackState new_state) {
|
||||
bool fire_on_change = state_ != new_state;
|
||||
bool fire_on_change = (state_ != new_state);
|
||||
state_ = new_state;
|
||||
if (fire_on_change)
|
||||
NotifierImpl<LocalAudioTrack>::FireOnChanged();
|
||||
@ -102,19 +86,17 @@ bool AudioTrackImpl::set_state(TrackState new_state) {
|
||||
|
||||
scoped_refptr<AudioTrack> AudioTrackImpl::Create(
|
||||
const std::string& label, uint32 ssrc) {
|
||||
RefCountImpl<AudioTrackImpl>* track =
|
||||
new RefCountImpl<AudioTrackImpl>(label, ssrc);
|
||||
talk_base::RefCountImpl<AudioTrackImpl>* track =
|
||||
new talk_base::RefCountImpl<AudioTrackImpl>(label, ssrc);
|
||||
return track;
|
||||
}
|
||||
|
||||
scoped_refptr<LocalAudioTrack> CreateLocalAudioTrack(
|
||||
const std::string& label,
|
||||
AudioDeviceModule* audio_device) {
|
||||
RefCountImpl<AudioTrackImpl>* track =
|
||||
new RefCountImpl<AudioTrackImpl>(label, audio_device);
|
||||
talk_base::RefCountImpl<AudioTrackImpl>* track =
|
||||
new talk_base::RefCountImpl<AudioTrackImpl>(label, audio_device);
|
||||
return track;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -49,14 +49,15 @@ class AudioTrackImpl : public NotifierImpl<LocalAudioTrack> {
|
||||
uint32 ssrc);
|
||||
|
||||
// Get the AudioDeviceModule associated with this track.
|
||||
virtual scoped_refptr<AudioDeviceModule> GetAudioDevice();
|
||||
virtual AudioDeviceModule* GetAudioDevice();
|
||||
|
||||
// Implement MediaStreamTrack
|
||||
virtual const std::string& kind();
|
||||
virtual const std::string& label();
|
||||
virtual uint32 ssrc();
|
||||
virtual TrackState state();
|
||||
virtual bool enabled();
|
||||
virtual const char* kind() const;
|
||||
virtual const std::string& label() const { return label_; }
|
||||
virtual TrackType type() const { return kAudio; }
|
||||
virtual uint32 ssrc() const { return ssrc_; }
|
||||
virtual TrackState state() const { return state_; }
|
||||
virtual bool enabled() const { return enabled_; }
|
||||
virtual bool set_enabled(bool enable);
|
||||
virtual bool set_ssrc(uint32 ssrc);
|
||||
virtual bool set_state(TrackState new_state);
|
||||
@ -67,15 +68,12 @@ class AudioTrackImpl : public NotifierImpl<LocalAudioTrack> {
|
||||
|
||||
private:
|
||||
bool enabled_;
|
||||
std::string kind_;
|
||||
std::string label_;
|
||||
uint32 ssrc_;
|
||||
TrackState state_;
|
||||
scoped_refptr<AudioDeviceModule> audio_device_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // TALK_APP_WEBRTC_AUDIOTRACKIMPL_H_
|
||||
|
@ -44,9 +44,6 @@ namespace webrtc {
|
||||
class AudioDeviceModule;
|
||||
class VideoCaptureModule;
|
||||
|
||||
const char kVideoTrackKind[] = "video";
|
||||
const char kAudioTrackKind[] = "audio";
|
||||
|
||||
// Generic observer interface.
|
||||
class Observer {
|
||||
public:
|
||||
@ -63,7 +60,7 @@ class Notifier {
|
||||
};
|
||||
|
||||
// Information about a track.
|
||||
class MediaStreamTrack : public RefCount,
|
||||
class MediaStreamTrack : public talk_base::RefCount,
|
||||
public Notifier {
|
||||
public:
|
||||
enum TrackState {
|
||||
@ -73,11 +70,17 @@ class MediaStreamTrack : public RefCount,
|
||||
kFailed = 3, // Track negotiation failed.
|
||||
};
|
||||
|
||||
virtual const std::string& kind() = 0;
|
||||
virtual const std::string& label() = 0;
|
||||
virtual uint32 ssrc() = 0;
|
||||
virtual bool enabled() = 0;
|
||||
virtual TrackState state() = 0;
|
||||
enum TrackType {
|
||||
kAudio = 0,
|
||||
kVideo = 1,
|
||||
};
|
||||
|
||||
virtual const char* kind() const = 0;
|
||||
virtual const std::string& label() const = 0;
|
||||
virtual TrackType type() const = 0;
|
||||
virtual uint32 ssrc() const = 0;
|
||||
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.
|
||||
virtual bool set_ssrc(uint32 ssrc) = 0;
|
||||
@ -85,7 +88,7 @@ class MediaStreamTrack : public RefCount,
|
||||
};
|
||||
|
||||
// Reference counted wrapper for a VideoRenderer.
|
||||
class VideoRenderer : public RefCount {
|
||||
class VideoRenderer : public talk_base::RefCount {
|
||||
public:
|
||||
virtual cricket::VideoRenderer* renderer() = 0;
|
||||
|
||||
@ -105,7 +108,7 @@ class VideoTrack : public MediaStreamTrack {
|
||||
virtual void SetRenderer(VideoRenderer* renderer) = 0;
|
||||
|
||||
// Get the VideoRenderer associated with this track.
|
||||
virtual scoped_refptr<VideoRenderer> GetRenderer() = 0;
|
||||
virtual VideoRenderer* GetRenderer() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~VideoTrack() {}
|
||||
@ -114,7 +117,7 @@ class VideoTrack : public MediaStreamTrack {
|
||||
class LocalVideoTrack : public VideoTrack {
|
||||
public:
|
||||
// Get the VideoCapture device associated with this track.
|
||||
virtual scoped_refptr<VideoCaptureModule> GetVideoCapture() = 0;
|
||||
virtual VideoCaptureModule* GetVideoCapture() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~LocalVideoTrack() {}
|
||||
@ -133,7 +136,7 @@ class AudioTrack : public MediaStreamTrack {
|
||||
class LocalAudioTrack : public AudioTrack {
|
||||
public:
|
||||
// Get the AudioDeviceModule associated with this track.
|
||||
virtual scoped_refptr<AudioDeviceModule> GetAudioDevice() = 0;
|
||||
virtual AudioDeviceModule* GetAudioDevice() = 0;
|
||||
protected:
|
||||
virtual ~LocalAudioTrack() {}
|
||||
};
|
||||
@ -143,20 +146,21 @@ scoped_refptr<LocalAudioTrack> CreateLocalAudioTrack(
|
||||
AudioDeviceModule* audio_device);
|
||||
|
||||
// List of of tracks.
|
||||
class MediaStreamTrackList : public RefCount, public Notifier {
|
||||
class MediaStreamTrackList : public talk_base::RefCount,
|
||||
public Notifier {
|
||||
public:
|
||||
virtual size_t count() = 0;
|
||||
virtual scoped_refptr<MediaStreamTrack> at(size_t index) = 0;
|
||||
virtual MediaStreamTrack* at(size_t index) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~MediaStreamTrackList() {}
|
||||
};
|
||||
|
||||
class MediaStream : public RefCount,
|
||||
class MediaStream : public talk_base::RefCount,
|
||||
public Notifier {
|
||||
public:
|
||||
virtual const std::string& label() = 0;
|
||||
virtual scoped_refptr<MediaStreamTrackList> tracks() = 0;
|
||||
virtual MediaStreamTrackList* tracks() = 0;
|
||||
|
||||
enum ReadyState {
|
||||
kInitializing,
|
||||
|
@ -50,7 +50,6 @@ typedef talk_base::TypedMessageData<bool> TrackEnabledMessageData;
|
||||
VideoTrackHandler::VideoTrackHandler(VideoTrack* track,
|
||||
MediaProviderInterface* provider)
|
||||
: provider_(provider),
|
||||
video_track_(track),
|
||||
state_(track->state()),
|
||||
enabled_(track->enabled()),
|
||||
renderer_(track->GetRenderer()),
|
||||
@ -68,7 +67,7 @@ void VideoTrackHandler::OnChanged() {
|
||||
TrackStateMessageData* state_param(new TrackStateMessageData(state_));
|
||||
signaling_thread_->Post(this, MSG_TRACK_STATECHANGED, state_param);
|
||||
}
|
||||
if (renderer_.get() != video_track_->GetRenderer().get()) {
|
||||
if (renderer_.get() != video_track_->GetRenderer()) {
|
||||
renderer_ = video_track_->GetRenderer();
|
||||
signaling_thread_->Post(this, MSG_TRACK_RENDERERCHANGED);
|
||||
}
|
||||
@ -103,14 +102,15 @@ void VideoTrackHandler::OnMessage(talk_base::Message* msg) {
|
||||
}
|
||||
|
||||
LocalVideoTrackHandler::LocalVideoTrackHandler(
|
||||
VideoTrack* track,
|
||||
LocalVideoTrack* track,
|
||||
MediaProviderInterface* provider)
|
||||
: VideoTrackHandler(track, provider) {
|
||||
: VideoTrackHandler(track, provider),
|
||||
local_video_track_(track) {
|
||||
}
|
||||
|
||||
void LocalVideoTrackHandler::OnRendererChanged() {
|
||||
scoped_refptr<VideoRenderer> renderer(video_track_->GetRenderer());
|
||||
if (renderer.get())
|
||||
VideoRenderer* renderer(video_track_->GetRenderer());
|
||||
if (renderer)
|
||||
provider_->SetLocalRenderer(video_track_->ssrc(), renderer->renderer());
|
||||
else
|
||||
provider_->SetLocalRenderer(video_track_->ssrc(), NULL);
|
||||
@ -118,11 +118,11 @@ void LocalVideoTrackHandler::OnRendererChanged() {
|
||||
|
||||
void LocalVideoTrackHandler::OnStateChanged(
|
||||
MediaStreamTrack::TrackState state) {
|
||||
LocalVideoTrack* track = static_cast<LocalVideoTrack*>(video_track_.get());
|
||||
if (state == VideoTrack::kLive) {
|
||||
provider_->SetCaptureDevice(track->ssrc(), track->GetVideoCapture());
|
||||
scoped_refptr<VideoRenderer> renderer(video_track_->GetRenderer());
|
||||
if (renderer.get())
|
||||
provider_->SetCaptureDevice(local_video_track_->ssrc(),
|
||||
local_video_track_->GetVideoCapture());
|
||||
VideoRenderer* renderer(video_track_->GetRenderer());
|
||||
if (renderer)
|
||||
provider_->SetLocalRenderer(video_track_->ssrc(), renderer->renderer());
|
||||
else
|
||||
provider_->SetLocalRenderer(video_track_->ssrc(), NULL);
|
||||
@ -136,12 +136,13 @@ void LocalVideoTrackHandler::OnEnabledChanged(bool enabled) {
|
||||
RemoteVideoTrackHandler::RemoteVideoTrackHandler(
|
||||
VideoTrack* track,
|
||||
MediaProviderInterface* provider)
|
||||
: VideoTrackHandler(track, provider) {
|
||||
: VideoTrackHandler(track, provider),
|
||||
remote_video_track_(track) {
|
||||
}
|
||||
|
||||
void RemoteVideoTrackHandler::OnRendererChanged() {
|
||||
scoped_refptr<VideoRenderer> renderer(video_track_->GetRenderer());
|
||||
if (renderer.get())
|
||||
VideoRenderer* renderer(video_track_->GetRenderer());
|
||||
if (renderer)
|
||||
provider_->SetRemoteRenderer(video_track_->ssrc(), renderer->renderer());
|
||||
else
|
||||
provider_->SetRemoteRenderer(video_track_->ssrc(), NULL);
|
||||
@ -181,13 +182,13 @@ LocalMediaStreamHandler::LocalMediaStreamHandler(
|
||||
MediaStream* stream,
|
||||
MediaProviderInterface* provider)
|
||||
: MediaStreamHandler(stream, provider) {
|
||||
scoped_refptr<MediaStreamTrackList> tracklist(stream->tracks());
|
||||
MediaStreamTrackList* tracklist(stream->tracks());
|
||||
|
||||
for (size_t j = 0; j < tracklist->count(); ++j) {
|
||||
scoped_refptr<MediaStreamTrack> track = tracklist->at(j);
|
||||
if (track->kind().compare(kVideoTrackKind) == 0) {
|
||||
MediaStreamTrack* track = tracklist->at(j);
|
||||
if (track->type() == MediaStreamTrack::kVideo) {
|
||||
LocalVideoTrack* video_track =
|
||||
static_cast<LocalVideoTrack*> (track.get());
|
||||
static_cast<LocalVideoTrack*>(track);
|
||||
VideoTrackHandler* handler(new LocalVideoTrackHandler(video_track,
|
||||
provider));
|
||||
video_handlers_.push_back(handler);
|
||||
@ -199,12 +200,12 @@ RemoteMediaStreamHandler::RemoteMediaStreamHandler(
|
||||
MediaStream* stream,
|
||||
MediaProviderInterface* provider)
|
||||
: MediaStreamHandler(stream, provider) {
|
||||
scoped_refptr<MediaStreamTrackList> tracklist(stream->tracks());
|
||||
MediaStreamTrackList* tracklist(stream->tracks());
|
||||
|
||||
for (size_t j = 0; j < tracklist->count(); ++j) {
|
||||
scoped_refptr<MediaStreamTrack> track = tracklist->at(j);
|
||||
if (track->kind().compare(kVideoTrackKind) == 0) {
|
||||
VideoTrack* video_track = static_cast<VideoTrack*> (track.get());
|
||||
MediaStreamTrack* track = tracklist->at(j);
|
||||
if (track->type() == MediaStreamTrack::kVideo) {
|
||||
VideoTrack* video_track = static_cast<VideoTrack*>(track);
|
||||
VideoTrackHandler* handler(new RemoteVideoTrackHandler(video_track,
|
||||
provider));
|
||||
video_handlers_.push_back(handler);
|
||||
@ -268,10 +269,10 @@ void MediaStreamHandlers::CommitLocalStreams(StreamCollection* streams) {
|
||||
// Iterate the new collection of local streams.
|
||||
// If its not found in the old collection it have been added.
|
||||
for (size_t j = 0; j < streams->count(); ++j) {
|
||||
scoped_refptr<MediaStream> stream = streams->at(j);
|
||||
MediaStream* stream = streams->at(j);
|
||||
StreamHandlerList::iterator it = local_streams_handlers_.begin();
|
||||
for (; it != local_streams_handlers_.end(); ++it) {
|
||||
if (stream.get() == (*it)->stream())
|
||||
if (stream == (*it)->stream())
|
||||
break;
|
||||
}
|
||||
if (it == local_streams_handlers_.end()) {
|
||||
|
@ -61,7 +61,7 @@ class VideoTrackHandler : public Observer,
|
||||
virtual void OnEnabledChanged(bool enabled) = 0;
|
||||
|
||||
MediaProviderInterface* provider_;
|
||||
scoped_refptr<VideoTrack> video_track_;
|
||||
VideoTrack* video_track_; // a weak reference of Local or Remote handler.
|
||||
|
||||
private:
|
||||
MediaStreamTrack::TrackState state_;
|
||||
@ -72,13 +72,16 @@ class VideoTrackHandler : public Observer,
|
||||
|
||||
class LocalVideoTrackHandler : public VideoTrackHandler {
|
||||
public:
|
||||
LocalVideoTrackHandler(VideoTrack* track,
|
||||
LocalVideoTrackHandler(LocalVideoTrack* track,
|
||||
MediaProviderInterface* provider);
|
||||
|
||||
protected:
|
||||
virtual void OnRendererChanged();
|
||||
virtual void OnStateChanged(MediaStreamTrack::TrackState state);
|
||||
virtual void OnEnabledChanged(bool enabled);
|
||||
|
||||
private:
|
||||
scoped_refptr<LocalVideoTrack> local_video_track_;
|
||||
};
|
||||
|
||||
class RemoteVideoTrackHandler : public VideoTrackHandler {
|
||||
@ -90,6 +93,9 @@ class RemoteVideoTrackHandler : public VideoTrackHandler {
|
||||
virtual void OnRendererChanged();
|
||||
virtual void OnStateChanged(MediaStreamTrack::TrackState state);
|
||||
virtual void OnEnabledChanged(bool enabled);
|
||||
|
||||
private:
|
||||
scoped_refptr<VideoTrack> remote_video_track_;
|
||||
};
|
||||
|
||||
class MediaStreamHandler : public Observer {
|
||||
|
@ -35,32 +35,22 @@ scoped_refptr<LocalMediaStream> CreateLocalMediaStream(
|
||||
|
||||
scoped_refptr<MediaStreamImpl> MediaStreamImpl::Create(
|
||||
const std::string& label) {
|
||||
RefCountImpl<MediaStreamImpl>* stream =
|
||||
new RefCountImpl<MediaStreamImpl>(label);
|
||||
talk_base::RefCountImpl<MediaStreamImpl>* stream =
|
||||
new talk_base::RefCountImpl<MediaStreamImpl>(label);
|
||||
return stream;
|
||||
}
|
||||
|
||||
MediaStreamImpl::MediaStreamImpl(const std::string& label)
|
||||
: label_(label),
|
||||
ready_state_(MediaStream::kInitializing),
|
||||
track_list_(new RefCountImpl<MediaStreamTrackListImpl>()) {
|
||||
}
|
||||
|
||||
const std::string& MediaStreamImpl::label() {
|
||||
return label_;
|
||||
}
|
||||
|
||||
scoped_refptr<MediaStreamTrackList> MediaStreamImpl::tracks() {
|
||||
return track_list_;
|
||||
}
|
||||
|
||||
MediaStream::ReadyState MediaStreamImpl::ready_state() {
|
||||
return ready_state_;
|
||||
track_list_(new talk_base::RefCountImpl<MediaStreamTrackListImpl>()) {
|
||||
}
|
||||
|
||||
void MediaStreamImpl::set_ready_state(MediaStream::ReadyState new_state) {
|
||||
ready_state_ = new_state;
|
||||
NotifierImpl<LocalMediaStream>::FireOnChanged();
|
||||
if (ready_state_ != new_state) {
|
||||
ready_state_ = new_state;
|
||||
NotifierImpl<LocalMediaStream>::FireOnChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool MediaStreamImpl::AddTrack(MediaStreamTrack* track) {
|
||||
@ -77,13 +67,4 @@ void MediaStreamImpl::MediaStreamTrackListImpl::AddTrack(
|
||||
NotifierImpl<MediaStreamTrackList>::FireOnChanged();
|
||||
}
|
||||
|
||||
size_t MediaStreamImpl::MediaStreamTrackListImpl::count() {
|
||||
return tracks_.size();
|
||||
}
|
||||
|
||||
scoped_refptr<MediaStreamTrack> MediaStreamImpl::MediaStreamTrackListImpl::at(
|
||||
size_t index) {
|
||||
return tracks_.at(index);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -42,8 +42,10 @@ class MediaStreamImpl
|
||||
class MediaStreamTrackListImpl : public NotifierImpl<MediaStreamTrackList> {
|
||||
public:
|
||||
void AddTrack(MediaStreamTrack* track);
|
||||
virtual size_t count();
|
||||
virtual scoped_refptr<MediaStreamTrack> at(size_t index);
|
||||
virtual size_t count() { return tracks_.size(); }
|
||||
virtual MediaStreamTrack* at(size_t index) {
|
||||
return tracks_.at(index);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<scoped_refptr<MediaStreamTrack> > tracks_;
|
||||
@ -55,9 +57,9 @@ class MediaStreamImpl
|
||||
virtual bool AddTrack(MediaStreamTrack* track);
|
||||
|
||||
// Implement MediaStream.
|
||||
virtual const std::string& label();
|
||||
virtual scoped_refptr<MediaStreamTrackList> tracks();
|
||||
virtual ReadyState ready_state();
|
||||
virtual const std::string& label() { return label_; }
|
||||
virtual MediaStreamTrackList* tracks() { return track_list_; }
|
||||
virtual ReadyState ready_state() { return ready_state_; }
|
||||
virtual void set_ready_state(ReadyState new_state);
|
||||
void set_state(ReadyState new_state);
|
||||
|
||||
|
@ -42,9 +42,12 @@ class TestObserver : public Observer {
|
||||
void OnChanged() {
|
||||
++changed_;
|
||||
}
|
||||
int NoChanged() {
|
||||
int NumChanges() {
|
||||
return changed_;
|
||||
}
|
||||
void Reset() {
|
||||
changed_ = 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
int changed_;
|
||||
@ -55,35 +58,28 @@ TEST(LocalStreamTest, Create) {
|
||||
std::string label(kStreamLabel1);
|
||||
scoped_refptr<LocalMediaStream> stream(MediaStreamImpl::Create(label));
|
||||
|
||||
EXPECT_EQ(stream->label().compare(label), 0);
|
||||
EXPECT_EQ(label, stream->label());
|
||||
// Check state.
|
||||
EXPECT_EQ(stream->ready_state(), MediaStream::kInitializing);
|
||||
EXPECT_EQ(MediaStream::kInitializing, stream->ready_state());
|
||||
|
||||
// Create a local Video track.
|
||||
{
|
||||
TestObserver tracklist_observer;
|
||||
|
||||
scoped_refptr<LocalVideoTrack> video_track(CreateLocalVideoTrack(
|
||||
kVideoDeviceName, NULL));
|
||||
|
||||
// Add an observer to the track list.
|
||||
scoped_refptr<MediaStreamTrackList> track_list(stream->tracks());
|
||||
stream->tracks()->RegisterObserver(&tracklist_observer);
|
||||
|
||||
// Add the track to the local stream.
|
||||
EXPECT_TRUE(stream->AddTrack(video_track));
|
||||
|
||||
// Verify that the track list observer have been notified
|
||||
// that the track have been added.
|
||||
EXPECT_EQ(tracklist_observer.NoChanged(), 1);
|
||||
}
|
||||
|
||||
EXPECT_EQ(stream->tracks()->count(), 1u);
|
||||
TestObserver tracklist_observer;
|
||||
scoped_refptr<LocalVideoTrack> video_track(CreateLocalVideoTrack(
|
||||
kVideoDeviceName, NULL));
|
||||
// Add an observer to the track list.
|
||||
scoped_refptr<MediaStreamTrackList> track_list(stream->tracks());
|
||||
stream->tracks()->RegisterObserver(&tracklist_observer);
|
||||
// Add the track to the local stream.
|
||||
EXPECT_TRUE(stream->AddTrack(video_track));
|
||||
// Verify that the track list observer have been notified
|
||||
// that the track have been added.
|
||||
EXPECT_EQ(1u, tracklist_observer.NumChanges());
|
||||
EXPECT_EQ(1u, stream->tracks()->count());
|
||||
|
||||
// Verify the track.
|
||||
scoped_refptr<webrtc::MediaStreamTrack> track(stream->tracks()->at(0));
|
||||
EXPECT_EQ(track->kind().compare(kVideoTrackKind), 0);
|
||||
EXPECT_EQ(track->label().compare(kVideoDeviceName), 0);
|
||||
EXPECT_EQ(MediaStreamTrack::kVideo, track->type());
|
||||
EXPECT_EQ(0, track->label().compare(kVideoDeviceName));
|
||||
EXPECT_TRUE(track->enabled());
|
||||
|
||||
// Verify the Track observer.
|
||||
@ -92,8 +88,8 @@ TEST(LocalStreamTest, Create) {
|
||||
track->RegisterObserver(&observer1);
|
||||
track->RegisterObserver(&observer2);
|
||||
track->set_enabled(false);
|
||||
EXPECT_EQ(observer1.NoChanged(), 1);
|
||||
EXPECT_EQ(observer2.NoChanged(), 1);
|
||||
EXPECT_EQ(1u, observer1.NumChanges());
|
||||
EXPECT_EQ(1u, observer2.NumChanges());
|
||||
EXPECT_FALSE(track->enabled());
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace talk_base {
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class StreamCollection : public RefCount {
|
||||
class StreamCollection : public talk_base::RefCount {
|
||||
public:
|
||||
virtual size_t count() = 0;
|
||||
virtual MediaStream* at(size_t index) = 0;
|
||||
@ -79,7 +79,7 @@ class PeerConnectionObserver {
|
||||
};
|
||||
|
||||
|
||||
class PeerConnection : public RefCount {
|
||||
class PeerConnection : public talk_base::RefCount {
|
||||
public:
|
||||
// SignalingMessage in json format
|
||||
virtual bool ProcessSignalingMessage(const std::string& msg) = 0;
|
||||
@ -113,7 +113,7 @@ class PeerConnection : public RefCount {
|
||||
};
|
||||
|
||||
// Reference counted wrapper for talk_base::NetworkManager.
|
||||
class PcNetworkManager : public RefCount {
|
||||
class PcNetworkManager : public talk_base::RefCount {
|
||||
public:
|
||||
static scoped_refptr<PcNetworkManager> Create(
|
||||
talk_base::NetworkManager* network_manager);
|
||||
@ -127,7 +127,7 @@ class PcNetworkManager : public RefCount {
|
||||
};
|
||||
|
||||
// Reference counted wrapper for talk_base::PacketSocketFactory.
|
||||
class PcPacketSocketFactory : public RefCount {
|
||||
class PcPacketSocketFactory : public talk_base::RefCount {
|
||||
public:
|
||||
static scoped_refptr<PcPacketSocketFactory> Create(
|
||||
talk_base::PacketSocketFactory* socket_factory);
|
||||
@ -141,7 +141,7 @@ class PcPacketSocketFactory : public RefCount {
|
||||
talk_base::PacketSocketFactory* socket_factory_;
|
||||
};
|
||||
|
||||
class PeerConnectionManager : public RefCount {
|
||||
class PeerConnectionManager : public talk_base::RefCount {
|
||||
public:
|
||||
// Create a new instance of PeerConnectionManager.
|
||||
static scoped_refptr<PeerConnectionManager> Create();
|
||||
|
@ -65,8 +65,8 @@ namespace webrtc {
|
||||
|
||||
scoped_refptr<PcNetworkManager> PcNetworkManager::Create(
|
||||
talk_base::NetworkManager* network_manager) {
|
||||
RefCountImpl<PcNetworkManager>* implementation =
|
||||
new RefCountImpl<PcNetworkManager>(network_manager);
|
||||
talk_base::RefCountImpl<PcNetworkManager>* implementation =
|
||||
new talk_base::RefCountImpl<PcNetworkManager>(network_manager);
|
||||
return implementation;
|
||||
}
|
||||
|
||||
@ -84,8 +84,8 @@ PcNetworkManager::~PcNetworkManager() {
|
||||
|
||||
scoped_refptr<PcPacketSocketFactory> PcPacketSocketFactory::Create(
|
||||
talk_base::PacketSocketFactory* socket_factory) {
|
||||
RefCountImpl<PcPacketSocketFactory>* implementation =
|
||||
new RefCountImpl<PcPacketSocketFactory>(socket_factory);
|
||||
talk_base::RefCountImpl<PcPacketSocketFactory>* implementation =
|
||||
new talk_base::RefCountImpl<PcPacketSocketFactory>(socket_factory);
|
||||
return implementation;
|
||||
}
|
||||
|
||||
@ -103,8 +103,8 @@ talk_base::PacketSocketFactory* PcPacketSocketFactory::socket_factory() const {
|
||||
}
|
||||
|
||||
scoped_refptr<PeerConnectionManager> PeerConnectionManager::Create() {
|
||||
RefCountImpl<PeerConnectionManagerImpl>* pc_manager =
|
||||
new RefCountImpl<PeerConnectionManagerImpl>();
|
||||
talk_base::RefCountImpl<PeerConnectionManagerImpl>* pc_manager =
|
||||
new talk_base::RefCountImpl<PeerConnectionManagerImpl>();
|
||||
|
||||
if (!pc_manager->Initialize()) {
|
||||
delete pc_manager;
|
||||
@ -119,12 +119,12 @@ scoped_refptr<PeerConnectionManager> PeerConnectionManager::Create(
|
||||
PcNetworkManager* network_manager,
|
||||
PcPacketSocketFactory* socket_factory,
|
||||
AudioDeviceModule* default_adm) {
|
||||
RefCountImpl<PeerConnectionManagerImpl>* pc_manager =
|
||||
new RefCountImpl<PeerConnectionManagerImpl>(worker_thread,
|
||||
signaling_thread,
|
||||
network_manager,
|
||||
socket_factory,
|
||||
default_adm);
|
||||
talk_base::RefCountImpl<PeerConnectionManagerImpl>* pc_manager =
|
||||
new talk_base::RefCountImpl<PeerConnectionManagerImpl>(worker_thread,
|
||||
signaling_thread,
|
||||
network_manager,
|
||||
socket_factory,
|
||||
default_adm);
|
||||
if (!pc_manager->Initialize()) {
|
||||
delete pc_manager;
|
||||
pc_manager = NULL;
|
||||
@ -222,12 +222,12 @@ scoped_refptr<PeerConnection> PeerConnectionManagerImpl::CreatePeerConnection(
|
||||
scoped_refptr<PeerConnection> PeerConnectionManagerImpl::CreatePeerConnection_s(
|
||||
const std::string& configuration,
|
||||
PeerConnectionObserver* observer) {
|
||||
RefCountImpl<PeerConnectionImpl>* pc(
|
||||
new RefCountImpl<PeerConnectionImpl>(channel_manager_.get(),
|
||||
signaling_thread_ptr_,
|
||||
worker_thread_ptr_,
|
||||
network_manager_,
|
||||
socket_factory_));
|
||||
talk_base::RefCountImpl<PeerConnectionImpl>* pc(
|
||||
new talk_base::RefCountImpl<PeerConnectionImpl>(channel_manager_.get(),
|
||||
signaling_thread_ptr_,
|
||||
worker_thread_ptr_,
|
||||
network_manager_,
|
||||
socket_factory_));
|
||||
if (!pc->Initialize(configuration, observer)) {
|
||||
delete pc;
|
||||
pc = NULL;
|
||||
|
@ -303,7 +303,7 @@ void PeerConnectionSignaling::InitMediaSessionOptions(
|
||||
// For each track in the stream, add it to the MediaSessionOptions.
|
||||
for (size_t j = 0; j < tracks->count(); ++j) {
|
||||
scoped_refptr<MediaStreamTrack> track = tracks->at(j);
|
||||
if (track->kind().compare(kAudioTrackKind) == 0) {
|
||||
if (MediaStreamTrack::kAudio == track->type()) {
|
||||
// TODO(perkj): Better ssrc?
|
||||
// Does talk_base::CreateRandomNonZeroId() generate unique id?
|
||||
if (track->ssrc() == 0)
|
||||
@ -312,7 +312,7 @@ void PeerConnectionSignaling::InitMediaSessionOptions(
|
||||
track->label(),
|
||||
stream->label()));
|
||||
}
|
||||
if (track->kind().compare(kVideoTrackKind) == 0) {
|
||||
if (MediaStreamTrack::kVideo == track->type()) {
|
||||
if (track->ssrc() == 0)
|
||||
track->set_ssrc(++ssrc_counter_); // TODO(perkj): Better ssrc?
|
||||
options->video_sources.push_back(cricket::SourceParam(track->ssrc(),
|
||||
@ -456,7 +456,7 @@ void PeerConnectionSignaling::UpdateSendingLocalStreams(
|
||||
|
||||
for (size_t j = 0; j < tracklist->count(); ++j) {
|
||||
scoped_refptr<MediaStreamTrack> track = tracklist->at(j);
|
||||
if (track->kind().compare(kAudioTrackKind) == 0) {
|
||||
if (MediaStreamTrack::kAudio == track->type()) {
|
||||
const cricket::ContentInfo* audio_content =
|
||||
GetFirstAudioContent(answer_desc);
|
||||
|
||||
@ -475,7 +475,7 @@ void PeerConnectionSignaling::UpdateSendingLocalStreams(
|
||||
track->set_state(MediaStreamTrack::kLive);
|
||||
stream_ok = true;
|
||||
}
|
||||
if (track->kind().compare(kVideoTrackKind) == 0) {
|
||||
if (MediaStreamTrack::kVideo == track->type()) {
|
||||
const cricket::ContentInfo* video_content =
|
||||
GetFirstVideoContent(answer_desc);
|
||||
|
||||
|
@ -30,11 +30,15 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "talk/base/criticalsection.h"
|
||||
|
||||
namespace talk_base {
|
||||
|
||||
// Reference count interface.
|
||||
class RefCount {
|
||||
public:
|
||||
virtual size_t AddRef() = 0;
|
||||
virtual size_t Release() = 0;
|
||||
virtual int AddRef() = 0;
|
||||
virtual int Release() = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
@ -64,21 +68,22 @@ class RefCountImpl : public T {
|
||||
: ref_count_(0), T(p1, p2, p3, p4, p5) {
|
||||
}
|
||||
|
||||
virtual size_t AddRef() {
|
||||
++ref_count_;
|
||||
return ref_count_;
|
||||
virtual int AddRef() {
|
||||
return talk_base::AtomicOps::Increment(&ref_count_);
|
||||
}
|
||||
|
||||
virtual size_t Release() {
|
||||
size_t ret = --ref_count_;
|
||||
if (!ref_count_) {
|
||||
virtual int Release() {
|
||||
int count = talk_base::AtomicOps::Decrement(&ref_count_);
|
||||
if (!count) {
|
||||
delete this;
|
||||
}
|
||||
return ret;
|
||||
return count;
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t ref_count_;
|
||||
int ref_count_;
|
||||
};
|
||||
|
||||
} // namespace talk_base
|
||||
|
||||
#endif // TALK_APP_WEBRTC_REF_COUNT_H_
|
||||
|
@ -39,15 +39,15 @@ namespace webrtc {
|
||||
class StreamCollectionImpl : public StreamCollection {
|
||||
public:
|
||||
static scoped_refptr<StreamCollectionImpl> Create() {
|
||||
RefCountImpl<StreamCollectionImpl>* implementation =
|
||||
new RefCountImpl<StreamCollectionImpl>();
|
||||
talk_base::RefCountImpl<StreamCollectionImpl>* implementation =
|
||||
new talk_base::RefCountImpl<StreamCollectionImpl>();
|
||||
return implementation;
|
||||
}
|
||||
|
||||
static scoped_refptr<StreamCollectionImpl> Create(
|
||||
StreamCollectionImpl* streams) {
|
||||
RefCountImpl<StreamCollectionImpl>* implementation =
|
||||
new RefCountImpl<StreamCollectionImpl>(streams);
|
||||
talk_base::RefCountImpl<StreamCollectionImpl>* implementation =
|
||||
new talk_base::RefCountImpl<StreamCollectionImpl>(streams);
|
||||
return implementation;
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,8 @@ class VideoRendererImpl : public VideoRenderer {
|
||||
|
||||
scoped_refptr<VideoRenderer> CreateVideoRenderer(
|
||||
cricket::VideoRenderer* renderer) {
|
||||
RefCountImpl<VideoRendererImpl>* r =
|
||||
new RefCountImpl<VideoRendererImpl>(renderer);
|
||||
talk_base::RefCountImpl<VideoRendererImpl>* r =
|
||||
new talk_base::RefCountImpl<VideoRendererImpl>(renderer);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,10 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
static const char kVideoTrackKind[] = "video";
|
||||
|
||||
VideoTrackImpl::VideoTrackImpl(const std::string& label, uint32 ssrc)
|
||||
: enabled_(true),
|
||||
kind_(kVideoTrackKind),
|
||||
label_(label),
|
||||
ssrc_(ssrc),
|
||||
state_(kInitializing),
|
||||
@ -42,7 +43,6 @@ VideoTrackImpl::VideoTrackImpl(const std::string& label, uint32 ssrc)
|
||||
VideoTrackImpl::VideoTrackImpl(const std::string& label,
|
||||
VideoCaptureModule* video_device)
|
||||
: enabled_(true),
|
||||
kind_(kVideoTrackKind),
|
||||
label_(label),
|
||||
ssrc_(0),
|
||||
state_(kInitializing),
|
||||
@ -54,25 +54,17 @@ void VideoTrackImpl::SetRenderer(VideoRenderer* renderer) {
|
||||
NotifierImpl<LocalVideoTrack>::FireOnChanged();
|
||||
}
|
||||
|
||||
scoped_refptr<VideoRenderer> VideoTrackImpl::GetRenderer() {
|
||||
return video_renderer_;
|
||||
VideoRenderer* VideoTrackImpl::GetRenderer() {
|
||||
return video_renderer_.get();
|
||||
}
|
||||
|
||||
// Get the VideoCapture device associated with this track.
|
||||
scoped_refptr<VideoCaptureModule> VideoTrackImpl::GetVideoCapture() {
|
||||
VideoCaptureModule* VideoTrackImpl::GetVideoCapture() {
|
||||
return video_device_.get();
|
||||
}
|
||||
|
||||
const std::string& VideoTrackImpl::kind() {
|
||||
return kind_;
|
||||
}
|
||||
|
||||
const std::string& VideoTrackImpl::label() {
|
||||
return label_;
|
||||
}
|
||||
|
||||
bool VideoTrackImpl::enabled() {
|
||||
return enabled_;
|
||||
const char* VideoTrackImpl::kind() const {
|
||||
return kVideoTrackKind;
|
||||
}
|
||||
|
||||
bool VideoTrackImpl::set_enabled(bool enable) {
|
||||
@ -82,10 +74,6 @@ bool VideoTrackImpl::set_enabled(bool enable) {
|
||||
NotifierImpl<LocalVideoTrack>::FireOnChanged();
|
||||
}
|
||||
|
||||
uint32 VideoTrackImpl::ssrc() {
|
||||
return ssrc_;
|
||||
}
|
||||
|
||||
bool VideoTrackImpl::set_ssrc(uint32 ssrc) {
|
||||
ASSERT(ssrc_ == 0);
|
||||
ASSERT(ssrc != 0);
|
||||
@ -96,10 +84,6 @@ bool VideoTrackImpl::set_ssrc(uint32 ssrc) {
|
||||
return true;
|
||||
}
|
||||
|
||||
MediaStreamTrack::TrackState VideoTrackImpl::state() {
|
||||
return state_;
|
||||
}
|
||||
|
||||
bool VideoTrackImpl::set_state(TrackState new_state) {
|
||||
bool fire_on_change = state_ != new_state;
|
||||
state_ = new_state;
|
||||
@ -109,17 +93,17 @@ bool VideoTrackImpl::set_state(TrackState new_state) {
|
||||
}
|
||||
|
||||
scoped_refptr<VideoTrack> VideoTrackImpl::Create(const std::string& label,
|
||||
uint32 ssrc) {
|
||||
RefCountImpl<VideoTrackImpl>* track =
|
||||
new RefCountImpl<VideoTrackImpl>(label, ssrc);
|
||||
uint32 ssrc) {
|
||||
talk_base::RefCountImpl<VideoTrackImpl>* track =
|
||||
new talk_base::RefCountImpl<VideoTrackImpl>(label, ssrc);
|
||||
return track;
|
||||
}
|
||||
|
||||
scoped_refptr<LocalVideoTrack> CreateLocalVideoTrack(
|
||||
const std::string& label,
|
||||
VideoCaptureModule* video_device) {
|
||||
RefCountImpl<VideoTrackImpl>* track =
|
||||
new RefCountImpl<VideoTrackImpl>(label, video_device);
|
||||
talk_base::RefCountImpl<VideoTrackImpl>* track =
|
||||
new talk_base::RefCountImpl<VideoTrackImpl>(label, video_device);
|
||||
return track;
|
||||
}
|
||||
|
||||
|
@ -46,15 +46,16 @@ class VideoTrackImpl : public NotifierImpl<LocalVideoTrack> {
|
||||
public:
|
||||
static scoped_refptr<VideoTrack> Create(const std::string& label,
|
||||
uint32 ssrc);
|
||||
virtual scoped_refptr<VideoCaptureModule> GetVideoCapture();
|
||||
virtual VideoCaptureModule* GetVideoCapture();
|
||||
virtual void SetRenderer(VideoRenderer* renderer);
|
||||
scoped_refptr<VideoRenderer> GetRenderer();
|
||||
VideoRenderer* GetRenderer();
|
||||
|
||||
virtual const std::string& kind();
|
||||
virtual const std::string& label();
|
||||
virtual uint32 ssrc();
|
||||
virtual bool enabled();
|
||||
virtual TrackState state();
|
||||
virtual const char* kind() const ;
|
||||
virtual const std::string& label() const { return label_; }
|
||||
virtual TrackType type() const { return kVideo; }
|
||||
virtual uint32 ssrc() const { return ssrc_; }
|
||||
virtual bool enabled() const { return enabled_; }
|
||||
virtual TrackState state() const { return state_; }
|
||||
virtual bool set_enabled(bool enable);
|
||||
virtual bool set_ssrc(uint32 ssrc);
|
||||
virtual bool set_state(TrackState new_state);
|
||||
@ -65,7 +66,6 @@ class VideoTrackImpl : public NotifierImpl<LocalVideoTrack> {
|
||||
|
||||
private:
|
||||
bool enabled_;
|
||||
std::string kind_;
|
||||
std::string label_;
|
||||
uint32 ssrc_;
|
||||
TrackState state_;
|
||||
|
@ -343,9 +343,9 @@ void Conductor::UIThreadCallback(int msg_id, void* data) {
|
||||
scoped_refptr<webrtc::MediaStreamTrackList> tracks =
|
||||
stream->tracks();
|
||||
for (size_t i = 0; i < tracks->count(); ++i) {
|
||||
if (tracks->at(i)->kind().compare(webrtc::kVideoTrackKind) == 0) {
|
||||
if (tracks->at(i)->type() == webrtc::MediaStreamTrack::kVideo) {
|
||||
webrtc::VideoTrack* track =
|
||||
reinterpret_cast<webrtc::VideoTrack*>(tracks->at(i).get());
|
||||
reinterpret_cast<webrtc::VideoTrack*>(tracks->at(i));
|
||||
LOG(INFO) << "Setting video renderer for track: " << track->label();
|
||||
scoped_refptr<webrtc::VideoRenderer> renderer(
|
||||
webrtc::CreateVideoRenderer(main_wnd_->remote_renderer()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user