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

Side by Side Diff: content/browser/renderer_host/media/media_devices_manager.h

Issue 2350693002: Remove device enumeration, caching and monitoring from MediaStreamManager. (Closed)
Patch Set: Minor DCHECK fix Created 4 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_
7
8 #include <array>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/system_monitor/system_monitor.h"
15 #include "content/common/content_export.h"
16 #include "content/common/media/media_devices.h"
17 #include "media/capture/video/video_capture_device_descriptor.h"
18
19 namespace base {
20 class SingleThreadTaskRunner;
21 }
22
23 namespace media {
24 class AudioManager;
25 }
26
27 namespace content {
28
29 class MediaStreamManager;
30 class VideoCaptureManager;
31
32 // Use MediaDeviceType values to index on this type.
33 using MediaDeviceEnumeration =
34 std::array<MediaDeviceInfoArray, NUM_MEDIA_DEVICE_TYPES>;
35
36 // MediaDevicesManager is responsible for doing media-device enumerations.
37 // In addition it implements caching for enumeration results and device
38 // monitoring in order to keep caches consistent.
39 // All its methods must be called on the IO thread.
40 class CONTENT_EXPORT MediaDevicesManager
41 : public base::SystemMonitor::DevicesChangedObserver {
42 public:
43 // Use MediaDeviceType values to index on this type.
44 using BoolDeviceTypes = std::array<bool, NUM_MEDIA_DEVICE_TYPES>;
45
46 using EnumerationCallback =
47 base::Callback<void(const MediaDeviceEnumeration&)>;
48
49 enum class CachePolicy {
50 NO_CACHE,
51 SYSTEM_MONITOR,
52 };
53
54 MediaDevicesManager(
55 media::AudioManager* audio_manager,
56 const scoped_refptr<VideoCaptureManager>& video_capture_manager,
57 MediaStreamManager* media_stream_manager);
58 ~MediaDevicesManager() override;
59
60 // Performs a possibly cached device enumeration for the requested device
61 // types and reports the results to |callback|.
62 // The enumeration results passed to |callback| are guaranteed to be valid
63 // only for the types specified in |requested_types|.
64 // Note that this function is not reentrant, so if |callback| needs to perform
65 // another call to EnumerateDevices, it must do so by posting a task to the
66 // IO thread.
67 void EnumerateDevices(const BoolDeviceTypes& requested_types,
68 const EnumerationCallback& callback);
69
70 // Manually sets a caching policy for a given device type.
71 // Note that manually setting the SYSTEM_MONITOR policy without having
72 // monitoring enabled may result in incorrect behavior.
73 void SetCachePolicy(MediaDeviceType type, CachePolicy policy);
hta - Chromium 2016/09/20 10:55:29 Why not return a failure when SYSTEM_MONITOR is se
Guido Urdaneta 2016/09/20 13:59:27 I originally made it public mainly for testing pur
74
75 // Tries to starts device monitoring. If successful, sets the caching policy
76 // to SYSTEM_MONITOR for the device types supported by the monitor.
77 void StartMonitoring();
78
79 // Stops device monitoring and sets the caching policy to NO_CACHE for all
80 // device types.
81 void StopMonitoring();
82 bool IsMonitoringStarted();
83
84 // Implements base::SystemMonitor::DevicesChangedObserver.
85 // This function is only called in response to physical audio/video device
86 // changes.
87 void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override;
88
89 // TODO(guidou): Remove this function once content::GetMediaDeviceIDForHMAC
90 // is rewritten to receive devices via a callback.
91 // See http://crbug.com/648155.
92 MediaDeviceInfoArray GetCachedDeviceInfo(MediaDeviceType type);
93
94 private:
95 struct EnumerationRequest;
96
97 void DoEnumerateDevices(MediaDeviceType type);
98 void EnumerateAudioDevices(bool is_input);
99
100 // Callback for VideoCaptureManager::EnumerateDevices.
101 void VideoInputDevicesEnumerated(
102 const media::VideoCaptureDeviceDescriptors& descriptors);
103
104 // Helpers to handle enumeration results.
105 void DevicesEnumerated(MediaDeviceType type,
106 const MediaDeviceInfoArray& snapshot);
107 void UpdateSnapshot(MediaDeviceType type,
108 const MediaDeviceInfoArray& new_snapshot);
109 void ProcessRequests();
110 bool IsEnumerationRequestReady(const EnumerationRequest& request_info);
111
112 // Helpers to handle device-change notification.
113 void HandleDevicesChanged(MediaDeviceType type);
114 void NotifyMediaStreamManager(MediaDeviceType type,
115 const MediaDeviceInfoArray& new_snapshot);
116 void NotifyDeviceChangeSubscribers(MediaDeviceType type,
117 const MediaDeviceInfoArray& snapshot);
118
119 #if defined(OS_MACOSX)
120 void StartMonitoringOnUIThread();
121 #endif
122
123 bool use_fake_devices_;
124 media::AudioManager* const audio_manager_; // not owned
125 scoped_refptr<VideoCaptureManager> video_capture_manager_;
126 MediaStreamManager* const media_stream_manager_; // not owned
127
128 using CachePolicies = std::array<CachePolicy, NUM_MEDIA_DEVICE_TYPES>;
hta - Chromium 2016/09/20 10:55:29 This is a pattern I haven't seen before. Is it a n
Guido Urdaneta 2016/09/20 13:59:27 Yes, it is. It's preferred over typedef, according
129 CachePolicies cache_policies_;
130
131 class CacheInfo;
132 using CacheInfos = std::vector<CacheInfo>;
133 CacheInfos cache_infos_;
134
135 BoolDeviceTypes has_seen_result_;
136 std::vector<EnumerationRequest> requests_;
137 MediaDeviceEnumeration current_snapshot_;
138 bool monitoring_started_;
139
140 base::WeakPtrFactory<MediaDevicesManager> weak_factory_;
141
142 DISALLOW_COPY_AND_ASSIGN(MediaDevicesManager);
143 };
144
145 } // namespace content
146
147 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698