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

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

Issue 2487133003: Remove dead code related to media device enumerations and monitoring. (Closed)
Patch Set: rebase Created 4 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
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 media capture devices (video supported
6 // supported now). Call flow: 6 // 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.
11 // 3. MediaStreamManager will request the corresponding media device manager(s) 11 // 3. MediaStreamManager will request the corresponding media device manager(s)
12 // to enumerate available devices. The result will be given to 12 // to enumerate available devices. The result will be given to
13 // MediaStreamUIController. 13 // MediaStreamUIController.
14 // 4. MediaStreamUIController will, by posting the request to UI, let the 14 // 4. MediaStreamUIController will, by posting the request to UI, let the
15 // users to select which devices to use and send callback to 15 // users to select which devices to use and send callback to
16 // MediaStreamManager with the result. 16 // MediaStreamManager with the result.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 // Cancel all requests for the given |render_process_id|. 134 // Cancel all requests for the given |render_process_id|.
135 void CancelAllRequests(int render_process_id); 135 void CancelAllRequests(int render_process_id);
136 136
137 // Closes the stream device for a certain render frame. The stream must have 137 // Closes the stream device for a certain render frame. The stream must have
138 // been opened by a call to GenerateStream. 138 // been opened by a call to GenerateStream.
139 void StopStreamDevice(int render_process_id, 139 void StopStreamDevice(int render_process_id,
140 int render_frame_id, 140 int render_frame_id,
141 const std::string& device_id); 141 const std::string& device_id);
142 142
143 // Gets a list of devices of |type|, which must be MEDIA_DEVICE_AUDIO_CAPTURE
144 // or MEDIA_DEVICE_VIDEO_CAPTURE.
145 // The request is identified using the string returned to the caller.
146 // When the |requester| is NULL, MediaStreamManager will enumerate both audio
147 // and video devices and also start monitoring device changes, such as
148 // plug/unplug. The new device lists will be delivered via media observer to
149 // MediaCaptureDevicesDispatcher.
150 virtual std::string EnumerateDevices(MediaStreamRequester* requester,
151 int render_process_id,
152 int render_frame_id,
153 const std::string& salt,
154 int page_request_id,
155 MediaStreamType type,
156 const url::Origin& security_origin);
157
158 // Open a device identified by |device_id|. |type| must be either 143 // Open a device identified by |device_id|. |type| must be either
159 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. 144 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE.
160 // The request is identified using string returned to the caller. 145 // The request is identified using string returned to the caller.
161 void OpenDevice(MediaStreamRequester* requester, 146 void OpenDevice(MediaStreamRequester* requester,
162 int render_process_id, 147 int render_process_id,
163 int render_frame_id, 148 int render_frame_id,
164 const std::string& salt, 149 const std::string& salt,
165 int page_request_id, 150 int page_request_id,
166 const std::string& device_id, 151 const std::string& device_id,
167 MediaStreamType type, 152 MediaStreamType type,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 void UseFakeUIForTests(std::unique_ptr<FakeMediaStreamUIProxy> fake_ui); 205 void UseFakeUIForTests(std::unique_ptr<FakeMediaStreamUIProxy> fake_ui);
221 206
222 // Register and unregister a new callback for receiving native log entries. 207 // Register and unregister a new callback for receiving native log entries.
223 // The registered callback will be invoked on the IO thread. 208 // The registered callback will be invoked on the IO thread.
224 // The registration and unregistration will be done asynchronously so it is 209 // The registration and unregistration will be done asynchronously so it is
225 // not guaranteed that when the call returns the operation has completed. 210 // not guaranteed that when the call returns the operation has completed.
226 void RegisterNativeLogCallback(int renderer_host_id, 211 void RegisterNativeLogCallback(int renderer_host_id,
227 const base::Callback<void(const std::string&)>& callback); 212 const base::Callback<void(const std::string&)>& callback);
228 void UnregisterNativeLogCallback(int renderer_host_id); 213 void UnregisterNativeLogCallback(int renderer_host_id);
229 214
230 // Register and unregister subscribers for device-change notifications.
231 // It is an error to try to subscribe a |subscriber| that is already
232 // subscribed or to cancel the subscription of a |subscriber| that is not
233 // subscribed. Also, subscribers must make sure to invoke
234 // CancelDeviceChangeNotifications() before destruction. Otherwise, dangling
235 // pointers and use-after-destruction problems will occur.
236 void SubscribeToDeviceChangeNotifications(MediaStreamRequester* subscriber);
237 void CancelDeviceChangeNotifications(MediaStreamRequester* subscriber);
238
239 // Generates a hash of a device's unique ID usable by one 215 // Generates a hash of a device's unique ID usable by one
240 // particular security origin. 216 // particular security origin.
241 static std::string GetHMACForMediaDeviceID(const std::string& salt, 217 static std::string GetHMACForMediaDeviceID(const std::string& salt,
242 const url::Origin& security_origin, 218 const url::Origin& security_origin,
243 const std::string& raw_unique_id); 219 const std::string& raw_unique_id);
244 220
245 // Convenience method to check if |device_guid| is an HMAC of 221 // Convenience method to check if |device_guid| is an HMAC of
246 // |raw_device_id| for |security_origin|. 222 // |raw_device_id| for |security_origin|.
247 static bool DoesMediaDeviceIDMatchHMAC(const std::string& salt, 223 static bool DoesMediaDeviceIDMatchHMAC(const std::string& salt,
248 const url::Origin& security_origin, 224 const url::Origin& security_origin,
(...skipping 14 matching lines...) Expand all
263 // Helper for sending up-to-date device lists to media observer when a 239 // Helper for sending up-to-date device lists to media observer when a
264 // capture device is plugged in or unplugged. 240 // capture device is plugged in or unplugged.
265 void NotifyDevicesChanged(MediaDeviceType stream_type, 241 void NotifyDevicesChanged(MediaDeviceType stream_type,
266 const MediaDeviceInfoArray& devices); 242 const MediaDeviceInfoArray& devices);
267 243
268 // This method is called when an audio or video device is removed. It makes 244 // This method is called when an audio or video device is removed. It makes
269 // sure all MediaStreams that use a removed device are stopped and that the 245 // sure all MediaStreams that use a removed device are stopped and that the
270 // render process is notified. 246 // render process is notified.
271 void StopRemovedDevice(MediaDeviceType type, const MediaDeviceInfo& device); 247 void StopRemovedDevice(MediaDeviceType type, const MediaDeviceInfo& device);
272 248
273 // TODO(guidou): Remove this function once handling for renderer requests for
274 // device-event notifications is moved out of MediaStreamDispatcherHost.
275 // See http://crbug.com/648183.
276 void NotifyDeviceChangeSubscribers(MediaStreamType type);
277
278 void SetGenerateStreamCallbackForTesting( 249 void SetGenerateStreamCallbackForTesting(
279 GenerateStreamTestCallback test_callback); 250 GenerateStreamTestCallback test_callback);
280 251
281 private: 252 private:
282 // Contains all data needed to keep track of requests. 253 // Contains all data needed to keep track of requests.
283 class DeviceRequest; 254 class DeviceRequest;
284 255
285 // |DeviceRequests| is a list to ensure requests are processed in the order 256 // |DeviceRequests| is a list to ensure requests are processed in the order
286 // they arrive. The first member of the pair is the label of the 257 // they arrive. The first member of the pair is the label of the
287 // |DeviceRequest|. 258 // |DeviceRequest|.
288 using LabeledDeviceRequest = std::pair<std::string, DeviceRequest*>; 259 using LabeledDeviceRequest = std::pair<std::string, DeviceRequest*>;
289 using DeviceRequests = std::list<LabeledDeviceRequest>; 260 using DeviceRequests = std::list<LabeledDeviceRequest>;
290 261
291 // Initializes the device managers on IO thread. Auto-starts the device 262 // Initializes the device managers on IO thread. Auto-starts the device
292 // thread and registers this as a listener with the device managers. 263 // thread and registers this as a listener with the device managers.
293 void InitializeDeviceManagersOnIOThread(); 264 void InitializeDeviceManagersOnIOThread();
294 265
295
296 // |output_parameters| contains real values only if the request requires it. 266 // |output_parameters| contains real values only if the request requires it.
297 void HandleAccessRequestResponse( 267 void HandleAccessRequestResponse(
298 const std::string& label, 268 const std::string& label,
299 const media::AudioParameters& output_parameters, 269 const media::AudioParameters& output_parameters,
300 const MediaStreamDevices& devices, 270 const MediaStreamDevices& devices,
301 content::MediaStreamRequestResult result); 271 content::MediaStreamRequestResult result);
302 void StopMediaStreamFromBrowser(const std::string& label); 272 void StopMediaStreamFromBrowser(const std::string& label);
303 273
304 void DoEnumerateDevices(const std::string& label);
305
306 void AudioOutputDevicesEnumerated(const std::string& label,
307 const MediaDeviceEnumeration& enumeration);
308
309 // Helpers. 274 // Helpers.
310 // Checks if all devices that was requested in the request identififed by 275 // Checks if all devices that was requested in the request identififed by
311 // |label| has been opened and set the request state accordingly. 276 // |label| has been opened and set the request state accordingly.
312 void HandleRequestDone(const std::string& label, 277 void HandleRequestDone(const std::string& label,
313 DeviceRequest* request); 278 DeviceRequest* request);
314 // Stop the use of the device associated with |session_id| of type |type| in 279 // Stop the use of the device associated with |session_id| of type |type| in
315 // all |requests_|. The device is removed from the request. If a request 280 // all |requests_|. The device is removed from the request. If a request
316 /// doesn't use any devices as a consequence, the request is deleted. 281 /// doesn't use any devices as a consequence, the request is deleted.
317 void StopDevice(MediaStreamType type, int session_id); 282 void StopDevice(MediaStreamType type, int session_id);
318 // Calls the correct capture manager and close the device with |session_id|. 283 // Calls the correct capture manager and close the device with |session_id|.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 MediaRequestState* existing_request_state) const; 329 MediaRequestState* existing_request_state) const;
365 330
366 void FinalizeGenerateStream(const std::string& label, DeviceRequest* request); 331 void FinalizeGenerateStream(const std::string& label, DeviceRequest* request);
367 void FinalizeRequestFailed(const std::string& label, 332 void FinalizeRequestFailed(const std::string& label,
368 DeviceRequest* request, 333 DeviceRequest* request,
369 content::MediaStreamRequestResult result); 334 content::MediaStreamRequestResult result);
370 void FinalizeOpenDevice(const std::string& label, DeviceRequest* request); 335 void FinalizeOpenDevice(const std::string& label, DeviceRequest* request);
371 void FinalizeMediaAccessRequest(const std::string& label, 336 void FinalizeMediaAccessRequest(const std::string& label,
372 DeviceRequest* request, 337 DeviceRequest* request,
373 const MediaStreamDevices& devices); 338 const MediaStreamDevices& devices);
374 void FinalizeEnumerateDevices(const std::string& label,
375 DeviceRequest* request);
376 void HandleCheckMediaAccessResponse(const std::string& label, 339 void HandleCheckMediaAccessResponse(const std::string& label,
377 bool have_access); 340 bool have_access);
378 341
379 // Picks a device ID from a list of required and alternate device IDs, 342 // Picks a device ID from a list of required and alternate device IDs,
380 // presented as part of a TrackControls structure. 343 // presented as part of a TrackControls structure.
381 // Either the required device ID is picked (if present), or the first 344 // Either the required device ID is picked (if present), or the first
382 // valid alternate device ID. 345 // valid alternate device ID.
383 // Returns false if the required device ID is present and invalid. 346 // Returns false if the required device ID is present and invalid.
384 // Otherwise, if no valid device is found, device_id is unchanged. 347 // Otherwise, if no valid device is found, device_id is unchanged.
385 bool PickDeviceId(const std::string& salt, 348 bool PickDeviceId(const std::string& salt,
(...skipping 22 matching lines...) Expand all
408 void DoNativeLogCallbackRegistration(int renderer_host_id, 371 void DoNativeLogCallbackRegistration(int renderer_host_id,
409 const base::Callback<void(const std::string&)>& callback); 372 const base::Callback<void(const std::string&)>& callback);
410 void DoNativeLogCallbackUnregistration(int renderer_host_id); 373 void DoNativeLogCallbackUnregistration(int renderer_host_id);
411 374
412 // Callback to handle the reply to a low-level enumeration request. 375 // Callback to handle the reply to a low-level enumeration request.
413 void DevicesEnumerated(bool requested_audio_input, 376 void DevicesEnumerated(bool requested_audio_input,
414 bool requested_video_input, 377 bool requested_video_input,
415 const std::string& label, 378 const std::string& label,
416 const MediaDeviceEnumeration& enumeration); 379 const MediaDeviceEnumeration& enumeration);
417 380
418 // TODO(guidou): Remove once handling of renderer-issued enumeration requests
419 // is moved out of MediaStreamManager. See http://crbug.com/648183.
420 void ProcessEnumerationRequest(const std::string& label,
421 DeviceRequest* request,
422 MediaStreamType stream_type,
423 const MediaDeviceInfoArray& enumeration);
424
425 // TODO(guidou): Remove this function once the concept of open enumeration
426 // requests is eliminated. See http://crbug.com/648183.
427 void ProcessOpenEnumerationRequests(MediaStreamType stream_type,
428 const MediaDeviceInfoArray& devices);
429
430 // Task runner shared by VideoCaptureManager and AudioInputDeviceManager and 381 // Task runner shared by VideoCaptureManager and AudioInputDeviceManager and
431 // used for enumerating audio output devices. 382 // used for enumerating audio output devices.
432 // Note: Enumeration tasks may take seconds to complete so must never be run 383 // Note: Enumeration tasks may take seconds to complete so must never be run
433 // on any of the BrowserThreads (UI, IO, etc). See http://crbug.com/256945. 384 // on any of the BrowserThreads (UI, IO, etc). See http://crbug.com/256945.
434 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; 385 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_;
435 386
436 media::AudioManager* const audio_manager_; // not owned 387 media::AudioManager* const audio_manager_; // not owned
437 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; 388 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
438 scoped_refptr<VideoCaptureManager> video_capture_manager_; 389 scoped_refptr<VideoCaptureManager> video_capture_manager_;
439 #if defined(OS_WIN) 390 #if defined(OS_WIN)
440 base::Thread video_capture_thread_; 391 base::Thread video_capture_thread_;
441 #endif 392 #endif
442 393
443 std::unique_ptr<MediaDevicesManager> media_devices_manager_; 394 std::unique_ptr<MediaDevicesManager> media_devices_manager_;
444 395
445 // All non-closed request. Must be accessed on IO thread. 396 // All non-closed request. Must be accessed on IO thread.
446 DeviceRequests requests_; 397 DeviceRequests requests_;
447 398
448 bool use_fake_ui_; 399 bool use_fake_ui_;
449 std::unique_ptr<FakeMediaStreamUIProxy> fake_ui_; 400 std::unique_ptr<FakeMediaStreamUIProxy> fake_ui_;
450 401
451 // Maps render process hosts to log callbacks. Used on the IO thread. 402 // Maps render process hosts to log callbacks. Used on the IO thread.
452 std::map<int, base::Callback<void(const std::string&)>> log_callbacks_; 403 std::map<int, base::Callback<void(const std::string&)>> log_callbacks_;
453 404
454 // Objects subscribed to changes in the set of media devices.
455 std::vector<MediaStreamRequester*> device_change_subscribers_;
456
457 GenerateStreamTestCallback generate_stream_test_callback_; 405 GenerateStreamTestCallback generate_stream_test_callback_;
458 406
459 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); 407 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager);
460 }; 408 };
461 409
462 } // namespace content 410 } // namespace content
463 411
464 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 412 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698