1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 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_abstract.h"
25 #include "model_options.h"
26 #include "model_preferences.h"
27 #include "model_sysinfo.h"
32 unsigned int AbstractEncoder::checkVersion(bool &modified)
34 if(m_preferences->getSkipVersionTest())
36 log("Warning: Skipping encoder version check this time!");
37 return (999 * REV_MULT) + (REV_MULT-1);
41 QStringList cmdLine = QStringList() << "--version";
43 log("Creating process:");
44 if(!startProcess(process, ENC_BINARY(m_sysinfo, m_options), cmdLine))
49 QRegExp regExpVersion("", Qt::CaseInsensitive);
50 QRegExp regExpVersionMod("\\bx264 (\\d)\\.(\\d+)\\.(\\d+)", Qt::CaseInsensitive);
52 switch(m_options->encType())
54 case OptionsModel::EncType_X264: regExpVersion.setPattern("\\bx264\\s(\\d)\\.(\\d+)\\.(\\d+)\\s([a-f0-9]{7})");
55 case OptionsModel::EncType_X265: regExpVersion.setPattern("\\bHEVC\\s+encoder\\s+version\\s+0\\.(\\d+)\\+(\\d+)-[a-f0-9]+\\b");
56 default: throw "Invalid encoder type!";
59 bool bTimeout = false;
60 bool bAborted = false;
62 unsigned int revision = UINT_MAX;
63 unsigned int coreVers = UINT_MAX;
66 while(process.state() != QProcess::NotRunning)
74 if(!process.waitForReadyRead())
76 if(process.state() == QProcess::Running)
79 qWarning("encoder process timed out <-- killing!");
80 log("\nPROCESS TIMEOUT !!!");
85 while(process.bytesAvailable() > 0)
87 QList<QByteArray> lines = process.readLine().split('\r');
88 while(!lines.isEmpty())
90 QString text = QString::fromUtf8(lines.takeFirst().constData()).simplified();
92 if((offset = regExpVersion.lastIndexIn(text)) >= 0)
94 bool ok1 = false, ok2 = false;
95 unsigned int temp1 = regExpVersion.cap(2).toUInt(&ok1);
96 unsigned int temp2 = regExpVersion.cap(3).toUInt(&ok2);
97 if(ok1) coreVers = temp1;
98 if(ok2) revision = temp2;
100 else if((offset = regExpVersionMod.lastIndexIn(text)) >= 0)
102 bool ok1 = false, ok2 = false;
103 unsigned int temp1 = regExpVersionMod.cap(2).toUInt(&ok1);
104 unsigned int temp2 = regExpVersionMod.cap(3).toUInt(&ok2);
105 if(ok1) coreVers = temp1;
106 if(ok2) revision = temp2;
117 process.waitForFinished();
118 if(process.state() != QProcess::NotRunning)
121 process.waitForFinished(-1);
124 if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
126 if(!(bTimeout || bAborted))
128 log(tr("\nPROCESS EXITED WITH ERROR CODE: %1").arg(QString::number(process.exitCode())));
133 if((revision == UINT_MAX) || (coreVers == UINT_MAX))
135 log(tr("\nFAILED TO DETERMINE ENCODER VERSION !!!"));
139 return (coreVers * REV_MULT) + (revision % REV_MULT);