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 "source_abstract.h"
25 #include "model_sysinfo.h"
26 #include "model_options.h"
27 #include "model_preferences.h"
33 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)
35 AbstractTool(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause),
36 m_sourceFile(sourceFile)
38 /*Nothing to do here*/
41 AbstractSource::~AbstractSource(void)
43 /*Nothing to do here*/
46 bool AbstractSource::checkSourceProperties(unsigned int &frames)
49 QList<QRegExp*> patterns;
52 checkSourceProperties_init(patterns, cmdLine);
54 log("Creating process:");
55 if(!startProcess(process, getBinaryPath(), cmdLine))
60 QTextCodec *localCodec = QTextCodec::codecForName("System");
62 bool bTimeout = false;
63 bool bAborted = false;
67 unsigned int fpsNom = 0;
68 unsigned int fpsDen = 0;
69 unsigned int fSizeW = 0;
70 unsigned int fSizeH = 0;
72 unsigned int waitCounter = 0;
74 while(process.state() != QProcess::NotRunning)
82 if(!process.waitForReadyRead(m_processTimeoutInterval))
84 if(process.state() == QProcess::Running)
86 if(++waitCounter > m_processTimeoutMaxCounter)
88 if(m_preferences->getAbortOnTimeout())
91 qWarning("Source process timed out <-- killing!");
92 log("\nPROCESS TIMEOUT !!!");
93 log("\nInput process has encountered a deadlock or your script takes EXTREMELY long to initialize!");
98 else if(waitCounter == m_processTimeoutWarning)
100 unsigned int timeOut = (waitCounter * m_processTimeoutInterval) / 1000U;
101 log(tr("Warning: Input process did not respond for %1 seconds, potential deadlock...").arg(QString::number(timeOut)));
109 while(process.bytesAvailable() > 0)
111 QList<QByteArray> lines = process.readLine().split('\r');
112 while(!lines.isEmpty())
114 QString text = localCodec->toUnicode(lines.takeFirst().constData()).simplified();
119 process.waitForFinished();
120 if(process.state() != QProcess::NotRunning)
123 process.waitForFinished(-1);
126 if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
128 if(!(bTimeout || bAborted))
130 const int exitCode = process.exitCode();
131 log(tr("\nPROCESS EXITED WITH ERROR CODE: %1").arg(QString::number(exitCode)));
132 if((exitCode < 0) || (exitCode >= 32))
134 log(tr("\nIMPORTANT: The Avs2YUV process terminated abnormally. This means Avisynth or one of your Avisynth-Plugin's just crashed."));
135 log(tr("IMPORTANT: Please fix your Avisynth script and try again! If you use Avisynth-MT, try using a *stable* Avisynth instead!"));
143 log(tr("\nFAILED TO DETERMINE AVS PROPERTIES !!!"));
149 if((fSizeW > 0) && (fSizeH > 0))
151 log(tr("Resolution: %1x%2").arg(QString::number(fSizeW), QString::number(fSizeH)));
153 if((fpsNom > 0) && (fpsDen > 0))
155 log(tr("Frame Rate: %1/%2").arg(QString::number(fpsNom), QString::number(fpsDen)));
157 if((fpsNom > 0) && (fpsDen == 0))
159 log(tr("Frame Rate: %1").arg(QString::number(fpsNom)));
163 log(tr("No. Frames: %1").arg(QString::number(frames)));
169 bool AbstractSource::createProcess(QProcess &processEncode, QProcess&processInput)
171 processInput.setStandardOutputProcess(&processEncode);
173 QStringList cmdLine_Input;
174 buildCommandLine(cmdLine_Input);
176 log("Creating input process:");
177 if(!startProcess(processInput, getBinaryPath(), cmdLine_Input, false))