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_media_stream_dependency_factory.h" | 5 #include "content/renderer/media/mock_media_stream_dependency_factory.h" |
6 #include "content/renderer/media/mock_peer_connection_impl.h" | 6 #include "content/renderer/media/mock_peer_connection_impl.h" |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 virtual MediaStreamInterface* find(const std::string& label) OVERRIDE { | 22 virtual MediaStreamInterface* find(const std::string& label) OVERRIDE { |
23 for (size_t i = 0; i < streams_.size(); ++i) { | 23 for (size_t i = 0; i < streams_.size(); ++i) { |
24 if (streams_[i]->label() == label) | 24 if (streams_[i]->label() == label) |
25 return streams_[i]; | 25 return streams_[i]; |
26 } | 26 } |
27 return NULL; | 27 return NULL; |
28 } | 28 } |
29 void AddStream(MediaStreamInterface* stream) { | 29 void AddStream(MediaStreamInterface* stream) { |
30 streams_.push_back(stream); | 30 streams_.push_back(stream); |
31 } | 31 } |
| 32 void RemoveStream(MediaStreamInterface* stream) { |
| 33 StreamVector::iterator it = streams_.begin(); |
| 34 for (; it != streams_.end(); ++it) { |
| 35 if (it->get() == stream) { |
| 36 streams_.erase(it); |
| 37 break; |
| 38 } |
| 39 } |
| 40 } |
32 | 41 |
33 protected: | 42 protected: |
34 virtual ~MockStreamCollection() {} | 43 virtual ~MockStreamCollection() {} |
35 | 44 |
36 private: | 45 private: |
37 std::vector<talk_base::scoped_refptr<MediaStreamInterface> > streams_; | 46 typedef std::vector<talk_base::scoped_refptr<MediaStreamInterface> > |
| 47 StreamVector; |
| 48 StreamVector streams_; |
38 }; | 49 }; |
39 | 50 |
40 const char MockPeerConnectionImpl::kDummyOffer[] = "dummy offer"; | 51 const char MockPeerConnectionImpl::kDummyOffer[] = "dummy offer"; |
| 52 const char MockPeerConnectionImpl::kDummyAnswer[] = "dummy answer"; |
41 | 53 |
42 MockPeerConnectionImpl::MockPeerConnectionImpl( | 54 MockPeerConnectionImpl::MockPeerConnectionImpl( |
43 MockMediaStreamDependencyFactory* factory) | 55 MockMediaStreamDependencyFactory* factory) |
44 : dependency_factory_(factory), | 56 : dependency_factory_(factory), |
45 local_streams_(new talk_base::RefCountedObject<MockStreamCollection>), | 57 local_streams_(new talk_base::RefCountedObject<MockStreamCollection>), |
46 remote_streams_(new talk_base::RefCountedObject<MockStreamCollection>), | 58 remote_streams_(new talk_base::RefCountedObject<MockStreamCollection>), |
47 hint_audio_(false), | 59 hint_audio_(false), |
48 hint_video_(false), | 60 hint_video_(false), |
49 action_(kAnswer), | 61 action_(kAnswer), |
50 ice_options_(kOnlyRelay), | 62 ice_options_(kOnlyRelay), |
51 ready_state_(kNew) { | 63 sdp_mline_index_(-1), |
| 64 ready_state_(kNew), |
| 65 ice_state_(kIceNew) { |
52 } | 66 } |
53 | 67 |
54 MockPeerConnectionImpl::~MockPeerConnectionImpl() {} | 68 MockPeerConnectionImpl::~MockPeerConnectionImpl() {} |
55 | 69 |
56 talk_base::scoped_refptr<StreamCollectionInterface> | 70 talk_base::scoped_refptr<StreamCollectionInterface> |
57 MockPeerConnectionImpl::local_streams() { | 71 MockPeerConnectionImpl::local_streams() { |
58 return local_streams_; | 72 return local_streams_; |
59 } | 73 } |
60 | 74 |
61 talk_base::scoped_refptr<StreamCollectionInterface> | 75 talk_base::scoped_refptr<StreamCollectionInterface> |
(...skipping 13 matching lines...) Expand all Loading... |
75 DCHECK(stream_label_.empty()); | 89 DCHECK(stream_label_.empty()); |
76 stream_label_ = local_stream->label(); | 90 stream_label_ = local_stream->label(); |
77 local_streams_->AddStream(local_stream); | 91 local_streams_->AddStream(local_stream); |
78 return true; | 92 return true; |
79 } | 93 } |
80 | 94 |
81 void MockPeerConnectionImpl::RemoveStream( | 95 void MockPeerConnectionImpl::RemoveStream( |
82 MediaStreamInterface* local_stream) { | 96 MediaStreamInterface* local_stream) { |
83 DCHECK_EQ(stream_label_, local_stream->label()); | 97 DCHECK_EQ(stream_label_, local_stream->label()); |
84 stream_label_.clear(); | 98 stream_label_.clear(); |
| 99 local_streams_->RemoveStream(local_stream); |
85 } | 100 } |
86 | 101 |
87 MockPeerConnectionImpl::ReadyState MockPeerConnectionImpl::ready_state() { | 102 MockPeerConnectionImpl::ReadyState MockPeerConnectionImpl::ready_state() { |
88 return ready_state_; | 103 return ready_state_; |
89 } | 104 } |
90 | 105 |
91 bool MockPeerConnectionImpl::StartIce(IceOptions options) { | 106 bool MockPeerConnectionImpl::StartIce(IceOptions options) { |
92 ice_options_ = options; | 107 ice_options_ = options; |
93 return true; | 108 return true; |
94 } | 109 } |
(...skipping 25 matching lines...) Expand all Loading... |
120 bool MockPeerConnectionImpl::SetRemoteDescription( | 135 bool MockPeerConnectionImpl::SetRemoteDescription( |
121 Action action, | 136 Action action, |
122 webrtc::SessionDescriptionInterface* desc) { | 137 webrtc::SessionDescriptionInterface* desc) { |
123 action_ = action; | 138 action_ = action; |
124 remote_desc_.reset(desc); | 139 remote_desc_.reset(desc); |
125 return desc->ToString(&description_sdp_); | 140 return desc->ToString(&description_sdp_); |
126 } | 141 } |
127 | 142 |
128 bool MockPeerConnectionImpl::ProcessIceMessage( | 143 bool MockPeerConnectionImpl::ProcessIceMessage( |
129 const webrtc::IceCandidateInterface* ice_candidate) { | 144 const webrtc::IceCandidateInterface* ice_candidate) { |
130 sdp_mid_ = ice_candidate->sdp_mid(); | 145 return AddIceCandidate(ice_candidate); |
131 sdp_mline_index_ = ice_candidate->sdp_mline_index(); | |
132 return ice_candidate->ToString(&ice_sdp_); | |
133 } | 146 } |
134 | 147 |
135 const webrtc::SessionDescriptionInterface* | 148 const webrtc::SessionDescriptionInterface* |
136 MockPeerConnectionImpl::local_description() const { | 149 MockPeerConnectionImpl::local_description() const { |
137 return local_desc_.get(); | 150 return local_desc_.get(); |
138 } | 151 } |
139 | 152 |
140 const webrtc::SessionDescriptionInterface* | 153 const webrtc::SessionDescriptionInterface* |
141 MockPeerConnectionImpl::remote_description() const { | 154 MockPeerConnectionImpl::remote_description() const { |
142 return remote_desc_.get(); | 155 return remote_desc_.get(); |
143 } | 156 } |
144 | 157 |
145 void MockPeerConnectionImpl::AddRemoteStream(MediaStreamInterface* stream) { | 158 void MockPeerConnectionImpl::AddRemoteStream(MediaStreamInterface* stream) { |
146 remote_streams_->AddStream(stream); | 159 remote_streams_->AddStream(stream); |
147 } | 160 } |
148 | 161 |
149 void MockPeerConnectionImpl::CreateOffer( | 162 void MockPeerConnectionImpl::CreateOffer( |
150 CreateSessionDescriptionObserver* observer, | 163 CreateSessionDescriptionObserver* observer, |
151 const MediaConstraintsInterface* constraints) { | 164 const MediaConstraintsInterface* constraints) { |
152 NOTIMPLEMENTED(); | 165 DCHECK(observer); |
| 166 created_sessiondescription_.reset( |
| 167 dependency_factory_->CreateSessionDescription(kDummyOffer)); |
153 } | 168 } |
154 | 169 |
155 void MockPeerConnectionImpl::CreateAnswer( | 170 void MockPeerConnectionImpl::CreateAnswer( |
156 CreateSessionDescriptionObserver* observer, | 171 CreateSessionDescriptionObserver* observer, |
157 const MediaConstraintsInterface* constraints) { | 172 const MediaConstraintsInterface* constraints) { |
158 NOTIMPLEMENTED(); | 173 DCHECK(observer); |
| 174 created_sessiondescription_.reset( |
| 175 dependency_factory_->CreateSessionDescription(kDummyAnswer)); |
159 } | 176 } |
160 | 177 |
161 void MockPeerConnectionImpl::SetLocalDescription( | 178 void MockPeerConnectionImpl::SetLocalDescription( |
162 SetSessionDescriptionObserver* observer, | 179 SetSessionDescriptionObserver* observer, |
163 SessionDescriptionInterface* desc) { | 180 SessionDescriptionInterface* desc) { |
164 NOTIMPLEMENTED(); | 181 desc->ToString(&description_sdp_); |
| 182 local_desc_.reset(desc); |
165 } | 183 } |
166 | 184 |
167 void MockPeerConnectionImpl::SetRemoteDescription( | 185 void MockPeerConnectionImpl::SetRemoteDescription( |
168 SetSessionDescriptionObserver* observer, | 186 SetSessionDescriptionObserver* observer, |
169 SessionDescriptionInterface* desc) { | 187 SessionDescriptionInterface* desc) { |
170 NOTIMPLEMENTED(); | 188 desc->ToString(&description_sdp_); |
| 189 remote_desc_.reset(desc); |
171 } | 190 } |
172 | 191 |
173 bool MockPeerConnectionImpl::UpdateIce( | 192 bool MockPeerConnectionImpl::UpdateIce( |
174 const IceServers& configuration, | 193 const IceServers& configuration, |
175 const MediaConstraintsInterface* constraints) { | 194 const MediaConstraintsInterface* constraints) { |
176 NOTIMPLEMENTED(); | 195 return true; |
177 return false; | |
178 } | 196 } |
179 | 197 |
180 bool MockPeerConnectionImpl::AddIceCandidate( | 198 bool MockPeerConnectionImpl::AddIceCandidate( |
181 const IceCandidateInterface* candidate) { | 199 const IceCandidateInterface* candidate) { |
182 NOTIMPLEMENTED(); | 200 sdp_mid_ = candidate->sdp_mid(); |
183 return false; | 201 sdp_mline_index_ = candidate->sdp_mline_index(); |
| 202 return candidate->ToString(&ice_sdp_); |
184 } | 203 } |
185 | 204 |
186 PeerConnectionInterface::IceState MockPeerConnectionImpl::ice_state() { | 205 PeerConnectionInterface::IceState MockPeerConnectionImpl::ice_state() { |
187 NOTIMPLEMENTED(); | 206 return ice_state_; |
188 return kIceNew; | |
189 } | 207 } |
190 | 208 |
191 } // namespace webrtc | 209 } // namespace webrtc |
OLD | NEW |