| 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 CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "content/renderer/media/media_stream_source.h" | 23 #include "content/renderer/media/media_stream_source.h" |
| 24 #include "services/service_manager/public/cpp/interface_provider.h" | 24 #include "services/service_manager/public/cpp/interface_provider.h" |
| 25 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 25 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 26 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 26 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 27 #include "third_party/WebKit/public/platform/WebVector.h" | 27 #include "third_party/WebKit/public/platform/WebVector.h" |
| 28 #include "third_party/WebKit/public/web/WebMediaDeviceChangeObserver.h" | 28 #include "third_party/WebKit/public/web/WebMediaDeviceChangeObserver.h" |
| 29 #include "third_party/WebKit/public/web/WebMediaDevicesRequest.h" | 29 #include "third_party/WebKit/public/web/WebMediaDevicesRequest.h" |
| 30 #include "third_party/WebKit/public/web/WebUserMediaClient.h" | 30 #include "third_party/WebKit/public/web/WebUserMediaClient.h" |
| 31 #include "third_party/WebKit/public/web/WebUserMediaRequest.h" | 31 #include "third_party/WebKit/public/web/WebUserMediaRequest.h" |
| 32 | 32 |
| 33 namespace base { |
| 34 class TaskRunner; |
| 35 } |
| 36 |
| 33 namespace content { | 37 namespace content { |
| 34 class PeerConnectionDependencyFactory; | 38 class PeerConnectionDependencyFactory; |
| 35 class MediaStreamAudioSource; | 39 class MediaStreamAudioSource; |
| 36 class MediaStreamDispatcher; | 40 class MediaStreamDispatcher; |
| 37 class MediaStreamVideoSource; | 41 class MediaStreamVideoSource; |
| 42 struct VideoCaptureSourceSelectionResult; |
| 38 | 43 |
| 39 // UserMediaClientImpl is a delegate for the Media Stream GetUserMedia API. | 44 // UserMediaClientImpl is a delegate for the Media Stream GetUserMedia API. |
| 40 // It ties together WebKit and MediaStreamManager | 45 // It ties together WebKit and MediaStreamManager |
| 41 // (via MediaStreamDispatcher and MediaStreamDispatcherHost) | 46 // (via MediaStreamDispatcher and MediaStreamDispatcherHost) |
| 42 // in the browser process. It must be created, called and destroyed on the | 47 // in the browser process. It must be created, called and destroyed on the |
| 43 // render thread. | 48 // render thread. |
| 44 class CONTENT_EXPORT UserMediaClientImpl | 49 class CONTENT_EXPORT UserMediaClientImpl |
| 45 : public RenderFrameObserver, | 50 : public RenderFrameObserver, |
| 46 NON_EXPORTED_BASE(public blink::WebUserMediaClient), | 51 NON_EXPORTED_BASE(public blink::WebUserMediaClient), |
| 47 public MediaStreamDispatcherEventHandler, | 52 public MediaStreamDispatcherEventHandler, |
| 48 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 53 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 49 public: | 54 public: |
| 50 // |render_frame| and |dependency_factory| must outlive this instance. | 55 // |render_frame| and |dependency_factory| must outlive this instance. |
| 51 UserMediaClientImpl( | 56 UserMediaClientImpl( |
| 52 RenderFrame* render_frame, | 57 RenderFrame* render_frame, |
| 53 PeerConnectionDependencyFactory* dependency_factory, | 58 PeerConnectionDependencyFactory* dependency_factory, |
| 54 std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher); | 59 std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher, |
| 60 const scoped_refptr<base::TaskRunner>& worker_task_runner); |
| 55 ~UserMediaClientImpl() override; | 61 ~UserMediaClientImpl() override; |
| 56 | 62 |
| 57 MediaStreamDispatcher* media_stream_dispatcher() const { | 63 MediaStreamDispatcher* media_stream_dispatcher() const { |
| 58 return media_stream_dispatcher_.get(); | 64 return media_stream_dispatcher_.get(); |
| 59 } | 65 } |
| 60 | 66 |
| 61 // blink::WebUserMediaClient implementation | 67 // blink::WebUserMediaClient implementation |
| 62 void requestUserMedia( | 68 void requestUserMedia( |
| 63 const blink::WebUserMediaRequest& user_media_request) override; | 69 const blink::WebUserMediaRequest& user_media_request) override; |
| 64 void cancelUserMediaRequest( | 70 void cancelUserMediaRequest( |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 281 |
| 276 // Returns true if we do find and remove the |source|. | 282 // Returns true if we do find and remove the |source|. |
| 277 // Otherwise returns false. | 283 // Otherwise returns false. |
| 278 bool RemoveLocalSource(const blink::WebMediaStreamSource& source); | 284 bool RemoveLocalSource(const blink::WebMediaStreamSource& source); |
| 279 | 285 |
| 280 void StopLocalSource(const blink::WebMediaStreamSource& source, | 286 void StopLocalSource(const blink::WebMediaStreamSource& source, |
| 281 bool notify_dispatcher); | 287 bool notify_dispatcher); |
| 282 | 288 |
| 283 const ::mojom::MediaDevicesDispatcherHostPtr& GetMediaDevicesDispatcher(); | 289 const ::mojom::MediaDevicesDispatcherHostPtr& GetMediaDevicesDispatcher(); |
| 284 | 290 |
| 285 void SelectUserMediaDevice( | 291 struct RequestSettings; |
| 292 |
| 293 void SelectAudioInputDevice( |
| 286 int request_id, | 294 int request_id, |
| 287 const blink::WebUserMediaRequest& user_media_request, | 295 const blink::WebUserMediaRequest& user_media_request, |
| 288 std::unique_ptr<StreamControls> controls, | 296 std::unique_ptr<StreamControls> controls, |
| 289 bool enable_automatic_output_device_selection, | 297 const RequestSettings& request_settings, |
| 290 const url::Origin& security_origin, | |
| 291 const EnumerationResult& device_enumeration); | 298 const EnumerationResult& device_enumeration); |
| 299 |
| 300 void SetupVideoInput(int request_id, |
| 301 const blink::WebUserMediaRequest& user_media_request, |
| 302 std::unique_ptr<StreamControls> controls, |
| 303 const RequestSettings& request_settings); |
| 304 |
| 305 void SelectVideoDeviceSourceSettings( |
| 306 int request_id, |
| 307 const blink::WebUserMediaRequest& user_media_request, |
| 308 std::unique_ptr<StreamControls> controls, |
| 309 const RequestSettings& request_settings, |
| 310 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> |
| 311 video_input_capabilities); |
| 312 |
| 313 void FinalizeSelectVideoDeviceSourceSettings( |
| 314 int request_id, |
| 315 const blink::WebUserMediaRequest& user_media_request, |
| 316 std::unique_ptr<StreamControls> controls, |
| 317 const RequestSettings& request_settings, |
| 318 const VideoCaptureSourceSelectionResult& selection_result); |
| 319 |
| 292 void FinalizeRequestUserMedia( | 320 void FinalizeRequestUserMedia( |
| 293 int request_id, | 321 int request_id, |
| 294 const blink::WebUserMediaRequest& user_media_request, | 322 const blink::WebUserMediaRequest& user_media_request, |
| 295 std::unique_ptr<StreamControls> controls, | 323 std::unique_ptr<StreamControls> controls, |
| 296 bool enable_automatic_output_device_selection, | 324 const RequestSettings& request_settings); |
| 297 const url::Origin& security_origin); | |
| 298 | 325 |
| 299 // Callback invoked by MediaDevicesEventDispatcher when a device-change | 326 // Callback invoked by MediaDevicesEventDispatcher when a device-change |
| 300 // notification arrives. | 327 // notification arrives. |
| 301 void DevicesChanged(MediaDeviceType device_type, | 328 void DevicesChanged(MediaDeviceType device_type, |
| 302 const MediaDeviceInfoArray& device_infos); | 329 const MediaDeviceInfoArray& device_infos); |
| 303 | 330 |
| 304 // Weak ref to a PeerConnectionDependencyFactory, owned by the RenderThread. | 331 // Weak ref to a PeerConnectionDependencyFactory, owned by the RenderThread. |
| 305 // It's valid for the lifetime of RenderThread. | 332 // It's valid for the lifetime of RenderThread. |
| 306 // TODO(xians): Remove this dependency once audio do not need it for local | 333 // TODO(xians): Remove this dependency once audio do not need it for local |
| 307 // audio. | 334 // audio. |
| 308 PeerConnectionDependencyFactory* const dependency_factory_; | 335 PeerConnectionDependencyFactory* const dependency_factory_; |
| 309 | 336 |
| 310 // UserMediaClientImpl owns MediaStreamDispatcher instead of RenderFrameImpl | 337 // UserMediaClientImpl owns MediaStreamDispatcher instead of RenderFrameImpl |
| 311 // (or RenderFrameObserver) to ensure tear-down occurs in the right order. | 338 // (or RenderFrameObserver) to ensure tear-down occurs in the right order. |
| 312 const std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher_; | 339 const std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher_; |
| 313 | 340 |
| 314 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher_; | 341 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher_; |
| 315 | 342 |
| 316 LocalStreamSources local_sources_; | 343 LocalStreamSources local_sources_; |
| 317 LocalStreamSources pending_local_sources_; | 344 LocalStreamSources pending_local_sources_; |
| 318 | 345 |
| 319 UserMediaRequests user_media_requests_; | 346 UserMediaRequests user_media_requests_; |
| 320 MediaDevicesEventDispatcher::SubscriptionIdList | 347 MediaDevicesEventDispatcher::SubscriptionIdList |
| 321 device_change_subscription_ids_; | 348 device_change_subscription_ids_; |
| 322 | 349 |
| 323 blink::WebMediaDeviceChangeObserver media_device_change_observer_; | 350 blink::WebMediaDeviceChangeObserver media_device_change_observer_; |
| 324 | 351 |
| 352 const scoped_refptr<base::TaskRunner> worker_task_runner_; |
| 353 |
| 325 // Note: This member must be the last to ensure all outstanding weak pointers | 354 // Note: This member must be the last to ensure all outstanding weak pointers |
| 326 // are invalidated first. | 355 // are invalidated first. |
| 327 base::WeakPtrFactory<UserMediaClientImpl> weak_factory_; | 356 base::WeakPtrFactory<UserMediaClientImpl> weak_factory_; |
| 328 | 357 |
| 329 DISALLOW_COPY_AND_ASSIGN(UserMediaClientImpl); | 358 DISALLOW_COPY_AND_ASSIGN(UserMediaClientImpl); |
| 330 }; | 359 }; |
| 331 | 360 |
| 332 } // namespace content | 361 } // namespace content |
| 333 | 362 |
| 334 #endif // CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ | 363 #endif // CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ |
| OLD | NEW |