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 "Encoder_AAC_FHG.h"
25 #include "Model_Settings.h"
31 #define max(a,b) (((a) > (b)) ? (a) : (b))
32 #define min(a,b) (((a) < (b)) ? (a) : (b))
34 FHGAACEncoder::FHGAACEncoder(void)
36 m_binary_enc(lamexp_lookup_tool("fhgaacenc.exe")),
37 m_binary_dll(lamexp_lookup_tool("enc_fhgaac.dll"))
39 if(m_binary_enc
.isEmpty() || m_binary_dll
.isEmpty())
41 throw "Error initializing FhgAacEnc. Tool 'fhgaacenc.exe' is not registred!";
47 FHGAACEncoder::~FHGAACEncoder(void)
51 bool FHGAACEncoder::encode(const QString
&sourceFile
, const AudioFileModel
&metaInfo
, const QString
&outputFile
, volatile bool *abortFlag
)
58 if(m_configRCMode
== SettingsModel::CBRMode
)
60 switch(m_configProfile
)
63 args
<< "--profile" << "lc"; //Forces use of LC AAC profile
67 args
<< "--profile" << "he"; //Forces use of HE AAC profile
71 args
<< "--profile" << "hev2"; //Forces use of HEv2 AAC profile
76 switch(m_configRCMode
)
78 case SettingsModel::CBRMode
:
79 args
<< "--cbr" << QString::number(max(32, min(maxBitrate
, (m_configBitrate
* 8))));
81 case SettingsModel::VBRMode
:
82 args
<< "--vbr" << QString::number(qRound(static_cast<double>(m_configBitrate
) / 5.0) + 1);
85 throw "Bad rate-control mode!";
89 args
<< "--dll" << m_binary_dll
;
91 if(!m_configCustomParams
.isEmpty()) args
<< m_configCustomParams
.split(" ", QString::SkipEmptyParts
);
93 args
<< QDir::toNativeSeparators(sourceFile
);
94 args
<< QDir::toNativeSeparators(outputFile
);
96 if(!startProcess(process
, m_binary_enc
, args
))
101 bool bTimeout
= false;
102 bool bAborted
= false;
104 QRegExp
regExp("Progress:\\s*(\\d+)%");
106 while(process
.state() != QProcess::NotRunning
)
112 emit
messageLogged("\nABORTED BY USER !!!");
115 process
.waitForReadyRead(m_processTimeoutInterval
);
116 if(!process
.bytesAvailable() && process
.state() == QProcess::Running
)
119 qWarning("FhgAacEnc process timed out <-- killing!");
120 emit
messageLogged("\nPROCESS TIMEOUT !!!");
124 while(process
.bytesAvailable() > 0)
126 QByteArray line
= process
.readLine();
127 QString text
= QString::fromUtf8(line
.constData()).simplified();
128 if(regExp
.lastIndexIn(text
) >= 0)
131 int progress
= regExp
.cap(1).toInt(&ok
);
132 if(ok
) emit
statusUpdated(progress
);
134 else if(!text
.isEmpty())
136 emit
messageLogged(text
);
141 process
.waitForFinished();
142 if(process
.state() != QProcess::NotRunning
)
145 process
.waitForFinished(-1);
148 emit
statusUpdated(100);
149 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", process
.exitCode()));
151 if(bTimeout
|| bAborted
|| process
.exitStatus() != QProcess::NormalExit
)
159 QString
FHGAACEncoder::extension(void)
164 bool FHGAACEncoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
166 if(containerType
.compare("Wave", Qt::CaseInsensitive
) == 0)
168 if(formatType
.compare("PCM", Qt::CaseInsensitive
) == 0)
178 void FHGAACEncoder::setProfile(int profile
)
180 m_configProfile
= profile
;