Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: content/browser/media/capture/web_contents_video_capture_device.cc

Issue 2652343003: Replace source pointer in cc::CopyOutputRequest with a base::UnguessableToken (Closed)
Patch Set: c Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <string> 11 #include <string>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "content/browser/media/capture/cursor_renderer.h" 21 #include "content/browser/media/capture/cursor_renderer.h"
22 #include "content/browser/media/capture/web_contents_tracker.h" 22 #include "content/browser/media/capture/web_contents_tracker.h"
23 #include "content/browser/media/capture/window_activity_tracker.h" 23 #include "content/browser/media/capture/window_activity_tracker.h"
24 #include "content/browser/renderer_host/render_widget_host_impl.h" 24 #include "content/browser/renderer_host/render_widget_host_impl.h"
25 #include "content/browser/renderer_host/render_widget_host_view_base.h" 25 #include "content/browser/renderer_host/render_widget_host_view_base.h"
26 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber .h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/render_process_host.h" 28 #include "content/public/browser/render_process_host.h"
28 #include "content/public/browser/render_widget_host_view.h" 29 #include "content/public/browser/render_widget_host_view.h"
29 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
30 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_contents_media_capture_id.h" 31 #include "content/public/browser/web_contents_media_capture_id.h"
32 #include "media/base/video_frame_metadata.h" 32 #include "media/base/video_frame_metadata.h"
33 #include "media/capture/content/screen_capture_device_core.h" 33 #include "media/capture/content/screen_capture_device_core.h"
34 #include "media/capture/content/thread_safe_capture_oracle.h" 34 #include "media/capture/content/thread_safe_capture_oracle.h"
35 #include "media/capture/content/video_capture_oracle.h" 35 #include "media/capture/content/video_capture_oracle.h"
36 #include "media/capture/video_capture_types.h" 36 #include "media/capture/video_capture_types.h"
37 #include "ui/base/layout.h" 37 #include "ui/base/layout.h"
38 #include "ui/gfx/geometry/dip_util.h" 38 #include "ui/gfx/geometry/dip_util.h"
39 #include "ui/gfx/geometry/size_conversions.h" 39 #include "ui/gfx/geometry/size_conversions.h"
(...skipping 13 matching lines...) Expand all
53 class FrameSubscriber : public RenderWidgetHostViewFrameSubscriber { 53 class FrameSubscriber : public RenderWidgetHostViewFrameSubscriber {
54 public: 54 public:
55 FrameSubscriber(media::VideoCaptureOracle::Event event_type, 55 FrameSubscriber(media::VideoCaptureOracle::Event event_type,
56 scoped_refptr<media::ThreadSafeCaptureOracle> oracle, 56 scoped_refptr<media::ThreadSafeCaptureOracle> oracle,
57 base::WeakPtr<content::CursorRenderer> cursor_renderer, 57 base::WeakPtr<content::CursorRenderer> cursor_renderer,
58 base::WeakPtr<content::WindowActivityTracker> tracker) 58 base::WeakPtr<content::WindowActivityTracker> tracker)
59 : event_type_(event_type), 59 : event_type_(event_type),
60 oracle_proxy_(std::move(oracle)), 60 oracle_proxy_(std::move(oracle)),
61 cursor_renderer_(cursor_renderer), 61 cursor_renderer_(cursor_renderer),
62 window_activity_tracker_(tracker), 62 window_activity_tracker_(tracker),
63 source_id_for_copy_request_(base::UnguessableToken::Create()),
63 weak_ptr_factory_(this) {} 64 weak_ptr_factory_(this) {}
64 65
65 bool ShouldCaptureFrame(
66 const gfx::Rect& damage_rect,
67 base::TimeTicks present_time,
68 scoped_refptr<media::VideoFrame>* storage,
69 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback*
70 deliver_frame_cb) override;
71
72 static void DidCaptureFrame( 66 static void DidCaptureFrame(
73 base::WeakPtr<FrameSubscriber> frame_subscriber_, 67 base::WeakPtr<FrameSubscriber> frame_subscriber_,
74 const media::ThreadSafeCaptureOracle::CaptureFrameCallback& 68 const media::ThreadSafeCaptureOracle::CaptureFrameCallback&
75 capture_frame_cb, 69 capture_frame_cb,
76 scoped_refptr<media::VideoFrame> frame, 70 scoped_refptr<media::VideoFrame> frame,
77 base::TimeTicks timestamp, 71 base::TimeTicks timestamp,
78 const gfx::Rect& region_in_frame, 72 const gfx::Rect& region_in_frame,
79 bool success); 73 bool success);
80 74
81 bool IsUserInteractingWithContent(); 75 bool IsUserInteractingWithContent();
82 76
77 // RenderWidgetHostViewFrameSubscriber implementation:
78 bool ShouldCaptureFrame(
79 const gfx::Rect& damage_rect,
80 base::TimeTicks present_time,
81 scoped_refptr<media::VideoFrame>* storage,
82 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback*
83 deliver_frame_cb) override;
84 const base::UnguessableToken& GetSourceIdForCopyRequest() override;
85
83 private: 86 private:
84 const media::VideoCaptureOracle::Event event_type_; 87 const media::VideoCaptureOracle::Event event_type_;
85 const scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy_; 88 const scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy_;
86 // We need a weak pointer since FrameSubscriber is owned externally and 89 // We need a weak pointer since FrameSubscriber is owned externally and
87 // may outlive the cursor renderer. 90 // may outlive the cursor renderer.
88 const base::WeakPtr<CursorRenderer> cursor_renderer_; 91 const base::WeakPtr<CursorRenderer> cursor_renderer_;
89 // We need a weak pointer since FrameSubscriber is owned externally and 92 // We need a weak pointer since FrameSubscriber is owned externally and
90 // may outlive the ui activity tracker. 93 // may outlive the ui activity tracker.
91 const base::WeakPtr<WindowActivityTracker> window_activity_tracker_; 94 const base::WeakPtr<WindowActivityTracker> window_activity_tracker_;
95 base::UnguessableToken source_id_for_copy_request_;
92 base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_; 96 base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_;
93 }; 97 };
94 98
95 // ContentCaptureSubscription is the relationship between a RenderWidgetHostView 99 // ContentCaptureSubscription is the relationship between a RenderWidgetHostView
96 // whose content is updating, a subscriber that is deciding which of these 100 // whose content is updating, a subscriber that is deciding which of these
97 // updates to capture (and where to deliver them to), and a callback that 101 // updates to capture (and where to deliver them to), and a callback that
98 // knows how to do the capture and prepare the result for delivery. 102 // knows how to do the capture and prepare the result for delivery.
99 // 103 //
100 // In practice, this means (a) installing a RenderWidgetHostFrameSubscriber in 104 // In practice, this means (a) installing a RenderWidgetHostFrameSubscriber in
101 // the RenderWidgetHostView, to process compositor updates, and (b) occasionally 105 // the RenderWidgetHostView, to process compositor updates, and (b) occasionally
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // resumed. 240 // resumed.
237 bool frame_capture_active_; 241 bool frame_capture_active_;
238 242
239 // Weak pointer factory used to invalidate callbacks. 243 // Weak pointer factory used to invalidate callbacks.
240 // NOTE: Weak pointers must be invalidated before all other member variables. 244 // NOTE: Weak pointers must be invalidated before all other member variables.
241 base::WeakPtrFactory<WebContentsCaptureMachine> weak_ptr_factory_; 245 base::WeakPtrFactory<WebContentsCaptureMachine> weak_ptr_factory_;
242 246
243 DISALLOW_COPY_AND_ASSIGN(WebContentsCaptureMachine); 247 DISALLOW_COPY_AND_ASSIGN(WebContentsCaptureMachine);
244 }; 248 };
245 249
246 bool FrameSubscriber::ShouldCaptureFrame(
247 const gfx::Rect& damage_rect,
248 base::TimeTicks present_time,
249 scoped_refptr<media::VideoFrame>* storage,
250 DeliverFrameCallback* deliver_frame_cb) {
251 TRACE_EVENT1("gpu.capture", "FrameSubscriber::ShouldCaptureFrame", "instance",
252 this);
253
254 media::ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb;
255 if (!oracle_proxy_->ObserveEventAndDecideCapture(
256 event_type_, damage_rect, present_time, storage, &capture_frame_cb)) {
257 return false;
258 }
259
260 DCHECK(*storage);
261 DCHECK(!capture_frame_cb.is_null());
262 *deliver_frame_cb =
263 base::Bind(&FrameSubscriber::DidCaptureFrame,
264 weak_ptr_factory_.GetWeakPtr(), capture_frame_cb, *storage);
265 return true;
266 }
267
268 void FrameSubscriber::DidCaptureFrame( 250 void FrameSubscriber::DidCaptureFrame(
269 base::WeakPtr<FrameSubscriber> frame_subscriber_, 251 base::WeakPtr<FrameSubscriber> frame_subscriber_,
270 const media::ThreadSafeCaptureOracle::CaptureFrameCallback& 252 const media::ThreadSafeCaptureOracle::CaptureFrameCallback&
271 capture_frame_cb, 253 capture_frame_cb,
272 scoped_refptr<media::VideoFrame> frame, 254 scoped_refptr<media::VideoFrame> frame,
273 base::TimeTicks timestamp, 255 base::TimeTicks timestamp,
274 const gfx::Rect& region_in_frame, 256 const gfx::Rect& region_in_frame,
275 bool success) { 257 bool success) {
276 if (success) { 258 if (success) {
277 // We can get a callback in the shutdown sequence for the browser main loop 259 // We can get a callback in the shutdown sequence for the browser main loop
(...skipping 25 matching lines...) Expand all
303 base::TimeDelta::FromMilliseconds(kMinPeriodNoAnimationMillis); 285 base::TimeDelta::FromMilliseconds(kMinPeriodNoAnimationMillis);
304 if (ui_activity && !animation_active) { 286 if (ui_activity && !animation_active) {
305 interactive_mode = true; 287 interactive_mode = true;
306 } else if (animation_active && window_activity_tracker_) { 288 } else if (animation_active && window_activity_tracker_) {
307 window_activity_tracker_->Reset(); 289 window_activity_tracker_->Reset();
308 } 290 }
309 } 291 }
310 return interactive_mode; 292 return interactive_mode;
311 } 293 }
312 294
295 bool FrameSubscriber::ShouldCaptureFrame(
296 const gfx::Rect& damage_rect,
297 base::TimeTicks present_time,
298 scoped_refptr<media::VideoFrame>* storage,
299 DeliverFrameCallback* deliver_frame_cb) {
300 TRACE_EVENT1("gpu.capture", "FrameSubscriber::ShouldCaptureFrame", "instance",
301 this);
302
303 media::ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb;
304 if (!oracle_proxy_->ObserveEventAndDecideCapture(
305 event_type_, damage_rect, present_time, storage, &capture_frame_cb)) {
306 return false;
307 }
308
309 DCHECK(*storage);
310 DCHECK(!capture_frame_cb.is_null());
311 *deliver_frame_cb =
312 base::Bind(&FrameSubscriber::DidCaptureFrame,
313 weak_ptr_factory_.GetWeakPtr(), capture_frame_cb, *storage);
314 return true;
315 }
316
317 const base::UnguessableToken& FrameSubscriber::GetSourceIdForCopyRequest() {
318 return source_id_for_copy_request_;
319 }
320
313 ContentCaptureSubscription::ContentCaptureSubscription( 321 ContentCaptureSubscription::ContentCaptureSubscription(
314 base::WeakPtr<RenderWidgetHostViewBase> source_view, 322 base::WeakPtr<RenderWidgetHostViewBase> source_view,
315 scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy, 323 scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy,
316 const CaptureCallback& capture_callback) 324 const CaptureCallback& capture_callback)
317 : source_view_(source_view), capture_callback_(capture_callback) { 325 : source_view_(source_view), capture_callback_(capture_callback) {
318 DCHECK_CURRENTLY_ON(BrowserThread::UI); 326 DCHECK_CURRENTLY_ON(BrowserThread::UI);
319 DCHECK(source_view_); 327 DCHECK(source_view_);
320 328
321 #if defined(USE_AURA) || defined(OS_MACOSX) 329 #if defined(USE_AURA) || defined(OS_MACOSX)
322 cursor_renderer_ = CursorRenderer::Create(source_view_->GetNativeView()); 330 cursor_renderer_ = CursorRenderer::Create(source_view_->GetNativeView());
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 void WebContentsVideoCaptureDevice::StopAndDeAllocate() { 752 void WebContentsVideoCaptureDevice::StopAndDeAllocate() {
745 core_->StopAndDeAllocate(); 753 core_->StopAndDeAllocate();
746 } 754 }
747 755
748 void WebContentsVideoCaptureDevice::OnUtilizationReport(int frame_feedback_id, 756 void WebContentsVideoCaptureDevice::OnUtilizationReport(int frame_feedback_id,
749 double utilization) { 757 double utilization) {
750 core_->OnConsumerReportingUtilization(frame_feedback_id, utilization); 758 core_->OnConsumerReportingUtilization(frame_feedback_id, utilization);
751 } 759 }
752 760
753 } // namespace content 761 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_process_host.cc ('k') | content/browser/media/capture/web_contents_video_capture_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698