1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2017 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"
29 #include <MUtils/Exception.h>
37 bool OpusDecoder::m_disableResampling
= false;
39 OpusDecoder::OpusDecoder(void)
41 m_binary(lamexp_tools_lookup("opusdec.exe"))
43 if(m_binary
.isEmpty())
45 MUTILS_THROW("Error initializing Opus decoder. Tool 'opusdec.exe' is not registred!");
49 OpusDecoder::~OpusDecoder(void)
53 bool OpusDecoder::decode(const QString
&sourceFile
, const QString
&outputFile
, QAtomicInt
&abortFlag
)
58 if(m_disableResampling
)
60 args
<< "--no-resample";
63 args
<< QDir::toNativeSeparators(sourceFile
);
64 args
<< QDir::toNativeSeparators(outputFile
);
66 if(!startProcess(process
, m_binary
, args
))
71 int prevProgress
= -1;
72 QRegExp
regExp("\\((\\d+)%\\)");
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 OpusDecoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
97 if(containerType
.compare("OGG", Qt::CaseInsensitive
) == 0)
99 if(formatType
.compare("Opus", Qt::CaseInsensitive
) == 0)
110 const AbstractDecoder::supportedType_t
*OpusDecoder::supportedTypes(void)
112 static const char *exts
[] =
117 static const supportedType_t s_supportedTypes
[] =
119 { "Opus Audio Codec", exts
},
123 return s_supportedTypes
;