From 2f38af371e80a82aa4f437a0e402a2ef8a8e578d Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 8 Dec 2017 22:43:18 +0100 Subject: [PATCH] Simplified mpg123 progress computation. --- src/Decoder_MP3.cpp | 18 +++++++++--------- src/Encoder_MP3.cpp | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Decoder_MP3.cpp b/src/Decoder_MP3.cpp index 216a622e..9c3d9a8a 100644 --- a/src/Decoder_MP3.cpp +++ b/src/Decoder_MP3.cpp @@ -70,7 +70,8 @@ bool MP3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA bool bAborted = false; int prevProgress = -1; - QRegExp regExp("\\b\\d+\\+\\d+\\s+(\\d+):(\\d+)\\.(\\d+)\\+(\\d+):(\\d+)\\.(\\d+)\\b"); + //QRegExp regExp("\\b\\d+\\+\\d+\\s+(\\d+):(\\d+)\\.(\\d+)\\+(\\d+):(\\d+)\\.(\\d+)\\b"); + QRegExp regExp("[_=>]\\s+(\\d+)\\+(\\d+)\\s+"); while(process.state() != QProcess::NotRunning) { @@ -96,14 +97,13 @@ bool MP3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { - quint32 values[6]; - if (MUtils::regexp_parse_uint32(regExp, values, 6)) + quint32 values[2]; + if (MUtils::regexp_parse_uint32(regExp, values, 2)) { - const double timeDone = (60.0 * double(values[0])) + double(values[1]) + (double(values[2]) / 100.0); - const double timeLeft = (60.0 * double(values[3])) + double(values[4]) + (double(values[5]) / 100.0); - if ((timeDone >= 0.005) || (timeLeft >= 0.005)) + const quint32 total = values[0] + values[1]; + if ((total >= 512U) && (values[0] >= 256U)) { - const int newProgress = qRound((static_cast(timeDone) / static_cast(timeDone + timeLeft)) * 100.0); + const int newProgress = qRound((static_cast(values[0]) / static_cast(total)) * 100.0); if (newProgress > prevProgress) { emit statusUpdated(newProgress); @@ -147,13 +147,13 @@ bool MP3Decoder::isFormatSupported(const QString &containerType, const QString & QMutexLocker lock(&m_regexMutex); if (m_regxLayer.isNull()) { - m_regxLayer.reset(new QRegExp(L1S("\\bLayer\\s+(1|2|3)\\b"), Qt::CaseInsensitive)); + m_regxLayer.reset(new QRegExp(L1S("^Layer\\s+(1|2|3)\\b"), Qt::CaseInsensitive)); } if (m_regxLayer->indexIn(formatProfile) >= 0) { if (m_regxVersion.isNull()) { - m_regxVersion.reset(new QRegExp(L1S("\\b(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive)); + m_regxVersion.reset(new QRegExp(L1S("^(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive)); } return (m_regxVersion->indexIn(formatVersion) >= 0); } diff --git a/src/Encoder_MP3.cpp b/src/Encoder_MP3.cpp index 165ce071..f37fae8d 100644 --- a/src/Encoder_MP3.cpp +++ b/src/Encoder_MP3.cpp @@ -322,13 +322,13 @@ bool MP3Encoder::isFormatSupported(const QString &containerType, const QString & QMutexLocker lock(&m_regexMutex); if (m_regxLayer.isNull()) { - m_regxLayer.reset(new QRegExp(L1S("\\bLayer\\s+(1|2|3)\\b"), Qt::CaseInsensitive)); + m_regxLayer.reset(new QRegExp(L1S("^Layer\\s+(1|2|3)\\b"), Qt::CaseInsensitive)); } if (m_regxLayer->indexIn(formatProfile) >= 0) { if (m_regxVersion.isNull()) { - m_regxVersion.reset(new QRegExp(L1S("\\b(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive)); + m_regxVersion.reset(new QRegExp(L1S("^(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive)); } return (m_regxVersion->indexIn(formatVersion) >= 0); }