summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-03-03 11:26:53 +0000
committerCarl Hetherington <cth@carlh.net>2014-03-03 11:26:53 +0000
commit9d075e8e4d9751eee153c0f00fb541a4217f116b (patch)
tree73e17ebaf60f8eafe86e0d1f627185ace63411d8 /src/lib
parent2ca921e378cd32ca44c389008a60dd08dd58f6e0 (diff)
Try to prevent OS X from sleeping during DCP encode.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cross.cc17
-rw-r--r--src/lib/cross.h27
-rw-r--r--src/lib/encoder.cc2
-rw-r--r--src/lib/encoder.h2
4 files changed, 45 insertions, 3 deletions
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 <sys/sysctl.h>
#include <mach-o/dyld.h>
+#include <IOKit/pwr_mgt/IOPMLib.h>
#endif
#ifdef DCPOMATIC_POSIX
#include <sys/types.h>
@@ -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 <boost/filesystem.hpp>
+#ifdef DCPOMATIC_OSX
+#include <IOKit/pwr_mgt/IOPMLib.h>
+#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<PlayerImage> 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> _writer;
+ Waker _waker;
};
#endif