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

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

Issue 34393006: Refactor MediaStreamManager to never output real device id. It now always output sourceId in the fo… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix broken video_capture_host unittests. Addressed justinlinlins comments. Created 7 years, 1 month 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 MediaStreamUIController for permission to 9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to
10 // use devices and for which device to use. 10 // use devices and for which device to use.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 MediaStreamType type, 134 MediaStreamType type,
135 const GURL& security_origin); 135 const GURL& security_origin);
136 136
137 // Implements MediaStreamProviderListener. 137 // Implements MediaStreamProviderListener.
138 virtual void Opened(MediaStreamType stream_type, 138 virtual void Opened(MediaStreamType stream_type,
139 int capture_session_id) OVERRIDE; 139 int capture_session_id) OVERRIDE;
140 virtual void Closed(MediaStreamType stream_type, 140 virtual void Closed(MediaStreamType stream_type,
141 int capture_session_id) OVERRIDE; 141 int capture_session_id) OVERRIDE;
142 virtual void DevicesEnumerated(MediaStreamType stream_type, 142 virtual void DevicesEnumerated(MediaStreamType stream_type,
143 const StreamDeviceInfoArray& devices) OVERRIDE; 143 const StreamDeviceInfoArray& devices) OVERRIDE;
144 virtual void Error(MediaStreamType stream_type,
145 int capture_session_id,
146 MediaStreamProviderError error) OVERRIDE;
147 144
148 // Implements base::SystemMonitor::DevicesChangedObserver. 145 // Implements base::SystemMonitor::DevicesChangedObserver.
149 virtual void OnDevicesChanged( 146 virtual void OnDevicesChanged(
150 base::SystemMonitor::DeviceType device_type) OVERRIDE; 147 base::SystemMonitor::DeviceType device_type) OVERRIDE;
151 148
152 // Used by unit test to make sure fake devices are used instead of a real 149 // Used by unit test to make sure fake devices are used instead of a real
153 // devices, which is needed for server based testing or certain tests (which 150 // devices, which is needed for server based testing or certain tests (which
154 // can pass --use-fake-device-for-media-stream). 151 // can pass --use-fake-device-for-media-stream).
155 void UseFakeDevice(); 152 void UseFakeDevice();
156 153
157 // Called by the tests to specify a fake UI that should be used for next 154 // Called by the tests to specify a fake UI that should be used for next
158 // generated stream (or when using --use-fake-ui-for-media-stream). 155 // generated stream (or when using --use-fake-ui-for-media-stream).
159 void UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui); 156 void UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui);
160 157
161 // This object gets deleted on the UI thread after the IO thread has been 158 // Used by test to find a StreamDeviceInfo that currently has been
162 // destroyed. So we need to know when IO thread is being destroyed so that 159 // requested and match the input arguments. If such a StreamDeviceInfo is
163 // we can delete VideoCaptureManager and AudioInputDeviceManager. 160 // found it is copied to |device_info|.
164 // We also must call this function explicitly in tests which use 161 bool FindRequestedDeviceInfo(const std::string& source_id,
Jói 2013/10/28 11:48:17 If this is never intended to be used by production
tommi (sloooow) - chröme 2013/10/28 13:48:23 ping
perkj_chrome 2013/10/29 08:52:17 Done.
perkj_chrome 2013/10/29 08:52:17 Done.
165 // TestBrowserThreadBundle, because the notification happens too late in that 162 int render_process_id,
166 // case (see http://crbug.com/247525#c14). 163 int render_view_id,
167 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 164 MediaStreamRequestType type,
165 StreamDeviceInfo* device_info);
168 166
169 protected: 167 protected:
170 // Used for testing. 168 // Used for testing.
171 MediaStreamManager(); 169 MediaStreamManager();
172 170
173 private: 171 private:
174 friend class MockMediaStreamDispatcherHost;
175
176 // Contains all data needed to keep track of requests. 172 // Contains all data needed to keep track of requests.
177 class DeviceRequest; 173 class DeviceRequest;
178 174
179 // Cache enumerated device list. 175 // Cache enumerated device list.
180 struct EnumerationCache { 176 struct EnumerationCache {
181 EnumerationCache(); 177 EnumerationCache();
182 ~EnumerationCache(); 178 ~EnumerationCache();
183 179
184 bool valid; 180 bool valid;
185 StreamDeviceInfoArray devices; 181 StreamDeviceInfoArray devices;
186 }; 182 };
187 183
188 typedef std::map<std::string, DeviceRequest*> DeviceRequests; 184 typedef std::map<std::string, DeviceRequest*> DeviceRequests;
189 185
186 // This object gets deleted on the UI thread after the IO thread has been
187 // destroyed. So we need to know when IO thread is being destroyed so that
tommi (sloooow) - chröme 2013/10/28 13:48:23 nit: "when the IO thread"
perkj_chrome 2013/10/29 08:52:17 Done.
188 // we can delete VideoCaptureManager and AudioInputDeviceManager.
189 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
190
190 // Initializes the device managers on IO thread. Auto-starts the device 191 // Initializes the device managers on IO thread. Auto-starts the device
191 // thread and registers this as a listener with the device managers. 192 // thread and registers this as a listener with the device managers.
192 void InitializeDeviceManagersOnIOThread(); 193 void InitializeDeviceManagersOnIOThread();
193 194
194 // Helper for sending up-to-date device lists to media observer when a 195 // Helper for sending up-to-date device lists to media observer when a
195 // capture device is plugged in or unplugged. 196 // capture device is plugged in or unplugged.
196 void NotifyDevicesChanged(MediaStreamType stream_type, 197 void NotifyDevicesChanged(MediaStreamType stream_type,
197 const StreamDeviceInfoArray& devices); 198 const StreamDeviceInfoArray& devices);
198 199
199
200 void HandleAccessRequestResponse(const std::string& label, 200 void HandleAccessRequestResponse(const std::string& label,
201 const MediaStreamDevices& devices); 201 const MediaStreamDevices& devices);
202 void StopStreamFromUI(const std::string& label); 202 void StopStreamFromUI(const std::string& label);
203 203
204 void DoCancelRequest(const std::string& label);
205
206 void DoStopStreamDevice(int render_process_id,
207 int render_view_id,
208 const std::string& device_id);
209
210 void DoEnumerateDevices(const std::string& label);
211
204 // Helpers. 212 // Helpers.
205 // Checks if all devices that was requested in the request identififed by 213 // Checks if all devices that was requested in the request identififed by
206 // |label| has been opened and set the request state accordingly. 214 // |label| has been opened and set the request state accordingly.
207 void HandleRequestDone(const std::string& label, 215 void HandleRequestDone(const std::string& label,
208 DeviceRequest* request); 216 DeviceRequest* request);
209 void StopDevice(const StreamDeviceInfo& device_info); 217 void StopDevice(const StreamDeviceInfo& device_info);
210 // Returns true if a request for devices has been completed and the devices 218 // Returns true if a request for devices has been completed and the devices
211 // has either been opened or an error has occurred. 219 // has either been opened or an error has occurred.
212 bool RequestDone(const DeviceRequest& request) const; 220 bool RequestDone(const DeviceRequest& request) const;
213 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); 221 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type);
214 void StartEnumeration(DeviceRequest* request); 222 void StartEnumeration(DeviceRequest* request);
215 std::string AddRequest(DeviceRequest* request); 223 std::string AddRequest(DeviceRequest* request);
216 void RemoveRequest(DeviceRequests::iterator it); 224 void DeleteRequest(DeviceRequests::iterator it);
217 void ClearEnumerationCache(EnumerationCache* cache); 225 void ClearEnumerationCache(EnumerationCache* cache);
218 void PostRequestToUI(const std::string& label); 226 void PostRequestToUI(const std::string& label);
219 void HandleRequest(const std::string& label); 227 void HandleRequest(const std::string& label);
228 bool SetupTabCaptureRequest(DeviceRequest* request);
229 bool SetupScreenCaptureRequest(DeviceRequest* request);
220 // Returns true if a device with |device_id| has already been requested by 230 // Returns true if a device with |device_id| has already been requested by
221 // |render_process_id| and |render_view_id| of type |type|. If it has been 231 // |render_process_id| and |render_view_id| of type |type|. If it has been
222 // requested, |device_info| contain information about the the device. 232 // requested, |device_info| contain information about the device.
223 bool FindExistingRequestedDeviceInfo(int render_process_id, 233 bool FindExistingRequestedDeviceInfo(int render_process_id,
224 int render_view_id, 234 int render_view_id,
235 GURL security_origin,
tommi (sloooow) - chröme 2013/10/28 13:48:23 const GURL&
perkj_chrome 2013/10/29 08:52:17 Done.
225 MediaStreamRequestType type, 236 MediaStreamRequestType type,
226 const std::string& device_id, 237 const std::string& device_id,
238 MediaStreamType device_type,
227 StreamDeviceInfo* device_info, 239 StreamDeviceInfo* device_info,
228 MediaRequestState* request_state) const; 240 MediaRequestState* request_state) const;
229 241
230 // Sends cached device list to a client corresponding to the request 242 void FinalizeGenerateStream(const std::string& label,
231 // identified by |label|. 243 DeviceRequest* request);
232 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label); 244 void FinalizeRequestFailed(const std::string& label);
245 void FinalizeOpenDevice(const std::string& label,
246 DeviceRequest* request);
247 void FinalizeMediaAccessRequest(const std::string& label,
248 const MediaStreamDevices& devices);
249 void FinalizeEnumerateDevices(const std::string& label,
250 DeviceRequest* request);
233 251
234 // Helpers to start and stop monitoring devices. 252 // Helpers to start and stop monitoring devices.
235 void StartMonitoring(); 253 void StartMonitoring();
236 void StopMonitoring(); 254 void StopMonitoring();
237 255
238 // Finds and returns the raw device id corresponding to the given 256 bool TransLateRequestedSourceIdToDeviceId(MediaStreamRequest* request);
239 // |device_guid|. Returns true if there was a raw device id that matched the 257 // Finds and returns the device id corresponding to the given
240 // given |device_guid|, false if nothing matched it. 258 // |source_id|. Returns true if there was a raw device id that matched the
241 bool TranslateGUIDToRawId( 259 // given |source_id|, false if nothing matched it.
260 bool TranslateSourceIdToDeviceId(
242 MediaStreamType stream_type, 261 MediaStreamType stream_type,
243 const GURL& security_origin, 262 const GURL& security_origin,
244 const std::string& device_guid, 263 const std::string& source_id,
245 std::string* raw_device_id); 264 std::string* device_id);
246 265
247 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. 266 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager.
248 scoped_ptr<base::Thread> device_thread_; 267 scoped_ptr<base::Thread> device_thread_;
249 268
250 media::AudioManager* const audio_manager_; // not owned 269 media::AudioManager* const audio_manager_; // not owned
251 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; 270 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
252 scoped_refptr<VideoCaptureManager> video_capture_manager_; 271 scoped_refptr<VideoCaptureManager> video_capture_manager_;
253 272
254 // Indicator of device monitoring state. 273 // Indicator of device monitoring state.
255 bool monitoring_started_; 274 bool monitoring_started_;
(...skipping 21 matching lines...) Expand all
277 296
278 bool use_fake_ui_; 297 bool use_fake_ui_;
279 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; 298 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_;
280 299
281 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); 300 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager);
282 }; 301 };
283 302
284 } // namespace content 303 } // namespace content
285 304
286 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 305 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698