1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 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, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Thread_Initialization.h"
26 #define LAMEXP_INC_TOOLS 1
28 #include "LockedFile.h"
29 #include "Tool_Abstract.h"
32 #include <MUtils/Global.h>
33 #include <MUtils/OSSupport.h>
34 #include <MUtils/Translation.h>
35 #include <MUtils/Exception.h>
39 #include <QCoreApplication>
44 #include <QTextStream>
46 #include <QThreadPool>
49 #include <QElapsedTimer>
52 #define PRINT_CPU_TYPE(X) case X: qDebug("Selected CPU is: " #X)
55 static const double g_allowedExtractDelay = 12.0;
56 static const size_t BUFF_SIZE = 512;
57 static const size_t EXPECTED_TOOL_COUNT = 28;
59 /* number of CPU cores -> number of threads */
60 static unsigned int cores2threads(const unsigned int cores)
62 static const size_t LUT_LEN = 4;
66 const unsigned int upperBound;
67 const double coeffs[4];
71 { 4, { -0.052695810565, 0.158087431694, 4.982841530055, -1.088233151184 } },
72 { 8, { 0.042431693989, -0.983442622951, 9.548961748634, -7.176393442623 } },
73 { 12, { -0.006277322404, 0.185573770492, 0.196830601093, 17.762622950820 } },
74 { 32, { 0.000673497268, -0.064655737705, 3.199584699454, 5.751606557377 } }
78 while((cores > LUT[index].upperBound) && (index < (LUT_LEN-1))) index++;
80 const double x = qBound(1.0, double(cores), double(LUT[LUT_LEN-1].upperBound));
81 const double y = (LUT[index].coeffs[0] * pow(x, 3.0)) + (LUT[index].coeffs[1] * pow(x, 2.0)) + (LUT[index].coeffs[2] * x) + LUT[index].coeffs[3];
83 return qRound(abs(y));
86 ////////////////////////////////////////////////////////////
87 // ExtractorTask class
88 ////////////////////////////////////////////////////////////
90 class ExtractorTask : public QRunnable
93 ExtractorTask(QResource *const toolResource, const QDir &appDir, const QString &toolName, const QByteArray &toolHash, const unsigned int toolVersion, const QString &toolTag)
98 m_toolVersion(toolVersion),
100 m_toolResource(toolResource)
107 delete m_toolResource;
110 static void clearFlags(void)
112 QMutexLocker lock(&s_mutex);
115 s_errMsg[0] = char(0);
118 static bool getExcept(void) { bool ret; QMutexLocker lock(&s_mutex); ret = s_bExcept; return ret; }
119 static bool getCustom(void) { bool ret; QMutexLocker lock(&s_mutex); ret = s_bCustom; return ret; }
121 static bool getErrMsg(char *buffer, const size_t buffSize)
123 QMutexLocker lock(&s_mutex);
126 strncpy_s(buffer, BUFF_SIZE, s_errMsg, _TRUNCATE);
137 if(!getExcept()) doExtract();
139 catch(const std::exception &e)
141 QMutexLocker lock(&s_mutex);
145 strncpy_s(s_errMsg, BUFF_SIZE, e.what(), _TRUNCATE);
148 qWarning("ExtractorTask exception error:\n%s\n\n", e.what());
152 QMutexLocker lock(&s_mutex);
156 strncpy_s(s_errMsg, BUFF_SIZE, "Unknown exception error!", _TRUNCATE);
159 qWarning("ExtractorTask encountered an unknown exception!");
165 LockedFile *lockedFile = NULL;
166 unsigned int version = m_toolVersion;
168 QFileInfo toolFileInfo(m_toolName);
169 const QString toolShortName = QString("%1.%2").arg(toolFileInfo.baseName().toLower(), toolFileInfo.suffix().toLower());
171 QFileInfo customTool(QString("%1/tools/%2/%3").arg(m_appDir.canonicalPath(), QString::number(lamexp_version_build()), toolShortName));
172 if(customTool.exists() && customTool.isFile())
174 qDebug("Setting up file: %s <- %s", toolShortName.toLatin1().constData(), m_appDir.relativeFilePath(customTool.canonicalFilePath()).toLatin1().constData());
175 lockedFile = new LockedFile(customTool.canonicalFilePath()); version = UINT_MAX; s_bCustom = true;
179 qDebug("Extracting file: %s -> %s", m_toolName.toLatin1().constData(), toolShortName.toLatin1().constData());
180 lockedFile = new LockedFile(m_toolResource, QString("%1/lxp_%2").arg(MUtils::temp_folder(), toolShortName), m_toolHash);
185 lamexp_tools_register(toolShortName, lockedFile, version, m_toolTag);
190 QResource *const m_toolResource;
192 const QString m_toolName;
193 const QByteArray m_toolHash;
194 const unsigned int m_toolVersion;
195 const QString m_toolTag;
197 static volatile bool s_bExcept;
198 static volatile bool s_bCustom;
199 static QMutex s_mutex;
200 static char s_errMsg[BUFF_SIZE];
203 QMutex ExtractorTask::s_mutex;
204 char ExtractorTask::s_errMsg[BUFF_SIZE] = {'\0'};
205 volatile bool ExtractorTask::s_bExcept = false;
206 volatile bool ExtractorTask::s_bCustom = false;
208 ////////////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////////////
212 InitializationThread::InitializationThread(const MUtils::CPUFetaures::cpu_info_t &cpuFeatures)
215 m_slowIndicator(false)
218 memcpy(&m_cpuFeatures, &cpuFeatures, sizeof(MUtils::CPUFetaures::cpu_info_t));
221 ////////////////////////////////////////////////////////////
223 ////////////////////////////////////////////////////////////
225 void InitializationThread::run(void)
231 catch(const std::exception &error)
233 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what());
234 MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
238 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
239 MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
243 double InitializationThread::doInit(const size_t threadCount)
249 unsigned int cpuSupport = 0;
250 if((m_cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE) && (m_cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE2) && m_cpuFeatures.intel)
252 cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_SSE : CPU_TYPE_X86_SSE;
256 cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_GEN : CPU_TYPE_X86_GEN;
259 //Hack to disable x64 on Wine, as x64 binaries won't run under Wine (tested with Wine 1.4 under Ubuntu 12.04 x64)
260 if(cpuSupport & CPU_TYPE_X64_ALL)
262 if(MUtils::OS::running_on_wine())
264 qWarning("Running under Wine on a 64-Bit system. Going to disable all x64 support!\n");
265 cpuSupport = (cpuSupport == CPU_TYPE_X64_SSE) ? CPU_TYPE_X86_SSE : CPU_TYPE_X86_GEN;
269 //Print selected CPU type
272 PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
273 PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
274 PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
275 PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
276 default: MUTILS_THROW("CPU support undefined!");
280 QQueue<QString> queueToolName;
281 QQueue<QString> queueChecksum;
282 QQueue<QString> queueVersInfo;
283 QQueue<unsigned int> queueVersions;
284 QQueue<unsigned int> queueCpuTypes;
287 for(int i = 0; true; i++)
289 if(!(g_lamexp_tools[i].pcName || g_lamexp_tools[i].pcHash || g_lamexp_tools[i].uiVersion))
293 else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
295 queueToolName.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcName));
296 queueChecksum.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcHash));
297 queueVersInfo.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcVersTag));
298 queueCpuTypes.enqueue(g_lamexp_tools[i].uiCpuType);
299 queueVersions.enqueue(g_lamexp_tools[i].uiVersion);
303 qFatal("Inconsistent checksum data detected. Take care!");
307 QDir appDir = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
309 QThreadPool *pool = new QThreadPool();
310 pool->setMaxThreadCount((threadCount > 0) ? threadCount : qBound(2U, cores2threads(m_cpuFeatures.count), EXPECTED_TOOL_COUNT));
311 /* qWarning("Using %u threads for extraction.", pool->maxThreadCount()); */
313 LockedFile::selfTest();
314 ExtractorTask::clearFlags();
317 QElapsedTimer timeExtractStart;
318 timeExtractStart.start();
321 while(!(queueToolName.isEmpty() || queueChecksum.isEmpty() || queueVersInfo.isEmpty() || queueCpuTypes.isEmpty() || queueVersions.isEmpty()))
323 const QString toolName = queueToolName.dequeue();
324 const QString checksum = queueChecksum.dequeue();
325 const QString versInfo = queueVersInfo.dequeue();
326 const unsigned int cpuType = queueCpuTypes.dequeue();
327 const unsigned int version = queueVersions.dequeue();
329 const QByteArray toolHash(checksum.toLatin1());
330 if(toolHash.size() != 96)
332 qFatal("The checksum for \"%s\" has an invalid size!", MUTILS_UTF8(toolName));
336 QResource *resource = new QResource(QString(":/tools/%1").arg(toolName));
337 if(!(resource->isValid() && resource->data()))
339 MUTILS_DELETE(resource);
340 qFatal("The resource for \"%s\" could not be found!", MUTILS_UTF8(toolName));
344 if(cpuType & cpuSupport)
346 pool->start(new ExtractorTask(resource, appDir, toolName, toolHash, version, versInfo));
350 MUTILS_DELETE(resource);
354 if(!(queueToolName.isEmpty() && queueChecksum.isEmpty() && queueVersInfo.isEmpty() && queueCpuTypes.isEmpty() && queueVersions.isEmpty()))
356 qFatal("Checksum queues *not* empty fater verification completed. Take care!");
359 //Wait for extrator threads to finish
363 //Performance measure
364 const double delayExtract = double(timeExtractStart.elapsed()) / 1000.0;
365 timeExtractStart.invalidate();
367 //Make sure all files were extracted correctly
368 if(ExtractorTask::getExcept())
370 char errorMsg[BUFF_SIZE];
371 if(ExtractorTask::getErrMsg(errorMsg, BUFF_SIZE))
373 qFatal("At least one of the required tools could not be initialized:\n%s", errorMsg);
376 qFatal("At least one of the required tools could not be initialized!");
380 qDebug("All extracted.\n");
382 //Using any custom tools?
383 if(ExtractorTask::getCustom())
385 qWarning("Warning: Using custom tools, you might encounter unexpected problems!\n");
389 if(delayExtract > g_allowedExtractDelay)
391 m_slowIndicator = true;
392 qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract);
393 qWarning("Please report performance problems to your anti-virus developer !!!\n");
397 qDebug("Extracting the tools took %.3f seconds (OK).\n", delayExtract);
400 //Register all translations
403 //Look for AAC encoders
414 ////////////////////////////////////////////////////////////
415 // INTERNAL FUNCTIONS
416 ////////////////////////////////////////////////////////////
418 void InitializationThread::delay(void)
420 MUtils::OS::sleep_ms(333);
423 ////////////////////////////////////////////////////////////
424 // Translation Support
425 ////////////////////////////////////////////////////////////
427 void InitializationThread::initTranslations(void)
429 //Search for language files
430 const QDir qmDirectory(":/localization");
431 const QStringList qmFiles = qmDirectory.entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);
433 //Make sure we found at least one translation
434 if(qmFiles.count() < 1)
436 qFatal("Could not find any translation files!");
440 //Initialize variables
441 const QString langResTemplate(":/localization/%1.txt");
442 QRegExp langIdExp("^LameXP_(\\w\\w)\\.qm$", Qt::CaseInsensitive);
444 //Add all available translations
445 for(QStringList::ConstIterator iter = qmFiles.constBegin(); iter != qmFiles.constEnd(); iter++)
447 const QString langFile = qmDirectory.absoluteFilePath(*iter);
448 QString langId, langName;
449 unsigned int systemId = 0, country = 0;
451 if(QFileInfo(langFile).isFile() && (langIdExp.indexIn(*iter) >= 0))
453 langId = langIdExp.cap(1).toLower();
454 QResource langRes = QResource(langResTemplate.arg(*iter));
455 if(langRes.isValid() && langRes.size() > 0)
457 QByteArray data = QByteArray::fromRawData(reinterpret_cast<const char*>(langRes.data()), langRes.size());
458 QTextStream stream(&data, QIODevice::ReadOnly);
459 stream.setAutoDetectUnicode(false); stream.setCodec("UTF-8");
461 while(!(stream.atEnd() || (stream.status() != QTextStream::Ok)))
463 QStringList langInfo = stream.readLine().simplified().split(",", QString::SkipEmptyParts);
464 if(langInfo.count() >= 3)
466 systemId = langInfo.at(0).trimmed().toUInt();
467 country = langInfo.at(1).trimmed().toUInt();
468 langName = langInfo.at(2).trimmed();
475 if(!(langId.isEmpty() || langName.isEmpty() || (systemId == 0)))
477 if(MUtils::Translation::insert(langId, langFile, langName, systemId, country))
479 qDebug("Registering translation: %s = %s (%u) [%u]", MUTILS_UTF8(*iter), MUTILS_UTF8(langName), systemId, country);
483 qWarning("Failed to register: %s", langFile.toLatin1().constData());
488 qDebug("All registered.\n");
491 ////////////////////////////////////////////////////////////
492 // AAC Encoder Detection
493 ////////////////////////////////////////////////////////////
495 void InitializationThread::initAacEnc_Nero(void)
497 const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
499 const QFileInfo neroFileInfo[3] =
501 QFileInfo(QString("%1/neroAacEnc.exe").arg(appPath)),
502 QFileInfo(QString("%1/neroAacDec.exe").arg(appPath)),
503 QFileInfo(QString("%1/neroAacTag.exe").arg(appPath))
506 bool neroFilesFound = true;
507 for(int i = 0; i < 3; i++)
509 if(!(neroFileInfo[i].exists() && neroFileInfo[i].isFile()))
511 neroFilesFound = false;
517 qDebug("Nero encoder binaries not found -> NeroAAC encoding support will be disabled!\n");
521 for(int i = 0; i < 3; i++)
523 if(!MUtils::OS::is_executable_file(neroFileInfo[i].canonicalFilePath()))
525 qDebug("%s executbale is invalid -> NeroAAC encoding support will be disabled!\n", MUTILS_UTF8(neroFileInfo[i].fileName()));
530 qDebug("Found Nero AAC encoder binary:\n%s\n", MUTILS_UTF8(neroFileInfo[0].canonicalFilePath()));
532 //Lock the Nero binaries
533 QScopedPointer<LockedFile> neroBin[3];
536 for(int i = 0; i < 3; i++)
538 neroBin[i].reset(new LockedFile(neroFileInfo[i].canonicalFilePath()));
543 qWarning("Failed to get excluive lock to Nero encoder binary -> NeroAAC encoding support will be disabled!");
548 MUtils::init_process(process, neroFileInfo[0].absolutePath());
550 process.start(neroFileInfo[0].canonicalFilePath(), QStringList() << "-help");
552 if(!process.waitForStarted())
554 qWarning("Nero process failed to create!");
555 qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
557 process.waitForFinished(-1);
561 bool neroSigFound = false;
562 quint32 neroVersion = 0;
564 QRegExp neroAacEncSig("Nero\\s+AAC\\s+Encoder", Qt::CaseInsensitive);
565 QRegExp neroAacEncVer("Package\\s+version:\\s+(\\d)\\.(\\d)\\.(\\d)\\.(\\d)", Qt::CaseInsensitive);
567 while(process.state() != QProcess::NotRunning)
569 if(!process.waitForReadyRead())
571 if(process.state() == QProcess::Running)
573 qWarning("NeroAAC process time out -> killing!");
575 process.waitForFinished(-1);
579 while(process.canReadLine())
581 QString line = QString::fromUtf8(process.readLine().constData()).simplified();
582 if(neroAacEncSig.lastIndexIn(line) >= 0)
587 if(neroSigFound && (neroAacEncVer.lastIndexIn(line) >= 0))
590 if(MUtils::regexp_parse_uint32(neroAacEncVer, tmp, 4))
592 neroVersion = (qBound(0U, tmp[0], 9U) * 1000U) + (qBound(0U, tmp[1], 9U) * 100U) + (qBound(0U, tmp[2], 9U) * 10U) + qBound(0U, tmp[3], 9U);
600 qWarning("NeroAAC version could not be determined -> NeroAAC encoding support will be disabled!");
603 else if(neroVersion < lamexp_toolver_neroaac())
605 qWarning("NeroAAC version is too much outdated (%s) -> NeroAAC support will be disabled!", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", neroVersion, "N/A")));
606 qWarning("Minimum required NeroAAC version currently is: %s\n", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", lamexp_toolver_neroaac(), "N/A")));
610 qDebug("Enabled NeroAAC encoder %s.\n", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", neroVersion, "N/A")));
612 for(int i = 0; i < 3; i++)
614 lamexp_tools_register(neroFileInfo[i].fileName(), neroBin[i].take(), neroVersion);
618 void InitializationThread::initAacEnc_FHG(void)
620 const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
622 const QFileInfo fhgFileInfo[5] =
624 QFileInfo(QString("%1/fhgaacenc.exe") .arg(appPath)),
625 QFileInfo(QString("%1/enc_fhgaac.dll") .arg(appPath)),
626 QFileInfo(QString("%1/nsutil.dll") .arg(appPath)),
627 QFileInfo(QString("%1/libmp4v2.dll") .arg(appPath)),
628 QFileInfo(QString("%1/libsndfile-1.dll").arg(appPath))
631 bool fhgFilesFound = true;
632 for(int i = 0; i < 5; i++)
634 if(!(fhgFileInfo[i].exists() && fhgFileInfo[i].isFile()))
636 fhgFilesFound = false;
642 qDebug("FhgAacEnc binaries not found -> FhgAacEnc support will be disabled!\n");
646 if(!MUtils::OS::is_executable_file(fhgFileInfo[0].canonicalFilePath()))
648 qDebug("FhgAacEnc executbale is invalid -> FhgAacEnc support will be disabled!\n");
652 qDebug("Found FhgAacEnc cli_exe:\n%s\n", MUTILS_UTF8(fhgFileInfo[0].canonicalFilePath()));
653 qDebug("Found FhgAacEnc enc_dll:\n%s\n", MUTILS_UTF8(fhgFileInfo[1].canonicalFilePath()));
655 //Lock the FhgAacEnc binaries
656 QScopedPointer<LockedFile> fhgBin[5];
659 for(int i = 0; i < 5; i++)
661 fhgBin[i].reset(new LockedFile(fhgFileInfo[i].canonicalFilePath()));
666 qWarning("Failed to get excluive lock to FhgAacEnc binary -> FhgAacEnc support will be disabled!");
671 MUtils::init_process(process, fhgFileInfo[0].absolutePath());
673 process.start(fhgFileInfo[0].canonicalFilePath(), QStringList() << "--version");
675 if(!process.waitForStarted())
677 qWarning("FhgAacEnc process failed to create!");
678 qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
680 process.waitForFinished(-1);
684 quint32 fhgVersion = 0;
685 QRegExp fhgAacEncSig("fhgaacenc version (\\d+) by tmkk", Qt::CaseInsensitive);
687 while(process.state() != QProcess::NotRunning)
689 process.waitForReadyRead();
690 if(!process.bytesAvailable() && process.state() == QProcess::Running)
692 qWarning("FhgAacEnc process time out -> killing!");
694 process.waitForFinished(-1);
697 while(process.bytesAvailable() > 0)
699 QString line = QString::fromUtf8(process.readLine().constData()).simplified();
700 if(fhgAacEncSig.lastIndexIn(line) >= 0)
703 if(MUtils::regexp_parse_uint32(fhgAacEncSig, tmp))
713 qWarning("FhgAacEnc version couldn't be determined -> FhgAacEnc support will be disabled!");
716 else if(fhgVersion < lamexp_toolver_fhgaacenc())
718 qWarning("FhgAacEnc version is too much outdated (%s) -> FhgAacEnc support will be disabled!", MUTILS_UTF8(lamexp_version2string("????-??-??", fhgVersion, "N/A")));
719 qWarning("Minimum required FhgAacEnc version currently is: %s\n", MUTILS_UTF8(lamexp_version2string("????-??-??", lamexp_toolver_fhgaacenc(), "N/A")));
723 qDebug("Enabled FhgAacEnc %s.\n", MUTILS_UTF8(lamexp_version2string("????-??-??", fhgVersion, "N/A")));
725 for(int i = 0; i < 5; i++)
727 lamexp_tools_register(fhgFileInfo[i].fileName(), fhgBin[i].take(), fhgVersion);
731 void InitializationThread::initAacEnc_QAAC(void)
733 const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
735 const QFileInfo qaacFileInfo[3] =
737 QFileInfo(QString("%1/qaac.exe") .arg(appPath)),
738 QFileInfo(QString("%1/libsoxr.dll") .arg(appPath)),
739 QFileInfo(QString("%1/libsoxconvolver.dll").arg(appPath))
742 bool qaacFilesFound = true;
743 for(int i = 0; i < 3; i++)
745 if(!(qaacFileInfo[i].exists() && qaacFileInfo[i].isFile()))
747 qaacFilesFound = false;
753 qDebug("QAAC binary or companion DLL's not found -> QAAC support will be disabled!\n");
757 if(!MUtils::OS::is_executable_file(qaacFileInfo[0].canonicalFilePath()))
759 qDebug("QAAC executbale is invalid -> QAAC support will be disabled!\n");
763 qDebug("Found QAAC encoder:\n%s\n", MUTILS_UTF8(qaacFileInfo[0].canonicalFilePath()));
765 //Lock the required QAAC binaries
766 QScopedPointer<LockedFile> qaacBin[3];
769 for(int i = 0; i < 3; i++)
771 qaacBin[i].reset(new LockedFile(qaacFileInfo[i].canonicalFilePath()));
776 qWarning("Failed to get excluive lock to QAAC binary -> QAAC support will be disabled!");
781 MUtils::init_process(process, qaacFileInfo[0].absolutePath());
782 process.start(qaacFileInfo[0].canonicalFilePath(), QStringList() << "--check");
784 if(!process.waitForStarted())
786 qWarning("QAAC process failed to create!");
787 qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
789 process.waitForFinished(-1);
793 QRegExp qaacEncSig("qaac (\\d)\\.(\\d+)", Qt::CaseInsensitive);
794 QRegExp coreEncSig("CoreAudioToolbox (\\d)\\.(\\d)\\.(\\d)\\.(\\d)", Qt::CaseInsensitive);
795 QRegExp soxrEncSig("libsoxr-\\d\\.\\d\\.\\d", Qt::CaseInsensitive);
796 QRegExp soxcEncSig("libsoxconvolver \\d\\.\\d\\.\\d", Qt::CaseInsensitive);
798 quint32 qaacVersion = 0;
799 quint32 coreVersion = 0;
800 bool soxrFound = false;
801 bool soxcFound = false;
803 while(process.state() != QProcess::NotRunning)
805 process.waitForReadyRead();
806 if(!process.bytesAvailable() && process.state() == QProcess::Running)
808 qWarning("QAAC process time out -> killing!");
810 process.waitForFinished(-1);
813 while(process.bytesAvailable() > 0)
815 QString line = QString::fromUtf8(process.readLine().constData()).simplified();
816 if(qaacEncSig.lastIndexIn(line) >= 0)
819 if(MUtils::regexp_parse_uint32(qaacEncSig, tmp, 2))
821 qaacVersion = (qBound(0U, tmp[0], 9U) * 100) + qBound(0U, tmp[1], 99U);
824 if(coreEncSig.lastIndexIn(line) >= 0)
827 if(MUtils::regexp_parse_uint32(coreEncSig, tmp, 4))
829 coreVersion = (qBound(0U, tmp[0], 9U) * 1000U) + (qBound(0U, tmp[1], 9U) * 100U) + (qBound(0U, tmp[2], 9U) * 10U) + qBound(0U, tmp[3], 9U);
832 if(soxcEncSig.lastIndexIn(line) >= 0)
836 if(soxrEncSig.lastIndexIn(line) >= 0)
845 qWarning("QAAC version couldn't be determined -> QAAC support will be disabled!");
848 else if(qaacVersion < lamexp_toolver_qaacenc())
850 qWarning("QAAC version is too much outdated (%s) -> QAAC support will be disabled!", MUTILS_UTF8(lamexp_version2string("v?.??", qaacVersion, "N/A")));
851 qWarning("Minimum required QAAC version currently is: %s.\n", MUTILS_UTF8(lamexp_version2string("v?.??", lamexp_toolver_qaacenc(), "N/A")));
857 qWarning("CoreAudioToolbox version couldn't be determined -> QAAC support will be disabled!");
860 else if(coreVersion < lamexp_toolver_coreaudio())
862 qWarning("CoreAudioToolbox version is outdated (%s) -> QAAC support will be disabled!", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", coreVersion, "N/A")));
863 qWarning("Minimum required CoreAudioToolbox version currently is: %s.\n", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", lamexp_toolver_coreaudio(), "N/A")));
867 if(!(soxrFound && soxcFound))
869 qWarning("libsoxr and/or libsoxconvolver not available -> QAAC support will be disabled!\n");
873 qDebug("Enabled qaac encoder %s (using CoreAudioToolbox %s).\n", MUTILS_UTF8(lamexp_version2string("v?.??", qaacVersion, "N/A")), MUTILS_UTF8(lamexp_version2string("v?.?.?.?", coreVersion, "N/A")));
875 for(int i = 0; i < 3; i++)
877 lamexp_tools_register(qaacFileInfo[i].fileName(), qaacBin[i].take(), qaacVersion);
881 ////////////////////////////////////////////////////////////
882 // Self-Test Function
883 ////////////////////////////////////////////////////////////
885 void InitializationThread::selfTest(void)
887 const unsigned int cpu[4] = {CPU_TYPE_X86_GEN, CPU_TYPE_X86_SSE, CPU_TYPE_X64_GEN, CPU_TYPE_X64_SSE};
889 LockedFile::selfTest();
891 for(size_t k = 0; k < 4; k++)
896 PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
897 PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
898 PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
899 PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
900 default: MUTILS_THROW("CPU support undefined!");
903 for(int i = 0; true; i++)
905 if(!(g_lamexp_tools[i].pcName || g_lamexp_tools[i].pcHash || g_lamexp_tools[i].uiVersion))
909 else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
911 const QString toolName = QString::fromLatin1(g_lamexp_tools[i].pcName);
912 const QByteArray expectedHash = QByteArray(g_lamexp_tools[i].pcHash);
913 if(g_lamexp_tools[i].uiCpuType & cpu[k])
915 qDebug("%02i -> %s", ++n, MUTILS_UTF8(toolName));
916 QFile resource(QString(":/tools/%1").arg(toolName));
917 if(!resource.open(QIODevice::ReadOnly))
919 qFatal("The resource for \"%s\" could not be opened!", MUTILS_UTF8(toolName));
922 QByteArray hash = LockedFile::fileHash(resource);
923 if(hash.isNull() || _stricmp(hash.constData(), expectedHash.constData()))
925 qFatal("Hash check for tool \"%s\" has failed!", MUTILS_UTF8(toolName));
933 qFatal("Inconsistent checksum data detected. Take care!");
936 if(n != EXPECTED_TOOL_COUNT)
938 qFatal("Tool count mismatch for CPU type %u !!!", cpu[k]);
944 ////////////////////////////////////////////////////////////
946 ////////////////////////////////////////////////////////////