| 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 #include "content/browser/media/capture/web_contents_video_capture_device.h" | 5 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 const media::VideoCaptureParams& params); | 189 const media::VideoCaptureParams& params); |
| 190 void InternalSuspend(); | 190 void InternalSuspend(); |
| 191 void InternalResume(); | 191 void InternalResume(); |
| 192 void InternalStop(const base::Closure& callback); | 192 void InternalStop(const base::Closure& callback); |
| 193 void InternalMaybeCaptureForRefresh(); | 193 void InternalMaybeCaptureForRefresh(); |
| 194 bool IsStarted() const; | 194 bool IsStarted() const; |
| 195 | 195 |
| 196 // Computes the preferred size of the target RenderWidget for optimal capture. | 196 // Computes the preferred size of the target RenderWidget for optimal capture. |
| 197 gfx::Size ComputeOptimalViewSize() const; | 197 gfx::Size ComputeOptimalViewSize() const; |
| 198 | 198 |
| 199 // Response callback for RWHVP::CopyFromCompositingSurfaceToVideoFrame(). | 199 // Response callback for RWHV::CopyFromSurfaceToVideoFrame(). |
| 200 void DidCopyToVideoFrame( | 200 void DidCopyToVideoFrame( |
| 201 const base::TimeTicks& start_time, | 201 const base::TimeTicks& start_time, |
| 202 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& | 202 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& |
| 203 deliver_frame_cb, | 203 deliver_frame_cb, |
| 204 const gfx::Rect& region_in_frame, | 204 const gfx::Rect& region_in_frame, |
| 205 bool success); | 205 bool success); |
| 206 | 206 |
| 207 // Remove the old subscription, and attempt to start a new one. If | 207 // Remove the old subscription, and attempt to start a new one. If |
| 208 // |is_still_tracking| is false, emit an error rather than attempt to start a | 208 // |is_still_tracking| is false, emit an error rather than attempt to start a |
| 209 // new subscription. | 209 // new subscription. |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 subscription_->MaybeCaptureForRefresh(); | 538 subscription_->MaybeCaptureForRefresh(); |
| 539 } | 539 } |
| 540 | 540 |
| 541 void WebContentsCaptureMachine::Capture( | 541 void WebContentsCaptureMachine::Capture( |
| 542 base::TimeTicks start_time, | 542 base::TimeTicks start_time, |
| 543 scoped_refptr<media::VideoFrame> target, | 543 scoped_refptr<media::VideoFrame> target, |
| 544 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& | 544 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& |
| 545 deliver_frame_cb) { | 545 deliver_frame_cb) { |
| 546 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 546 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 547 | 547 |
| 548 auto* const view = | 548 RenderWidgetHostView* const view = tracker_->GetTargetView(); |
| 549 static_cast<RenderWidgetHostViewBase*>(tracker_->GetTargetView()); | 549 if (!view) |
| 550 if (!view || !view->CanCopyToVideoFrame()) { | |
| 551 deliver_frame_cb.Run(base::TimeTicks(), gfx::Rect(), false); | |
| 552 return; | 550 return; |
| 553 } | 551 view->CopyFromSurfaceToVideoFrame( |
| 554 | 552 gfx::Rect(), std::move(target), |
| 555 const gfx::Size view_size = view->GetViewBounds().size(); | |
| 556 view->CopyFromCompositingSurfaceToVideoFrame( | |
| 557 gfx::Rect(view_size), std::move(target), | |
| 558 base::Bind(&WebContentsCaptureMachine::DidCopyToVideoFrame, | 553 base::Bind(&WebContentsCaptureMachine::DidCopyToVideoFrame, |
| 559 weak_ptr_factory_.GetWeakPtr(), start_time, deliver_frame_cb)); | 554 weak_ptr_factory_.GetWeakPtr(), start_time, deliver_frame_cb)); |
| 560 } | 555 } |
| 561 | 556 |
| 562 gfx::Size WebContentsCaptureMachine::ComputeOptimalViewSize() const { | 557 gfx::Size WebContentsCaptureMachine::ComputeOptimalViewSize() const { |
| 563 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 558 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 564 | 559 |
| 565 // TODO(miu): Propagate capture frame size changes as new "preferred size" | 560 // TODO(miu): Propagate capture frame size changes as new "preferred size" |
| 566 // updates, rather than just using the max frame size. | 561 // updates, rather than just using the max frame size. |
| 567 // http://crbug.com/350491 | 562 // http://crbug.com/350491 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 620 |
| 626 void WebContentsCaptureMachine::DidCopyToVideoFrame( | 621 void WebContentsCaptureMachine::DidCopyToVideoFrame( |
| 627 const base::TimeTicks& start_time, | 622 const base::TimeTicks& start_time, |
| 628 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& | 623 const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& |
| 629 deliver_frame_cb, | 624 deliver_frame_cb, |
| 630 const gfx::Rect& region_in_frame, | 625 const gfx::Rect& region_in_frame, |
| 631 bool success) { | 626 bool success) { |
| 632 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 627 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 633 | 628 |
| 634 // Capture can fail due to transient issues, so just skip this frame. | 629 // Capture can fail due to transient issues, so just skip this frame. |
| 635 DVLOG_IF(1, !success) << "CopyFromCompositingSurface failed; skipping frame."; | 630 DVLOG_IF(1, !success) |
| 631 << "CopyFromSurfaceToVideoFrame() failed; skipping frame."; |
| 636 deliver_frame_cb.Run(start_time, region_in_frame, success); | 632 deliver_frame_cb.Run(start_time, region_in_frame, success); |
| 637 } | 633 } |
| 638 | 634 |
| 639 void WebContentsCaptureMachine::RenewFrameSubscription(bool is_still_tracking) { | 635 void WebContentsCaptureMachine::RenewFrameSubscription(bool is_still_tracking) { |
| 640 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 636 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 641 | 637 |
| 642 // Always destroy the old subscription before creating a new one. | 638 // Always destroy the old subscription before creating a new one. |
| 643 if (subscription_) { | 639 if (subscription_) { |
| 644 DVLOG(1) << "Cancelling existing subscription."; | 640 DVLOG(1) << "Cancelling existing subscription."; |
| 645 subscription_.reset(); | 641 subscription_.reset(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 void WebContentsVideoCaptureDevice::StopAndDeAllocate() { | 748 void WebContentsVideoCaptureDevice::StopAndDeAllocate() { |
| 753 core_->StopAndDeAllocate(); | 749 core_->StopAndDeAllocate(); |
| 754 } | 750 } |
| 755 | 751 |
| 756 void WebContentsVideoCaptureDevice::OnUtilizationReport(int frame_feedback_id, | 752 void WebContentsVideoCaptureDevice::OnUtilizationReport(int frame_feedback_id, |
| 757 double utilization) { | 753 double utilization) { |
| 758 core_->OnConsumerReportingUtilization(frame_feedback_id, utilization); | 754 core_->OnConsumerReportingUtilization(frame_feedback_id, utilization); |
| 759 } | 755 } |
| 760 | 756 |
| 761 } // namespace content | 757 } // namespace content |
| OLD | NEW |