summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/media/media_stream_manager.cc
diff options
context:
space:
mode:
authorxians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-06 12:03:05 +0000
committerxians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-06 12:03:05 +0000
commit5a309716dd90e1812016255f6ab06e6819d84fc8 (patch)
treeb5abd4c8e254b684ae5a452c3ff15bd2111b3c18 /content/browser/renderer_host/media/media_stream_manager.cc
parent3919f5403f926c501b6802214340f4f7b7872e56 (diff)
downloadchromium_src-5a309716dd90e1812016255f6ab06e6819d84fc8.zip
chromium_src-5a309716dd90e1812016255f6ab06e6819d84fc8.tar.gz
chromium_src-5a309716dd90e1812016255f6ab06e6819d84fc8.tar.bz2
Pepper needs to repeatedly call enumeration API in order to get a synchronous up-to-date device list. This heavily loads the IO thread since the enumeration is done on IO thread.
This patch moves the device thread from VideoCaptureManager to MediaStreamManager, so that audio and video can share one device thread, and also allow running audio device API on this shared device thread. BUG=132701,130113 TEST=content_unittests Review URL: https://chromiumcodereview.appspot.com/10662049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145584 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/renderer_host/media/media_stream_manager.cc')
-rw-r--r--content/browser/renderer_host/media/media_stream_manager.cc57
1 files changed, 26 insertions, 31 deletions
diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc
index d6b2e60..3f5a804 100644
--- a/content/browser/renderer_host/media/media_stream_manager.cc
+++ b/content/browser/renderer_host/media/media_stream_manager.cc
@@ -14,18 +14,14 @@
#include "content/browser/renderer_host/media/media_stream_device_settings.h"
#include "content/browser/renderer_host/media/media_stream_requester.h"
#include "content/browser/renderer_host/media/video_capture_manager.h"
-#include "content/browser/resource_context_impl.h"
#include "content/common/media/media_stream_options.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/media_observer.h"
#include "googleurl/src/gurl.h"
-#include "media/audio/audio_manager.h"
using content::BrowserThread;
-static const char* kMediaStreamManagerKeyName = "content_media_stream_manager";
-
namespace media_stream {
// Creates a random label used to identify requests.
@@ -116,50 +112,36 @@ struct MediaStreamManager::DeviceRequest {
StreamDeviceInfoArray video_devices;
};
-// static
-MediaStreamManager* MediaStreamManager::GetForResourceContext(
- content::ResourceContext* resource_context,
- media::AudioManager* audio_manager) {
- MediaStreamManager* rv = static_cast<MediaStreamManager*>(
- resource_context->GetUserData(kMediaStreamManagerKeyName));
- if (!rv) {
- rv = new MediaStreamManager(audio_manager);
- resource_context->SetUserData(kMediaStreamManagerKeyName, rv);
- }
- return rv;
-}
-
-MediaStreamManager::MediaStreamManager(media::AudioManager* audio_manager)
+MediaStreamManager::MediaStreamManager(
+ AudioInputDeviceManager* audio_input_device_manager,
+ VideoCaptureManager* video_capture_manager)
: ALLOW_THIS_IN_INITIALIZER_LIST(
device_settings_(new MediaStreamDeviceSettings(this))),
- enumeration_in_progress_(content::NUM_MEDIA_STREAM_DEVICE_TYPES, false),
- audio_manager_(audio_manager) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ audio_input_device_manager_(audio_input_device_manager),
+ video_capture_manager_(video_capture_manager),
+ enumeration_in_progress_(content::NUM_MEDIA_STREAM_DEVICE_TYPES, false) {
}
MediaStreamManager::~MediaStreamManager() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (video_capture_manager_.get())
+ if (device_thread_.get()) {
video_capture_manager_->Unregister();
- if (audio_input_device_manager_.get())
audio_input_device_manager_->Unregister();
+ device_thread_->Stop();
+ }
}
VideoCaptureManager* MediaStreamManager::video_capture_manager() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (!video_capture_manager_.get()) {
- video_capture_manager_ = new VideoCaptureManager();
- video_capture_manager_->Register(this);
- }
+ DCHECK(video_capture_manager_.get());
+ EnsureDeviceThreadAndListener();
return video_capture_manager_.get();
}
AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (!audio_input_device_manager_.get()) {
- audio_input_device_manager_ = new AudioInputDeviceManager(audio_manager_);
- audio_input_device_manager_->Register(this);
- }
+ DCHECK(audio_input_device_manager_.get());
+ EnsureDeviceThreadAndListener();
return audio_input_device_manager_.get();
}
@@ -367,6 +349,19 @@ void MediaStreamManager::StartEnumeration(
(*label) = request_label;
}
+void MediaStreamManager::EnsureDeviceThreadAndListener() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (device_thread_.get())
+ return;
+
+ device_thread_.reset(new DeviceThread("MediaStreamDeviceThread"));
+ CHECK(device_thread_->Start());
+
+ audio_input_device_manager_->Register(this,
+ device_thread_->message_loop_proxy());
+ video_capture_manager_->Register(this, device_thread_->message_loop_proxy());
+}
+
void MediaStreamManager::Opened(MediaStreamType stream_type,
int capture_session_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));