From 6a34d584b8fcae89f8177fa4ca1c92efc5e3b739 Mon Sep 17 00:00:00 2001 From: "perkj@webrtc.org" Date: Thu, 13 Oct 2011 08:48:43 +0000 Subject: [PATCH] Implement MediaStreamProxy. This implements a proxy for MediaStreams and MediaStreamTracklists. BUG= TEST= Review URL: http://webrtc-codereview.appspot.com/217003 git-svn-id: http://webrtc.googlecode.com/svn/trunk@733 4adac7df-926f-26a2-2b94-8c16560cd09d --- third_party_mods/libjingle/libjingle.gyp | 2 + .../source/talk/app/webrtc_dev/mediastream.h | 8 - .../webrtc_dev/mediastreamhandler_unittest.cc | 6 +- .../webrtc_dev/mediastreamimpl_unittest.cc | 2 +- .../talk/app/webrtc_dev/mediastreamproxy.cc | 267 ++++++++++++++++++ .../talk/app/webrtc_dev/mediastreamproxy.h | 96 +++++++ .../talk/app/webrtc_dev/peerconnection.h | 4 + .../webrtc_dev/peerconnectionimpl_unittest.cc | 3 +- .../webrtc_dev/peerconnectionmanagerimpl.cc | 7 + .../webrtc_dev/peerconnectionmanagerimpl.h | 3 + .../app/webrtc_dev/peerconnectionsignaling.cc | 20 +- .../app/webrtc_dev/peerconnectionsignaling.h | 5 +- .../peerconnectionsignaling_unittest.cc | 10 +- .../peerconnection_client/conductor.cc | 2 +- 14 files changed, 403 insertions(+), 32 deletions(-) create mode 100644 third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamproxy.cc create mode 100644 third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamproxy.h diff --git a/third_party_mods/libjingle/libjingle.gyp b/third_party_mods/libjingle/libjingle.gyp index ea537b793..92926f530 100644 --- a/third_party_mods/libjingle/libjingle.gyp +++ b/third_party_mods/libjingle/libjingle.gyp @@ -692,6 +692,8 @@ '<(libjingle_mods)/source/talk/app/webrtc_dev/mediastreamprovider.h', '<(libjingle_mods)/source/talk/app/webrtc_dev/mediastreamimpl.h', '<(libjingle_mods)/source/talk/app/webrtc_dev/mediastreamimpl.cc', + '<(libjingle_mods)/source/talk/app/webrtc_dev/mediastreamproxy.h', + '<(libjingle_mods)/source/talk/app/webrtc_dev/mediastreamproxy.cc', '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnection.h', '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnectionimpl.cc', '<(libjingle_mods)/source/talk/app/webrtc_dev/peerconnectionimpl.h', diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastream.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastream.h index 6c1a3ea98..23de097e6 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastream.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastream.h @@ -78,11 +78,6 @@ class MediaStreamTrack : public RefCount, virtual uint32 ssrc() = 0; virtual bool enabled() = 0; virtual TrackState state() = 0; - // Enable or disables a track. - // For Remote streams - disable means that the video is not decoded, - // or audio not decoded. - // For local streams this means that video is not captured - // or audio is not captured. virtual bool set_enabled(bool enable) = 0; // Return false (or assert) if the ssrc is already set. virtual bool set_ssrc(uint32 ssrc) = 0; @@ -183,9 +178,6 @@ class LocalMediaStream : public MediaStream { virtual bool AddTrack(MediaStreamTrack* track) = 0; }; -scoped_refptr CreateLocalMediaStream( - const std::string& label); - } // namespace webrtc #endif // TALK_APP_WEBRTC_MEDIASTREAM_H_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamhandler_unittest.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamhandler_unittest.cc index c1bc7eb08..a5751eaa8 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamhandler_unittest.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamhandler_unittest.cc @@ -29,7 +29,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "talk/app/webrtc_dev/mediastream.h" +#include "talk/app/webrtc_dev/mediastreamimpl.h" #include "talk/app/webrtc_dev/mediastreamhandler.h" #include "talk/app/webrtc_dev/streamcollectionimpl.h" #include "talk/base/thread.h" @@ -67,7 +67,7 @@ class MockMediaProvier : public MediaProviderInterface { TEST(MediaStreamHandlerTest, LocalStreams) { // Create a local stream. std::string label(kStreamLabel1); - scoped_refptr stream(CreateLocalMediaStream(label)); + scoped_refptr stream(MediaStreamImpl::Create(label)); scoped_refptr video_track(CreateLocalVideoTrack( kVideoDeviceName, NULL)); video_track->set_ssrc(kVideoSsrc); @@ -105,7 +105,7 @@ TEST(MediaStreamHandlerTest, RemoteStreams) { // they are easier to create. // LocalMediaStreams inherit from MediaStreams. std::string label(kStreamLabel1); - scoped_refptr stream(CreateLocalMediaStream(label)); + scoped_refptr stream(MediaStreamImpl::Create(label)); scoped_refptr video_track(CreateLocalVideoTrack( kVideoDeviceName, NULL)); video_track->set_ssrc(kVideoSsrc); diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamimpl_unittest.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamimpl_unittest.cc index 686147f54..d96a90284 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamimpl_unittest.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamimpl_unittest.cc @@ -53,7 +53,7 @@ class TestObserver : public Observer { TEST(LocalStreamTest, Create) { // Create a local stream. std::string label(kStreamLabel1); - scoped_refptr stream(CreateLocalMediaStream(label)); + scoped_refptr stream(MediaStreamImpl::Create(label)); EXPECT_EQ(stream->label().compare(label), 0); // Check state. diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamproxy.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamproxy.cc new file mode 100644 index 000000000..608646cf5 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamproxy.cc @@ -0,0 +1,267 @@ +/* + * libjingle + * Copyright 2011, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "talk/app/webrtc_dev/mediastreamproxy.h" + +namespace { + +enum { + MSG_REGISTER_OBSERVER = 1, + MSG_UNREGISTER_OBSERVER, + MSG_ADD_TRACK, + MSG_READY_STATE, + MSG_SET_READY_STATE, + MSG_COUNT, + MSG_AT +}; + +typedef talk_base::TypedMessageData SizeTMessageData; +typedef talk_base::TypedMessageData ObserverMessageData; +typedef talk_base::TypedMessageData + ReadyStateMessageData; + + +class MediaStreamTrackMessageData : public talk_base::MessageData { + public: + explicit MediaStreamTrackMessageData(webrtc::MediaStreamTrack* track) + : track_(track), + result_(false) { + } + + scoped_refptr track_; + bool result_; +}; + +class MediaStreamTrackAtMessageData : public talk_base::MessageData { + public: + explicit MediaStreamTrackAtMessageData(size_t index) + : index_(index) { + } + + size_t index_; + scoped_refptr track_; +}; + +} // namespace anonymous + +namespace webrtc { + +scoped_refptr MediaStreamProxy::Create( + const std::string& label, + talk_base::Thread* signaling_thread) { + ASSERT(signaling_thread); + RefCountImpl* stream = + new RefCountImpl(label, signaling_thread); + return stream; +} + +MediaStreamProxy::MediaStreamProxy(const std::string& label, + talk_base::Thread* signaling_thread) + : signaling_thread_(signaling_thread), + media_stream_impl_(MediaStreamImpl::Create(label)), + track_list_(new RefCountImpl( + media_stream_impl_->tracks(), + signaling_thread_)) { +} + +const std::string& MediaStreamProxy::label() { + return media_stream_impl_->label(); +} + +scoped_refptr MediaStreamProxy::tracks() { + return track_list_; +} + +MediaStream::ReadyState MediaStreamProxy::ready_state() { + if (!signaling_thread_->IsCurrent()) { + ReadyStateMessageData msg(MediaStream::kInitializing); + Send(MSG_READY_STATE, &msg); + return msg.data(); + } + return media_stream_impl_->ready_state(); +} + +void MediaStreamProxy::set_ready_state(MediaStream::ReadyState new_state) { + if (!signaling_thread_->IsCurrent()) { + ReadyStateMessageData msg(MediaStream::kInitializing); + Send(MSG_SET_READY_STATE, &msg); + return; + } + media_stream_impl_->set_ready_state(new_state); +} + +bool MediaStreamProxy::AddTrack(MediaStreamTrack* track) { + if (!signaling_thread_->IsCurrent()) { + MediaStreamTrackMessageData msg(track); + Send(MSG_ADD_TRACK, &msg); + return msg.result_; + } + return media_stream_impl_->AddTrack(track); +} + +void MediaStreamProxy::RegisterObserver(Observer* observer) { + if (!signaling_thread_->IsCurrent()) { + ObserverMessageData msg(observer); + Send(MSG_REGISTER_OBSERVER, &msg); + return; + } + media_stream_impl_->RegisterObserver(observer); +} + +void MediaStreamProxy::UnregisterObserver(Observer* observer) { + if (!signaling_thread_->IsCurrent()) { + ObserverMessageData msg(observer); + Send(MSG_UNREGISTER_OBSERVER, &msg); + return; + } + media_stream_impl_->UnregisterObserver(observer); +} + +void MediaStreamProxy::Send(uint32 id, talk_base::MessageData* data) { + signaling_thread_->Send(this, id, data); +} + +// Implement MessageHandler +void MediaStreamProxy::OnMessage(talk_base::Message* msg) { + talk_base::MessageData* data = msg->pdata; + switch (msg->message_id) { + case MSG_REGISTER_OBSERVER: { + ObserverMessageData* observer = static_cast(data); + media_stream_impl_->RegisterObserver(observer->data()); + break; + } + case MSG_UNREGISTER_OBSERVER: { + ObserverMessageData* observer = static_cast(data); + media_stream_impl_->UnregisterObserver(observer->data()); + break; + } + case MSG_ADD_TRACK: { + MediaStreamTrackMessageData * track = + static_cast(data); + track->result_ = media_stream_impl_->AddTrack(track->track_.get()); + break; + } + case MSG_READY_STATE: { + ReadyStateMessageData* state = static_cast(data); + state->data() = media_stream_impl_->ready_state(); + break; + } + case MSG_SET_READY_STATE: { + ReadyStateMessageData* state = static_cast(data); + media_stream_impl_->set_ready_state(state->data()); + break; + } + default: + ASSERT(!"Not Implemented!"); + break; + } +} + +MediaStreamProxy::MediaStreamTrackListProxy::MediaStreamTrackListProxy( + MediaStreamTrackList* track_list, + talk_base::Thread* signaling_thread) + : track_list_(track_list), + signaling_thread_(signaling_thread) { +} + +size_t MediaStreamProxy::MediaStreamTrackListProxy::count() { + if (!signaling_thread_->IsCurrent()) { + SizeTMessageData msg(0u); + Send(MSG_COUNT, &msg); + return msg.data(); + } + return track_list_->count(); +} + +scoped_refptr MediaStreamProxy::MediaStreamTrackListProxy::at( + size_t index) { + if (!signaling_thread_->IsCurrent()) { + MediaStreamTrackAtMessageData msg(index); + Send(MSG_AT, &msg); + return msg.track_; + } + return track_list_->at(index); +} + +void MediaStreamProxy::MediaStreamTrackListProxy::RegisterObserver( + Observer* observer) { + if (!signaling_thread_->IsCurrent()) { + ObserverMessageData msg(observer); + Send(MSG_REGISTER_OBSERVER, &msg); + return; + } + track_list_->RegisterObserver(observer); +} + +void MediaStreamProxy::MediaStreamTrackListProxy::UnregisterObserver( + Observer* observer) { + if (!signaling_thread_->IsCurrent()) { + ObserverMessageData msg(observer); + Send(MSG_UNREGISTER_OBSERVER, &msg); + return; + } + track_list_->UnregisterObserver(observer); +} + +void MediaStreamProxy::MediaStreamTrackListProxy::Send( + uint32 id, talk_base::MessageData* data) { + signaling_thread_->Send(this, id, data); +} + +// Implement MessageHandler +void MediaStreamProxy::MediaStreamTrackListProxy::OnMessage( + talk_base::Message* msg) { + talk_base::MessageData* data = msg->pdata; + switch (msg->message_id) { + case MSG_REGISTER_OBSERVER: { + ObserverMessageData* observer = static_cast(data); + track_list_->RegisterObserver(observer->data()); + break; + } + case MSG_UNREGISTER_OBSERVER: { + ObserverMessageData* observer = static_cast(data); + track_list_->UnregisterObserver(observer->data()); + break; + } + case MSG_COUNT: { + SizeTMessageData* count = static_cast(data); + count->data() = track_list_->count(); + break; + } + case MSG_AT: { + MediaStreamTrackAtMessageData* track = + static_cast(data); + track->track_ = track_list_->at(track->index_); + break; + } + default: + ASSERT(!"Not Implemented!"); + break; + } +} + +} // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamproxy.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamproxy.h new file mode 100644 index 000000000..3aea51018 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/mediastreamproxy.h @@ -0,0 +1,96 @@ +/* + * libjingle + * Copyright 2011, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TALK_APP_WEBRTC_MEDIASTREAMPROXY_H_ +#define TALK_APP_WEBRTC_MEDIASTREAMPROXY_H_ + +#include +#include + +#include "talk/app/webrtc_dev/mediastreamimpl.h" +#include "talk/base/thread.h" + +namespace webrtc { + +// MediaStreamProxy is a proxy for the MediaStream interface. The purpose is +// to make sure MediaStreamImpl is only accessed from the signaling thread. +// It can be used as a proxy for both local and remote MediaStreams. +class MediaStreamProxy : public LocalMediaStream, + public talk_base::MessageHandler { + public: + class MediaStreamTrackListProxy : public MediaStreamTrackList, + public talk_base::MessageHandler { + public: + MediaStreamTrackListProxy(MediaStreamTrackList* track_list, + talk_base::Thread* signaling_thread); + virtual size_t count(); + virtual scoped_refptr at(size_t index); + + // Implement Notifier + virtual void RegisterObserver(Observer* observer); + virtual void UnregisterObserver(Observer* observer); + private: + void Send(uint32 id, talk_base::MessageData* data); + void OnMessage(talk_base::Message* msg); + + scoped_refptr track_list_; + talk_base::Thread* signaling_thread_; + }; + + static scoped_refptr Create( + const std::string& label, + talk_base::Thread* signaling_thread); + + // Implement LocalStream. + virtual bool AddTrack(MediaStreamTrack* track); + + // Implement MediaStream. + virtual const std::string& label(); + virtual scoped_refptr 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); + + protected: + explicit MediaStreamProxy(const std::string& label, + talk_base::Thread* signaling_thread); + + void Send(uint32 id, talk_base::MessageData* data); + // Implement MessageHandler + virtual void OnMessage(talk_base::Message* msg); + + talk_base::Thread* signaling_thread_; + scoped_refptr media_stream_impl_; + scoped_refptr track_list_; +}; + +} // namespace webrtc + +#endif // TALK_APP_WEBRTC_MEDIASTREAMPROXY_H_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection.h index d37b6000b..8dcd0fdfd 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnection.h @@ -160,6 +160,10 @@ class PeerConnectionManager : public RefCount { const std::string& config, PeerConnectionObserver* observer) = 0; + virtual scoped_refptr CreateLocalMediaStream( + const std::string& label) = 0; + + protected: // Dtor protected as objects shouldn't be deleted via this interface. ~PeerConnectionManager() {} diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionimpl_unittest.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionimpl_unittest.cc index 7a779a108..129b154db 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionimpl_unittest.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionimpl_unittest.cc @@ -67,7 +67,8 @@ class PeerConnectionImplTest : public testing::Test { TEST_F(PeerConnectionImplTest, AddRemoveStream) { // Create a local stream. std::string label(kStreamLabel1); - scoped_refptr stream(CreateLocalMediaStream(label)); + scoped_refptr stream( + pc_factory_->CreateLocalMediaStream(label)); pc_->AddStream(stream); pc_->CommitStreamChanges(); diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanagerimpl.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanagerimpl.cc index 68b6c3f34..0c52e9240 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanagerimpl.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanagerimpl.cc @@ -27,6 +27,7 @@ #include "talk/app/webrtc_dev/peerconnectionmanagerimpl.h" +#include "talk/app/webrtc_dev/mediastreamproxy.h" #include "talk/app/webrtc_dev/peerconnectionimpl.h" #include "talk/app/webrtc_dev/webrtc_devicemanager.h" #include "talk/base/basicpacketsocketfactory.h" @@ -234,4 +235,10 @@ scoped_refptr PeerConnectionManagerImpl::CreatePeerConnection_s( return pc; } +scoped_refptr +PeerConnectionManagerImpl::CreateLocalMediaStream( + const std::string& label) { + return MediaStreamProxy::Create(label, signaling_thread_ptr_); +} + } // namespace webrtc diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanagerimpl.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanagerimpl.h index 26933176e..202a3bf38 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanagerimpl.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionmanagerimpl.h @@ -45,6 +45,9 @@ class PeerConnectionManagerImpl : public PeerConnectionManager, PeerConnectionObserver* observer); bool Initialize(); + scoped_refptr CreateLocalMediaStream( + const std::string& label); + protected: PeerConnectionManagerImpl(); PeerConnectionManagerImpl(talk_base::Thread* worker_thread, diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling.cc index ecccbff39..7270c8a2c 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling.cc @@ -30,7 +30,6 @@ #include #include "talk/app/webrtc_dev/audiotrackimpl.h" -#include "talk/app/webrtc_dev/mediastreamimpl.h" #include "talk/app/webrtc_dev/videotrackimpl.h" #include "talk/app/webrtc_dev/sessiondescriptionprovider.h" #include "talk/base/helpers.h" @@ -95,7 +94,6 @@ PeerConnectionSignaling::~PeerConnectionSignaling() { delete remote_desc; delete queued_received_offer_.first; } - } void PeerConnectionSignaling::OnCandidatesReady( @@ -333,7 +331,7 @@ void PeerConnectionSignaling::InitMediaSessionOptions( void PeerConnectionSignaling::UpdateRemoteStreams( const cricket::SessionDescription* remote_desc) { RemoteStreamMap current_streams; - typedef std::pair > + typedef std::pair > MediaStreamPair; const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc); @@ -353,8 +351,8 @@ void PeerConnectionSignaling::UpdateRemoteStreams( if (old_streams_it == remote_streams_.end()) { if (new_streams_it == current_streams.end()) { // New stream - scoped_refptr stream( - MediaStreamImpl::Create(it->cname)); + scoped_refptr stream( + MediaStreamProxy::Create(it->cname, signaling_thread_)); current_streams.insert(MediaStreamPair(stream->label(), stream)); new_streams_it = current_streams.find(it->cname); } @@ -364,7 +362,7 @@ void PeerConnectionSignaling::UpdateRemoteStreams( new_streams_it->second->AddTrack(track); } else { - scoped_refptr stream(old_streams_it->second); + scoped_refptr stream(old_streams_it->second); current_streams.insert(MediaStreamPair(stream->label(), stream)); } } @@ -387,8 +385,8 @@ void PeerConnectionSignaling::UpdateRemoteStreams( if (old_streams_it == remote_streams_.end()) { if (new_streams_it == current_streams.end()) { // New stream - scoped_refptr stream( - MediaStreamImpl::Create(it->cname)); + scoped_refptr stream( + MediaStreamProxy::Create(it->cname, signaling_thread_)); current_streams.insert(MediaStreamPair(stream->label(), stream)); new_streams_it = current_streams.find(it->cname); } @@ -398,7 +396,7 @@ void PeerConnectionSignaling::UpdateRemoteStreams( track->set_state(MediaStreamTrack::kLive); } else { - scoped_refptr stream(old_streams_it->second); + scoped_refptr stream(old_streams_it->second); current_streams.insert(MediaStreamPair(stream->label(), stream)); } } @@ -409,7 +407,7 @@ void PeerConnectionSignaling::UpdateRemoteStreams( for (RemoteStreamMap::iterator it = current_streams.begin(); it != current_streams.end(); ++it) { - scoped_refptr new_stream(it->second); + scoped_refptr new_stream(it->second); RemoteStreamMap::iterator old_streams_it = remote_streams_.find(new_stream->label()); if (old_streams_it == remote_streams_.end()) { @@ -424,7 +422,7 @@ void PeerConnectionSignaling::UpdateRemoteStreams( for (RemoteStreamMap::iterator it = remote_streams_.begin(); it != remote_streams_.end(); ++it) { - scoped_refptr old_stream(it->second); + scoped_refptr old_stream(it->second); RemoteStreamMap::iterator new_streams_it = current_streams.find(old_stream->label()); if (new_streams_it == current_streams.end()) { diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling.h b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling.h index bc5e6b344..74061e262 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling.h +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling.h @@ -37,7 +37,7 @@ #include #include -#include "talk/app/webrtc_dev/mediastreamimpl.h" +#include "talk/app/webrtc_dev/mediastreamproxy.h" #include "talk/app/webrtc_dev/peerconnection.h" #include "talk/app/webrtc_dev/peerconnectionmessage.h" #include "talk/app/webrtc_dev/ref_count.h" @@ -125,7 +125,6 @@ class PeerConnectionSignaling : public WebRtcSessionObserver, virtual void OnMessage(talk_base::Message* msg); private: - void CreateOffer_s(); void CreateAnswer_s(); @@ -149,7 +148,7 @@ class PeerConnectionSignaling : public WebRtcSessionObserver, State state_; uint32 ssrc_counter_; - typedef std::map > + typedef std::map > RemoteStreamMap; RemoteStreamMap remote_streams_; typedef std::map > diff --git a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling_unittest.cc b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling_unittest.cc index 86c17bea1..e0e44a3dd 100644 --- a/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling_unittest.cc +++ b/third_party_mods/libjingle/source/talk/app/webrtc_dev/peerconnectionsignaling_unittest.cc @@ -139,6 +139,7 @@ class MockSignalingObserver : public sigslot::has_slots<> { virtual ~MockSignalingObserver() {} std::string last_message; + private: MediaStreamMap remote_media_streams_; scoped_refptr remote_local_collection_; @@ -147,7 +148,8 @@ class MockSignalingObserver : public sigslot::has_slots<> { class MockSessionDescriptionProvider : public SessionDescriptionProvider { public: - MockSessionDescriptionProvider(cricket::ChannelManager* channel_manager) + explicit MockSessionDescriptionProvider( + cricket::ChannelManager* channel_manager) : update_session_description_counter_(0), session_description_factory_( new cricket::MediaSessionDescriptionFactory(channel_manager)) { @@ -232,7 +234,7 @@ class PeerConnectionSignalingTest: public testing::Test { TEST_F(PeerConnectionSignalingTest, SimpleOneWayCall) { // Create a local stream. std::string label(kStreamLabel1); - scoped_refptr stream(CreateLocalMediaStream(label)); + scoped_refptr stream(MediaStreamImpl::Create(label)); MockMediaStreamObserver stream_observer1(stream); // Add a local audio track. @@ -305,7 +307,7 @@ TEST_F(PeerConnectionSignalingTest, Glare) { signaling2_->OnCandidatesReady(candidates_); // Create a local stream. std::string label(kStreamLabel1); - scoped_refptr stream(CreateLocalMediaStream(label)); + scoped_refptr stream(MediaStreamImpl::Create(label)); // Add a local audio track. scoped_refptr audio_track( @@ -368,7 +370,7 @@ TEST_F(PeerConnectionSignalingTest, AddRemoveStream) { signaling2_->OnCandidatesReady(candidates_); // Create a local stream. std::string label(kStreamLabel1); - scoped_refptr stream(CreateLocalMediaStream(label)); + scoped_refptr stream(MediaStreamImpl::Create(label)); MockMediaStreamObserver stream_observer1(stream); // Add a local audio track. diff --git a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc index 22c99ab79..fd4053e0b 100644 --- a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc +++ b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc @@ -260,7 +260,7 @@ void Conductor::AddStreams() { video_track->SetRenderer(renderer); scoped_refptr stream = - webrtc::CreateLocalMediaStream(kStreamLabel); + peer_connection_factory_->CreateLocalMediaStream(kStreamLabel); stream->AddTrack(audio_track); stream->AddTrack(video_track);