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.
5 #ifndef CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_
6 #define CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_
11 #include "base/compiler_specific.h"
12 #include "content/renderer/media/media_stream_dependency_factory.h"
13 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h"
14 #include "third_party/libjingle/source/talk/media/base/videorenderer.h"
18 class WebAudioCapturerSource;
20 class MockVideoRenderer : public cricket::VideoRenderer {
23 virtual ~MockVideoRenderer();
24 virtual bool SetSize(int width, int height, int reserved) OVERRIDE;
25 virtual bool RenderFrame(const cricket::VideoFrame* frame) OVERRIDE;
27 int width() const { return width_; }
28 int height() const { return height_; }
29 int num() const { return num_; }
37 class MockVideoSource : public webrtc::VideoSourceInterface {
41 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
42 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
43 virtual MediaSourceInterface::SourceState state() const OVERRIDE;
44 virtual cricket::VideoCapturer* GetVideoCapturer() OVERRIDE;
45 virtual void AddSink(cricket::VideoRenderer* output) OVERRIDE;
46 virtual void RemoveSink(cricket::VideoRenderer* output) OVERRIDE;
47 virtual cricket::VideoRenderer* FrameInput() OVERRIDE;
48 virtual const cricket::VideoOptions* options() const OVERRIDE;
50 // Changes the state of the source to live and notifies the observer.
52 // Changes the state of the source to ended and notifies the observer.
54 // Set the video capturer.
55 void SetVideoCapturer(cricket::VideoCapturer* capturer);
58 int GetLastFrameWidth() const;
59 int GetLastFrameHeight() const;
60 int GetFrameNum() const;
63 virtual ~MockVideoSource();
68 std::vector<webrtc::ObserverInterface*> observers_;
69 MediaSourceInterface::SourceState state_;
70 scoped_ptr<cricket::VideoCapturer> capturer_;
71 MockVideoRenderer renderer_;
74 class MockAudioSource : public webrtc::AudioSourceInterface {
76 explicit MockAudioSource(
77 const webrtc::MediaConstraintsInterface* constraints);
79 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
80 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
81 virtual MediaSourceInterface::SourceState state() const OVERRIDE;
83 // Changes the state of the source to live and notifies the observer.
85 // Changes the state of the source to ended and notifies the observer.
88 const webrtc::MediaConstraintsInterface::Constraints& optional_constraints() {
89 return optional_constraints_;
92 const webrtc::MediaConstraintsInterface::Constraints&
93 mandatory_constraints() {
94 return mandatory_constraints_;
98 virtual ~MockAudioSource();
101 webrtc::ObserverInterface* observer_;
102 MediaSourceInterface::SourceState state_;
103 webrtc::MediaConstraintsInterface::Constraints optional_constraints_;
104 webrtc::MediaConstraintsInterface::Constraints mandatory_constraints_;
107 class MockWebRtcVideoTrack : public webrtc::VideoTrackInterface {
109 MockWebRtcVideoTrack(const std::string& id,
110 webrtc::VideoSourceInterface* source);
111 virtual void AddRenderer(webrtc::VideoRendererInterface* renderer) OVERRIDE;
112 virtual void RemoveRenderer(
113 webrtc::VideoRendererInterface* renderer) OVERRIDE;
114 virtual std::string kind() const OVERRIDE;
115 virtual std::string id() const OVERRIDE;
116 virtual bool enabled() const OVERRIDE;
117 virtual TrackState state() const OVERRIDE;
118 virtual bool set_enabled(bool enable) OVERRIDE;
119 virtual bool set_state(TrackState new_state) OVERRIDE;
120 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
121 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
122 virtual webrtc::VideoSourceInterface* GetSource() const OVERRIDE;
125 virtual ~MockWebRtcVideoTrack();
131 scoped_refptr<webrtc::VideoSourceInterface> source_;
132 webrtc::ObserverInterface* observer_;
133 webrtc::VideoRendererInterface* renderer_;
136 class MockMediaStream : public webrtc::MediaStreamInterface {
138 explicit MockMediaStream(const std::string& label);
140 virtual bool AddTrack(webrtc::AudioTrackInterface* track) OVERRIDE;
141 virtual bool AddTrack(webrtc::VideoTrackInterface* track) OVERRIDE;
142 virtual bool RemoveTrack(webrtc::AudioTrackInterface* track) OVERRIDE;
143 virtual bool RemoveTrack(webrtc::VideoTrackInterface* track) OVERRIDE;
144 virtual std::string label() const OVERRIDE;
145 virtual webrtc::AudioTrackVector GetAudioTracks() OVERRIDE;
146 virtual webrtc::VideoTrackVector GetVideoTracks() OVERRIDE;
147 virtual talk_base::scoped_refptr<webrtc::AudioTrackInterface>
148 FindAudioTrack(const std::string& track_id) OVERRIDE;
149 virtual talk_base::scoped_refptr<webrtc::VideoTrackInterface>
150 FindVideoTrack(const std::string& track_id) OVERRIDE;
151 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
152 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
155 virtual ~MockMediaStream();
158 void NotifyObservers();
161 webrtc::AudioTrackVector audio_track_vector_;
162 webrtc::VideoTrackVector video_track_vector_;
164 typedef std::set<webrtc::ObserverInterface*> ObserverSet;
165 ObserverSet observers_;
168 // A mock factory for creating different objects for
169 // RTC MediaStreams and PeerConnections.
170 class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory {
172 MockMediaStreamDependencyFactory();
173 virtual ~MockMediaStreamDependencyFactory();
175 virtual scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
176 const webrtc::PeerConnectionInterface::IceServers& ice_servers,
177 const webrtc::MediaConstraintsInterface* constraints,
178 blink::WebFrame* frame,
179 webrtc::PeerConnectionObserver* observer) OVERRIDE;
180 virtual scoped_refptr<webrtc::AudioSourceInterface>
181 CreateLocalAudioSource(
182 const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
183 virtual WebRtcVideoCapturerAdapter* CreateVideoCapturer(
184 bool is_screen_capture) OVERRIDE;
185 virtual scoped_refptr<webrtc::VideoSourceInterface>
187 cricket::VideoCapturer* capturer,
188 const blink::WebMediaConstraints& constraints) OVERRIDE;
189 virtual scoped_refptr<WebAudioCapturerSource> CreateWebAudioSource(
190 blink::WebMediaStreamSource* source) OVERRIDE;
191 virtual scoped_refptr<webrtc::MediaStreamInterface>
192 CreateLocalMediaStream(const std::string& label) OVERRIDE;
193 virtual scoped_refptr<webrtc::VideoTrackInterface>
194 CreateLocalVideoTrack(const std::string& id,
195 webrtc::VideoSourceInterface* source) OVERRIDE;
196 virtual scoped_refptr<webrtc::VideoTrackInterface>
197 CreateLocalVideoTrack(const std::string& id,
198 cricket::VideoCapturer* capturer) OVERRIDE;
199 virtual webrtc::SessionDescriptionInterface* CreateSessionDescription(
200 const std::string& type,
201 const std::string& sdp,
202 webrtc::SdpParseError* error) OVERRIDE;
203 virtual webrtc::IceCandidateInterface* CreateIceCandidate(
204 const std::string& sdp_mid,
206 const std::string& sdp) OVERRIDE;
208 virtual scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer(
209 int render_view_id, const StreamDeviceInfo& device_info,
210 const blink::WebMediaConstraints& constraints,
211 MediaStreamAudioSource* audio_source) OVERRIDE;
212 void FailToCreateNextAudioCapturer() {
213 fail_to_create_next_audio_capturer_ = true;
216 virtual void StartLocalAudioTrack(
217 WebRtcLocalAudioTrack* audio_track) OVERRIDE;
219 MockAudioSource* last_audio_source() { return last_audio_source_.get(); }
220 MockVideoSource* last_video_source() { return last_video_source_.get(); }
223 bool fail_to_create_next_audio_capturer_;
224 scoped_refptr <MockAudioSource> last_audio_source_;
225 scoped_refptr <MockVideoSource> last_video_source_;
227 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamDependencyFactory);
230 } // namespace content
232 #endif // CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_