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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return label; | 57 return label; |
58 } | 58 } |
59 | 59 |
60 // 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. |
61 static bool Requested(const MediaStreamRequest& request, | 61 static bool Requested(const MediaStreamRequest& request, |
62 MediaStreamType stream_type) { | 62 MediaStreamType stream_type) { |
63 return (request.audio_type == stream_type || | 63 return (request.audio_type == stream_type || |
64 request.video_type == stream_type); | 64 request.video_type == stream_type); |
65 } | 65 } |
66 | 66 |
67 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. | |
68 class MediaStreamManager::DeviceRequest { | 67 class MediaStreamManager::DeviceRequest { |
69 public: | 68 public: |
70 DeviceRequest(MediaStreamRequester* requester, | 69 DeviceRequest(MediaStreamRequester* requester, |
71 const MediaStreamRequest& request, | 70 const MediaStreamRequest& request, |
72 int requesting_process_id, | 71 int requesting_process_id, |
73 int requesting_view_id) | 72 int requesting_view_id, |
| 73 ResourceContext* resource_context) |
74 : requester(requester), | 74 : requester(requester), |
75 request(request), | 75 request(request), |
76 requesting_process_id(requesting_process_id), | 76 requesting_process_id(requesting_process_id), |
77 requesting_view_id(requesting_view_id), | 77 requesting_view_id(requesting_view_id), |
| 78 resource_context(resource_context), |
78 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) { | 79 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) { |
79 } | 80 } |
80 | 81 |
81 ~DeviceRequest() {} | 82 ~DeviceRequest() {} |
82 | 83 |
83 // Update the request state and notify observers. | 84 // Update the request state and notify observers. |
84 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { | 85 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { |
85 if (stream_type == NUM_MEDIA_TYPES) { | 86 if (stream_type == NUM_MEDIA_TYPES) { |
86 for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES; ++i) { | 87 for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES; ++i) { |
87 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); | 88 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // MediaStreamRequest::render_process_id which in the tab capture case | 128 // MediaStreamRequest::render_process_id which in the tab capture case |
128 // specifies the target renderer from which audio and video is captured. | 129 // specifies the target renderer from which audio and video is captured. |
129 const int requesting_process_id; | 130 const int requesting_process_id; |
130 | 131 |
131 // The render view id that requested this stream to be generated and that | 132 // The render view id that requested this stream to be generated and that |
132 // will receive a handle to the MediaStream. This may be different from | 133 // will receive a handle to the MediaStream. This may be different from |
133 // MediaStreamRequest::render_view_id which in the tab capture case | 134 // MediaStreamRequest::render_view_id which in the tab capture case |
134 // specifies the target renderer from which audio and video is captured. | 135 // specifies the target renderer from which audio and video is captured. |
135 const int requesting_view_id; | 136 const int requesting_view_id; |
136 | 137 |
| 138 ResourceContext* resource_context; |
| 139 |
137 StreamDeviceInfoArray devices; | 140 StreamDeviceInfoArray devices; |
138 | 141 |
139 // Callback to the requester which audio/video devices have been selected. | 142 // Callback to the requester which audio/video devices have been selected. |
140 // It can be null if the requester has no interest to know the result. | 143 // It can be null if the requester has no interest to know the result. |
141 // Currently it is only used by |DEVICE_ACCESS| type. | 144 // Currently it is only used by |DEVICE_ACCESS| type. |
142 MediaStreamManager::MediaRequestResponseCallback callback; | 145 MediaStreamManager::MediaRequestResponseCallback callback; |
143 | 146 |
144 scoped_ptr<MediaStreamUIProxy> ui_proxy; | 147 scoped_ptr<MediaStreamUIProxy> ui_proxy; |
145 | 148 |
146 private: | 149 private: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 int page_request_id, | 208 int page_request_id, |
206 const StreamOptions& options, | 209 const StreamOptions& options, |
207 const GURL& security_origin, | 210 const GURL& security_origin, |
208 const MediaRequestResponseCallback& callback) { | 211 const MediaRequestResponseCallback& callback) { |
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
210 // Create a new request based on options. | 213 // Create a new request based on options. |
211 MediaStreamRequest stream_request( | 214 MediaStreamRequest stream_request( |
212 render_process_id, render_view_id, page_request_id, | 215 render_process_id, render_view_id, page_request_id, |
213 security_origin, MEDIA_DEVICE_ACCESS, std::string(), std::string(), | 216 security_origin, MEDIA_DEVICE_ACCESS, std::string(), std::string(), |
214 options.audio_type, options.video_type); | 217 options.audio_type, options.video_type); |
| 218 // TODO(perkj): The argument list with NULL parameters to DeviceRequest |
| 219 // suggests that this is the wrong design. Can this be refactored? |
215 DeviceRequest* request = new DeviceRequest(NULL, stream_request, | 220 DeviceRequest* request = new DeviceRequest(NULL, stream_request, |
216 render_process_id, render_view_id); | 221 render_process_id, render_view_id, |
| 222 NULL); |
217 const std::string& label = AddRequest(request); | 223 const std::string& label = AddRequest(request); |
218 | 224 |
219 request->callback = callback; | 225 request->callback = callback; |
220 BrowserThread::PostTask( | 226 BrowserThread::PostTask( |
221 BrowserThread::IO, FROM_HERE, | 227 BrowserThread::IO, FROM_HERE, |
222 base::Bind(&MediaStreamManager::HandleRequest, | 228 base::Bind(&MediaStreamManager::HandleRequest, |
223 base::Unretained(this), label)); | 229 base::Unretained(this), label)); |
224 return label; | 230 return label; |
225 } | 231 } |
226 | 232 |
227 std::string MediaStreamManager::GenerateStream( | 233 std::string MediaStreamManager::GenerateStream( |
228 MediaStreamRequester* requester, | 234 MediaStreamRequester* requester, |
229 int render_process_id, | 235 int render_process_id, |
230 int render_view_id, | 236 int render_view_id, |
| 237 ResourceContext* rc, |
231 int page_request_id, | 238 int page_request_id, |
232 const StreamOptions& options, | 239 const StreamOptions& options, |
233 const GURL& security_origin) { | 240 const GURL& security_origin) { |
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
235 if (CommandLine::ForCurrentProcess()->HasSwitch( | 242 if (CommandLine::ForCurrentProcess()->HasSwitch( |
236 switches::kUseFakeDeviceForMediaStream)) { | 243 switches::kUseFakeDeviceForMediaStream)) { |
237 UseFakeDevice(); | 244 UseFakeDevice(); |
238 } | 245 } |
239 if (CommandLine::ForCurrentProcess()->HasSwitch( | 246 if (CommandLine::ForCurrentProcess()->HasSwitch( |
240 switches::kUseFakeUIForMediaStream)) { | 247 switches::kUseFakeUIForMediaStream)) { |
241 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); | 248 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); |
242 } | 249 } |
243 | 250 |
244 // Create a new request based on options. | 251 // Create a new request based on options. |
245 MediaStreamRequest stream_request( | 252 MediaStreamRequest stream_request( |
246 render_process_id, render_view_id, page_request_id, | 253 render_process_id, render_view_id, page_request_id, |
247 security_origin, MEDIA_GENERATE_STREAM, | 254 security_origin, MEDIA_GENERATE_STREAM, |
248 options.audio_device_id, options.video_device_id, | 255 options.audio_device_id, options.video_device_id, |
249 options.audio_type, options.video_type); | 256 options.audio_type, options.video_type); |
250 DeviceRequest* request = new DeviceRequest(requester, stream_request, | 257 DeviceRequest* request = new DeviceRequest(requester, stream_request, |
251 render_process_id, | 258 render_process_id, |
252 render_view_id); | 259 render_view_id, |
| 260 rc); |
253 const std::string& label = AddRequest(request); | 261 const std::string& label = AddRequest(request); |
254 | 262 |
255 // Need to post a task since the requester won't have label till | 263 // Need to post a task since the requester won't have label till |
256 // this function returns. | 264 // this function returns. |
257 BrowserThread::PostTask( | 265 BrowserThread::PostTask( |
258 BrowserThread::IO, FROM_HERE, | 266 BrowserThread::IO, FROM_HERE, |
259 base::Bind(&MediaStreamManager::HandleRequest, | 267 base::Bind(&MediaStreamManager::HandleRequest, |
260 base::Unretained(this), label)); | 268 base::Unretained(this), label)); |
261 return label; | 269 return label; |
262 } | 270 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 MEDIA_REQUEST_STATE_CLOSING); | 400 MEDIA_REQUEST_STATE_CLOSING); |
393 } | 401 } |
394 } | 402 } |
395 } | 403 } |
396 } | 404 } |
397 | 405 |
398 std::string MediaStreamManager::EnumerateDevices( | 406 std::string MediaStreamManager::EnumerateDevices( |
399 MediaStreamRequester* requester, | 407 MediaStreamRequester* requester, |
400 int render_process_id, | 408 int render_process_id, |
401 int render_view_id, | 409 int render_view_id, |
| 410 ResourceContext* rc, |
402 int page_request_id, | 411 int page_request_id, |
403 MediaStreamType type, | 412 MediaStreamType type, |
404 const GURL& security_origin) { | 413 const GURL& security_origin) { |
405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
406 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 415 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
407 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 416 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
408 | 417 |
409 // When the requester is NULL, the request is made by the UI to ensure MSM | 418 // When the requester is NULL, the request is made by the UI to ensure MSM |
410 // starts monitoring devices. | 419 // starts monitoring devices. |
411 if (!requester) { | 420 if (!requester) { |
(...skipping 12 matching lines...) Expand all Loading... |
424 } else { | 433 } else { |
425 NOTREACHED(); | 434 NOTREACHED(); |
426 return std::string(); | 435 return std::string(); |
427 } | 436 } |
428 | 437 |
429 MediaStreamRequest stream_request( | 438 MediaStreamRequest stream_request( |
430 render_process_id, render_view_id, page_request_id, | 439 render_process_id, render_view_id, page_request_id, |
431 security_origin, MEDIA_ENUMERATE_DEVICES, std::string(), std::string(), | 440 security_origin, MEDIA_ENUMERATE_DEVICES, std::string(), std::string(), |
432 options.audio_type, options.video_type); | 441 options.audio_type, options.video_type); |
433 DeviceRequest* request = new DeviceRequest(requester, stream_request, | 442 DeviceRequest* request = new DeviceRequest(requester, stream_request, |
434 render_process_id, | 443 render_process_id, render_view_id, |
435 render_view_id); | 444 rc); |
436 const std::string& label = AddRequest(request); | 445 const std::string& label = AddRequest(request); |
437 BrowserThread::PostTask( | 446 BrowserThread::PostTask( |
438 BrowserThread::IO, FROM_HERE, | 447 BrowserThread::IO, FROM_HERE, |
439 base::Bind(&MediaStreamManager::DoEnumerateDevices, | 448 base::Bind(&MediaStreamManager::DoEnumerateDevices, |
440 base::Unretained(this), label)); | 449 base::Unretained(this), label)); |
441 | 450 |
442 return label; | 451 return label; |
443 } | 452 } |
444 | 453 |
445 void MediaStreamManager::DoEnumerateDevices(const std::string& label) { | 454 void MediaStreamManager::DoEnumerateDevices(const std::string& label) { |
(...skipping 19 matching lines...) Expand all Loading... |
465 FinalizeEnumerateDevices(label, request); | 474 FinalizeEnumerateDevices(label, request); |
466 } else { | 475 } else { |
467 StartEnumeration(request); | 476 StartEnumeration(request); |
468 } | 477 } |
469 } | 478 } |
470 | 479 |
471 std::string MediaStreamManager::OpenDevice( | 480 std::string MediaStreamManager::OpenDevice( |
472 MediaStreamRequester* requester, | 481 MediaStreamRequester* requester, |
473 int render_process_id, | 482 int render_process_id, |
474 int render_view_id, | 483 int render_view_id, |
| 484 ResourceContext* rc, |
475 int page_request_id, | 485 int page_request_id, |
476 const std::string& device_id, | 486 const std::string& device_id, |
477 MediaStreamType type, | 487 MediaStreamType type, |
478 const GURL& security_origin) { | 488 const GURL& security_origin) { |
479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
480 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 490 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
481 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 491 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
482 | 492 |
483 // Create a new request. | 493 // Create a new request. |
484 StreamOptions options; | 494 StreamOptions options; |
485 if (IsAudioMediaType(type)) { | 495 if (IsAudioMediaType(type)) { |
486 options.audio_type = type; | 496 options.audio_type = type; |
487 options.audio_device_id = device_id; | 497 options.audio_device_id = device_id; |
488 } else if (IsVideoMediaType(type)) { | 498 } else if (IsVideoMediaType(type)) { |
489 options.video_type = type; | 499 options.video_type = type; |
490 options.video_device_id = device_id; | 500 options.video_device_id = device_id; |
491 } else { | 501 } else { |
492 NOTREACHED(); | 502 NOTREACHED(); |
493 return std::string(); | 503 return std::string(); |
494 } | 504 } |
495 | 505 |
496 MediaStreamRequest stream_request( | 506 MediaStreamRequest stream_request( |
497 render_process_id, render_view_id, page_request_id, | 507 render_process_id, render_view_id, page_request_id, |
498 security_origin, MEDIA_OPEN_DEVICE, options.audio_device_id, | 508 security_origin, MEDIA_OPEN_DEVICE, options.audio_device_id, |
499 options.video_device_id, options.audio_type, options.video_type); | 509 options.video_device_id, options.audio_type, options.video_type); |
500 DeviceRequest* request = new DeviceRequest(requester, stream_request, | 510 DeviceRequest* request = new DeviceRequest(requester, stream_request, |
501 render_process_id, | 511 render_process_id, render_view_id, |
502 render_view_id); | 512 rc); |
503 const std::string& label = AddRequest(request); | 513 const std::string& label = AddRequest(request); |
504 BrowserThread::PostTask( | 514 BrowserThread::PostTask( |
505 BrowserThread::IO, FROM_HERE, | 515 BrowserThread::IO, FROM_HERE, |
506 base::Bind(&MediaStreamManager::HandleRequest, | 516 base::Bind(&MediaStreamManager::HandleRequest, |
507 base::Unretained(this), label)); | 517 base::Unretained(this), label)); |
508 | 518 |
509 return label; | 519 return label; |
510 } | 520 } |
511 | 521 |
512 void MediaStreamManager::StartMonitoring() { | 522 void MediaStreamManager::StartMonitoring() { |
(...skipping 18 matching lines...) Expand all Loading... |
531 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 541 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
532 if (monitoring_started_) { | 542 if (monitoring_started_) { |
533 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); | 543 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); |
534 monitoring_started_ = false; | 544 monitoring_started_ = false; |
535 ClearEnumerationCache(&audio_enumeration_cache_); | 545 ClearEnumerationCache(&audio_enumeration_cache_); |
536 ClearEnumerationCache(&video_enumeration_cache_); | 546 ClearEnumerationCache(&video_enumeration_cache_); |
537 } | 547 } |
538 } | 548 } |
539 | 549 |
540 bool MediaStreamManager::TranslateRequestedSourceIdToDeviceId( | 550 bool MediaStreamManager::TranslateRequestedSourceIdToDeviceId( |
541 MediaStreamRequest* request) { | 551 DeviceRequest* request) { |
| 552 MediaStreamRequest* ms_request = &request->request; |
542 // If a specific device has been requested we need to find the real device id. | 553 // If a specific device has been requested we need to find the real device id. |
543 if (request->audio_type == MEDIA_DEVICE_AUDIO_CAPTURE && | 554 if (ms_request->audio_type == MEDIA_DEVICE_AUDIO_CAPTURE && |
544 !request->requested_audio_device_id.empty()) { | 555 !ms_request->requested_audio_device_id.empty()) { |
545 if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_AUDIO_CAPTURE, | 556 if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_AUDIO_CAPTURE, |
546 request->security_origin, | 557 request->resource_context, |
547 request->requested_audio_device_id, | 558 ms_request->security_origin, |
548 &request->requested_audio_device_id)) { | 559 ms_request->requested_audio_device_id, |
| 560 &ms_request->requested_audio_device_id)) { |
549 // TODO(perkj): gUM should support mandatory and optional constraints. | 561 // TODO(perkj): gUM should support mandatory and optional constraints. |
550 // Ie - if the sourceId is optional but it does not match - gUM should | 562 // Ie - if the sourceId is optional but it does not match - gUM should |
551 // not fail. For now we treat sourceId as a mandatory constraint. | 563 // not fail. For now we treat sourceId as a mandatory constraint. |
552 LOG(ERROR) << "Requested device does not exist."; | 564 LOG(ERROR) << "Requested device does not exist."; |
553 return false; | 565 return false; |
554 } | 566 } |
555 } | 567 } |
556 | 568 |
557 if (request->video_type == MEDIA_DEVICE_VIDEO_CAPTURE && | 569 if (ms_request->video_type == MEDIA_DEVICE_VIDEO_CAPTURE && |
558 !request->requested_video_device_id.empty()) { | 570 !ms_request->requested_video_device_id.empty()) { |
559 if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_VIDEO_CAPTURE, | 571 if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_VIDEO_CAPTURE, |
560 request->security_origin, | 572 request->resource_context, |
561 request->requested_video_device_id, | 573 ms_request->security_origin, |
562 &request->requested_video_device_id)) { | 574 ms_request->requested_video_device_id, |
| 575 &ms_request->requested_video_device_id)) { |
563 // TODO(perkj): guM should support mandatory and optional constraints. | 576 // TODO(perkj): guM should support mandatory and optional constraints. |
564 // Ie - if the sourceId is optional but it does not match - guM should | 577 // Ie - if the sourceId is optional but it does not match - guM should |
565 // not fail. For now we treat sourceId as a mandatory constraint. | 578 // not fail. For now we treat sourceId as a mandatory constraint. |
566 return false; | 579 return false; |
567 } | 580 } |
568 } | 581 } |
569 DVLOG(3) << "Requested audio device " << request->requested_audio_device_id | 582 DVLOG(3) << "Requested audio device " |
570 << "Requested video device " << request->requested_video_device_id; | 583 << ms_request->requested_audio_device_id |
| 584 << "Requested video device " |
| 585 << ms_request->requested_video_device_id; |
571 return true; | 586 return true; |
572 } | 587 } |
573 | 588 |
574 void MediaStreamManager::TranslateDeviceIdToSourceId( | 589 void MediaStreamManager::TranslateDeviceIdToSourceId( |
575 const MediaStreamRequest& request, | 590 DeviceRequest* request, |
576 MediaStreamDevice* device) { | 591 MediaStreamDevice* device) { |
577 if (request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE || | 592 if (request->request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE || |
578 request.video_type == MEDIA_DEVICE_VIDEO_CAPTURE) { | 593 request->request.video_type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
579 device->id = content::GetHMACForMediaDeviceID( | 594 device->id = content::GetHMACForMediaDeviceID( |
580 request.security_origin, | 595 request->resource_context, |
| 596 request->request.security_origin, |
581 device->id); | 597 device->id); |
582 return; | 598 return; |
583 } | 599 } |
584 return; | 600 return; |
585 } | 601 } |
586 | 602 |
587 bool MediaStreamManager::TranslateSourceIdToDeviceId( | 603 bool MediaStreamManager::TranslateSourceIdToDeviceId( |
588 MediaStreamType stream_type, | 604 MediaStreamType stream_type, |
| 605 ResourceContext* rc, |
589 const GURL& security_origin, | 606 const GURL& security_origin, |
590 const std::string& source_id, | 607 const std::string& source_id, |
591 std::string* device_id) { | 608 std::string* device_id) { |
592 DCHECK(stream_type == MEDIA_DEVICE_AUDIO_CAPTURE || | 609 DCHECK(stream_type == MEDIA_DEVICE_AUDIO_CAPTURE || |
593 stream_type == MEDIA_DEVICE_VIDEO_CAPTURE); | 610 stream_type == MEDIA_DEVICE_VIDEO_CAPTURE); |
594 DCHECK(!source_id.empty()); | 611 DCHECK(!source_id.empty()); |
595 | 612 |
596 EnumerationCache* cache = | 613 EnumerationCache* cache = |
597 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? | 614 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? |
598 &audio_enumeration_cache_ : &video_enumeration_cache_; | 615 &audio_enumeration_cache_ : &video_enumeration_cache_; |
599 | 616 |
600 // If device monitoring hasn't started, the |device_guid| is not valid. | 617 // If device monitoring hasn't started, the |device_guid| is not valid. |
601 if (!cache->valid) | 618 if (!cache->valid) |
602 return false; | 619 return false; |
603 | 620 |
604 for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); | 621 for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); |
605 it != cache->devices.end(); | 622 it != cache->devices.end(); |
606 ++it) { | 623 ++it) { |
607 if (content::DoesMediaDeviceIDMatchHMAC(security_origin, source_id, | 624 if (content::DoesMediaDeviceIDMatchHMAC(rc, security_origin, source_id, |
608 it->device.id)) { | 625 it->device.id)) { |
609 *device_id = it->device.id; | 626 *device_id = it->device.id; |
610 return true; | 627 return true; |
611 } | 628 } |
612 } | 629 } |
613 return false; | 630 return false; |
614 } | 631 } |
615 | 632 |
616 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { | 633 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { |
617 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 634 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 if (!is_web_contents_capture && | 745 if (!is_web_contents_capture && |
729 !is_screen_capture && | 746 !is_screen_capture && |
730 ((IsAudioMediaType(audio_type) && !audio_enumeration_cache_.valid) || | 747 ((IsAudioMediaType(audio_type) && !audio_enumeration_cache_.valid) || |
731 (IsVideoMediaType(video_type) && !video_enumeration_cache_.valid))) { | 748 (IsVideoMediaType(video_type) && !video_enumeration_cache_.valid))) { |
732 // Enumerate the devices if there is no valid device lists to be used. | 749 // Enumerate the devices if there is no valid device lists to be used. |
733 StartEnumeration(request); | 750 StartEnumeration(request); |
734 return; | 751 return; |
735 } | 752 } |
736 | 753 |
737 // If a specific device has been requested we need to find the real device id. | 754 // If a specific device has been requested we need to find the real device id. |
738 if (!TranslateRequestedSourceIdToDeviceId(&request->request)) { | 755 if (!TranslateRequestedSourceIdToDeviceId(request)) { |
739 FinalizeRequestFailed(label, request); | 756 FinalizeRequestFailed(label, request); |
740 return; | 757 return; |
741 } | 758 } |
742 | 759 |
743 // No need to do new device enumerations, post the request to UI | 760 // No need to do new device enumerations, post the request to UI |
744 // immediately. | 761 // immediately. |
745 if (IsAudioMediaType(audio_type)) | 762 if (IsAudioMediaType(audio_type)) |
746 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 763 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
747 if (IsVideoMediaType(video_type)) | 764 if (IsVideoMediaType(video_type)) |
748 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 765 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 if (source_id == device_it->device.id) { | 842 if (source_id == device_it->device.id) { |
826 return &*device_it; | 843 return &*device_it; |
827 } | 844 } |
828 } | 845 } |
829 } | 846 } |
830 } | 847 } |
831 return NULL; | 848 return NULL; |
832 } | 849 } |
833 | 850 |
834 bool MediaStreamManager::FindExistingRequestedDeviceInfo( | 851 bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
835 int render_process_id, | 852 const DeviceRequest* new_request, |
836 int render_view_id, | 853 const MediaStreamDevice& new_device_info, |
837 const GURL& security_origin, | 854 StreamDeviceInfo* existing_device_info, |
838 MediaStreamRequestType type, | 855 MediaRequestState* existing_request_state) const { |
839 const std::string& device_id, | 856 DCHECK(existing_device_info); |
840 MediaStreamType device_type, | 857 DCHECK(existing_request_state); |
841 StreamDeviceInfo* device_info, | 858 |
842 MediaRequestState* request_state) const { | 859 const MediaStreamRequest& new_ms_request = new_request->request; |
843 DCHECK(device_info); | |
844 DCHECK(request_state); | |
845 | 860 |
846 std::string source_id = content::GetHMACForMediaDeviceID( | 861 std::string source_id = content::GetHMACForMediaDeviceID( |
847 security_origin, | 862 new_request->resource_context, |
848 device_id); | 863 new_ms_request.security_origin, |
| 864 new_device_info.id); |
849 | 865 |
850 for (DeviceRequests::const_iterator it = requests_.begin(); | 866 for (DeviceRequests::const_iterator it = requests_.begin(); |
851 it != requests_.end() ; ++it) { | 867 it != requests_.end() ; ++it) { |
852 const DeviceRequest* request = it->second; | 868 const DeviceRequest* request = it->second; |
853 if (request->requesting_process_id == render_process_id && | 869 if (request->requesting_process_id == new_request->requesting_process_id && |
854 request->requesting_view_id == render_view_id && | 870 request->requesting_view_id == new_request->requesting_view_id && |
855 request->request.request_type == type) { | 871 request->request.request_type == new_ms_request.request_type) { |
856 for (StreamDeviceInfoArray::const_iterator device_it = | 872 for (StreamDeviceInfoArray::const_iterator device_it = |
857 request->devices.begin(); | 873 request->devices.begin(); |
858 device_it != request->devices.end(); ++device_it) { | 874 device_it != request->devices.end(); ++device_it) { |
859 if (device_it->device.id == source_id && | 875 if (device_it->device.id == source_id && |
860 device_it->device.type == device_type) { | 876 device_it->device.type == new_device_info.type) { |
861 *device_info = *device_it; | 877 *existing_device_info = *device_it; |
862 *request_state = request->state(device_it->device.type); | 878 *existing_request_state = request->state(device_it->device.type); |
863 return true; | 879 return true; |
864 } | 880 } |
865 } | 881 } |
866 } | 882 } |
867 } | 883 } |
868 return false; | 884 return false; |
869 } | 885 } |
870 | 886 |
871 void MediaStreamManager::FinalizeGenerateStream(const std::string& label, | 887 void MediaStreamManager::FinalizeGenerateStream(const std::string& label, |
872 DeviceRequest* request) { | 888 DeviceRequest* request) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, | 922 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, |
907 DeviceRequest* request) { | 923 DeviceRequest* request) { |
908 const StreamDeviceInfoArray& requested_devices = request->devices; | 924 const StreamDeviceInfoArray& requested_devices = request->devices; |
909 request->requester->DeviceOpened(label, requested_devices.front()); | 925 request->requester->DeviceOpened(label, requested_devices.front()); |
910 } | 926 } |
911 | 927 |
912 void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label, | 928 void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label, |
913 DeviceRequest* request) { | 929 DeviceRequest* request) { |
914 for (StreamDeviceInfoArray::iterator it = request->devices.begin(); | 930 for (StreamDeviceInfoArray::iterator it = request->devices.begin(); |
915 it != request->devices.end(); ++it) { | 931 it != request->devices.end(); ++it) { |
916 TranslateDeviceIdToSourceId(request->request, &it->device); | 932 TranslateDeviceIdToSourceId(request, &it->device); |
917 } | 933 } |
918 request->requester->DevicesEnumerated(label, request->devices); | 934 request->requester->DevicesEnumerated(label, request->devices); |
919 } | 935 } |
920 | 936 |
921 void MediaStreamManager::FinalizeMediaAccessRequest( | 937 void MediaStreamManager::FinalizeMediaAccessRequest( |
922 const std::string& label, | 938 const std::string& label, |
923 DeviceRequest* request, | 939 DeviceRequest* request, |
924 const MediaStreamDevices& devices) { | 940 const MediaStreamDevices& devices) { |
925 if (!request->callback.is_null()) | 941 if (!request->callback.is_null()) |
926 request->callback.Run(devices, request->ui_proxy.Pass()); | 942 request->callback.Run(devices, request->ui_proxy.Pass()); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 } else if (device_info.device.type == request->request.video_type) { | 1169 } else if (device_info.device.type == request->request.video_type) { |
1154 found_video = true; | 1170 found_video = true; |
1155 } | 1171 } |
1156 | 1172 |
1157 // If this is request for a new MediaStream, a device is only opened once | 1173 // If this is request for a new MediaStream, a device is only opened once |
1158 // per render view. This is so that the permission to use a device can be | 1174 // per render view. This is so that the permission to use a device can be |
1159 // revoked by a single call to StopStreamDevice regardless of how many | 1175 // revoked by a single call to StopStreamDevice regardless of how many |
1160 // MediaStreams it is being used in. | 1176 // MediaStreams it is being used in. |
1161 if (request->request.request_type == MEDIA_GENERATE_STREAM) { | 1177 if (request->request.request_type == MEDIA_GENERATE_STREAM) { |
1162 MediaRequestState state; | 1178 MediaRequestState state; |
1163 if (FindExistingRequestedDeviceInfo(request->requesting_process_id, | 1179 if (FindExistingRequestedDeviceInfo(request, |
1164 request->requesting_view_id, | 1180 device_info.device, |
1165 request->request.security_origin, | |
1166 request->request.request_type, | |
1167 device_info.device.id, | |
1168 device_info.device.type, | |
1169 &device_info, | 1181 &device_info, |
1170 &state)) { | 1182 &state)) { |
1171 request->devices.push_back(device_info); | 1183 request->devices.push_back(device_info); |
1172 request->SetState(device_info.device.type, state); | 1184 request->SetState(device_info.device.type, state); |
1173 DVLOG(1) << "HandleAccessRequestResponse - device already opened " | 1185 DVLOG(1) << "HandleAccessRequestResponse - device already opened " |
1174 << ", {label = " << label << "}" | 1186 << ", {label = " << label << "}" |
1175 << ", device_id = " << device_it->id << "}"; | 1187 << ", device_id = " << device_it->id << "}"; |
1176 continue; | 1188 continue; |
1177 } | 1189 } |
1178 } | 1190 } |
1179 device_info.session_id = | 1191 device_info.session_id = |
1180 GetDeviceManager(device_info.device.type)->Open(device_info); | 1192 GetDeviceManager(device_info.device.type)->Open(device_info); |
1181 TranslateDeviceIdToSourceId(request->request, &device_info.device); | 1193 TranslateDeviceIdToSourceId(request, &device_info.device); |
1182 request->devices.push_back(device_info); | 1194 request->devices.push_back(device_info); |
1183 | 1195 |
1184 request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); | 1196 request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); |
1185 DVLOG(1) << "HandleAccessRequestResponse - opening device " | 1197 DVLOG(1) << "HandleAccessRequestResponse - opening device " |
1186 << ", {label = " << label << "}" | 1198 << ", {label = " << label << "}" |
1187 << ", {device_id = " << device_info.device.id << "}" | 1199 << ", {device_id = " << device_info.device.id << "}" |
1188 << ", {session_id = " << device_info.session_id << "}"; | 1200 << ", {session_id = " << device_info.session_id << "}"; |
1189 } | 1201 } |
1190 | 1202 |
1191 // Check whether we've received all stream types requested. | 1203 // Check whether we've received all stream types requested. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 } | 1337 } |
1326 | 1338 |
1327 // Always do enumeration even though some enumeration is in progress, | 1339 // Always do enumeration even though some enumeration is in progress, |
1328 // because those enumeration commands could be sent before these devices | 1340 // because those enumeration commands could be sent before these devices |
1329 // change. | 1341 // change. |
1330 ++active_enumeration_ref_count_[stream_type]; | 1342 ++active_enumeration_ref_count_[stream_type]; |
1331 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1343 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
1332 } | 1344 } |
1333 | 1345 |
1334 } // namespace content | 1346 } // namespace content |
OLD | NEW |