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 ~MockVideoRenderer() override; |
25 virtual bool SetSize(int width, int height, int reserved) override; | 25 bool SetSize(int width, int height, int reserved) override; |
26 virtual bool RenderFrame(const cricket::VideoFrame* frame) override; | 26 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 void RegisterObserver(webrtc::ObserverInterface* observer) override; |
43 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) override; | 43 void UnregisterObserver(webrtc::ObserverInterface* observer) override; |
44 virtual MediaSourceInterface::SourceState state() const override; | 44 MediaSourceInterface::SourceState state() const override; |
45 virtual cricket::VideoCapturer* GetVideoCapturer() override; | 45 cricket::VideoCapturer* GetVideoCapturer() override; |
46 virtual void AddSink(cricket::VideoRenderer* output) override; | 46 void AddSink(cricket::VideoRenderer* output) override; |
47 virtual void RemoveSink(cricket::VideoRenderer* output) override; | 47 void RemoveSink(cricket::VideoRenderer* output) override; |
48 virtual cricket::VideoRenderer* FrameInput() override; | 48 cricket::VideoRenderer* FrameInput() override; |
49 virtual const cricket::VideoOptions* options() const override; | 49 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; |
60 int GetLastFrameHeight() const; | 60 int GetLastFrameHeight() const; |
61 int GetFrameNum() const; | 61 int GetFrameNum() const; |
62 | 62 |
63 protected: | 63 protected: |
64 virtual ~MockVideoSource(); | 64 ~MockVideoSource() override; |
65 | 65 |
66 private: | 66 private: |
67 void FireOnChanged(); | 67 void FireOnChanged(); |
68 | 68 |
69 std::vector<webrtc::ObserverInterface*> observers_; | 69 std::vector<webrtc::ObserverInterface*> observers_; |
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 void RegisterObserver(webrtc::ObserverInterface* observer) override; |
81 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) override; | 81 void UnregisterObserver(webrtc::ObserverInterface* observer) override; |
82 virtual MediaSourceInterface::SourceState state() const override; | 82 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 ~MockAudioSource() override; |
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 void AddRenderer(webrtc::VideoRendererInterface* renderer) override; |
113 virtual void RemoveRenderer( | 113 void RemoveRenderer(webrtc::VideoRendererInterface* renderer) override; |
114 webrtc::VideoRendererInterface* renderer) override; | 114 std::string kind() const override; |
115 virtual std::string kind() const override; | 115 std::string id() const override; |
116 virtual std::string id() const override; | 116 bool enabled() const override; |
117 virtual bool enabled() const override; | 117 TrackState state() const override; |
118 virtual TrackState state() const override; | 118 bool set_enabled(bool enable) override; |
119 virtual bool set_enabled(bool enable) override; | 119 bool set_state(TrackState new_state) override; |
120 virtual bool set_state(TrackState new_state) override; | 120 void RegisterObserver(webrtc::ObserverInterface* observer) override; |
121 virtual void RegisterObserver(webrtc::ObserverInterface* observer) override; | 121 void UnregisterObserver(webrtc::ObserverInterface* observer) override; |
122 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) override; | 122 webrtc::VideoSourceInterface* GetSource() const override; |
123 virtual webrtc::VideoSourceInterface* GetSource() const override; | |
124 | 123 |
125 protected: | 124 protected: |
126 virtual ~MockWebRtcVideoTrack(); | 125 ~MockWebRtcVideoTrack() override; |
127 | 126 |
128 private: | 127 private: |
129 bool enabled_; | 128 bool enabled_; |
130 std::string id_; | 129 std::string id_; |
131 TrackState state_; | 130 TrackState state_; |
132 scoped_refptr<webrtc::VideoSourceInterface> source_; | 131 scoped_refptr<webrtc::VideoSourceInterface> source_; |
133 webrtc::ObserverInterface* observer_; | 132 webrtc::ObserverInterface* observer_; |
134 webrtc::VideoRendererInterface* renderer_; | 133 webrtc::VideoRendererInterface* renderer_; |
135 }; | 134 }; |
136 | 135 |
137 class MockMediaStream : public webrtc::MediaStreamInterface { | 136 class MockMediaStream : public webrtc::MediaStreamInterface { |
138 public: | 137 public: |
139 explicit MockMediaStream(const std::string& label); | 138 explicit MockMediaStream(const std::string& label); |
140 | 139 |
141 virtual bool AddTrack(webrtc::AudioTrackInterface* track) override; | 140 bool AddTrack(webrtc::AudioTrackInterface* track) override; |
142 virtual bool AddTrack(webrtc::VideoTrackInterface* track) override; | 141 bool AddTrack(webrtc::VideoTrackInterface* track) override; |
143 virtual bool RemoveTrack(webrtc::AudioTrackInterface* track) override; | 142 bool RemoveTrack(webrtc::AudioTrackInterface* track) override; |
144 virtual bool RemoveTrack(webrtc::VideoTrackInterface* track) override; | 143 bool RemoveTrack(webrtc::VideoTrackInterface* track) override; |
145 virtual std::string label() const override; | 144 std::string label() const override; |
146 virtual webrtc::AudioTrackVector GetAudioTracks() override; | 145 webrtc::AudioTrackVector GetAudioTracks() override; |
147 virtual webrtc::VideoTrackVector GetVideoTracks() override; | 146 webrtc::VideoTrackVector GetVideoTracks() override; |
148 virtual rtc::scoped_refptr<webrtc::AudioTrackInterface> | 147 rtc::scoped_refptr<webrtc::AudioTrackInterface> FindAudioTrack( |
149 FindAudioTrack(const std::string& track_id) override; | 148 const std::string& track_id) override; |
150 virtual rtc::scoped_refptr<webrtc::VideoTrackInterface> | 149 rtc::scoped_refptr<webrtc::VideoTrackInterface> FindVideoTrack( |
151 FindVideoTrack(const std::string& track_id) override; | 150 const std::string& track_id) override; |
152 virtual void RegisterObserver(webrtc::ObserverInterface* observer) override; | 151 void RegisterObserver(webrtc::ObserverInterface* observer) override; |
153 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) override; | 152 void UnregisterObserver(webrtc::ObserverInterface* observer) override; |
154 | 153 |
155 protected: | 154 protected: |
156 virtual ~MockMediaStream(); | 155 ~MockMediaStream() override; |
157 | 156 |
158 private: | 157 private: |
159 void NotifyObservers(); | 158 void NotifyObservers(); |
160 | 159 |
161 std::string label_; | 160 std::string label_; |
162 webrtc::AudioTrackVector audio_track_vector_; | 161 webrtc::AudioTrackVector audio_track_vector_; |
163 webrtc::VideoTrackVector video_track_vector_; | 162 webrtc::VideoTrackVector video_track_vector_; |
164 | 163 |
165 typedef std::set<webrtc::ObserverInterface*> ObserverSet; | 164 typedef std::set<webrtc::ObserverInterface*> ObserverSet; |
166 ObserverSet observers_; | 165 ObserverSet observers_; |
167 }; | 166 }; |
168 | 167 |
169 // A mock factory for creating different objects for | 168 // A mock factory for creating different objects for |
170 // RTC PeerConnections. | 169 // RTC PeerConnections. |
171 class MockPeerConnectionDependencyFactory | 170 class MockPeerConnectionDependencyFactory |
172 : public PeerConnectionDependencyFactory { | 171 : public PeerConnectionDependencyFactory { |
173 public: | 172 public: |
174 MockPeerConnectionDependencyFactory(); | 173 MockPeerConnectionDependencyFactory(); |
175 virtual ~MockPeerConnectionDependencyFactory(); | 174 ~MockPeerConnectionDependencyFactory() override; |
176 | 175 |
177 virtual scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( | 176 scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
178 const webrtc::PeerConnectionInterface::RTCConfiguration& config, | 177 const webrtc::PeerConnectionInterface::RTCConfiguration& config, |
179 const webrtc::MediaConstraintsInterface* constraints, | 178 const webrtc::MediaConstraintsInterface* constraints, |
180 blink::WebFrame* frame, | 179 blink::WebFrame* frame, |
181 webrtc::PeerConnectionObserver* observer) override; | 180 webrtc::PeerConnectionObserver* observer) override; |
182 virtual scoped_refptr<webrtc::AudioSourceInterface> | 181 scoped_refptr<webrtc::AudioSourceInterface> CreateLocalAudioSource( |
183 CreateLocalAudioSource( | 182 const webrtc::MediaConstraintsInterface* constraints) override; |
184 const webrtc::MediaConstraintsInterface* constraints) override; | 183 WebRtcVideoCapturerAdapter* CreateVideoCapturer( |
185 virtual WebRtcVideoCapturerAdapter* CreateVideoCapturer( | |
186 bool is_screen_capture) override; | 184 bool is_screen_capture) override; |
187 virtual scoped_refptr<webrtc::VideoSourceInterface> | 185 scoped_refptr<webrtc::VideoSourceInterface> CreateVideoSource( |
188 CreateVideoSource( | 186 cricket::VideoCapturer* capturer, |
189 cricket::VideoCapturer* capturer, | 187 const blink::WebMediaConstraints& constraints) override; |
190 const blink::WebMediaConstraints& constraints) override; | 188 scoped_refptr<WebAudioCapturerSource> CreateWebAudioSource( |
191 virtual scoped_refptr<WebAudioCapturerSource> CreateWebAudioSource( | |
192 blink::WebMediaStreamSource* source) override; | 189 blink::WebMediaStreamSource* source) override; |
193 virtual scoped_refptr<webrtc::MediaStreamInterface> | 190 scoped_refptr<webrtc::MediaStreamInterface> CreateLocalMediaStream( |
194 CreateLocalMediaStream(const std::string& label) override; | 191 const std::string& label) override; |
195 virtual scoped_refptr<webrtc::VideoTrackInterface> | 192 scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack( |
196 CreateLocalVideoTrack(const std::string& id, | 193 const std::string& id, |
197 webrtc::VideoSourceInterface* source) override; | 194 webrtc::VideoSourceInterface* source) override; |
198 virtual scoped_refptr<webrtc::VideoTrackInterface> | 195 scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack( |
199 CreateLocalVideoTrack(const std::string& id, | 196 const std::string& id, |
200 cricket::VideoCapturer* capturer) override; | 197 cricket::VideoCapturer* capturer) override; |
201 virtual webrtc::SessionDescriptionInterface* CreateSessionDescription( | 198 webrtc::SessionDescriptionInterface* CreateSessionDescription( |
202 const std::string& type, | 199 const std::string& type, |
203 const std::string& sdp, | 200 const std::string& sdp, |
204 webrtc::SdpParseError* error) override; | 201 webrtc::SdpParseError* error) override; |
205 virtual webrtc::IceCandidateInterface* CreateIceCandidate( | 202 webrtc::IceCandidateInterface* CreateIceCandidate( |
206 const std::string& sdp_mid, | 203 const std::string& sdp_mid, |
207 int sdp_mline_index, | 204 int sdp_mline_index, |
208 const std::string& sdp) override; | 205 const std::string& sdp) override; |
209 | 206 |
210 virtual scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer( | 207 scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer( |
211 int render_view_id, const StreamDeviceInfo& device_info, | 208 int render_view_id, |
| 209 const StreamDeviceInfo& device_info, |
212 const blink::WebMediaConstraints& constraints, | 210 const blink::WebMediaConstraints& constraints, |
213 MediaStreamAudioSource* audio_source) override; | 211 MediaStreamAudioSource* audio_source) override; |
214 void FailToCreateNextAudioCapturer() { | 212 void FailToCreateNextAudioCapturer() { |
215 fail_to_create_next_audio_capturer_ = true; | 213 fail_to_create_next_audio_capturer_ = true; |
216 } | 214 } |
217 | 215 |
218 virtual void StartLocalAudioTrack( | 216 void StartLocalAudioTrack(WebRtcLocalAudioTrack* audio_track) override; |
219 WebRtcLocalAudioTrack* audio_track) override; | |
220 | 217 |
221 MockAudioSource* last_audio_source() { return last_audio_source_.get(); } | 218 MockAudioSource* last_audio_source() { return last_audio_source_.get(); } |
222 MockVideoSource* last_video_source() { return last_video_source_.get(); } | 219 MockVideoSource* last_video_source() { return last_video_source_.get(); } |
223 | 220 |
224 private: | 221 private: |
225 bool fail_to_create_next_audio_capturer_; | 222 bool fail_to_create_next_audio_capturer_; |
226 scoped_refptr <MockAudioSource> last_audio_source_; | 223 scoped_refptr <MockAudioSource> last_audio_source_; |
227 scoped_refptr <MockVideoSource> last_video_source_; | 224 scoped_refptr <MockVideoSource> last_video_source_; |
228 | 225 |
229 DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionDependencyFactory); | 226 DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionDependencyFactory); |
230 }; | 227 }; |
231 | 228 |
232 } // namespace content | 229 } // namespace content |
233 | 230 |
234 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY
_H_ | 231 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY
_H_ |
OLD | NEW |