1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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_Opus.h"
32 bool OpusDecoder::m_disableResampling
= false;
34 OpusDecoder::OpusDecoder(void)
36 m_binary(lamexp_lookup_tool("opusdec.exe"))
38 if(m_binary
.isEmpty())
40 THROW("Error initializing Opus decoder. Tool 'opusdec.exe' is not registred!");
44 OpusDecoder::~OpusDecoder(void)
48 bool OpusDecoder::decode(const QString
&sourceFile
, const QString
&outputFile
, volatile bool *abortFlag
)
53 if(m_disableResampling
)
55 args
<< "--no-resample";
58 args
<< QDir::toNativeSeparators(sourceFile
);
59 args
<< QDir::toNativeSeparators(outputFile
);
61 if(!startProcess(process
, m_binary
, args
))
66 bool bTimeout
= false;
67 bool bAborted
= false;
68 int prevProgress
= -1;
70 QRegExp
regExp("\\((\\d+)%\\)");
72 while(process
.state() != QProcess::NotRunning
)
78 emit
messageLogged("\nABORTED BY USER !!!");
81 process
.waitForReadyRead(m_processTimeoutInterval
);
82 if(!process
.bytesAvailable() && process
.state() == QProcess::Running
)
85 qWarning("opusdec process timed out <-- killing!");
86 emit
messageLogged("\nPROCESS TIMEOUT !!!");
90 while(process
.bytesAvailable() > 0)
92 QByteArray line
= process
.readLine();
93 QString text
= QString::fromUtf8(line
.constData()).simplified();
94 if(regExp
.lastIndexIn(text
) >= 0)
97 int progress
= regExp
.cap(1).toInt(&ok
);
98 if(ok
&& (progress
> prevProgress
))
100 emit
statusUpdated(progress
);
101 prevProgress
= qMin(progress
+ 2, 99);
104 else if(!text
.isEmpty())
106 emit
messageLogged(text
);
111 process
.waitForFinished();
112 if(process
.state() != QProcess::NotRunning
)
115 process
.waitForFinished(-1);
118 emit
statusUpdated(100);
119 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", process
.exitCode()));
121 if(bTimeout
|| bAborted
|| process
.exitCode() != EXIT_SUCCESS
)
129 bool OpusDecoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
131 if(containerType
.compare("OGG", Qt::CaseInsensitive
) == 0)
133 if(formatType
.compare("Opus", Qt::CaseInsensitive
) == 0)
144 QStringList
OpusDecoder::supportedTypes(void)
146 return QStringList() << "Opus Audio Codec (*.opus *.ogg)";