| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 #include "base/basictypes.h" | 30 #include "base/basictypes.h" |
| 31 #include "base/memory/ref_counted.h" | 31 #include "base/memory/ref_counted.h" |
| 32 #include "base/memory/scoped_ptr.h" | 32 #include "base/memory/scoped_ptr.h" |
| 33 #include "base/message_loop/message_loop.h" | 33 #include "base/message_loop/message_loop.h" |
| 34 #include "base/system_monitor/system_monitor.h" | 34 #include "base/system_monitor/system_monitor.h" |
| 35 #include "content/browser/renderer_host/media/media_stream_provider.h" | 35 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 36 #include "content/common/content_export.h" | 36 #include "content/common/content_export.h" |
| 37 #include "content/common/media/media_stream_options.h" | 37 #include "content/common/media/media_stream_options.h" |
| 38 #include "content/public/browser/media_request_state.h" | 38 #include "content/public/browser/media_request_state.h" |
| 39 #include "content/public/browser/resource_context.h" |
| 39 | 40 |
| 40 namespace media { | 41 namespace media { |
| 41 class AudioManager; | 42 class AudioManager; |
| 42 } | 43 } |
| 43 | 44 |
| 44 namespace content { | 45 namespace content { |
| 45 | 46 |
| 46 class AudioInputDeviceManager; | 47 class AudioInputDeviceManager; |
| 47 class FakeMediaStreamUIProxy; | 48 class FakeMediaStreamUIProxy; |
| 48 class MediaStreamDeviceSettings; | 49 class MediaStreamDeviceSettings; |
| 49 class MediaStreamRequester; | 50 class MediaStreamRequester; |
| 50 class MediaStreamUIProxy; | 51 class MediaStreamUIProxy; |
| 51 class ResourceContext; | |
| 52 class VideoCaptureManager; | 52 class VideoCaptureManager; |
| 53 | 53 |
| 54 // MediaStreamManager is used to generate and close new media devices, not to | 54 // MediaStreamManager is used to generate and close new media devices, not to |
| 55 // start the media flow. The classes requesting new media streams are answered | 55 // start the media flow. The classes requesting new media streams are answered |
| 56 // using MediaStreamRequester. | 56 // using MediaStreamRequester. |
| 57 class CONTENT_EXPORT MediaStreamManager | 57 class CONTENT_EXPORT MediaStreamManager |
| 58 : public MediaStreamProviderListener, | 58 : public MediaStreamProviderListener, |
| 59 public base::MessageLoop::DestructionObserver, | 59 public base::MessageLoop::DestructionObserver, |
| 60 public base::SystemMonitor::DevicesChangedObserver { | 60 public base::SystemMonitor::DevicesChangedObserver { |
| 61 public: | 61 public: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 87 const GURL& security_origin, | 87 const GURL& security_origin, |
| 88 const MediaRequestResponseCallback& callback); | 88 const MediaRequestResponseCallback& callback); |
| 89 | 89 |
| 90 // GenerateStream opens new media devices according to |components|. It | 90 // GenerateStream opens new media devices according to |components|. It |
| 91 // creates a new request which is identified by a unique string that's | 91 // creates a new request which is identified by a unique string that's |
| 92 // returned to the caller. |render_process_id| and |render_view_id| refer to | 92 // returned to the caller. |render_process_id| and |render_view_id| refer to |
| 93 // the view where the infobar will appear to the user. | 93 // the view where the infobar will appear to the user. |
| 94 void GenerateStream(MediaStreamRequester* requester, | 94 void GenerateStream(MediaStreamRequester* requester, |
| 95 int render_process_id, | 95 int render_process_id, |
| 96 int render_view_id, | 96 int render_view_id, |
| 97 ResourceContext* rc, | 97 const ResourceContext::SaltCallback& sc, |
| 98 int page_request_id, | 98 int page_request_id, |
| 99 const StreamOptions& components, | 99 const StreamOptions& components, |
| 100 const GURL& security_origin); | 100 const GURL& security_origin); |
| 101 | 101 |
| 102 void CancelRequest(int render_process_id, | 102 void CancelRequest(int render_process_id, |
| 103 int render_view_id, | 103 int render_view_id, |
| 104 int page_request_id); | 104 int page_request_id); |
| 105 | 105 |
| 106 // Cancel an open request identified by |label|. | 106 // Cancel an open request identified by |label|. |
| 107 virtual void CancelRequest(const std::string& label); | 107 virtual void CancelRequest(const std::string& label); |
| 108 | 108 |
| 109 // Cancel all requests for the given |render_process_id|. | 109 // Cancel all requests for the given |render_process_id|. |
| 110 void CancelAllRequests(int render_process_id); | 110 void CancelAllRequests(int render_process_id); |
| 111 | 111 |
| 112 // Closes the stream device for a certain render view. The stream must have | 112 // Closes the stream device for a certain render view. The stream must have |
| 113 // been opened by a call to GenerateStream. | 113 // been opened by a call to GenerateStream. |
| 114 void StopStreamDevice(int render_process_id, | 114 void StopStreamDevice(int render_process_id, |
| 115 int render_view_id, | 115 int render_view_id, |
| 116 const std::string& device_id); | 116 const std::string& device_id); |
| 117 | 117 |
| 118 // Gets a list of devices of |type|, which must be MEDIA_DEVICE_AUDIO_CAPTURE | 118 // Gets a list of devices of |type|, which must be MEDIA_DEVICE_AUDIO_CAPTURE |
| 119 // or MEDIA_DEVICE_VIDEO_CAPTURE. | 119 // or MEDIA_DEVICE_VIDEO_CAPTURE. |
| 120 // The request is identified using the string returned to the caller. | 120 // The request is identified using the string returned to the caller. |
| 121 // When the |requester| is NULL, MediaStreamManager will enumerate both audio | 121 // When the |requester| is NULL, MediaStreamManager will enumerate both audio |
| 122 // and video devices and also start monitoring device changes, such as | 122 // and video devices and also start monitoring device changes, such as |
| 123 // plug/unplug. The new device lists will be delivered via media observer to | 123 // plug/unplug. The new device lists will be delivered via media observer to |
| 124 // MediaCaptureDevicesDispatcher. | 124 // MediaCaptureDevicesDispatcher. |
| 125 virtual std::string EnumerateDevices(MediaStreamRequester* requester, | 125 virtual std::string EnumerateDevices(MediaStreamRequester* requester, |
| 126 int render_process_id, | 126 int render_process_id, |
| 127 int render_view_id, | 127 int render_view_id, |
| 128 ResourceContext* rc, | 128 const ResourceContext::SaltCallback& sc, |
| 129 int page_request_id, | 129 int page_request_id, |
| 130 MediaStreamType type, | 130 MediaStreamType type, |
| 131 const GURL& security_origin); | 131 const GURL& security_origin); |
| 132 | 132 |
| 133 // Open a device identified by |device_id|. |type| must be either | 133 // Open a device identified by |device_id|. |type| must be either |
| 134 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. | 134 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. |
| 135 // The request is identified using string returned to the caller. | 135 // The request is identified using string returned to the caller. |
| 136 void OpenDevice(MediaStreamRequester* requester, | 136 void OpenDevice(MediaStreamRequester* requester, |
| 137 int render_process_id, | 137 int render_process_id, |
| 138 int render_view_id, | 138 int render_view_id, |
| 139 ResourceContext* rc, | 139 const ResourceContext::SaltCallback& sc, |
| 140 int page_request_id, | 140 int page_request_id, |
| 141 const std::string& device_id, | 141 const std::string& device_id, |
| 142 MediaStreamType type, | 142 MediaStreamType type, |
| 143 const GURL& security_origin); | 143 const GURL& security_origin); |
| 144 | 144 |
| 145 // Called by UI to make sure the device monitor is started so that UI receive | 145 // Called by UI to make sure the device monitor is started so that UI receive |
| 146 // notifications about device changes. | 146 // notifications about device changes. |
| 147 void EnsureDeviceMonitorStarted(); | 147 void EnsureDeviceMonitorStarted(); |
| 148 | 148 |
| 149 // Implements MediaStreamProviderListener. | 149 // Implements MediaStreamProviderListener. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // corresponding render processes are in |render_process_ids|, to be used by | 321 // corresponding render processes are in |render_process_ids|, to be used by |
| 322 // the webrtcLoggingPrivate API if requested. | 322 // the webrtcLoggingPrivate API if requested. |
| 323 void AddLogMessageOnUIThread(const std::set<int>& render_process_ids, | 323 void AddLogMessageOnUIThread(const std::set<int>& render_process_ids, |
| 324 const std::string& message); | 324 const std::string& message); |
| 325 | 325 |
| 326 // Finds and returns the device id corresponding to the given | 326 // Finds and returns the device id corresponding to the given |
| 327 // |source_id|. Returns true if there was a raw device id that matched the | 327 // |source_id|. Returns true if there was a raw device id that matched the |
| 328 // given |source_id|, false if nothing matched it. | 328 // given |source_id|, false if nothing matched it. |
| 329 bool TranslateSourceIdToDeviceId( | 329 bool TranslateSourceIdToDeviceId( |
| 330 MediaStreamType stream_type, | 330 MediaStreamType stream_type, |
| 331 ResourceContext* rc, | 331 const ResourceContext::SaltCallback& rc, |
| 332 const GURL& security_origin, | 332 const GURL& security_origin, |
| 333 const std::string& source_id, | 333 const std::string& source_id, |
| 334 std::string* device_id) const; | 334 std::string* device_id) const; |
| 335 | 335 |
| 336 // Task runner shared by VideoCaptureManager and AudioInputDeviceManager. | 336 // Task runner shared by VideoCaptureManager and AudioInputDeviceManager. |
| 337 // Note: Enumeration tasks may take seconds to complete so must never be run | 337 // Note: Enumeration tasks may take seconds to complete so must never be run |
| 338 // on any of the BrowserThreads (UI, IO, etc). See http://crbug.com/256945. | 338 // on any of the BrowserThreads (UI, IO, etc). See http://crbug.com/256945. |
| 339 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; | 339 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; |
| 340 | 340 |
| 341 media::AudioManager* const audio_manager_; // not owned | 341 media::AudioManager* const audio_manager_; // not owned |
| (...skipping 21 matching lines...) Expand all Loading... |
| 363 | 363 |
| 364 bool use_fake_ui_; | 364 bool use_fake_ui_; |
| 365 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; | 365 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; |
| 366 | 366 |
| 367 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 367 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
| 368 }; | 368 }; |
| 369 | 369 |
| 370 } // namespace content | 370 } // namespace content |
| 371 | 371 |
| 372 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 372 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
| OLD | NEW |