Refactored all decoder classes to use awaitProcess() from Tool_Abstract base class.

This commit is contained in:
LoRd_MuldeR 2017-12-10 18:53:47 +01:00
parent 4d7b7a766a
commit 7288244a27
18 changed files with 277 additions and 748 deletions

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 6 #define VER_LAMEXP_MINOR_LO 6
#define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 1 #define VER_LAMEXP_PATCH 1
#define VER_LAMEXP_BUILD 2066 #define VER_LAMEXP_BUILD 2068
#define VER_LAMEXP_CONFG 2002 #define VER_LAMEXP_CONFG 2002
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -60,62 +60,28 @@ bool AACDecoder::decode(const QString &sourceFile, const QString &outputFile, QA
return false; return false;
} }
bool bTimeout = false; int prevProgress = -1;
bool bAborted = false;
QRegExp regExp("\\[(\\d+)%\\]\\s+decoding\\s+"); QRegExp regExp("\\[(\\d+)%\\]\\s+decoding\\s+");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("FAAD process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
}
else if(!text.isEmpty())
{
emit messageLogged(text);
} }
} }
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool AACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool AACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -53,69 +53,37 @@ bool AC3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA
QStringList args; QStringList args;
args << QDir::toNativeSeparators(sourceFile); args << QDir::toNativeSeparators(sourceFile);
args << "-i" << "-w" << QDir::toNativeSeparators(outputFile); args << "-w" << QDir::toNativeSeparators(outputFile);
if(!startProcess(process, m_binary, args)) if(!startProcess(process, m_binary, args))
{ {
return false; return false;
} }
bool bTimeout = false; int prevProgress = -1;
bool bAborted = false; QRegExp regExp("\\b\\s*(\\d+)\\.(\\d+)?%(\\s+)Frames", Qt::CaseInsensitive);
QRegExp regExp("\\b(\\s*)(\\d+)\\.(\\d+)%(\\s+)Frames"); const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
while(process.state() != QProcess::NotRunning)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qWarning("Found! [\"%s\"]", MUTILS_UTF8(regExp.cap(1)));
bAborted = true; qint32 newProgress;
emit messageLogged("\nABORTED BY USER !!!"); if (MUtils::regexp_parse_int32(regExp, newProgress))
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); qWarning("newProgress: %d", newProgress);
qWarning("Valdec process timed out <-- killing!"); if (newProgress > prevProgress)
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(2).toInt(&ok);
if(ok) emit statusUpdated(progress);
}
else if(!text.isEmpty())
{
emit messageLogged(text);
} }
} }
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool AC3Decoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool AC3Decoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -62,62 +62,28 @@ bool ADPCMDecoder::decode(const QString &sourceFile, const QString &outputFile,
return false; return false;
} }
bool bTimeout = false; int prevProgress = -1;
bool bAborted = false;
QRegExp regExp("In:(\\d+)(\\.\\d+)*%"); QRegExp regExp("In:(\\d+)(\\.\\d+)*%");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("Sox process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
}
else if(!text.isEmpty())
{
emit messageLogged(text);
} }
} }
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool ADPCMDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool ADPCMDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -62,75 +62,29 @@ bool ALACDecoder::decode(const QString &sourceFile, const QString &outputFile, Q
return false; return false;
} }
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1; int prevProgress = -1;
//The ALAC Decoder doesn't actually send any status updates :-[
//emit statusUpdated(20 + (QUuid::createUuid().data1 % 60));
QRegExp regExp("\\[(\\d+)\\.(\\d)%\\]"); QRegExp regExp("\\[(\\d+)\\.(\\d)%\\]");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 intVal[2];
bAborted = true; if (MUtils::regexp_parse_int32(regExp, intVal, 2))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); const int newProgress = qRound(static_cast<double>(intVal[0]) + (static_cast<double>(intVal[1]) / 10.0));
qWarning("ALAC process timed out <-- killing!"); if (newProgress > prevProgress)
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
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])
{
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);
} }
} }
}
else if(!text.isEmpty())
{
emit messageLogged(text);
}
}
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool ALACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool ALACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -61,62 +61,28 @@ bool AvisynthDecoder::decode(const QString &sourceFile, const QString &outputFil
return false; return false;
} }
bool bTimeout = false; int prevProgress = -1;
bool bAborted = false; QRegExp regExp("\\d+/\\d+ \\[(\\d+)%\\]");
QRegExp regExp("(\\d+)/(\\d+) \\[(\\d+)%\\]"); const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
while(process.state() != QProcess::NotRunning)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("AVS2WAV process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(3).toInt(&ok);
if(ok) emit statusUpdated(progress);
}
else if(!text.isEmpty())
{
emit messageLogged(text);
} }
} }
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool AvisynthDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool AvisynthDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -61,62 +61,28 @@ bool FLACDecoder::decode(const QString &sourceFile, const QString &outputFile, Q
return false; return false;
} }
bool bTimeout = false; int prevProgress = -1;
bool bAborted = false;
QRegExp regExp("\\b(\\d+)% complete"); QRegExp regExp("\\b(\\d+)% complete");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("FLAC process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine().replace('\b', char(0x20)); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
}
else if(!text.isEmpty())
{
emit messageLogged(text);
} }
} }
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool FLACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool FLACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -61,67 +61,28 @@ bool MACDecoder::decode(const QString &sourceFile, const QString &outputFile, QA
return false; return false;
} }
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1; int prevProgress = -1;
QRegExp regExp("Progress: (\\d+).(\\d+)%"); QRegExp regExp("Progress: (\\d+).(\\d+)%");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("MAC process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
} }
} }
else if(!text.isEmpty())
{
emit messageLogged(text);
}
}
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool MACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool MACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -43,7 +43,7 @@ MP3Decoder::MP3Decoder(void)
: :
m_binary(lamexp_tools_lookup("mpg123.exe")) 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!"); MUTILS_THROW("Error initializing MPG123 decoder. Tool 'mpg123.exe' is not registred!");
} }
@ -61,41 +61,17 @@ bool MP3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA
args << "-v" << "--utf8" << "-w" << QDir::toNativeSeparators(outputFile); args << "-v" << "--utf8" << "-w" << QDir::toNativeSeparators(outputFile);
args << QDir::toNativeSeparators(sourceFile); args << QDir::toNativeSeparators(sourceFile);
if(!startProcess(process, m_binary, args)) if (!startProcess(process, m_binary, args))
{ {
return false; return false;
} }
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1; int prevProgress = -1;
//QRegExp regExp("\\b\\d+\\+\\d+\\s+(\\d+):(\\d+)\\.(\\d+)\\+(\\d+):(\\d+)\\.(\\d+)\\b");
QRegExp regExp("[_=>]\\s+(\\d+)\\+(\\d+)\\s+"); QRegExp regExp("[_=>]\\s+(\\d+)\\+(\\d+)\\s+");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{
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)
{
QByteArray line = process.readLine();
QString text = QString::fromUtf8(line.constData()).simplified();
if(regExp.lastIndexIn(text) >= 0)
{ {
quint32 values[2]; quint32 values[2];
if (MUtils::regexp_parse_uint32(regExp, values, 2)) if (MUtils::regexp_parse_uint32(regExp, values, 2))
@ -111,30 +87,12 @@ bool MP3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA
} }
} }
} }
}
else if(!text.isEmpty())
{
emit messageLogged(text);
}
}
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool MP3Decoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool MP3Decoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -62,67 +62,28 @@ bool MusepackDecoder::decode(const QString &sourceFile, const QString &outputFil
return false; return false;
} }
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1; int prevProgress = -1;
QRegExp regExp("Decoding progress: (\\d+)\\.(\\d+)%"); QRegExp regExp("Decoding progress: (\\d+)\\.(\\d+)%");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("MpcDec process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
} }
} }
else if(!text.isEmpty())
{
emit messageLogged(text);
}
}
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool MusepackDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool MusepackDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -68,67 +68,28 @@ bool OpusDecoder::decode(const QString &sourceFile, const QString &outputFile, Q
return false; return false;
} }
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1; int prevProgress = -1;
QRegExp regExp("\\((\\d+)%\\)"); QRegExp regExp("\\((\\d+)%\\)");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("opusdec process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
} }
} }
else if(!text.isEmpty())
{
emit messageLogged(text);
}
}
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool OpusDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool OpusDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -61,60 +61,18 @@ bool SpeexDecoder::decode(const QString &sourceFile, const QString &outputFile,
return false; return false;
} }
bool bTimeout = false;
bool bAborted = false;
QRegExp regExp("Working\\.\\.\\. (.)"); QRegExp regExp("Working\\.\\.\\. (.)");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill();
bAborted = true;
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{
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);
}
}
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool SpeexDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool SpeexDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -62,62 +62,28 @@ bool TTADecoder::decode(const QString &sourceFile, const QString &outputFile, QA
return false; return false;
} }
bool bTimeout = false; int prevProgress = -1;
bool bAborted = false;
QRegExp regExp("Progress: (\\d+)%"); QRegExp regExp("Progress: (\\d+)%");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("TTAEnc process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
}
else if(!text.isEmpty())
{
emit messageLogged(text);
} }
} }
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool TTADecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool TTADecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -60,67 +60,28 @@ bool VorbisDecoder::decode(const QString &sourceFile, const QString &outputFile,
return false; return false;
} }
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1; int prevProgress = -1;
QRegExp regExp("\\s+(\\d+)% decoded.");
QRegExp regExp(" (\\d+)% decoded."); const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
while(process.state() != QProcess::NotRunning)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("OggDec process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
} }
} }
else if(!text.isEmpty())
{
emit messageLogged(text);
}
}
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool VorbisDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool VorbisDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -62,62 +62,28 @@ bool WMADecoder::decode(const QString &sourceFile, const QString &outputFile, QA
return false; return false;
} }
bool bTimeout = false; int prevProgress = -1;
bool bAborted = false;
QRegExp regExp("\\[(\\d+)\\.(\\d+)%\\]"); QRegExp regExp("\\[(\\d+)\\.(\\d+)%\\]");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress, 2U))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("wma2wav process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
}
else if(!text.isEmpty())
{
emit messageLogged(text);
} }
} }
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool WMADecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool WMADecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -61,67 +61,28 @@ bool WavPackDecoder::decode(const QString &sourceFile, const QString &outputFile
return false; return false;
} }
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1; int prevProgress = -1;
QRegExp regExp("(\\s|\b)(\\d+)%\\s+done"); QRegExp regExp("(\\s|\b)(\\d+)%\\s+done");
while(process.state() != QProcess::NotRunning) const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
{ {
if(checkFlag(abortFlag)) if (regExp.lastIndexIn(text) >= 0)
{ {
process.kill(); qint32 newProgress;
bAborted = true; if (MUtils::regexp_parse_int32(regExp, newProgress, 2U))
emit messageLogged("\nABORTED BY USER !!!");
break;
}
process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{ {
process.kill(); if (newProgress > prevProgress)
qWarning("WvUnpack process timed out <-- killing!");
emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); emit statusUpdated(newProgress);
QString text = QString::fromUtf8(line.constData()).simplified(); prevProgress = qMin(newProgress + 2, 99);
if(regExp.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = regExp.cap(2).toInt(&ok);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
} }
} }
else if(!text.isEmpty())
{
emit messageLogged(text);
}
}
}
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 true;
}
return false;
});
return (result == RESULT_SUCCESS);
} }
bool WavPackDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) bool WavPackDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -156,6 +156,84 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
return false; return false;
} }
/*
* 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 * Convert program arguments to single string
*/ */

View File

@ -24,6 +24,7 @@
#include <MUtils\Global.h> #include <MUtils\Global.h>
#include <QObject> #include <QObject>
#include <functional>
class QMutex; class QMutex;
class QProcess; class QProcess;
@ -42,9 +43,6 @@ public:
AbstractTool(void); AbstractTool(void);
~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: signals:
void statusUpdated(int progress); void statusUpdated(int progress);
void messageLogged(const QString &line); void messageLogged(const QString &line);
@ -52,11 +50,25 @@ signals:
protected: protected:
static const int m_processTimeoutInterval = 600000; 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) static __forceinline bool checkFlag(QAtomicInt &flag)
{ {
return MUTILS_BOOLIFY(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: private:
static QScopedPointer<MUtils::JobObject> s_jobObjectInstance; static QScopedPointer<MUtils::JobObject> s_jobObjectInstance;
static QScopedPointer<QElapsedTimer> s_startProcessTimer; static QScopedPointer<QElapsedTimer> s_startProcessTimer;