Clean up version detection code.

This commit is contained in:
LoRd_MuldeR 2016-10-21 11:59:41 +02:00
parent 42a3d9cd05
commit 33de4dd98e
3 changed files with 24 additions and 44 deletions

View File

@ -30,6 +30,7 @@
#include "model_clipInfo.h" #include "model_clipInfo.h"
//MUtils //MUtils
#include <MUtils/Global.h>
#include <MUtils/Exception.h> #include <MUtils/Exception.h>
//Qt //Qt
@ -39,7 +40,7 @@
#include <QPair> #include <QPair>
//x265 version info //x265 version info
static const unsigned int VERSION_NVENCC_MINIMUM_VER = 211; static const unsigned int VERSION_NVENCC_MINIMUM_VER = 301;
static const unsigned int VERSION_NVENCC_MINIMUM_API = 70; static const unsigned int VERSION_NVENCC_MINIMUM_API = 70;
// ------------------------------------------------------------ // ------------------------------------------------------------
@ -248,27 +249,17 @@ QString NVEncEncoder::getName(void) const
void NVEncEncoder::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine) void NVEncEncoder::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
{ {
cmdLine << "--version"; cmdLine << "--version";
patterns << new QRegExp("\\bNVEncC\\s+\\(\\w+\\)\\s+(\\d)\\.(\\d+)\\s+by\\s+rigaya\\s+\\[NVENC\\s+API\\s+v(\\d+)\\.(\\d+)\\]", Qt::CaseInsensitive); patterns << new QRegExp("\\bNVEncC\\s+\\(x\\d+\\)\\s+(\\d)\\.(\\d+).*\\[NVENC\\s+API\\s+v(\\d+)\\.(\\d+)\\]", Qt::CaseInsensitive);
} }
void NVEncEncoder::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &core, unsigned int &build, bool &modified) void NVEncEncoder::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &core, unsigned int &build, bool &modified)
{ {
int offset = -1; if(patterns[0]->lastIndexIn(line) >= 0)
if((offset = patterns[0]->lastIndexIn(line)) >= 0)
{ {
bool ok[4] = { false, false, false, false };
unsigned int temp[4]; unsigned int temp[4];
temp[0] = patterns[0]->cap(1).toUInt(&ok[0]); if(MUtils::regexp_parse_uint32(*patterns[0], temp, 4))
temp[1] = patterns[0]->cap(2).toUInt(&ok[1]);
temp[2] = patterns[0]->cap(2).toUInt(&ok[2]);
temp[3] = patterns[0]->cap(2).toUInt(&ok[3]);
if(ok[0] && ok[1])
{ {
core = (100 * temp[0]) + temp[1]; core = (100 * temp[0]) + temp[1];
}
if (ok[2] && ok[3])
{
build = (10 * temp[2]) + temp[3]; build = (10 * temp[2]) + temp[3];
} }
} }
@ -289,7 +280,7 @@ QString NVEncEncoder::printVersion(const unsigned int &revision, const bool &mod
unsigned int core, build; unsigned int core, build;
splitRevision(revision, core, build); splitRevision(revision, core, build);
return tr("NVEncC version: %1.%2").arg(QString::number(core / 100), QString::number(core % 100).leftJustified(2, QLatin1Char('0'))); return tr("NVEncC version: %1.%2 [API: %3.%4]").arg(QString::number(core / 100), QString::number(core % 100).leftJustified(2, QLatin1Char('0')), QString::number(build / 10), QString::number(build % 10));
} }
bool NVEncEncoder::isVersionSupported(const unsigned int &revision, const bool &modified) bool NVEncEncoder::isVersionSupported(const unsigned int &revision, const bool &modified)

View File

@ -30,6 +30,7 @@
#include "model_clipInfo.h" #include "model_clipInfo.h"
//MUtils //MUtils
#include <MUtils/Global.h>
#include <MUtils/Exception.h> #include <MUtils/Exception.h>
//Qt //Qt
@ -235,28 +236,22 @@ void X264Encoder::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdL
void X264Encoder::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &core, unsigned int &build, bool &modified) void X264Encoder::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &core, unsigned int &build, bool &modified)
{ {
int offset = -1; if(patterns[0]->lastIndexIn(line) >= 0)
if((offset = patterns[0]->lastIndexIn(line)) >= 0)
{ {
bool ok1 = false, ok2 = false; unsigned int temp[3];
unsigned int temp1 = patterns[0]->cap(2).toUInt(&ok1); if(MUtils::regexp_parse_uint32(*patterns[0], temp, 3))
unsigned int temp2 = patterns[0]->cap(3).toUInt(&ok2);
if(ok1 && ok2 && (temp1 > 0) && (temp2 > 0))
{ {
core = temp1; core = temp[1];
build = temp2; build = temp[2];
} }
} }
else if((offset = patterns[1]->lastIndexIn(line)) >= 0) else if(patterns[1]->lastIndexIn(line) >= 0)
{ {
bool ok1 = false, ok2 = false; unsigned int temp[3];
unsigned int temp1 = patterns[1]->cap(2).toUInt(&ok1); if (MUtils::regexp_parse_uint32(*patterns[1], temp, 3))
unsigned int temp2 = patterns[1]->cap(3).toUInt(&ok2);
if(ok1 && ok2 && (temp1 > 0) && (temp2 > 0))
{ {
core = temp1; core = temp[1];
build = temp2; build = temp[2];
} }
modified = true; modified = true;
} }

View File

@ -30,6 +30,7 @@
#include "model_clipInfo.h" #include "model_clipInfo.h"
//MUtils //MUtils
#include <MUtils/Global.h>
#include <MUtils/Exception.h> #include <MUtils/Exception.h>
//Qt //Qt
@ -40,7 +41,7 @@
//x265 version info //x265 version info
static const unsigned int VERSION_X265_MINIMUM_VER = 21; static const unsigned int VERSION_X265_MINIMUM_VER = 21;
static const unsigned int VERSION_X265_MINIMUM_REV = 20; static const unsigned int VERSION_X265_MINIMUM_REV = 25;
// ------------------------------------------------------------ // ------------------------------------------------------------
// Helper Macros // Helper Macros
@ -235,24 +236,17 @@ void X265Encoder::checkVersion_parseLine(const QString &line, QList<QRegExp*> &p
if((offset = patterns[0]->lastIndexIn(line)) >= 0) if((offset = patterns[0]->lastIndexIn(line)) >= 0)
{ {
bool ok[3] = { false, false, false };
unsigned int temp[3]; unsigned int temp[3];
temp[0] = patterns[0]->cap(1).toUInt(&ok[0]); if(MUtils::regexp_parse_uint32(*patterns[0], temp, 3))
temp[1] = patterns[0]->cap(2).toUInt(&ok[1]);
temp[2] = patterns[0]->cap(3).toUInt(&ok[2]);
if(ok[0] && ok[1])
{ {
core = (10 * temp[0]) + temp[1]; core = (10 * temp[0]) + temp[1];
build = temp[2];
} }
if(ok[2]) build = temp[2];
} }
else if((offset = patterns[1]->lastIndexIn(line)) >= 0) else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
{ {
bool ok[2] = { false, false };
unsigned int temp[2]; unsigned int temp[2];
temp[0] = patterns[1]->cap(1).toUInt(&ok[0]); if (MUtils::regexp_parse_uint32(*patterns[0], temp, 2))
temp[1] = patterns[1]->cap(2).toUInt(&ok[1]);
if(ok[0] && ok[1])
{ {
core = (10 * temp[0]) + temp[1]; core = (10 * temp[0]) + temp[1];
} }
@ -280,7 +274,7 @@ bool X265Encoder::isVersionSupported(const unsigned int &revision, const bool &m
if((core < VERSION_X265_MINIMUM_VER) || ((core == VERSION_X265_MINIMUM_VER) && (build < VERSION_X265_MINIMUM_REV))) if((core < VERSION_X265_MINIMUM_VER) || ((core == VERSION_X265_MINIMUM_VER) && (build < VERSION_X265_MINIMUM_REV)))
{ {
log(tr("\nERROR: Your version of x265 is too old! (Minimum required revision is 0.%1+%2)").arg(QString::number(VERSION_X265_MINIMUM_VER), QString::number(VERSION_X265_MINIMUM_REV))); log(tr("\nERROR: Your version of x265 is too old! (Minimum required revision is %1.%2+%3)").arg(QString::number(VERSION_X265_MINIMUM_VER / 10), QString::number(VERSION_X265_MINIMUM_VER % 10), QString::number(VERSION_X265_MINIMUM_REV)));
return false; return false;
} }
else if(core > VERSION_X265_MINIMUM_VER) else if(core > VERSION_X265_MINIMUM_VER)