1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
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"
29 #include <MUtils/Exception.h>
35 #include <QMutexLocker>
38 QMutex
AACDecoder::m_regexMutex
;
39 MUtils::Lazy
<QRegExp
> AACDecoder::m_regxFeatures([]
41 return new QRegExp(L1S("\\bLC\\b"), Qt::CaseInsensitive
);
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
)
63 args
<< "-o" << QDir::toNativeSeparators(outputFile
);
64 args
<< QDir::toNativeSeparators(sourceFile
);
66 if(!startProcess(process
, m_binary
, args
))
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
, ®Exp
](const QString
&text
)
76 if (regExp
.lastIndexIn(text
) >= 0)
79 if (MUtils::regexp_parse_int32(regExp
, newProgress
))
81 if (newProgress
> prevProgress
)
83 emit
statusUpdated(newProgress
);
84 prevProgress
= NEXT_PROGRESS(newProgress
);
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())
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
},
128 return s_supportedTypes
;