#define VER_LAMEXP_MINOR_LO 6
#define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 1
-#define VER_LAMEXP_BUILD 2066
+#define VER_LAMEXP_BUILD 2068
#define VER_LAMEXP_CONFG 2002
///////////////////////////////////////////////////////////////////////////////
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
-
+ int prevProgress = -1;
QRegExp regExp("\\[(\\d+)%\\]\\s+decoding\\s+");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("FAAD process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok) emit statusUpdated(progress);
- }
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
+ if (newProgress > prevProgress)
+ {
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
+ }
}
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool AACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
QStringList args;
args << QDir::toNativeSeparators(sourceFile);
- args << "-i" << "-w" << QDir::toNativeSeparators(outputFile);
+ args << "-w" << QDir::toNativeSeparators(outputFile);
if(!startProcess(process, m_binary, args))
{
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
+ int prevProgress = -1;
+ QRegExp regExp("\\b\\s*(\\d+)\\.(\\d+)?%(\\s+)Frames", Qt::CaseInsensitive);
- QRegExp regExp("\\b(\\s*)(\\d+)\\.(\\d+)%(\\s+)Frames");
-
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("Valdec process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
- {
- bool ok = false;
- int progress = regExp.cap(2).toInt(&ok);
- if(ok) emit statusUpdated(progress);
- }
- else if(!text.isEmpty())
+ qWarning("Found! [\"%s\"]", MUTILS_UTF8(regExp.cap(1)));
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- emit messageLogged(text);
+ qWarning("newProgress: %d", newProgress);
+ if (newProgress > prevProgress)
+ {
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
+ }
}
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
-
- return true;
+ });
+
+ return (result == RESULT_SUCCESS);
}
bool AC3Decoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
-
+ int prevProgress = -1;
QRegExp regExp("In:(\\d+)(\\.\\d+)*%");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("Sox process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
- {
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok) emit statusUpdated(progress);
- }
- else if(!text.isEmpty())
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- emit messageLogged(text);
+ if (newProgress > prevProgress)
+ {
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
+ }
}
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool ADPCMDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
- //The ALAC Decoder doesn't actually send any status updates :-[
- //emit statusUpdated(20 + (QUuid::createUuid().data1 % 60));
QRegExp regExp("\\[(\\d+)\\.(\\d)%\\]");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("ALAC process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 intVal[2];
+ if (MUtils::regexp_parse_int32(regExp, intVal, 2))
{
- bool ok[2] = {false, false};
- int intVal[2] = {0, 0};
- intVal[0] = regExp.cap(1).toInt(&ok[0]);
- intVal[1] = regExp.cap(2).toInt(&ok[1]);
- if(ok[0] && ok[1])
+ const int newProgress = qRound(static_cast<double>(intVal[0]) + (static_cast<double>(intVal[1]) / 10.0));
+ if (newProgress > prevProgress)
{
- int progress = qRound(static_cast<double>(intVal[0]) + (static_cast<double>(intVal[1]) / 10.0));
- if(progress > prevProgress)
- {
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
- }
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
-
- return true;
+ });
+
+ return (result == RESULT_SUCCESS);
}
bool ALACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
+ int prevProgress = -1;
+ QRegExp regExp("\\d+/\\d+ \\[(\\d+)%\\]");
- QRegExp regExp("(\\d+)/(\\d+) \\[(\\d+)%\\]");
-
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("AVS2WAV process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
- {
- bool ok = false;
- int progress = regExp.cap(3).toInt(&ok);
- if(ok) emit statusUpdated(progress);
- }
- else if(!text.isEmpty())
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- emit messageLogged(text);
+ if (newProgress > prevProgress)
+ {
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
+ }
}
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool AvisynthDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
-
+ int prevProgress = -1;
QRegExp regExp("\\b(\\d+)% complete");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("FLAC process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine().replace('\b', char(0x20));
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
- {
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok) emit statusUpdated(progress);
- }
- else if(!text.isEmpty())
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- emit messageLogged(text);
+ if (newProgress > prevProgress)
+ {
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
+ }
}
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool FLACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp("Progress: (\\d+).(\\d+)%");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("MAC process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool MACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
:
m_binary(lamexp_tools_lookup("mpg123.exe"))
{
- if(m_binary.isEmpty())
+ if (m_binary.isEmpty())
{
MUTILS_THROW("Error initializing MPG123 decoder. Tool 'mpg123.exe' is not registred!");
}
args << "-v" << "--utf8" << "-w" << QDir::toNativeSeparators(outputFile);
args << QDir::toNativeSeparators(sourceFile);
- if(!startProcess(process, m_binary, args))
+ if (!startProcess(process, m_binary, args))
{
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
- //QRegExp regExp("\\b\\d+\\+\\d+\\s+(\\d+):(\\d+)\\.(\\d+)\\+(\\d+):(\\d+)\\.(\\d+)\\b");
QRegExp regExp("[_=>]\\s+(\\d+)\\+(\\d+)\\s+");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("mpg123 process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ quint32 values[2];
+ if (MUtils::regexp_parse_uint32(regExp, values, 2))
{
- quint32 values[2];
- if (MUtils::regexp_parse_uint32(regExp, values, 2))
+ const quint32 total = values[0] + values[1];
+ if ((total >= 512U) && (values[0] >= 256U))
{
- const quint32 total = values[0] + values[1];
- if ((total >= 512U) && (values[0] >= 256U))
+ const int newProgress = qRound((static_cast<double>(values[0]) / static_cast<double>(total)) * 100.0);
+ if (newProgress > prevProgress)
{
- const int newProgress = qRound((static_cast<double>(values[0]) / static_cast<double>(total)) * 100.0);
- if (newProgress > prevProgress)
- {
- emit statusUpdated(newProgress);
- prevProgress = qMin(newProgress + 2, 99);
- }
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
-
- return true;
+ });
+
+ return (result == RESULT_SUCCESS);
}
bool MP3Decoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp("Decoding progress: (\\d+)\\.(\\d+)%");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("MpcDec process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool MusepackDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp("\\((\\d+)%\\)");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("opusdec process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
-
- return true;
+ });
+
+ return (result == RESULT_SUCCESS);
}
bool OpusDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
-
QRegExp regExp("Working\\.\\.\\. (.)");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- qWarning("SpeexDec process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
- {
- /* qDebug("Status: %s", regExp.cap(1).toLatin1().constData()); */
- }
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool SpeexDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
-
+ int prevProgress = -1;
QRegExp regExp("Progress: (\\d+)%");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("TTAEnc process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
- {
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok) emit statusUpdated(progress);
- }
- else if(!text.isEmpty())
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- emit messageLogged(text);
+ if (newProgress > prevProgress)
+ {
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
+ }
}
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool TTADecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
+ QRegExp regExp("\\s+(\\d+)% decoded.");
- QRegExp regExp(" (\\d+)% decoded.");
-
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("OggDec process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool VorbisDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
-
+ int prevProgress = -1;
QRegExp regExp("\\[(\\d+)\\.(\\d+)%\\]");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("wma2wav process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
- {
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok) emit statusUpdated(progress);
- }
- else if(!text.isEmpty())
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress, 2U))
{
- emit messageLogged(text);
+ if (newProgress > prevProgress)
+ {
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
+ }
}
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool WMADecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp("(\\s|\b)(\\d+)%\\s+done");
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged("\nABORTED BY USER !!!");
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("WvUnpack process timed out <-- killing!");
- emit messageLogged("\nPROCESS TIMEOUT !!!");
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
+ if (regExp.lastIndexIn(text) >= 0)
{
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress, 2U))
{
- bool ok = false;
- int progress = regExp.cap(2).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool WavPackDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
}
/*
+* Wait for process to terminate while processing its output
+*/
+AbstractTool::result_t AbstractTool::awaitProcess(QProcess &process, QAtomicInt &abortFlag, std::function<bool(const QString &text)> &&handler, int *const exitCode)
+{
+ bool bTimeout = false;
+ bool bAborted = false;
+
+ QString lastText;
+
+ while (process.state() != QProcess::NotRunning)
+ {
+ if (checkFlag(abortFlag))
+ {
+ process.kill();
+ bAborted = true;
+ emit messageLogged("\nABORTED BY USER !!!");
+ break;
+ }
+
+ process.waitForReadyRead(m_processTimeoutInterval);
+ if (!process.bytesAvailable() && process.state() == QProcess::Running)
+ {
+ process.kill();
+ qWarning("Tool process timed out <-- killing!");
+ emit messageLogged("\nPROCESS TIMEOUT !!!");
+ bTimeout = true;
+ break;
+ }
+
+ while (process.bytesAvailable() > 0)
+ {
+ QByteArray line = process.readLine();
+ if (line.size() > 0)
+ {
+ static const char REPALCE_CHARS[3] = { '\r', '\b', '\t' };
+ for (size_t i = 0; i < MUTILS_ARR2LEN(REPALCE_CHARS); ++i)
+ {
+ line.replace(REPALCE_CHARS[i], char(0x20));
+ }
+ const QString text = QString::fromUtf8(line.constData()).simplified();
+ if (!text.isEmpty())
+ {
+ if (!handler(text))
+ {
+ if (text.compare(lastText, Qt::CaseInsensitive) != 0)
+ {
+ emit messageLogged(lastText = text);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ process.waitForFinished();
+ if (process.state() != QProcess::NotRunning)
+ {
+ process.kill();
+ process.waitForFinished(-1);
+ }
+
+ if (exitCode)
+ {
+ *exitCode = process.exitCode();
+ }
+
+ emit statusUpdated(100);
+ emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
+
+ if (bAborted || bTimeout || (process.exitCode() != EXIT_SUCCESS))
+ {
+ return bAborted ? RESULT_ABORTED : (bTimeout ? RESULT_TIMEOUT : RESULT_FAILURE);
+ }
+
+ return RESULT_SUCCESS;
+}
+
+/*
* Convert program arguments to single string
*/
QString AbstractTool::commandline2string(const QString &program, const QStringList &arguments)
#include <MUtils\Global.h>
#include <QObject>
+#include <functional>
class QMutex;
class QProcess;
AbstractTool(void);
~AbstractTool(void);
- bool startProcess(QProcess &process, const QString &program, const QStringList &args, const QString &workingDir = QString());
- static QString commandline2string(const QString &program, const QStringList &arguments);
-
signals:
void statusUpdated(int progress);
void messageLogged(const QString &line);
protected:
static const int m_processTimeoutInterval = 600000;
-
+
+ typedef enum
+ {
+ RESULT_ABORTED = -2,
+ RESULT_TIMEOUT = -1,
+ RESULT_FAILURE = 0,
+ RESULT_SUCCESS = 1
+ }
+ result_t;
+
static __forceinline bool checkFlag(QAtomicInt &flag)
{
return MUTILS_BOOLIFY(flag);
}
+ static QString commandline2string(const QString &program, const QStringList &arguments);
+
+ bool startProcess(QProcess &process, const QString &program, const QStringList &args, const QString &workingDir = QString());
+ result_t awaitProcess(QProcess &process, QAtomicInt &abortFlag, std::function<bool(const QString &text)> &&handler, int *const exitCode = NULL);
+
private:
static QScopedPointer<MUtils::JobObject> s_jobObjectInstance;
static QScopedPointer<QElapsedTimer> s_startProcessTimer;