| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2004 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_DEVICEMANAGER_H_ | |
| 12 #define WEBRTC_MEDIA_DEVICES_DEVICEMANAGER_H_ | |
| 13 | |
| 14 #include <map> | |
| 15 #include <memory> | |
| 16 #include <string> | |
| 17 #include <vector> | |
| 18 | |
| 19 #include "webrtc/base/sigslot.h" | |
| 20 #include "webrtc/base/stringencode.h" | |
| 21 #include "webrtc/base/window.h" | |
| 22 #include "webrtc/media/base/device.h" | |
| 23 #include "webrtc/media/base/screencastid.h" | |
| 24 #include "webrtc/media/base/videocapturerfactory.h" | |
| 25 #include "webrtc/media/base/videocommon.h" | |
| 26 | |
| 27 namespace rtc { | |
| 28 | |
| 29 class DesktopDescription; | |
| 30 class WindowDescription; | |
| 31 class WindowPicker; | |
| 32 | |
| 33 } | |
| 34 namespace cricket { | |
| 35 | |
| 36 class VideoCapturer; | |
| 37 | |
| 38 // DeviceManagerInterface - interface to manage the audio and | |
| 39 // video devices on the system. | |
| 40 class DeviceManagerInterface { | |
| 41 public: | |
| 42 virtual ~DeviceManagerInterface() { } | |
| 43 | |
| 44 // Initialization | |
| 45 virtual bool Init() = 0; | |
| 46 virtual void Terminate() = 0; | |
| 47 | |
| 48 // Capabilities | |
| 49 virtual int GetCapabilities() = 0; | |
| 50 | |
| 51 // Device enumeration | |
| 52 virtual bool GetAudioInputDevices(std::vector<Device>* devices) = 0; | |
| 53 virtual bool GetAudioOutputDevices(std::vector<Device>* devices) = 0; | |
| 54 | |
| 55 virtual bool GetAudioInputDevice(const std::string& name, Device* out) = 0; | |
| 56 virtual bool GetAudioOutputDevice(const std::string& name, Device* out) = 0; | |
| 57 | |
| 58 virtual bool GetVideoCaptureDevices(std::vector<Device>* devs) = 0; | |
| 59 virtual bool GetVideoCaptureDevice(const std::string& name, Device* out) = 0; | |
| 60 | |
| 61 // If the device manager needs to create video capturers, here is | |
| 62 // how to control which video capturers are created. These take | |
| 63 // ownership of the factories. | |
| 64 virtual void SetVideoDeviceCapturerFactory( | |
| 65 VideoDeviceCapturerFactory* video_device_capturer_factory) = 0; | |
| 66 virtual void SetScreenCapturerFactory( | |
| 67 ScreenCapturerFactory* screen_capturer_factory) = 0; | |
| 68 | |
| 69 // Caps the capture format according to max format for capturers created | |
| 70 // by CreateVideoCapturer(). See ConstrainSupportedFormats() in | |
| 71 // videocapturer.h for more detail. | |
| 72 // Note that once a VideoCapturer has been created, calling this API will | |
| 73 // not affect it. | |
| 74 virtual void SetVideoCaptureDeviceMaxFormat( | |
| 75 const std::string& usb_id, | |
| 76 const VideoFormat& max_format) = 0; | |
| 77 virtual void ClearVideoCaptureDeviceMaxFormat(const std::string& usb_id) = 0; | |
| 78 | |
| 79 // Device creation | |
| 80 virtual VideoCapturer* CreateVideoCapturer(const Device& device) const = 0; | |
| 81 | |
| 82 virtual bool GetWindows( | |
| 83 std::vector<rtc::WindowDescription>* descriptions) = 0; | |
| 84 virtual bool GetDesktops( | |
| 85 std::vector<rtc::DesktopDescription>* descriptions) = 0; | |
| 86 virtual VideoCapturer* CreateScreenCapturer( | |
| 87 const ScreencastId& screenid) const = 0; | |
| 88 | |
| 89 sigslot::signal0<> SignalDevicesChange; | |
| 90 | |
| 91 static const char kDefaultDeviceName[]; | |
| 92 }; | |
| 93 | |
| 94 class DeviceWatcher { | |
| 95 public: | |
| 96 explicit DeviceWatcher(DeviceManagerInterface* dm) {} | |
| 97 virtual ~DeviceWatcher() {} | |
| 98 virtual bool Start() { return true; } | |
| 99 virtual void Stop() {} | |
| 100 }; | |
| 101 | |
| 102 class DeviceManagerFactory { | |
| 103 public: | |
| 104 static DeviceManagerInterface* Create(); | |
| 105 | |
| 106 private: | |
| 107 DeviceManagerFactory() {} | |
| 108 }; | |
| 109 | |
| 110 class DeviceManager : public DeviceManagerInterface { | |
| 111 public: | |
| 112 DeviceManager(); | |
| 113 virtual ~DeviceManager(); | |
| 114 | |
| 115 // Initialization | |
| 116 virtual bool Init(); | |
| 117 virtual void Terminate(); | |
| 118 | |
| 119 // Capabilities | |
| 120 virtual int GetCapabilities(); | |
| 121 | |
| 122 // Device enumeration | |
| 123 virtual bool GetAudioInputDevices(std::vector<Device>* devices); | |
| 124 virtual bool GetAudioOutputDevices(std::vector<Device>* devices); | |
| 125 | |
| 126 virtual bool GetAudioInputDevice(const std::string& name, Device* out); | |
| 127 virtual bool GetAudioOutputDevice(const std::string& name, Device* out); | |
| 128 | |
| 129 virtual bool GetVideoCaptureDevices(std::vector<Device>* devs); | |
| 130 virtual bool GetVideoCaptureDevice(const std::string& name, Device* out); | |
| 131 | |
| 132 virtual void SetVideoDeviceCapturerFactory( | |
| 133 VideoDeviceCapturerFactory* video_device_capturer_factory) { | |
| 134 video_device_capturer_factory_.reset(video_device_capturer_factory); | |
| 135 } | |
| 136 virtual void SetScreenCapturerFactory( | |
| 137 ScreenCapturerFactory* screen_capturer_factory) { | |
| 138 screen_capturer_factory_.reset(screen_capturer_factory); | |
| 139 } | |
| 140 | |
| 141 | |
| 142 virtual void SetVideoCaptureDeviceMaxFormat(const std::string& usb_id, | |
| 143 const VideoFormat& max_format); | |
| 144 virtual void ClearVideoCaptureDeviceMaxFormat(const std::string& usb_id); | |
| 145 | |
| 146 // TODO(pthatcher): Rename to CreateVideoDeviceCapturer. | |
| 147 virtual VideoCapturer* CreateVideoCapturer(const Device& device) const; | |
| 148 | |
| 149 virtual bool GetWindows( | |
| 150 std::vector<rtc::WindowDescription>* descriptions); | |
| 151 virtual bool GetDesktops( | |
| 152 std::vector<rtc::DesktopDescription>* descriptions); | |
| 153 virtual VideoCapturer* CreateScreenCapturer( | |
| 154 const ScreencastId& screenid) const; | |
| 155 | |
| 156 // The exclusion_list MUST be a NULL terminated list. | |
| 157 static bool FilterDevices(std::vector<Device>* devices, | |
| 158 const char* const exclusion_list[]); | |
| 159 bool initialized() const { return initialized_; } | |
| 160 | |
| 161 protected: | |
| 162 virtual bool GetAudioDevices(bool input, std::vector<Device>* devs); | |
| 163 virtual bool GetAudioDevice(bool is_input, const std::string& name, | |
| 164 Device* out); | |
| 165 virtual bool GetDefaultVideoCaptureDevice(Device* device); | |
| 166 bool IsInWhitelist(const std::string& key, VideoFormat* video_format) const; | |
| 167 virtual bool GetMaxFormat(const Device& device, | |
| 168 VideoFormat* video_format) const; | |
| 169 | |
| 170 void set_initialized(bool initialized) { initialized_ = initialized; } | |
| 171 | |
| 172 void set_watcher(DeviceWatcher* watcher) { watcher_.reset(watcher); } | |
| 173 DeviceWatcher* watcher() { return watcher_.get(); } | |
| 174 | |
| 175 private: | |
| 176 // The exclusion_list MUST be a NULL terminated list. | |
| 177 static bool ShouldDeviceBeIgnored(const std::string& device_name, | |
| 178 const char* const exclusion_list[]); | |
| 179 | |
| 180 bool initialized_; | |
| 181 std::unique_ptr< | |
| 182 VideoDeviceCapturerFactory> video_device_capturer_factory_; | |
| 183 std::unique_ptr< | |
| 184 ScreenCapturerFactory> screen_capturer_factory_; | |
| 185 std::map<std::string, VideoFormat> max_formats_; | |
| 186 std::unique_ptr<DeviceWatcher> watcher_; | |
| 187 std::unique_ptr<rtc::WindowPicker> window_picker_; | |
| 188 }; | |
| 189 | |
| 190 } // namespace cricket | |
| 191 | |
| 192 #endif // WEBRTC_MEDIA_DEVICES_DEVICEMANAGER_H_ | |
| OLD | NEW |