OLD | NEW |
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 "media/video/capture/screen/screen_capture_device.h" | 5 #include "media/video/capture/screen/screen_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/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "media/video/capture/screen/mouse_cursor_shape.h" | |
13 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
14 #include "third_party/skia/include/core/SkDevice.h" | 13 #include "third_party/skia/include/core/SkDevice.h" |
15 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 15 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_shape.h" |
| 16 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 | 19 |
19 namespace { | 20 namespace { |
20 const int kBytesPerPixel = 4; | 21 const int kBytesPerPixel = 4; |
21 } // namespace | 22 } // namespace |
22 | 23 |
23 class ScreenCaptureDevice::Core | 24 class ScreenCaptureDevice::Core |
24 : public base::RefCountedThreadSafe<Core>, | 25 : public base::RefCountedThreadSafe<Core>, |
25 public webrtc::DesktopCapturer::Callback { | 26 public webrtc::DesktopCapturer::Callback { |
26 public: | 27 public: |
27 explicit Core(scoped_refptr<base::SequencedTaskRunner> task_runner); | 28 explicit Core(scoped_refptr<base::SequencedTaskRunner> task_runner); |
28 | 29 |
29 // Helper used in tests to supply a fake capturer. | 30 // Helper used in tests to supply a fake capturer. |
30 void SetScreenCapturerForTest(scoped_ptr<ScreenCapturer> capturer) { | 31 void SetScreenCapturerForTest(scoped_ptr<webrtc::ScreenCapturer> capturer) { |
31 screen_capturer_ = capturer.Pass(); | 32 screen_capturer_ = capturer.Pass(); |
32 } | 33 } |
33 | 34 |
34 // Implementation of VideoCaptureDevice methods. | 35 // Implementation of VideoCaptureDevice methods. |
35 void Allocate(int width, int height, | 36 void Allocate(int width, int height, |
36 int frame_rate, | 37 int frame_rate, |
37 EventHandler* event_handler); | 38 EventHandler* event_handler); |
38 void Start(); | 39 void Start(); |
39 void Stop(); | 40 void Stop(); |
40 void DeAllocate(); | 41 void DeAllocate(); |
(...skipping 29 matching lines...) Expand all Loading... |
70 // |event_handler_lock_| must be locked whenever |event_handler_| is used. | 71 // |event_handler_lock_| must be locked whenever |event_handler_| is used. |
71 // It's necessary because DeAllocate() needs to reset it on the calling thread | 72 // It's necessary because DeAllocate() needs to reset it on the calling thread |
72 // to ensure that the event handler is not called once DeAllocate() returns. | 73 // to ensure that the event handler is not called once DeAllocate() returns. |
73 base::Lock event_handler_lock_; | 74 base::Lock event_handler_lock_; |
74 EventHandler* event_handler_; | 75 EventHandler* event_handler_; |
75 | 76 |
76 // Frame rate specified to Allocate(). | 77 // Frame rate specified to Allocate(). |
77 int frame_rate_; | 78 int frame_rate_; |
78 | 79 |
79 // The underlying ScreenCapturer instance used to capture frames. | 80 // The underlying ScreenCapturer instance used to capture frames. |
80 scoped_ptr<ScreenCapturer> screen_capturer_; | 81 scoped_ptr<webrtc::ScreenCapturer> screen_capturer_; |
81 | 82 |
82 // After Allocate() is called we need to call OnFrameInfo() method of the | 83 // After Allocate() is called we need to call OnFrameInfo() method of the |
83 // |event_handler_| to specify the size of the frames this capturer will | 84 // |event_handler_| to specify the size of the frames this capturer will |
84 // produce. In order to get screen size from |screen_capturer_| we need to | 85 // produce. In order to get screen size from |screen_capturer_| we need to |
85 // capture at least one frame. Once screen size is known it's stored in | 86 // capture at least one frame. Once screen size is known it's stored in |
86 // |frame_size_|. | 87 // |frame_size_|. |
87 bool waiting_for_frame_size_; | 88 bool waiting_for_frame_size_; |
88 webrtc::DesktopSize frame_size_; | 89 webrtc::DesktopSize frame_size_; |
89 SkBitmap resized_bitmap_; | 90 SkBitmap resized_bitmap_; |
90 | 91 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 base::Time::Now(), 0, false, false); | 267 base::Time::Now(), 0, false, false); |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 void ScreenCaptureDevice::Core::DoAllocate(int frame_rate) { | 271 void ScreenCaptureDevice::Core::DoAllocate(int frame_rate) { |
271 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 272 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
272 | 273 |
273 frame_rate_ = frame_rate; | 274 frame_rate_ = frame_rate; |
274 | 275 |
275 // Create and start frame capturer. | 276 // Create and start frame capturer. |
| 277 if (!screen_capturer_) { |
276 #if defined(OS_CHROMEOS) && !defined(ARCH_CPU_ARMEL) | 278 #if defined(OS_CHROMEOS) && !defined(ARCH_CPU_ARMEL) |
277 // ScreenCapturerX11 polls by default, due to poor driver support for DAMAGE. | 279 // ScreenCapturerX11 polls by default, due to poor driver support for |
278 // ChromeOS' drivers [can be patched to] support DAMAGE properly, so use it. | 280 // DAMAGE. ChromeOS' drivers [can be patched to] support DAMAGE properly, so |
279 // However ARM driver seems to not support this properly, so disable it for | 281 // use it. However ARM driver seems to not support this properly, so disable |
280 // ARM. See http://crbug.com/230105. | 282 // it for ARM. See http://crbug.com/230105. |
281 if (!screen_capturer_) | 283 screen_capturer_.reset(webrtc::ScreenCapturer::CreateWithXDamage(true)); |
282 screen_capturer_ = ScreenCapturer::CreateWithXDamage(true); | |
283 #elif defined(OS_WIN) | 284 #elif defined(OS_WIN) |
284 // ScreenCapturerWin disables Aero by default. We don't want it disabled for | 285 // ScreenCapturerWin disables Aero by default. We don't want it disabled for |
285 // WebRTC screen capture, though. | 286 // WebRTC screen capture, though. |
286 if (!screen_capturer_) | 287 screen_capturer_.reset( |
287 screen_capturer_ = ScreenCapturer::CreateWithDisableAero(false); | 288 webrtc::ScreenCapturer::CreateWithDisableAero(false)); |
288 #else | 289 #else |
289 if (!screen_capturer_) | 290 screen_capturer_.reset(webrtc::ScreenCapturer::Create()); |
290 screen_capturer_ = ScreenCapturer::Create(); | |
291 #endif | 291 #endif |
| 292 } |
| 293 |
292 if (screen_capturer_) | 294 if (screen_capturer_) |
293 screen_capturer_->Start(this); | 295 screen_capturer_->Start(this); |
294 | 296 |
295 // Capture first frame, so that we can call OnFrameInfo() callback. | 297 // Capture first frame, so that we can call OnFrameInfo() callback. |
296 waiting_for_frame_size_ = true; | 298 waiting_for_frame_size_ = true; |
297 DoCapture(); | 299 DoCapture(); |
298 } | 300 } |
299 | 301 |
300 void ScreenCaptureDevice::Core::DoStart() { | 302 void ScreenCaptureDevice::Core::DoStart() { |
301 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 303 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 scoped_refptr<base::SequencedTaskRunner> task_runner) | 357 scoped_refptr<base::SequencedTaskRunner> task_runner) |
356 : core_(new Core(task_runner)) { | 358 : core_(new Core(task_runner)) { |
357 name_.device_name = "Screen"; | 359 name_.device_name = "Screen"; |
358 } | 360 } |
359 | 361 |
360 ScreenCaptureDevice::~ScreenCaptureDevice() { | 362 ScreenCaptureDevice::~ScreenCaptureDevice() { |
361 DeAllocate(); | 363 DeAllocate(); |
362 } | 364 } |
363 | 365 |
364 void ScreenCaptureDevice::SetScreenCapturerForTest( | 366 void ScreenCaptureDevice::SetScreenCapturerForTest( |
365 scoped_ptr<ScreenCapturer> capturer) { | 367 scoped_ptr<webrtc::ScreenCapturer> capturer) { |
366 core_->SetScreenCapturerForTest(capturer.Pass()); | 368 core_->SetScreenCapturerForTest(capturer.Pass()); |
367 } | 369 } |
368 | 370 |
369 void ScreenCaptureDevice::Allocate(int width, int height, | 371 void ScreenCaptureDevice::Allocate(int width, int height, |
370 int frame_rate, | 372 int frame_rate, |
371 EventHandler* event_handler) { | 373 EventHandler* event_handler) { |
372 core_->Allocate(width, height, frame_rate, event_handler); | 374 core_->Allocate(width, height, frame_rate, event_handler); |
373 } | 375 } |
374 | 376 |
375 void ScreenCaptureDevice::Start() { | 377 void ScreenCaptureDevice::Start() { |
376 core_->Start(); | 378 core_->Start(); |
377 } | 379 } |
378 | 380 |
379 void ScreenCaptureDevice::Stop() { | 381 void ScreenCaptureDevice::Stop() { |
380 core_->Stop(); | 382 core_->Stop(); |
381 } | 383 } |
382 | 384 |
383 void ScreenCaptureDevice::DeAllocate() { | 385 void ScreenCaptureDevice::DeAllocate() { |
384 core_->DeAllocate(); | 386 core_->DeAllocate(); |
385 } | 387 } |
386 | 388 |
387 const VideoCaptureDevice::Name& ScreenCaptureDevice::device_name() { | 389 const VideoCaptureDevice::Name& ScreenCaptureDevice::device_name() { |
388 return name_; | 390 return name_; |
389 } | 391 } |
390 | 392 |
391 } // namespace media | 393 } // namespace media |
OLD | NEW |