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

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

Issue 10912004: Begin adding support for tab mirroring via the MediaStream audio/video capturing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: AudioManager injection into MediaStreamManager, consistent enum naming; per wjia@ comments. Also, … Created 8 years, 3 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.
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 // MediaStreamDeviceSettings. 13 // MediaStreamDeviceSettings.
14 // 4. MediaStreamDeviceSettings will, by using user settings, pick devices which 14 // 4. MediaStreamDeviceSettings will, by using user settings, pick devices which
15 // devices to use and let MediaStreamManager know the result. 15 // devices to use and let MediaStreamManager know the result.
16 // 5. MediaStreamManager will call the proper media device manager to open the 16 // 5. MediaStreamManager will call the proper media device manager to open the
17 // device and let the MediaStreamRequester know it has been done. 17 // device and let the MediaStreamRequester know it has been done.
18 18
19 // When enumeration and open are done in separate operations, 19 // When enumeration and open are done in separate operations,
20 // MediaStreamDeviceSettings is not involved as in steps. 20 // MediaStreamDeviceSettings is not involved as in steps.
21 21
22 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 22 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
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>
28 27
29 #include "base/basictypes.h" 28 #include "base/basictypes.h"
30 #include "base/memory/scoped_ptr.h" 29 #include "base/memory/scoped_ptr.h"
31 #include "base/memory/ref_counted.h" 30 #include "base/memory/ref_counted.h"
32 #include "base/message_loop.h" 31 #include "base/message_loop.h"
33 #include "base/system_monitor/system_monitor.h" 32 #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;
44 } 43 }
45 } 44 }
46 45
46 namespace media {
47 class AudioManager;
48 }
49
47 namespace media_stream { 50 namespace media_stream {
48 51
49 class AudioInputDeviceManager; 52 class AudioInputDeviceManager;
50 class MediaStreamDeviceSettings; 53 class MediaStreamDeviceSettings;
51 class MediaStreamRequester; 54 class MediaStreamRequester;
52 class VideoCaptureManager; 55 class VideoCaptureManager;
53 56
54 // Thread that enters MTA on windows, and is base::Thread on linux and mac. 57 // Thread that enters MTA on windows, and is base::Thread on linux and mac.
55 class DeviceThread : public base::Thread { 58 class DeviceThread : public base::Thread {
56 public: 59 public:
(...skipping 12 matching lines...) Expand all
69 // MediaStreamManager is used to generate and close new media devices, not to 72 // MediaStreamManager is used to generate and close new media devices, not to
70 // start the media flow. 73 // start the media flow.
71 // The classes requesting new media streams are answered using 74 // The classes requesting new media streams are answered using
72 // MediaStreamManager::Listener. 75 // MediaStreamManager::Listener.
73 class CONTENT_EXPORT MediaStreamManager 76 class CONTENT_EXPORT MediaStreamManager
74 : public MediaStreamProviderListener, 77 : public MediaStreamProviderListener,
75 public MessageLoop::DestructionObserver, 78 public MessageLoop::DestructionObserver,
76 public SettingsRequester, 79 public SettingsRequester,
77 public base::SystemMonitor::DevicesChangedObserver { 80 public base::SystemMonitor::DevicesChangedObserver {
78 public: 81 public:
79 // This class takes the ownerships of the |audio_input_device_manager| 82 explicit MediaStreamManager(media::AudioManager* audio_manager);
80 // and |video_capture_manager|.
81 MediaStreamManager(AudioInputDeviceManager* audio_input_device_manager,
82 VideoCaptureManager* video_capture_manager);
83
84 virtual ~MediaStreamManager(); 83 virtual ~MediaStreamManager();
85 84
86 // Used to access VideoCaptureManager. 85 // Used to access the VideoCaptureManager for the given |stream_type|.
87 VideoCaptureManager* video_capture_manager(); 86 VideoCaptureManager* GetVideoCaptureManager(MediaStreamType stream_type);
88 87
89 // Used to access AudioInputDeviceManager. 88 // Used to access the AudioInputDeviceManager for the given |stream_type|.
90 AudioInputDeviceManager* audio_input_device_manager(); 89 AudioInputDeviceManager* GetAudioInputDeviceManager(
90 MediaStreamType stream_type);
91 91
92 // GenerateStream opens new media devices according to |components|. It 92 // GenerateStream opens new media devices according to |components|. It
93 // creates a new request which is identified by a unique |label| that's 93 // creates a new request which is identified by a unique |label| that's
94 // returned to the caller. 94 // returned to the caller. |render_process_id| and |render_view_id| refer to
95 // the view where the infobar will appear to the user.
95 void GenerateStream(MediaStreamRequester* requester, int render_process_id, 96 void GenerateStream(MediaStreamRequester* requester, int render_process_id,
96 int render_view_id, const StreamOptions& options, 97 int render_view_id, const StreamOptions& components,
97 const GURL& security_origin, std::string* label); 98 const GURL& security_origin, std::string* label);
98 99
100 // Like GenerateStream above, except the user is only able to allow/deny the
101 // request for the device specified by |device_id|.
102 void GenerateStreamForDevice(MediaStreamRequester* requester,
no longer working on chromium 2012/09/10 09:11:04 use the label instead?
miu 2012/09/10 21:24:38 I don't quite follow you here. Are you suggesting
no longer working on chromium 2012/09/10 22:12:38 Sorry, wrong comment, I meant returning the label,
103 int render_process_id, int render_view_id,
104 const StreamOptions& components,
105 const std::string& device_id,
106 const GURL& security_origin, std::string* label);
107
99 // Cancel generate stream. 108 // Cancel generate stream.
100 void CancelGenerateStream(const std::string& label); 109 void CancelGenerateStream(const std::string& label);
101 110
102 // Closes generated stream. 111 // Closes generated stream.
103 void StopGeneratedStream(const std::string& label); 112 void StopGeneratedStream(const std::string& label);
104 113
105 // Gets a list of devices of |type|. 114 // Gets a list of devices of |type|, which must be MEDIA_DEVICE_AUDIO_CAPTURE
115 // or MEDIA_DEVICE_VIDEO_CAPTURE.
106 // The request is identified using |label|, which is pointing to a 116 // The request is identified using |label|, which is pointing to a
107 // std::string. 117 // std::string.
108 // The request is persistent, which means the client keeps listening to 118 // The request is persistent, which means the client keeps listening to
109 // device changes, such as plug/unplug, and expects new device list for 119 // device changes, such as plug/unplug, and expects new device list for
110 // such a change, till the client stops the request. 120 // such a change, till the client stops the request.
111 void EnumerateDevices(MediaStreamRequester* requester, 121 void EnumerateDevices(MediaStreamRequester* requester,
112 int render_process_id, 122 int render_process_id,
113 int render_view_id, 123 int render_view_id,
114 MediaStreamType type, 124 MediaStreamType type,
115 const GURL& security_origin, 125 const GURL& security_origin,
116 std::string* label); 126 std::string* label);
117 127
118 // Open a device identified by |device_id|. 128 // Open a device identified by |device_id|. |type| must be either
129 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE.
119 // The request is identified using |label|, which is pointing to a 130 // The request is identified using |label|, which is pointing to a
120 // std::string. 131 // std::string.
121 void OpenDevice(MediaStreamRequester* requester, 132 void OpenDevice(MediaStreamRequester* requester,
122 int render_process_id, 133 int render_process_id,
123 int render_view_id, 134 int render_view_id,
124 const std::string& device_id, 135 const std::string& device_id,
125 MediaStreamType type, 136 MediaStreamType type,
126 const GURL& security_origin, 137 const GURL& security_origin,
127 std::string* label); 138 std::string* label);
128 139
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 void NotifyObserverDevicesOpened(DeviceRequest* request); 186 void NotifyObserverDevicesOpened(DeviceRequest* request);
176 void NotifyObserverDevicesClosed(DeviceRequest* request); 187 void NotifyObserverDevicesClosed(DeviceRequest* request);
177 void DevicesFromRequest(DeviceRequest* request, 188 void DevicesFromRequest(DeviceRequest* request,
178 content::MediaStreamDevices* devices); 189 content::MediaStreamDevices* devices);
179 190
180 // Helpers. 191 // Helpers.
181 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; 192 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const;
182 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); 193 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type);
183 void StartEnumeration(DeviceRequest* new_request, 194 void StartEnumeration(DeviceRequest* new_request,
184 std::string* label); 195 std::string* label);
185 void AddRequest(DeviceRequest* new_request, std::string* label); 196 void AddRequest(const DeviceRequest& new_request, std::string* label);
186 bool HasEnumerationRequest(MediaStreamType type); 197 bool HasEnumerationRequest(MediaStreamType type);
187 bool HasEnumerationRequest(); 198 bool HasEnumerationRequest();
188 void ClearEnumerationCache(EnumerationCache* cache); 199 void ClearEnumerationCache(EnumerationCache* cache);
189 200
190 // Helper to ensure the device thread and pass the message loop to device 201 // Helper to create the device manager for the given stream_type, if needed.
191 // managers, it also register itself as the listener to the device managers. 202 // Auto-starts the device thread and registers this as a listener with the
192 void EnsureDeviceThreadAndListener(); 203 // device managers.
204 void EnsureDeviceManagerStarted(MediaStreamType stream_type);
193 205
194 // Sends cached device list to a client corresponding to the request 206 // Sends cached device list to a client corresponding to the request
195 // identified by |label|. 207 // identified by |label|.
196 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label); 208 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label);
197 209
198 // Stop the request of enumerating devices indentified by |label|. 210 // Stop the request of enumerating devices indentified by |label|.
199 void StopEnumerateDevices(const std::string& label); 211 void StopEnumerateDevices(const std::string& label);
200 212
201 // Helpers to start and stop monitoring devices. 213 // Helpers to start and stop monitoring devices.
202 void StartMonitoring(); 214 void StartMonitoring();
203 void StopMonitoring(); 215 void StopMonitoring();
204 216
205 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. 217 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager.
206 scoped_ptr<base::Thread> device_thread_; 218 scoped_ptr<base::Thread> device_thread_;
207 219
208 scoped_ptr<MediaStreamDeviceSettings> device_settings_; 220 scoped_ptr<MediaStreamDeviceSettings> device_settings_;
209 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; 221
210 scoped_refptr<VideoCaptureManager> video_capture_manager_; 222 media::AudioManager* const audio_manager_; // not owned
223
224 // Device managers, instantiated on-demand.
225 scoped_refptr<MediaStreamProvider> device_manager_[content::NUM_MEDIA_TYPES];
211 226
212 // Indicator of device monitoring state. 227 // Indicator of device monitoring state.
213 bool monitoring_started_; 228 bool monitoring_started_;
214 229
215 // Stores most recently enumerated device lists. The cache is cleared when 230 // Stores most recently enumerated device lists. The cache is cleared when
216 // monitoring is stopped or there is no request for that type of device. 231 // monitoring is stopped or there is no request for that type of device.
217 EnumerationCache audio_enumeration_cache_; 232 EnumerationCache audio_enumeration_cache_;
218 EnumerationCache video_enumeration_cache_; 233 EnumerationCache video_enumeration_cache_;
219 234
220 // Keeps track of live enumeration commands sent to VideoCaptureManager or 235 // Keeps track of live enumeration commands sent to VideoCaptureManager or
221 // AudioInputDeviceManager, in order to only enumerate when necessary. 236 // AudioInputDeviceManager, in order to only enumerate when necessary.
222 int active_enumeration_ref_count_[content::NUM_MEDIA_STREAM_DEVICE_TYPES]; 237 int active_enumeration_ref_count_[content::NUM_MEDIA_TYPES];
223 238
224 // All non-closed request. 239 // All non-closed request.
225 typedef std::map<std::string, DeviceRequest> DeviceRequests; 240 typedef std::map<std::string, DeviceRequest> DeviceRequests;
226 DeviceRequests requests_; 241 DeviceRequests requests_;
227 242
228 // Hold a pointer to the IO loop to check we delete the device thread and 243 // Hold a pointer to the IO loop to check we delete the device thread and
229 // managers on the right thread. 244 // managers on the right thread.
230 MessageLoop* io_loop_; 245 MessageLoop* io_loop_;
231 246
232 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); 247 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager);
233 }; 248 };
234 249
235 } // namespace media_stream 250 } // namespace media_stream
236 251
237 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 252 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698