Updated avs2wav tool.
[LameXP.git] / src / Decoder_WMA.cpp
blob92568681dfb7338cdb1cdd9ee0d839a929cc4c2f
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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.
9 //
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"
24 #include "Global.h"
26 #include <QDir>
27 #include <QProcess>
28 #include <QRegExp>
29 #include <QSystemSemaphore>
30 #include <QUuid>
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)
49 QProcess process;
50 QStringList args;
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!");
58 return false;
61 if(!startProcess(process, m_binary, args))
63 m_semaphore->release();
64 return false;
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)
75 if(*abortFlag)
77 process.kill();
78 bAborted = true;
79 emit messageLogged("\nABORTED BY USER !!!");
80 break;
82 process.waitForReadyRead();
83 if(!process.bytesAvailable() && process.state() == QProcess::Running)
85 process.kill();
86 qWarning("WmaWav process timed out <-- killing!");
87 emit messageLogged("\nPROCESS TIMEOUT !!!");
88 bTimeout = true;
89 break;
91 while(process.bytesAvailable() > 0)
93 QByteArray line = process.readLine();
94 QString text = QString::fromUtf8(line.constData()).simplified();
95 if(!text.isEmpty())
97 emit messageLogged(text);
102 process.waitForFinished();
103 if(process.state() != QProcess::NotRunning)
105 process.kill();
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)
115 return false;
118 return true;
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)
129 return true;
134 return false;
137 bool WMADecoder::isDecoderAvailable(void)
139 return lamexp_check_tool("wmawav.exe");
142 QStringList WMADecoder::supportedTypes(void)
144 return QStringList() << "Windows Media Audio (*.wma)";