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 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 13 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" | 14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" |
15 #include "third_party/libjingle/source/talk/media/base/videorenderer.h" | 15 #include "third_party/libjingle/source/talk/media/base/videorenderer.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 class WebAudioCapturerSource; | 19 class WebAudioCapturerSource; |
20 | 20 |
21 class MockVideoRenderer : public cricket::VideoRenderer { | 21 class MockVideoRenderer : public cricket::VideoRenderer { |
22 public: | 22 public: |
23 MockVideoRenderer(); | 23 MockVideoRenderer(); |
24 virtual ~MockVideoRenderer(); | 24 virtual ~MockVideoRenderer(); |
25 virtual bool SetSize(int width, int height, int reserved) OVERRIDE; | 25 virtual bool SetSize(int width, int height, int reserved) override; |
26 virtual bool RenderFrame(const cricket::VideoFrame* frame) OVERRIDE; | 26 virtual bool RenderFrame(const cricket::VideoFrame* frame) override; |
27 | 27 |
28 int width() const { return width_; } | 28 int width() const { return width_; } |
29 int height() const { return height_; } | 29 int height() const { return height_; } |
30 int num() const { return num_; } | 30 int num() const { return num_; } |
31 | 31 |
32 private: | 32 private: |
33 int width_; | 33 int width_; |
34 int height_; | 34 int height_; |
35 int num_; | 35 int num_; |
36 }; | 36 }; |
37 | 37 |
38 class MockVideoSource : public webrtc::VideoSourceInterface { | 38 class MockVideoSource : public webrtc::VideoSourceInterface { |
39 public: | 39 public: |
40 MockVideoSource(); | 40 MockVideoSource(); |
41 | 41 |
42 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; | 42 virtual void RegisterObserver(webrtc::ObserverInterface* observer) override; |
43 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; | 43 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) override; |
44 virtual MediaSourceInterface::SourceState state() const OVERRIDE; | 44 virtual MediaSourceInterface::SourceState state() const override; |
45 virtual cricket::VideoCapturer* GetVideoCapturer() OVERRIDE; | 45 virtual cricket::VideoCapturer* GetVideoCapturer() override; |
46 virtual void AddSink(cricket::VideoRenderer* output) OVERRIDE; | 46 virtual void AddSink(cricket::VideoRenderer* output) override; |
47 virtual void RemoveSink(cricket::VideoRenderer* output) OVERRIDE; | 47 virtual void RemoveSink(cricket::VideoRenderer* output) override; |
48 virtual cricket::VideoRenderer* FrameInput() OVERRIDE; | 48 virtual cricket::VideoRenderer* FrameInput() override; |
49 virtual const cricket::VideoOptions* options() const OVERRIDE; | 49 virtual const cricket::VideoOptions* options() const override; |
50 | 50 |
51 // Changes the state of the source to live and notifies the observer. | 51 // Changes the state of the source to live and notifies the observer. |
52 void SetLive(); | 52 void SetLive(); |
53 // Changes the state of the source to ended and notifies the observer. | 53 // Changes the state of the source to ended and notifies the observer. |
54 void SetEnded(); | 54 void SetEnded(); |
55 // Set the video capturer. | 55 // Set the video capturer. |
56 void SetVideoCapturer(cricket::VideoCapturer* capturer); | 56 void SetVideoCapturer(cricket::VideoCapturer* capturer); |
57 | 57 |
58 // Test helpers. | 58 // Test helpers. |
59 int GetLastFrameWidth() const; | 59 int GetLastFrameWidth() const; |
(...skipping 10 matching lines...) Expand all Loading... |
70 MediaSourceInterface::SourceState state_; | 70 MediaSourceInterface::SourceState state_; |
71 scoped_ptr<cricket::VideoCapturer> capturer_; | 71 scoped_ptr<cricket::VideoCapturer> capturer_; |
72 MockVideoRenderer renderer_; | 72 MockVideoRenderer renderer_; |
73 }; | 73 }; |
74 | 74 |
75 class MockAudioSource : public webrtc::AudioSourceInterface { | 75 class MockAudioSource : public webrtc::AudioSourceInterface { |
76 public: | 76 public: |
77 explicit MockAudioSource( | 77 explicit MockAudioSource( |
78 const webrtc::MediaConstraintsInterface* constraints); | 78 const webrtc::MediaConstraintsInterface* constraints); |
79 | 79 |
80 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; | 80 virtual void RegisterObserver(webrtc::ObserverInterface* observer) override; |
81 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; | 81 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) override; |
82 virtual MediaSourceInterface::SourceState state() const OVERRIDE; | 82 virtual MediaSourceInterface::SourceState state() const override; |
83 | 83 |
84 // Changes the state of the source to live and notifies the observer. | 84 // Changes the state of the source to live and notifies the observer. |
85 void SetLive(); | 85 void SetLive(); |
86 // Changes the state of the source to ended and notifies the observer. | 86 // Changes the state of the source to ended and notifies the observer. |
87 void SetEnded(); | 87 void SetEnded(); |
88 | 88 |
89 const webrtc::MediaConstraintsInterface::Constraints& optional_constraints() { | 89 const webrtc::MediaConstraintsInterface::Constraints& optional_constraints() { |
90 return optional_constraints_; | 90 return optional_constraints_; |
91 } | 91 } |
92 | 92 |
93 const webrtc::MediaConstraintsInterface::Constraints& | 93 const webrtc::MediaConstraintsInterface::Constraints& |
94 mandatory_constraints() { | 94 mandatory_constraints() { |
95 return mandatory_constraints_; | 95 return mandatory_constraints_; |
96 } | 96 } |
97 | 97 |
98 protected: | 98 protected: |
99 virtual ~MockAudioSource(); | 99 virtual ~MockAudioSource(); |
100 | 100 |
101 private: | 101 private: |
102 webrtc::ObserverInterface* observer_; | 102 webrtc::ObserverInterface* observer_; |
103 MediaSourceInterface::SourceState state_; | 103 MediaSourceInterface::SourceState state_; |
104 webrtc::MediaConstraintsInterface::Constraints optional_constraints_; | 104 webrtc::MediaConstraintsInterface::Constraints optional_constraints_; |
105 webrtc::MediaConstraintsInterface::Constraints mandatory_constraints_; | 105 webrtc::MediaConstraintsInterface::Constraints mandatory_constraints_; |
106 }; | 106 }; |
107 | 107 |
108 class MockWebRtcVideoTrack : public webrtc::VideoTrackInterface { | 108 class MockWebRtcVideoTrack : public webrtc::VideoTrackInterface { |
109 public: | 109 public: |
110 MockWebRtcVideoTrack(const std::string& id, | 110 MockWebRtcVideoTrack(const std::string& id, |
111 webrtc::VideoSourceInterface* source); | 111 webrtc::VideoSourceInterface* source); |
112 virtual void AddRenderer(webrtc::VideoRendererInterface* renderer) OVERRIDE; | 112 virtual void AddRenderer(webrtc::VideoRendererInterface* renderer) override; |
113 virtual void RemoveRenderer( | 113 virtual void RemoveRenderer( |
114 webrtc::VideoRendererInterface* renderer) OVERRIDE; | 114 webrtc::VideoRendererInterface* renderer) override; |
115 virtual std::string kind() const OVERRIDE; | 115 virtual std::string kind() const override; |
116 virtual std::string id() const OVERRIDE; | 116 virtual std::string id() const override; |
117 virtual bool enabled() const OVERRIDE; | 117 virtual bool enabled() const override; |
118 virtual TrackState state() const OVERRIDE; | 118 virtual TrackState state() const override; |
119 virtual bool set_enabled(bool enable) OVERRIDE; | 119 virtual bool set_enabled(bool enable) override; |
120 virtual bool set_state(TrackState new_state) OVERRIDE; | 120 virtual bool set_state(TrackState new_state) override; |
121 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; | 121 virtual void RegisterObserver(webrtc::ObserverInterface* observer) override; |
122 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; | 122 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) override; |
123 virtual webrtc::VideoSourceInterface* GetSource() const OVERRIDE; | 123 virtual webrtc::VideoSourceInterface* GetSource() const override; |
124 | 124 |
125 protected: | 125 protected: |
126 virtual ~MockWebRtcVideoTrack(); | 126 virtual ~MockWebRtcVideoTrack(); |
127 | 127 |
128 private: | 128 private: |
129 bool enabled_; | 129 bool enabled_; |
130 std::string id_; | 130 std::string id_; |
131 TrackState state_; | 131 TrackState state_; |
132 scoped_refptr<webrtc::VideoSourceInterface> source_; | 132 scoped_refptr<webrtc::VideoSourceInterface> source_; |
133 webrtc::ObserverInterface* observer_; | 133 webrtc::ObserverInterface* observer_; |
134 webrtc::VideoRendererInterface* renderer_; | 134 webrtc::VideoRendererInterface* renderer_; |
135 }; | 135 }; |
136 | 136 |
137 class MockMediaStream : public webrtc::MediaStreamInterface { | 137 class MockMediaStream : public webrtc::MediaStreamInterface { |
138 public: | 138 public: |
139 explicit MockMediaStream(const std::string& label); | 139 explicit MockMediaStream(const std::string& label); |
140 | 140 |
141 virtual bool AddTrack(webrtc::AudioTrackInterface* track) OVERRIDE; | 141 virtual bool AddTrack(webrtc::AudioTrackInterface* track) override; |
142 virtual bool AddTrack(webrtc::VideoTrackInterface* track) OVERRIDE; | 142 virtual bool AddTrack(webrtc::VideoTrackInterface* track) override; |
143 virtual bool RemoveTrack(webrtc::AudioTrackInterface* track) OVERRIDE; | 143 virtual bool RemoveTrack(webrtc::AudioTrackInterface* track) override; |
144 virtual bool RemoveTrack(webrtc::VideoTrackInterface* track) OVERRIDE; | 144 virtual bool RemoveTrack(webrtc::VideoTrackInterface* track) override; |
145 virtual std::string label() const OVERRIDE; | 145 virtual std::string label() const override; |
146 virtual webrtc::AudioTrackVector GetAudioTracks() OVERRIDE; | 146 virtual webrtc::AudioTrackVector GetAudioTracks() override; |
147 virtual webrtc::VideoTrackVector GetVideoTracks() OVERRIDE; | 147 virtual webrtc::VideoTrackVector GetVideoTracks() override; |
148 virtual rtc::scoped_refptr<webrtc::AudioTrackInterface> | 148 virtual rtc::scoped_refptr<webrtc::AudioTrackInterface> |
149 FindAudioTrack(const std::string& track_id) OVERRIDE; | 149 FindAudioTrack(const std::string& track_id) override; |
150 virtual rtc::scoped_refptr<webrtc::VideoTrackInterface> | 150 virtual rtc::scoped_refptr<webrtc::VideoTrackInterface> |
151 FindVideoTrack(const std::string& track_id) OVERRIDE; | 151 FindVideoTrack(const std::string& track_id) override; |
152 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; | 152 virtual void RegisterObserver(webrtc::ObserverInterface* observer) override; |
153 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE; | 153 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) override; |
154 | 154 |
155 protected: | 155 protected: |
156 virtual ~MockMediaStream(); | 156 virtual ~MockMediaStream(); |
157 | 157 |
158 private: | 158 private: |
159 void NotifyObservers(); | 159 void NotifyObservers(); |
160 | 160 |
161 std::string label_; | 161 std::string label_; |
162 webrtc::AudioTrackVector audio_track_vector_; | 162 webrtc::AudioTrackVector audio_track_vector_; |
163 webrtc::VideoTrackVector video_track_vector_; | 163 webrtc::VideoTrackVector video_track_vector_; |
164 | 164 |
165 typedef std::set<webrtc::ObserverInterface*> ObserverSet; | 165 typedef std::set<webrtc::ObserverInterface*> ObserverSet; |
166 ObserverSet observers_; | 166 ObserverSet observers_; |
167 }; | 167 }; |
168 | 168 |
169 // A mock factory for creating different objects for | 169 // A mock factory for creating different objects for |
170 // RTC PeerConnections. | 170 // RTC PeerConnections. |
171 class MockPeerConnectionDependencyFactory | 171 class MockPeerConnectionDependencyFactory |
172 : public PeerConnectionDependencyFactory { | 172 : public PeerConnectionDependencyFactory { |
173 public: | 173 public: |
174 MockPeerConnectionDependencyFactory(); | 174 MockPeerConnectionDependencyFactory(); |
175 virtual ~MockPeerConnectionDependencyFactory(); | 175 virtual ~MockPeerConnectionDependencyFactory(); |
176 | 176 |
177 virtual scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( | 177 virtual scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
178 const webrtc::PeerConnectionInterface::RTCConfiguration& config, | 178 const webrtc::PeerConnectionInterface::RTCConfiguration& config, |
179 const webrtc::MediaConstraintsInterface* constraints, | 179 const webrtc::MediaConstraintsInterface* constraints, |
180 blink::WebFrame* frame, | 180 blink::WebFrame* frame, |
181 webrtc::PeerConnectionObserver* observer) OVERRIDE; | 181 webrtc::PeerConnectionObserver* observer) override; |
182 virtual scoped_refptr<webrtc::AudioSourceInterface> | 182 virtual scoped_refptr<webrtc::AudioSourceInterface> |
183 CreateLocalAudioSource( | 183 CreateLocalAudioSource( |
184 const webrtc::MediaConstraintsInterface* constraints) OVERRIDE; | 184 const webrtc::MediaConstraintsInterface* constraints) override; |
185 virtual WebRtcVideoCapturerAdapter* CreateVideoCapturer( | 185 virtual WebRtcVideoCapturerAdapter* CreateVideoCapturer( |
186 bool is_screen_capture) OVERRIDE; | 186 bool is_screen_capture) override; |
187 virtual scoped_refptr<webrtc::VideoSourceInterface> | 187 virtual scoped_refptr<webrtc::VideoSourceInterface> |
188 CreateVideoSource( | 188 CreateVideoSource( |
189 cricket::VideoCapturer* capturer, | 189 cricket::VideoCapturer* capturer, |
190 const blink::WebMediaConstraints& constraints) OVERRIDE; | 190 const blink::WebMediaConstraints& constraints) override; |
191 virtual scoped_refptr<WebAudioCapturerSource> CreateWebAudioSource( | 191 virtual scoped_refptr<WebAudioCapturerSource> CreateWebAudioSource( |
192 blink::WebMediaStreamSource* source) OVERRIDE; | 192 blink::WebMediaStreamSource* source) override; |
193 virtual scoped_refptr<webrtc::MediaStreamInterface> | 193 virtual scoped_refptr<webrtc::MediaStreamInterface> |
194 CreateLocalMediaStream(const std::string& label) OVERRIDE; | 194 CreateLocalMediaStream(const std::string& label) override; |
195 virtual scoped_refptr<webrtc::VideoTrackInterface> | 195 virtual scoped_refptr<webrtc::VideoTrackInterface> |
196 CreateLocalVideoTrack(const std::string& id, | 196 CreateLocalVideoTrack(const std::string& id, |
197 webrtc::VideoSourceInterface* source) OVERRIDE; | 197 webrtc::VideoSourceInterface* source) override; |
198 virtual scoped_refptr<webrtc::VideoTrackInterface> | 198 virtual scoped_refptr<webrtc::VideoTrackInterface> |
199 CreateLocalVideoTrack(const std::string& id, | 199 CreateLocalVideoTrack(const std::string& id, |
200 cricket::VideoCapturer* capturer) OVERRIDE; | 200 cricket::VideoCapturer* capturer) override; |
201 virtual webrtc::SessionDescriptionInterface* CreateSessionDescription( | 201 virtual webrtc::SessionDescriptionInterface* CreateSessionDescription( |
202 const std::string& type, | 202 const std::string& type, |
203 const std::string& sdp, | 203 const std::string& sdp, |
204 webrtc::SdpParseError* error) OVERRIDE; | 204 webrtc::SdpParseError* error) override; |
205 virtual webrtc::IceCandidateInterface* CreateIceCandidate( | 205 virtual webrtc::IceCandidateInterface* CreateIceCandidate( |
206 const std::string& sdp_mid, | 206 const std::string& sdp_mid, |
207 int sdp_mline_index, | 207 int sdp_mline_index, |
208 const std::string& sdp) OVERRIDE; | 208 const std::string& sdp) override; |
209 | 209 |
210 virtual scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer( | 210 virtual scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer( |
211 int render_view_id, const StreamDeviceInfo& device_info, | 211 int render_view_id, const StreamDeviceInfo& device_info, |
212 const blink::WebMediaConstraints& constraints, | 212 const blink::WebMediaConstraints& constraints, |
213 MediaStreamAudioSource* audio_source) OVERRIDE; | 213 MediaStreamAudioSource* audio_source) override; |
214 void FailToCreateNextAudioCapturer() { | 214 void FailToCreateNextAudioCapturer() { |
215 fail_to_create_next_audio_capturer_ = true; | 215 fail_to_create_next_audio_capturer_ = true; |
216 } | 216 } |
217 | 217 |
218 virtual void StartLocalAudioTrack( | 218 virtual void StartLocalAudioTrack( |
219 WebRtcLocalAudioTrack* audio_track) OVERRIDE; | 219 WebRtcLocalAudioTrack* audio_track) override; |
220 | 220 |
221 MockAudioSource* last_audio_source() { return last_audio_source_.get(); } | 221 MockAudioSource* last_audio_source() { return last_audio_source_.get(); } |
222 MockVideoSource* last_video_source() { return last_video_source_.get(); } | 222 MockVideoSource* last_video_source() { return last_video_source_.get(); } |
223 | 223 |
224 private: | 224 private: |
225 bool fail_to_create_next_audio_capturer_; | 225 bool fail_to_create_next_audio_capturer_; |
226 scoped_refptr <MockAudioSource> last_audio_source_; | 226 scoped_refptr <MockAudioSource> last_audio_source_; |
227 scoped_refptr <MockVideoSource> last_video_source_; | 227 scoped_refptr <MockVideoSource> last_video_source_; |
228 | 228 |
229 DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionDependencyFactory); | 229 DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionDependencyFactory); |
230 }; | 230 }; |
231 | 231 |
232 } // namespace content | 232 } // namespace content |
233 | 233 |
234 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY
_H_ | 234 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY
_H_ |
OLD | NEW |