OSDN Git Service

Added support for VLD and fixed a few memory leaks found by VLD.
[x264-launcher/x264-launcher.git] / src / global.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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.
14 //
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.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #pragma once
23
24 #include "targetver.h"
25
26 //C++ includes
27 #include <stdio.h>
28 #include <string.h>
29 #include <iostream>
30 #include <time.h>
31
32 //Win32 includes
33 #define WIN32_LEAN_AND_MEAN
34 #include <Windows.h>
35
36 //VLD
37 #include <vld.h>
38
39 //Debug build
40 #if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG)
41         #define X264_DEBUG (1)
42 #else
43         #define X264_DEBUG (0)
44 #endif
45
46 //Memory check
47 #if X264_DEBUG
48 #define X264_MEMORY_CHECK(FUNC, RETV,  ...) \
49 { \
50         SIZE_T _privateBytesBefore = x264_dbg_private_bytes(); \
51         RETV = FUNC(__VA_ARGS__); \
52         SIZE_T _privateBytesLeak = (x264_dbg_private_bytes() - _privateBytesBefore) / 1024; \
53         if(_privateBytesLeak > 0) { \
54                 char _buffer[128]; \
55                 _snprintf_s(_buffer, 128, _TRUNCATE, "Memory leak: Lost %u KiloBytes of PrivateUsage memory.\n", _privateBytesLeak); \
56                 OutputDebugStringA("----------\n"); \
57                 OutputDebugStringA(_buffer); \
58                 OutputDebugStringA("----------\n"); \
59         } \
60 }
61 #else
62 #define X264_MEMORY_CHECK(FUNC, RETV,  ...) \
63 { \
64         RETV = __noop(__VA_ARGS__); \
65 }
66 #endif
67
68 //Helper macros
69 #define QWCHAR(STR) reinterpret_cast<const wchar_t*>(STR.utf16())
70 #define X264_BOOL(X) ((X) ? "1" : "0")
71 #define X264_DELETE(PTR) if(PTR) { delete PTR; PTR = NULL; }
72 #define X264_DELETE_ARRAY(PTR) if(PTR) { delete [] PTR; PTR = NULL; }
73
74 //Declarations
75 class QString;
76 class QStringList;
77 class QDate;
78 class QTime;
79 class QIcon;
80 class QWidget;
81 class LockedFile;
82 enum QtMsgType;
83
84 //Types definitions
85 typedef struct
86 {
87         int family;
88         int model;
89         int stepping;
90         int count;
91         bool x64;
92         bool mmx;
93         bool mmx2;
94         bool sse;
95         bool sse2;
96         bool sse3;
97         bool ssse3;
98         char vendor[0x40];
99         char brand[0x40];
100         bool intel;
101 }
102 x264_cpu_t;
103
104 //Functions
105 LONG WINAPI x264_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo);
106 void x264_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t);
107 void x264_message_handler(QtMsgType type, const char *msg);
108 unsigned int x264_version_major(void);
109 unsigned int x264_version_minor(void);
110 unsigned int x264_version_build(void);
111 const QDate &x264_version_date(void);
112 bool x264_portable(void);
113 const QString &x264_data_path(void);
114 bool x264_is_prerelease(void);
115 const char *x264_version_time(void);
116 const char *x264_version_compiler(void);
117 const char *x264_version_arch(void);
118 void x264_init_console(int argc, char* argv[]);
119 bool x264_init_qt(int argc, char* argv[]);
120 const x264_cpu_t x264_detect_cpu_features(int argc, char **argv);
121 bool x264_shutdown_computer(const QString &message, const unsigned long timeout, const bool forceShutdown);
122 SIZE_T x264_dbg_private_bytes(void);
123 void x264_finalization(void);