Try to prevent OS X from sleeping during DCP encode.
authorCarl Hetherington <cth@carlh.net>
Mon, 3 Mar 2014 11:26:53 +0000 (11:26 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 3 Mar 2014 11:26:53 +0000 (11:26 +0000)
ChangeLog
src/lib/cross.cc
src/lib/cross.h
src/lib/encoder.cc
src/lib/encoder.h

index 1b7fd5ac46dd77a73395e580587f3983502962db..2712fc265839c1d3148761d060dd97df49ebf02d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-03-03  Carl Hetherington  <cth@carlh.net>
+
+       * Try to prevent OS X from sleeping during DCP encode.
+
 2014-02-26  Carl Hetherington  <cth@carlh.net>
 
        * Version 1.64.17 released.
 2014-02-26  Carl Hetherington  <cth@carlh.net>
 
        * Version 1.64.17 released.
index 9f7a761248aef9f045ba85a14e05356a066b5a4b..786f4b99767e1a8db5b4b1fc1f01695da547a919 100644 (file)
@@ -34,6 +34,7 @@
 #ifdef DCPOMATIC_OSX
 #include <sys/sysctl.h>
 #include <mach-o/dyld.h>
 #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>
 #endif
 #ifdef DCPOMATIC_POSIX
 #include <sys/types.h>
@@ -300,9 +301,23 @@ dcpomatic_fseek (FILE* stream, int64_t offset, int whence)
 }
 
 void
 }
 
 void
-kick ()
+Waker::nudge ()
 {
 #ifdef DCPOMATIC_WINDOWS
        SetThreadExecutionState (ES_CONTINUOUS);
 #endif 
 }
 {
 #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 
+}
index 822b36631d604343a94c5b5a03f48b75d8aa31cf..1c77545033fdb0c7e2ee17db2a297b9e8100659f 100644 (file)
 
 */
 
 
 */
 
+#ifndef DCPOMATIC_CROSS_H
+#define DCPOMATIC_CROSS_H
+
 #include <boost/filesystem.hpp>
 #include <boost/filesystem.hpp>
+#ifdef DCPOMATIC_OSX
+#include <IOKit/pwr_mgt/IOPMLib.h>
+#endif
 
 #ifdef DCPOMATIC_WINDOWS
 #define WEXITSTATUS(w) (w)
 
 #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);
 #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
index 92b4763be5768f5ca04c5f40621191d6ef52cb4b..73af11c55d2889412b232f80656cf2a72aa4e6ed 100644 (file)
@@ -180,7 +180,7 @@ Encoder::frame_done ()
 void
 Encoder::process_video (shared_ptr<PlayerImage> image, Eyes eyes, ColourConversion conversion, bool same)
 {
 void
 Encoder::process_video (shared_ptr<PlayerImage> image, Eyes eyes, ColourConversion conversion, bool same)
 {
-       kick ();
+       _waker.nudge ();
        
        boost::mutex::scoped_lock lock (_mutex);
 
        
        boost::mutex::scoped_lock lock (_mutex);
 
index 079174f89c96be258109ea339d97076261b3bc7e..e0ee2d41480f3fbf7b413cf0e974a96a4967c735 100644 (file)
@@ -37,6 +37,7 @@ extern "C" {
 }
 #include "util.h"
 #include "config.h"
 }
 #include "util.h"
 #include "config.h"
+#include "cross.h"
 
 class Image;
 class AudioBuffers;
 
 class Image;
 class AudioBuffers;
@@ -113,6 +114,7 @@ private:
        boost::condition _condition;
 
        boost::shared_ptr<Writer> _writer;
        boost::condition _condition;
 
        boost::shared_ptr<Writer> _writer;
+       Waker _waker;
 };
 
 #endif
 };
 
 #endif