OSDN Git Service

Clean up version detection code.
[x264-launcher/x264-launcher.git] / src / encoder_nvenc.cpp
index 7b16fd0..c2059cf 100644 (file)
 #include "model_status.h"
 #include "mediainfo.h"
 #include "model_sysinfo.h"
+#include "model_clipInfo.h"
 
 //MUtils
+#include <MUtils/Global.h>
 #include <MUtils/Exception.h>
 
 //Qt
@@ -38,8 +40,8 @@
 #include <QPair>
 
 //x265 version info
-static const unsigned int VERSION_NVENCC_MINIMUM_VER = 206;
-static const unsigned int VERSION_NVENCC_MINIMUM_API =  60;
+static const unsigned int VERSION_NVENCC_MINIMUM_VER = 301;
+static const unsigned int VERSION_NVENCC_MINIMUM_API =  70;
 
 // ------------------------------------------------------------
 // Helper Macros
@@ -49,10 +51,11 @@ static const unsigned int VERSION_NVENCC_MINIMUM_API =  60;
 { \
        bool ok = false; \
        unsigned int progressFrames = (X)->cap(1).toUInt(&ok); \
+       double progress = 0.0; \
        setStatus(JobStatus_Running); \
-       if(ok && (totalFrames > 0) && (totalFrames != UINT_MAX)) \
+       if(ok && (clipInfo.getFrameCount() > 0)) \
        { \
-               const double progress = (double(progressFrames) / double(totalFrames)); \
+               progress = (double(progressFrames) / double(clipInfo.getFrameCount())); \
                if(!qFuzzyCompare(progress, last_progress)) \
                { \
                        setProgress(floor(progress * 100.0)); \
@@ -60,7 +63,7 @@ static const unsigned int VERSION_NVENCC_MINIMUM_API =  60;
                        last_progress = progress; \
                } \
        } \
-       setDetails(tr("%1, est. file size %2").arg(line.mid(offset).trimmed(), sizeToString(qRound64(size_estimate)))); \
+       setDetails(tr("[%1] %2, est. file size %3").arg(QString().sprintf("%.1f%%", 100.0 * progress), line.mid(offset).trimmed(), sizeToString(qRound64(size_estimate)))); \
 } \
 while(0)
 
@@ -140,7 +143,7 @@ public:
        virtual QStringList supportedOutputFormats(void) const
        {
                QStringList extLst;
-               extLst << "mp4";
+               extLst << "mp4" << "264" << "hevc";
                return extLst;
        }
 
@@ -196,6 +199,11 @@ public:
                << QString("%1/toolset/%2/avutil-55.dll"   ).arg(sysinfo->getAppPath(), arch)
                << QString("%1/toolset/%2/swresample-2.dll").arg(sysinfo->getAppPath(), arch);
        }
+
+       virtual QString getHelpCommand(void) const
+       {
+               return "--help";
+       }
 };
 
 static const NVEncEncoderInfo s_nvencEncoderInfo;
@@ -241,27 +249,17 @@ QString NVEncEncoder::getName(void) const
 void NVEncEncoder::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
 {
        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)
 {
-       int offset = -1;
-
-       if((offset = patterns[0]->lastIndexIn(line)) >= 0)
+       if(patterns[0]->lastIndexIn(line) >= 0)
        {
-               bool ok[4] = { false, false, false, false };
                unsigned int temp[4];
-               temp[0] = patterns[0]->cap(1).toUInt(&ok[0]);
-               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])
+               if(MUtils::regexp_parse_uint32(*patterns[0], temp, 4))
                {
                        core = (100 * temp[0]) + temp[1];
-               }
-               if (ok[2] && ok[3])
-               {
                        build = (10 * temp[2]) + temp[3];
                }
        }
@@ -282,7 +280,7 @@ QString NVEncEncoder::printVersion(const unsigned int &revision, const bool &mod
        unsigned int 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)
@@ -314,7 +312,7 @@ bool NVEncEncoder::isVersionSupported(const unsigned int &revision, const bool &
 // Encoding Functions
 // ------------------------------------------------------------
 
-void NVEncEncoder::buildCommandLine(QStringList &cmdLine, const bool &usePipe, const unsigned int &frames, const QString &indexFile, const int &pass, const QString &passLogFile)
+void NVEncEncoder::buildCommandLine(QStringList &cmdLine, const bool &usePipe, const ClipInfo &clipInfo, const QString &indexFile, const int &pass, const QString &passLogFile)
 {
        switch (m_options->encVariant())
        {
@@ -386,16 +384,26 @@ void NVEncEncoder::buildCommandLine(QStringList &cmdLine, const bool &usePipe, c
 
 void NVEncEncoder::runEncodingPass_init(QList<QRegExp*> &patterns)
 {
-       patterns << new QRegExp("^(\\d+) frames:"); //regExpFrameCnt
+       patterns << new QRegExp("^(\\d+) frames:");
+       patterns << new QRegExp("Selected\\s+codec\\s+is\\s+not\\s+supported", Qt::CaseInsensitive);
+       patterns << new QRegExp("nvEncodeAPI.dll\\s+does\\s+not\\s+exists\\s+in\\s+your\\s+system", Qt::CaseInsensitive);
 }
 
-void NVEncEncoder::runEncodingPass_parseLine(const QString &line, QList<QRegExp*> &patterns, const unsigned int &totalFrames, const int &pass, double &last_progress, double &size_estimate)
+void NVEncEncoder::runEncodingPass_parseLine(const QString &line, QList<QRegExp*> &patterns, const ClipInfo &clipInfo, const int &pass, double &last_progress, double &size_estimate)
 {
        int offset = -1;
        if((offset = patterns[0]->lastIndexIn(line)) >= 0)
        {
                NVENCC_UPDATE_PROGRESS(patterns[0]);
        }
+       else if ((offset = patterns[1]->lastIndexIn(line)) >= 0)
+       {
+               log(QString("ERROR: YOUR HARDWARE DOES *NOT* SUPPORT THE '%1' CODEC !!!\n").arg(s_nvencEncoderInfo.variantToString(m_options->encVariant())));
+       }
+       else if ((offset = patterns[2]->lastIndexIn(line)) >= 0)
+       {
+               log("ERROR: NVIDIA ENCODER API (NVENCODEAPI.DLL) IS *NOT* AVAILABLE !!!\n");
+       }
        else if(!line.isEmpty())
        {
                log(line);