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
|
// 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"
namespace content {
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;
// 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();
protected:
virtual ~MockVideoSource();
private:
webrtc::ObserverInterface* observer_;
MediaSourceInterface::SourceState state_;
};
class MockLocalVideoTrack : public webrtc::VideoTrackInterface {
public:
MockLocalVideoTrack(std::string label,
webrtc::VideoSourceInterface* source);
virtual void AddRenderer(webrtc::VideoRendererInterface* renderer) OVERRIDE;
virtual void RemoveRenderer(
webrtc::VideoRendererInterface* renderer) OVERRIDE;
virtual cricket::VideoRenderer* FrameInput() OVERRIDE;
virtual std::string kind() const OVERRIDE;
virtual std::string label() 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 label_;
scoped_refptr<webrtc::VideoSourceInterface> source_;
};
class MockLocalAudioTrack : public webrtc::AudioTrackInterface {
public:
explicit MockLocalAudioTrack(const std::string& label)
: enabled_(false),
label_(label) {
}
virtual std::string kind() const OVERRIDE;
virtual std::string label() 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::AudioSourceInterface* GetSource() const OVERRIDE;
protected:
virtual ~MockLocalAudioTrack() {}
private:
bool enabled_;
std::string label_;
};
// 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::JsepInterface::IceServers& ice_servers,
const webrtc::MediaConstraintsInterface* constraints,
WebKit::WebFrame* frame,
webrtc::PeerConnectionObserver* observer) OVERRIDE;
virtual scoped_refptr<webrtc::VideoSourceInterface>
CreateVideoSource(
int video_session_id,
bool is_screencast,
const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
virtual scoped_refptr<webrtc::LocalMediaStreamInterface>
CreateLocalMediaStream(const std::string& label) OVERRIDE;
virtual scoped_refptr<webrtc::VideoTrackInterface>
CreateLocalVideoTrack(const std::string& label,
webrtc::VideoSourceInterface* source) OVERRIDE;
virtual scoped_refptr<webrtc::LocalAudioTrackInterface>
CreateLocalAudioTrack(const std::string& label,
webrtc::AudioDeviceModule* audio_device) OVERRIDE;
virtual webrtc::SessionDescriptionInterface* CreateSessionDescription(
const std::string& sdp) OVERRIDE;
virtual webrtc::SessionDescriptionInterface* CreateSessionDescription(
const std::string& type,
const std::string& sdp) OVERRIDE;
virtual webrtc::IceCandidateInterface* CreateIceCandidate(
const std::string& sdp_mid,
int sdp_mline_index,
const std::string& sdp) OVERRIDE;
virtual bool EnsurePeerConnectionFactory() OVERRIDE;
virtual bool PeerConnectionFactoryCreated() OVERRIDE;
virtual void SetAudioDeviceSessionId(int session_id) OVERRIDE;
MockVideoSource* last_video_source() { return last_video_source_; }
private:
bool mock_pc_factory_created_;
scoped_refptr <MockVideoSource> last_video_source_;
DISALLOW_COPY_AND_ASSIGN(MockMediaStreamDependencyFactory);
};
} // namespace content
#endif // CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_
|