| 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 1329b97d8c7b1d28da84667c995ae40956eac700..c1dd331f0aa3462e5411d6aa2bf68aff36211adf 100644
|
| --- a/content/browser/renderer_host/media/media_stream_manager.cc
|
| +++ b/content/browser/renderer_host/media/media_stream_manager.cc
|
| @@ -178,37 +178,6 @@ void MediaStreamManager::GenerateStream(MediaStreamRequester* requester,
|
| StartEnumeration(&new_request, label);
|
| }
|
|
|
| -void MediaStreamManager::CancelRequests(MediaStreamRequester* requester) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - DeviceRequests::iterator it = requests_.begin();
|
| - while (it != requests_.end()) {
|
| - if (it->second.requester == requester && !RequestDone(it->second)) {
|
| - // The request isn't complete, but there might be some devices already
|
| - // opened -> close them.
|
| - DeviceRequest* request = &(it->second);
|
| - if (request->state[content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE] ==
|
| - DeviceRequest::kOpening) {
|
| - for (StreamDeviceInfoArray::iterator it =
|
| - request->audio_devices.begin(); it != request->audio_devices.end();
|
| - ++it) {
|
| - audio_input_device_manager()->Close(it->session_id);
|
| - }
|
| - }
|
| - if (request->state[content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE] ==
|
| - DeviceRequest::kOpening) {
|
| - for (StreamDeviceInfoArray::iterator it =
|
| - request->video_devices.begin(); it != request->video_devices.end();
|
| - ++it) {
|
| - video_capture_manager()->Close(it->session_id);
|
| - }
|
| - }
|
| - requests_.erase(it++);
|
| - } else {
|
| - ++it;
|
| - }
|
| - }
|
| -}
|
| -
|
| void MediaStreamManager::CancelGenerateStream(const std::string& label) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
|
| @@ -256,7 +225,9 @@ 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::kGenerateStream) {
|
| +
|
| + if (it->second.type == DeviceRequest::kGenerateStream &&
|
| + RequestDone(it->second)) {
|
| NotifyObserverDevicesClosed(&(it->second));
|
| }
|
| requests_.erase(it);
|
| @@ -347,16 +318,12 @@ void MediaStreamManager::StartEnumeration(
|
| 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));
|
| + device_settings_->RequestCaptureDeviceUsage(request_label,
|
| + new_request->render_process_id,
|
| + new_request->render_view_id,
|
| + new_request->options,
|
| + new_request->security_origin);
|
| }
|
|
|
| (*label) = request_label;
|
| @@ -494,11 +461,7 @@ void MediaStreamManager::DevicesEnumerated(
|
| }
|
| break;
|
| default:
|
| - BrowserThread::PostTask(BrowserThread::IO,
|
| - FROM_HERE,
|
| - base::Bind(&MediaStreamDeviceSettings::AvailableDevices,
|
| - base::Unretained(device_settings_.get()),
|
| - *it, stream_type, devices));
|
| + device_settings_->AvailableDevices(*it, stream_type, devices);
|
| }
|
| }
|
| label_list.clear();
|
| @@ -537,17 +500,22 @@ void MediaStreamManager::Error(MediaStreamType stream_type,
|
| it->second.requester->VideoDeviceFailed(it->first, device_idx);
|
| }
|
| GetDeviceManager(stream_type)->Close(capture_session_id);
|
| - devices->erase(device_it);
|
| - } else if (it->second.audio_devices.size()
|
| - + it->second.video_devices.size() <= 1) {
|
| - // 2. Device not opened and no other devices for this request ->
|
| - // signal stream error and remove the request.
|
| - it->second.requester->StreamGenerationFailed(it->first);
|
| - requests_.erase(it);
|
| + // We don't erase the devices here so that we can update the UI
|
| + // properly in StopGeneratedStream().
|
| + it->second.state[stream_type] = DeviceRequest::kError;
|
| } else {
|
| - // 3. Not opened but other devices exists for this request -> remove
|
| - // device from list, but don't signal an error.
|
| - devices->erase(device_it);
|
| + // Request is not done, devices are not opened in this case.
|
| + if (it->second.audio_devices.size()
|
| + + it->second.video_devices.size() <= 1) {
|
| + // 2. Device not opened and no other devices for this request ->
|
| + // signal stream error and remove the request.
|
| + it->second.requester->StreamGenerationFailed(it->first);
|
| + requests_.erase(it);
|
| + } else {
|
| + // 3. Not opened but other devices exists for this request -> remove
|
| + // device from list, but don't signal an error.
|
| + devices->erase(device_it);
|
| + }
|
| }
|
| return;
|
| }
|
| @@ -686,8 +654,12 @@ void MediaStreamManager::DevicesFromRequest(
|
| bool MediaStreamManager::RequestDone(const DeviceRequest& request) const {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| // Check if all devices are opened.
|
| - if (Requested(request.options,
|
| - content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE)) {
|
| + MediaStreamType stream_type = content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE;
|
| + if (Requested(request.options, stream_type)) {
|
| + if (request.state[stream_type] != DeviceRequest::kDone &&
|
| + request.state[stream_type] != DeviceRequest::kError)
|
| + return false;
|
| +
|
| for (StreamDeviceInfoArray::const_iterator it =
|
| request.audio_devices.begin(); it != request.audio_devices.end();
|
| ++it) {
|
| @@ -696,8 +668,13 @@ bool MediaStreamManager::RequestDone(const DeviceRequest& request) const {
|
| }
|
| }
|
| }
|
| - if (Requested(request.options,
|
| - content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE)) {
|
| +
|
| + stream_type = content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE;
|
| + if (Requested(request.options, stream_type)) {
|
| + if (request.state[stream_type] != DeviceRequest::kDone &&
|
| + request.state[stream_type] != DeviceRequest::kError)
|
| + return false;
|
| +
|
| for (StreamDeviceInfoArray::const_iterator it =
|
| request.video_devices.begin(); it != request.video_devices.end();
|
| ++it) {
|
| @@ -706,6 +683,7 @@ bool MediaStreamManager::RequestDone(const DeviceRequest& request) const {
|
| }
|
| }
|
| }
|
| +
|
| return true;
|
| }
|
|
|
|
|