From bc8a935af24a45165630c411c6c43e53f312fb7a Mon Sep 17 00:00:00 2001 From: tommi Date: Tue, 28 Oct 2014 04:58:32 -0700 Subject: [PATCH] Update MockPeerConnectionImpl and MockPeerConnectionDependencyFactory. - Add support for multiple observers. - Add a way to access the PC observer from the mocked PeerConnection. This is needed for an upcoming getStats refactoring cl which separates the RtcPeerConnectionHandler from the observer. BUG=369796 Review URL: https://codereview.chromium.org/660423003 Cr-Commit-Position: refs/heads/master@{#301605} --- .../renderer/media/mock_peer_connection_impl.cc | 6 ++++-- content/renderer/media/mock_peer_connection_impl.h | 7 ++++++- .../mock_peer_connection_dependency_factory.cc | 24 +++++++++++----------- .../mock_peer_connection_dependency_factory.h | 6 +++--- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/content/renderer/media/mock_peer_connection_impl.cc b/content/renderer/media/mock_peer_connection_impl.cc index 9457a3d83d2e..379a2e26fd72 100644 --- a/content/renderer/media/mock_peer_connection_impl.cc +++ b/content/renderer/media/mock_peer_connection_impl.cc @@ -176,14 +176,16 @@ const char MockPeerConnectionImpl::kDummyOffer[] = "dummy offer"; const char MockPeerConnectionImpl::kDummyAnswer[] = "dummy answer"; MockPeerConnectionImpl::MockPeerConnectionImpl( - MockPeerConnectionDependencyFactory* factory) + MockPeerConnectionDependencyFactory* factory, + webrtc::PeerConnectionObserver* observer) : dependency_factory_(factory), local_streams_(new rtc::RefCountedObject), remote_streams_(new rtc::RefCountedObject), hint_audio_(false), hint_video_(false), getstats_result_(true), - sdp_mline_index_(-1) { + sdp_mline_index_(-1), + observer_(observer) { ON_CALL(*this, SetLocalDescription(_, _)).WillByDefault(testing::Invoke( this, &MockPeerConnectionImpl::SetLocalDescriptionWorker)); ON_CALL(*this, SetRemoteDescription(_, _)).WillByDefault(testing::Invoke( diff --git a/content/renderer/media/mock_peer_connection_impl.h b/content/renderer/media/mock_peer_connection_impl.h index 33d323d0c255..9a965edc06f5 100644 --- a/content/renderer/media/mock_peer_connection_impl.h +++ b/content/renderer/media/mock_peer_connection_impl.h @@ -21,7 +21,8 @@ class MockStreamCollection; class MockPeerConnectionImpl : public webrtc::PeerConnectionInterface { public: - explicit MockPeerConnectionImpl(MockPeerConnectionDependencyFactory* factory); + explicit MockPeerConnectionImpl(MockPeerConnectionDependencyFactory* factory, + webrtc::PeerConnectionObserver* observer); // PeerConnectionInterface implementation. virtual rtc::scoped_refptr @@ -113,6 +114,9 @@ class MockPeerConnectionImpl : public webrtc::PeerConnectionInterface { webrtc::SessionDescriptionInterface* created_session_description() const { return created_sessiondescription_.get(); } + webrtc::PeerConnectionObserver* observer() { + return observer_; + } static const char kDummyOffer[]; static const char kDummyAnswer[]; @@ -136,6 +140,7 @@ class MockPeerConnectionImpl : public webrtc::PeerConnectionInterface { std::string sdp_mid_; int sdp_mline_index_; std::string ice_sdp_; + webrtc::PeerConnectionObserver* observer_; DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionImpl); }; diff --git a/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc b/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc index c219537ae123..ca3f29851a3c 100644 --- a/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc +++ b/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc @@ -175,8 +175,7 @@ bool MockVideoRenderer::RenderFrame(const cricket::VideoFrame* frame) { MockAudioSource::MockAudioSource( const webrtc::MediaConstraintsInterface* constraints) - : observer_(NULL), - state_(MediaSourceInterface::kLive), + : state_(MediaSourceInterface::kLive), optional_constraints_(constraints->GetOptional()), mandatory_constraints_(constraints->GetMandatory()) { } @@ -184,12 +183,13 @@ MockAudioSource::MockAudioSource( MockAudioSource::~MockAudioSource() {} void MockAudioSource::RegisterObserver(webrtc::ObserverInterface* observer) { - observer_ = observer; + DCHECK(observers_.find(observer) == observers_.end()); + observers_.insert(observer); } void MockAudioSource::UnregisterObserver(webrtc::ObserverInterface* observer) { - DCHECK(observer_ == observer); - observer_ = NULL; + DCHECK(observers_.find(observer) != observers_.end()); + observers_.erase(observer); } webrtc::MediaSourceInterface::SourceState MockAudioSource::state() const { @@ -290,7 +290,6 @@ MockWebRtcVideoTrack::MockWebRtcVideoTrack( id_(id), state_(MediaStreamTrackInterface::kLive), source_(source), - observer_(NULL), renderer_(NULL) { } @@ -326,18 +325,19 @@ bool MockWebRtcVideoTrack::set_enabled(bool enable) { bool MockWebRtcVideoTrack::set_state(TrackState new_state) { state_ = new_state; - if (observer_) - observer_->OnChanged(); + for (auto& o : observers_) + o->OnChanged(); return true; } void MockWebRtcVideoTrack::RegisterObserver(ObserverInterface* observer) { - observer_ = observer; + DCHECK(observers_.find(observer) == observers_.end()); + observers_.insert(observer); } void MockWebRtcVideoTrack::UnregisterObserver(ObserverInterface* observer) { - DCHECK(observer_ == observer); - observer_ = NULL; + DCHECK(observers_.find(observer) != observers_.end()); + observers_.erase(observer); } VideoSourceInterface* MockWebRtcVideoTrack::GetSource() const { @@ -433,7 +433,7 @@ MockPeerConnectionDependencyFactory::CreatePeerConnection( const webrtc::MediaConstraintsInterface* constraints, blink::WebFrame* frame, webrtc::PeerConnectionObserver* observer) { - return new rtc::RefCountedObject(this); + return new rtc::RefCountedObject(this, observer); } scoped_refptr diff --git a/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.h b/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.h index b75558b33f23..b04282411c71 100644 --- a/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.h +++ b/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.h @@ -17,6 +17,7 @@ namespace content { class WebAudioCapturerSource; +typedef std::set ObserverSet; class MockVideoRenderer : public cricket::VideoRenderer { public: @@ -99,7 +100,7 @@ class MockAudioSource : public webrtc::AudioSourceInterface { ~MockAudioSource() override; private: - webrtc::ObserverInterface* observer_; + ObserverSet observers_; MediaSourceInterface::SourceState state_; webrtc::MediaConstraintsInterface::Constraints optional_constraints_; webrtc::MediaConstraintsInterface::Constraints mandatory_constraints_; @@ -129,7 +130,7 @@ class MockWebRtcVideoTrack : public webrtc::VideoTrackInterface { std::string id_; TrackState state_; scoped_refptr source_; - webrtc::ObserverInterface* observer_; + ObserverSet observers_; webrtc::VideoRendererInterface* renderer_; }; @@ -161,7 +162,6 @@ class MockMediaStream : public webrtc::MediaStreamInterface { webrtc::AudioTrackVector audio_track_vector_; webrtc::VideoTrackVector video_track_vector_; - typedef std::set ObserverSet; ObserverSet observers_; }; -- 2.11.4.GIT