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