| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 *video_type = MEDIA_DEVICE_VIDEO_CAPTURE; | 112 *video_type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Private helper method for SendMessageToNativeLog() that obtains the global | 117 // Private helper method for SendMessageToNativeLog() that obtains the global |
| 118 // MediaStreamManager instance on the UI thread before sending |message| to the | 118 // MediaStreamManager instance on the UI thread before sending |message| to the |
| 119 // webrtcLoggingPrivate API. | 119 // webrtcLoggingPrivate API. |
| 120 void DoAddLogMessage(const std::string& message) { | 120 void DoAddLogMessage(const std::string& message) { |
| 121 // Must be on the UI thread to access BrowserMainLoop. | 121 // Must be on the UI thread to access BrowserMainLoop. |
| 122 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 122 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 123 // May be null in tests. | 123 // May be null in tests. |
| 124 // TODO(vrk): Handle this more elegantly by having native log messages become | 124 // TODO(vrk): Handle this more elegantly by having native log messages become |
| 125 // no-ops until MediaStreamManager is aware that a renderer process has | 125 // no-ops until MediaStreamManager is aware that a renderer process has |
| 126 // started logging. crbug.com/333894 | 126 // started logging. crbug.com/333894 |
| 127 if (content::BrowserMainLoop::GetInstance()) { | 127 if (content::BrowserMainLoop::GetInstance()) { |
| 128 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
| 129 BrowserThread::IO, | 129 BrowserThread::IO, |
| 130 FROM_HERE, | 130 FROM_HERE, |
| 131 base::Bind(&MediaStreamManager::AddLogMessageOnIOThread, | 131 base::Bind(&MediaStreamManager::AddLogMessageOnIOThread, |
| 132 base::Unretained(content::BrowserMainLoop::GetInstance() | 132 base::Unretained(content::BrowserMainLoop::GetInstance() |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 361 } |
| 362 } | 362 } |
| 363 | 363 |
| 364 MediaStreamManager::~MediaStreamManager() { | 364 MediaStreamManager::~MediaStreamManager() { |
| 365 DVLOG(1) << "~MediaStreamManager"; | 365 DVLOG(1) << "~MediaStreamManager"; |
| 366 DCHECK(requests_.empty()); | 366 DCHECK(requests_.empty()); |
| 367 DCHECK(!device_task_runner_); | 367 DCHECK(!device_task_runner_); |
| 368 } | 368 } |
| 369 | 369 |
| 370 VideoCaptureManager* MediaStreamManager::video_capture_manager() { | 370 VideoCaptureManager* MediaStreamManager::video_capture_manager() { |
| 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 371 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 372 DCHECK(video_capture_manager_.get()); | 372 DCHECK(video_capture_manager_.get()); |
| 373 return video_capture_manager_.get(); | 373 return video_capture_manager_.get(); |
| 374 } | 374 } |
| 375 | 375 |
| 376 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { | 376 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { |
| 377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 377 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 378 DCHECK(audio_input_device_manager_.get()); | 378 DCHECK(audio_input_device_manager_.get()); |
| 379 return audio_input_device_manager_.get(); | 379 return audio_input_device_manager_.get(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 std::string MediaStreamManager::MakeMediaAccessRequest( | 382 std::string MediaStreamManager::MakeMediaAccessRequest( |
| 383 int render_process_id, | 383 int render_process_id, |
| 384 int render_view_id, | 384 int render_view_id, |
| 385 int page_request_id, | 385 int page_request_id, |
| 386 const StreamOptions& options, | 386 const StreamOptions& options, |
| 387 const GURL& security_origin, | 387 const GURL& security_origin, |
| 388 const MediaRequestResponseCallback& callback) { | 388 const MediaRequestResponseCallback& callback) { |
| 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 389 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 390 | 390 |
| 391 // TODO(perkj): The argument list with NULL parameters to DeviceRequest | 391 // TODO(perkj): The argument list with NULL parameters to DeviceRequest |
| 392 // suggests that this is the wrong design. Can this be refactored? | 392 // suggests that this is the wrong design. Can this be refactored? |
| 393 DeviceRequest* request = new DeviceRequest(NULL, | 393 DeviceRequest* request = new DeviceRequest(NULL, |
| 394 render_process_id, | 394 render_process_id, |
| 395 render_view_id, | 395 render_view_id, |
| 396 page_request_id, | 396 page_request_id, |
| 397 security_origin, | 397 security_origin, |
| 398 false, // user gesture | 398 false, // user gesture |
| 399 MEDIA_DEVICE_ACCESS, | 399 MEDIA_DEVICE_ACCESS, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 416 } | 416 } |
| 417 | 417 |
| 418 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, | 418 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, |
| 419 int render_process_id, | 419 int render_process_id, |
| 420 int render_view_id, | 420 int render_view_id, |
| 421 const ResourceContext::SaltCallback& sc, | 421 const ResourceContext::SaltCallback& sc, |
| 422 int page_request_id, | 422 int page_request_id, |
| 423 const StreamOptions& options, | 423 const StreamOptions& options, |
| 424 const GURL& security_origin, | 424 const GURL& security_origin, |
| 425 bool user_gesture) { | 425 bool user_gesture) { |
| 426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 426 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 427 DVLOG(1) << "GenerateStream()"; | 427 DVLOG(1) << "GenerateStream()"; |
| 428 if (CommandLine::ForCurrentProcess()->HasSwitch( | 428 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 429 switches::kUseFakeUIForMediaStream)) { | 429 switches::kUseFakeUIForMediaStream)) { |
| 430 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); | 430 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); |
| 431 } | 431 } |
| 432 | 432 |
| 433 DeviceRequest* request = new DeviceRequest(requester, | 433 DeviceRequest* request = new DeviceRequest(requester, |
| 434 render_process_id, | 434 render_process_id, |
| 435 render_view_id, | 435 render_view_id, |
| 436 page_request_id, | 436 page_request_id, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 463 request->requesting_view_id == render_view_id && | 463 request->requesting_view_id == render_view_id && |
| 464 request->page_request_id == page_request_id) { | 464 request->page_request_id == page_request_id) { |
| 465 CancelRequest(request_it->first); | 465 CancelRequest(request_it->first); |
| 466 return; | 466 return; |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 NOTREACHED(); | 469 NOTREACHED(); |
| 470 } | 470 } |
| 471 | 471 |
| 472 void MediaStreamManager::CancelRequest(const std::string& label) { | 472 void MediaStreamManager::CancelRequest(const std::string& label) { |
| 473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 473 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 474 DVLOG(1) << "CancelRequest({label = " << label << "})"; | 474 DVLOG(1) << "CancelRequest({label = " << label << "})"; |
| 475 DeviceRequest* request = FindRequest(label); | 475 DeviceRequest* request = FindRequest(label); |
| 476 if (!request) { | 476 if (!request) { |
| 477 // The request does not exist. | 477 // The request does not exist. |
| 478 LOG(ERROR) << "The request with label = " << label << " does not exist."; | 478 LOG(ERROR) << "The request with label = " << label << " does not exist."; |
| 479 return; | 479 return; |
| 480 } | 480 } |
| 481 | 481 |
| 482 if (request->request_type == MEDIA_ENUMERATE_DEVICES) { | 482 if (request->request_type == MEDIA_ENUMERATE_DEVICES) { |
| 483 // It isn't an ideal use of "CancelRequest" to make it a requirement | 483 // It isn't an ideal use of "CancelRequest" to make it a requirement |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 517 |
| 518 std::string label = request_it->first; | 518 std::string label = request_it->first; |
| 519 ++request_it; | 519 ++request_it; |
| 520 CancelRequest(label); | 520 CancelRequest(label); |
| 521 } | 521 } |
| 522 } | 522 } |
| 523 | 523 |
| 524 void MediaStreamManager::StopStreamDevice(int render_process_id, | 524 void MediaStreamManager::StopStreamDevice(int render_process_id, |
| 525 int render_view_id, | 525 int render_view_id, |
| 526 const std::string& device_id) { | 526 const std::string& device_id) { |
| 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 527 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 528 DVLOG(1) << "StopStreamDevice({render_view_id = " << render_view_id << "} " | 528 DVLOG(1) << "StopStreamDevice({render_view_id = " << render_view_id << "} " |
| 529 << ", {device_id = " << device_id << "})"; | 529 << ", {device_id = " << device_id << "})"; |
| 530 // Find the first request for this |render_process_id| and |render_view_id| | 530 // Find the first request for this |render_process_id| and |render_view_id| |
| 531 // of type MEDIA_GENERATE_STREAM that has requested to use |device_id| and | 531 // of type MEDIA_GENERATE_STREAM that has requested to use |device_id| and |
| 532 // stop it. | 532 // stop it. |
| 533 for (DeviceRequests::iterator request_it = requests_.begin(); | 533 for (DeviceRequests::iterator request_it = requests_.begin(); |
| 534 request_it != requests_.end(); ++request_it) { | 534 request_it != requests_.end(); ++request_it) { |
| 535 DeviceRequest* request = request_it->second; | 535 DeviceRequest* request = request_it->second; |
| 536 if (request->requesting_process_id != render_process_id || | 536 if (request->requesting_process_id != render_process_id || |
| 537 request->requesting_view_id != render_view_id || | 537 request->requesting_view_id != render_view_id || |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 } | 611 } |
| 612 | 612 |
| 613 std::string MediaStreamManager::EnumerateDevices( | 613 std::string MediaStreamManager::EnumerateDevices( |
| 614 MediaStreamRequester* requester, | 614 MediaStreamRequester* requester, |
| 615 int render_process_id, | 615 int render_process_id, |
| 616 int render_view_id, | 616 int render_view_id, |
| 617 const ResourceContext::SaltCallback& sc, | 617 const ResourceContext::SaltCallback& sc, |
| 618 int page_request_id, | 618 int page_request_id, |
| 619 MediaStreamType type, | 619 MediaStreamType type, |
| 620 const GURL& security_origin) { | 620 const GURL& security_origin) { |
| 621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 621 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 622 DCHECK(requester); | 622 DCHECK(requester); |
| 623 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 623 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 624 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 624 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
| 625 | 625 |
| 626 DeviceRequest* request = new DeviceRequest(requester, | 626 DeviceRequest* request = new DeviceRequest(requester, |
| 627 render_process_id, | 627 render_process_id, |
| 628 render_view_id, | 628 render_view_id, |
| 629 page_request_id, | 629 page_request_id, |
| 630 security_origin, | 630 security_origin, |
| 631 false, // user gesture | 631 false, // user gesture |
| (...skipping 12 matching lines...) Expand all Loading... |
| 644 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 644 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
| 645 // been stopped. | 645 // been stopped. |
| 646 BrowserThread::PostTask( | 646 BrowserThread::PostTask( |
| 647 BrowserThread::IO, FROM_HERE, | 647 BrowserThread::IO, FROM_HERE, |
| 648 base::Bind(&MediaStreamManager::DoEnumerateDevices, | 648 base::Bind(&MediaStreamManager::DoEnumerateDevices, |
| 649 base::Unretained(this), label)); | 649 base::Unretained(this), label)); |
| 650 return label; | 650 return label; |
| 651 } | 651 } |
| 652 | 652 |
| 653 void MediaStreamManager::DoEnumerateDevices(const std::string& label) { | 653 void MediaStreamManager::DoEnumerateDevices(const std::string& label) { |
| 654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 654 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 655 DeviceRequest* request = FindRequest(label); | 655 DeviceRequest* request = FindRequest(label); |
| 656 if (!request) | 656 if (!request) |
| 657 return; // This can happen if the request has been canceled. | 657 return; // This can happen if the request has been canceled. |
| 658 | 658 |
| 659 MediaStreamType type; | 659 MediaStreamType type; |
| 660 EnumerationCache* cache; | 660 EnumerationCache* cache; |
| 661 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE) { | 661 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 662 DCHECK_EQ(MEDIA_NO_SERVICE, request->video_type()); | 662 DCHECK_EQ(MEDIA_NO_SERVICE, request->video_type()); |
| 663 type = MEDIA_DEVICE_AUDIO_CAPTURE; | 663 type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 664 cache = &audio_enumeration_cache_; | 664 cache = &audio_enumeration_cache_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 680 } | 680 } |
| 681 | 681 |
| 682 void MediaStreamManager::OpenDevice(MediaStreamRequester* requester, | 682 void MediaStreamManager::OpenDevice(MediaStreamRequester* requester, |
| 683 int render_process_id, | 683 int render_process_id, |
| 684 int render_view_id, | 684 int render_view_id, |
| 685 const ResourceContext::SaltCallback& sc, | 685 const ResourceContext::SaltCallback& sc, |
| 686 int page_request_id, | 686 int page_request_id, |
| 687 const std::string& device_id, | 687 const std::string& device_id, |
| 688 MediaStreamType type, | 688 MediaStreamType type, |
| 689 const GURL& security_origin) { | 689 const GURL& security_origin) { |
| 690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 690 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 691 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 691 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 692 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 692 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
| 693 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; | 693 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; |
| 694 StreamOptions options; | 694 StreamOptions options; |
| 695 if (IsAudioMediaType(type)) { | 695 if (IsAudioMediaType(type)) { |
| 696 options.audio_requested = true; | 696 options.audio_requested = true; |
| 697 options.mandatory_audio.push_back( | 697 options.mandatory_audio.push_back( |
| 698 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); | 698 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); |
| 699 } else if (IsVideoMediaType(type)) { | 699 } else if (IsVideoMediaType(type)) { |
| 700 options.video_requested = true; | 700 options.video_requested = true; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 719 // and thus can not handle a response. Using base::Unretained is safe since | 719 // and thus can not handle a response. Using base::Unretained is safe since |
| 720 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 720 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
| 721 // been stopped. | 721 // been stopped. |
| 722 BrowserThread::PostTask( | 722 BrowserThread::PostTask( |
| 723 BrowserThread::IO, FROM_HERE, | 723 BrowserThread::IO, FROM_HERE, |
| 724 base::Bind(&MediaStreamManager::SetupRequest, | 724 base::Bind(&MediaStreamManager::SetupRequest, |
| 725 base::Unretained(this), label)); | 725 base::Unretained(this), label)); |
| 726 } | 726 } |
| 727 | 727 |
| 728 void MediaStreamManager::EnsureDeviceMonitorStarted() { | 728 void MediaStreamManager::EnsureDeviceMonitorStarted() { |
| 729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 729 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 730 StartMonitoring(); | 730 StartMonitoring(); |
| 731 } | 731 } |
| 732 | 732 |
| 733 void MediaStreamManager::StopRemovedDevices( | 733 void MediaStreamManager::StopRemovedDevices( |
| 734 const StreamDeviceInfoArray& old_devices, | 734 const StreamDeviceInfoArray& old_devices, |
| 735 const StreamDeviceInfoArray& new_devices) { | 735 const StreamDeviceInfoArray& new_devices) { |
| 736 DVLOG(1) << "StopRemovedDevices(" | 736 DVLOG(1) << "StopRemovedDevices(" |
| 737 << "{#old_devices = " << old_devices.size() << "} " | 737 << "{#old_devices = " << old_devices.size() << "} " |
| 738 << "{#new_devices = " << new_devices.size() << "})"; | 738 << "{#new_devices = " << new_devices.size() << "})"; |
| 739 for (StreamDeviceInfoArray::const_iterator old_dev_it = old_devices.begin(); | 739 for (StreamDeviceInfoArray::const_iterator old_dev_it = old_devices.begin(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 } | 779 } |
| 780 } | 780 } |
| 781 } | 781 } |
| 782 for (std::vector<int>::const_iterator it = session_ids.begin(); | 782 for (std::vector<int>::const_iterator it = session_ids.begin(); |
| 783 it != session_ids.end(); ++it) { | 783 it != session_ids.end(); ++it) { |
| 784 StopDevice(device.type, *it); | 784 StopDevice(device.type, *it); |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 | 787 |
| 788 void MediaStreamManager::StartMonitoring() { | 788 void MediaStreamManager::StartMonitoring() { |
| 789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 789 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 790 if (monitoring_started_) | 790 if (monitoring_started_) |
| 791 return; | 791 return; |
| 792 | 792 |
| 793 if (!base::SystemMonitor::Get()) | 793 if (!base::SystemMonitor::Get()) |
| 794 return; | 794 return; |
| 795 | 795 |
| 796 monitoring_started_ = true; | 796 monitoring_started_ = true; |
| 797 base::SystemMonitor::Get()->AddDevicesChangedObserver(this); | 797 base::SystemMonitor::Get()->AddDevicesChangedObserver(this); |
| 798 | 798 |
| 799 // Enumerate both the audio and video devices to cache the device lists | 799 // Enumerate both the audio and video devices to cache the device lists |
| 800 // and send them to media observer. | 800 // and send them to media observer. |
| 801 ++active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_CAPTURE]; | 801 ++active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_CAPTURE]; |
| 802 audio_input_device_manager_->EnumerateDevices(MEDIA_DEVICE_AUDIO_CAPTURE); | 802 audio_input_device_manager_->EnumerateDevices(MEDIA_DEVICE_AUDIO_CAPTURE); |
| 803 ++active_enumeration_ref_count_[MEDIA_DEVICE_VIDEO_CAPTURE]; | 803 ++active_enumeration_ref_count_[MEDIA_DEVICE_VIDEO_CAPTURE]; |
| 804 video_capture_manager_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 804 video_capture_manager_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 805 | 805 |
| 806 #if defined(OS_MACOSX) | 806 #if defined(OS_MACOSX) |
| 807 BrowserThread::PostTask( | 807 BrowserThread::PostTask( |
| 808 BrowserThread::UI, FROM_HERE, | 808 BrowserThread::UI, FROM_HERE, |
| 809 base::Bind(&MediaStreamManager::StartMonitoringOnUIThread, | 809 base::Bind(&MediaStreamManager::StartMonitoringOnUIThread, |
| 810 base::Unretained(this))); | 810 base::Unretained(this))); |
| 811 #endif | 811 #endif |
| 812 } | 812 } |
| 813 | 813 |
| 814 #if defined(OS_MACOSX) | 814 #if defined(OS_MACOSX) |
| 815 void MediaStreamManager::StartMonitoringOnUIThread() { | 815 void MediaStreamManager::StartMonitoringOnUIThread() { |
| 816 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 816 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 817 BrowserMainLoop* browser_main_loop = content::BrowserMainLoop::GetInstance(); | 817 BrowserMainLoop* browser_main_loop = content::BrowserMainLoop::GetInstance(); |
| 818 if (browser_main_loop) | 818 if (browser_main_loop) |
| 819 browser_main_loop->device_monitor_mac()->StartMonitoring(); | 819 browser_main_loop->device_monitor_mac()->StartMonitoring(); |
| 820 } | 820 } |
| 821 #endif | 821 #endif |
| 822 | 822 |
| 823 void MediaStreamManager::StopMonitoring() { | 823 void MediaStreamManager::StopMonitoring() { |
| 824 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 824 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
| 825 if (monitoring_started_) { | 825 if (monitoring_started_) { |
| 826 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); | 826 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 // Make sure the cache is marked as invalid so that FinalizeEnumerateDevices | 951 // Make sure the cache is marked as invalid so that FinalizeEnumerateDevices |
| 952 // will be called at the end of the enumeration. | 952 // will be called at the end of the enumeration. |
| 953 ClearEnumerationCache(cache); | 953 ClearEnumerationCache(cache); |
| 954 } | 954 } |
| 955 #endif | 955 #endif |
| 956 // If the cache isn't valid, we need to start a full enumeration. | 956 // If the cache isn't valid, we need to start a full enumeration. |
| 957 return !cache->valid; | 957 return !cache->valid; |
| 958 } | 958 } |
| 959 | 959 |
| 960 void MediaStreamManager::StartEnumeration(DeviceRequest* request) { | 960 void MediaStreamManager::StartEnumeration(DeviceRequest* request) { |
| 961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 961 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 962 | 962 |
| 963 // Start monitoring the devices when doing the first enumeration. | 963 // Start monitoring the devices when doing the first enumeration. |
| 964 StartMonitoring(); | 964 StartMonitoring(); |
| 965 | 965 |
| 966 // Start enumeration for devices of all requested device types. | 966 // Start enumeration for devices of all requested device types. |
| 967 const MediaStreamType streams[] = { request->audio_type(), | 967 const MediaStreamType streams[] = { request->audio_type(), |
| 968 request->video_type() }; | 968 request->video_type() }; |
| 969 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(streams); ++i) { | 969 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(streams); ++i) { |
| 970 if (streams[i] == MEDIA_NO_SERVICE) | 970 if (streams[i] == MEDIA_NO_SERVICE) |
| 971 continue; | 971 continue; |
| 972 request->SetState(streams[i], MEDIA_REQUEST_STATE_REQUESTED); | 972 request->SetState(streams[i], MEDIA_REQUEST_STATE_REQUESTED); |
| 973 DCHECK_GE(active_enumeration_ref_count_[streams[i]], 0); | 973 DCHECK_GE(active_enumeration_ref_count_[streams[i]], 0); |
| 974 if (active_enumeration_ref_count_[streams[i]] == 0) { | 974 if (active_enumeration_ref_count_[streams[i]] == 0) { |
| 975 ++active_enumeration_ref_count_[streams[i]]; | 975 ++active_enumeration_ref_count_[streams[i]]; |
| 976 GetDeviceManager(streams[i])->EnumerateDevices(streams[i]); | 976 GetDeviceManager(streams[i])->EnumerateDevices(streams[i]); |
| 977 } | 977 } |
| 978 } | 978 } |
| 979 } | 979 } |
| 980 | 980 |
| 981 std::string MediaStreamManager::AddRequest(DeviceRequest* request) { | 981 std::string MediaStreamManager::AddRequest(DeviceRequest* request) { |
| 982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 982 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 983 | 983 |
| 984 // Create a label for this request and verify it is unique. | 984 // Create a label for this request and verify it is unique. |
| 985 std::string unique_label; | 985 std::string unique_label; |
| 986 do { | 986 do { |
| 987 unique_label = RandomLabel(); | 987 unique_label = RandomLabel(); |
| 988 } while (requests_.find(unique_label) != requests_.end()); | 988 } while (requests_.find(unique_label) != requests_.end()); |
| 989 | 989 |
| 990 requests_.insert(std::make_pair(unique_label, request)); | 990 requests_.insert(std::make_pair(unique_label, request)); |
| 991 | 991 |
| 992 return unique_label; | 992 return unique_label; |
| 993 } | 993 } |
| 994 | 994 |
| 995 MediaStreamManager::DeviceRequest* | 995 MediaStreamManager::DeviceRequest* |
| 996 MediaStreamManager::FindRequest(const std::string& label) const { | 996 MediaStreamManager::FindRequest(const std::string& label) const { |
| 997 DeviceRequests::const_iterator request_it = requests_.find(label); | 997 DeviceRequests::const_iterator request_it = requests_.find(label); |
| 998 return request_it == requests_.end() ? NULL : request_it->second; | 998 return request_it == requests_.end() ? NULL : request_it->second; |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 void MediaStreamManager::DeleteRequest(const std::string& label) { | 1001 void MediaStreamManager::DeleteRequest(const std::string& label) { |
| 1002 DVLOG(1) << "DeleteRequest({label= " << label << "})"; | 1002 DVLOG(1) << "DeleteRequest({label= " << label << "})"; |
| 1003 DeviceRequests::iterator it = requests_.find(label); | 1003 DeviceRequests::iterator it = requests_.find(label); |
| 1004 scoped_ptr<DeviceRequest> request(it->second); | 1004 scoped_ptr<DeviceRequest> request(it->second); |
| 1005 requests_.erase(it); | 1005 requests_.erase(it); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 void MediaStreamManager::PostRequestToUI(const std::string& label, | 1008 void MediaStreamManager::PostRequestToUI(const std::string& label, |
| 1009 DeviceRequest* request) { | 1009 DeviceRequest* request) { |
| 1010 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1010 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1011 DCHECK(request->UIRequest()); | 1011 DCHECK(request->UIRequest()); |
| 1012 DVLOG(1) << "PostRequestToUI({label= " << label << "})"; | 1012 DVLOG(1) << "PostRequestToUI({label= " << label << "})"; |
| 1013 | 1013 |
| 1014 const MediaStreamType audio_type = request->audio_type(); | 1014 const MediaStreamType audio_type = request->audio_type(); |
| 1015 const MediaStreamType video_type = request->video_type(); | 1015 const MediaStreamType video_type = request->video_type(); |
| 1016 | 1016 |
| 1017 // Post the request to UI and set the state. | 1017 // Post the request to UI and set the state. |
| 1018 if (IsAudioMediaType(audio_type)) | 1018 if (IsAudioMediaType(audio_type)) |
| 1019 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 1019 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
| 1020 if (IsVideoMediaType(video_type)) | 1020 if (IsVideoMediaType(video_type)) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1047 request->ui_proxy = MediaStreamUIProxy::Create(); | 1047 request->ui_proxy = MediaStreamUIProxy::Create(); |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 request->ui_proxy->RequestAccess( | 1050 request->ui_proxy->RequestAccess( |
| 1051 *request->UIRequest(), | 1051 *request->UIRequest(), |
| 1052 base::Bind(&MediaStreamManager::HandleAccessRequestResponse, | 1052 base::Bind(&MediaStreamManager::HandleAccessRequestResponse, |
| 1053 base::Unretained(this), label)); | 1053 base::Unretained(this), label)); |
| 1054 } | 1054 } |
| 1055 | 1055 |
| 1056 void MediaStreamManager::SetupRequest(const std::string& label) { | 1056 void MediaStreamManager::SetupRequest(const std::string& label) { |
| 1057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1057 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1058 DeviceRequest* request = FindRequest(label); | 1058 DeviceRequest* request = FindRequest(label); |
| 1059 if (!request) { | 1059 if (!request) { |
| 1060 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!"; | 1060 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!"; |
| 1061 return; // This can happen if the request has been canceled. | 1061 return; // This can happen if the request has been canceled. |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 if (!request->security_origin.is_valid()) { | 1064 if (!request->security_origin.is_valid()) { |
| 1065 LOG(ERROR) << "Invalid security origin. " | 1065 LOG(ERROR) << "Invalid security origin. " |
| 1066 << request->security_origin; | 1066 << request->security_origin; |
| 1067 FinalizeRequestFailed(label, | 1067 FinalizeRequestFailed(label, |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, | 1332 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, |
| 1333 DeviceRequest* request) { | 1333 DeviceRequest* request) { |
| 1334 const StreamDeviceInfoArray& requested_devices = request->devices; | 1334 const StreamDeviceInfoArray& requested_devices = request->devices; |
| 1335 request->requester->DeviceOpened(request->requesting_view_id, | 1335 request->requester->DeviceOpened(request->requesting_view_id, |
| 1336 request->page_request_id, | 1336 request->page_request_id, |
| 1337 label, requested_devices.front()); | 1337 label, requested_devices.front()); |
| 1338 } | 1338 } |
| 1339 | 1339 |
| 1340 void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label, | 1340 void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label, |
| 1341 DeviceRequest* request) { | 1341 DeviceRequest* request) { |
| 1342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1342 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1343 DCHECK_EQ(request->request_type, MEDIA_ENUMERATE_DEVICES); | 1343 DCHECK_EQ(request->request_type, MEDIA_ENUMERATE_DEVICES); |
| 1344 | 1344 |
| 1345 if (request->security_origin.is_valid()) { | 1345 if (request->security_origin.is_valid()) { |
| 1346 for (StreamDeviceInfoArray::iterator it = request->devices.begin(); | 1346 for (StreamDeviceInfoArray::iterator it = request->devices.begin(); |
| 1347 it != request->devices.end(); ++it) { | 1347 it != request->devices.end(); ++it) { |
| 1348 TranslateDeviceIdToSourceId(request, &it->device); | 1348 TranslateDeviceIdToSourceId(request, &it->device); |
| 1349 } | 1349 } |
| 1350 } else { | 1350 } else { |
| 1351 request->devices.clear(); | 1351 request->devices.clear(); |
| 1352 } | 1352 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 DeviceRequest* request, | 1392 DeviceRequest* request, |
| 1393 const MediaStreamDevices& devices) { | 1393 const MediaStreamDevices& devices) { |
| 1394 if (!request->callback.is_null()) | 1394 if (!request->callback.is_null()) |
| 1395 request->callback.Run(devices, request->ui_proxy.Pass()); | 1395 request->callback.Run(devices, request->ui_proxy.Pass()); |
| 1396 | 1396 |
| 1397 // Delete the request since it is done. | 1397 // Delete the request since it is done. |
| 1398 DeleteRequest(label); | 1398 DeleteRequest(label); |
| 1399 } | 1399 } |
| 1400 | 1400 |
| 1401 void MediaStreamManager::InitializeDeviceManagersOnIOThread() { | 1401 void MediaStreamManager::InitializeDeviceManagersOnIOThread() { |
| 1402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1402 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1403 if (device_task_runner_) | 1403 if (device_task_runner_) |
| 1404 return; | 1404 return; |
| 1405 | 1405 |
| 1406 device_task_runner_ = audio_manager_->GetWorkerTaskRunner(); | 1406 device_task_runner_ = audio_manager_->GetWorkerTaskRunner(); |
| 1407 | 1407 |
| 1408 audio_input_device_manager_ = new AudioInputDeviceManager(audio_manager_); | 1408 audio_input_device_manager_ = new AudioInputDeviceManager(audio_manager_); |
| 1409 audio_input_device_manager_->Register(this, device_task_runner_); | 1409 audio_input_device_manager_->Register(this, device_task_runner_); |
| 1410 | 1410 |
| 1411 video_capture_manager_ = new VideoCaptureManager(); | 1411 video_capture_manager_ = new VideoCaptureManager(); |
| 1412 video_capture_manager_->Register(this, device_task_runner_); | 1412 video_capture_manager_->Register(this, device_task_runner_); |
| 1413 | 1413 |
| 1414 // We want to be notified of IO message loop destruction to delete the thread | 1414 // We want to be notified of IO message loop destruction to delete the thread |
| 1415 // and the device managers. | 1415 // and the device managers. |
| 1416 io_loop_ = base::MessageLoop::current(); | 1416 io_loop_ = base::MessageLoop::current(); |
| 1417 io_loop_->AddDestructionObserver(this); | 1417 io_loop_->AddDestructionObserver(this); |
| 1418 | 1418 |
| 1419 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1419 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1420 switches::kUseFakeDeviceForMediaStream)) { | 1420 switches::kUseFakeDeviceForMediaStream)) { |
| 1421 DVLOG(1) << "Using fake device"; | 1421 DVLOG(1) << "Using fake device"; |
| 1422 UseFakeDevice(); | 1422 UseFakeDevice(); |
| 1423 } | 1423 } |
| 1424 } | 1424 } |
| 1425 | 1425 |
| 1426 void MediaStreamManager::Opened(MediaStreamType stream_type, | 1426 void MediaStreamManager::Opened(MediaStreamType stream_type, |
| 1427 int capture_session_id) { | 1427 int capture_session_id) { |
| 1428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1428 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1429 DVLOG(1) << "Opened({stream_type = " << stream_type << "} " | 1429 DVLOG(1) << "Opened({stream_type = " << stream_type << "} " |
| 1430 << "{capture_session_id = " << capture_session_id << "})"; | 1430 << "{capture_session_id = " << capture_session_id << "})"; |
| 1431 // Find the request(s) containing this device and mark it as used. | 1431 // Find the request(s) containing this device and mark it as used. |
| 1432 // It can be used in several requests since the same device can be | 1432 // It can be used in several requests since the same device can be |
| 1433 // requested from the same web page. | 1433 // requested from the same web page. |
| 1434 for (DeviceRequests::iterator request_it = requests_.begin(); | 1434 for (DeviceRequests::iterator request_it = requests_.begin(); |
| 1435 request_it != requests_.end(); ++request_it) { | 1435 request_it != requests_.end(); ++request_it) { |
| 1436 const std::string& label = request_it->first; | 1436 const std::string& label = request_it->first; |
| 1437 DeviceRequest* request = request_it->second; | 1437 DeviceRequest* request = request_it->second; |
| 1438 StreamDeviceInfoArray* devices = &(request->devices); | 1438 StreamDeviceInfoArray* devices = &(request->devices); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 label), | 1491 label), |
| 1492 base::Bind(&MediaStreamManager::OnMediaStreamUIWindowId, | 1492 base::Bind(&MediaStreamManager::OnMediaStreamUIWindowId, |
| 1493 base::Unretained(this), | 1493 base::Unretained(this), |
| 1494 request->video_type(), | 1494 request->video_type(), |
| 1495 request->devices)); | 1495 request->devices)); |
| 1496 } | 1496 } |
| 1497 } | 1497 } |
| 1498 | 1498 |
| 1499 void MediaStreamManager::Closed(MediaStreamType stream_type, | 1499 void MediaStreamManager::Closed(MediaStreamType stream_type, |
| 1500 int capture_session_id) { | 1500 int capture_session_id) { |
| 1501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1501 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 void MediaStreamManager::DevicesEnumerated( | 1504 void MediaStreamManager::DevicesEnumerated( |
| 1505 MediaStreamType stream_type, const StreamDeviceInfoArray& devices) { | 1505 MediaStreamType stream_type, const StreamDeviceInfoArray& devices) { |
| 1506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1506 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1507 DVLOG(1) << "DevicesEnumerated(" | 1507 DVLOG(1) << "DevicesEnumerated(" |
| 1508 << "{stream_type = " << stream_type << "})" << std::endl; | 1508 << "{stream_type = " << stream_type << "})" << std::endl; |
| 1509 | 1509 |
| 1510 std::string log_message = "New device enumeration result:\n" + | 1510 std::string log_message = "New device enumeration result:\n" + |
| 1511 GetLogMessageString(stream_type, devices); | 1511 GetLogMessageString(stream_type, devices); |
| 1512 SendMessageToNativeLog(log_message); | 1512 SendMessageToNativeLog(log_message); |
| 1513 | 1513 |
| 1514 // Only cache the device list when the device list has been changed. | 1514 // Only cache the device list when the device list has been changed. |
| 1515 bool need_update_clients = false; | 1515 bool need_update_clients = false; |
| 1516 EnumerationCache* cache = | 1516 EnumerationCache* cache = |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 | 1587 |
| 1588 // static | 1588 // static |
| 1589 void MediaStreamManager::SendMessageToNativeLog(const std::string& message) { | 1589 void MediaStreamManager::SendMessageToNativeLog(const std::string& message) { |
| 1590 BrowserThread::PostTask( | 1590 BrowserThread::PostTask( |
| 1591 BrowserThread::UI, FROM_HERE, | 1591 BrowserThread::UI, FROM_HERE, |
| 1592 base::Bind(DoAddLogMessage, message)); | 1592 base::Bind(DoAddLogMessage, message)); |
| 1593 } | 1593 } |
| 1594 | 1594 |
| 1595 void MediaStreamManager::AddLogMessageOnIOThread(const std::string& message) { | 1595 void MediaStreamManager::AddLogMessageOnIOThread(const std::string& message) { |
| 1596 // Get render process ids on the IO thread. | 1596 // Get render process ids on the IO thread. |
| 1597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1597 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1598 | 1598 |
| 1599 // Grab all unique process ids that request a MediaStream or have a | 1599 // Grab all unique process ids that request a MediaStream or have a |
| 1600 // MediaStream running. | 1600 // MediaStream running. |
| 1601 std::set<int> requesting_process_ids; | 1601 std::set<int> requesting_process_ids; |
| 1602 for (DeviceRequests::const_iterator it = requests_.begin(); | 1602 for (DeviceRequests::const_iterator it = requests_.begin(); |
| 1603 it != requests_.end(); ++it) { | 1603 it != requests_.end(); ++it) { |
| 1604 DeviceRequest* request = it->second; | 1604 DeviceRequest* request = it->second; |
| 1605 if (request->request_type == MEDIA_GENERATE_STREAM) | 1605 if (request->request_type == MEDIA_GENERATE_STREAM) |
| 1606 requesting_process_ids.insert(request->requesting_process_id); | 1606 requesting_process_ids.insert(request->requesting_process_id); |
| 1607 } | 1607 } |
| 1608 | 1608 |
| 1609 // MediaStreamManager is a singleton in BrowserMainLoop, which owns the UI | 1609 // MediaStreamManager is a singleton in BrowserMainLoop, which owns the UI |
| 1610 // thread. MediaStreamManager has the same lifetime as the UI thread, so it is | 1610 // thread. MediaStreamManager has the same lifetime as the UI thread, so it is |
| 1611 // safe to use base::Unretained. | 1611 // safe to use base::Unretained. |
| 1612 BrowserThread::PostTask( | 1612 BrowserThread::PostTask( |
| 1613 BrowserThread::UI, | 1613 BrowserThread::UI, |
| 1614 FROM_HERE, | 1614 FROM_HERE, |
| 1615 base::Bind(&MediaStreamManager::AddLogMessageOnUIThread, | 1615 base::Bind(&MediaStreamManager::AddLogMessageOnUIThread, |
| 1616 base::Unretained(this), | 1616 base::Unretained(this), |
| 1617 requesting_process_ids, | 1617 requesting_process_ids, |
| 1618 message)); | 1618 message)); |
| 1619 } | 1619 } |
| 1620 | 1620 |
| 1621 void MediaStreamManager::AddLogMessageOnUIThread( | 1621 void MediaStreamManager::AddLogMessageOnUIThread( |
| 1622 const std::set<int>& requesting_process_ids, | 1622 const std::set<int>& requesting_process_ids, |
| 1623 const std::string& message) { | 1623 const std::string& message) { |
| 1624 #if defined(ENABLE_WEBRTC) | 1624 #if defined(ENABLE_WEBRTC) |
| 1625 // Must be on the UI thread to access RenderProcessHost from process ID. | 1625 // Must be on the UI thread to access RenderProcessHost from process ID. |
| 1626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1626 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1627 | 1627 |
| 1628 for (std::set<int>::const_iterator it = requesting_process_ids.begin(); | 1628 for (std::set<int>::const_iterator it = requesting_process_ids.begin(); |
| 1629 it != requesting_process_ids.end(); ++it) { | 1629 it != requesting_process_ids.end(); ++it) { |
| 1630 // Log the message to all renderers that are requesting a MediaStream or | 1630 // Log the message to all renderers that are requesting a MediaStream or |
| 1631 // have a MediaStream running. | 1631 // have a MediaStream running. |
| 1632 content::RenderProcessHostImpl* render_process_host_impl = | 1632 content::RenderProcessHostImpl* render_process_host_impl = |
| 1633 static_cast<content::RenderProcessHostImpl*>( | 1633 static_cast<content::RenderProcessHostImpl*>( |
| 1634 content::RenderProcessHost::FromID(*it)); | 1634 content::RenderProcessHost::FromID(*it)); |
| 1635 if (render_process_host_impl) | 1635 if (render_process_host_impl) |
| 1636 render_process_host_impl->WebRtcLogMessage(message); | 1636 render_process_host_impl->WebRtcLogMessage(message); |
| 1637 } | 1637 } |
| 1638 #endif | 1638 #endif |
| 1639 } | 1639 } |
| 1640 | 1640 |
| 1641 void MediaStreamManager::HandleAccessRequestResponse( | 1641 void MediaStreamManager::HandleAccessRequestResponse( |
| 1642 const std::string& label, | 1642 const std::string& label, |
| 1643 const MediaStreamDevices& devices, | 1643 const MediaStreamDevices& devices, |
| 1644 content::MediaStreamRequestResult result) { | 1644 content::MediaStreamRequestResult result) { |
| 1645 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1645 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1646 DVLOG(1) << "HandleAccessRequestResponse(" | 1646 DVLOG(1) << "HandleAccessRequestResponse(" |
| 1647 << ", {label = " << label << "})"; | 1647 << ", {label = " << label << "})"; |
| 1648 | 1648 |
| 1649 DeviceRequest* request = FindRequest(label); | 1649 DeviceRequest* request = FindRequest(label); |
| 1650 if (!request) { | 1650 if (!request) { |
| 1651 // The request has been canceled before the UI returned. | 1651 // The request has been canceled before the UI returned. |
| 1652 return; | 1652 return; |
| 1653 } | 1653 } |
| 1654 | 1654 |
| 1655 if (request->request_type == MEDIA_DEVICE_ACCESS) { | 1655 if (request->request_type == MEDIA_DEVICE_ACCESS) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 } | 1737 } |
| 1738 | 1738 |
| 1739 if (!found_video && IsVideoMediaType(request->video_type())) | 1739 if (!found_video && IsVideoMediaType(request->video_type())) |
| 1740 request->SetState(request->video_type(), MEDIA_REQUEST_STATE_ERROR); | 1740 request->SetState(request->video_type(), MEDIA_REQUEST_STATE_ERROR); |
| 1741 | 1741 |
| 1742 if (RequestDone(*request)) | 1742 if (RequestDone(*request)) |
| 1743 HandleRequestDone(label, request); | 1743 HandleRequestDone(label, request); |
| 1744 } | 1744 } |
| 1745 | 1745 |
| 1746 void MediaStreamManager::StopMediaStreamFromBrowser(const std::string& label) { | 1746 void MediaStreamManager::StopMediaStreamFromBrowser(const std::string& label) { |
| 1747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1747 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1748 | 1748 |
| 1749 DeviceRequest* request = FindRequest(label); | 1749 DeviceRequest* request = FindRequest(label); |
| 1750 if (!request) | 1750 if (!request) |
| 1751 return; | 1751 return; |
| 1752 | 1752 |
| 1753 // Notify renderers that the devices in the stream will be stopped. | 1753 // Notify renderers that the devices in the stream will be stopped. |
| 1754 if (request->requester) { | 1754 if (request->requester) { |
| 1755 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); | 1755 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); |
| 1756 device_it != request->devices.end(); ++device_it) { | 1756 device_it != request->devices.end(); ++device_it) { |
| 1757 request->requester->DeviceStopped(request->requesting_view_id, | 1757 request->requester->DeviceStopped(request->requesting_view_id, |
| 1758 label, | 1758 label, |
| 1759 *device_it); | 1759 *device_it); |
| 1760 } | 1760 } |
| 1761 } | 1761 } |
| 1762 | 1762 |
| 1763 CancelRequest(label); | 1763 CancelRequest(label); |
| 1764 } | 1764 } |
| 1765 | 1765 |
| 1766 void MediaStreamManager::UseFakeDevice() { | 1766 void MediaStreamManager::UseFakeDevice() { |
| 1767 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1767 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1768 video_capture_manager()->UseFakeDevice(); | 1768 video_capture_manager()->UseFakeDevice(); |
| 1769 audio_input_device_manager()->UseFakeDevice(); | 1769 audio_input_device_manager()->UseFakeDevice(); |
| 1770 } | 1770 } |
| 1771 | 1771 |
| 1772 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { | 1772 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { |
| 1773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1773 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1774 use_fake_ui_ = true; | 1774 use_fake_ui_ = true; |
| 1775 fake_ui_ = fake_ui.Pass(); | 1775 fake_ui_ = fake_ui.Pass(); |
| 1776 } | 1776 } |
| 1777 | 1777 |
| 1778 void MediaStreamManager::WillDestroyCurrentMessageLoop() { | 1778 void MediaStreamManager::WillDestroyCurrentMessageLoop() { |
| 1779 DVLOG(3) << "MediaStreamManager::WillDestroyCurrentMessageLoop()"; | 1779 DVLOG(3) << "MediaStreamManager::WillDestroyCurrentMessageLoop()"; |
| 1780 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 1780 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
| 1781 DCHECK(requests_.empty()); | 1781 DCHECK(requests_.empty()); |
| 1782 if (device_task_runner_) { | 1782 if (device_task_runner_) { |
| 1783 StopMonitoring(); | 1783 StopMonitoring(); |
| 1784 | 1784 |
| 1785 video_capture_manager_->Unregister(); | 1785 video_capture_manager_->Unregister(); |
| 1786 audio_input_device_manager_->Unregister(); | 1786 audio_input_device_manager_->Unregister(); |
| 1787 device_task_runner_ = NULL; | 1787 device_task_runner_ = NULL; |
| 1788 } | 1788 } |
| 1789 | 1789 |
| 1790 audio_input_device_manager_ = NULL; | 1790 audio_input_device_manager_ = NULL; |
| 1791 video_capture_manager_ = NULL; | 1791 video_capture_manager_ = NULL; |
| 1792 } | 1792 } |
| 1793 | 1793 |
| 1794 void MediaStreamManager::NotifyDevicesChanged( | 1794 void MediaStreamManager::NotifyDevicesChanged( |
| 1795 MediaStreamType stream_type, | 1795 MediaStreamType stream_type, |
| 1796 const StreamDeviceInfoArray& devices) { | 1796 const StreamDeviceInfoArray& devices) { |
| 1797 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1797 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1798 MediaObserver* media_observer = | 1798 MediaObserver* media_observer = |
| 1799 GetContentClient()->browser()->GetMediaObserver(); | 1799 GetContentClient()->browser()->GetMediaObserver(); |
| 1800 if (media_observer == NULL) | 1800 if (media_observer == NULL) |
| 1801 return; | 1801 return; |
| 1802 | 1802 |
| 1803 // Map the devices to MediaStreamDevices. | 1803 // Map the devices to MediaStreamDevices. |
| 1804 MediaStreamDevices new_devices; | 1804 MediaStreamDevices new_devices; |
| 1805 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); | 1805 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); |
| 1806 it != devices.end(); ++it) { | 1806 it != devices.end(); ++it) { |
| 1807 new_devices.push_back(it->device); | 1807 new_devices.push_back(it->device); |
| 1808 } | 1808 } |
| 1809 | 1809 |
| 1810 if (IsAudioMediaType(stream_type)) { | 1810 if (IsAudioMediaType(stream_type)) { |
| 1811 MediaCaptureDevicesImpl::GetInstance()->OnAudioCaptureDevicesChanged( | 1811 MediaCaptureDevicesImpl::GetInstance()->OnAudioCaptureDevicesChanged( |
| 1812 new_devices); | 1812 new_devices); |
| 1813 media_observer->OnAudioCaptureDevicesChanged(); | 1813 media_observer->OnAudioCaptureDevicesChanged(); |
| 1814 } else if (IsVideoMediaType(stream_type)) { | 1814 } else if (IsVideoMediaType(stream_type)) { |
| 1815 MediaCaptureDevicesImpl::GetInstance()->OnVideoCaptureDevicesChanged( | 1815 MediaCaptureDevicesImpl::GetInstance()->OnVideoCaptureDevicesChanged( |
| 1816 new_devices); | 1816 new_devices); |
| 1817 media_observer->OnVideoCaptureDevicesChanged(); | 1817 media_observer->OnVideoCaptureDevicesChanged(); |
| 1818 } else { | 1818 } else { |
| 1819 NOTREACHED(); | 1819 NOTREACHED(); |
| 1820 } | 1820 } |
| 1821 } | 1821 } |
| 1822 | 1822 |
| 1823 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const { | 1823 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const { |
| 1824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1824 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1825 | 1825 |
| 1826 const bool requested_audio = IsAudioMediaType(request.audio_type()); | 1826 const bool requested_audio = IsAudioMediaType(request.audio_type()); |
| 1827 const bool requested_video = IsVideoMediaType(request.video_type()); | 1827 const bool requested_video = IsVideoMediaType(request.video_type()); |
| 1828 | 1828 |
| 1829 const bool audio_done = | 1829 const bool audio_done = |
| 1830 !requested_audio || | 1830 !requested_audio || |
| 1831 request.state(request.audio_type()) == MEDIA_REQUEST_STATE_DONE || | 1831 request.state(request.audio_type()) == MEDIA_REQUEST_STATE_DONE || |
| 1832 request.state(request.audio_type()) == MEDIA_REQUEST_STATE_ERROR; | 1832 request.state(request.audio_type()) == MEDIA_REQUEST_STATE_ERROR; |
| 1833 if (!audio_done) | 1833 if (!audio_done) |
| 1834 return false; | 1834 return false; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1849 return video_capture_manager(); | 1849 return video_capture_manager(); |
| 1850 } else if (IsAudioMediaType(stream_type)) { | 1850 } else if (IsAudioMediaType(stream_type)) { |
| 1851 return audio_input_device_manager(); | 1851 return audio_input_device_manager(); |
| 1852 } | 1852 } |
| 1853 NOTREACHED(); | 1853 NOTREACHED(); |
| 1854 return NULL; | 1854 return NULL; |
| 1855 } | 1855 } |
| 1856 | 1856 |
| 1857 void MediaStreamManager::OnDevicesChanged( | 1857 void MediaStreamManager::OnDevicesChanged( |
| 1858 base::SystemMonitor::DeviceType device_type) { | 1858 base::SystemMonitor::DeviceType device_type) { |
| 1859 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1859 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1860 | 1860 |
| 1861 // NOTE: This method is only called in response to physical audio/video device | 1861 // NOTE: This method is only called in response to physical audio/video device |
| 1862 // changes (from the operating system). | 1862 // changes (from the operating system). |
| 1863 | 1863 |
| 1864 MediaStreamType stream_type; | 1864 MediaStreamType stream_type; |
| 1865 if (device_type == base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE) { | 1865 if (device_type == base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE) { |
| 1866 stream_type = MEDIA_DEVICE_AUDIO_CAPTURE; | 1866 stream_type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 1867 } else if (device_type == base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE) { | 1867 } else if (device_type == base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE) { |
| 1868 stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; | 1868 stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 1869 } else { | 1869 } else { |
| 1870 return; // Uninteresting device change. | 1870 return; // Uninteresting device change. |
| 1871 } | 1871 } |
| 1872 | 1872 |
| 1873 // Always do enumeration even though some enumeration is in progress, | 1873 // Always do enumeration even though some enumeration is in progress, |
| 1874 // because those enumeration commands could be sent before these devices | 1874 // because those enumeration commands could be sent before these devices |
| 1875 // change. | 1875 // change. |
| 1876 ++active_enumeration_ref_count_[stream_type]; | 1876 ++active_enumeration_ref_count_[stream_type]; |
| 1877 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1877 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
| 1878 } | 1878 } |
| 1879 | 1879 |
| 1880 void MediaStreamManager::OnMediaStreamUIWindowId(MediaStreamType video_type, | 1880 void MediaStreamManager::OnMediaStreamUIWindowId(MediaStreamType video_type, |
| 1881 StreamDeviceInfoArray devices, | 1881 StreamDeviceInfoArray devices, |
| 1882 gfx::NativeViewId window_id) { | 1882 gfx::NativeViewId window_id) { |
| 1883 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1883 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1884 if (!window_id) | 1884 if (!window_id) |
| 1885 return; | 1885 return; |
| 1886 | 1886 |
| 1887 // Pass along for desktop capturing. Ignored for other stream types. | 1887 // Pass along for desktop capturing. Ignored for other stream types. |
| 1888 if (video_type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 1888 if (video_type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
| 1889 for (StreamDeviceInfoArray::iterator it = devices.begin(); | 1889 for (StreamDeviceInfoArray::iterator it = devices.begin(); |
| 1890 it != devices.end(); | 1890 it != devices.end(); |
| 1891 ++it) { | 1891 ++it) { |
| 1892 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 1892 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
| 1893 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, | 1893 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, |
| 1894 window_id); | 1894 window_id); |
| 1895 break; | 1895 break; |
| 1896 } | 1896 } |
| 1897 } | 1897 } |
| 1898 } | 1898 } |
| 1899 } | 1899 } |
| 1900 | 1900 |
| 1901 } // namespace content | 1901 } // namespace content |
| OLD | NEW |