1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
26 #include <QApplication>
27 #include <QMessageBox>
33 #include <QPlastiqueStyle>
34 #include <QImageReader>
35 #include <QSharedMemory>
37 #include <QStringList>
38 #include <QSystemSemaphore>
44 #include <QTranslator>
47 #include <QLibraryInfo>
62 static bool g_x264_console_attached = false;
63 static QMutex g_x264_message_mutex;
64 static const DWORD g_main_thread_id = GetCurrentThreadId();
65 static FILE *g_x264_log_file = NULL;
66 static QDate g_x264_version_date;
69 static const char *g_x264_months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
70 static const char *g_x264_imageformats[] = {"png", "jpg", "gif", "ico", "svg", NULL};
75 unsigned int ver_major;
76 unsigned int ver_minor;
89 //The following code was borrowed from MPC-HC project: http://mpc-hc.sf.net/
90 #if defined(__INTEL_COMPILER)
91 #if (__INTEL_COMPILER >= 1200)
92 static const char *g_x264_version_compiler = "ICL 12.x";
93 #elif (__INTEL_COMPILER >= 1100)
94 static const char *g_x264_version_compiler = = "ICL 11.x";
95 #elif (__INTEL_COMPILER >= 1000)
96 static const char *g_x264_version_compiler = = "ICL 10.x";
98 #error Compiler is not supported!
100 #elif defined(_MSC_VER)
101 #if (_MSC_VER == 1600)
102 #if (_MSC_FULL_VER >= 160040219)
103 static const char *g_x264_version_compiler = "MSVC 2010-SP1";
105 static const char *g_x264_version_compiler = "MSVC 2010";
107 #elif (_MSC_VER == 1500)
108 #if (_MSC_FULL_VER >= 150030729)
109 static const char *g_x264_version_compiler = "MSVC 2008-SP1";
111 static const char *g_x264_version_compiler = "MSVC 2008";
114 #error Compiler is not supported!
117 // Note: /arch:SSE and /arch:SSE2 are only available for the x86 platform
118 #if !defined(_M_X64) && defined(_M_IX86_FP)
119 #if (_M_IX86_FP == 1)
120 x264_COMPILER_WARNING("SSE instruction set is enabled!")
121 #elif (_M_IX86_FP == 2)
122 x264_COMPILER_WARNING("SSE2 instruction set is enabled!")
126 #error Compiler is not supported!
129 //Architecture detection
131 static const char *g_x264_version_arch = "x64";
132 #elif defined(_M_IX86)
133 static const char *g_x264_version_arch = "x86";
135 #error Architecture is not supported!
139 * Global exception handler
141 LONG WINAPI x264_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo)
143 if(GetCurrentThreadId() != g_main_thread_id)
145 HANDLE mainThread = OpenThread(THREAD_TERMINATE, FALSE, g_main_thread_id);
146 if(mainThread) TerminateThread(mainThread, ULONG_MAX);
149 FatalAppExit(0, L"Unhandeled exception handler invoked, application will exit!");
150 TerminateProcess(GetCurrentProcess(), -1);
155 * Invalid parameters handler
157 void x264_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t)
159 if(GetCurrentThreadId() != g_main_thread_id)
161 HANDLE mainThread = OpenThread(THREAD_TERMINATE, FALSE, g_main_thread_id);
162 if(mainThread) TerminateThread(mainThread, ULONG_MAX);
165 FatalAppExit(0, L"Invalid parameter handler invoked, application will exit!");
166 TerminateProcess(GetCurrentProcess(), -1);
170 * Change console text color
172 static void x264_console_color(FILE* file, WORD attributes)
174 const HANDLE hConsole = (HANDLE)(_get_osfhandle(_fileno(file)));
175 if((hConsole != NULL) && (hConsole != INVALID_HANDLE_VALUE))
177 SetConsoleTextAttribute(hConsole, attributes);
184 void x264_message_handler(QtMsgType type, const char *msg)
186 static const char *GURU_MEDITATION = "\n\nGURU MEDITATION !!!\n\n";
188 QMutexLocker lock(&g_x264_message_mutex);
192 static char prefix[] = "DWCF";
193 int index = qBound(0, static_cast<int>(type), 3);
194 unsigned int timestamp = static_cast<unsigned int>(_time64(NULL) % 3600I64);
195 QString str = QString::fromUtf8(msg).trimmed().replace('\n', '\t');
196 fprintf(g_x264_log_file, "[%c][%04u] %s\r\n", prefix[index], timestamp, str.toUtf8().constData());
197 fflush(g_x264_log_file);
200 if(g_x264_console_attached)
202 UINT oldOutputCP = GetConsoleOutputCP();
203 if(oldOutputCP != CP_UTF8) SetConsoleOutputCP(CP_UTF8);
211 x264_console_color(stderr, FOREGROUND_RED | FOREGROUND_INTENSITY);
212 fprintf(stderr, GURU_MEDITATION);
213 fprintf(stderr, "%s\n", msg);
217 x264_console_color(stderr, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
218 fprintf(stderr, "%s\n", msg);
222 x264_console_color(stderr, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
223 fprintf(stderr, "%s\n", msg);
228 x264_console_color(stderr, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
229 if(oldOutputCP != CP_UTF8) SetConsoleOutputCP(oldOutputCP);
233 QString temp("[LameXP][%1] %2");
239 temp = temp.arg("C", QString::fromUtf8(msg));
242 temp = temp.arg("W", QString::fromUtf8(msg));
245 temp = temp.arg("I", QString::fromUtf8(msg));
249 temp.replace("\n", "\t").append("\n");
250 OutputDebugStringA(temp.toLatin1().constData());
253 if(type == QtCriticalMsg || type == QtFatalMsg)
256 MessageBoxW(NULL, QWCHAR(QString::fromUtf8(msg)), L"LameXP - GURU MEDITATION", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
257 FatalAppExit(0, L"The application has encountered a critical error and will exit now!");
258 TerminateProcess(GetCurrentProcess(), -1);
263 * Initialize the console
265 void x264_init_console(int argc, char* argv[])
267 bool enableConsole = true; //x264_version_demo();
271 wchar_t *logfile = NULL;
272 size_t logfile_len = 0;
273 if(!_wdupenv_s(&logfile, &logfile_len, L"X264_LAUNCHER_LOGFILE"))
275 if(logfile && (logfile_len > 0))
278 if(!_wfopen_s(&temp, logfile, L"wb"))
280 fprintf(temp, "%c%c%c", 0xEF, 0xBB, 0xBF);
281 g_x264_log_file = temp;
290 for(int i = 0; i < argc; i++)
292 if(!_stricmp(argv[i], "--console"))
294 enableConsole = true;
296 else if(!_stricmp(argv[i], "--no-console"))
298 enableConsole = false;
305 if(!g_x264_console_attached)
307 if(AllocConsole() != FALSE)
309 SetConsoleCtrlHandler(NULL, TRUE);
310 SetConsoleTitle(L"Simple x264 Launcher | Debug Console");
311 SetConsoleOutputCP(CP_UTF8);
312 g_x264_console_attached = true;
316 if(g_x264_console_attached)
318 //-------------------------------------------------------------------
319 //See: http://support.microsoft.com/default.aspx?scid=kb;en-us;105305
320 //-------------------------------------------------------------------
321 const int flags = _O_WRONLY | _O_U8TEXT;
322 int hCrtStdOut = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE), flags);
323 int hCrtStdErr = _open_osfhandle((intptr_t) GetStdHandle(STD_ERROR_HANDLE), flags);
324 FILE *hfStdOut = (hCrtStdOut >= 0) ? _fdopen(hCrtStdOut, "wb") : NULL;
325 FILE *hfStdErr = (hCrtStdErr >= 0) ? _fdopen(hCrtStdErr, "wb") : NULL;
326 if(hfStdOut) { *stdout = *hfStdOut; std::cout.rdbuf(new std::filebuf(hfStdOut)); }
327 if(hfStdErr) { *stderr = *hfStdErr; std::cerr.rdbuf(new std::filebuf(hfStdErr)); }
330 HWND hwndConsole = GetConsoleWindow();
332 if((hwndConsole != NULL) && (hwndConsole != INVALID_HANDLE_VALUE))
334 HMENU hMenu = GetSystemMenu(hwndConsole, 0);
335 EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
336 RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
338 SetWindowPos(hwndConsole, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
339 SetWindowLong(hwndConsole, GWL_STYLE, GetWindowLong(hwndConsole, GWL_STYLE) & (~WS_MAXIMIZEBOX) & (~WS_MINIMIZEBOX));
340 SetWindowPos(hwndConsole, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
348 unsigned int x264_version_major(void)
350 return g_x264_version.ver_major;
353 unsigned int x264_version_minor(void)
355 return g_x264_version.ver_minor;
358 const char *x264_version_compiler(void)
360 return g_x264_version_compiler;
363 const char *x264_version_arch(void)
365 return g_x264_version_arch;
369 * Get build date date
371 const QDate &x264_version_date(void)
373 if(!g_x264_version_date.isValid())
375 int date[3] = {0, 0, 0}; char temp[12] = {'\0'};
376 strncpy_s(temp, 12, g_x264_version.ver_date, _TRUNCATE);
378 if(strlen(temp) == 11)
380 temp[3] = temp[6] = '\0';
381 date[2] = atoi(&temp[4]);
382 date[0] = atoi(&temp[7]);
384 for(int j = 0; j < 12; j++)
386 if(!_strcmpi(&temp[0], g_x264_months[j]))
393 g_x264_version_date = QDate(date[0], date[1], date[2]);
396 if(!g_x264_version_date.isValid())
398 qFatal("Internal error: Date format could not be recognized!");
402 return g_x264_version_date;
405 const char *x264_version_time(void)
407 return g_x264_version.ver_time;
411 * Detect CPU features
413 x264_cpu_t x264_detect_cpu_features(int argc, char **argv)
415 typedef BOOL (WINAPI *IsWow64ProcessFun)(__in HANDLE hProcess, __out PBOOL Wow64Process);
416 typedef VOID (WINAPI *GetNativeSystemInfoFun)(__out LPSYSTEM_INFO lpSystemInfo);
418 static IsWow64ProcessFun IsWow64ProcessPtr = NULL;
419 static GetNativeSystemInfoFun GetNativeSystemInfoPtr = NULL;
422 SYSTEM_INFO systemInfo;
423 int CPUInfo[4] = {-1};
424 char CPUIdentificationString[0x40];
425 char CPUBrandString[0x40];
427 memset(&features, 0, sizeof(x264_cpu_t));
428 memset(&systemInfo, 0, sizeof(SYSTEM_INFO));
429 memset(CPUIdentificationString, 0, sizeof(CPUIdentificationString));
430 memset(CPUBrandString, 0, sizeof(CPUBrandString));
433 memcpy(CPUIdentificationString, &CPUInfo[1], sizeof(int));
434 memcpy(CPUIdentificationString + 4, &CPUInfo[3], sizeof(int));
435 memcpy(CPUIdentificationString + 8, &CPUInfo[2], sizeof(int));
436 features.intel = (_stricmp(CPUIdentificationString, "GenuineIntel") == 0);
437 strncpy_s(features.vendor, 0x40, CPUIdentificationString, _TRUNCATE);
442 features.mmx = (CPUInfo[3] & 0x800000) || false;
443 features.sse = (CPUInfo[3] & 0x2000000) || false;
444 features.sse2 = (CPUInfo[3] & 0x4000000) || false;
445 features.ssse3 = (CPUInfo[2] & 0x200) || false;
446 features.sse3 = (CPUInfo[2] & 0x1) || false;
447 features.ssse3 = (CPUInfo[2] & 0x200) || false;
448 features.stepping = CPUInfo[0] & 0xf;
449 features.model = ((CPUInfo[0] >> 4) & 0xf) + (((CPUInfo[0] >> 16) & 0xf) << 4);
450 features.family = ((CPUInfo[0] >> 8) & 0xf) + ((CPUInfo[0] >> 20) & 0xff);
453 __cpuid(CPUInfo, 0x80000000);
454 int nExIds = qMax<int>(qMin<int>(CPUInfo[0], 0x80000004), 0x80000000);
456 for(int i = 0x80000002; i <= nExIds; ++i)
462 memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
465 memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
468 memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
473 strncpy_s(features.brand, 0x40, CPUBrandString, _TRUNCATE);
475 if(strlen(features.brand) < 1) strncpy_s(features.brand, 0x40, "Unknown", _TRUNCATE);
476 if(strlen(features.vendor) < 1) strncpy_s(features.vendor, 0x40, "Unknown", _TRUNCATE);
478 #if !defined(_M_X64 ) && !defined(_M_IA64)
479 if(!IsWow64ProcessPtr || !GetNativeSystemInfoPtr)
481 QLibrary Kernel32Lib("kernel32.dll");
482 IsWow64ProcessPtr = (IsWow64ProcessFun) Kernel32Lib.resolve("IsWow64Process");
483 GetNativeSystemInfoPtr = (GetNativeSystemInfoFun) Kernel32Lib.resolve("GetNativeSystemInfo");
485 if(IsWow64ProcessPtr)
488 if(IsWow64ProcessPtr(GetCurrentProcess(), &x64))
493 if(GetNativeSystemInfoPtr)
495 GetNativeSystemInfoPtr(&systemInfo);
499 GetSystemInfo(&systemInfo);
501 features.count = qBound(1UL, systemInfo.dwNumberOfProcessors, 64UL);
503 GetNativeSystemInfo(&systemInfo);
504 features.count = systemInfo.dwNumberOfProcessors;
508 if((argv != NULL) && (argc > 0))
511 for(int i = 0; i < argc; i++)
513 if(!_stricmp("--force-cpu-no-64bit", argv[i])) { flag = true; features.x64 = false; }
514 if(!_stricmp("--force-cpu-no-sse", argv[i])) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = false; }
515 if(!_stricmp("--force-cpu-no-intel", argv[i])) { flag = true; features.intel = false; }
517 if(flag) qWarning("CPU flags overwritten by user-defined parameters. Take care!\n");
524 * Get the native operating system version
526 DWORD x264_get_os_version(void)
528 OSVERSIONINFO osVerInfo;
529 memset(&osVerInfo, 0, sizeof(OSVERSIONINFO));
530 osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
533 if(GetVersionEx(&osVerInfo) == TRUE)
535 if(osVerInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
537 throw "Ouuups: Not running under Windows NT. This is not supposed to happen!";
539 version = (DWORD)((osVerInfo.dwMajorVersion << 16) | (osVerInfo.dwMinorVersion & 0xffff));
546 * Check for compatibility mode
548 static bool x264_check_compatibility_mode(const char *exportName, const char *executableName)
550 QLibrary kernel32("kernel32.dll");
552 if(exportName != NULL)
554 if(kernel32.resolve(exportName) != NULL)
556 qWarning("Function '%s' exported from 'kernel32.dll' -> Windows compatibility mode!", exportName);
557 qFatal("%s", QApplication::tr("Executable '%1' doesn't support Windows compatibility mode.").arg(QString::fromLatin1(executableName)).toLatin1().constData());
566 * Check for process elevation
568 static bool x264_check_elevation(void)
570 typedef enum { x264_token_elevationType_class = 18, x264_token_elevation_class = 20 } X264_TOKEN_INFORMATION_CLASS;
571 typedef enum { x264_elevationType_default = 1, x264_elevationType_full, x264_elevationType_limited } X264_TOKEN_ELEVATION_TYPE;
573 HANDLE hToken = NULL;
574 bool bIsProcessElevated = false;
576 if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
578 X264_TOKEN_ELEVATION_TYPE tokenElevationType;
580 if(GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS) x264_token_elevationType_class, &tokenElevationType, sizeof(X264_TOKEN_ELEVATION_TYPE), &returnLength))
582 if(returnLength == sizeof(X264_TOKEN_ELEVATION_TYPE))
584 switch(tokenElevationType)
586 case x264_elevationType_default:
587 qDebug("Process token elevation type: Default -> UAC is disabled.\n");
589 case x264_elevationType_full:
590 qWarning("Process token elevation type: Full -> potential security risk!\n");
591 bIsProcessElevated = true;
593 case x264_elevationType_limited:
594 qDebug("Process token elevation type: Limited -> not elevated.\n");
603 qWarning("Failed to open process token!");
606 return !bIsProcessElevated;
610 * Initialize Qt framework
612 bool x264_init_qt(int argc, char* argv[])
614 static bool qt_initialized = false;
616 typedef BOOL (WINAPI *SetDllDirectoryProc)(WCHAR *lpPathName);
618 //Don't initialized again, if done already
625 QLibrary kernel32("kernel32.dll");
628 SetDllDirectoryProc pSetDllDirectory = (SetDllDirectoryProc) kernel32.resolve("SetDllDirectoryW");
629 if(pSetDllDirectory != NULL) pSetDllDirectory(L"");
633 //Extract executable name from argv[] array
634 char *executableName = argv[0];
635 while(char *temp = strpbrk(executableName, "\\/:?"))
637 executableName = temp + 1;
641 qDebug("Using Qt v%s [%s], %s, %s", qVersion(), QLibraryInfo::buildDate().toString(Qt::ISODate).toLatin1().constData(), (qSharedBuild() ? "DLL" : "Static"), QLibraryInfo::buildKey().toLatin1().constData());
642 qDebug("Compiled with Qt v%s [%s], %s\n", QT_VERSION_STR, QT_PACKAGEDATE_STR, QT_BUILD_KEY);
643 if(_stricmp(qVersion(), QT_VERSION_STR))
645 qFatal("%s", QApplication::tr("Executable '%1' requires Qt v%2, but found Qt v%3.").arg(QString::fromLatin1(executableName), QString::fromLatin1(QT_VERSION_STR), QString::fromLatin1(qVersion())).toLatin1().constData());
648 if(QLibraryInfo::buildKey().compare(QString::fromLatin1(QT_BUILD_KEY), Qt::CaseInsensitive))
650 qFatal("%s", QApplication::tr("Executable '%1' was built for Qt '%2', but found Qt '%3'.").arg(QString::fromLatin1(executableName), QString::fromLatin1(QT_BUILD_KEY), QLibraryInfo::buildKey()).toLatin1().constData());
654 //Check the Windows version
655 switch(QSysInfo::windowsVersion() & QSysInfo::WV_NT_based)
658 case QSysInfo::WV_NT:
659 qFatal("%s", QApplication::tr("Executable '%1' requires Windows 2000 or later.").arg(QString::fromLatin1(executableName)).toLatin1().constData());
661 case QSysInfo::WV_2000:
662 qDebug("Running on Windows 2000 (not officially supported!).\n");
663 x264_check_compatibility_mode("GetNativeSystemInfo", executableName);
665 case QSysInfo::WV_XP:
666 qDebug("Running on Windows XP.\n");
667 x264_check_compatibility_mode("GetLargePageMinimum", executableName);
669 case QSysInfo::WV_2003:
670 qDebug("Running on Windows Server 2003 or Windows XP x64-Edition.\n");
671 x264_check_compatibility_mode("GetLocaleInfoEx", executableName);
673 case QSysInfo::WV_VISTA:
674 qDebug("Running on Windows Vista or Windows Server 2008.\n");
675 x264_check_compatibility_mode("CreateRemoteThreadEx", executableName);
677 case QSysInfo::WV_WINDOWS7:
678 qDebug("Running on Windows 7 or Windows Server 2008 R2.\n");
679 x264_check_compatibility_mode(NULL, executableName);
683 DWORD osVersionNo = x264_get_os_version();
684 qWarning("Running on an unknown/untested WinNT-based OS (v%u.%u).\n", HIWORD(osVersionNo), LOWORD(osVersionNo));
690 QLibrary ntdll("ntdll.dll");
693 if(ntdll.resolve("wine_nt_to_unix_file_name") != NULL) isWine = true;
694 if(ntdll.resolve("wine_get_version") != NULL) isWine = true;
695 if(isWine) qWarning("It appears we are running under Wine, unexpected things might happen!\n");
699 //Create Qt application instance and setup version info
700 QApplication *application = new QApplication(argc, argv);
701 application->setApplicationName("LameXP - Audio Encoder Front-End");
702 application->setApplicationVersion(QString().sprintf("%d.%02d", x264_version_major(), x264_version_minor()));
703 application->setOrganizationName("LoRd_MuldeR");
704 application->setOrganizationDomain("mulder.at.gg");
705 application->setWindowIcon(QIcon(":/icons/movie.ico"));
707 //application->setEventFilter(x264_event_filter);
709 //Set text Codec for locale
710 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
712 //Load plugins from application directory
713 QCoreApplication::setLibraryPaths(QStringList() << QApplication::applicationDirPath());
714 qDebug("Library Path:\n%s\n", QApplication::libraryPaths().first().toUtf8().constData());
716 //Check for supported image formats
717 QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
718 for(int i = 0; g_x264_imageformats[i]; i++)
720 if(!supportedFormats.contains(g_x264_imageformats[i]))
722 qFatal("Qt initialization error: QImageIOHandler for '%s' missing!", g_x264_imageformats[i]);
727 //Add default translations
728 // g_x264_translation.files.insert(x264_DEFAULT_LANGID, "");
729 // g_x264_translation.names.insert(x264_DEFAULT_LANGID, "English");
731 //Check for process elevation
732 if(!x264_check_elevation())
734 if(QMessageBox::warning(NULL, "LameXP", "<nobr>LameXP was started with elevated rights. This is a potential security risk!</nobr>", "Quit Program (Recommended)", "Ignore") == 0)
740 //Update console icon, if a console is attached
741 if(g_x264_console_attached && !isWine)
743 typedef DWORD (__stdcall *SetConsoleIconFun)(HICON);
744 QLibrary kernel32("kernel32.dll");
747 SetConsoleIconFun SetConsoleIconPtr = (SetConsoleIconFun) kernel32.resolve("SetConsoleIcon");
748 if(SetConsoleIconPtr != NULL) SetConsoleIconPtr(QIcon(":/icons/movie.ico").pixmap(16, 16).toWinHICON());
754 qt_initialized = true;
759 * Check for debugger (detect routine)
761 static bool x264_check_for_debugger(void)
767 __except(GetExceptionCode() == EXCEPTION_BREAKPOINT ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
775 * Check for debugger (thread proc)
777 static void WINAPI x264_debug_thread_proc(__in LPVOID lpParameter)
779 while(!(IsDebuggerPresent() || x264_check_for_debugger()))
783 TerminateProcess(GetCurrentProcess(), -1);
787 * Check for debugger (startup routine)
789 static HANDLE x264_debug_thread_init(void)
791 if(IsDebuggerPresent() || x264_check_for_debugger())
793 FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
794 TerminateProcess(GetCurrentProcess(), -1);
797 return CreateThread(NULL, NULL, reinterpret_cast<LPTHREAD_START_ROUTINE>(&x264_debug_thread_proc), NULL, NULL, NULL);
801 * Initialize debug thread
803 static const HANDLE g_debug_thread = X264_DEBUG ? NULL : x264_debug_thread_init();
806 * Get number private bytes [debug only]
808 SIZE_T x264_dbg_private_bytes(void)
811 PROCESS_MEMORY_COUNTERS_EX memoryCounters;
812 memoryCounters.cb = sizeof(PROCESS_MEMORY_COUNTERS_EX);
813 GetProcessMemoryInfo(GetCurrentProcess(), (PPROCESS_MEMORY_COUNTERS) &memoryCounters, sizeof(PROCESS_MEMORY_COUNTERS_EX));
814 return memoryCounters.PrivateUsage;
816 throw "Cannot call this function in a non-debug build!";
821 * Finalization function
823 void x264_finalization(void)