From 9d075e8e4d9751eee153c0f00fb541a4217f116b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 3 Mar 2014 11:26:53 +0000 Subject: [PATCH] Try to prevent OS X from sleeping during DCP encode. --- ChangeLog | 4 ++++ src/lib/cross.cc | 17 ++++++++++++++++- src/lib/cross.h | 27 ++++++++++++++++++++++++++- src/lib/encoder.cc | 2 +- src/lib/encoder.h | 2 ++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b7fd5ac4..2712fc265 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-03-03 Carl Hetherington + + * Try to prevent OS X from sleeping during DCP encode. + 2014-02-26 Carl Hetherington * Version 1.64.17 released. diff --git a/src/lib/cross.cc b/src/lib/cross.cc index 9f7a76124..786f4b997 100644 --- a/src/lib/cross.cc +++ b/src/lib/cross.cc @@ -34,6 +34,7 @@ #ifdef DCPOMATIC_OSX #include #include +#include #endif #ifdef DCPOMATIC_POSIX #include @@ -300,9 +301,23 @@ dcpomatic_fseek (FILE* stream, int64_t offset, int whence) } void -kick () +Waker::nudge () { #ifdef DCPOMATIC_WINDOWS SetThreadExecutionState (ES_CONTINUOUS); #endif } + +Waker::Waker () +{ +#ifdef DCPOMATIC_OSX + IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR ("Encoding DCP"), &_assertion_id); +#endif +} + +Waker::~Waker () +{ +#ifdef DCPOMATIC_OSX + IOPMAssertionRelease (_assertion_id); +#endif +} diff --git a/src/lib/cross.h b/src/lib/cross.h index 822b36631..1c7754503 100644 --- a/src/lib/cross.h +++ b/src/lib/cross.h @@ -17,7 +17,13 @@ */ +#ifndef DCPOMATIC_CROSS_H +#define DCPOMATIC_CROSS_H + #include +#ifdef DCPOMATIC_OSX +#include +#endif #ifdef DCPOMATIC_WINDOWS #define WEXITSTATUS(w) (w) @@ -35,4 +41,23 @@ extern boost::filesystem::path app_contents (); #endif extern FILE * fopen_boost (boost::filesystem::path, std::string); extern int dcpomatic_fseek (FILE *, int64_t, int); -void kick (); + +/** A class which tries to keep the computer awake on various operating systems. + * Create a Waker to prevent sleep, and call ::nudge every so often (every minute or so). + * Destroy the Waker to allow sleep again. + */ +class Waker +{ +public: + Waker (); + ~Waker (); + + void nudge (); + +private: +#ifdef DCPOMATIC_OSX + IOPMAssertionID _assertion_id; +#endif +}; + +#endif diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 92b4763be..73af11c55 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -180,7 +180,7 @@ Encoder::frame_done () void Encoder::process_video (shared_ptr image, Eyes eyes, ColourConversion conversion, bool same) { - kick (); + _waker.nudge (); boost::mutex::scoped_lock lock (_mutex); diff --git a/src/lib/encoder.h b/src/lib/encoder.h index 079174f89..e0ee2d414 100644 --- a/src/lib/encoder.h +++ b/src/lib/encoder.h @@ -37,6 +37,7 @@ extern "C" { } #include "util.h" #include "config.h" +#include "cross.h" class Image; class AudioBuffers; @@ -113,6 +114,7 @@ private: boost::condition _condition; boost::shared_ptr _writer; + Waker _waker; }; #endif -- 2.30.2