Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Prevent the screen from sleeping when the desktop is being captured.
Browse files Browse the repository at this point in the history
BUG=405784

Review URL: https://codereview.chromium.org/502103003

Cr-Commit-Position: refs/heads/master@{#291908}
  • Loading branch information
jiayl authored and Commit bot committed Aug 26, 2014
1 parent c9f0746 commit aea4a57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions content/browser/media/capture/desktop_capture_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "content/browser/media/capture/desktop_capture_device_uma_types.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/desktop_media_id.h"
#include "content/public/browser/power_save_blocker.h"
#include "media/base/video_util.h"
#include "third_party/libyuv/include/libyuv/scale_argb.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_and_cursor_composer.h"
Expand Down Expand Up @@ -124,6 +125,10 @@ class DesktopCaptureDevice::Core : public webrtc::DesktopCapturer::Callback {

scoped_ptr<webrtc::BasicDesktopFrame> black_frame_;

// TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the
// screen from sleeping for the drive-by web.
scoped_ptr<PowerSaveBlocker> power_save_blocker_;

DISALLOW_COPY_AND_ASSIGN(Core);
};

Expand Down Expand Up @@ -164,6 +169,10 @@ void DesktopCaptureDevice::Core::AllocateAndStart(
// This capturer always outputs ARGB, non-interlaced.
capture_format_.pixel_format = media::PIXEL_FORMAT_ARGB;

power_save_blocker_.reset(PowerSaveBlocker::Create(
PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
"DesktopCaptureDevice is running").release());

desktop_capturer_->Start(this);

CaptureFrameAndScheduleNext();
Expand Down
10 changes: 10 additions & 0 deletions content/browser/media/capture/desktop_capture_device_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "content/browser/media/capture/desktop_capture_device_uma_types.h"
#include "content/common/gpu/client/gl_helper.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/power_save_blocker.h"
#include "media/base/video_util.h"
#include "media/video/capture/video_capture_types.h"
#include "skia/ext/image_operations.h"
Expand Down Expand Up @@ -174,6 +175,10 @@ class DesktopVideoCaptureMachine
gfx::Point cursor_hot_point_;
SkBitmap scaled_cursor_bitmap_;

// TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the
// screen from sleeping for the drive-by web.
scoped_ptr<PowerSaveBlocker> power_save_blocker_;

DISALLOW_COPY_AND_ASSIGN(DesktopVideoCaptureMachine);
};

Expand Down Expand Up @@ -213,6 +218,10 @@ bool DesktopVideoCaptureMachine::Start(
if (desktop_window_->GetHost())
desktop_window_->GetHost()->compositor()->AddObserver(this);

power_save_blocker_.reset(PowerSaveBlocker::Create(
PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
"DesktopCaptureDevice is running").release());

// Starts timer.
timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(),
base::Bind(&DesktopVideoCaptureMachine::Capture, AsWeakPtr(),
Expand All @@ -224,6 +233,7 @@ bool DesktopVideoCaptureMachine::Start(

void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
power_save_blocker_.reset();

// Stop observing compositor and window events.
if (desktop_window_) {
Expand Down

0 comments on commit aea4a57

Please sign in to comment.