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 2fe5e6fd2af6dc5f5a97f9c0da932f6c0c2177be..b2ea32024b46f3071e008a1b8d49460f78108268 100644 |
--- a/content/browser/renderer_host/media/media_stream_manager.cc |
+++ b/content/browser/renderer_host/media/media_stream_manager.cc |
@@ -15,6 +15,7 @@ |
#include "base/threading/thread.h" |
#include "content/browser/renderer_host/media/audio_input_device_manager.h" |
#include "content/browser/renderer_host/media/device_request_message_filter.h" |
+#include "content/browser/renderer_host/media/media_source_id_factory.h" |
#include "content/browser/renderer_host/media/media_stream_requester.h" |
#include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
#include "content/browser/renderer_host/media/video_capture_manager.h" |
@@ -197,9 +198,10 @@ std::string MediaStreamManager::MakeMediaAccessRequest( |
const std::string& label = AddRequest(request); |
request->callback = callback; |
- |
- HandleRequest(label); |
- |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&MediaStreamManager::HandleRequest, |
no longer working on chromium
2013/10/25 08:16:39
I don't fully understand this change, how can't we
perkj_chrome
2013/10/25 13:33:50
Yes. the label is used in error reporting.
In orde
|
+ base::Unretained(this), label)); |
return label; |
} |
@@ -248,22 +250,6 @@ std::string MediaStreamManager::GenerateStream( |
} |
} |
- std::string translated_audio_device_id; |
- std::string translated_video_device_id; |
- if (options.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
- bool found_match = TranslateGUIDToRawId( |
- MEDIA_DEVICE_AUDIO_CAPTURE, security_origin, options.audio_device_id, |
- &translated_audio_device_id); |
- DCHECK(found_match || translated_audio_device_id.empty()); |
- } |
- |
- if (options.video_type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
- bool found_match = TranslateGUIDToRawId( |
- MEDIA_DEVICE_VIDEO_CAPTURE, security_origin, options.video_device_id, |
- &translated_video_device_id); |
- DCHECK(found_match || translated_video_device_id.empty()); |
- } |
- |
if (options.video_type == MEDIA_DESKTOP_VIDEO_CAPTURE || |
options.audio_type == MEDIA_LOOPBACK_AUDIO_CAPTURE) { |
// For screen capture we only support two valid combinations: |
@@ -276,33 +262,45 @@ std::string MediaStreamManager::GenerateStream( |
LOG(ERROR) << "Invalid screen capture request."; |
return std::string(); |
} |
- translated_video_device_id = options.video_device_id; |
} |
// Create a new request based on options. |
MediaStreamRequest stream_request( |
target_render_process_id, target_render_view_id, page_request_id, |
tab_capture_device_id, security_origin, MEDIA_GENERATE_STREAM, |
- translated_audio_device_id, translated_video_device_id, |
+ options.audio_device_id, options.video_device_id, |
options.audio_type, options.video_type); |
DeviceRequest* request = new DeviceRequest(requester, stream_request); |
const std::string& label = AddRequest(request); |
- HandleRequest(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::HandleRequest, |
+ base::Unretained(this), label)); |
return label; |
} |
void MediaStreamManager::CancelRequest(const std::string& label) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&MediaStreamManager::DoCancelRequest, |
+ base::Unretained(this), label)); |
+} |
+ |
+void MediaStreamManager::DoCancelRequest(const std::string& label) { |
DeviceRequests::iterator request_it = requests_.find(label); |
if (request_it == requests_.end()) { |
NOTREACHED(); |
return; |
} |
- scoped_ptr<DeviceRequest> request(request_it->second); |
- RemoveRequest(request_it); |
+ DeviceRequest* request(request_it->second); |
if (request->request.request_type == MEDIA_ENUMERATE_DEVICES) { |
+ DeleteRequest(request_it); |
return; |
} |
@@ -321,6 +319,7 @@ void MediaStreamManager::CancelRequest(const std::string& label) { |
// Cancel the request if still pending at UI side. |
request->SetState(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_CLOSING); |
+ DeleteRequest(request_it); |
} |
void MediaStreamManager::CancelAllRequests(int render_process_id) { |
@@ -333,7 +332,10 @@ void MediaStreamManager::CancelAllRequests(int render_process_id) { |
std::string label = request_it->first; |
++request_it; |
- CancelRequest(label); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&MediaStreamManager::DoCancelRequest, |
no longer working on chromium
2013/10/25 08:16:39
same question here too.
perkj_chrome
2013/10/25 13:33:50
Same answer- we need to post always or never.
|
+ base::Unretained(this), label)); |
} |
} |
@@ -343,7 +345,16 @@ void MediaStreamManager::StopStreamDevice(int render_process_id, |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
DVLOG(1) << "StopStreamDevice({render_view_id = " << render_view_id << "} " |
<< ", {device_id = " << device_id << "})"; |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&MediaStreamManager::DoStopStreamDevice, |
+ base::Unretained(this), render_process_id, render_view_id, |
+ device_id)); |
+} |
+void MediaStreamManager::DoStopStreamDevice(int render_process_id, |
+ int render_view_id, |
+ const std::string& device_id) { |
// Find all requests for this |render_process_id| and |render_view_id| of type |
// MEDIA_GENERATE_STREAM that has requested to use |device_id|. |
DeviceRequests::iterator request_it = requests_.begin(); |
@@ -375,8 +386,7 @@ void MediaStreamManager::StopStreamDevice(int render_process_id, |
if (devices->empty()) { |
DeviceRequests::iterator del_itor(request_it); |
++request_it; |
- scoped_ptr<DeviceRequest> request(del_itor->second); |
- RemoveRequest(del_itor); |
+ DeleteRequest(del_itor); |
} else { |
++request_it; |
} |
@@ -427,13 +437,10 @@ std::string MediaStreamManager::EnumerateDevices( |
// Create a new request. |
StreamOptions options; |
- EnumerationCache* cache = NULL; |
if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
options.audio_type = type; |
- cache = &audio_enumeration_cache_; |
} else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
options.video_type = type; |
- cache = &video_enumeration_cache_; |
} else { |
NOTREACHED(); |
return std::string(); |
@@ -445,22 +452,34 @@ std::string MediaStreamManager::EnumerateDevices( |
options.audio_type, options.video_type); |
DeviceRequest* request = new DeviceRequest(requester, stream_request); |
const std::string& label = AddRequest(request); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&MediaStreamManager::DoEnumerateDevices, |
+ base::Unretained(this), label)); |
+ |
+ return label; |
+} |
+ |
+void MediaStreamManager::DoEnumerateDevices(const std::string& label) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ DeviceRequest* request = requests_[label]; |
+ |
+ const MediaStreamType type = |
+ request->request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE ? |
+ MEDIA_DEVICE_AUDIO_CAPTURE : MEDIA_DEVICE_VIDEO_CAPTURE; |
+ |
+ EnumerationCache* cache = |
+ request->request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE ? |
+ &audio_enumeration_cache_ : &video_enumeration_cache_; |
if (cache->valid) { |
// Cached device list of this type exists. Just send it out. |
request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); |
- |
- // 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)); |
+ request->devices = cache->devices; |
+ FinalizeEnumerateDevices(label, request); |
} else { |
StartEnumeration(request); |
} |
- |
- return label; |
} |
std::string MediaStreamManager::OpenDevice( |
@@ -478,8 +497,8 @@ std::string MediaStreamManager::OpenDevice( |
// Create a new request. |
StreamOptions options; |
if (IsAudioMediaType(type)) { |
- options.audio_type = type; |
- options.audio_device_id = device_id; |
+ options.audio_type = type; |
+ options.audio_device_id = device_id; |
} else if (IsVideoMediaType(type)) { |
options.video_type = type; |
options.video_device_id = device_id; |
@@ -494,23 +513,14 @@ std::string MediaStreamManager::OpenDevice( |
options.video_device_id, options.audio_type, options.video_type); |
DeviceRequest* request = new DeviceRequest(requester, stream_request); |
const std::string& label = AddRequest(request); |
- StartEnumeration(request); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&MediaStreamManager::HandleRequest, |
+ base::Unretained(this), label)); |
return 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 (!base::SystemMonitor::Get()) |
@@ -539,13 +549,48 @@ void MediaStreamManager::StopMonitoring() { |
} |
} |
-bool MediaStreamManager::TranslateGUIDToRawId(MediaStreamType stream_type, |
- const GURL& security_origin, |
- const std::string& device_guid, |
- std::string* raw_device_id) { |
+bool MediaStreamManager::TransLateRequestedSourceIdToDeviceId( |
+ MediaStreamRequest* request) { |
+ // If a specific device has been requested we need to find the real device id. |
+ if (request->audio_type == MEDIA_DEVICE_AUDIO_CAPTURE && |
+ !request->requested_audio_device_id.empty()) { |
+ if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_AUDIO_CAPTURE, |
+ request->security_origin, |
+ request->requested_audio_device_id, |
+ &request->requested_audio_device_id)) { |
+ // TODO(perkj): guM should support mandatory and optional constraints. |
no longer working on chromium
2013/10/25 12:00:07
nit, gUM
perkj_chrome
2013/10/25 13:33:50
Done.
|
+ // Ie - if the sourceId is optional but it does not match - guM should |
+ // not fail. For now we treat sourceId as a mandatory constraint. |
+ return false; |
+ } |
+ } |
+ |
+ if (request->video_type == MEDIA_DEVICE_VIDEO_CAPTURE && |
+ !request->requested_video_device_id.empty()) { |
+ if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_VIDEO_CAPTURE, |
+ request->security_origin, |
+ request->requested_video_device_id, |
+ &request->requested_video_device_id)) { |
+ // TODO(perkj): guM should support mandatory and optional constraints. |
+ // Ie - if the sourceId is optional but it does not match - guM should |
+ // not fail. For now we treat sourceId as a mandatory constraint. |
+ return false; |
+ } |
+ } |
+ DVLOG(1) << "Requested audio device " << request->requested_audio_device_id; |
+ DVLOG(1) << "Requested video device " << request->requested_video_device_id; |
+ return true; |
+} |
+ |
+ |
+bool MediaStreamManager::TranslateSourceIdToDeviceId( |
+ MediaStreamType stream_type, |
+ const GURL& security_origin, |
+ const std::string& source_id, |
+ std::string* device_id) { |
DCHECK(stream_type == MEDIA_DEVICE_AUDIO_CAPTURE || |
stream_type == MEDIA_DEVICE_VIDEO_CAPTURE); |
- if (device_guid.empty()) |
+ if (source_id.empty()) |
return false; |
EnumerationCache* cache = |
@@ -559,9 +604,9 @@ bool MediaStreamManager::TranslateGUIDToRawId(MediaStreamType stream_type, |
for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); |
it != cache->devices.end(); |
++it) { |
- if (DeviceRequestMessageFilter::DoesRawIdMatchGuid( |
- security_origin, device_guid, it->device.id)) { |
- *raw_device_id = it->device.id; |
+ if (MediaSourceIdFactory::DoesSourceIdMatchDeviceId( |
+ security_origin, source_id, it->device.id)) { |
+ *device_id = it->device.id; |
return true; |
} |
} |
@@ -609,7 +654,8 @@ std::string MediaStreamManager::AddRequest(DeviceRequest* request) { |
return unique_label; |
} |
-void MediaStreamManager::RemoveRequest(DeviceRequests::iterator it) { |
+void MediaStreamManager::DeleteRequest(DeviceRequests::iterator it) { |
+ delete it->second; |
no longer working on chromium
2013/10/25 12:00:07
I think it is safer to use smart pointer to do the
perkj_chrome
2013/10/25 13:33:50
ok- but I think delete NULL is ok.
|
requests_.erase(it); |
} |
@@ -673,6 +719,12 @@ void MediaStreamManager::HandleRequest(const std::string& label) { |
return; |
} |
+ // If a specific device has been requested we need to find the real device id. |
+ if (!TransLateRequestedSourceIdToDeviceId(&request->request)) { |
+ FinalizeRequestFailed(label); |
+ return; |
+ } |
+ |
// No need to do new device enumerations, post the request to UI |
// immediately. |
if (IsAudioMediaType(audio_type)) |
@@ -683,15 +735,48 @@ void MediaStreamManager::HandleRequest(const std::string& label) { |
PostRequestToUI(label); |
} |
+bool MediaStreamManager::FindRequestedDeviceInfo( |
+ const std::string& source_id, |
+ int render_process_id, |
+ int render_view_id, |
+ MediaStreamRequestType type, |
+ StreamDeviceInfo* device_info) { |
+ for (DeviceRequests::const_iterator it = requests_.begin(); |
+ it != requests_.end() ; ++it) { |
+ const DeviceRequest* request = it->second; |
+ if (request->request.render_process_id ==render_process_id && |
+ request->request.render_view_id == render_view_id && |
+ request->request.request_type == type) { |
+ for (StreamDeviceInfoArray::const_iterator device_it = |
+ request->devices.begin(); |
+ device_it != request->devices.end(); ++device_it) { |
+ if (source_id == device_it->device.id) { |
+ if (device_info) |
+ *device_info = *device_it; |
+ return true; |
+ } |
+ } |
+ } |
+ } |
+ return false; |
+} |
+ |
bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
int render_process_id, |
int render_view_id, |
+ GURL security_origin, |
MediaStreamRequestType type, |
const std::string& device_id, |
StreamDeviceInfo* device_info, |
MediaRequestState* request_state) const { |
DCHECK(device_info); |
DCHECK(request_state); |
+ |
+ std::string source_id; |
+ MediaSourceIdFactory::GenerateSourceId(security_origin, |
+ device_id, |
+ &source_id); |
+ |
for (DeviceRequests::const_iterator it = requests_.begin(); |
it != requests_.end() ; ++it) { |
const DeviceRequest* request = it->second; |
@@ -701,7 +786,7 @@ bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
for (StreamDeviceInfoArray::const_iterator device_it = |
request->devices.begin(); |
device_it != request->devices.end(); ++device_it) { |
- if (device_it->device.id == device_id) { |
+ if (device_it->device.id == source_id) { |
*device_info = *device_it; |
*request_state = request->state(device_it->device.type); |
return true; |
@@ -712,6 +797,77 @@ bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
return false; |
} |
+void MediaStreamManager::FinalizeGenerateStream(const std::string& label, |
+ DeviceRequest* request) { |
+ const StreamDeviceInfoArray& requested_devices = request->devices; |
+ |
+ // Partition the array of devices into audio vs video. |
+ StreamDeviceInfoArray audio_devices, video_devices; |
+ for (StreamDeviceInfoArray::const_iterator device_it = |
+ requested_devices.begin(); |
+ device_it != requested_devices.end(); ++device_it) { |
+ if (IsAudioMediaType(device_it->device.type)) { |
+ audio_devices.push_back(*device_it); |
+ } else if (IsVideoMediaType(device_it->device.type)) { |
+ video_devices.push_back(*device_it); |
+ } else { |
+ NOTREACHED(); |
+ } |
+ } |
+ |
+ request->requester->StreamGenerated(label, audio_devices, video_devices); |
+} |
+ |
+void MediaStreamManager::FinalizeRequestFailed( |
+ const std::string& label) { |
+ DeviceRequests::iterator request_it = requests_.find(label); |
+ if (request_it == requests_.end()) { |
no longer working on chromium
2013/10/25 12:00:07
nit, no need {}
perkj_chrome
2013/10/25 13:33:50
Done.
|
+ return; |
+ } |
+ DeviceRequest* request(request_it->second); |
+ if (request->requester) |
+ request->requester->StreamGenerationFailed(label); |
+ |
+ if (request->request.request_type == MEDIA_DEVICE_ACCESS && |
+ !request->callback.is_null()) { |
+ request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); |
+ } |
+ |
+ DeleteRequest(request_it); |
+} |
+ |
+void MediaStreamManager::FinalizeOpenDevice(const std::string& label, |
+ DeviceRequest* request) { |
+ const StreamDeviceInfoArray& requested_devices = request->devices; |
+ request->requester->DeviceOpened(label, requested_devices.front()); |
+} |
+ |
+void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label, |
+ DeviceRequest* request) { |
+ StreamDeviceInfoArray hmaced_devices; |
+ MediaSourceIdFactory::GenerateSourceIds(request->request.security_origin, |
+ request->devices, |
+ &hmaced_devices); |
+ request->requester->DevicesEnumerated(label, hmaced_devices); |
+} |
+ |
+void MediaStreamManager::FinalizeMediaAccessRequest( |
+ const std::string& label, |
+ const MediaStreamDevices& devices) { |
+ DeviceRequests::iterator request_it = requests_.find(label); |
+ if (request_it == requests_.end()) { |
no longer working on chromium
2013/10/25 12:00:07
ditto
perkj_chrome
2013/10/25 13:33:50
Done.
|
+ return; |
+ } |
+ DeviceRequest* request(request_it->second); |
+ |
+ if (!request->callback.is_null()) |
+ request->callback.Run(devices, request->ui_proxy.Pass()); |
+ |
+ // Delete the request since it is done. |
+ DeleteRequest(request_it); |
+ return; |
no longer working on chromium
2013/10/25 12:00:07
you don't need the return
perkj_chrome
2013/10/25 13:33:50
Done.
|
+} |
+ |
void MediaStreamManager::InitializeDeviceManagersOnIOThread() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
if (device_thread_) |
@@ -766,7 +922,6 @@ void MediaStreamManager::Opened(MediaStreamType stream_type, |
const StreamDeviceInfo* info = |
audio_input_device_manager_->GetOpenedDeviceInfoById( |
device_it->session_id); |
- DCHECK_EQ(info->device.id, device_it->device.id); |
device_it->device.input = info->device.input; |
device_it->device.matched_output = info->device.matched_output; |
} |
@@ -785,27 +940,12 @@ void MediaStreamManager::HandleRequestDone(const std::string& label, |
DVLOG(1) << "HandleRequestDone(" |
<< ", {label = " << label << "})"; |
- const StreamDeviceInfoArray& requested_devices = request->devices; |
switch (request->request.request_type) { |
case MEDIA_OPEN_DEVICE: |
- request->requester->DeviceOpened(label, requested_devices.front()); |
+ FinalizeOpenDevice(label, request); |
break; |
case MEDIA_GENERATE_STREAM: { |
- // Partition the array of devices into audio vs video. |
- StreamDeviceInfoArray audio_devices, video_devices; |
- for (StreamDeviceInfoArray::const_iterator device_it = |
- requested_devices.begin(); |
- device_it != requested_devices.end(); ++device_it) { |
- if (IsAudioMediaType(device_it->device.type)) { |
- audio_devices.push_back(*device_it); |
- } else if (IsVideoMediaType(device_it->device.type)) { |
- video_devices.push_back(*device_it); |
- } else { |
- NOTREACHED(); |
- } |
- } |
- |
- request->requester->StreamGenerated(label, audio_devices, video_devices); |
+ FinalizeGenerateStream(label, request); |
break; |
} |
default: |
@@ -865,8 +1005,10 @@ void MediaStreamManager::DevicesEnumerated( |
DeviceRequest* request = requests_[*it]; |
switch (request->request.request_type) { |
case MEDIA_ENUMERATE_DEVICES: |
- if (need_update_clients && request->requester) |
- request->requester->DevicesEnumerated(*it, devices); |
+ if (need_update_clients && request->requester) { |
+ request->devices = devices; |
+ FinalizeEnumerateDevices(*it, request); |
+ } |
break; |
default: |
if (request->state(request->request.audio_type) == |
@@ -879,8 +1021,8 @@ void MediaStreamManager::DevicesEnumerated( |
break; |
} |
- // Post the request to UI for permission approval. |
- PostRequestToUI(*it); |
+ // Continue to handle the request. |
+ HandleRequest(*it); |
break; |
} |
} |
@@ -889,69 +1031,6 @@ void MediaStreamManager::DevicesEnumerated( |
DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); |
} |
-void MediaStreamManager::Error(MediaStreamType stream_type, |
- int capture_session_id, |
- MediaStreamProviderError error) { |
- // Find the device for the error call. |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- DVLOG(1) << "Error(" |
- << "{stream_type = " << stream_type << "} ," |
- << "{capture_session_id = " << capture_session_id << "})"; |
- |
- |
- for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); |
- ++it) { |
- StreamDeviceInfoArray& devices = it->second->devices; |
- |
- // TODO(miu): BUG. It's possible for the audio (or video) device array in |
- // the "requester" to become out-of-sync with the order of devices we have |
- // here. See http://crbug.com/147650 |
- int audio_device_idx = -1; |
- int video_device_idx = -1; |
- for (StreamDeviceInfoArray::iterator device_it = devices.begin(); |
- device_it != devices.end(); ++device_it) { |
- if (IsAudioMediaType(device_it->device.type)) { |
- ++audio_device_idx; |
- } else if (IsVideoMediaType(device_it->device.type)) { |
- ++video_device_idx; |
- } else { |
- NOTREACHED(); |
- continue; |
- } |
- if (device_it->device.type != stream_type || |
- device_it->session_id != capture_session_id) { |
- continue; |
- } |
- // 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) != MEDIA_REQUEST_STATE_DONE); |
- if (it->second->state(stream_type) != MEDIA_REQUEST_STATE_DONE) { |
- // Request is not done, devices are not opened in this case. |
- if (devices.size() <= 1) { |
- scoped_ptr<DeviceRequest> request(it->second); |
- // 1. Device not opened and no other devices for this request -> |
- // signal stream error and remove the request. |
- if (request->requester) |
- request->requester->StreamGenerationFailed(it->first); |
- |
- RemoveRequest(it); |
- } else { |
- // 2. Not opened but other devices exists for this request -> remove |
- // device from list, but don't signal an error. |
- devices.erase(device_it); // NOTE: This invalidates device_it! |
- it->second->SetState(stream_type, MEDIA_REQUEST_STATE_ERROR); |
- DVLOG(1) << "Error(" |
- << ", {capture_session_id = " << capture_session_id << "})"; |
- } |
- } |
- if (RequestDone(*it->second)) |
- HandleRequestDone(it->first, it->second); |
- break; |
- } |
- } |
-} |
- |
void MediaStreamManager::HandleAccessRequestResponse( |
const std::string& label, |
const MediaStreamDevices& devices) { |
@@ -964,34 +1043,19 @@ void MediaStreamManager::HandleAccessRequestResponse( |
return; |
} |
- // Handle the case when the request was denied. |
- if (devices.empty()) { |
- // Notify the users about the request result. |
- scoped_ptr<DeviceRequest> request(request_it->second); |
- if (request->requester) |
- request->requester->StreamGenerationFailed(label); |
- |
- if (request->request.request_type == MEDIA_DEVICE_ACCESS && |
- !request->callback.is_null()) { |
- request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); |
- } |
- |
- RemoveRequest(request_it); |
+ DeviceRequest* request = request_it->second; |
+ if (request->request.request_type == MEDIA_DEVICE_ACCESS) { |
+ FinalizeMediaAccessRequest(label, devices); |
return; |
} |
- if (request_it->second->request.request_type == MEDIA_DEVICE_ACCESS) { |
- scoped_ptr<DeviceRequest> request(request_it->second); |
- if (!request->callback.is_null()) |
- request->callback.Run(devices, request->ui_proxy.Pass()); |
- |
- // Delete the request since it is done. |
- RemoveRequest(request_it); |
+ // Handle the case when the request was denied. |
+ if (devices.empty()) { |
+ FinalizeRequestFailed(label); |
return; |
} |
// Process all newly-accepted devices for this request. |
- DeviceRequest* request = request_it->second; |
bool found_audio = false; |
bool found_video = false; |
for (MediaStreamDevices::const_iterator device_it = devices.begin(); |
@@ -1032,11 +1096,11 @@ void MediaStreamManager::HandleAccessRequestResponse( |
// per render view. This is so that the permission to use a device can be |
// revoked by a single call to StopStreamDevice regardless of how many |
// MediaStreams it is being used in. |
- |
if (request->request.request_type == MEDIA_GENERATE_STREAM) { |
MediaRequestState state; |
if (FindExistingRequestedDeviceInfo(request->request.render_process_id, |
request->request.render_view_id, |
+ request->request.security_origin, |
request->request.request_type, |
device_it->id, |
&device_info, |
@@ -1051,7 +1115,12 @@ void MediaStreamManager::HandleAccessRequestResponse( |
} |
device_info.session_id = |
GetDeviceManager(device_info.device.type)->Open(device_info); |
+ MediaSourceIdFactory::GenerateSourceId( |
+ request->request.security_origin, |
+ device_it->id, |
+ &device_info.device.id); |
request->devices.push_back(device_info); |
+ |
request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); |
DVLOG(1) << "HandleAccessRequestResponse - opening device " |
<< ", {label = " << label << "}" |
@@ -1101,6 +1170,7 @@ void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { |
} |
void MediaStreamManager::WillDestroyCurrentMessageLoop() { |
+ DVLOG(3) << "MediaStreamManager::WillDestroyCurrentMessageLoop()"; |
DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
DCHECK(requests_.empty()); |
if (device_thread_) { |