From 1fb5160ec117e6497edd2310c8493eee9b983da3 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 18 May 2018 22:17:44 +0200 Subject: [PATCH] Updated file format detection routines. Also fixes WMA and "raw" AAC detection. --- src/Decoder_AAC.cpp | 9 ++++----- src/Decoder_AC3.cpp | 18 ++++++++++-------- src/Decoder_ADPCM.cpp | 8 ++++---- src/Decoder_ALAC.cpp | 4 ++-- src/Decoder_Avisynth.cpp | 5 +++-- src/Decoder_FLAC.cpp | 5 +++-- src/Decoder_MAC.cpp | 5 +++-- src/Decoder_MP3.cpp | 21 ++++++++++----------- src/Decoder_MP3.h | 3 ++- src/Decoder_Musepack.cpp | 5 +++-- src/Decoder_Opus.cpp | 4 ++-- src/Decoder_Shorten.cpp | 5 +++-- src/Decoder_Speex.cpp | 5 +++-- src/Decoder_TTA.cpp | 5 +++-- src/Decoder_Vorbis.cpp | 4 ++-- src/Decoder_WMA.cpp | 6 +++--- src/Decoder_WavPack.cpp | 5 +++-- src/Decoder_Wave.cpp | 4 ++-- 18 files changed, 65 insertions(+), 56 deletions(-) diff --git a/src/Decoder_AAC.cpp b/src/Decoder_AAC.cpp index e0143bc8..f8020839 100644 --- a/src/Decoder_AAC.cpp +++ b/src/Decoder_AAC.cpp @@ -86,14 +86,13 @@ bool AACDecoder::decode(const QString &sourceFile, const QString &outputFile, QA bool AACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("ADTS", Qt::CaseInsensitive) == 0 || containerType.compare("MPEG-4", Qt::CaseInsensitive) == 0) + if((containerType.compare(QLatin1String("ADTS"), Qt::CaseInsensitive) == 0) || (containerType.compare(QLatin1String("MPEG-4"), Qt::CaseInsensitive) == 0)) { - if(formatType.compare("AAC", Qt::CaseInsensitive) == 0) + if(formatType.compare(QLatin1String("AAC"), Qt::CaseInsensitive) == 0) { - QStringList profileParts = formatProfile.split(" ", QString::SkipEmptyParts); - if(profileParts.contains("LC", Qt::CaseInsensitive) || profileParts.contains("HE-AAC", Qt::CaseInsensitive) || profileParts.contains("HE-AACv2", Qt::CaseInsensitive)) + if((formatProfile.compare(QLatin1String("LC"), Qt::CaseInsensitive) == 0) || (formatProfile.compare(QLatin1String("HE-AAC"), Qt::CaseInsensitive) == 0) || (formatProfile.compare(QLatin1String("HE-AACv2"), Qt::CaseInsensitive) == 0)) { - if(formatVersion.compare("Version 2", Qt::CaseInsensitive) == 0 || formatVersion.compare("Version 4", Qt::CaseInsensitive) == 0 || formatVersion.isEmpty()) + if((formatVersion.compare(QLatin1String("2"), Qt::CaseInsensitive) == 0) || (formatVersion.compare(QLatin1String("4"), Qt::CaseInsensitive) == 0) || formatVersion.isEmpty()) { return true; } diff --git a/src/Decoder_AC3.cpp b/src/Decoder_AC3.cpp index 82361f39..79f8423b 100644 --- a/src/Decoder_AC3.cpp +++ b/src/Decoder_AC3.cpp @@ -86,30 +86,32 @@ bool AC3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA bool AC3Decoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("AC-3", Qt::CaseInsensitive) == 0) + static const QLatin1String ac3("AC-3"), eac3("E-AC-3"), dts("DTS"); + if(containerType.compare(ac3, Qt::CaseInsensitive) == 0) { - if(formatType.compare("AC-3", Qt::CaseInsensitive) == 0) + if(formatType.compare(ac3, Qt::CaseInsensitive) == 0) { return true; } } - if(containerType.compare("E-AC-3", Qt::CaseInsensitive) == 0) + if(containerType.compare(eac3, Qt::CaseInsensitive) == 0) { - if(formatType.compare("E-AC-3", Qt::CaseInsensitive) == 0) + if(formatType.compare(eac3, Qt::CaseInsensitive) == 0) { return true; } } - else if(containerType.compare("DTS", Qt::CaseInsensitive) == 0) + + else if(containerType.compare(dts, Qt::CaseInsensitive) == 0) { - if(formatType.compare("DTS", Qt::CaseInsensitive) == 0) + if(formatType.compare(dts, Qt::CaseInsensitive) == 0) { return true; } } - else if(containerType.compare("Wave", Qt::CaseInsensitive) == 0) + else if(containerType.compare(QLatin1String("Wave"), Qt::CaseInsensitive) == 0) { - if(formatType.compare("AC-3", Qt::CaseInsensitive) == 0 || formatType.compare("E-AC-3", Qt::CaseInsensitive) == 0 || formatType.compare("DTS", Qt::CaseInsensitive) == 0) + if((formatType.compare(ac3, Qt::CaseInsensitive) == 0) || (formatType.compare(eac3, Qt::CaseInsensitive) == 0) || (formatType.compare(dts, Qt::CaseInsensitive) == 0)) { return true; } diff --git a/src/Decoder_ADPCM.cpp b/src/Decoder_ADPCM.cpp index 8991a290..844d660d 100644 --- a/src/Decoder_ADPCM.cpp +++ b/src/Decoder_ADPCM.cpp @@ -88,17 +88,17 @@ bool ADPCMDecoder::decode(const QString &sourceFile, const QString &outputFile, bool ADPCMDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("Wave", Qt::CaseInsensitive) == 0) + if(containerType.compare(QLatin1String("Wave"), Qt::CaseInsensitive) == 0) { - if(formatType.compare("ADPCM", Qt::CaseInsensitive) == 0) + if(formatType.compare(QLatin1String("ADPCM"), Qt::CaseInsensitive) == 0) { return true; } } - if(containerType.compare("AIFF", Qt::CaseInsensitive) == 0 || containerType.compare("AU", Qt::CaseInsensitive) == 0) + if((containerType.compare(QLatin1String("AIFF"), Qt::CaseInsensitive) == 0) ||( containerType.compare(QLatin1String("AU"), Qt::CaseInsensitive) == 0)) { - if(formatType.compare("PCM", Qt::CaseInsensitive) == 0 || formatType.compare("ADPCM", Qt::CaseInsensitive) == 0) + if((formatType.compare(QLatin1String("PCM"), Qt::CaseInsensitive) == 0) || (formatType.compare(QLatin1String("ADPCM"), Qt::CaseInsensitive) == 0)) { return true; } diff --git a/src/Decoder_ALAC.cpp b/src/Decoder_ALAC.cpp index 2ace162d..269957a2 100644 --- a/src/Decoder_ALAC.cpp +++ b/src/Decoder_ALAC.cpp @@ -89,9 +89,9 @@ bool ALACDecoder::decode(const QString &sourceFile, const QString &outputFile, Q bool ALACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("MPEG-4", Qt::CaseInsensitive) == 0) + if(containerType.compare(QLatin1String("MPEG-4"), Qt::CaseInsensitive) == 0) { - if(formatType.compare("ALAC", Qt::CaseInsensitive) == 0) + if(formatType.compare(QLatin1String("ALAC"), Qt::CaseInsensitive) == 0) { return true; } diff --git a/src/Decoder_Avisynth.cpp b/src/Decoder_Avisynth.cpp index 88671d3a..a14ef922 100644 --- a/src/Decoder_Avisynth.cpp +++ b/src/Decoder_Avisynth.cpp @@ -87,9 +87,10 @@ bool AvisynthDecoder::decode(const QString &sourceFile, const QString &outputFil bool AvisynthDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("Avisynth", Qt::CaseInsensitive) == 0) + static const QLatin1String avs("Avisynth"); + if(containerType.compare(avs, Qt::CaseInsensitive) == 0) { - if(formatType.compare("Avisynth", Qt::CaseInsensitive) == 0) + if(formatType.compare(avs, Qt::CaseInsensitive) == 0) { return true; } diff --git a/src/Decoder_FLAC.cpp b/src/Decoder_FLAC.cpp index f307fc7f..d437eee9 100644 --- a/src/Decoder_FLAC.cpp +++ b/src/Decoder_FLAC.cpp @@ -87,9 +87,10 @@ bool FLACDecoder::decode(const QString &sourceFile, const QString &outputFile, Q bool FLACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("FLAC", Qt::CaseInsensitive) == 0 || containerType.compare("OGG", Qt::CaseInsensitive) == 0) + static const QLatin1String flac("FLAC"); + if((containerType.compare(flac, Qt::CaseInsensitive) == 0) || (containerType.compare(QLatin1String("OGG"), Qt::CaseInsensitive) == 0)) { - if(formatType.compare("FLAC", Qt::CaseInsensitive) == 0) + if(formatType.compare(flac, Qt::CaseInsensitive) == 0) { return true; } diff --git a/src/Decoder_MAC.cpp b/src/Decoder_MAC.cpp index 9e35cbbf..41094f05 100644 --- a/src/Decoder_MAC.cpp +++ b/src/Decoder_MAC.cpp @@ -87,9 +87,10 @@ bool MACDecoder::decode(const QString &sourceFile, const QString &outputFile, QA bool MACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("Monkey's Audio", Qt::CaseInsensitive) == 0) + static const QLatin1String mac("Monkey's Audio"); + if(containerType.compare(mac, Qt::CaseInsensitive) == 0) { - if(formatType.compare("Monkey's Audio", Qt::CaseInsensitive) == 0) + if(formatType.compare(mac, Qt::CaseInsensitive) == 0) { return true; } diff --git a/src/Decoder_MP3.cpp b/src/Decoder_MP3.cpp index 073c3318..4e47525a 100644 --- a/src/Decoder_MP3.cpp +++ b/src/Decoder_MP3.cpp @@ -36,8 +36,15 @@ #include //Static -QScopedPointer MP3Decoder::m_regxLayer, MP3Decoder::m_regxVersion; QMutex MP3Decoder::m_regexMutex; +MUtils::Lazy MP3Decoder::m_regxLayer([] +{ + return new QRegExp(L1S("^Layer\\s+(1|2|3)\\b"), Qt::CaseInsensitive); +}); +MUtils::Lazy MP3Decoder::m_regxVersion([] +{ + return new QRegExp(L1S("^(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive); +}); MP3Decoder::MP3Decoder(void) : @@ -103,17 +110,9 @@ bool MP3Decoder::isFormatSupported(const QString &containerType, const QString & if(formatType.compare(mpegAudio, Qt::CaseInsensitive) == 0) { 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)); - } - 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); + return ((*m_regxVersion).indexIn(formatVersion) >= 0); } } } diff --git a/src/Decoder_MP3.h b/src/Decoder_MP3.h index 4a66242e..90cb004c 100644 --- a/src/Decoder_MP3.h +++ b/src/Decoder_MP3.h @@ -23,6 +23,7 @@ #pragma once #include "Decoder_Abstract.h" +#include class MP3Decoder : public AbstractDecoder { @@ -36,6 +37,6 @@ public: private: const QString m_binary; - static QScopedPointer m_regxLayer, m_regxVersion; + static MUtils::Lazy m_regxLayer, m_regxVersion; static QMutex m_regexMutex; }; diff --git a/src/Decoder_Musepack.cpp b/src/Decoder_Musepack.cpp index 54d829c3..0f72a41d 100644 --- a/src/Decoder_Musepack.cpp +++ b/src/Decoder_Musepack.cpp @@ -88,9 +88,10 @@ bool MusepackDecoder::decode(const QString &sourceFile, const QString &outputFil bool MusepackDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("Musepack SV8", Qt::CaseInsensitive) == 0 || containerType.compare("Musepack SV7", Qt::CaseInsensitive) == 0) + static const QLatin1String mpc_sv8("Musepack SV8"), mpc_sv7("Musepack SV7"); + if((containerType.compare(mpc_sv8, Qt::CaseInsensitive) == 0) || (containerType.compare(mpc_sv7, Qt::CaseInsensitive) == 0)) { - if(formatType.compare("Musepack SV8", Qt::CaseInsensitive) == 0 || formatType.compare("Musepack SV7", Qt::CaseInsensitive) == 0) + if((formatType.compare(mpc_sv8, Qt::CaseInsensitive) == 0) || (formatType.compare(mpc_sv7, Qt::CaseInsensitive) == 0)) { return true; } diff --git a/src/Decoder_Opus.cpp b/src/Decoder_Opus.cpp index 6a3aa477..47daab80 100644 --- a/src/Decoder_Opus.cpp +++ b/src/Decoder_Opus.cpp @@ -96,9 +96,9 @@ bool OpusDecoder::decode(const QString &sourceFile, const QString &outputFile, Q bool OpusDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("OGG", Qt::CaseInsensitive) == 0) + if(containerType.compare(QLatin1String("OGG"), Qt::CaseInsensitive) == 0) { - if(formatType.compare("Opus", Qt::CaseInsensitive) == 0) + if(formatType.compare(QLatin1String("Opus"), Qt::CaseInsensitive) == 0) { { return true; diff --git a/src/Decoder_Shorten.cpp b/src/Decoder_Shorten.cpp index 0cee8b1f..0e0b80b1 100644 --- a/src/Decoder_Shorten.cpp +++ b/src/Decoder_Shorten.cpp @@ -70,9 +70,10 @@ bool ShortenDecoder::decode(const QString &sourceFile, const QString &outputFile bool ShortenDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("Shorten", Qt::CaseInsensitive) == 0) + static const QLatin1String shorten("Shorten"); + if(containerType.compare(shorten, Qt::CaseInsensitive) == 0) { - if(formatType.compare("Shorten", Qt::CaseInsensitive) == 0) + if(formatType.compare(shorten, Qt::CaseInsensitive) == 0) { return true; } diff --git a/src/Decoder_Speex.cpp b/src/Decoder_Speex.cpp index 1a12b633..dfd94db5 100644 --- a/src/Decoder_Speex.cpp +++ b/src/Decoder_Speex.cpp @@ -77,9 +77,10 @@ bool SpeexDecoder::decode(const QString &sourceFile, const QString &outputFile, bool SpeexDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("Speex", Qt::CaseInsensitive) == 0 || containerType.compare("OGG", Qt::CaseInsensitive) == 0) + static const QLatin1String speex("Speex"); + if(containerType.compare(speex, Qt::CaseInsensitive) == 0 || containerType.compare(QLatin1String("OGG"), Qt::CaseInsensitive) == 0) { - if(formatType.compare("Speex", Qt::CaseInsensitive) == 0) + if(formatType.compare(speex, Qt::CaseInsensitive) == 0) { return true; } diff --git a/src/Decoder_TTA.cpp b/src/Decoder_TTA.cpp index 4a64a879..f1b0a6d5 100644 --- a/src/Decoder_TTA.cpp +++ b/src/Decoder_TTA.cpp @@ -88,9 +88,10 @@ bool TTADecoder::decode(const QString &sourceFile, const QString &outputFile, QA bool TTADecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("TTA", Qt::CaseInsensitive) == 0) + static const QLatin1String tta("TTA"); + if(containerType.compare(tta, Qt::CaseInsensitive) == 0) { - if(formatType.compare("TTA", Qt::CaseInsensitive) == 0) + if(formatType.compare(tta, Qt::CaseInsensitive) == 0) { return true; } diff --git a/src/Decoder_Vorbis.cpp b/src/Decoder_Vorbis.cpp index 8ce4575a..aedc3603 100644 --- a/src/Decoder_Vorbis.cpp +++ b/src/Decoder_Vorbis.cpp @@ -87,9 +87,9 @@ bool VorbisDecoder::decode(const QString &sourceFile, const QString &outputFile, bool VorbisDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("OGG", Qt::CaseInsensitive) == 0) + if(containerType.compare(QLatin1String("OGG"), Qt::CaseInsensitive) == 0) { - if(formatType.compare("Vorbis", Qt::CaseInsensitive) == 0) + if(formatType.compare(QLatin1String("Vorbis"), Qt::CaseInsensitive) == 0) { return true; } diff --git a/src/Decoder_WMA.cpp b/src/Decoder_WMA.cpp index 66caa293..a9c00bd4 100644 --- a/src/Decoder_WMA.cpp +++ b/src/Decoder_WMA.cpp @@ -88,11 +88,11 @@ bool WMADecoder::decode(const QString &sourceFile, const QString &outputFile, QA bool WMADecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("Windows Media", Qt::CaseInsensitive) == 0) + if(containerType.compare(QLatin1String("Windows Media"), Qt::CaseInsensitive) == 0) { - if(formatType.compare("WMA", Qt::CaseInsensitive) == 0) + if(formatType.compare(QLatin1String("WMA"), Qt::CaseInsensitive) == 0) { - if(formatVersion.compare("Version 1", Qt::CaseInsensitive) == 0 || formatVersion.compare("Version 2", Qt::CaseInsensitive) == 0 || formatVersion.compare("Version 3", Qt::CaseInsensitive) == 0 || formatProfile.compare("Pro", Qt::CaseInsensitive) == 0 || formatProfile.compare("Lossless", Qt::CaseInsensitive) == 0) + if((formatVersion.compare(QLatin1String("1"), Qt::CaseInsensitive) == 0) || (formatVersion.compare(QLatin1String("2"), Qt::CaseInsensitive) == 0) || (formatVersion.compare(QLatin1String("3"), Qt::CaseInsensitive) == 0) || (formatProfile.compare(QLatin1String("Pro"), Qt::CaseInsensitive) == 0) || (formatProfile.compare(QLatin1String("Lossless"), Qt::CaseInsensitive) == 0)) { return true; } diff --git a/src/Decoder_WavPack.cpp b/src/Decoder_WavPack.cpp index 4d53cbb4..5805d077 100644 --- a/src/Decoder_WavPack.cpp +++ b/src/Decoder_WavPack.cpp @@ -87,9 +87,10 @@ bool WavPackDecoder::decode(const QString &sourceFile, const QString &outputFile bool WavPackDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("WavPack", Qt::CaseInsensitive) == 0) + static const QLatin1String wavPack("WavPack"); + if(containerType.compare(wavPack, Qt::CaseInsensitive) == 0) { - if(formatType.compare("WavPack", Qt::CaseInsensitive) == 0) + if(formatType.compare(wavPack, Qt::CaseInsensitive) == 0) { return true; } diff --git a/src/Decoder_Wave.cpp b/src/Decoder_Wave.cpp index f4259084..d82d18fe 100644 --- a/src/Decoder_Wave.cpp +++ b/src/Decoder_Wave.cpp @@ -85,9 +85,9 @@ void WaveDecoder::updateProgress(const double &progress) bool WaveDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) { - if(containerType.compare("Wave", Qt::CaseInsensitive) == 0) + if(containerType.compare(QLatin1String("Wave"), Qt::CaseInsensitive) == 0) { - if(formatType.compare("PCM", Qt::CaseInsensitive) == 0) + if(formatType.compare(QLatin1String("PCM"), Qt::CaseInsensitive) == 0) { return true; }