3 * Copyright 2004 Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef TALK_MEDIA_DEVICES_DEVICEMANAGER_H_
29 #define TALK_MEDIA_DEVICES_DEVICEMANAGER_H_
35 #include "talk/base/scoped_ptr.h"
36 #include "talk/base/sigslot.h"
37 #include "talk/base/stringencode.h"
38 #include "talk/base/window.h"
39 #include "talk/media/base/videocommon.h"
43 class DesktopDescription;
44 class WindowDescription;
52 // Used to represent an audio or video capture or render device.
55 Device(const std::string& first, int second)
57 id(talk_base::ToString(second)) {
59 Device(const std::string& first, const std::string& second)
60 : name(first), id(second) {}
66 class VideoCapturerFactory {
68 VideoCapturerFactory() {}
69 virtual ~VideoCapturerFactory() {}
71 virtual VideoCapturer* Create(const Device& device) = 0;
74 // DeviceManagerInterface - interface to manage the audio and
75 // video devices on the system.
76 class DeviceManagerInterface {
78 virtual ~DeviceManagerInterface() { }
81 virtual bool Init() = 0;
82 virtual void Terminate() = 0;
85 virtual int GetCapabilities() = 0;
88 virtual bool GetAudioInputDevices(std::vector<Device>* devices) = 0;
89 virtual bool GetAudioOutputDevices(std::vector<Device>* devices) = 0;
91 virtual bool GetAudioInputDevice(const std::string& name, Device* out) = 0;
92 virtual bool GetAudioOutputDevice(const std::string& name, Device* out) = 0;
94 virtual bool GetVideoCaptureDevices(std::vector<Device>* devs) = 0;
95 virtual bool GetVideoCaptureDevice(const std::string& name, Device* out) = 0;
97 // Caps the capture format according to max format for capturers created
98 // by CreateVideoCapturer(). See ConstrainSupportedFormats() in
99 // videocapturer.h for more detail.
100 // Note that once a VideoCapturer has been created, calling this API will
102 virtual void SetVideoCaptureDeviceMaxFormat(
103 const std::string& usb_id,
104 const VideoFormat& max_format) = 0;
105 virtual void ClearVideoCaptureDeviceMaxFormat(const std::string& usb_id) = 0;
108 virtual VideoCapturer* CreateVideoCapturer(const Device& device) const = 0;
110 virtual bool GetWindows(
111 std::vector<talk_base::WindowDescription>* descriptions) = 0;
112 virtual VideoCapturer* CreateWindowCapturer(talk_base::WindowId window) = 0;
114 virtual bool GetDesktops(
115 std::vector<talk_base::DesktopDescription>* descriptions) = 0;
116 virtual VideoCapturer* CreateDesktopCapturer(
117 talk_base::DesktopId desktop) = 0;
119 sigslot::signal0<> SignalDevicesChange;
121 static const char kDefaultDeviceName[];
124 class DeviceWatcher {
126 explicit DeviceWatcher(DeviceManagerInterface* dm) {}
127 virtual ~DeviceWatcher() {}
128 virtual bool Start() { return true; }
129 virtual void Stop() {}
132 class DeviceManagerFactory {
134 static DeviceManagerInterface* Create();
137 DeviceManagerFactory() {}
140 class DeviceManager : public DeviceManagerInterface {
143 virtual ~DeviceManager();
145 void set_device_video_capturer_factory(
146 VideoCapturerFactory* device_video_capturer_factory) {
147 device_video_capturer_factory_.reset(device_video_capturer_factory);
152 virtual void Terminate();
155 virtual int GetCapabilities();
157 // Device enumeration
158 virtual bool GetAudioInputDevices(std::vector<Device>* devices);
159 virtual bool GetAudioOutputDevices(std::vector<Device>* devices);
161 virtual bool GetAudioInputDevice(const std::string& name, Device* out);
162 virtual bool GetAudioOutputDevice(const std::string& name, Device* out);
164 virtual bool GetVideoCaptureDevices(std::vector<Device>* devs);
165 virtual bool GetVideoCaptureDevice(const std::string& name, Device* out);
167 virtual void SetVideoCaptureDeviceMaxFormat(const std::string& usb_id,
168 const VideoFormat& max_format);
169 virtual void ClearVideoCaptureDeviceMaxFormat(const std::string& usb_id);
171 virtual VideoCapturer* CreateVideoCapturer(const Device& device) const;
173 virtual bool GetWindows(
174 std::vector<talk_base::WindowDescription>* descriptions);
175 virtual VideoCapturer* CreateWindowCapturer(talk_base::WindowId window);
177 virtual bool GetDesktops(
178 std::vector<talk_base::DesktopDescription>* descriptions);
179 virtual VideoCapturer* CreateDesktopCapturer(talk_base::DesktopId desktop);
181 // The exclusion_list MUST be a NULL terminated list.
182 static bool FilterDevices(std::vector<Device>* devices,
183 const char* const exclusion_list[]);
184 bool initialized() const { return initialized_; }
187 virtual bool GetAudioDevices(bool input, std::vector<Device>* devs);
188 virtual bool GetAudioDevice(bool is_input, const std::string& name,
190 virtual bool GetDefaultVideoCaptureDevice(Device* device);
191 bool IsInWhitelist(const std::string& key, VideoFormat* video_format) const;
192 virtual bool GetMaxFormat(const Device& device,
193 VideoFormat* video_format) const;
195 void set_initialized(bool initialized) { initialized_ = initialized; }
197 void set_watcher(DeviceWatcher* watcher) { watcher_.reset(watcher); }
198 DeviceWatcher* watcher() { return watcher_.get(); }
201 // The exclusion_list MUST be a NULL terminated list.
202 static bool ShouldDeviceBeIgnored(const std::string& device_name,
203 const char* const exclusion_list[]);
204 bool GetFakeVideoCaptureDevice(const std::string& name, Device* out) const;
205 VideoCapturer* ConstructFakeVideoCapturer(const Device& device) const;
208 talk_base::scoped_ptr<VideoCapturerFactory> device_video_capturer_factory_;
209 std::map<std::string, VideoFormat> max_formats_;
210 talk_base::scoped_ptr<DeviceWatcher> watcher_;
211 talk_base::scoped_ptr<talk_base::WindowPicker> window_picker_;
214 } // namespace cricket
216 #endif // TALK_MEDIA_DEVICES_DEVICEMANAGER_H_