OSDN Git Service

Implemented coalescing of progress updates, in order to reduce the number of signals...
authorlordmulder <mulder2@gmx.de>
Wed, 16 Nov 2011 21:56:32 +0000 (22:56 +0100)
committerlordmulder <mulder2@gmx.de>
Wed, 16 Nov 2011 21:56:32 +0000 (22:56 +0100)
src/Config.h
src/Decoder_MP3.cpp
src/Decoder_Vorbis.cpp
src/Encoder_AAC.cpp
src/Encoder_AAC_FHG.cpp
src/Encoder_AC3.cpp
src/Encoder_FLAC.cpp
src/Encoder_MP3.cpp
src/Encoder_Vorbis.cpp
src/Thread_Process.cpp

index 282a167..082629c 100644 (file)
 
 #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
index 4db4d08..0c16f75 100644 (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())
index a63392c..abe0bae 100644 (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())
                        {
index ceb99c0..2f31184 100644 (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())
index 13d8f98..1f1b7e1 100644 (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())
                        {
index d6aed47..ed2a126 100644 (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())
                        {
index 04042a3..0f46c38 100644 (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())
                        {
index 2b85161..687ed7f 100644 (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())
                        {
index 65fa8e4..a2cb397 100644 (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())
                        {
index 716f79a..2a6a1a3 100644 (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:
@@ -433,4 +437,4 @@ void ProcessThread::setRenamePattern(const QString &pattern)
 // EVENTS
 ////////////////////////////////////////////////////////////
 
-/*NONE*/
+/*NONE*/
\ No newline at end of file