Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Unified Diff: content/browser/renderer_host/media/media_stream_manager.cc

Issue 11339014: Move content\browser\renderer_host\media to content namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/media_stream_manager.cc
===================================================================
--- content/browser/renderer_host/media/media_stream_manager.cc (revision 164646)
+++ content/browser/renderer_host/media/media_stream_manager.cc (working copy)
@@ -29,14 +29,11 @@
#include "base/win/scoped_com_initializer.h"
#endif
-using content::BrowserThread;
-using content::MediaStreamRequest;
-
namespace {
const char kExtensionScheme[] = "chrome-extension";
} // namespace
-namespace media_stream {
+namespace content {
// Creates a random label used to identify requests.
static std::string RandomLabel() {
@@ -79,8 +76,7 @@
type(GENERATE_STREAM),
render_process_id(-1),
render_view_id(-1),
- state_(content::NUM_MEDIA_TYPES,
- content::MEDIA_REQUEST_STATE_NOT_REQUESTED) {
+ state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) {
}
DeviceRequest(MediaStreamRequester* requester,
@@ -95,35 +91,31 @@
render_process_id(render_process_id),
render_view_id(render_view_id),
security_origin(request_security_origin),
- state_(content::NUM_MEDIA_TYPES,
- content::MEDIA_REQUEST_STATE_NOT_REQUESTED) {
+ state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) {
}
~DeviceRequest() {}
// Update the request state and notify observers.
- void setState(MediaStreamType stream_type,
- content::MediaRequestState new_state) {
+ void setState(MediaStreamType stream_type, MediaRequestState new_state) {
state_[stream_type] = new_state;
- if (options.video_type != content::MEDIA_TAB_VIDEO_CAPTURE &&
- options.audio_type != content::MEDIA_TAB_AUDIO_CAPTURE)
+ if (options.video_type != MEDIA_TAB_VIDEO_CAPTURE &&
+ options.audio_type != MEDIA_TAB_AUDIO_CAPTURE)
return;
- content::MediaObserver* media_observer =
- content::GetContentClient()->browser()->GetMediaObserver();
+ MediaObserver* media_observer =
+ GetContentClient()->browser()->GetMediaObserver();
if (media_observer == NULL)
return;
media_observer->OnMediaRequestStateChanged(
render_process_id, render_view_id,
- content::MediaStreamDevice(stream_type,
- requested_device_id,
- requested_device_id),
- new_state);
+ MediaStreamDevice(
+ stream_type, requested_device_id, requested_device_id), new_state);
}
- content::MediaRequestState getState(MediaStreamType stream_type) const {
+ MediaRequestState getState(MediaStreamType stream_type) const {
return state_[stream_type];
}
@@ -139,10 +131,10 @@
// Callback to the requester which audio/video devices have been selected.
// It can be null if the requester has no interest to know the result.
// Currently it is only used by |DEVICE_ACCESS| type.
- media_stream::MediaRequestResponseCallback callback;
+ MediaRequestResponseCallback callback;
private:
- std::vector<content::MediaRequestState> state_;
+ std::vector<MediaRequestState> state_;
};
MediaStreamManager::EnumerationCache::EnumerationCache()
@@ -154,7 +146,7 @@
MediaStreamManager::MediaStreamManager(media::AudioManager* audio_manager)
: ALLOW_THIS_IN_INITIALIZER_LIST(
- ui_controller_(new content::MediaStreamUIController(this))),
+ ui_controller_(new MediaStreamUIController(this))),
audio_manager_(audio_manager),
monitoring_started_(false),
io_loop_(NULL) {
@@ -251,10 +243,10 @@
PostRequestToUI(*label);
if (!security_origin.SchemeIs(kExtensionScheme) ||
- (options.audio_type != content::MEDIA_TAB_AUDIO_CAPTURE &&
- options.audio_type != content::MEDIA_NO_SERVICE) ||
- (options.video_type != content::MEDIA_TAB_VIDEO_CAPTURE &&
- options.video_type != content::MEDIA_NO_SERVICE)) {
+ (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE &&
+ options.audio_type != MEDIA_NO_SERVICE) ||
+ (options.video_type != MEDIA_TAB_VIDEO_CAPTURE &&
+ options.video_type != MEDIA_NO_SERVICE)) {
LOG(ERROR) << "Invalid request or used tab capture outside extension API.";
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&MediaStreamManager::CancelRequest,
@@ -266,24 +258,20 @@
// |device_id| actually exists. Note that no such MediaStreamProvider API for
// this currently exists. Also, we don't have a user-friendly device name for
// the infobar UI.
- if (content::IsAudioMediaType(options.audio_type)) {
+ if (IsAudioMediaType(options.audio_type)) {
// TODO(justinlin): Updating the state to requested and pending are no-ops
// in terms of the media manager, but these are the state changes we want to
// support in terms of extensions (which is registered as an observer).
- request.setState(options.audio_type,
- content::MEDIA_REQUEST_STATE_REQUESTED);
- request.setState(options.audio_type,
- content::MEDIA_REQUEST_STATE_PENDING_APPROVAL);
+ request.setState(options.audio_type, MEDIA_REQUEST_STATE_REQUESTED);
+ request.setState(options.audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL);
ui_controller_->AddAvailableDevicesToRequest(
*label, options.audio_type, StreamDeviceInfoArray(
1, StreamDeviceInfo(options.audio_type, device_id, device_id,
false)));
}
- if (content::IsVideoMediaType(options.video_type)) {
- request.setState(options.video_type,
- content::MEDIA_REQUEST_STATE_REQUESTED);
- request.setState(options.video_type,
- content::MEDIA_REQUEST_STATE_PENDING_APPROVAL);
+ if (IsVideoMediaType(options.video_type)) {
+ request.setState(options.video_type, MEDIA_REQUEST_STATE_REQUESTED);
+ request.setState(options.video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL);
ui_controller_->AddAvailableDevicesToRequest(
*label, options.video_type, StreamDeviceInfoArray(
1, StreamDeviceInfo(options.video_type, device_id, device_id,
@@ -303,11 +291,10 @@
// TODO(xians): update the |state| to STATE_DONE to trigger a state
// changed notification to UI before deleting the request?
DeviceRequest& request = it->second;
- for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES;
+ for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES;
++i) {
const MediaStreamType stream_type = static_cast<MediaStreamType>(i);
- if (request.getState(stream_type) !=
- content::MEDIA_REQUEST_STATE_OPENING) {
+ if (request.getState(stream_type) != MEDIA_REQUEST_STATE_OPENING) {
continue;
}
for (StreamDeviceInfoArray::const_iterator device_it =
@@ -344,12 +331,11 @@
if (it->second.type == DeviceRequest::GENERATE_STREAM &&
RequestDone(it->second)) {
// Notify observers that this device is being closed.
- for (int i = content::MEDIA_NO_SERVICE + 1;
- i != content::NUM_MEDIA_TYPES; ++i) {
+ for (int i = MEDIA_NO_SERVICE + 1; i != NUM_MEDIA_TYPES; ++i) {
if (it->second.getState(static_cast<MediaStreamType>(i)) !=
- content::MEDIA_REQUEST_STATE_NOT_REQUESTED)
+ MEDIA_REQUEST_STATE_NOT_REQUESTED)
it->second.setState(static_cast<MediaStreamType>(i),
- content::MEDIA_REQUEST_STATE_CLOSING);
+ MEDIA_REQUEST_STATE_CLOSING);
}
NotifyDevicesClosed(it->second);
}
@@ -371,16 +357,16 @@
const GURL& security_origin,
std::string* label) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
- type == content::MEDIA_DEVICE_VIDEO_CAPTURE);
+ DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
+ type == MEDIA_DEVICE_VIDEO_CAPTURE);
// Create a new request.
StreamOptions options;
EnumerationCache* cache = NULL;
- if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
+ if (type == MEDIA_DEVICE_AUDIO_CAPTURE) {
options.audio_type = type;
cache = &audio_enumeration_cache_;
- } else if (type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
+ } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) {
options.video_type = type;
cache = &video_enumeration_cache_;
} else {
@@ -396,7 +382,7 @@
if (cache->valid) {
// Cached device list of this type exists. Just send it out.
- new_request.setState(type, content::MEDIA_REQUEST_STATE_REQUESTED);
+ new_request.setState(type, MEDIA_REQUEST_STATE_REQUESTED);
AddRequest(new_request, label);
// Need to post a task since the requester won't have label till
// this function returns.
@@ -432,14 +418,14 @@
const GURL& security_origin,
std::string* label) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
- type == content::MEDIA_DEVICE_VIDEO_CAPTURE);
+ DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
+ type == MEDIA_DEVICE_VIDEO_CAPTURE);
// Create a new request.
StreamOptions options;
- if (content::IsAudioMediaType(type)) {
+ if (IsAudioMediaType(type)) {
options.audio_type = type;
- } else if (content::IsVideoMediaType(type)) {
+ } else if (IsVideoMediaType(type)) {
options.video_type = type;
} else {
NOTREACHED();
@@ -459,7 +445,7 @@
void MediaStreamManager::NotifyUIDevicesOpened(
int render_process_id,
int render_view_id,
- const content::MediaStreamDevices& devices) {
+ const MediaStreamDevices& devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
ui_controller_->NotifyUIIndicatorDevicesOpened(render_process_id,
render_view_id,
@@ -469,7 +455,7 @@
void MediaStreamManager::NotifyUIDevicesClosed(
int render_process_id,
int render_view_id,
- const content::MediaStreamDevices& devices) {
+ const MediaStreamDevices& devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
ui_controller_->NotifyUIIndicatorDevicesClosed(render_process_id,
render_view_id,
@@ -516,12 +502,11 @@
std::string* label) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES;
+ for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES;
++i) {
const MediaStreamType stream_type = static_cast<MediaStreamType>(i);
if (Requested(new_request->options, stream_type)) {
- new_request->setState(stream_type,
- content::MEDIA_REQUEST_STATE_REQUESTED);
+ new_request->setState(stream_type, MEDIA_REQUEST_STATE_REQUESTED);
DCHECK_GE(active_enumeration_ref_count_[stream_type], 0);
if (active_enumeration_ref_count_[stream_type] == 0) {
++active_enumeration_ref_count_[stream_type];
@@ -572,14 +557,12 @@
#endif
CHECK(device_thread_->Start());
- audio_input_device_manager_ =
- new media_stream::AudioInputDeviceManager(audio_manager_);
+ audio_input_device_manager_ = new AudioInputDeviceManager(audio_manager_);
audio_input_device_manager_->Register(this,
device_thread_->message_loop_proxy());
- video_capture_manager_ = new media_stream::VideoCaptureManager();
- video_capture_manager_->Register(this,
- device_thread_->message_loop_proxy());
+ video_capture_manager_ = new VideoCaptureManager();
+ video_capture_manager_->Register(this, device_thread_->message_loop_proxy());
// We want to be notified of IO message loop destruction to delete the thread
// and the device managers.
@@ -615,8 +598,7 @@
return;
}
- DCHECK_NE(request->getState(stream_type),
- content::MEDIA_REQUEST_STATE_REQUESTED);
+ DCHECK_NE(request->getState(stream_type), MEDIA_REQUEST_STATE_REQUESTED);
// Check if all devices for this stream type are opened. Update the state if
// they are.
@@ -631,7 +613,7 @@
}
}
- request->setState(stream_type, content::MEDIA_REQUEST_STATE_DONE);
+ request->setState(stream_type, MEDIA_REQUEST_STATE_DONE);
if (!RequestDone(*request)) {
// This stream_type is done, but not the other type.
@@ -647,9 +629,9 @@
StreamDeviceInfoArray audio_devices, video_devices;
for (StreamDeviceInfoArray::const_iterator device_it = devices->begin();
device_it != devices->end(); ++device_it) {
- if (content::IsAudioMediaType(device_it->stream_type)) {
+ if (IsAudioMediaType(device_it->stream_type)) {
audio_devices.push_back(*device_it);
- } else if (content::IsVideoMediaType(device_it->stream_type)) {
+ } else if (IsVideoMediaType(device_it->stream_type)) {
video_devices.push_back(*device_it);
} else {
NOTREACHED();
@@ -678,14 +660,13 @@
// Only cache the device list when there is an EnumerateDevices request, since
// other requests don't turn on device monitoring.
bool need_update_clients = false;
- EnumerationCache* cache =
- (stream_type == content::MEDIA_DEVICE_AUDIO_CAPTURE ?
+ EnumerationCache* cache = (stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ?
&audio_enumeration_cache_ : &video_enumeration_cache_);
if (HasEnumerationRequest(stream_type) &&
(!cache->valid ||
devices.size() != cache->devices.size() ||
!std::equal(devices.begin(), devices.end(), cache->devices.begin(),
- media_stream::StreamDeviceInfo::IsEqual))) {
+ StreamDeviceInfo::IsEqual))) {
cache->valid = true;
cache->devices = devices;
need_update_clients = true;
@@ -699,11 +680,10 @@
for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end();
++it) {
if (it->second.getState(stream_type) ==
- content::MEDIA_REQUEST_STATE_REQUESTED &&
+ MEDIA_REQUEST_STATE_REQUESTED &&
Requested(it->second.options, stream_type)) {
if (it->second.type != DeviceRequest::ENUMERATE_DEVICES)
- it->second.setState(stream_type,
- content::MEDIA_REQUEST_STATE_PENDING_APPROVAL);
+ it->second.setState(stream_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL);
label_list.push_back(it->first);
}
}
@@ -725,7 +705,7 @@
device.session_id =
GetDeviceManager(device_it->stream_type)->Open(device);
request.setState(device_it->stream_type,
- content::MEDIA_REQUEST_STATE_OPENING);
+ MEDIA_REQUEST_STATE_OPENING);
request.devices.push_back(device);
break;
}
@@ -759,9 +739,9 @@
int video_device_idx = -1;
for (StreamDeviceInfoArray::iterator device_it = devices.begin();
device_it != devices.end(); ++device_it) {
- if (content::IsAudioMediaType(device_it->stream_type)) {
+ if (IsAudioMediaType(device_it->stream_type)) {
++audio_device_idx;
- } else if (content::IsVideoMediaType(device_it->stream_type)) {
+ } else if (IsVideoMediaType(device_it->stream_type)) {
++video_device_idx;
} else {
NOTREACHED();
@@ -774,10 +754,8 @@
// We've found the failing device. Find the error case:
// An error should only be reported to the MediaStreamManager if
// the request has not been fulfilled yet.
- DCHECK(it->second.getState(stream_type) !=
- content::MEDIA_REQUEST_STATE_DONE);
- if (it->second.getState(stream_type) !=
- content::MEDIA_REQUEST_STATE_DONE) {
+ DCHECK(it->second.getState(stream_type) != MEDIA_REQUEST_STATE_DONE);
+ if (it->second.getState(stream_type) != MEDIA_REQUEST_STATE_DONE) {
// Request is not done, devices are not opened in this case.
if (devices.size() <= 1) {
// 1. Device not opened and no other devices for this request ->
@@ -811,10 +789,10 @@
if (request.type == DeviceRequest::DEVICE_ACCESS) {
if (!request.callback.is_null()) {
// Map the devices to MediaStreamDevices.
- content::MediaStreamDevices selected_devices;
+ MediaStreamDevices selected_devices;
for (StreamDeviceInfoArray::const_iterator it = devices.begin();
it != devices.end(); ++it) {
- selected_devices.push_back(content::MediaStreamDevice(
+ selected_devices.push_back(MediaStreamDevice(
it->stream_type, it->device_id, it->name));
}
@@ -836,13 +814,12 @@
// opened. in_use might be true if the device type can be used in more
// than one session.
DCHECK_EQ(request.getState(device_it->stream_type),
- content::MEDIA_REQUEST_STATE_PENDING_APPROVAL);
+ MEDIA_REQUEST_STATE_PENDING_APPROVAL);
device_info.in_use = false;
device_info.session_id =
GetDeviceManager(device_info.stream_type)->Open(device_info);
- request.setState(device_it->stream_type,
- content::MEDIA_REQUEST_STATE_OPENING);
+ request.setState(device_it->stream_type, MEDIA_REQUEST_STATE_OPENING);
request.devices.push_back(device_info);
if (device_info.stream_type == request.options.audio_type) {
@@ -853,13 +830,11 @@
}
// Check whether we've received all stream types requested.
- if (!found_audio && content::IsAudioMediaType(request.options.audio_type)) {
- request.setState(request.options.audio_type,
- content::MEDIA_REQUEST_STATE_ERROR);
+ if (!found_audio && IsAudioMediaType(request.options.audio_type)) {
+ request.setState(request.options.audio_type, MEDIA_REQUEST_STATE_ERROR);
}
- if (!found_video && content::IsVideoMediaType(request.options.video_type)) {
- request.setState(request.options.video_type,
- content::MEDIA_REQUEST_STATE_ERROR);
+ if (!found_video && IsVideoMediaType(request.options.video_type)) {
+ request.setState(request.options.video_type, MEDIA_REQUEST_STATE_ERROR);
}
}
@@ -876,7 +851,7 @@
it->second.requester->StreamGenerationFailed(label);
if (request.type == DeviceRequest::DEVICE_ACCESS)
- request.callback.Run(label, content::MediaStreamDevices());
+ request.callback.Run(label, MediaStreamDevices());
requests_.erase(it);
}
@@ -906,7 +881,7 @@
void MediaStreamManager::NotifyDevicesOpened(const DeviceRequest& request) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- content::MediaStreamDevices opened_devices;
+ MediaStreamDevices opened_devices;
DevicesFromRequest(request, &opened_devices);
if (opened_devices.empty())
return;
@@ -918,7 +893,7 @@
void MediaStreamManager::NotifyDevicesClosed(const DeviceRequest& request) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- content::MediaStreamDevices closed_devices;
+ MediaStreamDevices closed_devices;
DevicesFromRequest(request, &closed_devices);
if (closed_devices.empty())
return;
@@ -929,10 +904,10 @@
}
void MediaStreamManager::DevicesFromRequest(
- const DeviceRequest& request, content::MediaStreamDevices* devices) {
+ const DeviceRequest& request, MediaStreamDevices* devices) {
for (StreamDeviceInfoArray::const_iterator it = request.devices.begin();
it != request.devices.end(); ++it) {
- devices->push_back(content::MediaStreamDevice(
+ devices->push_back(MediaStreamDevice(
it->stream_type, it->device_id, it->name));
}
}
@@ -940,17 +915,15 @@
bool MediaStreamManager::RequestDone(const DeviceRequest& request) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- const bool requested_audio =
- content::IsAudioMediaType(request.options.audio_type);
- const bool requested_video =
- content::IsVideoMediaType(request.options.video_type);
+ const bool requested_audio = IsAudioMediaType(request.options.audio_type);
+ const bool requested_video = IsVideoMediaType(request.options.video_type);
const bool audio_done =
!requested_audio ||
request.getState(request.options.audio_type) ==
- content::MEDIA_REQUEST_STATE_DONE ||
+ MEDIA_REQUEST_STATE_DONE ||
request.getState(request.options.audio_type) ==
- content::MEDIA_REQUEST_STATE_ERROR;
+ MEDIA_REQUEST_STATE_ERROR;
if (!audio_done) {
return false;
}
@@ -958,9 +931,9 @@
const bool video_done =
!requested_video ||
request.getState(request.options.video_type) ==
- content::MEDIA_REQUEST_STATE_DONE ||
+ MEDIA_REQUEST_STATE_DONE ||
request.getState(request.options.video_type) ==
- content::MEDIA_REQUEST_STATE_ERROR;
+ MEDIA_REQUEST_STATE_ERROR;
if (!video_done) {
return false;
}
@@ -977,9 +950,9 @@
MediaStreamProvider* MediaStreamManager::GetDeviceManager(
MediaStreamType stream_type) {
- if (content::IsVideoMediaType(stream_type)) {
+ if (IsVideoMediaType(stream_type)) {
return video_capture_manager();
- } else if (content::IsAudioMediaType(stream_type)) {
+ } else if (IsAudioMediaType(stream_type)) {
return audio_input_device_manager();
}
NOTREACHED();
@@ -996,10 +969,10 @@
MediaStreamType stream_type;
EnumerationCache* cache;
if (device_type == base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE) {
- stream_type = content::MEDIA_DEVICE_AUDIO_CAPTURE;
+ stream_type = MEDIA_DEVICE_AUDIO_CAPTURE;
cache = &audio_enumeration_cache_;
} else if (device_type == base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE) {
- stream_type = content::MEDIA_DEVICE_VIDEO_CAPTURE;
+ stream_type = MEDIA_DEVICE_VIDEO_CAPTURE;
cache = &video_enumeration_cache_;
} else {
return; // Uninteresting device change.
@@ -1043,4 +1016,4 @@
return false;
}
-} // namespace media_stream
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698