From aa2b7c6bb45743fc7c49066b837603780b38312b Mon Sep 17 00:00:00 2001 From: lordmulder Date: Wed, 6 Nov 2013 00:30:27 +0100 Subject: [PATCH] Some improvements to global functions header file. --- src/global.cpp | 60 +++++++-- src/global.h | 173 +++++++++++++++---------- src/thread_encode.cpp | 11 +- src/version.h | 6 +- x264_launcher.rc | Bin 6014 -> 6214 bytes x264_launcher_MSVC2013.vcxproj | 3 + x264_launcher_MSVC2013.vcxproj.filters | 5 + 7 files changed, 173 insertions(+), 85 deletions(-) diff --git a/src/global.cpp b/src/global.cpp index ce26a92..3091ee6 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -19,9 +19,14 @@ // http://www.gnu.org/licenses/gpl-2.0.txt /////////////////////////////////////////////////////////////////////////////// +//x264 includes #include "global.h" #include "targetver.h" + +//Version +#define ENABLE_X264_VERSION_INCLUDE #include "version.h" +#undef ENABLE_X264_VERSION_INCLUDE //Windows includes #define NOMINMAX @@ -100,6 +105,9 @@ static const struct unsigned int ver_build; const char* ver_date; const char* ver_time; + unsigned int ver_x264_minimum_rev; + unsigned int ver_x264_current_api; + unsigned int ver_x264_avs2yuv_ver; } g_x264_version = { @@ -108,7 +116,10 @@ g_x264_version = (VER_X264_PATCH), (VER_X264_BUILD), __DATE__, - __TIME__ + __TIME__, + (VER_X264_MINIMUM_REV), + (VER_X264_CURRENT_API), + (VER_X264_AVS2YUV_VER) }; //CLI Arguments @@ -128,6 +139,15 @@ static struct } g_x264_os_version; +//Wine detection +static struct +{ + bool bInitialized; + bool bIsWine; + QReadWriteLock lock; +} +g_x264_wine; + //Portable Mode static struct { @@ -667,6 +687,21 @@ const char *x264_version_arch(void) return g_x264_version_arch; } +unsigned int x264_version_x264_minimum_rev(void) +{ + return g_x264_version.ver_x264_minimum_rev; +} + +unsigned int x264_version_x264_current_api(void) +{ + return g_x264_version.ver_x264_current_api; +} + +unsigned int x264_version_x264_avs2yuv_ver(void) +{ + return g_x264_version.ver_x264_avs2yuv_ver; +} + /* * Get CLI arguments */ @@ -1090,22 +1125,31 @@ static bool x264_check_compatibility_mode(const char *exportName, const char *ex */ bool x264_detect_wine(void) { - static bool isWine = false; - static bool isWine_initialized = false; + QReadLocker readLock(&g_x264_wine.lock); - if(!isWine_initialized) + //Already initialized? + if(g_x264_wine.bInitialized) { + return g_x264_wine.bIsWine; + } + + readLock.unlock(); + QWriteLocker writeLock(&g_x264_wine.lock); + + if(!g_x264_wine.bInitialized) + { + g_x264_wine.bIsWine = false; QLibrary ntdll("ntdll.dll"); if(ntdll.load()) { - if(ntdll.resolve("wine_nt_to_unix_file_name") != NULL) isWine = true; - if(ntdll.resolve("wine_get_version") != NULL) isWine = true; + if(ntdll.resolve("wine_nt_to_unix_file_name") != NULL) g_x264_wine.bIsWine = true; + if(ntdll.resolve("wine_get_version") != NULL) g_x264_wine.bIsWine = true; ntdll.unload(); } - isWine_initialized = true; + g_x264_wine.bInitialized = true; } - return isWine; + return g_x264_wine.bIsWine; } /* diff --git a/src/global.h b/src/global.h index 3090bf6..f0786f0 100644 --- a/src/global.h +++ b/src/global.h @@ -21,49 +21,10 @@ #pragma once +#define _CRT_RAND_S #include -//Debug build -#if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG) - #define X264_DEBUG (1) -#else - #define X264_DEBUG (0) -#endif - -//Memory check -#if X264_DEBUG -#define X264_MEMORY_CHECK(FUNC, RETV, ...) \ -{ \ - SIZE_T _privateBytesBefore = x264_dbg_private_bytes(); \ - RETV = FUNC(__VA_ARGS__); \ - SIZE_T _privateBytesLeak = (x264_dbg_private_bytes() - _privateBytesBefore) / 1024; \ - if(_privateBytesLeak > 0) { \ - char _buffer[128]; \ - _snprintf_s(_buffer, 128, _TRUNCATE, "Memory leak: Lost %u KiloBytes of PrivateUsage memory.\n", _privateBytesLeak); \ - OutputDebugStringA("----------\n"); \ - OutputDebugStringA(_buffer); \ - OutputDebugStringA("----------\n"); \ - } \ -} -#else -#define X264_MEMORY_CHECK(FUNC, RETV, ...) \ -{ \ - RETV = __noop(__VA_ARGS__); \ -} -#endif - -//Helper macros -#define QWCHAR(STR) reinterpret_cast(STR.utf16()) -#define QUTF8(STR) ((STR).toUtf8().constData()) -#define WCHAR2QSTR(STR) (QString::fromUtf16(reinterpret_cast((STR)))) -#define X264_BOOL(X) ((X) ? "1" : "0") -#define X264_DELETE(PTR) if(PTR) { delete PTR; PTR = NULL; } -#define X264_DELETE_ARRAY(PTR) if(PTR) { delete [] PTR; PTR = NULL; } -#define _X264_MAKE_STRING_(X) #X -#define X264_MAKE_STRING(X) _X264_MAKE_STRING_(X) -#define X264_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" X264_MAKE_STRING(__LINE__) ") : warning: " TXT)) - -//Declarations +//Forward declarations class QString; class QStringList; class QDate; @@ -74,6 +35,10 @@ class LockedFile; class QProcess; enum QtMsgType; +/////////////////////////////////////////////////////////////////////////////// +// TYPE DEFINITIONS +/////////////////////////////////////////////////////////////////////////////// + //Types definitions typedef struct { @@ -129,37 +94,105 @@ extern const x264_os_version_t x264_winver_win70; extern const x264_os_version_t x264_winver_win80; extern const x264_os_version_t x264_winver_win81; -//Functions -void x264_message_handler(QtMsgType type, const char *msg); -unsigned int x264_version_major(void); -unsigned int x264_version_minor(void); -unsigned int x264_version_build(void); -const QDate &x264_version_date(void); -bool x264_portable(void); -const QString &x264_data_path(void); -bool x264_is_prerelease(void); -const char *x264_version_time(void); -const char *x264_version_compiler(void); -const char *x264_version_arch(void); -void x264_init_console(int argc, char* argv[]); -bool x264_init_qt(int argc, char* argv[]); -x264_cpu_t x264_detect_cpu_features(const QStringList &argv); -bool x264_shutdown_computer(const QString &message, const unsigned long timeout, const bool forceShutdown); -void x264_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL); -void x264_sleep(const unsigned int delay); +/////////////////////////////////////////////////////////////////////////////// +// GLOBAL FUNCTIONS +/////////////////////////////////////////////////////////////////////////////// + const QStringList &x264_arguments(void); -bool x264_suspendProcess(const QProcess *proc, const bool suspend); -size_t x264_dbg_private_bytes(void); -void x264_finalization(void); -QString x264_path2ansi(const QString &longPath); -bool x264_change_process_priority(const int priority); -bool x264_change_process_priority(const QProcess *proc, const int priority); -bool x264_change_process_priority(void *hProcess, const int priority); -bool x264_play_sound(const unsigned short uiSoundIdx, const bool bAsync, const wchar_t *alias = NULL); -unsigned int x264_process_id(void); -bool x264_enable_close_button(const QWidget *win, const bool bEnable); +bool x264_beep(int beepType); void x264_blink_window(QWidget *poWindow, unsigned int count, unsigned int delay); bool x264_bring_to_front(const QWidget *win); +bool x264_change_process_priority(const QProcess *proc, const int priority); +bool x264_change_process_priority(const int priority); +bool x264_change_process_priority(void *hProcess, const int priority); +const QString &x264_data_path(void); +size_t x264_dbg_private_bytes(void); +x264_cpu_t x264_detect_cpu_features(const QStringList &argv); +bool x264_enable_close_button(const QWidget *win, const bool bEnable); +void x264_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL); +void x264_finalization(void); +void x264_init_console(int argc, char* argv[]); +bool x264_init_qt(int argc, char* argv[]); bool x264_is_executable(const QString &path); +bool x264_is_prerelease(void); +void x264_message_handler(QtMsgType type, const char *msg); +QString x264_path2ansi(const QString &longPath); +bool x264_play_sound(const unsigned short uiSoundIdx, const bool bAsync, const wchar_t *alias = NULL); +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_beep(int beepType); +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); +const char *x264_version_arch(void); +unsigned int x264_version_build(void); +const char *x264_version_compiler(void); +const QDate &x264_version_date(void); +unsigned int x264_version_major(void); +unsigned int x264_version_minor(void); +const char *x264_version_time(void); +unsigned int x264_version_x264_minimum_rev(void); +unsigned int x264_version_x264_current_api(void); +unsigned int x264_version_x264_avs2yuv_ver(void); + +/////////////////////////////////////////////////////////////////////////////// +// HELPER MACROS +/////////////////////////////////////////////////////////////////////////////// + +#define QWCHAR(STR) reinterpret_cast(STR.utf16()) +#define QUTF8(STR) ((STR).toUtf8().constData()) +#define WCHAR2QSTR(STR) (QString::fromUtf16(reinterpret_cast((STR)))) +#define X264_BOOL(X) ((X) ? "1" : "0") +#define X264_DELETE(PTR) if(PTR) { delete PTR; PTR = NULL; } +#define X264_DELETE_ARRAY(PTR) if(PTR) { delete [] PTR; PTR = NULL; } +#define _X264_MAKE_STRING_(X) #X +#define X264_MAKE_STRING(X) _X264_MAKE_STRING_(X) +#define X264_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" X264_MAKE_STRING(__LINE__) ") : warning: " TXT)) + +//Debug build +#if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG) + #define X264_DEBUG (1) +#else + #define X264_DEBUG (0) +#endif + +//Check for CPU-compatibility options +#if !defined(_M_X64) && defined(_MSC_VER) && defined(_M_IX86_FP) + #if (_M_IX86_FP != 0) + #error We should not enabled SSE or SSE2 in release builds! + #endif +#endif + +//Helper macro for throwing exceptions +#define THROW(MESSAGE) do \ +{ \ + throw std::runtime_error((MESSAGE)); \ +} \ +while(0) +#define THROW_FMT(FORMAT, ...) do \ +{ \ + char _error_msg[512]; \ + _snprintf_s(_error_msg, 512, _TRUNCATE, (FORMAT), __VA_ARGS__); \ + throw std::runtime_error(_error_msg); \ +} \ +while(0) + +//Memory check +#if X264_DEBUG + #define X264_MEMORY_CHECK(FUNC, RETV, ...) do \ + { \ + size_t _privateBytesBefore = x264_dbg_private_bytes(); \ + RETV = FUNC(__VA_ARGS__); \ + size_t _privateBytesLeak = (x264_dbg_private_bytes() - _privateBytesBefore) / 1024; \ + if(_privateBytesLeak > 0) { \ + x264_dbg_dbg_output_string("\nMemory leak: Lost %u KiloBytes of PrivateUsage memory!\n\n", _privateBytesLeak); \ + } \ + } \ + while(0) +#else + #define X264_MEMORY_CHECK(FUNC, RETV, ...) do \ + { \ + RETV = __noop(__VA_ARGS__); \ + } \ + while(0) +#endif diff --git a/src/thread_encode.cpp b/src/thread_encode.cpp index 87785a2..0c6ba4e 100644 --- a/src/thread_encode.cpp +++ b/src/thread_encode.cpp @@ -25,7 +25,6 @@ #include "model_options.h" #include "model_preferences.h" #include "job_object.h" -#include "version.h" #include #include @@ -262,18 +261,18 @@ void EncodeThread::encode(void) if(revision_avs2yuv != UINT_MAX) log(tr("Avs2YUV version: %1.%2.%3").arg(QString::number(revision_avs2yuv / REV_MULT), QString::number((revision_avs2yuv % REV_MULT) / 10),QString::number((revision_avs2yuv % REV_MULT) % 10))); //Is x264 revision supported? - if((revision_x264 % REV_MULT) < (VER_X264_MINIMUM_REV)) + if((revision_x264 % REV_MULT) < x264_version_x264_minimum_rev()) { - log(tr("\nERROR: Your revision of x264 is too old! (Minimum required revision is %2)").arg(QString::number(VER_X264_MINIMUM_REV))); + log(tr("\nERROR: Your revision of x264 is too old! (Minimum required revision is %2)").arg(QString::number(x264_version_x264_minimum_rev()))); setStatus(JobStatus_Failed); return; } - if((revision_x264 / REV_MULT) != (VER_X264_CURRENT_API)) + if((revision_x264 / REV_MULT) != x264_version_x264_current_api()) { log(tr("\nWARNING: Your revision of x264 uses an unsupported core (API) version, take care!")); - log(tr("This application works best with x264 core (API) version %2.").arg(QString::number(VER_X264_CURRENT_API))); + log(tr("This application works best with x264 core (API) version %2.").arg(QString::number(x264_version_x264_current_api()))); } - if((revision_avs2yuv != UINT_MAX) && ((revision_avs2yuv % REV_MULT) != (VER_X264_AVS2YUV_VER))) + if((revision_avs2yuv != UINT_MAX) && ((revision_avs2yuv % REV_MULT) != x264_version_x264_avs2yuv_ver())) { log(tr("\nERROR: Your version of avs2yuv is unsupported (Required version: v0.24 BugMaster's mod 2)")); log(tr("You can find the required version at: http://komisar.gin.by/tools/avs2yuv/")); diff --git a/src/version.h b/src/version.h index fa65816..6391370 100644 --- a/src/version.h +++ b/src/version.h @@ -19,10 +19,14 @@ // http://www.gnu.org/licenses/gpl-2.0.txt /////////////////////////////////////////////////////////////////////////////// +#ifndef ENABLE_X264_VERSION_INCLUDE +#error Please do *not* inlcude "version.h" directly! +#endif + #define VER_X264_MAJOR 2 #define VER_X264_MINOR 2 #define VER_X264_PATCH 4 -#define VER_X264_BUILD 608 +#define VER_X264_BUILD 610 #define VER_X264_MINIMUM_REV 2363 #define VER_X264_CURRENT_API 140 diff --git a/x264_launcher.rc b/x264_launcher.rc index 6f0b6139b016274094c531344eb338253c6c1666..c545210b77819be18a819a85af331b44bcc3a255 100644 GIT binary patch delta 225 zcmeyTcg$cyn{+rsCPN-W5JM_MF+&kUGJ_sN27?lV0)sw-{=~PE6Yq#j+`}=kPb!|5 zfeR$Y5C&9P1XP>JkPp-c5>;kM0g9!8%}E97bY<{kaAa^|@By;o86p^r7|a+Tyb_V57L&3Fw6lT-rI4f+58 diff --git a/x264_launcher_MSVC2013.vcxproj b/x264_launcher_MSVC2013.vcxproj index d5bf083..ca3c4c8 100644 --- a/x264_launcher_MSVC2013.vcxproj +++ b/x264_launcher_MSVC2013.vcxproj @@ -367,6 +367,9 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats" + + + diff --git a/x264_launcher_MSVC2013.vcxproj.filters b/x264_launcher_MSVC2013.vcxproj.filters index 27d436d..6b1008a 100644 --- a/x264_launcher_MSVC2013.vcxproj.filters +++ b/x264_launcher_MSVC2013.vcxproj.filters @@ -219,4 +219,9 @@ Assembly + + + Resource Files + + \ No newline at end of file