AbstractEncoder(JobObject *jobObject, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences, JobStatus &jobStatus, volatile bool *abort, volatile bool *pause, QSemaphore *semaphorePause, const QString &sourceFile, const QString &outputFile);
virtual ~AbstractEncoder(void);
- bool runEncodingPass(AbstractSource* pipedSource, const QString outputFile, const unsigned int &frames, const int &pass = 0, const QString &passLogFile = QString());
+ virtual bool runEncodingPass(AbstractSource* pipedSource, const QString outputFile, const unsigned int &frames, const int &pass = 0, const QString &passLogFile = QString());
protected:
virtual void buildCommandLine(QStringList &cmdLine, const bool &usePipe, const unsigned int &frames, const QString &indexFile, const int &pass, const QString &passLogFile) = 0;
void X264Encoder::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified)
{
int offset = -1;
+
if((offset = patterns[0]->lastIndexIn(line)) >= 0)
{
bool ok1 = false, ok2 = false;
unsigned int temp1 = patterns[0]->cap(2).toUInt(&ok1);
unsigned int temp2 = patterns[0]->cap(3).toUInt(&ok2);
- if(ok1) coreVers = temp1;
- if(ok2) revision = temp2;
+ if(ok1 && ok2)
+ {
+ coreVers = temp1;
+ revision = temp2;
+ }
}
else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
{
bool ok1 = false, ok2 = false;
unsigned int temp1 = patterns[1]->cap(2).toUInt(&ok1);
unsigned int temp2 = patterns[1]->cap(3).toUInt(&ok2);
- if(ok1) coreVers = temp1;
- if(ok2) revision = temp2;
+ if(ok1 && ok2)
+ {
+ coreVers = temp1;
+ revision = temp2;
+ }
modified = true;
}
+
+ if(!line.isEmpty())
+ {
+ log(line);
+ }
}
void X264Encoder::printVersion(const unsigned int &revision, const bool &modified)
{
- log(tr("\nx264 revision: %1 (core #%2)").arg(QString::number(revision % REV_MULT), QString::number(revision / REV_MULT)).append(modified ? tr(" - with custom patches!") : QString()));
+ log(tr("\nx264 revision: %1 (core #%2)\n").arg(QString::number(revision % REV_MULT), QString::number(revision / REV_MULT)).append(modified ? tr(" - with custom patches!") : QString()));
}
bool X264Encoder::isVersionSupported(const unsigned int &revision, const bool &modified)
void X264Encoder::runEncodingPass_parseLine(const QString &line, QList<QRegExp*> &patterns, const int &pass)
{
- log(tr("PARSE: \"%1\"").arg(line));
-
int offset = -1;
if((offset = patterns[0]->lastIndexIn(line)) >= 0)
{
void X265Encoder::printVersion(const unsigned int &revision, const bool &modified)
{
- log(tr("\nx265 version: 0.%1+%2").arg(QString::number(revision / REV_MULT), QString::number(revision % REV_MULT)));
+ log(tr("\nx265 version: 0.%1+%2\n").arg(QString::number(revision / REV_MULT), QString::number(revision % REV_MULT)));
}
bool X265Encoder::isVersionSupported(const unsigned int &revision, const bool &modified)
#include <QTextCodec>
#include <QDir>
+// ------------------------------------------------------------
+// Helper Macros
+// ------------------------------------------------------------
+
+#define PROCESS_PENDING_LINES(PROC, HANDLER, ...) do \
+{ \
+ while((PROC).bytesAvailable() > 0) \
+ { \
+ QList<QByteArray> lines = (PROC).readLine().split('\r'); \
+ while(!lines.isEmpty()) \
+ { \
+ const QString text = QString::fromUtf8(lines.takeFirst().constData()).simplified(); \
+ HANDLER(text, __VA_ARGS__); \
+ } \
+ } \
+} \
+while(0)
+
+// ------------------------------------------------------------
+// Constructor & Destructor
+// ------------------------------------------------------------
+
AbstractSource::AbstractSource(JobObject *jobObject, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences, JobStatus &jobStatus, volatile bool *abort, volatile bool *pause, QSemaphore *semaphorePause, const QString &sourceFile)
:
AbstractTool(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause),
/*Nothing to do here*/
}
+// ------------------------------------------------------------
+// Check Source Properties
+// ------------------------------------------------------------
+
bool AbstractSource::checkSourceProperties(unsigned int &frames)
{
QStringList cmdLine;
while(process.state() != QProcess::NotRunning)
{
- if(m_abort)
+ if(*m_abort)
{
process.kill();
bAborted = true;
}
waitCounter = 0;
-
- while(process.bytesAvailable() > 0)
- {
- QList<QByteArray> lines = process.readLine().split('\r');
- while(!lines.isEmpty())
- {
- QString text = localCodec->toUnicode(lines.takeFirst().constData()).simplified();
- }
- }
+ PROCESS_PENDING_LINES(process, checkSourceProperties_parseLine, patterns, frames, fSizeW, fSizeH, fpsNom, fpsDen);
+ }
+
+ if(!(bTimeout || bAborted))
+ {
+ PROCESS_PENDING_LINES(process, checkSourceProperties_parseLine, patterns, frames, fSizeW, fSizeH, fpsNom, fpsDen);
}
process.waitForFinished();
return true;
}
+// ------------------------------------------------------------
+// Source Processing
+// ------------------------------------------------------------
+
bool AbstractSource::createProcess(QProcess &processEncode, QProcess&processInput)
{
processInput.setStandardOutputProcess(&processEncode);
static const unsigned int VER_X264_AVS2YUV_VER = 242;
+// ------------------------------------------------------------
+// Constructor & Destructor
+// ------------------------------------------------------------
+
AvisynthSource::AvisynthSource(JobObject *jobObject, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences, JobStatus &jobStatus, volatile bool *abort, volatile bool *pause, QSemaphore *semaphorePause, const QString &sourceFile)
:
AbstractSource(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause, sourceFile),
/*Nothing to do here*/
}
+// ------------------------------------------------------------
+// Check Version
+// ------------------------------------------------------------
+
bool AvisynthSource::isSourceAvailable()
{
if(!(m_sysinfo->hasAVSSupport()))
void AvisynthSource::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
{
- cmdLine << "--version";
patterns << new QRegExp("\\bAvs2YUV (\\d+).(\\d+)\\b", Qt::CaseInsensitive);
patterns << new QRegExp("\\bAvs2YUV (\\d+).(\\d+)bm(\\d)\\b", Qt::CaseInsensitive);
}
void AvisynthSource::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified)
{
int offset = -1;
+
if((offset = patterns[0]->lastIndexIn(line)) >= 0)
{
bool ok1 = false, ok2 = false;
- unsigned int temp1 = patterns[0]->cap(2).toUInt(&ok1);
- unsigned int temp2 = patterns[0]->cap(3).toUInt(&ok2);
- if(ok1) coreVers = temp1;
- if(ok2) revision = temp2;
+ unsigned int temp1 = patterns[0]->cap(1).toUInt(&ok1);
+ unsigned int temp2 = patterns[0]->cap(2).toUInt(&ok2);
+ if(ok1 && ok2)
+ {
+ coreVers = temp1;
+ revision = temp2;
+ }
}
else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
{
- bool ok1 = false, ok2 = false;
- unsigned int temp1 = patterns[1]->cap(2).toUInt(&ok1);
- unsigned int temp2 = patterns[1]->cap(3).toUInt(&ok2);
- if(ok1) coreVers = temp1;
- if(ok2) revision = temp2;
+ bool ok1 = false, ok2 = false, ok3 = false;
+ unsigned int temp1 = patterns[1]->cap(1).toUInt(&ok1);
+ unsigned int temp2 = patterns[1]->cap(2).toUInt(&ok2);
+ unsigned int temp3 = patterns[1]->cap(3).toUInt(&ok3);
+ if(ok1 && ok2 && ok3)
+ {
+ coreVers = temp1;
+ revision = (temp2 * 10) + (temp3 % 10);
+ }
modified = true;
}
}
+bool AvisynthSource::checkVersion_succeeded(const int &exitCode)
+{
+ return (exitCode == EXIT_SUCCESS) || (exitCode == 2);
+}
+
void AvisynthSource::printVersion(const unsigned int &revision, const bool &modified)
{
log(tr("Avs2YUV version: %1.%2.%3").arg(QString::number(revision / REV_MULT), QString::number((revision % REV_MULT) / 10),QString::number((revision % REV_MULT) % 10)));
bool AvisynthSource::isVersionSupported(const unsigned int &revision, const bool &modified)
{
- if((revision != UINT_MAX) && ((revision % REV_MULT) != VER_X264_AVS2YUV_VER))
+ if((revision != UINT_MAX) && ((revision % REV_MULT) < VER_X264_AVS2YUV_VER))
{
- log(tr("\nERROR: Your version of avs2yuv is unsupported (Required version: v0.24 BugMaster's mod 2)"));
+ log(tr("\nERROR: Your version of avs2yuv is unsupported (required version: v0.24 BugMaster's mod 2)"));
log(tr("You can find the required version at: http://komisar.gin.by/tools/avs2yuv/"));
return false;
}
return true;
}
+// ------------------------------------------------------------
+// Check Source Properties
+// ------------------------------------------------------------
+
void AvisynthSource::checkSourceProperties_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
{
cmdLine << "-frames" << "1";
void AvisynthSource::checkSourceProperties_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &frames, unsigned int &fSizeW, unsigned int &fSizeH, unsigned int &fpsNom, unsigned int &fpsDen)
{
+ qWarning("parseLine \"%1\"", line.toUtf8().constData());
+
int offset = -1;
+
if((offset = patterns[0]->lastIndexIn(line)) >= 0)
{
bool ok1 = false, ok2 = false;
if(ok4) fpsDen = temp4;
if(ok5) frames = temp5;
}
+
if(!line.isEmpty())
{
log(line);
}
+
if(line.contains("failed to load avisynth.dll", Qt::CaseInsensitive))
{
log(tr("\nWarning: It seems that %1-Bit Avisynth is not currently installed !!!").arg(m_preferences->getUseAvisyth64Bit() ? "64" : "32"));
}
}
+// ------------------------------------------------------------
+// Source Processing
+// ------------------------------------------------------------
+
void AvisynthSource::buildCommandLine(QStringList &cmdLine)
{
cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
virtual void flushProcess(QProcess &processInput);
protected:
- void checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine);
- void checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified);
+ virtual void checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine);
+ virtual void checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified);
+ virtual bool checkVersion_succeeded(const int &exitCode);
virtual void checkSourceProperties_init(QList<QRegExp*> &patterns, QStringList &cmdLine);
virtual void checkSourceProperties_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &frames, unsigned int &fSizeW, unsigned int &fSizeH, unsigned int &fpsNom, unsigned int &fpsDen);
-
virtual const QString &getBinaryPath() { return m_binaryFile; }
virtual void buildCommandLine(QStringList &cmdLine);
/*Nothing to do here*/
}
+// ------------------------------------------------------------
+// Check Version
+// ------------------------------------------------------------
+
bool VapoursynthSource::isSourceAvailable()
{
if(!(m_sysinfo->hasVPSSupport() && (!m_sysinfo->getVPSPath().isEmpty()) && QFileInfo(m_sysinfo->getVPSPath()).isFile()))
void VapoursynthSource::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified)
{
int offset = -1;
+
if((offset = patterns[1]->lastIndexIn(line)) >= 0)
{
bool ok = false;
unsigned int temp = patterns[2]->cap(1).toUInt(&ok);
if(ok) coreVers = temp;
}
+
+ if(!line.isEmpty())
+ {
+ log(line);
+ }
}
void VapoursynthSource::printVersion(const unsigned int &revision, const bool &modified)
{
- log(tr("VapourSynth version: r%1 (API r%2)").arg(QString::number(revision % REV_MULT), QString::number(revision / REV_MULT)));
+ log(tr("\nVapourSynth version: r%1 (API r%2)").arg(QString::number(revision % REV_MULT), QString::number(revision / REV_MULT)));
}
bool VapoursynthSource::isVersionSupported(const unsigned int &revision, const bool &modified)
return true;
}
+// ------------------------------------------------------------
+// Check Source Properties
+// ------------------------------------------------------------
+
void VapoursynthSource::checkSourceProperties_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
{
cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
void VapoursynthSource::checkSourceProperties_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &frames, unsigned int &fSizeW, unsigned int &fSizeH, unsigned int &fpsNom, unsigned int &fpsDen)
{
int offset = -1;
+
if((offset = patterns[0]->lastIndexIn(line)) >= 0)
{
bool ok = false;
unsigned int temp = patterns[2]->cap(1).toUInt(&ok);
if(ok) fSizeH = temp;
}
+
if(!line.isEmpty())
{
log(line);
}
}
+// ------------------------------------------------------------
+// Check Source Properties
+// ------------------------------------------------------------
+
void VapoursynthSource::buildCommandLine(QStringList &cmdLine)
{
cmdLine << QDir::toNativeSeparators(x264_path2ansi(m_sourceFile, true));
virtual void flushProcess(QProcess &processInput);
protected:
- void checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine);
- void checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified);
+ virtual void checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine);
+ virtual void checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified);
virtual void checkSourceProperties_init(QList<QRegExp*> &patterns, QStringList &cmdLine);
virtual void checkSourceProperties_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &frames, unsigned int &fSizeW, unsigned int &fSizeH, unsigned int &fpsNom, unsigned int &fpsDen);
CHECK_STATUS(m_abort, (ok = (sourceRevision != UINT_MAX)));
//Print source versions
- m_pipedSource->printVersion(sourceModified, sourceModified);
+ m_pipedSource->printVersion(sourceRevision, sourceModified);
//Is source version supported?
CHECK_STATUS(m_abort, (ok = m_pipedSource->isVersionSupported(sourceRevision, sourceModified)));
{ \
const QString text = QString::fromUtf8(lines.takeFirst().constData()).simplified(); \
HANDLER(text, __VA_ARGS__); \
- if(!text.isEmpty()) \
- { \
- log(text); \
- } \
} \
} \
} \
X264_DELETE(pattern);
}
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
+ if(bTimeout || bAborted || (!checkVersion_succeeded(process.exitCode())))
{
if(!(bTimeout || bAborted))
{
return (coreVers * REV_MULT) + (revision % REV_MULT);
}
+bool AbstractTool::checkVersion_succeeded(const int &exitCode)
+{
+ return (exitCode == EXIT_SUCCESS);
+}
+
// ------------------------------------------------------------
// Process Creation
// ------------------------------------------------------------
virtual void checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine) = 0;
virtual void checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified) = 0;
+ virtual bool checkVersion_succeeded(const int &exitCode);
void log(const QString &text) { emit messageLogged(text); }
void setStatus(const JobStatus &newStatus) { emit statusChanged(newStatus); }
#define VER_X264_MAJOR 2
#define VER_X264_MINOR 3
#define VER_X264_PATCH 2
-#define VER_X264_BUILD 795
+#define VER_X264_BUILD 797
#define VER_X264_PORTABLE_EDITION (0)