Some improvements to global functions header file.

This commit is contained in:
LoRd_MuldeR 2013-11-06 00:30:27 +01:00
parent 59bd8af34e
commit aa2b7c6bb4
7 changed files with 173 additions and 85 deletions

View File

@ -19,9 +19,14 @@
// http://www.gnu.org/licenses/gpl-2.0.txt // http://www.gnu.org/licenses/gpl-2.0.txt
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
//x264 includes
#include "global.h" #include "global.h"
#include "targetver.h" #include "targetver.h"
//Version
#define ENABLE_X264_VERSION_INCLUDE
#include "version.h" #include "version.h"
#undef ENABLE_X264_VERSION_INCLUDE
//Windows includes //Windows includes
#define NOMINMAX #define NOMINMAX
@ -100,6 +105,9 @@ static const struct
unsigned int ver_build; unsigned int ver_build;
const char* ver_date; const char* ver_date;
const char* ver_time; 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 = g_x264_version =
{ {
@ -108,7 +116,10 @@ g_x264_version =
(VER_X264_PATCH), (VER_X264_PATCH),
(VER_X264_BUILD), (VER_X264_BUILD),
__DATE__, __DATE__,
__TIME__ __TIME__,
(VER_X264_MINIMUM_REV),
(VER_X264_CURRENT_API),
(VER_X264_AVS2YUV_VER)
}; };
//CLI Arguments //CLI Arguments
@ -128,6 +139,15 @@ static struct
} }
g_x264_os_version; g_x264_os_version;
//Wine detection
static struct
{
bool bInitialized;
bool bIsWine;
QReadWriteLock lock;
}
g_x264_wine;
//Portable Mode //Portable Mode
static struct static struct
{ {
@ -667,6 +687,21 @@ const char *x264_version_arch(void)
return g_x264_version_arch; 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 * Get CLI arguments
*/ */
@ -1090,22 +1125,31 @@ static bool x264_check_compatibility_mode(const char *exportName, const char *ex
*/ */
bool x264_detect_wine(void) bool x264_detect_wine(void)
{ {
static bool isWine = false; QReadLocker readLock(&g_x264_wine.lock);
static bool isWine_initialized = false;
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"); QLibrary ntdll("ntdll.dll");
if(ntdll.load()) if(ntdll.load())
{ {
if(ntdll.resolve("wine_nt_to_unix_file_name") != 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) isWine = true; if(ntdll.resolve("wine_get_version") != NULL) g_x264_wine.bIsWine = true;
ntdll.unload(); ntdll.unload();
} }
isWine_initialized = true; g_x264_wine.bInitialized = true;
} }
return isWine; return g_x264_wine.bIsWine;
} }
/* /*

View File

@ -21,49 +21,10 @@
#pragma once #pragma once
#define _CRT_RAND_S
#include <cstdlib> #include <cstdlib>
//Debug build //Forward declarations
#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<const wchar_t*>(STR.utf16())
#define QUTF8(STR) ((STR).toUtf8().constData())
#define WCHAR2QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((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
class QString; class QString;
class QStringList; class QStringList;
class QDate; class QDate;
@ -74,6 +35,10 @@ class LockedFile;
class QProcess; class QProcess;
enum QtMsgType; enum QtMsgType;
///////////////////////////////////////////////////////////////////////////////
// TYPE DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
//Types definitions //Types definitions
typedef struct 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_win80;
extern const x264_os_version_t x264_winver_win81; extern const x264_os_version_t x264_winver_win81;
//Functions ///////////////////////////////////////////////////////////////////////////////
void x264_message_handler(QtMsgType type, const char *msg); // GLOBAL FUNCTIONS
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);
const QStringList &x264_arguments(void); const QStringList &x264_arguments(void);
bool x264_suspendProcess(const QProcess *proc, const bool suspend); bool x264_beep(int beepType);
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);
void x264_blink_window(QWidget *poWindow, unsigned int count, unsigned int delay); void x264_blink_window(QWidget *poWindow, unsigned int count, unsigned int delay);
bool x264_bring_to_front(const QWidget *win); 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_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); 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<const wchar_t*>(STR.utf16())
#define QUTF8(STR) ((STR).toUtf8().constData())
#define WCHAR2QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((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

View File

@ -25,7 +25,6 @@
#include "model_options.h" #include "model_options.h"
#include "model_preferences.h" #include "model_preferences.h"
#include "job_object.h" #include "job_object.h"
#include "version.h"
#include <QDate> #include <QDate>
#include <QTime> #include <QTime>
@ -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))); 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? //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); setStatus(JobStatus_Failed);
return; 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("\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("\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/")); log(tr("You can find the required version at: http://komisar.gin.by/tools/avs2yuv/"));

View File

@ -19,10 +19,14 @@
// http://www.gnu.org/licenses/gpl-2.0.txt // 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_MAJOR 2
#define VER_X264_MINOR 2 #define VER_X264_MINOR 2
#define VER_X264_PATCH 4 #define VER_X264_PATCH 4
#define VER_X264_BUILD 608 #define VER_X264_BUILD 610
#define VER_X264_MINIMUM_REV 2363 #define VER_X264_MINIMUM_REV 2363
#define VER_X264_CURRENT_API 140 #define VER_X264_CURRENT_API 140

Binary file not shown.

View File

@ -367,6 +367,9 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats"
<ItemGroup> <ItemGroup>
<Object Include="asm\cpu-detect.obj" /> <Object Include="asm\cpu-detect.obj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Manifest Include="etc\manifest\compat.manifest" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View File

@ -219,4 +219,9 @@
<Filter>Assembly</Filter> <Filter>Assembly</Filter>
</Object> </Object>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Manifest Include="etc\manifest\compat.manifest">
<Filter>Resource Files</Filter>
</Manifest>
</ItemGroup>
</Project> </Project>