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

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

Issue 10928043: Media Related changes for TabCapture API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial Created 8 years, 3 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
diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc
index 94b703d59813fa61f8138ba21f122befeb4fc8e5..78a7e3e8065c597dd9312618530631a568179cc0 100644
--- a/content/browser/renderer_host/media/media_stream_manager.cc
+++ b/content/browser/renderer_host/media/media_stream_manager.cc
@@ -22,6 +22,7 @@
#include "googleurl/src/gurl.h"
using content::BrowserThread;
+using content::MediaStreamRequest;
namespace media_stream {
@@ -71,15 +72,6 @@ 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
- };
-
enum RequestType {
GENERATE_STREAM = 0,
ENUMERATE_DEVICES,
@@ -88,7 +80,8 @@ struct MediaStreamManager::DeviceRequest {
DeviceRequest()
: requester(NULL),
- state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED),
+ state(content::NUM_MEDIA_TYPES,
+ MediaStreamRequest::STATE_NOT_REQUESTED),
type(GENERATE_STREAM),
render_process_id(-1),
render_view_id(-1) {
@@ -101,7 +94,8 @@ struct MediaStreamManager::DeviceRequest {
const GURL& request_security_origin)
: requester(requester),
options(request_options),
- state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED),
+ state(content::NUM_MEDIA_TYPES,
+ MediaStreamRequest::STATE_NOT_REQUESTED),
type(GENERATE_STREAM),
render_process_id(render_process_id),
render_view_id(render_view_id),
@@ -113,7 +107,7 @@ struct MediaStreamManager::DeviceRequest {
MediaStreamRequester* requester;
StreamOptions options;
- std::vector<RequestState> state;
+ std::vector<MediaStreamRequest::RequestState> state;
RequestType type;
int render_process_id;
int render_view_id;
@@ -216,14 +210,16 @@ void MediaStreamManager::GenerateStreamForDevice(
// this currently exists. Also, we don't have a user-friendly device name for
// the infobar UI.
if (content::IsAudioMediaType(options.audio_type)) {
- request.state[options.audio_type] = DeviceRequest::STATE_PENDING_APPROVAL;
+ UpdateRequestState(&request, options.audio_type,
+ MediaStreamRequest::STATE_PENDING_APPROVAL);
device_settings_->AvailableDevices(
*label, options.audio_type, StreamDeviceInfoArray(
1, StreamDeviceInfo(options.audio_type, device_id, device_id,
false)));
}
if (content::IsVideoMediaType(options.video_type)) {
- request.state[options.video_type] = DeviceRequest::STATE_PENDING_APPROVAL;
+ request.state[options.video_type] =
perkj_chrome 2012/09/27 13:21:48 Why is there two ways of setting the RequestState?
justinlin 2012/10/02 17:19:48 Done. Missed this one. Made the field private so a
+ MediaStreamRequest::STATE_PENDING_APPROVAL;
device_settings_->AvailableDevices(
*label, options.video_type, StreamDeviceInfoArray(
1, StreamDeviceInfo(options.video_type, device_id, device_id,
@@ -242,7 +238,7 @@ void MediaStreamManager::CancelGenerateStream(const std::string& label) {
for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES;
++i) {
const MediaStreamType stream_type = static_cast<MediaStreamType>(i);
- if (request.state[stream_type] != DeviceRequest::STATE_OPENING) {
+ if (request.state[stream_type] != MediaStreamRequest::STATE_OPENING) {
continue;
}
for (StreamDeviceInfoArray::const_iterator device_it =
@@ -316,7 +312,7 @@ void MediaStreamManager::EnumerateDevices(
if (cache->valid) {
// Cached device list of this type exists. Just send it out.
- new_request.state[type] = DeviceRequest::STATE_REQUESTED;
+ new_request.state[type] = MediaStreamRequest::STATE_REQUESTED;
AddRequest(new_request, label);
// Need to post a task since the requester won't have label till
// this function returns.
@@ -411,6 +407,14 @@ void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) {
cache->valid = false;
}
+void MediaStreamManager::UpdateRequestState(
perkj_chrome 2012/09/27 13:21:48 No need to belong to MediaStreamManager. Can be st
justinlin 2012/10/02 17:19:48 Done.
+ DeviceRequest* request,
+ MediaStreamType media_type_index,
+ const MediaStreamRequest::RequestState newState) {
+ request->state[media_type_index] = newState;
+ NotifyObserverRequestStateChange(request, media_type_index);
+}
+
void MediaStreamManager::StartEnumeration(
DeviceRequest* new_request,
std::string* label) {
@@ -420,7 +424,8 @@ void MediaStreamManager::StartEnumeration(
++i) {
const MediaStreamType stream_type = static_cast<MediaStreamType>(i);
if (Requested(new_request->options, stream_type)) {
- new_request->state[stream_type] = DeviceRequest::STATE_REQUESTED;
+ UpdateRequestState(new_request, stream_type,
+ MediaStreamRequest::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];
@@ -499,7 +504,7 @@ void MediaStreamManager::Opened(MediaStreamType stream_type,
return;
}
- DCHECK_NE(request->state[stream_type], DeviceRequest::STATE_REQUESTED);
+ DCHECK_NE(request->state[stream_type], MediaStreamRequest::STATE_REQUESTED);
// Check if all devices for this stream type are opened. Update the state if
// they are.
@@ -513,7 +518,7 @@ void MediaStreamManager::Opened(MediaStreamType stream_type,
return;
}
}
- request->state[stream_type] = DeviceRequest::STATE_DONE;
+ UpdateRequestState(request, stream_type, MediaStreamRequest::STATE_DONE);
if (!RequestDone(*request)) {
// This stream_type is done, but not the other type.
@@ -580,10 +585,11 @@ 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] == MediaStreamRequest::STATE_REQUESTED &&
Requested(it->second.options, stream_type)) {
if (it->second.type != DeviceRequest::ENUMERATE_DEVICES)
- it->second.state[stream_type] = DeviceRequest::STATE_PENDING_APPROVAL;
+ UpdateRequestState(&it->second, stream_type,
+ MediaStreamRequest::STATE_PENDING_APPROVAL);
label_list.push_back(it->first);
}
}
@@ -604,8 +610,8 @@ 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;
+ UpdateRequestState(&request, device_it->stream_type,
+ MediaStreamRequest::STATE_OPENING);
request.devices.push_back(device);
break;
}
@@ -651,7 +657,7 @@ void MediaStreamManager::Error(MediaStreamType stream_type,
continue;
}
// 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] == MediaStreamRequest::STATE_DONE) {
// 1. Already opened -> signal device failure and close device.
// Use device_idx to signal which of the devices encountered an
// error.
@@ -666,7 +672,8 @@ void MediaStreamManager::Error(MediaStreamType stream_type,
GetDeviceManager(stream_type)->Close(capture_session_id);
// We don't erase the devices here so that we can update the UI
// properly in StopGeneratedStream().
- it->second.state[stream_type] = DeviceRequest::STATE_ERROR;
+ UpdateRequestState(&it->second, stream_type,
+ MediaStreamRequest::STATE_ERROR);
} else {
// Request is not done, devices are not opened in this case.
if (devices.size() <= 1) {
@@ -712,11 +719,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.state[device_it->stream_type],
- DeviceRequest::STATE_PENDING_APPROVAL);
+ MediaStreamRequest::STATE_PENDING_APPROVAL);
device_info.in_use = false;
device_info.session_id =
GetDeviceManager(device_info.stream_type)->Open(device_info);
- request.state[device_it->stream_type] = DeviceRequest::STATE_OPENING;
+ UpdateRequestState(&request, device_it->stream_type,
+ MediaStreamRequest::STATE_OPENING);
request.devices.push_back(device_info);
if (device_info.stream_type == request.options.audio_type) {
@@ -728,10 +736,12 @@ void MediaStreamManager::DevicesAccepted(const std::string& label,
// Check whether we've received all stream types requested.
if (!found_audio && content::IsAudioMediaType(request.options.audio_type)) {
- request.state[request.options.audio_type] = DeviceRequest::STATE_ERROR;
+ UpdateRequestState(&request, request.options.audio_type,
+ MediaStreamRequest::STATE_ERROR);
}
if (!found_video && content::IsVideoMediaType(request.options.video_type)) {
- request.state[request.options.video_type] = DeviceRequest::STATE_ERROR;
+ UpdateRequestState(&request, request.options.video_type,
+ MediaStreamRequest::STATE_ERROR);
}
}
@@ -797,6 +807,26 @@ void MediaStreamManager::NotifyObserverDevicesClosed(DeviceRequest* request) {
closed_devices);
}
+void MediaStreamManager::NotifyObserverRequestStateChange(
perkj_chrome 2012/09/27 13:21:48 No need to belong to MediaStreamManager- can be st
justinlin 2012/10/02 17:19:48 Done.
+ DeviceRequest* request, MediaStreamType media_type) {
+ content::MediaObserver* media_observer =
+ content::GetContentClient()->browser()->GetMediaObserver();
+ if (media_observer == NULL)
+ return;
+ for (StreamDeviceInfoArray::const_iterator it = request->devices.begin();
+ it != request->devices.end(); ++it) {
+ if (it->stream_type == media_type) {
+ media_observer->OnMediaRequestStateChange(request->render_process_id,
+ request->render_view_id,
+ content::MediaStreamDevice(
+ it->stream_type,
+ it->device_id,
+ it->name),
+ request->state[media_type]);
+ }
+ }
+}
+
void MediaStreamManager::DevicesFromRequest(
DeviceRequest* request, content::MediaStreamDevices* devices) {
for (StreamDeviceInfoArray::const_iterator it = request->devices.begin();
@@ -816,16 +846,20 @@ bool MediaStreamManager::RequestDone(const DeviceRequest& request) const {
const bool audio_done =
!requested_audio ||
- request.state[request.options.audio_type] == DeviceRequest::STATE_DONE ||
- request.state[request.options.audio_type] == DeviceRequest::STATE_ERROR;
+ request.state[request.options.audio_type] ==
+ MediaStreamRequest::STATE_DONE ||
+ request.state[request.options.audio_type] ==
+ MediaStreamRequest::STATE_ERROR;
if (!audio_done) {
return false;
}
const bool video_done =
!requested_video ||
- request.state[request.options.video_type] == DeviceRequest::STATE_DONE ||
- request.state[request.options.video_type] == DeviceRequest::STATE_ERROR;
+ request.state[request.options.video_type] ==
+ MediaStreamRequest::STATE_DONE ||
+ request.state[request.options.video_type] ==
+ MediaStreamRequest::STATE_ERROR;
if (!video_done) {
return false;
}

Powered by Google App Engine
This is Rietveld 408576698