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

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

Issue 10834232: Revert 150491 - refactor EnumerateDevices to make it a persistent request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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 // MediaStreamManager is used to open/enumerate media capture devices (video 5 // MediaStreamManager is used to open/enumerate media capture devices (video
6 // supported now). Call flow: 6 // supported now). Call flow:
7 // 1. GenerateStream is called when a render process wants to use a capture 7 // 1. GenerateStream is called when a render process wants to use a capture
8 // device. 8 // device.
9 // 2. MediaStreamManager will ask MediaStreamDeviceSettings for permission to 9 // 2. MediaStreamManager will ask MediaStreamDeviceSettings for permission to
10 // use devices and for which device to use. 10 // use devices and for which device to use.
(...skipping 12 matching lines...) Expand all
23 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 23 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
24 24
25 #include <map> 25 #include <map>
26 #include <string> 26 #include <string>
27 #include <vector> 27 #include <vector>
28 28
29 #include "base/basictypes.h" 29 #include "base/basictypes.h"
30 #include "base/memory/scoped_ptr.h" 30 #include "base/memory/scoped_ptr.h"
31 #include "base/memory/ref_counted.h" 31 #include "base/memory/ref_counted.h"
32 #include "base/message_loop.h" 32 #include "base/message_loop.h"
33 #include "base/system_monitor/system_monitor.h"
34 #include "base/threading/thread.h" 33 #include "base/threading/thread.h"
35 #include "content/browser/renderer_host/media/media_stream_provider.h" 34 #include "content/browser/renderer_host/media/media_stream_provider.h"
36 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" 35 #include "content/browser/renderer_host/media/media_stream_settings_requester.h"
37 #include "content/common/media/media_stream_options.h" 36 #include "content/common/media/media_stream_options.h"
38 #include "content/common/content_export.h" 37 #include "content/common/content_export.h"
39 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
40 39
41 namespace base { 40 namespace base {
42 namespace win { 41 namespace win {
43 class ScopedCOMInitializer; 42 class ScopedCOMInitializer;
(...skipping 22 matching lines...) Expand all
66 DISALLOW_COPY_AND_ASSIGN(DeviceThread); 65 DISALLOW_COPY_AND_ASSIGN(DeviceThread);
67 }; 66 };
68 67
69 // MediaStreamManager is used to generate and close new media devices, not to 68 // MediaStreamManager is used to generate and close new media devices, not to
70 // start the media flow. 69 // start the media flow.
71 // The classes requesting new media streams are answered using 70 // The classes requesting new media streams are answered using
72 // MediaStreamManager::Listener. 71 // MediaStreamManager::Listener.
73 class CONTENT_EXPORT MediaStreamManager 72 class CONTENT_EXPORT MediaStreamManager
74 : public MediaStreamProviderListener, 73 : public MediaStreamProviderListener,
75 public MessageLoop::DestructionObserver, 74 public MessageLoop::DestructionObserver,
76 public SettingsRequester, 75 public SettingsRequester {
77 public base::SystemMonitor::DevicesChangedObserver {
78 public: 76 public:
79 // This class takes the ownerships of the |audio_input_device_manager| 77 // This class takes the ownerships of the |audio_input_device_manager|
80 // and |video_capture_manager|. 78 // and |video_capture_manager|.
81 MediaStreamManager(AudioInputDeviceManager* audio_input_device_manager, 79 MediaStreamManager(AudioInputDeviceManager* audio_input_device_manager,
82 VideoCaptureManager* video_capture_manager); 80 VideoCaptureManager* video_capture_manager);
83 81
84 virtual ~MediaStreamManager(); 82 virtual ~MediaStreamManager();
85 83
86 // Used to access VideoCaptureManager. 84 // Used to access VideoCaptureManager.
87 VideoCaptureManager* video_capture_manager(); 85 VideoCaptureManager* video_capture_manager();
(...skipping 14 matching lines...) Expand all
102 100
103 // Cancel generate stream. 101 // Cancel generate stream.
104 void CancelGenerateStream(const std::string& label); 102 void CancelGenerateStream(const std::string& label);
105 103
106 // Closes generated stream. 104 // Closes generated stream.
107 void StopGeneratedStream(const std::string& label); 105 void StopGeneratedStream(const std::string& label);
108 106
109 // Gets a list of devices of |type|. 107 // Gets a list of devices of |type|.
110 // The request is identified using |label|, which is pointing to a 108 // The request is identified using |label|, which is pointing to a
111 // std::string. 109 // std::string.
112 // The request is persistent, which means the client keeps listening to
113 // device changes, such as plug/unplug, and expects new device list for
114 // such a change, till the client stops the request.
115 void EnumerateDevices(MediaStreamRequester* requester, 110 void EnumerateDevices(MediaStreamRequester* requester,
116 int render_process_id, 111 int render_process_id,
117 int render_view_id, 112 int render_view_id,
118 MediaStreamType type, 113 MediaStreamType type,
119 const GURL& security_origin, 114 const GURL& security_origin,
120 std::string* label); 115 std::string* label);
121 116
122 // Open a device identified by |device_id|. 117 // Open a device identified by |device_id|.
123 // The request is identified using |label|, which is pointing to a 118 // The request is identified using |label|, which is pointing to a
124 // std::string. 119 // std::string.
(...skipping 14 matching lines...) Expand all
139 const StreamDeviceInfoArray& devices) OVERRIDE; 134 const StreamDeviceInfoArray& devices) OVERRIDE;
140 virtual void Error(MediaStreamType stream_type, 135 virtual void Error(MediaStreamType stream_type,
141 int capture_session_id, 136 int capture_session_id,
142 MediaStreamProviderError error) OVERRIDE; 137 MediaStreamProviderError error) OVERRIDE;
143 138
144 // Implements SettingsRequester. 139 // Implements SettingsRequester.
145 virtual void DevicesAccepted(const std::string& label, 140 virtual void DevicesAccepted(const std::string& label,
146 const StreamDeviceInfoArray& devices) OVERRIDE; 141 const StreamDeviceInfoArray& devices) OVERRIDE;
147 virtual void SettingsError(const std::string& label) OVERRIDE; 142 virtual void SettingsError(const std::string& label) OVERRIDE;
148 143
149 // Implements base::SystemMonitor::DevicesChangedObserver.
150 virtual void OnDevicesChanged(
151 base::SystemMonitor::DeviceType device_type) OVERRIDE;
152
153 // Used by unit test to make sure fake devices are used instead of a real 144 // Used by unit test to make sure fake devices are used instead of a real
154 // devices, which is needed for server based testing. 145 // devices, which is needed for server based testing.
155 // TODO(xians): Remove this hack since we can create our own 146 // TODO(xians): Remove this hack since we can create our own
156 // MediaStreamManager in our unit tests. 147 // MediaStreamManager in our unit tests.
157 void UseFakeDevice(); 148 void UseFakeDevice();
158 149
159 // This object gets deleted on the UI thread after the IO thread has been 150 // This object gets deleted on the UI thread after the IO thread has been
160 // destroyed. So we need to know when IO thread is being destroyed so that 151 // destroyed. So we need to know when IO thread is being destroyed so that
161 // we can delete VideoCaptureManager and AudioInputDeviceManager. 152 // we can delete VideoCaptureManager and AudioInputDeviceManager.
162 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 153 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
163 154
164 private: 155 private:
165 // Contains all data needed to keep track of requests. 156 // Contains all data needed to keep track of requests.
166 struct DeviceRequest; 157 struct DeviceRequest;
167 158
168 // Cache enumerated device list.
169 struct EnumerationCache {
170 EnumerationCache();
171 ~EnumerationCache();
172
173 bool valid;
174 StreamDeviceInfoArray devices;
175 };
176
177 // Helpers for signaling the media observer that new capture devices are 159 // Helpers for signaling the media observer that new capture devices are
178 // opened/closed. 160 // opened/closed.
179 void NotifyObserverDevicesOpened(DeviceRequest* request); 161 void NotifyObserverDevicesOpened(DeviceRequest* request);
180 void NotifyObserverDevicesClosed(DeviceRequest* request); 162 void NotifyObserverDevicesClosed(DeviceRequest* request);
181 void DevicesFromRequest(DeviceRequest* request, 163 void DevicesFromRequest(DeviceRequest* request,
182 content::MediaStreamDevices* devices); 164 content::MediaStreamDevices* devices);
183 165
184 // Helpers. 166 // Helpers.
185 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; 167 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const;
186 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); 168 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type);
187 void StartEnumeration(DeviceRequest* new_request, 169 void StartEnumeration(DeviceRequest* new_request,
188 std::string* label); 170 std::string* label);
189 void AddRequest(DeviceRequest* new_request, std::string* label);
190 bool HasEnumerationRequest(MediaStreamType type);
191 bool HasEnumerationRequest();
192 void ClearEnumerationCache(EnumerationCache* cache);
193 171
194 // Helper to ensure the device thread and pass the message loop to device 172 // Helper to ensure the device thread and pass the message loop to device
195 // managers, it also register itself as the listener to the device managers. 173 // managers, it also register itself as the listener to the device managers.
196 void EnsureDeviceThreadAndListener(); 174 void EnsureDeviceThreadAndListener();
197 175
198 // Sends cached device list to a client corresponding to the request
199 // identified by |label|.
200 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label);
201
202 // Stop the request of enumerating devices indentified by |label|.
203 void StopEnumerateDevices(const std::string& label);
204
205 // Helpers to start and stop monitoring devices.
206 void StartMonitoring();
207 void StopMonitoring();
208
209 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. 176 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager.
210 scoped_ptr<base::Thread> device_thread_; 177 scoped_ptr<base::Thread> device_thread_;
211 178
212 scoped_ptr<MediaStreamDeviceSettings> device_settings_; 179 scoped_ptr<MediaStreamDeviceSettings> device_settings_;
213 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; 180 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
214 scoped_refptr<VideoCaptureManager> video_capture_manager_; 181 scoped_refptr<VideoCaptureManager> video_capture_manager_;
215 182
216 // Indicator of device monitoring state. 183 // Keeps track of device types currently being enumerated to not enumerate
217 bool monitoring_started_; 184 // when not necessary.
218 185 std::vector<bool> enumeration_in_progress_;
219 // Stores most recently enumerated device lists. The cache is cleared when
220 // monitoring is stopped or there is no request for that type of device.
221 EnumerationCache audio_enumeration_cache_;
222 EnumerationCache video_enumeration_cache_;
223
224 // Keeps track of live enumeration commands sent to VideoCaptureManager or
225 // AudioInputDeviceManager, in order to only enumerate when necessary.
226 int active_enumeration_ref_count_[content::NUM_MEDIA_STREAM_DEVICE_TYPES];
227 186
228 // All non-closed request. 187 // All non-closed request.
229 typedef std::map<std::string, DeviceRequest> DeviceRequests; 188 typedef std::map<std::string, DeviceRequest> DeviceRequests;
230 DeviceRequests requests_; 189 DeviceRequests requests_;
231 190
232 // Hold a pointer to the IO loop to check we delete the device thread and 191 // Hold a pointer to the IO loop to check we delete the device thread and
233 // managers on the right thread. 192 // managers on the right thread.
234 MessageLoop* io_loop_; 193 MessageLoop* io_loop_;
235 194
236 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); 195 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager);
237 }; 196 };
238 197
239 } // namespace media_stream 198 } // namespace media_stream
240 199
241 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 200 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698