Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.h

Issue 2350693002: Remove device enumeration, caching and monitoring from MediaStreamManager. (Closed)
Patch Set: latest hta@ comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // MediaStreamManager is used to open/enumerate media capture devices (video 5 // MediaStreamManager is used to open/enumerate media capture devices (video
6 // supported now). Call flow: 6 // supported now). Call flow:
7 // 1. GenerateStream is called when a render process wants to use a capture 7 // 1. GenerateStream is called when a render process wants to use a capture
8 // device. 8 // device.
9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to 9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to
10 // use devices and for which device to use. 10 // use devices and for which device to use.
(...skipping 19 matching lines...) Expand all
30 #include <map> 30 #include <map>
31 #include <memory> 31 #include <memory>
32 #include <string> 32 #include <string>
33 #include <utility> 33 #include <utility>
34 #include <vector> 34 #include <vector>
35 35
36 #include "base/macros.h" 36 #include "base/macros.h"
37 #include "base/memory/ref_counted.h" 37 #include "base/memory/ref_counted.h"
38 #include "base/message_loop/message_loop.h" 38 #include "base/message_loop/message_loop.h"
39 #include "base/power_monitor/power_observer.h" 39 #include "base/power_monitor/power_observer.h"
40 #include "base/system_monitor/system_monitor.h"
41 #include "base/threading/thread.h" 40 #include "base/threading/thread.h"
42 #include "build/build_config.h" 41 #include "build/build_config.h"
43 #include "content/browser/renderer_host/media/audio_output_device_enumerator.h" 42 #include "content/browser/renderer_host/media/audio_output_device_enumerator.h"
43 #include "content/browser/renderer_host/media/media_devices_manager.h"
44 #include "content/browser/renderer_host/media/media_stream_provider.h" 44 #include "content/browser/renderer_host/media/media_stream_provider.h"
45 #include "content/common/content_export.h" 45 #include "content/common/content_export.h"
46 #include "content/common/media/media_devices.h"
46 #include "content/common/media/media_stream_options.h" 47 #include "content/common/media/media_stream_options.h"
47 #include "content/public/browser/media_request_state.h" 48 #include "content/public/browser/media_request_state.h"
48 #include "content/public/browser/resource_context.h"
49 49
50 namespace media { 50 namespace media {
51 class AudioManager; 51 class AudioManager;
52 } 52 }
53 53
54 namespace url { 54 namespace url {
55 class Origin; 55 class Origin;
56 } 56 }
57 57
58 namespace content { 58 namespace content {
59 59
60 class AudioInputDeviceManager; 60 class AudioInputDeviceManager;
61 class AudioOutputDeviceEnumerator; 61 class AudioOutputDeviceEnumerator;
62 class BrowserContext; 62 class BrowserContext;
63 class FakeMediaStreamUIProxy; 63 class FakeMediaStreamUIProxy;
64 class MediaStreamDeviceSettings; 64 class MediaStreamDeviceSettings;
65 class MediaStreamRequester; 65 class MediaStreamRequester;
66 class MediaStreamUIProxy; 66 class MediaStreamUIProxy;
67 class VideoCaptureManager; 67 class VideoCaptureManager;
68 68
69 // MediaStreamManager is used to generate and close new media devices, not to 69 // MediaStreamManager is used to generate and close new media devices, not to
70 // start the media flow. The classes requesting new media streams are answered 70 // start the media flow. The classes requesting new media streams are answered
71 // using MediaStreamRequester. 71 // using MediaStreamRequester.
72 class CONTENT_EXPORT MediaStreamManager 72 class CONTENT_EXPORT MediaStreamManager
73 : public MediaStreamProviderListener, 73 : public MediaStreamProviderListener,
74 public base::MessageLoop::DestructionObserver, 74 public base::MessageLoop::DestructionObserver,
75 public base::PowerObserver, 75 public base::PowerObserver {
76 public base::SystemMonitor::DevicesChangedObserver {
77 public: 76 public:
78 // Callback to deliver the result of a media request. 77 // Callback to deliver the result of a media request.
79 typedef base::Callback<void(const MediaStreamDevices& devices, 78 typedef base::Callback<void(const MediaStreamDevices& devices,
80 std::unique_ptr<MediaStreamUIProxy> ui)> 79 std::unique_ptr<MediaStreamUIProxy> ui)>
81 MediaRequestResponseCallback; 80 MediaRequestResponseCallback;
82 81
83 // Adds |message| to native logs for outstanding device requests, for use by 82 // Adds |message| to native logs for outstanding device requests, for use by
84 // render processes hosts whose corresponding render processes are requesting 83 // render processes hosts whose corresponding render processes are requesting
85 // logging from webrtcLoggingPrivate API. Safe to call from any thread. 84 // logging from webrtcLoggingPrivate API. Safe to call from any thread.
86 static void SendMessageToNativeLog(const std::string& message); 85 static void SendMessageToNativeLog(const std::string& message);
87 86
88 explicit MediaStreamManager(media::AudioManager* audio_manager); 87 explicit MediaStreamManager(media::AudioManager* audio_manager);
89 88
90 ~MediaStreamManager() override; 89 ~MediaStreamManager() override;
91 90
92 // Used to access VideoCaptureManager. 91 // Used to access VideoCaptureManager.
93 VideoCaptureManager* video_capture_manager(); 92 VideoCaptureManager* video_capture_manager();
94 93
95 // Used to access AudioInputDeviceManager. 94 // Used to access AudioInputDeviceManager.
96 AudioInputDeviceManager* audio_input_device_manager(); 95 AudioInputDeviceManager* audio_input_device_manager();
97 96
97 // TODO(guidou): Remove when AudioRendererHost migrates to
98 // MediaDevicesManager. See http://crbug.com/647660.
98 // Used to access AudioOutputDeviceEnumerator. 99 // Used to access AudioOutputDeviceEnumerator.
99 AudioOutputDeviceEnumerator* audio_output_device_enumerator(); 100 AudioOutputDeviceEnumerator* audio_output_device_enumerator();
100 101
102 // Used to access MediaDevicesManager.
103 MediaDevicesManager* media_devices_manager();
104
101 // Creates a new media access request which is identified by a unique string 105 // Creates a new media access request which is identified by a unique string
102 // that's returned to the caller. This will trigger the infobar and ask users 106 // that's returned to the caller. This will trigger the infobar and ask users
103 // for access to the device. |render_process_id| and |render_frame_id| are 107 // for access to the device. |render_process_id| and |render_frame_id| are
104 // used to determine where the infobar will appear to the user. |callback| is 108 // used to determine where the infobar will appear to the user. |callback| is
105 // used to send the selected device to the clients. An empty list of device 109 // used to send the selected device to the clients. An empty list of device
106 // will be returned if the users deny the access. 110 // will be returned if the users deny the access.
107 std::string MakeMediaAccessRequest( 111 std::string MakeMediaAccessRequest(
108 int render_process_id, 112 int render_process_id,
109 int render_frame_id, 113 int render_frame_id,
110 int page_request_id, 114 int page_request_id,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 int render_frame_id, 168 int render_frame_id,
165 const std::string& salt, 169 const std::string& salt,
166 int page_request_id, 170 int page_request_id,
167 const std::string& device_id, 171 const std::string& device_id,
168 MediaStreamType type, 172 MediaStreamType type,
169 const url::Origin& security_origin); 173 const url::Origin& security_origin);
170 174
171 // Finds and returns the device id corresponding to the given 175 // Finds and returns the device id corresponding to the given
172 // |source_id|. Returns true if there was a raw device id that matched the 176 // |source_id|. Returns true if there was a raw device id that matched the
173 // given |source_id|, false if nothing matched it. 177 // given |source_id|, false if nothing matched it.
178 // TODO(guidou): Update to provide a callback-based interface.
179 // See http://crbug.com/648155.
174 bool TranslateSourceIdToDeviceId(MediaStreamType stream_type, 180 bool TranslateSourceIdToDeviceId(MediaStreamType stream_type,
175 const std::string& salt, 181 const std::string& salt,
176 const url::Origin& security_origin, 182 const url::Origin& security_origin,
177 const std::string& source_id, 183 const std::string& source_id,
178 std::string* device_id) const; 184 std::string* device_id) const;
179 185
180 // Find |device_id| in the list of |requests_|, and returns its session id, 186 // Find |device_id| in the list of |requests_|, and returns its session id,
181 // or StreamDeviceInfo::kNoId if not found. 187 // or StreamDeviceInfo::kNoId if not found.
182 int VideoDeviceIdToSessionId(const std::string& device_id) const; 188 int VideoDeviceIdToSessionId(const std::string& device_id) const;
183 189
184 // Called by UI to make sure the device monitor is started so that UI receive 190 // Called by UI to make sure the device monitor is started so that UI receive
185 // notifications about device changes. 191 // notifications about device changes.
186 void EnsureDeviceMonitorStarted(); 192 void EnsureDeviceMonitorStarted();
187 193
188 // Implements MediaStreamProviderListener. 194 // Implements MediaStreamProviderListener.
189 void Opened(MediaStreamType stream_type, int capture_session_id) override; 195 void Opened(MediaStreamType stream_type, int capture_session_id) override;
190 void Closed(MediaStreamType stream_type, int capture_session_id) override; 196 void Closed(MediaStreamType stream_type, int capture_session_id) override;
191 void DevicesEnumerated(MediaStreamType stream_type,
192 const StreamDeviceInfoArray& devices) override;
193 void Aborted(MediaStreamType stream_type, int capture_session_id) override; 197 void Aborted(MediaStreamType stream_type, int capture_session_id) override;
194 198
195 // Implements base::SystemMonitor::DevicesChangedObserver.
196 void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override;
197
198 // Returns all devices currently opened by a request with label |label|. 199 // Returns all devices currently opened by a request with label |label|.
199 // If no request with |label| exist, an empty array is returned. 200 // If no request with |label| exist, an empty array is returned.
200 StreamDeviceInfoArray GetDevicesOpenedByRequest( 201 StreamDeviceInfoArray GetDevicesOpenedByRequest(
201 const std::string& label) const; 202 const std::string& label) const;
202 203
203 // This object gets deleted on the UI thread after the IO thread has been 204 // This object gets deleted on the UI thread after the IO thread has been
204 // destroyed. So we need to know when IO thread is being destroyed so that 205 // destroyed. So we need to know when IO thread is being destroyed so that
205 // we can delete VideoCaptureManager and AudioInputDeviceManager. Normally 206 // we can delete VideoCaptureManager and AudioInputDeviceManager. Normally
206 // this is handled by 207 // this is handled by
207 // base::MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop. 208 // base::MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // is allowed to access |origin|. 258 // is allowed to access |origin|.
258 static bool IsOriginAllowed(int render_process_id, const url::Origin& origin); 259 static bool IsOriginAllowed(int render_process_id, const url::Origin& origin);
259 260
260 // Set whether the capturing is secure for the capturing session with given 261 // Set whether the capturing is secure for the capturing session with given
261 // |session_id|, |render_process_id|, and the MediaStreamType |type|. 262 // |session_id|, |render_process_id|, and the MediaStreamType |type|.
262 void SetCapturingLinkSecured(int render_process_id, 263 void SetCapturingLinkSecured(int render_process_id,
263 int session_id, 264 int session_id,
264 content::MediaStreamType type, 265 content::MediaStreamType type,
265 bool is_secure); 266 bool is_secure);
266 267
268 // Helper for sending up-to-date device lists to media observer when a
269 // capture device is plugged in or unplugged.
270 void NotifyDevicesChanged(MediaDeviceType stream_type,
271 const MediaDeviceInfoArray& devices);
272
273 // This method is called when an audio or video device is removed. It makes
274 // sure all MediaStreams that use a removed device are stopped and that the
275 // render process is notified.
276 void StopRemovedDevice(MediaDeviceType type, const MediaDeviceInfo& device);
277
278 // TODO(guidou): Remove this function once handling for renderer requests for
279 // device-event notifications is moved out of MediaStreamDispatcherHost.
280 // See http://crbug.com/648183.
281 void NotifyDeviceChangeSubscribers(MediaStreamType type);
282
267 private: 283 private:
268 // Contains all data needed to keep track of requests. 284 // Contains all data needed to keep track of requests.
269 class DeviceRequest; 285 class DeviceRequest;
270 286
271 // Cache enumerated device list.
272 struct EnumerationCache {
273 EnumerationCache();
274 ~EnumerationCache();
275
276 bool valid;
277 StreamDeviceInfoArray devices;
278 };
279
280 // |DeviceRequests| is a list to ensure requests are processed in the order 287 // |DeviceRequests| is a list to ensure requests are processed in the order
281 // they arrive. The first member of the pair is the label of the 288 // they arrive. The first member of the pair is the label of the
282 // |DeviceRequest|. 289 // |DeviceRequest|.
283 using LabeledDeviceRequest = std::pair<std::string, DeviceRequest*>; 290 using LabeledDeviceRequest = std::pair<std::string, DeviceRequest*>;
284 using DeviceRequests = std::list<LabeledDeviceRequest>; 291 using DeviceRequests = std::list<LabeledDeviceRequest>;
285 292
286 // Initializes the device managers on IO thread. Auto-starts the device 293 // Initializes the device managers on IO thread. Auto-starts the device
287 // thread and registers this as a listener with the device managers. 294 // thread and registers this as a listener with the device managers.
288 void InitializeDeviceManagersOnIOThread(); 295 void InitializeDeviceManagersOnIOThread();
289 296
290 // Helper for sending up-to-date device lists to media observer when a
291 // capture device is plugged in or unplugged.
292 void NotifyDevicesChanged(MediaStreamType stream_type,
293 const StreamDeviceInfoArray& devices);
294 297
295 // |output_parameters| contains real values only if the request requires it. 298 // |output_parameters| contains real values only if the request requires it.
296 void HandleAccessRequestResponse( 299 void HandleAccessRequestResponse(
297 const std::string& label, 300 const std::string& label,
298 const media::AudioParameters& output_parameters, 301 const media::AudioParameters& output_parameters,
299 const MediaStreamDevices& devices, 302 const MediaStreamDevices& devices,
300 content::MediaStreamRequestResult result); 303 content::MediaStreamRequestResult result);
301 void StopMediaStreamFromBrowser(const std::string& label); 304 void StopMediaStreamFromBrowser(const std::string& label);
302 305
303 void DoEnumerateDevices(const std::string& label); 306 void DoEnumerateDevices(const std::string& label);
304 307
305 void AudioOutputDevicesEnumerated( 308 void AudioOutputDevicesEnumerated(const std::string& label,
306 const AudioOutputDeviceEnumeration& device_enumeration); 309 const MediaDeviceEnumeration& enumeration);
307 310
308 // Helpers. 311 // Helpers.
309 // Checks if all devices that was requested in the request identififed by 312 // Checks if all devices that was requested in the request identififed by
310 // |label| has been opened and set the request state accordingly. 313 // |label| has been opened and set the request state accordingly.
311 void HandleRequestDone(const std::string& label, 314 void HandleRequestDone(const std::string& label,
312 DeviceRequest* request); 315 DeviceRequest* request);
313 // Stop the use of the device associated with |session_id| of type |type| in 316 // Stop the use of the device associated with |session_id| of type |type| in
314 // all |requests_|. The device is removed from the request. If a request 317 // all |requests_|. The device is removed from the request. If a request
315 /// doesn't use any devices as a consequence, the request is deleted. 318 /// doesn't use any devices as a consequence, the request is deleted.
316 void StopDevice(MediaStreamType type, int session_id); 319 void StopDevice(MediaStreamType type, int session_id);
317 // Calls the correct capture manager and close the device with |session_id|. 320 // Calls the correct capture manager and close the device with |session_id|.
318 // All requests that uses the device are updated. 321 // All requests that uses the device are updated.
319 void CloseDevice(MediaStreamType type, int session_id); 322 void CloseDevice(MediaStreamType type, int session_id);
320 // Returns true if a request for devices has been completed and the devices 323 // Returns true if a request for devices has been completed and the devices
321 // has either been opened or an error has occurred. 324 // has either been opened or an error has occurred.
322 bool RequestDone(const DeviceRequest& request) const; 325 bool RequestDone(const DeviceRequest& request) const;
323 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); 326 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type);
324 void StartEnumeration(DeviceRequest* request); 327 void StartEnumeration(DeviceRequest* request, const std::string& label);
325 std::string AddRequest(DeviceRequest* request); 328 std::string AddRequest(DeviceRequest* request);
326 DeviceRequest* FindRequest(const std::string& label) const; 329 DeviceRequest* FindRequest(const std::string& label) const;
327 void DeleteRequest(const std::string& label); 330 void DeleteRequest(const std::string& label);
328 void ClearEnumerationCache(EnumerationCache* cache);
329 // Returns true if the |cache| is invalid, false if it's invalid or if
330 // the |stream_type| is MEDIA_NO_SERVICE.
331 // On Android, this function will always return true for
332 // MEDIA_DEVICE_AUDIO_CAPTURE since we don't have a SystemMonitor to tell
333 // us about audio device changes.
334 bool EnumerationRequired(EnumerationCache* cache, MediaStreamType type);
335 // Prepare the request with label |label| by starting device enumeration if 331 // Prepare the request with label |label| by starting device enumeration if
336 // needed. 332 // needed.
337 void SetupRequest(const std::string& label); 333 void SetupRequest(const std::string& label);
338 // Prepare |request| of type MEDIA_DEVICE_AUDIO_CAPTURE and/or 334 // Prepare |request| of type MEDIA_DEVICE_AUDIO_CAPTURE and/or
339 // MEDIA_DEVICE_VIDEO_CAPTURE for being posted to the UI by parsing 335 // MEDIA_DEVICE_VIDEO_CAPTURE for being posted to the UI by parsing
340 // StreamControls for requested device IDs. 336 // StreamControls for requested device IDs.
341 bool SetupDeviceCaptureRequest(DeviceRequest* request); 337 bool SetupDeviceCaptureRequest(DeviceRequest* request,
338 const MediaDeviceEnumeration& enumeration);
342 // Prepare |request| of type MEDIA_TAB_AUDIO_CAPTURE and/or 339 // Prepare |request| of type MEDIA_TAB_AUDIO_CAPTURE and/or
343 // MEDIA_TAB_VIDEO_CAPTURE for being posted to the UI by parsing 340 // MEDIA_TAB_VIDEO_CAPTURE for being posted to the UI by parsing
344 // StreamControls for requested tab capture IDs. 341 // StreamControls for requested tab capture IDs.
345 bool SetupTabCaptureRequest(DeviceRequest* request); 342 bool SetupTabCaptureRequest(DeviceRequest* request);
346 // Prepare |request| of type MEDIA_DESKTOP_AUDIO_CAPTURE and/or 343 // Prepare |request| of type MEDIA_DESKTOP_AUDIO_CAPTURE and/or
347 // MEDIA_DESKTOP_VIDEO_CAPTURE for being posted to the UI by parsing 344 // MEDIA_DESKTOP_VIDEO_CAPTURE for being posted to the UI by parsing
348 // StreamControls for the requested desktop ID. 345 // StreamControls for the requested desktop ID.
349 bool SetupScreenCaptureRequest(DeviceRequest* request); 346 bool SetupScreenCaptureRequest(DeviceRequest* request);
350 // Called when a request has been setup and devices have been enumerated if 347 // Called when a request has been setup and devices have been enumerated if
351 // needed. 348 // needed.
352 void ReadOutputParamsAndPostRequestToUI(const std::string& label, 349 void ReadOutputParamsAndPostRequestToUI(
353 DeviceRequest* request); 350 const std::string& label,
351 DeviceRequest* request,
352 const MediaDeviceEnumeration& enumeration);
354 // Called when audio output parameters have been read if needed. 353 // Called when audio output parameters have been read if needed.
355 void PostRequestToUI(const std::string& label, 354 void PostRequestToUI(const std::string& label,
356 DeviceRequest* request, 355 DeviceRequest* request,
356 const MediaDeviceEnumeration& enumeration,
357 const media::AudioParameters& output_parameters); 357 const media::AudioParameters& output_parameters);
358 // Returns true if a device with |device_id| has already been requested with 358 // Returns true if a device with |device_id| has already been requested with
359 // a render procecss_id and render_frame_id and type equal to the the values 359 // a render procecss_id and render_frame_id and type equal to the the values
360 // in |request|. If it has been requested, |device_info| contain information 360 // in |request|. If it has been requested, |device_info| contain information
361 // about the device. 361 // about the device.
362 bool FindExistingRequestedDeviceInfo( 362 bool FindExistingRequestedDeviceInfo(
363 const DeviceRequest& new_request, 363 const DeviceRequest& new_request,
364 const MediaStreamDevice& new_device_info, 364 const MediaStreamDevice& new_device_info,
365 StreamDeviceInfo* existing_device_info, 365 StreamDeviceInfo* existing_device_info,
366 MediaRequestState* existing_request_state) const; 366 MediaRequestState* existing_request_state) const;
367 367
368 void FinalizeGenerateStream(const std::string& label, DeviceRequest* request); 368 void FinalizeGenerateStream(const std::string& label, DeviceRequest* request);
369 void FinalizeRequestFailed(const std::string& label, 369 void FinalizeRequestFailed(const std::string& label,
370 DeviceRequest* request, 370 DeviceRequest* request,
371 content::MediaStreamRequestResult result); 371 content::MediaStreamRequestResult result);
372 void FinalizeOpenDevice(const std::string& label, DeviceRequest* request); 372 void FinalizeOpenDevice(const std::string& label, DeviceRequest* request);
373 void FinalizeMediaAccessRequest(const std::string& label, 373 void FinalizeMediaAccessRequest(const std::string& label,
374 DeviceRequest* request, 374 DeviceRequest* request,
375 const MediaStreamDevices& devices); 375 const MediaStreamDevices& devices);
376 void FinalizeEnumerateDevices(const std::string& label, 376 void FinalizeEnumerateDevices(const std::string& label,
377 DeviceRequest* request); 377 DeviceRequest* request);
378 void HandleCheckMediaAccessResponse(const std::string& label, 378 void HandleCheckMediaAccessResponse(const std::string& label,
379 bool have_access); 379 bool have_access);
380 380
381 // This method is called when an audio or video device is plugged in or
382 // removed. It make sure all MediaStreams that use a removed device is
383 // stopped and that the render process is notified. |old_devices| is the list
384 // of previously available devices. |new_devices| is the new
385 // list of currently available devices.
386 void StopRemovedDevices(const StreamDeviceInfoArray& old_devices,
387 const StreamDeviceInfoArray& new_devices);
388 // Helper method used by StopRemovedDevices to stop the use of a certain
389 // device.
390 void StopRemovedDevice(const MediaStreamDevice& device);
391
392 // Helpers to start and stop monitoring devices.
393 void StartMonitoring();
394 void StopMonitoring();
395 #if defined(OS_MACOSX)
396 void StartMonitoringOnUIThread();
397 #endif
398
399 // Picks a device ID from a list of required and alternate device IDs, 381 // Picks a device ID from a list of required and alternate device IDs,
400 // presented as part of a TrackControls structure. 382 // presented as part of a TrackControls structure.
401 // Either the required device ID is picked (if present), or the first 383 // Either the required device ID is picked (if present), or the first
402 // valid alternate device ID. 384 // valid alternate device ID.
403 // Returns false if the required device ID is present and invalid. 385 // Returns false if the required device ID is present and invalid.
404 // Otherwise, if no valid device is found, device_id is unchanged. 386 // Otherwise, if no valid device is found, device_id is unchanged.
405 bool PickDeviceId(MediaStreamType type, 387 bool PickDeviceId(const std::string& salt,
406 const std::string& salt,
407 const url::Origin& security_origin, 388 const url::Origin& security_origin,
408 const TrackControls& controls, 389 const TrackControls& controls,
390 const MediaDeviceInfoArray& devices,
409 std::string* device_id) const; 391 std::string* device_id) const;
410 392
411 // Finds the requested device id from request. The requested device type 393 // Finds the requested device id from request. The requested device type
412 // must be MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. 394 // must be MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE.
413 bool GetRequestedDeviceCaptureId(const DeviceRequest* request, 395 bool GetRequestedDeviceCaptureId(const DeviceRequest* request,
414 MediaStreamType type, 396 MediaStreamType type,
397 const MediaDeviceInfoArray& devices,
415 std::string* device_id) const; 398 std::string* device_id) const;
416 399
417 void TranslateDeviceIdToSourceId(DeviceRequest* request, 400 void TranslateDeviceIdToSourceId(DeviceRequest* request,
418 MediaStreamDevice* device); 401 MediaStreamDevice* device);
419 402
420 // Handles the callback from MediaStreamUIProxy to receive the UI window id, 403 // Handles the callback from MediaStreamUIProxy to receive the UI window id,
421 // used for excluding the notification window in desktop capturing. 404 // used for excluding the notification window in desktop capturing.
422 void OnMediaStreamUIWindowId(MediaStreamType video_type, 405 void OnMediaStreamUIWindowId(MediaStreamType video_type,
423 StreamDeviceInfoArray devices, 406 StreamDeviceInfoArray devices,
424 gfx::NativeViewId window_id); 407 gfx::NativeViewId window_id);
425 408
426 // Runs on the IO thread and does the actual [un]registration of callbacks. 409 // Runs on the IO thread and does the actual [un]registration of callbacks.
427 void DoNativeLogCallbackRegistration(int renderer_host_id, 410 void DoNativeLogCallbackRegistration(int renderer_host_id,
428 const base::Callback<void(const std::string&)>& callback); 411 const base::Callback<void(const std::string&)>& callback);
429 void DoNativeLogCallbackUnregistration(int renderer_host_id); 412 void DoNativeLogCallbackUnregistration(int renderer_host_id);
430 413
431 void NotifyDeviceChangeSubscribers(MediaStreamType type); 414 // Callback to handle the reply to a low-level enumeration request.
415 void DevicesEnumerated(bool requested_audio_input,
416 bool requested_video_input,
417 const std::string& label,
418 const MediaDeviceEnumeration& enumeration);
419
420 // TODO(guidou): Remove once handling of renderer-issued enumeration requests
421 // is moved out of MediaStreamManager. See http://crbug.com/648183.
422 void ProcessEnumerationRequest(const std::string& label,
423 DeviceRequest* request,
424 MediaStreamType stream_type,
425 const MediaDeviceInfoArray& enumeration);
426
427 // TODO(guidou): Remove this function once the concept of open enumeration
428 // requests is eliminated. See http://crbug.com/648183.
429 void ProcessOpenEnumerationRequests(MediaStreamType stream_type,
430 const MediaDeviceInfoArray& devices);
432 431
433 // Task runner shared by VideoCaptureManager and AudioInputDeviceManager and 432 // Task runner shared by VideoCaptureManager and AudioInputDeviceManager and
434 // used for enumerating audio output devices. 433 // used for enumerating audio output devices.
435 // Note: Enumeration tasks may take seconds to complete so must never be run 434 // Note: Enumeration tasks may take seconds to complete so must never be run
436 // on any of the BrowserThreads (UI, IO, etc). See http://crbug.com/256945. 435 // on any of the BrowserThreads (UI, IO, etc). See http://crbug.com/256945.
437 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; 436 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_;
438 437
439 media::AudioManager* const audio_manager_; // not owned 438 media::AudioManager* const audio_manager_; // not owned
440 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; 439 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
441 scoped_refptr<VideoCaptureManager> video_capture_manager_; 440 scoped_refptr<VideoCaptureManager> video_capture_manager_;
442 std::unique_ptr<AudioOutputDeviceEnumerator> audio_output_device_enumerator_; 441 std::unique_ptr<AudioOutputDeviceEnumerator> audio_output_device_enumerator_;
443 #if defined(OS_WIN) 442 #if defined(OS_WIN)
444 base::Thread video_capture_thread_; 443 base::Thread video_capture_thread_;
445 #endif 444 #endif
446 445
447 // Indicator of device monitoring state. 446 std::unique_ptr<MediaDevicesManager> media_devices_manager_;
448 bool monitoring_started_;
449
450 // Stores most recently enumerated device lists. The cache is cleared when
451 // monitoring is stopped or there is no request for that type of device.
452 EnumerationCache audio_enumeration_cache_;
453 EnumerationCache video_enumeration_cache_;
454
455 // Keeps track of live enumeration commands sent to VideoCaptureManager or
456 // AudioInputDeviceManager, in order to only enumerate when necessary.
457 int active_enumeration_ref_count_[NUM_MEDIA_TYPES];
458 447
459 // All non-closed request. Must be accessed on IO thread. 448 // All non-closed request. Must be accessed on IO thread.
460 DeviceRequests requests_; 449 DeviceRequests requests_;
461 450
462 bool use_fake_ui_; 451 bool use_fake_ui_;
463 std::unique_ptr<FakeMediaStreamUIProxy> fake_ui_; 452 std::unique_ptr<FakeMediaStreamUIProxy> fake_ui_;
464 453
465 // Maps render process hosts to log callbacks. Used on the IO thread. 454 // Maps render process hosts to log callbacks. Used on the IO thread.
466 std::map<int, base::Callback<void(const std::string&)>> log_callbacks_; 455 std::map<int, base::Callback<void(const std::string&)>> log_callbacks_;
467 456
468 // Objects subscribed to changes in the set of media devices. 457 // Objects subscribed to changes in the set of media devices.
469 std::vector<MediaStreamRequester*> device_change_subscribers_; 458 std::vector<MediaStreamRequester*> device_change_subscribers_;
470 459
471 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); 460 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager);
472 }; 461 };
473 462
474 } // namespace content 463 } // namespace content
475 464
476 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 465 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698