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

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

Issue 268123003: Enables using the magnification API for screen capturing on Windows under a Finch experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/desktop_capture_device.h" 5 #include "content/browser/media/capture/desktop_capture_device.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
11 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "base/threading/sequenced_worker_pool.h" 15 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/threading/thread.h"
15 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" 17 #include "content/browser/media/capture/desktop_capture_device_uma_types.h"
16 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/desktop_media_id.h" 19 #include "content/public/browser/desktop_media_id.h"
18 #include "media/base/video_util.h" 20 #include "media/base/video_util.h"
19 #include "third_party/libyuv/include/libyuv/scale_argb.h" 21 #include "third_party/libyuv/include/libyuv/scale_argb.h"
20 #include "third_party/webrtc/modules/desktop_capture/desktop_and_cursor_composer .h" 22 #include "third_party/webrtc/modules/desktop_capture/desktop_and_cursor_composer .h"
21 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" 23 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
22 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" 24 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
23 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 25 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
24 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h" 26 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
(...skipping 23 matching lines...) Expand all
48 } // namespace 50 } // namespace
49 51
50 class DesktopCaptureDevice::Core 52 class DesktopCaptureDevice::Core
51 : public base::RefCountedThreadSafe<Core>, 53 : public base::RefCountedThreadSafe<Core>,
52 public webrtc::DesktopCapturer::Callback { 54 public webrtc::DesktopCapturer::Callback {
53 public: 55 public:
54 Core(scoped_refptr<base::SequencedTaskRunner> task_runner, 56 Core(scoped_refptr<base::SequencedTaskRunner> task_runner,
55 scoped_ptr<webrtc::DesktopCapturer> capturer, 57 scoped_ptr<webrtc::DesktopCapturer> capturer,
56 DesktopMediaID::Type type); 58 DesktopMediaID::Type type);
57 59
60 Core(scoped_ptr<base::Thread> thread,
61 scoped_ptr<webrtc::DesktopCapturer> capturer,
62 DesktopMediaID::Type type);
63
58 // Implementation of VideoCaptureDevice methods. 64 // Implementation of VideoCaptureDevice methods.
59 void AllocateAndStart(const media::VideoCaptureParams& params, 65 void AllocateAndStart(const media::VideoCaptureParams& params,
60 scoped_ptr<Client> client); 66 scoped_ptr<Client> client);
61 void StopAndDeAllocate(); 67 void StopAndDeAllocate();
62 68
63 void SetNotificationWindowId(gfx::NativeViewId window_id); 69 void SetNotificationWindowId(gfx::NativeViewId window_id);
64 70
65 private: 71 private:
66 friend class base::RefCountedThreadSafe<Core>; 72 friend class base::RefCountedThreadSafe<Core>;
67 virtual ~Core(); 73 virtual ~Core();
(...skipping 18 matching lines...) Expand all
86 void OnCaptureTimer(); 92 void OnCaptureTimer();
87 93
88 // Captures a frame and schedules timer for the next one. 94 // Captures a frame and schedules timer for the next one.
89 void CaptureFrameAndScheduleNext(); 95 void CaptureFrameAndScheduleNext();
90 96
91 // Captures a single frame. 97 // Captures a single frame.
92 void DoCapture(); 98 void DoCapture();
93 99
94 void DoSetNotificationWindowId(gfx::NativeViewId window_id); 100 void DoSetNotificationWindowId(gfx::NativeViewId window_id);
95 101
102 // The thread on which the capturer is running.
103 scoped_ptr<base::Thread> thread_;
104
96 // Task runner used for capturing operations. 105 // Task runner used for capturing operations.
97 scoped_refptr<base::SequencedTaskRunner> task_runner_; 106 scoped_refptr<base::SequencedTaskRunner> task_runner_;
98 107
99 // The underlying DesktopCapturer instance used to capture frames. 108 // The underlying DesktopCapturer instance used to capture frames.
100 scoped_ptr<webrtc::DesktopCapturer> desktop_capturer_; 109 scoped_ptr<webrtc::DesktopCapturer> desktop_capturer_;
101 110
102 // The device client which proxies device events to the controller. Accessed 111 // The device client which proxies device events to the controller. Accessed
103 // on the task_runner_ thread. 112 // on the task_runner_ thread.
104 scoped_ptr<Client> client_; 113 scoped_ptr<Client> client_;
105 114
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 scoped_refptr<base::SequencedTaskRunner> task_runner, 147 scoped_refptr<base::SequencedTaskRunner> task_runner,
139 scoped_ptr<webrtc::DesktopCapturer> capturer, 148 scoped_ptr<webrtc::DesktopCapturer> capturer,
140 DesktopMediaID::Type type) 149 DesktopMediaID::Type type)
141 : task_runner_(task_runner), 150 : task_runner_(task_runner),
142 desktop_capturer_(capturer.Pass()), 151 desktop_capturer_(capturer.Pass()),
143 capture_task_posted_(false), 152 capture_task_posted_(false),
144 capture_in_progress_(false), 153 capture_in_progress_(false),
145 capturer_type_(type) { 154 capturer_type_(type) {
146 } 155 }
147 156
157 DesktopCaptureDevice::Core::Core(scoped_ptr<base::Thread> thread,
Sergey Ulanov 2014/05/05 20:10:06 Same as with DesktopCaptureDevice, better to avoid
158 scoped_ptr<webrtc::DesktopCapturer> capturer,
159 DesktopMediaID::Type type)
160 : thread_(thread.Pass()),
161 task_runner_(thread_->message_loop_proxy()),
162 desktop_capturer_(capturer.Pass()),
163 capture_task_posted_(false),
164 capture_in_progress_(false),
165 capturer_type_(type) {
166 }
167
148 DesktopCaptureDevice::Core::~Core() { 168 DesktopCaptureDevice::Core::~Core() {
149 } 169 }
150 170
151 void DesktopCaptureDevice::Core::AllocateAndStart( 171 void DesktopCaptureDevice::Core::AllocateAndStart(
152 const media::VideoCaptureParams& params, 172 const media::VideoCaptureParams& params,
153 scoped_ptr<Client> client) { 173 scoped_ptr<Client> client) {
154 DCHECK_GT(params.requested_format.frame_size.GetArea(), 0); 174 DCHECK_GT(params.requested_format.frame_size.GetArea(), 0);
155 DCHECK_GT(params.requested_format.frame_rate, 0); 175 DCHECK_GT(params.requested_format.frame_rate, 0);
156 176
157 task_runner_->PostTask( 177 task_runner_->PostTask(
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 411 DCHECK(task_runner_->RunsTasksOnCurrentThread());
392 DCHECK(window_id); 412 DCHECK(window_id);
393 desktop_capturer_->SetExcludedWindow(window_id); 413 desktop_capturer_->SetExcludedWindow(window_id);
394 } 414 }
395 415
396 // static 416 // static
397 scoped_ptr<media::VideoCaptureDevice> DesktopCaptureDevice::Create( 417 scoped_ptr<media::VideoCaptureDevice> DesktopCaptureDevice::Create(
398 const DesktopMediaID& source) { 418 const DesktopMediaID& source) {
399 scoped_refptr<base::SequencedWorkerPool> blocking_pool = 419 scoped_refptr<base::SequencedWorkerPool> blocking_pool =
400 BrowserThread::GetBlockingPool(); 420 BrowserThread::GetBlockingPool();
401 scoped_refptr<base::SequencedTaskRunner> task_runner = 421 scoped_refptr<base::SequencedTaskRunner> task_runner =
Sergey Ulanov 2014/05/05 20:10:06 There is no point creating task runner if it's not
402 blocking_pool->GetSequencedTaskRunner( 422 blocking_pool->GetSequencedTaskRunner(
403 blocking_pool->GetSequenceToken()); 423 blocking_pool->GetSequenceToken());
424 scoped_ptr<base::Thread> ui_thread;
404 425
405 webrtc::DesktopCaptureOptions options = 426 webrtc::DesktopCaptureOptions options =
406 webrtc::DesktopCaptureOptions::CreateDefault(); 427 webrtc::DesktopCaptureOptions::CreateDefault();
407 // Leave desktop effects enabled during WebRTC captures. 428 // Leave desktop effects enabled during WebRTC captures.
408 options.set_disable_effects(false); 429 options.set_disable_effects(false);
409 430
410 scoped_ptr<webrtc::DesktopCapturer> capturer; 431 scoped_ptr<webrtc::DesktopCapturer> capturer;
411 432
412 switch (source.type) { 433 switch (source.type) {
413 case DesktopMediaID::TYPE_SCREEN: { 434 case DesktopMediaID::TYPE_SCREEN: {
414 scoped_ptr<webrtc::ScreenCapturer> screen_capturer; 435 scoped_ptr<webrtc::ScreenCapturer> screen_capturer;
436
437 #if defined(OS_WIN)
438 bool magnification_allowed = base::FieldTrialList::FindFullName(
Sergey Ulanov 2014/05/05 20:10:06 indent 2 spaces.
439 "ScreenCaptureUseMagnification") == "Enabled";
440
441 if (magnification_allowed) {
442 // The magnification capturer requires running on a dedicated UI thread.
443 ui_thread.reset(new base::Thread("screenCaptureUIThread"));
444 base::Thread::Options thread_options(base::MessageLoop::TYPE_UI, 0);
445 ui_thread->StartWithOptions(thread_options);
446 task_runner.reset();
447
448 options.set_allow_use_magnification_api(true);
449 }
450 #endif
451
415 screen_capturer.reset(webrtc::ScreenCapturer::Create(options)); 452 screen_capturer.reset(webrtc::ScreenCapturer::Create(options));
416 if (screen_capturer && screen_capturer->SelectScreen(source.id)) { 453 if (screen_capturer && screen_capturer->SelectScreen(source.id)) {
417 capturer.reset(new webrtc::DesktopAndCursorComposer( 454 capturer.reset(new webrtc::DesktopAndCursorComposer(
418 screen_capturer.release(), 455 screen_capturer.release(),
419 webrtc::MouseCursorMonitor::CreateForScreen(options, source.id))); 456 webrtc::MouseCursorMonitor::CreateForScreen(options, source.id)));
420 IncrementDesktopCaptureCounter(SCREEN_CAPTURER_CREATED); 457 IncrementDesktopCaptureCounter(SCREEN_CAPTURER_CREATED);
421 } 458 }
422 break; 459 break;
423 } 460 }
424 461
(...skipping 10 matching lines...) Expand all
435 break; 472 break;
436 } 473 }
437 474
438 default: { 475 default: {
439 NOTREACHED(); 476 NOTREACHED();
440 } 477 }
441 } 478 }
442 479
443 scoped_ptr<media::VideoCaptureDevice> result; 480 scoped_ptr<media::VideoCaptureDevice> result;
444 if (capturer) { 481 if (capturer) {
445 result.reset( 482 if (task_runner.get()) {
Sergey Ulanov 2014/05/05 20:10:06 if (!ui_thread)
446 new DesktopCaptureDevice(task_runner, capturer.Pass(), source.type)); 483 result.reset(
484 new DesktopCaptureDevice(task_runner, capturer.Pass(), source.type));
485 } else {
486 result.reset(new DesktopCaptureDevice(
487 ui_thread.Pass(), capturer.Pass(), source.type));
488 }
447 } 489 }
448 490
449 return result.Pass(); 491 return result.Pass();
450 } 492 }
451 493
452 DesktopCaptureDevice::DesktopCaptureDevice( 494 DesktopCaptureDevice::DesktopCaptureDevice(
453 scoped_refptr<base::SequencedTaskRunner> task_runner, 495 scoped_refptr<base::SequencedTaskRunner> task_runner,
454 scoped_ptr<webrtc::DesktopCapturer> capturer, 496 scoped_ptr<webrtc::DesktopCapturer> capturer,
455 DesktopMediaID::Type type) 497 DesktopMediaID::Type type)
456 : core_(new Core(task_runner, capturer.Pass(), type)) { 498 : core_(new Core(task_runner, capturer.Pass(), type)) {
457 } 499 }
458 500
501 DesktopCaptureDevice::DesktopCaptureDevice(
502 scoped_ptr<base::Thread> thread,
503 scoped_ptr<webrtc::DesktopCapturer> capturer,
504 DesktopMediaID::Type type)
505 : core_(new Core(thread.Pass(), capturer.Pass(), type)) {
506 }
507
459 DesktopCaptureDevice::~DesktopCaptureDevice() { 508 DesktopCaptureDevice::~DesktopCaptureDevice() {
460 StopAndDeAllocate(); 509 StopAndDeAllocate();
461 } 510 }
462 511
463 void DesktopCaptureDevice::AllocateAndStart( 512 void DesktopCaptureDevice::AllocateAndStart(
464 const media::VideoCaptureParams& params, 513 const media::VideoCaptureParams& params,
465 scoped_ptr<Client> client) { 514 scoped_ptr<Client> client) {
466 core_->AllocateAndStart(params, client.Pass()); 515 core_->AllocateAndStart(params, client.Pass());
467 } 516 }
468 517
469 void DesktopCaptureDevice::StopAndDeAllocate() { 518 void DesktopCaptureDevice::StopAndDeAllocate() {
470 core_->StopAndDeAllocate(); 519 core_->StopAndDeAllocate();
471 } 520 }
472 521
473 void DesktopCaptureDevice::SetNotificationWindowId( 522 void DesktopCaptureDevice::SetNotificationWindowId(
474 gfx::NativeViewId window_id) { 523 gfx::NativeViewId window_id) {
475 core_->SetNotificationWindowId(window_id); 524 core_->SetNotificationWindowId(window_id);
476 } 525 }
477 526
478 } // namespace content 527 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698