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"
17 class MockVideoSource
: public webrtc::VideoSourceInterface
{
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
;
27 virtual const cricket::VideoOptions
* options() const OVERRIDE
;
29 // Changes the state of the source to live and notifies the observer.
31 // Changes the state of the source to ended and notifies the observer.
35 virtual ~MockVideoSource();
38 webrtc::ObserverInterface
* observer_
;
39 MediaSourceInterface::SourceState state_
;
42 class MockAudioSource
: public webrtc::AudioSourceInterface
{
44 MockAudioSource(const webrtc::MediaConstraintsInterface
* constraints
);
46 virtual void RegisterObserver(webrtc::ObserverInterface
* observer
) OVERRIDE
;
47 virtual void UnregisterObserver(webrtc::ObserverInterface
* observer
) OVERRIDE
;
48 virtual MediaSourceInterface::SourceState
state() 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.
55 const webrtc::MediaConstraintsInterface::Constraints
& optional_constraints() {
56 return optional_constraints_
;
59 const webrtc::MediaConstraintsInterface::Constraints
&
60 mandatory_constraints() {
61 return mandatory_constraints_
;
65 virtual ~MockAudioSource();
68 webrtc::ObserverInterface
* observer_
;
69 MediaSourceInterface::SourceState state_
;
70 webrtc::MediaConstraintsInterface::Constraints optional_constraints_
;
71 webrtc::MediaConstraintsInterface::Constraints mandatory_constraints_
;
74 class MockLocalVideoTrack
: public webrtc::VideoTrackInterface
{
76 MockLocalVideoTrack(std::string id
,
77 webrtc::VideoSourceInterface
* source
);
78 virtual void AddRenderer(webrtc::VideoRendererInterface
* renderer
) OVERRIDE
;
79 virtual void RemoveRenderer(
80 webrtc::VideoRendererInterface
* renderer
) OVERRIDE
;
81 virtual cricket::VideoRenderer
* FrameInput() OVERRIDE
;
82 virtual std::string
kind() const OVERRIDE
;
83 virtual std::string
id() const OVERRIDE
;
84 virtual bool enabled() const OVERRIDE
;
85 virtual TrackState
state() const OVERRIDE
;
86 virtual bool set_enabled(bool enable
) OVERRIDE
;
87 virtual bool set_state(TrackState new_state
) OVERRIDE
;
88 virtual void RegisterObserver(webrtc::ObserverInterface
* observer
) OVERRIDE
;
89 virtual void UnregisterObserver(webrtc::ObserverInterface
* observer
) OVERRIDE
;
90 virtual webrtc::VideoSourceInterface
* GetSource() const OVERRIDE
;
93 virtual ~MockLocalVideoTrack();
98 scoped_refptr
<webrtc::VideoSourceInterface
> source_
;
101 class MockLocalAudioTrack
: public webrtc::AudioTrackInterface
{
103 explicit MockLocalAudioTrack(const std::string
& id
)
107 virtual std::string
kind() const OVERRIDE
;
108 virtual std::string
id() const OVERRIDE
;
109 virtual bool enabled() const OVERRIDE
;
110 virtual TrackState
state() const OVERRIDE
;
111 virtual bool set_enabled(bool enable
) OVERRIDE
;
112 virtual bool set_state(TrackState new_state
) OVERRIDE
;
113 virtual void RegisterObserver(webrtc::ObserverInterface
* observer
) OVERRIDE
;
114 virtual void UnregisterObserver(webrtc::ObserverInterface
* observer
) OVERRIDE
;
115 virtual webrtc::AudioSourceInterface
* GetSource() const OVERRIDE
;
118 virtual ~MockLocalAudioTrack() {}
125 // A mock factory for creating different objects for
126 // RTC MediaStreams and PeerConnections.
127 class MockMediaStreamDependencyFactory
: public MediaStreamDependencyFactory
{
129 MockMediaStreamDependencyFactory();
130 virtual ~MockMediaStreamDependencyFactory();
132 virtual scoped_refptr
<webrtc::PeerConnectionInterface
> CreatePeerConnection(
133 const webrtc::PeerConnectionInterface::IceServers
& ice_servers
,
134 const webrtc::MediaConstraintsInterface
* constraints
,
135 WebKit::WebFrame
* frame
,
136 webrtc::PeerConnectionObserver
* observer
) OVERRIDE
;
137 virtual scoped_refptr
<webrtc::AudioSourceInterface
>
138 CreateLocalAudioSource(
139 const webrtc::MediaConstraintsInterface
* constraints
) OVERRIDE
;
140 virtual scoped_refptr
<webrtc::VideoSourceInterface
>
141 CreateLocalVideoSource(
142 int video_session_id
,
144 const webrtc::MediaConstraintsInterface
* constraints
) OVERRIDE
;
145 virtual bool InitializeAudioSource(
146 const StreamDeviceInfo
& device_info
) OVERRIDE
;
147 virtual bool CreateWebAudioSource(
148 WebKit::WebMediaStreamSource
* source
) OVERRIDE
;
149 virtual scoped_refptr
<webrtc::MediaStreamInterface
>
150 CreateLocalMediaStream(const std::string
& label
) OVERRIDE
;
151 virtual scoped_refptr
<webrtc::VideoTrackInterface
>
152 CreateLocalVideoTrack(const std::string
& id
,
153 webrtc::VideoSourceInterface
* source
) OVERRIDE
;
154 virtual scoped_refptr
<webrtc::AudioTrackInterface
>
155 CreateLocalAudioTrack(const std::string
& id
,
156 webrtc::AudioSourceInterface
* source
) OVERRIDE
;
157 virtual webrtc::SessionDescriptionInterface
* CreateSessionDescription(
158 const std::string
& type
,
159 const std::string
& sdp
,
160 webrtc::SdpParseError
* error
) OVERRIDE
;
161 virtual webrtc::IceCandidateInterface
* CreateIceCandidate(
162 const std::string
& sdp_mid
,
164 const std::string
& sdp
) OVERRIDE
;
166 virtual bool EnsurePeerConnectionFactory() OVERRIDE
;
167 virtual bool PeerConnectionFactoryCreated() OVERRIDE
;
169 MockAudioSource
* last_audio_source() { return last_audio_source_
; }
170 MockVideoSource
* last_video_source() { return last_video_source_
; }
173 bool mock_pc_factory_created_
;
174 scoped_refptr
<MockAudioSource
> last_audio_source_
;
175 scoped_refptr
<MockVideoSource
> last_video_source_
;
177 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamDependencyFactory
);
180 } // namespace content
182 #endif // CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_