summaryrefslogtreecommitdiffstats
path: root/content/browser
diff options
context:
space:
mode:
authorwjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-08 18:45:05 +0000
committerwjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-08 18:45:05 +0000
commit4ad51a93bc3fd568aa32fe2dc0a1de4ed49817c5 (patch)
treea32d7c0488a3d8c788c37cd6a4ff8baa33a9cd8a /content/browser
parent6825759582fd94ee046f8c2e1dada868e127c7e3 (diff)
downloadchromium_src-4ad51a93bc3fd568aa32fe2dc0a1de4ed49817c5.zip
chromium_src-4ad51a93bc3fd568aa32fe2dc0a1de4ed49817c5.tar.gz
chromium_src-4ad51a93bc3fd568aa32fe2dc0a1de4ed49817c5.tar.bz2
Revert 150491 - refactor EnumerateDevices to make it a persistent request.
After the requester calls EnumerateDevices, it should expect new device list as initial response and whenever devices are changed. A new method StopEnumerateDevices is also added to allow the request to stop device enumeration. It also includes corresponding change in Pepper since EnumerateDevices contract is changed (http://codereview.chromium.org/10837064/). This patch keeps current Pepper API, while using the new API of EnumerateDevices from MediaStreamDispatcher. Pepper calls StopEnumerateDevices when it receives the first enumerated result. A new Pepper API will be created in a separate patch to make EnumerateDevices persistent. BUG=137799 Review URL: https://chromiumcodereview.appspot.com/10830063 BUG=141367 TBR=wjia@chromium.org Review URL: https://chromiumcodereview.appspot.com/10834232 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150593 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r--content/browser/renderer_host/media/media_stream_dispatcher_host.cc4
-rw-r--r--content/browser/renderer_host/media/media_stream_manager.cc297
-rw-r--r--content/browser/renderer_host/media/media_stream_manager.h49
3 files changed, 77 insertions, 273 deletions
diff --git a/content/browser/renderer_host/media/media_stream_dispatcher_host.cc b/content/browser/renderer_host/media/media_stream_dispatcher_host.cc
index 1f6eb43..fb817b9 100644
--- a/content/browser/renderer_host/media/media_stream_dispatcher_host.cc
+++ b/content/browser/renderer_host/media/media_stream_dispatcher_host.cc
@@ -100,9 +100,10 @@ void MediaStreamDispatcherHost::DevicesEnumerated(
StreamMap::iterator it = streams_.find(label);
DCHECK(it != streams_.end());
StreamRequest request = it->second;
+ streams_.erase(it);
Send(new MediaStreamMsg_DevicesEnumerated(
- request.render_view_id, request.page_request_id, label, devices));
+ request.render_view_id, request.page_request_id, devices));
}
void MediaStreamDispatcherHost::DeviceOpened(
@@ -195,6 +196,7 @@ void MediaStreamDispatcherHost::OnStopGeneratedStream(
<< ", {label = " << label << "})";
StreamMap::iterator it = streams_.find(label);
+ DCHECK(it != streams_.end());
GetManager()->StopGeneratedStream(label);
streams_.erase(it);
}
diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc
index b41b244..1329b97 100644
--- a/content/browser/renderer_host/media/media_stream_manager.cc
+++ b/content/browser/renderer_host/media/media_stream_manager.cc
@@ -47,10 +47,14 @@ static std::string RandomLabel() {
// Helper to verify if a media stream type is part of options or not.
static bool Requested(const StreamOptions& options,
MediaStreamType stream_type) {
- return (stream_type == content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE &&
- options.video) ||
- (stream_type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE &&
- options.audio);
+ if (stream_type == content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE &&
+ options.video) {
+ return true;
+ } else if (stream_type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE &&
+ options.audio) {
+ return true;
+ }
+ return false;
}
DeviceThread::DeviceThread(const char* name)
@@ -74,24 +78,24 @@ void DeviceThread::CleanUp() {
// TODO(xians): Merge DeviceRequest with MediaStreamRequest.
struct MediaStreamManager::DeviceRequest {
enum RequestState {
- STATE_NOT_REQUESTED = 0,
- STATE_REQUESTED,
- STATE_PENDING_APPROVAL,
- STATE_OPENING,
- STATE_DONE,
- STATE_ERROR
+ kNotRequested = 0,
+ kRequested,
+ kPendingApproval,
+ kOpening,
+ kDone,
+ kError
};
enum RequestType {
- GENERATE_STREAM = 0,
- ENUMERATE_DEVICES,
- OPEN_DEVICE
+ kGenerateStream = 0,
+ kEnumerateDevices,
+ kOpenDevice
};
DeviceRequest()
: requester(NULL),
- state(content::NUM_MEDIA_STREAM_DEVICE_TYPES, STATE_NOT_REQUESTED),
- type(GENERATE_STREAM),
+ state(content::NUM_MEDIA_STREAM_DEVICE_TYPES, kNotRequested),
+ type(kGenerateStream),
render_process_id(-1),
render_view_id(-1) {
options.audio = false;
@@ -105,8 +109,8 @@ struct MediaStreamManager::DeviceRequest {
const GURL& request_security_origin)
: requester(requester),
options(request_options),
- state(content::NUM_MEDIA_STREAM_DEVICE_TYPES, STATE_NOT_REQUESTED),
- type(GENERATE_STREAM),
+ state(content::NUM_MEDIA_STREAM_DEVICE_TYPES, kNotRequested),
+ type(kGenerateStream),
render_process_id(render_process_id),
render_view_id(render_view_id),
security_origin(request_security_origin) {
@@ -127,13 +131,6 @@ struct MediaStreamManager::DeviceRequest {
StreamDeviceInfoArray video_devices;
};
-MediaStreamManager::EnumerationCache::EnumerationCache()
- : valid(false) {
-}
-
-MediaStreamManager::EnumerationCache::~EnumerationCache() {
-}
-
MediaStreamManager::MediaStreamManager(
AudioInputDeviceManager* audio_input_device_manager,
VideoCaptureManager* video_capture_manager)
@@ -141,10 +138,8 @@ MediaStreamManager::MediaStreamManager(
device_settings_(new MediaStreamDeviceSettings(this))),
audio_input_device_manager_(audio_input_device_manager),
video_capture_manager_(video_capture_manager),
- monitoring_started_(false),
+ enumeration_in_progress_(content::NUM_MEDIA_STREAM_DEVICE_TYPES, false),
io_loop_(NULL) {
- memset(active_enumeration_ref_count_, 0,
- sizeof(active_enumeration_ref_count_));
}
MediaStreamManager::~MediaStreamManager() {
@@ -181,17 +176,6 @@ void MediaStreamManager::GenerateStream(MediaStreamRequester* requester,
render_view_id,
security_origin);
StartEnumeration(&new_request, label);
-
- // Get user confirmation to use capture devices.
- // Need to make an asynchronous call to make sure the |requester| gets the
- // |label| before it would receive any event.
- BrowserThread::PostTask(BrowserThread::IO,
- FROM_HERE,
- base::Bind(&MediaStreamDeviceSettings::RequestCaptureDeviceUsage,
- base::Unretained(device_settings_.get()),
- *label, render_process_id,
- render_view_id, options,
- security_origin));
}
void MediaStreamManager::CancelRequests(MediaStreamRequester* requester) {
@@ -203,7 +187,7 @@ void MediaStreamManager::CancelRequests(MediaStreamRequester* requester) {
// opened -> close them.
DeviceRequest* request = &(it->second);
if (request->state[content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE] ==
- DeviceRequest::STATE_OPENING) {
+ DeviceRequest::kOpening) {
for (StreamDeviceInfoArray::iterator it =
request->audio_devices.begin(); it != request->audio_devices.end();
++it) {
@@ -211,7 +195,7 @@ void MediaStreamManager::CancelRequests(MediaStreamRequester* requester) {
}
}
if (request->state[content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE] ==
- DeviceRequest::STATE_OPENING) {
+ DeviceRequest::kOpening) {
for (StreamDeviceInfoArray::iterator it =
request->video_devices.begin(); it != request->video_devices.end();
++it) {
@@ -234,7 +218,7 @@ void MediaStreamManager::CancelGenerateStream(const std::string& label) {
if (!RequestDone(it->second)) {
DeviceRequest* request = &(it->second);
if (request->state[content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE] ==
- DeviceRequest::STATE_OPENING) {
+ DeviceRequest::kOpening) {
for (StreamDeviceInfoArray::iterator it =
request->audio_devices.begin(); it != request->audio_devices.end();
++it) {
@@ -242,7 +226,7 @@ void MediaStreamManager::CancelGenerateStream(const std::string& label) {
}
}
if (request->state[content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE] ==
- DeviceRequest::STATE_OPENING) {
+ DeviceRequest::kOpening) {
for (StreamDeviceInfoArray::iterator it =
request->video_devices.begin(); it != request->video_devices.end();
++it) {
@@ -262,10 +246,6 @@ void MediaStreamManager::StopGeneratedStream(const std::string& label) {
// Find the request and close all open devices for the request.
DeviceRequests::iterator it = requests_.find(label);
if (it != requests_.end()) {
- if (it->second.type == DeviceRequest::ENUMERATE_DEVICES) {
- StopEnumerateDevices(label);
- return;
- }
for (StreamDeviceInfoArray::iterator audio_it =
it->second.audio_devices.begin();
audio_it != it->second.audio_devices.end(); ++audio_it) {
@@ -276,10 +256,11 @@ void MediaStreamManager::StopGeneratedStream(const std::string& label) {
video_it != it->second.video_devices.end(); ++video_it) {
video_capture_manager()->Close(video_it->session_id);
}
- if (it->second.type == DeviceRequest::GENERATE_STREAM) {
+ if (it->second.type == DeviceRequest::kGenerateStream) {
NotifyObserverDevicesClosed(&(it->second));
}
requests_.erase(it);
+ return;
}
}
@@ -291,53 +272,21 @@ void MediaStreamManager::EnumerateDevices(
const GURL& security_origin,
std::string* label) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK(type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE ||
- type == content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE);
// Create a new request.
StreamOptions options;
- EnumerationCache* cache = NULL;
- if (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) {
+ if (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE)
options.audio = true;
- cache = &audio_enumeration_cache_;
- } else {
+ else
options.video = true;
- cache = &video_enumeration_cache_;
- }
DeviceRequest new_request(requester, options,
render_process_id,
render_view_id,
security_origin);
- new_request.type = DeviceRequest::ENUMERATE_DEVICES;
-
- if (cache->valid) {
- // Cached device list of this type exists. Just send it out.
- new_request.state[type] = DeviceRequest::STATE_REQUESTED;
- AddRequest(&new_request, label);
- // Need to post a task since the requester won't have label till
- // this function returns.
- BrowserThread::PostTask(BrowserThread::IO,
- FROM_HERE,
- base::Bind(&MediaStreamManager::SendCachedDeviceList,
- base::Unretained(this), cache, *label));
- } else {
- StartEnumeration(&new_request, label);
- StartMonitoring();
- }
-}
-
-void MediaStreamManager::StopEnumerateDevices(const std::string& label) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ new_request.type = DeviceRequest::kEnumerateDevices;
- DeviceRequests::iterator it = requests_.find(label);
- if (it != requests_.end()) {
- DCHECK_EQ(it->second.type, DeviceRequest::ENUMERATE_DEVICES);
- requests_.erase(it);
- if (!HasEnumerationRequest()) {
- StopMonitoring();
- }
- }
+ StartEnumeration(&new_request, label);
}
void MediaStreamManager::OpenDevice(
@@ -361,47 +310,12 @@ void MediaStreamManager::OpenDevice(
render_process_id,
render_view_id,
security_origin);
- new_request.type = DeviceRequest::OPEN_DEVICE;
+ new_request.type = DeviceRequest::kOpenDevice;
new_request.requested_device_id = device_id;
StartEnumeration(&new_request, label);
}
-void MediaStreamManager::SendCachedDeviceList(
- EnumerationCache* cache,
- const std::string& label) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (cache->valid) {
- DeviceRequests::iterator it = requests_.find(label);
- if (it != requests_.end()) {
- it->second.requester->DevicesEnumerated(label, cache->devices);
- }
- }
-}
-
-void MediaStreamManager::StartMonitoring() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (!monitoring_started_) {
- monitoring_started_ = true;
- base::SystemMonitor::Get()->AddDevicesChangedObserver(this);
- }
-}
-
-void MediaStreamManager::StopMonitoring() {
- DCHECK_EQ(MessageLoop::current(), io_loop_);
- if (monitoring_started_ && !HasEnumerationRequest()) {
- base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this);
- monitoring_started_ = false;
- ClearEnumerationCache(&audio_enumeration_cache_);
- ClearEnumerationCache(&video_enumeration_cache_);
- }
-}
-
-void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) {
- DCHECK_EQ(MessageLoop::current(), io_loop_);
- cache->valid = false;
-}
-
void MediaStreamManager::StartEnumeration(
DeviceRequest* new_request,
std::string* label) {
@@ -409,31 +323,21 @@ void MediaStreamManager::StartEnumeration(
MediaStreamType stream_type = content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE;
if (Requested(new_request->options, stream_type)) {
- new_request->state[stream_type] = DeviceRequest::STATE_REQUESTED;
- DCHECK_GE(active_enumeration_ref_count_[stream_type], 0);
- if (!active_enumeration_ref_count_[stream_type]) {
- ++active_enumeration_ref_count_[stream_type];
+ new_request->state[stream_type] = DeviceRequest::kRequested;
+ if (!enumeration_in_progress_[stream_type]) {
+ enumeration_in_progress_[stream_type] = true;
GetDeviceManager(stream_type)->EnumerateDevices();
}
}
stream_type = content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE;
if (Requested(new_request->options, stream_type)) {
- new_request->state[stream_type] = DeviceRequest::STATE_REQUESTED;
- DCHECK_GE(active_enumeration_ref_count_[stream_type], 0);
- if (!active_enumeration_ref_count_[stream_type]) {
- ++active_enumeration_ref_count_[stream_type];
+ new_request->state[stream_type] = DeviceRequest::kRequested;
+ if (!enumeration_in_progress_[stream_type]) {
+ enumeration_in_progress_[stream_type] = true;
GetDeviceManager(stream_type)->EnumerateDevices();
}
}
- AddRequest(new_request, label);
-}
-
-void MediaStreamManager::AddRequest(
- DeviceRequest* new_request,
- std::string* label) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
// Create a label for this request and verify it is unique.
std::string request_label;
do {
@@ -442,6 +346,19 @@ void MediaStreamManager::AddRequest(
requests_.insert(std::make_pair(request_label, *new_request));
+ // Get user confirmation to use capture devices.
+ // Need to make an asynchronous call to make sure the |requester| gets the
+ // |label| before it would receive any event.
+ if (new_request->type == DeviceRequest::kGenerateStream) {
+ BrowserThread::PostTask(BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&MediaStreamDeviceSettings::RequestCaptureDeviceUsage,
+ base::Unretained(device_settings_.get()),
+ request_label, new_request->render_process_id,
+ new_request->render_view_id, new_request->options,
+ new_request->security_origin));
+ }
+
(*label) = request_label;
}
@@ -497,7 +414,7 @@ void MediaStreamManager::Opened(MediaStreamType stream_type,
return;
}
- DCHECK_NE(request->state[stream_type], DeviceRequest::STATE_REQUESTED);
+ DCHECK_NE(request->state[stream_type], DeviceRequest::kRequested);
// Check if all devices for this stream type are opened. Update the state if
// they are.
@@ -508,7 +425,7 @@ void MediaStreamManager::Opened(MediaStreamType stream_type,
return;
}
}
- request->state[stream_type] = DeviceRequest::STATE_DONE;
+ request->state[stream_type] = DeviceRequest::kDone;
if (!RequestDone(*request)) {
// This stream_type is done, but not the other type.
@@ -516,10 +433,10 @@ void MediaStreamManager::Opened(MediaStreamType stream_type,
}
switch (request->type) {
- case DeviceRequest::OPEN_DEVICE:
+ case DeviceRequest::kOpenDevice:
request->requester->DeviceOpened(label, (*devices)[0]);
break;
- case DeviceRequest::GENERATE_STREAM:
+ case DeviceRequest::kGenerateStream:
request->requester->StreamGenerated(label, request->audio_devices,
request->video_devices);
NotifyObserverDevicesOpened(request);
@@ -538,21 +455,6 @@ void MediaStreamManager::DevicesEnumerated(
MediaStreamType stream_type, const StreamDeviceInfoArray& devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // Only cache device list when there is EnumerateDevices request, since
- // other requests don't turn on device monitoring.
- bool need_update_clients = false;
- EnumerationCache* cache =
- (stream_type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE ?
- &audio_enumeration_cache_ : &video_enumeration_cache_);
- if (HasEnumerationRequest(stream_type) &&
- (!cache->valid ||
- !std::equal(devices.begin(), devices.end(), cache->devices.begin(),
- media_stream::StreamDeviceInfo::IsEqual))) {
- cache->valid = true;
- cache->devices = devices;
- need_update_clients = true;
- }
-
// Publish the result for all requests waiting for device list(s).
// Find the requests waiting for this device list, store their labels and
// release the iterator before calling device settings. We might get a call
@@ -560,10 +462,9 @@ void MediaStreamManager::DevicesEnumerated(
std::list<std::string> label_list;
for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end();
++it) {
- if (it->second.state[stream_type] == DeviceRequest::STATE_REQUESTED &&
+ if (it->second.state[stream_type] == DeviceRequest::kRequested &&
Requested(it->second.options, stream_type)) {
- if (it->second.type != DeviceRequest::ENUMERATE_DEVICES)
- it->second.state[stream_type] = DeviceRequest::STATE_PENDING_APPROVAL;
+ it->second.state[stream_type] = DeviceRequest::kPendingApproval;
label_list.push_back(it->first);
}
}
@@ -571,11 +472,11 @@ void MediaStreamManager::DevicesEnumerated(
it != label_list.end(); ++it) {
DeviceRequest& request = requests_[*it];
switch (request.type) {
- case DeviceRequest::ENUMERATE_DEVICES:
- if (need_update_clients)
- request.requester->DevicesEnumerated(*it, devices);
+ case DeviceRequest::kEnumerateDevices:
+ request.requester->DevicesEnumerated(*it, devices);
+ requests_.erase(*it);
break;
- case DeviceRequest::OPEN_DEVICE:
+ case DeviceRequest::kOpenDevice:
for (StreamDeviceInfoArray::const_iterator device_it = devices.begin();
device_it != devices.end(); device_it++) {
if (request.requested_device_id == device_it->device_id) {
@@ -583,8 +484,7 @@ void MediaStreamManager::DevicesEnumerated(
device.in_use = false;
device.session_id =
GetDeviceManager(device_it->stream_type)->Open(device);
- request.state[device_it->stream_type] =
- DeviceRequest::STATE_OPENING;
+ request.state[device_it->stream_type] = DeviceRequest::kOpening;
if (stream_type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE)
request.audio_devices.push_back(device);
else
@@ -602,8 +502,7 @@ void MediaStreamManager::DevicesEnumerated(
}
}
label_list.clear();
- --active_enumeration_ref_count_[stream_type];
- DCHECK_GE(active_enumeration_ref_count_[stream_type], 0);
+ enumeration_in_progress_[stream_type] = false;
}
void MediaStreamManager::Error(MediaStreamType stream_type,
@@ -627,7 +526,7 @@ void MediaStreamManager::Error(MediaStreamType stream_type,
device_it != devices->end(); ++device_it, ++device_idx) {
if (device_it->session_id == capture_session_id) {
// We've found the failing device. Find the error case:
- if (it->second.state[stream_type] == DeviceRequest::STATE_DONE) {
+ if (it->second.state[stream_type] == DeviceRequest::kDone) {
// 1. Already opened -> signal device failure and close device.
// Use device_idx to signal which of the devices encountered an
// error.
@@ -677,12 +576,12 @@ void MediaStreamManager::DevicesAccepted(const std::string& label,
// opened. in_use might be true if the device type can be used in more
// than one session.
DCHECK_EQ(request_it->second.state[device_it->stream_type],
- DeviceRequest::STATE_PENDING_APPROVAL);
+ DeviceRequest::kPendingApproval);
device_info.in_use = false;
device_info.session_id =
GetDeviceManager(device_info.stream_type)->Open(device_info);
request_it->second.state[device_it->stream_type] =
- DeviceRequest::STATE_OPENING;
+ DeviceRequest::kOpening;
if (device_info.stream_type ==
content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) {
request_it->second.audio_devices.push_back(device_info);
@@ -698,12 +597,12 @@ void MediaStreamManager::DevicesAccepted(const std::string& label,
content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE;
if (Requested(request_it->second.options, stream_type) &&
request_it->second.audio_devices.size() == 0) {
- request_it->second.state[stream_type] = DeviceRequest::STATE_ERROR;
+ request_it->second.state[stream_type] = DeviceRequest::kError;
}
stream_type = content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE;
if (Requested(request_it->second.options, stream_type) &&
request_it->second.video_devices.size() == 0) {
- request_it->second.state[stream_type] = DeviceRequest::STATE_ERROR;
+ request_it->second.state[stream_type] = DeviceRequest::kError;
}
return;
}
@@ -714,7 +613,7 @@ void MediaStreamManager::SettingsError(const std::string& label) {
// Erase this request and report an error.
DeviceRequests::iterator it = requests_.find(label);
if (it != requests_.end()) {
- DCHECK_EQ(it->second.type, DeviceRequest::GENERATE_STREAM);
+ DCHECK_EQ(it->second.type, DeviceRequest::kGenerateStream);
it->second.requester->StreamGenerationFailed(label);
requests_.erase(it);
return;
@@ -729,10 +628,7 @@ void MediaStreamManager::UseFakeDevice() {
void MediaStreamManager::WillDestroyCurrentMessageLoop() {
DCHECK_EQ(MessageLoop::current(), io_loop_);
- DCHECK(requests_.empty());
if (device_thread_.get()) {
- StopMonitoring();
-
video_capture_manager_->Unregister();
audio_input_device_manager_->Unregister();
device_thread_.reset();
@@ -825,57 +721,4 @@ MediaStreamProvider* MediaStreamManager::GetDeviceManager(
return NULL;
}
-void MediaStreamManager::OnDevicesChanged(
- base::SystemMonitor::DeviceType device_type) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- MediaStreamType stream_type;
- EnumerationCache* cache;
- if (device_type == base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE) {
- stream_type = content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE;
- cache = &audio_enumeration_cache_;
- } else if (device_type == base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE) {
- stream_type = content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE;
- cache = &video_enumeration_cache_;
- } else {
- return; // Uninteresting device change.
- }
-
- if (!HasEnumerationRequest(stream_type)) {
- // There is no request for that type, No need to enumerate devices.
- // Therefore, invalidate the cache of that type.
- ClearEnumerationCache(cache);
- return;
- }
-
- // Always do enumeration even though some enumeration is in progress,
- // because those enumeration commands could be sent before these devices
- // change.
- ++active_enumeration_ref_count_[stream_type];
- GetDeviceManager(stream_type)->EnumerateDevices();
-}
-
-bool MediaStreamManager::HasEnumerationRequest() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- for (DeviceRequests::iterator it = requests_.begin();
- it != requests_.end(); ++it) {
- if (it->second.type == DeviceRequest::ENUMERATE_DEVICES) {
- return true;
- }
- }
- return false;
-}
-
-bool MediaStreamManager::HasEnumerationRequest(
- MediaStreamType stream_type) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- for (DeviceRequests::iterator it = requests_.begin();
- it != requests_.end(); ++it) {
- if (it->second.type == DeviceRequest::ENUMERATE_DEVICES &&
- Requested(it->second.options, stream_type)) {
- return true;
- }
- }
- return false;
-}
-
} // namespace media_stream
diff --git a/content/browser/renderer_host/media/media_stream_manager.h b/content/browser/renderer_host/media/media_stream_manager.h
index 6fb5269..648f21c 100644
--- a/content/browser/renderer_host/media/media_stream_manager.h
+++ b/content/browser/renderer_host/media/media_stream_manager.h
@@ -30,7 +30,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
-#include "base/system_monitor/system_monitor.h"
#include "base/threading/thread.h"
#include "content/browser/renderer_host/media/media_stream_provider.h"
#include "content/browser/renderer_host/media/media_stream_settings_requester.h"
@@ -73,8 +72,7 @@ class DeviceThread : public base::Thread {
class CONTENT_EXPORT MediaStreamManager
: public MediaStreamProviderListener,
public MessageLoop::DestructionObserver,
- public SettingsRequester,
- public base::SystemMonitor::DevicesChangedObserver {
+ public SettingsRequester {
public:
// This class takes the ownerships of the |audio_input_device_manager|
// and |video_capture_manager|.
@@ -109,9 +107,6 @@ class CONTENT_EXPORT MediaStreamManager
// Gets a list of devices of |type|.
// The request is identified using |label|, which is pointing to a
// std::string.
- // The request is persistent, which means the client keeps listening to
- // device changes, such as plug/unplug, and expects new device list for
- // such a change, till the client stops the request.
void EnumerateDevices(MediaStreamRequester* requester,
int render_process_id,
int render_view_id,
@@ -146,10 +141,6 @@ class CONTENT_EXPORT MediaStreamManager
const StreamDeviceInfoArray& devices) OVERRIDE;
virtual void SettingsError(const std::string& label) OVERRIDE;
- // Implements base::SystemMonitor::DevicesChangedObserver.
- virtual void OnDevicesChanged(
- base::SystemMonitor::DeviceType device_type) OVERRIDE;
-
// Used by unit test to make sure fake devices are used instead of a real
// devices, which is needed for server based testing.
// TODO(xians): Remove this hack since we can create our own
@@ -165,15 +156,6 @@ class CONTENT_EXPORT MediaStreamManager
// Contains all data needed to keep track of requests.
struct DeviceRequest;
- // Cache enumerated device list.
- struct EnumerationCache {
- EnumerationCache();
- ~EnumerationCache();
-
- bool valid;
- StreamDeviceInfoArray devices;
- };
-
// Helpers for signaling the media observer that new capture devices are
// opened/closed.
void NotifyObserverDevicesOpened(DeviceRequest* request);
@@ -186,26 +168,11 @@ class CONTENT_EXPORT MediaStreamManager
MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type);
void StartEnumeration(DeviceRequest* new_request,
std::string* label);
- void AddRequest(DeviceRequest* new_request, std::string* label);
- bool HasEnumerationRequest(MediaStreamType type);
- bool HasEnumerationRequest();
- void ClearEnumerationCache(EnumerationCache* cache);
// Helper to ensure the device thread and pass the message loop to device
// managers, it also register itself as the listener to the device managers.
void EnsureDeviceThreadAndListener();
- // Sends cached device list to a client corresponding to the request
- // identified by |label|.
- void SendCachedDeviceList(EnumerationCache* cache, const std::string& label);
-
- // Stop the request of enumerating devices indentified by |label|.
- void StopEnumerateDevices(const std::string& label);
-
- // Helpers to start and stop monitoring devices.
- void StartMonitoring();
- void StopMonitoring();
-
// Device thread shared by VideoCaptureManager and AudioInputDeviceManager.
scoped_ptr<base::Thread> device_thread_;
@@ -213,17 +180,9 @@ class CONTENT_EXPORT MediaStreamManager
scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
scoped_refptr<VideoCaptureManager> video_capture_manager_;
- // Indicator of device monitoring state.
- bool monitoring_started_;
-
- // Stores most recently enumerated device lists. The cache is cleared when
- // monitoring is stopped or there is no request for that type of device.
- EnumerationCache audio_enumeration_cache_;
- EnumerationCache video_enumeration_cache_;
-
- // Keeps track of live enumeration commands sent to VideoCaptureManager or
- // AudioInputDeviceManager, in order to only enumerate when necessary.
- int active_enumeration_ref_count_[content::NUM_MEDIA_STREAM_DEVICE_TYPES];
+ // Keeps track of device types currently being enumerated to not enumerate
+ // when not necessary.
+ std::vector<bool> enumeration_in_progress_;
// All non-closed request.
typedef std::map<std::string, DeviceRequest> DeviceRequests;