Index: content/browser/renderer_host/media/media_stream_manager.h |
diff --git a/content/browser/renderer_host/media/media_stream_manager.h b/content/browser/renderer_host/media/media_stream_manager.h |
index 0fddf64ace80d8df36db50859f398b70b956e45d..0d91543f874b517b4c6a48fa9252bf1577a75b14 100644 |
--- a/content/browser/renderer_host/media/media_stream_manager.h |
+++ b/content/browser/renderer_host/media/media_stream_manager.h |
@@ -37,15 +37,15 @@ |
#include "base/memory/ref_counted.h" |
#include "base/message_loop/message_loop.h" |
#include "base/power_monitor/power_observer.h" |
-#include "base/system_monitor/system_monitor.h" |
#include "base/threading/thread.h" |
#include "build/build_config.h" |
#include "content/browser/renderer_host/media/audio_output_device_enumerator.h" |
+#include "content/browser/renderer_host/media/media_devices_manager.h" |
#include "content/browser/renderer_host/media/media_stream_provider.h" |
#include "content/common/content_export.h" |
+#include "content/common/media/media_devices.h" |
#include "content/common/media/media_stream_options.h" |
#include "content/public/browser/media_request_state.h" |
-#include "content/public/browser/resource_context.h" |
namespace media { |
class AudioManager; |
@@ -72,8 +72,7 @@ class VideoCaptureManager; |
class CONTENT_EXPORT MediaStreamManager |
: public MediaStreamProviderListener, |
public base::MessageLoop::DestructionObserver, |
- public base::PowerObserver, |
- public base::SystemMonitor::DevicesChangedObserver { |
+ public base::PowerObserver { |
public: |
// Callback to deliver the result of a media request. |
typedef base::Callback<void(const MediaStreamDevices& devices, |
@@ -95,9 +94,14 @@ class CONTENT_EXPORT MediaStreamManager |
// Used to access AudioInputDeviceManager. |
AudioInputDeviceManager* audio_input_device_manager(); |
+ // TODO(guidou): Remove when AudioRendererHost migrates to |
+ // MediaDevicesManager. See http://crbug.com/647660. |
// Used to access AudioOutputDeviceEnumerator. |
AudioOutputDeviceEnumerator* audio_output_device_enumerator(); |
+ // Used to access MediaDevicesManager. |
+ MediaDevicesManager* media_devices_manager(); |
+ |
// Creates a new media access request which is identified by a unique string |
// that's returned to the caller. This will trigger the infobar and ask users |
// for access to the device. |render_process_id| and |render_frame_id| are |
@@ -171,6 +175,8 @@ class CONTENT_EXPORT MediaStreamManager |
// Finds and returns the device id corresponding to the given |
// |source_id|. Returns true if there was a raw device id that matched the |
// given |source_id|, false if nothing matched it. |
+ // TODO(guidou): Update to provide a callback-based interface. |
+ // See http://crbug.com/648155. |
bool TranslateSourceIdToDeviceId(MediaStreamType stream_type, |
const std::string& salt, |
const url::Origin& security_origin, |
@@ -188,13 +194,8 @@ class CONTENT_EXPORT MediaStreamManager |
// Implements MediaStreamProviderListener. |
void Opened(MediaStreamType stream_type, int capture_session_id) override; |
void Closed(MediaStreamType stream_type, int capture_session_id) override; |
- void DevicesEnumerated(MediaStreamType stream_type, |
- const StreamDeviceInfoArray& devices) override; |
void Aborted(MediaStreamType stream_type, int capture_session_id) override; |
- // Implements base::SystemMonitor::DevicesChangedObserver. |
- void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override; |
- |
// Returns all devices currently opened by a request with label |label|. |
// If no request with |label| exist, an empty array is returned. |
StreamDeviceInfoArray GetDevicesOpenedByRequest( |
@@ -264,19 +265,25 @@ class CONTENT_EXPORT MediaStreamManager |
content::MediaStreamType type, |
bool is_secure); |
+ // Helper for sending up-to-date device lists to media observer when a |
+ // capture device is plugged in or unplugged. |
+ void NotifyDevicesChanged(MediaDeviceType stream_type, |
+ const MediaDeviceInfoArray& devices); |
+ |
+ // This method is called when an audio or video device is removed. It makes |
+ // sure all MediaStreams that use a removed device are stopped and that the |
+ // render process is notified. |
+ void StopRemovedDevice(MediaDeviceType type, const MediaDeviceInfo& device); |
+ |
+ // TODO(guidou): Remove this function once handling for renderer requests for |
+ // device-event notifications is moved out of MediaStreamDispatcherHost. |
+ // See http://crbug.com/648183. |
+ void NotifyDeviceChangeSubscribers(MediaStreamType type); |
+ |
private: |
// Contains all data needed to keep track of requests. |
class DeviceRequest; |
- // Cache enumerated device list. |
- struct EnumerationCache { |
- EnumerationCache(); |
- ~EnumerationCache(); |
- |
- bool valid; |
- StreamDeviceInfoArray devices; |
- }; |
- |
// |DeviceRequests| is a list to ensure requests are processed in the order |
// they arrive. The first member of the pair is the label of the |
// |DeviceRequest|. |
@@ -287,10 +294,6 @@ class CONTENT_EXPORT MediaStreamManager |
// thread and registers this as a listener with the device managers. |
void InitializeDeviceManagersOnIOThread(); |
- // Helper for sending up-to-date device lists to media observer when a |
- // capture device is plugged in or unplugged. |
- void NotifyDevicesChanged(MediaStreamType stream_type, |
- const StreamDeviceInfoArray& devices); |
// |output_parameters| contains real values only if the request requires it. |
void HandleAccessRequestResponse( |
@@ -302,8 +305,8 @@ class CONTENT_EXPORT MediaStreamManager |
void DoEnumerateDevices(const std::string& label); |
- void AudioOutputDevicesEnumerated( |
- const AudioOutputDeviceEnumeration& device_enumeration); |
+ void AudioOutputDevicesEnumerated(const std::string& label, |
+ const MediaDeviceEnumeration& enumeration); |
// Helpers. |
// Checks if all devices that was requested in the request identififed by |
@@ -321,24 +324,18 @@ class CONTENT_EXPORT MediaStreamManager |
// has either been opened or an error has occurred. |
bool RequestDone(const DeviceRequest& request) const; |
MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); |
- void StartEnumeration(DeviceRequest* request); |
+ void StartEnumeration(DeviceRequest* request, const std::string& label); |
std::string AddRequest(DeviceRequest* request); |
DeviceRequest* FindRequest(const std::string& label) const; |
void DeleteRequest(const std::string& label); |
- void ClearEnumerationCache(EnumerationCache* cache); |
- // Returns true if the |cache| is invalid, false if it's invalid or if |
- // the |stream_type| is MEDIA_NO_SERVICE. |
- // On Android, this function will always return true for |
- // MEDIA_DEVICE_AUDIO_CAPTURE since we don't have a SystemMonitor to tell |
- // us about audio device changes. |
- bool EnumerationRequired(EnumerationCache* cache, MediaStreamType type); |
// Prepare the request with label |label| by starting device enumeration if |
// needed. |
void SetupRequest(const std::string& label); |
// Prepare |request| of type MEDIA_DEVICE_AUDIO_CAPTURE and/or |
// MEDIA_DEVICE_VIDEO_CAPTURE for being posted to the UI by parsing |
// StreamControls for requested device IDs. |
- bool SetupDeviceCaptureRequest(DeviceRequest* request); |
+ bool SetupDeviceCaptureRequest(DeviceRequest* request, |
+ const MediaDeviceEnumeration& enumeration); |
// Prepare |request| of type MEDIA_TAB_AUDIO_CAPTURE and/or |
// MEDIA_TAB_VIDEO_CAPTURE for being posted to the UI by parsing |
// StreamControls for requested tab capture IDs. |
@@ -349,11 +346,14 @@ class CONTENT_EXPORT MediaStreamManager |
bool SetupScreenCaptureRequest(DeviceRequest* request); |
// Called when a request has been setup and devices have been enumerated if |
// needed. |
- void ReadOutputParamsAndPostRequestToUI(const std::string& label, |
- DeviceRequest* request); |
+ void ReadOutputParamsAndPostRequestToUI( |
+ const std::string& label, |
+ DeviceRequest* request, |
+ const MediaDeviceEnumeration& enumeration); |
// Called when audio output parameters have been read if needed. |
void PostRequestToUI(const std::string& label, |
DeviceRequest* request, |
+ const MediaDeviceEnumeration& enumeration, |
const media::AudioParameters& output_parameters); |
// Returns true if a device with |device_id| has already been requested with |
// a render procecss_id and render_frame_id and type equal to the the values |
@@ -378,40 +378,23 @@ class CONTENT_EXPORT MediaStreamManager |
void HandleCheckMediaAccessResponse(const std::string& label, |
bool have_access); |
- // This method is called when an audio or video device is plugged in or |
- // removed. It make sure all MediaStreams that use a removed device is |
- // stopped and that the render process is notified. |old_devices| is the list |
- // of previously available devices. |new_devices| is the new |
- // list of currently available devices. |
- void StopRemovedDevices(const StreamDeviceInfoArray& old_devices, |
- const StreamDeviceInfoArray& new_devices); |
- // Helper method used by StopRemovedDevices to stop the use of a certain |
- // device. |
- void StopRemovedDevice(const MediaStreamDevice& device); |
- |
- // Helpers to start and stop monitoring devices. |
- void StartMonitoring(); |
- void StopMonitoring(); |
-#if defined(OS_MACOSX) |
- void StartMonitoringOnUIThread(); |
-#endif |
- |
// Picks a device ID from a list of required and alternate device IDs, |
// presented as part of a TrackControls structure. |
// Either the required device ID is picked (if present), or the first |
// valid alternate device ID. |
// Returns false if the required device ID is present and invalid. |
// Otherwise, if no valid device is found, device_id is unchanged. |
- bool PickDeviceId(MediaStreamType type, |
- const std::string& salt, |
+ bool PickDeviceId(const std::string& salt, |
const url::Origin& security_origin, |
const TrackControls& controls, |
+ const MediaDeviceInfoArray& devices, |
std::string* device_id) const; |
// Finds the requested device id from request. The requested device type |
// must be MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. |
bool GetRequestedDeviceCaptureId(const DeviceRequest* request, |
MediaStreamType type, |
+ const MediaDeviceInfoArray& devices, |
std::string* device_id) const; |
void TranslateDeviceIdToSourceId(DeviceRequest* request, |
@@ -428,7 +411,23 @@ class CONTENT_EXPORT MediaStreamManager |
const base::Callback<void(const std::string&)>& callback); |
void DoNativeLogCallbackUnregistration(int renderer_host_id); |
- void NotifyDeviceChangeSubscribers(MediaStreamType type); |
+ // Callback to handle the reply to a low-level enumeration request. |
+ void DevicesEnumerated(bool requested_audio_input, |
+ bool requested_video_input, |
+ const std::string& label, |
+ const MediaDeviceEnumeration& enumeration); |
+ |
+ // TODO(guidou): Remove once handling of renderer-issued enumeration requests |
+ // is moved out of MediaStreamManager. See http://crbug.com/648183. |
+ void ProcessEnumerationRequest(const std::string& label, |
+ DeviceRequest* request, |
+ MediaStreamType stream_type, |
+ const MediaDeviceInfoArray& enumeration); |
+ |
+ // TODO(guidou): Remove this function once the concept of open enumeration |
+ // requests is eliminated. See http://crbug.com/648183. |
+ void ProcessOpenEnumerationRequests(MediaStreamType stream_type, |
+ const MediaDeviceInfoArray& devices); |
// Task runner shared by VideoCaptureManager and AudioInputDeviceManager and |
// used for enumerating audio output devices. |
@@ -444,17 +443,7 @@ class CONTENT_EXPORT MediaStreamManager |
base::Thread video_capture_thread_; |
#endif |
- // Indicator of device monitoring state. |
- bool monitoring_started_; |
- |
- // Stores most recently enumerated device lists. The cache is cleared when |
- // monitoring is stopped or there is no request for that type of device. |
- EnumerationCache audio_enumeration_cache_; |
- EnumerationCache video_enumeration_cache_; |
- |
- // Keeps track of live enumeration commands sent to VideoCaptureManager or |
- // AudioInputDeviceManager, in order to only enumerate when necessary. |
- int active_enumeration_ref_count_[NUM_MEDIA_TYPES]; |
+ std::unique_ptr<MediaDevicesManager> media_devices_manager_; |
// All non-closed request. Must be accessed on IO thread. |
DeviceRequests requests_; |