OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/media/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/run_loop.h" | |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 17 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
17 #include "content/browser/renderer_host/media/device_request_message_filter.h" | 18 #include "content/browser/renderer_host/media/device_request_message_filter.h" |
18 #include "content/browser/renderer_host/media/media_stream_requester.h" | 19 #include "content/browser/renderer_host/media/media_stream_requester.h" |
19 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 20 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
20 #include "content/browser/renderer_host/media/video_capture_manager.h" | 21 #include "content/browser/renderer_host/media/video_capture_manager.h" |
21 #include "content/browser/renderer_host/media/web_contents_capture_util.h" | 22 #include "content/browser/renderer_host/media/web_contents_capture_util.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
24 #include "content/public/browser/media_device_id.h" | 25 #include "content/public/browser/media_device_id.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 return label; | 57 return label; |
57 } | 58 } |
58 | 59 |
59 // Helper to verify if a media stream type is part of options or not. | 60 // Helper to verify if a media stream type is part of options or not. |
60 static bool Requested(const MediaStreamRequest& request, | 61 static bool Requested(const MediaStreamRequest& request, |
61 MediaStreamType stream_type) { | 62 MediaStreamType stream_type) { |
62 return (request.audio_type == stream_type || | 63 return (request.audio_type == stream_type || |
63 request.video_type == stream_type); | 64 request.video_type == stream_type); |
64 } | 65 } |
65 | 66 |
66 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. | |
67 class MediaStreamManager::DeviceRequest { | 67 class MediaStreamManager::DeviceRequest { |
68 public: | 68 public: |
69 DeviceRequest(MediaStreamRequester* requester, | 69 DeviceRequest(MediaStreamRequester* requester, |
70 const MediaStreamRequest& request, | 70 const MediaStreamRequest& request, |
71 int requesting_process_id, | 71 int requesting_process_id, |
72 int requesting_view_id) | 72 int requesting_view_id) |
73 : requester(requester), | 73 : requester(requester), |
74 request(request), | 74 request(request), |
75 requesting_process_id(requesting_process_id), | 75 requesting_process_id(requesting_process_id), |
76 requesting_view_id(requesting_view_id), | 76 requesting_view_id(requesting_view_id), |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 InitializeDeviceManagersOnIOThread(); | 174 InitializeDeviceManagersOnIOThread(); |
175 } else { | 175 } else { |
176 BrowserThread::PostTask( | 176 BrowserThread::PostTask( |
177 BrowserThread::IO, FROM_HERE, | 177 BrowserThread::IO, FROM_HERE, |
178 base::Bind(&MediaStreamManager::InitializeDeviceManagersOnIOThread, | 178 base::Bind(&MediaStreamManager::InitializeDeviceManagersOnIOThread, |
179 base::Unretained(this))); | 179 base::Unretained(this))); |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 MediaStreamManager::~MediaStreamManager() { | 183 MediaStreamManager::~MediaStreamManager() { |
184 DVLOG(1) << "~MediaStreamManager"; | |
184 DCHECK(requests_.empty()); | 185 DCHECK(requests_.empty()); |
185 DCHECK(!device_thread_.get()); | 186 DCHECK(!device_thread_.get()); |
186 } | 187 } |
187 | 188 |
188 VideoCaptureManager* MediaStreamManager::video_capture_manager() { | 189 VideoCaptureManager* MediaStreamManager::video_capture_manager() { |
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
190 DCHECK(video_capture_manager_.get()); | 191 DCHECK(video_capture_manager_.get()); |
191 return video_capture_manager_.get(); | 192 return video_capture_manager_.get(); |
192 } | 193 } |
193 | 194 |
194 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { | 195 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { |
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
196 DCHECK(audio_input_device_manager_.get()); | 197 DCHECK(audio_input_device_manager_.get()); |
197 return audio_input_device_manager_.get(); | 198 return audio_input_device_manager_.get(); |
198 } | 199 } |
199 | 200 |
200 std::string MediaStreamManager::MakeMediaAccessRequest( | 201 std::string MediaStreamManager::MakeMediaAccessRequest( |
201 int render_process_id, | 202 int render_process_id, |
202 int render_view_id, | 203 int render_view_id, |
203 int page_request_id, | 204 int page_request_id, |
204 const StreamOptions& options, | 205 const StreamOptions& options, |
205 const GURL& security_origin, | 206 const GURL& security_origin, |
206 const MediaRequestResponseCallback& callback) { | 207 const MediaRequestResponseCallback& callback) { |
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
208 // Create a new request based on options. | 209 // Create a new request based on options. |
209 MediaStreamRequest stream_request( | 210 MediaStreamRequest stream_request( |
210 render_process_id, render_view_id, page_request_id, std::string(), | 211 render_process_id, render_view_id, page_request_id, |
211 security_origin, MEDIA_DEVICE_ACCESS, std::string(), std::string(), | 212 security_origin, MEDIA_DEVICE_ACCESS, std::string(), std::string(), |
212 options.audio_type, options.video_type); | 213 options.audio_type, options.video_type); |
213 DeviceRequest* request = new DeviceRequest(NULL, stream_request, | 214 DeviceRequest* request = new DeviceRequest(NULL, stream_request, |
214 render_process_id, render_view_id); | 215 render_process_id, render_view_id); |
215 const std::string& label = AddRequest(request); | 216 const std::string& label = AddRequest(request); |
216 | 217 |
217 request->callback = callback; | 218 request->callback = callback; |
218 | 219 // Post a task and handle the request asynchronously. The reason is that the |
219 HandleRequest(label); | 220 // requester won't have a label for the request until this function returns |
220 | 221 // and thus can not handle a response. Using base::Unretained is safe since |
222 // MediaStreamManager is deleted on the UI thread, after the IO thread has | |
223 // been stopped. | |
tommi (sloooow) - chröme
2013/11/27 22:09:43
thanks!
perkj_chrome
2013/11/28 09:46:43
Done.
| |
224 BrowserThread::PostTask( | |
225 BrowserThread::IO, FROM_HERE, | |
226 base::Bind(&MediaStreamManager::SetupRequest, | |
227 base::Unretained(this), label)); | |
221 return label; | 228 return label; |
222 } | 229 } |
223 | 230 |
224 std::string MediaStreamManager::GenerateStream( | 231 std::string MediaStreamManager::GenerateStream( |
225 MediaStreamRequester* requester, | 232 MediaStreamRequester* requester, |
226 int render_process_id, | 233 int render_process_id, |
227 int render_view_id, | 234 int render_view_id, |
228 int page_request_id, | 235 int page_request_id, |
229 const StreamOptions& options, | 236 const StreamOptions& options, |
230 const GURL& security_origin) { | 237 const GURL& security_origin) { |
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
239 DVLOG(1) << "GenerateStream()"; | |
232 if (CommandLine::ForCurrentProcess()->HasSwitch( | 240 if (CommandLine::ForCurrentProcess()->HasSwitch( |
233 switches::kUseFakeDeviceForMediaStream)) { | 241 switches::kUseFakeDeviceForMediaStream)) { |
234 UseFakeDevice(); | 242 UseFakeDevice(); |
235 } | 243 } |
236 if (CommandLine::ForCurrentProcess()->HasSwitch( | 244 if (CommandLine::ForCurrentProcess()->HasSwitch( |
237 switches::kUseFakeUIForMediaStream)) { | 245 switches::kUseFakeUIForMediaStream)) { |
238 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); | 246 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); |
239 } | 247 } |
240 | 248 |
241 int target_render_process_id = render_process_id; | |
242 int target_render_view_id = render_view_id; | |
243 std::string tab_capture_device_id; | |
244 | |
245 // Customize options for a WebContents based capture. | |
246 if (options.audio_type == MEDIA_TAB_AUDIO_CAPTURE || | |
247 options.video_type == MEDIA_TAB_VIDEO_CAPTURE) { | |
248 // TODO(justinlin): Can't plumb audio mirroring using stream type right | |
249 // now, so plumbing by device_id. Will revisit once it's refactored. | |
250 // http://crbug.com/163100 | |
251 tab_capture_device_id = | |
252 WebContentsCaptureUtil::AppendWebContentsDeviceScheme( | |
253 !options.video_device_id.empty() ? | |
254 options.video_device_id : options.audio_device_id); | |
255 | |
256 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
257 tab_capture_device_id, &target_render_process_id, | |
258 &target_render_view_id); | |
259 if (!has_valid_device_id || | |
260 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && | |
261 options.audio_type != MEDIA_NO_SERVICE) || | |
262 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && | |
263 options.video_type != MEDIA_NO_SERVICE)) { | |
264 LOG(ERROR) << "Invalid request."; | |
265 return std::string(); | |
266 } | |
267 } | |
268 | |
269 std::string translated_audio_device_id; | |
270 std::string translated_video_device_id; | |
271 if (options.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE) { | |
272 bool found_match = TranslateGUIDToRawId( | |
273 MEDIA_DEVICE_AUDIO_CAPTURE, security_origin, options.audio_device_id, | |
274 &translated_audio_device_id); | |
275 DCHECK(found_match || translated_audio_device_id.empty()); | |
276 } | |
277 | |
278 if (options.video_type == MEDIA_DEVICE_VIDEO_CAPTURE) { | |
279 bool found_match = TranslateGUIDToRawId( | |
280 MEDIA_DEVICE_VIDEO_CAPTURE, security_origin, options.video_device_id, | |
281 &translated_video_device_id); | |
282 DCHECK(found_match || translated_video_device_id.empty()); | |
283 } | |
284 | |
285 if (options.video_type == MEDIA_DESKTOP_VIDEO_CAPTURE || | |
286 options.audio_type == MEDIA_LOOPBACK_AUDIO_CAPTURE) { | |
287 // For screen capture we only support two valid combinations: | |
288 // (1) screen video capture only, or | |
289 // (2) screen video capture with loopback audio capture. | |
290 if (options.video_type != MEDIA_DESKTOP_VIDEO_CAPTURE || | |
291 (options.audio_type != MEDIA_NO_SERVICE && | |
292 options.audio_type != MEDIA_LOOPBACK_AUDIO_CAPTURE)) { | |
293 // TODO(sergeyu): Surface error message to the calling JS code. | |
294 LOG(ERROR) << "Invalid screen capture request."; | |
295 return std::string(); | |
296 } | |
297 translated_video_device_id = options.video_device_id; | |
298 } | |
299 | |
300 // Create a new request based on options. | 249 // Create a new request based on options. |
301 MediaStreamRequest stream_request( | 250 MediaStreamRequest stream_request( |
302 target_render_process_id, target_render_view_id, page_request_id, | 251 render_process_id, render_view_id, page_request_id, |
303 tab_capture_device_id, security_origin, MEDIA_GENERATE_STREAM, | 252 security_origin, MEDIA_GENERATE_STREAM, |
304 translated_audio_device_id, translated_video_device_id, | 253 options.audio_device_id, options.video_device_id, |
305 options.audio_type, options.video_type); | 254 options.audio_type, options.video_type); |
306 DeviceRequest* request = new DeviceRequest(requester, stream_request, | 255 DeviceRequest* request = new DeviceRequest(requester, stream_request, |
307 render_process_id, | 256 render_process_id, |
308 render_view_id); | 257 render_view_id); |
309 const std::string& label = AddRequest(request); | 258 const std::string& label = AddRequest(request); |
310 HandleRequest(label); | 259 |
260 // Post a task and handle the request asynchronously. The reason is that the | |
261 // requester won't have a label for the request until this function returns | |
262 // and thus can not handle a response. Using base::Unretained is safe since | |
263 // MediaStreamManager is deleted on the UI thread, after the IO thread has | |
264 // been stopped. | |
tommi (sloooow) - chröme
2013/11/27 22:09:43
You could shorten this comment and point to the co
perkj_chrome
2013/11/28 09:46:43
If you don't feel strong about it I will leave thi
| |
265 BrowserThread::PostTask( | |
266 BrowserThread::IO, FROM_HERE, | |
267 base::Bind(&MediaStreamManager::SetupRequest, | |
268 base::Unretained(this), label)); | |
311 return label; | 269 return label; |
312 } | 270 } |
313 | 271 |
314 void MediaStreamManager::CancelRequest(const std::string& label) { | 272 void MediaStreamManager::CancelRequest(const std::string& label) { |
315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
316 DVLOG(1) << "CancelRequest({label = " << label << "})"; | 274 DVLOG(1) << "CancelRequest({label = " << label << "})"; |
317 DeviceRequests::iterator request_it = requests_.find(label); | 275 DeviceRequest* request = FindRequest(label); |
318 if (request_it == requests_.end()) { | 276 if (!request) { |
319 NOTREACHED(); | 277 // The request does not exist. |
278 LOG(ERROR) << "The request with label = " << label << " does not exist."; | |
320 return; | 279 return; |
321 } | 280 } |
322 scoped_ptr<DeviceRequest> request(request_it->second); | |
323 RemoveRequest(request_it); | |
324 | |
325 if (request->request.request_type == MEDIA_ENUMERATE_DEVICES) { | 281 if (request->request.request_type == MEDIA_ENUMERATE_DEVICES) { |
282 DeleteRequest(label); | |
326 return; | 283 return; |
327 } | 284 } |
328 | 285 |
329 // This is a request for opening one or more devices. | 286 // This is a request for opening one or more devices. |
330 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); | 287 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); |
331 device_it != request->devices.end(); ++device_it) { | 288 device_it != request->devices.end(); ++device_it) { |
289 MediaRequestState state = request->state(device_it->device.type); | |
332 // If we have not yet requested the device to be opened - just ignore it. | 290 // If we have not yet requested the device to be opened - just ignore it. |
333 if (request->state(device_it->device.type) != MEDIA_REQUEST_STATE_OPENING | 291 if (state != MEDIA_REQUEST_STATE_OPENING && |
334 && | 292 state != MEDIA_REQUEST_STATE_DONE) { |
335 request->state(device_it->device.type) != MEDIA_REQUEST_STATE_DONE) { | |
336 continue; | 293 continue; |
337 } | 294 } |
338 // Stop the opening/opened devices of the requests. | 295 // Stop the opening/opened devices of the requests. |
339 CloseDevice(device_it->device.type, device_it->session_id); | 296 CloseDevice(device_it->device.type, device_it->session_id); |
340 } | 297 } |
341 | 298 |
342 // Cancel the request if still pending at UI side. | 299 // Cancel the request if still pending at UI side. |
343 request->SetState(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_CLOSING); | 300 request->SetState(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_CLOSING); |
301 DeleteRequest(label); | |
344 } | 302 } |
345 | 303 |
346 void MediaStreamManager::CancelAllRequests(int render_process_id) { | 304 void MediaStreamManager::CancelAllRequests(int render_process_id) { |
347 DeviceRequests::iterator request_it = requests_.begin(); | 305 DeviceRequests::iterator request_it = requests_.begin(); |
348 while (request_it != requests_.end()) { | 306 while (request_it != requests_.end()) { |
349 if (request_it->second->requesting_process_id != render_process_id) { | 307 if (request_it->second->requesting_process_id != render_process_id) { |
350 ++request_it; | 308 ++request_it; |
351 continue; | 309 continue; |
352 } | 310 } |
353 | 311 |
354 std::string label = request_it->first; | 312 std::string label = request_it->first; |
355 ++request_it; | 313 ++request_it; |
356 CancelRequest(label); | 314 CancelRequest(label); |
357 } | 315 } |
358 } | 316 } |
359 | 317 |
360 void MediaStreamManager::StopStreamDevice(int render_process_id, | 318 void MediaStreamManager::StopStreamDevice(int render_process_id, |
361 int render_view_id, | 319 int render_view_id, |
362 const std::string& device_id) { | 320 const std::string& device_id) { |
363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
364 DVLOG(1) << "StopStreamDevice({render_view_id = " << render_view_id << "} " | 322 DVLOG(1) << "StopStreamDevice({render_view_id = " << render_view_id << "} " |
365 << ", {device_id = " << device_id << "})"; | 323 << ", {device_id = " << device_id << "})"; |
366 | |
367 // Find the first request for this |render_process_id| and |render_view_id| | 324 // Find the first request for this |render_process_id| and |render_view_id| |
368 // of type MEDIA_GENERATE_STREAM that has requested to use |device_id| and | 325 // of type MEDIA_GENERATE_STREAM that has requested to use |device_id| and |
369 // stop it. | 326 // stop it. |
370 for (DeviceRequests::iterator request_it = requests_.begin(); | 327 for (DeviceRequests::iterator request_it = requests_.begin(); |
371 request_it != requests_.end(); ++request_it) { | 328 request_it != requests_.end(); ++request_it) { |
372 DeviceRequest* request = request_it->second; | 329 DeviceRequest* request = request_it->second; |
373 const MediaStreamRequest& ms_request = request->request; | 330 const MediaStreamRequest& ms_request = request->request; |
374 if (request->requesting_process_id != render_process_id || | 331 if (request->requesting_process_id != render_process_id || |
375 request->requesting_view_id != render_view_id || | 332 request->requesting_view_id != render_view_id || |
376 ms_request.request_type != MEDIA_GENERATE_STREAM) { | 333 ms_request.request_type != MEDIA_GENERATE_STREAM) { |
(...skipping 25 matching lines...) Expand all Loading... | |
402 device_it->session_id != session_id) { | 359 device_it->session_id != session_id) { |
403 ++device_it; | 360 ++device_it; |
404 continue; | 361 continue; |
405 } | 362 } |
406 if (request->state(type) == MEDIA_REQUEST_STATE_DONE) | 363 if (request->state(type) == MEDIA_REQUEST_STATE_DONE) |
407 CloseDevice(type, session_id); | 364 CloseDevice(type, session_id); |
408 device_it = devices->erase(device_it); | 365 device_it = devices->erase(device_it); |
409 } | 366 } |
410 // If this request doesn't have any active devices, remove the request. | 367 // If this request doesn't have any active devices, remove the request. |
411 if (devices->empty()) { | 368 if (devices->empty()) { |
412 DeviceRequests::iterator del_itor(request_it); | 369 std::string label = request_it->first; |
413 ++request_it; | 370 ++request_it; |
414 scoped_ptr<DeviceRequest> request(del_itor->second); | 371 DeleteRequest(label); |
415 RemoveRequest(del_itor); | |
416 } else { | 372 } else { |
417 ++request_it; | 373 ++request_it; |
418 } | 374 } |
419 } | 375 } |
420 } | 376 } |
421 | 377 |
422 void MediaStreamManager::CloseDevice(MediaStreamType type, int session_id) { | 378 void MediaStreamManager::CloseDevice(MediaStreamType type, int session_id) { |
423 DVLOG(1) << "CloseDevice(" | 379 DVLOG(1) << "CloseDevice(" |
424 << "{type = " << type << "} " | 380 << "{type = " << type << "} " |
425 << "{session_id = " << session_id << "})"; | 381 << "{session_id = " << session_id << "})"; |
(...skipping 29 matching lines...) Expand all Loading... | |
455 // starts monitoring devices. | 411 // starts monitoring devices. |
456 if (!requester) { | 412 if (!requester) { |
457 if (!monitoring_started_) | 413 if (!monitoring_started_) |
458 StartMonitoring(); | 414 StartMonitoring(); |
459 | 415 |
460 return std::string(); | 416 return std::string(); |
461 } | 417 } |
462 | 418 |
463 // Create a new request. | 419 // Create a new request. |
464 StreamOptions options; | 420 StreamOptions options; |
465 EnumerationCache* cache = NULL; | |
466 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { | 421 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
467 options.audio_type = type; | 422 options.audio_type = type; |
468 cache = &audio_enumeration_cache_; | |
469 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { | 423 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
470 options.video_type = type; | 424 options.video_type = type; |
471 cache = &video_enumeration_cache_; | |
472 } else { | 425 } else { |
473 NOTREACHED(); | 426 NOTREACHED(); |
474 return std::string(); | 427 return std::string(); |
475 } | 428 } |
476 | 429 |
477 MediaStreamRequest stream_request( | 430 MediaStreamRequest stream_request( |
478 render_process_id, render_view_id, page_request_id, std::string(), | 431 render_process_id, render_view_id, page_request_id, |
479 security_origin, MEDIA_ENUMERATE_DEVICES, std::string(), std::string(), | 432 security_origin, MEDIA_ENUMERATE_DEVICES, std::string(), std::string(), |
480 options.audio_type, options.video_type); | 433 options.audio_type, options.video_type); |
481 DeviceRequest* request = new DeviceRequest(requester, stream_request, | 434 DeviceRequest* request = new DeviceRequest(requester, stream_request, |
482 render_process_id, | 435 render_process_id, |
483 render_view_id); | 436 render_view_id); |
484 const std::string& label = AddRequest(request); | 437 const std::string& label = AddRequest(request); |
438 // Post a task and handle the request asynchronously. The reason is that the | |
439 // requester won't have a label for the request until this function returns | |
440 // and thus can not handle a response. Using base::Unretained is safe since | |
441 // MediaStreamManager is deleted on the UI thread, after the IO thread has | |
442 // been stopped. | |
tommi (sloooow) - chröme
2013/11/27 22:09:43
same here (although this is fine too)
perkj_chrome
2013/11/28 09:46:43
dito
| |
443 BrowserThread::PostTask( | |
444 BrowserThread::IO, FROM_HERE, | |
445 base::Bind(&MediaStreamManager::DoEnumerateDevices, | |
446 base::Unretained(this), label)); | |
447 | |
448 return label; | |
449 } | |
450 | |
451 void MediaStreamManager::DoEnumerateDevices(const std::string& label) { | |
452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
453 DeviceRequest* request = FindRequest(label); | |
454 if (!request) | |
455 return; // This can happen if the request has been canceled. | |
456 | |
457 MediaStreamType type; | |
458 EnumerationCache* cache; | |
459 if (request->request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE) { | |
460 DCHECK_EQ(MEDIA_NO_SERVICE, request->request.video_type); | |
461 type = MEDIA_DEVICE_AUDIO_CAPTURE; | |
462 cache = &audio_enumeration_cache_; | |
463 } else { | |
464 DCHECK_EQ(MEDIA_DEVICE_VIDEO_CAPTURE, request->request.video_type); | |
465 type = MEDIA_DEVICE_VIDEO_CAPTURE; | |
466 cache = &video_enumeration_cache_; | |
467 } | |
485 | 468 |
486 if (cache->valid) { | 469 if (cache->valid) { |
487 // Cached device list of this type exists. Just send it out. | 470 // Cached device list of this type exists. Just send it out. |
488 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); | 471 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); |
489 | 472 request->devices = cache->devices; |
490 // Need to post a task since the requester won't have label till | 473 FinalizeEnumerateDevices(label, request); |
491 // this function returns. | |
492 BrowserThread::PostTask( | |
493 BrowserThread::IO, FROM_HERE, | |
494 base::Bind(&MediaStreamManager::SendCachedDeviceList, | |
495 base::Unretained(this), cache, label)); | |
496 } else { | 474 } else { |
497 StartEnumeration(request); | 475 StartEnumeration(request); |
498 } | 476 } |
499 | |
500 DVLOG(1) << "Enumerate Devices ({label = " << label << "})"; | 477 DVLOG(1) << "Enumerate Devices ({label = " << label << "})"; |
501 return label; | |
502 } | 478 } |
503 | 479 |
504 std::string MediaStreamManager::OpenDevice( | 480 std::string MediaStreamManager::OpenDevice( |
505 MediaStreamRequester* requester, | 481 MediaStreamRequester* requester, |
506 int render_process_id, | 482 int render_process_id, |
507 int render_view_id, | 483 int render_view_id, |
508 int page_request_id, | 484 int page_request_id, |
509 const std::string& device_id, | 485 const std::string& device_id, |
510 MediaStreamType type, | 486 MediaStreamType type, |
511 const GURL& security_origin) { | 487 const GURL& security_origin) { |
512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
513 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 489 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
514 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 490 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
515 | 491 |
516 // Create a new request. | 492 // Create a new request. |
517 StreamOptions options; | 493 StreamOptions options; |
518 if (IsAudioMediaType(type)) { | 494 if (IsAudioMediaType(type)) { |
519 options.audio_type = type; | 495 options.audio_type = type; |
520 options.audio_device_id = device_id; | 496 options.audio_device_id = device_id; |
521 } else if (IsVideoMediaType(type)) { | 497 } else if (IsVideoMediaType(type)) { |
522 options.video_type = type; | 498 options.video_type = type; |
523 options.video_device_id = device_id; | 499 options.video_device_id = device_id; |
524 } else { | 500 } else { |
525 NOTREACHED(); | 501 NOTREACHED(); |
526 return std::string(); | 502 return std::string(); |
527 } | 503 } |
528 | 504 |
529 MediaStreamRequest stream_request( | 505 MediaStreamRequest stream_request( |
530 render_process_id, render_view_id, page_request_id, std::string(), | 506 render_process_id, render_view_id, page_request_id, |
531 security_origin, MEDIA_OPEN_DEVICE, options.audio_device_id, | 507 security_origin, MEDIA_OPEN_DEVICE, options.audio_device_id, |
532 options.video_device_id, options.audio_type, options.video_type); | 508 options.video_device_id, options.audio_type, options.video_type); |
533 DeviceRequest* request = new DeviceRequest(requester, stream_request, | 509 DeviceRequest* request = new DeviceRequest(requester, stream_request, |
534 render_process_id, | 510 render_process_id, |
535 render_view_id); | 511 render_view_id); |
536 const std::string& label = AddRequest(request); | 512 const std::string& label = AddRequest(request); |
537 StartEnumeration(request); | 513 // Post a task and handle the request asynchronously. The reason is that the |
514 // requester won't have a label for the request until this function returns | |
515 // and thus can not handle a response. Using base::Unretained is safe since | |
516 // MediaStreamManager is deleted on the UI thread, after the IO thread has | |
517 // been stopped. | |
518 BrowserThread::PostTask( | |
519 BrowserThread::IO, FROM_HERE, | |
520 base::Bind(&MediaStreamManager::SetupRequest, | |
521 base::Unretained(this), label)); | |
538 | 522 |
539 DVLOG(1) << "OpenDevice ({label = " << label << "})"; | 523 DVLOG(1) << "OpenDevice ({label = " << label << "})"; |
540 return label; | 524 return label; |
541 } | 525 } |
542 | 526 |
543 void MediaStreamManager::SendCachedDeviceList( | |
544 EnumerationCache* cache, | |
545 const std::string& label) { | |
546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
547 if (cache->valid) { | |
548 DeviceRequests::iterator it = requests_.find(label); | |
549 if (it != requests_.end()) { | |
550 it->second->requester->DevicesEnumerated(label, cache->devices); | |
551 } | |
552 } | |
553 } | |
554 | |
555 void MediaStreamManager::StopRemovedDevices( | 527 void MediaStreamManager::StopRemovedDevices( |
556 const StreamDeviceInfoArray& old_devices, | 528 const StreamDeviceInfoArray& old_devices, |
557 const StreamDeviceInfoArray& new_devices) { | 529 const StreamDeviceInfoArray& new_devices) { |
558 DVLOG(1) << "StopRemovedDevices(" | 530 DVLOG(1) << "StopRemovedDevices(" |
559 << "{#old_devices = " << old_devices.size() << "} " | 531 << "{#old_devices = " << old_devices.size() << "} " |
560 << "{#new_devices = " << new_devices.size() << "})"; | 532 << "{#new_devices = " << new_devices.size() << "})"; |
561 for (StreamDeviceInfoArray::const_iterator old_dev_it = old_devices.begin(); | 533 for (StreamDeviceInfoArray::const_iterator old_dev_it = old_devices.begin(); |
562 old_dev_it != old_devices.end(); ++old_dev_it) { | 534 old_dev_it != old_devices.end(); ++old_dev_it) { |
563 bool device_found = false; | 535 bool device_found = false; |
564 for (StreamDeviceInfoArray::const_iterator new_dev_it = new_devices.begin(); | 536 for (StreamDeviceInfoArray::const_iterator new_dev_it = new_devices.begin(); |
(...skipping 13 matching lines...) Expand all Loading... | |
578 } | 550 } |
579 | 551 |
580 void MediaStreamManager::StopRemovedDevice(const MediaStreamDevice& device) { | 552 void MediaStreamManager::StopRemovedDevice(const MediaStreamDevice& device) { |
581 std::vector<int> session_ids; | 553 std::vector<int> session_ids; |
582 for (DeviceRequests::const_iterator it = requests_.begin(); | 554 for (DeviceRequests::const_iterator it = requests_.begin(); |
583 it != requests_.end() ; ++it) { | 555 it != requests_.end() ; ++it) { |
584 const DeviceRequest* request = it->second; | 556 const DeviceRequest* request = it->second; |
585 for (StreamDeviceInfoArray::const_iterator device_it = | 557 for (StreamDeviceInfoArray::const_iterator device_it = |
586 request->devices.begin(); | 558 request->devices.begin(); |
587 device_it != request->devices.end(); ++device_it) { | 559 device_it != request->devices.end(); ++device_it) { |
588 if (device_it->device.IsEqual(device)) { | 560 std::string source_id = content::GetHMACForMediaDeviceID( |
561 request->request.security_origin, | |
562 device.id); | |
563 if (device_it->device.id == source_id && | |
564 device_it->device.type == device.type) { | |
589 session_ids.push_back(device_it->session_id); | 565 session_ids.push_back(device_it->session_id); |
590 if (it->second->requester) { | 566 if (it->second->requester) { |
591 it->second->requester->DeviceStopped( | 567 it->second->requester->DeviceStopped( |
592 it->second->requesting_view_id, | 568 it->second->requesting_view_id, |
593 it->first, | 569 it->first, |
594 *device_it); | 570 *device_it); |
595 } | 571 } |
596 } | 572 } |
597 } | 573 } |
598 } | 574 } |
(...skipping 24 matching lines...) Expand all Loading... | |
623 void MediaStreamManager::StopMonitoring() { | 599 void MediaStreamManager::StopMonitoring() { |
624 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 600 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
625 if (monitoring_started_) { | 601 if (monitoring_started_) { |
626 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); | 602 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); |
627 monitoring_started_ = false; | 603 monitoring_started_ = false; |
628 ClearEnumerationCache(&audio_enumeration_cache_); | 604 ClearEnumerationCache(&audio_enumeration_cache_); |
629 ClearEnumerationCache(&video_enumeration_cache_); | 605 ClearEnumerationCache(&video_enumeration_cache_); |
630 } | 606 } |
631 } | 607 } |
632 | 608 |
633 bool MediaStreamManager::TranslateGUIDToRawId(MediaStreamType stream_type, | 609 bool MediaStreamManager::TranslateRequestedSourceIdToDeviceId( |
634 const GURL& security_origin, | 610 MediaStreamRequest* request) { |
635 const std::string& device_guid, | 611 // If a specific device has been requested we need to find the real device id. |
636 std::string* raw_device_id) { | 612 if (request->audio_type == MEDIA_DEVICE_AUDIO_CAPTURE && |
613 !request->requested_audio_device_id.empty()) { | |
614 if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_AUDIO_CAPTURE, | |
615 request->security_origin, | |
616 request->requested_audio_device_id, | |
617 &request->requested_audio_device_id)) { | |
618 // TODO(perkj): gUM should support mandatory and optional constraints. | |
619 // Ie - if the sourceId is optional but it does not match - gUM should | |
620 // not fail. For now we treat sourceId as a mandatory constraint. | |
621 LOG(ERROR) << "Requested device does not exist."; | |
622 return false; | |
623 } | |
624 } | |
625 | |
626 if (request->video_type == MEDIA_DEVICE_VIDEO_CAPTURE && | |
627 !request->requested_video_device_id.empty()) { | |
628 if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_VIDEO_CAPTURE, | |
629 request->security_origin, | |
630 request->requested_video_device_id, | |
631 &request->requested_video_device_id)) { | |
632 // TODO(perkj): guM should support mandatory and optional constraints. | |
633 // Ie - if the sourceId is optional but it does not match - guM should | |
634 // not fail. For now we treat sourceId as a mandatory constraint. | |
635 LOG(ERROR) << "Requested device does not exist."; | |
636 return false; | |
637 } | |
638 } | |
639 DVLOG(3) << "Requested audio device " << request->requested_audio_device_id | |
640 << " video device " << request->requested_video_device_id; | |
641 return true; | |
642 } | |
643 | |
644 void MediaStreamManager::TranslateDeviceIdToSourceId( | |
645 const MediaStreamRequest& request, | |
646 MediaStreamDevice* device) { | |
647 if (request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE || | |
648 request.video_type == MEDIA_DEVICE_VIDEO_CAPTURE) { | |
649 device->id = content::GetHMACForMediaDeviceID(request.security_origin, | |
650 device->id); | |
651 } | |
652 } | |
653 | |
654 bool MediaStreamManager::TranslateSourceIdToDeviceId( | |
655 MediaStreamType stream_type, | |
656 const GURL& security_origin, | |
657 const std::string& source_id, | |
658 std::string* device_id) { | |
637 DCHECK(stream_type == MEDIA_DEVICE_AUDIO_CAPTURE || | 659 DCHECK(stream_type == MEDIA_DEVICE_AUDIO_CAPTURE || |
638 stream_type == MEDIA_DEVICE_VIDEO_CAPTURE); | 660 stream_type == MEDIA_DEVICE_VIDEO_CAPTURE); |
639 if (device_guid.empty()) | 661 DCHECK(!source_id.empty()); |
640 return false; | |
641 | 662 |
642 EnumerationCache* cache = | 663 EnumerationCache* cache = |
643 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? | 664 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? |
644 &audio_enumeration_cache_ : &video_enumeration_cache_; | 665 &audio_enumeration_cache_ : &video_enumeration_cache_; |
645 | 666 |
646 // If device monitoring hasn't started, the |device_guid| is not valid. | 667 // If device monitoring hasn't started, the |device_guid| is not valid. |
647 if (!cache->valid) | 668 if (!cache->valid) |
648 return false; | 669 return false; |
649 | 670 |
650 for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); | 671 for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); |
651 it != cache->devices.end(); | 672 it != cache->devices.end(); |
652 ++it) { | 673 ++it) { |
653 if (content::DoesMediaDeviceIDMatchHMAC( | 674 if (content::DoesMediaDeviceIDMatchHMAC(security_origin, source_id, |
654 security_origin, device_guid, it->device.id)) { | 675 it->device.id)) { |
655 *raw_device_id = it->device.id; | 676 *device_id = it->device.id; |
656 return true; | 677 return true; |
657 } | 678 } |
658 } | 679 } |
659 return false; | 680 return false; |
660 } | 681 } |
661 | 682 |
662 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { | 683 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { |
663 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 684 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
664 cache->valid = false; | 685 cache->valid = false; |
665 } | 686 } |
(...skipping 27 matching lines...) Expand all Loading... | |
693 std::string unique_label; | 714 std::string unique_label; |
694 do { | 715 do { |
695 unique_label = RandomLabel(); | 716 unique_label = RandomLabel(); |
696 } while (requests_.find(unique_label) != requests_.end()); | 717 } while (requests_.find(unique_label) != requests_.end()); |
697 | 718 |
698 requests_.insert(std::make_pair(unique_label, request)); | 719 requests_.insert(std::make_pair(unique_label, request)); |
699 | 720 |
700 return unique_label; | 721 return unique_label; |
701 } | 722 } |
702 | 723 |
703 void MediaStreamManager::RemoveRequest(DeviceRequests::iterator it) { | 724 MediaStreamManager::DeviceRequest* |
725 MediaStreamManager::FindRequest(const std::string& label) const { | |
726 DeviceRequests::const_iterator request_it = requests_.find(label); | |
727 return request_it == requests_.end() ? NULL : request_it->second; | |
728 } | |
729 | |
730 void MediaStreamManager::DeleteRequest(const std::string& label) { | |
731 DeviceRequests::iterator it = requests_.find(label); | |
732 scoped_ptr<DeviceRequest> request(it->second); | |
704 requests_.erase(it); | 733 requests_.erase(it); |
705 } | 734 } |
706 | 735 |
707 void MediaStreamManager::PostRequestToUI(const std::string& label) { | 736 void MediaStreamManager::PostRequestToUI(const std::string& label, |
737 DeviceRequest* request) { | |
708 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
709 DeviceRequest* request = requests_[label]; | 739 DVLOG(1) << "PostRequestToUI({label= " << label << "})"; |
740 // If a specific device has been requested we need to find the real device id. | |
741 if (!TranslateRequestedSourceIdToDeviceId(&request->request)) { | |
742 FinalizeRequestFailed(label, request); | |
743 return; | |
744 } | |
745 | |
746 const MediaStreamType audio_type = request->request.audio_type; | |
747 const MediaStreamType video_type = request->request.video_type; | |
748 | |
749 // Post the request to UI and set the state. | |
750 if (IsAudioMediaType(audio_type)) | |
751 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | |
752 if (IsVideoMediaType(video_type)) | |
753 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | |
710 | 754 |
711 if (use_fake_ui_) { | 755 if (use_fake_ui_) { |
712 if (!fake_ui_) | 756 if (!fake_ui_) |
713 fake_ui_.reset(new FakeMediaStreamUIProxy()); | 757 fake_ui_.reset(new FakeMediaStreamUIProxy()); |
714 | 758 |
715 MediaStreamDevices devices; | 759 MediaStreamDevices devices; |
716 if (audio_enumeration_cache_.valid) { | 760 if (audio_enumeration_cache_.valid) { |
717 for (StreamDeviceInfoArray::const_iterator it = | 761 for (StreamDeviceInfoArray::const_iterator it = |
718 audio_enumeration_cache_.devices.begin(); | 762 audio_enumeration_cache_.devices.begin(); |
719 it != audio_enumeration_cache_.devices.end(); ++it) { | 763 it != audio_enumeration_cache_.devices.end(); ++it) { |
(...skipping 14 matching lines...) Expand all Loading... | |
734 } else { | 778 } else { |
735 request->ui_proxy = MediaStreamUIProxy::Create(); | 779 request->ui_proxy = MediaStreamUIProxy::Create(); |
736 } | 780 } |
737 | 781 |
738 request->ui_proxy->RequestAccess( | 782 request->ui_proxy->RequestAccess( |
739 request->request, | 783 request->request, |
740 base::Bind(&MediaStreamManager::HandleAccessRequestResponse, | 784 base::Bind(&MediaStreamManager::HandleAccessRequestResponse, |
741 base::Unretained(this), label)); | 785 base::Unretained(this), label)); |
742 } | 786 } |
743 | 787 |
744 void MediaStreamManager::HandleRequest(const std::string& label) { | 788 void MediaStreamManager::SetupRequest(const std::string& label) { |
745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
746 DeviceRequest* request = requests_[label]; | 790 DeviceRequest* request = FindRequest(label); |
791 if (!request) { | |
792 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!"; | |
793 return; // This can happen if the request has been canceled. | |
794 } | |
795 | |
796 if (!request->request.security_origin.is_valid()) { | |
797 LOG(ERROR) << "Invalid security origin. " | |
798 << request->request.security_origin; | |
799 FinalizeRequestFailed(label, request); | |
800 return; | |
801 } | |
747 | 802 |
748 const MediaStreamType audio_type = request->request.audio_type; | 803 const MediaStreamType audio_type = request->request.audio_type; |
749 const MediaStreamType video_type = request->request.video_type; | 804 const MediaStreamType video_type = request->request.video_type; |
750 | 805 |
751 bool is_web_contents_capture = | 806 bool is_web_contents_capture = |
752 audio_type == MEDIA_TAB_AUDIO_CAPTURE || | 807 audio_type == MEDIA_TAB_AUDIO_CAPTURE || |
753 video_type == MEDIA_TAB_VIDEO_CAPTURE; | 808 video_type == MEDIA_TAB_VIDEO_CAPTURE; |
809 if (is_web_contents_capture && !SetupTabCaptureRequest(request)) { | |
810 FinalizeRequestFailed(label, request); | |
811 return; | |
812 } | |
754 | 813 |
755 bool is_screen_capture = | 814 bool is_screen_capture = |
756 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; | 815 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; |
816 if (is_screen_capture && !SetupScreenCaptureRequest(request)) { | |
817 FinalizeRequestFailed(label, request); | |
818 return; | |
819 } | |
757 | 820 |
758 if (!is_web_contents_capture && | 821 if (!is_web_contents_capture && |
759 !is_screen_capture && | 822 !is_screen_capture && |
760 ((IsAudioMediaType(audio_type) && !audio_enumeration_cache_.valid) || | 823 ((IsAudioMediaType(audio_type) && !audio_enumeration_cache_.valid) || |
761 (IsVideoMediaType(video_type) && !video_enumeration_cache_.valid))) { | 824 (IsVideoMediaType(video_type) && !video_enumeration_cache_.valid))) { |
762 // Enumerate the devices if there is no valid device lists to be used. | 825 // Enumerate the devices if there is no valid device lists to be used. |
763 StartEnumeration(request); | 826 StartEnumeration(request); |
764 return; | 827 return; |
765 } | 828 } |
829 PostRequestToUI(label, request); | |
830 } | |
766 | 831 |
767 // No need to do new device enumerations, post the request to UI | 832 bool MediaStreamManager::SetupTabCaptureRequest(DeviceRequest* request) { |
768 // immediately. | 833 DCHECK(request->request.audio_type == MEDIA_TAB_AUDIO_CAPTURE || |
769 if (IsAudioMediaType(audio_type)) | 834 request->request.video_type == MEDIA_TAB_VIDEO_CAPTURE); |
770 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | |
771 if (IsVideoMediaType(video_type)) | |
772 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | |
773 | 835 |
774 PostRequestToUI(label); | 836 MediaStreamRequest* ms_request = &request->request; |
837 // Customize options for a WebContents based capture. | |
838 int target_render_process_id = 0; | |
839 int target_render_view_id = 0; | |
840 | |
841 // TODO(justinlin): Can't plumb audio mirroring using stream type right | |
842 // now, so plumbing by device_id. Will revisit once it's refactored. | |
843 // http://crbug.com/163100 | |
844 std::string tab_capture_device_id = | |
845 WebContentsCaptureUtil::AppendWebContentsDeviceScheme( | |
846 !ms_request->requested_video_device_id.empty() ? | |
847 ms_request->requested_video_device_id : | |
848 ms_request->requested_audio_device_id); | |
849 | |
850 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
851 tab_capture_device_id, &target_render_process_id, | |
852 &target_render_view_id); | |
853 if (!has_valid_device_id || | |
854 (ms_request->audio_type != MEDIA_TAB_AUDIO_CAPTURE && | |
855 ms_request->audio_type != MEDIA_NO_SERVICE) || | |
856 (ms_request->video_type != MEDIA_TAB_VIDEO_CAPTURE && | |
857 ms_request->video_type != MEDIA_NO_SERVICE)) { | |
858 return false; | |
859 } | |
860 ms_request->tab_capture_device_id = tab_capture_device_id; | |
861 ms_request->render_process_id = target_render_process_id; | |
862 ms_request->render_view_id = target_render_view_id; | |
863 DVLOG(3) << "SetupTabCaptureRequest " | |
864 << ", {tab_capture_device_id = " << tab_capture_device_id << "}" | |
865 << ", {target_render_process_id = " << target_render_process_id | |
866 << "}" | |
867 << ", {target_render_view_id = " << target_render_view_id << "}"; | |
868 return true; | |
869 } | |
870 | |
871 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) { | |
872 DCHECK(request->request.audio_type == MEDIA_LOOPBACK_AUDIO_CAPTURE || | |
873 request->request.video_type == MEDIA_DESKTOP_VIDEO_CAPTURE); | |
874 const MediaStreamRequest& ms_request = request->request; | |
875 | |
876 // For screen capture we only support two valid combinations: | |
877 // (1) screen video capture only, or | |
878 // (2) screen video capture with loopback audio capture. | |
879 if (ms_request.video_type != MEDIA_DESKTOP_VIDEO_CAPTURE || | |
880 (ms_request.audio_type != MEDIA_NO_SERVICE && | |
881 ms_request.audio_type != MEDIA_LOOPBACK_AUDIO_CAPTURE)) { | |
882 // TODO(sergeyu): Surface error message to the calling JS code. | |
883 LOG(ERROR) << "Invalid screen capture request."; | |
884 return false; | |
885 } | |
886 return true; | |
887 } | |
888 | |
889 StreamDeviceInfoArray MediaStreamManager::GetDevicesOpenedByRequest( | |
890 const std::string& label) const { | |
891 DeviceRequest* request = FindRequest(label); | |
892 if (!request) | |
893 return StreamDeviceInfoArray(); | |
894 return request->devices; | |
775 } | 895 } |
776 | 896 |
777 bool MediaStreamManager::FindExistingRequestedDeviceInfo( | 897 bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
778 int render_process_id, | 898 int render_process_id, |
779 int render_view_id, | 899 int render_view_id, |
900 const GURL& security_origin, | |
780 MediaStreamRequestType type, | 901 MediaStreamRequestType type, |
781 const std::string& device_id, | 902 const std::string& device_id, |
903 MediaStreamType device_type, | |
782 StreamDeviceInfo* device_info, | 904 StreamDeviceInfo* device_info, |
783 MediaRequestState* request_state) const { | 905 MediaRequestState* request_state) const { |
784 DCHECK(device_info); | 906 DCHECK(device_info); |
785 DCHECK(request_state); | 907 DCHECK(request_state); |
908 | |
909 std::string source_id = content::GetHMACForMediaDeviceID( | |
910 security_origin, | |
911 device_id); | |
912 | |
786 for (DeviceRequests::const_iterator it = requests_.begin(); | 913 for (DeviceRequests::const_iterator it = requests_.begin(); |
787 it != requests_.end() ; ++it) { | 914 it != requests_.end() ; ++it) { |
788 const DeviceRequest* request = it->second; | 915 const DeviceRequest* request = it->second; |
789 if (request->requesting_process_id ==render_process_id && | 916 if (request->requesting_process_id == render_process_id && |
790 request->requesting_view_id == render_view_id && | 917 request->requesting_view_id == render_view_id && |
791 request->request.request_type == type) { | 918 request->request.request_type == type) { |
792 for (StreamDeviceInfoArray::const_iterator device_it = | 919 for (StreamDeviceInfoArray::const_iterator device_it = |
793 request->devices.begin(); | 920 request->devices.begin(); |
794 device_it != request->devices.end(); ++device_it) { | 921 device_it != request->devices.end(); ++device_it) { |
795 if (device_it->device.id == device_id) { | 922 if (device_it->device.id == source_id && |
923 device_it->device.type == device_type) { | |
796 *device_info = *device_it; | 924 *device_info = *device_it; |
tommi (sloooow) - chröme
2013/11/27 22:09:43
fix indent
perkj_chrome
2013/11/28 09:46:43
Done.
| |
797 *request_state = request->state(device_it->device.type); | 925 *request_state = request->state(device_it->device.type); |
798 return true; | 926 return true; |
799 } | 927 } |
800 } | 928 } |
801 } | 929 } |
802 } | 930 } |
803 return false; | 931 return false; |
804 } | 932 } |
805 | 933 |
934 void MediaStreamManager::FinalizeGenerateStream(const std::string& label, | |
935 DeviceRequest* request) { | |
936 DVLOG(1) << "FinalizeGenerateStream label " << label; | |
937 const StreamDeviceInfoArray& requested_devices = request->devices; | |
938 | |
939 // Partition the array of devices into audio vs video. | |
940 StreamDeviceInfoArray audio_devices, video_devices; | |
941 for (StreamDeviceInfoArray::const_iterator device_it = | |
942 requested_devices.begin(); | |
943 device_it != requested_devices.end(); ++device_it) { | |
944 if (IsAudioMediaType(device_it->device.type)) { | |
945 audio_devices.push_back(*device_it); | |
946 } else if (IsVideoMediaType(device_it->device.type)) { | |
947 video_devices.push_back(*device_it); | |
948 } else { | |
949 NOTREACHED(); | |
950 } | |
951 } | |
952 | |
953 request->requester->StreamGenerated(label, audio_devices, video_devices); | |
954 } | |
955 | |
956 void MediaStreamManager::FinalizeRequestFailed( | |
957 const std::string& label, | |
958 DeviceRequest* request) { | |
959 if (request->requester) | |
960 request->requester->StreamGenerationFailed(label); | |
961 | |
962 if (request->request.request_type == MEDIA_DEVICE_ACCESS && | |
963 !request->callback.is_null()) { | |
964 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); | |
965 } | |
966 | |
967 DeleteRequest(label); | |
968 } | |
969 | |
970 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, | |
971 DeviceRequest* request) { | |
972 const StreamDeviceInfoArray& requested_devices = request->devices; | |
973 request->requester->DeviceOpened(label, requested_devices.front()); | |
974 } | |
975 | |
976 void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label, | |
977 DeviceRequest* request) { | |
978 if (!request->request.security_origin.is_valid()) { | |
979 request->requester->DevicesEnumerated(label, StreamDeviceInfoArray()); | |
980 return; | |
981 } | |
982 for (StreamDeviceInfoArray::iterator it = request->devices.begin(); | |
983 it != request->devices.end(); ++it) { | |
984 TranslateDeviceIdToSourceId(request->request, &it->device); | |
985 } | |
986 request->requester->DevicesEnumerated(label, request->devices); | |
987 } | |
988 | |
989 void MediaStreamManager::FinalizeMediaAccessRequest( | |
990 const std::string& label, | |
991 DeviceRequest* request, | |
992 const MediaStreamDevices& devices) { | |
993 if (!request->callback.is_null()) | |
994 request->callback.Run(devices, request->ui_proxy.Pass()); | |
995 | |
996 // Delete the request since it is done. | |
997 DeleteRequest(label); | |
998 } | |
999 | |
806 void MediaStreamManager::InitializeDeviceManagersOnIOThread() { | 1000 void MediaStreamManager::InitializeDeviceManagersOnIOThread() { |
807 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1001 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
808 if (device_thread_) | 1002 if (device_thread_) |
809 return; | 1003 return; |
810 | 1004 |
811 device_thread_.reset(new base::Thread("MediaStreamDeviceThread")); | 1005 device_thread_.reset(new base::Thread("MediaStreamDeviceThread")); |
812 #if defined(OS_WIN) | 1006 #if defined(OS_WIN) |
813 device_thread_->init_com_with_mta(true); | 1007 device_thread_->init_com_with_mta(true); |
814 #endif | 1008 #endif |
815 CHECK(device_thread_->Start()); | 1009 CHECK(device_thread_->Start()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
851 request->SetState(device_it->device.type, MEDIA_REQUEST_STATE_DONE); | 1045 request->SetState(device_it->device.type, MEDIA_REQUEST_STATE_DONE); |
852 | 1046 |
853 if (IsAudioMediaType(device_it->device.type)) { | 1047 if (IsAudioMediaType(device_it->device.type)) { |
854 // Store the native audio parameters in the device struct. | 1048 // Store the native audio parameters in the device struct. |
855 // TODO(xians): Handle the tab capture sample rate/channel layout | 1049 // TODO(xians): Handle the tab capture sample rate/channel layout |
856 // in AudioInputDeviceManager::Open(). | 1050 // in AudioInputDeviceManager::Open(). |
857 if (device_it->device.type != content::MEDIA_TAB_AUDIO_CAPTURE) { | 1051 if (device_it->device.type != content::MEDIA_TAB_AUDIO_CAPTURE) { |
858 const StreamDeviceInfo* info = | 1052 const StreamDeviceInfo* info = |
859 audio_input_device_manager_->GetOpenedDeviceInfoById( | 1053 audio_input_device_manager_->GetOpenedDeviceInfoById( |
860 device_it->session_id); | 1054 device_it->session_id); |
861 DCHECK_EQ(info->device.id, device_it->device.id); | |
862 device_it->device.input = info->device.input; | 1055 device_it->device.input = info->device.input; |
863 device_it->device.matched_output = info->device.matched_output; | 1056 device_it->device.matched_output = info->device.matched_output; |
864 } | 1057 } |
865 } | 1058 } |
866 if (RequestDone(*request)) | 1059 if (RequestDone(*request)) |
867 HandleRequestDone(label, request); | 1060 HandleRequestDone(label, request); |
868 break; | 1061 break; |
869 } | 1062 } |
870 } | 1063 } |
871 } | 1064 } |
872 } | 1065 } |
873 | 1066 |
874 void MediaStreamManager::HandleRequestDone(const std::string& label, | 1067 void MediaStreamManager::HandleRequestDone(const std::string& label, |
875 DeviceRequest* request) { | 1068 DeviceRequest* request) { |
876 DCHECK(RequestDone(*request)); | 1069 DCHECK(RequestDone(*request)); |
877 DVLOG(1) << "HandleRequestDone(" | 1070 DVLOG(1) << "HandleRequestDone(" |
878 << ", {label = " << label << "})"; | 1071 << ", {label = " << label << "})"; |
879 | 1072 |
880 const StreamDeviceInfoArray& requested_devices = request->devices; | |
881 switch (request->request.request_type) { | 1073 switch (request->request.request_type) { |
882 case MEDIA_OPEN_DEVICE: | 1074 case MEDIA_OPEN_DEVICE: |
883 request->requester->DeviceOpened(label, requested_devices.front()); | 1075 FinalizeOpenDevice(label, request); |
884 break; | 1076 break; |
885 case MEDIA_GENERATE_STREAM: { | 1077 case MEDIA_GENERATE_STREAM: { |
886 // Partition the array of devices into audio vs video. | 1078 FinalizeGenerateStream(label, request); |
887 StreamDeviceInfoArray audio_devices, video_devices; | |
888 for (StreamDeviceInfoArray::const_iterator device_it = | |
889 requested_devices.begin(); | |
890 device_it != requested_devices.end(); ++device_it) { | |
891 if (IsAudioMediaType(device_it->device.type)) { | |
892 audio_devices.push_back(*device_it); | |
893 } else if (IsVideoMediaType(device_it->device.type)) { | |
894 video_devices.push_back(*device_it); | |
895 } else { | |
896 NOTREACHED(); | |
897 } | |
898 } | |
899 | |
900 request->requester->StreamGenerated(label, audio_devices, video_devices); | |
901 break; | 1079 break; |
902 } | 1080 } |
903 default: | 1081 default: |
904 NOTREACHED(); | 1082 NOTREACHED(); |
905 break; | 1083 break; |
906 } | 1084 } |
907 | 1085 |
908 if (request->ui_proxy.get()) { | 1086 if (request->ui_proxy.get()) { |
909 request->ui_proxy->OnStarted( | 1087 request->ui_proxy->OnStarted( |
910 base::Bind(&MediaStreamManager::StopMediaStreamFromBrowser, | 1088 base::Bind(&MediaStreamManager::StopMediaStreamFromBrowser, |
(...skipping 22 matching lines...) Expand all Loading... | |
933 !std::equal(devices.begin(), devices.end(), cache->devices.begin(), | 1111 !std::equal(devices.begin(), devices.end(), cache->devices.begin(), |
934 StreamDeviceInfo::IsEqual)) { | 1112 StreamDeviceInfo::IsEqual)) { |
935 StopRemovedDevices(cache->devices, devices); | 1113 StopRemovedDevices(cache->devices, devices); |
936 cache->devices = devices; | 1114 cache->devices = devices; |
937 need_update_clients = true; | 1115 need_update_clients = true; |
938 | 1116 |
939 // The device might not be able to be enumerated when it is not warmed up, | 1117 // The device might not be able to be enumerated when it is not warmed up, |
940 // for example, when the machine just wakes up from sleep. We set the cache | 1118 // for example, when the machine just wakes up from sleep. We set the cache |
941 // to be invalid so that the next media request will trigger the | 1119 // to be invalid so that the next media request will trigger the |
942 // enumeration again. See issue/317673. | 1120 // enumeration again. See issue/317673. |
943 if (devices.size()) | 1121 cache->valid = !devices.empty(); |
944 cache->valid = true; | |
945 else | |
946 cache->valid = false; | |
947 } | 1122 } |
948 | 1123 |
949 if (need_update_clients && monitoring_started_) | 1124 if (need_update_clients && monitoring_started_) |
950 NotifyDevicesChanged(stream_type, devices); | 1125 NotifyDevicesChanged(stream_type, devices); |
951 | 1126 |
952 // Publish the result for all requests waiting for device list(s). | 1127 // Publish the result for all requests waiting for device list(s). |
953 // Find the requests waiting for this device list, store their labels and | 1128 // Find the requests waiting for this device list, store their labels and |
954 // release the iterator before calling device settings. We might get a call | 1129 // release the iterator before calling device settings. We might get a call |
955 // back from device_settings that will need to iterate through devices. | 1130 // back from device_settings that will need to iterate through devices. |
956 std::list<std::string> label_list; | 1131 std::list<std::string> label_list; |
957 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); | 1132 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); |
958 ++it) { | 1133 ++it) { |
959 if (it->second->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && | 1134 if (it->second->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && |
960 Requested(it->second->request, stream_type)) { | 1135 Requested(it->second->request, stream_type)) { |
961 if (it->second->request.request_type != MEDIA_ENUMERATE_DEVICES) | 1136 if (it->second->request.request_type != MEDIA_ENUMERATE_DEVICES) |
962 it->second->SetState(stream_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 1137 it->second->SetState(stream_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
963 label_list.push_back(it->first); | 1138 label_list.push_back(it->first); |
964 } | 1139 } |
965 } | 1140 } |
966 for (std::list<std::string>::iterator it = label_list.begin(); | 1141 for (std::list<std::string>::iterator it = label_list.begin(); |
967 it != label_list.end(); ++it) { | 1142 it != label_list.end(); ++it) { |
968 DeviceRequest* request = requests_[*it]; | 1143 DeviceRequest* request = FindRequest(*it); |
969 switch (request->request.request_type) { | 1144 switch (request->request.request_type) { |
970 case MEDIA_ENUMERATE_DEVICES: | 1145 case MEDIA_ENUMERATE_DEVICES: |
971 if (need_update_clients && request->requester) | 1146 if (need_update_clients && request->requester) { |
972 request->requester->DevicesEnumerated(*it, devices); | 1147 request->devices = devices; |
1148 FinalizeEnumerateDevices(*it, request); | |
1149 } | |
973 break; | 1150 break; |
974 default: | 1151 default: |
975 if (request->state(request->request.audio_type) == | 1152 if (request->state(request->request.audio_type) == |
976 MEDIA_REQUEST_STATE_REQUESTED || | 1153 MEDIA_REQUEST_STATE_REQUESTED || |
977 request->state(request->request.video_type) == | 1154 request->state(request->request.video_type) == |
978 MEDIA_REQUEST_STATE_REQUESTED) { | 1155 MEDIA_REQUEST_STATE_REQUESTED) { |
979 // We are doing enumeration for other type of media, wait until it is | 1156 // We are doing enumeration for other type of media, wait until it is |
980 // all done before posting the request to UI because UI needs | 1157 // all done before posting the request to UI because UI needs |
981 // the device lists to handle the request. | 1158 // the device lists to handle the request. |
982 break; | 1159 break; |
983 } | 1160 } |
984 | 1161 |
985 // Post the request to UI for permission approval. | 1162 PostRequestToUI(*it, request); |
986 PostRequestToUI(*it); | |
987 break; | 1163 break; |
988 } | 1164 } |
989 } | 1165 } |
990 label_list.clear(); | 1166 label_list.clear(); |
991 --active_enumeration_ref_count_[stream_type]; | 1167 --active_enumeration_ref_count_[stream_type]; |
992 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); | 1168 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); |
993 } | 1169 } |
994 | 1170 |
995 void MediaStreamManager::HandleAccessRequestResponse( | 1171 void MediaStreamManager::HandleAccessRequestResponse( |
996 const std::string& label, | 1172 const std::string& label, |
997 const MediaStreamDevices& devices) { | 1173 const MediaStreamDevices& devices) { |
998 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
999 DVLOG(1) << "HandleAccessRequestResponse(" | 1175 DVLOG(1) << "HandleAccessRequestResponse(" |
1000 << ", {label = " << label << "})"; | 1176 << ", {label = " << label << "})"; |
1001 | 1177 |
1002 DeviceRequests::iterator request_it = requests_.find(label); | 1178 DeviceRequest* request = FindRequest(label); |
1003 if (request_it == requests_.end()) { | 1179 if (!request) { |
1180 // The request has been canceled before the UI returned. | |
1181 return; | |
1182 } | |
1183 | |
1184 if (request->request.request_type == MEDIA_DEVICE_ACCESS) { | |
1185 FinalizeMediaAccessRequest(label, request, devices); | |
1004 return; | 1186 return; |
1005 } | 1187 } |
1006 | 1188 |
1007 // Handle the case when the request was denied. | 1189 // Handle the case when the request was denied. |
1008 if (devices.empty()) { | 1190 if (devices.empty()) { |
1009 // Notify the users about the request result. | 1191 FinalizeRequestFailed(label, request); |
1010 scoped_ptr<DeviceRequest> request(request_it->second); | |
1011 if (request->requester) | |
1012 request->requester->StreamGenerationFailed(label); | |
1013 | |
1014 if (request->request.request_type == MEDIA_DEVICE_ACCESS && | |
1015 !request->callback.is_null()) { | |
1016 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); | |
1017 } | |
1018 | |
1019 RemoveRequest(request_it); | |
1020 return; | |
1021 } | |
1022 | |
1023 if (request_it->second->request.request_type == MEDIA_DEVICE_ACCESS) { | |
1024 scoped_ptr<DeviceRequest> request(request_it->second); | |
1025 if (!request->callback.is_null()) | |
1026 request->callback.Run(devices, request->ui_proxy.Pass()); | |
1027 | |
1028 // Delete the request since it is done. | |
1029 RemoveRequest(request_it); | |
1030 return; | 1192 return; |
1031 } | 1193 } |
1032 | 1194 |
1033 // Process all newly-accepted devices for this request. | 1195 // Process all newly-accepted devices for this request. |
1034 DeviceRequest* request = request_it->second; | |
1035 bool found_audio = false; | 1196 bool found_audio = false; |
1036 bool found_video = false; | 1197 bool found_video = false; |
1037 for (MediaStreamDevices::const_iterator device_it = devices.begin(); | 1198 for (MediaStreamDevices::const_iterator device_it = devices.begin(); |
1038 device_it != devices.end(); ++device_it) { | 1199 device_it != devices.end(); ++device_it) { |
1039 StreamDeviceInfo device_info; | 1200 StreamDeviceInfo device_info; |
1040 device_info.device = *device_it; | 1201 device_info.device = *device_it; |
1041 | 1202 |
1042 // TODO(justinlin): Nicer way to do this? | 1203 // TODO(justinlin): Nicer way to do this? |
1043 // Re-append the device's id since we lost it when posting request to UI. | 1204 // Re-append the device's id since we lost it when posting request to UI. |
1044 if (device_info.device.type == content::MEDIA_TAB_VIDEO_CAPTURE || | 1205 if (device_info.device.type == content::MEDIA_TAB_VIDEO_CAPTURE || |
(...skipping 20 matching lines...) Expand all Loading... | |
1065 if (device_info.device.type == request->request.audio_type) { | 1226 if (device_info.device.type == request->request.audio_type) { |
1066 found_audio = true; | 1227 found_audio = true; |
1067 } else if (device_info.device.type == request->request.video_type) { | 1228 } else if (device_info.device.type == request->request.video_type) { |
1068 found_video = true; | 1229 found_video = true; |
1069 } | 1230 } |
1070 | 1231 |
1071 // If this is request for a new MediaStream, a device is only opened once | 1232 // If this is request for a new MediaStream, a device is only opened once |
1072 // per render view. This is so that the permission to use a device can be | 1233 // per render view. This is so that the permission to use a device can be |
1073 // revoked by a single call to StopStreamDevice regardless of how many | 1234 // revoked by a single call to StopStreamDevice regardless of how many |
1074 // MediaStreams it is being used in. | 1235 // MediaStreams it is being used in. |
1075 | |
1076 if (request->request.request_type == MEDIA_GENERATE_STREAM) { | 1236 if (request->request.request_type == MEDIA_GENERATE_STREAM) { |
1077 MediaRequestState state; | 1237 MediaRequestState state; |
1078 if (FindExistingRequestedDeviceInfo(request->requesting_process_id, | 1238 if (FindExistingRequestedDeviceInfo(request->requesting_process_id, |
1079 request->requesting_view_id, | 1239 request->requesting_view_id, |
1240 request->request.security_origin, | |
1080 request->request.request_type, | 1241 request->request.request_type, |
1081 device_it->id, | 1242 device_info.device.id, |
1243 device_info.device.type, | |
1082 &device_info, | 1244 &device_info, |
1083 &state)) { | 1245 &state)) { |
1084 request->devices.push_back(device_info); | 1246 request->devices.push_back(device_info); |
1085 request->SetState(device_info.device.type, state); | 1247 request->SetState(device_info.device.type, state); |
1086 DVLOG(1) << "HandleAccessRequestResponse - device already opened " | 1248 DVLOG(1) << "HandleAccessRequestResponse - device already opened " |
1087 << ", {label = " << label << "}" | 1249 << ", {label = " << label << "}" |
1088 << ", device_id = " << device_it->id << "}"; | 1250 << ", device_id = " << device_it->id << "}"; |
1089 continue; | 1251 continue; |
1090 } | 1252 } |
1091 } | 1253 } |
1092 device_info.session_id = | 1254 device_info.session_id = |
1093 GetDeviceManager(device_info.device.type)->Open(device_info); | 1255 GetDeviceManager(device_info.device.type)->Open(device_info); |
1256 TranslateDeviceIdToSourceId(request->request, &device_info.device); | |
1094 request->devices.push_back(device_info); | 1257 request->devices.push_back(device_info); |
1258 | |
1095 request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); | 1259 request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); |
1096 DVLOG(1) << "HandleAccessRequestResponse - opening device " | 1260 DVLOG(1) << "HandleAccessRequestResponse - opening device " |
1097 << ", {label = " << label << "}" | 1261 << ", {label = " << label << "}" |
1098 << ", {device_id = " << device_it->id << "}" | 1262 << ", {device_id = " << device_info.device.id << "}" |
1099 << ", {session_id = " << device_info.session_id << "}"; | 1263 << ", {session_id = " << device_info.session_id << "}"; |
1100 } | 1264 } |
1101 | 1265 |
1102 // Check whether we've received all stream types requested. | 1266 // Check whether we've received all stream types requested. |
1103 if (!found_audio && IsAudioMediaType(request->request.audio_type)) { | 1267 if (!found_audio && IsAudioMediaType(request->request.audio_type)) { |
1104 request->SetState(request->request.audio_type, MEDIA_REQUEST_STATE_ERROR); | 1268 request->SetState(request->request.audio_type, MEDIA_REQUEST_STATE_ERROR); |
1105 DVLOG(1) << "Set no audio found label " << label; | 1269 DVLOG(1) << "Set no audio found label " << label; |
1106 } | 1270 } |
1107 | 1271 |
1108 if (!found_video && IsVideoMediaType(request->request.video_type)) | 1272 if (!found_video && IsVideoMediaType(request->request.video_type)) |
1109 request->SetState(request->request.video_type, MEDIA_REQUEST_STATE_ERROR); | 1273 request->SetState(request->request.video_type, MEDIA_REQUEST_STATE_ERROR); |
1110 | 1274 |
1111 if (RequestDone(*request)) | 1275 if (RequestDone(*request)) |
1112 HandleRequestDone(label, request); | 1276 HandleRequestDone(label, request); |
1113 } | 1277 } |
1114 | 1278 |
1115 void MediaStreamManager::StopMediaStreamFromBrowser(const std::string& label) { | 1279 void MediaStreamManager::StopMediaStreamFromBrowser(const std::string& label) { |
1116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1117 | 1281 |
1118 DeviceRequests::iterator it = requests_.find(label); | 1282 DeviceRequest* request = FindRequest(label); |
1119 if (it == requests_.end()) | 1283 if (!request) |
1120 return; | 1284 return; |
1121 | 1285 |
1122 DeviceRequest* request = it->second; | |
1123 // Notify renderers that the devices in the stream will be stopped. | 1286 // Notify renderers that the devices in the stream will be stopped. |
1124 if (request->requester) { | 1287 if (request->requester) { |
1125 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); | 1288 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); |
1126 device_it != request->devices.end(); ++device_it) { | 1289 device_it != request->devices.end(); ++device_it) { |
1127 request->requester->DeviceStopped(request->requesting_view_id, | 1290 request->requester->DeviceStopped(request->requesting_view_id, |
1128 label, | 1291 label, |
1129 *device_it); | 1292 *device_it); |
1130 } | 1293 } |
1131 } | 1294 } |
1132 | 1295 |
1133 CancelRequest(label); | 1296 CancelRequest(label); |
1134 } | 1297 } |
1135 | 1298 |
1136 void MediaStreamManager::UseFakeDevice() { | 1299 void MediaStreamManager::UseFakeDevice() { |
1137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1138 video_capture_manager()->UseFakeDevice(); | 1301 video_capture_manager()->UseFakeDevice(); |
1139 audio_input_device_manager()->UseFakeDevice(); | 1302 audio_input_device_manager()->UseFakeDevice(); |
1140 } | 1303 } |
1141 | 1304 |
1142 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { | 1305 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { |
1143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1144 use_fake_ui_ = true; | 1307 use_fake_ui_ = true; |
1145 fake_ui_ = fake_ui.Pass(); | 1308 fake_ui_ = fake_ui.Pass(); |
1146 } | 1309 } |
1147 | 1310 |
1148 void MediaStreamManager::WillDestroyCurrentMessageLoop() { | 1311 void MediaStreamManager::WillDestroyCurrentMessageLoop() { |
1312 DVLOG(3) << "MediaStreamManager::WillDestroyCurrentMessageLoop()"; | |
1149 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 1313 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
1150 DCHECK(requests_.empty()); | 1314 DCHECK(requests_.empty()); |
1151 if (device_thread_) { | 1315 if (device_thread_) { |
1152 StopMonitoring(); | 1316 StopMonitoring(); |
1153 | 1317 |
1154 video_capture_manager_->Unregister(); | 1318 video_capture_manager_->Unregister(); |
1155 audio_input_device_manager_->Unregister(); | 1319 audio_input_device_manager_->Unregister(); |
1156 device_thread_.reset(); | 1320 device_thread_.reset(); |
1157 } | 1321 } |
1158 | 1322 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1240 } | 1404 } |
1241 | 1405 |
1242 // Always do enumeration even though some enumeration is in progress, | 1406 // Always do enumeration even though some enumeration is in progress, |
1243 // because those enumeration commands could be sent before these devices | 1407 // because those enumeration commands could be sent before these devices |
1244 // change. | 1408 // change. |
1245 ++active_enumeration_ref_count_[stream_type]; | 1409 ++active_enumeration_ref_count_[stream_type]; |
1246 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1410 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
1247 } | 1411 } |
1248 | 1412 |
1249 } // namespace content | 1413 } // namespace content |
OLD | NEW |