Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: content/renderer/media/mock_media_stream_dependency_factory.cc

Issue 14200016: Added implementation of RemoteMediaStreams. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/renderer/media/mock_peer_connection_impl.h" 8 #include "content/renderer/media/mock_peer_connection_impl.h"
9 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" 9 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
10 #include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h" 10 #include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h"
(...skipping 21 matching lines...) Expand all
32 if ((*it)->id() == track_id) { 32 if ((*it)->id() == track_id) {
33 break; 33 break;
34 } 34 }
35 } 35 }
36 return it; 36 return it;
37 }; 37 };
38 38
39 class MockMediaStream : public webrtc::MediaStreamInterface { 39 class MockMediaStream : public webrtc::MediaStreamInterface {
40 public: 40 public:
41 explicit MockMediaStream(const std::string& label) 41 explicit MockMediaStream(const std::string& label)
42 : label_(label) { 42 : label_(label),
43 observer_(NULL) {
43 } 44 }
44 virtual bool AddTrack(AudioTrackInterface* track) OVERRIDE { 45 virtual bool AddTrack(AudioTrackInterface* track) OVERRIDE {
45 audio_track_vector_.push_back(track); 46 audio_track_vector_.push_back(track);
47 if (observer_)
48 observer_->OnChanged();
46 return true; 49 return true;
47 } 50 }
48 virtual bool AddTrack(VideoTrackInterface* track) OVERRIDE { 51 virtual bool AddTrack(VideoTrackInterface* track) OVERRIDE {
49 video_track_vector_.push_back(track); 52 video_track_vector_.push_back(track);
53 if (observer_)
54 observer_->OnChanged();
50 return true; 55 return true;
51 } 56 }
52 virtual bool RemoveTrack(AudioTrackInterface* track) OVERRIDE { 57 virtual bool RemoveTrack(AudioTrackInterface* track) OVERRIDE {
53 AudioTrackVector::iterator it = FindTrack(&audio_track_vector_, 58 AudioTrackVector::iterator it = FindTrack(&audio_track_vector_,
54 track->id()); 59 track->id());
55 if (it == audio_track_vector_.end()) 60 if (it == audio_track_vector_.end())
56 return false; 61 return false;
57 audio_track_vector_.erase(it); 62 audio_track_vector_.erase(it);
63 if (observer_)
64 observer_->OnChanged();
58 return true; 65 return true;
59 } 66 }
60 virtual bool RemoveTrack(VideoTrackInterface* track) OVERRIDE { 67 virtual bool RemoveTrack(VideoTrackInterface* track) OVERRIDE {
61 VideoTrackVector::iterator it = FindTrack(&video_track_vector_, 68 VideoTrackVector::iterator it = FindTrack(&video_track_vector_,
62 track->id()); 69 track->id());
63 if (it == video_track_vector_.end()) 70 if (it == video_track_vector_.end())
64 return false; 71 return false;
65 video_track_vector_.erase(it); 72 video_track_vector_.erase(it);
73 if (observer_)
74 observer_->OnChanged();
66 return true; 75 return true;
67 } 76 }
68 virtual std::string label() const OVERRIDE { return label_; } 77 virtual std::string label() const OVERRIDE { return label_; }
69 virtual AudioTrackVector GetAudioTracks() OVERRIDE { 78 virtual AudioTrackVector GetAudioTracks() OVERRIDE {
70 return audio_track_vector_; 79 return audio_track_vector_;
71 } 80 }
72 virtual VideoTrackVector GetVideoTracks() OVERRIDE { 81 virtual VideoTrackVector GetVideoTracks() OVERRIDE {
73 return video_track_vector_; 82 return video_track_vector_;
74 } 83 }
75 virtual talk_base::scoped_refptr<AudioTrackInterface> 84 virtual talk_base::scoped_refptr<AudioTrackInterface>
76 FindAudioTrack(const std::string& track_id) OVERRIDE { 85 FindAudioTrack(const std::string& track_id) OVERRIDE {
77 AudioTrackVector::iterator it = FindTrack(&audio_track_vector_, track_id); 86 AudioTrackVector::iterator it = FindTrack(&audio_track_vector_, track_id);
78 return it == audio_track_vector_.end() ? NULL : *it; 87 return it == audio_track_vector_.end() ? NULL : *it;
79 } 88 }
80 virtual talk_base::scoped_refptr<VideoTrackInterface> 89 virtual talk_base::scoped_refptr<VideoTrackInterface>
81 FindVideoTrack(const std::string& track_id) OVERRIDE { 90 FindVideoTrack(const std::string& track_id) OVERRIDE {
82 VideoTrackVector::iterator it = FindTrack(&video_track_vector_, track_id); 91 VideoTrackVector::iterator it = FindTrack(&video_track_vector_, track_id);
83 return it == video_track_vector_.end() ? NULL : *it; 92 return it == video_track_vector_.end() ? NULL : *it;
84 } 93 }
85 virtual void RegisterObserver(ObserverInterface* observer) OVERRIDE { 94 virtual void RegisterObserver(ObserverInterface* observer) OVERRIDE {
86 NOTIMPLEMENTED(); 95 DCHECK(!observer_);
96 observer_ = observer;
87 } 97 }
88 virtual void UnregisterObserver(ObserverInterface* observer) OVERRIDE { 98 virtual void UnregisterObserver(ObserverInterface* observer) OVERRIDE {
89 NOTIMPLEMENTED(); 99 DCHECK(observer_ == observer);
100 observer_ = NULL;
90 } 101 }
91 102
92 protected: 103 protected:
93 virtual ~MockMediaStream() {} 104 virtual ~MockMediaStream() {}
94 105
95 private: 106 private:
96 std::string label_; 107 std::string label_;
97 AudioTrackVector audio_track_vector_; 108 AudioTrackVector audio_track_vector_;
98 VideoTrackVector video_track_vector_; 109 VideoTrackVector video_track_vector_;
110 webrtc::ObserverInterface* observer_;
99 }; 111 };
100 112
101 MockAudioSource::MockAudioSource( 113 MockAudioSource::MockAudioSource(
102 const webrtc::MediaConstraintsInterface* constraints) 114 const webrtc::MediaConstraintsInterface* constraints)
103 : observer_(NULL), 115 : observer_(NULL),
104 state_(MediaSourceInterface::kInitializing), 116 state_(MediaSourceInterface::kInitializing),
105 optional_constraints_(constraints->GetOptional()), 117 optional_constraints_(constraints->GetOptional()),
106 mandatory_constraints_(constraints->GetMandatory()) { 118 mandatory_constraints_(constraints->GetMandatory()) {
107 } 119 }
108 120
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 196
185 const cricket::VideoOptions* MockVideoSource::options() const { 197 const cricket::VideoOptions* MockVideoSource::options() const {
186 NOTIMPLEMENTED(); 198 NOTIMPLEMENTED();
187 return NULL; 199 return NULL;
188 } 200 }
189 201
190 MockLocalVideoTrack::MockLocalVideoTrack(std::string id, 202 MockLocalVideoTrack::MockLocalVideoTrack(std::string id,
191 webrtc::VideoSourceInterface* source) 203 webrtc::VideoSourceInterface* source)
192 : enabled_(false), 204 : enabled_(false),
193 id_(id), 205 id_(id),
194 source_(source) { 206 state_(MediaStreamTrackInterface::kLive),
207 source_(source),
208 observer_(NULL) {
195 } 209 }
196 210
197 MockLocalVideoTrack::~MockLocalVideoTrack() {} 211 MockLocalVideoTrack::~MockLocalVideoTrack() {}
198 212
199 void MockLocalVideoTrack::AddRenderer(VideoRendererInterface* renderer) { 213 void MockLocalVideoTrack::AddRenderer(VideoRendererInterface* renderer) {
200 NOTIMPLEMENTED(); 214 NOTIMPLEMENTED();
201 } 215 }
202 216
203 void MockLocalVideoTrack::RemoveRenderer(VideoRendererInterface* renderer) { 217 void MockLocalVideoTrack::RemoveRenderer(VideoRendererInterface* renderer) {
204 NOTIMPLEMENTED(); 218 NOTIMPLEMENTED();
205 } 219 }
206 220
207 cricket::VideoRenderer* MockLocalVideoTrack::FrameInput() { 221 cricket::VideoRenderer* MockLocalVideoTrack::FrameInput() {
208 NOTIMPLEMENTED(); 222 NOTIMPLEMENTED();
209 return NULL; 223 return NULL;
210 } 224 }
211 225
212 std::string MockLocalVideoTrack::kind() const { 226 std::string MockLocalVideoTrack::kind() const {
213 NOTIMPLEMENTED(); 227 NOTIMPLEMENTED();
214 return std::string(); 228 return std::string();
215 } 229 }
216 230
217 std::string MockLocalVideoTrack::id() const { return id_; } 231 std::string MockLocalVideoTrack::id() const { return id_; }
218 232
219 bool MockLocalVideoTrack::enabled() const { return enabled_; } 233 bool MockLocalVideoTrack::enabled() const { return enabled_; }
220 234
221 MockLocalVideoTrack::TrackState MockLocalVideoTrack::state() const { 235 MockLocalVideoTrack::TrackState MockLocalVideoTrack::state() const {
222 NOTIMPLEMENTED(); 236 return state_;
223 return kInitializing;
224 } 237 }
225 238
226 bool MockLocalVideoTrack::set_enabled(bool enable) { 239 bool MockLocalVideoTrack::set_enabled(bool enable) {
227 enabled_ = enable; 240 enabled_ = enable;
228 return true; 241 return true;
229 } 242 }
230 243
231 bool MockLocalVideoTrack::set_state(TrackState new_state) { 244 bool MockLocalVideoTrack::set_state(TrackState new_state) {
232 NOTIMPLEMENTED(); 245 state_ = new_state;
233 return false; 246 if (observer_)
247 observer_->OnChanged();
248 return true;
234 } 249 }
235 250
236 void MockLocalVideoTrack::RegisterObserver(ObserverInterface* observer) { 251 void MockLocalVideoTrack::RegisterObserver(ObserverInterface* observer) {
237 NOTIMPLEMENTED(); 252 observer_ = observer;
238 } 253 }
239 254
240 void MockLocalVideoTrack::UnregisterObserver(ObserverInterface* observer) { 255 void MockLocalVideoTrack::UnregisterObserver(ObserverInterface* observer) {
241 NOTIMPLEMENTED(); 256 DCHECK(observer_ == observer);
257 observer_ = NULL;
242 } 258 }
243 259
244 VideoSourceInterface* MockLocalVideoTrack::GetSource() const { 260 VideoSourceInterface* MockLocalVideoTrack::GetSource() const {
245 return source_; 261 return source_;
246 } 262 }
247 263
248 std::string MockLocalAudioTrack::kind() const { 264 std::string MockLocalAudioTrack::kind() const {
249 NOTIMPLEMENTED(); 265 NOTIMPLEMENTED();
250 return std::string(); 266 return std::string();
251 } 267 }
252 268
253 std::string MockLocalAudioTrack::id() const { return id_; } 269 std::string MockLocalAudioTrack::id() const { return id_; }
254 270
255 bool MockLocalAudioTrack::enabled() const { return enabled_; } 271 bool MockLocalAudioTrack::enabled() const { return enabled_; }
256 272
257 MockLocalVideoTrack::TrackState MockLocalAudioTrack::state() const { 273 MockLocalAudioTrack::TrackState MockLocalAudioTrack::state() const {
258 NOTIMPLEMENTED(); 274 return state_;
259 return kInitializing;
260 } 275 }
261 276
262 bool MockLocalAudioTrack::set_enabled(bool enable) { 277 bool MockLocalAudioTrack::set_enabled(bool enable) {
263 enabled_ = enable; 278 enabled_ = enable;
264 return true; 279 return true;
265 } 280 }
266 281
267 bool MockLocalAudioTrack::set_state(TrackState new_state) { 282 bool MockLocalAudioTrack::set_state(TrackState new_state) {
268 NOTIMPLEMENTED(); 283 state_ = new_state;
269 return false; 284 if (observer_)
285 observer_->OnChanged();
286 return true;
270 } 287 }
271 288
272 void MockLocalAudioTrack::RegisterObserver(ObserverInterface* observer) { 289 void MockLocalAudioTrack::RegisterObserver(ObserverInterface* observer) {
273 NOTIMPLEMENTED(); 290 observer_ = observer;
274 } 291 }
275 292
276 void MockLocalAudioTrack::UnregisterObserver(ObserverInterface* observer) { 293 void MockLocalAudioTrack::UnregisterObserver(ObserverInterface* observer) {
277 NOTIMPLEMENTED(); 294 DCHECK(observer_ == observer);
295 observer_ = NULL;
278 } 296 }
279 297
280 AudioSourceInterface* MockLocalAudioTrack::GetSource() const { 298 AudioSourceInterface* MockLocalAudioTrack::GetSource() const {
281 NOTIMPLEMENTED(); 299 NOTIMPLEMENTED();
282 return NULL; 300 return NULL;
283 } 301 }
284 302
285 class MockSessionDescription : public SessionDescriptionInterface { 303 class MockSessionDescription : public SessionDescriptionInterface {
286 public: 304 public:
287 MockSessionDescription(const std::string& type, 305 MockSessionDescription(const std::string& type,
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 476
459 webrtc::IceCandidateInterface* 477 webrtc::IceCandidateInterface*
460 MockMediaStreamDependencyFactory::CreateIceCandidate( 478 MockMediaStreamDependencyFactory::CreateIceCandidate(
461 const std::string& sdp_mid, 479 const std::string& sdp_mid,
462 int sdp_mline_index, 480 int sdp_mline_index,
463 const std::string& sdp) { 481 const std::string& sdp) {
464 return new MockIceCandidate(sdp_mid, sdp_mline_index, sdp); 482 return new MockIceCandidate(sdp_mid, sdp_mline_index, sdp);
465 } 483 }
466 484
467 } // namespace content 485 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698