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 #ifndef CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ |
6 #define CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ | 6 #define CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 21 matching lines...) Expand all Loading... |
32 class PrefRegistrySyncable; | 32 class PrefRegistrySyncable; |
33 } | 33 } |
34 | 34 |
35 // This singleton is used to receive updates about media events from the content | 35 // This singleton is used to receive updates about media events from the content |
36 // layer. | 36 // layer. |
37 class MediaCaptureDevicesDispatcher : public content::MediaObserver, | 37 class MediaCaptureDevicesDispatcher : public content::MediaObserver, |
38 public content::NotificationObserver { | 38 public content::NotificationObserver { |
39 public: | 39 public: |
40 class Observer { | 40 class Observer { |
41 public: | 41 public: |
42 // Handle an information update consisting of a up-to-date audio capture | |
43 // device lists. This happens when a microphone is plugged in or unplugged. | |
44 virtual void OnUpdateAudioDevices( | |
45 const content::MediaStreamDevices& devices) {} | |
46 | |
47 // Handle an information update consisting of a up-to-date video capture | |
48 // device lists. This happens when a camera is plugged in or unplugged. | |
49 virtual void OnUpdateVideoDevices( | |
50 const content::MediaStreamDevices& devices) {} | |
51 | |
52 // Handle an information update related to a media stream request. | 42 // Handle an information update related to a media stream request. |
53 virtual void OnRequestUpdate( | 43 virtual void OnRequestUpdate( |
54 int render_process_id, | 44 int render_process_id, |
55 int render_view_id, | 45 int render_view_id, |
56 const content::MediaStreamDevice& device, | 46 const content::MediaStreamDevice& device, |
57 const content::MediaRequestState state) {} | 47 const content::MediaRequestState state) {} |
58 | 48 |
59 // Handle an information update that a new stream is being created. | 49 // Handle an information update that a new stream is being created. |
60 virtual void OnCreatingAudioStream(int render_process_id, | 50 virtual void OnCreatingAudioStream(int render_process_id, |
61 int render_frame_id) {} | 51 int render_frame_id) {} |
62 | 52 |
63 virtual ~Observer() {} | 53 virtual ~Observer() {} |
64 }; | 54 }; |
65 | 55 |
66 static MediaCaptureDevicesDispatcher* GetInstance(); | 56 static MediaCaptureDevicesDispatcher* GetInstance(); |
67 | 57 |
68 // Registers the preferences related to Media Stream default devices. | 58 // Registers the preferences related to Media Stream default devices. |
69 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 59 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
70 | 60 |
71 // Methods for observers. Called on UI thread. | 61 // Methods for observers. Called on UI thread. |
72 // Observers should add themselves on construction and remove themselves | 62 // Observers should add themselves on construction and remove themselves |
73 // on destruction. | 63 // on destruction. |
74 void AddObserver(Observer* observer); | 64 void AddObserver(Observer* observer); |
75 void RemoveObserver(Observer* observer); | 65 void RemoveObserver(Observer* observer); |
76 const content::MediaStreamDevices& GetAudioCaptureDevices(); | |
77 const content::MediaStreamDevices& GetVideoCaptureDevices(); | |
78 | 66 |
79 // Method called from WebCapturerDelegate implementations to process access | 67 // Method called from WebCapturerDelegate implementations to process access |
80 // requests. |extension| is set to NULL if request was made from a drive-by | 68 // requests. |extension| is set to NULL if request was made from a drive-by |
81 // page. | 69 // page. |
82 void ProcessMediaAccessRequest( | 70 void ProcessMediaAccessRequest( |
83 content::WebContents* web_contents, | 71 content::WebContents* web_contents, |
84 const content::MediaStreamRequest& request, | 72 const content::MediaStreamRequest& request, |
85 const content::MediaResponseCallback& callback, | 73 const content::MediaResponseCallback& callback, |
86 const extensions::Extension* extension); | 74 const extensions::Extension* extension); |
87 | 75 |
(...skipping 12 matching lines...) Expand all Loading... |
100 const content::MediaStreamDevice* | 88 const content::MediaStreamDevice* |
101 GetRequestedAudioDevice(const std::string& requested_audio_device_id); | 89 GetRequestedAudioDevice(const std::string& requested_audio_device_id); |
102 const content::MediaStreamDevice* | 90 const content::MediaStreamDevice* |
103 GetRequestedVideoDevice(const std::string& requested_video_device_id); | 91 GetRequestedVideoDevice(const std::string& requested_video_device_id); |
104 | 92 |
105 // Returns the first available audio or video device, or NULL if no devices | 93 // Returns the first available audio or video device, or NULL if no devices |
106 // are available. | 94 // are available. |
107 const content::MediaStreamDevice* GetFirstAvailableAudioDevice(); | 95 const content::MediaStreamDevice* GetFirstAvailableAudioDevice(); |
108 const content::MediaStreamDevice* GetFirstAvailableVideoDevice(); | 96 const content::MediaStreamDevice* GetFirstAvailableVideoDevice(); |
109 | 97 |
110 // Unittests that do not require actual device enumeration should call this | |
111 // API on the singleton. It is safe to call this multiple times on the | |
112 // signleton. | |
113 void DisableDeviceEnumerationForTesting(); | |
114 | |
115 // Overridden from content::MediaObserver: | 98 // Overridden from content::MediaObserver: |
116 virtual void OnAudioCaptureDevicesChanged( | |
117 const content::MediaStreamDevices& devices) OVERRIDE; | |
118 virtual void OnVideoCaptureDevicesChanged( | |
119 const content::MediaStreamDevices& devices) OVERRIDE; | |
120 virtual void OnMediaRequestStateChanged( | 99 virtual void OnMediaRequestStateChanged( |
121 int render_process_id, | 100 int render_process_id, |
122 int render_view_id, | 101 int render_view_id, |
123 int page_request_id, | 102 int page_request_id, |
124 const GURL& security_origin, | 103 const GURL& security_origin, |
125 const content::MediaStreamDevice& device, | 104 const content::MediaStreamDevice& device, |
126 content::MediaRequestState state) OVERRIDE; | 105 content::MediaRequestState state) OVERRIDE; |
127 virtual void OnAudioStreamPlayingChanged( | 106 virtual void OnAudioStreamPlayingChanged( |
128 int render_process_id, | 107 int render_process_id, |
129 int render_view_id, | 108 int render_view_id, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 void ProcessRegularMediaAccessRequest( | 169 void ProcessRegularMediaAccessRequest( |
191 content::WebContents* web_contents, | 170 content::WebContents* web_contents, |
192 const content::MediaStreamRequest& request, | 171 const content::MediaStreamRequest& request, |
193 const content::MediaResponseCallback& callback); | 172 const content::MediaResponseCallback& callback); |
194 void ProcessQueuedAccessRequest(content::WebContents* web_contents); | 173 void ProcessQueuedAccessRequest(content::WebContents* web_contents); |
195 void OnAccessRequestResponse(content::WebContents* web_contents, | 174 void OnAccessRequestResponse(content::WebContents* web_contents, |
196 const content::MediaStreamDevices& devices, | 175 const content::MediaStreamDevices& devices, |
197 scoped_ptr<content::MediaStreamUI> ui); | 176 scoped_ptr<content::MediaStreamUI> ui); |
198 | 177 |
199 // Called by the MediaObserver() functions, executed on UI thread. | 178 // Called by the MediaObserver() functions, executed on UI thread. |
200 void UpdateAudioDevicesOnUIThread(const content::MediaStreamDevices& devices); | |
201 void UpdateVideoDevicesOnUIThread(const content::MediaStreamDevices& devices); | |
202 void UpdateMediaRequestStateOnUIThread( | 179 void UpdateMediaRequestStateOnUIThread( |
203 int render_process_id, | 180 int render_process_id, |
204 int render_view_id, | 181 int render_view_id, |
205 int page_request_id, | 182 int page_request_id, |
206 const GURL& security_origin, | 183 const GURL& security_origin, |
207 const content::MediaStreamDevice& device, | 184 const content::MediaStreamDevice& device, |
208 content::MediaRequestState state); | 185 content::MediaRequestState state); |
209 void OnCreatingAudioStreamOnUIThread(int render_process_id, | 186 void OnCreatingAudioStreamOnUIThread(int render_process_id, |
210 int render_frame_id); | 187 int render_frame_id); |
211 | 188 |
212 // A list of cached audio capture devices. | |
213 content::MediaStreamDevices audio_devices_; | |
214 | |
215 // A list of cached video capture devices. | |
216 content::MediaStreamDevices video_devices_; | |
217 | |
218 // A list of observers for the device update notifications. | 189 // A list of observers for the device update notifications. |
219 ObserverList<Observer> observers_; | 190 ObserverList<Observer> observers_; |
220 | 191 |
221 // Flag to indicate if device enumeration has been done/doing. | |
222 // Only accessed on UI thread. | |
223 bool devices_enumerated_; | |
224 | |
225 // Flag used by unittests to disable device enumeration. | |
226 bool is_device_enumeration_disabled_; | |
227 | |
228 RequestsQueues pending_requests_; | 192 RequestsQueues pending_requests_; |
229 | 193 |
230 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; | 194 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; |
231 | 195 |
232 scoped_refptr<AudioStreamIndicator> audio_stream_indicator_; | 196 scoped_refptr<AudioStreamIndicator> audio_stream_indicator_; |
233 | 197 |
234 scoped_ptr<DesktopStreamsRegistry> desktop_streams_registry_; | 198 scoped_ptr<DesktopStreamsRegistry> desktop_streams_registry_; |
235 | 199 |
236 content::NotificationRegistrar notifications_registrar_; | 200 content::NotificationRegistrar notifications_registrar_; |
237 | 201 |
238 // Tracks MEDIA_DESKTOP_VIDEO_CAPTURE sessions which reach the | 202 // Tracks MEDIA_DESKTOP_VIDEO_CAPTURE sessions which reach the |
239 // MEDIA_REQUEST_STATE_DONE state. Sessions are remove when | 203 // MEDIA_REQUEST_STATE_DONE state. Sessions are remove when |
240 // MEDIA_REQUEST_STATE_CLOSING is encountered. | 204 // MEDIA_REQUEST_STATE_CLOSING is encountered. |
241 struct DesktopCaptureSession { | 205 struct DesktopCaptureSession { |
242 int render_process_id; | 206 int render_process_id; |
243 int render_view_id; | 207 int render_view_id; |
244 int page_request_id; | 208 int page_request_id; |
245 }; | 209 }; |
246 typedef std::list<DesktopCaptureSession> DesktopCaptureSessions; | 210 typedef std::list<DesktopCaptureSession> DesktopCaptureSessions; |
247 DesktopCaptureSessions desktop_capture_sessions_; | 211 DesktopCaptureSessions desktop_capture_sessions_; |
248 | 212 |
249 DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); | 213 DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); |
250 }; | 214 }; |
251 | 215 |
252 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ | 216 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ |
OLD | NEW |