diff options
author | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 03:32:53 +0000 |
---|---|---|
committer | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 03:32:53 +0000 |
commit | d2ce5dad5aa1e7a4518c60b362516873c49a61b4 (patch) | |
tree | f09f61957a7b0c0fd6aaaffd34ddcfb4cc46859c | |
parent | dfa3f55a525200a5dacece875adefa1ecbbde58c (diff) | |
download | chromium_src-d2ce5dad5aa1e7a4518c60b362516873c49a61b4.zip chromium_src-d2ce5dad5aa1e7a4518c60b362516873c49a61b4.tar.gz chromium_src-d2ce5dad5aa1e7a4518c60b362516873c49a61b4.tar.bz2 |
Remove MediaStreamDeviceThread in favor of audio worker TaskRunner.
Part Deux! See https://codereview.chromium.org/17444005/ for the
previous attempt. It was reverted oh so long ago because on OSX we
use the UI thread as the "audio thread" for http://crbug.com/158170.
Now that the AudioManager has the concept of a worker thread for
heavy tasks, this can safely be relanded without fear of blocking
any browser threads.
See http://crbug.com/256945 for more context on the previous revert.
BUG=none
TEST=unittests pass.
Review URL: https://codereview.chromium.org/154143002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249252 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 35 insertions, 39 deletions
diff --git a/content/browser/renderer_host/media/audio_input_device_manager.cc b/content/browser/renderer_host/media/audio_input_device_manager.cc index cfe00ca..dc4b1e3 100644 --- a/content/browser/renderer_host/media/audio_input_device_manager.cc +++ b/content/browser/renderer_host/media/audio_input_device_manager.cc @@ -55,12 +55,12 @@ const StreamDeviceInfo* AudioInputDeviceManager::GetOpenedDeviceInfoById( void AudioInputDeviceManager::Register( MediaStreamProviderListener* listener, - base::MessageLoopProxy* device_thread_loop) { + const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(!listener_); - DCHECK(!device_loop_.get()); + DCHECK(!device_task_runner_); listener_ = listener; - device_loop_ = device_thread_loop; + device_task_runner_ = device_task_runner; } void AudioInputDeviceManager::Unregister() { @@ -72,7 +72,7 @@ void AudioInputDeviceManager::EnumerateDevices(MediaStreamType stream_type) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(listener_); - device_loop_->PostTask( + device_task_runner_->PostTask( FROM_HERE, base::Bind(&AudioInputDeviceManager::EnumerateOnDeviceThread, this, stream_type)); @@ -82,7 +82,7 @@ int AudioInputDeviceManager::Open(const StreamDeviceInfo& device) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // Generate a new id for this device. int session_id = next_capture_session_id_++; - device_loop_->PostTask( + device_task_runner_->PostTask( FROM_HERE, base::Bind(&AudioInputDeviceManager::OpenOnDeviceThread, this, session_id, device)); @@ -241,7 +241,7 @@ void AudioInputDeviceManager::ClosedOnIOThread(MediaStreamType stream_type, } bool AudioInputDeviceManager::IsOnDeviceThread() const { - return device_loop_->BelongsToCurrentThread(); + return device_task_runner_->BelongsToCurrentThread(); } AudioInputDeviceManager::StreamDeviceList::iterator diff --git a/content/browser/renderer_host/media/audio_input_device_manager.h b/content/browser/renderer_host/media/audio_input_device_manager.h index 133673f..231f30b 100644 --- a/content/browser/renderer_host/media/audio_input_device_manager.h +++ b/content/browser/renderer_host/media/audio_input_device_manager.h @@ -45,7 +45,8 @@ class CONTENT_EXPORT AudioInputDeviceManager : public MediaStreamProvider { // MediaStreamProvider implementation, called on IO thread. virtual void Register(MediaStreamProviderListener* listener, - base::MessageLoopProxy* device_thread_loop) OVERRIDE; + const scoped_refptr<base::SingleThreadTaskRunner>& + device_task_runner) OVERRIDE; virtual void Unregister() OVERRIDE; virtual void EnumerateDevices(MediaStreamType stream_type) OVERRIDE; virtual int Open(const StreamDeviceInfo& device) OVERRIDE; @@ -90,7 +91,7 @@ class CONTENT_EXPORT AudioInputDeviceManager : public MediaStreamProvider { media::AudioManager* const audio_manager_; // Weak. // The message loop of media stream device thread that this object runs on. - scoped_refptr<base::MessageLoopProxy> device_loop_; + scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); }; diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc index 88a1aa1..0c2118f 100644 --- a/content/browser/renderer_host/media/media_stream_manager.cc +++ b/content/browser/renderer_host/media/media_stream_manager.cc @@ -346,7 +346,7 @@ MediaStreamManager::MediaStreamManager(media::AudioManager* audio_manager) MediaStreamManager::~MediaStreamManager() { DVLOG(1) << "~MediaStreamManager"; DCHECK(requests_.empty()); - DCHECK(!device_thread_.get()); + DCHECK(!device_task_runner_); } VideoCaptureManager* MediaStreamManager::video_capture_manager() { @@ -1353,22 +1353,16 @@ void MediaStreamManager::FinalizeMediaAccessRequest( void MediaStreamManager::InitializeDeviceManagersOnIOThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (device_thread_) + if (device_task_runner_) return; - device_thread_.reset(new base::Thread("MediaStreamDeviceThread")); -#if defined(OS_WIN) - device_thread_->init_com_with_mta(true); -#endif - CHECK(device_thread_->Start()); + device_task_runner_ = audio_manager_->GetWorkerTaskRunner(); audio_input_device_manager_ = new AudioInputDeviceManager(audio_manager_); - audio_input_device_manager_->Register( - this, device_thread_->message_loop_proxy().get()); + audio_input_device_manager_->Register(this, device_task_runner_); video_capture_manager_ = new VideoCaptureManager(); - video_capture_manager_->Register(this, - device_thread_->message_loop_proxy().get()); + video_capture_manager_->Register(this, device_task_runner_); // We want to be notified of IO message loop destruction to delete the thread // and the device managers. @@ -1735,12 +1729,12 @@ void MediaStreamManager::WillDestroyCurrentMessageLoop() { DVLOG(3) << "MediaStreamManager::WillDestroyCurrentMessageLoop()"; DCHECK_EQ(base::MessageLoop::current(), io_loop_); DCHECK(requests_.empty()); - if (device_thread_) { + if (device_task_runner_) { StopMonitoring(); video_capture_manager_->Unregister(); audio_input_device_manager_->Unregister(); - device_thread_.reset(); + device_task_runner_ = NULL; } audio_input_device_manager_ = NULL; diff --git a/content/browser/renderer_host/media/media_stream_manager.h b/content/browser/renderer_host/media/media_stream_manager.h index 88f02e1..41cc751 100644 --- a/content/browser/renderer_host/media/media_stream_manager.h +++ b/content/browser/renderer_host/media/media_stream_manager.h @@ -37,10 +37,6 @@ #include "content/common/media/media_stream_options.h" #include "content/public/browser/media_request_state.h" -namespace base { -class Thread; -} - namespace media { class AudioManager; } @@ -336,8 +332,10 @@ class CONTENT_EXPORT MediaStreamManager const std::string& source_id, std::string* device_id) const; - // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. - scoped_ptr<base::Thread> device_thread_; + // Task runner shared by VideoCaptureManager and AudioInputDeviceManager. + // Note: Enumeration tasks may take seconds to complete so must never be run + // on any of the BrowserThreads (UI, IO, etc). See http://crbug.com/256945. + scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; media::AudioManager* const audio_manager_; // not owned scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; diff --git a/content/browser/renderer_host/media/media_stream_provider.h b/content/browser/renderer_host/media/media_stream_provider.h index 051bb2c..f83aa4f 100644 --- a/content/browser/renderer_host/media/media_stream_provider.h +++ b/content/browser/renderer_host/media/media_stream_provider.h @@ -20,7 +20,7 @@ #include "content/common/media/media_stream_options.h" namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } namespace content { @@ -60,7 +60,8 @@ class CONTENT_EXPORT MediaStreamProvider public: // Registers a listener and a device message loop. virtual void Register(MediaStreamProviderListener* listener, - base::MessageLoopProxy* device_thread_loop) = 0; + const scoped_refptr<base::SingleThreadTaskRunner>& + device_task_runner) = 0; // Unregisters the previously registered listener. virtual void Unregister() = 0; diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc index 7392624..a547037 100644 --- a/content/browser/renderer_host/media/video_capture_manager.cc +++ b/content/browser/renderer_host/media/video_capture_manager.cc @@ -65,13 +65,14 @@ VideoCaptureManager::~VideoCaptureManager() { DCHECK(devices_.empty()); } -void VideoCaptureManager::Register(MediaStreamProviderListener* listener, - base::MessageLoopProxy* device_thread_loop) { +void VideoCaptureManager::Register( + MediaStreamProviderListener* listener, + const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(!listener_); - DCHECK(!device_loop_.get()); + DCHECK(!device_task_runner_.get()); listener_ = listener; - device_loop_ = device_thread_loop; + device_task_runner_ = device_task_runner; } void VideoCaptureManager::Unregister() { @@ -84,7 +85,7 @@ void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; DCHECK(listener_); base::PostTaskAndReplyWithResult( - device_loop_, FROM_HERE, + device_task_runner_, FROM_HERE, base::Bind(&VideoCaptureManager::GetAvailableDevicesInfoOnDeviceThread, this, stream_type, devices_info_cache_), base::Bind(&VideoCaptureManager::OnDevicesInfoEnumerated, this, @@ -246,7 +247,7 @@ void VideoCaptureManager::StartCaptureForClient( DVLOG(1) << "VideoCaptureManager starting device (type = " << entry->stream_type << ", id = " << entry->id << ")"; - device_loop_->PostTask( + device_task_runner_->PostTask( FROM_HERE, base::Bind( &VideoCaptureManager::DoStartDeviceOnDeviceThread, @@ -382,7 +383,7 @@ void VideoCaptureManager::OnDevicesInfoEnumerated( } bool VideoCaptureManager::IsOnDeviceThread() const { - return device_loop_->BelongsToCurrentThread(); + return device_task_runner_->BelongsToCurrentThread(); } VideoCaptureManager::DeviceInfos @@ -505,7 +506,7 @@ void VideoCaptureManager::DestroyDeviceEntryIfNoClients(DeviceEntry* entry) { // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. devices_.erase(entry); entry->video_capture_controller.reset(); - device_loop_->PostTask( + device_task_runner_->PostTask( FROM_HERE, base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, base::Owned(entry))); diff --git a/content/browser/renderer_host/media/video_capture_manager.h b/content/browser/renderer_host/media/video_capture_manager.h index 1a707bb..b3537fa 100644 --- a/content/browser/renderer_host/media/video_capture_manager.h +++ b/content/browser/renderer_host/media/video_capture_manager.h @@ -41,7 +41,8 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { // Implements MediaStreamProvider. virtual void Register(MediaStreamProviderListener* listener, - base::MessageLoopProxy* device_thread_loop) OVERRIDE; + const scoped_refptr<base::SingleThreadTaskRunner>& + device_task_runner) OVERRIDE; virtual void Unregister() OVERRIDE; @@ -167,7 +168,7 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { DeviceInfos& device_vector); // The message loop of media stream device thread, where VCD's live. - scoped_refptr<base::MessageLoopProxy> device_loop_; + scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; // Only accessed on Browser::IO thread. MediaStreamProviderListener* listener_; |