media_capture_devices_dispatcher.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE-CHROMIUM file.
  4. #ifndef BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
  5. #define BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
  6. #include <string>
  7. #include "base/memory/singleton.h"
  8. #include "content/public/browser/media_observer.h"
  9. #include "content/public/common/media_stream_request.h"
  10. namespace brightray {
  11. // This singleton is used to receive updates about media events from the content
  12. // layer.
  13. class MediaCaptureDevicesDispatcher : public content::MediaObserver {
  14. public:
  15. static MediaCaptureDevicesDispatcher* GetInstance();
  16. // Methods for observers. Called on UI thread.
  17. const content::MediaStreamDevices& GetAudioCaptureDevices();
  18. const content::MediaStreamDevices& GetVideoCaptureDevices();
  19. // Helper to get the default devices which can be used by the media request.
  20. // Uses the first available devices if the default devices are not available.
  21. // If the return list is empty, it means there is no available device on the
  22. // OS.
  23. // Called on the UI thread.
  24. void GetDefaultDevices(bool audio,
  25. bool video,
  26. content::MediaStreamDevices* devices);
  27. // Helpers for picking particular requested devices, identified by raw id.
  28. // If the device requested is not available it will return NULL.
  29. const content::MediaStreamDevice* GetRequestedAudioDevice(
  30. const std::string& requested_audio_device_id);
  31. const content::MediaStreamDevice* GetRequestedVideoDevice(
  32. const std::string& requested_video_device_id);
  33. // Returns the first available audio or video device, or NULL if no devices
  34. // are available.
  35. const content::MediaStreamDevice* GetFirstAvailableAudioDevice();
  36. const content::MediaStreamDevice* GetFirstAvailableVideoDevice();
  37. // Unittests that do not require actual device enumeration should call this
  38. // API on the singleton. It is safe to call this multiple times on the
  39. // signleton.
  40. void DisableDeviceEnumerationForTesting();
  41. // Overridden from content::MediaObserver:
  42. void OnAudioCaptureDevicesChanged() override;
  43. void OnVideoCaptureDevicesChanged() override;
  44. void OnMediaRequestStateChanged(int render_process_id,
  45. int render_view_id,
  46. int page_request_id,
  47. const GURL& security_origin,
  48. content::MediaStreamType stream_type,
  49. content::MediaRequestState state) override;
  50. void OnCreatingAudioStream(int render_process_id,
  51. int render_view_id) override;
  52. void OnSetCapturingLinkSecured(int render_process_id,
  53. int render_frame_id,
  54. int page_request_id,
  55. content::MediaStreamType stream_type,
  56. bool is_secure) override;
  57. private:
  58. friend struct base::DefaultSingletonTraits<MediaCaptureDevicesDispatcher>;
  59. MediaCaptureDevicesDispatcher();
  60. ~MediaCaptureDevicesDispatcher() override;
  61. // Flag used by unittests to disable device enumeration.
  62. bool is_device_enumeration_disabled_;
  63. DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher);
  64. };
  65. } // namespace brightray
  66. #endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_