OSDN Git Service

Prevent system from going into Standby or Hibernation while an encode is running.
authorlordmulder <mulder2@gmx.de>
Sun, 10 Nov 2013 22:20:24 +0000 (23:20 +0100)
committerlordmulder <mulder2@gmx.de>
Sun, 10 Nov 2013 22:20:24 +0000 (23:20 +0100)
src/global.cpp
src/global.h
src/thread_encode.cpp
src/version.h

index 8aebb58..e2d5ae0 100644 (file)
@@ -1710,6 +1710,23 @@ bool x264_shutdown_computer(const QString &message, const unsigned long timeout,
 }
 
 /*
+ * Inform the system that it is in use, thereby preventing the system from entering sleep
+ */
+bool x264_set_thread_execution_state(const bool systemRequired)
+{
+       EXECUTION_STATE state = NULL;
+       if(systemRequired)
+       {
+               state = SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
+       }
+       else
+       {
+               state = SetThreadExecutionState(ES_CONTINUOUS);
+       }
+       return (state != NULL);
+}
+
+/*
  * Check for debugger (detect routine)
  */
 static __forceinline bool x264_check_for_debugger(void)
index 6c477e8..36bd497 100644 (file)
@@ -121,6 +121,7 @@ bool x264_play_sound(const unsigned short uiSoundIdx, const bool bAsync, const w
 bool x264_portable(void);
 unsigned int x264_process_id(void);
 QString x264_query_reg_string(const bool bUser, const QString &path, const QString &name);
+bool x264_set_thread_execution_state(const bool systemRequired);
 bool x264_shutdown_computer(const QString &message, const unsigned long timeout, const bool forceShutdown);
 void x264_sleep(const unsigned int delay);
 bool x264_suspendProcess(const QProcess *proc, const bool suspend);
index cf54a6a..6d64a6f 100644 (file)
 QMutex EncodeThread::m_mutex_startProcess;
 
 /*
+ * RAII execution state handler
+ */
+static class ExecutionStateHandler
+{
+public:
+       ExecutionStateHandler(void)
+       {
+               x264_set_thread_execution_state(true);
+       }
+       ~ExecutionStateHandler(void)
+       {
+               x264_set_thread_execution_state(false);
+       }
+private:
+       //Disable copy constructor and assignment
+       ExecutionStateHandler(const ExecutionStateHandler &other) {}
+       ExecutionStateHandler &operator=(const ExecutionStateHandler &) {}
+
+       //Prevent object allocation on the heap
+       void *operator new(size_t);   void *operator new[](size_t);
+       void operator delete(void *); void operator delete[](void*);
+};
+
+/*
  * Macros
  */
 #define CHECK_STATUS(ABORT_FLAG, OK_FLAG) do \
@@ -169,6 +193,7 @@ void EncodeThread::checkedRun(void)
        {
                try
                {
+                       ExecutionStateHandler executionStateHandler;
                        encode();
                }
                catch(char *msg)
index 34c2646..25d8c58 100644 (file)
@@ -26,7 +26,7 @@
 #define VER_X264_MAJOR 2
 #define VER_X264_MINOR 2
 #define VER_X264_PATCH 5
-#define VER_X264_BUILD 623
+#define VER_X264_BUILD 625
 
 #define VER_X264_MINIMUM_REV 2363
 #define VER_X264_CURRENT_API 140