henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2004 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 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. |
| 15 | * |
| 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. |
| 26 | */ |
| 27 | |
| 28 | #ifndef TALK_MEDIA_DEVICES_DEVICEMANAGER_H_ |
| 29 | #define TALK_MEDIA_DEVICES_DEVICEMANAGER_H_ |
| 30 | |
| 31 | #include <map> |
| 32 | #include <string> |
| 33 | #include <vector> |
| 34 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 35 | #include "webrtc/base/scoped_ptr.h" |
| 36 | #include "webrtc/base/sigslot.h" |
| 37 | #include "webrtc/base/stringencode.h" |
| 38 | #include "webrtc/base/window.h" |
buildbot@webrtc.org | e0d03f1 | 2014-08-02 03:04:01 +0000 | [diff] [blame^] | 39 | #include "talk/media/base/videocommon.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 41 | namespace rtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | |
| 43 | class DesktopDescription; |
| 44 | class WindowDescription; |
| 45 | class WindowPicker; |
| 46 | |
| 47 | } |
| 48 | namespace cricket { |
| 49 | |
| 50 | class VideoCapturer; |
| 51 | |
buildbot@webrtc.org | e0d03f1 | 2014-08-02 03:04:01 +0000 | [diff] [blame^] | 52 | // Used to represent an audio or video capture or render device. |
| 53 | struct Device { |
| 54 | Device() {} |
| 55 | Device(const std::string& first, int second) |
| 56 | : name(first), |
| 57 | id(rtc::ToString(second)) { |
| 58 | } |
| 59 | Device(const std::string& first, const std::string& second) |
| 60 | : name(first), id(second) {} |
| 61 | |
| 62 | std::string name; |
| 63 | std::string id; |
| 64 | }; |
| 65 | |
| 66 | class VideoCapturerFactory { |
| 67 | public: |
| 68 | VideoCapturerFactory() {} |
| 69 | virtual ~VideoCapturerFactory() {} |
| 70 | |
| 71 | virtual VideoCapturer* Create(const Device& device) = 0; |
| 72 | }; |
| 73 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | // DeviceManagerInterface - interface to manage the audio and |
| 75 | // video devices on the system. |
| 76 | class DeviceManagerInterface { |
| 77 | public: |
| 78 | virtual ~DeviceManagerInterface() { } |
| 79 | |
| 80 | // Initialization |
| 81 | virtual bool Init() = 0; |
| 82 | virtual void Terminate() = 0; |
| 83 | |
| 84 | // Capabilities |
| 85 | virtual int GetCapabilities() = 0; |
| 86 | |
| 87 | // Device enumeration |
| 88 | virtual bool GetAudioInputDevices(std::vector<Device>* devices) = 0; |
| 89 | virtual bool GetAudioOutputDevices(std::vector<Device>* devices) = 0; |
| 90 | |
| 91 | virtual bool GetAudioInputDevice(const std::string& name, Device* out) = 0; |
| 92 | virtual bool GetAudioOutputDevice(const std::string& name, Device* out) = 0; |
| 93 | |
| 94 | virtual bool GetVideoCaptureDevices(std::vector<Device>* devs) = 0; |
| 95 | virtual bool GetVideoCaptureDevice(const std::string& name, Device* out) = 0; |
| 96 | |
| 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 |
| 101 | // not affect it. |
| 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; |
| 106 | |
| 107 | // Device creation |
| 108 | virtual VideoCapturer* CreateVideoCapturer(const Device& device) const = 0; |
| 109 | |
| 110 | virtual bool GetWindows( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 111 | std::vector<rtc::WindowDescription>* descriptions) = 0; |
buildbot@webrtc.org | e0d03f1 | 2014-08-02 03:04:01 +0000 | [diff] [blame^] | 112 | virtual VideoCapturer* CreateWindowCapturer(rtc::WindowId window) = 0; |
| 113 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | virtual bool GetDesktops( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 115 | std::vector<rtc::DesktopDescription>* descriptions) = 0; |
buildbot@webrtc.org | e0d03f1 | 2014-08-02 03:04:01 +0000 | [diff] [blame^] | 116 | virtual VideoCapturer* CreateDesktopCapturer( |
| 117 | rtc::DesktopId desktop) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | |
| 119 | sigslot::signal0<> SignalDevicesChange; |
| 120 | |
| 121 | static const char kDefaultDeviceName[]; |
| 122 | }; |
| 123 | |
| 124 | class DeviceWatcher { |
| 125 | public: |
| 126 | explicit DeviceWatcher(DeviceManagerInterface* dm) {} |
| 127 | virtual ~DeviceWatcher() {} |
| 128 | virtual bool Start() { return true; } |
| 129 | virtual void Stop() {} |
| 130 | }; |
| 131 | |
| 132 | class DeviceManagerFactory { |
| 133 | public: |
| 134 | static DeviceManagerInterface* Create(); |
| 135 | |
| 136 | private: |
| 137 | DeviceManagerFactory() {} |
| 138 | }; |
| 139 | |
| 140 | class DeviceManager : public DeviceManagerInterface { |
| 141 | public: |
| 142 | DeviceManager(); |
| 143 | virtual ~DeviceManager(); |
| 144 | |
buildbot@webrtc.org | e0d03f1 | 2014-08-02 03:04:01 +0000 | [diff] [blame^] | 145 | void set_device_video_capturer_factory( |
| 146 | VideoCapturerFactory* device_video_capturer_factory) { |
| 147 | device_video_capturer_factory_.reset(device_video_capturer_factory); |
| 148 | } |
| 149 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | // Initialization |
| 151 | virtual bool Init(); |
| 152 | virtual void Terminate(); |
| 153 | |
| 154 | // Capabilities |
| 155 | virtual int GetCapabilities(); |
| 156 | |
| 157 | // Device enumeration |
| 158 | virtual bool GetAudioInputDevices(std::vector<Device>* devices); |
| 159 | virtual bool GetAudioOutputDevices(std::vector<Device>* devices); |
| 160 | |
| 161 | virtual bool GetAudioInputDevice(const std::string& name, Device* out); |
| 162 | virtual bool GetAudioOutputDevice(const std::string& name, Device* out); |
| 163 | |
| 164 | virtual bool GetVideoCaptureDevices(std::vector<Device>* devs); |
| 165 | virtual bool GetVideoCaptureDevice(const std::string& name, Device* out); |
| 166 | |
| 167 | virtual void SetVideoCaptureDeviceMaxFormat(const std::string& usb_id, |
| 168 | const VideoFormat& max_format); |
| 169 | virtual void ClearVideoCaptureDeviceMaxFormat(const std::string& usb_id); |
| 170 | |
| 171 | virtual VideoCapturer* CreateVideoCapturer(const Device& device) const; |
| 172 | |
| 173 | virtual bool GetWindows( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 174 | std::vector<rtc::WindowDescription>* descriptions); |
buildbot@webrtc.org | e0d03f1 | 2014-08-02 03:04:01 +0000 | [diff] [blame^] | 175 | virtual VideoCapturer* CreateWindowCapturer(rtc::WindowId window); |
| 176 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 177 | virtual bool GetDesktops( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 178 | std::vector<rtc::DesktopDescription>* descriptions); |
buildbot@webrtc.org | e0d03f1 | 2014-08-02 03:04:01 +0000 | [diff] [blame^] | 179 | virtual VideoCapturer* CreateDesktopCapturer(rtc::DesktopId desktop); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | |
| 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_; } |
| 185 | |
| 186 | protected: |
| 187 | virtual bool GetAudioDevices(bool input, std::vector<Device>* devs); |
| 188 | virtual bool GetAudioDevice(bool is_input, const std::string& name, |
| 189 | Device* out); |
| 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; |
| 194 | |
| 195 | void set_initialized(bool initialized) { initialized_ = initialized; } |
| 196 | |
| 197 | void set_watcher(DeviceWatcher* watcher) { watcher_.reset(watcher); } |
| 198 | DeviceWatcher* watcher() { return watcher_.get(); } |
| 199 | |
| 200 | private: |
| 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[]); |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 204 | bool GetFakeVideoCaptureDevice(const std::string& name, Device* out) const; |
buildbot@webrtc.org | e0d03f1 | 2014-08-02 03:04:01 +0000 | [diff] [blame^] | 205 | VideoCapturer* ConstructFakeVideoCapturer(const Device& device) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 206 | |
| 207 | bool initialized_; |
buildbot@webrtc.org | e0d03f1 | 2014-08-02 03:04:01 +0000 | [diff] [blame^] | 208 | rtc::scoped_ptr<VideoCapturerFactory> device_video_capturer_factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 209 | std::map<std::string, VideoFormat> max_formats_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 210 | rtc::scoped_ptr<DeviceWatcher> watcher_; |
| 211 | rtc::scoped_ptr<rtc::WindowPicker> window_picker_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | } // namespace cricket |
| 215 | |
| 216 | #endif // TALK_MEDIA_DEVICES_DEVICEMANAGER_H_ |