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 f35795252c46127548d77e93a667a0460b0a487b..164f2ab26b558b120a8186dc5423224f960e4904 100644 |
--- a/content/browser/renderer_host/media/media_stream_manager.cc |
+++ b/content/browser/renderer_host/media/media_stream_manager.cc |
@@ -25,6 +25,7 @@ |
#endif |
using content::BrowserThread; |
+using content::MediaStreamRequest; |
namespace media_stream { |
@@ -74,15 +75,6 @@ void DeviceThread::CleanUp() { |
// TODO(xians): Merge DeviceRequest with MediaStreamRequest. |
perkj_chrome
2012/10/04 08:19:25
Is this todo fixed by this?
justinlin
2012/10/08 08:59:45
Not quite.
|
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, |
@@ -91,10 +83,11 @@ struct MediaStreamManager::DeviceRequest { |
DeviceRequest() |
: requester(NULL), |
- state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED), |
type(GENERATE_STREAM), |
render_process_id(-1), |
- render_view_id(-1) { |
+ render_view_id(-1), |
+ state_(content::NUM_MEDIA_TYPES, |
+ MediaStreamRequest::STATE_NOT_REQUESTED) { |
perkj_chrome
2012/10/04 08:19:25
indentation
justinlin
2012/10/08 08:59:45
Done.
|
} |
DeviceRequest(MediaStreamRequester* requester, |
@@ -104,11 +97,12 @@ struct MediaStreamManager::DeviceRequest { |
const GURL& request_security_origin) |
: requester(requester), |
options(request_options), |
- state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED), |
type(GENERATE_STREAM), |
render_process_id(render_process_id), |
render_view_id(render_view_id), |
- security_origin(request_security_origin) { |
+ security_origin(request_security_origin), |
+ state_(content::NUM_MEDIA_TYPES, |
no longer working on chromium
2012/10/04 18:41:49
This is a struct, use state or make the struct int
justinlin
2012/10/08 08:59:45
Done. It's kind of in an awkward state now, not su
|
+ MediaStreamRequest::STATE_NOT_REQUESTED) { |
perkj_chrome
2012/10/04 08:19:25
indentation
justinlin
2012/10/08 08:59:45
Done.
|
DCHECK(requester); |
} |
@@ -116,15 +110,50 @@ struct MediaStreamManager::DeviceRequest { |
MediaStreamRequester* requester; |
StreamOptions options; |
- std::vector<RequestState> state; |
RequestType type; |
int render_process_id; |
int render_view_id; |
GURL security_origin; |
std::string requested_device_id; |
StreamDeviceInfoArray devices; |
+ |
+ void setState(int index, MediaStreamRequest::RequestState newState) { |
no longer working on chromium
2012/10/04 18:41:49
Oh, since you are adding functions to this struct,
justinlin
2012/10/08 08:59:45
Done.
|
+ state_[index] = newState; |
+ } |
+ |
+ MediaStreamRequest::RequestState getState(int index) const { |
+ return state_[index]; |
+ } |
perkj_chrome
2012/10/04 08:19:25
empty line before privat: section
justinlin
2012/10/08 08:59:45
Done.
|
+ private: |
+ std::vector<MediaStreamRequest::RequestState> state_; |
}; |
+static void NotifyObserverRequestStateChange( |
+ MediaStreamManager::DeviceRequest* request, |
+ MediaStreamType stream_type, |
+ const MediaStreamRequest::RequestState newState, |
+ const std::string& device_id) { |
+ content::MediaObserver* media_observer = |
+ content::GetContentClient()->browser()->GetMediaObserver(); |
perkj_chrome
2012/10/04 08:19:25
I am not familiar with GetMediaObserver. Why is th
justinlin
2012/10/08 08:59:45
Same as the other methods that notify observers.
|
+ if (media_observer == NULL) |
+ return; |
+ media_observer->OnMediaRequestStateChange( |
+ request->render_process_id, |
+ request->render_view_id, |
+ content::MediaStreamDevice(stream_type,device_id, ""), |
no longer working on chromium
2012/10/04 18:41:49
one space
justinlin
2012/10/08 08:59:45
Done.
|
+ newState); |
+} |
+ |
+// Helper to update the request state and notify observers. |
+static void UpdateRequestState( |
+ MediaStreamManager::DeviceRequest* request, |
+ MediaStreamType stream_type, |
+ const MediaStreamRequest::RequestState newState, |
+ const std::string& device_id = "") { |
+ request->setState(stream_type, newState); |
+ NotifyObserverRequestStateChange(request, stream_type, newState, device_id); |
no longer working on chromium
2012/10/04 18:41:49
It does not gain anything to break it into two fun
justinlin
2012/10/08 08:59:45
Done.
|
+} |
+ |
MediaStreamManager::EnumerationCache::EnumerationCache() |
: valid(false) { |
} |
@@ -219,14 +248,18 @@ 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_id); |
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; |
+ UpdateRequestState(&request, options.video_type, |
+ MediaStreamRequest::STATE_PENDING_APPROVAL, |
+ device_id); |
device_settings_->AvailableDevices( |
*label, options.video_type, StreamDeviceInfoArray( |
1, StreamDeviceInfo(options.video_type, device_id, device_id, |
@@ -245,7 +278,8 @@ 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.getState(stream_type) != |
+ MediaStreamRequest::STATE_OPENING) { |
continue; |
} |
for (StreamDeviceInfoArray::const_iterator device_it = |
@@ -319,7 +353,8 @@ void MediaStreamManager::EnumerateDevices( |
if (cache->valid) { |
// Cached device list of this type exists. Just send it out. |
- new_request.state[type] = DeviceRequest::STATE_REQUESTED; |
+ UpdateRequestState(&new_request, type, |
+ MediaStreamRequest::STATE_REQUESTED); |
AddRequest(new_request, label); |
// Need to post a task since the requester won't have label till |
// this function returns. |
@@ -423,7 +458,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]; |
@@ -473,7 +509,6 @@ void MediaStreamManager::EnsureDeviceManagersStarted() { |
io_loop_ = MessageLoop::current(); |
io_loop_->AddDestructionObserver(this); |
} |
no longer working on chromium
2012/10/04 18:41:49
add back one empty line
justinlin
2012/10/08 08:59:45
Done.
|
- |
void MediaStreamManager::Opened(MediaStreamType stream_type, |
int capture_session_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
@@ -502,7 +537,8 @@ void MediaStreamManager::Opened(MediaStreamType stream_type, |
return; |
} |
- DCHECK_NE(request->state[stream_type], DeviceRequest::STATE_REQUESTED); |
+ DCHECK_NE(request->getState(stream_type), |
+ MediaStreamRequest::STATE_REQUESTED); |
// Check if all devices for this stream type are opened. Update the state if |
// they are. |
@@ -516,7 +552,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. |
@@ -583,10 +619,12 @@ 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.getState(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, |
no longer working on chromium
2012/10/04 18:41:49
Are you sure you want this?
The request might not
justinlin
2012/10/08 08:59:45
Yes, we filter by the stream type later in the ext
|
+ MediaStreamRequest::STATE_PENDING_APPROVAL); |
label_list.push_back(it->first); |
} |
} |
@@ -607,8 +645,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; |
} |
@@ -656,8 +694,9 @@ void MediaStreamManager::Error(MediaStreamType stream_type, |
// 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.state[stream_type] != DeviceRequest::STATE_DONE); |
- if (it->second.state[stream_type] != DeviceRequest::STATE_DONE) { |
+ DCHECK(it->second.getState(stream_type) |
+ != MediaStreamRequest::STATE_DONE); |
+ if (it->second.getState(stream_type) != MediaStreamRequest::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 -> |
@@ -701,12 +740,14 @@ void MediaStreamManager::DevicesAccepted(const std::string& label, |
// Set in_use to false to be able to track if this device has been |
// 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); |
+ DCHECK_EQ(request.getState(device_it->stream_type), |
+ 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, |
+ device_info.device_id); |
request.devices.push_back(device_info); |
if (device_info.stream_type == request.options.audio_type) { |
@@ -718,10 +759,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); |
} |
} |
@@ -806,16 +849,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.getState(request.options.audio_type) == |
+ MediaStreamRequest::STATE_DONE || |
+ request.getState(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.getState(request.options.video_type) == |
+ MediaStreamRequest::STATE_DONE || |
perkj_chrome
2012/10/04 08:19:25
Fits on line above, here and elsewhere?
justinlin
2012/10/08 08:59:45
Done.
|
+ request.getState(request.options.video_type) == |
+ MediaStreamRequest::STATE_ERROR; |
if (!video_done) { |
return false; |
} |