Try to prevent OS X from sleeping during DCP encode.
[dcpomatic.git] / src / lib / cross.cc
index 57b3f93b24d9dde847ff6fa123539526d6d259bb..786f4b99767e1a8db5b4b1fc1f01695da547a919 100644 (file)
@@ -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>
@@ -298,3 +299,25 @@ dcpomatic_fseek (FILE* stream, int64_t offset, int whence)
        return fseek (stream, offset, whence);
 #endif 
 }
+
+void
+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 
+}