1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_
#define CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "content/renderer/media/media_stream_dependency_factory.h"
#include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h"
#include "third_party/libjingle/source/talk/media/base/videorenderer.h"
namespace content {
class WebAudioCapturerSource;
class MockVideoRenderer : public cricket::VideoRenderer {
public:
MockVideoRenderer();
virtual ~MockVideoRenderer();
virtual bool SetSize(int width, int height, int reserved) OVERRIDE;
virtual bool RenderFrame(const cricket::VideoFrame* frame) OVERRIDE;
int width() const { return width_; }
int height() const { return height_; }
int num() const { return num_; }
private:
int width_;
int height_;
int num_;
};
class MockVideoSource : public webrtc::VideoSourceInterface {
public:
MockVideoSource();
virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
virtual MediaSourceInterface::SourceState state() const OVERRIDE;
virtual cricket::VideoCapturer* GetVideoCapturer() OVERRIDE;
virtual void AddSink(cricket::VideoRenderer* output) OVERRIDE;
virtual void RemoveSink(cricket::VideoRenderer* output) OVERRIDE;
virtual cricket::VideoRenderer* FrameInput() OVERRIDE;
virtual const cricket::VideoOptions* options() const OVERRIDE;
// Changes the state of the source to live and notifies the observer.
void SetLive();
// Changes the state of the source to ended and notifies the observer.
void SetEnded();
// Set the video capturer.
void SetVideoCapturer(cricket::VideoCapturer* capturer);
// Test helpers.
int GetLastFrameWidth() const { return renderer_.width(); }
int GetLastFrameHeight() const { return renderer_.height(); }
int GetFrameNum() const { return renderer_.num(); }
protected:
virtual ~MockVideoSource();
private:
void FireOnChanged();
std::vector<webrtc::ObserverInterface*> observers_;
MediaSourceInterface::SourceState state_;
scoped_ptr<cricket::VideoCapturer> capturer_;
MockVideoRenderer renderer_;
};
class MockAudioSource : public webrtc::AudioSourceInterface {
public:
explicit MockAudioSource(
const webrtc::MediaConstraintsInterface* constraints);
virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
virtual MediaSourceInterface::SourceState state() const OVERRIDE;
// Changes the state of the source to live and notifies the observer.
void SetLive();
// Changes the state of the source to ended and notifies the observer.
void SetEnded();
const webrtc::MediaConstraintsInterface::Constraints& optional_constraints() {
return optional_constraints_;
}
const webrtc::MediaConstraintsInterface::Constraints&
mandatory_constraints() {
return mandatory_constraints_;
}
protected:
virtual ~MockAudioSource();
private:
webrtc::ObserverInterface* observer_;
MediaSourceInterface::SourceState state_;
webrtc::MediaConstraintsInterface::Constraints optional_constraints_;
webrtc::MediaConstraintsInterface::Constraints mandatory_constraints_;
};
class MockLocalVideoTrack : public webrtc::VideoTrackInterface {
public:
MockLocalVideoTrack(std::string id,
webrtc::VideoSourceInterface* source);
virtual void AddRenderer(webrtc::VideoRendererInterface* renderer) OVERRIDE;
virtual void RemoveRenderer(
webrtc::VideoRendererInterface* renderer) OVERRIDE;
virtual std::string kind() const OVERRIDE;
virtual std::string id() const OVERRIDE;
virtual bool enabled() const OVERRIDE;
virtual TrackState state() const OVERRIDE;
virtual bool set_enabled(bool enable) OVERRIDE;
virtual bool set_state(TrackState new_state) OVERRIDE;
virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
virtual webrtc::VideoSourceInterface* GetSource() const OVERRIDE;
protected:
virtual ~MockLocalVideoTrack();
private:
bool enabled_;
std::string id_;
TrackState state_;
scoped_refptr<webrtc::VideoSourceInterface> source_;
webrtc::ObserverInterface* observer_;
};
// A mock factory for creating different objects for
// RTC MediaStreams and PeerConnections.
class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory {
public:
MockMediaStreamDependencyFactory();
virtual ~MockMediaStreamDependencyFactory();
virtual scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
const webrtc::PeerConnectionInterface::IceServers& ice_servers,
const webrtc::MediaConstraintsInterface* constraints,
blink::WebFrame* frame,
webrtc::PeerConnectionObserver* observer) OVERRIDE;
virtual scoped_refptr<webrtc::AudioSourceInterface>
CreateLocalAudioSource(
const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
virtual cricket::VideoCapturer* CreateVideoCapturer(
const StreamDeviceInfo& info) OVERRIDE;
virtual scoped_refptr<webrtc::VideoSourceInterface>
CreateVideoSource(
cricket::VideoCapturer* capturer,
const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
virtual scoped_refptr<WebAudioCapturerSource> CreateWebAudioSource(
blink::WebMediaStreamSource* source) OVERRIDE;
virtual scoped_refptr<webrtc::MediaStreamInterface>
CreateLocalMediaStream(const std::string& label) OVERRIDE;
virtual scoped_refptr<webrtc::VideoTrackInterface>
CreateLocalVideoTrack(const std::string& id,
webrtc::VideoSourceInterface* source) OVERRIDE;
virtual scoped_refptr<webrtc::VideoTrackInterface>
CreateLocalVideoTrack(const std::string& id,
cricket::VideoCapturer* capturer) OVERRIDE;
virtual scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack(
const blink::WebMediaStreamTrack& blink_track,
const scoped_refptr<WebRtcAudioCapturer>& capturer,
WebAudioCapturerSource* webaudio_source,
webrtc::AudioSourceInterface* source) OVERRIDE;
virtual webrtc::SessionDescriptionInterface* CreateSessionDescription(
const std::string& type,
const std::string& sdp,
webrtc::SdpParseError* error) OVERRIDE;
virtual webrtc::IceCandidateInterface* CreateIceCandidate(
const std::string& sdp_mid,
int sdp_mline_index,
const std::string& sdp) OVERRIDE;
virtual scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer(
int render_view_id, const StreamDeviceInfo& device_info,
const blink::WebMediaConstraints& constraints) OVERRIDE;
MockAudioSource* last_audio_source() { return last_audio_source_.get(); }
MockVideoSource* last_video_source() { return last_video_source_.get(); }
private:
scoped_refptr <MockAudioSource> last_audio_source_;
scoped_refptr <MockVideoSource> last_video_source_;
DISALLOW_COPY_AND_ASSIGN(MockMediaStreamDependencyFactory);
};
} // namespace content
#endif // CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_
|