Implemented coalescing of progress updates, in order to reduce the number of signals that are sent to the main/GUI thread. Depending on the encoder/decoder used, this reduces the CPU time consumed by the LameXP process quite a bit.

This commit is contained in:
LoRd_MuldeR 2011-11-16 22:56:32 +01:00
parent a2cae5c288
commit 3f3451e5c1
10 changed files with 72 additions and 15 deletions

View File

@ -27,10 +27,10 @@
#define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 3
#define VER_LAMEXP_TYPE Final
#define VER_LAMEXP_PATCH 2
#define VER_LAMEXP_BUILD 774
#define VER_LAMEXP_MINOR_LO 4
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 1
#define VER_LAMEXP_BUILD 777
///////////////////////////////////////////////////////////////////////////////
// Tools versions

View File

@ -56,6 +56,7 @@ bool MP3Decoder::decode(const QString &sourceFile, const QString &outputFile, vo
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1;
QRegExp regExp("\\s+Time:\\s+(\\d+):(\\d+)\\.(\\d+)\\s+\\[(\\d+):(\\d+)\\.(\\d+)\\],");
@ -94,7 +95,12 @@ bool MP3Decoder::decode(const QString &sourceFile, const QString &outputFile, vo
int timeLeft = (60 * values[3]) + values[4];
if(timeDone > 0 || timeLeft > 0)
{
statusUpdated(static_cast<int>((static_cast<double>(timeDone) / static_cast<double>(timeDone + timeLeft)) * 100.0));
int newProgress = qRound((static_cast<double>(timeDone) / static_cast<double>(timeDone + timeLeft)) * 100.0);
if(newProgress > prevProgress)
{
emit statusUpdated(newProgress);
prevProgress = qMin(newProgress + 2, 99);
}
}
}
else if(!text.isEmpty())

View File

@ -56,6 +56,7 @@ bool VorbisDecoder::decode(const QString &sourceFile, const QString &outputFile,
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1;
QRegExp regExp(" (\\d+)% decoded.");
@ -85,7 +86,11 @@ bool VorbisDecoder::decode(const QString &sourceFile, const QString &outputFile,
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
}
}
else if(!text.isEmpty())
{

View File

@ -97,6 +97,8 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInf
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1;
QRegExp regExp("Processed\\s+(\\d+)\\s+seconds");
QRegExp regExp_pass1("First\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds");
@ -130,7 +132,12 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInf
int progress = regExp_pass1.cap(1).toInt(&ok);
if(ok && metaInfo.fileDuration() > 0)
{
emit statusUpdated(static_cast<int>((static_cast<double>(progress) / static_cast<double>(metaInfo.fileDuration())) * 50.0));
int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(metaInfo.fileDuration())) * 50.0);
if(newProgress > prevProgress)
{
emit statusUpdated(newProgress);
prevProgress = qMin(newProgress + 2, 99);
}
}
}
else if(regExp_pass2.lastIndexIn(text) >= 0)
@ -139,7 +146,12 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInf
int progress = regExp_pass2.cap(1).toInt(&ok);
if(ok && metaInfo.fileDuration() > 0)
{
emit statusUpdated(static_cast<int>((static_cast<double>(progress) / static_cast<double>(metaInfo.fileDuration())) * 50.0) + 50);
int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(metaInfo.fileDuration())) * 50.0) + 50;
if(newProgress > prevProgress)
{
emit statusUpdated(newProgress);
prevProgress = qMin(newProgress + 2, 99);
}
}
}
else if(regExp.lastIndexIn(text) >= 0)
@ -148,7 +160,12 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInf
int progress = regExp.cap(1).toInt(&ok);
if(ok && metaInfo.fileDuration() > 0)
{
emit statusUpdated(static_cast<int>((static_cast<double>(progress) / static_cast<double>(metaInfo.fileDuration())) * 100.0));
int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(metaInfo.fileDuration())) * 100.0);
if(newProgress > prevProgress)
{
emit statusUpdated(newProgress);
prevProgress = qMin(newProgress + 2, 99);
}
}
}
else if(!text.isEmpty())

View File

@ -97,6 +97,7 @@ bool FHGAACEncoder::encode(const QString &sourceFile, const AudioFileModel &meta
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1;
QRegExp regExp("Progress:\\s*(\\d+)%");
@ -126,7 +127,11 @@ bool FHGAACEncoder::encode(const QString &sourceFile, const AudioFileModel &meta
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
}
}
else if(!text.isEmpty())
{

View File

@ -93,6 +93,7 @@ bool AC3Encoder::encode(const QString &sourceFile, const AudioFileModel &metaInf
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1;
QRegExp regExp("progress:(\\s+)(\\d+)%(\\s+)\\|");
@ -122,7 +123,11 @@ bool AC3Encoder::encode(const QString &sourceFile, const AudioFileModel &metaInf
{
bool ok = false;
int progress = regExp.cap(2).toInt(&ok);
if(ok) emit statusUpdated(progress);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
}
}
else if(!text.isEmpty())
{

View File

@ -71,6 +71,7 @@ bool FLACEncoder::encode(const QString &sourceFile, const AudioFileModel &metaIn
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1;
QRegExp regExp("\\s(\\d+)% complete");
@ -100,7 +101,11 @@ bool FLACEncoder::encode(const QString &sourceFile, const AudioFileModel &metaIn
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
}
}
else if(!text.isEmpty())
{

View File

@ -139,6 +139,7 @@ bool MP3Encoder::encode(const QString &sourceFile, const AudioFileModel &metaInf
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1;
QRegExp regExp("\\(.*(\\d+)%\\)\\|");
@ -168,7 +169,11 @@ bool MP3Encoder::encode(const QString &sourceFile, const AudioFileModel &metaInf
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
}
}
else if(!text.isEmpty())
{

View File

@ -97,6 +97,7 @@ bool VorbisEncoder::encode(const QString &sourceFile, const AudioFileModel &meta
bool bTimeout = false;
bool bAborted = false;
int prevProgress = -1;
QRegExp regExp("\\[.*(\\d+)[.,](\\d+)%\\]");
@ -126,7 +127,11 @@ bool VorbisEncoder::encode(const QString &sourceFile, const AudioFileModel &meta
{
bool ok = false;
int progress = regExp.cap(1).toInt(&ok);
if(ok) emit statusUpdated(progress);
if(ok && (progress > prevProgress))
{
emit statusUpdated(progress);
prevProgress = qMin(progress + 2, 99);
}
}
else if(!text.isEmpty())
{

View File

@ -209,6 +209,8 @@ void ProcessThread::processFile()
bSuccess = fileInfo.exists() && fileInfo.isFile() && (fileInfo.size() > 0);
}
QThread::msleep(500);
//Report result
emit processStateChanged(m_jobId, (bSuccess ? tr("Done.") : (m_aborted ? tr("Aborted!") : tr("Failed!"))), (bSuccess ? ProgressModel::JobComplete : ProgressModel::JobFailed));
emit processStateFinished(m_jobId, outFileName, bSuccess);
@ -222,6 +224,8 @@ void ProcessThread::processFile()
void ProcessThread::handleUpdate(int progress)
{
//printf("Progress: %d\n", progress);
switch(m_currentStep)
{
case EncodingStep: