| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/webrtc/mock_peer_connection_dependency_factory.
h" | 5 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 void MockMediaStream::NotifyObservers() { | 113 void MockMediaStream::NotifyObservers() { |
| 114 for (ObserverSet::iterator it = observers_.begin(); it != observers_.end(); | 114 for (ObserverSet::iterator it = observers_.begin(); it != observers_.end(); |
| 115 ++it) { | 115 ++it) { |
| 116 (*it)->OnChanged(); | 116 (*it)->OnChanged(); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 MockMediaStream::~MockMediaStream() {} | 120 MockMediaStream::~MockMediaStream() {} |
| 121 | 121 |
| 122 class MockRtcVideoCapturer : public WebRtcVideoCapturerAdapter { | |
| 123 public: | |
| 124 explicit MockRtcVideoCapturer(bool is_screencast) | |
| 125 : WebRtcVideoCapturerAdapter(is_screencast), | |
| 126 number_of_capturered_frames_(0), | |
| 127 width_(0), | |
| 128 height_(0) { | |
| 129 } | |
| 130 | |
| 131 void OnFrameCaptured(const scoped_refptr<media::VideoFrame>& frame) override { | |
| 132 ++number_of_capturered_frames_; | |
| 133 width_ = frame->visible_rect().width(); | |
| 134 height_ = frame->visible_rect().height(); | |
| 135 } | |
| 136 | |
| 137 int GetLastFrameWidth() const { | |
| 138 return width_; | |
| 139 } | |
| 140 | |
| 141 int GetLastFrameHeight() const { | |
| 142 return height_; | |
| 143 } | |
| 144 | |
| 145 int GetFrameNum() const { | |
| 146 return number_of_capturered_frames_; | |
| 147 } | |
| 148 | |
| 149 private: | |
| 150 int number_of_capturered_frames_; | |
| 151 int width_; | |
| 152 int height_; | |
| 153 }; | |
| 154 | |
| 155 scoped_refptr<MockWebRtcAudioTrack> MockWebRtcAudioTrack::Create( | 122 scoped_refptr<MockWebRtcAudioTrack> MockWebRtcAudioTrack::Create( |
| 156 const std::string& id) { | 123 const std::string& id) { |
| 157 return new rtc::RefCountedObject<MockWebRtcAudioTrack>(id); | 124 return new rtc::RefCountedObject<MockWebRtcAudioTrack>(id); |
| 158 } | 125 } |
| 159 | 126 |
| 160 MockWebRtcAudioTrack::MockWebRtcAudioTrack(const std::string& id) | 127 MockWebRtcAudioTrack::MockWebRtcAudioTrack(const std::string& id) |
| 161 : id_(id), | 128 : id_(id), |
| 162 enabled_(true), | 129 enabled_(true), |
| 163 state_(webrtc::MediaStreamTrackInterface::kLive) {} | 130 state_(webrtc::MediaStreamTrackInterface::kLive) {} |
| 164 | 131 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 MockPeerConnectionDependencyFactory::~MockPeerConnectionDependencyFactory() {} | 327 MockPeerConnectionDependencyFactory::~MockPeerConnectionDependencyFactory() {} |
| 361 | 328 |
| 362 scoped_refptr<webrtc::PeerConnectionInterface> | 329 scoped_refptr<webrtc::PeerConnectionInterface> |
| 363 MockPeerConnectionDependencyFactory::CreatePeerConnection( | 330 MockPeerConnectionDependencyFactory::CreatePeerConnection( |
| 364 const webrtc::PeerConnectionInterface::RTCConfiguration& config, | 331 const webrtc::PeerConnectionInterface::RTCConfiguration& config, |
| 365 blink::WebFrame* frame, | 332 blink::WebFrame* frame, |
| 366 webrtc::PeerConnectionObserver* observer) { | 333 webrtc::PeerConnectionObserver* observer) { |
| 367 return new rtc::RefCountedObject<MockPeerConnectionImpl>(this, observer); | 334 return new rtc::RefCountedObject<MockPeerConnectionImpl>(this, observer); |
| 368 } | 335 } |
| 369 | 336 |
| 370 WebRtcVideoCapturerAdapter* | |
| 371 MockPeerConnectionDependencyFactory::CreateVideoCapturer( | |
| 372 bool is_screen_capture) { | |
| 373 return new MockRtcVideoCapturer(is_screen_capture); | |
| 374 } | |
| 375 | |
| 376 scoped_refptr<webrtc::VideoTrackSourceInterface> | 337 scoped_refptr<webrtc::VideoTrackSourceInterface> |
| 377 MockPeerConnectionDependencyFactory::CreateVideoSource( | 338 MockPeerConnectionDependencyFactory::CreateVideoTrackSourceProxy( |
| 378 cricket::VideoCapturer* capturer) { | 339 webrtc::VideoTrackSourceInterface* source) { |
| 379 // Video source normally take ownership of |capturer|. | |
| 380 delete capturer; | |
| 381 NOTIMPLEMENTED(); | |
| 382 return nullptr; | 340 return nullptr; |
| 383 } | 341 } |
| 384 | |
| 385 scoped_refptr<webrtc::MediaStreamInterface> | 342 scoped_refptr<webrtc::MediaStreamInterface> |
| 386 MockPeerConnectionDependencyFactory::CreateLocalMediaStream( | 343 MockPeerConnectionDependencyFactory::CreateLocalMediaStream( |
| 387 const std::string& label) { | 344 const std::string& label) { |
| 388 return new rtc::RefCountedObject<MockMediaStream>(label); | 345 return new rtc::RefCountedObject<MockMediaStream>(label); |
| 389 } | 346 } |
| 390 | 347 |
| 391 scoped_refptr<webrtc::VideoTrackInterface> | 348 scoped_refptr<webrtc::VideoTrackInterface> |
| 392 MockPeerConnectionDependencyFactory::CreateLocalVideoTrack( | 349 MockPeerConnectionDependencyFactory::CreateLocalVideoTrack( |
| 393 const std::string& id, | 350 const std::string& id, |
| 394 webrtc::VideoTrackSourceInterface* source) { | 351 webrtc::VideoTrackSourceInterface* source) { |
| 395 scoped_refptr<webrtc::VideoTrackInterface> track( | 352 scoped_refptr<webrtc::VideoTrackInterface> track( |
| 396 new rtc::RefCountedObject<MockWebRtcVideoTrack>( | 353 new rtc::RefCountedObject<MockWebRtcVideoTrack>( |
| 397 id, source)); | 354 id, source)); |
| 398 return track; | 355 return track; |
| 399 } | 356 } |
| 400 | 357 |
| 401 scoped_refptr<webrtc::VideoTrackInterface> | |
| 402 MockPeerConnectionDependencyFactory::CreateLocalVideoTrack( | |
| 403 const std::string& id, | |
| 404 cricket::VideoCapturer* capturer) { | |
| 405 return new rtc::RefCountedObject<MockWebRtcVideoTrack>(id, nullptr); | |
| 406 } | |
| 407 | |
| 408 SessionDescriptionInterface* | 358 SessionDescriptionInterface* |
| 409 MockPeerConnectionDependencyFactory::CreateSessionDescription( | 359 MockPeerConnectionDependencyFactory::CreateSessionDescription( |
| 410 const std::string& type, | 360 const std::string& type, |
| 411 const std::string& sdp, | 361 const std::string& sdp, |
| 412 webrtc::SdpParseError* error) { | 362 webrtc::SdpParseError* error) { |
| 413 return new MockSessionDescription(type, sdp); | 363 return new MockSessionDescription(type, sdp); |
| 414 } | 364 } |
| 415 | 365 |
| 416 webrtc::IceCandidateInterface* | 366 webrtc::IceCandidateInterface* |
| 417 MockPeerConnectionDependencyFactory::CreateIceCandidate( | 367 MockPeerConnectionDependencyFactory::CreateIceCandidate( |
| 418 const std::string& sdp_mid, | 368 const std::string& sdp_mid, |
| 419 int sdp_mline_index, | 369 int sdp_mline_index, |
| 420 const std::string& sdp) { | 370 const std::string& sdp) { |
| 421 return new MockIceCandidate(sdp_mid, sdp_mline_index, sdp); | 371 return new MockIceCandidate(sdp_mid, sdp_mline_index, sdp); |
| 422 } | 372 } |
| 423 | 373 |
| 424 scoped_refptr<base::SingleThreadTaskRunner> | 374 scoped_refptr<base::SingleThreadTaskRunner> |
| 425 MockPeerConnectionDependencyFactory::GetWebRtcSignalingThread() const { | 375 MockPeerConnectionDependencyFactory::GetWebRtcSignalingThread() const { |
| 426 return signaling_thread_.task_runner(); | 376 return signaling_thread_.task_runner(); |
| 427 } | 377 } |
| 428 | 378 |
| 429 } // namespace content | 379 } // namespace content |
| OLD | NEW |