1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Decoder_WMA.h"
29 #include <QSystemSemaphore>
32 WMADecoder::WMADecoder(void)
34 m_binary(lamexp_lookup_tool("wmawav.exe")),
35 m_semaphore(new QSystemSemaphore("{84BB780D-67D3-49DC-ADF0-97C795A55D5C}", 1))
37 if(m_binary
.isEmpty())
39 throw "Error initializing WMA decoder. Tool 'wmawav.exe' is not registred!";
43 WMADecoder::~WMADecoder(void)
47 bool WMADecoder::decode(const QString
&sourceFile
, const QString
&outputFile
, volatile bool *abortFlag
)
52 args
<< pathToShort(QDir::toNativeSeparators(sourceFile
));
53 args
<< pathToShort(QDir::toNativeSeparators(outputFile
));
55 if(!m_semaphore
->acquire())
57 emit
messageLogged("Failed to acquire the semaphore!");
61 if(!startProcess(process
, m_binary
, args
))
63 m_semaphore
->release();
67 bool bTimeout
= false;
68 bool bAborted
= false;
70 //The WMA Decoder doesn't actually send any status updates :-[
71 emit
statusUpdated(20 + (QUuid::createUuid().data1
% 80));
73 while(process
.state() != QProcess::NotRunning
)
79 emit
messageLogged("\nABORTED BY USER !!!");
82 process
.waitForReadyRead();
83 if(!process
.bytesAvailable() && process
.state() == QProcess::Running
)
86 qWarning("WmaWav process timed out <-- killing!");
87 emit
messageLogged("\nPROCESS TIMEOUT !!!");
91 while(process
.bytesAvailable() > 0)
93 QByteArray line
= process
.readLine();
94 QString text
= QString::fromUtf8(line
.constData()).simplified();
97 emit
messageLogged(text
);
102 process
.waitForFinished();
103 if(process
.state() != QProcess::NotRunning
)
106 process
.waitForFinished(-1);
109 emit
statusUpdated(100);
110 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", process
.exitCode()));
111 m_semaphore
->release();
113 if(bTimeout
|| bAborted
|| process
.exitStatus() != QProcess::NormalExit
|| QFileInfo(outputFile
).size() == 0)
121 bool WMADecoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
123 if(containerType
.compare("Windows Media", Qt::CaseInsensitive
) == 0)
125 if(formatType
.compare("WMA", Qt::CaseInsensitive
) == 0)
127 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)
137 bool WMADecoder::isDecoderAvailable(void)
139 return lamexp_check_tool("wmawav.exe");
142 QStringList
WMADecoder::supportedTypes(void)
144 return QStringList() << "Windows Media Audio (*.wma)";