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