| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_ |
| 7 | 7 |
| 8 #include <array> | 8 #include <array> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/system_monitor/system_monitor.h" | 14 #include "base/system_monitor/system_monitor.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/common/media/media_devices.h" | 16 #include "content/common/media/media_devices.h" |
| 17 #include "media/audio/audio_device_description.h" |
| 17 #include "media/capture/video/video_capture_device_descriptor.h" | 18 #include "media/capture/video/video_capture_device_descriptor.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 class AudioManager; | 21 class AudioSystem; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 25 class MediaStreamManager; | 26 class MediaStreamManager; |
| 26 class VideoCaptureManager; | 27 class VideoCaptureManager; |
| 27 | 28 |
| 28 // Use MediaDeviceType values to index on this type. | 29 // Use MediaDeviceType values to index on this type. |
| 29 using MediaDeviceEnumeration = | 30 using MediaDeviceEnumeration = |
| 30 std::array<MediaDeviceInfoArray, NUM_MEDIA_DEVICE_TYPES>; | 31 std::array<MediaDeviceInfoArray, NUM_MEDIA_DEVICE_TYPES>; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 53 class BoolDeviceTypes final | 54 class BoolDeviceTypes final |
| 54 : public std::array<bool, NUM_MEDIA_DEVICE_TYPES> { | 55 : public std::array<bool, NUM_MEDIA_DEVICE_TYPES> { |
| 55 public: | 56 public: |
| 56 BoolDeviceTypes() { fill(false); } | 57 BoolDeviceTypes() { fill(false); } |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 using EnumerationCallback = | 60 using EnumerationCallback = |
| 60 base::Callback<void(const MediaDeviceEnumeration&)>; | 61 base::Callback<void(const MediaDeviceEnumeration&)>; |
| 61 | 62 |
| 62 MediaDevicesManager( | 63 MediaDevicesManager( |
| 63 media::AudioManager* audio_manager, | 64 media::AudioSystem* audio_system, |
| 64 const scoped_refptr<VideoCaptureManager>& video_capture_manager, | 65 const scoped_refptr<VideoCaptureManager>& video_capture_manager, |
| 65 MediaStreamManager* media_stream_manager); | 66 MediaStreamManager* media_stream_manager); |
| 66 ~MediaDevicesManager() override; | 67 ~MediaDevicesManager() override; |
| 67 | 68 |
| 68 // Performs a possibly cached device enumeration for the requested device | 69 // Performs a possibly cached device enumeration for the requested device |
| 69 // types and reports the results to |callback|. | 70 // types and reports the results to |callback|. |
| 70 // The enumeration results passed to |callback| are guaranteed to be valid | 71 // The enumeration results passed to |callback| are guaranteed to be valid |
| 71 // only for the types specified in |requested_types|. | 72 // only for the types specified in |requested_types|. |
| 72 // Note that this function is not reentrant, so if |callback| needs to perform | 73 // Note that this function is not reentrant, so if |callback| needs to perform |
| 73 // another call to EnumerateDevices, it must do so by posting a task to the | 74 // another call to EnumerateDevices, it must do so by posting a task to the |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 void SetCachePolicy(MediaDeviceType type, CachePolicy policy); | 131 void SetCachePolicy(MediaDeviceType type, CachePolicy policy); |
| 131 | 132 |
| 132 // Helpers to issue low-level device enumerations. | 133 // Helpers to issue low-level device enumerations. |
| 133 void DoEnumerateDevices(MediaDeviceType type); | 134 void DoEnumerateDevices(MediaDeviceType type); |
| 134 void EnumerateAudioDevices(bool is_input); | 135 void EnumerateAudioDevices(bool is_input); |
| 135 | 136 |
| 136 // Callback for VideoCaptureManager::EnumerateDevices. | 137 // Callback for VideoCaptureManager::EnumerateDevices. |
| 137 void VideoInputDevicesEnumerated( | 138 void VideoInputDevicesEnumerated( |
| 138 const media::VideoCaptureDeviceDescriptors& descriptors); | 139 const media::VideoCaptureDeviceDescriptors& descriptors); |
| 139 | 140 |
| 141 // Callback for AudioSystem::GetDeviceDescriptions. |
| 142 void AudioDevicesEnumerated( |
| 143 MediaDeviceType type, |
| 144 media::AudioDeviceDescriptions device_descriptions); |
| 145 |
| 140 // Helpers to handle enumeration results. | 146 // Helpers to handle enumeration results. |
| 141 void DevicesEnumerated(MediaDeviceType type, | 147 void DevicesEnumerated(MediaDeviceType type, |
| 142 const MediaDeviceInfoArray& snapshot); | 148 const MediaDeviceInfoArray& snapshot); |
| 143 void UpdateSnapshot(MediaDeviceType type, | 149 void UpdateSnapshot(MediaDeviceType type, |
| 144 const MediaDeviceInfoArray& new_snapshot); | 150 const MediaDeviceInfoArray& new_snapshot); |
| 145 void ProcessRequests(); | 151 void ProcessRequests(); |
| 146 bool IsEnumerationRequestReady(const EnumerationRequest& request_info); | 152 bool IsEnumerationRequestReady(const EnumerationRequest& request_info); |
| 147 | 153 |
| 148 // Helpers to handle device-change notification. | 154 // Helpers to handle device-change notification. |
| 149 void HandleDevicesChanged(MediaDeviceType type); | 155 void HandleDevicesChanged(MediaDeviceType type); |
| 150 void NotifyMediaStreamManager(MediaDeviceType type, | 156 void NotifyMediaStreamManager(MediaDeviceType type, |
| 151 const MediaDeviceInfoArray& new_snapshot); | 157 const MediaDeviceInfoArray& new_snapshot); |
| 152 void NotifyDeviceChangeSubscribers(MediaDeviceType type, | 158 void NotifyDeviceChangeSubscribers(MediaDeviceType type, |
| 153 const MediaDeviceInfoArray& snapshot); | 159 const MediaDeviceInfoArray& snapshot); |
| 154 | 160 |
| 155 #if defined(OS_MACOSX) | 161 #if defined(OS_MACOSX) |
| 156 void StartMonitoringOnUIThread(); | 162 void StartMonitoringOnUIThread(); |
| 157 #endif | 163 #endif |
| 158 | 164 |
| 159 bool use_fake_devices_; | 165 bool use_fake_devices_; |
| 160 media::AudioManager* const audio_manager_; // not owned | 166 media::AudioSystem* const audio_system_; // not owned |
| 161 scoped_refptr<VideoCaptureManager> video_capture_manager_; | 167 scoped_refptr<VideoCaptureManager> video_capture_manager_; |
| 162 MediaStreamManager* const media_stream_manager_; // not owned | 168 MediaStreamManager* const media_stream_manager_; // not owned |
| 163 | 169 |
| 164 using CachePolicies = std::array<CachePolicy, NUM_MEDIA_DEVICE_TYPES>; | 170 using CachePolicies = std::array<CachePolicy, NUM_MEDIA_DEVICE_TYPES>; |
| 165 CachePolicies cache_policies_; | 171 CachePolicies cache_policies_; |
| 166 | 172 |
| 167 class CacheInfo; | 173 class CacheInfo; |
| 168 using CacheInfos = std::vector<CacheInfo>; | 174 using CacheInfos = std::vector<CacheInfo>; |
| 169 CacheInfos cache_infos_; | 175 CacheInfos cache_infos_; |
| 170 | 176 |
| 171 BoolDeviceTypes has_seen_result_; | 177 BoolDeviceTypes has_seen_result_; |
| 172 std::vector<EnumerationRequest> requests_; | 178 std::vector<EnumerationRequest> requests_; |
| 173 MediaDeviceEnumeration current_snapshot_; | 179 MediaDeviceEnumeration current_snapshot_; |
| 174 bool monitoring_started_; | 180 bool monitoring_started_; |
| 175 | 181 |
| 176 std::vector<MediaDeviceChangeSubscriber*> | 182 std::vector<MediaDeviceChangeSubscriber*> |
| 177 device_change_subscribers_[NUM_MEDIA_DEVICE_TYPES]; | 183 device_change_subscribers_[NUM_MEDIA_DEVICE_TYPES]; |
| 178 | 184 |
| 179 base::WeakPtrFactory<MediaDevicesManager> weak_factory_; | 185 base::WeakPtrFactory<MediaDevicesManager> weak_factory_; |
| 180 | 186 |
| 181 DISALLOW_COPY_AND_ASSIGN(MediaDevicesManager); | 187 DISALLOW_COPY_AND_ASSIGN(MediaDevicesManager); |
| 182 }; | 188 }; |
| 183 | 189 |
| 184 } // namespace content | 190 } // namespace content |
| 185 | 191 |
| 186 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_ | 192 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_ |
| OLD | NEW |