| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // are available. | 106 // are available. |
| 107 const content::MediaStreamDevice* GetFirstAvailableAudioDevice(); | 107 const content::MediaStreamDevice* GetFirstAvailableAudioDevice(); |
| 108 const content::MediaStreamDevice* GetFirstAvailableVideoDevice(); | 108 const content::MediaStreamDevice* GetFirstAvailableVideoDevice(); |
| 109 | 109 |
| 110 // Unittests that do not require actual device enumeration should call this | 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 | 111 // API on the singleton. It is safe to call this multiple times on the |
| 112 // signleton. | 112 // signleton. |
| 113 void DisableDeviceEnumerationForTesting(); | 113 void DisableDeviceEnumerationForTesting(); |
| 114 | 114 |
| 115 // Overridden from content::MediaObserver: | 115 // Overridden from content::MediaObserver: |
| 116 virtual void OnAudioCaptureDevicesChanged( | 116 virtual void OnAudioCaptureDevicesChanged() OVERRIDE; |
| 117 const content::MediaStreamDevices& devices) OVERRIDE; | 117 virtual void OnVideoCaptureDevicesChanged() OVERRIDE; |
| 118 virtual void OnVideoCaptureDevicesChanged( | |
| 119 const content::MediaStreamDevices& devices) OVERRIDE; | |
| 120 virtual void OnMediaRequestStateChanged( | 118 virtual void OnMediaRequestStateChanged( |
| 121 int render_process_id, | 119 int render_process_id, |
| 122 int render_view_id, | 120 int render_view_id, |
| 123 int page_request_id, | 121 int page_request_id, |
| 124 const GURL& security_origin, | 122 const GURL& security_origin, |
| 125 const content::MediaStreamDevice& device, | 123 const content::MediaStreamDevice& device, |
| 126 content::MediaRequestState state) OVERRIDE; | 124 content::MediaRequestState state) OVERRIDE; |
| 127 virtual void OnAudioStreamPlayingChanged( | 125 virtual void OnAudioStreamPlayingChanged( |
| 128 int render_process_id, | 126 int render_process_id, |
| 129 int render_view_id, | 127 int render_view_id, |
| 130 int stream_id, | 128 int stream_id, |
| 131 bool is_playing, | 129 bool is_playing, |
| 132 float power_dBFS, | 130 float power_dBFS, |
| 133 bool clipped) OVERRIDE; | 131 bool clipped) OVERRIDE; |
| 134 virtual void OnCreatingAudioStream(int render_process_id, | 132 virtual void OnCreatingAudioStream(int render_process_id, |
| 135 int render_frame_id) OVERRIDE; | 133 int render_frame_id) OVERRIDE; |
| 136 | 134 |
| 137 scoped_refptr<MediaStreamCaptureIndicator> GetMediaStreamCaptureIndicator(); | 135 scoped_refptr<MediaStreamCaptureIndicator> GetMediaStreamCaptureIndicator(); |
| 138 | 136 |
| 139 scoped_refptr<AudioStreamIndicator> GetAudioStreamIndicator(); | 137 scoped_refptr<AudioStreamIndicator> GetAudioStreamIndicator(); |
| 140 | 138 |
| 141 DesktopStreamsRegistry* GetDesktopStreamsRegistry(); | 139 DesktopStreamsRegistry* GetDesktopStreamsRegistry(); |
| 142 | 140 |
| 143 bool IsDesktopCaptureInProgress(); | 141 bool IsDesktopCaptureInProgress(); |
| 144 | 142 |
| 143 // Only for testing. |
| 144 void SetTestAudioCaptureDevices(const content::MediaStreamDevices& devices); |
| 145 void SetTestVideoCaptureDevices(const content::MediaStreamDevices& devices); |
| 146 |
| 145 private: | 147 private: |
| 146 friend struct DefaultSingletonTraits<MediaCaptureDevicesDispatcher>; | 148 friend struct DefaultSingletonTraits<MediaCaptureDevicesDispatcher>; |
| 147 | 149 |
| 148 struct PendingAccessRequest { | 150 struct PendingAccessRequest { |
| 149 PendingAccessRequest(const content::MediaStreamRequest& request, | 151 PendingAccessRequest(const content::MediaStreamRequest& request, |
| 150 const content::MediaResponseCallback& callback); | 152 const content::MediaResponseCallback& callback); |
| 151 ~PendingAccessRequest(); | 153 ~PendingAccessRequest(); |
| 152 | 154 |
| 153 // TODO(gbillock): make the MediaStreamDevicesController owned by | 155 // TODO(gbillock): make the MediaStreamDevicesController owned by |
| 154 // this object when we're using bubbles. | 156 // this object when we're using bubbles. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 void ProcessRegularMediaAccessRequest( | 192 void ProcessRegularMediaAccessRequest( |
| 191 content::WebContents* web_contents, | 193 content::WebContents* web_contents, |
| 192 const content::MediaStreamRequest& request, | 194 const content::MediaStreamRequest& request, |
| 193 const content::MediaResponseCallback& callback); | 195 const content::MediaResponseCallback& callback); |
| 194 void ProcessQueuedAccessRequest(content::WebContents* web_contents); | 196 void ProcessQueuedAccessRequest(content::WebContents* web_contents); |
| 195 void OnAccessRequestResponse(content::WebContents* web_contents, | 197 void OnAccessRequestResponse(content::WebContents* web_contents, |
| 196 const content::MediaStreamDevices& devices, | 198 const content::MediaStreamDevices& devices, |
| 197 scoped_ptr<content::MediaStreamUI> ui); | 199 scoped_ptr<content::MediaStreamUI> ui); |
| 198 | 200 |
| 199 // Called by the MediaObserver() functions, executed on UI thread. | 201 // Called by the MediaObserver() functions, executed on UI thread. |
| 200 void UpdateAudioDevicesOnUIThread(const content::MediaStreamDevices& devices); | 202 void NotifyAudioDevicesChangedOnUIThread(); |
| 201 void UpdateVideoDevicesOnUIThread(const content::MediaStreamDevices& devices); | 203 void NotifyVideoDevicesChangedOnUIThread(); |
| 202 void UpdateMediaRequestStateOnUIThread( | 204 void UpdateMediaRequestStateOnUIThread( |
| 203 int render_process_id, | 205 int render_process_id, |
| 204 int render_view_id, | 206 int render_view_id, |
| 205 int page_request_id, | 207 int page_request_id, |
| 206 const GURL& security_origin, | 208 const GURL& security_origin, |
| 207 const content::MediaStreamDevice& device, | 209 const content::MediaStreamDevice& device, |
| 208 content::MediaRequestState state); | 210 content::MediaRequestState state); |
| 209 void OnCreatingAudioStreamOnUIThread(int render_process_id, | 211 void OnCreatingAudioStreamOnUIThread(int render_process_id, |
| 210 int render_frame_id); | 212 int render_frame_id); |
| 211 | 213 |
| 212 // A list of cached audio capture devices. | 214 // Only for testing, a list of cached audio capture devices. |
| 213 content::MediaStreamDevices audio_devices_; | 215 content::MediaStreamDevices test_audio_devices_; |
| 214 | 216 |
| 215 // A list of cached video capture devices. | 217 // Only for testing, a list of cached video capture devices. |
| 216 content::MediaStreamDevices video_devices_; | 218 content::MediaStreamDevices test_video_devices_; |
| 217 | 219 |
| 218 // A list of observers for the device update notifications. | 220 // A list of observers for the device update notifications. |
| 219 ObserverList<Observer> observers_; | 221 ObserverList<Observer> observers_; |
| 220 | 222 |
| 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. | 223 // Flag used by unittests to disable device enumeration. |
| 226 bool is_device_enumeration_disabled_; | 224 bool is_device_enumeration_disabled_; |
| 227 | 225 |
| 228 RequestsQueues pending_requests_; | 226 RequestsQueues pending_requests_; |
| 229 | 227 |
| 230 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; | 228 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; |
| 231 | 229 |
| 232 scoped_refptr<AudioStreamIndicator> audio_stream_indicator_; | 230 scoped_refptr<AudioStreamIndicator> audio_stream_indicator_; |
| 233 | 231 |
| 234 scoped_ptr<DesktopStreamsRegistry> desktop_streams_registry_; | 232 scoped_ptr<DesktopStreamsRegistry> desktop_streams_registry_; |
| 235 | 233 |
| 236 content::NotificationRegistrar notifications_registrar_; | 234 content::NotificationRegistrar notifications_registrar_; |
| 237 | 235 |
| 238 // Tracks MEDIA_DESKTOP_VIDEO_CAPTURE sessions which reach the | 236 // Tracks MEDIA_DESKTOP_VIDEO_CAPTURE sessions which reach the |
| 239 // MEDIA_REQUEST_STATE_DONE state. Sessions are remove when | 237 // MEDIA_REQUEST_STATE_DONE state. Sessions are remove when |
| 240 // MEDIA_REQUEST_STATE_CLOSING is encountered. | 238 // MEDIA_REQUEST_STATE_CLOSING is encountered. |
| 241 struct DesktopCaptureSession { | 239 struct DesktopCaptureSession { |
| 242 int render_process_id; | 240 int render_process_id; |
| 243 int render_view_id; | 241 int render_view_id; |
| 244 int page_request_id; | 242 int page_request_id; |
| 245 }; | 243 }; |
| 246 typedef std::list<DesktopCaptureSession> DesktopCaptureSessions; | 244 typedef std::list<DesktopCaptureSession> DesktopCaptureSessions; |
| 247 DesktopCaptureSessions desktop_capture_sessions_; | 245 DesktopCaptureSessions desktop_capture_sessions_; |
| 248 | 246 |
| 249 DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); | 247 DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); |
| 250 }; | 248 }; |
| 251 | 249 |
| 252 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ | 250 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ |
| OLD | NEW |