| 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 24 matching lines...) Expand all Loading... |
| 35 #include "media/audio/audio_parameters.h" | 35 #include "media/audio/audio_parameters.h" |
| 36 #include "media/base/channel_layout.h" | 36 #include "media/base/channel_layout.h" |
| 37 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 38 | 38 |
| 39 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 40 #include "base/win/scoped_com_initializer.h" | 40 #include "base/win/scoped_com_initializer.h" |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 namespace content { | 43 namespace content { |
| 44 | 44 |
| 45 // Forward declaration of DeviceMonitorMac and its only useable method. |
| 46 class DeviceMonitorMac { |
| 47 public: |
| 48 void StartMonitoring(); |
| 49 }; |
| 50 |
| 45 namespace { | 51 namespace { |
| 46 // Creates a random label used to identify requests. | 52 // Creates a random label used to identify requests. |
| 47 std::string RandomLabel() { | 53 std::string RandomLabel() { |
| 48 // An earlier PeerConnection spec, | 54 // An earlier PeerConnection spec, |
| 49 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the | 55 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the |
| 50 // MediaStream::label alphabet as containing 36 characters from | 56 // MediaStream::label alphabet as containing 36 characters from |
| 51 // range: U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, | 57 // range: U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, |
| 52 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E. | 58 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E. |
| 53 // Here we use a safe subset. | 59 // Here we use a safe subset. |
| 54 static const char kAlphabet[] = "0123456789" | 60 static const char kAlphabet[] = "0123456789" |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 | 783 |
| 778 monitoring_started_ = true; | 784 monitoring_started_ = true; |
| 779 base::SystemMonitor::Get()->AddDevicesChangedObserver(this); | 785 base::SystemMonitor::Get()->AddDevicesChangedObserver(this); |
| 780 | 786 |
| 781 // Enumerate both the audio and video devices to cache the device lists | 787 // Enumerate both the audio and video devices to cache the device lists |
| 782 // and send them to media observer. | 788 // and send them to media observer. |
| 783 ++active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_CAPTURE]; | 789 ++active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_CAPTURE]; |
| 784 audio_input_device_manager_->EnumerateDevices(MEDIA_DEVICE_AUDIO_CAPTURE); | 790 audio_input_device_manager_->EnumerateDevices(MEDIA_DEVICE_AUDIO_CAPTURE); |
| 785 ++active_enumeration_ref_count_[MEDIA_DEVICE_VIDEO_CAPTURE]; | 791 ++active_enumeration_ref_count_[MEDIA_DEVICE_VIDEO_CAPTURE]; |
| 786 video_capture_manager_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 792 video_capture_manager_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 793 |
| 794 #if defined(OS_MACOSX) |
| 795 BrowserThread::PostTask( |
| 796 BrowserThread::UI, FROM_HERE, |
| 797 base::Bind(&MediaStreamManager::StartMonitoringOnUIThread, |
| 798 base::Unretained(this))); |
| 799 #endif |
| 787 } | 800 } |
| 788 | 801 |
| 802 #if defined(OS_MACOSX) |
| 803 void MediaStreamManager::StartMonitoringOnUIThread() { |
| 804 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 805 BrowserMainLoop* browser_main_loop = content::BrowserMainLoop::GetInstance(); |
| 806 if (browser_main_loop) |
| 807 browser_main_loop->device_monitor_mac()->StartMonitoring(); |
| 808 } |
| 809 #endif |
| 810 |
| 789 void MediaStreamManager::StopMonitoring() { | 811 void MediaStreamManager::StopMonitoring() { |
| 790 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 812 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
| 791 if (monitoring_started_) { | 813 if (monitoring_started_) { |
| 792 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); | 814 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); |
| 793 monitoring_started_ = false; | 815 monitoring_started_ = false; |
| 794 ClearEnumerationCache(&audio_enumeration_cache_); | 816 ClearEnumerationCache(&audio_enumeration_cache_); |
| 795 ClearEnumerationCache(&video_enumeration_cache_); | 817 ClearEnumerationCache(&video_enumeration_cache_); |
| 796 } | 818 } |
| 797 } | 819 } |
| 798 | 820 |
| (...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 } | 1838 } |
| 1817 | 1839 |
| 1818 // Always do enumeration even though some enumeration is in progress, | 1840 // Always do enumeration even though some enumeration is in progress, |
| 1819 // because those enumeration commands could be sent before these devices | 1841 // because those enumeration commands could be sent before these devices |
| 1820 // change. | 1842 // change. |
| 1821 ++active_enumeration_ref_count_[stream_type]; | 1843 ++active_enumeration_ref_count_[stream_type]; |
| 1822 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1844 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
| 1823 } | 1845 } |
| 1824 | 1846 |
| 1825 } // namespace content | 1847 } // namespace content |
| OLD | NEW |