| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/mock_peer_connection_impl.h" | 5 #include "content/renderer/media/mock_peer_connection_impl.h" |
| 6 | 6 |
| 7 #include <vector> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 | 10 |
| 9 namespace webrtc { | 11 namespace webrtc { |
| 10 | 12 |
| 13 class MockStreamCollection : public StreamCollectionInterface { |
| 14 public: |
| 15 virtual size_t count() OVERRIDE { |
| 16 return streams_.size(); |
| 17 } |
| 18 virtual MediaStreamInterface* at(size_t index) OVERRIDE { |
| 19 return streams_[index]; |
| 20 } |
| 21 virtual MediaStreamInterface* find(const std::string& label) OVERRIDE { |
| 22 for (size_t i = 0; i < streams_.size(); ++i) { |
| 23 if (streams_[i]->label() == label) |
| 24 return streams_[i]; |
| 25 } |
| 26 return NULL; |
| 27 } |
| 28 void AddStream(MediaStreamInterface* stream) { |
| 29 streams_.push_back(stream); |
| 30 } |
| 31 |
| 32 protected: |
| 33 virtual ~MockStreamCollection() {} |
| 34 |
| 35 private: |
| 36 std::vector<MediaStreamInterface*> streams_; |
| 37 }; |
| 38 |
| 11 MockPeerConnectionImpl::MockPeerConnectionImpl() | 39 MockPeerConnectionImpl::MockPeerConnectionImpl() |
| 12 : observer_(NULL), | 40 : stream_changes_committed_(false), |
| 13 video_stream_(false), | 41 remote_streams_(new talk_base::RefCountedObject<MockStreamCollection>) { |
| 14 connected_(false), | |
| 15 video_capture_set_(false) { | |
| 16 } | 42 } |
| 17 | 43 |
| 18 MockPeerConnectionImpl::~MockPeerConnectionImpl() {} | 44 MockPeerConnectionImpl::~MockPeerConnectionImpl() {} |
| 19 | 45 |
| 20 void MockPeerConnectionImpl::RegisterObserver( | 46 void MockPeerConnectionImpl::ProcessSignalingMessage(const std::string& msg) { |
| 21 PeerConnectionObserver* observer) { | 47 signaling_message_ = msg; |
| 22 observer_ = observer; | |
| 23 } | 48 } |
| 24 | 49 |
| 25 bool MockPeerConnectionImpl::SignalingMessage( | 50 bool MockPeerConnectionImpl::Send(const std::string& msg) { |
| 26 const std::string& signaling_message) { | |
| 27 signaling_message_ = signaling_message; | |
| 28 return true; | |
| 29 } | |
| 30 | |
| 31 bool MockPeerConnectionImpl::AddStream( | |
| 32 const std::string& stream_id, | |
| 33 bool video) { | |
| 34 stream_id_ = stream_id; | |
| 35 video_stream_ = video; | |
| 36 return true; | |
| 37 } | |
| 38 | |
| 39 bool MockPeerConnectionImpl::RemoveStream(const std::string& stream_id) { | |
| 40 stream_id_.clear(); | |
| 41 video_stream_ = false; | |
| 42 return true; | |
| 43 } | |
| 44 | |
| 45 bool MockPeerConnectionImpl::Connect() { | |
| 46 connected_ = true; | |
| 47 return true; | |
| 48 } | |
| 49 | |
| 50 bool MockPeerConnectionImpl::Close() { | |
| 51 observer_ = NULL; | |
| 52 signaling_message_.clear(); | |
| 53 stream_id_.clear(); | |
| 54 video_stream_ = false; | |
| 55 connected_ = false; | |
| 56 video_capture_set_ = false; | |
| 57 return true; | |
| 58 } | |
| 59 | |
| 60 bool MockPeerConnectionImpl::SetAudioDevice( | |
| 61 const std::string& wave_in_device, | |
| 62 const std::string& wave_out_device, | |
| 63 int opts) { | |
| 64 NOTIMPLEMENTED(); | 51 NOTIMPLEMENTED(); |
| 65 return false; | 52 return false; |
| 66 } | 53 } |
| 67 | 54 |
| 68 bool MockPeerConnectionImpl::SetLocalVideoRenderer( | 55 talk_base::scoped_refptr<StreamCollectionInterface> |
| 69 cricket::VideoRenderer* renderer) { | 56 MockPeerConnectionImpl::local_streams() { |
| 70 NOTIMPLEMENTED(); | 57 NOTIMPLEMENTED(); |
| 71 return false; | 58 return NULL; |
| 72 } | 59 } |
| 73 | 60 |
| 74 bool MockPeerConnectionImpl::SetVideoRenderer( | 61 talk_base::scoped_refptr<StreamCollectionInterface> |
| 75 const std::string& stream_id, | 62 MockPeerConnectionImpl::remote_streams() { |
| 76 cricket::VideoRenderer* renderer) { | 63 return remote_streams_; |
| 77 video_renderer_stream_id_ = stream_id; | |
| 78 return true; | |
| 79 } | 64 } |
| 80 | 65 |
| 81 bool MockPeerConnectionImpl::SetVideoCapture(const std::string& cam_device) { | 66 void MockPeerConnectionImpl::AddStream(LocalMediaStreamInterface* stream) { |
| 82 video_capture_set_ = true; | 67 stream_label_ = stream->label(); |
| 83 return true; | |
| 84 } | 68 } |
| 85 | 69 |
| 86 MockPeerConnectionImpl::ReadyState MockPeerConnectionImpl::GetReadyState() { | 70 void MockPeerConnectionImpl::RemoveStream(LocalMediaStreamInterface* stream) { |
| 71 stream_label_.clear(); |
| 72 } |
| 73 |
| 74 void MockPeerConnectionImpl::CommitStreamChanges() { |
| 75 stream_changes_committed_ = true; |
| 76 } |
| 77 |
| 78 void MockPeerConnectionImpl::Close() { |
| 79 signaling_message_.clear(); |
| 80 stream_label_.clear(); |
| 81 stream_changes_committed_ = false; |
| 82 } |
| 83 |
| 84 MockPeerConnectionImpl::ReadyState MockPeerConnectionImpl::ready_state() { |
| 87 NOTIMPLEMENTED(); | 85 NOTIMPLEMENTED(); |
| 88 return NEW; | 86 return kNew; |
| 87 } |
| 88 |
| 89 MockPeerConnectionImpl::SdpState MockPeerConnectionImpl::sdp_state() { |
| 90 NOTIMPLEMENTED(); |
| 91 return kSdpNew; |
| 92 } |
| 93 |
| 94 void MockPeerConnectionImpl::AddRemoteStream(MediaStreamInterface* stream) { |
| 95 remote_streams_->AddStream(stream); |
| 89 } | 96 } |
| 90 | 97 |
| 91 } // namespace webrtc | 98 } // namespace webrtc |
| OLD | NEW |