blob: 1d37a2facfc2b033e972a17e2ce786d17aac805f [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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.
4
5#ifndef CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_
6#define CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_
7
8#include <string>
9#include <vector>
10
11#include "base/compiler_specific.h"
12#include "content/renderer/media/media_stream_dependency_factory.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010013#include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000014
15namespace content {
16
17class MockVideoSource : public webrtc::VideoSourceInterface {
18 public:
19 MockVideoSource();
20
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;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000027 virtual const cricket::VideoOptions* options() const OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000028
29 // Changes the state of the source to live and notifies the observer.
30 void SetLive();
31 // Changes the state of the source to ended and notifies the observer.
32 void SetEnded();
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010033 // Set the video capturer.
34 void SetVideoCapturer(cricket::VideoCapturer* capturer);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000035
36 protected:
37 virtual ~MockVideoSource();
38
39 private:
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010040 void FireOnChanged();
41
42 std::vector<webrtc::ObserverInterface*> observers_;
43 MediaSourceInterface::SourceState state_;
44 scoped_ptr<cricket::VideoCapturer> capturer_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000045};
46
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000047class MockAudioSource : public webrtc::AudioSourceInterface {
48 public:
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010049 explicit MockAudioSource(
50 const webrtc::MediaConstraintsInterface* constraints);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000051
52 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
53 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
54 virtual MediaSourceInterface::SourceState state() const OVERRIDE;
55
56 // Changes the state of the source to live and notifies the observer.
57 void SetLive();
58 // Changes the state of the source to ended and notifies the observer.
59 void SetEnded();
60
61 const webrtc::MediaConstraintsInterface::Constraints& optional_constraints() {
62 return optional_constraints_;
63 }
64
65 const webrtc::MediaConstraintsInterface::Constraints&
66 mandatory_constraints() {
67 return mandatory_constraints_;
68 }
69
70 protected:
71 virtual ~MockAudioSource();
72
73 private:
74 webrtc::ObserverInterface* observer_;
75 MediaSourceInterface::SourceState state_;
76 webrtc::MediaConstraintsInterface::Constraints optional_constraints_;
77 webrtc::MediaConstraintsInterface::Constraints mandatory_constraints_;
78};
79
Torne (Richard Coles)58218062012-11-14 11:43:16 +000080class MockLocalVideoTrack : public webrtc::VideoTrackInterface {
81 public:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000082 MockLocalVideoTrack(std::string id,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000083 webrtc::VideoSourceInterface* source);
84 virtual void AddRenderer(webrtc::VideoRendererInterface* renderer) OVERRIDE;
85 virtual void RemoveRenderer(
86 webrtc::VideoRendererInterface* renderer) OVERRIDE;
87 virtual cricket::VideoRenderer* FrameInput() OVERRIDE;
88 virtual std::string kind() const OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000089 virtual std::string id() const OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000090 virtual bool enabled() const OVERRIDE;
91 virtual TrackState state() const OVERRIDE;
92 virtual bool set_enabled(bool enable) OVERRIDE;
93 virtual bool set_state(TrackState new_state) OVERRIDE;
94 virtual void RegisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
95 virtual void UnregisterObserver(webrtc::ObserverInterface* observer) OVERRIDE;
96 virtual webrtc::VideoSourceInterface* GetSource() const OVERRIDE;
97
98 protected:
99 virtual ~MockLocalVideoTrack();
100
101 private:
102 bool enabled_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000103 std::string id_;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100104 TrackState state_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000105 scoped_refptr<webrtc::VideoSourceInterface> source_;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100106 webrtc::ObserverInterface* observer_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000107};
108
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000109// A mock factory for creating different objects for
110// RTC MediaStreams and PeerConnections.
111class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory {
112 public:
113 MockMediaStreamDependencyFactory();
114 virtual ~MockMediaStreamDependencyFactory();
115
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000116 virtual scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
117 const webrtc::PeerConnectionInterface::IceServers& ice_servers,
118 const webrtc::MediaConstraintsInterface* constraints,
119 WebKit::WebFrame* frame,
120 webrtc::PeerConnectionObserver* observer) OVERRIDE;
121 virtual scoped_refptr<webrtc::AudioSourceInterface>
122 CreateLocalAudioSource(
123 const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000124 virtual scoped_refptr<webrtc::VideoSourceInterface>
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000125 CreateLocalVideoSource(
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000126 int video_session_id,
127 bool is_screencast,
128 const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
Ben Murdochbb1529c2013-08-08 10:24:53 +0100129 virtual scoped_refptr<WebRtcAudioCapturer> CreateWebAudioSource(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000130 WebKit::WebMediaStreamSource* source) OVERRIDE;
131 virtual scoped_refptr<webrtc::MediaStreamInterface>
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000132 CreateLocalMediaStream(const std::string& label) OVERRIDE;
133 virtual scoped_refptr<webrtc::VideoTrackInterface>
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000134 CreateLocalVideoTrack(const std::string& id,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000135 webrtc::VideoSourceInterface* source) OVERRIDE;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100136 virtual scoped_refptr<webrtc::VideoTrackInterface>
137 CreateLocalVideoTrack(const std::string& id,
138 cricket::VideoCapturer* capturer) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000139 virtual scoped_refptr<webrtc::AudioTrackInterface>
140 CreateLocalAudioTrack(const std::string& id,
Ben Murdochbb1529c2013-08-08 10:24:53 +0100141 const scoped_refptr<WebRtcAudioCapturer>& capturer,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000142 webrtc::AudioSourceInterface* source) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000143 virtual webrtc::SessionDescriptionInterface* CreateSessionDescription(
144 const std::string& type,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000145 const std::string& sdp,
146 webrtc::SdpParseError* error) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000147 virtual webrtc::IceCandidateInterface* CreateIceCandidate(
148 const std::string& sdp_mid,
149 int sdp_mline_index,
150 const std::string& sdp) OVERRIDE;
151
152 virtual bool EnsurePeerConnectionFactory() OVERRIDE;
153 virtual bool PeerConnectionFactoryCreated() OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000154
Ben Murdochbb1529c2013-08-08 10:24:53 +0100155 virtual scoped_refptr<WebRtcAudioCapturer> MaybeCreateAudioCapturer(
156 int render_view_id, const StreamDeviceInfo& device_info) OVERRIDE;
157
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100158 MockAudioSource* last_audio_source() { return last_audio_source_.get(); }
159 MockVideoSource* last_video_source() { return last_video_source_.get(); }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000160
161 private:
162 bool mock_pc_factory_created_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000163 scoped_refptr <MockAudioSource> last_audio_source_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000164 scoped_refptr <MockVideoSource> last_video_source_;
165
166 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamDependencyFactory);
167};
168
169} // namespace content
170
171#endif // CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_DEPENDENCY_FACTORY_H_