You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
7.4 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #ifndef TALK_MEDIA_DEVICES_DEVICEMANAGER_H_
  28. #define TALK_MEDIA_DEVICES_DEVICEMANAGER_H_
  29. #include <map>
  30. #include <string>
  31. #include <vector>
  32. #include "talk/base/scoped_ptr.h"
  33. #include "talk/base/sigslot.h"
  34. #include "talk/base/stringencode.h"
  35. #include "talk/base/window.h"
  36. #include "talk/media/base/videocommon.h"
  37. namespace talk_base {
  38. class DesktopDescription;
  39. class WindowDescription;
  40. class WindowPicker;
  41. }
  42. namespace cricket {
  43. class VideoCapturer;
  44. // Used to represent an audio or video capture or render device.
  45. struct Device {
  46. Device() {}
  47. Device(const std::string& first, int second)
  48. : name(first),
  49. id(talk_base::ToString(second)) {
  50. }
  51. Device(const std::string& first, const std::string& second)
  52. : name(first), id(second) {}
  53. std::string name;
  54. std::string id;
  55. };
  56. class VideoCapturerFactory {
  57. public:
  58. VideoCapturerFactory() {}
  59. virtual ~VideoCapturerFactory() {}
  60. virtual VideoCapturer* Create(const Device& device) = 0;
  61. };
  62. // DeviceManagerInterface - interface to manage the audio and
  63. // video devices on the system.
  64. class DeviceManagerInterface {
  65. public:
  66. virtual ~DeviceManagerInterface() { }
  67. // Initialization
  68. virtual bool Init() = 0;
  69. virtual void Terminate() = 0;
  70. // Capabilities
  71. virtual int GetCapabilities() = 0;
  72. // Device enumeration
  73. virtual bool GetAudioInputDevices(std::vector<Device>* devices) = 0;
  74. virtual bool GetAudioOutputDevices(std::vector<Device>* devices) = 0;
  75. virtual bool GetAudioInputDevice(const std::string& name, Device* out) = 0;
  76. virtual bool GetAudioOutputDevice(const std::string& name, Device* out) = 0;
  77. virtual bool GetVideoCaptureDevices(std::vector<Device>* devs) = 0;
  78. virtual bool GetVideoCaptureDevice(const std::string& name, Device* out) = 0;
  79. // Caps the capture format according to max format for capturers created
  80. // by CreateVideoCapturer(). See ConstrainSupportedFormats() in
  81. // videocapturer.h for more detail.
  82. // Note that once a VideoCapturer has been created, calling this API will
  83. // not affect it.
  84. virtual void SetVideoCaptureDeviceMaxFormat(
  85. const std::string& uvc_id,
  86. const VideoFormat& max_format) = 0;
  87. virtual void ClearVideoCaptureDeviceMaxFormat(const std::string& uvc_id) = 0;
  88. // Device creation
  89. virtual VideoCapturer* CreateVideoCapturer(const Device& device) const = 0;
  90. virtual bool GetWindows(
  91. std::vector<talk_base::WindowDescription>* descriptions) = 0;
  92. virtual VideoCapturer* CreateWindowCapturer(talk_base::WindowId window) = 0;
  93. virtual bool GetDesktops(
  94. std::vector<talk_base::DesktopDescription>* descriptions) = 0;
  95. virtual VideoCapturer* CreateDesktopCapturer(
  96. talk_base::DesktopId desktop) = 0;
  97. sigslot::signal0<> SignalDevicesChange;
  98. static const char kDefaultDeviceName[];
  99. };
  100. class DeviceWatcher {
  101. public:
  102. explicit DeviceWatcher(DeviceManagerInterface* dm) {}
  103. virtual ~DeviceWatcher() {}
  104. virtual bool Start() { return true; }
  105. virtual void Stop() {}
  106. };
  107. class DeviceManagerFactory {
  108. public:
  109. static DeviceManagerInterface* Create();
  110. private:
  111. DeviceManagerFactory() {}
  112. };
  113. class DeviceManager : public DeviceManagerInterface {
  114. public:
  115. DeviceManager();
  116. virtual ~DeviceManager();
  117. void set_device_video_capturer_factory(
  118. VideoCapturerFactory* device_video_capturer_factory) {
  119. device_video_capturer_factory_.reset(device_video_capturer_factory);
  120. }
  121. // Initialization
  122. virtual bool Init();
  123. virtual void Terminate();
  124. // Capabilities
  125. virtual int GetCapabilities();
  126. // Device enumeration
  127. virtual bool GetAudioInputDevices(std::vector<Device>* devices);
  128. virtual bool GetAudioOutputDevices(std::vector<Device>* devices);
  129. virtual bool GetAudioInputDevice(const std::string& name, Device* out);
  130. virtual bool GetAudioOutputDevice(const std::string& name, Device* out);
  131. virtual bool GetVideoCaptureDevices(std::vector<Device>* devs);
  132. virtual bool GetVideoCaptureDevice(const std::string& name, Device* out);
  133. virtual void SetVideoCaptureDeviceMaxFormat(const std::string& uvc_id,
  134. const VideoFormat& max_format);
  135. virtual void ClearVideoCaptureDeviceMaxFormat(const std::string& uvc_id);
  136. virtual VideoCapturer* CreateVideoCapturer(const Device& device) const;
  137. virtual bool GetWindows(
  138. std::vector<talk_base::WindowDescription>* descriptions);
  139. virtual VideoCapturer* CreateWindowCapturer(talk_base::WindowId window);
  140. virtual bool GetDesktops(
  141. std::vector<talk_base::DesktopDescription>* descriptions);
  142. virtual VideoCapturer* CreateDesktopCapturer(talk_base::DesktopId desktop);
  143. // The exclusion_list MUST be a NULL terminated list.
  144. static bool FilterDevices(std::vector<Device>* devices,
  145. const char* const exclusion_list[]);
  146. bool initialized() const { return initialized_; }
  147. protected:
  148. virtual bool GetAudioDevices(bool input, std::vector<Device>* devs);
  149. virtual bool GetAudioDevice(bool is_input, const std::string& name,
  150. Device* out);
  151. virtual bool GetDefaultVideoCaptureDevice(Device* device);
  152. bool IsInWhitelist(const std::string& key, VideoFormat* video_format) const;
  153. bool IsDeviceWhitelisted(const Device& device,
  154. VideoFormat* video_format) const;
  155. virtual void GetMaxFormat(const Device& device,
  156. VideoFormat* video_format) const;
  157. void set_initialized(bool initialized) { initialized_ = initialized; }
  158. void set_watcher(DeviceWatcher* watcher) { watcher_.reset(watcher); }
  159. DeviceWatcher* watcher() { return watcher_.get(); }
  160. private:
  161. // The exclusion_list MUST be a NULL terminated list.
  162. static bool ShouldDeviceBeIgnored(const std::string& device_name,
  163. const char* const exclusion_list[]);
  164. bool initialized_;
  165. talk_base::scoped_ptr<VideoCapturerFactory> device_video_capturer_factory_;
  166. std::map<std::string, VideoFormat> max_formats_;
  167. talk_base::scoped_ptr<DeviceWatcher> watcher_;
  168. talk_base::scoped_ptr<talk_base::WindowPicker> window_picker_;
  169. };
  170. } // namespace cricket
  171. #endif // TALK_MEDIA_DEVICES_DEVICEMANAGER_H_