Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ |
| 6 | #define CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/compiler_specific.h" |
| 12 | #include "content/renderer/media/media_stream_dependency_factory.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 13 | #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 14 | |
| 15 | namespace content { |
| 16 | |
| 17 | class MockVideoSource : public webrtc::VideoSourceInterface { |
| 18 | public: |
| 19 | MockVideoSource(); |
| 20 | |
| 21 | virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; |
| 22 | virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; |
| 23 | virtual MediaSourceInterface::SourceState state() const OVERRIDE; |
| 24 | virtual cricket::VideoCapturer* GetVideoCapturer() OVERRIDE; |
| 25 | virtual void AddSink(cricket::VideoRenderer* output) OVERRIDE; |
| 26 | virtual void RemoveSink(cricket::VideoRenderer* output) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 27 | virtual const cricket::VideoOptions* options() const OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 28 | |
| 29 | // Changes the state of the source to live and notifies the observer. |
| 30 | void SetLive(); |
| 31 | // Changes the state of the source to ended and notifies the observer. |
| 32 | void SetEnded(); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 33 | // Set the video capturer. |
| 34 | void SetVideoCapturer(cricket::VideoCapturer* capturer); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 35 | |
| 36 | protected: |
| 37 | virtual ~MockVideoSource(); |
| 38 | |
| 39 | private: |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 40 | void FireOnChanged(); |
| 41 | |
| 42 | std::vector<webrtc::ObserverInterface*> observers_; |
| 43 | MediaSourceInterface::SourceState state_; |
| 44 | scoped_ptr<cricket::VideoCapturer> capturer_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 47 | class MockAudioSource : public webrtc::AudioSourceInterface { |
| 48 | public: |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 49 | explicit MockAudioSource( |
| 50 | const webrtc::MediaConstraintsInterface* constraints); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 51 | |
| 52 | virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; |
| 53 | virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; |
| 54 | virtual MediaSourceInterface::SourceState state() const OVERRIDE; |
| 55 | |
| 56 | // Changes the state of the source to live and notifies the observer. |
| 57 | void SetLive(); |
| 58 | // Changes the state of the source to ended and notifies the observer. |
| 59 | void SetEnded(); |
| 60 | |
| 61 | const webrtc::MediaConstraintsInterface::Constraints& optional_constraints() { |
| 62 | return optional_constraints_; |
| 63 | } |
| 64 | |
| 65 | const webrtc::MediaConstraintsInterface::Constraints& |
| 66 | mandatory_constraints() { |
| 67 | return mandatory_constraints_; |
| 68 | } |
| 69 | |
| 70 | protected: |
| 71 | virtual ~MockAudioSource(); |
| 72 | |
| 73 | private: |
| 74 | webrtc::ObserverInterface* observer_; |
| 75 | MediaSourceInterface::SourceState state_; |
| 76 | webrtc::MediaConstraintsInterface::Constraints optional_constraints_; |
| 77 | webrtc::MediaConstraintsInterface::Constraints mandatory_constraints_; |
| 78 | }; |
| 79 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 80 | class MockLocalVideoTrack : public webrtc::VideoTrackInterface { |
| 81 | public: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 82 | MockLocalVideoTrack(std::string id, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 83 | webrtc::VideoSourceInterface* source); |
| 84 | virtual void AddRenderer(webrtc::VideoRendererInterface* renderer) OVERRIDE; |
| 85 | virtual void RemoveRenderer( |
| 86 | webrtc::VideoRendererInterface* renderer) OVERRIDE; |
| 87 | virtual cricket::VideoRenderer* FrameInput() OVERRIDE; |
| 88 | virtual std::string kind() const OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 89 | virtual std::string id() const OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 90 | virtual bool enabled() const OVERRIDE; |
| 91 | virtual TrackState state() const OVERRIDE; |
| 92 | virtual bool set_enabled(bool enable) OVERRIDE; |
| 93 | virtual bool set_state(TrackState new_state) OVERRIDE; |
| 94 | virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; |
| 95 | virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; |
| 96 | virtual webrtc::VideoSourceInterface* GetSource() const OVERRIDE; |
| 97 | |
| 98 | protected: |
| 99 | virtual ~MockLocalVideoTrack(); |
| 100 | |
| 101 | private: |
| 102 | bool enabled_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 103 | std::string id_; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 104 | TrackState state_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 105 | scoped_refptr<webrtc::VideoSourceInterface> source_; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 106 | webrtc::ObserverInterface* observer_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 109 | // A mock factory for creating different objects for |
| 110 | // RTC MediaStreams and PeerConnections. |
| 111 | class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory { |
| 112 | public: |
| 113 | MockMediaStreamDependencyFactory(); |
| 114 | virtual ~MockMediaStreamDependencyFactory(); |
| 115 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 116 | virtual scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
| 117 | const webrtc::PeerConnectionInterface::IceServers& ice_servers, |
| 118 | const webrtc::MediaConstraintsInterface* constraints, |
| 119 | WebKit::WebFrame* frame, |
| 120 | webrtc::PeerConnectionObserver* observer) OVERRIDE; |
| 121 | virtual scoped_refptr<webrtc::AudioSourceInterface> |
| 122 | CreateLocalAudioSource( |
| 123 | const webrtc::MediaConstraintsInterface* constraints) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 124 | virtual scoped_refptr<webrtc::VideoSourceInterface> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 125 | CreateLocalVideoSource( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 126 | int video_session_id, |
| 127 | bool is_screencast, |
| 128 | const webrtc::MediaConstraintsInterface* constraints) OVERRIDE; |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 129 | virtual scoped_refptr<WebRtcAudioCapturer> CreateWebAudioSource( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 130 | WebKit::WebMediaStreamSource* source) OVERRIDE; |
| 131 | virtual scoped_refptr<webrtc::MediaStreamInterface> |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 132 | CreateLocalMediaStream(const std::string& label) OVERRIDE; |
| 133 | virtual scoped_refptr<webrtc::VideoTrackInterface> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 134 | CreateLocalVideoTrack(const std::string& id, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 135 | webrtc::VideoSourceInterface* source) OVERRIDE; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 136 | virtual scoped_refptr<webrtc::VideoTrackInterface> |
| 137 | CreateLocalVideoTrack(const std::string& id, |
| 138 | cricket::VideoCapturer* capturer) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 139 | virtual scoped_refptr<webrtc::AudioTrackInterface> |
| 140 | CreateLocalAudioTrack(const std::string& id, |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 141 | const scoped_refptr<WebRtcAudioCapturer>& capturer, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 142 | webrtc::AudioSourceInterface* source) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 143 | virtual webrtc::SessionDescriptionInterface* CreateSessionDescription( |
| 144 | const std::string& type, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 145 | const std::string& sdp, |
| 146 | webrtc::SdpParseError* error) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 147 | virtual webrtc::IceCandidateInterface* CreateIceCandidate( |
| 148 | const std::string& sdp_mid, |
| 149 | int sdp_mline_index, |
| 150 | const std::string& sdp) OVERRIDE; |
| 151 | |
| 152 | virtual bool EnsurePeerConnectionFactory() OVERRIDE; |
| 153 | virtual bool PeerConnectionFactoryCreated() OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 154 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 155 | virtual scoped_refptr<WebRtcAudioCapturer> MaybeCreateAudioCapturer( |
| 156 | int render_view_id, const StreamDeviceInfo& device_info) OVERRIDE; |
| 157 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 158 | MockAudioSource* last_audio_source() { return last_audio_source_.get(); } |
| 159 | MockVideoSource* last_video_source() { return last_video_source_.get(); } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 160 | |
| 161 | private: |
| 162 | bool mock_pc_factory_created_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 163 | scoped_refptr <MockAudioSource> last_audio_source_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 164 | scoped_refptr <MockVideoSource> last_video_source_; |
| 165 | |
| 166 | DISALLOW_COPY_AND_ASSIGN(MockMediaStreamDependencyFactory); |
| 167 | }; |
| 168 | |
| 169 | } // namespace content |
| 170 | |
| 171 | #endif // CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ |