| 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 // Implementation notes: This needs to work on a variety of hardware | 5 // Implementation notes: This needs to work on a variety of hardware |
| 6 // configurations where the speed of the CPU and GPU greatly affect overall | 6 // configurations where the speed of the CPU and GPU greatly affect overall |
| 7 // performance. Spanning several threads, the process of capturing has been | 7 // performance. Spanning several threads, the process of capturing has been |
| 8 // split up into four conceptual stages: | 8 // split up into four conceptual stages: |
| 9 // | 9 // |
| 10 // 1. Reserve Buffer: Before a frame can be captured, a slot in the client's | 10 // 1. Reserve Buffer: Before a frame can be captured, a slot in the client's |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 #include "content/browser/media/capture/web_contents_tracker.h" | 73 #include "content/browser/media/capture/web_contents_tracker.h" |
| 74 #include "content/browser/media/capture/window_activity_tracker.h" | 74 #include "content/browser/media/capture/window_activity_tracker.h" |
| 75 #include "content/browser/renderer_host/render_widget_host_impl.h" | 75 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 76 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 76 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 77 #include "content/public/browser/browser_thread.h" | 77 #include "content/public/browser/browser_thread.h" |
| 78 #include "content/public/browser/render_process_host.h" | 78 #include "content/public/browser/render_process_host.h" |
| 79 #include "content/public/browser/render_widget_host_view.h" | 79 #include "content/public/browser/render_widget_host_view.h" |
| 80 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 80 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
| 81 #include "content/public/browser/web_contents.h" | 81 #include "content/public/browser/web_contents.h" |
| 82 #include "content/public/browser/web_contents_media_capture_id.h" | 82 #include "content/public/browser/web_contents_media_capture_id.h" |
| 83 #include "device/capture/content/screen_capture_device_core.h" |
| 84 #include "device/capture/content/thread_safe_capture_oracle.h" |
| 85 #include "device/capture/content/video_capture_oracle.h" |
| 83 #include "media/base/bind_to_current_loop.h" | 86 #include "media/base/bind_to_current_loop.h" |
| 84 #include "media/base/video_capture_types.h" | 87 #include "media/base/video_capture_types.h" |
| 85 #include "media/base/video_frame_metadata.h" | 88 #include "media/base/video_frame_metadata.h" |
| 86 #include "media/base/video_util.h" | 89 #include "media/base/video_util.h" |
| 87 #include "media/capture/content/screen_capture_device_core.h" | |
| 88 #include "media/capture/content/thread_safe_capture_oracle.h" | |
| 89 #include "media/capture/content/video_capture_oracle.h" | |
| 90 #include "skia/ext/image_operations.h" | 90 #include "skia/ext/image_operations.h" |
| 91 #include "third_party/skia/include/core/SkBitmap.h" | 91 #include "third_party/skia/include/core/SkBitmap.h" |
| 92 #include "third_party/skia/include/core/SkColor.h" | 92 #include "third_party/skia/include/core/SkColor.h" |
| 93 #include "ui/base/layout.h" | 93 #include "ui/base/layout.h" |
| 94 #include "ui/gfx/geometry/dip_util.h" | 94 #include "ui/gfx/geometry/dip_util.h" |
| 95 #include "ui/gfx/geometry/size_conversions.h" | 95 #include "ui/gfx/geometry/size_conversions.h" |
| 96 | 96 |
| 97 namespace content { | 97 namespace content { |
| 98 | 98 |
| 99 namespace { | 99 namespace { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 128 base::TimeTicks last_frame_rate_log_time_; | 128 base::TimeTicks last_frame_rate_log_time_; |
| 129 int count_frames_rendered_; | 129 int count_frames_rendered_; |
| 130 | 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(VideoFrameDeliveryLog); | 131 DISALLOW_COPY_AND_ASSIGN(VideoFrameDeliveryLog); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 // FrameSubscriber is a proxy to the ThreadSafeCaptureOracle that's compatible | 134 // FrameSubscriber is a proxy to the ThreadSafeCaptureOracle that's compatible |
| 135 // with RenderWidgetHostViewFrameSubscriber. We create one per event type. | 135 // with RenderWidgetHostViewFrameSubscriber. We create one per event type. |
| 136 class FrameSubscriber : public RenderWidgetHostViewFrameSubscriber { | 136 class FrameSubscriber : public RenderWidgetHostViewFrameSubscriber { |
| 137 public: | 137 public: |
| 138 FrameSubscriber(media::VideoCaptureOracle::Event event_type, | 138 FrameSubscriber(device::VideoCaptureOracle::Event event_type, |
| 139 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle, | 139 const scoped_refptr<device::ThreadSafeCaptureOracle>& oracle, |
| 140 VideoFrameDeliveryLog* delivery_log, | 140 VideoFrameDeliveryLog* delivery_log, |
| 141 base::WeakPtr<content::CursorRenderer> cursor_renderer, | 141 base::WeakPtr<content::CursorRenderer> cursor_renderer, |
| 142 base::WeakPtr<content::WindowActivityTracker> tracker) | 142 base::WeakPtr<content::WindowActivityTracker> tracker) |
| 143 : event_type_(event_type), | 143 : event_type_(event_type), |
| 144 oracle_proxy_(oracle), | 144 oracle_proxy_(oracle), |
| 145 delivery_log_(delivery_log), | 145 delivery_log_(delivery_log), |
| 146 cursor_renderer_(cursor_renderer), | 146 cursor_renderer_(cursor_renderer), |
| 147 window_activity_tracker_(tracker), | 147 window_activity_tracker_(tracker), |
| 148 weak_ptr_factory_(this) {} | 148 weak_ptr_factory_(this) {} |
| 149 | 149 |
| 150 bool ShouldCaptureFrame( | 150 bool ShouldCaptureFrame( |
| 151 const gfx::Rect& damage_rect, | 151 const gfx::Rect& damage_rect, |
| 152 base::TimeTicks present_time, | 152 base::TimeTicks present_time, |
| 153 scoped_refptr<media::VideoFrame>* storage, | 153 scoped_refptr<media::VideoFrame>* storage, |
| 154 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback* | 154 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback* |
| 155 deliver_frame_cb) override; | 155 deliver_frame_cb) override; |
| 156 | 156 |
| 157 static void DidCaptureFrame( | 157 static void DidCaptureFrame( |
| 158 base::WeakPtr<FrameSubscriber> frame_subscriber_, | 158 base::WeakPtr<FrameSubscriber> frame_subscriber_, |
| 159 const media::ThreadSafeCaptureOracle::CaptureFrameCallback& | 159 const device::ThreadSafeCaptureOracle::CaptureFrameCallback& |
| 160 capture_frame_cb, | 160 capture_frame_cb, |
| 161 const scoped_refptr<media::VideoFrame>& frame, | 161 const scoped_refptr<media::VideoFrame>& frame, |
| 162 base::TimeTicks timestamp, | 162 base::TimeTicks timestamp, |
| 163 const gfx::Rect& region_in_frame, | 163 const gfx::Rect& region_in_frame, |
| 164 bool success); | 164 bool success); |
| 165 | 165 |
| 166 bool IsUserInteractingWithContent(); | 166 bool IsUserInteractingWithContent(); |
| 167 | 167 |
| 168 private: | 168 private: |
| 169 const media::VideoCaptureOracle::Event event_type_; | 169 const device::VideoCaptureOracle::Event event_type_; |
| 170 scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy_; | 170 scoped_refptr<device::ThreadSafeCaptureOracle> oracle_proxy_; |
| 171 VideoFrameDeliveryLog* const delivery_log_; | 171 VideoFrameDeliveryLog* const delivery_log_; |
| 172 // We need a weak pointer since FrameSubscriber is owned externally and | 172 // We need a weak pointer since FrameSubscriber is owned externally and |
| 173 // may outlive the cursor renderer. | 173 // may outlive the cursor renderer. |
| 174 base::WeakPtr<CursorRenderer> cursor_renderer_; | 174 base::WeakPtr<CursorRenderer> cursor_renderer_; |
| 175 // We need a weak pointer since FrameSubscriber is owned externally and | 175 // We need a weak pointer since FrameSubscriber is owned externally and |
| 176 // may outlive the ui activity tracker. | 176 // may outlive the ui activity tracker. |
| 177 base::WeakPtr<WindowActivityTracker> window_activity_tracker_; | 177 base::WeakPtr<WindowActivityTracker> window_activity_tracker_; |
| 178 base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_; | 178 base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_; |
| 179 }; | 179 }; |
| 180 | 180 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 197 const base::TimeTicks&, | 197 const base::TimeTicks&, |
| 198 const scoped_refptr<media::VideoFrame>&, | 198 const scoped_refptr<media::VideoFrame>&, |
| 199 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback&)> | 199 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback&)> |
| 200 CaptureCallback; | 200 CaptureCallback; |
| 201 | 201 |
| 202 // Create a subscription. Whenever a manual capture is required, the | 202 // Create a subscription. Whenever a manual capture is required, the |
| 203 // subscription will invoke |capture_callback| on the UI thread to do the | 203 // subscription will invoke |capture_callback| on the UI thread to do the |
| 204 // work. | 204 // work. |
| 205 ContentCaptureSubscription( | 205 ContentCaptureSubscription( |
| 206 const RenderWidgetHost& source, | 206 const RenderWidgetHost& source, |
| 207 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 207 const scoped_refptr<device::ThreadSafeCaptureOracle>& oracle_proxy, |
| 208 const CaptureCallback& capture_callback); | 208 const CaptureCallback& capture_callback); |
| 209 ~ContentCaptureSubscription(); | 209 ~ContentCaptureSubscription(); |
| 210 | 210 |
| 211 void MaybeCaptureForRefresh(); | 211 void MaybeCaptureForRefresh(); |
| 212 | 212 |
| 213 private: | 213 private: |
| 214 // Called for active frame refresh requests, or mouse activity events. | 214 // Called for active frame refresh requests, or mouse activity events. |
| 215 void OnEvent(FrameSubscriber* subscriber); | 215 void OnEvent(FrameSubscriber* subscriber); |
| 216 | 216 |
| 217 // Maintain a weak reference to the RenderWidgetHost (via its routing ID), | 217 // Maintain a weak reference to the RenderWidgetHost (via its routing ID), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 246 // these activities is not possible. This operation may be expensive (tens to | 246 // these activities is not possible. This operation may be expensive (tens to |
| 247 // hundreds of milliseconds), so the caller should ensure that it runs on a | 247 // hundreds of milliseconds), so the caller should ensure that it runs on a |
| 248 // thread where such a pause would cause UI jank. | 248 // thread where such a pause would cause UI jank. |
| 249 void RenderVideoFrame( | 249 void RenderVideoFrame( |
| 250 const SkBitmap& input, | 250 const SkBitmap& input, |
| 251 const scoped_refptr<media::VideoFrame>& output, | 251 const scoped_refptr<media::VideoFrame>& output, |
| 252 const base::Callback<void(const gfx::Rect&, bool)>& done_cb); | 252 const base::Callback<void(const gfx::Rect&, bool)>& done_cb); |
| 253 | 253 |
| 254 // Renews capture subscriptions based on feedback from WebContentsTracker, and | 254 // Renews capture subscriptions based on feedback from WebContentsTracker, and |
| 255 // also executes copying of the backing store on the UI BrowserThread. | 255 // also executes copying of the backing store on the UI BrowserThread. |
| 256 class WebContentsCaptureMachine : public media::VideoCaptureMachine { | 256 class WebContentsCaptureMachine : public device::VideoCaptureMachine { |
| 257 public: | 257 public: |
| 258 WebContentsCaptureMachine(int render_process_id, | 258 WebContentsCaptureMachine(int render_process_id, |
| 259 int main_render_frame_id, | 259 int main_render_frame_id, |
| 260 bool enable_auto_throttling); | 260 bool enable_auto_throttling); |
| 261 ~WebContentsCaptureMachine() override; | 261 ~WebContentsCaptureMachine() override; |
| 262 | 262 |
| 263 // VideoCaptureMachine overrides. | 263 // VideoCaptureMachine overrides. |
| 264 void Start(const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 264 void Start(const scoped_refptr<device::ThreadSafeCaptureOracle>& oracle_proxy, |
| 265 const media::VideoCaptureParams& params, | 265 const media::VideoCaptureParams& params, |
| 266 const base::Callback<void(bool)> callback) override; | 266 const base::Callback<void(bool)> callback) override; |
| 267 void Stop(const base::Closure& callback) override; | 267 void Stop(const base::Closure& callback) override; |
| 268 bool IsAutoThrottlingEnabled() const override { | 268 bool IsAutoThrottlingEnabled() const override { |
| 269 return auto_throttling_enabled_; | 269 return auto_throttling_enabled_; |
| 270 } | 270 } |
| 271 void MaybeCaptureForRefresh() override; | 271 void MaybeCaptureForRefresh() override; |
| 272 | 272 |
| 273 // Starts a copy from the backing store or the composited surface. Must be run | 273 // Starts a copy from the backing store or the composited surface. Must be run |
| 274 // on the UI BrowserThread. |deliver_frame_cb| will be run when the operation | 274 // on the UI BrowserThread. |deliver_frame_cb| will be run when the operation |
| 275 // completes. The copy will occur to |target|. | 275 // completes. The copy will occur to |target|. |
| 276 // | 276 // |
| 277 // This may be used as a ContentCaptureSubscription::CaptureCallback. | 277 // This may be used as a ContentCaptureSubscription::CaptureCallback. |
| 278 void Capture(const base::TimeTicks& start_time, | 278 void Capture(const base::TimeTicks& start_time, |
| 279 const scoped_refptr<media::VideoFrame>& target, | 279 const scoped_refptr<media::VideoFrame>& target, |
| 280 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& | 280 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& |
| 281 deliver_frame_cb); | 281 deliver_frame_cb); |
| 282 | 282 |
| 283 private: | 283 private: |
| 284 bool InternalStart( | 284 bool InternalStart( |
| 285 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 285 const scoped_refptr<device::ThreadSafeCaptureOracle>& oracle_proxy, |
| 286 const media::VideoCaptureParams& params); | 286 const media::VideoCaptureParams& params); |
| 287 void InternalStop(const base::Closure& callback); | 287 void InternalStop(const base::Closure& callback); |
| 288 void InternalMaybeCaptureForRefresh(); | 288 void InternalMaybeCaptureForRefresh(); |
| 289 bool IsStarted() const; | 289 bool IsStarted() const; |
| 290 | 290 |
| 291 // Computes the preferred size of the target RenderWidget for optimal capture. | 291 // Computes the preferred size of the target RenderWidget for optimal capture. |
| 292 gfx::Size ComputeOptimalViewSize() const; | 292 gfx::Size ComputeOptimalViewSize() const; |
| 293 | 293 |
| 294 // Response callback for RenderWidgetHost::CopyFromBackingStore(). | 294 // Response callback for RenderWidgetHost::CopyFromBackingStore(). |
| 295 void DidCopyFromBackingStore( | 295 void DidCopyFromBackingStore( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 326 // Set to false to prevent the capture size from automatically adjusting in | 326 // Set to false to prevent the capture size from automatically adjusting in |
| 327 // response to end-to-end utilization. This is enabled via the throttling | 327 // response to end-to-end utilization. This is enabled via the throttling |
| 328 // option in the WebContentsVideoCaptureDevice device ID. | 328 // option in the WebContentsVideoCaptureDevice device ID. |
| 329 const bool auto_throttling_enabled_; | 329 const bool auto_throttling_enabled_; |
| 330 | 330 |
| 331 // A dedicated worker thread on which SkBitmap->VideoFrame conversion will | 331 // A dedicated worker thread on which SkBitmap->VideoFrame conversion will |
| 332 // occur. Only used when this activity cannot be done on the GPU. | 332 // occur. Only used when this activity cannot be done on the GPU. |
| 333 std::unique_ptr<base::Thread> render_thread_; | 333 std::unique_ptr<base::Thread> render_thread_; |
| 334 | 334 |
| 335 // Makes all the decisions about which frames to copy, and how. | 335 // Makes all the decisions about which frames to copy, and how. |
| 336 scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy_; | 336 scoped_refptr<device::ThreadSafeCaptureOracle> oracle_proxy_; |
| 337 | 337 |
| 338 // Video capture parameters that this machine is started with. | 338 // Video capture parameters that this machine is started with. |
| 339 media::VideoCaptureParams capture_params_; | 339 media::VideoCaptureParams capture_params_; |
| 340 | 340 |
| 341 // Last known RenderView size. | 341 // Last known RenderView size. |
| 342 gfx::Size last_view_size_; | 342 gfx::Size last_view_size_; |
| 343 | 343 |
| 344 // Responsible for forwarding events from the active RenderWidgetHost to the | 344 // Responsible for forwarding events from the active RenderWidgetHost to the |
| 345 // oracle, and initiating captures accordingly. | 345 // oracle, and initiating captures accordingly. |
| 346 std::unique_ptr<ContentCaptureSubscription> subscription_; | 346 std::unique_ptr<ContentCaptureSubscription> subscription_; |
| 347 | 347 |
| 348 // Weak pointer factory used to invalidate callbacks. | 348 // Weak pointer factory used to invalidate callbacks. |
| 349 // NOTE: Weak pointers must be invalidated before all other member variables. | 349 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 350 base::WeakPtrFactory<WebContentsCaptureMachine> weak_ptr_factory_; | 350 base::WeakPtrFactory<WebContentsCaptureMachine> weak_ptr_factory_; |
| 351 | 351 |
| 352 DISALLOW_COPY_AND_ASSIGN(WebContentsCaptureMachine); | 352 DISALLOW_COPY_AND_ASSIGN(WebContentsCaptureMachine); |
| 353 }; | 353 }; |
| 354 | 354 |
| 355 bool FrameSubscriber::ShouldCaptureFrame( | 355 bool FrameSubscriber::ShouldCaptureFrame( |
| 356 const gfx::Rect& damage_rect, | 356 const gfx::Rect& damage_rect, |
| 357 base::TimeTicks present_time, | 357 base::TimeTicks present_time, |
| 358 scoped_refptr<media::VideoFrame>* storage, | 358 scoped_refptr<media::VideoFrame>* storage, |
| 359 DeliverFrameCallback* deliver_frame_cb) { | 359 DeliverFrameCallback* deliver_frame_cb) { |
| 360 TRACE_EVENT1("gpu.capture", "FrameSubscriber::ShouldCaptureFrame", "instance", | 360 TRACE_EVENT1("gpu.capture", "FrameSubscriber::ShouldCaptureFrame", "instance", |
| 361 this); | 361 this); |
| 362 | 362 |
| 363 media::ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 363 device::ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
| 364 | 364 |
| 365 bool oracle_decision = oracle_proxy_->ObserveEventAndDecideCapture( | 365 bool oracle_decision = oracle_proxy_->ObserveEventAndDecideCapture( |
| 366 event_type_, damage_rect, present_time, storage, &capture_frame_cb); | 366 event_type_, damage_rect, present_time, storage, &capture_frame_cb); |
| 367 | 367 |
| 368 if (!capture_frame_cb.is_null()) | 368 if (!capture_frame_cb.is_null()) |
| 369 *deliver_frame_cb = | 369 *deliver_frame_cb = |
| 370 base::Bind(&FrameSubscriber::DidCaptureFrame, | 370 base::Bind(&FrameSubscriber::DidCaptureFrame, |
| 371 weak_ptr_factory_.GetWeakPtr(), capture_frame_cb, *storage); | 371 weak_ptr_factory_.GetWeakPtr(), capture_frame_cb, *storage); |
| 372 if (oracle_decision) | 372 if (oracle_decision) |
| 373 delivery_log_->ChronicleFrameDelivery(present_time); | 373 delivery_log_->ChronicleFrameDelivery(present_time); |
| 374 return oracle_decision; | 374 return oracle_decision; |
| 375 } | 375 } |
| 376 | 376 |
| 377 void FrameSubscriber::DidCaptureFrame( | 377 void FrameSubscriber::DidCaptureFrame( |
| 378 base::WeakPtr<FrameSubscriber> frame_subscriber_, | 378 base::WeakPtr<FrameSubscriber> frame_subscriber_, |
| 379 const media::ThreadSafeCaptureOracle::CaptureFrameCallback& | 379 const device::ThreadSafeCaptureOracle::CaptureFrameCallback& |
| 380 capture_frame_cb, | 380 capture_frame_cb, |
| 381 const scoped_refptr<media::VideoFrame>& frame, | 381 const scoped_refptr<media::VideoFrame>& frame, |
| 382 base::TimeTicks timestamp, | 382 base::TimeTicks timestamp, |
| 383 const gfx::Rect& region_in_frame, | 383 const gfx::Rect& region_in_frame, |
| 384 bool success) { | 384 bool success) { |
| 385 // We can get a callback in the shutdown sequence for the browser main loop | 385 // We can get a callback in the shutdown sequence for the browser main loop |
| 386 // and this can result in a DCHECK failure. Avoid this by doing DCHECK only | 386 // and this can result in a DCHECK failure. Avoid this by doing DCHECK only |
| 387 // on success. | 387 // on success. |
| 388 if (success) { | 388 if (success) { |
| 389 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 389 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 418 interactive_mode = true; | 418 interactive_mode = true; |
| 419 } else if (animation_active && window_activity_tracker_.get()) { | 419 } else if (animation_active && window_activity_tracker_.get()) { |
| 420 window_activity_tracker_->Reset(); | 420 window_activity_tracker_->Reset(); |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 return interactive_mode; | 423 return interactive_mode; |
| 424 } | 424 } |
| 425 | 425 |
| 426 ContentCaptureSubscription::ContentCaptureSubscription( | 426 ContentCaptureSubscription::ContentCaptureSubscription( |
| 427 const RenderWidgetHost& source, | 427 const RenderWidgetHost& source, |
| 428 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 428 const scoped_refptr<device::ThreadSafeCaptureOracle>& oracle_proxy, |
| 429 const CaptureCallback& capture_callback) | 429 const CaptureCallback& capture_callback) |
| 430 : render_process_id_(source.GetProcess()->GetID()), | 430 : render_process_id_(source.GetProcess()->GetID()), |
| 431 render_widget_id_(source.GetRoutingID()), | 431 render_widget_id_(source.GetRoutingID()), |
| 432 delivery_log_(), | 432 delivery_log_(), |
| 433 capture_callback_(capture_callback) { | 433 capture_callback_(capture_callback) { |
| 434 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 434 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 435 | 435 |
| 436 RenderWidgetHostView* const view = source.GetView(); | 436 RenderWidgetHostView* const view = source.GetView(); |
| 437 #if defined(USE_AURA) || defined(OS_MACOSX) | 437 #if defined(USE_AURA) || defined(OS_MACOSX) |
| 438 if (view) { | 438 if (view) { |
| 439 cursor_renderer_ = CursorRenderer::Create(view->GetNativeView()); | 439 cursor_renderer_ = CursorRenderer::Create(view->GetNativeView()); |
| 440 window_activity_tracker_ = | 440 window_activity_tracker_ = |
| 441 WindowActivityTracker::Create(view->GetNativeView()); | 441 WindowActivityTracker::Create(view->GetNativeView()); |
| 442 } | 442 } |
| 443 #endif | 443 #endif |
| 444 refresh_subscriber_.reset(new FrameSubscriber( | 444 refresh_subscriber_.reset(new FrameSubscriber( |
| 445 media::VideoCaptureOracle::kActiveRefreshRequest, oracle_proxy, | 445 device::VideoCaptureOracle::kActiveRefreshRequest, oracle_proxy, |
| 446 &delivery_log_, | 446 &delivery_log_, |
| 447 cursor_renderer_ ? cursor_renderer_->GetWeakPtr() | 447 cursor_renderer_ ? cursor_renderer_->GetWeakPtr() |
| 448 : base::WeakPtr<CursorRenderer>(), | 448 : base::WeakPtr<CursorRenderer>(), |
| 449 window_activity_tracker_ ? window_activity_tracker_->GetWeakPtr() | 449 window_activity_tracker_ ? window_activity_tracker_->GetWeakPtr() |
| 450 : base::WeakPtr<WindowActivityTracker>())); | 450 : base::WeakPtr<WindowActivityTracker>())); |
| 451 mouse_activity_subscriber_.reset(new FrameSubscriber( | 451 mouse_activity_subscriber_.reset(new FrameSubscriber( |
| 452 media::VideoCaptureOracle::kMouseCursorUpdate, oracle_proxy, | 452 device::VideoCaptureOracle::kMouseCursorUpdate, oracle_proxy, |
| 453 &delivery_log_, cursor_renderer_ ? cursor_renderer_->GetWeakPtr() | 453 &delivery_log_, cursor_renderer_ ? cursor_renderer_->GetWeakPtr() |
| 454 : base::WeakPtr<CursorRenderer>(), | 454 : base::WeakPtr<CursorRenderer>(), |
| 455 window_activity_tracker_ ? window_activity_tracker_->GetWeakPtr() | 455 window_activity_tracker_ ? window_activity_tracker_->GetWeakPtr() |
| 456 : base::WeakPtr<WindowActivityTracker>())); | 456 : base::WeakPtr<WindowActivityTracker>())); |
| 457 | 457 |
| 458 // Subscribe to compositor updates. These will be serviced directly by the | 458 // Subscribe to compositor updates. These will be serviced directly by the |
| 459 // oracle. | 459 // oracle. |
| 460 if (view) { | 460 if (view) { |
| 461 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( | 461 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( |
| 462 new FrameSubscriber( | 462 new FrameSubscriber( |
| 463 media::VideoCaptureOracle::kCompositorUpdate, oracle_proxy, | 463 device::VideoCaptureOracle::kCompositorUpdate, oracle_proxy, |
| 464 &delivery_log_, cursor_renderer_ ? cursor_renderer_->GetWeakPtr() | 464 &delivery_log_, cursor_renderer_ ? cursor_renderer_->GetWeakPtr() |
| 465 : base::WeakPtr<CursorRenderer>(), | 465 : base::WeakPtr<CursorRenderer>(), |
| 466 window_activity_tracker_ ? window_activity_tracker_->GetWeakPtr() | 466 window_activity_tracker_ ? window_activity_tracker_->GetWeakPtr() |
| 467 : base::WeakPtr<WindowActivityTracker>())); | 467 : base::WeakPtr<WindowActivityTracker>())); |
| 468 view->BeginFrameSubscription(std::move(subscriber)); | 468 view->BeginFrameSubscription(std::move(subscriber)); |
| 469 } | 469 } |
| 470 | 470 |
| 471 // Subscribe to mouse movement and mouse cursor update events. | 471 // Subscribe to mouse movement and mouse cursor update events. |
| 472 if (window_activity_tracker_) { | 472 if (window_activity_tracker_) { |
| 473 window_activity_tracker_->RegisterMouseInteractionObserver( | 473 window_activity_tracker_->RegisterMouseInteractionObserver( |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 } | 625 } |
| 626 | 626 |
| 627 WebContentsCaptureMachine::~WebContentsCaptureMachine() {} | 627 WebContentsCaptureMachine::~WebContentsCaptureMachine() {} |
| 628 | 628 |
| 629 bool WebContentsCaptureMachine::IsStarted() const { | 629 bool WebContentsCaptureMachine::IsStarted() const { |
| 630 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 630 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 631 return weak_ptr_factory_.HasWeakPtrs(); | 631 return weak_ptr_factory_.HasWeakPtrs(); |
| 632 } | 632 } |
| 633 | 633 |
| 634 void WebContentsCaptureMachine::Start( | 634 void WebContentsCaptureMachine::Start( |
| 635 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 635 const scoped_refptr<device::ThreadSafeCaptureOracle>& oracle_proxy, |
| 636 const media::VideoCaptureParams& params, | 636 const media::VideoCaptureParams& params, |
| 637 const base::Callback<void(bool)> callback) { | 637 const base::Callback<void(bool)> callback) { |
| 638 // Starts the capture machine asynchronously. | 638 // Starts the capture machine asynchronously. |
| 639 BrowserThread::PostTaskAndReplyWithResult( | 639 BrowserThread::PostTaskAndReplyWithResult( |
| 640 BrowserThread::UI, FROM_HERE, | 640 BrowserThread::UI, FROM_HERE, |
| 641 base::Bind(&WebContentsCaptureMachine::InternalStart, | 641 base::Bind(&WebContentsCaptureMachine::InternalStart, |
| 642 base::Unretained(this), oracle_proxy, params), | 642 base::Unretained(this), oracle_proxy, params), |
| 643 callback); | 643 callback); |
| 644 } | 644 } |
| 645 | 645 |
| 646 bool WebContentsCaptureMachine::InternalStart( | 646 bool WebContentsCaptureMachine::InternalStart( |
| 647 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 647 const scoped_refptr<device::ThreadSafeCaptureOracle>& oracle_proxy, |
| 648 const media::VideoCaptureParams& params) { | 648 const media::VideoCaptureParams& params) { |
| 649 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 649 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 650 DCHECK(!IsStarted()); | 650 DCHECK(!IsStarted()); |
| 651 | 651 |
| 652 DCHECK(oracle_proxy); | 652 DCHECK(oracle_proxy); |
| 653 oracle_proxy_ = oracle_proxy; | 653 oracle_proxy_ = oracle_proxy; |
| 654 capture_params_ = params; | 654 capture_params_ = params; |
| 655 | 655 |
| 656 render_thread_.reset(new base::Thread("WebContentsVideo_RenderThread")); | 656 render_thread_.reset(new base::Thread("WebContentsVideo_RenderThread")); |
| 657 if (!render_thread_->Start()) { | 657 if (!render_thread_->Start()) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 | 932 |
| 933 oracle_proxy_->UpdateCaptureSize(physical_size); | 933 oracle_proxy_->UpdateCaptureSize(physical_size); |
| 934 } | 934 } |
| 935 | 935 |
| 936 } // namespace | 936 } // namespace |
| 937 | 937 |
| 938 WebContentsVideoCaptureDevice::WebContentsVideoCaptureDevice( | 938 WebContentsVideoCaptureDevice::WebContentsVideoCaptureDevice( |
| 939 int render_process_id, | 939 int render_process_id, |
| 940 int main_render_frame_id, | 940 int main_render_frame_id, |
| 941 bool enable_auto_throttling) | 941 bool enable_auto_throttling) |
| 942 : core_(new media::ScreenCaptureDeviceCore( | 942 : core_(new device::ScreenCaptureDeviceCore( |
| 943 std::unique_ptr<media::VideoCaptureMachine>( | 943 std::unique_ptr<device::VideoCaptureMachine>( |
| 944 new WebContentsCaptureMachine(render_process_id, | 944 new WebContentsCaptureMachine(render_process_id, |
| 945 main_render_frame_id, | 945 main_render_frame_id, |
| 946 enable_auto_throttling)))) {} | 946 enable_auto_throttling)))) {} |
| 947 | 947 |
| 948 WebContentsVideoCaptureDevice::~WebContentsVideoCaptureDevice() { | 948 WebContentsVideoCaptureDevice::~WebContentsVideoCaptureDevice() { |
| 949 DVLOG(2) << "WebContentsVideoCaptureDevice@" << this << " destroying."; | 949 DVLOG(2) << "WebContentsVideoCaptureDevice@" << this << " destroying."; |
| 950 } | 950 } |
| 951 | 951 |
| 952 // static | 952 // static |
| 953 media::VideoCaptureDevice* WebContentsVideoCaptureDevice::Create( | 953 device::VideoCaptureDevice* WebContentsVideoCaptureDevice::Create( |
| 954 const std::string& device_id) { | 954 const std::string& device_id) { |
| 955 // Parse device_id into render_process_id and main_render_frame_id. | 955 // Parse device_id into render_process_id and main_render_frame_id. |
| 956 int render_process_id = -1; | 956 int render_process_id = -1; |
| 957 int main_render_frame_id = -1; | 957 int main_render_frame_id = -1; |
| 958 if (!WebContentsMediaCaptureId::ExtractTabCaptureTarget( | 958 if (!WebContentsMediaCaptureId::ExtractTabCaptureTarget( |
| 959 device_id, &render_process_id, &main_render_frame_id)) { | 959 device_id, &render_process_id, &main_render_frame_id)) { |
| 960 return NULL; | 960 return NULL; |
| 961 } | 961 } |
| 962 | 962 |
| 963 return new WebContentsVideoCaptureDevice( | 963 return new WebContentsVideoCaptureDevice( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 974 | 974 |
| 975 void WebContentsVideoCaptureDevice::RequestRefreshFrame() { | 975 void WebContentsVideoCaptureDevice::RequestRefreshFrame() { |
| 976 core_->RequestRefreshFrame(); | 976 core_->RequestRefreshFrame(); |
| 977 } | 977 } |
| 978 | 978 |
| 979 void WebContentsVideoCaptureDevice::StopAndDeAllocate() { | 979 void WebContentsVideoCaptureDevice::StopAndDeAllocate() { |
| 980 core_->StopAndDeAllocate(); | 980 core_->StopAndDeAllocate(); |
| 981 } | 981 } |
| 982 | 982 |
| 983 } // namespace content | 983 } // namespace content |
| OLD | NEW |