Skip to content

Commit

Permalink
Assert both display and system keep-alive on each capture.
Browse files Browse the repository at this point in the history
This ensures that while the screen is actively being captured,
the host system will not suspend, e.g. due to inactivity.

BUG=129912


Review URL: https://chromiumcodereview.appspot.com/12211101

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181864 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
wez@chromium.org committed Feb 12, 2013
1 parent 0b59118 commit ab09a0e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions media/video/capture/screen/screen_capturer_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class ScreenCapturerWin : public ScreenCapturer {
base::ScopedNativeLibrary dwmapi_library_;
DwmEnableCompositionFunc composition_func_;

// Used to suppress duplicate logging of SetThreadExecutionState errors.
bool set_thread_execution_state_failed_;

DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWin);
};

Expand Down Expand Up @@ -203,7 +206,8 @@ void ScreenCaptureFrameWin::AllocateBitmap(HDC desktop_dc,
ScreenCapturerWin::ScreenCapturerWin()
: delegate_(NULL),
desktop_dc_rect_(SkIRect::MakeEmpty()),
composition_func_(NULL) {
composition_func_(NULL),
set_thread_execution_state_failed_(false) {
}

ScreenCapturerWin::~ScreenCapturerWin() {
Expand All @@ -216,8 +220,14 @@ void ScreenCapturerWin::InvalidateRegion(const SkRegion& invalid_region) {
void ScreenCapturerWin::CaptureFrame() {
base::Time capture_start_time = base::Time::Now();

// Force the system to power-up display hardware, if it has been suspended.
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
// Request that the system not power-down the system, or the display hardware.
if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) {
if (!set_thread_execution_state_failed_) {
set_thread_execution_state_failed_ = true;
LOG_GETLASTERROR(WARNING)
<< "Failed to make system & display power assertion";
}
}

// Make sure the GDI capture resources are up-to-date.
PrepareCaptureResources();
Expand Down

0 comments on commit ab09a0e

Please sign in to comment.