OSDN Git Service

Fixed detection of MPEG Audio files.
authorLoRd_MuldeR <mulder2@gmx.de>
Sat, 2 Dec 2017 13:55:40 +0000 (14:55 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Sat, 2 Dec 2017 13:55:40 +0000 (14:55 +0100)
src/Config.h
src/Decoder_MP3.cpp
src/Encoder_MP3.cpp
src/Encoder_MP3.h

index 52ae739..8cba58e 100644 (file)
@@ -34,8 +34,8 @@
 #define VER_LAMEXP_MINOR_HI                                    1
 #define VER_LAMEXP_MINOR_LO                                    6
 #define VER_LAMEXP_TYPE                                                Alpha
-#define VER_LAMEXP_PATCH                                       9
-#define VER_LAMEXP_BUILD                                       2056
+#define VER_LAMEXP_PATCH                                       10
+#define VER_LAMEXP_BUILD                                       2058
 #define VER_LAMEXP_CONFG                                       2002
 
 ///////////////////////////////////////////////////////////////////////////////
index d293f0f..216a622 100644 (file)
@@ -139,19 +139,22 @@ bool MP3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA
 
 bool MP3Decoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
 {
-       const QLatin1String mpegAudio("MPEG Audio"), waveAudio("Wave");
+       static const QLatin1String mpegAudio("MPEG Audio"), waveAudio("Wave");
        if((containerType.compare(mpegAudio, Qt::CaseInsensitive) == 0) || (containerType.compare(waveAudio, Qt::CaseInsensitive) == 0))
        {
                if(formatType.compare(mpegAudio, Qt::CaseInsensitive) == 0)
                {
                        QMutexLocker lock(&m_regexMutex);
-                       if (m_regxLayer.isNull() || m_regxVersion.isNull())
+                       if (m_regxLayer.isNull())
                        {
-                               m_regxLayer.reset(new QRegExp("\\bLayer\\s+(1|2|3)\\b", Qt::CaseInsensitive));
-                               m_regxVersion.reset(new QRegExp("\\bVersion\\s+(1|2|2\\.5)\\b", Qt::CaseInsensitive));
+                               m_regxLayer.reset(new QRegExp(L1S("\\bLayer\\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));
+                               }
                                return (m_regxVersion->indexIn(formatVersion) >= 0);
                        }
                }
index 5884a03..165ce07 100644 (file)
@@ -33,6 +33,10 @@ static const int g_lameAgorithmQualityLUT[5] = {7, 5, 2, 0, INT_MAX};
 static const int g_mp3BitrateLUT[15] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1};
 static const int g_lameVBRQualityLUT[11] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0, INT_MAX};
 
+//Static
+QScopedPointer<QRegExp> MP3Encoder::m_regxLayer, MP3Encoder::m_regxVersion;
+QMutex MP3Encoder::m_regexMutex;
+
 ///////////////////////////////////////////////////////////////////////////////
 // Encoder Info
 ///////////////////////////////////////////////////////////////////////////////
@@ -305,16 +309,28 @@ bool MP3Encoder::isFormatSupported(const QString &containerType, const QString &
                        return true;
                }
        }
-       else if(containerType.compare(L1S("MPEG Audio"), Qt::CaseInsensitive) == 0)
+
+       static const QLatin1String mpegAudio("MPEG Audio"), waveAudio("Wave"), pcmFormat("PCM");
+       if ((containerType.compare(mpegAudio, Qt::CaseInsensitive) == 0) || (containerType.compare(waveAudio, Qt::CaseInsensitive) == 0))
        {
-               if(formatType.compare(L1S("MPEG Audio"), Qt::CaseInsensitive) == 0)
+               if (formatType.compare(pcmFormat, Qt::CaseInsensitive) == 0)
                {
-                       if(formatProfile.compare(L1S("Layer 3"), Qt::CaseInsensitive) == 0 || formatProfile.compare(L1S("Layer 2"), Qt::CaseInsensitive) == 0)
+                       return true;
+               }
+               else if (formatType.compare(mpegAudio, Qt::CaseInsensitive) == 0)
+               {
+                       QMutexLocker lock(&m_regexMutex);
+                       if (m_regxLayer.isNull())
+                       {
+                               m_regxLayer.reset(new QRegExp(L1S("\\bLayer\\s+(1|2|3)\\b"), Qt::CaseInsensitive));
+                       }
+                       if (m_regxLayer->indexIn(formatProfile) >= 0)
                        {
-                               if(formatVersion.compare(L1S("Version 1"), Qt::CaseInsensitive) == 0 || formatVersion.compare(L1S("Version 2"), Qt::CaseInsensitive) == 0)
+                               if (m_regxVersion.isNull())
                                {
-                                       return true;
+                                       m_regxVersion.reset(new QRegExp(L1S("\\b(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive));
                                }
+                               return (m_regxVersion->indexIn(formatVersion) >= 0);
                        }
                }
        }
index 461fe20..5281cb6 100644 (file)
@@ -54,5 +54,8 @@ private:
        int m_configBitrateMinimum;
        int m_configChannelMode;
 
+       static QMutex m_regexMutex;
+       static QScopedPointer<QRegExp> m_regxLayer, m_regxVersion;
+
        int clipBitrate(int bitrate);
 };