Small code clean-up.

This commit is contained in:
LoRd_MuldeR 2018-12-07 14:12:31 +01:00
parent 4e984329f0
commit 926eb88a64
2 changed files with 12 additions and 12 deletions

View File

@ -34,8 +34,15 @@ static const int g_mp3BitrateLUT[15] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 16
static const int g_lameVBRQualityLUT[11] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0, INT_MAX}; static const int g_lameVBRQualityLUT[11] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0, INT_MAX};
//Static //Static
QScopedPointer<QRegExp> MP3Encoder::m_regxLayer, MP3Encoder::m_regxVersion;
QMutex MP3Encoder::m_regexMutex; QMutex MP3Encoder::m_regexMutex;
MUtils::Lazy<QRegExp> MP3Encoder::m_regxLayer([]
{
return new QRegExp(L1S("^Layer\\s+(1|2|3)\\b"), Qt::CaseInsensitive);
});
MUtils::Lazy<QRegExp> MP3Encoder::m_regxVersion([]
{
return new QRegExp(L1S("^(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive);
});
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Encoder Info // Encoder Info
@ -281,17 +288,9 @@ bool MP3Encoder::isFormatSupported(const QString &containerType, const QString &
else if (formatType.compare(mpegAudio, Qt::CaseInsensitive) == 0) else if (formatType.compare(mpegAudio, Qt::CaseInsensitive) == 0)
{ {
QMutexLocker lock(&m_regexMutex); QMutexLocker lock(&m_regexMutex);
if (m_regxLayer.isNull()) if ((*m_regxLayer).indexIn(formatProfile) >= 0)
{ {
m_regxLayer.reset(new QRegExp(L1S("^Layer\\s+(1|2|3)\\b"), Qt::CaseInsensitive)); return ((*m_regxVersion).indexIn(formatVersion) >= 0);
}
if (m_regxLayer->indexIn(formatProfile) >= 0)
{
if (m_regxVersion.isNull())
{
m_regxVersion.reset(new QRegExp(L1S("^(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive));
}
return (m_regxVersion->indexIn(formatVersion) >= 0);
} }
} }
} }

View File

@ -25,6 +25,7 @@
#include "Encoder_Abstract.h" #include "Encoder_Abstract.h"
#include <QObject> #include <QObject>
#include <MUtils/Lazy.h>
class MP3Encoder : public AbstractEncoder class MP3Encoder : public AbstractEncoder
{ {
@ -55,7 +56,7 @@ private:
int m_configChannelMode; int m_configChannelMode;
static QMutex m_regexMutex; static QMutex m_regexMutex;
static QScopedPointer<QRegExp> m_regxLayer, m_regxVersion; static MUtils::Lazy<QRegExp> m_regxLayer, m_regxVersion;
int clipBitrate(int bitrate); int clipBitrate(int bitrate);
}; };