| Index: content/browser/renderer_host/media/media_devices_manager.h
|
| diff --git a/content/browser/renderer_host/media/media_devices_manager.h b/content/browser/renderer_host/media/media_devices_manager.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2761abf0c60188b9c347061701656c6c7642873d
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/media/media_devices_manager.h
|
| @@ -0,0 +1,147 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_
|
| +#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_
|
| +
|
| +#include <array>
|
| +#include <vector>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/macros.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/system_monitor/system_monitor.h"
|
| +#include "content/common/content_export.h"
|
| +#include "content/common/media/media_devices.h"
|
| +#include "media/capture/video/video_capture_device_descriptor.h"
|
| +
|
| +namespace base {
|
| +class SingleThreadTaskRunner;
|
| +}
|
| +
|
| +namespace media {
|
| +class AudioManager;
|
| +}
|
| +
|
| +namespace content {
|
| +
|
| +class MediaStreamManager;
|
| +class VideoCaptureManager;
|
| +
|
| +// Use MediaDeviceType values to index on this type.
|
| +using MediaDeviceEnumeration =
|
| + std::array<MediaDeviceInfoArray, NUM_MEDIA_DEVICE_TYPES>;
|
| +
|
| +// MediaDevicesManager is responsible for doing media-device enumerations.
|
| +// In addition it implements caching for enumeration results and device
|
| +// monitoring in order to keep caches consistent.
|
| +// All its methods must be called on the IO thread.
|
| +class CONTENT_EXPORT MediaDevicesManager
|
| + : public base::SystemMonitor::DevicesChangedObserver {
|
| + public:
|
| + // Use MediaDeviceType values to index on this type.
|
| + using BoolDeviceTypes = std::array<bool, NUM_MEDIA_DEVICE_TYPES>;
|
| +
|
| + using EnumerationCallback =
|
| + base::Callback<void(const MediaDeviceEnumeration&)>;
|
| +
|
| + enum class CachePolicy {
|
| + NO_CACHE,
|
| + SYSTEM_MONITOR,
|
| + };
|
| +
|
| + MediaDevicesManager(
|
| + media::AudioManager* audio_manager,
|
| + const scoped_refptr<VideoCaptureManager>& video_capture_manager,
|
| + MediaStreamManager* media_stream_manager);
|
| + ~MediaDevicesManager() override;
|
| +
|
| + // Performs a possibly cached device enumeration for the requested device
|
| + // types and reports the results to |callback|.
|
| + // The enumeration results passed to |callback| are guaranteed to be valid
|
| + // only for the types specified in |requested_types|.
|
| + // Note that this function is not reentrant, so if |callback| needs to perform
|
| + // another call to EnumerateDevices, it must do so by posting a task to the
|
| + // IO thread.
|
| + void EnumerateDevices(const BoolDeviceTypes& requested_types,
|
| + const EnumerationCallback& callback);
|
| +
|
| + // Manually sets a caching policy for a given device type.
|
| + // Note that manually setting the SYSTEM_MONITOR policy without having
|
| + // monitoring enabled may result in incorrect behavior.
|
| + void SetCachePolicy(MediaDeviceType type, CachePolicy policy);
|
| +
|
| + // Tries to starts device monitoring. If successful, sets the caching policy
|
| + // to SYSTEM_MONITOR for the device types supported by the monitor.
|
| + void StartMonitoring();
|
| +
|
| + // Stops device monitoring and sets the caching policy to NO_CACHE for all
|
| + // device types.
|
| + void StopMonitoring();
|
| + bool IsMonitoringStarted();
|
| +
|
| + // Implements base::SystemMonitor::DevicesChangedObserver.
|
| + // This function is only called in response to physical audio/video device
|
| + // changes.
|
| + void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override;
|
| +
|
| + // TODO(guidou): Remove this function once content::GetMediaDeviceIDForHMAC
|
| + // is rewritten to receive devices via a callback.
|
| + // See http://crbug.com/648155.
|
| + MediaDeviceInfoArray GetCachedDeviceInfo(MediaDeviceType type);
|
| +
|
| + private:
|
| + struct EnumerationRequest;
|
| +
|
| + void DoEnumerateDevices(MediaDeviceType type);
|
| + void EnumerateAudioDevices(bool is_input);
|
| +
|
| + // Callback for VideoCaptureManager::EnumerateDevices.
|
| + void VideoInputDevicesEnumerated(
|
| + const media::VideoCaptureDeviceDescriptors& descriptors);
|
| +
|
| + // Helpers to handle enumeration results.
|
| + void DevicesEnumerated(MediaDeviceType type,
|
| + const MediaDeviceInfoArray& snapshot);
|
| + void UpdateSnapshot(MediaDeviceType type,
|
| + const MediaDeviceInfoArray& new_snapshot);
|
| + void ProcessRequests();
|
| + bool IsEnumerationRequestReady(const EnumerationRequest& request_info);
|
| +
|
| + // Helpers to handle device-change notification.
|
| + void HandleDevicesChanged(MediaDeviceType type);
|
| + void NotifyMediaStreamManager(MediaDeviceType type,
|
| + const MediaDeviceInfoArray& new_snapshot);
|
| + void NotifyDeviceChangeSubscribers(MediaDeviceType type,
|
| + const MediaDeviceInfoArray& snapshot);
|
| +
|
| +#if defined(OS_MACOSX)
|
| + void StartMonitoringOnUIThread();
|
| +#endif
|
| +
|
| + bool use_fake_devices_;
|
| + media::AudioManager* const audio_manager_; // not owned
|
| + scoped_refptr<VideoCaptureManager> video_capture_manager_;
|
| + MediaStreamManager* const media_stream_manager_; // not owned
|
| +
|
| + using CachePolicies = std::array<CachePolicy, NUM_MEDIA_DEVICE_TYPES>;
|
| + CachePolicies cache_policies_;
|
| +
|
| + class CacheInfo;
|
| + using CacheInfos = std::vector<CacheInfo>;
|
| + CacheInfos cache_infos_;
|
| +
|
| + BoolDeviceTypes has_seen_result_;
|
| + std::vector<EnumerationRequest> requests_;
|
| + MediaDeviceEnumeration current_snapshot_;
|
| + bool monitoring_started_;
|
| +
|
| + base::WeakPtrFactory<MediaDevicesManager> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MediaDevicesManager);
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_
|
|
|