Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.cc

Issue 364123002: [Cross-Site Isolation] Migrate entire MediaStream verticals to be per-RenderFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: It's random enough. + REBASE Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // MediaStreamManager::DeviceRequest represents a request to either enumerate 176 // MediaStreamManager::DeviceRequest represents a request to either enumerate
177 // available devices or open one or more devices. 177 // available devices or open one or more devices.
178 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create 178 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create
179 // several subclasses of DeviceRequest and move some of the responsibility of 179 // several subclasses of DeviceRequest and move some of the responsibility of
180 // the MediaStreamManager to the subclasses to get rid of the way too many if 180 // the MediaStreamManager to the subclasses to get rid of the way too many if
181 // statements in MediaStreamManager. 181 // statements in MediaStreamManager.
182 class MediaStreamManager::DeviceRequest { 182 class MediaStreamManager::DeviceRequest {
183 public: 183 public:
184 DeviceRequest(MediaStreamRequester* requester, 184 DeviceRequest(MediaStreamRequester* requester,
185 int requesting_process_id, 185 int requesting_process_id,
186 int requesting_view_id, 186 int requesting_frame_id,
187 int page_request_id, 187 int page_request_id,
188 const GURL& security_origin, 188 const GURL& security_origin,
189 bool have_permission, 189 bool have_permission,
190 bool user_gesture, 190 bool user_gesture,
191 MediaStreamRequestType request_type, 191 MediaStreamRequestType request_type,
192 const StreamOptions& options, 192 const StreamOptions& options,
193 const ResourceContext::SaltCallback& salt_callback) 193 const ResourceContext::SaltCallback& salt_callback)
194 : requester(requester), 194 : requester(requester),
195 requesting_process_id(requesting_process_id), 195 requesting_process_id(requesting_process_id),
196 requesting_view_id(requesting_view_id), 196 requesting_frame_id(requesting_frame_id),
197 page_request_id(page_request_id), 197 page_request_id(page_request_id),
198 security_origin(security_origin), 198 security_origin(security_origin),
199 have_permission(have_permission), 199 have_permission(have_permission),
200 user_gesture(user_gesture), 200 user_gesture(user_gesture),
201 request_type(request_type), 201 request_type(request_type),
202 options(options), 202 options(options),
203 salt_callback(salt_callback), 203 salt_callback(salt_callback),
204 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), 204 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED),
205 audio_type_(MEDIA_NO_SERVICE), 205 audio_type_(MEDIA_NO_SERVICE),
206 video_type_(MEDIA_NO_SERVICE) { 206 video_type_(MEDIA_NO_SERVICE) {
(...skipping 16 matching lines...) Expand all
223 } 223 }
224 224
225 MediaStreamType video_type() const { return video_type_; } 225 MediaStreamType video_type() const { return video_type_; }
226 226
227 // Creates a MediaStreamRequest object that is used by this request when UI 227 // Creates a MediaStreamRequest object that is used by this request when UI
228 // is asked for permission and device selection. 228 // is asked for permission and device selection.
229 void CreateUIRequest(const std::string& requested_audio_device_id, 229 void CreateUIRequest(const std::string& requested_audio_device_id,
230 const std::string& requested_video_device_id) { 230 const std::string& requested_video_device_id) {
231 DCHECK(!ui_request_); 231 DCHECK(!ui_request_);
232 ui_request_.reset(new MediaStreamRequest(requesting_process_id, 232 ui_request_.reset(new MediaStreamRequest(requesting_process_id,
233 requesting_view_id, 233 requesting_frame_id,
234 page_request_id, 234 page_request_id,
235 security_origin, 235 security_origin,
236 user_gesture, 236 user_gesture,
237 request_type, 237 request_type,
238 requested_audio_device_id, 238 requested_audio_device_id,
239 requested_video_device_id, 239 requested_video_device_id,
240 audio_type_, 240 audio_type_,
241 video_type_)); 241 video_type_));
242 } 242 }
243 243
244 // Creates a tab capture specific MediaStreamRequest object that is used by 244 // Creates a tab capture specific MediaStreamRequest object that is used by
245 // this request when UI is asked for permission and device selection. 245 // this request when UI is asked for permission and device selection.
246 void CreateTabCatureUIRequest(int target_render_process_id, 246 void CreateTabCaptureUIRequest(int target_render_process_id,
247 int target_render_view_id, 247 int target_render_frame_id,
248 const std::string& tab_capture_id) { 248 const std::string& tab_capture_id) {
249 DCHECK(!ui_request_); 249 DCHECK(!ui_request_);
250 ui_request_.reset(new MediaStreamRequest(target_render_process_id, 250 ui_request_.reset(new MediaStreamRequest(target_render_process_id,
251 target_render_view_id, 251 target_render_frame_id,
252 page_request_id, 252 page_request_id,
253 security_origin, 253 security_origin,
254 user_gesture, 254 user_gesture,
255 request_type, 255 request_type,
256 "", 256 "",
257 "", 257 "",
258 audio_type_, 258 audio_type_,
259 video_type_)); 259 video_type_));
260 ui_request_->tab_capture_device_id = tab_capture_id; 260 ui_request_->tab_capture_device_id = tab_capture_id;
261 } 261 }
(...skipping 14 matching lines...) Expand all
276 MediaObserver* media_observer = 276 MediaObserver* media_observer =
277 GetContentClient()->browser()->GetMediaObserver(); 277 GetContentClient()->browser()->GetMediaObserver();
278 if (!media_observer) 278 if (!media_observer)
279 return; 279 return;
280 280
281 // If |ui_request_| doesn't exist, it means that the request has not yet 281 // If |ui_request_| doesn't exist, it means that the request has not yet
282 // been setup fully and there are no valid observers. 282 // been setup fully and there are no valid observers.
283 if (!ui_request_) 283 if (!ui_request_)
284 return; 284 return;
285 285
286 // If we appended a device_id scheme, we want to remove it when notifying
287 // observers which may be in different modules since this scheme is only
288 // used internally within the content module.
289 std::string device_id =
290 WebContentsCaptureUtil::StripWebContentsDeviceScheme(
291 ui_request_->tab_capture_device_id);
292
293 media_observer->OnMediaRequestStateChanged( 286 media_observer->OnMediaRequestStateChanged(
294 ui_request_->render_process_id, ui_request_->render_view_id, 287 ui_request_->render_process_id, ui_request_->render_frame_id,
295 ui_request_->page_request_id, ui_request_->security_origin, 288 ui_request_->page_request_id, ui_request_->security_origin,
296 MediaStreamDevice(stream_type, device_id, device_id), new_state); 289 stream_type, new_state);
297 } 290 }
298 291
299 MediaRequestState state(MediaStreamType stream_type) const { 292 MediaRequestState state(MediaStreamType stream_type) const {
300 return state_[stream_type]; 293 return state_[stream_type];
301 } 294 }
302 295
303 MediaStreamRequester* const requester; // Can be NULL. 296 MediaStreamRequester* const requester; // Can be NULL.
304 297
305 298
306 // The render process id that requested this stream to be generated and that 299 // The render process id that requested this stream to be generated and that
307 // will receive a handle to the MediaStream. This may be different from 300 // will receive a handle to the MediaStream. This may be different from
308 // MediaStreamRequest::render_process_id which in the tab capture case 301 // MediaStreamRequest::render_process_id which in the tab capture case
309 // specifies the target renderer from which audio and video is captured. 302 // specifies the target renderer from which audio and video is captured.
310 const int requesting_process_id; 303 const int requesting_process_id;
311 304
312 // The render view id that requested this stream to be generated and that 305 // The render frame id that requested this stream to be generated and that
313 // will receive a handle to the MediaStream. This may be different from 306 // will receive a handle to the MediaStream. This may be different from
314 // MediaStreamRequest::render_view_id which in the tab capture case 307 // MediaStreamRequest::render_frame_id which in the tab capture case
315 // specifies the target renderer from which audio and video is captured. 308 // specifies the target renderer from which audio and video is captured.
316 const int requesting_view_id; 309 const int requesting_frame_id;
317 310
318 // An ID the render view provided to identify this request. 311 // An ID the render frame provided to identify this request.
319 const int page_request_id; 312 const int page_request_id;
320 313
321 const GURL security_origin; 314 const GURL security_origin;
322 315
323 // This is used when enumerating devices; if we don't have device access 316 // This is used when enumerating devices; if we don't have device access
324 // permission, we remove the device label. 317 // permission, we remove the device label.
325 bool have_permission; 318 bool have_permission;
326 319
327 const bool user_gesture; 320 const bool user_gesture;
328 321
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 } 400 }
408 401
409 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { 402 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() {
410 DCHECK_CURRENTLY_ON(BrowserThread::IO); 403 DCHECK_CURRENTLY_ON(BrowserThread::IO);
411 DCHECK(audio_input_device_manager_.get()); 404 DCHECK(audio_input_device_manager_.get());
412 return audio_input_device_manager_.get(); 405 return audio_input_device_manager_.get();
413 } 406 }
414 407
415 std::string MediaStreamManager::MakeMediaAccessRequest( 408 std::string MediaStreamManager::MakeMediaAccessRequest(
416 int render_process_id, 409 int render_process_id,
417 int render_view_id, 410 int render_frame_id,
418 int page_request_id, 411 int page_request_id,
419 const StreamOptions& options, 412 const StreamOptions& options,
420 const GURL& security_origin, 413 const GURL& security_origin,
421 const MediaRequestResponseCallback& callback) { 414 const MediaRequestResponseCallback& callback) {
422 DCHECK_CURRENTLY_ON(BrowserThread::IO); 415 DCHECK_CURRENTLY_ON(BrowserThread::IO);
423 416
424 // TODO(perkj): The argument list with NULL parameters to DeviceRequest 417 // TODO(perkj): The argument list with NULL parameters to DeviceRequest
425 // suggests that this is the wrong design. Can this be refactored? 418 // suggests that this is the wrong design. Can this be refactored?
426 DeviceRequest* request = new DeviceRequest(NULL, 419 DeviceRequest* request = new DeviceRequest(NULL,
427 render_process_id, 420 render_process_id,
428 render_view_id, 421 render_frame_id,
429 page_request_id, 422 page_request_id,
430 security_origin, 423 security_origin,
431 true, 424 true,
432 false, // user gesture 425 false, // user gesture
433 MEDIA_DEVICE_ACCESS, 426 MEDIA_DEVICE_ACCESS,
434 options, 427 options,
435 base::Bind(&ReturnEmptySalt)); 428 base::Bind(&ReturnEmptySalt));
436 429
437 const std::string& label = AddRequest(request); 430 const std::string& label = AddRequest(request);
438 431
439 request->callback = callback; 432 request->callback = callback;
440 // Post a task and handle the request asynchronously. The reason is that the 433 // Post a task and handle the request asynchronously. The reason is that the
441 // requester won't have a label for the request until this function returns 434 // requester won't have a label for the request until this function returns
442 // and thus can not handle a response. Using base::Unretained is safe since 435 // and thus can not handle a response. Using base::Unretained is safe since
443 // MediaStreamManager is deleted on the UI thread, after the IO thread has 436 // MediaStreamManager is deleted on the UI thread, after the IO thread has
444 // been stopped. 437 // been stopped.
445 BrowserThread::PostTask( 438 BrowserThread::PostTask(
446 BrowserThread::IO, FROM_HERE, 439 BrowserThread::IO, FROM_HERE,
447 base::Bind(&MediaStreamManager::SetupRequest, 440 base::Bind(&MediaStreamManager::SetupRequest,
448 base::Unretained(this), label)); 441 base::Unretained(this), label));
449 return label; 442 return label;
450 } 443 }
451 444
452 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, 445 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester,
453 int render_process_id, 446 int render_process_id,
454 int render_view_id, 447 int render_frame_id,
455 const ResourceContext::SaltCallback& sc, 448 const ResourceContext::SaltCallback& sc,
456 int page_request_id, 449 int page_request_id,
457 const StreamOptions& options, 450 const StreamOptions& options,
458 const GURL& security_origin, 451 const GURL& security_origin,
459 bool user_gesture) { 452 bool user_gesture) {
460 DCHECK_CURRENTLY_ON(BrowserThread::IO); 453 DCHECK_CURRENTLY_ON(BrowserThread::IO);
461 DVLOG(1) << "GenerateStream()"; 454 DVLOG(1) << "GenerateStream()";
462 if (CommandLine::ForCurrentProcess()->HasSwitch( 455 if (CommandLine::ForCurrentProcess()->HasSwitch(
463 switches::kUseFakeUIForMediaStream)) { 456 switches::kUseFakeUIForMediaStream)) {
464 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); 457 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>());
465 } 458 }
466 459
467 DeviceRequest* request = new DeviceRequest(requester, 460 DeviceRequest* request = new DeviceRequest(requester,
468 render_process_id, 461 render_process_id,
469 render_view_id, 462 render_frame_id,
470 page_request_id, 463 page_request_id,
471 security_origin, 464 security_origin,
472 true, 465 true,
473 user_gesture, 466 user_gesture,
474 MEDIA_GENERATE_STREAM, 467 MEDIA_GENERATE_STREAM,
475 options, 468 options,
476 sc); 469 sc);
477 470
478 const std::string& label = AddRequest(request); 471 const std::string& label = AddRequest(request);
479 472
480 // Post a task and handle the request asynchronously. The reason is that the 473 // Post a task and handle the request asynchronously. The reason is that the
481 // requester won't have a label for the request until this function returns 474 // requester won't have a label for the request until this function returns
482 // and thus can not handle a response. Using base::Unretained is safe since 475 // and thus can not handle a response. Using base::Unretained is safe since
483 // MediaStreamManager is deleted on the UI thread, after the IO thread has 476 // MediaStreamManager is deleted on the UI thread, after the IO thread has
484 // been stopped. 477 // been stopped.
485 BrowserThread::PostTask( 478 BrowserThread::PostTask(
486 BrowserThread::IO, FROM_HERE, 479 BrowserThread::IO, FROM_HERE,
487 base::Bind(&MediaStreamManager::SetupRequest, 480 base::Bind(&MediaStreamManager::SetupRequest,
488 base::Unretained(this), label)); 481 base::Unretained(this), label));
489 } 482 }
490 483
491 void MediaStreamManager::CancelRequest(int render_process_id, 484 void MediaStreamManager::CancelRequest(int render_process_id,
492 int render_view_id, 485 int render_frame_id,
493 int page_request_id) { 486 int page_request_id) {
494 for (DeviceRequests::const_iterator request_it = requests_.begin(); 487 for (DeviceRequests::const_iterator request_it = requests_.begin();
495 request_it != requests_.end(); ++request_it) { 488 request_it != requests_.end(); ++request_it) {
496 const DeviceRequest* request = request_it->second; 489 const DeviceRequest* request = request_it->second;
497 if (request->requesting_process_id == render_process_id && 490 if (request->requesting_process_id == render_process_id &&
498 request->requesting_view_id == render_view_id && 491 request->requesting_frame_id == render_frame_id &&
499 request->page_request_id == page_request_id) { 492 request->page_request_id == page_request_id) {
500 CancelRequest(request_it->first); 493 CancelRequest(request_it->first);
501 return; 494 return;
502 } 495 }
503 } 496 }
504 NOTREACHED(); 497 NOTREACHED();
505 } 498 }
506 499
507 void MediaStreamManager::CancelRequest(const std::string& label) { 500 void MediaStreamManager::CancelRequest(const std::string& label) {
508 DCHECK_CURRENTLY_ON(BrowserThread::IO); 501 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 continue; 543 continue;
551 } 544 }
552 545
553 std::string label = request_it->first; 546 std::string label = request_it->first;
554 ++request_it; 547 ++request_it;
555 CancelRequest(label); 548 CancelRequest(label);
556 } 549 }
557 } 550 }
558 551
559 void MediaStreamManager::StopStreamDevice(int render_process_id, 552 void MediaStreamManager::StopStreamDevice(int render_process_id,
560 int render_view_id, 553 int render_frame_id,
561 const std::string& device_id) { 554 const std::string& device_id) {
562 DCHECK_CURRENTLY_ON(BrowserThread::IO); 555 DCHECK_CURRENTLY_ON(BrowserThread::IO);
563 DVLOG(1) << "StopStreamDevice({render_view_id = " << render_view_id << "} " 556 DVLOG(1) << "StopStreamDevice({render_frame_id = " << render_frame_id << "} "
564 << ", {device_id = " << device_id << "})"; 557 << ", {device_id = " << device_id << "})";
565 // Find the first request for this |render_process_id| and |render_view_id| 558 // Find the first request for this |render_process_id| and |render_frame_id|
566 // of type MEDIA_GENERATE_STREAM that has requested to use |device_id| and 559 // of type MEDIA_GENERATE_STREAM that has requested to use |device_id| and
567 // stop it. 560 // stop it.
568 for (DeviceRequests::iterator request_it = requests_.begin(); 561 for (DeviceRequests::iterator request_it = requests_.begin();
569 request_it != requests_.end(); ++request_it) { 562 request_it != requests_.end(); ++request_it) {
570 DeviceRequest* request = request_it->second; 563 DeviceRequest* request = request_it->second;
571 if (request->requesting_process_id != render_process_id || 564 if (request->requesting_process_id != render_process_id ||
572 request->requesting_view_id != render_view_id || 565 request->requesting_frame_id != render_frame_id ||
573 request->request_type != MEDIA_GENERATE_STREAM) { 566 request->request_type != MEDIA_GENERATE_STREAM) {
574 continue; 567 continue;
575 } 568 }
576 569
577 StreamDeviceInfoArray& devices = request->devices; 570 StreamDeviceInfoArray& devices = request->devices;
578 for (StreamDeviceInfoArray::iterator device_it = devices.begin(); 571 for (StreamDeviceInfoArray::iterator device_it = devices.begin();
579 device_it != devices.end(); ++device_it) { 572 device_it != devices.end(); ++device_it) {
580 if (device_it->device.id == device_id) { 573 if (device_it->device.id == device_id) {
581 StopDevice(device_it->device.type, device_it->session_id); 574 StopDevice(device_it->device.type, device_it->session_id);
582 return; 575 return;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 // Note that only one device per type can be opened. 634 // Note that only one device per type can be opened.
642 request_it->second->SetState(type, MEDIA_REQUEST_STATE_CLOSING); 635 request_it->second->SetState(type, MEDIA_REQUEST_STATE_CLOSING);
643 } 636 }
644 } 637 }
645 } 638 }
646 } 639 }
647 640
648 std::string MediaStreamManager::EnumerateDevices( 641 std::string MediaStreamManager::EnumerateDevices(
649 MediaStreamRequester* requester, 642 MediaStreamRequester* requester,
650 int render_process_id, 643 int render_process_id,
651 int render_view_id, 644 int render_frame_id,
652 const ResourceContext::SaltCallback& sc, 645 const ResourceContext::SaltCallback& sc,
653 int page_request_id, 646 int page_request_id,
654 MediaStreamType type, 647 MediaStreamType type,
655 const GURL& security_origin, 648 const GURL& security_origin,
656 bool have_permission) { 649 bool have_permission) {
657 DCHECK_CURRENTLY_ON(BrowserThread::IO); 650 DCHECK_CURRENTLY_ON(BrowserThread::IO);
658 DCHECK(requester); 651 DCHECK(requester);
659 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || 652 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
660 type == MEDIA_DEVICE_VIDEO_CAPTURE || 653 type == MEDIA_DEVICE_VIDEO_CAPTURE ||
661 type == MEDIA_DEVICE_AUDIO_OUTPUT); 654 type == MEDIA_DEVICE_AUDIO_OUTPUT);
662 655
663 DeviceRequest* request = new DeviceRequest(requester, 656 DeviceRequest* request = new DeviceRequest(requester,
664 render_process_id, 657 render_process_id,
665 render_view_id, 658 render_frame_id,
666 page_request_id, 659 page_request_id,
667 security_origin, 660 security_origin,
668 have_permission, 661 have_permission,
669 false, // user gesture 662 false, // user gesture
670 MEDIA_ENUMERATE_DEVICES, 663 MEDIA_ENUMERATE_DEVICES,
671 StreamOptions(), 664 StreamOptions(),
672 sc); 665 sc);
673 if (IsAudioInputMediaType(type) || type == MEDIA_DEVICE_AUDIO_OUTPUT) 666 if (IsAudioInputMediaType(type) || type == MEDIA_DEVICE_AUDIO_OUTPUT)
674 request->SetAudioType(type); 667 request->SetAudioType(type);
675 else if (IsVideoMediaType(type)) 668 else if (IsVideoMediaType(type))
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 // Cached device list of this type exists. Just send it out. 719 // Cached device list of this type exists. Just send it out.
727 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); 720 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED);
728 request->devices = cache->devices; 721 request->devices = cache->devices;
729 FinalizeEnumerateDevices(label, request); 722 FinalizeEnumerateDevices(label, request);
730 } else { 723 } else {
731 StartEnumeration(request); 724 StartEnumeration(request);
732 } 725 }
733 DVLOG(1) << "Enumerate Devices ({label = " << label << "})"; 726 DVLOG(1) << "Enumerate Devices ({label = " << label << "})";
734 } 727 }
735 728
736 void MediaStreamManager::EnumerateAudioOutputDevices( 729 void MediaStreamManager::EnumerateAudioOutputDevices(const std::string& label) {
737 const std::string& label) {
738 DCHECK(device_task_runner_->BelongsToCurrentThread()); 730 DCHECK(device_task_runner_->BelongsToCurrentThread());
739 731
740 scoped_ptr<media::AudioDeviceNames> device_names( 732 scoped_ptr<media::AudioDeviceNames> device_names(
741 new media::AudioDeviceNames()); 733 new media::AudioDeviceNames());
742 audio_manager_->GetAudioOutputDeviceNames(device_names.get()); 734 audio_manager_->GetAudioOutputDeviceNames(device_names.get());
743 StreamDeviceInfoArray devices; 735 StreamDeviceInfoArray devices;
744 for (media::AudioDeviceNames::iterator it = device_names->begin(); 736 for (media::AudioDeviceNames::iterator it = device_names->begin();
745 it != device_names->end(); ++it) { 737 it != device_names->end(); ++it) {
746 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_OUTPUT, 738 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_OUTPUT,
747 it->device_name, 739 it->device_name,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 FinalizeEnumerateDevices(it->first, it->second); 771 FinalizeEnumerateDevices(it->first, it->second);
780 } 772 }
781 } 773 }
782 774
783 --active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_OUTPUT]; 775 --active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_OUTPUT];
784 DCHECK_GE(active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_OUTPUT], 0); 776 DCHECK_GE(active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_OUTPUT], 0);
785 } 777 }
786 778
787 void MediaStreamManager::OpenDevice(MediaStreamRequester* requester, 779 void MediaStreamManager::OpenDevice(MediaStreamRequester* requester,
788 int render_process_id, 780 int render_process_id,
789 int render_view_id, 781 int render_frame_id,
790 const ResourceContext::SaltCallback& sc, 782 const ResourceContext::SaltCallback& sc,
791 int page_request_id, 783 int page_request_id,
792 const std::string& device_id, 784 const std::string& device_id,
793 MediaStreamType type, 785 MediaStreamType type,
794 const GURL& security_origin) { 786 const GURL& security_origin) {
795 DCHECK_CURRENTLY_ON(BrowserThread::IO); 787 DCHECK_CURRENTLY_ON(BrowserThread::IO);
796 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || 788 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
797 type == MEDIA_DEVICE_VIDEO_CAPTURE); 789 type == MEDIA_DEVICE_VIDEO_CAPTURE);
798 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; 790 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})";
799 StreamOptions options; 791 StreamOptions options;
800 if (IsAudioInputMediaType(type)) { 792 if (IsAudioInputMediaType(type)) {
801 options.audio_requested = true; 793 options.audio_requested = true;
802 options.mandatory_audio.push_back( 794 options.mandatory_audio.push_back(
803 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); 795 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id));
804 } else if (IsVideoMediaType(type)) { 796 } else if (IsVideoMediaType(type)) {
805 options.video_requested = true; 797 options.video_requested = true;
806 options.mandatory_video.push_back( 798 options.mandatory_video.push_back(
807 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); 799 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id));
808 } else { 800 } else {
809 NOTREACHED(); 801 NOTREACHED();
810 } 802 }
811 DeviceRequest* request = new DeviceRequest(requester, 803 DeviceRequest* request = new DeviceRequest(requester,
812 render_process_id, 804 render_process_id,
813 render_view_id, 805 render_frame_id,
814 page_request_id, 806 page_request_id,
815 security_origin, 807 security_origin,
816 true, 808 true,
817 false, // user gesture 809 false, // user gesture
818 MEDIA_OPEN_DEVICE, 810 MEDIA_OPEN_DEVICE,
819 options, 811 options,
820 sc); 812 sc);
821 813
822 const std::string& label = AddRequest(request); 814 const std::string& label = AddRequest(request);
823 // Post a task and handle the request asynchronously. The reason is that the 815 // Post a task and handle the request asynchronously. The reason is that the
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 device_it != request->devices.end(); ++device_it) { 895 device_it != request->devices.end(); ++device_it) {
904 std::string source_id = content::GetHMACForMediaDeviceID( 896 std::string source_id = content::GetHMACForMediaDeviceID(
905 request->salt_callback, 897 request->salt_callback,
906 request->security_origin, 898 request->security_origin,
907 device.id); 899 device.id);
908 if (device_it->device.id == source_id && 900 if (device_it->device.id == source_id &&
909 device_it->device.type == device.type) { 901 device_it->device.type == device.type) {
910 session_ids.push_back(device_it->session_id); 902 session_ids.push_back(device_it->session_id);
911 if (it->second->requester) { 903 if (it->second->requester) {
912 it->second->requester->DeviceStopped( 904 it->second->requester->DeviceStopped(
913 it->second->requesting_view_id, 905 it->second->requesting_frame_id,
914 it->first, 906 it->first,
915 *device_it); 907 *device_it);
916 } 908 }
917 } 909 }
918 } 910 }
919 } 911 }
920 for (std::vector<int>::const_iterator it = session_ids.begin(); 912 for (std::vector<int>::const_iterator it = session_ids.begin();
921 it != session_ids.end(); ++it) { 913 it != session_ids.end(); ++it) {
922 StopDevice(device.type, *it); 914 StopDevice(device.type, *it);
923 } 915 }
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 &mandatory_audio) && 1280 &mandatory_audio) &&
1289 !request->options.GetFirstVideoConstraintByName(kMediaStreamSourceId, 1281 !request->options.GetFirstVideoConstraintByName(kMediaStreamSourceId,
1290 &capture_device_id, 1282 &capture_device_id,
1291 &mandatory_video)) { 1283 &mandatory_video)) {
1292 return false; 1284 return false;
1293 } 1285 }
1294 DCHECK(mandatory_audio || mandatory_video); 1286 DCHECK(mandatory_audio || mandatory_video);
1295 1287
1296 // Customize options for a WebContents based capture. 1288 // Customize options for a WebContents based capture.
1297 int target_render_process_id = 0; 1289 int target_render_process_id = 0;
1298 int target_render_view_id = 0; 1290 int target_render_frame_id = 0;
1299
1300 // TODO(justinlin): Can't plumb audio mirroring using stream type right
1301 // now, so plumbing by device_id. Will revisit once it's refactored.
1302 // http://crbug.com/163100
1303 std::string tab_capture_device_id =
1304 WebContentsCaptureUtil::AppendWebContentsDeviceScheme(capture_device_id);
1305 1291
1306 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget( 1292 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget(
1307 tab_capture_device_id, &target_render_process_id, 1293 capture_device_id, &target_render_process_id, &target_render_frame_id);
1308 &target_render_view_id);
1309 if (!has_valid_device_id || 1294 if (!has_valid_device_id ||
1310 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && 1295 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE &&
1311 request->audio_type() != MEDIA_NO_SERVICE) || 1296 request->audio_type() != MEDIA_NO_SERVICE) ||
1312 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE && 1297 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE &&
1313 request->video_type() != MEDIA_NO_SERVICE)) { 1298 request->video_type() != MEDIA_NO_SERVICE)) {
1314 return false; 1299 return false;
1315 } 1300 }
1316 1301
1317 request->CreateTabCatureUIRequest(target_render_process_id, 1302 request->CreateTabCaptureUIRequest(target_render_process_id,
1318 target_render_view_id, 1303 target_render_frame_id,
1319 tab_capture_device_id); 1304 capture_device_id);
1320 1305
1321 DVLOG(3) << "SetupTabCaptureRequest " 1306 DVLOG(3) << "SetupTabCaptureRequest "
1322 << ", {tab_capture_device_id = " << tab_capture_device_id << "}" 1307 << ", {capture_device_id = " << capture_device_id << "}"
1323 << ", {target_render_process_id = " << target_render_process_id 1308 << ", {target_render_process_id = " << target_render_process_id
1324 << "}" 1309 << "}"
1325 << ", {target_render_view_id = " << target_render_view_id << "}"; 1310 << ", {target_render_frame_id = " << target_render_frame_id << "}";
1326 return true; 1311 return true;
1327 } 1312 }
1328 1313
1329 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) { 1314 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) {
1330 DCHECK(request->audio_type() == MEDIA_LOOPBACK_AUDIO_CAPTURE || 1315 DCHECK(request->audio_type() == MEDIA_LOOPBACK_AUDIO_CAPTURE ||
1331 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE); 1316 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE);
1332 1317
1333 // For screen capture we only support two valid combinations: 1318 // For screen capture we only support two valid combinations:
1334 // (1) screen video capture only, or 1319 // (1) screen video capture only, or
1335 // (2) screen video capture with loopback audio capture. 1320 // (2) screen video capture with loopback audio capture.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 1372
1388 std::string source_id = content::GetHMACForMediaDeviceID( 1373 std::string source_id = content::GetHMACForMediaDeviceID(
1389 new_request.salt_callback, 1374 new_request.salt_callback,
1390 new_request.security_origin, 1375 new_request.security_origin,
1391 new_device_info.id); 1376 new_device_info.id);
1392 1377
1393 for (DeviceRequests::const_iterator it = requests_.begin(); 1378 for (DeviceRequests::const_iterator it = requests_.begin();
1394 it != requests_.end() ; ++it) { 1379 it != requests_.end() ; ++it) {
1395 const DeviceRequest* request = it->second; 1380 const DeviceRequest* request = it->second;
1396 if (request->requesting_process_id == new_request.requesting_process_id && 1381 if (request->requesting_process_id == new_request.requesting_process_id &&
1397 request->requesting_view_id == new_request.requesting_view_id && 1382 request->requesting_frame_id == new_request.requesting_frame_id &&
1398 request->request_type == new_request.request_type) { 1383 request->request_type == new_request.request_type) {
1399 for (StreamDeviceInfoArray::const_iterator device_it = 1384 for (StreamDeviceInfoArray::const_iterator device_it =
1400 request->devices.begin(); 1385 request->devices.begin();
1401 device_it != request->devices.end(); ++device_it) { 1386 device_it != request->devices.end(); ++device_it) {
1402 if (device_it->device.id == source_id && 1387 if (device_it->device.id == source_id &&
1403 device_it->device.type == new_device_info.type) { 1388 device_it->device.type == new_device_info.type) {
1404 *existing_device_info = *device_it; 1389 *existing_device_info = *device_it;
1405 *existing_request_state = request->state(device_it->device.type); 1390 *existing_request_state = request->state(device_it->device.type);
1406 return true; 1391 return true;
1407 } 1392 }
(...skipping 16 matching lines...) Expand all
1424 if (IsAudioInputMediaType(device_it->device.type)) { 1409 if (IsAudioInputMediaType(device_it->device.type)) {
1425 audio_devices.push_back(*device_it); 1410 audio_devices.push_back(*device_it);
1426 } else if (IsVideoMediaType(device_it->device.type)) { 1411 } else if (IsVideoMediaType(device_it->device.type)) {
1427 video_devices.push_back(*device_it); 1412 video_devices.push_back(*device_it);
1428 } else { 1413 } else {
1429 NOTREACHED(); 1414 NOTREACHED();
1430 } 1415 }
1431 } 1416 }
1432 1417
1433 request->requester->StreamGenerated( 1418 request->requester->StreamGenerated(
1434 request->requesting_view_id, 1419 request->requesting_frame_id,
1435 request->page_request_id, 1420 request->page_request_id,
1436 label, audio_devices, video_devices); 1421 label, audio_devices, video_devices);
1437 } 1422 }
1438 1423
1439 void MediaStreamManager::FinalizeRequestFailed( 1424 void MediaStreamManager::FinalizeRequestFailed(
1440 const std::string& label, 1425 const std::string& label,
1441 DeviceRequest* request, 1426 DeviceRequest* request,
1442 content::MediaStreamRequestResult result) { 1427 content::MediaStreamRequestResult result) {
1443 if (request->requester) 1428 if (request->requester)
1444 request->requester->StreamGenerationFailed( 1429 request->requester->StreamGenerationFailed(
1445 request->requesting_view_id, 1430 request->requesting_frame_id,
1446 request->page_request_id, 1431 request->page_request_id,
1447 result); 1432 result);
1448 1433
1449 if (request->request_type == MEDIA_DEVICE_ACCESS && 1434 if (request->request_type == MEDIA_DEVICE_ACCESS &&
1450 !request->callback.is_null()) { 1435 !request->callback.is_null()) {
1451 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); 1436 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass());
1452 } 1437 }
1453 1438
1454 DeleteRequest(label); 1439 DeleteRequest(label);
1455 } 1440 }
1456 1441
1457 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, 1442 void MediaStreamManager::FinalizeOpenDevice(const std::string& label,
1458 DeviceRequest* request) { 1443 DeviceRequest* request) {
1459 const StreamDeviceInfoArray& requested_devices = request->devices; 1444 const StreamDeviceInfoArray& requested_devices = request->devices;
1460 request->requester->DeviceOpened(request->requesting_view_id, 1445 request->requester->DeviceOpened(request->requesting_frame_id,
1461 request->page_request_id, 1446 request->page_request_id,
1462 label, requested_devices.front()); 1447 label, requested_devices.front());
1463 } 1448 }
1464 1449
1465 void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label, 1450 void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label,
1466 DeviceRequest* request) { 1451 DeviceRequest* request) {
1467 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1452 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1468 DCHECK_EQ(request->request_type, MEDIA_ENUMERATE_DEVICES); 1453 DCHECK_EQ(request->request_type, MEDIA_ENUMERATE_DEVICES);
1469 1454
1470 if (request->security_origin.is_valid()) { 1455 if (request->security_origin.is_valid()) {
1471 for (StreamDeviceInfoArray::iterator it = request->devices.begin(); 1456 for (StreamDeviceInfoArray::iterator it = request->devices.begin();
1472 it != request->devices.end(); ++it) { 1457 it != request->devices.end(); ++it) {
1473 TranslateDeviceIdToSourceId(request, &it->device); 1458 TranslateDeviceIdToSourceId(request, &it->device);
1474 } 1459 }
1475 } else { 1460 } else {
1476 request->devices.clear(); 1461 request->devices.clear();
1477 } 1462 }
1478 1463
1479 if (!request->have_permission) 1464 if (!request->have_permission)
1480 ClearDeviceLabels(&request->devices); 1465 ClearDeviceLabels(&request->devices);
1481 1466
1482 request->requester->DevicesEnumerated( 1467 request->requester->DevicesEnumerated(
1483 request->requesting_view_id, 1468 request->requesting_frame_id,
1484 request->page_request_id, 1469 request->page_request_id,
1485 label, 1470 label,
1486 request->devices); 1471 request->devices);
1487 1472
1488 // TODO(tommi): 1473 // TODO(tommi):
1489 // Ideally enumeration requests should be deleted once they have been served 1474 // Ideally enumeration requests should be deleted once they have been served
1490 // (as any request). However, this implementation mixes requests and 1475 // (as any request). However, this implementation mixes requests and
1491 // notifications together so enumeration requests are kept open by some 1476 // notifications together so enumeration requests are kept open by some
1492 // implementations (only Pepper?) and enumerations are done again when 1477 // implementations (only Pepper?) and enumerations are done again when
1493 // device notifications are fired. 1478 // device notifications are fired.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 DCHECK(!devices.empty()); 1795 DCHECK(!devices.empty());
1811 1796
1812 // Process all newly-accepted devices for this request. 1797 // Process all newly-accepted devices for this request.
1813 bool found_audio = false; 1798 bool found_audio = false;
1814 bool found_video = false; 1799 bool found_video = false;
1815 for (MediaStreamDevices::const_iterator device_it = devices.begin(); 1800 for (MediaStreamDevices::const_iterator device_it = devices.begin();
1816 device_it != devices.end(); ++device_it) { 1801 device_it != devices.end(); ++device_it) {
1817 StreamDeviceInfo device_info; 1802 StreamDeviceInfo device_info;
1818 device_info.device = *device_it; 1803 device_info.device = *device_it;
1819 1804
1820 // TODO(justinlin): Nicer way to do this?
1821 // Re-append the device's id since we lost it when posting request to UI.
1822 if (device_info.device.type == content::MEDIA_TAB_VIDEO_CAPTURE || 1805 if (device_info.device.type == content::MEDIA_TAB_VIDEO_CAPTURE ||
1823 device_info.device.type == content::MEDIA_TAB_AUDIO_CAPTURE) { 1806 device_info.device.type == content::MEDIA_TAB_AUDIO_CAPTURE) {
1824 device_info.device.id = request->UIRequest()->tab_capture_device_id; 1807 device_info.device.id = request->UIRequest()->tab_capture_device_id;
1825 1808
1826 // Initialize the sample_rate and channel_layout here since for audio 1809 // Initialize the sample_rate and channel_layout here since for audio
1827 // mirroring, we don't go through EnumerateDevices where these are usually 1810 // mirroring, we don't go through EnumerateDevices where these are usually
1828 // initialized. 1811 // initialized.
1829 if (device_info.device.type == content::MEDIA_TAB_AUDIO_CAPTURE) { 1812 if (device_info.device.type == content::MEDIA_TAB_AUDIO_CAPTURE) {
1830 const media::AudioParameters parameters = 1813 const media::AudioParameters parameters =
1831 audio_manager_->GetDefaultOutputStreamParameters(); 1814 audio_manager_->GetDefaultOutputStreamParameters();
1832 int sample_rate = parameters.sample_rate(); 1815 int sample_rate = parameters.sample_rate();
1833 // If we weren't able to get the native sampling rate or the sample_rate 1816 // If we weren't able to get the native sampling rate or the sample_rate
1834 // is outside the valid range for input devices set reasonable defaults. 1817 // is outside the valid range for input devices set reasonable defaults.
1835 if (sample_rate <= 0 || sample_rate > 96000) 1818 if (sample_rate <= 0 || sample_rate > 96000)
1836 sample_rate = 44100; 1819 sample_rate = 44100;
1837 1820
1838 device_info.device.input.sample_rate = sample_rate; 1821 device_info.device.input.sample_rate = sample_rate;
1839 device_info.device.input.channel_layout = media::CHANNEL_LAYOUT_STEREO; 1822 device_info.device.input.channel_layout = media::CHANNEL_LAYOUT_STEREO;
1840 } 1823 }
1841 } 1824 }
1842 1825
1843 if (device_info.device.type == request->audio_type()) { 1826 if (device_info.device.type == request->audio_type()) {
1844 found_audio = true; 1827 found_audio = true;
1845 } else if (device_info.device.type == request->video_type()) { 1828 } else if (device_info.device.type == request->video_type()) {
1846 found_video = true; 1829 found_video = true;
1847 } 1830 }
1848 1831
1849 // If this is request for a new MediaStream, a device is only opened once 1832 // If this is request for a new MediaStream, a device is only opened once
1850 // per render view. This is so that the permission to use a device can be 1833 // per render frame. This is so that the permission to use a device can be
1851 // revoked by a single call to StopStreamDevice regardless of how many 1834 // revoked by a single call to StopStreamDevice regardless of how many
1852 // MediaStreams it is being used in. 1835 // MediaStreams it is being used in.
1853 if (request->request_type == MEDIA_GENERATE_STREAM) { 1836 if (request->request_type == MEDIA_GENERATE_STREAM) {
1854 MediaRequestState state; 1837 MediaRequestState state;
1855 if (FindExistingRequestedDeviceInfo(*request, 1838 if (FindExistingRequestedDeviceInfo(*request,
1856 device_info.device, 1839 device_info.device,
1857 &device_info, 1840 &device_info,
1858 &state)) { 1841 &state)) {
1859 request->devices.push_back(device_info); 1842 request->devices.push_back(device_info);
1860 request->SetState(device_info.device.type, state); 1843 request->SetState(device_info.device.type, state);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1876 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1894 1877
1895 DeviceRequest* request = FindRequest(label); 1878 DeviceRequest* request = FindRequest(label);
1896 if (!request) 1879 if (!request)
1897 return; 1880 return;
1898 1881
1899 // Notify renderers that the devices in the stream will be stopped. 1882 // Notify renderers that the devices in the stream will be stopped.
1900 if (request->requester) { 1883 if (request->requester) {
1901 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); 1884 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin();
1902 device_it != request->devices.end(); ++device_it) { 1885 device_it != request->devices.end(); ++device_it) {
1903 request->requester->DeviceStopped(request->requesting_view_id, 1886 request->requester->DeviceStopped(request->requesting_frame_id,
1904 label, 1887 label,
1905 *device_it); 1888 *device_it);
1906 } 1889 }
1907 } 1890 }
1908 1891
1909 CancelRequest(label); 1892 CancelRequest(label);
1910 } 1893 }
1911 1894
1912 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { 1895 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) {
1913 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1896 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { 2015 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) {
2033 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, 2016 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id,
2034 window_id); 2017 window_id);
2035 break; 2018 break;
2036 } 2019 }
2037 } 2020 }
2038 } 2021 }
2039 } 2022 }
2040 2023
2041 } // namespace content 2024 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698