| 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 #include "content/browser/renderer_host/media/media_stream_provider.h" | 44 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 45 #include "content/common/content_export.h" | 45 #include "content/common/content_export.h" |
| 46 #include "content/common/media/media_stream_options.h" | 46 #include "content/common/media/media_stream_options.h" |
| 47 #include "content/public/browser/media_request_state.h" | 47 #include "content/public/browser/media_request_state.h" |
| 48 #include "content/public/browser/resource_context.h" | 48 #include "content/public/browser/resource_context.h" |
| 49 | 49 |
| 50 namespace media { | 50 namespace media { |
| 51 class AudioManager; | 51 class AudioManager; |
| 52 } | 52 } |
| 53 | 53 |
| 54 namespace url { |
| 55 class Origin; |
| 56 } |
| 57 |
| 54 namespace content { | 58 namespace content { |
| 55 | 59 |
| 56 class AudioInputDeviceManager; | 60 class AudioInputDeviceManager; |
| 57 class AudioOutputDeviceEnumerator; | 61 class AudioOutputDeviceEnumerator; |
| 58 class BrowserContext; | 62 class BrowserContext; |
| 59 class FakeMediaStreamUIProxy; | 63 class FakeMediaStreamUIProxy; |
| 60 class MediaStreamDeviceSettings; | 64 class MediaStreamDeviceSettings; |
| 61 class MediaStreamRequester; | 65 class MediaStreamRequester; |
| 62 class MediaStreamUIProxy; | 66 class MediaStreamUIProxy; |
| 63 class VideoCaptureManager; | 67 class VideoCaptureManager; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // that's returned to the caller. This will trigger the infobar and ask users | 102 // that's returned to the caller. This will trigger the infobar and ask users |
| 99 // for access to the device. |render_process_id| and |render_frame_id| are | 103 // for access to the device. |render_process_id| and |render_frame_id| are |
| 100 // used to determine where the infobar will appear to the user. |callback| is | 104 // used to determine where the infobar will appear to the user. |callback| is |
| 101 // used to send the selected device to the clients. An empty list of device | 105 // used to send the selected device to the clients. An empty list of device |
| 102 // will be returned if the users deny the access. | 106 // will be returned if the users deny the access. |
| 103 std::string MakeMediaAccessRequest( | 107 std::string MakeMediaAccessRequest( |
| 104 int render_process_id, | 108 int render_process_id, |
| 105 int render_frame_id, | 109 int render_frame_id, |
| 106 int page_request_id, | 110 int page_request_id, |
| 107 const StreamControls& controls, | 111 const StreamControls& controls, |
| 108 const GURL& security_origin, | 112 const url::Origin& security_origin, |
| 109 const MediaRequestResponseCallback& callback); | 113 const MediaRequestResponseCallback& callback); |
| 110 | 114 |
| 111 // GenerateStream opens new media devices according to |components|. It | 115 // GenerateStream opens new media devices according to |components|. It |
| 112 // creates a new request which is identified by a unique string that's | 116 // creates a new request which is identified by a unique string that's |
| 113 // returned to the caller. |render_process_id| and |render_frame_id| are used | 117 // returned to the caller. |render_process_id| and |render_frame_id| are used |
| 114 // to determine where the infobar will appear to the user. | 118 // to determine where the infobar will appear to the user. |
| 115 void GenerateStream(MediaStreamRequester* requester, | 119 void GenerateStream(MediaStreamRequester* requester, |
| 116 int render_process_id, | 120 int render_process_id, |
| 117 int render_frame_id, | 121 int render_frame_id, |
| 118 const ResourceContext::SaltCallback& sc, | 122 const ResourceContext::SaltCallback& sc, |
| 119 int page_request_id, | 123 int page_request_id, |
| 120 const StreamControls& controls, | 124 const StreamControls& controls, |
| 121 const GURL& security_origin, | 125 const url::Origin& security_origin, |
| 122 bool user_gesture); | 126 bool user_gesture); |
| 123 | 127 |
| 124 void CancelRequest(int render_process_id, | 128 void CancelRequest(int render_process_id, |
| 125 int render_frame_id, | 129 int render_frame_id, |
| 126 int page_request_id); | 130 int page_request_id); |
| 127 | 131 |
| 128 // Cancel an open request identified by |label|. | 132 // Cancel an open request identified by |label|. |
| 129 virtual void CancelRequest(const std::string& label); | 133 virtual void CancelRequest(const std::string& label); |
| 130 | 134 |
| 131 // Cancel all requests for the given |render_process_id|. | 135 // Cancel all requests for the given |render_process_id|. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 143 // When the |requester| is NULL, MediaStreamManager will enumerate both audio | 147 // When the |requester| is NULL, MediaStreamManager will enumerate both audio |
| 144 // and video devices and also start monitoring device changes, such as | 148 // and video devices and also start monitoring device changes, such as |
| 145 // plug/unplug. The new device lists will be delivered via media observer to | 149 // plug/unplug. The new device lists will be delivered via media observer to |
| 146 // MediaCaptureDevicesDispatcher. | 150 // MediaCaptureDevicesDispatcher. |
| 147 virtual std::string EnumerateDevices(MediaStreamRequester* requester, | 151 virtual std::string EnumerateDevices(MediaStreamRequester* requester, |
| 148 int render_process_id, | 152 int render_process_id, |
| 149 int render_frame_id, | 153 int render_frame_id, |
| 150 const ResourceContext::SaltCallback& sc, | 154 const ResourceContext::SaltCallback& sc, |
| 151 int page_request_id, | 155 int page_request_id, |
| 152 MediaStreamType type, | 156 MediaStreamType type, |
| 153 const GURL& security_origin); | 157 const url::Origin& security_origin); |
| 154 | 158 |
| 155 // Open a device identified by |device_id|. |type| must be either | 159 // Open a device identified by |device_id|. |type| must be either |
| 156 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. | 160 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. |
| 157 // The request is identified using string returned to the caller. | 161 // The request is identified using string returned to the caller. |
| 158 void OpenDevice(MediaStreamRequester* requester, | 162 void OpenDevice(MediaStreamRequester* requester, |
| 159 int render_process_id, | 163 int render_process_id, |
| 160 int render_frame_id, | 164 int render_frame_id, |
| 161 const ResourceContext::SaltCallback& sc, | 165 const ResourceContext::SaltCallback& sc, |
| 162 int page_request_id, | 166 int page_request_id, |
| 163 const std::string& device_id, | 167 const std::string& device_id, |
| 164 MediaStreamType type, | 168 MediaStreamType type, |
| 165 const GURL& security_origin); | 169 const url::Origin& security_origin); |
| 166 | 170 |
| 167 // Finds and returns the device id corresponding to the given | 171 // Finds and returns the device id corresponding to the given |
| 168 // |source_id|. Returns true if there was a raw device id that matched the | 172 // |source_id|. Returns true if there was a raw device id that matched the |
| 169 // given |source_id|, false if nothing matched it. | 173 // given |source_id|, false if nothing matched it. |
| 170 bool TranslateSourceIdToDeviceId(MediaStreamType stream_type, | 174 bool TranslateSourceIdToDeviceId(MediaStreamType stream_type, |
| 171 const ResourceContext::SaltCallback& rc, | 175 const ResourceContext::SaltCallback& rc, |
| 172 const GURL& security_origin, | 176 const url::Origin& security_origin, |
| 173 const std::string& source_id, | 177 const std::string& source_id, |
| 174 std::string* device_id) const; | 178 std::string* device_id) const; |
| 175 | 179 |
| 176 // Called by UI to make sure the device monitor is started so that UI receive | 180 // Called by UI to make sure the device monitor is started so that UI receive |
| 177 // notifications about device changes. | 181 // notifications about device changes. |
| 178 void EnsureDeviceMonitorStarted(); | 182 void EnsureDeviceMonitorStarted(); |
| 179 | 183 |
| 180 // Implements MediaStreamProviderListener. | 184 // Implements MediaStreamProviderListener. |
| 181 void Opened(MediaStreamType stream_type, int capture_session_id) override; | 185 void Opened(MediaStreamType stream_type, int capture_session_id) override; |
| 182 void Closed(MediaStreamType stream_type, int capture_session_id) override; | 186 void Closed(MediaStreamType stream_type, int capture_session_id) override; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // subscribed. Also, subscribers must make sure to invoke | 233 // subscribed. Also, subscribers must make sure to invoke |
| 230 // CancelDeviceChangeNotifications() before destruction. Otherwise, dangling | 234 // CancelDeviceChangeNotifications() before destruction. Otherwise, dangling |
| 231 // pointers and use-after-destruction problems will occur. | 235 // pointers and use-after-destruction problems will occur. |
| 232 void SubscribeToDeviceChangeNotifications(MediaStreamRequester* subscriber); | 236 void SubscribeToDeviceChangeNotifications(MediaStreamRequester* subscriber); |
| 233 void CancelDeviceChangeNotifications(MediaStreamRequester* subscriber); | 237 void CancelDeviceChangeNotifications(MediaStreamRequester* subscriber); |
| 234 | 238 |
| 235 // Generates a hash of a device's unique ID usable by one | 239 // Generates a hash of a device's unique ID usable by one |
| 236 // particular security origin. | 240 // particular security origin. |
| 237 static std::string GetHMACForMediaDeviceID( | 241 static std::string GetHMACForMediaDeviceID( |
| 238 const ResourceContext::SaltCallback& sc, | 242 const ResourceContext::SaltCallback& sc, |
| 239 const GURL& security_origin, | 243 const url::Origin& security_origin, |
| 240 const std::string& raw_unique_id); | 244 const std::string& raw_unique_id); |
| 241 | 245 |
| 242 // Convenience method to check if |device_guid| is an HMAC of | 246 // Convenience method to check if |device_guid| is an HMAC of |
| 243 // |raw_device_id| for |security_origin|. | 247 // |raw_device_id| for |security_origin|. |
| 244 static bool DoesMediaDeviceIDMatchHMAC( | 248 static bool DoesMediaDeviceIDMatchHMAC( |
| 245 const ResourceContext::SaltCallback& sc, | 249 const ResourceContext::SaltCallback& sc, |
| 246 const GURL& security_origin, | 250 const url::Origin& security_origin, |
| 247 const std::string& device_guid, | 251 const std::string& device_guid, |
| 248 const std::string& raw_unique_id); | 252 const std::string& raw_unique_id); |
| 249 | 253 |
| 254 // Returns true if the renderer process identified with |render_process_id| |
| 255 // is allowed to access |origin|. |
| 256 static bool IsOriginAllowed(int render_process_id, const url::Origin& origin); |
| 257 |
| 250 private: | 258 private: |
| 251 // Contains all data needed to keep track of requests. | 259 // Contains all data needed to keep track of requests. |
| 252 class DeviceRequest; | 260 class DeviceRequest; |
| 253 | 261 |
| 254 // Cache enumerated device list. | 262 // Cache enumerated device list. |
| 255 struct EnumerationCache { | 263 struct EnumerationCache { |
| 256 EnumerationCache(); | 264 EnumerationCache(); |
| 257 ~EnumerationCache(); | 265 ~EnumerationCache(); |
| 258 | 266 |
| 259 bool valid; | 267 bool valid; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 #endif | 388 #endif |
| 381 | 389 |
| 382 // Picks a device ID from a list of required and alternate device IDs, | 390 // Picks a device ID from a list of required and alternate device IDs, |
| 383 // presented as part of a TrackControls structure. | 391 // presented as part of a TrackControls structure. |
| 384 // Either the required device ID is picked (if present), or the first | 392 // Either the required device ID is picked (if present), or the first |
| 385 // valid alternate device ID. | 393 // valid alternate device ID. |
| 386 // Returns false if the required device ID is present and invalid. | 394 // Returns false if the required device ID is present and invalid. |
| 387 // Otherwise, if no valid device is found, device_id is unchanged. | 395 // Otherwise, if no valid device is found, device_id is unchanged. |
| 388 bool PickDeviceId(MediaStreamType type, | 396 bool PickDeviceId(MediaStreamType type, |
| 389 const ResourceContext::SaltCallback& salt_callback, | 397 const ResourceContext::SaltCallback& salt_callback, |
| 390 const GURL& security_origin, | 398 const url::Origin& security_origin, |
| 391 const TrackControls& controls, | 399 const TrackControls& controls, |
| 392 std::string* device_id) const; | 400 std::string* device_id) const; |
| 393 | 401 |
| 394 // Finds the requested device id from request. The requested device type | 402 // Finds the requested device id from request. The requested device type |
| 395 // must be MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. | 403 // must be MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. |
| 396 bool GetRequestedDeviceCaptureId(const DeviceRequest* request, | 404 bool GetRequestedDeviceCaptureId(const DeviceRequest* request, |
| 397 MediaStreamType type, | 405 MediaStreamType type, |
| 398 std::string* device_id) const; | 406 std::string* device_id) const; |
| 399 | 407 |
| 400 void TranslateDeviceIdToSourceId(DeviceRequest* request, | 408 void TranslateDeviceIdToSourceId(DeviceRequest* request, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 | 458 |
| 451 // Objects subscribed to changes in the set of media devices. | 459 // Objects subscribed to changes in the set of media devices. |
| 452 std::vector<MediaStreamRequester*> device_change_subscribers_; | 460 std::vector<MediaStreamRequester*> device_change_subscribers_; |
| 453 | 461 |
| 454 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 462 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
| 455 }; | 463 }; |
| 456 | 464 |
| 457 } // namespace content | 465 } // namespace content |
| 458 | 466 |
| 459 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 467 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
| OLD | NEW |