Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: webrtc/media/devices/fakedevicemanager.h

Issue 1715883002: Remove DeviceManager and DeviceInfo. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef WEBRTC_MEDIA_DEVICES_FAKEDEVICEMANAGER_H_
12 #define WEBRTC_MEDIA_DEVICES_FAKEDEVICEMANAGER_H_
13
14 #include <memory>
15 #include <string>
16 #include <vector>
17
18 #include "webrtc/base/window.h"
19 #include "webrtc/base/windowpicker.h"
20 #include "webrtc/media/base/fakevideocapturer.h"
21 #include "webrtc/media/base/mediacommon.h"
22 #include "webrtc/media/devices/devicemanager.h"
23
24 namespace cricket {
25
26 class FakeDeviceManager : public DeviceManagerInterface {
27 public:
28 FakeDeviceManager() {}
29 virtual bool Init() {
30 return true;
31 }
32 virtual void Terminate() {
33 }
34 virtual int GetCapabilities() {
35 std::vector<Device> devices;
36 int caps = VIDEO_RECV;
37 if (!input_devices_.empty()) {
38 caps |= AUDIO_SEND;
39 }
40 if (!output_devices_.empty()) {
41 caps |= AUDIO_RECV;
42 }
43 if (!vidcap_devices_.empty()) {
44 caps |= VIDEO_SEND;
45 }
46 return caps;
47 }
48 virtual bool GetAudioInputDevices(std::vector<Device>* devs) {
49 *devs = input_devices_;
50 return true;
51 }
52 virtual bool GetAudioOutputDevices(std::vector<Device>* devs) {
53 *devs = output_devices_;
54 return true;
55 }
56 virtual bool GetAudioInputDevice(const std::string& name, Device* out) {
57 return GetAudioDevice(true, name, out);
58 }
59 virtual bool GetAudioOutputDevice(const std::string& name, Device* out) {
60 return GetAudioDevice(false, name, out);
61 }
62 virtual bool GetVideoCaptureDevices(std::vector<Device>* devs) {
63 *devs = vidcap_devices_;
64 return true;
65 }
66 virtual void SetVideoDeviceCapturerFactory(
67 VideoDeviceCapturerFactory* video_device_capturer_factory) {
68 }
69 virtual void SetScreenCapturerFactory(
70 ScreenCapturerFactory* screen_capturer_factory) {
71 screen_capturer_factory_.reset(screen_capturer_factory);
72 }
73 virtual void SetVideoCaptureDeviceMaxFormat(const std::string& usb_id,
74 const VideoFormat& max_format) {
75 max_formats_[usb_id] = max_format;
76 }
77 bool IsMaxFormatForDevice(const std::string& usb_id,
78 const VideoFormat& max_format) const {
79 std::map<std::string, VideoFormat>::const_iterator found =
80 max_formats_.find(usb_id);
81 return (found != max_formats_.end()) ?
82 max_format == found->second :
83 false;
84 }
85 virtual void ClearVideoCaptureDeviceMaxFormat(const std::string& usb_id) {
86 max_formats_.erase(usb_id);
87 }
88 virtual VideoCapturer* CreateVideoCapturer(const Device& device) const {
89 return new FakeVideoCapturer();
90 }
91 virtual VideoCapturer* CreateScreenCapturer(
92 const ScreencastId& screenid) const {
93 if (!screen_capturer_factory_) {
94 return new FakeVideoCapturer();
95 }
96 return screen_capturer_factory_->Create(screenid);
97 }
98 virtual bool GetWindows(
99 std::vector<rtc::WindowDescription>* descriptions) {
100 descriptions->clear();
101 const uint32_t id = 1u; // Note that 0 is not a valid ID.
102 const rtc::WindowId window_id =
103 rtc::WindowId::Cast(id);
104 std::string title = "FakeWindow";
105 rtc::WindowDescription window_description(window_id, title);
106 descriptions->push_back(window_description);
107 return true;
108 }
109 virtual VideoCapturer* CreateWindowCapturer(rtc::WindowId window) {
110 if (!window.IsValid()) {
111 return NULL;
112 }
113 return new FakeVideoCapturer;
114 }
115 virtual bool GetDesktops(
116 std::vector<rtc::DesktopDescription>* descriptions) {
117 descriptions->clear();
118 const int id = 0;
119 const int valid_index = 0;
120 const rtc::DesktopId desktop_id =
121 rtc::DesktopId::Cast(id, valid_index);
122 std::string title = "FakeDesktop";
123 rtc::DesktopDescription desktop_description(desktop_id, title);
124 descriptions->push_back(desktop_description);
125 return true;
126 }
127 virtual VideoCapturer* CreateDesktopCapturer(rtc::DesktopId desktop) {
128 if (!desktop.IsValid()) {
129 return NULL;
130 }
131 return new FakeVideoCapturer;
132 }
133
134 virtual bool GetDefaultVideoCaptureDevice(Device* device) {
135 if (vidcap_devices_.empty()) {
136 return false;
137 }
138 *device = vidcap_devices_[0];
139 return true;
140 }
141
142 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
143 bool QtKitToSgDevice(const std::string& qtkit_name, Device* out) {
144 out->name = qtkit_name;
145 out->id = "sg:" + qtkit_name;
146 return true;
147 }
148 #endif
149
150 void SetAudioInputDevices(const std::vector<std::string>& devices) {
151 input_devices_.clear();
152 for (size_t i = 0; i < devices.size(); ++i) {
153 input_devices_.push_back(Device(devices[i],
154 static_cast<int>(i)));
155 }
156 SignalDevicesChange();
157 }
158 void SetAudioOutputDevices(const std::vector<std::string>& devices) {
159 output_devices_.clear();
160 for (size_t i = 0; i < devices.size(); ++i) {
161 output_devices_.push_back(Device(devices[i],
162 static_cast<int>(i)));
163 }
164 SignalDevicesChange();
165 }
166 void SetVideoCaptureDevices(const std::vector<std::string>& devices) {
167 vidcap_devices_.clear();
168 for (size_t i = 0; i < devices.size(); ++i) {
169 vidcap_devices_.push_back(Device(devices[i],
170 static_cast<int>(i)));
171 }
172 SignalDevicesChange();
173 }
174 virtual bool GetVideoCaptureDevice(const std::string& name,
175 Device* out) {
176 if (vidcap_devices_.empty())
177 return false;
178
179 // If the name is empty, return the default device.
180 if (name.empty() || name == kDefaultDeviceName) {
181 *out = vidcap_devices_[0];
182 return true;
183 }
184
185 return FindDeviceByName(vidcap_devices_, name, out);
186 }
187 bool GetAudioDevice(bool is_input, const std::string& name,
188 Device* out) {
189 // If the name is empty, return the default device.
190 if (name.empty() || name == kDefaultDeviceName) {
191 *out = Device(name, -1);
192 return true;
193 }
194
195 return FindDeviceByName((is_input ? input_devices_ : output_devices_),
196 name, out);
197 }
198 static bool FindDeviceByName(const std::vector<Device>& devices,
199 const std::string& name,
200 Device* out) {
201 for (std::vector<Device>::const_iterator it = devices.begin();
202 it != devices.end(); ++it) {
203 if (name == it->name) {
204 *out = *it;
205 return true;
206 }
207 }
208 return false;
209 }
210
211 private:
212 std::vector<Device> input_devices_;
213 std::vector<Device> output_devices_;
214 std::vector<Device> vidcap_devices_;
215 std::map<std::string, VideoFormat> max_formats_;
216 std::unique_ptr<
217 ScreenCapturerFactory> screen_capturer_factory_;
218 };
219
220 } // namespace cricket
221
222 #endif // WEBRTC_MEDIA_DEVICES_FAKEDEVICEMANAGER_H_
OLDNEW
« no previous file with comments | « webrtc/media/devices/dummydevicemanager_unittest.cc ('k') | webrtc/media/devices/linuxdeviceinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698