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 #include "content/browser/renderer_host/media/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "content/public/browser/media_request_state.h" | 32 #include "content/public/browser/media_request_state.h" |
33 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
34 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
35 #include "content/public/common/media_stream_request.h" | 35 #include "content/public/common/media_stream_request.h" |
36 #include "media/audio/audio_manager_base.h" | 36 #include "media/audio/audio_manager_base.h" |
37 #include "media/audio/audio_parameters.h" | 37 #include "media/audio/audio_parameters.h" |
38 #include "media/base/channel_layout.h" | 38 #include "media/base/channel_layout.h" |
39 #include "media/base/media_switches.h" | 39 #include "media/base/media_switches.h" |
40 #include "media/video/capture/fake_video_capture_device_factory.h" | 40 #include "media/video/capture/fake_video_capture_device_factory.h" |
41 #include "media/video/capture/file_video_capture_device_factory.h" | 41 #include "media/video/capture/file_video_capture_device_factory.h" |
42 #include "ui/gfx/screen.h" | |
42 #include "url/gurl.h" | 43 #include "url/gurl.h" |
43 | 44 |
44 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
45 #include "base/win/scoped_com_initializer.h" | 46 #include "base/win/scoped_com_initializer.h" |
46 #endif | 47 #endif |
47 | 48 |
48 namespace content { | 49 namespace content { |
49 | 50 |
50 // Forward declaration of DeviceMonitorMac and its only useable method. | 51 // Forward declaration of DeviceMonitorMac and its only useable method. |
51 class DeviceMonitorMac { | 52 class DeviceMonitorMac { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 : valid(false) { | 337 : valid(false) { |
337 } | 338 } |
338 | 339 |
339 MediaStreamManager::EnumerationCache::~EnumerationCache() { | 340 MediaStreamManager::EnumerationCache::~EnumerationCache() { |
340 } | 341 } |
341 | 342 |
342 MediaStreamManager::MediaStreamManager() | 343 MediaStreamManager::MediaStreamManager() |
343 : audio_manager_(NULL), | 344 : audio_manager_(NULL), |
344 monitoring_started_(false), | 345 monitoring_started_(false), |
345 io_loop_(NULL), | 346 io_loop_(NULL), |
347 observing_screen_(false), | |
346 use_fake_ui_(false) {} | 348 use_fake_ui_(false) {} |
347 | 349 |
348 MediaStreamManager::MediaStreamManager(media::AudioManager* audio_manager) | 350 MediaStreamManager::MediaStreamManager(media::AudioManager* audio_manager) |
349 : audio_manager_(audio_manager), | 351 : audio_manager_(audio_manager), |
350 monitoring_started_(false), | 352 monitoring_started_(false), |
351 io_loop_(NULL), | 353 io_loop_(NULL), |
354 observing_screen_(false), | |
352 use_fake_ui_(false) { | 355 use_fake_ui_(false) { |
353 DCHECK(audio_manager_); | 356 DCHECK(audio_manager_); |
354 memset(active_enumeration_ref_count_, 0, | 357 memset(active_enumeration_ref_count_, 0, |
355 sizeof(active_enumeration_ref_count_)); | 358 sizeof(active_enumeration_ref_count_)); |
356 | 359 |
357 // Some unit tests create the MSM in the IO thread and assumes the | 360 // Some unit tests create the MSM in the IO thread and assumes the |
358 // initialization is done synchronously. | 361 // initialization is done synchronously. |
359 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 362 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
360 InitializeDeviceManagersOnIOThread(); | 363 InitializeDeviceManagersOnIOThread(); |
361 } else { | 364 } else { |
(...skipping 13 matching lines...) Expand all Loading... | |
375 MediaStreamManager::~MediaStreamManager() { | 378 MediaStreamManager::~MediaStreamManager() { |
376 DVLOG(1) << "~MediaStreamManager"; | 379 DVLOG(1) << "~MediaStreamManager"; |
377 DCHECK(requests_.empty()); | 380 DCHECK(requests_.empty()); |
378 DCHECK(!device_task_runner_); | 381 DCHECK(!device_task_runner_); |
379 | 382 |
380 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | 383 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
381 // The PowerMonitor instance owned by BrowserMainLoops always outlives the | 384 // The PowerMonitor instance owned by BrowserMainLoops always outlives the |
382 // MediaStreamManager, but it may be NULL in unit tests. | 385 // MediaStreamManager, but it may be NULL in unit tests. |
383 if (power_monitor) | 386 if (power_monitor) |
384 power_monitor->RemoveObserver(this); | 387 power_monitor->RemoveObserver(this); |
388 | |
389 if (observing_screen_) { | |
390 gfx::Screen* screen = | |
391 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE); | |
392 if (screen) | |
393 screen->RemoveObserver(this); | |
394 } | |
385 } | 395 } |
386 | 396 |
387 VideoCaptureManager* MediaStreamManager::video_capture_manager() { | 397 VideoCaptureManager* MediaStreamManager::video_capture_manager() { |
388 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 398 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
389 DCHECK(video_capture_manager_.get()); | 399 DCHECK(video_capture_manager_.get()); |
390 return video_capture_manager_.get(); | 400 return video_capture_manager_.get(); |
391 } | 401 } |
392 | 402 |
393 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { | 403 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { |
394 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 404 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 const StreamOptions& options, | 450 const StreamOptions& options, |
441 const GURL& security_origin, | 451 const GURL& security_origin, |
442 bool user_gesture) { | 452 bool user_gesture) { |
443 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 453 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
444 DVLOG(1) << "GenerateStream()"; | 454 DVLOG(1) << "GenerateStream()"; |
445 if (CommandLine::ForCurrentProcess()->HasSwitch( | 455 if (CommandLine::ForCurrentProcess()->HasSwitch( |
446 switches::kUseFakeUIForMediaStream)) { | 456 switches::kUseFakeUIForMediaStream)) { |
447 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); | 457 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); |
448 } | 458 } |
449 | 459 |
460 if (!observing_screen_) { | |
vrk (LEFT CHROMIUM)
2014/05/09 01:11:31
Hmm.. I don't think this is the right place to add
Zachary Kuznia
2014/05/09 07:42:22
I will discuss this with them.
| |
461 gfx::Screen* screen = | |
462 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE); | |
463 if (screen) { | |
464 screen->AddObserver(this); | |
465 OnDisplayBoundsChanged(screen->GetPrimaryDisplay()); | |
vrk (LEFT CHROMIUM)
2014/05/09 01:11:31
Generally it's best let observer functions be call
Zachary Kuznia
2014/05/09 07:42:22
Done.
| |
466 observing_screen_ = true; | |
467 } | |
468 } | |
469 | |
450 DeviceRequest* request = new DeviceRequest(requester, | 470 DeviceRequest* request = new DeviceRequest(requester, |
451 render_process_id, | 471 render_process_id, |
452 render_view_id, | 472 render_view_id, |
453 page_request_id, | 473 page_request_id, |
454 security_origin, | 474 security_origin, |
455 user_gesture, | 475 user_gesture, |
456 MEDIA_GENERATE_STREAM, | 476 MEDIA_GENERATE_STREAM, |
457 options, | 477 options, |
458 sc); | 478 sc); |
459 | 479 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 int render_view_id, | 721 int render_view_id, |
702 const ResourceContext::SaltCallback& sc, | 722 const ResourceContext::SaltCallback& sc, |
703 int page_request_id, | 723 int page_request_id, |
704 const std::string& device_id, | 724 const std::string& device_id, |
705 MediaStreamType type, | 725 MediaStreamType type, |
706 const GURL& security_origin) { | 726 const GURL& security_origin) { |
707 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 727 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
708 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 728 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
709 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 729 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
710 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; | 730 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; |
731 | |
711 StreamOptions options; | 732 StreamOptions options; |
712 if (IsAudioMediaType(type)) { | 733 if (IsAudioMediaType(type)) { |
713 options.audio_requested = true; | 734 options.audio_requested = true; |
714 options.mandatory_audio.push_back( | 735 options.mandatory_audio.push_back( |
715 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); | 736 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); |
716 } else if (IsVideoMediaType(type)) { | 737 } else if (IsVideoMediaType(type)) { |
717 options.video_requested = true; | 738 options.video_requested = true; |
718 options.mandatory_video.push_back( | 739 options.mandatory_video.push_back( |
719 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); | 740 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); |
720 } else { | 741 } else { |
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1940 ++it) { | 1961 ++it) { |
1941 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 1962 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
1942 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, | 1963 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, |
1943 window_id); | 1964 window_id); |
1944 break; | 1965 break; |
1945 } | 1966 } |
1946 } | 1967 } |
1947 } | 1968 } |
1948 } | 1969 } |
1949 | 1970 |
1971 void MediaStreamManager::OnDisplayBoundsChanged(const gfx::Display& display) { | |
1972 if (display.IsInternal()) { | |
vrk (LEFT CHROMIUM)
2014/05/09 01:11:31
Move the "if (display.IsInternal())" check to SetD
Zachary Kuznia
2014/05/09 07:42:22
Done.
| |
1973 BrowserThread::PostTask( | |
1974 BrowserThread::IO, | |
1975 FROM_HERE, | |
1976 base::Bind(&MediaStreamManager::SetDisplayRotationOnIOThread, | |
1977 base::Unretained(this), display.rotation())); | |
1978 } | |
1979 } | |
1980 | |
1981 void MediaStreamManager::OnDisplayAdded(const gfx::Display& new_display) { | |
vrk (LEFT CHROMIUM)
2014/05/09 01:11:31
Nit: {} on one line, and comment out the unused pa
Zachary Kuznia
2014/05/09 07:42:22
Done.
| |
1982 } | |
1983 | |
1984 void MediaStreamManager::OnDisplayRemoved(const gfx::Display& old_display) { | |
vrk (LEFT CHROMIUM)
2014/05/09 01:11:31
ditto above
Zachary Kuznia
2014/05/09 07:42:22
Done, save that the } doesn't fit on the same line
| |
1985 } | |
1986 | |
1987 void MediaStreamManager::SetDisplayRotationOnIOThread( | |
1988 gfx::Display::Rotation rotation) { | |
1989 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
1990 video_capture_manager()->SetDisplayRotation(rotation); | |
1991 } | |
1992 | |
1950 } // namespace content | 1993 } // namespace content |
OLD | NEW |