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

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

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

Powered by Google App Engine
This is Rietveld 408576698