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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 class AudioManager; | 44 class AudioManager; |
45 } | 45 } |
46 | 46 |
47 namespace content { | 47 namespace content { |
48 | 48 |
49 class AudioInputDeviceManager; | 49 class AudioInputDeviceManager; |
50 class FakeMediaStreamUIProxy; | 50 class FakeMediaStreamUIProxy; |
51 class MediaStreamDeviceSettings; | 51 class MediaStreamDeviceSettings; |
52 class MediaStreamRequester; | 52 class MediaStreamRequester; |
53 class MediaStreamUIProxy; | 53 class MediaStreamUIProxy; |
| 54 class ResourceContext; |
54 class VideoCaptureManager; | 55 class VideoCaptureManager; |
55 | 56 |
56 // MediaStreamManager is used to generate and close new media devices, not to | 57 // MediaStreamManager is used to generate and close new media devices, not to |
57 // start the media flow. The classes requesting new media streams are answered | 58 // start the media flow. The classes requesting new media streams are answered |
58 // using MediaStreamRequester. | 59 // using MediaStreamRequester. |
59 class CONTENT_EXPORT MediaStreamManager | 60 class CONTENT_EXPORT MediaStreamManager |
60 : public MediaStreamProviderListener, | 61 : public MediaStreamProviderListener, |
61 public base::MessageLoop::DestructionObserver, | 62 public base::MessageLoop::DestructionObserver, |
62 public base::SystemMonitor::DevicesChangedObserver { | 63 public base::SystemMonitor::DevicesChangedObserver { |
63 public: | 64 public: |
(...skipping 25 matching lines...) Expand all Loading... |
89 const GURL& security_origin, | 90 const GURL& security_origin, |
90 const MediaRequestResponseCallback& callback); | 91 const MediaRequestResponseCallback& callback); |
91 | 92 |
92 // GenerateStream opens new media devices according to |components|. It | 93 // GenerateStream opens new media devices according to |components|. It |
93 // creates a new request which is identified by a unique string that's | 94 // creates a new request which is identified by a unique string that's |
94 // returned to the caller. |render_process_id| and |render_view_id| refer to | 95 // returned to the caller. |render_process_id| and |render_view_id| refer to |
95 // the view where the infobar will appear to the user. | 96 // the view where the infobar will appear to the user. |
96 std::string GenerateStream(MediaStreamRequester* requester, | 97 std::string GenerateStream(MediaStreamRequester* requester, |
97 int render_process_id, | 98 int render_process_id, |
98 int render_view_id, | 99 int render_view_id, |
| 100 ResourceContext* rc, |
99 int page_request_id, | 101 int page_request_id, |
100 const StreamOptions& components, | 102 const StreamOptions& components, |
101 const GURL& security_origin); | 103 const GURL& security_origin); |
102 | 104 |
103 virtual void CancelRequest(const std::string& label); | 105 virtual void CancelRequest(const std::string& label); |
104 void CancelAllRequests(int render_process_id); | 106 void CancelAllRequests(int render_process_id); |
105 | 107 |
106 // Closes the stream device for a certain render view. The stream must have | 108 // Closes the stream device for a certain render view. The stream must have |
107 // been opened by a call to GenerateStream. | 109 // been opened by a call to GenerateStream. |
108 void StopStreamDevice(int render_process_id, | 110 void StopStreamDevice(int render_process_id, |
109 int render_view_id, | 111 int render_view_id, |
110 const std::string& device_id); | 112 const std::string& device_id); |
111 | 113 |
112 // Gets a list of devices of |type|, which must be MEDIA_DEVICE_AUDIO_CAPTURE | 114 // Gets a list of devices of |type|, which must be MEDIA_DEVICE_AUDIO_CAPTURE |
113 // or MEDIA_DEVICE_VIDEO_CAPTURE. | 115 // or MEDIA_DEVICE_VIDEO_CAPTURE. |
114 // The request is identified using the string returned to the caller. | 116 // The request is identified using the string returned to the caller. |
115 // When the |requester| is NULL, MediaStreamManager will enumerate both audio | 117 // When the |requester| is NULL, MediaStreamManager will enumerate both audio |
116 // and video devices and also start monitoring device changes, such as | 118 // and video devices and also start monitoring device changes, such as |
117 // plug/unplug. The new device lists will be delivered via media observer to | 119 // plug/unplug. The new device lists will be delivered via media observer to |
118 // MediaCaptureDevicesDispatcher. | 120 // MediaCaptureDevicesDispatcher. |
119 virtual std::string EnumerateDevices(MediaStreamRequester* requester, | 121 virtual std::string EnumerateDevices(MediaStreamRequester* requester, |
120 int render_process_id, | 122 int render_process_id, |
121 int render_view_id, | 123 int render_view_id, |
| 124 ResourceContext* rc, |
122 int page_request_id, | 125 int page_request_id, |
123 MediaStreamType type, | 126 MediaStreamType type, |
124 const GURL& security_origin); | 127 const GURL& security_origin); |
125 | 128 |
126 // Open a device identified by |device_id|. |type| must be either | 129 // Open a device identified by |device_id|. |type| must be either |
127 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. | 130 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. |
128 // The request is identified using string returned to the caller. | 131 // The request is identified using string returned to the caller. |
129 std::string OpenDevice(MediaStreamRequester* requester, | 132 std::string OpenDevice(MediaStreamRequester* requester, |
130 int render_process_id, | 133 int render_process_id, |
131 int render_view_id, | 134 int render_view_id, |
| 135 ResourceContext* rc, |
132 int page_request_id, | 136 int page_request_id, |
133 const std::string& device_id, | 137 const std::string& device_id, |
134 MediaStreamType type, | 138 MediaStreamType type, |
135 const GURL& security_origin); | 139 const GURL& security_origin); |
136 | 140 |
137 // Implements MediaStreamProviderListener. | 141 // Implements MediaStreamProviderListener. |
138 virtual void Opened(MediaStreamType stream_type, | 142 virtual void Opened(MediaStreamType stream_type, |
139 int capture_session_id) OVERRIDE; | 143 int capture_session_id) OVERRIDE; |
140 virtual void Closed(MediaStreamType stream_type, | 144 virtual void Closed(MediaStreamType stream_type, |
141 int capture_session_id) OVERRIDE; | 145 int capture_session_id) OVERRIDE; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); | 230 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); |
227 void StartEnumeration(DeviceRequest* request); | 231 void StartEnumeration(DeviceRequest* request); |
228 std::string AddRequest(DeviceRequest* request); | 232 std::string AddRequest(DeviceRequest* request); |
229 DeviceRequest* FindRequest(const std::string& label); | 233 DeviceRequest* FindRequest(const std::string& label); |
230 void DeleteRequest(const std::string& label); | 234 void DeleteRequest(const std::string& label); |
231 void ClearEnumerationCache(EnumerationCache* cache); | 235 void ClearEnumerationCache(EnumerationCache* cache); |
232 void PostRequestToUI(const std::string& label); | 236 void PostRequestToUI(const std::string& label); |
233 void HandleRequest(const std::string& label); | 237 void HandleRequest(const std::string& label); |
234 bool SetupTabCaptureRequest(DeviceRequest* request); | 238 bool SetupTabCaptureRequest(DeviceRequest* request); |
235 bool SetupScreenCaptureRequest(DeviceRequest* request); | 239 bool SetupScreenCaptureRequest(DeviceRequest* request); |
236 // Returns true if a device with |device_id| has already been requested by | 240 // Returns true if a device with |device_id| has already been requested with |
237 // |render_process_id| and |render_view_id| of type |type|. If it has been | 241 // a render procecss_id and render_view_id and type equal to the the values |
238 // requested, |device_info| contain information about the device. | 242 // in |request|. If it has been requested, |device_info| contain information |
239 bool FindExistingRequestedDeviceInfo(int render_process_id, | 243 // about the device. |
240 int render_view_id, | 244 bool FindExistingRequestedDeviceInfo( |
241 const GURL& security_origin, | 245 const DeviceRequest& new_request, |
242 MediaStreamRequestType type, | 246 const MediaStreamDevice& new_device_info, |
243 const std::string& device_id, | 247 StreamDeviceInfo* existing_device_info, |
244 MediaStreamType device_type, | 248 MediaRequestState* existing_request_state) const; |
245 StreamDeviceInfo* device_info, | |
246 MediaRequestState* request_state) const; | |
247 | 249 |
248 void FinalizeGenerateStream(const std::string& label, | 250 void FinalizeGenerateStream(const std::string& label, |
249 DeviceRequest* request); | 251 DeviceRequest* request); |
250 void FinalizeRequestFailed(const std::string& label, | 252 void FinalizeRequestFailed(const std::string& label, |
251 DeviceRequest* request); | 253 DeviceRequest* request); |
252 void FinalizeOpenDevice(const std::string& label, | 254 void FinalizeOpenDevice(const std::string& label, |
253 DeviceRequest* request); | 255 DeviceRequest* request); |
254 void FinalizeMediaAccessRequest(const std::string& label, | 256 void FinalizeMediaAccessRequest(const std::string& label, |
255 DeviceRequest* request, | 257 DeviceRequest* request, |
256 const MediaStreamDevices& devices); | 258 const MediaStreamDevices& devices); |
257 void FinalizeEnumerateDevices(const std::string& label, | 259 void FinalizeEnumerateDevices(const std::string& label, |
258 DeviceRequest* request); | 260 DeviceRequest* request); |
259 | 261 |
260 // Helpers to start and stop monitoring devices. | 262 // Helpers to start and stop monitoring devices. |
261 void StartMonitoring(); | 263 void StartMonitoring(); |
262 void StopMonitoring(); | 264 void StopMonitoring(); |
263 | 265 |
264 bool TranslateRequestedSourceIdToDeviceId(MediaStreamRequest* request); | 266 bool TranslateRequestedSourceIdToDeviceId(DeviceRequest* request); |
265 void TranslateDeviceIdToSourceId(const MediaStreamRequest& request, | 267 void TranslateDeviceIdToSourceId(DeviceRequest* request, |
266 MediaStreamDevice* device); | 268 MediaStreamDevice* device); |
267 | 269 |
268 // Finds and returns the device id corresponding to the given | 270 // 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 | 271 // |source_id|. Returns true if there was a raw device id that matched the |
270 // given |source_id|, false if nothing matched it. | 272 // given |source_id|, false if nothing matched it. |
271 bool TranslateSourceIdToDeviceId( | 273 bool TranslateSourceIdToDeviceId( |
272 MediaStreamType stream_type, | 274 MediaStreamType stream_type, |
| 275 ResourceContext* rc, |
273 const GURL& security_origin, | 276 const GURL& security_origin, |
274 const std::string& source_id, | 277 const std::string& source_id, |
275 std::string* device_id); | 278 std::string* device_id); |
276 | 279 |
277 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. | 280 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. |
278 scoped_ptr<base::Thread> device_thread_; | 281 scoped_ptr<base::Thread> device_thread_; |
279 | 282 |
280 media::AudioManager* const audio_manager_; // not owned | 283 media::AudioManager* const audio_manager_; // not owned |
281 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; | 284 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; |
282 scoped_refptr<VideoCaptureManager> video_capture_manager_; | 285 scoped_refptr<VideoCaptureManager> video_capture_manager_; |
(...skipping 24 matching lines...) Expand all Loading... |
307 | 310 |
308 bool use_fake_ui_; | 311 bool use_fake_ui_; |
309 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; | 312 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; |
310 | 313 |
311 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 314 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
312 }; | 315 }; |
313 | 316 |
314 } // namespace content | 317 } // namespace content |
315 | 318 |
316 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 319 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
OLD | NEW |