Some code clean-up using new Lazy<T> operator->().
[LameXP.git] / src / Decoder_AAC.cpp
blob0727a612c6983cc276a6dd9e736acd3dc0704cad
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Decoder_AAC.h"
25 //Internal
26 #include "Global.h"
28 //MUtils
29 #include <MUtils/Exception.h>
31 //Qt
32 #include <QDir>
33 #include <QProcess>
34 #include <QRegExp>
35 #include <QMutexLocker>
37 //Static
38 QMutex AACDecoder::m_regexMutex;
39 MUtils::Lazy<QRegExp> AACDecoder::m_regxFeatures([]
41 return new QRegExp(L1S("\\bLC\\b"), Qt::CaseInsensitive);
42 });
44 AACDecoder::AACDecoder(void)
46 m_binary(lamexp_tools_lookup("faad.exe"))
48 if(m_binary.isEmpty())
50 MUTILS_THROW("Error initializing AAC decoder. Tool 'faad.exe' is not registred!");
54 AACDecoder::~AACDecoder(void)
58 bool AACDecoder::decode(const QString &sourceFile, const QString &outputFile, QAtomicInt &abortFlag)
60 QProcess process;
61 QStringList args;
63 args << "-o" << QDir::toNativeSeparators(outputFile);
64 args << QDir::toNativeSeparators(sourceFile);
66 if(!startProcess(process, m_binary, args))
68 return false;
71 int prevProgress = -1;
72 QRegExp regExp("\\[(\\d+)%\\]\\s*decoding", Qt::CaseInsensitive); //regExp("\\b(\\d+)%\\s+decoding", Qt::CaseInsensitive);
74 const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
76 if (regExp.lastIndexIn(text) >= 0)
78 qint32 newProgress;
79 if (MUtils::regexp_parse_int32(regExp, newProgress))
81 if (newProgress > prevProgress)
83 emit statusUpdated(newProgress);
84 prevProgress = NEXT_PROGRESS(newProgress);
87 return true;
89 return false;
90 });
92 return (result == RESULT_SUCCESS);
95 bool AACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
97 if((containerType.compare(QLatin1String("ADTS"), Qt::CaseInsensitive) == 0) || (containerType.compare(QLatin1String("MPEG-4"), Qt::CaseInsensitive) == 0))
99 if(formatType.compare(QLatin1String("AAC"), Qt::CaseInsensitive) == 0)
101 QMutexLocker lock(&m_regexMutex);
102 if (m_regxFeatures->indexIn(formatProfile) >= 0)
104 if((formatVersion.compare(QLatin1String("2"), Qt::CaseInsensitive) == 0) || (formatVersion.compare(QLatin1String("4"), Qt::CaseInsensitive) == 0) || formatVersion.isEmpty())
106 return true;
112 return false;
115 const AbstractDecoder::supportedType_t *AACDecoder::supportedTypes(void)
117 static const char *exts[] =
119 "mp4", "m4a", "aac", NULL
122 static const supportedType_t s_supportedTypes[] =
124 { "Advanced Audio Coding", exts },
125 { NULL, NULL }
128 return s_supportedTypes;