| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/threading/thread.h" |
| 14 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 15 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_requester.h" | 16 #include "content/browser/renderer_host/media/media_stream_requester.h" |
| 16 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 17 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 17 #include "content/browser/renderer_host/media/video_capture_manager.h" | 18 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 18 #include "content/browser/renderer_host/media/web_contents_capture_util.h" | 19 #include "content/browser/renderer_host/media/web_contents_capture_util.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/browser/media_observer.h" | 22 #include "content/public/browser/media_observer.h" |
| 22 #include "content/public/browser/media_request_state.h" | 23 #include "content/public/browser/media_request_state.h" |
| 23 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } else { | 142 } else { |
| 142 BrowserThread::PostTask( | 143 BrowserThread::PostTask( |
| 143 BrowserThread::IO, FROM_HERE, | 144 BrowserThread::IO, FROM_HERE, |
| 144 base::Bind(&MediaStreamManager::InitializeDeviceManagersOnIOThread, | 145 base::Bind(&MediaStreamManager::InitializeDeviceManagersOnIOThread, |
| 145 base::Unretained(this))); | 146 base::Unretained(this))); |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 | 149 |
| 149 MediaStreamManager::~MediaStreamManager() { | 150 MediaStreamManager::~MediaStreamManager() { |
| 150 DCHECK(requests_.empty()); | 151 DCHECK(requests_.empty()); |
| 151 DCHECK(!device_loop_.get()); | 152 DCHECK(!device_thread_.get()); |
| 152 DCHECK(!io_loop_); | 153 DCHECK(!io_loop_); |
| 153 } | 154 } |
| 154 | 155 |
| 155 VideoCaptureManager* MediaStreamManager::video_capture_manager() { | 156 VideoCaptureManager* MediaStreamManager::video_capture_manager() { |
| 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 157 DCHECK(video_capture_manager_.get()); | 158 DCHECK(video_capture_manager_.get()); |
| 158 return video_capture_manager_.get(); | 159 return video_capture_manager_.get(); |
| 159 } | 160 } |
| 160 | 161 |
| 161 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { | 162 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 if (IsAudioMediaType(audio_type)) | 579 if (IsAudioMediaType(audio_type)) |
| 579 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 580 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
| 580 if (IsVideoMediaType(video_type)) | 581 if (IsVideoMediaType(video_type)) |
| 581 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 582 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
| 582 | 583 |
| 583 PostRequestToUI(label); | 584 PostRequestToUI(label); |
| 584 } | 585 } |
| 585 | 586 |
| 586 void MediaStreamManager::InitializeDeviceManagersOnIOThread() { | 587 void MediaStreamManager::InitializeDeviceManagersOnIOThread() { |
| 587 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 588 if (device_loop_.get()) | 589 if (device_thread_) |
| 589 return; | 590 return; |
| 590 device_loop_ = audio_manager_->GetMessageLoop(); | 591 |
| 592 device_thread_.reset(new base::Thread("MediaStreamDeviceThread")); |
| 593 #if defined(OS_WIN) |
| 594 device_thread_->init_com_with_mta(true); |
| 595 #endif |
| 596 CHECK(device_thread_->Start()); |
| 591 | 597 |
| 592 audio_input_device_manager_ = new AudioInputDeviceManager(audio_manager_); | 598 audio_input_device_manager_ = new AudioInputDeviceManager(audio_manager_); |
| 593 audio_input_device_manager_->Register(this, device_loop_.get()); | 599 audio_input_device_manager_->Register( |
| 600 this, device_thread_->message_loop_proxy().get()); |
| 594 | 601 |
| 595 video_capture_manager_ = new VideoCaptureManager(); | 602 video_capture_manager_ = new VideoCaptureManager(); |
| 596 video_capture_manager_->Register(this, device_loop_.get()); | 603 video_capture_manager_->Register(this, |
| 604 device_thread_->message_loop_proxy().get()); |
| 597 | 605 |
| 598 // We want to be notified of IO message loop destruction to delete the thread | 606 // We want to be notified of IO message loop destruction to delete the thread |
| 599 // and the device managers. | 607 // and the device managers. |
| 600 io_loop_ = base::MessageLoop::current(); | 608 io_loop_ = base::MessageLoop::current(); |
| 601 io_loop_->AddDestructionObserver(this); | 609 io_loop_->AddDestructionObserver(this); |
| 602 } | 610 } |
| 603 | 611 |
| 604 void MediaStreamManager::Opened(MediaStreamType stream_type, | 612 void MediaStreamManager::Opened(MediaStreamType stream_type, |
| 605 int capture_session_id) { | 613 int capture_session_id) { |
| 606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 | 938 |
| 931 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { | 939 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { |
| 932 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 940 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 933 use_fake_ui_ = true; | 941 use_fake_ui_ = true; |
| 934 fake_ui_ = fake_ui.Pass(); | 942 fake_ui_ = fake_ui.Pass(); |
| 935 } | 943 } |
| 936 | 944 |
| 937 void MediaStreamManager::WillDestroyCurrentMessageLoop() { | 945 void MediaStreamManager::WillDestroyCurrentMessageLoop() { |
| 938 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 946 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
| 939 DCHECK(requests_.empty()); | 947 DCHECK(requests_.empty()); |
| 940 if (device_loop_.get()) { | 948 if (device_thread_) { |
| 941 StopMonitoring(); | 949 StopMonitoring(); |
| 942 | 950 |
| 943 video_capture_manager_->Unregister(); | 951 video_capture_manager_->Unregister(); |
| 944 audio_input_device_manager_->Unregister(); | 952 audio_input_device_manager_->Unregister(); |
| 945 device_loop_ = NULL; | 953 device_thread_.reset(); |
| 946 } | 954 } |
| 947 | 955 |
| 948 audio_input_device_manager_ = NULL; | 956 audio_input_device_manager_ = NULL; |
| 949 video_capture_manager_ = NULL; | 957 video_capture_manager_ = NULL; |
| 950 io_loop_ = NULL; | 958 io_loop_ = NULL; |
| 951 } | 959 } |
| 952 | 960 |
| 953 void MediaStreamManager::NotifyDevicesChanged( | 961 void MediaStreamManager::NotifyDevicesChanged( |
| 954 MediaStreamType stream_type, | 962 MediaStreamType stream_type, |
| 955 const StreamDeviceInfoArray& devices) { | 963 const StreamDeviceInfoArray& devices) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 } | 1044 } |
| 1037 | 1045 |
| 1038 // Always do enumeration even though some enumeration is in progress, | 1046 // Always do enumeration even though some enumeration is in progress, |
| 1039 // because those enumeration commands could be sent before these devices | 1047 // because those enumeration commands could be sent before these devices |
| 1040 // change. | 1048 // change. |
| 1041 ++active_enumeration_ref_count_[stream_type]; | 1049 ++active_enumeration_ref_count_[stream_type]; |
| 1042 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1050 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
| 1043 } | 1051 } |
| 1044 | 1052 |
| 1045 } // namespace content | 1053 } // namespace content |
| OLD | NEW |