| 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 <cctype> | 7 #include <cctype> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 #endif | 223 #endif |
| 224 } | 224 } |
| 225 | 225 |
| 226 bool CalledOnIOThread() { | 226 bool CalledOnIOThread() { |
| 227 // Check if this function call is on the IO thread, except for unittests where | 227 // Check if this function call is on the IO thread, except for unittests where |
| 228 // an IO thread might not have been created. | 228 // an IO thread might not have been created. |
| 229 return BrowserThread::CurrentlyOn(BrowserThread::IO) || | 229 return BrowserThread::CurrentlyOn(BrowserThread::IO) || |
| 230 !BrowserThread::IsMessageLoopValid(BrowserThread::IO); | 230 !BrowserThread::IsMessageLoopValid(BrowserThread::IO); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void DummyEnumerationCallback(const AudioOutputDeviceEnumeration& e) {} | |
| 234 | |
| 235 } // namespace | 233 } // namespace |
| 236 | 234 |
| 237 | 235 |
| 238 // MediaStreamManager::DeviceRequest represents a request to either enumerate | 236 // MediaStreamManager::DeviceRequest represents a request to either enumerate |
| 239 // available devices or open one or more devices. | 237 // available devices or open one or more devices. |
| 240 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create | 238 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create |
| 241 // several subclasses of DeviceRequest and move some of the responsibility of | 239 // several subclasses of DeviceRequest and move some of the responsibility of |
| 242 // the MediaStreamManager to the subclasses to get rid of the way too many if | 240 // the MediaStreamManager to the subclasses to get rid of the way too many if |
| 243 // statements in MediaStreamManager. | 241 // statements in MediaStreamManager. |
| 244 class MediaStreamManager::DeviceRequest { | 242 class MediaStreamManager::DeviceRequest { |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 953 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 956 if (monitoring_started_) | 954 if (monitoring_started_) |
| 957 return; | 955 return; |
| 958 | 956 |
| 959 if (!base::SystemMonitor::Get()) | 957 if (!base::SystemMonitor::Get()) |
| 960 return; | 958 return; |
| 961 | 959 |
| 962 monitoring_started_ = true; | 960 monitoring_started_ = true; |
| 963 base::SystemMonitor::Get()->AddDevicesChangedObserver(this); | 961 base::SystemMonitor::Get()->AddDevicesChangedObserver(this); |
| 964 | 962 |
| 965 // Enable caching for audio output device enumerations and do an enumeration | |
| 966 // to populate the cache. | |
| 967 audio_output_device_enumerator_->SetCachePolicy( | |
| 968 AudioOutputDeviceEnumerator::CACHE_POLICY_MANUAL_INVALIDATION); | |
| 969 audio_output_device_enumerator_->Enumerate( | |
| 970 base::Bind(&DummyEnumerationCallback)); | |
| 971 | |
| 972 // Enumerate both the audio and video input devices to cache the device lists | 963 // Enumerate both the audio and video input devices to cache the device lists |
| 973 // and send them to media observer. | 964 // and send them to media observer. |
| 974 ++active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_CAPTURE]; | 965 ++active_enumeration_ref_count_[MEDIA_DEVICE_AUDIO_CAPTURE]; |
| 975 audio_input_device_manager_->EnumerateDevices(MEDIA_DEVICE_AUDIO_CAPTURE); | 966 audio_input_device_manager_->EnumerateDevices(MEDIA_DEVICE_AUDIO_CAPTURE); |
| 976 ++active_enumeration_ref_count_[MEDIA_DEVICE_VIDEO_CAPTURE]; | 967 ++active_enumeration_ref_count_[MEDIA_DEVICE_VIDEO_CAPTURE]; |
| 977 video_capture_manager_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 968 video_capture_manager_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 978 | 969 |
| 979 #if defined(OS_MACOSX) | 970 #if defined(OS_MACOSX) |
| 980 BrowserThread::PostTask( | 971 BrowserThread::PostTask( |
| 981 BrowserThread::UI, FROM_HERE, | 972 BrowserThread::UI, FROM_HERE, |
| (...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2063 void MediaStreamManager::OnDevicesChanged( | 2054 void MediaStreamManager::OnDevicesChanged( |
| 2064 base::SystemMonitor::DeviceType device_type) { | 2055 base::SystemMonitor::DeviceType device_type) { |
| 2065 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2056 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 2066 | 2057 |
| 2067 // NOTE: This method is only called in response to physical audio/video device | 2058 // NOTE: This method is only called in response to physical audio/video device |
| 2068 // changes (from the operating system). | 2059 // changes (from the operating system). |
| 2069 | 2060 |
| 2070 MediaStreamType stream_type; | 2061 MediaStreamType stream_type; |
| 2071 if (device_type == base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE) { | 2062 if (device_type == base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE) { |
| 2072 stream_type = MEDIA_DEVICE_AUDIO_CAPTURE; | 2063 stream_type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 2073 audio_output_device_enumerator_->InvalidateCache(); | |
| 2074 } else if (device_type == base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE) { | 2064 } else if (device_type == base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE) { |
| 2075 stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; | 2065 stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 2076 } else { | 2066 } else { |
| 2077 return; // Uninteresting device change. | 2067 return; // Uninteresting device change. |
| 2078 } | 2068 } |
| 2079 | 2069 |
| 2080 // Always do enumeration even though some enumeration is in progress, because | 2070 // Always do enumeration even though some enumeration is in progress, because |
| 2081 // those enumeration commands could be sent before these devices change. | 2071 // those enumeration commands could be sent before these devices change. |
| 2082 ++active_enumeration_ref_count_[stream_type]; | 2072 ++active_enumeration_ref_count_[stream_type]; |
| 2083 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 2073 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2163 const std::string& device_guid, | 2153 const std::string& device_guid, |
| 2164 const std::string& raw_unique_id) { | 2154 const std::string& raw_unique_id) { |
| 2165 DCHECK(security_origin.is_valid()); | 2155 DCHECK(security_origin.is_valid()); |
| 2166 DCHECK(!raw_unique_id.empty()); | 2156 DCHECK(!raw_unique_id.empty()); |
| 2167 std::string guid_from_raw_device_id = | 2157 std::string guid_from_raw_device_id = |
| 2168 GetHMACForMediaDeviceID(sc, security_origin, raw_unique_id); | 2158 GetHMACForMediaDeviceID(sc, security_origin, raw_unique_id); |
| 2169 return guid_from_raw_device_id == device_guid; | 2159 return guid_from_raw_device_id == device_guid; |
| 2170 } | 2160 } |
| 2171 | 2161 |
| 2172 } // namespace content | 2162 } // namespace content |
| OLD | NEW |