| OLD | NEW |
| 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 23 matching lines...) Expand all Loading... |
| 34 #include "base/memory/ref_counted.h" | 34 #include "base/memory/ref_counted.h" |
| 35 #include "base/memory/scoped_ptr.h" | 35 #include "base/memory/scoped_ptr.h" |
| 36 #include "base/message_loop/message_loop.h" | 36 #include "base/message_loop/message_loop.h" |
| 37 #include "base/power_monitor/power_observer.h" | 37 #include "base/power_monitor/power_observer.h" |
| 38 #include "base/system_monitor/system_monitor.h" | 38 #include "base/system_monitor/system_monitor.h" |
| 39 #include "content/browser/renderer_host/media/media_stream_provider.h" | 39 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 40 #include "content/common/content_export.h" | 40 #include "content/common/content_export.h" |
| 41 #include "content/common/media/media_stream_options.h" | 41 #include "content/common/media/media_stream_options.h" |
| 42 #include "content/public/browser/media_request_state.h" | 42 #include "content/public/browser/media_request_state.h" |
| 43 #include "content/public/browser/resource_context.h" | 43 #include "content/public/browser/resource_context.h" |
| 44 #include "ui/gfx/display.h" |
| 45 #include "ui/gfx/display_observer.h" |
| 44 | 46 |
| 45 namespace media { | 47 namespace media { |
| 46 class AudioManager; | 48 class AudioManager; |
| 47 } | 49 } |
| 48 | 50 |
| 49 namespace content { | 51 namespace content { |
| 50 | 52 |
| 51 class AudioInputDeviceManager; | 53 class AudioInputDeviceManager; |
| 52 class FakeMediaStreamUIProxy; | 54 class FakeMediaStreamUIProxy; |
| 53 class MediaStreamDeviceSettings; | 55 class MediaStreamDeviceSettings; |
| 54 class MediaStreamRequester; | 56 class MediaStreamRequester; |
| 55 class MediaStreamUIProxy; | 57 class MediaStreamUIProxy; |
| 56 class VideoCaptureManager; | 58 class VideoCaptureManager; |
| 57 | 59 |
| 58 // MediaStreamManager is used to generate and close new media devices, not to | 60 // MediaStreamManager is used to generate and close new media devices, not to |
| 59 // start the media flow. The classes requesting new media streams are answered | 61 // start the media flow. The classes requesting new media streams are answered |
| 60 // using MediaStreamRequester. | 62 // using MediaStreamRequester. |
| 61 class CONTENT_EXPORT MediaStreamManager | 63 class CONTENT_EXPORT MediaStreamManager |
| 62 : public MediaStreamProviderListener, | 64 : public MediaStreamProviderListener, |
| 63 public base::MessageLoop::DestructionObserver, | 65 public base::MessageLoop::DestructionObserver, |
| 64 public base::PowerObserver, | 66 public base::PowerObserver, |
| 65 public base::SystemMonitor::DevicesChangedObserver { | 67 public base::SystemMonitor::DevicesChangedObserver, |
| 68 public gfx::DisplayObserver { |
| 66 public: | 69 public: |
| 67 // Callback to deliver the result of a media request. | 70 // Callback to deliver the result of a media request. |
| 68 typedef base::Callback<void(const MediaStreamDevices& devices, | 71 typedef base::Callback<void(const MediaStreamDevices& devices, |
| 69 scoped_ptr<MediaStreamUIProxy> ui)> | 72 scoped_ptr<MediaStreamUIProxy> ui)> |
| 70 MediaRequestResponseCallback; | 73 MediaRequestResponseCallback; |
| 71 | 74 |
| 72 explicit MediaStreamManager(media::AudioManager* audio_manager); | 75 explicit MediaStreamManager(media::AudioManager* audio_manager); |
| 73 virtual ~MediaStreamManager(); | 76 virtual ~MediaStreamManager(); |
| 74 | 77 |
| 75 // Used to access VideoCaptureManager. | 78 // Used to access VideoCaptureManager. |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // the webrtcLoggingPrivate API if requested. | 347 // the webrtcLoggingPrivate API if requested. |
| 345 void AddLogMessageOnUIThread(const std::set<int>& render_process_ids, | 348 void AddLogMessageOnUIThread(const std::set<int>& render_process_ids, |
| 346 const std::string& message); | 349 const std::string& message); |
| 347 | 350 |
| 348 // Handles the callback from MediaStreamUIProxy to receive the UI window id, | 351 // Handles the callback from MediaStreamUIProxy to receive the UI window id, |
| 349 // used for excluding the notification window in desktop capturing. | 352 // used for excluding the notification window in desktop capturing. |
| 350 void OnMediaStreamUIWindowId(MediaStreamType video_type, | 353 void OnMediaStreamUIWindowId(MediaStreamType video_type, |
| 351 StreamDeviceInfoArray devices, | 354 StreamDeviceInfoArray devices, |
| 352 gfx::NativeViewId window_id); | 355 gfx::NativeViewId window_id); |
| 353 | 356 |
| 357 // gfx::DisplayObserver: |
| 358 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; |
| 359 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; |
| 360 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; |
| 361 |
| 362 void SetDisplayRotationOnIOThread(gfx::Display::Rotation rotation); |
| 363 |
| 354 // Task runner shared by VideoCaptureManager and AudioInputDeviceManager. | 364 // Task runner shared by VideoCaptureManager and AudioInputDeviceManager. |
| 355 // Note: Enumeration tasks may take seconds to complete so must never be run | 365 // Note: Enumeration tasks may take seconds to complete so must never be run |
| 356 // on any of the BrowserThreads (UI, IO, etc). See http://crbug.com/256945. | 366 // on any of the BrowserThreads (UI, IO, etc). See http://crbug.com/256945. |
| 357 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; | 367 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; |
| 358 | 368 |
| 359 media::AudioManager* const audio_manager_; // not owned | 369 media::AudioManager* const audio_manager_; // not owned |
| 360 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; | 370 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; |
| 361 scoped_refptr<VideoCaptureManager> video_capture_manager_; | 371 scoped_refptr<VideoCaptureManager> video_capture_manager_; |
| 362 | 372 |
| 363 // Indicator of device monitoring state. | 373 // Indicator of device monitoring state. |
| 364 bool monitoring_started_; | 374 bool monitoring_started_; |
| 365 | 375 |
| 366 // Stores most recently enumerated device lists. The cache is cleared when | 376 // Stores most recently enumerated device lists. The cache is cleared when |
| 367 // monitoring is stopped or there is no request for that type of device. | 377 // monitoring is stopped or there is no request for that type of device. |
| 368 EnumerationCache audio_enumeration_cache_; | 378 EnumerationCache audio_enumeration_cache_; |
| 369 EnumerationCache video_enumeration_cache_; | 379 EnumerationCache video_enumeration_cache_; |
| 370 | 380 |
| 371 // Keeps track of live enumeration commands sent to VideoCaptureManager or | 381 // Keeps track of live enumeration commands sent to VideoCaptureManager or |
| 372 // AudioInputDeviceManager, in order to only enumerate when necessary. | 382 // AudioInputDeviceManager, in order to only enumerate when necessary. |
| 373 int active_enumeration_ref_count_[NUM_MEDIA_TYPES]; | 383 int active_enumeration_ref_count_[NUM_MEDIA_TYPES]; |
| 374 | 384 |
| 375 // All non-closed request. Must be accessed on IO thread. | 385 // All non-closed request. Must be accessed on IO thread. |
| 376 DeviceRequests requests_; | 386 DeviceRequests requests_; |
| 377 | 387 |
| 378 // Hold a pointer to the IO loop to check we delete the device thread and | 388 // Hold a pointer to the IO loop to check we delete the device thread and |
| 379 // managers on the right thread. | 389 // managers on the right thread. |
| 380 base::MessageLoop* io_loop_; | 390 base::MessageLoop* io_loop_; |
| 381 | 391 |
| 392 bool observing_screen_; |
| 382 bool use_fake_ui_; | 393 bool use_fake_ui_; |
| 383 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; | 394 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; |
| 384 | 395 |
| 385 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 396 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
| 386 }; | 397 }; |
| 387 | 398 |
| 388 } // namespace content | 399 } // namespace content |
| 389 | 400 |
| 390 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 401 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
| OLD | NEW |