1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2021 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 ///////////////////////////////////////////////////////////////////////////////
27 #include "thread_ipc_send.h"
30 #include <MUtils/Startup.h>
31 #include <MUtils/OSSupport.h>
32 #include <MUtils/CPUFeatures.h>
33 #include <MUtils/IPCChannel.h>
34 #include <MUtils/Version.h>
37 #include <QApplication>
39 #include <QPlastiqueStyle>
41 #include <QTextStream>
45 #define WIN32_LEAN_AND_MEAN
48 ///////////////////////////////////////////////////////////////////////////////
50 ///////////////////////////////////////////////////////////////////////////////
52 static void x264_print_logo(void)
55 qDebug("Simple x264 Launcher v%u.%02u.%u - use 64-Bit x264 with 32-Bit Avisynth", x264_version_major(), x264_version_minor(), x264_version_build());
56 qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(MUtils::Version::app_build_date().year(), MUtils::OS::current_date().year()));
57 qDebug("Built on %s at %s with %s for Win-%s.\n", MUTILS_UTF8(MUtils::Version::app_build_date().toString(Qt::ISODate)), MUTILS_UTF8(MUtils::Version::app_build_time().toString(Qt::ISODate)), MUtils::Version::compiler_version(), MUtils::Version::compiler_arch());
60 qDebug("This program is free software: you can redistribute it and/or modify");
61 qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
62 qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
64 //Print library version
65 qDebug("This application is powerd by MUtils library v%u.%02u (%s, %s).\n", MUtils::Version::lib_version_major(), MUtils::Version::lib_version_minor(), MUTILS_UTF8(MUtils::Version::lib_build_date().toString(Qt::ISODate)), MUTILS_UTF8(MUtils::Version::lib_build_time().toString(Qt::ISODate)));
67 //Print warning, if this is a "debug" build
70 qWarning("---------------------------------------------------------");
71 qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
72 qWarning("---------------------------------------------------------\n");
76 static int x264_initialize_ipc(MUtils::IPCChannel *const ipcChannel)
80 if((iResult = ipcChannel->initialize()) != MUtils::IPCChannel::RET_SUCCESS_MASTER)
82 if(iResult == MUtils::IPCChannel::RET_SUCCESS_SLAVE)
84 qDebug("Simple x264 Launcher is already running, connecting to running instance...");
85 QScopedPointer<IPCThread_Send> messageProducerThread(new IPCThread_Send(ipcChannel));
86 messageProducerThread->start();
87 if(!messageProducerThread->wait(30000))
89 qWarning("MessageProducer thread has encountered timeout -> going to kill!");
90 messageProducerThread->terminate();
91 messageProducerThread->wait();
92 MUtils::OS::system_message_err(L"Simple x264 Launcher", L"Simple x264 Launcher is already running, but the running instance doesn't respond!");
99 qFatal("The IPC initialization has failed!");
107 ///////////////////////////////////////////////////////////////////////////////
109 ///////////////////////////////////////////////////////////////////////////////
111 static int simple_x264_main(int &argc, char **argv)
119 const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments();
121 //Enumerate CLI arguments
122 if(!arguments.isEmpty())
124 qDebug("Command-Line Arguments:");
125 foreach(const QString &key, arguments.uniqueKeys())
127 foreach(const QString &val, arguments.values(key))
131 qDebug("--%s = \"%s\"", MUTILS_UTF8(key), MUTILS_UTF8(val));
134 qDebug("--%s", MUTILS_UTF8(key));
140 //Detect CPU capabilities
141 const MUtils::CPUFetaures::cpu_info_t cpuFeatures = MUtils::CPUFetaures::detect();
142 qDebug(" CPU vendor id : %s (Intel=%s)", cpuFeatures.idstr, MUTILS_BOOL2STR(cpuFeatures.vendor & MUtils::CPUFetaures::VENDOR_INTEL));
143 qDebug("CPU brand string : %s", cpuFeatures.brand);
144 qDebug(" CPU signature : Family=%d, Model=%d, Stepping=%d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
145 qDebug("CPU architecture : %s", cpuFeatures.x64 ? "x64 (64-Bit)" : "x86 (32-Bit)");
146 qDebug("CPU capabilities : CMOV=%s, MMX=%s, SSE=%s, SSE2=%s, SSE3=%s, SSSE3=%s", MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_CMOV), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_MMX), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE2), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE3), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSSE3));
147 qDebug("CPU capabilities : SSE4.1=%s, SSE4.2=%s, AVX=%s, AVX2=%s, FMA3=%s, LZCNT=%s", MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE41), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE42), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_AVX), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_AVX2), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_FMA3), MUTILS_BOOL2STR(cpuFeatures.features & MUtils::CPUFetaures::FLAG_LZCNT));
148 qDebug(" Number of CPU's : %d\n", cpuFeatures.count);
151 QScopedPointer<QApplication> application(MUtils::Startup::create_qt(argc, argv, QLatin1String("Simple x264 Launcher"), QLatin1String("LoRd_MuldeR"), QLatin1String("muldersoft.com"), false));
152 if(application.isNull())
157 //Initialize application
158 application->setWindowIcon(QIcon(":/icons/movie.ico"));
159 application->setApplicationVersion(QString().sprintf("%d.%02d.%04d", x264_version_major(), x264_version_minor(), x264_version_build()));
161 //Initialize the IPC handler class
162 QScopedPointer<MUtils::IPCChannel> ipcChannel(new MUtils::IPCChannel("simple-x264-launcher", x264_version_build(), "instance"));
163 if((iResult = x264_initialize_ipc(ipcChannel.data())) < 1)
165 return (iResult == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
168 //Running in portable mode?
169 if(x264_is_portable())
171 qDebug("Application is running in portable mode!\n");
175 if(!arguments.contains(CLI_PARAM_NO_GUI_STYLE))
177 qApp->setStyle(new QPlastiqueStyle());
179 if (arguments.contains(CLI_PARAM_DARK_GUI_MODE))
181 QFile qss(":qdarkstyle/style.qss");
182 if (qss.open(QFile::ReadOnly | QFile::Text))
184 QTextStream textStream(&qss);
185 application->setStyleSheet(textStream.readAll());
190 QScopedPointer<MainWindow> mainWindow(new MainWindow(cpuFeatures, ipcChannel.data()));
194 int ret = qApp->exec();
200 ///////////////////////////////////////////////////////////////////////////////
201 // Applicaton entry point
202 ///////////////////////////////////////////////////////////////////////////////
204 int main(int argc, char* argv[])
206 return MUtils::Startup::startup(argc, argv, simple_x264_main, "Simple x264 Launcher", x264_is_prerelease());